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_32 coords
[] = { pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
};
803 UINT_64 address
= pMetaEq
->solve(coords
);
805 pOut
->addr
= address
>> 1;
806 pOut
->bitPosition
= static_cast<UINT_32
>((address
& 1) << 2);
808 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->cMaskFlags
.pipeAligned
,
811 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
813 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
820 ************************************************************************************************************************
821 * Gfx9Lib::HwlComputeHtileAddrFromCoord
824 * Interface function stub of AddrComputeHtileAddrFromCoord
828 ************************************************************************************************************************
830 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileAddrFromCoord(
831 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
832 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
834 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
836 if (pIn
->numMipLevels
> 1)
838 returnCode
= ADDR_NOTIMPLEMENTED
;
842 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
843 input
.size
= sizeof(input
);
844 input
.hTileFlags
= pIn
->hTileFlags
;
845 input
.depthFlags
= pIn
->depthflags
;
846 input
.swizzleMode
= pIn
->swizzleMode
;
847 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
848 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
849 input
.numSlices
= Max(pIn
->numSlices
, 1u);
850 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
852 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
853 output
.size
= sizeof(output
);
855 returnCode
= ComputeHtileInfo(&input
, &output
);
857 if (returnCode
== ADDR_OK
)
859 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
860 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
861 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
862 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
864 MetaEqParams metaEqParams
= {0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
865 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
866 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
868 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
870 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
871 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
872 UINT_32 zb
= pIn
->slice
;
874 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
875 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
876 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
878 UINT_32 coords
[] = { pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
};
879 UINT_64 address
= pMetaEq
->solve(coords
);
881 pOut
->addr
= address
>> 1;
883 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
886 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
888 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
896 ************************************************************************************************************************
897 * Gfx9Lib::HwlComputeHtileCoordFromAddr
900 * Interface function stub of AddrComputeHtileCoordFromAddr
904 ************************************************************************************************************************
906 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileCoordFromAddr(
907 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
908 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
) ///< [out] output structure
910 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
912 if (pIn
->numMipLevels
> 1)
914 returnCode
= ADDR_NOTIMPLEMENTED
;
918 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
919 input
.size
= sizeof(input
);
920 input
.hTileFlags
= pIn
->hTileFlags
;
921 input
.swizzleMode
= pIn
->swizzleMode
;
922 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
923 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
924 input
.numSlices
= Max(pIn
->numSlices
, 1u);
925 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
927 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
928 output
.size
= sizeof(output
);
930 returnCode
= ComputeHtileInfo(&input
, &output
);
932 if (returnCode
== ADDR_OK
)
934 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
935 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
936 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
937 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
939 MetaEqParams metaEqParams
= {0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
940 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
941 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
943 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
945 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
948 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
950 UINT_64 nibbleAddress
= (pIn
->addr
^ (pipeXor
<< m_pipeInterleaveLog2
)) << 1;
952 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
953 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
955 UINT_32 coords
[NUM_DIMS
];
956 pMetaEq
->solveAddr(nibbleAddress
, sliceSizeInBlock
, coords
);
958 pOut
->slice
= coords
[DIM_M
] / sliceSizeInBlock
;
959 pOut
->y
= ((coords
[DIM_M
] % sliceSizeInBlock
) / pitchInBlock
) * output
.metaBlkHeight
+ coords
[DIM_Y
];
960 pOut
->x
= (coords
[DIM_M
] % pitchInBlock
) * output
.metaBlkWidth
+ coords
[DIM_X
];
968 ************************************************************************************************************************
969 * Gfx9Lib::HwlComputeDccAddrFromCoord
972 * Interface function stub of AddrComputeDccAddrFromCoord
976 ************************************************************************************************************************
978 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeDccAddrFromCoord(
979 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
,
980 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
)
982 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
984 if ((pIn
->numMipLevels
> 1) || (pIn
->mipId
> 1) || pIn
->dccKeyFlags
.linear
)
986 returnCode
= ADDR_NOTIMPLEMENTED
;
990 ADDR2_COMPUTE_DCCINFO_INPUT input
= {0};
991 input
.size
= sizeof(input
);
992 input
.dccKeyFlags
= pIn
->dccKeyFlags
;
993 input
.colorFlags
= pIn
->colorFlags
;
994 input
.swizzleMode
= pIn
->swizzleMode
;
995 input
.resourceType
= pIn
->resourceType
;
996 input
.bpp
= pIn
->bpp
;
997 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
998 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
999 input
.numSlices
= Max(pIn
->numSlices
, 1u);
1000 input
.numFrags
= Max(pIn
->numFrags
, 1u);
1001 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
1003 ADDR2_COMPUTE_DCCINFO_OUTPUT output
= {0};
1004 output
.size
= sizeof(output
);
1006 returnCode
= ComputeDccInfo(&input
, &output
);
1008 if (returnCode
== ADDR_OK
)
1010 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
1011 UINT_32 numSamplesLog2
= Log2(pIn
->numFrags
);
1012 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
1013 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
1014 UINT_32 metaBlkDepthLog2
= Log2(output
.metaBlkDepth
);
1015 UINT_32 compBlkWidthLog2
= Log2(output
.compressBlkWidth
);
1016 UINT_32 compBlkHeightLog2
= Log2(output
.compressBlkHeight
);
1017 UINT_32 compBlkDepthLog2
= Log2(output
.compressBlkDepth
);
1019 MetaEqParams metaEqParams
= {pIn
->mipId
, elementBytesLog2
, numSamplesLog2
, pIn
->dccKeyFlags
,
1020 Gfx9DataColor
, pIn
->swizzleMode
, pIn
->resourceType
,
1021 metaBlkWidthLog2
, metaBlkHeightLog2
, metaBlkDepthLog2
,
1022 compBlkWidthLog2
, compBlkHeightLog2
, compBlkDepthLog2
};
1024 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
1026 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
1027 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
1028 UINT_32 zb
= pIn
->slice
/ output
.metaBlkDepth
;
1030 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
1031 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
1032 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
1034 UINT_32 coords
[] = { pIn
->x
, pIn
->y
, pIn
->slice
, pIn
->sample
, blockIndex
};
1035 UINT_64 address
= pMetaEq
->solve(coords
);
1037 pOut
->addr
= address
>> 1;
1039 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->dccKeyFlags
.pipeAligned
,
1042 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
1044 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
1052 ************************************************************************************************************************
1053 * Gfx9Lib::HwlInitGlobalParams
1056 * Initializes global parameters
1059 * TRUE if all settings are valid
1061 ************************************************************************************************************************
1063 BOOL_32
Gfx9Lib::HwlInitGlobalParams(
1064 const ADDR_CREATE_INPUT
* pCreateIn
) ///< [in] create input
1066 BOOL_32 valid
= TRUE
;
1068 if (m_settings
.isArcticIsland
)
1070 GB_ADDR_CONFIG gbAddrConfig
;
1072 gbAddrConfig
.u32All
= pCreateIn
->regValue
.gbAddrConfig
;
1074 // These values are copied from CModel code
1075 switch (gbAddrConfig
.bits
.NUM_PIPES
)
1077 case ADDR_CONFIG_1_PIPE
:
1081 case ADDR_CONFIG_2_PIPE
:
1085 case ADDR_CONFIG_4_PIPE
:
1089 case ADDR_CONFIG_8_PIPE
:
1093 case ADDR_CONFIG_16_PIPE
:
1097 case ADDR_CONFIG_32_PIPE
:
1102 ADDR_ASSERT_ALWAYS();
1106 switch (gbAddrConfig
.bits
.PIPE_INTERLEAVE_SIZE
)
1108 case ADDR_CONFIG_PIPE_INTERLEAVE_256B
:
1109 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_256B
;
1110 m_pipeInterleaveLog2
= 8;
1112 case ADDR_CONFIG_PIPE_INTERLEAVE_512B
:
1113 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_512B
;
1114 m_pipeInterleaveLog2
= 9;
1116 case ADDR_CONFIG_PIPE_INTERLEAVE_1KB
:
1117 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_1KB
;
1118 m_pipeInterleaveLog2
= 10;
1120 case ADDR_CONFIG_PIPE_INTERLEAVE_2KB
:
1121 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_2KB
;
1122 m_pipeInterleaveLog2
= 11;
1125 ADDR_ASSERT_ALWAYS();
1129 // Addr::V2::Lib::ComputePipeBankXor()/ComputeSlicePipeBankXor() requires pipe interleave to be exactly 8 bits,
1130 // and any larger value requires a post-process (left shift) on the output pipeBankXor bits.
1131 ADDR_ASSERT(m_pipeInterleaveBytes
== ADDR_PIPEINTERLEAVE_256B
);
1133 switch (gbAddrConfig
.bits
.NUM_BANKS
)
1135 case ADDR_CONFIG_1_BANK
:
1139 case ADDR_CONFIG_2_BANK
:
1143 case ADDR_CONFIG_4_BANK
:
1147 case ADDR_CONFIG_8_BANK
:
1151 case ADDR_CONFIG_16_BANK
:
1156 ADDR_ASSERT_ALWAYS();
1160 switch (gbAddrConfig
.bits
.NUM_SHADER_ENGINES
)
1162 case ADDR_CONFIG_1_SHADER_ENGINE
:
1166 case ADDR_CONFIG_2_SHADER_ENGINE
:
1170 case ADDR_CONFIG_4_SHADER_ENGINE
:
1174 case ADDR_CONFIG_8_SHADER_ENGINE
:
1179 ADDR_ASSERT_ALWAYS();
1183 switch (gbAddrConfig
.bits
.NUM_RB_PER_SE
)
1185 case ADDR_CONFIG_1_RB_PER_SHADER_ENGINE
:
1189 case ADDR_CONFIG_2_RB_PER_SHADER_ENGINE
:
1193 case ADDR_CONFIG_4_RB_PER_SHADER_ENGINE
:
1198 ADDR_ASSERT_ALWAYS();
1202 switch (gbAddrConfig
.bits
.MAX_COMPRESSED_FRAGS
)
1204 case ADDR_CONFIG_1_MAX_COMPRESSED_FRAGMENTS
:
1206 m_maxCompFragLog2
= 0;
1208 case ADDR_CONFIG_2_MAX_COMPRESSED_FRAGMENTS
:
1210 m_maxCompFragLog2
= 1;
1212 case ADDR_CONFIG_4_MAX_COMPRESSED_FRAGMENTS
:
1214 m_maxCompFragLog2
= 2;
1216 case ADDR_CONFIG_8_MAX_COMPRESSED_FRAGMENTS
:
1218 m_maxCompFragLog2
= 3;
1221 ADDR_ASSERT_ALWAYS();
1225 if ((m_rbPerSeLog2
== 1) &&
1226 (((m_pipesLog2
== 1) && ((m_seLog2
== 2) || (m_seLog2
== 3))) ||
1227 ((m_pipesLog2
== 2) && ((m_seLog2
== 1) || (m_seLog2
== 2)))))
1229 ADDR_ASSERT(m_settings
.isVega10
== FALSE
);
1230 ADDR_ASSERT(m_settings
.isRaven
== FALSE
);
1232 ADDR_ASSERT(m_settings
.isVega20
== FALSE
);
1234 if (m_settings
.isVega12
)
1236 m_settings
.htileCacheRbConflict
= 1;
1240 // For simplicity we never allow VAR swizzle mode for GFX9, the actural value is 18 on GFX9
1241 m_blockVarSizeLog2
= 0;
1246 ADDR_NOT_IMPLEMENTED();
1251 InitEquationTable();
1258 ************************************************************************************************************************
1259 * Gfx9Lib::HwlConvertChipFamily
1262 * Convert familyID defined in atiid.h to ChipFamily and set m_chipFamily/m_chipRevision
1265 ************************************************************************************************************************
1267 ChipFamily
Gfx9Lib::HwlConvertChipFamily(
1268 UINT_32 uChipFamily
, ///< [in] chip family defined in atiih.h
1269 UINT_32 uChipRevision
) ///< [in] chip revision defined in "asic_family"_id.h
1271 ChipFamily family
= ADDR_CHIP_FAMILY_AI
;
1273 switch (uChipFamily
)
1276 m_settings
.isArcticIsland
= 1;
1277 m_settings
.isVega10
= ASICREV_IS_VEGA10_P(uChipRevision
);
1278 m_settings
.isVega12
= ASICREV_IS_VEGA12_P(uChipRevision
);
1279 m_settings
.isVega20
= ASICREV_IS_VEGA20_P(uChipRevision
);
1280 m_settings
.isDce12
= 1;
1282 if (m_settings
.isVega10
== 0)
1284 m_settings
.htileAlignFix
= 1;
1285 m_settings
.applyAliasFix
= 1;
1288 m_settings
.metaBaseAlignFix
= 1;
1290 m_settings
.depthPipeXorDisable
= 1;
1293 m_settings
.isArcticIsland
= 1;
1295 if (ASICREV_IS_RAVEN(uChipRevision
))
1297 m_settings
.isRaven
= 1;
1299 m_settings
.depthPipeXorDisable
= 1;
1302 if (ASICREV_IS_RAVEN2(uChipRevision
))
1304 m_settings
.isRaven
= 1;
1307 if (m_settings
.isRaven
== 0)
1309 m_settings
.htileAlignFix
= 1;
1310 m_settings
.applyAliasFix
= 1;
1313 if (ASICREV_IS_RENOIR(uChipRevision
))
1315 m_settings
.isRaven
= 1;
1318 m_settings
.isDcn1
= m_settings
.isRaven
;
1320 m_settings
.metaBaseAlignFix
= 1;
1324 ADDR_ASSERT(!"This should be a Fusion");
1332 ************************************************************************************************************************
1333 * Gfx9Lib::InitRbEquation
1339 ************************************************************************************************************************
1341 VOID
Gfx9Lib::GetRbEquation(
1342 CoordEq
* pRbEq
, ///< [out] rb equation
1343 UINT_32 numRbPerSeLog2
, ///< [in] number of rb per shader engine
1344 UINT_32 numSeLog2
) ///< [in] number of shader engine
1347 // RB's are distributed on 16x16, except when we have 1 rb per se, in which case its 32x32
1348 UINT_32 rbRegion
= (numRbPerSeLog2
== 0) ? 5 : 4;
1349 Coordinate
cx(DIM_X
, rbRegion
);
1350 Coordinate
cy(DIM_Y
, rbRegion
);
1353 UINT_32 numRbTotalLog2
= numRbPerSeLog2
+ numSeLog2
;
1355 // Clear the rb equation
1357 pRbEq
->resize(numRbTotalLog2
);
1359 if ((numSeLog2
> 0) && (numRbPerSeLog2
== 1))
1361 // Special case when more than 1 SE, and 2 RB per SE
1362 (*pRbEq
)[0].add(cx
);
1363 (*pRbEq
)[0].add(cy
);
1367 if (m_settings
.applyAliasFix
== false)
1369 (*pRbEq
)[0].add(cy
);
1372 (*pRbEq
)[0].add(cy
);
1376 UINT_32 numBits
= 2 * (numRbTotalLog2
- start
);
1378 for (UINT_32 i
= 0; i
< numBits
; i
++)
1381 start
+ (((start
+ i
) >= numRbTotalLog2
) ? (2 * (numRbTotalLog2
- start
) - i
- 1) : i
);
1385 (*pRbEq
)[idx
].add(cx
);
1390 (*pRbEq
)[idx
].add(cy
);
1397 ************************************************************************************************************************
1398 * Gfx9Lib::GetDataEquation
1401 * Get data equation for fmask and Z
1404 ************************************************************************************************************************
1406 VOID
Gfx9Lib::GetDataEquation(
1407 CoordEq
* pDataEq
, ///< [out] data surface equation
1408 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1409 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1410 AddrResourceType resourceType
, ///< [in] data surface resource type
1411 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1412 UINT_32 numSamplesLog2
) ///< [in] data surface sample count
1415 Coordinate
cx(DIM_X
, 0);
1416 Coordinate
cy(DIM_Y
, 0);
1417 Coordinate
cz(DIM_Z
, 0);
1418 Coordinate
cs(DIM_S
, 0);
1420 // Clear the equation
1422 pDataEq
->resize(27);
1424 if (dataSurfaceType
== Gfx9DataColor
)
1426 if (IsLinear(swizzleMode
))
1428 Coordinate
cm(DIM_M
, 0);
1430 pDataEq
->resize(49);
1432 for (UINT_32 i
= 0; i
< 49; i
++)
1434 (*pDataEq
)[i
].add(cm
);
1438 else if (IsThick(resourceType
, swizzleMode
))
1440 // Color 3d_S and 3d_Z modes, 3d_D is same as color 2d
1442 if (IsStandardSwizzle(resourceType
, swizzleMode
))
1444 // Standard 3d swizzle
1445 // Fill in bottom x bits
1446 for (i
= elementBytesLog2
; i
< 4; i
++)
1448 (*pDataEq
)[i
].add(cx
);
1451 // Fill in 2 bits of y and then z
1452 for (i
= 4; i
< 6; i
++)
1454 (*pDataEq
)[i
].add(cy
);
1457 for (i
= 6; i
< 8; i
++)
1459 (*pDataEq
)[i
].add(cz
);
1462 if (elementBytesLog2
< 2)
1464 // fill in z & y bit
1465 (*pDataEq
)[8].add(cz
);
1466 (*pDataEq
)[9].add(cy
);
1470 else if (elementBytesLog2
== 2)
1472 // fill in y and x bit
1473 (*pDataEq
)[8].add(cy
);
1474 (*pDataEq
)[9].add(cx
);
1481 (*pDataEq
)[8].add(cx
);
1483 (*pDataEq
)[9].add(cx
);
1490 UINT_32 m2dEnd
= (elementBytesLog2
==0) ? 3 : ((elementBytesLog2
< 4) ? 4 : 5);
1491 UINT_32 numZs
= (elementBytesLog2
== 0 || elementBytesLog2
== 4) ?
1492 2 : ((elementBytesLog2
== 1) ? 3 : 1);
1493 pDataEq
->mort2d(cx
, cy
, elementBytesLog2
, m2dEnd
);
1494 for (i
= m2dEnd
+ 1; i
<= m2dEnd
+ numZs
; i
++)
1496 (*pDataEq
)[i
].add(cz
);
1499 if ((elementBytesLog2
== 0) || (elementBytesLog2
== 3))
1502 (*pDataEq
)[6].add(cx
);
1503 (*pDataEq
)[7].add(cz
);
1507 else if (elementBytesLog2
== 2)
1510 (*pDataEq
)[6].add(cy
);
1511 (*pDataEq
)[7].add(cz
);
1516 (*pDataEq
)[8].add(cy
);
1517 (*pDataEq
)[9].add(cx
);
1521 // Fill in bit 10 and up
1522 pDataEq
->mort3d( cz
, cy
, cx
, 10 );
1524 else if (IsThin(resourceType
, swizzleMode
))
1526 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1528 UINT_32 microYBits
= (8 - elementBytesLog2
) / 2;
1529 UINT_32 tileSplitStart
= blockSizeLog2
- numSamplesLog2
;
1531 // Fill in bottom x bits
1532 for (i
= elementBytesLog2
; i
< 4; i
++)
1534 (*pDataEq
)[i
].add(cx
);
1537 // Fill in bottom y bits
1538 for (i
= 4; i
< 4 + microYBits
; i
++)
1540 (*pDataEq
)[i
].add(cy
);
1543 // Fill in last of the micro_x bits
1544 for (i
= 4 + microYBits
; i
< 8; i
++)
1546 (*pDataEq
)[i
].add(cx
);
1549 // Fill in x/y bits below sample split
1550 pDataEq
->mort2d(cy
, cx
, 8, tileSplitStart
- 1);
1551 // Fill in sample bits
1552 for (i
= 0; i
< numSamplesLog2
; i
++)
1555 (*pDataEq
)[tileSplitStart
+ i
].add(cs
);
1557 // Fill in x/y bits above sample split
1558 if ((numSamplesLog2
& 1) ^ (blockSizeLog2
& 1))
1560 pDataEq
->mort2d(cx
, cy
, blockSizeLog2
);
1564 pDataEq
->mort2d(cy
, cx
, blockSizeLog2
);
1569 ADDR_ASSERT_ALWAYS();
1575 UINT_32 sampleStart
= elementBytesLog2
;
1576 UINT_32 pixelStart
= elementBytesLog2
+ numSamplesLog2
;
1577 UINT_32 ymajStart
= 6 + numSamplesLog2
;
1579 for (UINT_32 s
= 0; s
< numSamplesLog2
; s
++)
1582 (*pDataEq
)[sampleStart
+ s
].add(cs
);
1585 // Put in the x-major order pixel bits
1586 pDataEq
->mort2d(cx
, cy
, pixelStart
, ymajStart
- 1);
1587 // Put in the y-major order pixel bits
1588 pDataEq
->mort2d(cy
, cx
, ymajStart
);
1593 ************************************************************************************************************************
1594 * Gfx9Lib::GetPipeEquation
1600 ************************************************************************************************************************
1602 VOID
Gfx9Lib::GetPipeEquation(
1603 CoordEq
* pPipeEq
, ///< [out] pipe equation
1604 CoordEq
* pDataEq
, ///< [in] data equation
1605 UINT_32 pipeInterleaveLog2
, ///< [in] pipe interleave
1606 UINT_32 numPipeLog2
, ///< [in] number of pipes
1607 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1608 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1609 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1610 AddrResourceType resourceType
///< [in] data surface resource type
1613 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1616 pDataEq
->copy(dataEq
);
1618 if (dataSurfaceType
== Gfx9DataColor
)
1620 INT_32 shift
= static_cast<INT_32
>(numSamplesLog2
);
1621 dataEq
.shift(-shift
, blockSizeLog2
- numSamplesLog2
);
1624 dataEq
.copy(*pPipeEq
, pipeInterleaveLog2
, numPipeLog2
);
1626 // This section should only apply to z/stencil, maybe fmask
1627 // If the pipe bit is below the comp block size,
1628 // then keep moving up the address until we find a bit that is above
1629 UINT_32 pipeStart
= 0;
1631 if (dataSurfaceType
!= Gfx9DataColor
)
1633 Coordinate
tileMin(DIM_X
, 3);
1635 while (dataEq
[pipeInterleaveLog2
+ pipeStart
][0] < tileMin
)
1640 // if pipe is 0, then the first pipe bit is above the comp block size,
1641 // so we don't need to do anything
1642 // Note, this if condition is not necessary, since if we execute the loop when pipe==0,
1643 // we will get the same pipe equation
1646 for (UINT_32 i
= 0; i
< numPipeLog2
; i
++)
1648 // Copy the jth bit above pipe interleave to the current pipe equation bit
1649 dataEq
[pipeInterleaveLog2
+ pipeStart
+ i
].copyto((*pPipeEq
)[i
]);
1654 if (IsPrt(swizzleMode
))
1656 // Clear out bits above the block size if prt's are enabled
1657 dataEq
.resize(blockSizeLog2
);
1661 if (IsXor(swizzleMode
))
1665 if (IsThick(resourceType
, swizzleMode
))
1669 dataEq
.copy(xorMask2
, pipeInterleaveLog2
+ numPipeLog2
, 2 * numPipeLog2
);
1671 xorMask
.resize(numPipeLog2
);
1673 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1675 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
]);
1676 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
+ 1]);
1681 // Xor in the bits above the pipe+gpu bits
1682 dataEq
.copy(xorMask
, pipeInterleaveLog2
+ pipeStart
+ numPipeLog2
, numPipeLog2
);
1684 if ((numSamplesLog2
== 0) && (IsPrt(swizzleMode
) == FALSE
))
1688 // if 1xaa and not prt, then xor in the z bits
1690 xorMask2
.resize(numPipeLog2
);
1691 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1693 co
.set(DIM_Z
, numPipeLog2
- 1 - pipeIdx
);
1694 xorMask2
[pipeIdx
].add(co
);
1697 pPipeEq
->xorin(xorMask2
);
1702 pPipeEq
->xorin(xorMask
);
1706 ************************************************************************************************************************
1707 * Gfx9Lib::GetMetaEquation
1710 * Get meta equation for cmask/htile/DCC
1712 * Pointer to a calculated meta equation
1713 ************************************************************************************************************************
1715 const CoordEq
* Gfx9Lib::GetMetaEquation(
1716 const MetaEqParams
& metaEqParams
)
1718 UINT_32 cachedMetaEqIndex
;
1720 for (cachedMetaEqIndex
= 0; cachedMetaEqIndex
< MaxCachedMetaEq
; cachedMetaEqIndex
++)
1722 if (memcmp(&metaEqParams
,
1723 &m_cachedMetaEqKey
[cachedMetaEqIndex
],
1724 static_cast<UINT_32
>(sizeof(metaEqParams
))) == 0)
1730 CoordEq
* pMetaEq
= NULL
;
1732 if (cachedMetaEqIndex
< MaxCachedMetaEq
)
1734 pMetaEq
= &m_cachedMetaEq
[cachedMetaEqIndex
];
1738 m_cachedMetaEqKey
[m_metaEqOverrideIndex
] = metaEqParams
;
1740 pMetaEq
= &m_cachedMetaEq
[m_metaEqOverrideIndex
++];
1742 m_metaEqOverrideIndex
%= MaxCachedMetaEq
;
1744 GenMetaEquation(pMetaEq
,
1745 metaEqParams
.maxMip
,
1746 metaEqParams
.elementBytesLog2
,
1747 metaEqParams
.numSamplesLog2
,
1748 metaEqParams
.metaFlag
,
1749 metaEqParams
.dataSurfaceType
,
1750 metaEqParams
.swizzleMode
,
1751 metaEqParams
.resourceType
,
1752 metaEqParams
.metaBlkWidthLog2
,
1753 metaEqParams
.metaBlkHeightLog2
,
1754 metaEqParams
.metaBlkDepthLog2
,
1755 metaEqParams
.compBlkWidthLog2
,
1756 metaEqParams
.compBlkHeightLog2
,
1757 metaEqParams
.compBlkDepthLog2
);
1764 ************************************************************************************************************************
1765 * Gfx9Lib::GenMetaEquation
1768 * Get meta equation for cmask/htile/DCC
1771 ************************************************************************************************************************
1773 VOID
Gfx9Lib::GenMetaEquation(
1774 CoordEq
* pMetaEq
, ///< [out] meta equation
1775 UINT_32 maxMip
, ///< [in] max mip Id
1776 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1777 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1778 ADDR2_META_FLAGS metaFlag
, ///< [in] meta falg
1779 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1780 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1781 AddrResourceType resourceType
, ///< [in] data surface resource type
1782 UINT_32 metaBlkWidthLog2
, ///< [in] meta block width
1783 UINT_32 metaBlkHeightLog2
, ///< [in] meta block height
1784 UINT_32 metaBlkDepthLog2
, ///< [in] meta block depth
1785 UINT_32 compBlkWidthLog2
, ///< [in] compress block width
1786 UINT_32 compBlkHeightLog2
, ///< [in] compress block height
1787 UINT_32 compBlkDepthLog2
) ///< [in] compress block depth
1790 UINT_32 numPipeTotalLog2
= GetPipeLog2ForMetaAddressing(metaFlag
.pipeAligned
, swizzleMode
);
1791 UINT_32 pipeInterleaveLog2
= m_pipeInterleaveLog2
;
1793 // Get the correct data address and rb equation
1795 GetDataEquation(&dataEq
, dataSurfaceType
, swizzleMode
, resourceType
,
1796 elementBytesLog2
, numSamplesLog2
);
1798 // Get pipe and rb equations
1799 CoordEq pipeEquation
;
1800 GetPipeEquation(&pipeEquation
, &dataEq
, pipeInterleaveLog2
, numPipeTotalLog2
,
1801 numSamplesLog2
, dataSurfaceType
, swizzleMode
, resourceType
);
1802 numPipeTotalLog2
= pipeEquation
.getsize();
1804 if (metaFlag
.linear
)
1806 // Linear metadata supporting was removed for GFX9! No one can use this feature.
1807 ADDR_ASSERT_ALWAYS();
1809 ADDR_ASSERT(dataSurfaceType
== Gfx9DataColor
);
1811 dataEq
.copy(*pMetaEq
);
1813 if (IsLinear(swizzleMode
))
1815 if (metaFlag
.pipeAligned
)
1817 // Remove the pipe bits
1818 INT_32 shift
= static_cast<INT_32
>(numPipeTotalLog2
);
1819 pMetaEq
->shift(-shift
, pipeInterleaveLog2
);
1821 // Divide by comp block size, which for linear (which is always color) is 256 B
1824 if (metaFlag
.pipeAligned
)
1826 // Put pipe bits back in
1827 pMetaEq
->shift(numPipeTotalLog2
, pipeInterleaveLog2
);
1829 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1831 pipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ i
]);
1840 UINT_32 maxCompFragLog2
= static_cast<INT_32
>(m_maxCompFragLog2
);
1841 UINT_32 compFragLog2
=
1842 ((dataSurfaceType
== Gfx9DataColor
) && (numSamplesLog2
> maxCompFragLog2
)) ?
1843 maxCompFragLog2
: numSamplesLog2
;
1845 UINT_32 uncompFragLog2
= numSamplesLog2
- compFragLog2
;
1847 // Make sure the metaaddr is cleared
1849 pMetaEq
->resize(27);
1851 if (IsThick(resourceType
, swizzleMode
))
1853 Coordinate
cx(DIM_X
, 0);
1854 Coordinate
cy(DIM_Y
, 0);
1855 Coordinate
cz(DIM_Z
, 0);
1859 pMetaEq
->mort3d(cy
, cx
, cz
);
1863 pMetaEq
->mort3d(cx
, cy
, cz
);
1868 Coordinate
cx(DIM_X
, 0);
1869 Coordinate
cy(DIM_Y
, 0);
1874 pMetaEq
->mort2d(cy
, cx
, compFragLog2
);
1878 pMetaEq
->mort2d(cx
, cy
, compFragLog2
);
1881 //------------------------------------------------------------------------------------------------------------------------
1882 // Put the compressible fragments at the lsb
1883 // the uncompressible frags will be at the msb of the micro address
1884 //------------------------------------------------------------------------------------------------------------------------
1885 for (UINT_32 s
= 0; s
< compFragLog2
; s
++)
1888 (*pMetaEq
)[s
].add(cs
);
1892 // Keep a copy of the pipe equations
1893 CoordEq origPipeEquation
;
1894 pipeEquation
.copy(origPipeEquation
);
1897 // filter out everything under the compressed block size
1898 co
.set(DIM_X
, compBlkWidthLog2
);
1899 pMetaEq
->Filter('<', co
, 0, DIM_X
);
1900 co
.set(DIM_Y
, compBlkHeightLog2
);
1901 pMetaEq
->Filter('<', co
, 0, DIM_Y
);
1902 co
.set(DIM_Z
, compBlkDepthLog2
);
1903 pMetaEq
->Filter('<', co
, 0, DIM_Z
);
1905 // For non-color, filter out sample bits
1906 if (dataSurfaceType
!= Gfx9DataColor
)
1909 pMetaEq
->Filter('<', co
, 0, DIM_S
);
1912 // filter out everything above the metablock size
1913 co
.set(DIM_X
, metaBlkWidthLog2
- 1);
1914 pMetaEq
->Filter('>', co
, 0, DIM_X
);
1915 co
.set(DIM_Y
, metaBlkHeightLog2
- 1);
1916 pMetaEq
->Filter('>', co
, 0, DIM_Y
);
1917 co
.set(DIM_Z
, metaBlkDepthLog2
- 1);
1918 pMetaEq
->Filter('>', co
, 0, DIM_Z
);
1920 // filter out everything above the metablock size for the channel bits
1921 co
.set(DIM_X
, metaBlkWidthLog2
- 1);
1922 pipeEquation
.Filter('>', co
, 0, DIM_X
);
1923 co
.set(DIM_Y
, metaBlkHeightLog2
- 1);
1924 pipeEquation
.Filter('>', co
, 0, DIM_Y
);
1925 co
.set(DIM_Z
, metaBlkDepthLog2
- 1);
1926 pipeEquation
.Filter('>', co
, 0, DIM_Z
);
1928 // Make sure we still have the same number of channel bits
1929 if (pipeEquation
.getsize() != numPipeTotalLog2
)
1931 ADDR_ASSERT_ALWAYS();
1934 // Loop through all channel and rb bits,
1935 // and make sure these components exist in the metadata address
1936 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1938 for (UINT_32 j
= pipeEquation
[i
].getsize(); j
> 0; j
--)
1940 if (pMetaEq
->Exists(pipeEquation
[i
][j
- 1]) == FALSE
)
1942 ADDR_ASSERT_ALWAYS();
1947 const UINT_32 numSeLog2
= metaFlag
.rbAligned
? m_seLog2
: 0;
1948 const UINT_32 numRbPeSeLog2
= metaFlag
.rbAligned
? m_rbPerSeLog2
: 0;
1949 const UINT_32 numRbTotalLog2
= numRbPeSeLog2
+ numSeLog2
;
1950 CoordEq origRbEquation
;
1952 GetRbEquation(&origRbEquation
, numRbPeSeLog2
, numSeLog2
);
1954 CoordEq rbEquation
= origRbEquation
;
1956 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1958 for (UINT_32 j
= rbEquation
[i
].getsize(); j
> 0; j
--)
1960 if (pMetaEq
->Exists(rbEquation
[i
][j
- 1]) == FALSE
)
1962 ADDR_ASSERT_ALWAYS();
1967 if (m_settings
.applyAliasFix
)
1972 // Loop through each rb id bit; if it is equal to any of the filtered channel bits, clear it
1973 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1975 for (UINT_32 j
= 0; j
< numPipeTotalLog2
; j
++)
1977 BOOL_32 isRbEquationInPipeEquation
= FALSE
;
1979 if (m_settings
.applyAliasFix
)
1981 CoordTerm filteredPipeEq
;
1982 filteredPipeEq
= pipeEquation
[j
];
1984 filteredPipeEq
.Filter('>', co
, 0, DIM_Z
);
1986 isRbEquationInPipeEquation
= (rbEquation
[i
] == filteredPipeEq
);
1990 isRbEquationInPipeEquation
= (rbEquation
[i
] == pipeEquation
[j
]);
1993 if (isRbEquationInPipeEquation
)
1995 rbEquation
[i
].Clear();
2000 bool rbAppendedWithPipeBits
[1 << (MaxSeLog2
+ MaxRbPerSeLog2
)] = {};
2002 // Loop through each bit of the channel, get the smallest coordinate,
2003 // and remove it from the metaaddr, and rb_equation
2004 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
2006 pipeEquation
[i
].getsmallest(co
);
2008 UINT_32 old_size
= pMetaEq
->getsize();
2009 pMetaEq
->Filter('=', co
);
2010 UINT_32 new_size
= pMetaEq
->getsize();
2011 if (new_size
!= old_size
-1)
2013 ADDR_ASSERT_ALWAYS();
2015 pipeEquation
.remove(co
);
2016 for (UINT_32 j
= 0; j
< numRbTotalLog2
; j
++)
2018 if (rbEquation
[j
].remove(co
))
2020 // if we actually removed something from this bit, then add the remaining
2021 // channel bits, as these can be removed for this bit
2022 for (UINT_32 k
= 0; k
< pipeEquation
[i
].getsize(); k
++)
2024 if (pipeEquation
[i
][k
] != co
)
2026 rbEquation
[j
].add(pipeEquation
[i
][k
]);
2027 rbAppendedWithPipeBits
[j
] = true;
2034 // Loop through the rb bits and see what remain;
2035 // filter out the smallest coordinate if it remains
2036 UINT_32 rbBitsLeft
= 0;
2037 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
2039 BOOL_32 isRbEqAppended
= FALSE
;
2041 if (m_settings
.applyAliasFix
)
2043 isRbEqAppended
= (rbEquation
[i
].getsize() > (rbAppendedWithPipeBits
[i
] ? 1 : 0));
2047 isRbEqAppended
= (rbEquation
[i
].getsize() > 0);
2053 rbEquation
[i
].getsmallest(co
);
2054 UINT_32 old_size
= pMetaEq
->getsize();
2055 pMetaEq
->Filter('=', co
);
2056 UINT_32 new_size
= pMetaEq
->getsize();
2057 if (new_size
!= old_size
- 1)
2061 for (UINT_32 j
= i
+ 1; j
< numRbTotalLog2
; j
++)
2063 if (rbEquation
[j
].remove(co
))
2065 // if we actually removed something from this bit, then add the remaining
2066 // rb bits, as these can be removed for this bit
2067 for (UINT_32 k
= 0; k
< rbEquation
[i
].getsize(); k
++)
2069 if (rbEquation
[i
][k
] != co
)
2071 rbEquation
[j
].add(rbEquation
[i
][k
]);
2072 rbAppendedWithPipeBits
[j
] |= rbAppendedWithPipeBits
[i
];
2080 // capture the size of the metaaddr
2081 UINT_32 metaSize
= pMetaEq
->getsize();
2082 // resize to 49 bits...make this a nibble address
2083 pMetaEq
->resize(49);
2084 // Concatenate the macro address above the current address
2085 for (UINT_32 i
= metaSize
, j
= 0; i
< 49; i
++, j
++)
2088 (*pMetaEq
)[i
].add(co
);
2091 // Multiply by meta element size (in nibbles)
2092 if (dataSurfaceType
== Gfx9DataColor
)
2096 else if (dataSurfaceType
== Gfx9DataDepthStencil
)
2101 //------------------------------------------------------------------------------------------
2102 // Note the pipeInterleaveLog2+1 is because address is a nibble address
2103 // Shift up from pipe interleave number of channel
2104 // and rb bits left, and uncompressed fragments
2105 //------------------------------------------------------------------------------------------
2107 pMetaEq
->shift(numPipeTotalLog2
+ rbBitsLeft
+ uncompFragLog2
, pipeInterleaveLog2
+ 1);
2109 // Put in the channel bits
2110 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
2112 origPipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+1 + i
]);
2115 // Put in remaining rb bits
2116 for (UINT_32 i
= 0, j
= 0; j
< rbBitsLeft
; i
= (i
+ 1) % numRbTotalLog2
)
2118 BOOL_32 isRbEqAppended
= FALSE
;
2120 if (m_settings
.applyAliasFix
)
2122 isRbEqAppended
= (rbEquation
[i
].getsize() > (rbAppendedWithPipeBits
[i
] ? 1 : 0));
2126 isRbEqAppended
= (rbEquation
[i
].getsize() > 0);
2131 origRbEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ j
]);
2132 // Mark any rb bit we add in to the rb mask
2137 //------------------------------------------------------------------------------------------
2138 // Put in the uncompressed fragment bits
2139 //------------------------------------------------------------------------------------------
2140 for (UINT_32 i
= 0; i
< uncompFragLog2
; i
++)
2142 co
.set(DIM_S
, compFragLog2
+ i
);
2143 (*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ rbBitsLeft
+ i
].add(co
);
2149 ************************************************************************************************************************
2150 * Gfx9Lib::IsEquationSupported
2153 * Check if equation is supported for given swizzle mode and resource type.
2157 ************************************************************************************************************************
2159 BOOL_32
Gfx9Lib::IsEquationSupported(
2160 AddrResourceType rsrcType
,
2161 AddrSwizzleMode swMode
,
2162 UINT_32 elementBytesLog2
) const
2164 BOOL_32 supported
= (elementBytesLog2
< MaxElementBytesLog2
) &&
2165 (IsValidSwMode(swMode
) == TRUE
) &&
2166 (IsLinear(swMode
) == FALSE
) &&
2167 (((IsTex2d(rsrcType
) == TRUE
) &&
2168 ((elementBytesLog2
< 4) ||
2169 ((IsRotateSwizzle(swMode
) == FALSE
) &&
2170 (IsZOrderSwizzle(swMode
) == FALSE
)))) ||
2171 ((IsTex3d(rsrcType
) == TRUE
) &&
2172 (IsRotateSwizzle(swMode
) == FALSE
) &&
2173 (IsBlock256b(swMode
) == FALSE
)));
2179 ************************************************************************************************************************
2180 * Gfx9Lib::InitEquationTable
2183 * Initialize Equation table.
2187 ************************************************************************************************************************
2189 VOID
Gfx9Lib::InitEquationTable()
2191 memset(m_equationTable
, 0, sizeof(m_equationTable
));
2193 // Loop all possible resource type (2D/3D)
2194 for (UINT_32 rsrcTypeIdx
= 0; rsrcTypeIdx
< MaxRsrcType
; rsrcTypeIdx
++)
2196 AddrResourceType rsrcType
= static_cast<AddrResourceType
>(rsrcTypeIdx
+ ADDR_RSRC_TEX_2D
);
2198 // Loop all possible swizzle mode
2199 for (UINT_32 swModeIdx
= 0; swModeIdx
< MaxSwModeType
; swModeIdx
++)
2201 AddrSwizzleMode swMode
= static_cast<AddrSwizzleMode
>(swModeIdx
);
2203 // Loop all possible bpp
2204 for (UINT_32 bppIdx
= 0; bppIdx
< MaxElementBytesLog2
; bppIdx
++)
2206 UINT_32 equationIndex
= ADDR_INVALID_EQUATION_INDEX
;
2208 // Check if the input is supported
2209 if (IsEquationSupported(rsrcType
, swMode
, bppIdx
))
2211 ADDR_EQUATION equation
;
2212 ADDR_E_RETURNCODE retCode
;
2214 memset(&equation
, 0, sizeof(ADDR_EQUATION
));
2216 // Generate the equation
2217 if (IsBlock256b(swMode
) && IsTex2d(rsrcType
))
2219 retCode
= ComputeBlock256Equation(rsrcType
, swMode
, bppIdx
, &equation
);
2221 else if (IsThin(rsrcType
, swMode
))
2223 retCode
= ComputeThinEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2227 retCode
= ComputeThickEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2230 // Only fill the equation into the table if the return code is ADDR_OK,
2231 // otherwise if the return code is not ADDR_OK, it indicates this is not
2232 // a valid input, we do nothing but just fill invalid equation index
2233 // into the lookup table.
2234 if (retCode
== ADDR_OK
)
2236 equationIndex
= m_numEquations
;
2237 ADDR_ASSERT(equationIndex
< EquationTableSize
);
2239 m_equationTable
[equationIndex
] = equation
;
2245 ADDR_ASSERT_ALWAYS();
2249 // Fill the index into the lookup table, if the combination is not supported
2250 // fill the invalid equation index
2251 m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][bppIdx
] = equationIndex
;
2258 ************************************************************************************************************************
2259 * Gfx9Lib::HwlGetEquationIndex
2262 * Interface function stub of GetEquationIndex
2266 ************************************************************************************************************************
2268 UINT_32
Gfx9Lib::HwlGetEquationIndex(
2269 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
2270 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
2273 AddrResourceType rsrcType
= pIn
->resourceType
;
2274 AddrSwizzleMode swMode
= pIn
->swizzleMode
;
2275 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
2276 UINT_32 index
= ADDR_INVALID_EQUATION_INDEX
;
2278 if (IsEquationSupported(rsrcType
, swMode
, elementBytesLog2
))
2280 UINT_32 rsrcTypeIdx
= static_cast<UINT_32
>(rsrcType
) - 1;
2281 UINT_32 swModeIdx
= static_cast<UINT_32
>(swMode
);
2283 index
= m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][elementBytesLog2
];
2286 if (pOut
->pMipInfo
!= NULL
)
2288 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
2290 pOut
->pMipInfo
[i
].equationIndex
= index
;
2298 ************************************************************************************************************************
2299 * Gfx9Lib::HwlComputeBlock256Equation
2302 * Interface function stub of ComputeBlock256Equation
2306 ************************************************************************************************************************
2308 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeBlock256Equation(
2309 AddrResourceType rsrcType
,
2310 AddrSwizzleMode swMode
,
2311 UINT_32 elementBytesLog2
,
2312 ADDR_EQUATION
* pEquation
) const
2314 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2316 pEquation
->numBits
= 8;
2319 for (; i
< elementBytesLog2
; i
++)
2321 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2324 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2326 const UINT_32 maxBitsUsed
= 4;
2327 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2328 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2330 for (i
= 0; i
< maxBitsUsed
; i
++)
2332 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2333 InitChannel(1, 1, i
, &y
[i
]);
2336 if (IsStandardSwizzle(rsrcType
, swMode
))
2338 switch (elementBytesLog2
)
2381 ADDR_ASSERT_ALWAYS();
2382 ret
= ADDR_INVALIDPARAMS
;
2386 else if (IsDisplaySwizzle(rsrcType
, swMode
))
2388 switch (elementBytesLog2
)
2431 ADDR_ASSERT_ALWAYS();
2432 ret
= ADDR_INVALIDPARAMS
;
2436 else if (IsRotateSwizzle(swMode
))
2438 switch (elementBytesLog2
)
2475 ADDR_ASSERT_ALWAYS();
2477 ret
= ADDR_INVALIDPARAMS
;
2483 ADDR_ASSERT_ALWAYS();
2484 ret
= ADDR_INVALIDPARAMS
;
2490 ASSERTED Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2491 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 0)) ==
2492 (microBlockDim
.w
* (1 << elementBytesLog2
)));
2493 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 1)) == microBlockDim
.h
);
2500 ************************************************************************************************************************
2501 * Gfx9Lib::HwlComputeThinEquation
2504 * Interface function stub of ComputeThinEquation
2508 ************************************************************************************************************************
2510 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThinEquation(
2511 AddrResourceType rsrcType
,
2512 AddrSwizzleMode swMode
,
2513 UINT_32 elementBytesLog2
,
2514 ADDR_EQUATION
* pEquation
) const
2516 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2518 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2520 UINT_32 maxXorBits
= blockSizeLog2
;
2521 if (IsNonPrtXor(swMode
))
2523 // For non-prt-xor, maybe need to initialize some more bits for xor
2524 // The highest xor bit used in equation will be max the following 3 items:
2525 // 1. m_pipeInterleaveLog2 + 2 * pipeXorBits
2526 // 2. m_pipeInterleaveLog2 + pipeXorBits + 2 * bankXorBits
2529 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 2 * GetPipeXorBits(blockSizeLog2
));
2530 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2531 GetPipeXorBits(blockSizeLog2
) +
2532 2 * GetBankXorBits(blockSizeLog2
));
2535 const UINT_32 maxBitsUsed
= 14;
2536 ADDR_ASSERT((2 * maxBitsUsed
) >= maxXorBits
);
2537 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2538 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2540 const UINT_32 extraXorBits
= 16;
2541 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2542 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2544 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2546 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2547 InitChannel(1, 1, i
, &y
[i
]);
2550 ADDR_CHANNEL_SETTING
* pixelBit
= pEquation
->addr
;
2552 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2554 InitChannel(1, 0 , i
, &pixelBit
[i
]);
2559 UINT_32 lowBits
= 0;
2561 if (IsZOrderSwizzle(swMode
))
2563 if (elementBytesLog2
<= 3)
2565 for (UINT_32 i
= elementBytesLog2
; i
< 6; i
++)
2567 pixelBit
[i
] = (((i
- elementBytesLog2
) & 1) == 0) ? x
[xIdx
++] : y
[yIdx
++];
2574 ret
= ADDR_INVALIDPARAMS
;
2579 ret
= HwlComputeBlock256Equation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
2583 Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2584 xIdx
= Log2(microBlockDim
.w
);
2585 yIdx
= Log2(microBlockDim
.h
);
2592 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2594 pixelBit
[i
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2597 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2599 xorExtra
[i
- blockSizeLog2
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2605 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2606 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2608 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2609 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2611 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2613 UINT_32 xor1BitPos
= pipeStart
+ 2 * pipeXorBits
- 1 - i
;
2614 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2615 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2617 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2620 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2622 UINT_32 xor1BitPos
= bankStart
+ 2 * bankXorBits
- 1 - i
;
2623 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2624 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2626 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2629 if (IsPrt(swMode
) == FALSE
)
2631 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2633 InitChannel(1, 2, pipeXorBits
- i
- 1, &pEquation
->xor2
[pipeStart
+ i
]);
2636 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2638 InitChannel(1, 2, bankXorBits
- i
- 1 + pipeXorBits
, &pEquation
->xor2
[bankStart
+ i
]);
2643 pEquation
->numBits
= blockSizeLog2
;
2650 ************************************************************************************************************************
2651 * Gfx9Lib::HwlComputeThickEquation
2654 * Interface function stub of ComputeThickEquation
2658 ************************************************************************************************************************
2660 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThickEquation(
2661 AddrResourceType rsrcType
,
2662 AddrSwizzleMode swMode
,
2663 UINT_32 elementBytesLog2
,
2664 ADDR_EQUATION
* pEquation
) const
2666 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2668 ADDR_ASSERT(IsTex3d(rsrcType
));
2670 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2672 UINT_32 maxXorBits
= blockSizeLog2
;
2673 if (IsNonPrtXor(swMode
))
2675 // For non-prt-xor, maybe need to initialize some more bits for xor
2676 // The highest xor bit used in equation will be max the following 3:
2677 // 1. m_pipeInterleaveLog2 + 3 * pipeXorBits
2678 // 2. m_pipeInterleaveLog2 + pipeXorBits + 3 * bankXorBits
2681 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 3 * GetPipeXorBits(blockSizeLog2
));
2682 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2683 GetPipeXorBits(blockSizeLog2
) +
2684 3 * GetBankXorBits(blockSizeLog2
));
2687 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2689 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2692 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2694 const UINT_32 maxBitsUsed
= 12;
2695 ADDR_ASSERT((3 * maxBitsUsed
) >= maxXorBits
);
2696 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2697 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2698 ADDR_CHANNEL_SETTING z
[maxBitsUsed
] = {};
2700 const UINT_32 extraXorBits
= 24;
2701 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2702 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2704 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2706 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2707 InitChannel(1, 1, i
, &y
[i
]);
2708 InitChannel(1, 2, i
, &z
[i
]);
2711 if (IsZOrderSwizzle(swMode
))
2713 switch (elementBytesLog2
)
2766 ADDR_ASSERT_ALWAYS();
2767 ret
= ADDR_INVALIDPARAMS
;
2771 else if (IsStandardSwizzle(rsrcType
, swMode
))
2773 switch (elementBytesLog2
)
2826 ADDR_ASSERT_ALWAYS();
2827 ret
= ADDR_INVALIDPARAMS
;
2833 ADDR_ASSERT_ALWAYS();
2834 ret
= ADDR_INVALIDPARAMS
;
2839 Dim3d microBlockDim
= Block1K_3d
[elementBytesLog2
];
2840 UINT_32 xIdx
= Log2(microBlockDim
.w
);
2841 UINT_32 yIdx
= Log2(microBlockDim
.h
);
2842 UINT_32 zIdx
= Log2(microBlockDim
.d
);
2844 pixelBit
= pEquation
->addr
;
2846 const UINT_32 lowBits
= 10;
2847 ADDR_ASSERT(pEquation
->addr
[lowBits
- 1].valid
== 1);
2848 ADDR_ASSERT(pEquation
->addr
[lowBits
].valid
== 0);
2850 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2854 pixelBit
[i
] = x
[xIdx
++];
2856 else if ((i
% 3) == 1)
2858 pixelBit
[i
] = z
[zIdx
++];
2862 pixelBit
[i
] = y
[yIdx
++];
2866 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2870 xorExtra
[i
- blockSizeLog2
] = x
[xIdx
++];
2872 else if ((i
% 3) == 1)
2874 xorExtra
[i
- blockSizeLog2
] = z
[zIdx
++];
2878 xorExtra
[i
- blockSizeLog2
] = y
[yIdx
++];
2885 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2886 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2887 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2889 UINT_32 xor1BitPos
= pipeStart
+ (3 * pipeXorBits
) - 1 - (2 * i
);
2890 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2891 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2893 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2895 UINT_32 xor2BitPos
= pipeStart
+ (3 * pipeXorBits
) - 2 - (2 * i
);
2896 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2897 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2899 InitChannel(&pEquation
->xor2
[pipeStart
+ i
], pXor2Src
);
2902 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2903 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2904 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2906 UINT_32 xor1BitPos
= bankStart
+ (3 * bankXorBits
) - 1 - (2 * i
);
2907 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2908 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2910 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2912 UINT_32 xor2BitPos
= bankStart
+ (3 * bankXorBits
) - 2 - (2 * i
);
2913 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2914 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2916 InitChannel(&pEquation
->xor2
[bankStart
+ i
], pXor2Src
);
2920 pEquation
->numBits
= blockSizeLog2
;
2927 ************************************************************************************************************************
2928 * Gfx9Lib::IsValidDisplaySwizzleMode
2931 * Check if a swizzle mode is supported by display engine
2934 * TRUE is swizzle mode is supported by display engine
2935 ************************************************************************************************************************
2937 BOOL_32
Gfx9Lib::IsValidDisplaySwizzleMode(
2938 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
2940 BOOL_32 support
= FALSE
;
2942 if (m_settings
.isDce12
)
2944 switch (pIn
->swizzleMode
)
2946 case ADDR_SW_256B_D
:
2947 case ADDR_SW_256B_R
:
2948 support
= (pIn
->bpp
== 32);
2951 case ADDR_SW_LINEAR
:
2954 case ADDR_SW_64KB_D
:
2955 case ADDR_SW_64KB_R
:
2956 case ADDR_SW_4KB_D_X
:
2957 case ADDR_SW_4KB_R_X
:
2958 case ADDR_SW_64KB_D_X
:
2959 case ADDR_SW_64KB_R_X
:
2960 support
= (pIn
->bpp
<= 64);
2967 else if (m_settings
.isDcn1
)
2969 switch (pIn
->swizzleMode
)
2972 case ADDR_SW_64KB_D
:
2973 case ADDR_SW_64KB_D_T
:
2974 case ADDR_SW_4KB_D_X
:
2975 case ADDR_SW_64KB_D_X
:
2976 support
= (pIn
->bpp
== 64);
2979 case ADDR_SW_LINEAR
:
2981 case ADDR_SW_64KB_S
:
2982 case ADDR_SW_64KB_S_T
:
2983 case ADDR_SW_4KB_S_X
:
2984 case ADDR_SW_64KB_S_X
:
2985 support
= (pIn
->bpp
<= 64);
2994 ADDR_NOT_IMPLEMENTED();
3001 ************************************************************************************************************************
3002 * Gfx9Lib::HwlComputePipeBankXor
3005 * Generate a PipeBankXor value to be ORed into bits above pipeInterleaveBits of address
3009 ************************************************************************************************************************
3011 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputePipeBankXor(
3012 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
3013 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
) const
3015 if (IsXor(pIn
->swizzleMode
))
3017 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3018 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3019 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3021 UINT_32 pipeXor
= 0;
3022 UINT_32 bankXor
= 0;
3024 const UINT_32 bankMask
= (1 << bankBits
) - 1;
3025 const UINT_32 index
= pIn
->surfIndex
& bankMask
;
3027 const UINT_32 bpp
= pIn
->flags
.fmask
?
3028 GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
) : GetElemLib()->GetBitsPerPixel(pIn
->format
);
3031 static const UINT_32 BankXorSmallBpp
[] = {0, 7, 4, 3, 8, 15, 12, 11, 1, 6, 5, 2, 9, 14, 13, 10};
3032 static const UINT_32 BankXorLargeBpp
[] = {0, 7, 8, 15, 4, 3, 12, 11, 1, 6, 9, 14, 5, 2, 13, 10};
3034 bankXor
= (bpp
<= 32) ? BankXorSmallBpp
[index
] : BankXorLargeBpp
[index
];
3036 else if (bankBits
> 0)
3038 UINT_32 bankIncrease
= (1 << (bankBits
- 1)) - 1;
3039 bankIncrease
= (bankIncrease
== 0) ? 1 : bankIncrease
;
3040 bankXor
= (index
* bankIncrease
) & bankMask
;
3043 pOut
->pipeBankXor
= (bankXor
<< pipeBits
) | pipeXor
;
3047 pOut
->pipeBankXor
= 0;
3054 ************************************************************************************************************************
3055 * Gfx9Lib::HwlComputeSlicePipeBankXor
3058 * Generate slice PipeBankXor value based on base PipeBankXor value and slice id
3062 ************************************************************************************************************************
3064 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSlicePipeBankXor(
3065 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
3066 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
) const
3068 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3069 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3070 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3072 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
3073 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
3075 pOut
->pipeBankXor
= pIn
->basePipeBankXor
^ (pipeXor
| (bankXor
<< pipeBits
));
3081 ************************************************************************************************************************
3082 * Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern
3085 * Compute sub resource offset to support swizzle pattern
3089 ************************************************************************************************************************
3091 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern(
3092 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
3093 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
) const
3095 ADDR_ASSERT(IsThin(pIn
->resourceType
, pIn
->swizzleMode
));
3097 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3098 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3099 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3100 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
3101 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
3102 UINT_32 pipeBankXor
= ((pipeXor
| (bankXor
<< pipeBits
)) ^ (pIn
->pipeBankXor
)) << m_pipeInterleaveLog2
;
3104 pOut
->offset
= pIn
->slice
* pIn
->sliceSize
+
3105 pIn
->macroBlockOffset
+
3106 (pIn
->mipTailOffset
^ pipeBankXor
) -
3107 static_cast<UINT_64
>(pipeBankXor
);
3112 ************************************************************************************************************************
3113 * Gfx9Lib::ValidateNonSwModeParams
3116 * Validate compute surface info params except swizzle mode
3119 * TRUE if parameters are valid, FALSE otherwise
3120 ************************************************************************************************************************
3122 BOOL_32
Gfx9Lib::ValidateNonSwModeParams(
3123 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3125 BOOL_32 valid
= TRUE
;
3127 if ((pIn
->bpp
== 0) || (pIn
->bpp
> 128) || (pIn
->width
== 0) || (pIn
->numFrags
> 8) || (pIn
->numSamples
> 16))
3129 ADDR_ASSERT_ALWAYS();
3133 if (pIn
->resourceType
>= ADDR_RSRC_MAX_TYPE
)
3135 ADDR_ASSERT_ALWAYS();
3139 const BOOL_32 mipmap
= (pIn
->numMipLevels
> 1);
3140 const BOOL_32 msaa
= (pIn
->numFrags
> 1);
3141 const BOOL_32 isBc
= ElemLib::IsBlockCompressed(pIn
->format
);
3143 const AddrResourceType rsrcType
= pIn
->resourceType
;
3144 const BOOL_32 tex3d
= IsTex3d(rsrcType
);
3145 const BOOL_32 tex2d
= IsTex2d(rsrcType
);
3146 const BOOL_32 tex1d
= IsTex1d(rsrcType
);
3148 const ADDR2_SURFACE_FLAGS flags
= pIn
->flags
;
3149 const BOOL_32 zbuffer
= flags
.depth
|| flags
.stencil
;
3150 const BOOL_32 display
= flags
.display
|| flags
.rotated
;
3151 const BOOL_32 stereo
= flags
.qbStereo
;
3152 const BOOL_32 fmask
= flags
.fmask
;
3154 // Resource type check
3157 if (msaa
|| zbuffer
|| display
|| stereo
|| isBc
|| fmask
)
3159 ADDR_ASSERT_ALWAYS();
3165 if ((msaa
&& mipmap
) || (stereo
&& msaa
) || (stereo
&& mipmap
))
3167 ADDR_ASSERT_ALWAYS();
3173 if (msaa
|| zbuffer
|| display
|| stereo
|| fmask
)
3175 ADDR_ASSERT_ALWAYS();
3181 ADDR_ASSERT_ALWAYS();
3189 ************************************************************************************************************************
3190 * Gfx9Lib::ValidateSwModeParams
3193 * Validate compute surface info related to swizzle mode
3196 * TRUE if parameters are valid, FALSE otherwise
3197 ************************************************************************************************************************
3199 BOOL_32
Gfx9Lib::ValidateSwModeParams(
3200 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3202 BOOL_32 valid
= TRUE
;
3204 if ((pIn
->swizzleMode
>= ADDR_SW_MAX_TYPE
) || (IsValidSwMode(pIn
->swizzleMode
) == FALSE
))
3206 ADDR_ASSERT_ALWAYS();
3210 const BOOL_32 mipmap
= (pIn
->numMipLevels
> 1);
3211 const BOOL_32 msaa
= (pIn
->numFrags
> 1);
3212 const BOOL_32 isBc
= ElemLib::IsBlockCompressed(pIn
->format
);
3213 const BOOL_32 is422
= ElemLib::IsMacroPixelPacked(pIn
->format
);
3215 const AddrResourceType rsrcType
= pIn
->resourceType
;
3216 const BOOL_32 tex3d
= IsTex3d(rsrcType
);
3217 const BOOL_32 tex2d
= IsTex2d(rsrcType
);
3218 const BOOL_32 tex1d
= IsTex1d(rsrcType
);
3220 const AddrSwizzleMode swizzle
= pIn
->swizzleMode
;
3221 const BOOL_32 linear
= IsLinear(swizzle
);
3222 const BOOL_32 blk256B
= IsBlock256b(swizzle
);
3223 const BOOL_32 isNonPrtXor
= IsNonPrtXor(swizzle
);
3225 const ADDR2_SURFACE_FLAGS flags
= pIn
->flags
;
3226 const BOOL_32 zbuffer
= flags
.depth
|| flags
.stencil
;
3227 const BOOL_32 color
= flags
.color
;
3228 const BOOL_32 texture
= flags
.texture
;
3229 const BOOL_32 display
= flags
.display
|| flags
.rotated
;
3230 const BOOL_32 prt
= flags
.prt
;
3231 const BOOL_32 fmask
= flags
.fmask
;
3233 const BOOL_32 thin3d
= tex3d
&& flags
.view3dAs2dArray
;
3234 const BOOL_32 zMaxMip
= tex3d
&& mipmap
&&
3235 (pIn
->numSlices
>= pIn
->width
) && (pIn
->numSlices
>= pIn
->height
);
3238 if (msaa
&& (GetBlockSize(swizzle
) < (m_pipeInterleaveBytes
* pIn
->numFrags
)))
3240 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3241 ADDR_ASSERT_ALWAYS();
3245 if (display
&& (IsValidDisplaySwizzleMode(pIn
) == FALSE
))
3247 ADDR_ASSERT_ALWAYS();
3251 if ((pIn
->bpp
== 96) && (linear
== FALSE
))
3253 ADDR_ASSERT_ALWAYS();
3257 if (prt
&& isNonPrtXor
)
3259 ADDR_ASSERT_ALWAYS();
3263 // Resource type check
3266 if (linear
== FALSE
)
3268 ADDR_ASSERT_ALWAYS();
3273 // Swizzle type check
3276 if (((tex1d
== FALSE
) && prt
) || zbuffer
|| msaa
|| (pIn
->bpp
== 0) ||
3277 ((pIn
->bpp
% 8) != 0) || (isBc
&& texture
) || fmask
)
3279 ADDR_ASSERT_ALWAYS();
3283 else if (IsZOrderSwizzle(swizzle
))
3285 if ((color
&& msaa
) || thin3d
|| isBc
|| is422
|| (tex2d
&& (pIn
->bpp
> 64)) || (msaa
&& (pIn
->bpp
> 32)))
3287 ADDR_ASSERT_ALWAYS();
3291 else if (IsStandardSwizzle(swizzle
))
3293 if (zbuffer
|| thin3d
|| (tex3d
&& (pIn
->bpp
== 128) && color
) || fmask
)
3295 ADDR_ASSERT_ALWAYS();
3299 else if (IsDisplaySwizzle(swizzle
))
3301 if (zbuffer
|| (prt
&& tex3d
) || fmask
|| zMaxMip
)
3303 ADDR_ASSERT_ALWAYS();
3307 else if (IsRotateSwizzle(swizzle
))
3309 if (zbuffer
|| (pIn
->bpp
> 64) || tex3d
|| isBc
|| fmask
)
3311 ADDR_ASSERT_ALWAYS();
3317 ADDR_ASSERT_ALWAYS();
3324 if (prt
|| zbuffer
|| tex3d
|| mipmap
|| msaa
)
3326 ADDR_ASSERT_ALWAYS();
3335 ************************************************************************************************************************
3336 * Gfx9Lib::HwlComputeSurfaceInfoSanityCheck
3339 * Compute surface info sanity check
3342 * ADDR_OK if parameters are valid, ADDR_INVALIDPARAMS otherwise
3343 ************************************************************************************************************************
3345 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoSanityCheck(
3346 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3348 return ValidateNonSwModeParams(pIn
) && ValidateSwModeParams(pIn
) ? ADDR_OK
: ADDR_INVALIDPARAMS
;
3352 ************************************************************************************************************************
3353 * Gfx9Lib::HwlGetPreferredSurfaceSetting
3356 * Internal function to get suggested surface information for cliet to use
3360 ************************************************************************************************************************
3362 ADDR_E_RETURNCODE
Gfx9Lib::HwlGetPreferredSurfaceSetting(
3363 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
3364 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const
3366 ADDR_E_RETURNCODE returnCode
= ADDR_INVALIDPARAMS
;
3367 ElemLib
* pElemLib
= GetElemLib();
3369 UINT_32 bpp
= pIn
->bpp
;
3370 UINT_32 width
= Max(pIn
->width
, 1u);
3371 UINT_32 height
= Max(pIn
->height
, 1u);
3372 UINT_32 numSamples
= Max(pIn
->numSamples
, 1u);
3373 UINT_32 numFrags
= (pIn
->numFrags
== 0) ? numSamples
: pIn
->numFrags
;
3375 if (pIn
->flags
.fmask
)
3377 bpp
= GetFmaskBpp(numSamples
, numFrags
);
3380 pOut
->resourceType
= ADDR_RSRC_TEX_2D
;
3384 // Set format to INVALID will skip this conversion
3385 if (pIn
->format
!= ADDR_FMT_INVALID
)
3387 UINT_32 expandX
, expandY
;
3389 // Don't care for this case
3390 ElemMode elemMode
= ADDR_UNCOMPRESSED
;
3392 // Get compression/expansion factors and element mode which indicates compression/expansion
3393 bpp
= pElemLib
->GetBitsPerPixel(pIn
->format
,
3398 UINT_32 basePitch
= 0;
3399 GetElemLib()->AdjustSurfaceInfo(elemMode
,
3408 // The output may get changed for volume(3D) texture resource in future
3409 pOut
->resourceType
= pIn
->resourceType
;
3412 const UINT_32 numSlices
= Max(pIn
->numSlices
, 1u);
3413 const UINT_32 numMipLevels
= Max(pIn
->numMipLevels
, 1u);
3414 const BOOL_32 msaa
= (numFrags
> 1) || (numSamples
> 1);
3415 const BOOL_32 displayRsrc
= pIn
->flags
.display
|| pIn
->flags
.rotated
;
3417 // Pre sanity check on non swizzle mode parameters
3418 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {};
3419 localIn
.flags
= pIn
->flags
;
3420 localIn
.resourceType
= pOut
->resourceType
;
3421 localIn
.format
= pIn
->format
;
3423 localIn
.width
= width
;
3424 localIn
.height
= height
;
3425 localIn
.numSlices
= numSlices
;
3426 localIn
.numMipLevels
= numMipLevels
;
3427 localIn
.numSamples
= numSamples
;
3428 localIn
.numFrags
= numFrags
;
3430 if (ValidateNonSwModeParams(&localIn
))
3432 // Forbid swizzle mode(s) by client setting
3433 ADDR2_SWMODE_SET allowedSwModeSet
= {};
3434 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.linear
? 0 : Gfx9LinearSwModeMask
;
3435 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.micro
? 0 : Gfx9Blk256BSwModeMask
;
3436 allowedSwModeSet
.value
|=
3437 pIn
->forbiddenBlock
.macroThin4KB
? 0 :
3438 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThin4KBSwModeMask
: Gfx9Blk4KBSwModeMask
);
3439 allowedSwModeSet
.value
|=
3440 pIn
->forbiddenBlock
.macroThick4KB
? 0 :
3441 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThick4KBSwModeMask
: 0);
3442 allowedSwModeSet
.value
|=
3443 pIn
->forbiddenBlock
.macroThin64KB
? 0 :
3444 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThin64KBSwModeMask
: Gfx9Blk64KBSwModeMask
);
3445 allowedSwModeSet
.value
|=
3446 pIn
->forbiddenBlock
.macroThick64KB
? 0 :
3447 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThick64KBSwModeMask
: 0);
3449 if (pIn
->preferredSwSet
.value
!= 0)
3451 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_Z
? ~0 : ~Gfx9ZSwModeMask
;
3452 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_S
? ~0 : ~Gfx9StandardSwModeMask
;
3453 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_D
? ~0 : ~Gfx9DisplaySwModeMask
;
3454 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_R
? ~0 : ~Gfx9RotateSwModeMask
;
3459 allowedSwModeSet
.value
&= ~Gfx9XorSwModeMask
;
3462 if (pIn
->maxAlign
> 0)
3464 if (pIn
->maxAlign
< Size64K
)
3466 allowedSwModeSet
.value
&= ~Gfx9Blk64KBSwModeMask
;
3469 if (pIn
->maxAlign
< Size4K
)
3471 allowedSwModeSet
.value
&= ~Gfx9Blk4KBSwModeMask
;
3474 if (pIn
->maxAlign
< Size256
)
3476 allowedSwModeSet
.value
&= ~Gfx9Blk256BSwModeMask
;
3480 // Filter out invalid swizzle mode(s) by image attributes and HW restrictions
3481 switch (pOut
->resourceType
)
3483 case ADDR_RSRC_TEX_1D
:
3484 allowedSwModeSet
.value
&= Gfx9Rsrc1dSwModeMask
;
3487 case ADDR_RSRC_TEX_2D
:
3488 allowedSwModeSet
.value
&= pIn
->flags
.prt
? Gfx9Rsrc2dPrtSwModeMask
: Gfx9Rsrc2dSwModeMask
;
3492 allowedSwModeSet
.value
&= ~(Gfx9RotateSwModeMask
| Gfx9ZSwModeMask
);
3496 case ADDR_RSRC_TEX_3D
:
3497 allowedSwModeSet
.value
&= pIn
->flags
.prt
? Gfx9Rsrc3dPrtSwModeMask
: Gfx9Rsrc3dSwModeMask
;
3499 if ((numMipLevels
> 1) && (numSlices
>= width
) && (numSlices
>= height
))
3501 // SW_*_D for 3D mipmaps (maxmip > 0) is only supported for Xmajor or Ymajor mipmap
3502 // When depth (Z) is the maximum dimension then must use one of the SW_*_S
3503 // or SW_*_Z modes if mipmapping is desired on a 3D surface
3504 allowedSwModeSet
.value
&= ~Gfx9DisplaySwModeMask
;
3507 if ((bpp
== 128) && pIn
->flags
.color
)
3509 allowedSwModeSet
.value
&= ~Gfx9StandardSwModeMask
;
3512 if (pIn
->flags
.view3dAs2dArray
)
3514 allowedSwModeSet
.value
&= Gfx9Rsrc3dThinSwModeMask
| Gfx9LinearSwModeMask
;
3519 ADDR_ASSERT_ALWAYS();
3520 allowedSwModeSet
.value
= 0;
3524 if (pIn
->format
== ADDR_FMT_32_32_32
)
3526 allowedSwModeSet
.value
&= Gfx9LinearSwModeMask
;
3529 if (ElemLib::IsBlockCompressed(pIn
->format
))
3531 if (pIn
->flags
.texture
)
3533 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
| Gfx9DisplaySwModeMask
;
3537 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
| Gfx9DisplaySwModeMask
| Gfx9LinearSwModeMask
;
3541 if (ElemLib::IsMacroPixelPacked(pIn
->format
) ||
3542 (msaa
&& ((bpp
> 32) || pIn
->flags
.color
|| pIn
->flags
.unordered
)))
3544 allowedSwModeSet
.value
&= ~Gfx9ZSwModeMask
;
3547 if (pIn
->flags
.fmask
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
)
3549 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3551 if (pIn
->flags
.noMetadata
== FALSE
)
3553 if (pIn
->flags
.depth
&&
3554 pIn
->flags
.texture
&&
3555 (((bpp
== 16) && (numFrags
>= 4)) || ((bpp
== 32) && (numFrags
>= 2))))
3557 // When _X/_T swizzle mode was used for MSAA depth texture, TC will get zplane
3558 // equation from wrong address within memory range a tile covered and use the
3559 // garbage data for compressed Z reading which finally leads to corruption.
3560 allowedSwModeSet
.value
&= ~Gfx9XorSwModeMask
;
3563 if (m_settings
.htileCacheRbConflict
&&
3564 (pIn
->flags
.depth
|| pIn
->flags
.stencil
) &&
3566 (pIn
->flags
.metaRbUnaligned
== FALSE
) &&
3567 (pIn
->flags
.metaPipeUnaligned
== FALSE
))
3569 // Z_X 2D array with Rb/Pipe aligned HTile won't have metadata cache coherency
3570 allowedSwModeSet
.value
&= ~Gfx9XSwModeMask
;
3577 allowedSwModeSet
.value
&= Gfx9MsaaSwModeMask
;
3580 if ((numFrags
> 1) &&
3581 (Size4K
< (m_pipeInterleaveBytes
* numFrags
)))
3583 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3584 allowedSwModeSet
.value
&= Gfx9Blk64KBSwModeMask
;
3587 if (numMipLevels
> 1)
3589 allowedSwModeSet
.value
&= ~Gfx9Blk256BSwModeMask
;
3594 if (m_settings
.isDce12
)
3596 allowedSwModeSet
.value
&= (bpp
== 32) ? Dce12Bpp32SwModeMask
: Dce12NonBpp32SwModeMask
;
3598 else if (m_settings
.isDcn1
)
3600 allowedSwModeSet
.value
&= (bpp
== 64) ? Dcn1Bpp64SwModeMask
: Dcn1NonBpp64SwModeMask
;
3604 ADDR_NOT_IMPLEMENTED();
3608 if (allowedSwModeSet
.value
!= 0)
3611 // Post sanity check, at least AddrLib should accept the output generated by its own
3612 UINT_32 validateSwModeSet
= allowedSwModeSet
.value
;
3614 for (UINT_32 i
= 0; validateSwModeSet
!= 0; i
++)
3616 if (validateSwModeSet
& 1)
3618 localIn
.swizzleMode
= static_cast<AddrSwizzleMode
>(i
);
3619 ADDR_ASSERT(ValidateSwModeParams(&localIn
));
3622 validateSwModeSet
>>= 1;
3626 pOut
->validSwModeSet
= allowedSwModeSet
;
3627 pOut
->canXor
= (allowedSwModeSet
.value
& Gfx9XorSwModeMask
) ? TRUE
: FALSE
;
3628 pOut
->validBlockSet
= GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
);
3629 pOut
->validSwTypeSet
= GetAllowedSwSet(allowedSwModeSet
);
3631 pOut
->clientPreferredSwSet
= pIn
->preferredSwSet
;
3633 if (pOut
->clientPreferredSwSet
.value
== 0)
3635 pOut
->clientPreferredSwSet
.value
= AddrSwSetAll
;
3638 // Apply optional restrictions
3639 if (pIn
->flags
.needEquation
)
3641 FilterInvalidEqSwizzleMode(allowedSwModeSet
, pIn
->resourceType
, Log2(bpp
>> 3));
3644 if (allowedSwModeSet
.value
== Gfx9LinearSwModeMask
)
3646 pOut
->swizzleMode
= ADDR_SW_LINEAR
;
3650 // Always ignore linear swizzle mode if there is other choice.
3651 allowedSwModeSet
.swLinear
= 0;
3653 ADDR2_BLOCK_SET allowedBlockSet
= GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
);
3655 // Determine block size if there is 2 or more block type candidates
3656 if (IsPow2(allowedBlockSet
.value
) == FALSE
)
3658 AddrSwizzleMode swMode
[AddrBlockMaxTiledType
] = { ADDR_SW_LINEAR
};
3660 swMode
[AddrBlockMicro
] = ADDR_SW_256B_D
;
3661 swMode
[AddrBlockThin4KB
] = ADDR_SW_4KB_D
;
3662 swMode
[AddrBlockThin64KB
] = ADDR_SW_64KB_D
;
3664 if (pOut
->resourceType
== ADDR_RSRC_TEX_3D
)
3666 swMode
[AddrBlockThick4KB
] = ADDR_SW_4KB_S
;
3667 swMode
[AddrBlockThick64KB
] = ADDR_SW_64KB_S
;
3670 Dim3d blkDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}, {0}, {0}, {0}};
3671 Dim3d padDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}, {0}, {0}, {0}};
3672 UINT_64 padSize
[AddrBlockMaxTiledType
] = {0};
3674 const UINT_32 ratioLow
= pIn
->flags
.minimizeAlign
? 1 : (pIn
->flags
.opt4space
? 3 : 2);
3675 const UINT_32 ratioHi
= pIn
->flags
.minimizeAlign
? 1 : (pIn
->flags
.opt4space
? 2 : 1);
3676 const UINT_64 sizeAlignInElement
= Max(NextPow2(pIn
->minSizeAlign
) / (bpp
>> 3), 1u);
3677 UINT_32 minSizeBlk
= AddrBlockMicro
;
3678 UINT_64 minSize
= 0;
3680 for (UINT_32 i
= AddrBlockMicro
; i
< AddrBlockMaxTiledType
; i
++)
3682 if (allowedBlockSet
.value
& (1 << i
))
3684 ComputeBlockDimensionForSurf(&blkDim
[i
].w
,
3694 blkDim
[i
].w
= PowTwoAlign(blkDim
[i
].w
, 32);
3697 padSize
[i
] = ComputePadSize(&blkDim
[i
], width
, height
, numSlices
, &padDim
[i
]);
3698 padSize
[i
] = PowTwoAlign(padSize
[i
] * numFrags
, sizeAlignInElement
);
3700 if ((minSize
== 0) ||
3701 ((padSize
[i
] * ratioHi
) <= (minSize
* ratioLow
)))
3703 minSize
= padSize
[i
];
3709 if ((allowedBlockSet
.micro
== TRUE
) &&
3710 (width
<= blkDim
[AddrBlockMicro
].w
) &&
3711 (height
<= blkDim
[AddrBlockMicro
].h
) &&
3712 (NextPow2(pIn
->minSizeAlign
) <= Size256
))
3714 minSizeBlk
= AddrBlockMicro
;
3717 if (minSizeBlk
== AddrBlockMicro
)
3719 ADDR_ASSERT(pOut
->resourceType
!= ADDR_RSRC_TEX_3D
);
3720 allowedSwModeSet
.value
&= Gfx9Blk256BSwModeMask
;
3722 else if (minSizeBlk
== AddrBlockThick4KB
)
3724 ADDR_ASSERT(pOut
->resourceType
== ADDR_RSRC_TEX_3D
);
3725 allowedSwModeSet
.value
&= Gfx9Rsrc3dThick4KBSwModeMask
;
3727 else if (minSizeBlk
== AddrBlockThin4KB
)
3729 allowedSwModeSet
.value
&= (pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ?
3730 Gfx9Rsrc3dThin4KBSwModeMask
: Gfx9Blk4KBSwModeMask
;
3732 else if (minSizeBlk
== AddrBlockThick64KB
)
3734 ADDR_ASSERT(pOut
->resourceType
== ADDR_RSRC_TEX_3D
);
3735 allowedSwModeSet
.value
&= Gfx9Rsrc3dThick64KBSwModeMask
;
3739 ADDR_ASSERT(minSizeBlk
== AddrBlockThin64KB
);
3740 allowedSwModeSet
.value
&= (pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ?
3741 Gfx9Rsrc3dThin64KBSwModeMask
: Gfx9Blk64KBSwModeMask
;
3745 // Block type should be determined.
3746 ADDR_ASSERT(IsPow2(GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
).value
));
3748 ADDR2_SWTYPE_SET allowedSwSet
= GetAllowedSwSet(allowedSwModeSet
);
3750 // Determine swizzle type if there is 2 or more swizzle type candidates
3751 if (IsPow2(allowedSwSet
.value
) == FALSE
)
3753 if (ElemLib::IsBlockCompressed(pIn
->format
))
3755 if (allowedSwSet
.sw_D
)
3757 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3761 ADDR_ASSERT(allowedSwSet
.sw_S
);
3762 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3765 else if (ElemLib::IsMacroPixelPacked(pIn
->format
))
3767 if (allowedSwSet
.sw_S
)
3769 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3771 else if (allowedSwSet
.sw_D
)
3773 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3777 ADDR_ASSERT(allowedSwSet
.sw_R
);
3778 allowedSwModeSet
.value
&= Gfx9RotateSwModeMask
;
3781 else if (pOut
->resourceType
== ADDR_RSRC_TEX_3D
)
3783 if (pIn
->flags
.color
&& allowedSwSet
.sw_D
)
3785 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3787 else if (allowedSwSet
.sw_Z
)
3789 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3793 ADDR_ASSERT(allowedSwSet
.sw_S
);
3794 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3799 if (pIn
->flags
.rotated
&& allowedSwSet
.sw_R
)
3801 allowedSwModeSet
.value
&= Gfx9RotateSwModeMask
;
3803 else if (allowedSwSet
.sw_D
)
3805 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3807 else if (allowedSwSet
.sw_S
)
3809 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3813 ADDR_ASSERT(allowedSwSet
.sw_Z
);
3814 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3819 // Swizzle type should be determined.
3820 ADDR_ASSERT(IsPow2(GetAllowedSwSet(allowedSwModeSet
).value
));
3822 // Determine swizzle mode now. Always select the "largest" swizzle mode for a given block type + swizzle
3823 // type combination. For example, for AddrBlockThin64KB + ADDR_SW_S, select SW_64KB_S_X(25) if it's
3824 // available, or otherwise select SW_64KB_S_T(17) if it's available, or otherwise select SW_64KB_S(9).
3825 pOut
->swizzleMode
= static_cast<AddrSwizzleMode
>(Log2NonPow2(allowedSwModeSet
.value
));
3828 returnCode
= ADDR_OK
;
3832 // Invalid combination...
3833 ADDR_ASSERT_ALWAYS();
3838 // Invalid combination...
3839 ADDR_ASSERT_ALWAYS();
3846 ************************************************************************************************************************
3847 * Gfx9Lib::ComputeStereoInfo
3850 * Compute height alignment and right eye pipeBankXor for stereo surface
3855 ************************************************************************************************************************
3857 ADDR_E_RETURNCODE
Gfx9Lib::ComputeStereoInfo(
3858 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
3859 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
,
3860 UINT_32
* pHeightAlign
3863 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3865 UINT_32 eqIndex
= HwlGetEquationIndex(pIn
, pOut
);
3867 if (eqIndex
< m_numEquations
)
3869 if (IsXor(pIn
->swizzleMode
))
3871 const UINT_32 blkSizeLog2
= GetBlockSizeLog2(pIn
->swizzleMode
);
3872 const UINT_32 numPipeBits
= GetPipeXorBits(blkSizeLog2
);
3873 const UINT_32 numBankBits
= GetBankXorBits(blkSizeLog2
);
3874 const UINT_32 bppLog2
= Log2(pIn
->bpp
>> 3);
3875 const UINT_32 maxYCoordBlock256
= Log2(Block256_2d
[bppLog2
].h
) - 1;
3876 const ADDR_EQUATION
*pEqToCheck
= &m_equationTable
[eqIndex
];
3878 ADDR_ASSERT(maxYCoordBlock256
==
3879 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], Log2Size256
, 1));
3881 const UINT_32 maxYCoordInBaseEquation
=
3882 (blkSizeLog2
- Log2Size256
) / 2 + maxYCoordBlock256
;
3884 ADDR_ASSERT(maxYCoordInBaseEquation
==
3885 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], blkSizeLog2
, 1));
3887 const UINT_32 maxYCoordInPipeXor
= (numPipeBits
== 0) ? 0 : maxYCoordBlock256
+ numPipeBits
;
3889 ADDR_ASSERT(maxYCoordInPipeXor
==
3890 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
], numPipeBits
, 1));
3892 const UINT_32 maxYCoordInBankXor
= (numBankBits
== 0) ?
3893 0 : maxYCoordBlock256
+ (numPipeBits
+ 1) / 2 + numBankBits
;
3895 ADDR_ASSERT(maxYCoordInBankXor
==
3896 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
+ numPipeBits
], numBankBits
, 1));
3898 const UINT_32 maxYCoordInPipeBankXor
= Max(maxYCoordInPipeXor
, maxYCoordInBankXor
);
3900 if (maxYCoordInPipeBankXor
> maxYCoordInBaseEquation
)
3902 *pHeightAlign
= 1u << maxYCoordInPipeBankXor
;
3904 if (pOut
->pStereoInfo
!= NULL
)
3906 pOut
->pStereoInfo
->rightSwizzle
= 0;
3908 if ((PowTwoAlign(pIn
->height
, *pHeightAlign
) % (*pHeightAlign
* 2)) != 0)
3910 if (maxYCoordInPipeXor
== maxYCoordInPipeBankXor
)
3912 pOut
->pStereoInfo
->rightSwizzle
|= (1u << 1);
3915 if (maxYCoordInBankXor
== maxYCoordInPipeBankXor
)
3917 pOut
->pStereoInfo
->rightSwizzle
|=
3918 1u << ((numPipeBits
% 2) ? numPipeBits
: numPipeBits
+ 1);
3921 ADDR_ASSERT(pOut
->pStereoInfo
->rightSwizzle
==
3922 GetCoordActiveMask(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
],
3923 numPipeBits
+ numBankBits
, 1, maxYCoordInPipeBankXor
));
3931 ADDR_ASSERT_ALWAYS();
3932 returnCode
= ADDR_ERROR
;
3939 ************************************************************************************************************************
3940 * Gfx9Lib::HwlComputeSurfaceInfoTiled
3943 * Internal function to calculate alignment for tiled surface
3947 ************************************************************************************************************************
3949 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoTiled(
3950 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
3951 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
3954 ADDR_E_RETURNCODE returnCode
= ComputeBlockDimensionForSurf(&pOut
->blockWidth
,
3962 if (returnCode
== ADDR_OK
)
3964 UINT_32 pitchAlignInElement
= pOut
->blockWidth
;
3966 if ((IsTex2d(pIn
->resourceType
) == TRUE
) &&
3967 (pIn
->flags
.display
|| pIn
->flags
.rotated
) &&
3968 (pIn
->numMipLevels
<= 1) &&
3969 (pIn
->numSamples
<= 1) &&
3970 (pIn
->numFrags
<= 1))
3972 // Display engine needs pitch align to be at least 32 pixels.
3973 pitchAlignInElement
= PowTwoAlign(pitchAlignInElement
, 32);
3976 pOut
->pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
3978 if ((pIn
->numMipLevels
<= 1) && (pIn
->pitchInElement
> 0))
3980 if ((pIn
->pitchInElement
% pitchAlignInElement
) != 0)
3982 returnCode
= ADDR_INVALIDPARAMS
;
3984 else if (pIn
->pitchInElement
< pOut
->pitch
)
3986 returnCode
= ADDR_INVALIDPARAMS
;
3990 pOut
->pitch
= pIn
->pitchInElement
;
3994 UINT_32 heightAlign
= 0;
3996 if (pIn
->flags
.qbStereo
)
3998 returnCode
= ComputeStereoInfo(pIn
, pOut
, &heightAlign
);
4001 if (returnCode
== ADDR_OK
)
4003 pOut
->height
= PowTwoAlign(pIn
->height
, pOut
->blockHeight
);
4005 if (heightAlign
> 1)
4007 pOut
->height
= PowTwoAlign(pOut
->height
, heightAlign
);
4010 pOut
->numSlices
= PowTwoAlign(pIn
->numSlices
, pOut
->blockSlices
);
4012 pOut
->epitchIsHeight
= FALSE
;
4013 pOut
->mipChainInTail
= FALSE
;
4014 pOut
->firstMipIdInTail
= pIn
->numMipLevels
;
4016 pOut
->mipChainPitch
= pOut
->pitch
;
4017 pOut
->mipChainHeight
= pOut
->height
;
4018 pOut
->mipChainSlice
= pOut
->numSlices
;
4020 if (pIn
->numMipLevels
> 1)
4022 pOut
->firstMipIdInTail
= GetMipChainInfo(pIn
->resourceType
,
4034 const UINT_32 endingMipId
= Min(pOut
->firstMipIdInTail
, pIn
->numMipLevels
- 1);
4036 if (endingMipId
== 0)
4038 const Dim3d tailMaxDim
= GetMipTailDim(pIn
->resourceType
,
4044 pOut
->epitchIsHeight
= TRUE
;
4045 pOut
->pitch
= tailMaxDim
.w
;
4046 pOut
->height
= tailMaxDim
.h
;
4047 pOut
->numSlices
= IsThick(pIn
->resourceType
, pIn
->swizzleMode
) ?
4048 tailMaxDim
.d
: pIn
->numSlices
;
4049 pOut
->mipChainInTail
= TRUE
;
4053 UINT_32 mip0WidthInBlk
= pOut
->pitch
/ pOut
->blockWidth
;
4054 UINT_32 mip0HeightInBlk
= pOut
->height
/ pOut
->blockHeight
;
4056 AddrMajorMode majorMode
= GetMajorMode(pIn
->resourceType
,
4060 pOut
->numSlices
/ pOut
->blockSlices
);
4061 if (majorMode
== ADDR_MAJOR_Y
)
4063 UINT_32 mip1WidthInBlk
= RoundHalf(mip0WidthInBlk
);
4065 if ((mip1WidthInBlk
== 1) && (endingMipId
> 2))
4070 pOut
->mipChainPitch
+= (mip1WidthInBlk
* pOut
->blockWidth
);
4072 pOut
->epitchIsHeight
= FALSE
;
4076 UINT_32 mip1HeightInBlk
= RoundHalf(mip0HeightInBlk
);
4078 if ((mip1HeightInBlk
== 1) && (endingMipId
> 2))
4083 pOut
->mipChainHeight
+= (mip1HeightInBlk
* pOut
->blockHeight
);
4085 pOut
->epitchIsHeight
= TRUE
;
4089 if (pOut
->pMipInfo
!= NULL
)
4091 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
4093 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4095 Dim3d mipStartPos
= {0};
4096 UINT_32 mipTailOffsetInBytes
= 0;
4098 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
4108 &mipTailOffsetInBytes
);
4110 UINT_32 pitchInBlock
=
4111 pOut
->mipChainPitch
/ pOut
->blockWidth
;
4112 UINT_32 sliceInBlock
=
4113 (pOut
->mipChainHeight
/ pOut
->blockHeight
) * pitchInBlock
;
4114 UINT_64 blockIndex
=
4115 mipStartPos
.d
* sliceInBlock
+ mipStartPos
.h
* pitchInBlock
+ mipStartPos
.w
;
4116 UINT_64 macroBlockOffset
=
4117 blockIndex
<< GetBlockSizeLog2(pIn
->swizzleMode
);
4119 pOut
->pMipInfo
[i
].macroBlockOffset
= macroBlockOffset
;
4120 pOut
->pMipInfo
[i
].mipTailOffset
= mipTailOffsetInBytes
;
4124 else if (pOut
->pMipInfo
!= NULL
)
4126 pOut
->pMipInfo
[0].pitch
= pOut
->pitch
;
4127 pOut
->pMipInfo
[0].height
= pOut
->height
;
4128 pOut
->pMipInfo
[0].depth
= IsTex3d(pIn
->resourceType
)? pOut
->numSlices
: 1;
4129 pOut
->pMipInfo
[0].offset
= 0;
4132 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->mipChainPitch
) * pOut
->mipChainHeight
*
4133 (pIn
->bpp
>> 3) * pIn
->numFrags
;
4134 pOut
->surfSize
= pOut
->sliceSize
* pOut
->mipChainSlice
;
4135 pOut
->baseAlign
= ComputeSurfaceBaseAlignTiled(pIn
->swizzleMode
);
4137 if ((IsBlock256b(pIn
->swizzleMode
) == FALSE
) &&
4138 (pIn
->flags
.color
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
|| pIn
->flags
.fmask
) &&
4139 (pIn
->flags
.texture
== TRUE
) &&
4140 (pIn
->flags
.noMetadata
== FALSE
) &&
4141 (pIn
->flags
.metaPipeUnaligned
== FALSE
))
4143 // Assume client requires pipe aligned metadata, which is TcCompatible and will be accessed by TC...
4144 // Then we need extra padding for base surface. Otherwise, metadata and data surface for same pixel will
4145 // be flushed to different pipes, but texture engine only uses pipe id of data surface to fetch both of
4146 // them, which may cause invalid metadata to be fetched.
4147 pOut
->baseAlign
= Max(pOut
->baseAlign
, m_pipeInterleaveBytes
* m_pipes
* m_se
);
4152 pOut
->baseAlign
= Max(pOut
->baseAlign
, PrtAlignment
);
4161 ************************************************************************************************************************
4162 * Gfx9Lib::HwlComputeSurfaceInfoLinear
4165 * Internal function to calculate alignment for linear surface
4169 ************************************************************************************************************************
4171 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoLinear(
4172 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
4173 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
4176 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
4178 UINT_32 actualHeight
= 0;
4179 UINT_32 elementBytes
= pIn
->bpp
>> 3;
4180 const UINT_32 alignment
= pIn
->flags
.prt
? PrtAlignment
: 256;
4182 if (IsTex1d(pIn
->resourceType
))
4184 if (pIn
->height
> 1)
4186 returnCode
= ADDR_INVALIDPARAMS
;
4190 const UINT_32 pitchAlignInElement
= alignment
/ elementBytes
;
4192 pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
4193 actualHeight
= pIn
->numMipLevels
;
4195 if (pIn
->flags
.prt
== FALSE
)
4197 returnCode
= ApplyCustomizedPitchHeight(pIn
, elementBytes
, pitchAlignInElement
,
4198 &pitch
, &actualHeight
);
4201 if (returnCode
== ADDR_OK
)
4203 if (pOut
->pMipInfo
!= NULL
)
4205 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4207 pOut
->pMipInfo
[i
].offset
= pitch
* elementBytes
* i
;
4208 pOut
->pMipInfo
[i
].pitch
= pitch
;
4209 pOut
->pMipInfo
[i
].height
= 1;
4210 pOut
->pMipInfo
[i
].depth
= 1;
4218 returnCode
= ComputeSurfaceLinearPadding(pIn
, &pitch
, &actualHeight
, pOut
->pMipInfo
);
4221 if ((pitch
== 0) || (actualHeight
== 0))
4223 returnCode
= ADDR_INVALIDPARAMS
;
4226 if (returnCode
== ADDR_OK
)
4228 pOut
->pitch
= pitch
;
4229 pOut
->height
= pIn
->height
;
4230 pOut
->numSlices
= pIn
->numSlices
;
4231 pOut
->mipChainPitch
= pitch
;
4232 pOut
->mipChainHeight
= actualHeight
;
4233 pOut
->mipChainSlice
= pOut
->numSlices
;
4234 pOut
->epitchIsHeight
= (pIn
->numMipLevels
> 1) ? TRUE
: FALSE
;
4235 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->pitch
) * actualHeight
* elementBytes
;
4236 pOut
->surfSize
= pOut
->sliceSize
* pOut
->numSlices
;
4237 pOut
->baseAlign
= (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
) ? (pIn
->bpp
/ 8) : alignment
;
4238 pOut
->blockWidth
= (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
) ? 1 : (256 / elementBytes
);
4239 pOut
->blockHeight
= 1;
4240 pOut
->blockSlices
= 1;
4243 // Post calculation validate
4244 ADDR_ASSERT(pOut
->sliceSize
> 0);
4250 ************************************************************************************************************************
4251 * Gfx9Lib::GetMipChainInfo
4254 * Internal function to get out information about mip chain
4257 * Smaller value between Id of first mip fitted in mip tail and max Id of mip being created
4258 ************************************************************************************************************************
4260 UINT_32
Gfx9Lib::GetMipChainInfo(
4261 AddrResourceType resourceType
,
4262 AddrSwizzleMode swizzleMode
,
4268 UINT_32 blockHeight
,
4270 UINT_32 numMipLevel
,
4271 ADDR2_MIP_INFO
* pMipInfo
) const
4273 const Dim3d tailMaxDim
=
4274 GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4276 UINT_32 mipPitch
= mip0Width
;
4277 UINT_32 mipHeight
= mip0Height
;
4278 UINT_32 mipDepth
= IsTex3d(resourceType
) ? mip0Depth
: 1;
4280 UINT_32 firstMipIdInTail
= numMipLevel
;
4281 BOOL_32 inTail
= FALSE
;
4282 BOOL_32 finalDim
= FALSE
;
4283 BOOL_32 is3dThick
= IsThick(resourceType
, swizzleMode
);
4284 BOOL_32 is3dThin
= IsTex3d(resourceType
) && (is3dThick
== FALSE
);
4286 for (UINT_32 mipId
= 0; mipId
< numMipLevel
; mipId
++)
4290 if (finalDim
== FALSE
)
4296 mipSize
= mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3);
4300 mipSize
= mipPitch
* mipHeight
* (bpp
>> 3);
4305 UINT_32 index
= Log2(bpp
>> 3);
4309 mipPitch
= Block256_3dZ
[index
].w
;
4310 mipHeight
= Block256_3dZ
[index
].h
;
4311 mipDepth
= Block256_3dZ
[index
].d
;
4315 mipPitch
= Block256_2d
[index
].w
;
4316 mipHeight
= Block256_2d
[index
].h
;
4325 inTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
,
4326 mipPitch
, mipHeight
, mipDepth
);
4330 firstMipIdInTail
= mipId
;
4331 mipPitch
= tailMaxDim
.w
;
4332 mipHeight
= tailMaxDim
.h
;
4336 mipDepth
= tailMaxDim
.d
;
4341 mipPitch
= PowTwoAlign(mipPitch
, blockWidth
);
4342 mipHeight
= PowTwoAlign(mipHeight
, blockHeight
);
4346 mipDepth
= PowTwoAlign(mipDepth
, blockDepth
);
4351 if (pMipInfo
!= NULL
)
4353 pMipInfo
[mipId
].pitch
= mipPitch
;
4354 pMipInfo
[mipId
].height
= mipHeight
;
4355 pMipInfo
[mipId
].depth
= mipDepth
;
4356 pMipInfo
[mipId
].offset
= offset
;
4359 offset
+= (mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3));
4365 mipDepth
= Max(mipDepth
>> 1, 1u);
4370 mipPitch
= Max(mipPitch
>> 1, 1u);
4371 mipHeight
= Max(mipHeight
>> 1, 1u);
4373 if (is3dThick
|| is3dThin
)
4375 mipDepth
= Max(mipDepth
>> 1, 1u);
4380 return firstMipIdInTail
;
4384 ************************************************************************************************************************
4385 * Gfx9Lib::GetMetaMiptailInfo
4388 * Get mip tail coordinate information.
4392 ************************************************************************************************************************
4394 VOID
Gfx9Lib::GetMetaMiptailInfo(
4395 ADDR2_META_MIP_INFO
* pInfo
, ///< [out] output structure to store per mip coord
4396 Dim3d mipCoord
, ///< [in] mip tail base coord
4397 UINT_32 numMipInTail
, ///< [in] number of mips in tail
4398 Dim3d
* pMetaBlkDim
///< [in] meta block width/height/depth
4401 BOOL_32 isThick
= (pMetaBlkDim
->d
> 1);
4402 UINT_32 mipWidth
= pMetaBlkDim
->w
;
4403 UINT_32 mipHeight
= pMetaBlkDim
->h
>> 1;
4404 UINT_32 mipDepth
= pMetaBlkDim
->d
;
4409 minInc
= (pMetaBlkDim
->h
>= 512) ? 128 : ((pMetaBlkDim
->h
== 256) ? 64 : 32);
4411 else if (pMetaBlkDim
->h
>= 1024)
4415 else if (pMetaBlkDim
->h
== 512)
4424 UINT_32 blk32MipId
= 0xFFFFFFFF;
4426 for (UINT_32 mip
= 0; mip
< numMipInTail
; mip
++)
4428 pInfo
[mip
].inMiptail
= TRUE
;
4429 pInfo
[mip
].startX
= mipCoord
.w
;
4430 pInfo
[mip
].startY
= mipCoord
.h
;
4431 pInfo
[mip
].startZ
= mipCoord
.d
;
4432 pInfo
[mip
].width
= mipWidth
;
4433 pInfo
[mip
].height
= mipHeight
;
4434 pInfo
[mip
].depth
= mipDepth
;
4438 if (blk32MipId
== 0xFFFFFFFF)
4443 mipCoord
.w
= pInfo
[blk32MipId
].startX
;
4444 mipCoord
.h
= pInfo
[blk32MipId
].startY
;
4445 mipCoord
.d
= pInfo
[blk32MipId
].startZ
;
4447 switch (mip
- blk32MipId
)
4450 mipCoord
.w
+= 32; // 16x16
4453 mipCoord
.h
+= 32; // 8x8
4456 mipCoord
.h
+= 32; // 4x4
4460 mipCoord
.h
+= 32; // 2x2
4464 mipCoord
.h
+= 32; // 1x1
4467 // The following are for BC/ASTC formats
4469 mipCoord
.h
+= 48; // 1/2 x 1/2
4472 mipCoord
.h
+= 48; // 1/4 x 1/4
4476 mipCoord
.h
+= 48; // 1/8 x 1/8
4480 mipCoord
.h
+= 48; // 1/16 x 1/16
4484 ADDR_ASSERT_ALWAYS();
4488 mipWidth
= ((mip
- blk32MipId
) == 0) ? 16 : 8;
4489 mipHeight
= mipWidth
;
4493 mipDepth
= mipWidth
;
4498 if (mipWidth
<= minInc
)
4500 // if we're below the minimal increment...
4503 // For 3d, just go in z direction
4504 mipCoord
.d
+= mipDepth
;
4508 // For 2d, first go across, then down
4509 if ((mipWidth
* 2) == minInc
)
4511 // if we're 2 mips below, that's when we go back in x, and down in y
4512 mipCoord
.w
-= minInc
;
4513 mipCoord
.h
+= minInc
;
4517 // otherwise, just go across in x
4518 mipCoord
.w
+= minInc
;
4524 // On even mip, go down, otherwise, go across
4527 mipCoord
.w
+= mipWidth
;
4531 mipCoord
.h
+= mipHeight
;
4534 // Divide the width by 2
4536 // After the first mip in tail, the mip is always a square
4537 mipHeight
= mipWidth
;
4538 // ...or for 3d, a cube
4541 mipDepth
= mipWidth
;
4548 ************************************************************************************************************************
4549 * Gfx9Lib::GetMipStartPos
4552 * Internal function to get out information about mip logical start position
4555 * logical start position in macro block width/heith/depth of one mip level within one slice
4556 ************************************************************************************************************************
4558 Dim3d
Gfx9Lib::GetMipStartPos(
4559 AddrResourceType resourceType
,
4560 AddrSwizzleMode swizzleMode
,
4565 UINT_32 blockHeight
,
4568 UINT_32 log2ElementBytes
,
4569 UINT_32
* pMipTailBytesOffset
) const
4571 Dim3d mipStartPos
= {0};
4572 const Dim3d tailMaxDim
= GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4574 // Report mip in tail if Mip0 is already in mip tail
4575 BOOL_32 inMipTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
, width
, height
, depth
);
4576 UINT_32 log2BlkSize
= GetBlockSizeLog2(swizzleMode
);
4577 UINT_32 mipIndexInTail
= mipId
;
4579 if (inMipTail
== FALSE
)
4581 // Mip 0 dimension, unit in block
4582 UINT_32 mipWidthInBlk
= width
/ blockWidth
;
4583 UINT_32 mipHeightInBlk
= height
/ blockHeight
;
4584 UINT_32 mipDepthInBlk
= depth
/ blockDepth
;
4585 AddrMajorMode majorMode
= GetMajorMode(resourceType
,
4591 UINT_32 endingMip
= mipId
+ 1;
4593 for (UINT_32 i
= 1; i
<= mipId
; i
++)
4595 if ((i
== 1) || (i
== 3))
4597 if (majorMode
== ADDR_MAJOR_Y
)
4599 mipStartPos
.w
+= mipWidthInBlk
;
4603 mipStartPos
.h
+= mipHeightInBlk
;
4608 if (majorMode
== ADDR_MAJOR_X
)
4610 mipStartPos
.w
+= mipWidthInBlk
;
4612 else if (majorMode
== ADDR_MAJOR_Y
)
4614 mipStartPos
.h
+= mipHeightInBlk
;
4618 mipStartPos
.d
+= mipDepthInBlk
;
4622 BOOL_32 inTail
= FALSE
;
4624 if (IsThick(resourceType
, swizzleMode
))
4626 UINT_32 dim
= log2BlkSize
% 3;
4631 (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1) && (mipDepthInBlk
<= 2);
4636 (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
<= 2);
4641 (mipWidthInBlk
<= 2) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
== 1);
4646 if (log2BlkSize
& 1)
4648 inTail
= (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1);
4652 inTail
= (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2);
4662 mipWidthInBlk
= RoundHalf(mipWidthInBlk
);
4663 mipHeightInBlk
= RoundHalf(mipHeightInBlk
);
4664 mipDepthInBlk
= RoundHalf(mipDepthInBlk
);
4667 if (mipId
>= endingMip
)
4670 mipIndexInTail
= mipId
- endingMip
;
4676 UINT_32 index
= mipIndexInTail
+ MaxMacroBits
- log2BlkSize
;
4677 ADDR_ASSERT(index
< sizeof(MipTailOffset256B
) / sizeof(UINT_32
));
4678 *pMipTailBytesOffset
= MipTailOffset256B
[index
] << 8;
4685 ************************************************************************************************************************
4686 * Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled
4689 * Internal function to calculate address from coord for tiled swizzle surface
4693 ************************************************************************************************************************
4695 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled(
4696 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
4697 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
4700 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
4701 localIn
.swizzleMode
= pIn
->swizzleMode
;
4702 localIn
.flags
= pIn
->flags
;
4703 localIn
.resourceType
= pIn
->resourceType
;
4704 localIn
.bpp
= pIn
->bpp
;
4705 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
4706 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
4707 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
4708 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
4709 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
4710 localIn
.numFrags
= Max(pIn
->numFrags
, 1u);
4711 if (localIn
.numMipLevels
<= 1)
4713 localIn
.pitchInElement
= pIn
->pitchInElement
;
4716 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
4717 ADDR_E_RETURNCODE returnCode
= ComputeSurfaceInfoTiled(&localIn
, &localOut
);
4719 BOOL_32 valid
= (returnCode
== ADDR_OK
) &&
4720 (IsThin(pIn
->resourceType
, pIn
->swizzleMode
) ||
4721 IsThick(pIn
->resourceType
, pIn
->swizzleMode
)) &&
4722 ((pIn
->pipeBankXor
== 0) || (IsXor(pIn
->swizzleMode
)));
4726 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
4727 Dim3d mipStartPos
= {0};
4728 UINT_32 mipTailBytesOffset
= 0;
4730 if (pIn
->numMipLevels
> 1)
4732 // Mip-map chain cannot be MSAA surface
4733 ADDR_ASSERT((pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1));
4735 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
4740 localOut
.blockWidth
,
4741 localOut
.blockHeight
,
4742 localOut
.blockSlices
,
4745 &mipTailBytesOffset
);
4748 UINT_32 interleaveOffset
= 0;
4749 UINT_32 pipeBits
= 0;
4750 UINT_32 pipeXor
= 0;
4751 UINT_32 bankBits
= 0;
4752 UINT_32 bankXor
= 0;
4754 if (IsThin(pIn
->resourceType
, pIn
->swizzleMode
))
4756 UINT_32 blockOffset
= 0;
4757 UINT_32 log2BlkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4759 if (IsZOrderSwizzle(pIn
->swizzleMode
))
4761 // Morton generation
4762 if ((log2ElementBytes
== 0) || (log2ElementBytes
== 2))
4764 UINT_32 totalLowBits
= 6 - log2ElementBytes
;
4765 UINT_32 mortBits
= totalLowBits
/ 2;
4766 UINT_32 lowBitsValue
= MortonGen2d(pIn
->y
, pIn
->x
, mortBits
);
4767 // Are 9 bits enough?
4768 UINT_32 highBitsValue
=
4769 MortonGen2d(pIn
->x
>> mortBits
, pIn
->y
>> mortBits
, 9) << totalLowBits
;
4770 blockOffset
= lowBitsValue
| highBitsValue
;
4771 ADDR_ASSERT(blockOffset
== lowBitsValue
+ highBitsValue
);
4775 blockOffset
= MortonGen2d(pIn
->y
, pIn
->x
, 13);
4778 // Fill LSBs with sample bits
4779 if (pIn
->numSamples
> 1)
4781 blockOffset
*= pIn
->numSamples
;
4782 blockOffset
|= pIn
->sample
;
4785 // Shift according to BytesPP
4786 blockOffset
<<= log2ElementBytes
;
4790 // Micro block offset
4791 UINT_32 microBlockOffset
= ComputeSurface2DMicroBlockOffset(pIn
);
4792 blockOffset
= microBlockOffset
;
4794 // Micro block dimension
4795 ADDR_ASSERT(log2ElementBytes
< MaxNumOfBpp
);
4796 Dim2d microBlockDim
= Block256_2d
[log2ElementBytes
];
4797 // Morton generation, does 12 bit enough?
4799 MortonGen2d((pIn
->x
/ microBlockDim
.w
), (pIn
->y
/ microBlockDim
.h
), 12) << 8;
4801 // Sample bits start location
4802 UINT_32 sampleStart
= log2BlkSize
- Log2(pIn
->numSamples
);
4803 // Join sample bits information to the highest Macro block bits
4804 if (IsNonPrtXor(pIn
->swizzleMode
))
4806 // Non-prt-Xor : xor highest Macro block bits with sample bits
4807 blockOffset
= blockOffset
^ (pIn
->sample
<< sampleStart
);
4811 // Non-Xor or prt-Xor: replace highest Macro block bits with sample bits
4812 // after this op, the blockOffset only contains log2 Macro block size bits
4813 blockOffset
%= (1 << sampleStart
);
4814 blockOffset
|= (pIn
->sample
<< sampleStart
);
4815 ADDR_ASSERT((blockOffset
>> log2BlkSize
) == 0);
4819 if (IsXor(pIn
->swizzleMode
))
4821 // Mask off bits above Macro block bits to keep page synonyms working for prt
4822 if (IsPrt(pIn
->swizzleMode
))
4824 blockOffset
&= ((1 << log2BlkSize
) - 1);
4827 // Preserve offset inside pipe interleave
4828 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4829 blockOffset
>>= m_pipeInterleaveLog2
;
4832 pipeBits
= GetPipeXorBits(log2BlkSize
);
4834 pipeXor
= FoldXor2d(blockOffset
, pipeBits
);
4835 blockOffset
>>= pipeBits
;
4838 bankBits
= GetBankXorBits(log2BlkSize
);
4840 bankXor
= FoldXor2d(blockOffset
, bankBits
);
4841 blockOffset
>>= bankBits
;
4843 // Put all the part back together
4844 blockOffset
<<= bankBits
;
4845 blockOffset
|= bankXor
;
4846 blockOffset
<<= pipeBits
;
4847 blockOffset
|= pipeXor
;
4848 blockOffset
<<= m_pipeInterleaveLog2
;
4849 blockOffset
|= interleaveOffset
;
4852 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4853 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2BlkSize
)));
4855 blockOffset
|= mipTailBytesOffset
;
4857 if (IsNonPrtXor(pIn
->swizzleMode
) && (pIn
->numSamples
<= 1))
4859 // Apply slice xor if not MSAA/PRT
4860 blockOffset
^= (ReverseBitVector(pIn
->slice
, pipeBits
) << m_pipeInterleaveLog2
);
4861 blockOffset
^= (ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
) <<
4862 (m_pipeInterleaveLog2
+ pipeBits
));
4865 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4866 bankBits
, pipeBits
, &blockOffset
);
4868 blockOffset
%= (1 << log2BlkSize
);
4870 UINT_32 pitchInMacroBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4871 UINT_32 paddedHeightInMacroBlock
= localOut
.mipChainHeight
/ localOut
.blockHeight
;
4872 UINT_32 sliceSizeInMacroBlock
= pitchInMacroBlock
* paddedHeightInMacroBlock
;
4873 UINT_64 macroBlockIndex
=
4874 (pIn
->slice
+ mipStartPos
.d
) * sliceSizeInMacroBlock
+
4875 ((pIn
->y
/ localOut
.blockHeight
) + mipStartPos
.h
) * pitchInMacroBlock
+
4876 ((pIn
->x
/ localOut
.blockWidth
) + mipStartPos
.w
);
4878 pOut
->addr
= blockOffset
| (macroBlockIndex
<< log2BlkSize
);
4882 UINT_32 log2BlkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4884 Dim3d microBlockDim
= Block1K_3d
[log2ElementBytes
];
4886 UINT_32 blockOffset
= MortonGen3d((pIn
->x
/ microBlockDim
.w
),
4887 (pIn
->y
/ microBlockDim
.h
),
4888 (pIn
->slice
/ microBlockDim
.d
),
4892 blockOffset
|= ComputeSurface3DMicroBlockOffset(pIn
);
4894 if (IsXor(pIn
->swizzleMode
))
4896 // Mask off bits above Macro block bits to keep page synonyms working for prt
4897 if (IsPrt(pIn
->swizzleMode
))
4899 blockOffset
&= ((1 << log2BlkSize
) - 1);
4902 // Preserve offset inside pipe interleave
4903 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4904 blockOffset
>>= m_pipeInterleaveLog2
;
4907 pipeBits
= GetPipeXorBits(log2BlkSize
);
4909 pipeXor
= FoldXor3d(blockOffset
, pipeBits
);
4910 blockOffset
>>= pipeBits
;
4913 bankBits
= GetBankXorBits(log2BlkSize
);
4915 bankXor
= FoldXor3d(blockOffset
, bankBits
);
4916 blockOffset
>>= bankBits
;
4918 // Put all the part back together
4919 blockOffset
<<= bankBits
;
4920 blockOffset
|= bankXor
;
4921 blockOffset
<<= pipeBits
;
4922 blockOffset
|= pipeXor
;
4923 blockOffset
<<= m_pipeInterleaveLog2
;
4924 blockOffset
|= interleaveOffset
;
4927 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4928 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2BlkSize
)));
4929 blockOffset
|= mipTailBytesOffset
;
4931 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4932 bankBits
, pipeBits
, &blockOffset
);
4934 blockOffset
%= (1 << log2BlkSize
);
4936 UINT_32 xb
= pIn
->x
/ localOut
.blockWidth
+ mipStartPos
.w
;
4937 UINT_32 yb
= pIn
->y
/ localOut
.blockHeight
+ mipStartPos
.h
;
4938 UINT_32 zb
= pIn
->slice
/ localOut
.blockSlices
+ + mipStartPos
.d
;
4940 UINT_32 pitchInBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4941 UINT_32 sliceSizeInBlock
=
4942 (localOut
.mipChainHeight
/ localOut
.blockHeight
) * pitchInBlock
;
4943 UINT_64 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
4945 pOut
->addr
= blockOffset
| (blockIndex
<< log2BlkSize
);
4950 returnCode
= ADDR_INVALIDPARAMS
;
4957 ************************************************************************************************************************
4958 * Gfx9Lib::ComputeSurfaceInfoLinear
4961 * Internal function to calculate padding for linear swizzle 2D/3D surface
4965 ************************************************************************************************************************
4967 ADDR_E_RETURNCODE
Gfx9Lib::ComputeSurfaceLinearPadding(
4968 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input srtucture
4969 UINT_32
* pMipmap0PaddedWidth
, ///< [out] padded width in element
4970 UINT_32
* pSlice0PaddedHeight
, ///< [out] padded height for HW
4971 ADDR2_MIP_INFO
* pMipInfo
///< [out] per mip information
4974 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
4976 UINT_32 elementBytes
= pIn
->bpp
>> 3;
4977 UINT_32 pitchAlignInElement
= 0;
4979 if (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
)
4981 ADDR_ASSERT(pIn
->numMipLevels
<= 1);
4982 ADDR_ASSERT(pIn
->numSlices
<= 1);
4983 pitchAlignInElement
= 1;
4987 pitchAlignInElement
= (256 / elementBytes
);
4990 UINT_32 mipChainWidth
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
4991 UINT_32 slice0PaddedHeight
= pIn
->height
;
4993 returnCode
= ApplyCustomizedPitchHeight(pIn
, elementBytes
, pitchAlignInElement
,
4994 &mipChainWidth
, &slice0PaddedHeight
);
4996 if (returnCode
== ADDR_OK
)
4998 UINT_32 mipChainHeight
= 0;
4999 UINT_32 mipHeight
= pIn
->height
;
5000 UINT_32 mipDepth
= (pIn
->resourceType
== ADDR_RSRC_TEX_3D
) ? pIn
->numSlices
: 1;
5002 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
5004 if (pMipInfo
!= NULL
)
5006 pMipInfo
[i
].offset
= mipChainWidth
* mipChainHeight
* elementBytes
;
5007 pMipInfo
[i
].pitch
= mipChainWidth
;
5008 pMipInfo
[i
].height
= mipHeight
;
5009 pMipInfo
[i
].depth
= mipDepth
;
5012 mipChainHeight
+= mipHeight
;
5013 mipHeight
= RoundHalf(mipHeight
);
5014 mipHeight
= Max(mipHeight
, 1u);
5017 *pMipmap0PaddedWidth
= mipChainWidth
;
5018 *pSlice0PaddedHeight
= (pIn
->numMipLevels
> 1) ? mipChainHeight
: slice0PaddedHeight
;
5025 ************************************************************************************************************************
5026 * Gfx9Lib::ComputeThinBlockDimension
5029 * Internal function to get thin block width/height/depth in element from surface input params.
5033 ************************************************************************************************************************
5035 VOID
Gfx9Lib::ComputeThinBlockDimension(
5041 AddrResourceType resourceType
,
5042 AddrSwizzleMode swizzleMode
) const
5044 ADDR_ASSERT(IsThin(resourceType
, swizzleMode
));
5046 const UINT_32 log2BlkSize
= GetBlockSizeLog2(swizzleMode
);
5047 const UINT_32 eleBytes
= bpp
>> 3;
5048 const UINT_32 microBlockSizeTableIndex
= Log2(eleBytes
);
5049 const UINT_32 log2blkSizeIn256B
= log2BlkSize
- 8;
5050 const UINT_32 widthAmp
= log2blkSizeIn256B
/ 2;
5051 const UINT_32 heightAmp
= log2blkSizeIn256B
- widthAmp
;
5053 ADDR_ASSERT(microBlockSizeTableIndex
< sizeof(Block256_2d
) / sizeof(Block256_2d
[0]));
5055 *pWidth
= (Block256_2d
[microBlockSizeTableIndex
].w
<< widthAmp
);
5056 *pHeight
= (Block256_2d
[microBlockSizeTableIndex
].h
<< heightAmp
);
5061 const UINT_32 log2sample
= Log2(numSamples
);
5062 const UINT_32 q
= log2sample
>> 1;
5063 const UINT_32 r
= log2sample
& 1;
5065 if (log2BlkSize
& 1)
5068 *pHeight
>>= (q
+ r
);
5072 *pWidth
>>= (q
+ r
);