101e04c3fSmrg/*
201e04c3fSmrg * Copyright © 2017 Advanced Micro Devices, Inc.
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining
501e04c3fSmrg * a copy of this software and associated documentation files (the
601e04c3fSmrg * "Software"), to deal in the Software without restriction, including
701e04c3fSmrg * without limitation the rights to use, copy, modify, merge, publish,
801e04c3fSmrg * distribute, sub license, and/or sell copies of the Software, and to
901e04c3fSmrg * permit persons to whom the Software is furnished to do so, subject to
1001e04c3fSmrg * the following conditions:
1101e04c3fSmrg *
1201e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1301e04c3fSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
1401e04c3fSmrg * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1501e04c3fSmrg * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
1601e04c3fSmrg * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1701e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1801e04c3fSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1901e04c3fSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
2001e04c3fSmrg *
2101e04c3fSmrg * The above copyright notice and this permission notice (including the
2201e04c3fSmrg * next paragraph) shall be included in all copies or substantial portions
2301e04c3fSmrg * of the Software.
2401e04c3fSmrg */
2501e04c3fSmrg
2601e04c3fSmrg#ifndef AC_SURFACE_H
2701e04c3fSmrg#define AC_SURFACE_H
2801e04c3fSmrg
2901e04c3fSmrg#include "amd_family.h"
307ec681f3Smrg#include "util/format/u_format.h"
317ec681f3Smrg
327ec681f3Smrg/* NIR is optional. Some components don't want to include NIR with ac_surface.h. */
337ec681f3Smrg#ifdef AC_SURFACE_INCLUDE_NIR
347ec681f3Smrg#include "compiler/nir/nir_builder.h"
357ec681f3Smrg#endif
367ec681f3Smrg
377ec681f3Smrg#include <stdbool.h>
387ec681f3Smrg#include <stdint.h>
397ec681f3Smrg#include <stdio.h>
4001e04c3fSmrg
4101e04c3fSmrg#ifdef __cplusplus
4201e04c3fSmrgextern "C" {
4301e04c3fSmrg#endif
4401e04c3fSmrg
4501e04c3fSmrg/* Forward declarations. */
467ec681f3Smrgstruct ac_addrlib;
4701e04c3fSmrg
4801e04c3fSmrgstruct amdgpu_gpu_info;
4901e04c3fSmrgstruct radeon_info;
5001e04c3fSmrg
517ec681f3Smrg#define RADEON_SURF_MAX_LEVELS 15
5201e04c3fSmrg
537ec681f3Smrgenum radeon_surf_mode
547ec681f3Smrg{
557ec681f3Smrg   RADEON_SURF_MODE_LINEAR_ALIGNED = 1,
567ec681f3Smrg   RADEON_SURF_MODE_1D = 2,
577ec681f3Smrg   RADEON_SURF_MODE_2D = 3,
5801e04c3fSmrg};
5901e04c3fSmrg
607ec681f3Smrg/* This describes D/S/Z/R swizzle modes.
617ec681f3Smrg * Defined in the GB_TILE_MODEn.MICRO_TILE_MODE_NEW order.
627ec681f3Smrg */
637ec681f3Smrgenum radeon_micro_mode
647ec681f3Smrg{
657ec681f3Smrg   RADEON_MICRO_MODE_DISPLAY = 0,
667ec681f3Smrg   RADEON_MICRO_MODE_STANDARD = 1,
677ec681f3Smrg   RADEON_MICRO_MODE_DEPTH = 2,
687ec681f3Smrg   RADEON_MICRO_MODE_RENDER = 3, /* gfx9 and older: rotated */
6901e04c3fSmrg};
7001e04c3fSmrg
7101e04c3fSmrg/* the first 16 bits are reserved for libdrm_radeon, don't use them */
727ec681f3Smrg#define RADEON_SURF_SCANOUT      (1 << 16)
737ec681f3Smrg#define RADEON_SURF_ZBUFFER      (1 << 17)
747ec681f3Smrg#define RADEON_SURF_SBUFFER      (1 << 18)
757ec681f3Smrg#define RADEON_SURF_Z_OR_SBUFFER (RADEON_SURF_ZBUFFER | RADEON_SURF_SBUFFER)
7601e04c3fSmrg/* bits 19 and 20 are reserved for libdrm_radeon, don't use them */
777ec681f3Smrg#define RADEON_SURF_FMASK                 (1 << 21)
787ec681f3Smrg#define RADEON_SURF_DISABLE_DCC           (1ull << 22)
797ec681f3Smrg#define RADEON_SURF_TC_COMPATIBLE_HTILE   (1ull << 23)
807ec681f3Smrg#define RADEON_SURF_IMPORTED              (1ull << 24)
817ec681f3Smrg#define RADEON_SURF_CONTIGUOUS_DCC_LAYERS (1ull << 25)
827ec681f3Smrg#define RADEON_SURF_SHAREABLE             (1ull << 26)
837ec681f3Smrg#define RADEON_SURF_NO_RENDER_TARGET      (1ull << 27)
847ec681f3Smrg/* Force a swizzle mode (gfx9+) or tile mode (gfx6-8).
857ec681f3Smrg * If this is not set, optimize for space. */
867ec681f3Smrg#define RADEON_SURF_FORCE_SWIZZLE_MODE    (1ull << 28)
877ec681f3Smrg#define RADEON_SURF_NO_FMASK              (1ull << 29)
887ec681f3Smrg#define RADEON_SURF_NO_HTILE              (1ull << 30)
897ec681f3Smrg#define RADEON_SURF_FORCE_MICRO_TILE_MODE (1ull << 31)
907ec681f3Smrg#define RADEON_SURF_PRT                   (1ull << 32)
9101e04c3fSmrg
9201e04c3fSmrgstruct legacy_surf_level {
937ec681f3Smrg   uint32_t offset_256B;   /* divided by 256, the hw can only do 40-bit addresses */
947ec681f3Smrg   uint32_t slice_size_dw; /* in dwords; max = 4GB / 4. */
957ec681f3Smrg   unsigned nblk_x : 15;
967ec681f3Smrg   unsigned nblk_y : 15;
977ec681f3Smrg   enum radeon_surf_mode mode : 2;
987ec681f3Smrg};
997ec681f3Smrg
1007ec681f3Smrgstruct legacy_surf_dcc_level {
1017ec681f3Smrg   uint32_t dcc_offset;    /* relative offset within DCC mip tree */
1027ec681f3Smrg   uint32_t dcc_fast_clear_size;
1037ec681f3Smrg   uint32_t dcc_slice_fast_clear_size;
10401e04c3fSmrg};
10501e04c3fSmrg
10601e04c3fSmrgstruct legacy_surf_fmask {
1077ec681f3Smrg   unsigned slice_tile_max; /* max 4M */
1087ec681f3Smrg   uint8_t tiling_index;    /* max 31 */
1097ec681f3Smrg   uint8_t bankh;           /* max 8 */
1107ec681f3Smrg   uint16_t pitch_in_pixels;
11101e04c3fSmrg};
11201e04c3fSmrg
11301e04c3fSmrgstruct legacy_surf_layout {
1147ec681f3Smrg   unsigned bankw : 4;               /* max 8 */
1157ec681f3Smrg   unsigned bankh : 4;               /* max 8 */
1167ec681f3Smrg   unsigned mtilea : 4;              /* max 8 */
1177ec681f3Smrg   unsigned tile_split : 13;         /* max 4K */
1187ec681f3Smrg   unsigned stencil_tile_split : 13; /* max 4K */
1197ec681f3Smrg   unsigned pipe_config : 5;         /* max 17 */
1207ec681f3Smrg   unsigned num_banks : 5;           /* max 16 */
1217ec681f3Smrg   unsigned macro_tile_index : 4;    /* max 15 */
1227ec681f3Smrg
1237ec681f3Smrg   /* Whether the depth miptree or stencil miptree as used by the DB are
1247ec681f3Smrg    * adjusted from their TC compatible form to ensure depth/stencil
1257ec681f3Smrg    * compatibility. If either is true, the corresponding plane cannot be
1267ec681f3Smrg    * sampled from.
1277ec681f3Smrg    */
1287ec681f3Smrg   unsigned depth_adjusted : 1;
1297ec681f3Smrg   unsigned stencil_adjusted : 1;
1307ec681f3Smrg
1317ec681f3Smrg   struct legacy_surf_level level[RADEON_SURF_MAX_LEVELS];
1327ec681f3Smrg   uint8_t tiling_index[RADEON_SURF_MAX_LEVELS];
1337ec681f3Smrg
1347ec681f3Smrg   union {
1357ec681f3Smrg      /* Color layout */
1367ec681f3Smrg      struct {
1377ec681f3Smrg         struct legacy_surf_dcc_level dcc_level[RADEON_SURF_MAX_LEVELS];
1387ec681f3Smrg         struct legacy_surf_fmask fmask;
1397ec681f3Smrg         unsigned cmask_slice_tile_max;
1407ec681f3Smrg      } color;
1417ec681f3Smrg
1427ec681f3Smrg      /* Z/S layout */
1437ec681f3Smrg      struct {
1447ec681f3Smrg         struct legacy_surf_level stencil_level[RADEON_SURF_MAX_LEVELS];
1457ec681f3Smrg         uint8_t stencil_tiling_index[RADEON_SURF_MAX_LEVELS];
1467ec681f3Smrg      } zs;
1477ec681f3Smrg   };
14801e04c3fSmrg};
14901e04c3fSmrg
15001e04c3fSmrg/* Same as addrlib - AddrResourceType. */
1517ec681f3Smrgenum gfx9_resource_type
1527ec681f3Smrg{
1537ec681f3Smrg   RADEON_RESOURCE_1D = 0,
1547ec681f3Smrg   RADEON_RESOURCE_2D,
1557ec681f3Smrg   RADEON_RESOURCE_3D,
15601e04c3fSmrg};
15701e04c3fSmrg
1587ec681f3Smrgstruct gfx9_surf_meta_flags {
1597ec681f3Smrg   uint8_t rb_aligned : 1;   /* optimal for RBs */
1607ec681f3Smrg   uint8_t pipe_aligned : 1; /* optimal for TC */
1617ec681f3Smrg   uint8_t independent_64B_blocks : 1;
1627ec681f3Smrg   uint8_t independent_128B_blocks : 1;
1637ec681f3Smrg   uint8_t max_compressed_block_size : 2;
1647ec681f3Smrg   uint8_t display_equation_valid : 1;
16501e04c3fSmrg};
16601e04c3fSmrg
1677ec681f3Smrgstruct gfx9_surf_level {
1687ec681f3Smrg   unsigned offset;
1697ec681f3Smrg   unsigned size; /* the size of one level in one layer (the image is an array of layers
1707ec681f3Smrg                   * where each layer has an array of levels) */
1717ec681f3Smrg};
1727ec681f3Smrg
1737ec681f3Smrg/**
1747ec681f3Smrg * Meta address equation.
1757ec681f3Smrg *
1767ec681f3Smrg * DCC/HTILE address equation for doing DCC/HTILE address computations in shaders.
1777ec681f3Smrg *
1787ec681f3Smrg * ac_surface_meta_address_test.c contains the reference implementation.
1797ec681f3Smrg * ac_nir_{dcc,htile}_addr_from_coord is the NIR implementation.
1807ec681f3Smrg *
1817ec681f3Smrg * For DCC:
1827ec681f3Smrg * The gfx9 equation doesn't support mipmapping.
1837ec681f3Smrg * The gfx10 equation doesn't support mipmapping and MSAA.
1847ec681f3Smrg * (those are also limitations of Addr2ComputeDccAddrFromCoord)
1857ec681f3Smrg *
1867ec681f3Smrg * For HTILE:
1877ec681f3Smrg * The gfx9 equation isn't implemented.
1887ec681f3Smrg * The gfx10 equation doesn't support mipmapping.
1897ec681f3Smrg */
1907ec681f3Smrgstruct gfx9_meta_equation {
1917ec681f3Smrg   uint16_t meta_block_width;
1927ec681f3Smrg   uint16_t meta_block_height;
1937ec681f3Smrg   uint16_t meta_block_depth;
1947ec681f3Smrg
1957ec681f3Smrg   union {
1967ec681f3Smrg      /* The gfx9 DCC equation is chip-specific, and it varies with:
1977ec681f3Smrg       * - resource type
1987ec681f3Smrg       * - swizzle_mode
1997ec681f3Smrg       * - bpp
2007ec681f3Smrg       * - number of samples
2017ec681f3Smrg       * - number of fragments
2027ec681f3Smrg       * - pipe_aligned
2037ec681f3Smrg       * - rb_aligned
2047ec681f3Smrg       */
2057ec681f3Smrg      struct {
2067ec681f3Smrg         uint8_t num_bits;
2077ec681f3Smrg         uint8_t num_pipe_bits;
2087ec681f3Smrg
2097ec681f3Smrg         struct {
2107ec681f3Smrg            struct {
2117ec681f3Smrg               uint8_t dim:3; /* 0..4 */
2127ec681f3Smrg               uint8_t ord:5; /* 0..31 */
2137ec681f3Smrg            } coord[5]; /* 0..num_coords-1 */
2147ec681f3Smrg         } bit[20]; /* 0..num_bits-1 */
2157ec681f3Smrg      } gfx9;
2167ec681f3Smrg
2177ec681f3Smrg      /* The gfx10 DCC equation is chip-specific, it requires 64KB_R_X, and it varies with:
2187ec681f3Smrg       * - bpp
2197ec681f3Smrg       * - number of samples
2207ec681f3Smrg       * - number of fragments
2217ec681f3Smrg       * - pipe_aligned
2227ec681f3Smrg       *
2237ec681f3Smrg       * The gfx10 HTILE equation is chip-specific, it requires 64KB_Z_X, and it varies with:
2247ec681f3Smrg       * - number of samples
2257ec681f3Smrg       */
2267ec681f3Smrg      uint16_t gfx10_bits[64];
2277ec681f3Smrg   } u;
22801e04c3fSmrg};
22901e04c3fSmrg
23001e04c3fSmrgstruct gfx9_surf_layout {
2317ec681f3Smrg   uint16_t epitch;           /* gfx9 only, not on gfx10 */
2327ec681f3Smrg   uint8_t swizzle_mode;      /* color or depth */
2337ec681f3Smrg
2347ec681f3Smrg   enum gfx9_resource_type resource_type:8; /* 1D, 2D or 3D */
2357ec681f3Smrg   uint16_t surf_pitch;                   /* in blocks */
2367ec681f3Smrg   uint16_t surf_height;
2377ec681f3Smrg
2387ec681f3Smrg   uint64_t surf_offset; /* 0 unless imported with an offset */
2397ec681f3Smrg   /* The size of the 2D plane containing all mipmap levels. */
2407ec681f3Smrg   uint64_t surf_slice_size;
2417ec681f3Smrg   /* Mipmap level offset within the slice in bytes. Only valid for LINEAR. */
2427ec681f3Smrg   uint32_t offset[RADEON_SURF_MAX_LEVELS];
2437ec681f3Smrg   /* Mipmap level pitch in elements. Only valid for LINEAR. */
2447ec681f3Smrg   uint16_t pitch[RADEON_SURF_MAX_LEVELS];
2457ec681f3Smrg
2467ec681f3Smrg   uint16_t base_mip_width;
2477ec681f3Smrg   uint16_t base_mip_height;
2487ec681f3Smrg
2497ec681f3Smrg   /* Pitch of level in blocks, only valid for prt images. */
2507ec681f3Smrg   uint16_t prt_level_pitch[RADEON_SURF_MAX_LEVELS];
2517ec681f3Smrg   /* Offset within slice in bytes, only valid for prt images. */
2527ec681f3Smrg   uint32_t prt_level_offset[RADEON_SURF_MAX_LEVELS];
2537ec681f3Smrg
2547ec681f3Smrg   /* DCC or HTILE level info */
2557ec681f3Smrg   struct gfx9_surf_level meta_levels[RADEON_SURF_MAX_LEVELS];
2567ec681f3Smrg
2577ec681f3Smrg   union {
2587ec681f3Smrg      /* Color */
2597ec681f3Smrg      struct {
2607ec681f3Smrg         struct gfx9_surf_meta_flags dcc; /* metadata of color */
2617ec681f3Smrg         uint8_t fmask_swizzle_mode;
2627ec681f3Smrg         uint16_t fmask_epitch;     /* gfx9 only, not on gfx10 */
2637ec681f3Smrg
2647ec681f3Smrg         uint16_t dcc_pitch_max;
2657ec681f3Smrg         uint16_t dcc_height;
2667ec681f3Smrg
2677ec681f3Smrg         uint8_t dcc_block_width;
2687ec681f3Smrg         uint8_t dcc_block_height;
2697ec681f3Smrg         uint8_t dcc_block_depth;
2707ec681f3Smrg
2717ec681f3Smrg         /* Displayable DCC. This is always rb_aligned=0 and pipe_aligned=0.
2727ec681f3Smrg          * The 3D engine doesn't support that layout except for chips with 1 RB.
2737ec681f3Smrg          * All other chips must set rb_aligned=1.
2747ec681f3Smrg          * A compute shader needs to convert from aligned DCC to unaligned.
2757ec681f3Smrg          */
2767ec681f3Smrg         uint8_t display_dcc_alignment_log2;
2777ec681f3Smrg         uint32_t display_dcc_size;
2787ec681f3Smrg         uint16_t display_dcc_pitch_max; /* (mip chain pitch - 1) */
2797ec681f3Smrg         uint16_t display_dcc_height;
2807ec681f3Smrg         bool dcc_retile_use_uint16;     /* if all values fit into uint16_t */
2817ec681f3Smrg         uint32_t dcc_retile_num_elements;
2827ec681f3Smrg         void *dcc_retile_map;
2837ec681f3Smrg
2847ec681f3Smrg         /* CMASK level info (only level 0) */
2857ec681f3Smrg         struct gfx9_surf_level cmask_level0;
2867ec681f3Smrg
2877ec681f3Smrg         /* For DCC retiling. */
2887ec681f3Smrg         struct gfx9_meta_equation dcc_equation; /* 2D only */
2897ec681f3Smrg         struct gfx9_meta_equation display_dcc_equation;
2907ec681f3Smrg
2917ec681f3Smrg         /* For FCE compute. */
2927ec681f3Smrg         struct gfx9_meta_equation cmask_equation; /* 2D only */
2937ec681f3Smrg      } color;
2947ec681f3Smrg
2957ec681f3Smrg      /* Z/S */
2967ec681f3Smrg      struct {
2977ec681f3Smrg         uint64_t stencil_offset; /* separate stencil */
2987ec681f3Smrg         uint16_t stencil_epitch;   /* gfx9 only, not on gfx10 */
2997ec681f3Smrg         uint8_t stencil_swizzle_mode;
3007ec681f3Smrg
3017ec681f3Smrg         /* For HTILE VRS. */
3027ec681f3Smrg         struct gfx9_meta_equation htile_equation;
3037ec681f3Smrg      } zs;
3047ec681f3Smrg   };
30501e04c3fSmrg};
30601e04c3fSmrg
30701e04c3fSmrgstruct radeon_surf {
3087ec681f3Smrg   /* Format properties. */
3097ec681f3Smrg   uint8_t blk_w : 4;
3107ec681f3Smrg   uint8_t blk_h : 4;
3117ec681f3Smrg   uint8_t bpe : 5;
3127ec681f3Smrg   /* Display, standard(thin), depth, render(rotated). AKA D,S,Z,R swizzle modes. */
3137ec681f3Smrg   uint8_t micro_tile_mode : 3;
3147ec681f3Smrg   /* Number of mipmap levels where DCC or HTILE is enabled starting from level 0.
3157ec681f3Smrg    * Non-zero levels may be disabled due to alignment constraints, but not
3167ec681f3Smrg    * the first level.
3177ec681f3Smrg    */
3187ec681f3Smrg   uint8_t num_meta_levels : 4;
3197ec681f3Smrg   uint8_t is_linear : 1;
3207ec681f3Smrg   uint8_t has_stencil : 1;
3217ec681f3Smrg   /* This might be true even if micro_tile_mode isn't displayable or rotated. */
3227ec681f3Smrg   uint8_t is_displayable : 1;
3237ec681f3Smrg   uint8_t first_mip_tail_level : 4;
3247ec681f3Smrg
3257ec681f3Smrg   /* These are return values. Some of them can be set by the caller, but
3267ec681f3Smrg    * they will be treated as hints (e.g. bankw, bankh) and might be
3277ec681f3Smrg    * changed by the calculator.
3287ec681f3Smrg    */
3297ec681f3Smrg
3307ec681f3Smrg   /* Not supported yet for depth + stencil. */
3317ec681f3Smrg   uint16_t prt_tile_width;
3327ec681f3Smrg   uint16_t prt_tile_height;
3337ec681f3Smrg
3347ec681f3Smrg   /* Tile swizzle can be OR'd with low bits of the BASE_256B address.
3357ec681f3Smrg    * The value is the same for all mipmap levels. Supported tile modes:
3367ec681f3Smrg    * - GFX6: Only macro tiling.
3377ec681f3Smrg    * - GFX9: Only *_X and *_T swizzle modes. Level 0 must not be in the mip
3387ec681f3Smrg    *   tail.
3397ec681f3Smrg    *
3407ec681f3Smrg    * Only these surfaces are allowed to set it:
3417ec681f3Smrg    * - color (if it doesn't have to be displayable)
3427ec681f3Smrg    * - DCC (same tile swizzle as color)
3437ec681f3Smrg    * - FMASK
3447ec681f3Smrg    * - CMASK if it's TC-compatible or if the gen is GFX9
3457ec681f3Smrg    * - depth/stencil if HTILE is not TC-compatible and if the gen is not GFX9
3467ec681f3Smrg    */
3477ec681f3Smrg   uint8_t tile_swizzle;
3487ec681f3Smrg   uint8_t fmask_tile_swizzle;
3497ec681f3Smrg
3507ec681f3Smrg   /* Use (1 << log2) to compute the alignment. */
3517ec681f3Smrg   uint8_t surf_alignment_log2;
3527ec681f3Smrg   uint8_t fmask_alignment_log2;
3537ec681f3Smrg   uint8_t meta_alignment_log2; /* DCC or HTILE */
3547ec681f3Smrg   uint8_t cmask_alignment_log2;
3557ec681f3Smrg   uint8_t alignment_log2;
3567ec681f3Smrg
3577ec681f3Smrg   /* DRM format modifier. Set to DRM_FORMAT_MOD_INVALID to have addrlib
3587ec681f3Smrg    * select tiling parameters instead.
3597ec681f3Smrg    */
3607ec681f3Smrg   uint64_t modifier;
3617ec681f3Smrg   uint64_t flags;
3627ec681f3Smrg
3637ec681f3Smrg   uint64_t surf_size;
3647ec681f3Smrg   uint64_t fmask_size;
3657ec681f3Smrg   uint32_t fmask_slice_size; /* max 2^31 (16K * 16K * 8) */
3667ec681f3Smrg
3677ec681f3Smrg   /* DCC and HTILE (they are very small) */
3687ec681f3Smrg   uint32_t meta_size;
3697ec681f3Smrg   uint32_t meta_slice_size;
3707ec681f3Smrg   uint32_t meta_pitch;
3717ec681f3Smrg
3727ec681f3Smrg   uint32_t cmask_size;
3737ec681f3Smrg   uint32_t cmask_slice_size;
3747ec681f3Smrg   uint16_t cmask_pitch; /* GFX9+ */
3757ec681f3Smrg   uint16_t cmask_height; /* GFX9+ */
3767ec681f3Smrg
3777ec681f3Smrg   /* All buffers combined. */
3787ec681f3Smrg   uint64_t meta_offset; /* DCC or HTILE */
3797ec681f3Smrg   uint64_t fmask_offset;
3807ec681f3Smrg   uint64_t cmask_offset;
3817ec681f3Smrg   uint64_t display_dcc_offset;
3827ec681f3Smrg   uint64_t total_size;
3837ec681f3Smrg
3847ec681f3Smrg   union {
3857ec681f3Smrg      /* Return values for GFX8 and older.
3867ec681f3Smrg       *
3877ec681f3Smrg       * Some of them can be set by the caller if certain parameters are
3887ec681f3Smrg       * desirable. The allocator will try to obey them.
3897ec681f3Smrg       */
3907ec681f3Smrg      struct legacy_surf_layout legacy;
3917ec681f3Smrg
3927ec681f3Smrg      /* GFX9+ return values. */
3937ec681f3Smrg      struct gfx9_surf_layout gfx9;
3947ec681f3Smrg   } u;
39501e04c3fSmrg};
39601e04c3fSmrg
39701e04c3fSmrgstruct ac_surf_info {
3987ec681f3Smrg   uint32_t width;
3997ec681f3Smrg   uint32_t height;
4007ec681f3Smrg   uint32_t depth;
4017ec681f3Smrg   uint8_t samples;         /* For Z/S: samples; For color: FMASK coverage samples */
4027ec681f3Smrg   uint8_t storage_samples; /* For color: allocated samples */
4037ec681f3Smrg   uint8_t levels;
4047ec681f3Smrg   uint8_t num_channels; /* heuristic for displayability */
4057ec681f3Smrg   uint16_t array_size;
4067ec681f3Smrg   uint32_t *surf_index; /* Set a monotonic counter for tile swizzling. */
4077ec681f3Smrg   uint32_t *fmask_surf_index;
40801e04c3fSmrg};
40901e04c3fSmrg
41001e04c3fSmrgstruct ac_surf_config {
4117ec681f3Smrg   struct ac_surf_info info;
4127ec681f3Smrg   unsigned is_1d : 1;
4137ec681f3Smrg   unsigned is_3d : 1;
4147ec681f3Smrg   unsigned is_cube : 1;
41501e04c3fSmrg};
41601e04c3fSmrg
4177ec681f3Smrgstruct ac_addrlib *ac_addrlib_create(const struct radeon_info *info, uint64_t *max_alignment);
4187ec681f3Smrgvoid ac_addrlib_destroy(struct ac_addrlib *addrlib);
4197ec681f3Smrgvoid *ac_addrlib_get_handle(struct ac_addrlib *addrlib);
4207ec681f3Smrg
4217ec681f3Smrgint ac_compute_surface(struct ac_addrlib *addrlib, const struct radeon_info *info,
4227ec681f3Smrg                       const struct ac_surf_config *config, enum radeon_surf_mode mode,
4237ec681f3Smrg                       struct radeon_surf *surf);
4247ec681f3Smrgvoid ac_surface_zero_dcc_fields(struct radeon_surf *surf);
4257ec681f3Smrg
4267ec681f3Smrgvoid ac_surface_set_bo_metadata(const struct radeon_info *info, struct radeon_surf *surf,
4277ec681f3Smrg                                uint64_t tiling_flags, enum radeon_surf_mode *mode);
4287ec681f3Smrgvoid ac_surface_get_bo_metadata(const struct radeon_info *info, struct radeon_surf *surf,
4297ec681f3Smrg                                uint64_t *tiling_flags);
4307ec681f3Smrg
4317ec681f3Smrgbool ac_surface_set_umd_metadata(const struct radeon_info *info, struct radeon_surf *surf,
4327ec681f3Smrg                                 unsigned num_storage_samples, unsigned num_mipmap_levels,
4337ec681f3Smrg                                 unsigned size_metadata, const uint32_t metadata[64]);
4347ec681f3Smrgvoid ac_surface_get_umd_metadata(const struct radeon_info *info, struct radeon_surf *surf,
4357ec681f3Smrg                                 unsigned num_mipmap_levels, uint32_t desc[8],
4367ec681f3Smrg                                 unsigned *size_metadata, uint32_t metadata[64]);
4377ec681f3Smrg
4387ec681f3Smrgbool ac_surface_override_offset_stride(const struct radeon_info *info, struct radeon_surf *surf,
4397ec681f3Smrg                                       unsigned num_mipmap_levels, uint64_t offset, unsigned pitch);
4407ec681f3Smrg
4417ec681f3Smrgstruct ac_modifier_options {
4427ec681f3Smrg	bool dcc; /* Whether to allow DCC. */
4437ec681f3Smrg	bool dcc_retile; /* Whether to allow use of a DCC retile map. */
4447ec681f3Smrg};
44501e04c3fSmrg
4467ec681f3Smrgbool ac_is_modifier_supported(const struct radeon_info *info,
4477ec681f3Smrg                              const struct ac_modifier_options *options,
4487ec681f3Smrg                              enum pipe_format format,
4497ec681f3Smrg                              uint64_t modifier);
4507ec681f3Smrgbool ac_get_supported_modifiers(const struct radeon_info *info,
4517ec681f3Smrg                                const struct ac_modifier_options *options,
4527ec681f3Smrg                                enum pipe_format format,
4537ec681f3Smrg                                unsigned *mod_count,
4547ec681f3Smrg                                uint64_t *mods);
4557ec681f3Smrgbool ac_modifier_has_dcc(uint64_t modifier);
4567ec681f3Smrgbool ac_modifier_has_dcc_retile(uint64_t modifier);
4577ec681f3Smrgbool ac_modifier_supports_dcc_image_stores(uint64_t modifier);
4587ec681f3Smrgvoid ac_modifier_max_extent(const struct radeon_info *info,
4597ec681f3Smrg                            uint64_t modifier, uint32_t *width, uint32_t *height);
4607ec681f3Smrg
4617ec681f3Smrgunsigned ac_surface_get_nplanes(const struct radeon_surf *surf);
4627ec681f3Smrguint64_t ac_surface_get_plane_offset(enum chip_class chip_class,
4637ec681f3Smrg                                     const struct radeon_surf *surf,
4647ec681f3Smrg                                     unsigned plane, unsigned layer);
4657ec681f3Smrguint64_t ac_surface_get_plane_stride(enum chip_class chip_class,
4667ec681f3Smrg                                     const struct radeon_surf *surf,
4677ec681f3Smrg                                     unsigned plane);
4687ec681f3Smrg/* Of the whole miplevel, not an individual layer */
4697ec681f3Smrguint64_t ac_surface_get_plane_size(const struct radeon_surf *surf,
4707ec681f3Smrg                                   unsigned plane);
4717ec681f3Smrg
4727ec681f3Smrgvoid ac_surface_print_info(FILE *out, const struct radeon_info *info,
4737ec681f3Smrg                           const struct radeon_surf *surf);
4747ec681f3Smrg
4757ec681f3Smrgbool ac_surface_supports_dcc_image_stores(enum chip_class chip_class,
4767ec681f3Smrg                                          const struct radeon_surf *surf);
4777ec681f3Smrg
4787ec681f3Smrg#ifdef AC_SURFACE_INCLUDE_NIR
4797ec681f3Smrgnir_ssa_def *ac_nir_dcc_addr_from_coord(nir_builder *b, const struct radeon_info *info,
4807ec681f3Smrg                                        unsigned bpe, struct gfx9_meta_equation *equation,
4817ec681f3Smrg                                        nir_ssa_def *dcc_pitch, nir_ssa_def *dcc_height,
4827ec681f3Smrg                                        nir_ssa_def *dcc_slice_size,
4837ec681f3Smrg                                        nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *z,
4847ec681f3Smrg                                        nir_ssa_def *sample, nir_ssa_def *pipe_xor);
4857ec681f3Smrg
4867ec681f3Smrgnir_ssa_def *ac_nir_cmask_addr_from_coord(nir_builder *b, const struct radeon_info *info,
4877ec681f3Smrg                                        struct gfx9_meta_equation *equation,
4887ec681f3Smrg                                        nir_ssa_def *cmask_pitch, nir_ssa_def *cmask_height,
4897ec681f3Smrg                                        nir_ssa_def *cmask_slice_size,
4907ec681f3Smrg                                        nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *z,
4917ec681f3Smrg                                        nir_ssa_def *pipe_xor,
4927ec681f3Smrg                                        nir_ssa_def **bit_position);
4937ec681f3Smrg
4947ec681f3Smrgnir_ssa_def *ac_nir_htile_addr_from_coord(nir_builder *b, const struct radeon_info *info,
4957ec681f3Smrg                                          struct gfx9_meta_equation *equation,
4967ec681f3Smrg                                          nir_ssa_def *htile_pitch,
4977ec681f3Smrg                                          nir_ssa_def *htile_slice_size,
4987ec681f3Smrg                                          nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *z,
4997ec681f3Smrg                                          nir_ssa_def *pipe_xor);
5007ec681f3Smrg#endif
50101e04c3fSmrg
50201e04c3fSmrg#ifdef __cplusplus
50301e04c3fSmrg}
50401e04c3fSmrg#endif
50501e04c3fSmrg
50601e04c3fSmrg#endif /* AC_SURFACE_H */
507