2 * Copyright © 2011 Red Hat All Rights Reserved.
3 * Copyright © 2017 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
18 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
28 #include "ac_surface.h"
29 #include "amd_family.h"
30 #include "addrlib/src/amdgpu_asic_addr.h"
31 #include "ac_gpu_info.h"
32 #include "util/macros.h"
33 #include "util/u_atomic.h"
34 #include "util/u_math.h"
41 #include "drm-uapi/amdgpu_drm.h"
43 #include "addrlib/inc/addrinterface.h"
45 #ifndef CIASICIDGFXENGINE_SOUTHERNISLAND
46 #define CIASICIDGFXENGINE_SOUTHERNISLAND 0x0000000A
49 #ifndef CIASICIDGFXENGINE_ARCTICISLAND
50 #define CIASICIDGFXENGINE_ARCTICISLAND 0x0000000D
53 static void *ADDR_API
allocSysMem(const ADDR_ALLOCSYSMEM_INPUT
* pInput
)
55 return malloc(pInput
->sizeInBytes
);
58 static ADDR_E_RETURNCODE ADDR_API
freeSysMem(const ADDR_FREESYSMEM_INPUT
* pInput
)
60 free(pInput
->pVirtAddr
);
64 ADDR_HANDLE
amdgpu_addr_create(const struct radeon_info
*info
,
65 const struct amdgpu_gpu_info
*amdinfo
,
66 uint64_t *max_alignment
)
68 ADDR_CREATE_INPUT addrCreateInput
= {0};
69 ADDR_CREATE_OUTPUT addrCreateOutput
= {0};
70 ADDR_REGISTER_VALUE regValue
= {0};
71 ADDR_CREATE_FLAGS createFlags
= {{0}};
72 ADDR_GET_MAX_ALIGNMENTS_OUTPUT addrGetMaxAlignmentsOutput
= {0};
73 ADDR_E_RETURNCODE addrRet
;
75 addrCreateInput
.size
= sizeof(ADDR_CREATE_INPUT
);
76 addrCreateOutput
.size
= sizeof(ADDR_CREATE_OUTPUT
);
78 regValue
.gbAddrConfig
= amdinfo
->gb_addr_cfg
;
79 createFlags
.value
= 0;
81 addrCreateInput
.chipFamily
= info
->family_id
;
82 addrCreateInput
.chipRevision
= info
->chip_external_rev
;
84 if (addrCreateInput
.chipFamily
== FAMILY_UNKNOWN
)
87 if (addrCreateInput
.chipFamily
>= FAMILY_AI
) {
88 addrCreateInput
.chipEngine
= CIASICIDGFXENGINE_ARCTICISLAND
;
90 regValue
.noOfBanks
= amdinfo
->mc_arb_ramcfg
& 0x3;
91 regValue
.noOfRanks
= (amdinfo
->mc_arb_ramcfg
& 0x4) >> 2;
93 regValue
.backendDisables
= amdinfo
->enabled_rb_pipes_mask
;
94 regValue
.pTileConfig
= amdinfo
->gb_tile_mode
;
95 regValue
.noOfEntries
= ARRAY_SIZE(amdinfo
->gb_tile_mode
);
96 if (addrCreateInput
.chipFamily
== FAMILY_SI
) {
97 regValue
.pMacroTileConfig
= NULL
;
98 regValue
.noOfMacroEntries
= 0;
100 regValue
.pMacroTileConfig
= amdinfo
->gb_macro_tile_mode
;
101 regValue
.noOfMacroEntries
= ARRAY_SIZE(amdinfo
->gb_macro_tile_mode
);
104 createFlags
.useTileIndex
= 1;
105 createFlags
.useHtileSliceAlign
= 1;
107 addrCreateInput
.chipEngine
= CIASICIDGFXENGINE_SOUTHERNISLAND
;
110 addrCreateInput
.callbacks
.allocSysMem
= allocSysMem
;
111 addrCreateInput
.callbacks
.freeSysMem
= freeSysMem
;
112 addrCreateInput
.callbacks
.debugPrint
= 0;
113 addrCreateInput
.createFlags
= createFlags
;
114 addrCreateInput
.regValue
= regValue
;
116 addrRet
= AddrCreate(&addrCreateInput
, &addrCreateOutput
);
117 if (addrRet
!= ADDR_OK
)
121 addrRet
= AddrGetMaxAlignments(addrCreateOutput
.hLib
, &addrGetMaxAlignmentsOutput
);
122 if (addrRet
== ADDR_OK
){
123 *max_alignment
= addrGetMaxAlignmentsOutput
.baseAlign
;
126 return addrCreateOutput
.hLib
;
129 static int surf_config_sanity(const struct ac_surf_config
*config
,
132 /* FMASK is allocated together with the color surface and can't be
133 * allocated separately.
135 assert(!(flags
& RADEON_SURF_FMASK
));
136 if (flags
& RADEON_SURF_FMASK
)
139 /* all dimension must be at least 1 ! */
140 if (!config
->info
.width
|| !config
->info
.height
|| !config
->info
.depth
||
141 !config
->info
.array_size
|| !config
->info
.levels
)
144 switch (config
->info
.samples
) {
152 if (flags
& RADEON_SURF_Z_OR_SBUFFER
)
159 if (!(flags
& RADEON_SURF_Z_OR_SBUFFER
)) {
160 switch (config
->info
.storage_samples
) {
172 if (config
->is_3d
&& config
->info
.array_size
> 1)
174 if (config
->is_cube
&& config
->info
.depth
> 1)
180 static int gfx6_compute_level(ADDR_HANDLE addrlib
,
181 const struct ac_surf_config
*config
,
182 struct radeon_surf
*surf
, bool is_stencil
,
183 unsigned level
, bool compressed
,
184 ADDR_COMPUTE_SURFACE_INFO_INPUT
*AddrSurfInfoIn
,
185 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
*AddrSurfInfoOut
,
186 ADDR_COMPUTE_DCCINFO_INPUT
*AddrDccIn
,
187 ADDR_COMPUTE_DCCINFO_OUTPUT
*AddrDccOut
,
188 ADDR_COMPUTE_HTILE_INFO_INPUT
*AddrHtileIn
,
189 ADDR_COMPUTE_HTILE_INFO_OUTPUT
*AddrHtileOut
)
191 struct legacy_surf_level
*surf_level
;
192 ADDR_E_RETURNCODE ret
;
194 AddrSurfInfoIn
->mipLevel
= level
;
195 AddrSurfInfoIn
->width
= u_minify(config
->info
.width
, level
);
196 AddrSurfInfoIn
->height
= u_minify(config
->info
.height
, level
);
198 /* Make GFX6 linear surfaces compatible with GFX9 for hybrid graphics,
199 * because GFX9 needs linear alignment of 256 bytes.
201 if (config
->info
.levels
== 1 &&
202 AddrSurfInfoIn
->tileMode
== ADDR_TM_LINEAR_ALIGNED
&&
203 AddrSurfInfoIn
->bpp
&&
204 util_is_power_of_two_or_zero(AddrSurfInfoIn
->bpp
)) {
205 unsigned alignment
= 256 / (AddrSurfInfoIn
->bpp
/ 8);
207 AddrSurfInfoIn
->width
= align(AddrSurfInfoIn
->width
, alignment
);
210 /* addrlib assumes the bytes/pixel is a divisor of 64, which is not
211 * true for r32g32b32 formats. */
212 if (AddrSurfInfoIn
->bpp
== 96) {
213 assert(config
->info
.levels
== 1);
214 assert(AddrSurfInfoIn
->tileMode
== ADDR_TM_LINEAR_ALIGNED
);
216 /* The least common multiple of 64 bytes and 12 bytes/pixel is
217 * 192 bytes, or 16 pixels. */
218 AddrSurfInfoIn
->width
= align(AddrSurfInfoIn
->width
, 16);
222 AddrSurfInfoIn
->numSlices
= u_minify(config
->info
.depth
, level
);
223 else if (config
->is_cube
)
224 AddrSurfInfoIn
->numSlices
= 6;
226 AddrSurfInfoIn
->numSlices
= config
->info
.array_size
;
229 /* Set the base level pitch. This is needed for calculation
230 * of non-zero levels. */
232 AddrSurfInfoIn
->basePitch
= surf
->u
.legacy
.stencil_level
[0].nblk_x
;
234 AddrSurfInfoIn
->basePitch
= surf
->u
.legacy
.level
[0].nblk_x
;
236 /* Convert blocks to pixels for compressed formats. */
238 AddrSurfInfoIn
->basePitch
*= surf
->blk_w
;
241 ret
= AddrComputeSurfaceInfo(addrlib
,
244 if (ret
!= ADDR_OK
) {
248 surf_level
= is_stencil
? &surf
->u
.legacy
.stencil_level
[level
] : &surf
->u
.legacy
.level
[level
];
249 surf_level
->offset
= align64(surf
->surf_size
, AddrSurfInfoOut
->baseAlign
);
250 surf_level
->slice_size_dw
= AddrSurfInfoOut
->sliceSize
/ 4;
251 surf_level
->nblk_x
= AddrSurfInfoOut
->pitch
;
252 surf_level
->nblk_y
= AddrSurfInfoOut
->height
;
254 switch (AddrSurfInfoOut
->tileMode
) {
255 case ADDR_TM_LINEAR_ALIGNED
:
256 surf_level
->mode
= RADEON_SURF_MODE_LINEAR_ALIGNED
;
258 case ADDR_TM_1D_TILED_THIN1
:
259 surf_level
->mode
= RADEON_SURF_MODE_1D
;
261 case ADDR_TM_2D_TILED_THIN1
:
262 surf_level
->mode
= RADEON_SURF_MODE_2D
;
269 surf
->u
.legacy
.stencil_tiling_index
[level
] = AddrSurfInfoOut
->tileIndex
;
271 surf
->u
.legacy
.tiling_index
[level
] = AddrSurfInfoOut
->tileIndex
;
273 surf
->surf_size
= surf_level
->offset
+ AddrSurfInfoOut
->surfSize
;
275 /* Clear DCC fields at the beginning. */
276 surf_level
->dcc_offset
= 0;
278 /* The previous level's flag tells us if we can use DCC for this level. */
279 if (AddrSurfInfoIn
->flags
.dccCompatible
&&
280 (level
== 0 || AddrDccOut
->subLvlCompressible
)) {
281 bool prev_level_clearable
= level
== 0 ||
282 AddrDccOut
->dccRamSizeAligned
;
284 AddrDccIn
->colorSurfSize
= AddrSurfInfoOut
->surfSize
;
285 AddrDccIn
->tileMode
= AddrSurfInfoOut
->tileMode
;
286 AddrDccIn
->tileInfo
= *AddrSurfInfoOut
->pTileInfo
;
287 AddrDccIn
->tileIndex
= AddrSurfInfoOut
->tileIndex
;
288 AddrDccIn
->macroModeIndex
= AddrSurfInfoOut
->macroModeIndex
;
290 ret
= AddrComputeDccInfo(addrlib
,
294 if (ret
== ADDR_OK
) {
295 surf_level
->dcc_offset
= surf
->dcc_size
;
296 surf
->num_dcc_levels
= level
+ 1;
297 surf
->dcc_size
= surf_level
->dcc_offset
+ AddrDccOut
->dccRamSize
;
298 surf
->dcc_alignment
= MAX2(surf
->dcc_alignment
, AddrDccOut
->dccRamBaseAlign
);
300 /* If the DCC size of a subresource (1 mip level or 1 slice)
301 * is not aligned, the DCC memory layout is not contiguous for
302 * that subresource, which means we can't use fast clear.
304 * We only do fast clears for whole mipmap levels. If we did
305 * per-slice fast clears, the same restriction would apply.
306 * (i.e. only compute the slice size and see if it's aligned)
308 * The last level can be non-contiguous and still be clearable
309 * if it's interleaved with the next level that doesn't exist.
311 if (AddrDccOut
->dccRamSizeAligned
||
312 (prev_level_clearable
&& level
== config
->info
.levels
- 1))
313 surf_level
->dcc_fast_clear_size
= AddrDccOut
->dccFastClearSize
;
315 surf_level
->dcc_fast_clear_size
= 0;
317 /* Compute the DCC slice size because addrlib doesn't
318 * provide this info. As DCC memory is linear (each
319 * slice is the same size) it's easy to compute.
321 surf
->dcc_slice_size
= AddrDccOut
->dccRamSize
/ config
->info
.array_size
;
323 /* For arrays, we have to compute the DCC info again
324 * with one slice size to get a correct fast clear
327 if (config
->info
.array_size
> 1) {
328 AddrDccIn
->colorSurfSize
= AddrSurfInfoOut
->sliceSize
;
329 AddrDccIn
->tileMode
= AddrSurfInfoOut
->tileMode
;
330 AddrDccIn
->tileInfo
= *AddrSurfInfoOut
->pTileInfo
;
331 AddrDccIn
->tileIndex
= AddrSurfInfoOut
->tileIndex
;
332 AddrDccIn
->macroModeIndex
= AddrSurfInfoOut
->macroModeIndex
;
334 ret
= AddrComputeDccInfo(addrlib
,
335 AddrDccIn
, AddrDccOut
);
336 if (ret
== ADDR_OK
) {
337 /* If the DCC memory isn't properly
338 * aligned, the data are interleaved
341 if (AddrDccOut
->dccRamSizeAligned
)
342 surf_level
->dcc_slice_fast_clear_size
= AddrDccOut
->dccFastClearSize
;
344 surf_level
->dcc_slice_fast_clear_size
= 0;
347 surf_level
->dcc_slice_fast_clear_size
= surf_level
->dcc_fast_clear_size
;
354 AddrSurfInfoIn
->flags
.depth
&&
355 surf_level
->mode
== RADEON_SURF_MODE_2D
&&
357 !(surf
->flags
& RADEON_SURF_NO_HTILE
)) {
358 AddrHtileIn
->flags
.tcCompatible
= AddrSurfInfoOut
->tcCompatible
;
359 AddrHtileIn
->pitch
= AddrSurfInfoOut
->pitch
;
360 AddrHtileIn
->height
= AddrSurfInfoOut
->height
;
361 AddrHtileIn
->numSlices
= AddrSurfInfoOut
->depth
;
362 AddrHtileIn
->blockWidth
= ADDR_HTILE_BLOCKSIZE_8
;
363 AddrHtileIn
->blockHeight
= ADDR_HTILE_BLOCKSIZE_8
;
364 AddrHtileIn
->pTileInfo
= AddrSurfInfoOut
->pTileInfo
;
365 AddrHtileIn
->tileIndex
= AddrSurfInfoOut
->tileIndex
;
366 AddrHtileIn
->macroModeIndex
= AddrSurfInfoOut
->macroModeIndex
;
368 ret
= AddrComputeHtileInfo(addrlib
,
372 if (ret
== ADDR_OK
) {
373 surf
->htile_size
= AddrHtileOut
->htileBytes
;
374 surf
->htile_slice_size
= AddrHtileOut
->sliceSize
;
375 surf
->htile_alignment
= AddrHtileOut
->baseAlign
;
382 static void gfx6_set_micro_tile_mode(struct radeon_surf
*surf
,
383 const struct radeon_info
*info
)
385 uint32_t tile_mode
= info
->si_tile_mode_array
[surf
->u
.legacy
.tiling_index
[0]];
387 if (info
->chip_class
>= GFX7
)
388 surf
->micro_tile_mode
= G_009910_MICRO_TILE_MODE_NEW(tile_mode
);
390 surf
->micro_tile_mode
= G_009910_MICRO_TILE_MODE(tile_mode
);
393 static unsigned cik_get_macro_tile_index(struct radeon_surf
*surf
)
395 unsigned index
, tileb
;
397 tileb
= 8 * 8 * surf
->bpe
;
398 tileb
= MIN2(surf
->u
.legacy
.tile_split
, tileb
);
400 for (index
= 0; tileb
> 64; index
++)
407 static bool get_display_flag(const struct ac_surf_config
*config
,
408 const struct radeon_surf
*surf
)
410 unsigned num_channels
= config
->info
.num_channels
;
411 unsigned bpe
= surf
->bpe
;
413 if (!config
->is_3d
&&
415 !(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
) &&
416 surf
->flags
& RADEON_SURF_SCANOUT
&&
417 config
->info
.samples
<= 1 &&
418 surf
->blk_w
<= 2 && surf
->blk_h
== 1) {
420 if (surf
->blk_w
== 2 && surf
->blk_h
== 1)
423 if (/* RGBA8 or RGBA16F */
424 (bpe
>= 4 && bpe
<= 8 && num_channels
== 4) ||
425 /* R5G6B5 or R5G5B5A1 */
426 (bpe
== 2 && num_channels
>= 3) ||
428 (bpe
== 1 && num_channels
== 1))
435 * This must be called after the first level is computed.
437 * Copy surface-global settings like pipe/bank config from level 0 surface
438 * computation, and compute tile swizzle.
440 static int gfx6_surface_settings(ADDR_HANDLE addrlib
,
441 const struct radeon_info
*info
,
442 const struct ac_surf_config
*config
,
443 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* csio
,
444 struct radeon_surf
*surf
)
446 surf
->surf_alignment
= csio
->baseAlign
;
447 surf
->u
.legacy
.pipe_config
= csio
->pTileInfo
->pipeConfig
- 1;
448 gfx6_set_micro_tile_mode(surf
, info
);
450 /* For 2D modes only. */
451 if (csio
->tileMode
>= ADDR_TM_2D_TILED_THIN1
) {
452 surf
->u
.legacy
.bankw
= csio
->pTileInfo
->bankWidth
;
453 surf
->u
.legacy
.bankh
= csio
->pTileInfo
->bankHeight
;
454 surf
->u
.legacy
.mtilea
= csio
->pTileInfo
->macroAspectRatio
;
455 surf
->u
.legacy
.tile_split
= csio
->pTileInfo
->tileSplitBytes
;
456 surf
->u
.legacy
.num_banks
= csio
->pTileInfo
->banks
;
457 surf
->u
.legacy
.macro_tile_index
= csio
->macroModeIndex
;
459 surf
->u
.legacy
.macro_tile_index
= 0;
462 /* Compute tile swizzle. */
463 /* TODO: fix tile swizzle with mipmapping for GFX6 */
464 if ((info
->chip_class
>= GFX7
|| config
->info
.levels
== 1) &&
465 config
->info
.surf_index
&&
466 surf
->u
.legacy
.level
[0].mode
== RADEON_SURF_MODE_2D
&&
467 !(surf
->flags
& (RADEON_SURF_Z_OR_SBUFFER
| RADEON_SURF_SHAREABLE
)) &&
468 !get_display_flag(config
, surf
)) {
469 ADDR_COMPUTE_BASE_SWIZZLE_INPUT AddrBaseSwizzleIn
= {0};
470 ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT AddrBaseSwizzleOut
= {0};
472 AddrBaseSwizzleIn
.size
= sizeof(ADDR_COMPUTE_BASE_SWIZZLE_INPUT
);
473 AddrBaseSwizzleOut
.size
= sizeof(ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT
);
475 AddrBaseSwizzleIn
.surfIndex
= p_atomic_inc_return(config
->info
.surf_index
) - 1;
476 AddrBaseSwizzleIn
.tileIndex
= csio
->tileIndex
;
477 AddrBaseSwizzleIn
.macroModeIndex
= csio
->macroModeIndex
;
478 AddrBaseSwizzleIn
.pTileInfo
= csio
->pTileInfo
;
479 AddrBaseSwizzleIn
.tileMode
= csio
->tileMode
;
481 int r
= AddrComputeBaseSwizzle(addrlib
, &AddrBaseSwizzleIn
,
482 &AddrBaseSwizzleOut
);
486 assert(AddrBaseSwizzleOut
.tileSwizzle
<=
487 u_bit_consecutive(0, sizeof(surf
->tile_swizzle
) * 8));
488 surf
->tile_swizzle
= AddrBaseSwizzleOut
.tileSwizzle
;
493 static void ac_compute_cmask(const struct radeon_info
*info
,
494 const struct ac_surf_config
*config
,
495 struct radeon_surf
*surf
)
497 unsigned pipe_interleave_bytes
= info
->pipe_interleave_bytes
;
498 unsigned num_pipes
= info
->num_tile_pipes
;
499 unsigned cl_width
, cl_height
;
501 if (surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
||
502 (config
->info
.samples
>= 2 && !surf
->fmask_size
))
505 assert(info
->chip_class
<= GFX8
);
520 case 16: /* Hawaii */
529 unsigned base_align
= num_pipes
* pipe_interleave_bytes
;
531 unsigned width
= align(surf
->u
.legacy
.level
[0].nblk_x
, cl_width
*8);
532 unsigned height
= align(surf
->u
.legacy
.level
[0].nblk_y
, cl_height
*8);
533 unsigned slice_elements
= (width
* height
) / (8*8);
535 /* Each element of CMASK is a nibble. */
536 unsigned slice_bytes
= slice_elements
/ 2;
538 surf
->u
.legacy
.cmask_slice_tile_max
= (width
* height
) / (128*128);
539 if (surf
->u
.legacy
.cmask_slice_tile_max
)
540 surf
->u
.legacy
.cmask_slice_tile_max
-= 1;
544 num_layers
= config
->info
.depth
;
545 else if (config
->is_cube
)
548 num_layers
= config
->info
.array_size
;
550 surf
->cmask_alignment
= MAX2(256, base_align
);
551 surf
->cmask_slice_size
= align(slice_bytes
, base_align
);
552 surf
->cmask_size
= surf
->cmask_slice_size
* num_layers
;
556 * Fill in the tiling information in \p surf based on the given surface config.
558 * The following fields of \p surf must be initialized by the caller:
559 * blk_w, blk_h, bpe, flags.
561 static int gfx6_compute_surface(ADDR_HANDLE addrlib
,
562 const struct radeon_info
*info
,
563 const struct ac_surf_config
*config
,
564 enum radeon_surf_mode mode
,
565 struct radeon_surf
*surf
)
569 ADDR_COMPUTE_SURFACE_INFO_INPUT AddrSurfInfoIn
= {0};
570 ADDR_COMPUTE_SURFACE_INFO_OUTPUT AddrSurfInfoOut
= {0};
571 ADDR_COMPUTE_DCCINFO_INPUT AddrDccIn
= {0};
572 ADDR_COMPUTE_DCCINFO_OUTPUT AddrDccOut
= {0};
573 ADDR_COMPUTE_HTILE_INFO_INPUT AddrHtileIn
= {0};
574 ADDR_COMPUTE_HTILE_INFO_OUTPUT AddrHtileOut
= {0};
575 ADDR_TILEINFO AddrTileInfoIn
= {0};
576 ADDR_TILEINFO AddrTileInfoOut
= {0};
579 AddrSurfInfoIn
.size
= sizeof(ADDR_COMPUTE_SURFACE_INFO_INPUT
);
580 AddrSurfInfoOut
.size
= sizeof(ADDR_COMPUTE_SURFACE_INFO_OUTPUT
);
581 AddrDccIn
.size
= sizeof(ADDR_COMPUTE_DCCINFO_INPUT
);
582 AddrDccOut
.size
= sizeof(ADDR_COMPUTE_DCCINFO_OUTPUT
);
583 AddrHtileIn
.size
= sizeof(ADDR_COMPUTE_HTILE_INFO_INPUT
);
584 AddrHtileOut
.size
= sizeof(ADDR_COMPUTE_HTILE_INFO_OUTPUT
);
585 AddrSurfInfoOut
.pTileInfo
= &AddrTileInfoOut
;
587 compressed
= surf
->blk_w
== 4 && surf
->blk_h
== 4;
589 /* MSAA requires 2D tiling. */
590 if (config
->info
.samples
> 1)
591 mode
= RADEON_SURF_MODE_2D
;
593 /* DB doesn't support linear layouts. */
594 if (surf
->flags
& (RADEON_SURF_Z_OR_SBUFFER
) &&
595 mode
< RADEON_SURF_MODE_1D
)
596 mode
= RADEON_SURF_MODE_1D
;
598 /* Set the requested tiling mode. */
600 case RADEON_SURF_MODE_LINEAR_ALIGNED
:
601 AddrSurfInfoIn
.tileMode
= ADDR_TM_LINEAR_ALIGNED
;
603 case RADEON_SURF_MODE_1D
:
604 AddrSurfInfoIn
.tileMode
= ADDR_TM_1D_TILED_THIN1
;
606 case RADEON_SURF_MODE_2D
:
607 AddrSurfInfoIn
.tileMode
= ADDR_TM_2D_TILED_THIN1
;
613 /* The format must be set correctly for the allocation of compressed
614 * textures to work. In other cases, setting the bpp is sufficient.
619 AddrSurfInfoIn
.format
= ADDR_FMT_BC1
;
622 AddrSurfInfoIn
.format
= ADDR_FMT_BC3
;
629 AddrDccIn
.bpp
= AddrSurfInfoIn
.bpp
= surf
->bpe
* 8;
632 AddrDccIn
.numSamples
= AddrSurfInfoIn
.numSamples
=
633 MAX2(1, config
->info
.samples
);
634 AddrSurfInfoIn
.tileIndex
= -1;
636 if (!(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
)) {
637 AddrDccIn
.numSamples
= AddrSurfInfoIn
.numFrags
=
638 MAX2(1, config
->info
.storage_samples
);
641 /* Set the micro tile type. */
642 if (surf
->flags
& RADEON_SURF_SCANOUT
)
643 AddrSurfInfoIn
.tileType
= ADDR_DISPLAYABLE
;
644 else if (surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
)
645 AddrSurfInfoIn
.tileType
= ADDR_DEPTH_SAMPLE_ORDER
;
647 AddrSurfInfoIn
.tileType
= ADDR_NON_DISPLAYABLE
;
649 AddrSurfInfoIn
.flags
.color
= !(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
);
650 AddrSurfInfoIn
.flags
.depth
= (surf
->flags
& RADEON_SURF_ZBUFFER
) != 0;
651 AddrSurfInfoIn
.flags
.cube
= config
->is_cube
;
652 AddrSurfInfoIn
.flags
.display
= get_display_flag(config
, surf
);
653 AddrSurfInfoIn
.flags
.pow2Pad
= config
->info
.levels
> 1;
654 AddrSurfInfoIn
.flags
.tcCompatible
= (surf
->flags
& RADEON_SURF_TC_COMPATIBLE_HTILE
) != 0;
656 /* Only degrade the tile mode for space if TC-compatible HTILE hasn't been
657 * requested, because TC-compatible HTILE requires 2D tiling.
659 AddrSurfInfoIn
.flags
.opt4Space
= !AddrSurfInfoIn
.flags
.tcCompatible
&&
660 !AddrSurfInfoIn
.flags
.fmask
&&
661 config
->info
.samples
<= 1 &&
662 !(surf
->flags
& RADEON_SURF_FORCE_SWIZZLE_MODE
);
665 * - If we add MSAA support, keep in mind that CB can't decompress 8bpp
667 * - Mipmapped array textures have low performance (discovered by a closed
670 AddrSurfInfoIn
.flags
.dccCompatible
=
671 info
->chip_class
>= GFX8
&&
672 info
->has_graphics
&& /* disable DCC on compute-only chips */
673 !(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
) &&
674 !(surf
->flags
& RADEON_SURF_DISABLE_DCC
) &&
676 ((config
->info
.array_size
== 1 && config
->info
.depth
== 1) ||
677 config
->info
.levels
== 1);
679 AddrSurfInfoIn
.flags
.noStencil
= (surf
->flags
& RADEON_SURF_SBUFFER
) == 0;
680 AddrSurfInfoIn
.flags
.compressZ
= !!(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
);
682 /* On GFX7-GFX8, the DB uses the same pitch and tile mode (except tilesplit)
683 * for Z and stencil. This can cause a number of problems which we work
686 * - a depth part that is incompatible with mipmapped texturing
687 * - at least on Stoney, entirely incompatible Z/S aspects (e.g.
688 * incorrect tiling applied to the stencil part, stencil buffer
689 * memory accesses that go out of bounds) even without mipmapping
691 * Some piglit tests that are prone to different types of related
693 * ./bin/ext_framebuffer_multisample-upsample 2 stencil
694 * ./bin/framebuffer-blit-levels {draw,read} stencil
695 * ./bin/ext_framebuffer_multisample-unaligned-blit N {depth,stencil} {msaa,upsample,downsample}
696 * ./bin/fbo-depth-array fs-writes-{depth,stencil} / {depth,stencil}-{clear,layered-clear,draw}
697 * ./bin/depthstencil-render-miplevels 1024 d=s=z24_s8
699 int stencil_tile_idx
= -1;
701 if (AddrSurfInfoIn
.flags
.depth
&& !AddrSurfInfoIn
.flags
.noStencil
&&
702 (config
->info
.levels
> 1 || info
->family
== CHIP_STONEY
)) {
703 /* Compute stencilTileIdx that is compatible with the (depth)
704 * tileIdx. This degrades the depth surface if necessary to
705 * ensure that a matching stencilTileIdx exists. */
706 AddrSurfInfoIn
.flags
.matchStencilTileCfg
= 1;
708 /* Keep the depth mip-tail compatible with texturing. */
709 AddrSurfInfoIn
.flags
.noStencil
= 1;
712 /* Set preferred macrotile parameters. This is usually required
713 * for shared resources. This is for 2D tiling only. */
714 if (AddrSurfInfoIn
.tileMode
>= ADDR_TM_2D_TILED_THIN1
&&
715 surf
->u
.legacy
.bankw
&& surf
->u
.legacy
.bankh
&&
716 surf
->u
.legacy
.mtilea
&& surf
->u
.legacy
.tile_split
) {
717 /* If any of these parameters are incorrect, the calculation
719 AddrTileInfoIn
.banks
= surf
->u
.legacy
.num_banks
;
720 AddrTileInfoIn
.bankWidth
= surf
->u
.legacy
.bankw
;
721 AddrTileInfoIn
.bankHeight
= surf
->u
.legacy
.bankh
;
722 AddrTileInfoIn
.macroAspectRatio
= surf
->u
.legacy
.mtilea
;
723 AddrTileInfoIn
.tileSplitBytes
= surf
->u
.legacy
.tile_split
;
724 AddrTileInfoIn
.pipeConfig
= surf
->u
.legacy
.pipe_config
+ 1; /* +1 compared to GB_TILE_MODE */
725 AddrSurfInfoIn
.flags
.opt4Space
= 0;
726 AddrSurfInfoIn
.pTileInfo
= &AddrTileInfoIn
;
728 /* If AddrSurfInfoIn.pTileInfo is set, Addrlib doesn't set
729 * the tile index, because we are expected to know it if
730 * we know the other parameters.
732 * This is something that can easily be fixed in Addrlib.
733 * For now, just figure it out here.
734 * Note that only 2D_TILE_THIN1 is handled here.
736 assert(!(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
));
737 assert(AddrSurfInfoIn
.tileMode
== ADDR_TM_2D_TILED_THIN1
);
739 if (info
->chip_class
== GFX6
) {
740 if (AddrSurfInfoIn
.tileType
== ADDR_DISPLAYABLE
) {
742 AddrSurfInfoIn
.tileIndex
= 11; /* 16bpp */
744 AddrSurfInfoIn
.tileIndex
= 12; /* 32bpp */
747 AddrSurfInfoIn
.tileIndex
= 14; /* 8bpp */
748 else if (surf
->bpe
== 2)
749 AddrSurfInfoIn
.tileIndex
= 15; /* 16bpp */
750 else if (surf
->bpe
== 4)
751 AddrSurfInfoIn
.tileIndex
= 16; /* 32bpp */
753 AddrSurfInfoIn
.tileIndex
= 17; /* 64bpp (and 128bpp) */
757 if (AddrSurfInfoIn
.tileType
== ADDR_DISPLAYABLE
)
758 AddrSurfInfoIn
.tileIndex
= 10; /* 2D displayable */
760 AddrSurfInfoIn
.tileIndex
= 14; /* 2D non-displayable */
762 /* Addrlib doesn't set this if tileIndex is forced like above. */
763 AddrSurfInfoOut
.macroModeIndex
= cik_get_macro_tile_index(surf
);
767 surf
->has_stencil
= !!(surf
->flags
& RADEON_SURF_SBUFFER
);
768 surf
->num_dcc_levels
= 0;
771 surf
->dcc_alignment
= 1;
772 surf
->htile_size
= 0;
773 surf
->htile_slice_size
= 0;
774 surf
->htile_alignment
= 1;
776 const bool only_stencil
= (surf
->flags
& RADEON_SURF_SBUFFER
) &&
777 !(surf
->flags
& RADEON_SURF_ZBUFFER
);
779 /* Calculate texture layout information. */
781 for (level
= 0; level
< config
->info
.levels
; level
++) {
782 r
= gfx6_compute_level(addrlib
, config
, surf
, false, level
, compressed
,
783 &AddrSurfInfoIn
, &AddrSurfInfoOut
,
784 &AddrDccIn
, &AddrDccOut
, &AddrHtileIn
, &AddrHtileOut
);
791 if (!AddrSurfInfoOut
.tcCompatible
) {
792 AddrSurfInfoIn
.flags
.tcCompatible
= 0;
793 surf
->flags
&= ~RADEON_SURF_TC_COMPATIBLE_HTILE
;
796 if (AddrSurfInfoIn
.flags
.matchStencilTileCfg
) {
797 AddrSurfInfoIn
.flags
.matchStencilTileCfg
= 0;
798 AddrSurfInfoIn
.tileIndex
= AddrSurfInfoOut
.tileIndex
;
799 stencil_tile_idx
= AddrSurfInfoOut
.stencilTileIdx
;
801 assert(stencil_tile_idx
>= 0);
804 r
= gfx6_surface_settings(addrlib
, info
, config
,
805 &AddrSurfInfoOut
, surf
);
811 /* Calculate texture layout information for stencil. */
812 if (surf
->flags
& RADEON_SURF_SBUFFER
) {
813 AddrSurfInfoIn
.tileIndex
= stencil_tile_idx
;
814 AddrSurfInfoIn
.bpp
= 8;
815 AddrSurfInfoIn
.flags
.depth
= 0;
816 AddrSurfInfoIn
.flags
.stencil
= 1;
817 AddrSurfInfoIn
.flags
.tcCompatible
= 0;
818 /* This will be ignored if AddrSurfInfoIn.pTileInfo is NULL. */
819 AddrTileInfoIn
.tileSplitBytes
= surf
->u
.legacy
.stencil_tile_split
;
821 for (level
= 0; level
< config
->info
.levels
; level
++) {
822 r
= gfx6_compute_level(addrlib
, config
, surf
, true, level
, compressed
,
823 &AddrSurfInfoIn
, &AddrSurfInfoOut
,
824 &AddrDccIn
, &AddrDccOut
,
829 /* DB uses the depth pitch for both stencil and depth. */
831 if (surf
->u
.legacy
.stencil_level
[level
].nblk_x
!=
832 surf
->u
.legacy
.level
[level
].nblk_x
)
833 surf
->u
.legacy
.stencil_adjusted
= true;
835 surf
->u
.legacy
.level
[level
].nblk_x
=
836 surf
->u
.legacy
.stencil_level
[level
].nblk_x
;
841 r
= gfx6_surface_settings(addrlib
, info
, config
,
842 &AddrSurfInfoOut
, surf
);
847 /* For 2D modes only. */
848 if (AddrSurfInfoOut
.tileMode
>= ADDR_TM_2D_TILED_THIN1
) {
849 surf
->u
.legacy
.stencil_tile_split
=
850 AddrSurfInfoOut
.pTileInfo
->tileSplitBytes
;
857 if (config
->info
.samples
>= 2 && AddrSurfInfoIn
.flags
.color
&&
858 info
->has_graphics
&& !(surf
->flags
& RADEON_SURF_NO_FMASK
)) {
859 ADDR_COMPUTE_FMASK_INFO_INPUT fin
= {0};
860 ADDR_COMPUTE_FMASK_INFO_OUTPUT fout
= {0};
861 ADDR_TILEINFO fmask_tile_info
= {};
863 fin
.size
= sizeof(fin
);
864 fout
.size
= sizeof(fout
);
866 fin
.tileMode
= AddrSurfInfoOut
.tileMode
;
867 fin
.pitch
= AddrSurfInfoOut
.pitch
;
868 fin
.height
= config
->info
.height
;
869 fin
.numSlices
= AddrSurfInfoIn
.numSlices
;
870 fin
.numSamples
= AddrSurfInfoIn
.numSamples
;
871 fin
.numFrags
= AddrSurfInfoIn
.numFrags
;
873 fout
.pTileInfo
= &fmask_tile_info
;
875 r
= AddrComputeFmaskInfo(addrlib
, &fin
, &fout
);
879 surf
->fmask_size
= fout
.fmaskBytes
;
880 surf
->fmask_alignment
= fout
.baseAlign
;
881 surf
->fmask_tile_swizzle
= 0;
883 surf
->u
.legacy
.fmask
.slice_tile_max
=
884 (fout
.pitch
* fout
.height
) / 64;
885 if (surf
->u
.legacy
.fmask
.slice_tile_max
)
886 surf
->u
.legacy
.fmask
.slice_tile_max
-= 1;
888 surf
->u
.legacy
.fmask
.tiling_index
= fout
.tileIndex
;
889 surf
->u
.legacy
.fmask
.bankh
= fout
.pTileInfo
->bankHeight
;
890 surf
->u
.legacy
.fmask
.pitch_in_pixels
= fout
.pitch
;
891 surf
->u
.legacy
.fmask
.slice_size
= fout
.sliceSize
;
893 /* Compute tile swizzle for FMASK. */
894 if (config
->info
.fmask_surf_index
&&
895 !(surf
->flags
& RADEON_SURF_SHAREABLE
)) {
896 ADDR_COMPUTE_BASE_SWIZZLE_INPUT xin
= {0};
897 ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT xout
= {0};
899 xin
.size
= sizeof(ADDR_COMPUTE_BASE_SWIZZLE_INPUT
);
900 xout
.size
= sizeof(ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT
);
902 /* This counter starts from 1 instead of 0. */
903 xin
.surfIndex
= p_atomic_inc_return(config
->info
.fmask_surf_index
);
904 xin
.tileIndex
= fout
.tileIndex
;
905 xin
.macroModeIndex
= fout
.macroModeIndex
;
906 xin
.pTileInfo
= fout
.pTileInfo
;
907 xin
.tileMode
= fin
.tileMode
;
909 int r
= AddrComputeBaseSwizzle(addrlib
, &xin
, &xout
);
913 assert(xout
.tileSwizzle
<=
914 u_bit_consecutive(0, sizeof(surf
->tile_swizzle
) * 8));
915 surf
->fmask_tile_swizzle
= xout
.tileSwizzle
;
919 /* Recalculate the whole DCC miptree size including disabled levels.
920 * This is what addrlib does, but calling addrlib would be a lot more
923 if (surf
->dcc_size
&& config
->info
.levels
> 1) {
924 /* The smallest miplevels that are never compressed by DCC
925 * still read the DCC buffer via TC if the base level uses DCC,
926 * and for some reason the DCC buffer needs to be larger if
927 * the miptree uses non-zero tile_swizzle. Otherwise there are
930 * "dcc_alignment * 4" was determined by trial and error.
932 surf
->dcc_size
= align64(surf
->surf_size
>> 8,
933 surf
->dcc_alignment
* 4);
936 /* Make sure HTILE covers the whole miptree, because the shader reads
937 * TC-compatible HTILE even for levels where it's disabled by DB.
939 if (surf
->htile_size
&& config
->info
.levels
> 1 &&
940 surf
->flags
& RADEON_SURF_TC_COMPATIBLE_HTILE
) {
941 /* MSAA can't occur with levels > 1, so ignore the sample count. */
942 const unsigned total_pixels
= surf
->surf_size
/ surf
->bpe
;
943 const unsigned htile_block_size
= 8 * 8;
944 const unsigned htile_element_size
= 4;
946 surf
->htile_size
= (total_pixels
/ htile_block_size
) *
948 surf
->htile_size
= align(surf
->htile_size
, surf
->htile_alignment
);
949 } else if (!surf
->htile_size
) {
950 /* Unset this if HTILE is not present. */
951 surf
->flags
&= ~RADEON_SURF_TC_COMPATIBLE_HTILE
;
954 surf
->is_linear
= surf
->u
.legacy
.level
[0].mode
== RADEON_SURF_MODE_LINEAR_ALIGNED
;
955 surf
->is_displayable
= surf
->is_linear
||
956 surf
->micro_tile_mode
== RADEON_MICRO_MODE_DISPLAY
||
957 surf
->micro_tile_mode
== RADEON_MICRO_MODE_RENDER
;
959 /* The rotated micro tile mode doesn't work if both CMASK and RB+ are
960 * used at the same time. This case is not currently expected to occur
961 * because we don't use rotated. Enforce this restriction on all chips
962 * to facilitate testing.
964 if (surf
->micro_tile_mode
== RADEON_MICRO_MODE_RENDER
) {
965 assert(!"rotate micro tile mode is unsupported");
969 ac_compute_cmask(info
, config
, surf
);
973 /* This is only called when expecting a tiled layout. */
975 gfx9_get_preferred_swizzle_mode(ADDR_HANDLE addrlib
,
976 struct radeon_surf
*surf
,
977 ADDR2_COMPUTE_SURFACE_INFO_INPUT
*in
,
978 bool is_fmask
, AddrSwizzleMode
*swizzle_mode
)
980 ADDR_E_RETURNCODE ret
;
981 ADDR2_GET_PREFERRED_SURF_SETTING_INPUT sin
= {0};
982 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT sout
= {0};
984 sin
.size
= sizeof(ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
);
985 sout
.size
= sizeof(ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
);
987 sin
.flags
= in
->flags
;
988 sin
.resourceType
= in
->resourceType
;
989 sin
.format
= in
->format
;
990 sin
.resourceLoction
= ADDR_RSRC_LOC_INVIS
;
991 /* TODO: We could allow some of these: */
992 sin
.forbiddenBlock
.micro
= 1; /* don't allow the 256B swizzle modes */
993 sin
.forbiddenBlock
.var
= 1; /* don't allow the variable-sized swizzle modes */
995 sin
.width
= in
->width
;
996 sin
.height
= in
->height
;
997 sin
.numSlices
= in
->numSlices
;
998 sin
.numMipLevels
= in
->numMipLevels
;
999 sin
.numSamples
= in
->numSamples
;
1000 sin
.numFrags
= in
->numFrags
;
1003 sin
.flags
.display
= 0;
1004 sin
.flags
.color
= 0;
1005 sin
.flags
.fmask
= 1;
1008 if (surf
->flags
& RADEON_SURF_FORCE_MICRO_TILE_MODE
) {
1009 sin
.forbiddenBlock
.linear
= 1;
1011 if (surf
->micro_tile_mode
== RADEON_MICRO_MODE_DISPLAY
)
1012 sin
.preferredSwSet
.sw_D
= 1;
1013 else if (surf
->micro_tile_mode
== RADEON_MICRO_MODE_STANDARD
)
1014 sin
.preferredSwSet
.sw_S
= 1;
1015 else if (surf
->micro_tile_mode
== RADEON_MICRO_MODE_DEPTH
)
1016 sin
.preferredSwSet
.sw_Z
= 1;
1017 else if (surf
->micro_tile_mode
== RADEON_MICRO_MODE_RENDER
)
1018 sin
.preferredSwSet
.sw_R
= 1;
1021 ret
= Addr2GetPreferredSurfaceSetting(addrlib
, &sin
, &sout
);
1025 *swizzle_mode
= sout
.swizzleMode
;
1029 static bool is_dcc_supported_by_CB(const struct radeon_info
*info
, unsigned sw_mode
)
1031 if (info
->chip_class
>= GFX10
)
1032 return sw_mode
== ADDR_SW_64KB_Z_X
|| sw_mode
== ADDR_SW_64KB_R_X
;
1034 return sw_mode
!= ADDR_SW_LINEAR
;
1037 ASSERTED
static bool is_dcc_supported_by_L2(const struct radeon_info
*info
,
1038 const struct radeon_surf
*surf
)
1040 if (info
->chip_class
<= GFX9
) {
1041 /* Only independent 64B blocks are supported. */
1042 return surf
->u
.gfx9
.dcc
.independent_64B_blocks
&&
1043 !surf
->u
.gfx9
.dcc
.independent_128B_blocks
&&
1044 surf
->u
.gfx9
.dcc
.max_compressed_block_size
== V_028C78_MAX_BLOCK_SIZE_64B
;
1047 if (info
->family
== CHIP_NAVI10
) {
1048 /* Only independent 128B blocks are supported. */
1049 return !surf
->u
.gfx9
.dcc
.independent_64B_blocks
&&
1050 surf
->u
.gfx9
.dcc
.independent_128B_blocks
&&
1051 surf
->u
.gfx9
.dcc
.max_compressed_block_size
<= V_028C78_MAX_BLOCK_SIZE_128B
;
1054 if (info
->family
== CHIP_NAVI12
||
1055 info
->family
== CHIP_NAVI14
) {
1056 /* Either 64B or 128B can be used, but not both.
1057 * If 64B is used, DCC image stores are unsupported.
1059 return surf
->u
.gfx9
.dcc
.independent_64B_blocks
!=
1060 surf
->u
.gfx9
.dcc
.independent_128B_blocks
&&
1061 (!surf
->u
.gfx9
.dcc
.independent_64B_blocks
||
1062 surf
->u
.gfx9
.dcc
.max_compressed_block_size
== V_028C78_MAX_BLOCK_SIZE_64B
) &&
1063 (!surf
->u
.gfx9
.dcc
.independent_128B_blocks
||
1064 surf
->u
.gfx9
.dcc
.max_compressed_block_size
<= V_028C78_MAX_BLOCK_SIZE_128B
);
1067 unreachable("unhandled chip");
1071 static bool is_dcc_supported_by_DCN(const struct radeon_info
*info
,
1072 const struct ac_surf_config
*config
,
1073 const struct radeon_surf
*surf
,
1074 bool rb_aligned
, bool pipe_aligned
)
1076 if (!info
->use_display_dcc_unaligned
&&
1077 !info
->use_display_dcc_with_retile_blit
)
1080 /* 16bpp and 64bpp are more complicated, so they are disallowed for now. */
1084 /* Handle unaligned DCC. */
1085 if (info
->use_display_dcc_unaligned
&&
1086 (rb_aligned
|| pipe_aligned
))
1089 switch (info
->chip_class
) {
1091 /* There are more constraints, but we always set
1092 * INDEPENDENT_64B_BLOCKS = 1 and MAX_COMPRESSED_BLOCK_SIZE = 64B,
1093 * which always works.
1095 assert(surf
->u
.gfx9
.dcc
.independent_64B_blocks
&&
1096 surf
->u
.gfx9
.dcc
.max_compressed_block_size
== V_028C78_MAX_BLOCK_SIZE_64B
);
1099 /* DCN requires INDEPENDENT_128B_BLOCKS = 0.
1100 * For 4K, it also requires INDEPENDENT_64B_BLOCKS = 1.
1102 return !surf
->u
.gfx9
.dcc
.independent_128B_blocks
&&
1103 ((config
->info
.width
<= 2560 &&
1104 config
->info
.height
<= 2560) ||
1105 (surf
->u
.gfx9
.dcc
.independent_64B_blocks
&&
1106 surf
->u
.gfx9
.dcc
.max_compressed_block_size
== V_028C78_MAX_BLOCK_SIZE_64B
));
1108 unreachable("unhandled chip");
1113 static int gfx9_compute_miptree(ADDR_HANDLE addrlib
,
1114 const struct radeon_info
*info
,
1115 const struct ac_surf_config
*config
,
1116 struct radeon_surf
*surf
, bool compressed
,
1117 ADDR2_COMPUTE_SURFACE_INFO_INPUT
*in
)
1119 ADDR2_MIP_INFO mip_info
[RADEON_SURF_MAX_LEVELS
] = {};
1120 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT out
= {0};
1121 ADDR_E_RETURNCODE ret
;
1123 out
.size
= sizeof(ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
);
1124 out
.pMipInfo
= mip_info
;
1126 ret
= Addr2ComputeSurfaceInfo(addrlib
, in
, &out
);
1130 if (in
->flags
.stencil
) {
1131 surf
->u
.gfx9
.stencil
.swizzle_mode
= in
->swizzleMode
;
1132 surf
->u
.gfx9
.stencil
.epitch
= out
.epitchIsHeight
? out
.mipChainHeight
- 1 :
1133 out
.mipChainPitch
- 1;
1134 surf
->surf_alignment
= MAX2(surf
->surf_alignment
, out
.baseAlign
);
1135 surf
->u
.gfx9
.stencil_offset
= align(surf
->surf_size
, out
.baseAlign
);
1136 surf
->surf_size
= surf
->u
.gfx9
.stencil_offset
+ out
.surfSize
;
1140 surf
->u
.gfx9
.surf
.swizzle_mode
= in
->swizzleMode
;
1141 surf
->u
.gfx9
.surf
.epitch
= out
.epitchIsHeight
? out
.mipChainHeight
- 1 :
1142 out
.mipChainPitch
- 1;
1144 /* CMASK fast clear uses these even if FMASK isn't allocated.
1145 * FMASK only supports the Z swizzle modes, whose numbers are multiples of 4.
1147 surf
->u
.gfx9
.fmask
.swizzle_mode
= surf
->u
.gfx9
.surf
.swizzle_mode
& ~0x3;
1148 surf
->u
.gfx9
.fmask
.epitch
= surf
->u
.gfx9
.surf
.epitch
;
1150 surf
->u
.gfx9
.surf_slice_size
= out
.sliceSize
;
1151 surf
->u
.gfx9
.surf_pitch
= out
.pitch
;
1152 if (!compressed
&& surf
->blk_w
> 1 && out
.pitch
== out
.pixelPitch
) {
1153 /* Adjust surf_pitch to be in elements units,
1155 surf
->u
.gfx9
.surf_pitch
/= surf
->blk_w
;
1157 surf
->u
.gfx9
.surf_height
= out
.height
;
1158 surf
->surf_size
= out
.surfSize
;
1159 surf
->surf_alignment
= out
.baseAlign
;
1161 if (in
->swizzleMode
== ADDR_SW_LINEAR
) {
1162 for (unsigned i
= 0; i
< in
->numMipLevels
; i
++) {
1163 surf
->u
.gfx9
.offset
[i
] = mip_info
[i
].offset
;
1164 surf
->u
.gfx9
.pitch
[i
] = mip_info
[i
].pitch
;
1168 if (in
->flags
.depth
) {
1169 assert(in
->swizzleMode
!= ADDR_SW_LINEAR
);
1171 if (surf
->flags
& RADEON_SURF_NO_HTILE
)
1175 ADDR2_COMPUTE_HTILE_INFO_INPUT hin
= {0};
1176 ADDR2_COMPUTE_HTILE_INFO_OUTPUT hout
= {0};
1178 hin
.size
= sizeof(ADDR2_COMPUTE_HTILE_INFO_INPUT
);
1179 hout
.size
= sizeof(ADDR2_COMPUTE_HTILE_INFO_OUTPUT
);
1181 hin
.hTileFlags
.pipeAligned
= !in
->flags
.metaPipeUnaligned
;
1182 hin
.hTileFlags
.rbAligned
= !in
->flags
.metaRbUnaligned
;
1183 hin
.depthFlags
= in
->flags
;
1184 hin
.swizzleMode
= in
->swizzleMode
;
1185 hin
.unalignedWidth
= in
->width
;
1186 hin
.unalignedHeight
= in
->height
;
1187 hin
.numSlices
= in
->numSlices
;
1188 hin
.numMipLevels
= in
->numMipLevels
;
1189 hin
.firstMipIdInTail
= out
.firstMipIdInTail
;
1191 ret
= Addr2ComputeHtileInfo(addrlib
, &hin
, &hout
);
1195 surf
->u
.gfx9
.htile
.rb_aligned
= hin
.hTileFlags
.rbAligned
;
1196 surf
->u
.gfx9
.htile
.pipe_aligned
= hin
.hTileFlags
.pipeAligned
;
1197 surf
->htile_size
= hout
.htileBytes
;
1198 surf
->htile_slice_size
= hout
.sliceSize
;
1199 surf
->htile_alignment
= hout
.baseAlign
;
1204 /* Compute tile swizzle for the color surface.
1205 * All *_X and *_T modes can use the swizzle.
1207 if (config
->info
.surf_index
&&
1208 in
->swizzleMode
>= ADDR_SW_64KB_Z_T
&&
1209 !out
.mipChainInTail
&&
1210 !(surf
->flags
& RADEON_SURF_SHAREABLE
) &&
1211 !in
->flags
.display
) {
1212 ADDR2_COMPUTE_PIPEBANKXOR_INPUT xin
= {0};
1213 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT xout
= {0};
1215 xin
.size
= sizeof(ADDR2_COMPUTE_PIPEBANKXOR_INPUT
);
1216 xout
.size
= sizeof(ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
);
1218 xin
.surfIndex
= p_atomic_inc_return(config
->info
.surf_index
) - 1;
1219 xin
.flags
= in
->flags
;
1220 xin
.swizzleMode
= in
->swizzleMode
;
1221 xin
.resourceType
= in
->resourceType
;
1222 xin
.format
= in
->format
;
1223 xin
.numSamples
= in
->numSamples
;
1224 xin
.numFrags
= in
->numFrags
;
1226 ret
= Addr2ComputePipeBankXor(addrlib
, &xin
, &xout
);
1230 assert(xout
.pipeBankXor
<=
1231 u_bit_consecutive(0, sizeof(surf
->tile_swizzle
) * 8));
1232 surf
->tile_swizzle
= xout
.pipeBankXor
;
1236 if (info
->has_graphics
&&
1237 !(surf
->flags
& RADEON_SURF_DISABLE_DCC
) &&
1239 is_dcc_supported_by_CB(info
, in
->swizzleMode
) &&
1240 (!in
->flags
.display
||
1241 is_dcc_supported_by_DCN(info
, config
, surf
,
1242 !in
->flags
.metaRbUnaligned
,
1243 !in
->flags
.metaPipeUnaligned
))) {
1244 ADDR2_COMPUTE_DCCINFO_INPUT din
= {0};
1245 ADDR2_COMPUTE_DCCINFO_OUTPUT dout
= {0};
1246 ADDR2_META_MIP_INFO meta_mip_info
[RADEON_SURF_MAX_LEVELS
] = {};
1248 din
.size
= sizeof(ADDR2_COMPUTE_DCCINFO_INPUT
);
1249 dout
.size
= sizeof(ADDR2_COMPUTE_DCCINFO_OUTPUT
);
1250 dout
.pMipInfo
= meta_mip_info
;
1252 din
.dccKeyFlags
.pipeAligned
= !in
->flags
.metaPipeUnaligned
;
1253 din
.dccKeyFlags
.rbAligned
= !in
->flags
.metaRbUnaligned
;
1254 din
.colorFlags
= in
->flags
;
1255 din
.resourceType
= in
->resourceType
;
1256 din
.swizzleMode
= in
->swizzleMode
;
1258 din
.unalignedWidth
= in
->width
;
1259 din
.unalignedHeight
= in
->height
;
1260 din
.numSlices
= in
->numSlices
;
1261 din
.numFrags
= in
->numFrags
;
1262 din
.numMipLevels
= in
->numMipLevels
;
1263 din
.dataSurfaceSize
= out
.surfSize
;
1264 din
.firstMipIdInTail
= out
.firstMipIdInTail
;
1266 ret
= Addr2ComputeDccInfo(addrlib
, &din
, &dout
);
1270 surf
->u
.gfx9
.dcc
.rb_aligned
= din
.dccKeyFlags
.rbAligned
;
1271 surf
->u
.gfx9
.dcc
.pipe_aligned
= din
.dccKeyFlags
.pipeAligned
;
1272 surf
->u
.gfx9
.dcc_block_width
= dout
.compressBlkWidth
;
1273 surf
->u
.gfx9
.dcc_block_height
= dout
.compressBlkHeight
;
1274 surf
->u
.gfx9
.dcc_block_depth
= dout
.compressBlkDepth
;
1275 surf
->dcc_size
= dout
.dccRamSize
;
1276 surf
->dcc_alignment
= dout
.dccRamBaseAlign
;
1277 surf
->num_dcc_levels
= in
->numMipLevels
;
1279 /* Disable DCC for levels that are in the mip tail.
1281 * There are two issues that this is intended to
1284 * 1. Multiple mip levels may share a cache line. This
1285 * can lead to corruption when switching between
1286 * rendering to different mip levels because the
1287 * RBs don't maintain coherency.
1289 * 2. Texturing with metadata after rendering sometimes
1290 * fails with corruption, probably for a similar
1293 * Working around these issues for all levels in the
1294 * mip tail may be overly conservative, but it's what
1297 * Alternative solutions that also work but are worse:
1298 * - Disable DCC entirely.
1299 * - Flush TC L2 after rendering.
1301 for (unsigned i
= 0; i
< in
->numMipLevels
; i
++) {
1302 if (meta_mip_info
[i
].inMiptail
) {
1303 surf
->num_dcc_levels
= i
;
1308 if (!surf
->num_dcc_levels
)
1311 surf
->u
.gfx9
.display_dcc_size
= surf
->dcc_size
;
1312 surf
->u
.gfx9
.display_dcc_alignment
= surf
->dcc_alignment
;
1313 surf
->u
.gfx9
.display_dcc_pitch_max
= dout
.pitch
- 1;
1315 /* Compute displayable DCC. */
1316 if (in
->flags
.display
&&
1317 surf
->num_dcc_levels
&&
1318 info
->use_display_dcc_with_retile_blit
) {
1319 /* Compute displayable DCC info. */
1320 din
.dccKeyFlags
.pipeAligned
= 0;
1321 din
.dccKeyFlags
.rbAligned
= 0;
1323 assert(din
.numSlices
== 1);
1324 assert(din
.numMipLevels
== 1);
1325 assert(din
.numFrags
== 1);
1326 assert(surf
->tile_swizzle
== 0);
1327 assert(surf
->u
.gfx9
.dcc
.pipe_aligned
||
1328 surf
->u
.gfx9
.dcc
.rb_aligned
);
1330 ret
= Addr2ComputeDccInfo(addrlib
, &din
, &dout
);
1334 surf
->u
.gfx9
.display_dcc_size
= dout
.dccRamSize
;
1335 surf
->u
.gfx9
.display_dcc_alignment
= dout
.dccRamBaseAlign
;
1336 surf
->u
.gfx9
.display_dcc_pitch_max
= dout
.pitch
- 1;
1337 assert(surf
->u
.gfx9
.display_dcc_size
<= surf
->dcc_size
);
1339 /* Compute address mapping from non-displayable to displayable DCC. */
1340 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT addrin
= {};
1341 addrin
.size
= sizeof(addrin
);
1342 addrin
.colorFlags
.color
= 1;
1343 addrin
.swizzleMode
= din
.swizzleMode
;
1344 addrin
.resourceType
= din
.resourceType
;
1345 addrin
.bpp
= din
.bpp
;
1346 addrin
.unalignedWidth
= din
.unalignedWidth
;
1347 addrin
.unalignedHeight
= din
.unalignedHeight
;
1348 addrin
.numSlices
= 1;
1349 addrin
.numMipLevels
= 1;
1350 addrin
.numFrags
= 1;
1352 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT addrout
= {};
1353 addrout
.size
= sizeof(addrout
);
1355 surf
->u
.gfx9
.dcc_retile_num_elements
=
1356 DIV_ROUND_UP(in
->width
, dout
.compressBlkWidth
) *
1357 DIV_ROUND_UP(in
->height
, dout
.compressBlkHeight
) * 2;
1358 /* Align the size to 4 (for the compute shader). */
1359 surf
->u
.gfx9
.dcc_retile_num_elements
=
1360 align(surf
->u
.gfx9
.dcc_retile_num_elements
, 4);
1362 surf
->u
.gfx9
.dcc_retile_map
=
1363 malloc(surf
->u
.gfx9
.dcc_retile_num_elements
* 4);
1364 if (!surf
->u
.gfx9
.dcc_retile_map
)
1365 return ADDR_OUTOFMEMORY
;
1368 surf
->u
.gfx9
.dcc_retile_use_uint16
= true;
1370 for (unsigned y
= 0; y
< in
->height
; y
+= dout
.compressBlkHeight
) {
1373 for (unsigned x
= 0; x
< in
->width
; x
+= dout
.compressBlkWidth
) {
1376 /* Compute src DCC address */
1377 addrin
.dccKeyFlags
.pipeAligned
= surf
->u
.gfx9
.dcc
.pipe_aligned
;
1378 addrin
.dccKeyFlags
.rbAligned
= surf
->u
.gfx9
.dcc
.rb_aligned
;
1381 ret
= Addr2ComputeDccAddrFromCoord(addrlib
, &addrin
, &addrout
);
1385 surf
->u
.gfx9
.dcc_retile_map
[index
* 2] = addrout
.addr
;
1386 if (addrout
.addr
> UINT16_MAX
)
1387 surf
->u
.gfx9
.dcc_retile_use_uint16
= false;
1389 /* Compute dst DCC address */
1390 addrin
.dccKeyFlags
.pipeAligned
= 0;
1391 addrin
.dccKeyFlags
.rbAligned
= 0;
1394 ret
= Addr2ComputeDccAddrFromCoord(addrlib
, &addrin
, &addrout
);
1398 surf
->u
.gfx9
.dcc_retile_map
[index
* 2 + 1] = addrout
.addr
;
1399 if (addrout
.addr
> UINT16_MAX
)
1400 surf
->u
.gfx9
.dcc_retile_use_uint16
= false;
1402 assert(index
* 2 + 1 < surf
->u
.gfx9
.dcc_retile_num_elements
);
1406 /* Fill the remaining pairs with the last one (for the compute shader). */
1407 for (unsigned i
= index
* 2; i
< surf
->u
.gfx9
.dcc_retile_num_elements
; i
++)
1408 surf
->u
.gfx9
.dcc_retile_map
[i
] = surf
->u
.gfx9
.dcc_retile_map
[i
- 2];
1413 if (in
->numSamples
> 1 && info
->has_graphics
&&
1414 !(surf
->flags
& RADEON_SURF_NO_FMASK
)) {
1415 ADDR2_COMPUTE_FMASK_INFO_INPUT fin
= {0};
1416 ADDR2_COMPUTE_FMASK_INFO_OUTPUT fout
= {0};
1418 fin
.size
= sizeof(ADDR2_COMPUTE_FMASK_INFO_INPUT
);
1419 fout
.size
= sizeof(ADDR2_COMPUTE_FMASK_INFO_OUTPUT
);
1421 ret
= gfx9_get_preferred_swizzle_mode(addrlib
, surf
, in
,
1422 true, &fin
.swizzleMode
);
1426 fin
.unalignedWidth
= in
->width
;
1427 fin
.unalignedHeight
= in
->height
;
1428 fin
.numSlices
= in
->numSlices
;
1429 fin
.numSamples
= in
->numSamples
;
1430 fin
.numFrags
= in
->numFrags
;
1432 ret
= Addr2ComputeFmaskInfo(addrlib
, &fin
, &fout
);
1436 surf
->u
.gfx9
.fmask
.swizzle_mode
= fin
.swizzleMode
;
1437 surf
->u
.gfx9
.fmask
.epitch
= fout
.pitch
- 1;
1438 surf
->fmask_size
= fout
.fmaskBytes
;
1439 surf
->fmask_alignment
= fout
.baseAlign
;
1441 /* Compute tile swizzle for the FMASK surface. */
1442 if (config
->info
.fmask_surf_index
&&
1443 fin
.swizzleMode
>= ADDR_SW_64KB_Z_T
&&
1444 !(surf
->flags
& RADEON_SURF_SHAREABLE
)) {
1445 ADDR2_COMPUTE_PIPEBANKXOR_INPUT xin
= {0};
1446 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT xout
= {0};
1448 xin
.size
= sizeof(ADDR2_COMPUTE_PIPEBANKXOR_INPUT
);
1449 xout
.size
= sizeof(ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
);
1451 /* This counter starts from 1 instead of 0. */
1452 xin
.surfIndex
= p_atomic_inc_return(config
->info
.fmask_surf_index
);
1453 xin
.flags
= in
->flags
;
1454 xin
.swizzleMode
= fin
.swizzleMode
;
1455 xin
.resourceType
= in
->resourceType
;
1456 xin
.format
= in
->format
;
1457 xin
.numSamples
= in
->numSamples
;
1458 xin
.numFrags
= in
->numFrags
;
1460 ret
= Addr2ComputePipeBankXor(addrlib
, &xin
, &xout
);
1464 assert(xout
.pipeBankXor
<=
1465 u_bit_consecutive(0, sizeof(surf
->fmask_tile_swizzle
) * 8));
1466 surf
->fmask_tile_swizzle
= xout
.pipeBankXor
;
1470 /* CMASK -- on GFX10 only for FMASK */
1471 if (in
->swizzleMode
!= ADDR_SW_LINEAR
&&
1472 in
->resourceType
== ADDR_RSRC_TEX_2D
&&
1473 ((info
->chip_class
<= GFX9
&& in
->numSamples
== 1) ||
1474 (surf
->fmask_size
&& in
->numSamples
>= 2))) {
1475 ADDR2_COMPUTE_CMASK_INFO_INPUT cin
= {0};
1476 ADDR2_COMPUTE_CMASK_INFO_OUTPUT cout
= {0};
1478 cin
.size
= sizeof(ADDR2_COMPUTE_CMASK_INFO_INPUT
);
1479 cout
.size
= sizeof(ADDR2_COMPUTE_CMASK_INFO_OUTPUT
);
1481 assert(in
->flags
.metaPipeUnaligned
== 0);
1482 assert(in
->flags
.metaRbUnaligned
== 0);
1484 cin
.cMaskFlags
.pipeAligned
= 1;
1485 cin
.cMaskFlags
.rbAligned
= 1;
1486 cin
.colorFlags
= in
->flags
;
1487 cin
.resourceType
= in
->resourceType
;
1488 cin
.unalignedWidth
= in
->width
;
1489 cin
.unalignedHeight
= in
->height
;
1490 cin
.numSlices
= in
->numSlices
;
1492 if (in
->numSamples
> 1)
1493 cin
.swizzleMode
= surf
->u
.gfx9
.fmask
.swizzle_mode
;
1495 cin
.swizzleMode
= in
->swizzleMode
;
1497 ret
= Addr2ComputeCmaskInfo(addrlib
, &cin
, &cout
);
1501 surf
->cmask_size
= cout
.cmaskBytes
;
1502 surf
->cmask_alignment
= cout
.baseAlign
;
1509 static int gfx9_compute_surface(ADDR_HANDLE addrlib
,
1510 const struct radeon_info
*info
,
1511 const struct ac_surf_config
*config
,
1512 enum radeon_surf_mode mode
,
1513 struct radeon_surf
*surf
)
1516 ADDR2_COMPUTE_SURFACE_INFO_INPUT AddrSurfInfoIn
= {0};
1519 AddrSurfInfoIn
.size
= sizeof(ADDR2_COMPUTE_SURFACE_INFO_INPUT
);
1521 compressed
= surf
->blk_w
== 4 && surf
->blk_h
== 4;
1523 /* The format must be set correctly for the allocation of compressed
1524 * textures to work. In other cases, setting the bpp is sufficient. */
1526 switch (surf
->bpe
) {
1528 AddrSurfInfoIn
.format
= ADDR_FMT_BC1
;
1531 AddrSurfInfoIn
.format
= ADDR_FMT_BC3
;
1537 switch (surf
->bpe
) {
1539 assert(!(surf
->flags
& RADEON_SURF_ZBUFFER
));
1540 AddrSurfInfoIn
.format
= ADDR_FMT_8
;
1543 assert(surf
->flags
& RADEON_SURF_ZBUFFER
||
1544 !(surf
->flags
& RADEON_SURF_SBUFFER
));
1545 AddrSurfInfoIn
.format
= ADDR_FMT_16
;
1548 assert(surf
->flags
& RADEON_SURF_ZBUFFER
||
1549 !(surf
->flags
& RADEON_SURF_SBUFFER
));
1550 AddrSurfInfoIn
.format
= ADDR_FMT_32
;
1553 assert(!(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
));
1554 AddrSurfInfoIn
.format
= ADDR_FMT_32_32
;
1557 assert(!(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
));
1558 AddrSurfInfoIn
.format
= ADDR_FMT_32_32_32
;
1561 assert(!(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
));
1562 AddrSurfInfoIn
.format
= ADDR_FMT_32_32_32_32
;
1567 AddrSurfInfoIn
.bpp
= surf
->bpe
* 8;
1570 bool is_color_surface
= !(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
);
1571 AddrSurfInfoIn
.flags
.color
= is_color_surface
&&
1572 !(surf
->flags
& RADEON_SURF_NO_RENDER_TARGET
);
1573 AddrSurfInfoIn
.flags
.depth
= (surf
->flags
& RADEON_SURF_ZBUFFER
) != 0;
1574 AddrSurfInfoIn
.flags
.display
= get_display_flag(config
, surf
);
1575 /* flags.texture currently refers to TC-compatible HTILE */
1576 AddrSurfInfoIn
.flags
.texture
= is_color_surface
||
1577 surf
->flags
& RADEON_SURF_TC_COMPATIBLE_HTILE
;
1578 AddrSurfInfoIn
.flags
.opt4space
= 1;
1580 AddrSurfInfoIn
.numMipLevels
= config
->info
.levels
;
1581 AddrSurfInfoIn
.numSamples
= MAX2(1, config
->info
.samples
);
1582 AddrSurfInfoIn
.numFrags
= AddrSurfInfoIn
.numSamples
;
1584 if (!(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
))
1585 AddrSurfInfoIn
.numFrags
= MAX2(1, config
->info
.storage_samples
);
1587 /* GFX9 doesn't support 1D depth textures, so allocate all 1D textures
1588 * as 2D to avoid having shader variants for 1D vs 2D, so all shaders
1589 * must sample 1D textures as 2D. */
1591 AddrSurfInfoIn
.resourceType
= ADDR_RSRC_TEX_3D
;
1592 else if (info
->chip_class
!= GFX9
&& config
->is_1d
)
1593 AddrSurfInfoIn
.resourceType
= ADDR_RSRC_TEX_1D
;
1595 AddrSurfInfoIn
.resourceType
= ADDR_RSRC_TEX_2D
;
1597 AddrSurfInfoIn
.width
= config
->info
.width
;
1598 AddrSurfInfoIn
.height
= config
->info
.height
;
1601 AddrSurfInfoIn
.numSlices
= config
->info
.depth
;
1602 else if (config
->is_cube
)
1603 AddrSurfInfoIn
.numSlices
= 6;
1605 AddrSurfInfoIn
.numSlices
= config
->info
.array_size
;
1607 /* This is propagated to HTILE/DCC. */
1608 AddrSurfInfoIn
.flags
.metaPipeUnaligned
= 0;
1609 AddrSurfInfoIn
.flags
.metaRbUnaligned
= 0;
1611 /* Optimal values for the L2 cache. */
1612 if (info
->chip_class
== GFX9
) {
1613 surf
->u
.gfx9
.dcc
.independent_64B_blocks
= 1;
1614 surf
->u
.gfx9
.dcc
.independent_128B_blocks
= 0;
1615 surf
->u
.gfx9
.dcc
.max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
1616 } else if (info
->chip_class
>= GFX10
) {
1617 surf
->u
.gfx9
.dcc
.independent_64B_blocks
= 0;
1618 surf
->u
.gfx9
.dcc
.independent_128B_blocks
= 1;
1619 surf
->u
.gfx9
.dcc
.max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
1622 if (AddrSurfInfoIn
.flags
.display
) {
1623 /* The display hardware can only read DCC with RB_ALIGNED=0 and
1624 * PIPE_ALIGNED=0. PIPE_ALIGNED really means L2CACHE_ALIGNED.
1626 * The CB block requires RB_ALIGNED=1 except 1 RB chips.
1627 * PIPE_ALIGNED is optional, but PIPE_ALIGNED=0 requires L2 flushes
1628 * after rendering, so PIPE_ALIGNED=1 is recommended.
1630 if (info
->use_display_dcc_unaligned
) {
1631 AddrSurfInfoIn
.flags
.metaPipeUnaligned
= 1;
1632 AddrSurfInfoIn
.flags
.metaRbUnaligned
= 1;
1635 /* Adjust DCC settings to meet DCN requirements. */
1636 if (info
->use_display_dcc_unaligned
||
1637 info
->use_display_dcc_with_retile_blit
) {
1638 /* Only Navi12/14 support independent 64B blocks in L2,
1639 * but without DCC image stores.
1641 if (info
->family
== CHIP_NAVI12
||
1642 info
->family
== CHIP_NAVI14
) {
1643 surf
->u
.gfx9
.dcc
.independent_64B_blocks
= 1;
1644 surf
->u
.gfx9
.dcc
.independent_128B_blocks
= 0;
1645 surf
->u
.gfx9
.dcc
.max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
1651 case RADEON_SURF_MODE_LINEAR_ALIGNED
:
1652 assert(config
->info
.samples
<= 1);
1653 assert(!(surf
->flags
& RADEON_SURF_Z_OR_SBUFFER
));
1654 AddrSurfInfoIn
.swizzleMode
= ADDR_SW_LINEAR
;
1657 case RADEON_SURF_MODE_1D
:
1658 case RADEON_SURF_MODE_2D
:
1659 if (surf
->flags
& RADEON_SURF_IMPORTED
||
1660 (info
->chip_class
>= GFX10
&&
1661 surf
->flags
& RADEON_SURF_FORCE_SWIZZLE_MODE
)) {
1662 AddrSurfInfoIn
.swizzleMode
= surf
->u
.gfx9
.surf
.swizzle_mode
;
1666 r
= gfx9_get_preferred_swizzle_mode(addrlib
, surf
, &AddrSurfInfoIn
,
1667 false, &AddrSurfInfoIn
.swizzleMode
);
1676 surf
->u
.gfx9
.resource_type
= AddrSurfInfoIn
.resourceType
;
1677 surf
->has_stencil
= !!(surf
->flags
& RADEON_SURF_SBUFFER
);
1679 surf
->num_dcc_levels
= 0;
1680 surf
->surf_size
= 0;
1681 surf
->fmask_size
= 0;
1683 surf
->htile_size
= 0;
1684 surf
->htile_slice_size
= 0;
1685 surf
->u
.gfx9
.surf_offset
= 0;
1686 surf
->u
.gfx9
.stencil_offset
= 0;
1687 surf
->cmask_size
= 0;
1688 surf
->u
.gfx9
.dcc_retile_use_uint16
= false;
1689 surf
->u
.gfx9
.dcc_retile_num_elements
= 0;
1690 surf
->u
.gfx9
.dcc_retile_map
= NULL
;
1692 /* Calculate texture layout information. */
1693 r
= gfx9_compute_miptree(addrlib
, info
, config
, surf
, compressed
,
1698 /* Calculate texture layout information for stencil. */
1699 if (surf
->flags
& RADEON_SURF_SBUFFER
) {
1700 AddrSurfInfoIn
.flags
.stencil
= 1;
1701 AddrSurfInfoIn
.bpp
= 8;
1702 AddrSurfInfoIn
.format
= ADDR_FMT_8
;
1704 if (!AddrSurfInfoIn
.flags
.depth
) {
1705 r
= gfx9_get_preferred_swizzle_mode(addrlib
, surf
, &AddrSurfInfoIn
,
1706 false, &AddrSurfInfoIn
.swizzleMode
);
1710 AddrSurfInfoIn
.flags
.depth
= 0;
1712 r
= gfx9_compute_miptree(addrlib
, info
, config
, surf
, compressed
,
1718 surf
->is_linear
= surf
->u
.gfx9
.surf
.swizzle_mode
== ADDR_SW_LINEAR
;
1720 /* Query whether the surface is displayable. */
1721 /* This is only useful for surfaces that are allocated without SCANOUT. */
1722 bool displayable
= false;
1723 if (!config
->is_3d
&& !config
->is_cube
) {
1724 r
= Addr2IsValidDisplaySwizzleMode(addrlib
, surf
->u
.gfx9
.surf
.swizzle_mode
,
1725 surf
->bpe
* 8, &displayable
);
1729 /* Display needs unaligned DCC. */
1730 if (surf
->num_dcc_levels
&&
1731 !is_dcc_supported_by_DCN(info
, config
, surf
,
1732 surf
->u
.gfx9
.dcc
.rb_aligned
,
1733 surf
->u
.gfx9
.dcc
.pipe_aligned
))
1734 displayable
= false;
1736 surf
->is_displayable
= displayable
;
1738 /* Validate that we allocated a displayable surface if requested. */
1739 assert(!AddrSurfInfoIn
.flags
.display
|| surf
->is_displayable
);
1741 /* Validate that DCC is set up correctly. */
1742 if (surf
->num_dcc_levels
) {
1743 assert(is_dcc_supported_by_L2(info
, surf
));
1744 if (AddrSurfInfoIn
.flags
.color
)
1745 assert(is_dcc_supported_by_CB(info
, surf
->u
.gfx9
.surf
.swizzle_mode
));
1746 if (AddrSurfInfoIn
.flags
.display
) {
1747 assert(is_dcc_supported_by_DCN(info
, config
, surf
,
1748 surf
->u
.gfx9
.dcc
.rb_aligned
,
1749 surf
->u
.gfx9
.dcc
.pipe_aligned
));
1753 if (info
->has_graphics
&&
1756 config
->info
.levels
== 1 &&
1757 AddrSurfInfoIn
.flags
.color
&&
1759 surf
->surf_alignment
>= 64 * 1024 && /* 64KB tiling */
1760 !(surf
->flags
& (RADEON_SURF_DISABLE_DCC
|
1761 RADEON_SURF_FORCE_SWIZZLE_MODE
|
1762 RADEON_SURF_FORCE_MICRO_TILE_MODE
))) {
1763 /* Validate that DCC is enabled if DCN can do it. */
1764 if ((info
->use_display_dcc_unaligned
||
1765 info
->use_display_dcc_with_retile_blit
) &&
1766 AddrSurfInfoIn
.flags
.display
&&
1768 assert(surf
->num_dcc_levels
);
1771 /* Validate that non-scanout DCC is always enabled. */
1772 if (!AddrSurfInfoIn
.flags
.display
)
1773 assert(surf
->num_dcc_levels
);
1776 if (!surf
->htile_size
) {
1777 /* Unset this if HTILE is not present. */
1778 surf
->flags
&= ~RADEON_SURF_TC_COMPATIBLE_HTILE
;
1781 switch (surf
->u
.gfx9
.surf
.swizzle_mode
) {
1783 case ADDR_SW_256B_S
:
1785 case ADDR_SW_64KB_S
:
1786 case ADDR_SW_64KB_S_T
:
1787 case ADDR_SW_4KB_S_X
:
1788 case ADDR_SW_64KB_S_X
:
1789 surf
->micro_tile_mode
= RADEON_MICRO_MODE_STANDARD
;
1793 case ADDR_SW_LINEAR
:
1794 case ADDR_SW_256B_D
:
1796 case ADDR_SW_64KB_D
:
1797 case ADDR_SW_64KB_D_T
:
1798 case ADDR_SW_4KB_D_X
:
1799 case ADDR_SW_64KB_D_X
:
1800 surf
->micro_tile_mode
= RADEON_MICRO_MODE_DISPLAY
;
1803 /* R = rotated (gfx9), render target (gfx10). */
1804 case ADDR_SW_256B_R
:
1806 case ADDR_SW_64KB_R
:
1807 case ADDR_SW_64KB_R_T
:
1808 case ADDR_SW_4KB_R_X
:
1809 case ADDR_SW_64KB_R_X
:
1810 case ADDR_SW_VAR_R_X
:
1811 /* The rotated micro tile mode doesn't work if both CMASK and RB+ are
1812 * used at the same time. We currently do not use rotated
1815 assert(info
->chip_class
>= GFX10
||
1816 !"rotate micro tile mode is unsupported");
1817 surf
->micro_tile_mode
= RADEON_MICRO_MODE_RENDER
;
1822 case ADDR_SW_64KB_Z
:
1823 case ADDR_SW_64KB_Z_T
:
1824 case ADDR_SW_4KB_Z_X
:
1825 case ADDR_SW_64KB_Z_X
:
1826 case ADDR_SW_VAR_Z_X
:
1827 surf
->micro_tile_mode
= RADEON_MICRO_MODE_DEPTH
;
1837 free(surf
->u
.gfx9
.dcc_retile_map
);
1838 surf
->u
.gfx9
.dcc_retile_map
= NULL
;
1842 int ac_compute_surface(ADDR_HANDLE addrlib
, const struct radeon_info
*info
,
1843 const struct ac_surf_config
*config
,
1844 enum radeon_surf_mode mode
,
1845 struct radeon_surf
*surf
)
1849 r
= surf_config_sanity(config
, surf
->flags
);
1853 if (info
->chip_class
>= GFX9
)
1854 r
= gfx9_compute_surface(addrlib
, info
, config
, mode
, surf
);
1856 r
= gfx6_compute_surface(addrlib
, info
, config
, mode
, surf
);
1861 /* Determine the memory layout of multiple allocations in one buffer. */
1862 surf
->total_size
= surf
->surf_size
;
1864 if (surf
->htile_size
) {
1865 surf
->htile_offset
= align64(surf
->total_size
, surf
->htile_alignment
);
1866 surf
->total_size
= surf
->htile_offset
+ surf
->htile_size
;
1869 if (surf
->fmask_size
) {
1870 assert(config
->info
.samples
>= 2);
1871 surf
->fmask_offset
= align64(surf
->total_size
, surf
->fmask_alignment
);
1872 surf
->total_size
= surf
->fmask_offset
+ surf
->fmask_size
;
1875 /* Single-sample CMASK is in a separate buffer. */
1876 if (surf
->cmask_size
&& config
->info
.samples
>= 2) {
1877 surf
->cmask_offset
= align64(surf
->total_size
, surf
->cmask_alignment
);
1878 surf
->total_size
= surf
->cmask_offset
+ surf
->cmask_size
;
1881 if (surf
->dcc_size
&&
1882 /* dcc_size is computed on GFX9+ only if it's displayable. */
1883 (info
->chip_class
>= GFX9
|| !get_display_flag(config
, surf
))) {
1884 /* It's better when displayable DCC is immediately after
1885 * the image due to hw-specific reasons.
1887 if (info
->chip_class
>= GFX9
&&
1888 surf
->u
.gfx9
.dcc_retile_num_elements
) {
1889 /* Add space for the displayable DCC buffer. */
1890 surf
->display_dcc_offset
=
1891 align64(surf
->total_size
, surf
->u
.gfx9
.display_dcc_alignment
);
1892 surf
->total_size
= surf
->display_dcc_offset
+
1893 surf
->u
.gfx9
.display_dcc_size
;
1895 /* Add space for the DCC retile buffer. (16-bit or 32-bit elements) */
1896 surf
->dcc_retile_map_offset
=
1897 align64(surf
->total_size
, info
->tcc_cache_line_size
);
1899 if (surf
->u
.gfx9
.dcc_retile_use_uint16
) {
1900 surf
->total_size
= surf
->dcc_retile_map_offset
+
1901 surf
->u
.gfx9
.dcc_retile_num_elements
* 2;
1903 surf
->total_size
= surf
->dcc_retile_map_offset
+
1904 surf
->u
.gfx9
.dcc_retile_num_elements
* 4;
1908 surf
->dcc_offset
= align64(surf
->total_size
, surf
->dcc_alignment
);
1909 surf
->total_size
= surf
->dcc_offset
+ surf
->dcc_size
;