2 * Copyright © 2007-2019 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 Reserved
73 {1, 0, 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, 0}, // ADDR_SW_256B_S
75 {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_256B_D
76 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_256B_R
78 {0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, // ADDR_SW_4KB_Z
79 {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, // ADDR_SW_4KB_S
80 {0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_4KB_D
81 {0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_4KB_R
83 {0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0}, // ADDR_SW_64KB_Z
84 {0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, // ADDR_SW_64KB_S
85 {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_64KB_D
86 {0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_64KB_R
88 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Reserved
89 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Reserved
90 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Reserved
91 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Reserved
93 {0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0}, // ADDR_SW_64KB_Z_T
94 {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0}, // ADDR_SW_64KB_S_T
95 {0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0}, // ADDR_SW_64KB_D_T
96 {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0}, // ADDR_SW_64KB_R_T
98 {0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_4KB_Z_x
99 {0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0}, // ADDR_SW_4KB_S_x
100 {0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0}, // ADDR_SW_4KB_D_x
101 {0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0}, // ADDR_SW_4KB_R_x
103 {0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_64KB_Z_X
104 {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0}, // ADDR_SW_64KB_S_X
105 {0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0}, // ADDR_SW_64KB_D_X
106 {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0}, // ADDR_SW_64KB_R_X
108 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Reserved
109 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Reserved
110 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Reserved
111 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // Reserved
112 {1, 0, 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, 8, 6, 5, 4, 3, 2, 1, 0};
117 const Dim3d
Gfx9Lib::Block256_3dS
[] = {{16, 4, 4}, {8, 4, 4}, {4, 4, 4}, {2, 4, 4}, {1, 4, 4}};
119 const Dim3d
Gfx9Lib::Block256_3dZ
[] = {{8, 4, 8}, {4, 4, 8}, {4, 4, 4}, {4, 2, 4}, {2, 2, 4}};
122 ************************************************************************************************************************
128 ************************************************************************************************************************
130 Gfx9Lib::Gfx9Lib(const Client
* pClient
)
134 m_class
= AI_ADDRLIB
;
135 memset(&m_settings
, 0, sizeof(m_settings
));
136 memcpy(m_swizzleModeTable
, SwizzleModeTable
, sizeof(SwizzleModeTable
));
137 memset(m_cachedMetaEqKey
, 0, sizeof(m_cachedMetaEqKey
));
138 m_metaEqOverrideIndex
= 0;
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 ADDR_ASSERT(pIn
->resourceType
== ADDR_RSRC_TEX_2D
);
284 UINT_32 numPipeTotal
= GetPipeNumForMetaAddressing(pIn
->cMaskFlags
.pipeAligned
,
287 UINT_32 numRbTotal
= pIn
->cMaskFlags
.rbAligned
? m_se
* m_rbPerSe
: 1;
289 UINT_32 numCompressBlkPerMetaBlkLog2
, numCompressBlkPerMetaBlk
;
291 if ((numPipeTotal
== 1) && (numRbTotal
== 1))
293 numCompressBlkPerMetaBlkLog2
= 13;
297 if (m_settings
.applyAliasFix
)
299 numCompressBlkPerMetaBlkLog2
= m_seLog2
+ m_rbPerSeLog2
+ Max(10u, m_pipeInterleaveLog2
);
303 numCompressBlkPerMetaBlkLog2
= m_seLog2
+ m_rbPerSeLog2
+ 10;
306 numCompressBlkPerMetaBlkLog2
= Max(numCompressBlkPerMetaBlkLog2
, 13u);
309 numCompressBlkPerMetaBlk
= 1 << numCompressBlkPerMetaBlkLog2
;
311 Dim2d metaBlkDim
= {8, 8};
312 UINT_32 totalAmpBits
= numCompressBlkPerMetaBlkLog2
;
313 UINT_32 heightAmp
= totalAmpBits
>> 1;
314 UINT_32 widthAmp
= totalAmpBits
- heightAmp
;
315 metaBlkDim
.w
<<= widthAmp
;
316 metaBlkDim
.h
<<= heightAmp
;
319 Dim2d metaBlkDimDbg
= {8, 8};
320 for (UINT_32 index
= 0; index
< numCompressBlkPerMetaBlkLog2
; index
++)
322 if (metaBlkDimDbg
.h
< metaBlkDimDbg
.w
)
324 metaBlkDimDbg
.h
<<= 1;
328 metaBlkDimDbg
.w
<<= 1;
331 ADDR_ASSERT((metaBlkDimDbg
.w
== metaBlkDim
.w
) && (metaBlkDimDbg
.h
== metaBlkDim
.h
));
334 UINT_32 numMetaBlkX
= (pIn
->unalignedWidth
+ metaBlkDim
.w
- 1) / metaBlkDim
.w
;
335 UINT_32 numMetaBlkY
= (pIn
->unalignedHeight
+ metaBlkDim
.h
- 1) / metaBlkDim
.h
;
336 UINT_32 numMetaBlkZ
= Max(pIn
->numSlices
, 1u);
338 UINT_32 sizeAlign
= numPipeTotal
* numRbTotal
* m_pipeInterleaveBytes
;
340 if (m_settings
.metaBaseAlignFix
)
342 sizeAlign
= Max(sizeAlign
, GetBlockSize(pIn
->swizzleMode
));
345 pOut
->pitch
= numMetaBlkX
* metaBlkDim
.w
;
346 pOut
->height
= numMetaBlkY
* metaBlkDim
.h
;
347 pOut
->sliceSize
= (numMetaBlkX
* numMetaBlkY
* numCompressBlkPerMetaBlk
) >> 1;
348 pOut
->cmaskBytes
= PowTwoAlign(pOut
->sliceSize
* numMetaBlkZ
, sizeAlign
);
349 pOut
->baseAlign
= Max(numCompressBlkPerMetaBlk
>> 1, sizeAlign
);
351 pOut
->metaBlkWidth
= metaBlkDim
.w
;
352 pOut
->metaBlkHeight
= metaBlkDim
.h
;
354 pOut
->metaBlkNumPerSlice
= numMetaBlkX
* numMetaBlkY
;
360 ************************************************************************************************************************
361 * Gfx9Lib::GetMetaMipInfo
368 ************************************************************************************************************************
370 VOID
Gfx9Lib::GetMetaMipInfo(
371 UINT_32 numMipLevels
, ///< [in] number of mip levels
372 Dim3d
* pMetaBlkDim
, ///< [in] meta block dimension
373 BOOL_32 dataThick
, ///< [in] data surface is thick
374 ADDR2_META_MIP_INFO
* pInfo
, ///< [out] meta mip info
375 UINT_32 mip0Width
, ///< [in] mip0 width
376 UINT_32 mip0Height
, ///< [in] mip0 height
377 UINT_32 mip0Depth
, ///< [in] mip0 depth
378 UINT_32
* pNumMetaBlkX
, ///< [out] number of metablock X in mipchain
379 UINT_32
* pNumMetaBlkY
, ///< [out] number of metablock Y in mipchain
380 UINT_32
* pNumMetaBlkZ
) ///< [out] number of metablock Z in mipchain
383 UINT_32 numMetaBlkX
= (mip0Width
+ pMetaBlkDim
->w
- 1) / pMetaBlkDim
->w
;
384 UINT_32 numMetaBlkY
= (mip0Height
+ pMetaBlkDim
->h
- 1) / pMetaBlkDim
->h
;
385 UINT_32 numMetaBlkZ
= (mip0Depth
+ pMetaBlkDim
->d
- 1) / pMetaBlkDim
->d
;
386 UINT_32 tailWidth
= pMetaBlkDim
->w
;
387 UINT_32 tailHeight
= pMetaBlkDim
->h
>> 1;
388 UINT_32 tailDepth
= pMetaBlkDim
->d
;
389 BOOL_32 inTail
= FALSE
;
390 AddrMajorMode major
= ADDR_MAJOR_MAX_TYPE
;
392 if (numMipLevels
> 1)
394 if (dataThick
&& (numMetaBlkZ
> numMetaBlkX
) && (numMetaBlkZ
> numMetaBlkY
))
397 major
= ADDR_MAJOR_Z
;
399 else if (numMetaBlkX
>= numMetaBlkY
)
402 major
= ADDR_MAJOR_X
;
407 major
= ADDR_MAJOR_Y
;
410 inTail
= ((mip0Width
<= tailWidth
) &&
411 (mip0Height
<= tailHeight
) &&
412 ((dataThick
== FALSE
) || (mip0Depth
<= tailDepth
)));
420 if (major
== ADDR_MAJOR_Z
)
423 pMipDim
= &numMetaBlkY
;
424 pOrderDim
= &numMetaBlkZ
;
427 else if (major
== ADDR_MAJOR_X
)
430 pMipDim
= &numMetaBlkY
;
431 pOrderDim
= &numMetaBlkX
;
437 pMipDim
= &numMetaBlkX
;
438 pOrderDim
= &numMetaBlkY
;
442 if ((*pMipDim
< 3) && (*pOrderDim
> orderLimit
) && (numMipLevels
> 3))
448 *pMipDim
+= ((*pMipDim
/ 2) + (*pMipDim
& 1));
455 UINT_32 mipWidth
= mip0Width
;
456 UINT_32 mipHeight
= mip0Height
;
457 UINT_32 mipDepth
= mip0Depth
;
458 Dim3d mipCoord
= {0};
460 for (UINT_32 mip
= 0; mip
< numMipLevels
; mip
++)
464 GetMetaMiptailInfo(&pInfo
[mip
], mipCoord
, numMipLevels
- mip
,
470 mipWidth
= PowTwoAlign(mipWidth
, pMetaBlkDim
->w
);
471 mipHeight
= PowTwoAlign(mipHeight
, pMetaBlkDim
->h
);
472 mipDepth
= PowTwoAlign(mipDepth
, pMetaBlkDim
->d
);
474 pInfo
[mip
].inMiptail
= FALSE
;
475 pInfo
[mip
].startX
= mipCoord
.w
;
476 pInfo
[mip
].startY
= mipCoord
.h
;
477 pInfo
[mip
].startZ
= mipCoord
.d
;
478 pInfo
[mip
].width
= mipWidth
;
479 pInfo
[mip
].height
= mipHeight
;
480 pInfo
[mip
].depth
= dataThick
? mipDepth
: 1;
482 if ((mip
>= 3) || (mip
& 1))
487 mipCoord
.w
+= mipWidth
;
490 mipCoord
.h
+= mipHeight
;
493 mipCoord
.d
+= mipDepth
;
504 mipCoord
.h
+= mipHeight
;
507 mipCoord
.w
+= mipWidth
;
510 mipCoord
.h
+= mipHeight
;
517 mipWidth
= Max(mipWidth
>> 1, 1u);
518 mipHeight
= Max(mipHeight
>> 1, 1u);
519 mipDepth
= Max(mipDepth
>> 1, 1u);
521 inTail
= ((mipWidth
<= tailWidth
) &&
522 (mipHeight
<= tailHeight
) &&
523 ((dataThick
== FALSE
) || (mipDepth
<= tailDepth
)));
528 *pNumMetaBlkX
= numMetaBlkX
;
529 *pNumMetaBlkY
= numMetaBlkY
;
530 *pNumMetaBlkZ
= numMetaBlkZ
;
534 ************************************************************************************************************************
535 * Gfx9Lib::HwlComputeDccInfo
538 * Interface function to compute DCC key info
542 ************************************************************************************************************************
544 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeDccInfo(
545 const ADDR2_COMPUTE_DCCINFO_INPUT
* pIn
, ///< [in] input structure
546 ADDR2_COMPUTE_DCCINFO_OUTPUT
* pOut
///< [out] output structure
549 BOOL_32 dataLinear
= IsLinear(pIn
->swizzleMode
);
550 BOOL_32 metaLinear
= pIn
->dccKeyFlags
.linear
;
551 BOOL_32 pipeAligned
= pIn
->dccKeyFlags
.pipeAligned
;
557 else if (metaLinear
== TRUE
)
562 UINT_32 numPipeTotal
= GetPipeNumForMetaAddressing(pipeAligned
, pIn
->swizzleMode
);
566 // Linear metadata supporting was removed for GFX9! No one can use this feature on GFX9.
567 ADDR_ASSERT_ALWAYS();
569 pOut
->dccRamBaseAlign
= numPipeTotal
* m_pipeInterleaveBytes
;
570 pOut
->dccRamSize
= PowTwoAlign((pIn
->dataSurfaceSize
/ 256), pOut
->dccRamBaseAlign
);
574 BOOL_32 dataThick
= IsThick(pIn
->resourceType
, pIn
->swizzleMode
);
576 UINT_32 minMetaBlkSize
= dataThick
? 65536 : 4096;
578 UINT_32 numFrags
= Max(pIn
->numFrags
, 1u);
579 UINT_32 numSlices
= Max(pIn
->numSlices
, 1u);
581 minMetaBlkSize
/= numFrags
;
583 UINT_32 numCompressBlkPerMetaBlk
= minMetaBlkSize
;
585 UINT_32 numRbTotal
= pIn
->dccKeyFlags
.rbAligned
? m_se
* m_rbPerSe
: 1;
587 if ((numPipeTotal
> 1) || (numRbTotal
> 1))
589 const UINT_32 thinBlkSize
= 1 << (m_settings
.applyAliasFix
? Max(10u, m_pipeInterleaveLog2
) : 10);
591 numCompressBlkPerMetaBlk
=
592 Max(numCompressBlkPerMetaBlk
, m_se
* m_rbPerSe
* (dataThick
? 262144 : thinBlkSize
));
594 if (numCompressBlkPerMetaBlk
> 65536 * pIn
->bpp
)
596 numCompressBlkPerMetaBlk
= 65536 * pIn
->bpp
;
600 Dim3d compressBlkDim
= GetDccCompressBlk(pIn
->resourceType
, pIn
->swizzleMode
, pIn
->bpp
);
601 Dim3d metaBlkDim
= compressBlkDim
;
603 for (UINT_32 index
= 1; index
< numCompressBlkPerMetaBlk
; index
<<= 1)
605 if ((metaBlkDim
.h
< metaBlkDim
.w
) ||
606 ((pIn
->numMipLevels
> 1) && (metaBlkDim
.h
== metaBlkDim
.w
)))
608 if ((dataThick
== FALSE
) || (metaBlkDim
.h
<= metaBlkDim
.d
))
619 if ((dataThick
== FALSE
) || (metaBlkDim
.w
<= metaBlkDim
.d
))
634 GetMetaMipInfo(pIn
->numMipLevels
, &metaBlkDim
, dataThick
, pOut
->pMipInfo
,
635 pIn
->unalignedWidth
, pIn
->unalignedHeight
, numSlices
,
636 &numMetaBlkX
, &numMetaBlkY
, &numMetaBlkZ
);
638 UINT_32 sizeAlign
= numPipeTotal
* numRbTotal
* m_pipeInterleaveBytes
;
640 if (numFrags
> m_maxCompFrag
)
642 sizeAlign
*= (numFrags
/ m_maxCompFrag
);
645 if (m_settings
.metaBaseAlignFix
)
647 sizeAlign
= Max(sizeAlign
, GetBlockSize(pIn
->swizzleMode
));
650 pOut
->dccRamSize
= numMetaBlkX
* numMetaBlkY
* numMetaBlkZ
*
651 numCompressBlkPerMetaBlk
* numFrags
;
652 pOut
->dccRamSize
= PowTwoAlign(pOut
->dccRamSize
, sizeAlign
);
653 pOut
->dccRamBaseAlign
= Max(numCompressBlkPerMetaBlk
, sizeAlign
);
655 pOut
->pitch
= numMetaBlkX
* metaBlkDim
.w
;
656 pOut
->height
= numMetaBlkY
* metaBlkDim
.h
;
657 pOut
->depth
= numMetaBlkZ
* metaBlkDim
.d
;
659 pOut
->compressBlkWidth
= compressBlkDim
.w
;
660 pOut
->compressBlkHeight
= compressBlkDim
.h
;
661 pOut
->compressBlkDepth
= compressBlkDim
.d
;
663 pOut
->metaBlkWidth
= metaBlkDim
.w
;
664 pOut
->metaBlkHeight
= metaBlkDim
.h
;
665 pOut
->metaBlkDepth
= metaBlkDim
.d
;
667 pOut
->metaBlkNumPerSlice
= numMetaBlkX
* numMetaBlkY
;
668 pOut
->fastClearSizePerSlice
=
669 pOut
->metaBlkNumPerSlice
* numCompressBlkPerMetaBlk
* Min(numFrags
, m_maxCompFrag
);
676 ************************************************************************************************************************
677 * Gfx9Lib::HwlComputeMaxBaseAlignments
680 * Gets maximum alignments
683 ************************************************************************************************************************
685 UINT_32
Gfx9Lib::HwlComputeMaxBaseAlignments() const
691 ************************************************************************************************************************
692 * Gfx9Lib::HwlComputeMaxMetaBaseAlignments
695 * Gets maximum alignments for metadata
697 * maximum alignments for metadata
698 ************************************************************************************************************************
700 UINT_32
Gfx9Lib::HwlComputeMaxMetaBaseAlignments() const
702 // Max base alignment for Htile
703 const UINT_32 maxNumPipeTotal
= GetPipeNumForMetaAddressing(TRUE
, ADDR_SW_64KB_Z
);
704 const UINT_32 maxNumRbTotal
= m_se
* m_rbPerSe
;
706 // If applyAliasFix was set, the extra bits should be MAX(10u, m_pipeInterleaveLog2),
707 // but we never saw any ASIC whose m_pipeInterleaveLog2 != 8, so just put an assertion and simply the logic.
708 ADDR_ASSERT((m_settings
.applyAliasFix
== FALSE
) || (m_pipeInterleaveLog2
<= 10u));
709 const UINT_32 maxNumCompressBlkPerMetaBlk
= 1u << (m_seLog2
+ m_rbPerSeLog2
+ 10u);
711 UINT_32 maxBaseAlignHtile
= maxNumPipeTotal
* maxNumRbTotal
* m_pipeInterleaveBytes
;
713 if (maxNumPipeTotal
> 2)
715 maxBaseAlignHtile
*= (maxNumPipeTotal
>> 1);
718 maxBaseAlignHtile
= Max(maxNumCompressBlkPerMetaBlk
<< 2, maxBaseAlignHtile
);
720 if (m_settings
.metaBaseAlignFix
)
722 maxBaseAlignHtile
= Max(maxBaseAlignHtile
, Size64K
);
725 if (m_settings
.htileAlignFix
)
727 maxBaseAlignHtile
*= maxNumPipeTotal
;
730 // Max base alignment for Cmask will not be larger than that for Htile, no need to calculate
732 // Max base alignment for 2D Dcc will not be larger than that for 3D, no need to calculate
733 UINT_32 maxBaseAlignDcc3D
= 65536;
735 if ((maxNumPipeTotal
> 1) || (maxNumRbTotal
> 1))
737 maxBaseAlignDcc3D
= Min(m_se
* m_rbPerSe
* 262144, 65536 * 128u);
740 // Max base alignment for Msaa Dcc
741 UINT_32 maxBaseAlignDccMsaa
= maxNumPipeTotal
* maxNumRbTotal
* m_pipeInterleaveBytes
* (8 / m_maxCompFrag
);
743 if (m_settings
.metaBaseAlignFix
)
745 maxBaseAlignDccMsaa
= Max(maxBaseAlignDccMsaa
, Size64K
);
748 return Max(maxBaseAlignHtile
, Max(maxBaseAlignDccMsaa
, maxBaseAlignDcc3D
));
752 ************************************************************************************************************************
753 * Gfx9Lib::HwlComputeCmaskAddrFromCoord
756 * Interface function stub of AddrComputeCmaskAddrFromCoord
760 ************************************************************************************************************************
762 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeCmaskAddrFromCoord(
763 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
764 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
766 ADDR2_COMPUTE_CMASK_INFO_INPUT input
= {0};
767 input
.size
= sizeof(input
);
768 input
.cMaskFlags
= pIn
->cMaskFlags
;
769 input
.colorFlags
= pIn
->colorFlags
;
770 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
771 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
772 input
.numSlices
= Max(pIn
->numSlices
, 1u);
773 input
.swizzleMode
= pIn
->swizzleMode
;
774 input
.resourceType
= pIn
->resourceType
;
776 ADDR2_COMPUTE_CMASK_INFO_OUTPUT output
= {0};
777 output
.size
= sizeof(output
);
779 ADDR_E_RETURNCODE returnCode
= ComputeCmaskInfo(&input
, &output
);
781 if (returnCode
== ADDR_OK
)
783 UINT_32 fmaskBpp
= GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
);
784 UINT_32 fmaskElementBytesLog2
= Log2(fmaskBpp
>> 3);
785 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
786 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
788 MetaEqParams metaEqParams
= {0, fmaskElementBytesLog2
, 0, pIn
->cMaskFlags
,
789 Gfx9DataFmask
, pIn
->swizzleMode
, pIn
->resourceType
,
790 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
792 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
794 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
795 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
796 UINT_32 zb
= pIn
->slice
;
798 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
799 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
800 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
802 UINT_64 address
= pMetaEq
->solve(pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
);
804 pOut
->addr
= address
>> 1;
805 pOut
->bitPosition
= static_cast<UINT_32
>((address
& 1) << 2);
807 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->cMaskFlags
.pipeAligned
,
810 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
812 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
819 ************************************************************************************************************************
820 * Gfx9Lib::HwlComputeHtileAddrFromCoord
823 * Interface function stub of AddrComputeHtileAddrFromCoord
827 ************************************************************************************************************************
829 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileAddrFromCoord(
830 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
831 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
833 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
835 if (pIn
->numMipLevels
> 1)
837 returnCode
= ADDR_NOTIMPLEMENTED
;
841 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
842 input
.size
= sizeof(input
);
843 input
.hTileFlags
= pIn
->hTileFlags
;
844 input
.depthFlags
= pIn
->depthflags
;
845 input
.swizzleMode
= pIn
->swizzleMode
;
846 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
847 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
848 input
.numSlices
= Max(pIn
->numSlices
, 1u);
849 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
851 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
852 output
.size
= sizeof(output
);
854 returnCode
= ComputeHtileInfo(&input
, &output
);
856 if (returnCode
== ADDR_OK
)
858 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
859 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
860 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
861 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
863 MetaEqParams metaEqParams
= {0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
864 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
865 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
867 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
869 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
870 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
871 UINT_32 zb
= pIn
->slice
;
873 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
874 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
875 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
877 UINT_64 address
= pMetaEq
->solve(pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
);
879 pOut
->addr
= address
>> 1;
881 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
884 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
886 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
894 ************************************************************************************************************************
895 * Gfx9Lib::HwlComputeHtileCoordFromAddr
898 * Interface function stub of AddrComputeHtileCoordFromAddr
902 ************************************************************************************************************************
904 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileCoordFromAddr(
905 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
906 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
) ///< [out] output structure
908 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
910 if (pIn
->numMipLevels
> 1)
912 returnCode
= ADDR_NOTIMPLEMENTED
;
916 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
917 input
.size
= sizeof(input
);
918 input
.hTileFlags
= pIn
->hTileFlags
;
919 input
.swizzleMode
= pIn
->swizzleMode
;
920 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
921 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
922 input
.numSlices
= Max(pIn
->numSlices
, 1u);
923 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
925 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
926 output
.size
= sizeof(output
);
928 returnCode
= ComputeHtileInfo(&input
, &output
);
930 if (returnCode
== ADDR_OK
)
932 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
933 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
934 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
935 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
937 MetaEqParams metaEqParams
= {0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
938 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
939 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
941 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
943 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
946 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
948 UINT_64 nibbleAddress
= (pIn
->addr
^ (pipeXor
<< m_pipeInterleaveLog2
)) << 1;
950 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
951 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
953 UINT_32 x
, y
, z
, s
, m
;
954 pMetaEq
->solveAddr(nibbleAddress
, sliceSizeInBlock
, x
, y
, z
, s
, m
);
956 pOut
->slice
= m
/ sliceSizeInBlock
;
957 pOut
->y
= ((m
% sliceSizeInBlock
) / pitchInBlock
) * output
.metaBlkHeight
+ y
;
958 pOut
->x
= (m
% pitchInBlock
) * output
.metaBlkWidth
+ x
;
966 ************************************************************************************************************************
967 * Gfx9Lib::HwlComputeDccAddrFromCoord
970 * Interface function stub of AddrComputeDccAddrFromCoord
974 ************************************************************************************************************************
976 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeDccAddrFromCoord(
977 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
,
978 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
)
980 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
982 if ((pIn
->numMipLevels
> 1) || (pIn
->mipId
> 1) || pIn
->dccKeyFlags
.linear
)
984 returnCode
= ADDR_NOTIMPLEMENTED
;
988 ADDR2_COMPUTE_DCCINFO_INPUT input
= {0};
989 input
.size
= sizeof(input
);
990 input
.dccKeyFlags
= pIn
->dccKeyFlags
;
991 input
.colorFlags
= pIn
->colorFlags
;
992 input
.swizzleMode
= pIn
->swizzleMode
;
993 input
.resourceType
= pIn
->resourceType
;
994 input
.bpp
= pIn
->bpp
;
995 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
996 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
997 input
.numSlices
= Max(pIn
->numSlices
, 1u);
998 input
.numFrags
= Max(pIn
->numFrags
, 1u);
999 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
1001 ADDR2_COMPUTE_DCCINFO_OUTPUT output
= {0};
1002 output
.size
= sizeof(output
);
1004 returnCode
= ComputeDccInfo(&input
, &output
);
1006 if (returnCode
== ADDR_OK
)
1008 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
1009 UINT_32 numSamplesLog2
= Log2(pIn
->numFrags
);
1010 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
1011 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
1012 UINT_32 metaBlkDepthLog2
= Log2(output
.metaBlkDepth
);
1013 UINT_32 compBlkWidthLog2
= Log2(output
.compressBlkWidth
);
1014 UINT_32 compBlkHeightLog2
= Log2(output
.compressBlkHeight
);
1015 UINT_32 compBlkDepthLog2
= Log2(output
.compressBlkDepth
);
1017 MetaEqParams metaEqParams
= {pIn
->mipId
, elementBytesLog2
, numSamplesLog2
, pIn
->dccKeyFlags
,
1018 Gfx9DataColor
, pIn
->swizzleMode
, pIn
->resourceType
,
1019 metaBlkWidthLog2
, metaBlkHeightLog2
, metaBlkDepthLog2
,
1020 compBlkWidthLog2
, compBlkHeightLog2
, compBlkDepthLog2
};
1022 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
1024 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
1025 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
1026 UINT_32 zb
= pIn
->slice
/ output
.metaBlkDepth
;
1028 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
1029 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
1030 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
1032 UINT_64 address
= pMetaEq
->solve(pIn
->x
, pIn
->y
, pIn
->slice
, pIn
->sample
, blockIndex
);
1034 pOut
->addr
= address
>> 1;
1036 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->dccKeyFlags
.pipeAligned
,
1039 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
1041 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
1049 ************************************************************************************************************************
1050 * Gfx9Lib::HwlInitGlobalParams
1053 * Initializes global parameters
1056 * TRUE if all settings are valid
1058 ************************************************************************************************************************
1060 BOOL_32
Gfx9Lib::HwlInitGlobalParams(
1061 const ADDR_CREATE_INPUT
* pCreateIn
) ///< [in] create input
1063 BOOL_32 valid
= TRUE
;
1065 if (m_settings
.isArcticIsland
)
1067 GB_ADDR_CONFIG gbAddrConfig
;
1069 gbAddrConfig
.u32All
= pCreateIn
->regValue
.gbAddrConfig
;
1071 // These values are copied from CModel code
1072 switch (gbAddrConfig
.bits
.NUM_PIPES
)
1074 case ADDR_CONFIG_1_PIPE
:
1078 case ADDR_CONFIG_2_PIPE
:
1082 case ADDR_CONFIG_4_PIPE
:
1086 case ADDR_CONFIG_8_PIPE
:
1090 case ADDR_CONFIG_16_PIPE
:
1094 case ADDR_CONFIG_32_PIPE
:
1099 ADDR_ASSERT_ALWAYS();
1103 switch (gbAddrConfig
.bits
.PIPE_INTERLEAVE_SIZE
)
1105 case ADDR_CONFIG_PIPE_INTERLEAVE_256B
:
1106 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_256B
;
1107 m_pipeInterleaveLog2
= 8;
1109 case ADDR_CONFIG_PIPE_INTERLEAVE_512B
:
1110 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_512B
;
1111 m_pipeInterleaveLog2
= 9;
1113 case ADDR_CONFIG_PIPE_INTERLEAVE_1KB
:
1114 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_1KB
;
1115 m_pipeInterleaveLog2
= 10;
1117 case ADDR_CONFIG_PIPE_INTERLEAVE_2KB
:
1118 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_2KB
;
1119 m_pipeInterleaveLog2
= 11;
1122 ADDR_ASSERT_ALWAYS();
1126 // Addr::V2::Lib::ComputePipeBankXor()/ComputeSlicePipeBankXor() requires pipe interleave to be exactly 8 bits,
1127 // and any larger value requires a post-process (left shift) on the output pipeBankXor bits.
1128 ADDR_ASSERT(m_pipeInterleaveBytes
== ADDR_PIPEINTERLEAVE_256B
);
1130 switch (gbAddrConfig
.bits
.NUM_BANKS
)
1132 case ADDR_CONFIG_1_BANK
:
1136 case ADDR_CONFIG_2_BANK
:
1140 case ADDR_CONFIG_4_BANK
:
1144 case ADDR_CONFIG_8_BANK
:
1148 case ADDR_CONFIG_16_BANK
:
1153 ADDR_ASSERT_ALWAYS();
1157 switch (gbAddrConfig
.bits
.NUM_SHADER_ENGINES
)
1159 case ADDR_CONFIG_1_SHADER_ENGINE
:
1163 case ADDR_CONFIG_2_SHADER_ENGINE
:
1167 case ADDR_CONFIG_4_SHADER_ENGINE
:
1171 case ADDR_CONFIG_8_SHADER_ENGINE
:
1176 ADDR_ASSERT_ALWAYS();
1180 switch (gbAddrConfig
.bits
.NUM_RB_PER_SE
)
1182 case ADDR_CONFIG_1_RB_PER_SHADER_ENGINE
:
1186 case ADDR_CONFIG_2_RB_PER_SHADER_ENGINE
:
1190 case ADDR_CONFIG_4_RB_PER_SHADER_ENGINE
:
1195 ADDR_ASSERT_ALWAYS();
1199 switch (gbAddrConfig
.bits
.MAX_COMPRESSED_FRAGS
)
1201 case ADDR_CONFIG_1_MAX_COMPRESSED_FRAGMENTS
:
1203 m_maxCompFragLog2
= 0;
1205 case ADDR_CONFIG_2_MAX_COMPRESSED_FRAGMENTS
:
1207 m_maxCompFragLog2
= 1;
1209 case ADDR_CONFIG_4_MAX_COMPRESSED_FRAGMENTS
:
1211 m_maxCompFragLog2
= 2;
1213 case ADDR_CONFIG_8_MAX_COMPRESSED_FRAGMENTS
:
1215 m_maxCompFragLog2
= 3;
1218 ADDR_ASSERT_ALWAYS();
1222 if ((m_rbPerSeLog2
== 1) &&
1223 (((m_pipesLog2
== 1) && ((m_seLog2
== 2) || (m_seLog2
== 3))) ||
1224 ((m_pipesLog2
== 2) && ((m_seLog2
== 1) || (m_seLog2
== 2)))))
1226 ADDR_ASSERT(m_settings
.isVega10
== FALSE
);
1227 ADDR_ASSERT(m_settings
.isRaven
== FALSE
);
1229 ADDR_ASSERT(m_settings
.isVega20
== FALSE
);
1231 if (m_settings
.isVega12
)
1233 m_settings
.htileCacheRbConflict
= 1;
1237 // For simplicity we never allow VAR swizzle mode for GFX9, the actural value is 18 on GFX9
1238 m_blockVarSizeLog2
= 0;
1243 ADDR_NOT_IMPLEMENTED();
1248 InitEquationTable();
1255 ************************************************************************************************************************
1256 * Gfx9Lib::HwlConvertChipFamily
1259 * Convert familyID defined in atiid.h to ChipFamily and set m_chipFamily/m_chipRevision
1262 ************************************************************************************************************************
1264 ChipFamily
Gfx9Lib::HwlConvertChipFamily(
1265 UINT_32 uChipFamily
, ///< [in] chip family defined in atiih.h
1266 UINT_32 uChipRevision
) ///< [in] chip revision defined in "asic_family"_id.h
1268 ChipFamily family
= ADDR_CHIP_FAMILY_AI
;
1270 switch (uChipFamily
)
1273 m_settings
.isArcticIsland
= 1;
1274 m_settings
.isVega10
= ASICREV_IS_VEGA10_P(uChipRevision
);
1275 m_settings
.isVega12
= ASICREV_IS_VEGA12_P(uChipRevision
);
1276 m_settings
.isVega20
= ASICREV_IS_VEGA20_P(uChipRevision
);
1277 m_settings
.isDce12
= 1;
1279 if (m_settings
.isVega10
== 0)
1281 m_settings
.htileAlignFix
= 1;
1282 m_settings
.applyAliasFix
= 1;
1285 m_settings
.metaBaseAlignFix
= 1;
1287 m_settings
.depthPipeXorDisable
= 1;
1290 m_settings
.isArcticIsland
= 1;
1292 if (ASICREV_IS_RAVEN(uChipRevision
))
1294 m_settings
.isRaven
= 1;
1296 m_settings
.depthPipeXorDisable
= 1;
1299 if (ASICREV_IS_RAVEN2(uChipRevision
))
1301 m_settings
.isRaven
= 1;
1304 if (m_settings
.isRaven
== 0)
1306 m_settings
.htileAlignFix
= 1;
1307 m_settings
.applyAliasFix
= 1;
1310 if (ASICREV_IS_RENOIR(uChipRevision
))
1312 m_settings
.isRaven
= 1;
1315 m_settings
.isDcn1
= m_settings
.isRaven
;
1317 m_settings
.metaBaseAlignFix
= 1;
1321 ADDR_ASSERT(!"This should be a Fusion");
1329 ************************************************************************************************************************
1330 * Gfx9Lib::InitRbEquation
1336 ************************************************************************************************************************
1338 VOID
Gfx9Lib::GetRbEquation(
1339 CoordEq
* pRbEq
, ///< [out] rb equation
1340 UINT_32 numRbPerSeLog2
, ///< [in] number of rb per shader engine
1341 UINT_32 numSeLog2
) ///< [in] number of shader engine
1344 // RB's are distributed on 16x16, except when we have 1 rb per se, in which case its 32x32
1345 UINT_32 rbRegion
= (numRbPerSeLog2
== 0) ? 5 : 4;
1346 Coordinate
cx('x', rbRegion
);
1347 Coordinate
cy('y', rbRegion
);
1350 UINT_32 numRbTotalLog2
= numRbPerSeLog2
+ numSeLog2
;
1352 // Clear the rb equation
1354 pRbEq
->resize(numRbTotalLog2
);
1356 if ((numSeLog2
> 0) && (numRbPerSeLog2
== 1))
1358 // Special case when more than 1 SE, and 2 RB per SE
1359 (*pRbEq
)[0].add(cx
);
1360 (*pRbEq
)[0].add(cy
);
1364 if (m_settings
.applyAliasFix
== false)
1366 (*pRbEq
)[0].add(cy
);
1369 (*pRbEq
)[0].add(cy
);
1373 UINT_32 numBits
= 2 * (numRbTotalLog2
- start
);
1375 for (UINT_32 i
= 0; i
< numBits
; i
++)
1378 start
+ (((start
+ i
) >= numRbTotalLog2
) ? (2 * (numRbTotalLog2
- start
) - i
- 1) : i
);
1382 (*pRbEq
)[idx
].add(cx
);
1387 (*pRbEq
)[idx
].add(cy
);
1394 ************************************************************************************************************************
1395 * Gfx9Lib::GetDataEquation
1398 * Get data equation for fmask and Z
1401 ************************************************************************************************************************
1403 VOID
Gfx9Lib::GetDataEquation(
1404 CoordEq
* pDataEq
, ///< [out] data surface equation
1405 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1406 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1407 AddrResourceType resourceType
, ///< [in] data surface resource type
1408 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1409 UINT_32 numSamplesLog2
) ///< [in] data surface sample count
1412 Coordinate
cx('x', 0);
1413 Coordinate
cy('y', 0);
1414 Coordinate
cz('z', 0);
1415 Coordinate
cs('s', 0);
1417 // Clear the equation
1419 pDataEq
->resize(27);
1421 if (dataSurfaceType
== Gfx9DataColor
)
1423 if (IsLinear(swizzleMode
))
1425 Coordinate
cm('m', 0);
1427 pDataEq
->resize(49);
1429 for (UINT_32 i
= 0; i
< 49; i
++)
1431 (*pDataEq
)[i
].add(cm
);
1435 else if (IsThick(resourceType
, swizzleMode
))
1437 // Color 3d_S and 3d_Z modes, 3d_D is same as color 2d
1439 if (IsStandardSwizzle(resourceType
, swizzleMode
))
1441 // Standard 3d swizzle
1442 // Fill in bottom x bits
1443 for (i
= elementBytesLog2
; i
< 4; i
++)
1445 (*pDataEq
)[i
].add(cx
);
1448 // Fill in 2 bits of y and then z
1449 for (i
= 4; i
< 6; i
++)
1451 (*pDataEq
)[i
].add(cy
);
1454 for (i
= 6; i
< 8; i
++)
1456 (*pDataEq
)[i
].add(cz
);
1459 if (elementBytesLog2
< 2)
1461 // fill in z & y bit
1462 (*pDataEq
)[8].add(cz
);
1463 (*pDataEq
)[9].add(cy
);
1467 else if (elementBytesLog2
== 2)
1469 // fill in y and x bit
1470 (*pDataEq
)[8].add(cy
);
1471 (*pDataEq
)[9].add(cx
);
1478 (*pDataEq
)[8].add(cx
);
1480 (*pDataEq
)[9].add(cx
);
1487 UINT_32 m2dEnd
= (elementBytesLog2
==0) ? 3 : ((elementBytesLog2
< 4) ? 4 : 5);
1488 UINT_32 numZs
= (elementBytesLog2
== 0 || elementBytesLog2
== 4) ?
1489 2 : ((elementBytesLog2
== 1) ? 3 : 1);
1490 pDataEq
->mort2d(cx
, cy
, elementBytesLog2
, m2dEnd
);
1491 for (i
= m2dEnd
+ 1; i
<= m2dEnd
+ numZs
; i
++)
1493 (*pDataEq
)[i
].add(cz
);
1496 if ((elementBytesLog2
== 0) || (elementBytesLog2
== 3))
1499 (*pDataEq
)[6].add(cx
);
1500 (*pDataEq
)[7].add(cz
);
1504 else if (elementBytesLog2
== 2)
1507 (*pDataEq
)[6].add(cy
);
1508 (*pDataEq
)[7].add(cz
);
1513 (*pDataEq
)[8].add(cy
);
1514 (*pDataEq
)[9].add(cx
);
1518 // Fill in bit 10 and up
1519 pDataEq
->mort3d( cz
, cy
, cx
, 10 );
1521 else if (IsThin(resourceType
, swizzleMode
))
1523 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1525 UINT_32 microYBits
= (8 - elementBytesLog2
) / 2;
1526 UINT_32 tileSplitStart
= blockSizeLog2
- numSamplesLog2
;
1528 // Fill in bottom x bits
1529 for (i
= elementBytesLog2
; i
< 4; i
++)
1531 (*pDataEq
)[i
].add(cx
);
1534 // Fill in bottom y bits
1535 for (i
= 4; i
< 4 + microYBits
; i
++)
1537 (*pDataEq
)[i
].add(cy
);
1540 // Fill in last of the micro_x bits
1541 for (i
= 4 + microYBits
; i
< 8; i
++)
1543 (*pDataEq
)[i
].add(cx
);
1546 // Fill in x/y bits below sample split
1547 pDataEq
->mort2d(cy
, cx
, 8, tileSplitStart
- 1);
1548 // Fill in sample bits
1549 for (i
= 0; i
< numSamplesLog2
; i
++)
1552 (*pDataEq
)[tileSplitStart
+ i
].add(cs
);
1554 // Fill in x/y bits above sample split
1555 if ((numSamplesLog2
& 1) ^ (blockSizeLog2
& 1))
1557 pDataEq
->mort2d(cx
, cy
, blockSizeLog2
);
1561 pDataEq
->mort2d(cy
, cx
, blockSizeLog2
);
1566 ADDR_ASSERT_ALWAYS();
1572 UINT_32 sampleStart
= elementBytesLog2
;
1573 UINT_32 pixelStart
= elementBytesLog2
+ numSamplesLog2
;
1574 UINT_32 ymajStart
= 6 + numSamplesLog2
;
1576 for (UINT_32 s
= 0; s
< numSamplesLog2
; s
++)
1579 (*pDataEq
)[sampleStart
+ s
].add(cs
);
1582 // Put in the x-major order pixel bits
1583 pDataEq
->mort2d(cx
, cy
, pixelStart
, ymajStart
- 1);
1584 // Put in the y-major order pixel bits
1585 pDataEq
->mort2d(cy
, cx
, ymajStart
);
1590 ************************************************************************************************************************
1591 * Gfx9Lib::GetPipeEquation
1597 ************************************************************************************************************************
1599 VOID
Gfx9Lib::GetPipeEquation(
1600 CoordEq
* pPipeEq
, ///< [out] pipe equation
1601 CoordEq
* pDataEq
, ///< [in] data equation
1602 UINT_32 pipeInterleaveLog2
, ///< [in] pipe interleave
1603 UINT_32 numPipeLog2
, ///< [in] number of pipes
1604 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1605 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1606 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1607 AddrResourceType resourceType
///< [in] data surface resource type
1610 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1613 pDataEq
->copy(dataEq
);
1615 if (dataSurfaceType
== Gfx9DataColor
)
1617 INT_32 shift
= static_cast<INT_32
>(numSamplesLog2
);
1618 dataEq
.shift(-shift
, blockSizeLog2
- numSamplesLog2
);
1621 dataEq
.copy(*pPipeEq
, pipeInterleaveLog2
, numPipeLog2
);
1623 // This section should only apply to z/stencil, maybe fmask
1624 // If the pipe bit is below the comp block size,
1625 // then keep moving up the address until we find a bit that is above
1626 UINT_32 pipeStart
= 0;
1628 if (dataSurfaceType
!= Gfx9DataColor
)
1630 Coordinate
tileMin('x', 3);
1632 while (dataEq
[pipeInterleaveLog2
+ pipeStart
][0] < tileMin
)
1637 // if pipe is 0, then the first pipe bit is above the comp block size,
1638 // so we don't need to do anything
1639 // Note, this if condition is not necessary, since if we execute the loop when pipe==0,
1640 // we will get the same pipe equation
1643 for (UINT_32 i
= 0; i
< numPipeLog2
; i
++)
1645 // Copy the jth bit above pipe interleave to the current pipe equation bit
1646 dataEq
[pipeInterleaveLog2
+ pipeStart
+ i
].copyto((*pPipeEq
)[i
]);
1651 if (IsPrt(swizzleMode
))
1653 // Clear out bits above the block size if prt's are enabled
1654 dataEq
.resize(blockSizeLog2
);
1658 if (IsXor(swizzleMode
))
1662 if (IsThick(resourceType
, swizzleMode
))
1666 dataEq
.copy(xorMask2
, pipeInterleaveLog2
+ numPipeLog2
, 2 * numPipeLog2
);
1668 xorMask
.resize(numPipeLog2
);
1670 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1672 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
]);
1673 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
+ 1]);
1678 // Xor in the bits above the pipe+gpu bits
1679 dataEq
.copy(xorMask
, pipeInterleaveLog2
+ pipeStart
+ numPipeLog2
, numPipeLog2
);
1681 if ((numSamplesLog2
== 0) && (IsPrt(swizzleMode
) == FALSE
))
1685 // if 1xaa and not prt, then xor in the z bits
1687 xorMask2
.resize(numPipeLog2
);
1688 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1690 co
.set('z', numPipeLog2
- 1 - pipeIdx
);
1691 xorMask2
[pipeIdx
].add(co
);
1694 pPipeEq
->xorin(xorMask2
);
1699 pPipeEq
->xorin(xorMask
);
1703 ************************************************************************************************************************
1704 * Gfx9Lib::GetMetaEquation
1707 * Get meta equation for cmask/htile/DCC
1709 * Pointer to a calculated meta equation
1710 ************************************************************************************************************************
1712 const CoordEq
* Gfx9Lib::GetMetaEquation(
1713 const MetaEqParams
& metaEqParams
)
1715 UINT_32 cachedMetaEqIndex
;
1717 for (cachedMetaEqIndex
= 0; cachedMetaEqIndex
< MaxCachedMetaEq
; cachedMetaEqIndex
++)
1719 if (memcmp(&metaEqParams
,
1720 &m_cachedMetaEqKey
[cachedMetaEqIndex
],
1721 static_cast<UINT_32
>(sizeof(metaEqParams
))) == 0)
1727 CoordEq
* pMetaEq
= NULL
;
1729 if (cachedMetaEqIndex
< MaxCachedMetaEq
)
1731 pMetaEq
= &m_cachedMetaEq
[cachedMetaEqIndex
];
1735 m_cachedMetaEqKey
[m_metaEqOverrideIndex
] = metaEqParams
;
1737 pMetaEq
= &m_cachedMetaEq
[m_metaEqOverrideIndex
++];
1739 m_metaEqOverrideIndex
%= MaxCachedMetaEq
;
1741 GenMetaEquation(pMetaEq
,
1742 metaEqParams
.maxMip
,
1743 metaEqParams
.elementBytesLog2
,
1744 metaEqParams
.numSamplesLog2
,
1745 metaEqParams
.metaFlag
,
1746 metaEqParams
.dataSurfaceType
,
1747 metaEqParams
.swizzleMode
,
1748 metaEqParams
.resourceType
,
1749 metaEqParams
.metaBlkWidthLog2
,
1750 metaEqParams
.metaBlkHeightLog2
,
1751 metaEqParams
.metaBlkDepthLog2
,
1752 metaEqParams
.compBlkWidthLog2
,
1753 metaEqParams
.compBlkHeightLog2
,
1754 metaEqParams
.compBlkDepthLog2
);
1761 ************************************************************************************************************************
1762 * Gfx9Lib::GenMetaEquation
1765 * Get meta equation for cmask/htile/DCC
1768 ************************************************************************************************************************
1770 VOID
Gfx9Lib::GenMetaEquation(
1771 CoordEq
* pMetaEq
, ///< [out] meta equation
1772 UINT_32 maxMip
, ///< [in] max mip Id
1773 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1774 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1775 ADDR2_META_FLAGS metaFlag
, ///< [in] meta falg
1776 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1777 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1778 AddrResourceType resourceType
, ///< [in] data surface resource type
1779 UINT_32 metaBlkWidthLog2
, ///< [in] meta block width
1780 UINT_32 metaBlkHeightLog2
, ///< [in] meta block height
1781 UINT_32 metaBlkDepthLog2
, ///< [in] meta block depth
1782 UINT_32 compBlkWidthLog2
, ///< [in] compress block width
1783 UINT_32 compBlkHeightLog2
, ///< [in] compress block height
1784 UINT_32 compBlkDepthLog2
) ///< [in] compress block depth
1787 UINT_32 numPipeTotalLog2
= GetPipeLog2ForMetaAddressing(metaFlag
.pipeAligned
, swizzleMode
);
1788 UINT_32 pipeInterleaveLog2
= m_pipeInterleaveLog2
;
1790 // Get the correct data address and rb equation
1792 GetDataEquation(&dataEq
, dataSurfaceType
, swizzleMode
, resourceType
,
1793 elementBytesLog2
, numSamplesLog2
);
1795 // Get pipe and rb equations
1796 CoordEq pipeEquation
;
1797 GetPipeEquation(&pipeEquation
, &dataEq
, pipeInterleaveLog2
, numPipeTotalLog2
,
1798 numSamplesLog2
, dataSurfaceType
, swizzleMode
, resourceType
);
1799 numPipeTotalLog2
= pipeEquation
.getsize();
1801 if (metaFlag
.linear
)
1803 // Linear metadata supporting was removed for GFX9! No one can use this feature.
1804 ADDR_ASSERT_ALWAYS();
1806 ADDR_ASSERT(dataSurfaceType
== Gfx9DataColor
);
1808 dataEq
.copy(*pMetaEq
);
1810 if (IsLinear(swizzleMode
))
1812 if (metaFlag
.pipeAligned
)
1814 // Remove the pipe bits
1815 INT_32 shift
= static_cast<INT_32
>(numPipeTotalLog2
);
1816 pMetaEq
->shift(-shift
, pipeInterleaveLog2
);
1818 // Divide by comp block size, which for linear (which is always color) is 256 B
1821 if (metaFlag
.pipeAligned
)
1823 // Put pipe bits back in
1824 pMetaEq
->shift(numPipeTotalLog2
, pipeInterleaveLog2
);
1826 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1828 pipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ i
]);
1837 UINT_32 maxCompFragLog2
= static_cast<INT_32
>(m_maxCompFragLog2
);
1838 UINT_32 compFragLog2
=
1839 ((dataSurfaceType
== Gfx9DataColor
) && (numSamplesLog2
> maxCompFragLog2
)) ?
1840 maxCompFragLog2
: numSamplesLog2
;
1842 UINT_32 uncompFragLog2
= numSamplesLog2
- compFragLog2
;
1844 // Make sure the metaaddr is cleared
1846 pMetaEq
->resize(27);
1848 if (IsThick(resourceType
, swizzleMode
))
1850 Coordinate
cx('x', 0);
1851 Coordinate
cy('y', 0);
1852 Coordinate
cz('z', 0);
1856 pMetaEq
->mort3d(cy
, cx
, cz
);
1860 pMetaEq
->mort3d(cx
, cy
, cz
);
1865 Coordinate
cx('x', 0);
1866 Coordinate
cy('y', 0);
1871 pMetaEq
->mort2d(cy
, cx
, compFragLog2
);
1875 pMetaEq
->mort2d(cx
, cy
, compFragLog2
);
1878 //------------------------------------------------------------------------------------------------------------------------
1879 // Put the compressible fragments at the lsb
1880 // the uncompressible frags will be at the msb of the micro address
1881 //------------------------------------------------------------------------------------------------------------------------
1882 for (UINT_32 s
= 0; s
< compFragLog2
; s
++)
1885 (*pMetaEq
)[s
].add(cs
);
1889 // Keep a copy of the pipe equations
1890 CoordEq origPipeEquation
;
1891 pipeEquation
.copy(origPipeEquation
);
1894 // filter out everything under the compressed block size
1895 co
.set('x', compBlkWidthLog2
);
1896 pMetaEq
->Filter('<', co
, 0, 'x');
1897 co
.set('y', compBlkHeightLog2
);
1898 pMetaEq
->Filter('<', co
, 0, 'y');
1899 co
.set('z', compBlkDepthLog2
);
1900 pMetaEq
->Filter('<', co
, 0, 'z');
1902 // For non-color, filter out sample bits
1903 if (dataSurfaceType
!= Gfx9DataColor
)
1906 pMetaEq
->Filter('<', co
, 0, 's');
1909 // filter out everything above the metablock size
1910 co
.set('x', metaBlkWidthLog2
- 1);
1911 pMetaEq
->Filter('>', co
, 0, 'x');
1912 co
.set('y', metaBlkHeightLog2
- 1);
1913 pMetaEq
->Filter('>', co
, 0, 'y');
1914 co
.set('z', metaBlkDepthLog2
- 1);
1915 pMetaEq
->Filter('>', co
, 0, 'z');
1917 // filter out everything above the metablock size for the channel bits
1918 co
.set('x', metaBlkWidthLog2
- 1);
1919 pipeEquation
.Filter('>', co
, 0, 'x');
1920 co
.set('y', metaBlkHeightLog2
- 1);
1921 pipeEquation
.Filter('>', co
, 0, 'y');
1922 co
.set('z', metaBlkDepthLog2
- 1);
1923 pipeEquation
.Filter('>', co
, 0, 'z');
1925 // Make sure we still have the same number of channel bits
1926 if (pipeEquation
.getsize() != numPipeTotalLog2
)
1928 ADDR_ASSERT_ALWAYS();
1931 // Loop through all channel and rb bits,
1932 // and make sure these components exist in the metadata address
1933 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1935 for (UINT_32 j
= pipeEquation
[i
].getsize(); j
> 0; j
--)
1937 if (pMetaEq
->Exists(pipeEquation
[i
][j
- 1]) == FALSE
)
1939 ADDR_ASSERT_ALWAYS();
1944 const UINT_32 numSeLog2
= metaFlag
.rbAligned
? m_seLog2
: 0;
1945 const UINT_32 numRbPeSeLog2
= metaFlag
.rbAligned
? m_rbPerSeLog2
: 0;
1946 const UINT_32 numRbTotalLog2
= numRbPeSeLog2
+ numSeLog2
;
1947 CoordEq origRbEquation
;
1949 GetRbEquation(&origRbEquation
, numRbPeSeLog2
, numSeLog2
);
1951 CoordEq rbEquation
= origRbEquation
;
1953 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1955 for (UINT_32 j
= rbEquation
[i
].getsize(); j
> 0; j
--)
1957 if (pMetaEq
->Exists(rbEquation
[i
][j
- 1]) == FALSE
)
1959 ADDR_ASSERT_ALWAYS();
1964 if (m_settings
.applyAliasFix
)
1969 // Loop through each rb id bit; if it is equal to any of the filtered channel bits, clear it
1970 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1972 for (UINT_32 j
= 0; j
< numPipeTotalLog2
; j
++)
1974 BOOL_32 isRbEquationInPipeEquation
= FALSE
;
1976 if (m_settings
.applyAliasFix
)
1978 CoordTerm filteredPipeEq
;
1979 filteredPipeEq
= pipeEquation
[j
];
1981 filteredPipeEq
.Filter('>', co
, 0, 'z');
1983 isRbEquationInPipeEquation
= (rbEquation
[i
] == filteredPipeEq
);
1987 isRbEquationInPipeEquation
= (rbEquation
[i
] == pipeEquation
[j
]);
1990 if (isRbEquationInPipeEquation
)
1992 rbEquation
[i
].Clear();
1997 bool rbAppendedWithPipeBits
[1 << (MaxSeLog2
+ MaxRbPerSeLog2
)] = {};
1999 // Loop through each bit of the channel, get the smallest coordinate,
2000 // and remove it from the metaaddr, and rb_equation
2001 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
2003 pipeEquation
[i
].getsmallest(co
);
2005 UINT_32 old_size
= pMetaEq
->getsize();
2006 pMetaEq
->Filter('=', co
);
2007 UINT_32 new_size
= pMetaEq
->getsize();
2008 if (new_size
!= old_size
-1)
2010 ADDR_ASSERT_ALWAYS();
2012 pipeEquation
.remove(co
);
2013 for (UINT_32 j
= 0; j
< numRbTotalLog2
; j
++)
2015 if (rbEquation
[j
].remove(co
))
2017 // if we actually removed something from this bit, then add the remaining
2018 // channel bits, as these can be removed for this bit
2019 for (UINT_32 k
= 0; k
< pipeEquation
[i
].getsize(); k
++)
2021 if (pipeEquation
[i
][k
] != co
)
2023 rbEquation
[j
].add(pipeEquation
[i
][k
]);
2024 rbAppendedWithPipeBits
[j
] = true;
2031 // Loop through the rb bits and see what remain;
2032 // filter out the smallest coordinate if it remains
2033 UINT_32 rbBitsLeft
= 0;
2034 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
2036 BOOL_32 isRbEqAppended
= FALSE
;
2038 if (m_settings
.applyAliasFix
)
2040 isRbEqAppended
= (rbEquation
[i
].getsize() > (rbAppendedWithPipeBits
[i
] ? 1 : 0));
2044 isRbEqAppended
= (rbEquation
[i
].getsize() > 0);
2050 rbEquation
[i
].getsmallest(co
);
2051 UINT_32 old_size
= pMetaEq
->getsize();
2052 pMetaEq
->Filter('=', co
);
2053 UINT_32 new_size
= pMetaEq
->getsize();
2054 if (new_size
!= old_size
- 1)
2058 for (UINT_32 j
= i
+ 1; j
< numRbTotalLog2
; j
++)
2060 if (rbEquation
[j
].remove(co
))
2062 // if we actually removed something from this bit, then add the remaining
2063 // rb bits, as these can be removed for this bit
2064 for (UINT_32 k
= 0; k
< rbEquation
[i
].getsize(); k
++)
2066 if (rbEquation
[i
][k
] != co
)
2068 rbEquation
[j
].add(rbEquation
[i
][k
]);
2069 rbAppendedWithPipeBits
[j
] |= rbAppendedWithPipeBits
[i
];
2077 // capture the size of the metaaddr
2078 UINT_32 metaSize
= pMetaEq
->getsize();
2079 // resize to 49 bits...make this a nibble address
2080 pMetaEq
->resize(49);
2081 // Concatenate the macro address above the current address
2082 for (UINT_32 i
= metaSize
, j
= 0; i
< 49; i
++, j
++)
2085 (*pMetaEq
)[i
].add(co
);
2088 // Multiply by meta element size (in nibbles)
2089 if (dataSurfaceType
== Gfx9DataColor
)
2093 else if (dataSurfaceType
== Gfx9DataDepthStencil
)
2098 //------------------------------------------------------------------------------------------
2099 // Note the pipeInterleaveLog2+1 is because address is a nibble address
2100 // Shift up from pipe interleave number of channel
2101 // and rb bits left, and uncompressed fragments
2102 //------------------------------------------------------------------------------------------
2104 pMetaEq
->shift(numPipeTotalLog2
+ rbBitsLeft
+ uncompFragLog2
, pipeInterleaveLog2
+ 1);
2106 // Put in the channel bits
2107 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
2109 origPipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+1 + i
]);
2112 // Put in remaining rb bits
2113 for (UINT_32 i
= 0, j
= 0; j
< rbBitsLeft
; i
= (i
+ 1) % numRbTotalLog2
)
2115 BOOL_32 isRbEqAppended
= FALSE
;
2117 if (m_settings
.applyAliasFix
)
2119 isRbEqAppended
= (rbEquation
[i
].getsize() > (rbAppendedWithPipeBits
[i
] ? 1 : 0));
2123 isRbEqAppended
= (rbEquation
[i
].getsize() > 0);
2128 origRbEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ j
]);
2129 // Mark any rb bit we add in to the rb mask
2134 //------------------------------------------------------------------------------------------
2135 // Put in the uncompressed fragment bits
2136 //------------------------------------------------------------------------------------------
2137 for (UINT_32 i
= 0; i
< uncompFragLog2
; i
++)
2139 co
.set('s', compFragLog2
+ i
);
2140 (*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ rbBitsLeft
+ i
].add(co
);
2146 ************************************************************************************************************************
2147 * Gfx9Lib::IsEquationSupported
2150 * Check if equation is supported for given swizzle mode and resource type.
2154 ************************************************************************************************************************
2156 BOOL_32
Gfx9Lib::IsEquationSupported(
2157 AddrResourceType rsrcType
,
2158 AddrSwizzleMode swMode
,
2159 UINT_32 elementBytesLog2
) const
2161 BOOL_32 supported
= (elementBytesLog2
< MaxElementBytesLog2
) &&
2162 (IsValidSwMode(swMode
) == TRUE
) &&
2163 (IsLinear(swMode
) == FALSE
) &&
2164 (((IsTex2d(rsrcType
) == TRUE
) &&
2165 ((elementBytesLog2
< 4) ||
2166 ((IsRotateSwizzle(swMode
) == FALSE
) &&
2167 (IsZOrderSwizzle(swMode
) == FALSE
)))) ||
2168 ((IsTex3d(rsrcType
) == TRUE
) &&
2169 (IsRotateSwizzle(swMode
) == FALSE
) &&
2170 (IsBlock256b(swMode
) == FALSE
)));
2176 ************************************************************************************************************************
2177 * Gfx9Lib::InitEquationTable
2180 * Initialize Equation table.
2184 ************************************************************************************************************************
2186 VOID
Gfx9Lib::InitEquationTable()
2188 memset(m_equationTable
, 0, sizeof(m_equationTable
));
2190 // Loop all possible resource type (2D/3D)
2191 for (UINT_32 rsrcTypeIdx
= 0; rsrcTypeIdx
< MaxRsrcType
; rsrcTypeIdx
++)
2193 AddrResourceType rsrcType
= static_cast<AddrResourceType
>(rsrcTypeIdx
+ ADDR_RSRC_TEX_2D
);
2195 // Loop all possible swizzle mode
2196 for (UINT_32 swModeIdx
= 0; swModeIdx
< MaxSwModeType
; swModeIdx
++)
2198 AddrSwizzleMode swMode
= static_cast<AddrSwizzleMode
>(swModeIdx
);
2200 // Loop all possible bpp
2201 for (UINT_32 bppIdx
= 0; bppIdx
< MaxElementBytesLog2
; bppIdx
++)
2203 UINT_32 equationIndex
= ADDR_INVALID_EQUATION_INDEX
;
2205 // Check if the input is supported
2206 if (IsEquationSupported(rsrcType
, swMode
, bppIdx
))
2208 ADDR_EQUATION equation
;
2209 ADDR_E_RETURNCODE retCode
;
2211 memset(&equation
, 0, sizeof(ADDR_EQUATION
));
2213 // Generate the equation
2214 if (IsBlock256b(swMode
) && IsTex2d(rsrcType
))
2216 retCode
= ComputeBlock256Equation(rsrcType
, swMode
, bppIdx
, &equation
);
2218 else if (IsThin(rsrcType
, swMode
))
2220 retCode
= ComputeThinEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2224 retCode
= ComputeThickEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2227 // Only fill the equation into the table if the return code is ADDR_OK,
2228 // otherwise if the return code is not ADDR_OK, it indicates this is not
2229 // a valid input, we do nothing but just fill invalid equation index
2230 // into the lookup table.
2231 if (retCode
== ADDR_OK
)
2233 equationIndex
= m_numEquations
;
2234 ADDR_ASSERT(equationIndex
< EquationTableSize
);
2236 m_equationTable
[equationIndex
] = equation
;
2242 ADDR_ASSERT_ALWAYS();
2246 // Fill the index into the lookup table, if the combination is not supported
2247 // fill the invalid equation index
2248 m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][bppIdx
] = equationIndex
;
2255 ************************************************************************************************************************
2256 * Gfx9Lib::HwlGetEquationIndex
2259 * Interface function stub of GetEquationIndex
2263 ************************************************************************************************************************
2265 UINT_32
Gfx9Lib::HwlGetEquationIndex(
2266 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
2267 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
2270 AddrResourceType rsrcType
= pIn
->resourceType
;
2271 AddrSwizzleMode swMode
= pIn
->swizzleMode
;
2272 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
2273 UINT_32 index
= ADDR_INVALID_EQUATION_INDEX
;
2275 if (IsEquationSupported(rsrcType
, swMode
, elementBytesLog2
))
2277 UINT_32 rsrcTypeIdx
= static_cast<UINT_32
>(rsrcType
) - 1;
2278 UINT_32 swModeIdx
= static_cast<UINT_32
>(swMode
);
2280 index
= m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][elementBytesLog2
];
2283 if (pOut
->pMipInfo
!= NULL
)
2285 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
2287 pOut
->pMipInfo
[i
].equationIndex
= index
;
2295 ************************************************************************************************************************
2296 * Gfx9Lib::HwlComputeBlock256Equation
2299 * Interface function stub of ComputeBlock256Equation
2303 ************************************************************************************************************************
2305 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeBlock256Equation(
2306 AddrResourceType rsrcType
,
2307 AddrSwizzleMode swMode
,
2308 UINT_32 elementBytesLog2
,
2309 ADDR_EQUATION
* pEquation
) const
2311 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2313 pEquation
->numBits
= 8;
2316 for (; i
< elementBytesLog2
; i
++)
2318 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2321 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2323 const UINT_32 maxBitsUsed
= 4;
2324 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2325 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2327 for (i
= 0; i
< maxBitsUsed
; i
++)
2329 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2330 InitChannel(1, 1, i
, &y
[i
]);
2333 if (IsStandardSwizzle(rsrcType
, swMode
))
2335 switch (elementBytesLog2
)
2378 ADDR_ASSERT_ALWAYS();
2379 ret
= ADDR_INVALIDPARAMS
;
2383 else if (IsDisplaySwizzle(rsrcType
, swMode
))
2385 switch (elementBytesLog2
)
2428 ADDR_ASSERT_ALWAYS();
2429 ret
= ADDR_INVALIDPARAMS
;
2433 else if (IsRotateSwizzle(swMode
))
2435 switch (elementBytesLog2
)
2472 ADDR_ASSERT_ALWAYS();
2474 ret
= ADDR_INVALIDPARAMS
;
2480 ADDR_ASSERT_ALWAYS();
2481 ret
= ADDR_INVALIDPARAMS
;
2487 ASSERTED Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2488 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 0)) ==
2489 (microBlockDim
.w
* (1 << elementBytesLog2
)));
2490 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 1)) == microBlockDim
.h
);
2497 ************************************************************************************************************************
2498 * Gfx9Lib::HwlComputeThinEquation
2501 * Interface function stub of ComputeThinEquation
2505 ************************************************************************************************************************
2507 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThinEquation(
2508 AddrResourceType rsrcType
,
2509 AddrSwizzleMode swMode
,
2510 UINT_32 elementBytesLog2
,
2511 ADDR_EQUATION
* pEquation
) const
2513 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2515 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2517 UINT_32 maxXorBits
= blockSizeLog2
;
2518 if (IsNonPrtXor(swMode
))
2520 // For non-prt-xor, maybe need to initialize some more bits for xor
2521 // The highest xor bit used in equation will be max the following 3 items:
2522 // 1. m_pipeInterleaveLog2 + 2 * pipeXorBits
2523 // 2. m_pipeInterleaveLog2 + pipeXorBits + 2 * bankXorBits
2526 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 2 * GetPipeXorBits(blockSizeLog2
));
2527 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2528 GetPipeXorBits(blockSizeLog2
) +
2529 2 * GetBankXorBits(blockSizeLog2
));
2532 const UINT_32 maxBitsUsed
= 14;
2533 ADDR_ASSERT((2 * maxBitsUsed
) >= maxXorBits
);
2534 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2535 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2537 const UINT_32 extraXorBits
= 16;
2538 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2539 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2541 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2543 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2544 InitChannel(1, 1, i
, &y
[i
]);
2547 ADDR_CHANNEL_SETTING
* pixelBit
= pEquation
->addr
;
2549 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2551 InitChannel(1, 0 , i
, &pixelBit
[i
]);
2556 UINT_32 lowBits
= 0;
2558 if (IsZOrderSwizzle(swMode
))
2560 if (elementBytesLog2
<= 3)
2562 for (UINT_32 i
= elementBytesLog2
; i
< 6; i
++)
2564 pixelBit
[i
] = (((i
- elementBytesLog2
) & 1) == 0) ? x
[xIdx
++] : y
[yIdx
++];
2571 ret
= ADDR_INVALIDPARAMS
;
2576 ret
= HwlComputeBlock256Equation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
2580 Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2581 xIdx
= Log2(microBlockDim
.w
);
2582 yIdx
= Log2(microBlockDim
.h
);
2589 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2591 pixelBit
[i
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2594 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2596 xorExtra
[i
- blockSizeLog2
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2602 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2603 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2605 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2606 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2608 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2610 UINT_32 xor1BitPos
= pipeStart
+ 2 * pipeXorBits
- 1 - i
;
2611 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2612 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2614 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2617 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2619 UINT_32 xor1BitPos
= bankStart
+ 2 * bankXorBits
- 1 - i
;
2620 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2621 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2623 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2626 if (IsPrt(swMode
) == FALSE
)
2628 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2630 InitChannel(1, 2, pipeXorBits
- i
- 1, &pEquation
->xor2
[pipeStart
+ i
]);
2633 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2635 InitChannel(1, 2, bankXorBits
- i
- 1 + pipeXorBits
, &pEquation
->xor2
[bankStart
+ i
]);
2640 pEquation
->numBits
= blockSizeLog2
;
2647 ************************************************************************************************************************
2648 * Gfx9Lib::HwlComputeThickEquation
2651 * Interface function stub of ComputeThickEquation
2655 ************************************************************************************************************************
2657 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThickEquation(
2658 AddrResourceType rsrcType
,
2659 AddrSwizzleMode swMode
,
2660 UINT_32 elementBytesLog2
,
2661 ADDR_EQUATION
* pEquation
) const
2663 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2665 ADDR_ASSERT(IsTex3d(rsrcType
));
2667 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2669 UINT_32 maxXorBits
= blockSizeLog2
;
2670 if (IsNonPrtXor(swMode
))
2672 // For non-prt-xor, maybe need to initialize some more bits for xor
2673 // The highest xor bit used in equation will be max the following 3:
2674 // 1. m_pipeInterleaveLog2 + 3 * pipeXorBits
2675 // 2. m_pipeInterleaveLog2 + pipeXorBits + 3 * bankXorBits
2678 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 3 * GetPipeXorBits(blockSizeLog2
));
2679 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2680 GetPipeXorBits(blockSizeLog2
) +
2681 3 * GetBankXorBits(blockSizeLog2
));
2684 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2686 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2689 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2691 const UINT_32 maxBitsUsed
= 12;
2692 ADDR_ASSERT((3 * maxBitsUsed
) >= maxXorBits
);
2693 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2694 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2695 ADDR_CHANNEL_SETTING z
[maxBitsUsed
] = {};
2697 const UINT_32 extraXorBits
= 24;
2698 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2699 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2701 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2703 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2704 InitChannel(1, 1, i
, &y
[i
]);
2705 InitChannel(1, 2, i
, &z
[i
]);
2708 if (IsZOrderSwizzle(swMode
))
2710 switch (elementBytesLog2
)
2763 ADDR_ASSERT_ALWAYS();
2764 ret
= ADDR_INVALIDPARAMS
;
2768 else if (IsStandardSwizzle(rsrcType
, swMode
))
2770 switch (elementBytesLog2
)
2823 ADDR_ASSERT_ALWAYS();
2824 ret
= ADDR_INVALIDPARAMS
;
2830 ADDR_ASSERT_ALWAYS();
2831 ret
= ADDR_INVALIDPARAMS
;
2836 Dim3d microBlockDim
= Block1K_3d
[elementBytesLog2
];
2837 UINT_32 xIdx
= Log2(microBlockDim
.w
);
2838 UINT_32 yIdx
= Log2(microBlockDim
.h
);
2839 UINT_32 zIdx
= Log2(microBlockDim
.d
);
2841 pixelBit
= pEquation
->addr
;
2843 const UINT_32 lowBits
= 10;
2844 ADDR_ASSERT(pEquation
->addr
[lowBits
- 1].valid
== 1);
2845 ADDR_ASSERT(pEquation
->addr
[lowBits
].valid
== 0);
2847 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2851 pixelBit
[i
] = x
[xIdx
++];
2853 else if ((i
% 3) == 1)
2855 pixelBit
[i
] = z
[zIdx
++];
2859 pixelBit
[i
] = y
[yIdx
++];
2863 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2867 xorExtra
[i
- blockSizeLog2
] = x
[xIdx
++];
2869 else if ((i
% 3) == 1)
2871 xorExtra
[i
- blockSizeLog2
] = z
[zIdx
++];
2875 xorExtra
[i
- blockSizeLog2
] = y
[yIdx
++];
2882 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2883 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2884 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2886 UINT_32 xor1BitPos
= pipeStart
+ (3 * pipeXorBits
) - 1 - (2 * i
);
2887 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2888 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2890 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2892 UINT_32 xor2BitPos
= pipeStart
+ (3 * pipeXorBits
) - 2 - (2 * i
);
2893 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2894 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2896 InitChannel(&pEquation
->xor2
[pipeStart
+ i
], pXor2Src
);
2899 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2900 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2901 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2903 UINT_32 xor1BitPos
= bankStart
+ (3 * bankXorBits
) - 1 - (2 * i
);
2904 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2905 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2907 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2909 UINT_32 xor2BitPos
= bankStart
+ (3 * bankXorBits
) - 2 - (2 * i
);
2910 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2911 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2913 InitChannel(&pEquation
->xor2
[bankStart
+ i
], pXor2Src
);
2917 pEquation
->numBits
= blockSizeLog2
;
2924 ************************************************************************************************************************
2925 * Gfx9Lib::IsValidDisplaySwizzleMode
2928 * Check if a swizzle mode is supported by display engine
2931 * TRUE is swizzle mode is supported by display engine
2932 ************************************************************************************************************************
2934 BOOL_32
Gfx9Lib::IsValidDisplaySwizzleMode(
2935 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
2937 BOOL_32 support
= FALSE
;
2939 if (m_settings
.isDce12
)
2941 switch (pIn
->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
:
2953 case ADDR_SW_4KB_D_X
:
2954 case ADDR_SW_4KB_R_X
:
2955 case ADDR_SW_64KB_D_X
:
2956 case ADDR_SW_64KB_R_X
:
2957 support
= (pIn
->bpp
<= 64);
2964 else if (m_settings
.isDcn1
)
2966 switch (pIn
->swizzleMode
)
2969 case ADDR_SW_64KB_D
:
2970 case ADDR_SW_64KB_D_T
:
2971 case ADDR_SW_4KB_D_X
:
2972 case ADDR_SW_64KB_D_X
:
2973 support
= (pIn
->bpp
== 64);
2976 case ADDR_SW_LINEAR
:
2978 case ADDR_SW_64KB_S
:
2979 case ADDR_SW_64KB_S_T
:
2980 case ADDR_SW_4KB_S_X
:
2981 case ADDR_SW_64KB_S_X
:
2982 support
= (pIn
->bpp
<= 64);
2991 ADDR_NOT_IMPLEMENTED();
2998 ************************************************************************************************************************
2999 * Gfx9Lib::HwlComputePipeBankXor
3002 * Generate a PipeBankXor value to be ORed into bits above pipeInterleaveBits of address
3006 ************************************************************************************************************************
3008 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputePipeBankXor(
3009 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
3010 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
) const
3012 if (IsXor(pIn
->swizzleMode
))
3014 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3015 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3016 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3018 UINT_32 pipeXor
= 0;
3019 UINT_32 bankXor
= 0;
3021 const UINT_32 bankMask
= (1 << bankBits
) - 1;
3022 const UINT_32 index
= pIn
->surfIndex
& bankMask
;
3024 const UINT_32 bpp
= pIn
->flags
.fmask
?
3025 GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
) : GetElemLib()->GetBitsPerPixel(pIn
->format
);
3028 static const UINT_32 BankXorSmallBpp
[] = {0, 7, 4, 3, 8, 15, 12, 11, 1, 6, 5, 2, 9, 14, 13, 10};
3029 static const UINT_32 BankXorLargeBpp
[] = {0, 7, 8, 15, 4, 3, 12, 11, 1, 6, 9, 14, 5, 2, 13, 10};
3031 bankXor
= (bpp
<= 32) ? BankXorSmallBpp
[index
] : BankXorLargeBpp
[index
];
3033 else if (bankBits
> 0)
3035 UINT_32 bankIncrease
= (1 << (bankBits
- 1)) - 1;
3036 bankIncrease
= (bankIncrease
== 0) ? 1 : bankIncrease
;
3037 bankXor
= (index
* bankIncrease
) & bankMask
;
3040 pOut
->pipeBankXor
= (bankXor
<< pipeBits
) | pipeXor
;
3044 pOut
->pipeBankXor
= 0;
3051 ************************************************************************************************************************
3052 * Gfx9Lib::HwlComputeSlicePipeBankXor
3055 * Generate slice PipeBankXor value based on base PipeBankXor value and slice id
3059 ************************************************************************************************************************
3061 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSlicePipeBankXor(
3062 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
3063 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
) const
3065 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3066 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3067 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3069 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
3070 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
3072 pOut
->pipeBankXor
= pIn
->basePipeBankXor
^ (pipeXor
| (bankXor
<< pipeBits
));
3078 ************************************************************************************************************************
3079 * Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern
3082 * Compute sub resource offset to support swizzle pattern
3086 ************************************************************************************************************************
3088 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern(
3089 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
3090 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
) const
3092 ADDR_ASSERT(IsThin(pIn
->resourceType
, pIn
->swizzleMode
));
3094 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3095 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3096 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3097 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
3098 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
3099 UINT_32 pipeBankXor
= ((pipeXor
| (bankXor
<< pipeBits
)) ^ (pIn
->pipeBankXor
)) << m_pipeInterleaveLog2
;
3101 pOut
->offset
= pIn
->slice
* pIn
->sliceSize
+
3102 pIn
->macroBlockOffset
+
3103 (pIn
->mipTailOffset
^ pipeBankXor
) -
3104 static_cast<UINT_64
>(pipeBankXor
);
3109 ************************************************************************************************************************
3110 * Gfx9Lib::ValidateNonSwModeParams
3113 * Validate compute surface info params except swizzle mode
3116 * TRUE if parameters are valid, FALSE otherwise
3117 ************************************************************************************************************************
3119 BOOL_32
Gfx9Lib::ValidateNonSwModeParams(
3120 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3122 BOOL_32 valid
= TRUE
;
3124 if ((pIn
->bpp
== 0) || (pIn
->bpp
> 128) || (pIn
->width
== 0) || (pIn
->numFrags
> 8) || (pIn
->numSamples
> 16))
3126 ADDR_ASSERT_ALWAYS();
3130 if (pIn
->resourceType
>= ADDR_RSRC_MAX_TYPE
)
3132 ADDR_ASSERT_ALWAYS();
3136 const BOOL_32 mipmap
= (pIn
->numMipLevels
> 1);
3137 const BOOL_32 msaa
= (pIn
->numFrags
> 1);
3138 const BOOL_32 isBc
= ElemLib::IsBlockCompressed(pIn
->format
);
3140 const AddrResourceType rsrcType
= pIn
->resourceType
;
3141 const BOOL_32 tex3d
= IsTex3d(rsrcType
);
3142 const BOOL_32 tex2d
= IsTex2d(rsrcType
);
3143 const BOOL_32 tex1d
= IsTex1d(rsrcType
);
3145 const ADDR2_SURFACE_FLAGS flags
= pIn
->flags
;
3146 const BOOL_32 zbuffer
= flags
.depth
|| flags
.stencil
;
3147 const BOOL_32 display
= flags
.display
|| flags
.rotated
;
3148 const BOOL_32 stereo
= flags
.qbStereo
;
3149 const BOOL_32 fmask
= flags
.fmask
;
3151 // Resource type check
3154 if (msaa
|| zbuffer
|| display
|| stereo
|| isBc
|| fmask
)
3156 ADDR_ASSERT_ALWAYS();
3162 if ((msaa
&& mipmap
) || (stereo
&& msaa
) || (stereo
&& mipmap
))
3164 ADDR_ASSERT_ALWAYS();
3170 if (msaa
|| zbuffer
|| display
|| stereo
|| fmask
)
3172 ADDR_ASSERT_ALWAYS();
3178 ADDR_ASSERT_ALWAYS();
3186 ************************************************************************************************************************
3187 * Gfx9Lib::ValidateSwModeParams
3190 * Validate compute surface info related to swizzle mode
3193 * TRUE if parameters are valid, FALSE otherwise
3194 ************************************************************************************************************************
3196 BOOL_32
Gfx9Lib::ValidateSwModeParams(
3197 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3199 BOOL_32 valid
= TRUE
;
3201 if ((pIn
->swizzleMode
>= ADDR_SW_MAX_TYPE
) || (IsValidSwMode(pIn
->swizzleMode
) == FALSE
))
3203 ADDR_ASSERT_ALWAYS();
3207 const BOOL_32 mipmap
= (pIn
->numMipLevels
> 1);
3208 const BOOL_32 msaa
= (pIn
->numFrags
> 1);
3209 const BOOL_32 isBc
= ElemLib::IsBlockCompressed(pIn
->format
);
3210 const BOOL_32 is422
= ElemLib::IsMacroPixelPacked(pIn
->format
);
3212 const AddrResourceType rsrcType
= pIn
->resourceType
;
3213 const BOOL_32 tex3d
= IsTex3d(rsrcType
);
3214 const BOOL_32 tex2d
= IsTex2d(rsrcType
);
3215 const BOOL_32 tex1d
= IsTex1d(rsrcType
);
3217 const AddrSwizzleMode swizzle
= pIn
->swizzleMode
;
3218 const BOOL_32 linear
= IsLinear(swizzle
);
3219 const BOOL_32 blk256B
= IsBlock256b(swizzle
);
3220 const BOOL_32 isNonPrtXor
= IsNonPrtXor(swizzle
);
3222 const ADDR2_SURFACE_FLAGS flags
= pIn
->flags
;
3223 const BOOL_32 zbuffer
= flags
.depth
|| flags
.stencil
;
3224 const BOOL_32 color
= flags
.color
;
3225 const BOOL_32 texture
= flags
.texture
;
3226 const BOOL_32 display
= flags
.display
|| flags
.rotated
;
3227 const BOOL_32 prt
= flags
.prt
;
3228 const BOOL_32 fmask
= flags
.fmask
;
3230 const BOOL_32 thin3d
= tex3d
&& flags
.view3dAs2dArray
;
3231 const BOOL_32 zMaxMip
= tex3d
&& mipmap
&&
3232 (pIn
->numSlices
>= pIn
->width
) && (pIn
->numSlices
>= pIn
->height
);
3235 if (msaa
&& (GetBlockSize(swizzle
) < (m_pipeInterleaveBytes
* pIn
->numFrags
)))
3237 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3238 ADDR_ASSERT_ALWAYS();
3242 if (display
&& (IsValidDisplaySwizzleMode(pIn
) == FALSE
))
3244 ADDR_ASSERT_ALWAYS();
3248 if ((pIn
->bpp
== 96) && (linear
== FALSE
))
3250 ADDR_ASSERT_ALWAYS();
3254 if (prt
&& isNonPrtXor
)
3256 ADDR_ASSERT_ALWAYS();
3260 // Resource type check
3263 if (linear
== FALSE
)
3265 ADDR_ASSERT_ALWAYS();
3270 // Swizzle type check
3273 if (((tex1d
== FALSE
) && prt
) || zbuffer
|| msaa
|| (pIn
->bpp
== 0) ||
3274 ((pIn
->bpp
% 8) != 0) || (isBc
&& texture
) || fmask
)
3276 ADDR_ASSERT_ALWAYS();
3280 else if (IsZOrderSwizzle(swizzle
))
3282 if ((color
&& msaa
) || thin3d
|| isBc
|| is422
|| (tex2d
&& (pIn
->bpp
> 64)) || (msaa
&& (pIn
->bpp
> 32)))
3284 ADDR_ASSERT_ALWAYS();
3288 else if (IsStandardSwizzle(swizzle
))
3290 if (zbuffer
|| thin3d
|| (tex3d
&& (pIn
->bpp
== 128) && color
) || fmask
)
3292 ADDR_ASSERT_ALWAYS();
3296 else if (IsDisplaySwizzle(swizzle
))
3298 if (zbuffer
|| (prt
&& tex3d
) || fmask
|| zMaxMip
)
3300 ADDR_ASSERT_ALWAYS();
3304 else if (IsRotateSwizzle(swizzle
))
3306 if (zbuffer
|| (pIn
->bpp
> 64) || tex3d
|| isBc
|| fmask
)
3308 ADDR_ASSERT_ALWAYS();
3314 ADDR_ASSERT_ALWAYS();
3321 if (prt
|| zbuffer
|| tex3d
|| mipmap
|| msaa
)
3323 ADDR_ASSERT_ALWAYS();
3332 ************************************************************************************************************************
3333 * Gfx9Lib::HwlComputeSurfaceInfoSanityCheck
3336 * Compute surface info sanity check
3339 * ADDR_OK if parameters are valid, ADDR_INVALIDPARAMS otherwise
3340 ************************************************************************************************************************
3342 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoSanityCheck(
3343 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3345 return ValidateNonSwModeParams(pIn
) && ValidateSwModeParams(pIn
) ? ADDR_OK
: ADDR_INVALIDPARAMS
;
3349 ************************************************************************************************************************
3350 * Gfx9Lib::HwlGetPreferredSurfaceSetting
3353 * Internal function to get suggested surface information for cliet to use
3357 ************************************************************************************************************************
3359 ADDR_E_RETURNCODE
Gfx9Lib::HwlGetPreferredSurfaceSetting(
3360 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
3361 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const
3363 ADDR_E_RETURNCODE returnCode
= ADDR_INVALIDPARAMS
;
3364 ElemLib
* pElemLib
= GetElemLib();
3366 UINT_32 bpp
= pIn
->bpp
;
3367 UINT_32 width
= Max(pIn
->width
, 1u);
3368 UINT_32 height
= Max(pIn
->height
, 1u);
3369 UINT_32 numSamples
= Max(pIn
->numSamples
, 1u);
3370 UINT_32 numFrags
= (pIn
->numFrags
== 0) ? numSamples
: pIn
->numFrags
;
3372 if (pIn
->flags
.fmask
)
3374 bpp
= GetFmaskBpp(numSamples
, numFrags
);
3377 pOut
->resourceType
= ADDR_RSRC_TEX_2D
;
3381 // Set format to INVALID will skip this conversion
3382 if (pIn
->format
!= ADDR_FMT_INVALID
)
3384 UINT_32 expandX
, expandY
;
3386 // Don't care for this case
3387 ElemMode elemMode
= ADDR_UNCOMPRESSED
;
3389 // Get compression/expansion factors and element mode which indicates compression/expansion
3390 bpp
= pElemLib
->GetBitsPerPixel(pIn
->format
,
3395 UINT_32 basePitch
= 0;
3396 GetElemLib()->AdjustSurfaceInfo(elemMode
,
3405 // The output may get changed for volume(3D) texture resource in future
3406 pOut
->resourceType
= pIn
->resourceType
;
3409 const UINT_32 numSlices
= Max(pIn
->numSlices
, 1u);
3410 const UINT_32 numMipLevels
= Max(pIn
->numMipLevels
, 1u);
3411 const BOOL_32 msaa
= (numFrags
> 1) || (numSamples
> 1);
3412 const BOOL_32 displayRsrc
= pIn
->flags
.display
|| pIn
->flags
.rotated
;
3414 // Pre sanity check on non swizzle mode parameters
3415 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {};
3416 localIn
.flags
= pIn
->flags
;
3417 localIn
.resourceType
= pOut
->resourceType
;
3418 localIn
.format
= pIn
->format
;
3420 localIn
.width
= width
;
3421 localIn
.height
= height
;
3422 localIn
.numSlices
= numSlices
;
3423 localIn
.numMipLevels
= numMipLevels
;
3424 localIn
.numSamples
= numSamples
;
3425 localIn
.numFrags
= numFrags
;
3427 if (ValidateNonSwModeParams(&localIn
))
3429 // Forbid swizzle mode(s) by client setting
3430 ADDR2_SWMODE_SET allowedSwModeSet
= {};
3431 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.linear
? 0 : Gfx9LinearSwModeMask
;
3432 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.micro
? 0 : Gfx9Blk256BSwModeMask
;
3433 allowedSwModeSet
.value
|=
3434 pIn
->forbiddenBlock
.macroThin4KB
? 0 :
3435 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThin4KBSwModeMask
: Gfx9Blk4KBSwModeMask
);
3436 allowedSwModeSet
.value
|=
3437 pIn
->forbiddenBlock
.macroThick4KB
? 0 :
3438 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThick4KBSwModeMask
: 0);
3439 allowedSwModeSet
.value
|=
3440 pIn
->forbiddenBlock
.macroThin64KB
? 0 :
3441 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThin64KBSwModeMask
: Gfx9Blk64KBSwModeMask
);
3442 allowedSwModeSet
.value
|=
3443 pIn
->forbiddenBlock
.macroThick64KB
? 0 :
3444 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThick64KBSwModeMask
: 0);
3446 if (pIn
->preferredSwSet
.value
!= 0)
3448 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_Z
? ~0 : ~Gfx9ZSwModeMask
;
3449 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_S
? ~0 : ~Gfx9StandardSwModeMask
;
3450 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_D
? ~0 : ~Gfx9DisplaySwModeMask
;
3451 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_R
? ~0 : ~Gfx9RotateSwModeMask
;
3456 allowedSwModeSet
.value
&= ~Gfx9XorSwModeMask
;
3459 if (pIn
->maxAlign
> 0)
3461 if (pIn
->maxAlign
< Size64K
)
3463 allowedSwModeSet
.value
&= ~Gfx9Blk64KBSwModeMask
;
3466 if (pIn
->maxAlign
< Size4K
)
3468 allowedSwModeSet
.value
&= ~Gfx9Blk4KBSwModeMask
;
3471 if (pIn
->maxAlign
< Size256
)
3473 allowedSwModeSet
.value
&= ~Gfx9Blk256BSwModeMask
;
3477 // Filter out invalid swizzle mode(s) by image attributes and HW restrictions
3478 switch (pOut
->resourceType
)
3480 case ADDR_RSRC_TEX_1D
:
3481 allowedSwModeSet
.value
&= Gfx9Rsrc1dSwModeMask
;
3484 case ADDR_RSRC_TEX_2D
:
3485 allowedSwModeSet
.value
&= pIn
->flags
.prt
? Gfx9Rsrc2dPrtSwModeMask
: Gfx9Rsrc2dSwModeMask
;
3489 allowedSwModeSet
.value
&= ~(Gfx9RotateSwModeMask
| Gfx9ZSwModeMask
);
3493 case ADDR_RSRC_TEX_3D
:
3494 allowedSwModeSet
.value
&= pIn
->flags
.prt
? Gfx9Rsrc3dPrtSwModeMask
: Gfx9Rsrc3dSwModeMask
;
3496 if ((numMipLevels
> 1) && (numSlices
>= width
) && (numSlices
>= height
))
3498 // SW_*_D for 3D mipmaps (maxmip > 0) is only supported for Xmajor or Ymajor mipmap
3499 // When depth (Z) is the maximum dimension then must use one of the SW_*_S
3500 // or SW_*_Z modes if mipmapping is desired on a 3D surface
3501 allowedSwModeSet
.value
&= ~Gfx9DisplaySwModeMask
;
3504 if ((bpp
== 128) && pIn
->flags
.color
)
3506 allowedSwModeSet
.value
&= ~Gfx9StandardSwModeMask
;
3509 if (pIn
->flags
.view3dAs2dArray
)
3511 allowedSwModeSet
.value
&= Gfx9Rsrc3dThinSwModeMask
| Gfx9LinearSwModeMask
;
3516 ADDR_ASSERT_ALWAYS();
3517 allowedSwModeSet
.value
= 0;
3521 if (pIn
->format
== ADDR_FMT_32_32_32
)
3523 allowedSwModeSet
.value
&= Gfx9LinearSwModeMask
;
3526 if (ElemLib::IsBlockCompressed(pIn
->format
))
3528 if (pIn
->flags
.texture
)
3530 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
| Gfx9DisplaySwModeMask
;
3534 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
| Gfx9DisplaySwModeMask
| Gfx9LinearSwModeMask
;
3538 if (ElemLib::IsMacroPixelPacked(pIn
->format
) ||
3539 (msaa
&& ((bpp
> 32) || pIn
->flags
.color
|| pIn
->flags
.unordered
)))
3541 allowedSwModeSet
.value
&= ~Gfx9ZSwModeMask
;
3544 if (pIn
->flags
.fmask
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
)
3546 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3548 if (pIn
->flags
.noMetadata
== FALSE
)
3550 if (pIn
->flags
.depth
&&
3551 pIn
->flags
.texture
&&
3552 (((bpp
== 16) && (numFrags
>= 4)) || ((bpp
== 32) && (numFrags
>= 2))))
3554 // When _X/_T swizzle mode was used for MSAA depth texture, TC will get zplane
3555 // equation from wrong address within memory range a tile covered and use the
3556 // garbage data for compressed Z reading which finally leads to corruption.
3557 allowedSwModeSet
.value
&= ~Gfx9XorSwModeMask
;
3560 if (m_settings
.htileCacheRbConflict
&&
3561 (pIn
->flags
.depth
|| pIn
->flags
.stencil
) &&
3563 (pIn
->flags
.metaRbUnaligned
== FALSE
) &&
3564 (pIn
->flags
.metaPipeUnaligned
== FALSE
))
3566 // Z_X 2D array with Rb/Pipe aligned HTile won't have metadata cache coherency
3567 allowedSwModeSet
.value
&= ~Gfx9XSwModeMask
;
3574 allowedSwModeSet
.value
&= Gfx9MsaaSwModeMask
;
3577 if ((numFrags
> 1) &&
3578 (Size4K
< (m_pipeInterleaveBytes
* numFrags
)))
3580 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3581 allowedSwModeSet
.value
&= Gfx9Blk64KBSwModeMask
;
3584 if (numMipLevels
> 1)
3586 allowedSwModeSet
.value
&= ~Gfx9Blk256BSwModeMask
;
3591 if (m_settings
.isDce12
)
3593 allowedSwModeSet
.value
&= (bpp
== 32) ? Dce12Bpp32SwModeMask
: Dce12NonBpp32SwModeMask
;
3595 else if (m_settings
.isDcn1
)
3597 allowedSwModeSet
.value
&= (bpp
== 64) ? Dcn1Bpp64SwModeMask
: Dcn1NonBpp64SwModeMask
;
3601 ADDR_NOT_IMPLEMENTED();
3605 if (allowedSwModeSet
.value
!= 0)
3608 // Post sanity check, at least AddrLib should accept the output generated by its own
3609 UINT_32 validateSwModeSet
= allowedSwModeSet
.value
;
3611 for (UINT_32 i
= 0; validateSwModeSet
!= 0; i
++)
3613 if (validateSwModeSet
& 1)
3615 localIn
.swizzleMode
= static_cast<AddrSwizzleMode
>(i
);
3616 ADDR_ASSERT(ValidateSwModeParams(&localIn
));
3619 validateSwModeSet
>>= 1;
3623 pOut
->validSwModeSet
= allowedSwModeSet
;
3624 pOut
->canXor
= (allowedSwModeSet
.value
& Gfx9XorSwModeMask
) ? TRUE
: FALSE
;
3625 pOut
->validBlockSet
= GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
);
3626 pOut
->validSwTypeSet
= GetAllowedSwSet(allowedSwModeSet
);
3628 pOut
->clientPreferredSwSet
= pIn
->preferredSwSet
;
3630 if (pOut
->clientPreferredSwSet
.value
== 0)
3632 pOut
->clientPreferredSwSet
.value
= AddrSwSetAll
;
3635 // Apply optional restrictions
3636 if (pIn
->flags
.needEquation
)
3638 FilterInvalidEqSwizzleMode(allowedSwModeSet
, pIn
->resourceType
, Log2(bpp
>> 3));
3641 if (allowedSwModeSet
.value
== Gfx9LinearSwModeMask
)
3643 pOut
->swizzleMode
= ADDR_SW_LINEAR
;
3647 // Always ignore linear swizzle mode if there is other choice.
3648 allowedSwModeSet
.swLinear
= 0;
3650 ADDR2_BLOCK_SET allowedBlockSet
= GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
);
3652 // Determine block size if there is 2 or more block type candidates
3653 if (IsPow2(allowedBlockSet
.value
) == FALSE
)
3655 AddrSwizzleMode swMode
[AddrBlockMaxTiledType
] = { ADDR_SW_LINEAR
};
3657 swMode
[AddrBlockMicro
] = ADDR_SW_256B_D
;
3658 swMode
[AddrBlockThin4KB
] = ADDR_SW_4KB_D
;
3659 swMode
[AddrBlockThin64KB
] = ADDR_SW_64KB_D
;
3661 if (pOut
->resourceType
== ADDR_RSRC_TEX_3D
)
3663 swMode
[AddrBlockThick4KB
] = ADDR_SW_4KB_S
;
3664 swMode
[AddrBlockThick64KB
] = ADDR_SW_64KB_S
;
3667 Dim3d blkDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}, {0}, {0}, {0}};
3668 Dim3d padDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}, {0}, {0}, {0}};
3669 UINT_64 padSize
[AddrBlockMaxTiledType
] = {0};
3671 const UINT_32 ratioLow
= pIn
->flags
.minimizeAlign
? 1 : (pIn
->flags
.opt4space
? 3 : 2);
3672 const UINT_32 ratioHi
= pIn
->flags
.minimizeAlign
? 1 : (pIn
->flags
.opt4space
? 2 : 1);
3673 const UINT_64 sizeAlignInElement
= Max(NextPow2(pIn
->minSizeAlign
) / (bpp
>> 3), 1u);
3674 UINT_32 minSizeBlk
= AddrBlockMicro
;
3675 UINT_64 minSize
= 0;
3677 for (UINT_32 i
= AddrBlockMicro
; i
< AddrBlockMaxTiledType
; i
++)
3679 if (allowedBlockSet
.value
& (1 << i
))
3681 ComputeBlockDimensionForSurf(&blkDim
[i
].w
,
3691 blkDim
[i
].w
= PowTwoAlign(blkDim
[i
].w
, 32);
3694 padSize
[i
] = ComputePadSize(&blkDim
[i
], width
, height
, numSlices
, &padDim
[i
]);
3695 padSize
[i
] = PowTwoAlign(padSize
[i
] * numFrags
, sizeAlignInElement
);
3697 if ((minSize
== 0) ||
3698 ((padSize
[i
] * ratioHi
) <= (minSize
* ratioLow
)))
3700 minSize
= padSize
[i
];
3706 if ((allowedBlockSet
.micro
== TRUE
) &&
3707 (width
<= blkDim
[AddrBlockMicro
].w
) &&
3708 (height
<= blkDim
[AddrBlockMicro
].h
) &&
3709 (NextPow2(pIn
->minSizeAlign
) <= Size256
))
3711 minSizeBlk
= AddrBlockMicro
;
3714 if (minSizeBlk
== AddrBlockMicro
)
3716 ADDR_ASSERT(pOut
->resourceType
!= ADDR_RSRC_TEX_3D
);
3717 allowedSwModeSet
.value
&= Gfx9Blk256BSwModeMask
;
3719 else if (minSizeBlk
== AddrBlockThick4KB
)
3721 ADDR_ASSERT(pOut
->resourceType
== ADDR_RSRC_TEX_3D
);
3722 allowedSwModeSet
.value
&= Gfx9Rsrc3dThick4KBSwModeMask
;
3724 else if (minSizeBlk
== AddrBlockThin4KB
)
3726 allowedSwModeSet
.value
&= (pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ?
3727 Gfx9Rsrc3dThin4KBSwModeMask
: Gfx9Blk4KBSwModeMask
;
3729 else if (minSizeBlk
== AddrBlockThick64KB
)
3731 ADDR_ASSERT(pOut
->resourceType
== ADDR_RSRC_TEX_3D
);
3732 allowedSwModeSet
.value
&= Gfx9Rsrc3dThick64KBSwModeMask
;
3736 ADDR_ASSERT(minSizeBlk
== AddrBlockThin64KB
);
3737 allowedSwModeSet
.value
&= (pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ?
3738 Gfx9Rsrc3dThin64KBSwModeMask
: Gfx9Blk64KBSwModeMask
;
3742 // Block type should be determined.
3743 ADDR_ASSERT(IsPow2(GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
).value
));
3745 ADDR2_SWTYPE_SET allowedSwSet
= GetAllowedSwSet(allowedSwModeSet
);
3747 // Determine swizzle type if there is 2 or more swizzle type candidates
3748 if (IsPow2(allowedSwSet
.value
) == FALSE
)
3750 if (ElemLib::IsBlockCompressed(pIn
->format
))
3752 if (allowedSwSet
.sw_D
)
3754 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3758 ADDR_ASSERT(allowedSwSet
.sw_S
);
3759 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3762 else if (ElemLib::IsMacroPixelPacked(pIn
->format
))
3764 if (allowedSwSet
.sw_S
)
3766 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3768 else if (allowedSwSet
.sw_D
)
3770 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3774 ADDR_ASSERT(allowedSwSet
.sw_R
);
3775 allowedSwModeSet
.value
&= Gfx9RotateSwModeMask
;
3778 else if (pOut
->resourceType
== ADDR_RSRC_TEX_3D
)
3780 if (pIn
->flags
.color
&& allowedSwSet
.sw_D
)
3782 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3784 else if (allowedSwSet
.sw_Z
)
3786 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3790 ADDR_ASSERT(allowedSwSet
.sw_S
);
3791 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3796 if (pIn
->flags
.rotated
&& allowedSwSet
.sw_R
)
3798 allowedSwModeSet
.value
&= Gfx9RotateSwModeMask
;
3800 else if (allowedSwSet
.sw_D
)
3802 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3804 else if (allowedSwSet
.sw_S
)
3806 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3810 ADDR_ASSERT(allowedSwSet
.sw_Z
);
3811 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3816 // Swizzle type should be determined.
3817 ADDR_ASSERT(IsPow2(GetAllowedSwSet(allowedSwModeSet
).value
));
3819 // Determine swizzle mode now. Always select the "largest" swizzle mode for a given block type + swizzle
3820 // type combination. For example, for AddrBlockThin64KB + ADDR_SW_S, select SW_64KB_S_X(25) if it's
3821 // available, or otherwise select SW_64KB_S_T(17) if it's available, or otherwise select SW_64KB_S(9).
3822 pOut
->swizzleMode
= static_cast<AddrSwizzleMode
>(Log2NonPow2(allowedSwModeSet
.value
));
3825 returnCode
= ADDR_OK
;
3829 // Invalid combination...
3830 ADDR_ASSERT_ALWAYS();
3835 // Invalid combination...
3836 ADDR_ASSERT_ALWAYS();
3843 ************************************************************************************************************************
3844 * Gfx9Lib::ComputeStereoInfo
3847 * Compute height alignment and right eye pipeBankXor for stereo surface
3852 ************************************************************************************************************************
3854 ADDR_E_RETURNCODE
Gfx9Lib::ComputeStereoInfo(
3855 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
3856 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
,
3857 UINT_32
* pHeightAlign
3860 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3862 UINT_32 eqIndex
= HwlGetEquationIndex(pIn
, pOut
);
3864 if (eqIndex
< m_numEquations
)
3866 if (IsXor(pIn
->swizzleMode
))
3868 const UINT_32 blkSizeLog2
= GetBlockSizeLog2(pIn
->swizzleMode
);
3869 const UINT_32 numPipeBits
= GetPipeXorBits(blkSizeLog2
);
3870 const UINT_32 numBankBits
= GetBankXorBits(blkSizeLog2
);
3871 const UINT_32 bppLog2
= Log2(pIn
->bpp
>> 3);
3872 const UINT_32 maxYCoordBlock256
= Log2(Block256_2d
[bppLog2
].h
) - 1;
3873 const ADDR_EQUATION
*pEqToCheck
= &m_equationTable
[eqIndex
];
3875 ADDR_ASSERT(maxYCoordBlock256
==
3876 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], Log2Size256
, 1));
3878 const UINT_32 maxYCoordInBaseEquation
=
3879 (blkSizeLog2
- Log2Size256
) / 2 + maxYCoordBlock256
;
3881 ADDR_ASSERT(maxYCoordInBaseEquation
==
3882 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], blkSizeLog2
, 1));
3884 const UINT_32 maxYCoordInPipeXor
= (numPipeBits
== 0) ? 0 : maxYCoordBlock256
+ numPipeBits
;
3886 ADDR_ASSERT(maxYCoordInPipeXor
==
3887 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
], numPipeBits
, 1));
3889 const UINT_32 maxYCoordInBankXor
= (numBankBits
== 0) ?
3890 0 : maxYCoordBlock256
+ (numPipeBits
+ 1) / 2 + numBankBits
;
3892 ADDR_ASSERT(maxYCoordInBankXor
==
3893 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
+ numPipeBits
], numBankBits
, 1));
3895 const UINT_32 maxYCoordInPipeBankXor
= Max(maxYCoordInPipeXor
, maxYCoordInBankXor
);
3897 if (maxYCoordInPipeBankXor
> maxYCoordInBaseEquation
)
3899 *pHeightAlign
= 1u << maxYCoordInPipeBankXor
;
3901 if (pOut
->pStereoInfo
!= NULL
)
3903 pOut
->pStereoInfo
->rightSwizzle
= 0;
3905 if ((PowTwoAlign(pIn
->height
, *pHeightAlign
) % (*pHeightAlign
* 2)) != 0)
3907 if (maxYCoordInPipeXor
== maxYCoordInPipeBankXor
)
3909 pOut
->pStereoInfo
->rightSwizzle
|= (1u << 1);
3912 if (maxYCoordInBankXor
== maxYCoordInPipeBankXor
)
3914 pOut
->pStereoInfo
->rightSwizzle
|=
3915 1u << ((numPipeBits
% 2) ? numPipeBits
: numPipeBits
+ 1);
3918 ADDR_ASSERT(pOut
->pStereoInfo
->rightSwizzle
==
3919 GetCoordActiveMask(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
],
3920 numPipeBits
+ numBankBits
, 1, maxYCoordInPipeBankXor
));
3928 ADDR_ASSERT_ALWAYS();
3929 returnCode
= ADDR_ERROR
;
3936 ************************************************************************************************************************
3937 * Gfx9Lib::HwlComputeSurfaceInfoTiled
3940 * Internal function to calculate alignment for tiled surface
3944 ************************************************************************************************************************
3946 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoTiled(
3947 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
3948 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
3951 ADDR_E_RETURNCODE returnCode
= ComputeBlockDimensionForSurf(&pOut
->blockWidth
,
3959 if (returnCode
== ADDR_OK
)
3961 UINT_32 pitchAlignInElement
= pOut
->blockWidth
;
3963 if ((IsTex2d(pIn
->resourceType
) == TRUE
) &&
3964 (pIn
->flags
.display
|| pIn
->flags
.rotated
) &&
3965 (pIn
->numMipLevels
<= 1) &&
3966 (pIn
->numSamples
<= 1) &&
3967 (pIn
->numFrags
<= 1))
3969 // Display engine needs pitch align to be at least 32 pixels.
3970 pitchAlignInElement
= PowTwoAlign(pitchAlignInElement
, 32);
3973 pOut
->pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
3975 if ((pIn
->numMipLevels
<= 1) && (pIn
->pitchInElement
> 0))
3977 if ((pIn
->pitchInElement
% pitchAlignInElement
) != 0)
3979 returnCode
= ADDR_INVALIDPARAMS
;
3981 else if (pIn
->pitchInElement
< pOut
->pitch
)
3983 returnCode
= ADDR_INVALIDPARAMS
;
3987 pOut
->pitch
= pIn
->pitchInElement
;
3991 UINT_32 heightAlign
= 0;
3993 if (pIn
->flags
.qbStereo
)
3995 returnCode
= ComputeStereoInfo(pIn
, pOut
, &heightAlign
);
3998 if (returnCode
== ADDR_OK
)
4000 pOut
->height
= PowTwoAlign(pIn
->height
, pOut
->blockHeight
);
4002 if (heightAlign
> 1)
4004 pOut
->height
= PowTwoAlign(pOut
->height
, heightAlign
);
4007 pOut
->numSlices
= PowTwoAlign(pIn
->numSlices
, pOut
->blockSlices
);
4009 pOut
->epitchIsHeight
= FALSE
;
4010 pOut
->mipChainInTail
= FALSE
;
4011 pOut
->firstMipIdInTail
= pIn
->numMipLevels
;
4013 pOut
->mipChainPitch
= pOut
->pitch
;
4014 pOut
->mipChainHeight
= pOut
->height
;
4015 pOut
->mipChainSlice
= pOut
->numSlices
;
4017 if (pIn
->numMipLevels
> 1)
4019 pOut
->firstMipIdInTail
= GetMipChainInfo(pIn
->resourceType
,
4031 const UINT_32 endingMipId
= Min(pOut
->firstMipIdInTail
, pIn
->numMipLevels
- 1);
4033 if (endingMipId
== 0)
4035 const Dim3d tailMaxDim
= GetMipTailDim(pIn
->resourceType
,
4041 pOut
->epitchIsHeight
= TRUE
;
4042 pOut
->pitch
= tailMaxDim
.w
;
4043 pOut
->height
= tailMaxDim
.h
;
4044 pOut
->numSlices
= IsThick(pIn
->resourceType
, pIn
->swizzleMode
) ?
4045 tailMaxDim
.d
: pIn
->numSlices
;
4046 pOut
->mipChainInTail
= TRUE
;
4050 UINT_32 mip0WidthInBlk
= pOut
->pitch
/ pOut
->blockWidth
;
4051 UINT_32 mip0HeightInBlk
= pOut
->height
/ pOut
->blockHeight
;
4053 AddrMajorMode majorMode
= GetMajorMode(pIn
->resourceType
,
4057 pOut
->numSlices
/ pOut
->blockSlices
);
4058 if (majorMode
== ADDR_MAJOR_Y
)
4060 UINT_32 mip1WidthInBlk
= RoundHalf(mip0WidthInBlk
);
4062 if ((mip1WidthInBlk
== 1) && (endingMipId
> 2))
4067 pOut
->mipChainPitch
+= (mip1WidthInBlk
* pOut
->blockWidth
);
4069 pOut
->epitchIsHeight
= FALSE
;
4073 UINT_32 mip1HeightInBlk
= RoundHalf(mip0HeightInBlk
);
4075 if ((mip1HeightInBlk
== 1) && (endingMipId
> 2))
4080 pOut
->mipChainHeight
+= (mip1HeightInBlk
* pOut
->blockHeight
);
4082 pOut
->epitchIsHeight
= TRUE
;
4086 if (pOut
->pMipInfo
!= NULL
)
4088 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
4090 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4092 Dim3d mipStartPos
= {0};
4093 UINT_32 mipTailOffsetInBytes
= 0;
4095 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
4105 &mipTailOffsetInBytes
);
4107 UINT_32 pitchInBlock
=
4108 pOut
->mipChainPitch
/ pOut
->blockWidth
;
4109 UINT_32 sliceInBlock
=
4110 (pOut
->mipChainHeight
/ pOut
->blockHeight
) * pitchInBlock
;
4111 UINT_64 blockIndex
=
4112 mipStartPos
.d
* sliceInBlock
+ mipStartPos
.h
* pitchInBlock
+ mipStartPos
.w
;
4113 UINT_64 macroBlockOffset
=
4114 blockIndex
<< GetBlockSizeLog2(pIn
->swizzleMode
);
4116 pOut
->pMipInfo
[i
].macroBlockOffset
= macroBlockOffset
;
4117 pOut
->pMipInfo
[i
].mipTailOffset
= mipTailOffsetInBytes
;
4121 else if (pOut
->pMipInfo
!= NULL
)
4123 pOut
->pMipInfo
[0].pitch
= pOut
->pitch
;
4124 pOut
->pMipInfo
[0].height
= pOut
->height
;
4125 pOut
->pMipInfo
[0].depth
= IsTex3d(pIn
->resourceType
)? pOut
->numSlices
: 1;
4126 pOut
->pMipInfo
[0].offset
= 0;
4129 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->mipChainPitch
) * pOut
->mipChainHeight
*
4130 (pIn
->bpp
>> 3) * pIn
->numFrags
;
4131 pOut
->surfSize
= pOut
->sliceSize
* pOut
->mipChainSlice
;
4132 pOut
->baseAlign
= ComputeSurfaceBaseAlignTiled(pIn
->swizzleMode
);
4134 if ((IsBlock256b(pIn
->swizzleMode
) == FALSE
) &&
4135 (pIn
->flags
.color
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
|| pIn
->flags
.fmask
) &&
4136 (pIn
->flags
.texture
== TRUE
) &&
4137 (pIn
->flags
.noMetadata
== FALSE
) &&
4138 (pIn
->flags
.metaPipeUnaligned
== FALSE
))
4140 // Assume client requires pipe aligned metadata, which is TcCompatible and will be accessed by TC...
4141 // Then we need extra padding for base surface. Otherwise, metadata and data surface for same pixel will
4142 // be flushed to different pipes, but texture engine only uses pipe id of data surface to fetch both of
4143 // them, which may cause invalid metadata to be fetched.
4144 pOut
->baseAlign
= Max(pOut
->baseAlign
, m_pipeInterleaveBytes
* m_pipes
* m_se
);
4149 pOut
->baseAlign
= Max(pOut
->baseAlign
, PrtAlignment
);
4158 ************************************************************************************************************************
4159 * Gfx9Lib::HwlComputeSurfaceInfoLinear
4162 * Internal function to calculate alignment for linear surface
4166 ************************************************************************************************************************
4168 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoLinear(
4169 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
4170 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
4173 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
4175 UINT_32 actualHeight
= 0;
4176 UINT_32 elementBytes
= pIn
->bpp
>> 3;
4177 const UINT_32 alignment
= pIn
->flags
.prt
? PrtAlignment
: 256;
4179 if (IsTex1d(pIn
->resourceType
))
4181 if (pIn
->height
> 1)
4183 returnCode
= ADDR_INVALIDPARAMS
;
4187 const UINT_32 pitchAlignInElement
= alignment
/ elementBytes
;
4189 pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
4190 actualHeight
= pIn
->numMipLevels
;
4192 if (pIn
->flags
.prt
== FALSE
)
4194 returnCode
= ApplyCustomizedPitchHeight(pIn
, elementBytes
, pitchAlignInElement
,
4195 &pitch
, &actualHeight
);
4198 if (returnCode
== ADDR_OK
)
4200 if (pOut
->pMipInfo
!= NULL
)
4202 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4204 pOut
->pMipInfo
[i
].offset
= pitch
* elementBytes
* i
;
4205 pOut
->pMipInfo
[i
].pitch
= pitch
;
4206 pOut
->pMipInfo
[i
].height
= 1;
4207 pOut
->pMipInfo
[i
].depth
= 1;
4215 returnCode
= ComputeSurfaceLinearPadding(pIn
, &pitch
, &actualHeight
, pOut
->pMipInfo
);
4218 if ((pitch
== 0) || (actualHeight
== 0))
4220 returnCode
= ADDR_INVALIDPARAMS
;
4223 if (returnCode
== ADDR_OK
)
4225 pOut
->pitch
= pitch
;
4226 pOut
->height
= pIn
->height
;
4227 pOut
->numSlices
= pIn
->numSlices
;
4228 pOut
->mipChainPitch
= pitch
;
4229 pOut
->mipChainHeight
= actualHeight
;
4230 pOut
->mipChainSlice
= pOut
->numSlices
;
4231 pOut
->epitchIsHeight
= (pIn
->numMipLevels
> 1) ? TRUE
: FALSE
;
4232 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->pitch
) * actualHeight
* elementBytes
;
4233 pOut
->surfSize
= pOut
->sliceSize
* pOut
->numSlices
;
4234 pOut
->baseAlign
= (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
) ? (pIn
->bpp
/ 8) : alignment
;
4235 pOut
->blockWidth
= (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
) ? 1 : (256 / elementBytes
);
4236 pOut
->blockHeight
= 1;
4237 pOut
->blockSlices
= 1;
4240 // Post calculation validate
4241 ADDR_ASSERT(pOut
->sliceSize
> 0);
4247 ************************************************************************************************************************
4248 * Gfx9Lib::GetMipChainInfo
4251 * Internal function to get out information about mip chain
4254 * Smaller value between Id of first mip fitted in mip tail and max Id of mip being created
4255 ************************************************************************************************************************
4257 UINT_32
Gfx9Lib::GetMipChainInfo(
4258 AddrResourceType resourceType
,
4259 AddrSwizzleMode swizzleMode
,
4265 UINT_32 blockHeight
,
4267 UINT_32 numMipLevel
,
4268 ADDR2_MIP_INFO
* pMipInfo
) const
4270 const Dim3d tailMaxDim
=
4271 GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4273 UINT_32 mipPitch
= mip0Width
;
4274 UINT_32 mipHeight
= mip0Height
;
4275 UINT_32 mipDepth
= IsTex3d(resourceType
) ? mip0Depth
: 1;
4277 UINT_32 firstMipIdInTail
= numMipLevel
;
4278 BOOL_32 inTail
= FALSE
;
4279 BOOL_32 finalDim
= FALSE
;
4280 BOOL_32 is3dThick
= IsThick(resourceType
, swizzleMode
);
4281 BOOL_32 is3dThin
= IsTex3d(resourceType
) && (is3dThick
== FALSE
);
4283 for (UINT_32 mipId
= 0; mipId
< numMipLevel
; mipId
++)
4287 if (finalDim
== FALSE
)
4293 mipSize
= mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3);
4297 mipSize
= mipPitch
* mipHeight
* (bpp
>> 3);
4302 UINT_32 index
= Log2(bpp
>> 3);
4306 mipPitch
= Block256_3dZ
[index
].w
;
4307 mipHeight
= Block256_3dZ
[index
].h
;
4308 mipDepth
= Block256_3dZ
[index
].d
;
4312 mipPitch
= Block256_2d
[index
].w
;
4313 mipHeight
= Block256_2d
[index
].h
;
4322 inTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
,
4323 mipPitch
, mipHeight
, mipDepth
);
4327 firstMipIdInTail
= mipId
;
4328 mipPitch
= tailMaxDim
.w
;
4329 mipHeight
= tailMaxDim
.h
;
4333 mipDepth
= tailMaxDim
.d
;
4338 mipPitch
= PowTwoAlign(mipPitch
, blockWidth
);
4339 mipHeight
= PowTwoAlign(mipHeight
, blockHeight
);
4343 mipDepth
= PowTwoAlign(mipDepth
, blockDepth
);
4348 if (pMipInfo
!= NULL
)
4350 pMipInfo
[mipId
].pitch
= mipPitch
;
4351 pMipInfo
[mipId
].height
= mipHeight
;
4352 pMipInfo
[mipId
].depth
= mipDepth
;
4353 pMipInfo
[mipId
].offset
= offset
;
4356 offset
+= (mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3));
4362 mipDepth
= Max(mipDepth
>> 1, 1u);
4367 mipPitch
= Max(mipPitch
>> 1, 1u);
4368 mipHeight
= Max(mipHeight
>> 1, 1u);
4370 if (is3dThick
|| is3dThin
)
4372 mipDepth
= Max(mipDepth
>> 1, 1u);
4377 return firstMipIdInTail
;
4381 ************************************************************************************************************************
4382 * Gfx9Lib::GetMetaMiptailInfo
4385 * Get mip tail coordinate information.
4389 ************************************************************************************************************************
4391 VOID
Gfx9Lib::GetMetaMiptailInfo(
4392 ADDR2_META_MIP_INFO
* pInfo
, ///< [out] output structure to store per mip coord
4393 Dim3d mipCoord
, ///< [in] mip tail base coord
4394 UINT_32 numMipInTail
, ///< [in] number of mips in tail
4395 Dim3d
* pMetaBlkDim
///< [in] meta block width/height/depth
4398 BOOL_32 isThick
= (pMetaBlkDim
->d
> 1);
4399 UINT_32 mipWidth
= pMetaBlkDim
->w
;
4400 UINT_32 mipHeight
= pMetaBlkDim
->h
>> 1;
4401 UINT_32 mipDepth
= pMetaBlkDim
->d
;
4406 minInc
= (pMetaBlkDim
->h
>= 512) ? 128 : ((pMetaBlkDim
->h
== 256) ? 64 : 32);
4408 else if (pMetaBlkDim
->h
>= 1024)
4412 else if (pMetaBlkDim
->h
== 512)
4421 UINT_32 blk32MipId
= 0xFFFFFFFF;
4423 for (UINT_32 mip
= 0; mip
< numMipInTail
; mip
++)
4425 pInfo
[mip
].inMiptail
= TRUE
;
4426 pInfo
[mip
].startX
= mipCoord
.w
;
4427 pInfo
[mip
].startY
= mipCoord
.h
;
4428 pInfo
[mip
].startZ
= mipCoord
.d
;
4429 pInfo
[mip
].width
= mipWidth
;
4430 pInfo
[mip
].height
= mipHeight
;
4431 pInfo
[mip
].depth
= mipDepth
;
4435 if (blk32MipId
== 0xFFFFFFFF)
4440 mipCoord
.w
= pInfo
[blk32MipId
].startX
;
4441 mipCoord
.h
= pInfo
[blk32MipId
].startY
;
4442 mipCoord
.d
= pInfo
[blk32MipId
].startZ
;
4444 switch (mip
- blk32MipId
)
4447 mipCoord
.w
+= 32; // 16x16
4450 mipCoord
.h
+= 32; // 8x8
4453 mipCoord
.h
+= 32; // 4x4
4457 mipCoord
.h
+= 32; // 2x2
4461 mipCoord
.h
+= 32; // 1x1
4464 // The following are for BC/ASTC formats
4466 mipCoord
.h
+= 48; // 1/2 x 1/2
4469 mipCoord
.h
+= 48; // 1/4 x 1/4
4473 mipCoord
.h
+= 48; // 1/8 x 1/8
4477 mipCoord
.h
+= 48; // 1/16 x 1/16
4481 ADDR_ASSERT_ALWAYS();
4485 mipWidth
= ((mip
- blk32MipId
) == 0) ? 16 : 8;
4486 mipHeight
= mipWidth
;
4490 mipDepth
= mipWidth
;
4495 if (mipWidth
<= minInc
)
4497 // if we're below the minimal increment...
4500 // For 3d, just go in z direction
4501 mipCoord
.d
+= mipDepth
;
4505 // For 2d, first go across, then down
4506 if ((mipWidth
* 2) == minInc
)
4508 // if we're 2 mips below, that's when we go back in x, and down in y
4509 mipCoord
.w
-= minInc
;
4510 mipCoord
.h
+= minInc
;
4514 // otherwise, just go across in x
4515 mipCoord
.w
+= minInc
;
4521 // On even mip, go down, otherwise, go across
4524 mipCoord
.w
+= mipWidth
;
4528 mipCoord
.h
+= mipHeight
;
4531 // Divide the width by 2
4533 // After the first mip in tail, the mip is always a square
4534 mipHeight
= mipWidth
;
4535 // ...or for 3d, a cube
4538 mipDepth
= mipWidth
;
4545 ************************************************************************************************************************
4546 * Gfx9Lib::GetMipStartPos
4549 * Internal function to get out information about mip logical start position
4552 * logical start position in macro block width/heith/depth of one mip level within one slice
4553 ************************************************************************************************************************
4555 Dim3d
Gfx9Lib::GetMipStartPos(
4556 AddrResourceType resourceType
,
4557 AddrSwizzleMode swizzleMode
,
4562 UINT_32 blockHeight
,
4565 UINT_32 log2ElementBytes
,
4566 UINT_32
* pMipTailBytesOffset
) const
4568 Dim3d mipStartPos
= {0};
4569 const Dim3d tailMaxDim
= GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4571 // Report mip in tail if Mip0 is already in mip tail
4572 BOOL_32 inMipTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
, width
, height
, depth
);
4573 UINT_32 log2BlkSize
= GetBlockSizeLog2(swizzleMode
);
4574 UINT_32 mipIndexInTail
= mipId
;
4576 if (inMipTail
== FALSE
)
4578 // Mip 0 dimension, unit in block
4579 UINT_32 mipWidthInBlk
= width
/ blockWidth
;
4580 UINT_32 mipHeightInBlk
= height
/ blockHeight
;
4581 UINT_32 mipDepthInBlk
= depth
/ blockDepth
;
4582 AddrMajorMode majorMode
= GetMajorMode(resourceType
,
4588 UINT_32 endingMip
= mipId
+ 1;
4590 for (UINT_32 i
= 1; i
<= mipId
; i
++)
4592 if ((i
== 1) || (i
== 3))
4594 if (majorMode
== ADDR_MAJOR_Y
)
4596 mipStartPos
.w
+= mipWidthInBlk
;
4600 mipStartPos
.h
+= mipHeightInBlk
;
4605 if (majorMode
== ADDR_MAJOR_X
)
4607 mipStartPos
.w
+= mipWidthInBlk
;
4609 else if (majorMode
== ADDR_MAJOR_Y
)
4611 mipStartPos
.h
+= mipHeightInBlk
;
4615 mipStartPos
.d
+= mipDepthInBlk
;
4619 BOOL_32 inTail
= FALSE
;
4621 if (IsThick(resourceType
, swizzleMode
))
4623 UINT_32 dim
= log2BlkSize
% 3;
4628 (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1) && (mipDepthInBlk
<= 2);
4633 (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
<= 2);
4638 (mipWidthInBlk
<= 2) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
== 1);
4643 if (log2BlkSize
& 1)
4645 inTail
= (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1);
4649 inTail
= (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2);
4659 mipWidthInBlk
= RoundHalf(mipWidthInBlk
);
4660 mipHeightInBlk
= RoundHalf(mipHeightInBlk
);
4661 mipDepthInBlk
= RoundHalf(mipDepthInBlk
);
4664 if (mipId
>= endingMip
)
4667 mipIndexInTail
= mipId
- endingMip
;
4673 UINT_32 index
= mipIndexInTail
+ MaxMacroBits
- log2BlkSize
;
4674 ADDR_ASSERT(index
< sizeof(MipTailOffset256B
) / sizeof(UINT_32
));
4675 *pMipTailBytesOffset
= MipTailOffset256B
[index
] << 8;
4682 ************************************************************************************************************************
4683 * Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled
4686 * Internal function to calculate address from coord for tiled swizzle surface
4690 ************************************************************************************************************************
4692 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled(
4693 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
4694 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
4697 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
4698 localIn
.swizzleMode
= pIn
->swizzleMode
;
4699 localIn
.flags
= pIn
->flags
;
4700 localIn
.resourceType
= pIn
->resourceType
;
4701 localIn
.bpp
= pIn
->bpp
;
4702 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
4703 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
4704 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
4705 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
4706 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
4707 localIn
.numFrags
= Max(pIn
->numFrags
, 1u);
4708 if (localIn
.numMipLevels
<= 1)
4710 localIn
.pitchInElement
= pIn
->pitchInElement
;
4713 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
4714 ADDR_E_RETURNCODE returnCode
= ComputeSurfaceInfoTiled(&localIn
, &localOut
);
4716 BOOL_32 valid
= (returnCode
== ADDR_OK
) &&
4717 (IsThin(pIn
->resourceType
, pIn
->swizzleMode
) ||
4718 IsThick(pIn
->resourceType
, pIn
->swizzleMode
)) &&
4719 ((pIn
->pipeBankXor
== 0) || (IsXor(pIn
->swizzleMode
)));
4723 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
4724 Dim3d mipStartPos
= {0};
4725 UINT_32 mipTailBytesOffset
= 0;
4727 if (pIn
->numMipLevels
> 1)
4729 // Mip-map chain cannot be MSAA surface
4730 ADDR_ASSERT((pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1));
4732 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
4737 localOut
.blockWidth
,
4738 localOut
.blockHeight
,
4739 localOut
.blockSlices
,
4742 &mipTailBytesOffset
);
4745 UINT_32 interleaveOffset
= 0;
4746 UINT_32 pipeBits
= 0;
4747 UINT_32 pipeXor
= 0;
4748 UINT_32 bankBits
= 0;
4749 UINT_32 bankXor
= 0;
4751 if (IsThin(pIn
->resourceType
, pIn
->swizzleMode
))
4753 UINT_32 blockOffset
= 0;
4754 UINT_32 log2BlkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4756 if (IsZOrderSwizzle(pIn
->swizzleMode
))
4758 // Morton generation
4759 if ((log2ElementBytes
== 0) || (log2ElementBytes
== 2))
4761 UINT_32 totalLowBits
= 6 - log2ElementBytes
;
4762 UINT_32 mortBits
= totalLowBits
/ 2;
4763 UINT_32 lowBitsValue
= MortonGen2d(pIn
->y
, pIn
->x
, mortBits
);
4764 // Are 9 bits enough?
4765 UINT_32 highBitsValue
=
4766 MortonGen2d(pIn
->x
>> mortBits
, pIn
->y
>> mortBits
, 9) << totalLowBits
;
4767 blockOffset
= lowBitsValue
| highBitsValue
;
4768 ADDR_ASSERT(blockOffset
== lowBitsValue
+ highBitsValue
);
4772 blockOffset
= MortonGen2d(pIn
->y
, pIn
->x
, 13);
4775 // Fill LSBs with sample bits
4776 if (pIn
->numSamples
> 1)
4778 blockOffset
*= pIn
->numSamples
;
4779 blockOffset
|= pIn
->sample
;
4782 // Shift according to BytesPP
4783 blockOffset
<<= log2ElementBytes
;
4787 // Micro block offset
4788 UINT_32 microBlockOffset
= ComputeSurface2DMicroBlockOffset(pIn
);
4789 blockOffset
= microBlockOffset
;
4791 // Micro block dimension
4792 ADDR_ASSERT(log2ElementBytes
< MaxNumOfBpp
);
4793 Dim2d microBlockDim
= Block256_2d
[log2ElementBytes
];
4794 // Morton generation, does 12 bit enough?
4796 MortonGen2d((pIn
->x
/ microBlockDim
.w
), (pIn
->y
/ microBlockDim
.h
), 12) << 8;
4798 // Sample bits start location
4799 UINT_32 sampleStart
= log2BlkSize
- Log2(pIn
->numSamples
);
4800 // Join sample bits information to the highest Macro block bits
4801 if (IsNonPrtXor(pIn
->swizzleMode
))
4803 // Non-prt-Xor : xor highest Macro block bits with sample bits
4804 blockOffset
= blockOffset
^ (pIn
->sample
<< sampleStart
);
4808 // Non-Xor or prt-Xor: replace highest Macro block bits with sample bits
4809 // after this op, the blockOffset only contains log2 Macro block size bits
4810 blockOffset
%= (1 << sampleStart
);
4811 blockOffset
|= (pIn
->sample
<< sampleStart
);
4812 ADDR_ASSERT((blockOffset
>> log2BlkSize
) == 0);
4816 if (IsXor(pIn
->swizzleMode
))
4818 // Mask off bits above Macro block bits to keep page synonyms working for prt
4819 if (IsPrt(pIn
->swizzleMode
))
4821 blockOffset
&= ((1 << log2BlkSize
) - 1);
4824 // Preserve offset inside pipe interleave
4825 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4826 blockOffset
>>= m_pipeInterleaveLog2
;
4829 pipeBits
= GetPipeXorBits(log2BlkSize
);
4831 pipeXor
= FoldXor2d(blockOffset
, pipeBits
);
4832 blockOffset
>>= pipeBits
;
4835 bankBits
= GetBankXorBits(log2BlkSize
);
4837 bankXor
= FoldXor2d(blockOffset
, bankBits
);
4838 blockOffset
>>= bankBits
;
4840 // Put all the part back together
4841 blockOffset
<<= bankBits
;
4842 blockOffset
|= bankXor
;
4843 blockOffset
<<= pipeBits
;
4844 blockOffset
|= pipeXor
;
4845 blockOffset
<<= m_pipeInterleaveLog2
;
4846 blockOffset
|= interleaveOffset
;
4849 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4850 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2BlkSize
)));
4852 blockOffset
|= mipTailBytesOffset
;
4854 if (IsNonPrtXor(pIn
->swizzleMode
) && (pIn
->numSamples
<= 1))
4856 // Apply slice xor if not MSAA/PRT
4857 blockOffset
^= (ReverseBitVector(pIn
->slice
, pipeBits
) << m_pipeInterleaveLog2
);
4858 blockOffset
^= (ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
) <<
4859 (m_pipeInterleaveLog2
+ pipeBits
));
4862 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4863 bankBits
, pipeBits
, &blockOffset
);
4865 blockOffset
%= (1 << log2BlkSize
);
4867 UINT_32 pitchInMacroBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4868 UINT_32 paddedHeightInMacroBlock
= localOut
.mipChainHeight
/ localOut
.blockHeight
;
4869 UINT_32 sliceSizeInMacroBlock
= pitchInMacroBlock
* paddedHeightInMacroBlock
;
4870 UINT_64 macroBlockIndex
=
4871 (pIn
->slice
+ mipStartPos
.d
) * sliceSizeInMacroBlock
+
4872 ((pIn
->y
/ localOut
.blockHeight
) + mipStartPos
.h
) * pitchInMacroBlock
+
4873 ((pIn
->x
/ localOut
.blockWidth
) + mipStartPos
.w
);
4875 pOut
->addr
= blockOffset
| (macroBlockIndex
<< log2BlkSize
);
4879 UINT_32 log2BlkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4881 Dim3d microBlockDim
= Block1K_3d
[log2ElementBytes
];
4883 UINT_32 blockOffset
= MortonGen3d((pIn
->x
/ microBlockDim
.w
),
4884 (pIn
->y
/ microBlockDim
.h
),
4885 (pIn
->slice
/ microBlockDim
.d
),
4889 blockOffset
|= ComputeSurface3DMicroBlockOffset(pIn
);
4891 if (IsXor(pIn
->swizzleMode
))
4893 // Mask off bits above Macro block bits to keep page synonyms working for prt
4894 if (IsPrt(pIn
->swizzleMode
))
4896 blockOffset
&= ((1 << log2BlkSize
) - 1);
4899 // Preserve offset inside pipe interleave
4900 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4901 blockOffset
>>= m_pipeInterleaveLog2
;
4904 pipeBits
= GetPipeXorBits(log2BlkSize
);
4906 pipeXor
= FoldXor3d(blockOffset
, pipeBits
);
4907 blockOffset
>>= pipeBits
;
4910 bankBits
= GetBankXorBits(log2BlkSize
);
4912 bankXor
= FoldXor3d(blockOffset
, bankBits
);
4913 blockOffset
>>= bankBits
;
4915 // Put all the part back together
4916 blockOffset
<<= bankBits
;
4917 blockOffset
|= bankXor
;
4918 blockOffset
<<= pipeBits
;
4919 blockOffset
|= pipeXor
;
4920 blockOffset
<<= m_pipeInterleaveLog2
;
4921 blockOffset
|= interleaveOffset
;
4924 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4925 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2BlkSize
)));
4926 blockOffset
|= mipTailBytesOffset
;
4928 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4929 bankBits
, pipeBits
, &blockOffset
);
4931 blockOffset
%= (1 << log2BlkSize
);
4933 UINT_32 xb
= pIn
->x
/ localOut
.blockWidth
+ mipStartPos
.w
;
4934 UINT_32 yb
= pIn
->y
/ localOut
.blockHeight
+ mipStartPos
.h
;
4935 UINT_32 zb
= pIn
->slice
/ localOut
.blockSlices
+ + mipStartPos
.d
;
4937 UINT_32 pitchInBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4938 UINT_32 sliceSizeInBlock
=
4939 (localOut
.mipChainHeight
/ localOut
.blockHeight
) * pitchInBlock
;
4940 UINT_64 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
4942 pOut
->addr
= blockOffset
| (blockIndex
<< log2BlkSize
);
4947 returnCode
= ADDR_INVALIDPARAMS
;
4954 ************************************************************************************************************************
4955 * Gfx9Lib::ComputeSurfaceInfoLinear
4958 * Internal function to calculate padding for linear swizzle 2D/3D surface
4962 ************************************************************************************************************************
4964 ADDR_E_RETURNCODE
Gfx9Lib::ComputeSurfaceLinearPadding(
4965 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input srtucture
4966 UINT_32
* pMipmap0PaddedWidth
, ///< [out] padded width in element
4967 UINT_32
* pSlice0PaddedHeight
, ///< [out] padded height for HW
4968 ADDR2_MIP_INFO
* pMipInfo
///< [out] per mip information
4971 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
4973 UINT_32 elementBytes
= pIn
->bpp
>> 3;
4974 UINT_32 pitchAlignInElement
= 0;
4976 if (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
)
4978 ADDR_ASSERT(pIn
->numMipLevels
<= 1);
4979 ADDR_ASSERT(pIn
->numSlices
<= 1);
4980 pitchAlignInElement
= 1;
4984 pitchAlignInElement
= (256 / elementBytes
);
4987 UINT_32 mipChainWidth
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
4988 UINT_32 slice0PaddedHeight
= pIn
->height
;
4990 returnCode
= ApplyCustomizedPitchHeight(pIn
, elementBytes
, pitchAlignInElement
,
4991 &mipChainWidth
, &slice0PaddedHeight
);
4993 if (returnCode
== ADDR_OK
)
4995 UINT_32 mipChainHeight
= 0;
4996 UINT_32 mipHeight
= pIn
->height
;
4997 UINT_32 mipDepth
= (pIn
->resourceType
== ADDR_RSRC_TEX_3D
) ? pIn
->numSlices
: 1;
4999 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
5001 if (pMipInfo
!= NULL
)
5003 pMipInfo
[i
].offset
= mipChainWidth
* mipChainHeight
* elementBytes
;
5004 pMipInfo
[i
].pitch
= mipChainWidth
;
5005 pMipInfo
[i
].height
= mipHeight
;
5006 pMipInfo
[i
].depth
= mipDepth
;
5009 mipChainHeight
+= mipHeight
;
5010 mipHeight
= RoundHalf(mipHeight
);
5011 mipHeight
= Max(mipHeight
, 1u);
5014 *pMipmap0PaddedWidth
= mipChainWidth
;
5015 *pSlice0PaddedHeight
= (pIn
->numMipLevels
> 1) ? mipChainHeight
: slice0PaddedHeight
;
5022 ************************************************************************************************************************
5023 * Gfx9Lib::ComputeThinBlockDimension
5026 * Internal function to get thin block width/height/depth in element from surface input params.
5030 ************************************************************************************************************************
5032 VOID
Gfx9Lib::ComputeThinBlockDimension(
5038 AddrResourceType resourceType
,
5039 AddrSwizzleMode swizzleMode
) const
5041 ADDR_ASSERT(IsThin(resourceType
, swizzleMode
));
5043 const UINT_32 log2BlkSize
= GetBlockSizeLog2(swizzleMode
);
5044 const UINT_32 eleBytes
= bpp
>> 3;
5045 const UINT_32 microBlockSizeTableIndex
= Log2(eleBytes
);
5046 const UINT_32 log2blkSizeIn256B
= log2BlkSize
- 8;
5047 const UINT_32 widthAmp
= log2blkSizeIn256B
/ 2;
5048 const UINT_32 heightAmp
= log2blkSizeIn256B
- widthAmp
;
5050 ADDR_ASSERT(microBlockSizeTableIndex
< sizeof(Block256_2d
) / sizeof(Block256_2d
[0]));
5052 *pWidth
= (Block256_2d
[microBlockSizeTableIndex
].w
<< widthAmp
);
5053 *pHeight
= (Block256_2d
[microBlockSizeTableIndex
].h
<< heightAmp
);
5058 const UINT_32 log2sample
= Log2(numSamples
);
5059 const UINT_32 q
= log2sample
>> 1;
5060 const UINT_32 r
= log2sample
& 1;
5062 if (log2BlkSize
& 1)
5065 *pHeight
>>= (q
+ r
);
5069 *pWidth
>>= (q
+ r
);