2 * Copyright © 2007-2018 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
17 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
28 ************************************************************************************************************************
29 * @file gfx9addrlib.cpp
30 * @brief Contgfx9ns the implementation for the Gfx9Lib class.
31 ************************************************************************************************************************
34 #include "gfx9addrlib.h"
36 #include "gfx9_gb_reg.h"
38 #include "amdgpu_asic_addr.h"
40 #include "util/macros.h"
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////////////////////////////////////////////
49 ************************************************************************************************************************
53 * Creates an Gfx9Lib object.
56 * Returns an Gfx9Lib object pointer.
57 ************************************************************************************************************************
59 Addr::Lib
* Gfx9HwlInit(const Client
* pClient
)
61 return V2::Gfx9Lib::CreateObj(pClient
);
67 ////////////////////////////////////////////////////////////////////////////////////////////////////
68 // Static Const Member
69 ////////////////////////////////////////////////////////////////////////////////////////////////////
71 const SwizzleModeFlags
Gfx9Lib::SwizzleModeTable
[ADDR_SW_MAX_TYPE
] =
72 {//Linear 256B 4KB 64KB Var Z Std Disp Rot XOR T RtOpt
73 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // ADDR_SW_LINEAR
74 {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_256B_S
75 {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_256B_D
76 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_256B_R
78 {0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, // ADDR_SW_4KB_Z
79 {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_4KB_S
80 {0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_4KB_D
81 {0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_4KB_R
83 {0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0}, // ADDR_SW_64KB_Z
84 {0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_64KB_S
85 {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_64KB_D
86 {0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_64KB_R
88 {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, // ADDR_SW_VAR_Z
89 {0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_VAR_S
90 {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_VAR_D
91 {0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_VAR_R
93 {0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0}, // ADDR_SW_64KB_Z_T
94 {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0}, // ADDR_SW_64KB_S_T
95 {0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0}, // ADDR_SW_64KB_D_T
96 {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0}, // ADDR_SW_64KB_R_T
98 {0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0}, // ADDR_SW_4KB_Z_x
99 {0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0}, // ADDR_SW_4KB_S_x
100 {0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0}, // ADDR_SW_4KB_D_x
101 {0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0}, // ADDR_SW_4KB_R_x
103 {0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0}, // ADDR_SW_64KB_Z_X
104 {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}, // ADDR_SW_64KB_S_X
105 {0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0}, // ADDR_SW_64KB_D_X
106 {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0}, // ADDR_SW_64KB_R_X
108 {0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0}, // ADDR_SW_VAR_Z_X
109 {0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0}, // ADDR_SW_VAR_S_X
110 {0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0}, // ADDR_SW_VAR_D_X
111 {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0}, // ADDR_SW_VAR_R_X
112 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // ADDR_SW_LINEAR_GENERAL
115 const UINT_32
Gfx9Lib::MipTailOffset256B
[] = {2048, 1024, 512, 256, 128, 64, 32, 16,
116 8, 6, 5, 4, 3, 2, 1, 0};
118 const Dim3d
Gfx9Lib::Block256_3dS
[] = {{16, 4, 4}, {8, 4, 4}, {4, 4, 4}, {2, 4, 4}, {1, 4, 4}};
120 const Dim3d
Gfx9Lib::Block256_3dZ
[] = {{8, 4, 8}, {4, 4, 8}, {4, 4, 4}, {4, 2, 4}, {2, 2, 4}};
123 ************************************************************************************************************************
129 ************************************************************************************************************************
131 Gfx9Lib::Gfx9Lib(const Client
* pClient
)
136 m_class
= AI_ADDRLIB
;
137 memset(&m_settings
, 0, sizeof(m_settings
));
138 memcpy(m_swizzleModeTable
, SwizzleModeTable
, sizeof(SwizzleModeTable
));
142 ************************************************************************************************************************
147 ************************************************************************************************************************
154 ************************************************************************************************************************
155 * Gfx9Lib::HwlComputeHtileInfo
158 * Interface function stub of AddrComputeHtilenfo
162 ************************************************************************************************************************
164 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileInfo(
165 const ADDR2_COMPUTE_HTILE_INFO_INPUT
* pIn
, ///< [in] input structure
166 ADDR2_COMPUTE_HTILE_INFO_OUTPUT
* pOut
///< [out] output structure
169 UINT_32 numPipeTotal
= GetPipeNumForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
172 UINT_32 numRbTotal
= pIn
->hTileFlags
.rbAligned
? m_se
* m_rbPerSe
: 1;
174 UINT_32 numCompressBlkPerMetaBlk
, numCompressBlkPerMetaBlkLog2
;
176 if ((numPipeTotal
== 1) && (numRbTotal
== 1))
178 numCompressBlkPerMetaBlkLog2
= 10;
182 if (m_settings
.applyAliasFix
)
184 numCompressBlkPerMetaBlkLog2
= m_seLog2
+ m_rbPerSeLog2
+ Max(10u, m_pipeInterleaveLog2
);
188 numCompressBlkPerMetaBlkLog2
= m_seLog2
+ m_rbPerSeLog2
+ 10;
192 numCompressBlkPerMetaBlk
= 1 << numCompressBlkPerMetaBlkLog2
;
194 Dim3d metaBlkDim
= {8, 8, 1};
195 UINT_32 totalAmpBits
= numCompressBlkPerMetaBlkLog2
;
196 UINT_32 widthAmp
= (pIn
->numMipLevels
> 1) ? (totalAmpBits
>> 1) : RoundHalf(totalAmpBits
);
197 UINT_32 heightAmp
= totalAmpBits
- widthAmp
;
198 metaBlkDim
.w
<<= widthAmp
;
199 metaBlkDim
.h
<<= heightAmp
;
202 Dim3d metaBlkDimDbg
= {8, 8, 1};
203 for (UINT_32 index
= 0; index
< numCompressBlkPerMetaBlkLog2
; index
++)
205 if ((metaBlkDimDbg
.h
< metaBlkDimDbg
.w
) ||
206 ((pIn
->numMipLevels
> 1) && (metaBlkDimDbg
.h
== metaBlkDimDbg
.w
)))
208 metaBlkDimDbg
.h
<<= 1;
212 metaBlkDimDbg
.w
<<= 1;
215 ADDR_ASSERT((metaBlkDimDbg
.w
== metaBlkDim
.w
) && (metaBlkDimDbg
.h
== metaBlkDim
.h
));
222 GetMetaMipInfo(pIn
->numMipLevels
, &metaBlkDim
, FALSE
, pOut
->pMipInfo
,
223 pIn
->unalignedWidth
, pIn
->unalignedHeight
, pIn
->numSlices
,
224 &numMetaBlkX
, &numMetaBlkY
, &numMetaBlkZ
);
226 const UINT_32 metaBlkSize
= numCompressBlkPerMetaBlk
<< 2;
227 UINT_32 align
= numPipeTotal
* numRbTotal
* m_pipeInterleaveBytes
;
229 if ((IsXor(pIn
->swizzleMode
) == FALSE
) && (numPipeTotal
> 2))
231 align
*= (numPipeTotal
>> 1);
234 align
= Max(align
, metaBlkSize
);
236 if (m_settings
.metaBaseAlignFix
)
238 align
= Max(align
, GetBlockSize(pIn
->swizzleMode
));
241 if (m_settings
.htileAlignFix
)
243 const INT_32 metaBlkSizeLog2
= numCompressBlkPerMetaBlkLog2
+ 2;
244 const INT_32 htileCachelineSizeLog2
= 11;
245 const INT_32 maxNumOfRbMaskBits
= 1 + Log2(numPipeTotal
) + Log2(numRbTotal
);
247 INT_32 rbMaskPadding
= Max(0, htileCachelineSizeLog2
- (metaBlkSizeLog2
- maxNumOfRbMaskBits
));
249 align
<<= rbMaskPadding
;
252 pOut
->pitch
= numMetaBlkX
* metaBlkDim
.w
;
253 pOut
->height
= numMetaBlkY
* metaBlkDim
.h
;
254 pOut
->sliceSize
= numMetaBlkX
* numMetaBlkY
* metaBlkSize
;
256 pOut
->metaBlkWidth
= metaBlkDim
.w
;
257 pOut
->metaBlkHeight
= metaBlkDim
.h
;
258 pOut
->metaBlkNumPerSlice
= numMetaBlkX
* numMetaBlkY
;
260 pOut
->baseAlign
= align
;
261 pOut
->htileBytes
= PowTwoAlign(pOut
->sliceSize
* numMetaBlkZ
, align
);
267 ************************************************************************************************************************
268 * Gfx9Lib::HwlComputeCmaskInfo
271 * Interface function stub of AddrComputeCmaskInfo
275 ************************************************************************************************************************
277 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeCmaskInfo(
278 const ADDR2_COMPUTE_CMASK_INFO_INPUT
* pIn
, ///< [in] input structure
279 ADDR2_COMPUTE_CMASK_INFO_OUTPUT
* pOut
///< [out] output structure
282 // TODO: Clarify with AddrLib team
283 // ADDR_ASSERT(pIn->resourceType == ADDR_RSRC_TEX_2D);
285 UINT_32 numPipeTotal
= GetPipeNumForMetaAddressing(pIn
->cMaskFlags
.pipeAligned
,
288 UINT_32 numRbTotal
= pIn
->cMaskFlags
.rbAligned
? m_se
* m_rbPerSe
: 1;
290 UINT_32 numCompressBlkPerMetaBlkLog2
, numCompressBlkPerMetaBlk
;
292 if ((numPipeTotal
== 1) && (numRbTotal
== 1))
294 numCompressBlkPerMetaBlkLog2
= 13;
298 if (m_settings
.applyAliasFix
)
300 numCompressBlkPerMetaBlkLog2
= m_seLog2
+ m_rbPerSeLog2
+ Max(10u, m_pipeInterleaveLog2
);
304 numCompressBlkPerMetaBlkLog2
= m_seLog2
+ m_rbPerSeLog2
+ 10;
307 numCompressBlkPerMetaBlkLog2
= Max(numCompressBlkPerMetaBlkLog2
, 13u);
310 numCompressBlkPerMetaBlk
= 1 << numCompressBlkPerMetaBlkLog2
;
312 Dim2d metaBlkDim
= {8, 8};
313 UINT_32 totalAmpBits
= numCompressBlkPerMetaBlkLog2
;
314 UINT_32 heightAmp
= totalAmpBits
>> 1;
315 UINT_32 widthAmp
= totalAmpBits
- heightAmp
;
316 metaBlkDim
.w
<<= widthAmp
;
317 metaBlkDim
.h
<<= heightAmp
;
320 Dim2d metaBlkDimDbg
= {8, 8};
321 for (UINT_32 index
= 0; index
< numCompressBlkPerMetaBlkLog2
; index
++)
323 if (metaBlkDimDbg
.h
< metaBlkDimDbg
.w
)
325 metaBlkDimDbg
.h
<<= 1;
329 metaBlkDimDbg
.w
<<= 1;
332 ADDR_ASSERT((metaBlkDimDbg
.w
== metaBlkDim
.w
) && (metaBlkDimDbg
.h
== metaBlkDim
.h
));
335 UINT_32 numMetaBlkX
= (pIn
->unalignedWidth
+ metaBlkDim
.w
- 1) / metaBlkDim
.w
;
336 UINT_32 numMetaBlkY
= (pIn
->unalignedHeight
+ metaBlkDim
.h
- 1) / metaBlkDim
.h
;
337 UINT_32 numMetaBlkZ
= Max(pIn
->numSlices
, 1u);
339 UINT_32 sizeAlign
= numPipeTotal
* numRbTotal
* m_pipeInterleaveBytes
;
341 if (m_settings
.metaBaseAlignFix
)
343 sizeAlign
= Max(sizeAlign
, GetBlockSize(pIn
->swizzleMode
));
346 pOut
->pitch
= numMetaBlkX
* metaBlkDim
.w
;
347 pOut
->height
= numMetaBlkY
* metaBlkDim
.h
;
348 pOut
->sliceSize
= (numMetaBlkX
* numMetaBlkY
* numCompressBlkPerMetaBlk
) >> 1;
349 pOut
->cmaskBytes
= PowTwoAlign(pOut
->sliceSize
* numMetaBlkZ
, sizeAlign
);
350 pOut
->baseAlign
= Max(numCompressBlkPerMetaBlk
>> 1, sizeAlign
);
352 pOut
->metaBlkWidth
= metaBlkDim
.w
;
353 pOut
->metaBlkHeight
= metaBlkDim
.h
;
355 pOut
->metaBlkNumPerSlice
= numMetaBlkX
* numMetaBlkY
;
361 ************************************************************************************************************************
362 * Gfx9Lib::GetMetaMipInfo
369 ************************************************************************************************************************
371 VOID
Gfx9Lib::GetMetaMipInfo(
372 UINT_32 numMipLevels
, ///< [in] number of mip levels
373 Dim3d
* pMetaBlkDim
, ///< [in] meta block dimension
374 BOOL_32 dataThick
, ///< [in] data surface is thick
375 ADDR2_META_MIP_INFO
* pInfo
, ///< [out] meta mip info
376 UINT_32 mip0Width
, ///< [in] mip0 width
377 UINT_32 mip0Height
, ///< [in] mip0 height
378 UINT_32 mip0Depth
, ///< [in] mip0 depth
379 UINT_32
* pNumMetaBlkX
, ///< [out] number of metablock X in mipchain
380 UINT_32
* pNumMetaBlkY
, ///< [out] number of metablock Y in mipchain
381 UINT_32
* pNumMetaBlkZ
) ///< [out] number of metablock Z in mipchain
384 UINT_32 numMetaBlkX
= (mip0Width
+ pMetaBlkDim
->w
- 1) / pMetaBlkDim
->w
;
385 UINT_32 numMetaBlkY
= (mip0Height
+ pMetaBlkDim
->h
- 1) / pMetaBlkDim
->h
;
386 UINT_32 numMetaBlkZ
= (mip0Depth
+ pMetaBlkDim
->d
- 1) / pMetaBlkDim
->d
;
387 UINT_32 tailWidth
= pMetaBlkDim
->w
;
388 UINT_32 tailHeight
= pMetaBlkDim
->h
>> 1;
389 UINT_32 tailDepth
= pMetaBlkDim
->d
;
390 BOOL_32 inTail
= FALSE
;
391 AddrMajorMode major
= ADDR_MAJOR_MAX_TYPE
;
393 if (numMipLevels
> 1)
395 if (dataThick
&& (numMetaBlkZ
> numMetaBlkX
) && (numMetaBlkZ
> numMetaBlkY
))
398 major
= ADDR_MAJOR_Z
;
400 else if (numMetaBlkX
>= numMetaBlkY
)
403 major
= ADDR_MAJOR_X
;
408 major
= ADDR_MAJOR_Y
;
411 inTail
= ((mip0Width
<= tailWidth
) &&
412 (mip0Height
<= tailHeight
) &&
413 ((dataThick
== FALSE
) || (mip0Depth
<= tailDepth
)));
421 if (major
== ADDR_MAJOR_Z
)
424 pMipDim
= &numMetaBlkY
;
425 pOrderDim
= &numMetaBlkZ
;
428 else if (major
== ADDR_MAJOR_X
)
431 pMipDim
= &numMetaBlkY
;
432 pOrderDim
= &numMetaBlkX
;
438 pMipDim
= &numMetaBlkX
;
439 pOrderDim
= &numMetaBlkY
;
443 if ((*pMipDim
< 3) && (*pOrderDim
> orderLimit
) && (numMipLevels
> 3))
449 *pMipDim
+= ((*pMipDim
/ 2) + (*pMipDim
& 1));
456 UINT_32 mipWidth
= mip0Width
;
457 UINT_32 mipHeight
= mip0Height
;
458 UINT_32 mipDepth
= mip0Depth
;
459 Dim3d mipCoord
= {0};
461 for (UINT_32 mip
= 0; mip
< numMipLevels
; mip
++)
465 GetMetaMiptailInfo(&pInfo
[mip
], mipCoord
, numMipLevels
- mip
,
471 mipWidth
= PowTwoAlign(mipWidth
, pMetaBlkDim
->w
);
472 mipHeight
= PowTwoAlign(mipHeight
, pMetaBlkDim
->h
);
473 mipDepth
= PowTwoAlign(mipDepth
, pMetaBlkDim
->d
);
475 pInfo
[mip
].inMiptail
= FALSE
;
476 pInfo
[mip
].startX
= mipCoord
.w
;
477 pInfo
[mip
].startY
= mipCoord
.h
;
478 pInfo
[mip
].startZ
= mipCoord
.d
;
479 pInfo
[mip
].width
= mipWidth
;
480 pInfo
[mip
].height
= mipHeight
;
481 pInfo
[mip
].depth
= dataThick
? mipDepth
: 1;
483 if ((mip
>= 3) || (mip
& 1))
488 mipCoord
.w
+= mipWidth
;
491 mipCoord
.h
+= mipHeight
;
494 mipCoord
.d
+= mipDepth
;
505 mipCoord
.h
+= mipHeight
;
508 mipCoord
.w
+= mipWidth
;
511 mipCoord
.h
+= mipHeight
;
518 mipWidth
= Max(mipWidth
>> 1, 1u);
519 mipHeight
= Max(mipHeight
>> 1, 1u);
520 mipDepth
= Max(mipDepth
>> 1, 1u);
522 inTail
= ((mipWidth
<= tailWidth
) &&
523 (mipHeight
<= tailHeight
) &&
524 ((dataThick
== FALSE
) || (mipDepth
<= tailDepth
)));
529 *pNumMetaBlkX
= numMetaBlkX
;
530 *pNumMetaBlkY
= numMetaBlkY
;
531 *pNumMetaBlkZ
= numMetaBlkZ
;
535 ************************************************************************************************************************
536 * Gfx9Lib::HwlComputeDccInfo
539 * Interface function to compute DCC key info
543 ************************************************************************************************************************
545 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeDccInfo(
546 const ADDR2_COMPUTE_DCCINFO_INPUT
* pIn
, ///< [in] input structure
547 ADDR2_COMPUTE_DCCINFO_OUTPUT
* pOut
///< [out] output structure
550 BOOL_32 dataLinear
= IsLinear(pIn
->swizzleMode
);
551 BOOL_32 metaLinear
= pIn
->dccKeyFlags
.linear
;
552 BOOL_32 pipeAligned
= pIn
->dccKeyFlags
.pipeAligned
;
558 else if (metaLinear
== TRUE
)
563 UINT_32 numPipeTotal
= GetPipeNumForMetaAddressing(pipeAligned
, pIn
->swizzleMode
);
567 // Linear metadata supporting was removed for GFX9! No one can use this feature on GFX9.
568 ADDR_ASSERT_ALWAYS();
570 pOut
->dccRamBaseAlign
= numPipeTotal
* m_pipeInterleaveBytes
;
571 pOut
->dccRamSize
= PowTwoAlign((pIn
->dataSurfaceSize
/ 256), pOut
->dccRamBaseAlign
);
575 BOOL_32 dataThick
= IsThick(pIn
->resourceType
, pIn
->swizzleMode
);
577 UINT_32 minMetaBlkSize
= dataThick
? 65536 : 4096;
579 UINT_32 numFrags
= Max(pIn
->numFrags
, 1u);
580 UINT_32 numSlices
= Max(pIn
->numSlices
, 1u);
582 minMetaBlkSize
/= numFrags
;
584 UINT_32 numCompressBlkPerMetaBlk
= minMetaBlkSize
;
586 UINT_32 numRbTotal
= pIn
->dccKeyFlags
.rbAligned
? m_se
* m_rbPerSe
: 1;
588 if ((numPipeTotal
> 1) || (numRbTotal
> 1))
590 const UINT_32 thinBlkSize
= 1 << (m_settings
.applyAliasFix
? Max(10u, m_pipeInterleaveLog2
) : 10);
592 numCompressBlkPerMetaBlk
=
593 Max(numCompressBlkPerMetaBlk
, m_se
* m_rbPerSe
* (dataThick
? 262144 : thinBlkSize
));
595 if (numCompressBlkPerMetaBlk
> 65536 * pIn
->bpp
)
597 numCompressBlkPerMetaBlk
= 65536 * pIn
->bpp
;
601 Dim3d compressBlkDim
= GetDccCompressBlk(pIn
->resourceType
, pIn
->swizzleMode
, pIn
->bpp
);
602 Dim3d metaBlkDim
= compressBlkDim
;
604 for (UINT_32 index
= 1; index
< numCompressBlkPerMetaBlk
; index
<<= 1)
606 if ((metaBlkDim
.h
< metaBlkDim
.w
) ||
607 ((pIn
->numMipLevels
> 1) && (metaBlkDim
.h
== metaBlkDim
.w
)))
609 if ((dataThick
== FALSE
) || (metaBlkDim
.h
<= metaBlkDim
.d
))
620 if ((dataThick
== FALSE
) || (metaBlkDim
.w
<= metaBlkDim
.d
))
635 GetMetaMipInfo(pIn
->numMipLevels
, &metaBlkDim
, dataThick
, pOut
->pMipInfo
,
636 pIn
->unalignedWidth
, pIn
->unalignedHeight
, numSlices
,
637 &numMetaBlkX
, &numMetaBlkY
, &numMetaBlkZ
);
639 UINT_32 sizeAlign
= numPipeTotal
* numRbTotal
* m_pipeInterleaveBytes
;
641 if (numFrags
> m_maxCompFrag
)
643 sizeAlign
*= (numFrags
/ m_maxCompFrag
);
646 if (m_settings
.metaBaseAlignFix
)
648 sizeAlign
= Max(sizeAlign
, GetBlockSize(pIn
->swizzleMode
));
651 pOut
->dccRamSize
= numMetaBlkX
* numMetaBlkY
* numMetaBlkZ
*
652 numCompressBlkPerMetaBlk
* numFrags
;
653 pOut
->dccRamSize
= PowTwoAlign(pOut
->dccRamSize
, sizeAlign
);
654 pOut
->dccRamBaseAlign
= Max(numCompressBlkPerMetaBlk
, sizeAlign
);
656 pOut
->pitch
= numMetaBlkX
* metaBlkDim
.w
;
657 pOut
->height
= numMetaBlkY
* metaBlkDim
.h
;
658 pOut
->depth
= numMetaBlkZ
* metaBlkDim
.d
;
660 pOut
->compressBlkWidth
= compressBlkDim
.w
;
661 pOut
->compressBlkHeight
= compressBlkDim
.h
;
662 pOut
->compressBlkDepth
= compressBlkDim
.d
;
664 pOut
->metaBlkWidth
= metaBlkDim
.w
;
665 pOut
->metaBlkHeight
= metaBlkDim
.h
;
666 pOut
->metaBlkDepth
= metaBlkDim
.d
;
668 pOut
->metaBlkNumPerSlice
= numMetaBlkX
* numMetaBlkY
;
669 pOut
->fastClearSizePerSlice
=
670 pOut
->metaBlkNumPerSlice
* numCompressBlkPerMetaBlk
* Min(numFrags
, m_maxCompFrag
);
677 ************************************************************************************************************************
678 * Gfx9Lib::HwlComputeMaxBaseAlignments
681 * Gets maximum alignments
684 ************************************************************************************************************************
686 UINT_32
Gfx9Lib::HwlComputeMaxBaseAlignments() const
688 return ComputeSurfaceBaseAlignTiled(ADDR_SW_64KB
);
692 ************************************************************************************************************************
693 * Gfx9Lib::HwlComputeMaxMetaBaseAlignments
696 * Gets maximum alignments for metadata
698 * maximum alignments for metadata
699 ************************************************************************************************************************
701 UINT_32
Gfx9Lib::HwlComputeMaxMetaBaseAlignments() const
703 // Max base alignment for Htile
704 const UINT_32 maxNumPipeTotal
= GetPipeNumForMetaAddressing(TRUE
, ADDR_SW_64KB_Z
);
705 const UINT_32 maxNumRbTotal
= m_se
* m_rbPerSe
;
707 // If applyAliasFix was set, the extra bits should be MAX(10u, m_pipeInterleaveLog2),
708 // but we never saw any ASIC whose m_pipeInterleaveLog2 != 8, so just put an assertion and simply the logic.
709 ADDR_ASSERT((m_settings
.applyAliasFix
== FALSE
) || (m_pipeInterleaveLog2
<= 10u));
710 const UINT_32 maxNumCompressBlkPerMetaBlk
= 1u << (m_seLog2
+ m_rbPerSeLog2
+ 10u);
712 UINT_32 maxBaseAlignHtile
= maxNumPipeTotal
* maxNumRbTotal
* m_pipeInterleaveBytes
;
714 if (maxNumPipeTotal
> 2)
716 maxBaseAlignHtile
*= (maxNumPipeTotal
>> 1);
719 maxBaseAlignHtile
= Max(maxNumCompressBlkPerMetaBlk
<< 2, maxBaseAlignHtile
);
721 if (m_settings
.metaBaseAlignFix
)
723 maxBaseAlignHtile
= Max(maxBaseAlignHtile
, GetBlockSize(ADDR_SW_64KB
));
726 if (m_settings
.htileAlignFix
)
728 maxBaseAlignHtile
*= maxNumPipeTotal
;
731 // Max base alignment for Cmask will not be larger than that for Htile, no need to calculate
733 // Max base alignment for 2D Dcc will not be larger than that for 3D, no need to calculate
734 UINT_32 maxBaseAlignDcc3D
= 65536;
736 if ((maxNumPipeTotal
> 1) || (maxNumRbTotal
> 1))
738 maxBaseAlignDcc3D
= Min(m_se
* m_rbPerSe
* 262144, 65536 * 128u);
741 // Max base alignment for Msaa Dcc
742 UINT_32 maxBaseAlignDccMsaa
= maxNumPipeTotal
* maxNumRbTotal
* m_pipeInterleaveBytes
* (8 / m_maxCompFrag
);
744 if (m_settings
.metaBaseAlignFix
)
746 maxBaseAlignDccMsaa
= Max(maxBaseAlignDccMsaa
, GetBlockSize(ADDR_SW_64KB
));
749 return Max(maxBaseAlignHtile
, Max(maxBaseAlignDccMsaa
, maxBaseAlignDcc3D
));
753 ************************************************************************************************************************
754 * Gfx9Lib::HwlComputeCmaskAddrFromCoord
757 * Interface function stub of AddrComputeCmaskAddrFromCoord
761 ************************************************************************************************************************
763 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeCmaskAddrFromCoord(
764 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
765 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
767 ADDR2_COMPUTE_CMASK_INFO_INPUT input
= {0};
768 input
.size
= sizeof(input
);
769 input
.cMaskFlags
= pIn
->cMaskFlags
;
770 input
.colorFlags
= pIn
->colorFlags
;
771 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
772 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
773 input
.numSlices
= Max(pIn
->numSlices
, 1u);
774 input
.swizzleMode
= pIn
->swizzleMode
;
775 input
.resourceType
= pIn
->resourceType
;
777 ADDR2_COMPUTE_CMASK_INFO_OUTPUT output
= {0};
778 output
.size
= sizeof(output
);
780 ADDR_E_RETURNCODE returnCode
= ComputeCmaskInfo(&input
, &output
);
782 if (returnCode
== ADDR_OK
)
784 UINT_32 fmaskBpp
= GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
);
785 UINT_32 fmaskElementBytesLog2
= Log2(fmaskBpp
>> 3);
786 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
787 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
789 MetaEqParams metaEqParams
= {0, fmaskElementBytesLog2
, 0, pIn
->cMaskFlags
,
790 Gfx9DataFmask
, pIn
->swizzleMode
, pIn
->resourceType
,
791 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
793 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
795 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
796 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
797 UINT_32 zb
= pIn
->slice
;
799 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
800 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
801 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
803 UINT_64 address
= pMetaEq
->solve(pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
);
805 pOut
->addr
= address
>> 1;
806 pOut
->bitPosition
= static_cast<UINT_32
>((address
& 1) << 2);
808 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->cMaskFlags
.pipeAligned
,
811 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
813 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
820 ************************************************************************************************************************
821 * Gfx9Lib::HwlComputeHtileAddrFromCoord
824 * Interface function stub of AddrComputeHtileAddrFromCoord
828 ************************************************************************************************************************
830 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileAddrFromCoord(
831 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
832 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
834 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
836 if (pIn
->numMipLevels
> 1)
838 returnCode
= ADDR_NOTIMPLEMENTED
;
842 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
843 input
.size
= sizeof(input
);
844 input
.hTileFlags
= pIn
->hTileFlags
;
845 input
.depthFlags
= pIn
->depthflags
;
846 input
.swizzleMode
= pIn
->swizzleMode
;
847 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
848 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
849 input
.numSlices
= Max(pIn
->numSlices
, 1u);
850 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
852 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
853 output
.size
= sizeof(output
);
855 returnCode
= ComputeHtileInfo(&input
, &output
);
857 if (returnCode
== ADDR_OK
)
859 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
860 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
861 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
862 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
864 MetaEqParams metaEqParams
= {0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
865 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
866 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
868 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
870 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
871 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
872 UINT_32 zb
= pIn
->slice
;
874 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
875 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
876 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
878 UINT_64 address
= pMetaEq
->solve(pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
);
880 pOut
->addr
= address
>> 1;
882 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
885 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
887 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
895 ************************************************************************************************************************
896 * Gfx9Lib::HwlComputeHtileCoordFromAddr
899 * Interface function stub of AddrComputeHtileCoordFromAddr
903 ************************************************************************************************************************
905 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileCoordFromAddr(
906 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
907 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
) ///< [out] output structure
909 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
911 if (pIn
->numMipLevels
> 1)
913 returnCode
= ADDR_NOTIMPLEMENTED
;
917 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
918 input
.size
= sizeof(input
);
919 input
.hTileFlags
= pIn
->hTileFlags
;
920 input
.swizzleMode
= pIn
->swizzleMode
;
921 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
922 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
923 input
.numSlices
= Max(pIn
->numSlices
, 1u);
924 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
926 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
927 output
.size
= sizeof(output
);
929 returnCode
= ComputeHtileInfo(&input
, &output
);
931 if (returnCode
== ADDR_OK
)
933 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
934 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
935 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
936 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
938 MetaEqParams metaEqParams
= {0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
939 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
940 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
942 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
944 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
947 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
949 UINT_64 nibbleAddress
= (pIn
->addr
^ (pipeXor
<< m_pipeInterleaveLog2
)) << 1;
951 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
952 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
954 UINT_32 x
, y
, z
, s
, m
;
955 pMetaEq
->solveAddr(nibbleAddress
, sliceSizeInBlock
, x
, y
, z
, s
, m
);
957 pOut
->slice
= m
/ sliceSizeInBlock
;
958 pOut
->y
= ((m
% sliceSizeInBlock
) / pitchInBlock
) * output
.metaBlkHeight
+ y
;
959 pOut
->x
= (m
% pitchInBlock
) * output
.metaBlkWidth
+ x
;
967 ************************************************************************************************************************
968 * Gfx9Lib::HwlComputeDccAddrFromCoord
971 * Interface function stub of AddrComputeDccAddrFromCoord
975 ************************************************************************************************************************
977 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeDccAddrFromCoord(
978 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
,
979 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
)
981 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
983 if ((pIn
->numMipLevels
> 1) || (pIn
->mipId
> 1) || pIn
->dccKeyFlags
.linear
)
985 returnCode
= ADDR_NOTIMPLEMENTED
;
989 ADDR2_COMPUTE_DCCINFO_INPUT input
= {0};
990 input
.size
= sizeof(input
);
991 input
.dccKeyFlags
= pIn
->dccKeyFlags
;
992 input
.colorFlags
= pIn
->colorFlags
;
993 input
.swizzleMode
= pIn
->swizzleMode
;
994 input
.resourceType
= pIn
->resourceType
;
995 input
.bpp
= pIn
->bpp
;
996 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
997 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
998 input
.numSlices
= Max(pIn
->numSlices
, 1u);
999 input
.numFrags
= Max(pIn
->numFrags
, 1u);
1000 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
1002 ADDR2_COMPUTE_DCCINFO_OUTPUT output
= {0};
1003 output
.size
= sizeof(output
);
1005 returnCode
= ComputeDccInfo(&input
, &output
);
1007 if (returnCode
== ADDR_OK
)
1009 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
1010 UINT_32 numSamplesLog2
= Log2(pIn
->numFrags
);
1011 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
1012 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
1013 UINT_32 metaBlkDepthLog2
= Log2(output
.metaBlkDepth
);
1014 UINT_32 compBlkWidthLog2
= Log2(output
.compressBlkWidth
);
1015 UINT_32 compBlkHeightLog2
= Log2(output
.compressBlkHeight
);
1016 UINT_32 compBlkDepthLog2
= Log2(output
.compressBlkDepth
);
1018 MetaEqParams metaEqParams
= {pIn
->mipId
, elementBytesLog2
, numSamplesLog2
, pIn
->dccKeyFlags
,
1019 Gfx9DataColor
, pIn
->swizzleMode
, pIn
->resourceType
,
1020 metaBlkWidthLog2
, metaBlkHeightLog2
, metaBlkDepthLog2
,
1021 compBlkWidthLog2
, compBlkHeightLog2
, compBlkDepthLog2
};
1023 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
1025 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
1026 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
1027 UINT_32 zb
= pIn
->slice
/ output
.metaBlkDepth
;
1029 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
1030 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
1031 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
1033 UINT_64 address
= pMetaEq
->solve(pIn
->x
, pIn
->y
, pIn
->slice
, pIn
->sample
, blockIndex
);
1035 pOut
->addr
= address
>> 1;
1037 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->dccKeyFlags
.pipeAligned
,
1040 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
1042 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
1050 ************************************************************************************************************************
1051 * Gfx9Lib::HwlInitGlobalParams
1054 * Initializes global parameters
1057 * TRUE if all settings are valid
1059 ************************************************************************************************************************
1061 BOOL_32
Gfx9Lib::HwlInitGlobalParams(
1062 const ADDR_CREATE_INPUT
* pCreateIn
) ///< [in] create input
1064 BOOL_32 valid
= TRUE
;
1066 if (m_settings
.isArcticIsland
)
1068 GB_ADDR_CONFIG gbAddrConfig
;
1070 gbAddrConfig
.u32All
= pCreateIn
->regValue
.gbAddrConfig
;
1072 // These values are copied from CModel code
1073 switch (gbAddrConfig
.bits
.NUM_PIPES
)
1075 case ADDR_CONFIG_1_PIPE
:
1079 case ADDR_CONFIG_2_PIPE
:
1083 case ADDR_CONFIG_4_PIPE
:
1087 case ADDR_CONFIG_8_PIPE
:
1091 case ADDR_CONFIG_16_PIPE
:
1095 case ADDR_CONFIG_32_PIPE
:
1100 ADDR_ASSERT_ALWAYS();
1104 switch (gbAddrConfig
.bits
.PIPE_INTERLEAVE_SIZE
)
1106 case ADDR_CONFIG_PIPE_INTERLEAVE_256B
:
1107 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_256B
;
1108 m_pipeInterleaveLog2
= 8;
1110 case ADDR_CONFIG_PIPE_INTERLEAVE_512B
:
1111 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_512B
;
1112 m_pipeInterleaveLog2
= 9;
1114 case ADDR_CONFIG_PIPE_INTERLEAVE_1KB
:
1115 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_1KB
;
1116 m_pipeInterleaveLog2
= 10;
1118 case ADDR_CONFIG_PIPE_INTERLEAVE_2KB
:
1119 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_2KB
;
1120 m_pipeInterleaveLog2
= 11;
1123 ADDR_ASSERT_ALWAYS();
1127 // Addr::V2::Lib::ComputePipeBankXor()/ComputeSlicePipeBankXor() requires pipe interleave to be exactly 8 bits,
1128 // and any larger value requires a post-process (left shift) on the output pipeBankXor bits.
1129 ADDR_ASSERT(m_pipeInterleaveBytes
== ADDR_PIPEINTERLEAVE_256B
);
1131 switch (gbAddrConfig
.bits
.NUM_BANKS
)
1133 case ADDR_CONFIG_1_BANK
:
1137 case ADDR_CONFIG_2_BANK
:
1141 case ADDR_CONFIG_4_BANK
:
1145 case ADDR_CONFIG_8_BANK
:
1149 case ADDR_CONFIG_16_BANK
:
1154 ADDR_ASSERT_ALWAYS();
1158 switch (gbAddrConfig
.bits
.NUM_SHADER_ENGINES
)
1160 case ADDR_CONFIG_1_SHADER_ENGINE
:
1164 case ADDR_CONFIG_2_SHADER_ENGINE
:
1168 case ADDR_CONFIG_4_SHADER_ENGINE
:
1172 case ADDR_CONFIG_8_SHADER_ENGINE
:
1177 ADDR_ASSERT_ALWAYS();
1181 switch (gbAddrConfig
.bits
.NUM_RB_PER_SE
)
1183 case ADDR_CONFIG_1_RB_PER_SHADER_ENGINE
:
1187 case ADDR_CONFIG_2_RB_PER_SHADER_ENGINE
:
1191 case ADDR_CONFIG_4_RB_PER_SHADER_ENGINE
:
1196 ADDR_ASSERT_ALWAYS();
1200 switch (gbAddrConfig
.bits
.MAX_COMPRESSED_FRAGS
)
1202 case ADDR_CONFIG_1_MAX_COMPRESSED_FRAGMENTS
:
1204 m_maxCompFragLog2
= 0;
1206 case ADDR_CONFIG_2_MAX_COMPRESSED_FRAGMENTS
:
1208 m_maxCompFragLog2
= 1;
1210 case ADDR_CONFIG_4_MAX_COMPRESSED_FRAGMENTS
:
1212 m_maxCompFragLog2
= 2;
1214 case ADDR_CONFIG_8_MAX_COMPRESSED_FRAGMENTS
:
1216 m_maxCompFragLog2
= 3;
1219 ADDR_ASSERT_ALWAYS();
1223 m_blockVarSizeLog2
= pCreateIn
->regValue
.blockVarSizeLog2
;
1224 ADDR_ASSERT((m_blockVarSizeLog2
== 0) ||
1225 ((m_blockVarSizeLog2
>= 17u) && (m_blockVarSizeLog2
<= 20u)));
1226 m_blockVarSizeLog2
= Min(Max(17u, m_blockVarSizeLog2
), 20u);
1228 if ((m_rbPerSeLog2
== 1) &&
1229 (((m_pipesLog2
== 1) && ((m_seLog2
== 2) || (m_seLog2
== 3))) ||
1230 ((m_pipesLog2
== 2) && ((m_seLog2
== 1) || (m_seLog2
== 2)))))
1232 ADDR_ASSERT(m_settings
.isVega10
== FALSE
);
1233 ADDR_ASSERT(m_settings
.isRaven
== FALSE
);
1234 ADDR_ASSERT(m_settings
.isVega20
== FALSE
);
1236 if (m_settings
.isVega12
)
1238 m_settings
.htileCacheRbConflict
= 1;
1245 ADDR_NOT_IMPLEMENTED();
1250 InitEquationTable();
1257 ************************************************************************************************************************
1258 * Gfx9Lib::HwlConvertChipFamily
1261 * Convert familyID defined in atiid.h to ChipFamily and set m_chipFamily/m_chipRevision
1264 ************************************************************************************************************************
1266 ChipFamily
Gfx9Lib::HwlConvertChipFamily(
1267 UINT_32 uChipFamily
, ///< [in] chip family defined in atiih.h
1268 UINT_32 uChipRevision
) ///< [in] chip revision defined in "asic_family"_id.h
1270 ChipFamily family
= ADDR_CHIP_FAMILY_AI
;
1272 switch (uChipFamily
)
1275 m_settings
.isArcticIsland
= 1;
1276 m_settings
.isVega10
= ASICREV_IS_VEGA10_P(uChipRevision
);
1277 m_settings
.isVega12
= ASICREV_IS_VEGA12_P(uChipRevision
);
1278 m_settings
.isVega20
= ASICREV_IS_VEGA20_P(uChipRevision
);
1279 m_settings
.isDce12
= 1;
1281 if (m_settings
.isVega10
== 0)
1283 m_settings
.htileAlignFix
= 1;
1284 m_settings
.applyAliasFix
= 1;
1287 m_settings
.metaBaseAlignFix
= 1;
1289 m_settings
.depthPipeXorDisable
= 1;
1292 m_settings
.isArcticIsland
= 1;
1294 if (ASICREV_IS_RAVEN(uChipRevision
))
1296 m_settings
.isRaven
= 1;
1298 m_settings
.depthPipeXorDisable
= 1;
1301 if (ASICREV_IS_RAVEN2(uChipRevision
))
1303 m_settings
.isRaven
= 1;
1306 if (m_settings
.isRaven
== 0)
1308 m_settings
.htileAlignFix
= 1;
1309 m_settings
.applyAliasFix
= 1;
1312 m_settings
.isDcn1
= m_settings
.isRaven
;
1314 m_settings
.metaBaseAlignFix
= 1;
1318 ADDR_ASSERT(!"This should be a Fusion");
1326 ************************************************************************************************************************
1327 * Gfx9Lib::InitRbEquation
1333 ************************************************************************************************************************
1335 VOID
Gfx9Lib::GetRbEquation(
1336 CoordEq
* pRbEq
, ///< [out] rb equation
1337 UINT_32 numRbPerSeLog2
, ///< [in] number of rb per shader engine
1338 UINT_32 numSeLog2
) ///< [in] number of shader engine
1341 // RB's are distributed on 16x16, except when we have 1 rb per se, in which case its 32x32
1342 UINT_32 rbRegion
= (numRbPerSeLog2
== 0) ? 5 : 4;
1343 Coordinate
cx('x', rbRegion
);
1344 Coordinate
cy('y', rbRegion
);
1347 UINT_32 numRbTotalLog2
= numRbPerSeLog2
+ numSeLog2
;
1349 // Clear the rb equation
1351 pRbEq
->resize(numRbTotalLog2
);
1353 if ((numSeLog2
> 0) && (numRbPerSeLog2
== 1))
1355 // Special case when more than 1 SE, and 2 RB per SE
1356 (*pRbEq
)[0].add(cx
);
1357 (*pRbEq
)[0].add(cy
);
1361 if (m_settings
.applyAliasFix
== false)
1363 (*pRbEq
)[0].add(cy
);
1366 (*pRbEq
)[0].add(cy
);
1370 UINT_32 numBits
= 2 * (numRbTotalLog2
- start
);
1372 for (UINT_32 i
= 0; i
< numBits
; i
++)
1375 start
+ (((start
+ i
) >= numRbTotalLog2
) ? (2 * (numRbTotalLog2
- start
) - i
- 1) : i
);
1379 (*pRbEq
)[idx
].add(cx
);
1384 (*pRbEq
)[idx
].add(cy
);
1391 ************************************************************************************************************************
1392 * Gfx9Lib::GetDataEquation
1395 * Get data equation for fmask and Z
1398 ************************************************************************************************************************
1400 VOID
Gfx9Lib::GetDataEquation(
1401 CoordEq
* pDataEq
, ///< [out] data surface equation
1402 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1403 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1404 AddrResourceType resourceType
, ///< [in] data surface resource type
1405 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1406 UINT_32 numSamplesLog2
) ///< [in] data surface sample count
1409 Coordinate
cx('x', 0);
1410 Coordinate
cy('y', 0);
1411 Coordinate
cz('z', 0);
1412 Coordinate
cs('s', 0);
1414 // Clear the equation
1416 pDataEq
->resize(27);
1418 if (dataSurfaceType
== Gfx9DataColor
)
1420 if (IsLinear(swizzleMode
))
1422 Coordinate
cm('m', 0);
1424 pDataEq
->resize(49);
1426 for (UINT_32 i
= 0; i
< 49; i
++)
1428 (*pDataEq
)[i
].add(cm
);
1432 else if (IsThick(resourceType
, swizzleMode
))
1434 // Color 3d_S and 3d_Z modes, 3d_D is same as color 2d
1436 if (IsStandardSwizzle(resourceType
, swizzleMode
))
1438 // Standard 3d swizzle
1439 // Fill in bottom x bits
1440 for (i
= elementBytesLog2
; i
< 4; i
++)
1442 (*pDataEq
)[i
].add(cx
);
1445 // Fill in 2 bits of y and then z
1446 for (i
= 4; i
< 6; i
++)
1448 (*pDataEq
)[i
].add(cy
);
1451 for (i
= 6; i
< 8; i
++)
1453 (*pDataEq
)[i
].add(cz
);
1456 if (elementBytesLog2
< 2)
1458 // fill in z & y bit
1459 (*pDataEq
)[8].add(cz
);
1460 (*pDataEq
)[9].add(cy
);
1464 else if (elementBytesLog2
== 2)
1466 // fill in y and x bit
1467 (*pDataEq
)[8].add(cy
);
1468 (*pDataEq
)[9].add(cx
);
1475 (*pDataEq
)[8].add(cx
);
1477 (*pDataEq
)[9].add(cx
);
1484 UINT_32 m2dEnd
= (elementBytesLog2
==0) ? 3 : ((elementBytesLog2
< 4) ? 4 : 5);
1485 UINT_32 numZs
= (elementBytesLog2
== 0 || elementBytesLog2
== 4) ?
1486 2 : ((elementBytesLog2
== 1) ? 3 : 1);
1487 pDataEq
->mort2d(cx
, cy
, elementBytesLog2
, m2dEnd
);
1488 for (i
= m2dEnd
+ 1; i
<= m2dEnd
+ numZs
; i
++)
1490 (*pDataEq
)[i
].add(cz
);
1493 if ((elementBytesLog2
== 0) || (elementBytesLog2
== 3))
1496 (*pDataEq
)[6].add(cx
);
1497 (*pDataEq
)[7].add(cz
);
1501 else if (elementBytesLog2
== 2)
1504 (*pDataEq
)[6].add(cy
);
1505 (*pDataEq
)[7].add(cz
);
1510 (*pDataEq
)[8].add(cy
);
1511 (*pDataEq
)[9].add(cx
);
1515 // Fill in bit 10 and up
1516 pDataEq
->mort3d( cz
, cy
, cx
, 10 );
1518 else if (IsThin(resourceType
, swizzleMode
))
1520 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1522 UINT_32 microYBits
= (8 - elementBytesLog2
) / 2;
1523 UINT_32 tileSplitStart
= blockSizeLog2
- numSamplesLog2
;
1525 // Fill in bottom x bits
1526 for (i
= elementBytesLog2
; i
< 4; i
++)
1528 (*pDataEq
)[i
].add(cx
);
1531 // Fill in bottom y bits
1532 for (i
= 4; i
< 4 + microYBits
; i
++)
1534 (*pDataEq
)[i
].add(cy
);
1537 // Fill in last of the micro_x bits
1538 for (i
= 4 + microYBits
; i
< 8; i
++)
1540 (*pDataEq
)[i
].add(cx
);
1543 // Fill in x/y bits below sample split
1544 pDataEq
->mort2d(cy
, cx
, 8, tileSplitStart
- 1);
1545 // Fill in sample bits
1546 for (i
= 0; i
< numSamplesLog2
; i
++)
1549 (*pDataEq
)[tileSplitStart
+ i
].add(cs
);
1551 // Fill in x/y bits above sample split
1552 if ((numSamplesLog2
& 1) ^ (blockSizeLog2
& 1))
1554 pDataEq
->mort2d(cx
, cy
, blockSizeLog2
);
1558 pDataEq
->mort2d(cy
, cx
, blockSizeLog2
);
1563 ADDR_ASSERT_ALWAYS();
1569 UINT_32 sampleStart
= elementBytesLog2
;
1570 UINT_32 pixelStart
= elementBytesLog2
+ numSamplesLog2
;
1571 UINT_32 ymajStart
= 6 + numSamplesLog2
;
1573 for (UINT_32 s
= 0; s
< numSamplesLog2
; s
++)
1576 (*pDataEq
)[sampleStart
+ s
].add(cs
);
1579 // Put in the x-major order pixel bits
1580 pDataEq
->mort2d(cx
, cy
, pixelStart
, ymajStart
- 1);
1581 // Put in the y-major order pixel bits
1582 pDataEq
->mort2d(cy
, cx
, ymajStart
);
1587 ************************************************************************************************************************
1588 * Gfx9Lib::GetPipeEquation
1594 ************************************************************************************************************************
1596 VOID
Gfx9Lib::GetPipeEquation(
1597 CoordEq
* pPipeEq
, ///< [out] pipe equation
1598 CoordEq
* pDataEq
, ///< [in] data equation
1599 UINT_32 pipeInterleaveLog2
, ///< [in] pipe interleave
1600 UINT_32 numPipeLog2
, ///< [in] number of pipes
1601 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1602 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1603 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1604 AddrResourceType resourceType
///< [in] data surface resource type
1607 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1610 pDataEq
->copy(dataEq
);
1612 if (dataSurfaceType
== Gfx9DataColor
)
1614 INT_32 shift
= static_cast<INT_32
>(numSamplesLog2
);
1615 dataEq
.shift(-shift
, blockSizeLog2
- numSamplesLog2
);
1618 dataEq
.copy(*pPipeEq
, pipeInterleaveLog2
, numPipeLog2
);
1620 // This section should only apply to z/stencil, maybe fmask
1621 // If the pipe bit is below the comp block size,
1622 // then keep moving up the address until we find a bit that is above
1623 UINT_32 pipeStart
= 0;
1625 if (dataSurfaceType
!= Gfx9DataColor
)
1627 Coordinate
tileMin('x', 3);
1629 while (dataEq
[pipeInterleaveLog2
+ pipeStart
][0] < tileMin
)
1634 // if pipe is 0, then the first pipe bit is above the comp block size,
1635 // so we don't need to do anything
1636 // Note, this if condition is not necessary, since if we execute the loop when pipe==0,
1637 // we will get the same pipe equation
1640 for (UINT_32 i
= 0; i
< numPipeLog2
; i
++)
1642 // Copy the jth bit above pipe interleave to the current pipe equation bit
1643 dataEq
[pipeInterleaveLog2
+ pipeStart
+ i
].copyto((*pPipeEq
)[i
]);
1648 if (IsPrt(swizzleMode
))
1650 // Clear out bits above the block size if prt's are enabled
1651 dataEq
.resize(blockSizeLog2
);
1655 if (IsXor(swizzleMode
))
1659 if (IsThick(resourceType
, swizzleMode
))
1663 dataEq
.copy(xorMask2
, pipeInterleaveLog2
+ numPipeLog2
, 2 * numPipeLog2
);
1665 xorMask
.resize(numPipeLog2
);
1667 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1669 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
]);
1670 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
+ 1]);
1675 // Xor in the bits above the pipe+gpu bits
1676 dataEq
.copy(xorMask
, pipeInterleaveLog2
+ pipeStart
+ numPipeLog2
, numPipeLog2
);
1678 if ((numSamplesLog2
== 0) && (IsPrt(swizzleMode
) == FALSE
))
1682 // if 1xaa and not prt, then xor in the z bits
1684 xorMask2
.resize(numPipeLog2
);
1685 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1687 co
.set('z', numPipeLog2
- 1 - pipeIdx
);
1688 xorMask2
[pipeIdx
].add(co
);
1691 pPipeEq
->xorin(xorMask2
);
1696 pPipeEq
->xorin(xorMask
);
1700 ************************************************************************************************************************
1701 * Gfx9Lib::GetMetaEquation
1704 * Get meta equation for cmask/htile/DCC
1706 * Pointer to a calculated meta equation
1707 ************************************************************************************************************************
1709 const CoordEq
* Gfx9Lib::GetMetaEquation(
1710 const MetaEqParams
& metaEqParams
)
1712 UINT_32 cachedMetaEqIndex
;
1714 for (cachedMetaEqIndex
= 0; cachedMetaEqIndex
< MaxCachedMetaEq
; cachedMetaEqIndex
++)
1716 if (memcmp(&metaEqParams
,
1717 &m_cachedMetaEqKey
[cachedMetaEqIndex
],
1718 static_cast<UINT_32
>(sizeof(metaEqParams
))) == 0)
1724 CoordEq
* pMetaEq
= NULL
;
1726 if (cachedMetaEqIndex
< MaxCachedMetaEq
)
1728 pMetaEq
= &m_cachedMetaEq
[cachedMetaEqIndex
];
1732 m_cachedMetaEqKey
[m_metaEqOverrideIndex
] = metaEqParams
;
1734 pMetaEq
= &m_cachedMetaEq
[m_metaEqOverrideIndex
++];
1736 m_metaEqOverrideIndex
%= MaxCachedMetaEq
;
1738 GenMetaEquation(pMetaEq
,
1739 metaEqParams
.maxMip
,
1740 metaEqParams
.elementBytesLog2
,
1741 metaEqParams
.numSamplesLog2
,
1742 metaEqParams
.metaFlag
,
1743 metaEqParams
.dataSurfaceType
,
1744 metaEqParams
.swizzleMode
,
1745 metaEqParams
.resourceType
,
1746 metaEqParams
.metaBlkWidthLog2
,
1747 metaEqParams
.metaBlkHeightLog2
,
1748 metaEqParams
.metaBlkDepthLog2
,
1749 metaEqParams
.compBlkWidthLog2
,
1750 metaEqParams
.compBlkHeightLog2
,
1751 metaEqParams
.compBlkDepthLog2
);
1758 ************************************************************************************************************************
1759 * Gfx9Lib::GenMetaEquation
1762 * Get meta equation for cmask/htile/DCC
1765 ************************************************************************************************************************
1767 VOID
Gfx9Lib::GenMetaEquation(
1768 CoordEq
* pMetaEq
, ///< [out] meta equation
1769 UINT_32 maxMip
, ///< [in] max mip Id
1770 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1771 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1772 ADDR2_META_FLAGS metaFlag
, ///< [in] meta falg
1773 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1774 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1775 AddrResourceType resourceType
, ///< [in] data surface resource type
1776 UINT_32 metaBlkWidthLog2
, ///< [in] meta block width
1777 UINT_32 metaBlkHeightLog2
, ///< [in] meta block height
1778 UINT_32 metaBlkDepthLog2
, ///< [in] meta block depth
1779 UINT_32 compBlkWidthLog2
, ///< [in] compress block width
1780 UINT_32 compBlkHeightLog2
, ///< [in] compress block height
1781 UINT_32 compBlkDepthLog2
) ///< [in] compress block depth
1784 UINT_32 numPipeTotalLog2
= GetPipeLog2ForMetaAddressing(metaFlag
.pipeAligned
, swizzleMode
);
1785 UINT_32 pipeInterleaveLog2
= m_pipeInterleaveLog2
;
1787 // Get the correct data address and rb equation
1789 GetDataEquation(&dataEq
, dataSurfaceType
, swizzleMode
, resourceType
,
1790 elementBytesLog2
, numSamplesLog2
);
1792 // Get pipe and rb equations
1793 CoordEq pipeEquation
;
1794 GetPipeEquation(&pipeEquation
, &dataEq
, pipeInterleaveLog2
, numPipeTotalLog2
,
1795 numSamplesLog2
, dataSurfaceType
, swizzleMode
, resourceType
);
1796 numPipeTotalLog2
= pipeEquation
.getsize();
1798 if (metaFlag
.linear
)
1800 // Linear metadata supporting was removed for GFX9! No one can use this feature.
1801 ADDR_ASSERT_ALWAYS();
1803 ADDR_ASSERT(dataSurfaceType
== Gfx9DataColor
);
1805 dataEq
.copy(*pMetaEq
);
1807 if (IsLinear(swizzleMode
))
1809 if (metaFlag
.pipeAligned
)
1811 // Remove the pipe bits
1812 INT_32 shift
= static_cast<INT_32
>(numPipeTotalLog2
);
1813 pMetaEq
->shift(-shift
, pipeInterleaveLog2
);
1815 // Divide by comp block size, which for linear (which is always color) is 256 B
1818 if (metaFlag
.pipeAligned
)
1820 // Put pipe bits back in
1821 pMetaEq
->shift(numPipeTotalLog2
, pipeInterleaveLog2
);
1823 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1825 pipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ i
]);
1834 UINT_32 maxCompFragLog2
= static_cast<INT_32
>(m_maxCompFragLog2
);
1835 UINT_32 compFragLog2
=
1836 ((dataSurfaceType
== Gfx9DataColor
) && (numSamplesLog2
> maxCompFragLog2
)) ?
1837 maxCompFragLog2
: numSamplesLog2
;
1839 UINT_32 uncompFragLog2
= numSamplesLog2
- compFragLog2
;
1841 // Make sure the metaaddr is cleared
1843 pMetaEq
->resize(27);
1845 if (IsThick(resourceType
, swizzleMode
))
1847 Coordinate
cx('x', 0);
1848 Coordinate
cy('y', 0);
1849 Coordinate
cz('z', 0);
1853 pMetaEq
->mort3d(cy
, cx
, cz
);
1857 pMetaEq
->mort3d(cx
, cy
, cz
);
1862 Coordinate
cx('x', 0);
1863 Coordinate
cy('y', 0);
1868 pMetaEq
->mort2d(cy
, cx
, compFragLog2
);
1872 pMetaEq
->mort2d(cx
, cy
, compFragLog2
);
1875 //------------------------------------------------------------------------------------------------------------------------
1876 // Put the compressible fragments at the lsb
1877 // the uncompressible frags will be at the msb of the micro address
1878 //------------------------------------------------------------------------------------------------------------------------
1879 for (UINT_32 s
= 0; s
< compFragLog2
; s
++)
1882 (*pMetaEq
)[s
].add(cs
);
1886 // Keep a copy of the pipe equations
1887 CoordEq origPipeEquation
;
1888 pipeEquation
.copy(origPipeEquation
);
1891 // filter out everything under the compressed block size
1892 co
.set('x', compBlkWidthLog2
);
1893 pMetaEq
->Filter('<', co
, 0, 'x');
1894 co
.set('y', compBlkHeightLog2
);
1895 pMetaEq
->Filter('<', co
, 0, 'y');
1896 co
.set('z', compBlkDepthLog2
);
1897 pMetaEq
->Filter('<', co
, 0, 'z');
1899 // For non-color, filter out sample bits
1900 if (dataSurfaceType
!= Gfx9DataColor
)
1903 pMetaEq
->Filter('<', co
, 0, 's');
1906 // filter out everything above the metablock size
1907 co
.set('x', metaBlkWidthLog2
- 1);
1908 pMetaEq
->Filter('>', co
, 0, 'x');
1909 co
.set('y', metaBlkHeightLog2
- 1);
1910 pMetaEq
->Filter('>', co
, 0, 'y');
1911 co
.set('z', metaBlkDepthLog2
- 1);
1912 pMetaEq
->Filter('>', co
, 0, 'z');
1914 // filter out everything above the metablock size for the channel bits
1915 co
.set('x', metaBlkWidthLog2
- 1);
1916 pipeEquation
.Filter('>', co
, 0, 'x');
1917 co
.set('y', metaBlkHeightLog2
- 1);
1918 pipeEquation
.Filter('>', co
, 0, 'y');
1919 co
.set('z', metaBlkDepthLog2
- 1);
1920 pipeEquation
.Filter('>', co
, 0, 'z');
1922 // Make sure we still have the same number of channel bits
1923 if (pipeEquation
.getsize() != numPipeTotalLog2
)
1925 ADDR_ASSERT_ALWAYS();
1928 // Loop through all channel and rb bits,
1929 // and make sure these components exist in the metadata address
1930 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1932 for (UINT_32 j
= pipeEquation
[i
].getsize(); j
> 0; j
--)
1934 if (pMetaEq
->Exists(pipeEquation
[i
][j
- 1]) == FALSE
)
1936 ADDR_ASSERT_ALWAYS();
1941 const UINT_32 numSeLog2
= metaFlag
.rbAligned
? m_seLog2
: 0;
1942 const UINT_32 numRbPeSeLog2
= metaFlag
.rbAligned
? m_rbPerSeLog2
: 0;
1943 const UINT_32 numRbTotalLog2
= numRbPeSeLog2
+ numSeLog2
;
1944 CoordEq origRbEquation
;
1946 GetRbEquation(&origRbEquation
, numRbPeSeLog2
, numSeLog2
);
1948 CoordEq rbEquation
= origRbEquation
;
1950 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1952 for (UINT_32 j
= rbEquation
[i
].getsize(); j
> 0; j
--)
1954 if (pMetaEq
->Exists(rbEquation
[i
][j
- 1]) == FALSE
)
1956 ADDR_ASSERT_ALWAYS();
1961 if (m_settings
.applyAliasFix
)
1966 // Loop through each rb id bit; if it is equal to any of the filtered channel bits, clear it
1967 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1969 for (UINT_32 j
= 0; j
< numPipeTotalLog2
; j
++)
1971 BOOL_32 isRbEquationInPipeEquation
= FALSE
;
1973 if (m_settings
.applyAliasFix
)
1975 CoordTerm filteredPipeEq
;
1976 filteredPipeEq
= pipeEquation
[j
];
1978 filteredPipeEq
.Filter('>', co
, 0, 'z');
1980 isRbEquationInPipeEquation
= (rbEquation
[i
] == filteredPipeEq
);
1984 isRbEquationInPipeEquation
= (rbEquation
[i
] == pipeEquation
[j
]);
1987 if (isRbEquationInPipeEquation
)
1989 rbEquation
[i
].Clear();
1994 bool rbAppendedWithPipeBits
[1 << (MaxSeLog2
+ MaxRbPerSeLog2
)] = {};
1996 // Loop through each bit of the channel, get the smallest coordinate,
1997 // and remove it from the metaaddr, and rb_equation
1998 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
2000 pipeEquation
[i
].getsmallest(co
);
2002 UINT_32 old_size
= pMetaEq
->getsize();
2003 pMetaEq
->Filter('=', co
);
2004 UINT_32 new_size
= pMetaEq
->getsize();
2005 if (new_size
!= old_size
-1)
2007 ADDR_ASSERT_ALWAYS();
2009 pipeEquation
.remove(co
);
2010 for (UINT_32 j
= 0; j
< numRbTotalLog2
; j
++)
2012 if (rbEquation
[j
].remove(co
))
2014 // if we actually removed something from this bit, then add the remaining
2015 // channel bits, as these can be removed for this bit
2016 for (UINT_32 k
= 0; k
< pipeEquation
[i
].getsize(); k
++)
2018 if (pipeEquation
[i
][k
] != co
)
2020 rbEquation
[j
].add(pipeEquation
[i
][k
]);
2021 rbAppendedWithPipeBits
[j
] = true;
2028 // Loop through the rb bits and see what remain;
2029 // filter out the smallest coordinate if it remains
2030 UINT_32 rbBitsLeft
= 0;
2031 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
2033 BOOL_32 isRbEqAppended
= FALSE
;
2035 if (m_settings
.applyAliasFix
)
2037 isRbEqAppended
= (rbEquation
[i
].getsize() > (rbAppendedWithPipeBits
[i
] ? 1 : 0));
2041 isRbEqAppended
= (rbEquation
[i
].getsize() > 0);
2047 rbEquation
[i
].getsmallest(co
);
2048 UINT_32 old_size
= pMetaEq
->getsize();
2049 pMetaEq
->Filter('=', co
);
2050 UINT_32 new_size
= pMetaEq
->getsize();
2051 if (new_size
!= old_size
- 1)
2055 for (UINT_32 j
= i
+ 1; j
< numRbTotalLog2
; j
++)
2057 if (rbEquation
[j
].remove(co
))
2059 // if we actually removed something from this bit, then add the remaining
2060 // rb bits, as these can be removed for this bit
2061 for (UINT_32 k
= 0; k
< rbEquation
[i
].getsize(); k
++)
2063 if (rbEquation
[i
][k
] != co
)
2065 rbEquation
[j
].add(rbEquation
[i
][k
]);
2066 rbAppendedWithPipeBits
[j
] |= rbAppendedWithPipeBits
[i
];
2074 // capture the size of the metaaddr
2075 UINT_32 metaSize
= pMetaEq
->getsize();
2076 // resize to 49 bits...make this a nibble address
2077 pMetaEq
->resize(49);
2078 // Concatenate the macro address above the current address
2079 for (UINT_32 i
= metaSize
, j
= 0; i
< 49; i
++, j
++)
2082 (*pMetaEq
)[i
].add(co
);
2085 // Multiply by meta element size (in nibbles)
2086 if (dataSurfaceType
== Gfx9DataColor
)
2090 else if (dataSurfaceType
== Gfx9DataDepthStencil
)
2095 //------------------------------------------------------------------------------------------
2096 // Note the pipeInterleaveLog2+1 is because address is a nibble address
2097 // Shift up from pipe interleave number of channel
2098 // and rb bits left, and uncompressed fragments
2099 //------------------------------------------------------------------------------------------
2101 pMetaEq
->shift(numPipeTotalLog2
+ rbBitsLeft
+ uncompFragLog2
, pipeInterleaveLog2
+ 1);
2103 // Put in the channel bits
2104 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
2106 origPipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+1 + i
]);
2109 // Put in remaining rb bits
2110 for (UINT_32 i
= 0, j
= 0; j
< rbBitsLeft
; i
= (i
+ 1) % numRbTotalLog2
)
2112 BOOL_32 isRbEqAppended
= FALSE
;
2114 if (m_settings
.applyAliasFix
)
2116 isRbEqAppended
= (rbEquation
[i
].getsize() > (rbAppendedWithPipeBits
[i
] ? 1 : 0));
2120 isRbEqAppended
= (rbEquation
[i
].getsize() > 0);
2125 origRbEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ j
]);
2126 // Mark any rb bit we add in to the rb mask
2131 //------------------------------------------------------------------------------------------
2132 // Put in the uncompressed fragment bits
2133 //------------------------------------------------------------------------------------------
2134 for (UINT_32 i
= 0; i
< uncompFragLog2
; i
++)
2136 co
.set('s', compFragLog2
+ i
);
2137 (*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ rbBitsLeft
+ i
].add(co
);
2143 ************************************************************************************************************************
2144 * Gfx9Lib::IsEquationSupported
2147 * Check if equation is supported for given swizzle mode and resource type.
2151 ************************************************************************************************************************
2153 BOOL_32
Gfx9Lib::IsEquationSupported(
2154 AddrResourceType rsrcType
,
2155 AddrSwizzleMode swMode
,
2156 UINT_32 elementBytesLog2
) const
2158 BOOL_32 supported
= (elementBytesLog2
< MaxElementBytesLog2
) &&
2159 (IsLinear(swMode
) == FALSE
) &&
2160 (((IsTex2d(rsrcType
) == TRUE
) &&
2161 ((elementBytesLog2
< 4) ||
2162 ((IsRotateSwizzle(swMode
) == FALSE
) &&
2163 (IsZOrderSwizzle(swMode
) == FALSE
)))) ||
2164 ((IsTex3d(rsrcType
) == TRUE
) &&
2165 (IsRotateSwizzle(swMode
) == FALSE
) &&
2166 (IsBlock256b(swMode
) == FALSE
)));
2172 ************************************************************************************************************************
2173 * Gfx9Lib::InitEquationTable
2176 * Initialize Equation table.
2180 ************************************************************************************************************************
2182 VOID
Gfx9Lib::InitEquationTable()
2184 memset(m_equationTable
, 0, sizeof(m_equationTable
));
2186 // Loop all possible resource type (2D/3D)
2187 for (UINT_32 rsrcTypeIdx
= 0; rsrcTypeIdx
< MaxRsrcType
; rsrcTypeIdx
++)
2189 AddrResourceType rsrcType
= static_cast<AddrResourceType
>(rsrcTypeIdx
+ ADDR_RSRC_TEX_2D
);
2191 // Loop all possible swizzle mode
2192 for (UINT_32 swModeIdx
= 0; swModeIdx
< MaxSwMode
; swModeIdx
++)
2194 AddrSwizzleMode swMode
= static_cast<AddrSwizzleMode
>(swModeIdx
);
2196 // Loop all possible bpp
2197 for (UINT_32 bppIdx
= 0; bppIdx
< MaxElementBytesLog2
; bppIdx
++)
2199 UINT_32 equationIndex
= ADDR_INVALID_EQUATION_INDEX
;
2201 // Check if the input is supported
2202 if (IsEquationSupported(rsrcType
, swMode
, bppIdx
))
2204 ADDR_EQUATION equation
;
2205 ADDR_E_RETURNCODE retCode
;
2207 memset(&equation
, 0, sizeof(ADDR_EQUATION
));
2209 // Generate the equation
2210 if (IsBlock256b(swMode
) && IsTex2d(rsrcType
))
2212 retCode
= ComputeBlock256Equation(rsrcType
, swMode
, bppIdx
, &equation
);
2214 else if (IsThin(rsrcType
, swMode
))
2216 retCode
= ComputeThinEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2220 retCode
= ComputeThickEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2223 // Only fill the equation into the table if the return code is ADDR_OK,
2224 // otherwise if the return code is not ADDR_OK, it indicates this is not
2225 // a valid input, we do nothing but just fill invalid equation index
2226 // into the lookup table.
2227 if (retCode
== ADDR_OK
)
2229 equationIndex
= m_numEquations
;
2230 ADDR_ASSERT(equationIndex
< EquationTableSize
);
2232 m_equationTable
[equationIndex
] = equation
;
2238 ADDR_ASSERT_ALWAYS();
2242 // Fill the index into the lookup table, if the combination is not supported
2243 // fill the invalid equation index
2244 m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][bppIdx
] = equationIndex
;
2251 ************************************************************************************************************************
2252 * Gfx9Lib::HwlGetEquationIndex
2255 * Interface function stub of GetEquationIndex
2259 ************************************************************************************************************************
2261 UINT_32
Gfx9Lib::HwlGetEquationIndex(
2262 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
2263 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
2266 AddrResourceType rsrcType
= pIn
->resourceType
;
2267 AddrSwizzleMode swMode
= pIn
->swizzleMode
;
2268 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
2269 UINT_32 index
= ADDR_INVALID_EQUATION_INDEX
;
2271 if (IsEquationSupported(rsrcType
, swMode
, elementBytesLog2
))
2273 UINT_32 rsrcTypeIdx
= static_cast<UINT_32
>(rsrcType
) - 1;
2274 UINT_32 swModeIdx
= static_cast<UINT_32
>(swMode
);
2276 index
= m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][elementBytesLog2
];
2279 if (pOut
->pMipInfo
!= NULL
)
2281 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
2283 pOut
->pMipInfo
[i
].equationIndex
= index
;
2291 ************************************************************************************************************************
2292 * Gfx9Lib::HwlComputeBlock256Equation
2295 * Interface function stub of ComputeBlock256Equation
2299 ************************************************************************************************************************
2301 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeBlock256Equation(
2302 AddrResourceType rsrcType
,
2303 AddrSwizzleMode swMode
,
2304 UINT_32 elementBytesLog2
,
2305 ADDR_EQUATION
* pEquation
) const
2307 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2309 pEquation
->numBits
= 8;
2312 for (; i
< elementBytesLog2
; i
++)
2314 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2317 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2319 const UINT_32 maxBitsUsed
= 4;
2320 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2321 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2323 for (i
= 0; i
< maxBitsUsed
; i
++)
2325 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2326 InitChannel(1, 1, i
, &y
[i
]);
2329 if (IsStandardSwizzle(rsrcType
, swMode
))
2331 switch (elementBytesLog2
)
2374 ADDR_ASSERT_ALWAYS();
2375 ret
= ADDR_INVALIDPARAMS
;
2379 else if (IsDisplaySwizzle(rsrcType
, swMode
))
2381 switch (elementBytesLog2
)
2424 ADDR_ASSERT_ALWAYS();
2425 ret
= ADDR_INVALIDPARAMS
;
2429 else if (IsRotateSwizzle(swMode
))
2431 switch (elementBytesLog2
)
2468 ADDR_ASSERT_ALWAYS();
2470 ret
= ADDR_INVALIDPARAMS
;
2476 ADDR_ASSERT_ALWAYS();
2477 ret
= ADDR_INVALIDPARAMS
;
2483 MAYBE_UNUSED Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2484 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 0)) ==
2485 (microBlockDim
.w
* (1 << elementBytesLog2
)));
2486 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 1)) == microBlockDim
.h
);
2493 ************************************************************************************************************************
2494 * Gfx9Lib::HwlComputeThinEquation
2497 * Interface function stub of ComputeThinEquation
2501 ************************************************************************************************************************
2503 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThinEquation(
2504 AddrResourceType rsrcType
,
2505 AddrSwizzleMode swMode
,
2506 UINT_32 elementBytesLog2
,
2507 ADDR_EQUATION
* pEquation
) const
2509 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2511 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2513 UINT_32 maxXorBits
= blockSizeLog2
;
2514 if (IsNonPrtXor(swMode
))
2516 // For non-prt-xor, maybe need to initialize some more bits for xor
2517 // The highest xor bit used in equation will be max the following 3 items:
2518 // 1. m_pipeInterleaveLog2 + 2 * pipeXorBits
2519 // 2. m_pipeInterleaveLog2 + pipeXorBits + 2 * bankXorBits
2522 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 2 * GetPipeXorBits(blockSizeLog2
));
2523 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2524 GetPipeXorBits(blockSizeLog2
) +
2525 2 * GetBankXorBits(blockSizeLog2
));
2528 const UINT_32 maxBitsUsed
= 14;
2529 ADDR_ASSERT((2 * maxBitsUsed
) >= maxXorBits
);
2530 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2531 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2533 const UINT_32 extraXorBits
= 16;
2534 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2535 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2537 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2539 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2540 InitChannel(1, 1, i
, &y
[i
]);
2543 ADDR_CHANNEL_SETTING
* pixelBit
= pEquation
->addr
;
2545 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2547 InitChannel(1, 0 , i
, &pixelBit
[i
]);
2552 UINT_32 lowBits
= 0;
2554 if (IsZOrderSwizzle(swMode
))
2556 if (elementBytesLog2
<= 3)
2558 for (UINT_32 i
= elementBytesLog2
; i
< 6; i
++)
2560 pixelBit
[i
] = (((i
- elementBytesLog2
) & 1) == 0) ? x
[xIdx
++] : y
[yIdx
++];
2567 ret
= ADDR_INVALIDPARAMS
;
2572 ret
= HwlComputeBlock256Equation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
2576 Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2577 xIdx
= Log2(microBlockDim
.w
);
2578 yIdx
= Log2(microBlockDim
.h
);
2585 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2587 pixelBit
[i
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2590 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2592 xorExtra
[i
- blockSizeLog2
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2598 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2599 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2601 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2602 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2604 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2606 UINT_32 xor1BitPos
= pipeStart
+ 2 * pipeXorBits
- 1 - i
;
2607 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2608 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2610 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2613 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2615 UINT_32 xor1BitPos
= bankStart
+ 2 * bankXorBits
- 1 - i
;
2616 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2617 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2619 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2622 if (IsPrt(swMode
) == FALSE
)
2624 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2626 InitChannel(1, 2, pipeXorBits
- i
- 1, &pEquation
->xor2
[pipeStart
+ i
]);
2629 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2631 InitChannel(1, 2, bankXorBits
- i
- 1 + pipeXorBits
, &pEquation
->xor2
[bankStart
+ i
]);
2636 pEquation
->numBits
= blockSizeLog2
;
2643 ************************************************************************************************************************
2644 * Gfx9Lib::HwlComputeThickEquation
2647 * Interface function stub of ComputeThickEquation
2651 ************************************************************************************************************************
2653 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThickEquation(
2654 AddrResourceType rsrcType
,
2655 AddrSwizzleMode swMode
,
2656 UINT_32 elementBytesLog2
,
2657 ADDR_EQUATION
* pEquation
) const
2659 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2661 ADDR_ASSERT(IsTex3d(rsrcType
));
2663 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2665 UINT_32 maxXorBits
= blockSizeLog2
;
2666 if (IsNonPrtXor(swMode
))
2668 // For non-prt-xor, maybe need to initialize some more bits for xor
2669 // The highest xor bit used in equation will be max the following 3:
2670 // 1. m_pipeInterleaveLog2 + 3 * pipeXorBits
2671 // 2. m_pipeInterleaveLog2 + pipeXorBits + 3 * bankXorBits
2674 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 3 * GetPipeXorBits(blockSizeLog2
));
2675 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2676 GetPipeXorBits(blockSizeLog2
) +
2677 3 * GetBankXorBits(blockSizeLog2
));
2680 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2682 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2685 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2687 const UINT_32 maxBitsUsed
= 12;
2688 ADDR_ASSERT((3 * maxBitsUsed
) >= maxXorBits
);
2689 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2690 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2691 ADDR_CHANNEL_SETTING z
[maxBitsUsed
] = {};
2693 const UINT_32 extraXorBits
= 24;
2694 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2695 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2697 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2699 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2700 InitChannel(1, 1, i
, &y
[i
]);
2701 InitChannel(1, 2, i
, &z
[i
]);
2704 if (IsZOrderSwizzle(swMode
))
2706 switch (elementBytesLog2
)
2759 ADDR_ASSERT_ALWAYS();
2760 ret
= ADDR_INVALIDPARAMS
;
2764 else if (IsStandardSwizzle(rsrcType
, swMode
))
2766 switch (elementBytesLog2
)
2819 ADDR_ASSERT_ALWAYS();
2820 ret
= ADDR_INVALIDPARAMS
;
2826 ADDR_ASSERT_ALWAYS();
2827 ret
= ADDR_INVALIDPARAMS
;
2832 Dim3d microBlockDim
= Block1K_3d
[elementBytesLog2
];
2833 UINT_32 xIdx
= Log2(microBlockDim
.w
);
2834 UINT_32 yIdx
= Log2(microBlockDim
.h
);
2835 UINT_32 zIdx
= Log2(microBlockDim
.d
);
2837 pixelBit
= pEquation
->addr
;
2839 const UINT_32 lowBits
= 10;
2840 ADDR_ASSERT(pEquation
->addr
[lowBits
- 1].valid
== 1);
2841 ADDR_ASSERT(pEquation
->addr
[lowBits
].valid
== 0);
2843 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2847 pixelBit
[i
] = x
[xIdx
++];
2849 else if ((i
% 3) == 1)
2851 pixelBit
[i
] = z
[zIdx
++];
2855 pixelBit
[i
] = y
[yIdx
++];
2859 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2863 xorExtra
[i
- blockSizeLog2
] = x
[xIdx
++];
2865 else if ((i
% 3) == 1)
2867 xorExtra
[i
- blockSizeLog2
] = z
[zIdx
++];
2871 xorExtra
[i
- blockSizeLog2
] = y
[yIdx
++];
2878 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2879 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2880 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2882 UINT_32 xor1BitPos
= pipeStart
+ (3 * pipeXorBits
) - 1 - (2 * i
);
2883 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2884 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2886 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2888 UINT_32 xor2BitPos
= pipeStart
+ (3 * pipeXorBits
) - 2 - (2 * i
);
2889 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2890 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2892 InitChannel(&pEquation
->xor2
[pipeStart
+ i
], pXor2Src
);
2895 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2896 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2897 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2899 UINT_32 xor1BitPos
= bankStart
+ (3 * bankXorBits
) - 1 - (2 * i
);
2900 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2901 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2903 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2905 UINT_32 xor2BitPos
= bankStart
+ (3 * bankXorBits
) - 2 - (2 * i
);
2906 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2907 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2909 InitChannel(&pEquation
->xor2
[bankStart
+ i
], pXor2Src
);
2913 pEquation
->numBits
= blockSizeLog2
;
2920 ************************************************************************************************************************
2921 * Gfx9Lib::IsValidDisplaySwizzleMode
2924 * Check if a swizzle mode is supported by display engine
2927 * TRUE is swizzle mode is supported by display engine
2928 ************************************************************************************************************************
2930 BOOL_32
Gfx9Lib::IsValidDisplaySwizzleMode(
2931 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
2933 BOOL_32 support
= FALSE
;
2935 const AddrResourceType resourceType
= pIn
->resourceType
;
2937 const AddrSwizzleMode swizzleMode
= pIn
->swizzleMode
;
2939 if (m_settings
.isDce12
)
2941 switch (swizzleMode
)
2943 case ADDR_SW_256B_D
:
2944 case ADDR_SW_256B_R
:
2945 support
= (pIn
->bpp
== 32);
2948 case ADDR_SW_LINEAR
:
2951 case ADDR_SW_64KB_D
:
2952 case ADDR_SW_64KB_R
:
2955 case ADDR_SW_4KB_D_X
:
2956 case ADDR_SW_4KB_R_X
:
2957 case ADDR_SW_64KB_D_X
:
2958 case ADDR_SW_64KB_R_X
:
2959 case ADDR_SW_VAR_D_X
:
2960 case ADDR_SW_VAR_R_X
:
2961 support
= (pIn
->bpp
<= 64);
2968 else if (m_settings
.isDcn1
)
2970 switch (swizzleMode
)
2973 case ADDR_SW_64KB_D
:
2975 case ADDR_SW_64KB_D_T
:
2976 case ADDR_SW_4KB_D_X
:
2977 case ADDR_SW_64KB_D_X
:
2978 case ADDR_SW_VAR_D_X
:
2979 support
= (pIn
->bpp
== 64);
2982 case ADDR_SW_LINEAR
:
2984 case ADDR_SW_64KB_S
:
2986 case ADDR_SW_64KB_S_T
:
2987 case ADDR_SW_4KB_S_X
:
2988 case ADDR_SW_64KB_S_X
:
2989 case ADDR_SW_VAR_S_X
:
2990 support
= (pIn
->bpp
<= 64);
2999 ADDR_NOT_IMPLEMENTED();
3006 ************************************************************************************************************************
3007 * Gfx9Lib::HwlComputePipeBankXor
3010 * Generate a PipeBankXor value to be ORed into bits above pipeInterleaveBits of address
3014 ************************************************************************************************************************
3016 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputePipeBankXor(
3017 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
3018 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
) const
3020 if (IsXor(pIn
->swizzleMode
))
3022 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3023 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3024 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3026 UINT_32 pipeXor
= 0;
3027 UINT_32 bankXor
= 0;
3029 const UINT_32 bankMask
= (1 << bankBits
) - 1;
3030 const UINT_32 index
= pIn
->surfIndex
& bankMask
;
3032 const UINT_32 bpp
= pIn
->flags
.fmask
?
3033 GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
) : GetElemLib()->GetBitsPerPixel(pIn
->format
);
3036 static const UINT_32 BankXorSmallBpp
[] = {0, 7, 4, 3, 8, 15, 12, 11, 1, 6, 5, 2, 9, 14, 13, 10};
3037 static const UINT_32 BankXorLargeBpp
[] = {0, 7, 8, 15, 4, 3, 12, 11, 1, 6, 9, 14, 5, 2, 13, 10};
3039 bankXor
= (bpp
<= 32) ? BankXorSmallBpp
[index
] : BankXorLargeBpp
[index
];
3041 else if (bankBits
> 0)
3043 UINT_32 bankIncrease
= (1 << (bankBits
- 1)) - 1;
3044 bankIncrease
= (bankIncrease
== 0) ? 1 : bankIncrease
;
3045 bankXor
= (index
* bankIncrease
) & bankMask
;
3048 pOut
->pipeBankXor
= (bankXor
<< pipeBits
) | pipeXor
;
3052 pOut
->pipeBankXor
= 0;
3059 ************************************************************************************************************************
3060 * Gfx9Lib::HwlComputeSlicePipeBankXor
3063 * Generate slice PipeBankXor value based on base PipeBankXor value and slice id
3067 ************************************************************************************************************************
3069 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSlicePipeBankXor(
3070 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
3071 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
) const
3073 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3074 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3075 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3077 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
3078 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
3080 pOut
->pipeBankXor
= pIn
->basePipeBankXor
^ (pipeXor
| (bankXor
<< pipeBits
));
3086 ************************************************************************************************************************
3087 * Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern
3090 * Compute sub resource offset to support swizzle pattern
3094 ************************************************************************************************************************
3096 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern(
3097 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
3098 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
) const
3100 ADDR_ASSERT(IsThin(pIn
->resourceType
, pIn
->swizzleMode
));
3102 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3103 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3104 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3105 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
3106 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
3107 UINT_32 pipeBankXor
= ((pipeXor
| (bankXor
<< pipeBits
)) ^ (pIn
->pipeBankXor
)) << m_pipeInterleaveLog2
;
3109 pOut
->offset
= pIn
->slice
* pIn
->sliceSize
+
3110 pIn
->macroBlockOffset
+
3111 (pIn
->mipTailOffset
^ pipeBankXor
) -
3112 static_cast<UINT_64
>(pipeBankXor
);
3117 ************************************************************************************************************************
3118 * Gfx9Lib::HwlComputeSurfaceInfoSanityCheck
3121 * Compute surface info sanity check
3125 ************************************************************************************************************************
3127 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoSanityCheck(
3128 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3130 BOOL_32 invalid
= FALSE
;
3132 if ((pIn
->bpp
> 128) || (pIn
->width
== 0) || (pIn
->numFrags
> 8) || (pIn
->numSamples
> 16))
3136 else if ((pIn
->swizzleMode
>= ADDR_SW_MAX_TYPE
) ||
3137 (pIn
->resourceType
>= ADDR_RSRC_MAX_TYPE
))
3142 BOOL_32 mipmap
= (pIn
->numMipLevels
> 1);
3143 BOOL_32 msaa
= (pIn
->numFrags
> 1);
3145 ADDR2_SURFACE_FLAGS flags
= pIn
->flags
;
3146 BOOL_32 zbuffer
= (flags
.depth
|| flags
.stencil
);
3147 BOOL_32 color
= flags
.color
;
3148 BOOL_32 display
= flags
.display
|| flags
.rotated
;
3150 AddrResourceType rsrcType
= pIn
->resourceType
;
3151 BOOL_32 tex3d
= IsTex3d(rsrcType
);
3152 BOOL_32 thin3d
= tex3d
&& flags
.view3dAs2dArray
;
3153 AddrSwizzleMode swizzle
= pIn
->swizzleMode
;
3154 BOOL_32 linear
= IsLinear(swizzle
);
3155 BOOL_32 blk256B
= IsBlock256b(swizzle
);
3156 BOOL_32 blkVar
= IsBlockVariable(swizzle
);
3157 BOOL_32 isNonPrtXor
= IsNonPrtXor(swizzle
);
3158 BOOL_32 prt
= flags
.prt
;
3159 BOOL_32 stereo
= flags
.qbStereo
;
3161 if (invalid
== FALSE
)
3163 if ((pIn
->numFrags
> 1) &&
3164 (GetBlockSize(swizzle
) < (m_pipeInterleaveBytes
* pIn
->numFrags
)))
3166 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3171 if (invalid
== FALSE
)
3175 case ADDR_RSRC_TEX_1D
:
3176 invalid
= msaa
|| zbuffer
|| display
|| (linear
== FALSE
) || stereo
;
3178 case ADDR_RSRC_TEX_2D
:
3179 invalid
= (msaa
&& mipmap
) || (stereo
&& msaa
) || (stereo
&& mipmap
);
3181 case ADDR_RSRC_TEX_3D
:
3182 invalid
= msaa
|| zbuffer
|| display
|| stereo
;
3190 if (invalid
== FALSE
)
3194 invalid
= (IsValidDisplaySwizzleMode(pIn
) == FALSE
);
3198 if (invalid
== FALSE
)
3202 invalid
= ((ADDR_RSRC_TEX_1D
!= rsrcType
) && prt
) ||
3203 zbuffer
|| msaa
|| (pIn
->bpp
== 0) || ((pIn
->bpp
% 8) != 0);
3207 if (blk256B
|| blkVar
|| isNonPrtXor
)
3212 invalid
= invalid
|| zbuffer
|| tex3d
|| mipmap
|| msaa
;
3216 if (invalid
== FALSE
)
3218 if (IsZOrderSwizzle(swizzle
))
3220 invalid
= (color
&& msaa
) || thin3d
;
3222 else if (IsStandardSwizzle(swizzle
))
3224 invalid
= zbuffer
|| thin3d
;
3226 else if (IsDisplaySwizzle(swizzle
))
3228 invalid
= zbuffer
|| (prt
&& (ADDR_RSRC_TEX_3D
== rsrcType
));
3230 else if (IsRotateSwizzle(swizzle
))
3232 invalid
= zbuffer
|| (pIn
->bpp
> 64) || tex3d
;
3236 ADDR_ASSERT(!"invalid swizzle mode");
3243 ADDR_ASSERT(invalid
== FALSE
);
3245 return invalid
? ADDR_INVALIDPARAMS
: ADDR_OK
;
3249 ************************************************************************************************************************
3250 * Gfx9Lib::HwlGetPreferredSurfaceSetting
3253 * Internal function to get suggested surface information for cliet to use
3257 ************************************************************************************************************************
3259 ADDR_E_RETURNCODE
Gfx9Lib::HwlGetPreferredSurfaceSetting(
3260 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
3261 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const
3263 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3264 ElemLib
* pElemLib
= GetElemLib();
3266 UINT_32 bpp
= pIn
->bpp
;
3267 UINT_32 width
= pIn
->width
;
3268 UINT_32 height
= pIn
->height
;
3269 UINT_32 numSamples
= Max(pIn
->numSamples
, 1u);
3270 UINT_32 numFrags
= (pIn
->numFrags
== 0) ? numSamples
: pIn
->numFrags
;
3272 if (pIn
->flags
.fmask
)
3274 bpp
= GetFmaskBpp(numSamples
, numFrags
);
3277 pOut
->resourceType
= ADDR_RSRC_TEX_2D
;
3281 // Set format to INVALID will skip this conversion
3282 if (pIn
->format
!= ADDR_FMT_INVALID
)
3284 UINT_32 expandX
, expandY
;
3286 // Don't care for this case
3287 ElemMode elemMode
= ADDR_UNCOMPRESSED
;
3289 // Get compression/expansion factors and element mode which indicates compression/expansion
3290 bpp
= pElemLib
->GetBitsPerPixel(pIn
->format
,
3295 UINT_32 basePitch
= 0;
3296 GetElemLib()->AdjustSurfaceInfo(elemMode
,
3305 // The output may get changed for volume(3D) texture resource in future
3306 pOut
->resourceType
= pIn
->resourceType
;
3309 const UINT_32 numSlices
= Max(pIn
->numSlices
, 1u);
3310 const UINT_32 numMipLevels
= Max(pIn
->numMipLevels
, 1u);
3311 const BOOL_32 msaa
= (numFrags
> 1) || (numSamples
> 1);
3312 const BOOL_32 displayRsrc
= pIn
->flags
.display
|| pIn
->flags
.rotated
;
3314 // Forbid swizzle mode(s) by client setting, for simplicity we never allow VAR swizzle mode for GFX9
3315 ADDR2_SWMODE_SET allowedSwModeSet
= {};
3316 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.linear
? 0 : Gfx9LinearSwModeMask
;
3317 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.micro
? 0 : Gfx9Blk256BSwModeMask
;
3318 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.macro4KB
? 0 : Gfx9Blk4KBSwModeMask
;
3319 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.macro64KB
? 0 : Gfx9Blk64KBSwModeMask
;
3321 if (pIn
->preferredSwSet
.value
!= 0)
3323 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_Z
? ~0 : ~Gfx9ZSwModeMask
;
3324 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_S
? ~0 : ~Gfx9StandardSwModeMask
;
3325 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_D
? ~0 : ~Gfx9DisplaySwModeMask
;
3326 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_R
? ~0 : ~Gfx9RotateSwModeMask
;
3331 allowedSwModeSet
.value
&= ~Gfx9XorSwModeMask
;
3334 if (pIn
->maxAlign
> 0)
3336 if (pIn
->maxAlign
< GetBlockSize(ADDR_SW_64KB
))
3338 allowedSwModeSet
.value
&= ~Gfx9Blk64KBSwModeMask
;
3341 if (pIn
->maxAlign
< GetBlockSize(ADDR_SW_4KB
))
3343 allowedSwModeSet
.value
&= ~Gfx9Blk4KBSwModeMask
;
3346 if (pIn
->maxAlign
< GetBlockSize(ADDR_SW_256B
))
3348 allowedSwModeSet
.value
&= ~Gfx9Blk256BSwModeMask
;
3352 // Filter out invalid swizzle mode(s) by image attributes and HW restrictions
3353 switch (pOut
->resourceType
)
3355 case ADDR_RSRC_TEX_1D
:
3356 allowedSwModeSet
.value
&= Gfx9Rsrc1dSwModeMask
;
3359 case ADDR_RSRC_TEX_2D
:
3360 allowedSwModeSet
.value
&= pIn
->flags
.prt
? Gfx9Rsrc2dPrtSwModeMask
: Gfx9Rsrc2dSwModeMask
;
3364 allowedSwModeSet
.value
&= ~(Gfx9RotateSwModeMask
| Gfx9ZSwModeMask
);
3368 case ADDR_RSRC_TEX_3D
:
3369 allowedSwModeSet
.value
&= pIn
->flags
.prt
? Gfx9Rsrc3dPrtSwModeMask
: Gfx9Rsrc3dSwModeMask
;
3371 if ((numMipLevels
> 1) && (numSlices
>= width
) && (numSlices
>= height
))
3373 // SW_*_D for 3D mipmaps (maxmip > 0) is only supported for Xmajor or Ymajor mipmap
3374 // When depth (Z) is the maximum dimension then must use one of the SW_*_S
3375 // or SW_*_Z modes if mipmapping is desired on a 3D surface
3376 allowedSwModeSet
.value
&= ~Gfx9DisplaySwModeMask
;
3379 if ((bpp
== 128) && pIn
->flags
.color
)
3381 allowedSwModeSet
.value
&= ~Gfx9StandardSwModeMask
;
3384 if (pIn
->flags
.view3dAs2dArray
)
3386 allowedSwModeSet
.value
&= Gfx9Rsrc3dThinSwModeMask
| Gfx9LinearSwModeMask
;
3391 ADDR_ASSERT_ALWAYS();
3392 allowedSwModeSet
.value
= 0;
3396 if (pIn
->format
== ADDR_FMT_32_32_32
)
3398 allowedSwModeSet
.value
&= Gfx9LinearSwModeMask
;
3401 if (ElemLib::IsBlockCompressed(pIn
->format
))
3403 if (pIn
->flags
.texture
)
3405 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
| Gfx9DisplaySwModeMask
;
3409 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
| Gfx9DisplaySwModeMask
| Gfx9LinearSwModeMask
;
3413 if (ElemLib::IsMacroPixelPacked(pIn
->format
) ||
3414 (msaa
&& ((bpp
> 32) || pIn
->flags
.color
|| pIn
->flags
.unordered
)))
3416 allowedSwModeSet
.value
&= ~Gfx9ZSwModeMask
;
3419 if (pIn
->flags
.fmask
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
)
3421 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3423 if (pIn
->flags
.noMetadata
== FALSE
)
3425 if (pIn
->flags
.depth
&&
3426 pIn
->flags
.texture
&&
3427 (((bpp
== 16) && (numFrags
>= 4)) || ((bpp
== 32) && (numFrags
>= 2))))
3429 // When _X/_T swizzle mode was used for MSAA depth texture, TC will get zplane
3430 // equation from wrong address within memory range a tile covered and use the
3431 // garbage data for compressed Z reading which finally leads to corruption.
3432 allowedSwModeSet
.value
&= ~Gfx9XorSwModeMask
;
3435 if (m_settings
.htileCacheRbConflict
&&
3436 (pIn
->flags
.depth
|| pIn
->flags
.stencil
) &&
3438 (pIn
->flags
.metaRbUnaligned
== FALSE
) &&
3439 (pIn
->flags
.metaPipeUnaligned
== FALSE
))
3441 // Z_X 2D array with Rb/Pipe aligned HTile won't have metadata cache coherency
3442 allowedSwModeSet
.value
&= ~Gfx9XSwModeMask
;
3449 allowedSwModeSet
.value
&= Gfx9MsaaSwModeMask
;
3452 if ((numFrags
> 1) &&
3453 (GetBlockSize(ADDR_SW_4KB
) < (m_pipeInterleaveBytes
* numFrags
)))
3455 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3456 allowedSwModeSet
.value
&= Gfx9Blk64KBSwModeMask
;
3459 if (numMipLevels
> 1)
3461 allowedSwModeSet
.value
&= ~Gfx9Blk256BSwModeMask
;
3466 if (m_settings
.isDce12
)
3468 allowedSwModeSet
.value
&= (bpp
== 32) ? Dce12Bpp32SwModeMask
: Dce12NonBpp32SwModeMask
;
3470 else if (m_settings
.isDcn1
)
3472 allowedSwModeSet
.value
&= (bpp
== 64) ? Dcn1Bpp64SwModeMask
: Dcn1NonBpp64SwModeMask
;
3476 ADDR_NOT_IMPLEMENTED();
3480 if (allowedSwModeSet
.value
!= 0)
3483 // Post sanity check, at least AddrLib should accept the output generated by its own
3484 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {};
3485 localIn
.flags
= pIn
->flags
;
3486 localIn
.resourceType
= pOut
->resourceType
;
3487 localIn
.format
= pIn
->format
;
3489 localIn
.width
= width
;
3490 localIn
.height
= height
;
3491 localIn
.numSlices
= numSlices
;
3492 localIn
.numMipLevels
= numMipLevels
;
3493 localIn
.numSamples
= numSamples
;
3494 localIn
.numFrags
= numFrags
;
3496 UINT_32 validateSwModeSet
= allowedSwModeSet
.value
;
3497 for (UINT_32 i
= 0; validateSwModeSet
!= 0; i
++)
3499 if (validateSwModeSet
& 1)
3501 localIn
.swizzleMode
= static_cast<AddrSwizzleMode
>(i
);
3502 HwlComputeSurfaceInfoSanityCheck(&localIn
);
3505 validateSwModeSet
>>= 1;
3509 pOut
->validSwModeSet
= allowedSwModeSet
;
3510 pOut
->canXor
= (allowedSwModeSet
.value
& Gfx9XorSwModeMask
) ? TRUE
: FALSE
;
3511 pOut
->validBlockSet
= GetAllowedBlockSet(allowedSwModeSet
);
3512 pOut
->validSwTypeSet
= GetAllowedSwSet(allowedSwModeSet
);
3514 pOut
->clientPreferredSwSet
= pIn
->preferredSwSet
;
3516 if (pOut
->clientPreferredSwSet
.value
== 0)
3518 pOut
->clientPreferredSwSet
.value
= AddrSwSetAll
;
3521 if (allowedSwModeSet
.value
== Gfx9LinearSwModeMask
)
3523 pOut
->swizzleMode
= ADDR_SW_LINEAR
;
3527 // Always ignore linear swizzle mode if there is other choice.
3528 allowedSwModeSet
.swLinear
= 0;
3530 ADDR2_BLOCK_SET allowedBlockSet
= GetAllowedBlockSet(allowedSwModeSet
);
3532 // Determine block size if there is 2 or more block type candidates
3533 if (IsPow2(allowedBlockSet
.value
) == FALSE
)
3535 const AddrSwizzleMode swMode
[AddrBlockMaxTiledType
] = {ADDR_SW_256B
, ADDR_SW_4KB
, ADDR_SW_64KB
};
3536 Dim3d blkDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}};
3537 Dim3d padDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}};
3538 UINT_64 padSize
[AddrBlockMaxTiledType
] = {0};
3540 const UINT_32 ratioLow
= pIn
->flags
.minimizeAlign
? 1 : (pIn
->flags
.opt4space
? 3 : 2);
3541 const UINT_32 ratioHi
= pIn
->flags
.minimizeAlign
? 1 : (pIn
->flags
.opt4space
? 2 : 1);
3542 const UINT_64 sizeAlignInElement
= Max(NextPow2(pIn
->minSizeAlign
) / (bpp
>> 3), 1u);
3543 UINT_32 minSizeBlk
= AddrBlockMicro
;
3544 UINT_64 minSize
= 0;
3546 for (UINT_32 i
= AddrBlockMicro
; i
< AddrBlockMaxTiledType
; i
++)
3548 if (allowedBlockSet
.value
& (1 << i
))
3550 ComputeBlockDimensionForSurf(&blkDim
[i
].w
,
3560 blkDim
[i
].w
= PowTwoAlign(blkDim
[i
].w
, 32);
3563 padSize
[i
] = ComputePadSize(&blkDim
[i
], width
, height
, numSlices
, &padDim
[i
]);
3564 padSize
[i
] = PowTwoAlign(padSize
[i
], sizeAlignInElement
);
3566 if ((minSize
== 0) ||
3567 ((padSize
[i
] * ratioHi
) <= (minSize
* ratioLow
)))
3569 minSize
= padSize
[i
];
3575 if ((allowedBlockSet
.micro
== TRUE
) &&
3576 (width
<= blkDim
[AddrBlockMicro
].w
) &&
3577 (height
<= blkDim
[AddrBlockMicro
].h
) &&
3578 (NextPow2(pIn
->minSizeAlign
) <= GetBlockSize(ADDR_SW_256B
)))
3580 minSizeBlk
= AddrBlockMicro
;
3583 if (minSizeBlk
== AddrBlockMicro
)
3585 allowedSwModeSet
.value
&= Gfx9Blk256BSwModeMask
;
3587 else if (minSizeBlk
== AddrBlock4KB
)
3589 allowedSwModeSet
.value
&= Gfx9Blk4KBSwModeMask
;
3593 ADDR_ASSERT(minSizeBlk
== AddrBlock64KB
);
3594 allowedSwModeSet
.value
&= Gfx9Blk64KBSwModeMask
;
3598 // Block type should be determined.
3599 ADDR_ASSERT(IsPow2(GetAllowedBlockSet(allowedSwModeSet
).value
));
3601 ADDR2_SWTYPE_SET allowedSwSet
= GetAllowedSwSet(allowedSwModeSet
);
3603 // Determine swizzle type if there is 2 or more swizzle type candidates
3604 if (IsPow2(allowedSwSet
.value
) == FALSE
)
3606 if (ElemLib::IsBlockCompressed(pIn
->format
))
3608 if (allowedSwSet
.sw_D
)
3610 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3614 ADDR_ASSERT(allowedSwSet
.sw_S
);
3615 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3618 else if (ElemLib::IsMacroPixelPacked(pIn
->format
))
3620 if (allowedSwSet
.sw_S
)
3622 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3624 else if (allowedSwSet
.sw_D
)
3626 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3630 ADDR_ASSERT(allowedSwSet
.sw_R
);
3631 allowedSwModeSet
.value
&= Gfx9RotateSwModeMask
;
3634 else if (pOut
->resourceType
== ADDR_RSRC_TEX_3D
)
3636 if (pIn
->flags
.color
&& allowedSwSet
.sw_D
)
3638 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3640 else if (allowedSwSet
.sw_Z
)
3642 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3646 ADDR_ASSERT(allowedSwSet
.sw_S
);
3647 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3652 if (pIn
->flags
.rotated
&& allowedSwSet
.sw_R
)
3654 allowedSwModeSet
.value
&= Gfx9RotateSwModeMask
;
3656 else if (displayRsrc
&& allowedSwSet
.sw_D
)
3658 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3660 else if (allowedSwSet
.sw_S
)
3662 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3666 ADDR_ASSERT(allowedSwSet
.sw_Z
);
3667 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3672 // Swizzle type should be determined.
3673 ADDR_ASSERT(IsPow2(GetAllowedSwSet(allowedSwModeSet
).value
));
3675 // Determine swizzle mode now - always select the "largest" swizzle mode for a given block type +
3676 // swizzle type combination. For example, for AddrBlock64KB + ADDR_SW_S, select SW_64KB_S_X(25) if it's
3677 // available, or otherwise select SW_64KB_S_T(17) if it's available, or otherwise select SW_64KB_S(9).
3678 pOut
->swizzleMode
= static_cast<AddrSwizzleMode
>(Log2NonPow2(allowedSwModeSet
.value
));
3683 // Invalid combination...
3684 ADDR_ASSERT_ALWAYS();
3685 returnCode
= ADDR_INVALIDPARAMS
;
3692 ************************************************************************************************************************
3693 * Gfx9Lib::ComputeStereoInfo
3696 * Compute height alignment and right eye pipeBankXor for stereo surface
3701 ************************************************************************************************************************
3703 ADDR_E_RETURNCODE
Gfx9Lib::ComputeStereoInfo(
3704 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
3705 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
,
3706 UINT_32
* pHeightAlign
3709 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3711 UINT_32 eqIndex
= HwlGetEquationIndex(pIn
, pOut
);
3713 if (eqIndex
< m_numEquations
)
3715 if (IsXor(pIn
->swizzleMode
))
3717 const UINT_32 blkSizeLog2
= GetBlockSizeLog2(pIn
->swizzleMode
);
3718 const UINT_32 numPipeBits
= GetPipeXorBits(blkSizeLog2
);
3719 const UINT_32 numBankBits
= GetBankXorBits(blkSizeLog2
);
3720 const UINT_32 bppLog2
= Log2(pIn
->bpp
>> 3);
3721 const UINT_32 maxYCoordBlock256
= Log2(Block256_2d
[bppLog2
].h
) - 1;
3722 MAYBE_UNUSED
const ADDR_EQUATION
*pEqToCheck
= &m_equationTable
[eqIndex
];
3724 ADDR_ASSERT(maxYCoordBlock256
==
3725 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], GetBlockSizeLog2(ADDR_SW_256B
), 1));
3727 const UINT_32 maxYCoordInBaseEquation
=
3728 (blkSizeLog2
- GetBlockSizeLog2(ADDR_SW_256B
)) / 2 + maxYCoordBlock256
;
3730 ADDR_ASSERT(maxYCoordInBaseEquation
==
3731 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], blkSizeLog2
, 1));
3733 const UINT_32 maxYCoordInPipeXor
= (numPipeBits
== 0) ? 0 : maxYCoordBlock256
+ numPipeBits
;
3735 ADDR_ASSERT(maxYCoordInPipeXor
==
3736 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
], numPipeBits
, 1));
3738 const UINT_32 maxYCoordInBankXor
= (numBankBits
== 0) ?
3739 0 : maxYCoordBlock256
+ (numPipeBits
+ 1) / 2 + numBankBits
;
3741 ADDR_ASSERT(maxYCoordInBankXor
==
3742 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
+ numPipeBits
], numBankBits
, 1));
3744 const UINT_32 maxYCoordInPipeBankXor
= Max(maxYCoordInPipeXor
, maxYCoordInBankXor
);
3746 if (maxYCoordInPipeBankXor
> maxYCoordInBaseEquation
)
3748 *pHeightAlign
= 1u << maxYCoordInPipeBankXor
;
3750 if (pOut
->pStereoInfo
!= NULL
)
3752 pOut
->pStereoInfo
->rightSwizzle
= 0;
3754 if ((PowTwoAlign(pIn
->height
, *pHeightAlign
) % (*pHeightAlign
* 2)) != 0)
3756 if (maxYCoordInPipeXor
== maxYCoordInPipeBankXor
)
3758 pOut
->pStereoInfo
->rightSwizzle
|= (1u << 1);
3761 if (maxYCoordInBankXor
== maxYCoordInPipeBankXor
)
3763 pOut
->pStereoInfo
->rightSwizzle
|=
3764 1u << ((numPipeBits
% 2) ? numPipeBits
: numPipeBits
+ 1);
3767 ADDR_ASSERT(pOut
->pStereoInfo
->rightSwizzle
==
3768 GetCoordActiveMask(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
],
3769 numPipeBits
+ numBankBits
, 1, maxYCoordInPipeBankXor
));
3777 ADDR_ASSERT_ALWAYS();
3778 returnCode
= ADDR_ERROR
;
3785 ************************************************************************************************************************
3786 * Gfx9Lib::HwlComputeSurfaceInfoTiled
3789 * Internal function to calculate alignment for tiled surface
3793 ************************************************************************************************************************
3795 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoTiled(
3796 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
3797 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
3800 ADDR_E_RETURNCODE returnCode
= ComputeBlockDimensionForSurf(&pOut
->blockWidth
,
3808 if (returnCode
== ADDR_OK
)
3810 UINT_32 pitchAlignInElement
= pOut
->blockWidth
;
3812 if ((IsTex2d(pIn
->resourceType
) == TRUE
) &&
3813 (pIn
->flags
.display
|| pIn
->flags
.rotated
) &&
3814 (pIn
->numMipLevels
<= 1) &&
3815 (pIn
->numSamples
<= 1) &&
3816 (pIn
->numFrags
<= 1))
3818 // Display engine needs pitch align to be at least 32 pixels.
3819 pitchAlignInElement
= PowTwoAlign(pitchAlignInElement
, 32);
3822 pOut
->pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
3824 if ((pIn
->numMipLevels
<= 1) && (pIn
->pitchInElement
> 0))
3826 if ((pIn
->pitchInElement
% pitchAlignInElement
) != 0)
3828 returnCode
= ADDR_INVALIDPARAMS
;
3830 else if (pIn
->pitchInElement
< pOut
->pitch
)
3832 returnCode
= ADDR_INVALIDPARAMS
;
3836 pOut
->pitch
= pIn
->pitchInElement
;
3840 UINT_32 heightAlign
= 0;
3842 if (pIn
->flags
.qbStereo
)
3844 returnCode
= ComputeStereoInfo(pIn
, pOut
, &heightAlign
);
3847 if (returnCode
== ADDR_OK
)
3849 pOut
->height
= PowTwoAlign(pIn
->height
, pOut
->blockHeight
);
3851 if (heightAlign
> 1)
3853 pOut
->height
= PowTwoAlign(pOut
->height
, heightAlign
);
3856 pOut
->numSlices
= PowTwoAlign(pIn
->numSlices
, pOut
->blockSlices
);
3858 pOut
->epitchIsHeight
= FALSE
;
3859 pOut
->mipChainInTail
= FALSE
;
3860 pOut
->firstMipIdInTail
= pIn
->numMipLevels
;
3862 pOut
->mipChainPitch
= pOut
->pitch
;
3863 pOut
->mipChainHeight
= pOut
->height
;
3864 pOut
->mipChainSlice
= pOut
->numSlices
;
3866 if (pIn
->numMipLevels
> 1)
3868 pOut
->firstMipIdInTail
= GetMipChainInfo(pIn
->resourceType
,
3880 const UINT_32 endingMipId
= Min(pOut
->firstMipIdInTail
, pIn
->numMipLevels
- 1);
3882 if (endingMipId
== 0)
3884 const Dim3d tailMaxDim
= GetMipTailDim(pIn
->resourceType
,
3890 pOut
->epitchIsHeight
= TRUE
;
3891 pOut
->pitch
= tailMaxDim
.w
;
3892 pOut
->height
= tailMaxDim
.h
;
3893 pOut
->numSlices
= IsThick(pIn
->resourceType
, pIn
->swizzleMode
) ?
3894 tailMaxDim
.d
: pIn
->numSlices
;
3895 pOut
->mipChainInTail
= TRUE
;
3899 UINT_32 mip0WidthInBlk
= pOut
->pitch
/ pOut
->blockWidth
;
3900 UINT_32 mip0HeightInBlk
= pOut
->height
/ pOut
->blockHeight
;
3902 AddrMajorMode majorMode
= GetMajorMode(pIn
->resourceType
,
3906 pOut
->numSlices
/ pOut
->blockSlices
);
3907 if (majorMode
== ADDR_MAJOR_Y
)
3909 UINT_32 mip1WidthInBlk
= RoundHalf(mip0WidthInBlk
);
3911 if ((mip1WidthInBlk
== 1) && (endingMipId
> 2))
3916 pOut
->mipChainPitch
+= (mip1WidthInBlk
* pOut
->blockWidth
);
3918 pOut
->epitchIsHeight
= FALSE
;
3922 UINT_32 mip1HeightInBlk
= RoundHalf(mip0HeightInBlk
);
3924 if ((mip1HeightInBlk
== 1) && (endingMipId
> 2))
3929 pOut
->mipChainHeight
+= (mip1HeightInBlk
* pOut
->blockHeight
);
3931 pOut
->epitchIsHeight
= TRUE
;
3935 if (pOut
->pMipInfo
!= NULL
)
3937 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
3939 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
3941 Dim3d mipStartPos
= {0};
3942 UINT_32 mipTailOffsetInBytes
= 0;
3944 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
3954 &mipTailOffsetInBytes
);
3956 UINT_32 pitchInBlock
=
3957 pOut
->mipChainPitch
/ pOut
->blockWidth
;
3958 UINT_32 sliceInBlock
=
3959 (pOut
->mipChainHeight
/ pOut
->blockHeight
) * pitchInBlock
;
3960 UINT_64 blockIndex
=
3961 mipStartPos
.d
* sliceInBlock
+ mipStartPos
.h
* pitchInBlock
+ mipStartPos
.w
;
3962 UINT_64 macroBlockOffset
=
3963 blockIndex
<< GetBlockSizeLog2(pIn
->swizzleMode
);
3965 pOut
->pMipInfo
[i
].macroBlockOffset
= macroBlockOffset
;
3966 pOut
->pMipInfo
[i
].mipTailOffset
= mipTailOffsetInBytes
;
3970 else if (pOut
->pMipInfo
!= NULL
)
3972 pOut
->pMipInfo
[0].pitch
= pOut
->pitch
;
3973 pOut
->pMipInfo
[0].height
= pOut
->height
;
3974 pOut
->pMipInfo
[0].depth
= IsTex3d(pIn
->resourceType
)? pOut
->numSlices
: 1;
3975 pOut
->pMipInfo
[0].offset
= 0;
3978 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->mipChainPitch
) * pOut
->mipChainHeight
*
3979 (pIn
->bpp
>> 3) * pIn
->numFrags
;
3980 pOut
->surfSize
= pOut
->sliceSize
* pOut
->mipChainSlice
;
3981 pOut
->baseAlign
= ComputeSurfaceBaseAlignTiled(pIn
->swizzleMode
);
3983 if ((IsBlock256b(pIn
->swizzleMode
) == FALSE
) &&
3984 (pIn
->flags
.color
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
|| pIn
->flags
.fmask
) &&
3985 (pIn
->flags
.texture
== TRUE
) &&
3986 (pIn
->flags
.noMetadata
== FALSE
) &&
3987 (pIn
->flags
.metaPipeUnaligned
== FALSE
))
3989 // Assume client requires pipe aligned metadata, which is TcCompatible and will be accessed by TC...
3990 // Then we need extra padding for base surface. Otherwise, metadata and data surface for same pixel will
3991 // be flushed to different pipes, but texture engine only uses pipe id of data surface to fetch both of
3992 // them, which may cause invalid metadata to be fetched.
3993 pOut
->baseAlign
= Max(pOut
->baseAlign
, m_pipeInterleaveBytes
* m_pipes
);
3998 pOut
->baseAlign
= Max(pOut
->baseAlign
, PrtAlignment
);
4007 ************************************************************************************************************************
4008 * Gfx9Lib::HwlComputeSurfaceInfoLinear
4011 * Internal function to calculate alignment for linear surface
4015 ************************************************************************************************************************
4017 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoLinear(
4018 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
4019 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
4022 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
4024 UINT_32 actualHeight
= 0;
4025 UINT_32 elementBytes
= pIn
->bpp
>> 3;
4026 const UINT_32 alignment
= pIn
->flags
.prt
? PrtAlignment
: 256;
4028 if (IsTex1d(pIn
->resourceType
))
4030 if (pIn
->height
> 1)
4032 returnCode
= ADDR_INVALIDPARAMS
;
4036 const UINT_32 pitchAlignInElement
= alignment
/ elementBytes
;
4038 pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
4039 actualHeight
= pIn
->numMipLevels
;
4041 if (pIn
->flags
.prt
== FALSE
)
4043 returnCode
= ApplyCustomizedPitchHeight(pIn
, elementBytes
, pitchAlignInElement
,
4044 &pitch
, &actualHeight
);
4047 if (returnCode
== ADDR_OK
)
4049 if (pOut
->pMipInfo
!= NULL
)
4051 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4053 pOut
->pMipInfo
[i
].offset
= pitch
* elementBytes
* i
;
4054 pOut
->pMipInfo
[i
].pitch
= pitch
;
4055 pOut
->pMipInfo
[i
].height
= 1;
4056 pOut
->pMipInfo
[i
].depth
= 1;
4064 returnCode
= ComputeSurfaceLinearPadding(pIn
, &pitch
, &actualHeight
, pOut
->pMipInfo
);
4067 if ((pitch
== 0) || (actualHeight
== 0))
4069 returnCode
= ADDR_INVALIDPARAMS
;
4072 if (returnCode
== ADDR_OK
)
4074 pOut
->pitch
= pitch
;
4075 pOut
->height
= pIn
->height
;
4076 pOut
->numSlices
= pIn
->numSlices
;
4077 pOut
->mipChainPitch
= pitch
;
4078 pOut
->mipChainHeight
= actualHeight
;
4079 pOut
->mipChainSlice
= pOut
->numSlices
;
4080 pOut
->epitchIsHeight
= (pIn
->numMipLevels
> 1) ? TRUE
: FALSE
;
4081 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->pitch
) * actualHeight
* elementBytes
;
4082 pOut
->surfSize
= pOut
->sliceSize
* pOut
->numSlices
;
4083 pOut
->baseAlign
= (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
) ? (pIn
->bpp
/ 8) : alignment
;
4084 pOut
->blockWidth
= (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
) ? 1 : (256 / elementBytes
);
4085 pOut
->blockHeight
= 1;
4086 pOut
->blockSlices
= 1;
4089 // Post calculation validate
4090 ADDR_ASSERT(pOut
->sliceSize
> 0);
4096 ************************************************************************************************************************
4097 * Gfx9Lib::GetMipChainInfo
4100 * Internal function to get out information about mip chain
4103 * Smaller value between Id of first mip fitted in mip tail and max Id of mip being created
4104 ************************************************************************************************************************
4106 UINT_32
Gfx9Lib::GetMipChainInfo(
4107 AddrResourceType resourceType
,
4108 AddrSwizzleMode swizzleMode
,
4114 UINT_32 blockHeight
,
4116 UINT_32 numMipLevel
,
4117 ADDR2_MIP_INFO
* pMipInfo
) const
4119 const Dim3d tailMaxDim
=
4120 GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4122 UINT_32 mipPitch
= mip0Width
;
4123 UINT_32 mipHeight
= mip0Height
;
4124 UINT_32 mipDepth
= IsTex3d(resourceType
) ? mip0Depth
: 1;
4126 UINT_32 firstMipIdInTail
= numMipLevel
;
4127 BOOL_32 inTail
= FALSE
;
4128 BOOL_32 finalDim
= FALSE
;
4129 BOOL_32 is3dThick
= IsThick(resourceType
, swizzleMode
);
4130 BOOL_32 is3dThin
= IsTex3d(resourceType
) && (is3dThick
== FALSE
);
4132 for (UINT_32 mipId
= 0; mipId
< numMipLevel
; mipId
++)
4136 if (finalDim
== FALSE
)
4142 mipSize
= mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3);
4146 mipSize
= mipPitch
* mipHeight
* (bpp
>> 3);
4151 UINT_32 index
= Log2(bpp
>> 3);
4155 mipPitch
= Block256_3dZ
[index
].w
;
4156 mipHeight
= Block256_3dZ
[index
].h
;
4157 mipDepth
= Block256_3dZ
[index
].d
;
4161 mipPitch
= Block256_2d
[index
].w
;
4162 mipHeight
= Block256_2d
[index
].h
;
4171 inTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
,
4172 mipPitch
, mipHeight
, mipDepth
);
4176 firstMipIdInTail
= mipId
;
4177 mipPitch
= tailMaxDim
.w
;
4178 mipHeight
= tailMaxDim
.h
;
4182 mipDepth
= tailMaxDim
.d
;
4187 mipPitch
= PowTwoAlign(mipPitch
, blockWidth
);
4188 mipHeight
= PowTwoAlign(mipHeight
, blockHeight
);
4192 mipDepth
= PowTwoAlign(mipDepth
, blockDepth
);
4197 if (pMipInfo
!= NULL
)
4199 pMipInfo
[mipId
].pitch
= mipPitch
;
4200 pMipInfo
[mipId
].height
= mipHeight
;
4201 pMipInfo
[mipId
].depth
= mipDepth
;
4202 pMipInfo
[mipId
].offset
= offset
;
4205 offset
+= (mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3));
4211 mipDepth
= Max(mipDepth
>> 1, 1u);
4216 mipPitch
= Max(mipPitch
>> 1, 1u);
4217 mipHeight
= Max(mipHeight
>> 1, 1u);
4219 if (is3dThick
|| is3dThin
)
4221 mipDepth
= Max(mipDepth
>> 1, 1u);
4226 return firstMipIdInTail
;
4230 ************************************************************************************************************************
4231 * Gfx9Lib::GetMetaMiptailInfo
4234 * Get mip tail coordinate information.
4238 ************************************************************************************************************************
4240 VOID
Gfx9Lib::GetMetaMiptailInfo(
4241 ADDR2_META_MIP_INFO
* pInfo
, ///< [out] output structure to store per mip coord
4242 Dim3d mipCoord
, ///< [in] mip tail base coord
4243 UINT_32 numMipInTail
, ///< [in] number of mips in tail
4244 Dim3d
* pMetaBlkDim
///< [in] meta block width/height/depth
4247 BOOL_32 isThick
= (pMetaBlkDim
->d
> 1);
4248 UINT_32 mipWidth
= pMetaBlkDim
->w
;
4249 UINT_32 mipHeight
= pMetaBlkDim
->h
>> 1;
4250 UINT_32 mipDepth
= pMetaBlkDim
->d
;
4255 minInc
= (pMetaBlkDim
->h
>= 512) ? 128 : ((pMetaBlkDim
->h
== 256) ? 64 : 32);
4257 else if (pMetaBlkDim
->h
>= 1024)
4261 else if (pMetaBlkDim
->h
== 512)
4270 UINT_32 blk32MipId
= 0xFFFFFFFF;
4272 for (UINT_32 mip
= 0; mip
< numMipInTail
; mip
++)
4274 pInfo
[mip
].inMiptail
= TRUE
;
4275 pInfo
[mip
].startX
= mipCoord
.w
;
4276 pInfo
[mip
].startY
= mipCoord
.h
;
4277 pInfo
[mip
].startZ
= mipCoord
.d
;
4278 pInfo
[mip
].width
= mipWidth
;
4279 pInfo
[mip
].height
= mipHeight
;
4280 pInfo
[mip
].depth
= mipDepth
;
4284 if (blk32MipId
== 0xFFFFFFFF)
4289 mipCoord
.w
= pInfo
[blk32MipId
].startX
;
4290 mipCoord
.h
= pInfo
[blk32MipId
].startY
;
4291 mipCoord
.d
= pInfo
[blk32MipId
].startZ
;
4293 switch (mip
- blk32MipId
)
4296 mipCoord
.w
+= 32; // 16x16
4299 mipCoord
.h
+= 32; // 8x8
4302 mipCoord
.h
+= 32; // 4x4
4306 mipCoord
.h
+= 32; // 2x2
4310 mipCoord
.h
+= 32; // 1x1
4313 // The following are for BC/ASTC formats
4315 mipCoord
.h
+= 48; // 1/2 x 1/2
4318 mipCoord
.h
+= 48; // 1/4 x 1/4
4322 mipCoord
.h
+= 48; // 1/8 x 1/8
4326 mipCoord
.h
+= 48; // 1/16 x 1/16
4330 ADDR_ASSERT_ALWAYS();
4334 mipWidth
= ((mip
- blk32MipId
) == 0) ? 16 : 8;
4335 mipHeight
= mipWidth
;
4339 mipDepth
= mipWidth
;
4344 if (mipWidth
<= minInc
)
4346 // if we're below the minimal increment...
4349 // For 3d, just go in z direction
4350 mipCoord
.d
+= mipDepth
;
4354 // For 2d, first go across, then down
4355 if ((mipWidth
* 2) == minInc
)
4357 // if we're 2 mips below, that's when we go back in x, and down in y
4358 mipCoord
.w
-= minInc
;
4359 mipCoord
.h
+= minInc
;
4363 // otherwise, just go across in x
4364 mipCoord
.w
+= minInc
;
4370 // On even mip, go down, otherwise, go across
4373 mipCoord
.w
+= mipWidth
;
4377 mipCoord
.h
+= mipHeight
;
4380 // Divide the width by 2
4382 // After the first mip in tail, the mip is always a square
4383 mipHeight
= mipWidth
;
4384 // ...or for 3d, a cube
4387 mipDepth
= mipWidth
;
4394 ************************************************************************************************************************
4395 * Gfx9Lib::GetMipStartPos
4398 * Internal function to get out information about mip logical start position
4401 * logical start position in macro block width/heith/depth of one mip level within one slice
4402 ************************************************************************************************************************
4404 Dim3d
Gfx9Lib::GetMipStartPos(
4405 AddrResourceType resourceType
,
4406 AddrSwizzleMode swizzleMode
,
4411 UINT_32 blockHeight
,
4414 UINT_32 log2ElementBytes
,
4415 UINT_32
* pMipTailBytesOffset
) const
4417 Dim3d mipStartPos
= {0};
4418 const Dim3d tailMaxDim
= GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4420 // Report mip in tail if Mip0 is already in mip tail
4421 BOOL_32 inMipTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
, width
, height
, depth
);
4422 UINT_32 log2blkSize
= GetBlockSizeLog2(swizzleMode
);
4423 UINT_32 mipIndexInTail
= mipId
;
4425 if (inMipTail
== FALSE
)
4427 // Mip 0 dimension, unit in block
4428 UINT_32 mipWidthInBlk
= width
/ blockWidth
;
4429 UINT_32 mipHeightInBlk
= height
/ blockHeight
;
4430 UINT_32 mipDepthInBlk
= depth
/ blockDepth
;
4431 AddrMajorMode majorMode
= GetMajorMode(resourceType
,
4437 UINT_32 endingMip
= mipId
+ 1;
4439 for (UINT_32 i
= 1; i
<= mipId
; i
++)
4441 if ((i
== 1) || (i
== 3))
4443 if (majorMode
== ADDR_MAJOR_Y
)
4445 mipStartPos
.w
+= mipWidthInBlk
;
4449 mipStartPos
.h
+= mipHeightInBlk
;
4454 if (majorMode
== ADDR_MAJOR_X
)
4456 mipStartPos
.w
+= mipWidthInBlk
;
4458 else if (majorMode
== ADDR_MAJOR_Y
)
4460 mipStartPos
.h
+= mipHeightInBlk
;
4464 mipStartPos
.d
+= mipDepthInBlk
;
4468 BOOL_32 inTail
= FALSE
;
4470 if (IsThick(resourceType
, swizzleMode
))
4472 UINT_32 dim
= log2blkSize
% 3;
4477 (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1) && (mipDepthInBlk
<= 2);
4482 (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
<= 2);
4487 (mipWidthInBlk
<= 2) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
== 1);
4492 if (log2blkSize
& 1)
4494 inTail
= (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1);
4498 inTail
= (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2);
4508 mipWidthInBlk
= RoundHalf(mipWidthInBlk
);
4509 mipHeightInBlk
= RoundHalf(mipHeightInBlk
);
4510 mipDepthInBlk
= RoundHalf(mipDepthInBlk
);
4513 if (mipId
>= endingMip
)
4516 mipIndexInTail
= mipId
- endingMip
;
4522 UINT_32 index
= mipIndexInTail
+ MaxMacroBits
- log2blkSize
;
4523 ADDR_ASSERT(index
< sizeof(MipTailOffset256B
) / sizeof(UINT_32
));
4524 *pMipTailBytesOffset
= MipTailOffset256B
[index
] << 8;
4531 ************************************************************************************************************************
4532 * Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled
4535 * Internal function to calculate address from coord for tiled swizzle surface
4539 ************************************************************************************************************************
4541 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled(
4542 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
4543 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
4546 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
4547 localIn
.swizzleMode
= pIn
->swizzleMode
;
4548 localIn
.flags
= pIn
->flags
;
4549 localIn
.resourceType
= pIn
->resourceType
;
4550 localIn
.bpp
= pIn
->bpp
;
4551 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
4552 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
4553 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
4554 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
4555 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
4556 localIn
.numFrags
= Max(pIn
->numFrags
, 1u);
4557 if (localIn
.numMipLevels
<= 1)
4559 localIn
.pitchInElement
= pIn
->pitchInElement
;
4562 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
4563 ADDR_E_RETURNCODE returnCode
= ComputeSurfaceInfoTiled(&localIn
, &localOut
);
4565 BOOL_32 valid
= (returnCode
== ADDR_OK
) &&
4566 (IsThin(pIn
->resourceType
, pIn
->swizzleMode
) ||
4567 IsThick(pIn
->resourceType
, pIn
->swizzleMode
)) &&
4568 ((pIn
->pipeBankXor
== 0) || (IsXor(pIn
->swizzleMode
)));
4572 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
4573 Dim3d mipStartPos
= {0};
4574 UINT_32 mipTailBytesOffset
= 0;
4576 if (pIn
->numMipLevels
> 1)
4578 // Mip-map chain cannot be MSAA surface
4579 ADDR_ASSERT((pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1));
4581 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
4586 localOut
.blockWidth
,
4587 localOut
.blockHeight
,
4588 localOut
.blockSlices
,
4591 &mipTailBytesOffset
);
4594 UINT_32 interleaveOffset
= 0;
4595 UINT_32 pipeBits
= 0;
4596 UINT_32 pipeXor
= 0;
4597 UINT_32 bankBits
= 0;
4598 UINT_32 bankXor
= 0;
4600 if (IsThin(pIn
->resourceType
, pIn
->swizzleMode
))
4602 UINT_32 blockOffset
= 0;
4603 UINT_32 log2blkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4605 if (IsZOrderSwizzle(pIn
->swizzleMode
))
4607 // Morton generation
4608 if ((log2ElementBytes
== 0) || (log2ElementBytes
== 2))
4610 UINT_32 totalLowBits
= 6 - log2ElementBytes
;
4611 UINT_32 mortBits
= totalLowBits
/ 2;
4612 UINT_32 lowBitsValue
= MortonGen2d(pIn
->y
, pIn
->x
, mortBits
);
4613 // Are 9 bits enough?
4614 UINT_32 highBitsValue
=
4615 MortonGen2d(pIn
->x
>> mortBits
, pIn
->y
>> mortBits
, 9) << totalLowBits
;
4616 blockOffset
= lowBitsValue
| highBitsValue
;
4617 ADDR_ASSERT(blockOffset
== lowBitsValue
+ highBitsValue
);
4621 blockOffset
= MortonGen2d(pIn
->y
, pIn
->x
, 13);
4624 // Fill LSBs with sample bits
4625 if (pIn
->numSamples
> 1)
4627 blockOffset
*= pIn
->numSamples
;
4628 blockOffset
|= pIn
->sample
;
4631 // Shift according to BytesPP
4632 blockOffset
<<= log2ElementBytes
;
4636 // Micro block offset
4637 UINT_32 microBlockOffset
= ComputeSurface2DMicroBlockOffset(pIn
);
4638 blockOffset
= microBlockOffset
;
4640 // Micro block dimension
4641 ADDR_ASSERT(log2ElementBytes
< MaxNumOfBpp
);
4642 Dim2d microBlockDim
= Block256_2d
[log2ElementBytes
];
4643 // Morton generation, does 12 bit enough?
4645 MortonGen2d((pIn
->x
/ microBlockDim
.w
), (pIn
->y
/ microBlockDim
.h
), 12) << 8;
4647 // Sample bits start location
4648 UINT_32 sampleStart
= log2blkSize
- Log2(pIn
->numSamples
);
4649 // Join sample bits information to the highest Macro block bits
4650 if (IsNonPrtXor(pIn
->swizzleMode
))
4652 // Non-prt-Xor : xor highest Macro block bits with sample bits
4653 blockOffset
= blockOffset
^ (pIn
->sample
<< sampleStart
);
4657 // Non-Xor or prt-Xor: replace highest Macro block bits with sample bits
4658 // after this op, the blockOffset only contains log2 Macro block size bits
4659 blockOffset
%= (1 << sampleStart
);
4660 blockOffset
|= (pIn
->sample
<< sampleStart
);
4661 ADDR_ASSERT((blockOffset
>> log2blkSize
) == 0);
4665 if (IsXor(pIn
->swizzleMode
))
4667 // Mask off bits above Macro block bits to keep page synonyms working for prt
4668 if (IsPrt(pIn
->swizzleMode
))
4670 blockOffset
&= ((1 << log2blkSize
) - 1);
4673 // Preserve offset inside pipe interleave
4674 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4675 blockOffset
>>= m_pipeInterleaveLog2
;
4678 pipeBits
= GetPipeXorBits(log2blkSize
);
4680 pipeXor
= FoldXor2d(blockOffset
, pipeBits
);
4681 blockOffset
>>= pipeBits
;
4684 bankBits
= GetBankXorBits(log2blkSize
);
4686 bankXor
= FoldXor2d(blockOffset
, bankBits
);
4687 blockOffset
>>= bankBits
;
4689 // Put all the part back together
4690 blockOffset
<<= bankBits
;
4691 blockOffset
|= bankXor
;
4692 blockOffset
<<= pipeBits
;
4693 blockOffset
|= pipeXor
;
4694 blockOffset
<<= m_pipeInterleaveLog2
;
4695 blockOffset
|= interleaveOffset
;
4698 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4699 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2blkSize
)));
4701 blockOffset
|= mipTailBytesOffset
;
4703 if (IsNonPrtXor(pIn
->swizzleMode
) && (pIn
->numSamples
<= 1))
4705 // Apply slice xor if not MSAA/PRT
4706 blockOffset
^= (ReverseBitVector(pIn
->slice
, pipeBits
) << m_pipeInterleaveLog2
);
4707 blockOffset
^= (ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
) <<
4708 (m_pipeInterleaveLog2
+ pipeBits
));
4711 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4712 bankBits
, pipeBits
, &blockOffset
);
4714 blockOffset
%= (1 << log2blkSize
);
4716 UINT_32 pitchInMacroBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4717 UINT_32 paddedHeightInMacroBlock
= localOut
.mipChainHeight
/ localOut
.blockHeight
;
4718 UINT_32 sliceSizeInMacroBlock
= pitchInMacroBlock
* paddedHeightInMacroBlock
;
4719 UINT_64 macroBlockIndex
=
4720 (pIn
->slice
+ mipStartPos
.d
) * sliceSizeInMacroBlock
+
4721 ((pIn
->y
/ localOut
.blockHeight
) + mipStartPos
.h
) * pitchInMacroBlock
+
4722 ((pIn
->x
/ localOut
.blockWidth
) + mipStartPos
.w
);
4724 pOut
->addr
= blockOffset
| (macroBlockIndex
<< log2blkSize
);
4728 UINT_32 log2blkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4730 Dim3d microBlockDim
= Block1K_3d
[log2ElementBytes
];
4732 UINT_32 blockOffset
= MortonGen3d((pIn
->x
/ microBlockDim
.w
),
4733 (pIn
->y
/ microBlockDim
.h
),
4734 (pIn
->slice
/ microBlockDim
.d
),
4738 blockOffset
|= ComputeSurface3DMicroBlockOffset(pIn
);
4740 if (IsXor(pIn
->swizzleMode
))
4742 // Mask off bits above Macro block bits to keep page synonyms working for prt
4743 if (IsPrt(pIn
->swizzleMode
))
4745 blockOffset
&= ((1 << log2blkSize
) - 1);
4748 // Preserve offset inside pipe interleave
4749 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4750 blockOffset
>>= m_pipeInterleaveLog2
;
4753 pipeBits
= GetPipeXorBits(log2blkSize
);
4755 pipeXor
= FoldXor3d(blockOffset
, pipeBits
);
4756 blockOffset
>>= pipeBits
;
4759 bankBits
= GetBankXorBits(log2blkSize
);
4761 bankXor
= FoldXor3d(blockOffset
, bankBits
);
4762 blockOffset
>>= bankBits
;
4764 // Put all the part back together
4765 blockOffset
<<= bankBits
;
4766 blockOffset
|= bankXor
;
4767 blockOffset
<<= pipeBits
;
4768 blockOffset
|= pipeXor
;
4769 blockOffset
<<= m_pipeInterleaveLog2
;
4770 blockOffset
|= interleaveOffset
;
4773 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4774 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2blkSize
)));
4775 blockOffset
|= mipTailBytesOffset
;
4777 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4778 bankBits
, pipeBits
, &blockOffset
);
4780 blockOffset
%= (1 << log2blkSize
);
4782 UINT_32 xb
= pIn
->x
/ localOut
.blockWidth
+ mipStartPos
.w
;
4783 UINT_32 yb
= pIn
->y
/ localOut
.blockHeight
+ mipStartPos
.h
;
4784 UINT_32 zb
= pIn
->slice
/ localOut
.blockSlices
+ + mipStartPos
.d
;
4786 UINT_32 pitchInBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4787 UINT_32 sliceSizeInBlock
=
4788 (localOut
.mipChainHeight
/ localOut
.blockHeight
) * pitchInBlock
;
4789 UINT_64 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
4791 pOut
->addr
= blockOffset
| (blockIndex
<< log2blkSize
);
4796 returnCode
= ADDR_INVALIDPARAMS
;
4803 ************************************************************************************************************************
4804 * Gfx9Lib::ComputeSurfaceInfoLinear
4807 * Internal function to calculate padding for linear swizzle 2D/3D surface
4811 ************************************************************************************************************************
4813 ADDR_E_RETURNCODE
Gfx9Lib::ComputeSurfaceLinearPadding(
4814 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input srtucture
4815 UINT_32
* pMipmap0PaddedWidth
, ///< [out] padded width in element
4816 UINT_32
* pSlice0PaddedHeight
, ///< [out] padded height for HW
4817 ADDR2_MIP_INFO
* pMipInfo
///< [out] per mip information
4820 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
4822 UINT_32 elementBytes
= pIn
->bpp
>> 3;
4823 UINT_32 pitchAlignInElement
= 0;
4825 if (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
)
4827 ADDR_ASSERT(pIn
->numMipLevels
<= 1);
4828 ADDR_ASSERT(pIn
->numSlices
<= 1);
4829 pitchAlignInElement
= 1;
4833 pitchAlignInElement
= (256 / elementBytes
);
4836 UINT_32 mipChainWidth
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
4837 UINT_32 slice0PaddedHeight
= pIn
->height
;
4839 returnCode
= ApplyCustomizedPitchHeight(pIn
, elementBytes
, pitchAlignInElement
,
4840 &mipChainWidth
, &slice0PaddedHeight
);
4842 if (returnCode
== ADDR_OK
)
4844 UINT_32 mipChainHeight
= 0;
4845 UINT_32 mipHeight
= pIn
->height
;
4846 UINT_32 mipDepth
= (pIn
->resourceType
== ADDR_RSRC_TEX_3D
) ? pIn
->numSlices
: 1;
4848 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4850 if (pMipInfo
!= NULL
)
4852 pMipInfo
[i
].offset
= mipChainWidth
* mipChainHeight
* elementBytes
;
4853 pMipInfo
[i
].pitch
= mipChainWidth
;
4854 pMipInfo
[i
].height
= mipHeight
;
4855 pMipInfo
[i
].depth
= mipDepth
;
4858 mipChainHeight
+= mipHeight
;
4859 mipHeight
= RoundHalf(mipHeight
);
4860 mipHeight
= Max(mipHeight
, 1u);
4863 *pMipmap0PaddedWidth
= mipChainWidth
;
4864 *pSlice0PaddedHeight
= (pIn
->numMipLevels
> 1) ? mipChainHeight
: slice0PaddedHeight
;