1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2017 Advanced Micro Devices, Inc. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 5bf215546Sopenharmony_ci * a copy of this software and associated documentation files (the 6bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 7bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 8bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 9bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 10bf215546Sopenharmony_ci * the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 13bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 14bf215546Sopenharmony_ci * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15bf215546Sopenharmony_ci * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS 16bf215546Sopenharmony_ci * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 19bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 20bf215546Sopenharmony_ci * 21bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 22bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 23bf215546Sopenharmony_ci * of the Software. 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#ifndef AC_SURFACE_H 27bf215546Sopenharmony_ci#define AC_SURFACE_H 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "amd_family.h" 30bf215546Sopenharmony_ci#include "util/format/u_format.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci/* NIR is optional. Some components don't want to include NIR with ac_surface.h. */ 33bf215546Sopenharmony_ci#ifdef AC_SURFACE_INCLUDE_NIR 34bf215546Sopenharmony_ci#include "compiler/nir/nir_builder.h" 35bf215546Sopenharmony_ci#endif 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci#include <stdbool.h> 38bf215546Sopenharmony_ci#include <stdint.h> 39bf215546Sopenharmony_ci#include <stdio.h> 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci#ifdef __cplusplus 42bf215546Sopenharmony_ciextern "C" { 43bf215546Sopenharmony_ci#endif 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci/* Forward declarations. */ 46bf215546Sopenharmony_cistruct ac_addrlib; 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_cistruct amdgpu_gpu_info; 49bf215546Sopenharmony_cistruct radeon_info; 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci#define RADEON_SURF_MAX_LEVELS 15 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_cienum radeon_surf_mode 54bf215546Sopenharmony_ci{ 55bf215546Sopenharmony_ci RADEON_SURF_MODE_LINEAR_ALIGNED = 1, 56bf215546Sopenharmony_ci RADEON_SURF_MODE_1D = 2, 57bf215546Sopenharmony_ci RADEON_SURF_MODE_2D = 3, 58bf215546Sopenharmony_ci}; 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci/* This describes D/S/Z/R swizzle modes. 61bf215546Sopenharmony_ci * Defined in the GB_TILE_MODEn.MICRO_TILE_MODE_NEW order. 62bf215546Sopenharmony_ci */ 63bf215546Sopenharmony_cienum radeon_micro_mode 64bf215546Sopenharmony_ci{ 65bf215546Sopenharmony_ci RADEON_MICRO_MODE_DISPLAY = 0, 66bf215546Sopenharmony_ci RADEON_MICRO_MODE_STANDARD = 1, 67bf215546Sopenharmony_ci RADEON_MICRO_MODE_DEPTH = 2, 68bf215546Sopenharmony_ci RADEON_MICRO_MODE_RENDER = 3, /* gfx9 and older: rotated */ 69bf215546Sopenharmony_ci}; 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci/* the first 16 bits are reserved for libdrm_radeon, don't use them */ 72bf215546Sopenharmony_ci#define RADEON_SURF_SCANOUT (1 << 16) 73bf215546Sopenharmony_ci#define RADEON_SURF_ZBUFFER (1 << 17) 74bf215546Sopenharmony_ci#define RADEON_SURF_SBUFFER (1 << 18) 75bf215546Sopenharmony_ci#define RADEON_SURF_Z_OR_SBUFFER (RADEON_SURF_ZBUFFER | RADEON_SURF_SBUFFER) 76bf215546Sopenharmony_ci/* bits 19 and 20 are reserved for libdrm_radeon, don't use them */ 77bf215546Sopenharmony_ci#define RADEON_SURF_FMASK (1 << 21) 78bf215546Sopenharmony_ci#define RADEON_SURF_DISABLE_DCC (1ull << 22) 79bf215546Sopenharmony_ci#define RADEON_SURF_TC_COMPATIBLE_HTILE (1ull << 23) 80bf215546Sopenharmony_ci#define RADEON_SURF_IMPORTED (1ull << 24) 81bf215546Sopenharmony_ci#define RADEON_SURF_CONTIGUOUS_DCC_LAYERS (1ull << 25) 82bf215546Sopenharmony_ci#define RADEON_SURF_SHAREABLE (1ull << 26) 83bf215546Sopenharmony_ci#define RADEON_SURF_NO_RENDER_TARGET (1ull << 27) 84bf215546Sopenharmony_ci/* Force a swizzle mode (gfx9+) or tile mode (gfx6-8). 85bf215546Sopenharmony_ci * If this is not set, optimize for space. */ 86bf215546Sopenharmony_ci#define RADEON_SURF_FORCE_SWIZZLE_MODE (1ull << 28) 87bf215546Sopenharmony_ci#define RADEON_SURF_NO_FMASK (1ull << 29) 88bf215546Sopenharmony_ci#define RADEON_SURF_NO_HTILE (1ull << 30) 89bf215546Sopenharmony_ci#define RADEON_SURF_FORCE_MICRO_TILE_MODE (1ull << 31) 90bf215546Sopenharmony_ci#define RADEON_SURF_PRT (1ull << 32) 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_cistruct legacy_surf_level { 93bf215546Sopenharmony_ci uint32_t offset_256B; /* divided by 256, the hw can only do 40-bit addresses */ 94bf215546Sopenharmony_ci uint32_t slice_size_dw; /* in dwords; max = 4GB / 4. */ 95bf215546Sopenharmony_ci unsigned nblk_x : 15; 96bf215546Sopenharmony_ci unsigned nblk_y : 15; 97bf215546Sopenharmony_ci enum radeon_surf_mode mode : 2; 98bf215546Sopenharmony_ci}; 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_cistruct legacy_surf_dcc_level { 101bf215546Sopenharmony_ci uint32_t dcc_offset; /* relative offset within DCC mip tree */ 102bf215546Sopenharmony_ci uint32_t dcc_fast_clear_size; 103bf215546Sopenharmony_ci uint32_t dcc_slice_fast_clear_size; 104bf215546Sopenharmony_ci}; 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_cistruct legacy_surf_fmask { 107bf215546Sopenharmony_ci unsigned slice_tile_max; /* max 4M */ 108bf215546Sopenharmony_ci uint8_t tiling_index; /* max 31 */ 109bf215546Sopenharmony_ci uint8_t bankh; /* max 8 */ 110bf215546Sopenharmony_ci uint16_t pitch_in_pixels; 111bf215546Sopenharmony_ci}; 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_cistruct legacy_surf_layout { 114bf215546Sopenharmony_ci unsigned bankw : 4; /* max 8 */ 115bf215546Sopenharmony_ci unsigned bankh : 4; /* max 8 */ 116bf215546Sopenharmony_ci unsigned mtilea : 4; /* max 8 */ 117bf215546Sopenharmony_ci unsigned tile_split : 13; /* max 4K */ 118bf215546Sopenharmony_ci unsigned stencil_tile_split : 13; /* max 4K */ 119bf215546Sopenharmony_ci unsigned pipe_config : 5; /* max 17 */ 120bf215546Sopenharmony_ci unsigned num_banks : 5; /* max 16 */ 121bf215546Sopenharmony_ci unsigned macro_tile_index : 4; /* max 15 */ 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci /* Whether the depth miptree or stencil miptree as used by the DB are 124bf215546Sopenharmony_ci * adjusted from their TC compatible form to ensure depth/stencil 125bf215546Sopenharmony_ci * compatibility. If either is true, the corresponding plane cannot be 126bf215546Sopenharmony_ci * sampled from. 127bf215546Sopenharmony_ci */ 128bf215546Sopenharmony_ci unsigned depth_adjusted : 1; 129bf215546Sopenharmony_ci unsigned stencil_adjusted : 1; 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci struct legacy_surf_level level[RADEON_SURF_MAX_LEVELS]; 132bf215546Sopenharmony_ci uint8_t tiling_index[RADEON_SURF_MAX_LEVELS]; 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_ci union { 135bf215546Sopenharmony_ci /* Color layout */ 136bf215546Sopenharmony_ci struct { 137bf215546Sopenharmony_ci struct legacy_surf_dcc_level dcc_level[RADEON_SURF_MAX_LEVELS]; 138bf215546Sopenharmony_ci struct legacy_surf_fmask fmask; 139bf215546Sopenharmony_ci unsigned cmask_slice_tile_max; 140bf215546Sopenharmony_ci } color; 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci /* Z/S layout */ 143bf215546Sopenharmony_ci struct { 144bf215546Sopenharmony_ci struct legacy_surf_level stencil_level[RADEON_SURF_MAX_LEVELS]; 145bf215546Sopenharmony_ci uint8_t stencil_tiling_index[RADEON_SURF_MAX_LEVELS]; 146bf215546Sopenharmony_ci } zs; 147bf215546Sopenharmony_ci }; 148bf215546Sopenharmony_ci}; 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci/* Same as addrlib - AddrResourceType. */ 151bf215546Sopenharmony_cienum gfx9_resource_type 152bf215546Sopenharmony_ci{ 153bf215546Sopenharmony_ci RADEON_RESOURCE_1D = 0, 154bf215546Sopenharmony_ci RADEON_RESOURCE_2D, 155bf215546Sopenharmony_ci RADEON_RESOURCE_3D, 156bf215546Sopenharmony_ci}; 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_cistruct gfx9_surf_meta_flags { 159bf215546Sopenharmony_ci uint8_t rb_aligned : 1; /* optimal for RBs */ 160bf215546Sopenharmony_ci uint8_t pipe_aligned : 1; /* optimal for TC */ 161bf215546Sopenharmony_ci uint8_t independent_64B_blocks : 1; 162bf215546Sopenharmony_ci uint8_t independent_128B_blocks : 1; 163bf215546Sopenharmony_ci uint8_t max_compressed_block_size : 2; 164bf215546Sopenharmony_ci uint8_t display_equation_valid : 1; 165bf215546Sopenharmony_ci}; 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_cistruct gfx9_surf_level { 168bf215546Sopenharmony_ci unsigned offset; 169bf215546Sopenharmony_ci unsigned size; /* the size of one level in one layer (the image is an array of layers 170bf215546Sopenharmony_ci * where each layer has an array of levels) */ 171bf215546Sopenharmony_ci}; 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_ci/** 174bf215546Sopenharmony_ci * Meta address equation. 175bf215546Sopenharmony_ci * 176bf215546Sopenharmony_ci * DCC/HTILE address equation for doing DCC/HTILE address computations in shaders. 177bf215546Sopenharmony_ci * 178bf215546Sopenharmony_ci * ac_surface_meta_address_test.c contains the reference implementation. 179bf215546Sopenharmony_ci * ac_nir_{dcc,htile}_addr_from_coord is the NIR implementation. 180bf215546Sopenharmony_ci * 181bf215546Sopenharmony_ci * For DCC: 182bf215546Sopenharmony_ci * The gfx9 equation doesn't support mipmapping. 183bf215546Sopenharmony_ci * The gfx10 equation doesn't support mipmapping and MSAA. 184bf215546Sopenharmony_ci * (those are also limitations of Addr2ComputeDccAddrFromCoord) 185bf215546Sopenharmony_ci * 186bf215546Sopenharmony_ci * For HTILE: 187bf215546Sopenharmony_ci * The gfx9 equation isn't implemented. 188bf215546Sopenharmony_ci * The gfx10 equation doesn't support mipmapping. 189bf215546Sopenharmony_ci */ 190bf215546Sopenharmony_cistruct gfx9_meta_equation { 191bf215546Sopenharmony_ci uint16_t meta_block_width; 192bf215546Sopenharmony_ci uint16_t meta_block_height; 193bf215546Sopenharmony_ci uint16_t meta_block_depth; 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci union { 196bf215546Sopenharmony_ci /* The gfx9 DCC equation is chip-specific, and it varies with: 197bf215546Sopenharmony_ci * - resource type 198bf215546Sopenharmony_ci * - swizzle_mode 199bf215546Sopenharmony_ci * - bpp 200bf215546Sopenharmony_ci * - number of samples 201bf215546Sopenharmony_ci * - number of fragments 202bf215546Sopenharmony_ci * - pipe_aligned 203bf215546Sopenharmony_ci * - rb_aligned 204bf215546Sopenharmony_ci */ 205bf215546Sopenharmony_ci struct { 206bf215546Sopenharmony_ci uint8_t num_bits; 207bf215546Sopenharmony_ci uint8_t num_pipe_bits; 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_ci struct { 210bf215546Sopenharmony_ci struct { 211bf215546Sopenharmony_ci uint8_t dim:3; /* 0..4 */ 212bf215546Sopenharmony_ci uint8_t ord:5; /* 0..31 */ 213bf215546Sopenharmony_ci } coord[5]; /* 0..num_coords-1 */ 214bf215546Sopenharmony_ci } bit[20]; /* 0..num_bits-1 */ 215bf215546Sopenharmony_ci } gfx9; 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci /* The gfx10 DCC equation is chip-specific, it requires 64KB_R_X, and it varies with: 218bf215546Sopenharmony_ci * - bpp 219bf215546Sopenharmony_ci * - number of samples 220bf215546Sopenharmony_ci * - number of fragments 221bf215546Sopenharmony_ci * - pipe_aligned 222bf215546Sopenharmony_ci * 223bf215546Sopenharmony_ci * The gfx10 HTILE equation is chip-specific, it requires 64KB_Z_X, and it varies with: 224bf215546Sopenharmony_ci * - number of samples 225bf215546Sopenharmony_ci */ 226bf215546Sopenharmony_ci uint16_t gfx10_bits[64]; 227bf215546Sopenharmony_ci } u; 228bf215546Sopenharmony_ci}; 229bf215546Sopenharmony_ci 230bf215546Sopenharmony_cistruct gfx9_surf_layout { 231bf215546Sopenharmony_ci uint16_t epitch; /* gfx9 only, not on gfx10 */ 232bf215546Sopenharmony_ci uint8_t swizzle_mode; /* color or depth */ 233bf215546Sopenharmony_ci 234bf215546Sopenharmony_ci enum gfx9_resource_type resource_type:8; /* 1D, 2D or 3D */ 235bf215546Sopenharmony_ci uint16_t surf_pitch; /* in blocks */ 236bf215546Sopenharmony_ci uint16_t surf_height; 237bf215546Sopenharmony_ci 238bf215546Sopenharmony_ci uint64_t surf_offset; /* 0 unless imported with an offset */ 239bf215546Sopenharmony_ci /* The size of the 2D plane containing all mipmap levels. */ 240bf215546Sopenharmony_ci uint64_t surf_slice_size; 241bf215546Sopenharmony_ci /* Mipmap level offset within the slice in bytes. Only valid for LINEAR. */ 242bf215546Sopenharmony_ci uint32_t offset[RADEON_SURF_MAX_LEVELS]; 243bf215546Sopenharmony_ci /* Mipmap level pitch in elements. Only valid for LINEAR. */ 244bf215546Sopenharmony_ci uint16_t pitch[RADEON_SURF_MAX_LEVELS]; 245bf215546Sopenharmony_ci 246bf215546Sopenharmony_ci uint16_t base_mip_width; 247bf215546Sopenharmony_ci uint16_t base_mip_height; 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_ci /* Pitch of level in blocks, only valid for prt images. */ 250bf215546Sopenharmony_ci uint16_t prt_level_pitch[RADEON_SURF_MAX_LEVELS]; 251bf215546Sopenharmony_ci /* Offset within slice in bytes, only valid for prt images. */ 252bf215546Sopenharmony_ci uint32_t prt_level_offset[RADEON_SURF_MAX_LEVELS]; 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ci /* DCC or HTILE level info */ 255bf215546Sopenharmony_ci struct gfx9_surf_level meta_levels[RADEON_SURF_MAX_LEVELS]; 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci union { 258bf215546Sopenharmony_ci /* Color */ 259bf215546Sopenharmony_ci struct { 260bf215546Sopenharmony_ci struct gfx9_surf_meta_flags dcc; /* metadata of color */ 261bf215546Sopenharmony_ci uint8_t fmask_swizzle_mode; 262bf215546Sopenharmony_ci uint16_t fmask_epitch; /* gfx9 only, not on gfx10 */ 263bf215546Sopenharmony_ci 264bf215546Sopenharmony_ci uint16_t dcc_pitch_max; 265bf215546Sopenharmony_ci uint16_t dcc_height; 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci uint8_t dcc_block_width; 268bf215546Sopenharmony_ci uint8_t dcc_block_height; 269bf215546Sopenharmony_ci uint8_t dcc_block_depth; 270bf215546Sopenharmony_ci 271bf215546Sopenharmony_ci /* Displayable DCC. This is always rb_aligned=0 and pipe_aligned=0. 272bf215546Sopenharmony_ci * The 3D engine doesn't support that layout except for chips with 1 RB. 273bf215546Sopenharmony_ci * All other chips must set rb_aligned=1. 274bf215546Sopenharmony_ci * A compute shader needs to convert from aligned DCC to unaligned. 275bf215546Sopenharmony_ci */ 276bf215546Sopenharmony_ci uint8_t display_dcc_alignment_log2; 277bf215546Sopenharmony_ci uint32_t display_dcc_size; 278bf215546Sopenharmony_ci uint16_t display_dcc_pitch_max; /* (mip chain pitch - 1) */ 279bf215546Sopenharmony_ci uint16_t display_dcc_height; 280bf215546Sopenharmony_ci bool dcc_retile_use_uint16; /* if all values fit into uint16_t */ 281bf215546Sopenharmony_ci uint32_t dcc_retile_num_elements; 282bf215546Sopenharmony_ci void *dcc_retile_map; 283bf215546Sopenharmony_ci 284bf215546Sopenharmony_ci /* CMASK level info (only level 0) */ 285bf215546Sopenharmony_ci struct gfx9_surf_level cmask_level0; 286bf215546Sopenharmony_ci 287bf215546Sopenharmony_ci /* For DCC retiling. */ 288bf215546Sopenharmony_ci struct gfx9_meta_equation dcc_equation; /* 2D only */ 289bf215546Sopenharmony_ci struct gfx9_meta_equation display_dcc_equation; 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci /* For FCE compute. */ 292bf215546Sopenharmony_ci struct gfx9_meta_equation cmask_equation; /* 2D only */ 293bf215546Sopenharmony_ci } color; 294bf215546Sopenharmony_ci 295bf215546Sopenharmony_ci /* Z/S */ 296bf215546Sopenharmony_ci struct { 297bf215546Sopenharmony_ci uint64_t stencil_offset; /* separate stencil */ 298bf215546Sopenharmony_ci uint16_t stencil_epitch; /* gfx9 only, not on gfx10 */ 299bf215546Sopenharmony_ci uint8_t stencil_swizzle_mode; 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci /* For HTILE VRS. */ 302bf215546Sopenharmony_ci struct gfx9_meta_equation htile_equation; 303bf215546Sopenharmony_ci } zs; 304bf215546Sopenharmony_ci }; 305bf215546Sopenharmony_ci}; 306bf215546Sopenharmony_ci 307bf215546Sopenharmony_cistruct radeon_surf { 308bf215546Sopenharmony_ci /* Format properties. */ 309bf215546Sopenharmony_ci uint8_t blk_w : 4; 310bf215546Sopenharmony_ci uint8_t blk_h : 4; 311bf215546Sopenharmony_ci uint8_t bpe : 5; 312bf215546Sopenharmony_ci /* Display, standard(thin), depth, render(rotated). AKA D,S,Z,R swizzle modes. */ 313bf215546Sopenharmony_ci uint8_t micro_tile_mode : 3; 314bf215546Sopenharmony_ci /* Number of mipmap levels where DCC or HTILE is enabled starting from level 0. 315bf215546Sopenharmony_ci * Non-zero levels may be disabled due to alignment constraints, but not 316bf215546Sopenharmony_ci * the first level. 317bf215546Sopenharmony_ci */ 318bf215546Sopenharmony_ci uint8_t num_meta_levels : 4; 319bf215546Sopenharmony_ci uint8_t is_linear : 1; 320bf215546Sopenharmony_ci uint8_t has_stencil : 1; 321bf215546Sopenharmony_ci /* This might be true even if micro_tile_mode isn't displayable or rotated. */ 322bf215546Sopenharmony_ci uint8_t is_displayable : 1; 323bf215546Sopenharmony_ci uint8_t first_mip_tail_level : 4; 324bf215546Sopenharmony_ci 325bf215546Sopenharmony_ci /* These are return values. Some of them can be set by the caller, but 326bf215546Sopenharmony_ci * they will be treated as hints (e.g. bankw, bankh) and might be 327bf215546Sopenharmony_ci * changed by the calculator. 328bf215546Sopenharmony_ci */ 329bf215546Sopenharmony_ci 330bf215546Sopenharmony_ci /* Not supported yet for depth + stencil. */ 331bf215546Sopenharmony_ci uint16_t prt_tile_width; 332bf215546Sopenharmony_ci uint16_t prt_tile_height; 333bf215546Sopenharmony_ci uint16_t prt_tile_depth; 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ci /* Tile swizzle can be OR'd with low bits of the BASE_256B address. 336bf215546Sopenharmony_ci * The value is the same for all mipmap levels. Supported tile modes: 337bf215546Sopenharmony_ci * - GFX6: Only macro tiling. 338bf215546Sopenharmony_ci * - GFX9: Only *_X and *_T swizzle modes. Level 0 must not be in the mip 339bf215546Sopenharmony_ci * tail. 340bf215546Sopenharmony_ci * 341bf215546Sopenharmony_ci * Only these surfaces are allowed to set it: 342bf215546Sopenharmony_ci * - color (if it doesn't have to be displayable) 343bf215546Sopenharmony_ci * - DCC (same tile swizzle as color) 344bf215546Sopenharmony_ci * - FMASK 345bf215546Sopenharmony_ci * - CMASK if it's TC-compatible or if the gen is GFX9 346bf215546Sopenharmony_ci * - depth/stencil if HTILE is not TC-compatible and if the gen is not GFX9 347bf215546Sopenharmony_ci */ 348bf215546Sopenharmony_ci uint8_t tile_swizzle; 349bf215546Sopenharmony_ci uint8_t fmask_tile_swizzle; 350bf215546Sopenharmony_ci 351bf215546Sopenharmony_ci /* Use (1 << log2) to compute the alignment. */ 352bf215546Sopenharmony_ci uint8_t surf_alignment_log2; 353bf215546Sopenharmony_ci uint8_t fmask_alignment_log2; 354bf215546Sopenharmony_ci uint8_t meta_alignment_log2; /* DCC or HTILE */ 355bf215546Sopenharmony_ci uint8_t cmask_alignment_log2; 356bf215546Sopenharmony_ci uint8_t alignment_log2; 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci /* DRM format modifier. Set to DRM_FORMAT_MOD_INVALID to have addrlib 359bf215546Sopenharmony_ci * select tiling parameters instead. 360bf215546Sopenharmony_ci */ 361bf215546Sopenharmony_ci uint64_t modifier; 362bf215546Sopenharmony_ci uint64_t flags; 363bf215546Sopenharmony_ci 364bf215546Sopenharmony_ci uint64_t surf_size; 365bf215546Sopenharmony_ci uint64_t fmask_size; 366bf215546Sopenharmony_ci uint32_t fmask_slice_size; /* max 2^31 (16K * 16K * 8) */ 367bf215546Sopenharmony_ci 368bf215546Sopenharmony_ci /* DCC and HTILE (they are very small) */ 369bf215546Sopenharmony_ci uint32_t meta_size; 370bf215546Sopenharmony_ci uint32_t meta_slice_size; 371bf215546Sopenharmony_ci uint32_t meta_pitch; 372bf215546Sopenharmony_ci 373bf215546Sopenharmony_ci uint32_t cmask_size; 374bf215546Sopenharmony_ci uint32_t cmask_slice_size; 375bf215546Sopenharmony_ci uint16_t cmask_pitch; /* GFX9+ */ 376bf215546Sopenharmony_ci uint16_t cmask_height; /* GFX9+ */ 377bf215546Sopenharmony_ci 378bf215546Sopenharmony_ci /* All buffers combined. */ 379bf215546Sopenharmony_ci uint64_t meta_offset; /* DCC or HTILE */ 380bf215546Sopenharmony_ci uint64_t fmask_offset; 381bf215546Sopenharmony_ci uint64_t cmask_offset; 382bf215546Sopenharmony_ci uint64_t display_dcc_offset; 383bf215546Sopenharmony_ci uint64_t total_size; 384bf215546Sopenharmony_ci 385bf215546Sopenharmony_ci union { 386bf215546Sopenharmony_ci /* Return values for GFX8 and older. 387bf215546Sopenharmony_ci * 388bf215546Sopenharmony_ci * Some of them can be set by the caller if certain parameters are 389bf215546Sopenharmony_ci * desirable. The allocator will try to obey them. 390bf215546Sopenharmony_ci */ 391bf215546Sopenharmony_ci struct legacy_surf_layout legacy; 392bf215546Sopenharmony_ci 393bf215546Sopenharmony_ci /* GFX9+ return values. */ 394bf215546Sopenharmony_ci struct gfx9_surf_layout gfx9; 395bf215546Sopenharmony_ci } u; 396bf215546Sopenharmony_ci}; 397bf215546Sopenharmony_ci 398bf215546Sopenharmony_cistruct ac_surf_info { 399bf215546Sopenharmony_ci uint32_t width; 400bf215546Sopenharmony_ci uint32_t height; 401bf215546Sopenharmony_ci uint32_t depth; 402bf215546Sopenharmony_ci uint8_t samples; /* For Z/S: samples; For color: FMASK coverage samples */ 403bf215546Sopenharmony_ci uint8_t storage_samples; /* For color: allocated samples */ 404bf215546Sopenharmony_ci uint8_t levels; 405bf215546Sopenharmony_ci uint8_t num_channels; /* heuristic for displayability */ 406bf215546Sopenharmony_ci uint16_t array_size; 407bf215546Sopenharmony_ci uint32_t *surf_index; /* Set a monotonic counter for tile swizzling. */ 408bf215546Sopenharmony_ci uint32_t *fmask_surf_index; 409bf215546Sopenharmony_ci}; 410bf215546Sopenharmony_ci 411bf215546Sopenharmony_cistruct ac_surf_config { 412bf215546Sopenharmony_ci struct ac_surf_info info; 413bf215546Sopenharmony_ci unsigned is_1d : 1; 414bf215546Sopenharmony_ci unsigned is_3d : 1; 415bf215546Sopenharmony_ci unsigned is_cube : 1; 416bf215546Sopenharmony_ci}; 417bf215546Sopenharmony_ci 418bf215546Sopenharmony_cistruct ac_addrlib *ac_addrlib_create(const struct radeon_info *info, uint64_t *max_alignment); 419bf215546Sopenharmony_civoid ac_addrlib_destroy(struct ac_addrlib *addrlib); 420bf215546Sopenharmony_civoid *ac_addrlib_get_handle(struct ac_addrlib *addrlib); 421bf215546Sopenharmony_ci 422bf215546Sopenharmony_ciint ac_compute_surface(struct ac_addrlib *addrlib, const struct radeon_info *info, 423bf215546Sopenharmony_ci const struct ac_surf_config *config, enum radeon_surf_mode mode, 424bf215546Sopenharmony_ci struct radeon_surf *surf); 425bf215546Sopenharmony_civoid ac_surface_zero_dcc_fields(struct radeon_surf *surf); 426bf215546Sopenharmony_ci 427bf215546Sopenharmony_civoid ac_surface_set_bo_metadata(const struct radeon_info *info, struct radeon_surf *surf, 428bf215546Sopenharmony_ci uint64_t tiling_flags, enum radeon_surf_mode *mode); 429bf215546Sopenharmony_civoid ac_surface_get_bo_metadata(const struct radeon_info *info, struct radeon_surf *surf, 430bf215546Sopenharmony_ci uint64_t *tiling_flags); 431bf215546Sopenharmony_ci 432bf215546Sopenharmony_cibool ac_surface_set_umd_metadata(const struct radeon_info *info, struct radeon_surf *surf, 433bf215546Sopenharmony_ci unsigned num_storage_samples, unsigned num_mipmap_levels, 434bf215546Sopenharmony_ci unsigned size_metadata, const uint32_t metadata[64]); 435bf215546Sopenharmony_civoid ac_surface_get_umd_metadata(const struct radeon_info *info, struct radeon_surf *surf, 436bf215546Sopenharmony_ci unsigned num_mipmap_levels, uint32_t desc[8], 437bf215546Sopenharmony_ci unsigned *size_metadata, uint32_t metadata[64]); 438bf215546Sopenharmony_ci 439bf215546Sopenharmony_cibool ac_surface_override_offset_stride(const struct radeon_info *info, struct radeon_surf *surf, 440bf215546Sopenharmony_ci unsigned num_mipmap_levels, uint64_t offset, unsigned pitch); 441bf215546Sopenharmony_ci 442bf215546Sopenharmony_cistruct ac_modifier_options { 443bf215546Sopenharmony_ci bool dcc; /* Whether to allow DCC. */ 444bf215546Sopenharmony_ci bool dcc_retile; /* Whether to allow use of a DCC retile map. */ 445bf215546Sopenharmony_ci}; 446bf215546Sopenharmony_ci 447bf215546Sopenharmony_cibool ac_is_modifier_supported(const struct radeon_info *info, 448bf215546Sopenharmony_ci const struct ac_modifier_options *options, 449bf215546Sopenharmony_ci enum pipe_format format, 450bf215546Sopenharmony_ci uint64_t modifier); 451bf215546Sopenharmony_cibool ac_get_supported_modifiers(const struct radeon_info *info, 452bf215546Sopenharmony_ci const struct ac_modifier_options *options, 453bf215546Sopenharmony_ci enum pipe_format format, 454bf215546Sopenharmony_ci unsigned *mod_count, 455bf215546Sopenharmony_ci uint64_t *mods); 456bf215546Sopenharmony_cibool ac_modifier_has_dcc(uint64_t modifier); 457bf215546Sopenharmony_cibool ac_modifier_has_dcc_retile(uint64_t modifier); 458bf215546Sopenharmony_cibool ac_modifier_supports_dcc_image_stores(uint64_t modifier); 459bf215546Sopenharmony_civoid ac_modifier_max_extent(const struct radeon_info *info, 460bf215546Sopenharmony_ci uint64_t modifier, uint32_t *width, uint32_t *height); 461bf215546Sopenharmony_ci 462bf215546Sopenharmony_ciunsigned ac_surface_get_nplanes(const struct radeon_surf *surf); 463bf215546Sopenharmony_ciuint64_t ac_surface_get_plane_offset(enum amd_gfx_level gfx_level, 464bf215546Sopenharmony_ci const struct radeon_surf *surf, 465bf215546Sopenharmony_ci unsigned plane, unsigned layer); 466bf215546Sopenharmony_ciuint64_t ac_surface_get_plane_stride(enum amd_gfx_level gfx_level, 467bf215546Sopenharmony_ci const struct radeon_surf *surf, 468bf215546Sopenharmony_ci unsigned plane, unsigned level); 469bf215546Sopenharmony_ci/* Of the whole miplevel, not an individual layer */ 470bf215546Sopenharmony_ciuint64_t ac_surface_get_plane_size(const struct radeon_surf *surf, 471bf215546Sopenharmony_ci unsigned plane); 472bf215546Sopenharmony_ci 473bf215546Sopenharmony_civoid ac_surface_print_info(FILE *out, const struct radeon_info *info, 474bf215546Sopenharmony_ci const struct radeon_surf *surf); 475bf215546Sopenharmony_ci 476bf215546Sopenharmony_cibool ac_surface_supports_dcc_image_stores(enum amd_gfx_level gfx_level, 477bf215546Sopenharmony_ci const struct radeon_surf *surf); 478bf215546Sopenharmony_ci 479bf215546Sopenharmony_ci#ifdef AC_SURFACE_INCLUDE_NIR 480bf215546Sopenharmony_cinir_ssa_def *ac_nir_dcc_addr_from_coord(nir_builder *b, const struct radeon_info *info, 481bf215546Sopenharmony_ci unsigned bpe, struct gfx9_meta_equation *equation, 482bf215546Sopenharmony_ci nir_ssa_def *dcc_pitch, nir_ssa_def *dcc_height, 483bf215546Sopenharmony_ci nir_ssa_def *dcc_slice_size, 484bf215546Sopenharmony_ci nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *z, 485bf215546Sopenharmony_ci nir_ssa_def *sample, nir_ssa_def *pipe_xor); 486bf215546Sopenharmony_ci 487bf215546Sopenharmony_cinir_ssa_def *ac_nir_cmask_addr_from_coord(nir_builder *b, const struct radeon_info *info, 488bf215546Sopenharmony_ci struct gfx9_meta_equation *equation, 489bf215546Sopenharmony_ci nir_ssa_def *cmask_pitch, nir_ssa_def *cmask_height, 490bf215546Sopenharmony_ci nir_ssa_def *cmask_slice_size, 491bf215546Sopenharmony_ci nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *z, 492bf215546Sopenharmony_ci nir_ssa_def *pipe_xor, 493bf215546Sopenharmony_ci nir_ssa_def **bit_position); 494bf215546Sopenharmony_ci 495bf215546Sopenharmony_cinir_ssa_def *ac_nir_htile_addr_from_coord(nir_builder *b, const struct radeon_info *info, 496bf215546Sopenharmony_ci struct gfx9_meta_equation *equation, 497bf215546Sopenharmony_ci nir_ssa_def *htile_pitch, 498bf215546Sopenharmony_ci nir_ssa_def *htile_slice_size, 499bf215546Sopenharmony_ci nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *z, 500bf215546Sopenharmony_ci nir_ssa_def *pipe_xor); 501bf215546Sopenharmony_ci#endif 502bf215546Sopenharmony_ci 503bf215546Sopenharmony_ci#ifdef __cplusplus 504bf215546Sopenharmony_ci} 505bf215546Sopenharmony_ci#endif 506bf215546Sopenharmony_ci 507bf215546Sopenharmony_ci#endif /* AC_SURFACE_H */ 508