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
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
770 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
771 input
.numSlices
= Max(pIn
->numSlices
, 1u);
772 input
.swizzleMode
= pIn
->swizzleMode
;
773 input
.resourceType
= pIn
->resourceType
;
775 ADDR2_COMPUTE_CMASK_INFO_OUTPUT output
= {0};
776 output
.size
= sizeof(output
);
778 ADDR_E_RETURNCODE returnCode
= ComputeCmaskInfo(&input
, &output
);
780 if (returnCode
== ADDR_OK
)
782 UINT_32 fmaskBpp
= GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
);
783 UINT_32 fmaskElementBytesLog2
= Log2(fmaskBpp
>> 3);
784 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
785 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
787 MetaEqParams metaEqParams
= {0, fmaskElementBytesLog2
, 0, pIn
->cMaskFlags
,
788 Gfx9DataFmask
, pIn
->swizzleMode
, pIn
->resourceType
,
789 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
791 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
793 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
794 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
795 UINT_32 zb
= pIn
->slice
;
797 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
798 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
799 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
801 UINT_32 coords
[] = { pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
};
802 UINT_64 address
= pMetaEq
->solve(coords
);
804 pOut
->addr
= address
>> 1;
805 pOut
->bitPosition
= static_cast<UINT_32
>((address
& 1) << 2);
807 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->cMaskFlags
.pipeAligned
,
810 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
812 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
819 ************************************************************************************************************************
820 * Gfx9Lib::HwlComputeHtileAddrFromCoord
823 * Interface function stub of AddrComputeHtileAddrFromCoord
827 ************************************************************************************************************************
829 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileAddrFromCoord(
830 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
831 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
833 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
835 if (pIn
->numMipLevels
> 1)
837 returnCode
= ADDR_NOTIMPLEMENTED
;
841 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
842 input
.size
= sizeof(input
);
843 input
.hTileFlags
= pIn
->hTileFlags
;
844 input
.depthFlags
= pIn
->depthflags
;
845 input
.swizzleMode
= pIn
->swizzleMode
;
846 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
847 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
848 input
.numSlices
= Max(pIn
->numSlices
, 1u);
849 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
851 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
852 output
.size
= sizeof(output
);
854 returnCode
= ComputeHtileInfo(&input
, &output
);
856 if (returnCode
== ADDR_OK
)
858 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
859 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
860 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
861 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
863 MetaEqParams metaEqParams
= {0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
864 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
865 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
867 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
869 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
870 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
871 UINT_32 zb
= pIn
->slice
;
873 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
874 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
875 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
877 UINT_32 coords
[] = { pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
};
878 UINT_64 address
= pMetaEq
->solve(coords
);
880 pOut
->addr
= address
>> 1;
882 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
885 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
887 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
895 ************************************************************************************************************************
896 * Gfx9Lib::HwlComputeHtileCoordFromAddr
899 * Interface function stub of AddrComputeHtileCoordFromAddr
903 ************************************************************************************************************************
905 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileCoordFromAddr(
906 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
907 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
) ///< [out] output structure
909 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
911 if (pIn
->numMipLevels
> 1)
913 returnCode
= ADDR_NOTIMPLEMENTED
;
917 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
918 input
.size
= sizeof(input
);
919 input
.hTileFlags
= pIn
->hTileFlags
;
920 input
.swizzleMode
= pIn
->swizzleMode
;
921 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
922 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
923 input
.numSlices
= Max(pIn
->numSlices
, 1u);
924 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
926 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
927 output
.size
= sizeof(output
);
929 returnCode
= ComputeHtileInfo(&input
, &output
);
931 if (returnCode
== ADDR_OK
)
933 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
934 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
935 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
936 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
938 MetaEqParams metaEqParams
= {0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
939 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
940 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0};
942 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
944 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
947 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
949 UINT_64 nibbleAddress
= (pIn
->addr
^ (pipeXor
<< m_pipeInterleaveLog2
)) << 1;
951 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
952 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
954 UINT_32 coords
[NUM_DIMS
];
955 pMetaEq
->solveAddr(nibbleAddress
, sliceSizeInBlock
, coords
);
957 pOut
->slice
= coords
[DIM_M
] / sliceSizeInBlock
;
958 pOut
->y
= ((coords
[DIM_M
] % sliceSizeInBlock
) / pitchInBlock
) * output
.metaBlkHeight
+ coords
[DIM_Y
];
959 pOut
->x
= (coords
[DIM_M
] % pitchInBlock
) * output
.metaBlkWidth
+ coords
[DIM_X
];
967 ************************************************************************************************************************
968 * Gfx9Lib::HwlComputeDccAddrFromCoord
971 * Interface function stub of AddrComputeDccAddrFromCoord
975 ************************************************************************************************************************
977 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeDccAddrFromCoord(
978 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
,
979 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
)
981 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
983 if ((pIn
->numMipLevels
> 1) || (pIn
->mipId
> 1) || pIn
->dccKeyFlags
.linear
)
985 returnCode
= ADDR_NOTIMPLEMENTED
;
989 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
990 UINT_32 numSamplesLog2
= Log2(pIn
->numFrags
);
991 UINT_32 metaBlkWidthLog2
= Log2(pIn
->metaBlkWidth
);
992 UINT_32 metaBlkHeightLog2
= Log2(pIn
->metaBlkHeight
);
993 UINT_32 metaBlkDepthLog2
= Log2(pIn
->metaBlkDepth
);
994 UINT_32 compBlkWidthLog2
= Log2(pIn
->compressBlkWidth
);
995 UINT_32 compBlkHeightLog2
= Log2(pIn
->compressBlkHeight
);
996 UINT_32 compBlkDepthLog2
= Log2(pIn
->compressBlkDepth
);
998 MetaEqParams metaEqParams
= {pIn
->mipId
, elementBytesLog2
, numSamplesLog2
, pIn
->dccKeyFlags
,
999 Gfx9DataColor
, pIn
->swizzleMode
, pIn
->resourceType
,
1000 metaBlkWidthLog2
, metaBlkHeightLog2
, metaBlkDepthLog2
,
1001 compBlkWidthLog2
, compBlkHeightLog2
, compBlkDepthLog2
};
1003 const CoordEq
* pMetaEq
= GetMetaEquation(metaEqParams
);
1005 UINT_32 xb
= pIn
->x
/ pIn
->metaBlkWidth
;
1006 UINT_32 yb
= pIn
->y
/ pIn
->metaBlkHeight
;
1007 UINT_32 zb
= pIn
->slice
/ pIn
->metaBlkDepth
;
1009 UINT_32 pitchInBlock
= pIn
->pitch
/ pIn
->metaBlkWidth
;
1010 UINT_32 sliceSizeInBlock
= (pIn
->height
/ pIn
->metaBlkHeight
) * pitchInBlock
;
1011 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
1013 UINT_32 coords
[] = { pIn
->x
, pIn
->y
, pIn
->slice
, pIn
->sample
, blockIndex
};
1014 UINT_64 address
= pMetaEq
->solve(coords
);
1016 pOut
->addr
= address
>> 1;
1018 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->dccKeyFlags
.pipeAligned
,
1021 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
1023 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
1030 ************************************************************************************************************************
1031 * Gfx9Lib::HwlInitGlobalParams
1034 * Initializes global parameters
1037 * TRUE if all settings are valid
1039 ************************************************************************************************************************
1041 BOOL_32
Gfx9Lib::HwlInitGlobalParams(
1042 const ADDR_CREATE_INPUT
* pCreateIn
) ///< [in] create input
1044 BOOL_32 valid
= TRUE
;
1046 if (m_settings
.isArcticIsland
)
1048 GB_ADDR_CONFIG_gfx9 gbAddrConfig
;
1050 gbAddrConfig
.u32All
= pCreateIn
->regValue
.gbAddrConfig
;
1052 // These values are copied from CModel code
1053 switch (gbAddrConfig
.bits
.NUM_PIPES
)
1055 case ADDR_CONFIG_1_PIPE
:
1059 case ADDR_CONFIG_2_PIPE
:
1063 case ADDR_CONFIG_4_PIPE
:
1067 case ADDR_CONFIG_8_PIPE
:
1071 case ADDR_CONFIG_16_PIPE
:
1075 case ADDR_CONFIG_32_PIPE
:
1080 ADDR_ASSERT_ALWAYS();
1084 switch (gbAddrConfig
.bits
.PIPE_INTERLEAVE_SIZE
)
1086 case ADDR_CONFIG_PIPE_INTERLEAVE_256B
:
1087 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_256B
;
1088 m_pipeInterleaveLog2
= 8;
1090 case ADDR_CONFIG_PIPE_INTERLEAVE_512B
:
1091 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_512B
;
1092 m_pipeInterleaveLog2
= 9;
1094 case ADDR_CONFIG_PIPE_INTERLEAVE_1KB
:
1095 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_1KB
;
1096 m_pipeInterleaveLog2
= 10;
1098 case ADDR_CONFIG_PIPE_INTERLEAVE_2KB
:
1099 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_2KB
;
1100 m_pipeInterleaveLog2
= 11;
1103 ADDR_ASSERT_ALWAYS();
1107 // Addr::V2::Lib::ComputePipeBankXor()/ComputeSlicePipeBankXor() requires pipe interleave to be exactly 8 bits,
1108 // and any larger value requires a post-process (left shift) on the output pipeBankXor bits.
1109 ADDR_ASSERT(m_pipeInterleaveBytes
== ADDR_PIPEINTERLEAVE_256B
);
1111 switch (gbAddrConfig
.bits
.NUM_BANKS
)
1113 case ADDR_CONFIG_1_BANK
:
1117 case ADDR_CONFIG_2_BANK
:
1121 case ADDR_CONFIG_4_BANK
:
1125 case ADDR_CONFIG_8_BANK
:
1129 case ADDR_CONFIG_16_BANK
:
1134 ADDR_ASSERT_ALWAYS();
1138 switch (gbAddrConfig
.bits
.NUM_SHADER_ENGINES
)
1140 case ADDR_CONFIG_1_SHADER_ENGINE
:
1144 case ADDR_CONFIG_2_SHADER_ENGINE
:
1148 case ADDR_CONFIG_4_SHADER_ENGINE
:
1152 case ADDR_CONFIG_8_SHADER_ENGINE
:
1157 ADDR_ASSERT_ALWAYS();
1161 switch (gbAddrConfig
.bits
.NUM_RB_PER_SE
)
1163 case ADDR_CONFIG_1_RB_PER_SHADER_ENGINE
:
1167 case ADDR_CONFIG_2_RB_PER_SHADER_ENGINE
:
1171 case ADDR_CONFIG_4_RB_PER_SHADER_ENGINE
:
1176 ADDR_ASSERT_ALWAYS();
1180 switch (gbAddrConfig
.bits
.MAX_COMPRESSED_FRAGS
)
1182 case ADDR_CONFIG_1_MAX_COMPRESSED_FRAGMENTS
:
1184 m_maxCompFragLog2
= 0;
1186 case ADDR_CONFIG_2_MAX_COMPRESSED_FRAGMENTS
:
1188 m_maxCompFragLog2
= 1;
1190 case ADDR_CONFIG_4_MAX_COMPRESSED_FRAGMENTS
:
1192 m_maxCompFragLog2
= 2;
1194 case ADDR_CONFIG_8_MAX_COMPRESSED_FRAGMENTS
:
1196 m_maxCompFragLog2
= 3;
1199 ADDR_ASSERT_ALWAYS();
1203 if ((m_rbPerSeLog2
== 1) &&
1204 (((m_pipesLog2
== 1) && ((m_seLog2
== 2) || (m_seLog2
== 3))) ||
1205 ((m_pipesLog2
== 2) && ((m_seLog2
== 1) || (m_seLog2
== 2)))))
1207 ADDR_ASSERT(m_settings
.isVega10
== FALSE
);
1208 ADDR_ASSERT(m_settings
.isRaven
== FALSE
);
1210 ADDR_ASSERT(m_settings
.isVega20
== FALSE
);
1212 if (m_settings
.isVega12
)
1214 m_settings
.htileCacheRbConflict
= 1;
1218 // For simplicity we never allow VAR swizzle mode for GFX9, the actural value is 18 on GFX9
1219 m_blockVarSizeLog2
= 0;
1224 ADDR_NOT_IMPLEMENTED();
1229 InitEquationTable();
1236 ************************************************************************************************************************
1237 * Gfx9Lib::HwlConvertChipFamily
1240 * Convert familyID defined in atiid.h to ChipFamily and set m_chipFamily/m_chipRevision
1243 ************************************************************************************************************************
1245 ChipFamily
Gfx9Lib::HwlConvertChipFamily(
1246 UINT_32 uChipFamily
, ///< [in] chip family defined in atiih.h
1247 UINT_32 uChipRevision
) ///< [in] chip revision defined in "asic_family"_id.h
1249 ChipFamily family
= ADDR_CHIP_FAMILY_AI
;
1251 switch (uChipFamily
)
1254 m_settings
.isArcticIsland
= 1;
1255 m_settings
.isVega10
= ASICREV_IS_VEGA10_P(uChipRevision
);
1256 m_settings
.isVega12
= ASICREV_IS_VEGA12_P(uChipRevision
);
1257 m_settings
.isVega20
= ASICREV_IS_VEGA20_P(uChipRevision
);
1258 m_settings
.isDce12
= 1;
1260 if (m_settings
.isVega10
== 0)
1262 m_settings
.htileAlignFix
= 1;
1263 m_settings
.applyAliasFix
= 1;
1266 m_settings
.metaBaseAlignFix
= 1;
1268 m_settings
.depthPipeXorDisable
= 1;
1271 m_settings
.isArcticIsland
= 1;
1273 if (ASICREV_IS_RAVEN(uChipRevision
))
1275 m_settings
.isRaven
= 1;
1277 m_settings
.depthPipeXorDisable
= 1;
1280 if (ASICREV_IS_RAVEN2(uChipRevision
))
1282 m_settings
.isRaven
= 1;
1285 if (m_settings
.isRaven
== 0)
1287 m_settings
.htileAlignFix
= 1;
1288 m_settings
.applyAliasFix
= 1;
1291 if (ASICREV_IS_RENOIR(uChipRevision
))
1293 m_settings
.isRaven
= 1;
1296 m_settings
.isDcn1
= m_settings
.isRaven
;
1298 m_settings
.metaBaseAlignFix
= 1;
1302 ADDR_ASSERT(!"This should be a Fusion");
1310 ************************************************************************************************************************
1311 * Gfx9Lib::InitRbEquation
1317 ************************************************************************************************************************
1319 VOID
Gfx9Lib::GetRbEquation(
1320 CoordEq
* pRbEq
, ///< [out] rb equation
1321 UINT_32 numRbPerSeLog2
, ///< [in] number of rb per shader engine
1322 UINT_32 numSeLog2
) ///< [in] number of shader engine
1325 // RB's are distributed on 16x16, except when we have 1 rb per se, in which case its 32x32
1326 UINT_32 rbRegion
= (numRbPerSeLog2
== 0) ? 5 : 4;
1327 Coordinate
cx(DIM_X
, rbRegion
);
1328 Coordinate
cy(DIM_Y
, rbRegion
);
1331 UINT_32 numRbTotalLog2
= numRbPerSeLog2
+ numSeLog2
;
1333 // Clear the rb equation
1335 pRbEq
->resize(numRbTotalLog2
);
1337 if ((numSeLog2
> 0) && (numRbPerSeLog2
== 1))
1339 // Special case when more than 1 SE, and 2 RB per SE
1340 (*pRbEq
)[0].add(cx
);
1341 (*pRbEq
)[0].add(cy
);
1345 if (m_settings
.applyAliasFix
== false)
1347 (*pRbEq
)[0].add(cy
);
1350 (*pRbEq
)[0].add(cy
);
1354 UINT_32 numBits
= 2 * (numRbTotalLog2
- start
);
1356 for (UINT_32 i
= 0; i
< numBits
; i
++)
1359 start
+ (((start
+ i
) >= numRbTotalLog2
) ? (2 * (numRbTotalLog2
- start
) - i
- 1) : i
);
1363 (*pRbEq
)[idx
].add(cx
);
1368 (*pRbEq
)[idx
].add(cy
);
1375 ************************************************************************************************************************
1376 * Gfx9Lib::GetDataEquation
1379 * Get data equation for fmask and Z
1382 ************************************************************************************************************************
1384 VOID
Gfx9Lib::GetDataEquation(
1385 CoordEq
* pDataEq
, ///< [out] data surface equation
1386 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1387 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1388 AddrResourceType resourceType
, ///< [in] data surface resource type
1389 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1390 UINT_32 numSamplesLog2
) ///< [in] data surface sample count
1393 Coordinate
cx(DIM_X
, 0);
1394 Coordinate
cy(DIM_Y
, 0);
1395 Coordinate
cz(DIM_Z
, 0);
1396 Coordinate
cs(DIM_S
, 0);
1398 // Clear the equation
1400 pDataEq
->resize(27);
1402 if (dataSurfaceType
== Gfx9DataColor
)
1404 if (IsLinear(swizzleMode
))
1406 Coordinate
cm(DIM_M
, 0);
1408 pDataEq
->resize(49);
1410 for (UINT_32 i
= 0; i
< 49; i
++)
1412 (*pDataEq
)[i
].add(cm
);
1416 else if (IsThick(resourceType
, swizzleMode
))
1418 // Color 3d_S and 3d_Z modes, 3d_D is same as color 2d
1420 if (IsStandardSwizzle(resourceType
, swizzleMode
))
1422 // Standard 3d swizzle
1423 // Fill in bottom x bits
1424 for (i
= elementBytesLog2
; i
< 4; i
++)
1426 (*pDataEq
)[i
].add(cx
);
1429 // Fill in 2 bits of y and then z
1430 for (i
= 4; i
< 6; i
++)
1432 (*pDataEq
)[i
].add(cy
);
1435 for (i
= 6; i
< 8; i
++)
1437 (*pDataEq
)[i
].add(cz
);
1440 if (elementBytesLog2
< 2)
1442 // fill in z & y bit
1443 (*pDataEq
)[8].add(cz
);
1444 (*pDataEq
)[9].add(cy
);
1448 else if (elementBytesLog2
== 2)
1450 // fill in y and x bit
1451 (*pDataEq
)[8].add(cy
);
1452 (*pDataEq
)[9].add(cx
);
1459 (*pDataEq
)[8].add(cx
);
1461 (*pDataEq
)[9].add(cx
);
1468 UINT_32 m2dEnd
= (elementBytesLog2
==0) ? 3 : ((elementBytesLog2
< 4) ? 4 : 5);
1469 UINT_32 numZs
= (elementBytesLog2
== 0 || elementBytesLog2
== 4) ?
1470 2 : ((elementBytesLog2
== 1) ? 3 : 1);
1471 pDataEq
->mort2d(cx
, cy
, elementBytesLog2
, m2dEnd
);
1472 for (i
= m2dEnd
+ 1; i
<= m2dEnd
+ numZs
; i
++)
1474 (*pDataEq
)[i
].add(cz
);
1477 if ((elementBytesLog2
== 0) || (elementBytesLog2
== 3))
1480 (*pDataEq
)[6].add(cx
);
1481 (*pDataEq
)[7].add(cz
);
1485 else if (elementBytesLog2
== 2)
1488 (*pDataEq
)[6].add(cy
);
1489 (*pDataEq
)[7].add(cz
);
1494 (*pDataEq
)[8].add(cy
);
1495 (*pDataEq
)[9].add(cx
);
1499 // Fill in bit 10 and up
1500 pDataEq
->mort3d( cz
, cy
, cx
, 10 );
1502 else if (IsThin(resourceType
, swizzleMode
))
1504 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1506 UINT_32 microYBits
= (8 - elementBytesLog2
) / 2;
1507 UINT_32 tileSplitStart
= blockSizeLog2
- numSamplesLog2
;
1509 // Fill in bottom x bits
1510 for (i
= elementBytesLog2
; i
< 4; i
++)
1512 (*pDataEq
)[i
].add(cx
);
1515 // Fill in bottom y bits
1516 for (i
= 4; i
< 4 + microYBits
; i
++)
1518 (*pDataEq
)[i
].add(cy
);
1521 // Fill in last of the micro_x bits
1522 for (i
= 4 + microYBits
; i
< 8; i
++)
1524 (*pDataEq
)[i
].add(cx
);
1527 // Fill in x/y bits below sample split
1528 pDataEq
->mort2d(cy
, cx
, 8, tileSplitStart
- 1);
1529 // Fill in sample bits
1530 for (i
= 0; i
< numSamplesLog2
; i
++)
1533 (*pDataEq
)[tileSplitStart
+ i
].add(cs
);
1535 // Fill in x/y bits above sample split
1536 if ((numSamplesLog2
& 1) ^ (blockSizeLog2
& 1))
1538 pDataEq
->mort2d(cx
, cy
, blockSizeLog2
);
1542 pDataEq
->mort2d(cy
, cx
, blockSizeLog2
);
1547 ADDR_ASSERT_ALWAYS();
1553 UINT_32 sampleStart
= elementBytesLog2
;
1554 UINT_32 pixelStart
= elementBytesLog2
+ numSamplesLog2
;
1555 UINT_32 ymajStart
= 6 + numSamplesLog2
;
1557 for (UINT_32 s
= 0; s
< numSamplesLog2
; s
++)
1560 (*pDataEq
)[sampleStart
+ s
].add(cs
);
1563 // Put in the x-major order pixel bits
1564 pDataEq
->mort2d(cx
, cy
, pixelStart
, ymajStart
- 1);
1565 // Put in the y-major order pixel bits
1566 pDataEq
->mort2d(cy
, cx
, ymajStart
);
1571 ************************************************************************************************************************
1572 * Gfx9Lib::GetPipeEquation
1578 ************************************************************************************************************************
1580 VOID
Gfx9Lib::GetPipeEquation(
1581 CoordEq
* pPipeEq
, ///< [out] pipe equation
1582 CoordEq
* pDataEq
, ///< [in] data equation
1583 UINT_32 pipeInterleaveLog2
, ///< [in] pipe interleave
1584 UINT_32 numPipeLog2
, ///< [in] number of pipes
1585 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1586 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1587 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1588 AddrResourceType resourceType
///< [in] data surface resource type
1591 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1594 pDataEq
->copy(dataEq
);
1596 if (dataSurfaceType
== Gfx9DataColor
)
1598 INT_32 shift
= static_cast<INT_32
>(numSamplesLog2
);
1599 dataEq
.shift(-shift
, blockSizeLog2
- numSamplesLog2
);
1602 dataEq
.copy(*pPipeEq
, pipeInterleaveLog2
, numPipeLog2
);
1604 // This section should only apply to z/stencil, maybe fmask
1605 // If the pipe bit is below the comp block size,
1606 // then keep moving up the address until we find a bit that is above
1607 UINT_32 pipeStart
= 0;
1609 if (dataSurfaceType
!= Gfx9DataColor
)
1611 Coordinate
tileMin(DIM_X
, 3);
1613 while (dataEq
[pipeInterleaveLog2
+ pipeStart
][0] < tileMin
)
1618 // if pipe is 0, then the first pipe bit is above the comp block size,
1619 // so we don't need to do anything
1620 // Note, this if condition is not necessary, since if we execute the loop when pipe==0,
1621 // we will get the same pipe equation
1624 for (UINT_32 i
= 0; i
< numPipeLog2
; i
++)
1626 // Copy the jth bit above pipe interleave to the current pipe equation bit
1627 dataEq
[pipeInterleaveLog2
+ pipeStart
+ i
].copyto((*pPipeEq
)[i
]);
1632 if (IsPrt(swizzleMode
))
1634 // Clear out bits above the block size if prt's are enabled
1635 dataEq
.resize(blockSizeLog2
);
1639 if (IsXor(swizzleMode
))
1643 if (IsThick(resourceType
, swizzleMode
))
1647 dataEq
.copy(xorMask2
, pipeInterleaveLog2
+ numPipeLog2
, 2 * numPipeLog2
);
1649 xorMask
.resize(numPipeLog2
);
1651 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1653 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
]);
1654 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
+ 1]);
1659 // Xor in the bits above the pipe+gpu bits
1660 dataEq
.copy(xorMask
, pipeInterleaveLog2
+ pipeStart
+ numPipeLog2
, numPipeLog2
);
1662 if ((numSamplesLog2
== 0) && (IsPrt(swizzleMode
) == FALSE
))
1666 // if 1xaa and not prt, then xor in the z bits
1668 xorMask2
.resize(numPipeLog2
);
1669 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1671 co
.set(DIM_Z
, numPipeLog2
- 1 - pipeIdx
);
1672 xorMask2
[pipeIdx
].add(co
);
1675 pPipeEq
->xorin(xorMask2
);
1680 pPipeEq
->xorin(xorMask
);
1684 ************************************************************************************************************************
1685 * Gfx9Lib::GetMetaEquation
1688 * Get meta equation for cmask/htile/DCC
1690 * Pointer to a calculated meta equation
1691 ************************************************************************************************************************
1693 const CoordEq
* Gfx9Lib::GetMetaEquation(
1694 const MetaEqParams
& metaEqParams
)
1696 UINT_32 cachedMetaEqIndex
;
1698 for (cachedMetaEqIndex
= 0; cachedMetaEqIndex
< MaxCachedMetaEq
; cachedMetaEqIndex
++)
1700 if (memcmp(&metaEqParams
,
1701 &m_cachedMetaEqKey
[cachedMetaEqIndex
],
1702 static_cast<UINT_32
>(sizeof(metaEqParams
))) == 0)
1708 CoordEq
* pMetaEq
= NULL
;
1710 if (cachedMetaEqIndex
< MaxCachedMetaEq
)
1712 pMetaEq
= &m_cachedMetaEq
[cachedMetaEqIndex
];
1716 m_cachedMetaEqKey
[m_metaEqOverrideIndex
] = metaEqParams
;
1718 pMetaEq
= &m_cachedMetaEq
[m_metaEqOverrideIndex
++];
1720 m_metaEqOverrideIndex
%= MaxCachedMetaEq
;
1722 GenMetaEquation(pMetaEq
,
1723 metaEqParams
.maxMip
,
1724 metaEqParams
.elementBytesLog2
,
1725 metaEqParams
.numSamplesLog2
,
1726 metaEqParams
.metaFlag
,
1727 metaEqParams
.dataSurfaceType
,
1728 metaEqParams
.swizzleMode
,
1729 metaEqParams
.resourceType
,
1730 metaEqParams
.metaBlkWidthLog2
,
1731 metaEqParams
.metaBlkHeightLog2
,
1732 metaEqParams
.metaBlkDepthLog2
,
1733 metaEqParams
.compBlkWidthLog2
,
1734 metaEqParams
.compBlkHeightLog2
,
1735 metaEqParams
.compBlkDepthLog2
);
1742 ************************************************************************************************************************
1743 * Gfx9Lib::GenMetaEquation
1746 * Get meta equation for cmask/htile/DCC
1749 ************************************************************************************************************************
1751 VOID
Gfx9Lib::GenMetaEquation(
1752 CoordEq
* pMetaEq
, ///< [out] meta equation
1753 UINT_32 maxMip
, ///< [in] max mip Id
1754 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1755 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1756 ADDR2_META_FLAGS metaFlag
, ///< [in] meta falg
1757 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1758 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1759 AddrResourceType resourceType
, ///< [in] data surface resource type
1760 UINT_32 metaBlkWidthLog2
, ///< [in] meta block width
1761 UINT_32 metaBlkHeightLog2
, ///< [in] meta block height
1762 UINT_32 metaBlkDepthLog2
, ///< [in] meta block depth
1763 UINT_32 compBlkWidthLog2
, ///< [in] compress block width
1764 UINT_32 compBlkHeightLog2
, ///< [in] compress block height
1765 UINT_32 compBlkDepthLog2
) ///< [in] compress block depth
1768 UINT_32 numPipeTotalLog2
= GetPipeLog2ForMetaAddressing(metaFlag
.pipeAligned
, swizzleMode
);
1769 UINT_32 pipeInterleaveLog2
= m_pipeInterleaveLog2
;
1771 // Get the correct data address and rb equation
1773 GetDataEquation(&dataEq
, dataSurfaceType
, swizzleMode
, resourceType
,
1774 elementBytesLog2
, numSamplesLog2
);
1776 // Get pipe and rb equations
1777 CoordEq pipeEquation
;
1778 GetPipeEquation(&pipeEquation
, &dataEq
, pipeInterleaveLog2
, numPipeTotalLog2
,
1779 numSamplesLog2
, dataSurfaceType
, swizzleMode
, resourceType
);
1780 numPipeTotalLog2
= pipeEquation
.getsize();
1782 if (metaFlag
.linear
)
1784 // Linear metadata supporting was removed for GFX9! No one can use this feature.
1785 ADDR_ASSERT_ALWAYS();
1787 ADDR_ASSERT(dataSurfaceType
== Gfx9DataColor
);
1789 dataEq
.copy(*pMetaEq
);
1791 if (IsLinear(swizzleMode
))
1793 if (metaFlag
.pipeAligned
)
1795 // Remove the pipe bits
1796 INT_32 shift
= static_cast<INT_32
>(numPipeTotalLog2
);
1797 pMetaEq
->shift(-shift
, pipeInterleaveLog2
);
1799 // Divide by comp block size, which for linear (which is always color) is 256 B
1802 if (metaFlag
.pipeAligned
)
1804 // Put pipe bits back in
1805 pMetaEq
->shift(numPipeTotalLog2
, pipeInterleaveLog2
);
1807 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1809 pipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ i
]);
1818 UINT_32 maxCompFragLog2
= static_cast<INT_32
>(m_maxCompFragLog2
);
1819 UINT_32 compFragLog2
=
1820 ((dataSurfaceType
== Gfx9DataColor
) && (numSamplesLog2
> maxCompFragLog2
)) ?
1821 maxCompFragLog2
: numSamplesLog2
;
1823 UINT_32 uncompFragLog2
= numSamplesLog2
- compFragLog2
;
1825 // Make sure the metaaddr is cleared
1827 pMetaEq
->resize(27);
1829 if (IsThick(resourceType
, swizzleMode
))
1831 Coordinate
cx(DIM_X
, 0);
1832 Coordinate
cy(DIM_Y
, 0);
1833 Coordinate
cz(DIM_Z
, 0);
1837 pMetaEq
->mort3d(cy
, cx
, cz
);
1841 pMetaEq
->mort3d(cx
, cy
, cz
);
1846 Coordinate
cx(DIM_X
, 0);
1847 Coordinate
cy(DIM_Y
, 0);
1852 pMetaEq
->mort2d(cy
, cx
, compFragLog2
);
1856 pMetaEq
->mort2d(cx
, cy
, compFragLog2
);
1859 //------------------------------------------------------------------------------------------------------------------------
1860 // Put the compressible fragments at the lsb
1861 // the uncompressible frags will be at the msb of the micro address
1862 //------------------------------------------------------------------------------------------------------------------------
1863 for (UINT_32 s
= 0; s
< compFragLog2
; s
++)
1866 (*pMetaEq
)[s
].add(cs
);
1870 // Keep a copy of the pipe equations
1871 CoordEq origPipeEquation
;
1872 pipeEquation
.copy(origPipeEquation
);
1875 // filter out everything under the compressed block size
1876 co
.set(DIM_X
, compBlkWidthLog2
);
1877 pMetaEq
->Filter('<', co
, 0, DIM_X
);
1878 co
.set(DIM_Y
, compBlkHeightLog2
);
1879 pMetaEq
->Filter('<', co
, 0, DIM_Y
);
1880 co
.set(DIM_Z
, compBlkDepthLog2
);
1881 pMetaEq
->Filter('<', co
, 0, DIM_Z
);
1883 // For non-color, filter out sample bits
1884 if (dataSurfaceType
!= Gfx9DataColor
)
1887 pMetaEq
->Filter('<', co
, 0, DIM_S
);
1890 // filter out everything above the metablock size
1891 co
.set(DIM_X
, metaBlkWidthLog2
- 1);
1892 pMetaEq
->Filter('>', co
, 0, DIM_X
);
1893 co
.set(DIM_Y
, metaBlkHeightLog2
- 1);
1894 pMetaEq
->Filter('>', co
, 0, DIM_Y
);
1895 co
.set(DIM_Z
, metaBlkDepthLog2
- 1);
1896 pMetaEq
->Filter('>', co
, 0, DIM_Z
);
1898 // filter out everything above the metablock size for the channel bits
1899 co
.set(DIM_X
, metaBlkWidthLog2
- 1);
1900 pipeEquation
.Filter('>', co
, 0, DIM_X
);
1901 co
.set(DIM_Y
, metaBlkHeightLog2
- 1);
1902 pipeEquation
.Filter('>', co
, 0, DIM_Y
);
1903 co
.set(DIM_Z
, metaBlkDepthLog2
- 1);
1904 pipeEquation
.Filter('>', co
, 0, DIM_Z
);
1906 // Make sure we still have the same number of channel bits
1907 if (pipeEquation
.getsize() != numPipeTotalLog2
)
1909 ADDR_ASSERT_ALWAYS();
1912 // Loop through all channel and rb bits,
1913 // and make sure these components exist in the metadata address
1914 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1916 for (UINT_32 j
= pipeEquation
[i
].getsize(); j
> 0; j
--)
1918 if (pMetaEq
->Exists(pipeEquation
[i
][j
- 1]) == FALSE
)
1920 ADDR_ASSERT_ALWAYS();
1925 const UINT_32 numSeLog2
= metaFlag
.rbAligned
? m_seLog2
: 0;
1926 const UINT_32 numRbPeSeLog2
= metaFlag
.rbAligned
? m_rbPerSeLog2
: 0;
1927 const UINT_32 numRbTotalLog2
= numRbPeSeLog2
+ numSeLog2
;
1928 CoordEq origRbEquation
;
1930 GetRbEquation(&origRbEquation
, numRbPeSeLog2
, numSeLog2
);
1932 CoordEq rbEquation
= origRbEquation
;
1934 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1936 for (UINT_32 j
= rbEquation
[i
].getsize(); j
> 0; j
--)
1938 if (pMetaEq
->Exists(rbEquation
[i
][j
- 1]) == FALSE
)
1940 ADDR_ASSERT_ALWAYS();
1945 if (m_settings
.applyAliasFix
)
1950 // Loop through each rb id bit; if it is equal to any of the filtered channel bits, clear it
1951 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1953 for (UINT_32 j
= 0; j
< numPipeTotalLog2
; j
++)
1955 BOOL_32 isRbEquationInPipeEquation
= FALSE
;
1957 if (m_settings
.applyAliasFix
)
1959 CoordTerm filteredPipeEq
;
1960 filteredPipeEq
= pipeEquation
[j
];
1962 filteredPipeEq
.Filter('>', co
, 0, DIM_Z
);
1964 isRbEquationInPipeEquation
= (rbEquation
[i
] == filteredPipeEq
);
1968 isRbEquationInPipeEquation
= (rbEquation
[i
] == pipeEquation
[j
]);
1971 if (isRbEquationInPipeEquation
)
1973 rbEquation
[i
].Clear();
1978 bool rbAppendedWithPipeBits
[1 << (MaxSeLog2
+ MaxRbPerSeLog2
)] = {};
1980 // Loop through each bit of the channel, get the smallest coordinate,
1981 // and remove it from the metaaddr, and rb_equation
1982 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1984 pipeEquation
[i
].getsmallest(co
);
1986 UINT_32 old_size
= pMetaEq
->getsize();
1987 pMetaEq
->Filter('=', co
);
1988 UINT_32 new_size
= pMetaEq
->getsize();
1989 if (new_size
!= old_size
-1)
1991 ADDR_ASSERT_ALWAYS();
1993 pipeEquation
.remove(co
);
1994 for (UINT_32 j
= 0; j
< numRbTotalLog2
; j
++)
1996 if (rbEquation
[j
].remove(co
))
1998 // if we actually removed something from this bit, then add the remaining
1999 // channel bits, as these can be removed for this bit
2000 for (UINT_32 k
= 0; k
< pipeEquation
[i
].getsize(); k
++)
2002 if (pipeEquation
[i
][k
] != co
)
2004 rbEquation
[j
].add(pipeEquation
[i
][k
]);
2005 rbAppendedWithPipeBits
[j
] = true;
2012 // Loop through the rb bits and see what remain;
2013 // filter out the smallest coordinate if it remains
2014 UINT_32 rbBitsLeft
= 0;
2015 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
2017 BOOL_32 isRbEqAppended
= FALSE
;
2019 if (m_settings
.applyAliasFix
)
2021 isRbEqAppended
= (rbEquation
[i
].getsize() > (rbAppendedWithPipeBits
[i
] ? 1 : 0));
2025 isRbEqAppended
= (rbEquation
[i
].getsize() > 0);
2031 rbEquation
[i
].getsmallest(co
);
2032 UINT_32 old_size
= pMetaEq
->getsize();
2033 pMetaEq
->Filter('=', co
);
2034 UINT_32 new_size
= pMetaEq
->getsize();
2035 if (new_size
!= old_size
- 1)
2039 for (UINT_32 j
= i
+ 1; j
< numRbTotalLog2
; j
++)
2041 if (rbEquation
[j
].remove(co
))
2043 // if we actually removed something from this bit, then add the remaining
2044 // rb bits, as these can be removed for this bit
2045 for (UINT_32 k
= 0; k
< rbEquation
[i
].getsize(); k
++)
2047 if (rbEquation
[i
][k
] != co
)
2049 rbEquation
[j
].add(rbEquation
[i
][k
]);
2050 rbAppendedWithPipeBits
[j
] |= rbAppendedWithPipeBits
[i
];
2058 // capture the size of the metaaddr
2059 UINT_32 metaSize
= pMetaEq
->getsize();
2060 // resize to 49 bits...make this a nibble address
2061 pMetaEq
->resize(49);
2062 // Concatenate the macro address above the current address
2063 for (UINT_32 i
= metaSize
, j
= 0; i
< 49; i
++, j
++)
2066 (*pMetaEq
)[i
].add(co
);
2069 // Multiply by meta element size (in nibbles)
2070 if (dataSurfaceType
== Gfx9DataColor
)
2074 else if (dataSurfaceType
== Gfx9DataDepthStencil
)
2079 //------------------------------------------------------------------------------------------
2080 // Note the pipeInterleaveLog2+1 is because address is a nibble address
2081 // Shift up from pipe interleave number of channel
2082 // and rb bits left, and uncompressed fragments
2083 //------------------------------------------------------------------------------------------
2085 pMetaEq
->shift(numPipeTotalLog2
+ rbBitsLeft
+ uncompFragLog2
, pipeInterleaveLog2
+ 1);
2087 // Put in the channel bits
2088 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
2090 origPipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+1 + i
]);
2093 // Put in remaining rb bits
2094 for (UINT_32 i
= 0, j
= 0; j
< rbBitsLeft
; i
= (i
+ 1) % numRbTotalLog2
)
2096 BOOL_32 isRbEqAppended
= FALSE
;
2098 if (m_settings
.applyAliasFix
)
2100 isRbEqAppended
= (rbEquation
[i
].getsize() > (rbAppendedWithPipeBits
[i
] ? 1 : 0));
2104 isRbEqAppended
= (rbEquation
[i
].getsize() > 0);
2109 origRbEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ j
]);
2110 // Mark any rb bit we add in to the rb mask
2115 //------------------------------------------------------------------------------------------
2116 // Put in the uncompressed fragment bits
2117 //------------------------------------------------------------------------------------------
2118 for (UINT_32 i
= 0; i
< uncompFragLog2
; i
++)
2120 co
.set(DIM_S
, compFragLog2
+ i
);
2121 (*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ rbBitsLeft
+ i
].add(co
);
2127 ************************************************************************************************************************
2128 * Gfx9Lib::IsEquationSupported
2131 * Check if equation is supported for given swizzle mode and resource type.
2135 ************************************************************************************************************************
2137 BOOL_32
Gfx9Lib::IsEquationSupported(
2138 AddrResourceType rsrcType
,
2139 AddrSwizzleMode swMode
,
2140 UINT_32 elementBytesLog2
) const
2142 BOOL_32 supported
= (elementBytesLog2
< MaxElementBytesLog2
) &&
2143 (IsValidSwMode(swMode
) == TRUE
) &&
2144 (IsLinear(swMode
) == FALSE
) &&
2145 (((IsTex2d(rsrcType
) == TRUE
) &&
2146 ((elementBytesLog2
< 4) ||
2147 ((IsRotateSwizzle(swMode
) == FALSE
) &&
2148 (IsZOrderSwizzle(swMode
) == FALSE
)))) ||
2149 ((IsTex3d(rsrcType
) == TRUE
) &&
2150 (IsRotateSwizzle(swMode
) == FALSE
) &&
2151 (IsBlock256b(swMode
) == FALSE
)));
2157 ************************************************************************************************************************
2158 * Gfx9Lib::InitEquationTable
2161 * Initialize Equation table.
2165 ************************************************************************************************************************
2167 VOID
Gfx9Lib::InitEquationTable()
2169 memset(m_equationTable
, 0, sizeof(m_equationTable
));
2171 // Loop all possible resource type (2D/3D)
2172 for (UINT_32 rsrcTypeIdx
= 0; rsrcTypeIdx
< MaxRsrcType
; rsrcTypeIdx
++)
2174 AddrResourceType rsrcType
= static_cast<AddrResourceType
>(rsrcTypeIdx
+ ADDR_RSRC_TEX_2D
);
2176 // Loop all possible swizzle mode
2177 for (UINT_32 swModeIdx
= 0; swModeIdx
< MaxSwModeType
; swModeIdx
++)
2179 AddrSwizzleMode swMode
= static_cast<AddrSwizzleMode
>(swModeIdx
);
2181 // Loop all possible bpp
2182 for (UINT_32 bppIdx
= 0; bppIdx
< MaxElementBytesLog2
; bppIdx
++)
2184 UINT_32 equationIndex
= ADDR_INVALID_EQUATION_INDEX
;
2186 // Check if the input is supported
2187 if (IsEquationSupported(rsrcType
, swMode
, bppIdx
))
2189 ADDR_EQUATION equation
;
2190 ADDR_E_RETURNCODE retCode
;
2192 memset(&equation
, 0, sizeof(ADDR_EQUATION
));
2194 // Generate the equation
2195 if (IsBlock256b(swMode
) && IsTex2d(rsrcType
))
2197 retCode
= ComputeBlock256Equation(rsrcType
, swMode
, bppIdx
, &equation
);
2199 else if (IsThin(rsrcType
, swMode
))
2201 retCode
= ComputeThinEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2205 retCode
= ComputeThickEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2208 // Only fill the equation into the table if the return code is ADDR_OK,
2209 // otherwise if the return code is not ADDR_OK, it indicates this is not
2210 // a valid input, we do nothing but just fill invalid equation index
2211 // into the lookup table.
2212 if (retCode
== ADDR_OK
)
2214 equationIndex
= m_numEquations
;
2215 ADDR_ASSERT(equationIndex
< EquationTableSize
);
2217 m_equationTable
[equationIndex
] = equation
;
2223 ADDR_ASSERT_ALWAYS();
2227 // Fill the index into the lookup table, if the combination is not supported
2228 // fill the invalid equation index
2229 m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][bppIdx
] = equationIndex
;
2236 ************************************************************************************************************************
2237 * Gfx9Lib::HwlGetEquationIndex
2240 * Interface function stub of GetEquationIndex
2244 ************************************************************************************************************************
2246 UINT_32
Gfx9Lib::HwlGetEquationIndex(
2247 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
2248 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
2251 AddrResourceType rsrcType
= pIn
->resourceType
;
2252 AddrSwizzleMode swMode
= pIn
->swizzleMode
;
2253 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
2254 UINT_32 index
= ADDR_INVALID_EQUATION_INDEX
;
2256 if (IsEquationSupported(rsrcType
, swMode
, elementBytesLog2
))
2258 UINT_32 rsrcTypeIdx
= static_cast<UINT_32
>(rsrcType
) - 1;
2259 UINT_32 swModeIdx
= static_cast<UINT_32
>(swMode
);
2261 index
= m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][elementBytesLog2
];
2264 if (pOut
->pMipInfo
!= NULL
)
2266 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
2268 pOut
->pMipInfo
[i
].equationIndex
= index
;
2276 ************************************************************************************************************************
2277 * Gfx9Lib::HwlComputeBlock256Equation
2280 * Interface function stub of ComputeBlock256Equation
2284 ************************************************************************************************************************
2286 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeBlock256Equation(
2287 AddrResourceType rsrcType
,
2288 AddrSwizzleMode swMode
,
2289 UINT_32 elementBytesLog2
,
2290 ADDR_EQUATION
* pEquation
) const
2292 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2294 pEquation
->numBits
= 8;
2297 for (; i
< elementBytesLog2
; i
++)
2299 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2302 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2304 const UINT_32 maxBitsUsed
= 4;
2305 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2306 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2308 for (i
= 0; i
< maxBitsUsed
; i
++)
2310 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2311 InitChannel(1, 1, i
, &y
[i
]);
2314 if (IsStandardSwizzle(rsrcType
, swMode
))
2316 switch (elementBytesLog2
)
2359 ADDR_ASSERT_ALWAYS();
2360 ret
= ADDR_INVALIDPARAMS
;
2364 else if (IsDisplaySwizzle(rsrcType
, swMode
))
2366 switch (elementBytesLog2
)
2409 ADDR_ASSERT_ALWAYS();
2410 ret
= ADDR_INVALIDPARAMS
;
2414 else if (IsRotateSwizzle(swMode
))
2416 switch (elementBytesLog2
)
2453 ADDR_ASSERT_ALWAYS();
2455 ret
= ADDR_INVALIDPARAMS
;
2461 ADDR_ASSERT_ALWAYS();
2462 ret
= ADDR_INVALIDPARAMS
;
2468 ASSERTED Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2469 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 0)) ==
2470 (microBlockDim
.w
* (1 << elementBytesLog2
)));
2471 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 1)) == microBlockDim
.h
);
2478 ************************************************************************************************************************
2479 * Gfx9Lib::HwlComputeThinEquation
2482 * Interface function stub of ComputeThinEquation
2486 ************************************************************************************************************************
2488 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThinEquation(
2489 AddrResourceType rsrcType
,
2490 AddrSwizzleMode swMode
,
2491 UINT_32 elementBytesLog2
,
2492 ADDR_EQUATION
* pEquation
) const
2494 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2496 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2498 UINT_32 maxXorBits
= blockSizeLog2
;
2499 if (IsNonPrtXor(swMode
))
2501 // For non-prt-xor, maybe need to initialize some more bits for xor
2502 // The highest xor bit used in equation will be max the following 3 items:
2503 // 1. m_pipeInterleaveLog2 + 2 * pipeXorBits
2504 // 2. m_pipeInterleaveLog2 + pipeXorBits + 2 * bankXorBits
2507 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 2 * GetPipeXorBits(blockSizeLog2
));
2508 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2509 GetPipeXorBits(blockSizeLog2
) +
2510 2 * GetBankXorBits(blockSizeLog2
));
2513 const UINT_32 maxBitsUsed
= 14;
2514 ADDR_ASSERT((2 * maxBitsUsed
) >= maxXorBits
);
2515 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2516 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2518 const UINT_32 extraXorBits
= 16;
2519 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2520 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2522 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2524 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2525 InitChannel(1, 1, i
, &y
[i
]);
2528 ADDR_CHANNEL_SETTING
* pixelBit
= pEquation
->addr
;
2530 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2532 InitChannel(1, 0 , i
, &pixelBit
[i
]);
2537 UINT_32 lowBits
= 0;
2539 if (IsZOrderSwizzle(swMode
))
2541 if (elementBytesLog2
<= 3)
2543 for (UINT_32 i
= elementBytesLog2
; i
< 6; i
++)
2545 pixelBit
[i
] = (((i
- elementBytesLog2
) & 1) == 0) ? x
[xIdx
++] : y
[yIdx
++];
2552 ret
= ADDR_INVALIDPARAMS
;
2557 ret
= HwlComputeBlock256Equation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
2561 Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2562 xIdx
= Log2(microBlockDim
.w
);
2563 yIdx
= Log2(microBlockDim
.h
);
2570 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2572 pixelBit
[i
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2575 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2577 xorExtra
[i
- blockSizeLog2
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2583 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2584 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2586 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2587 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2589 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2591 UINT_32 xor1BitPos
= pipeStart
+ 2 * pipeXorBits
- 1 - i
;
2592 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2593 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2595 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2598 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2600 UINT_32 xor1BitPos
= bankStart
+ 2 * bankXorBits
- 1 - i
;
2601 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2602 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2604 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2607 if (IsPrt(swMode
) == FALSE
)
2609 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2611 InitChannel(1, 2, pipeXorBits
- i
- 1, &pEquation
->xor2
[pipeStart
+ i
]);
2614 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2616 InitChannel(1, 2, bankXorBits
- i
- 1 + pipeXorBits
, &pEquation
->xor2
[bankStart
+ i
]);
2621 pEquation
->numBits
= blockSizeLog2
;
2628 ************************************************************************************************************************
2629 * Gfx9Lib::HwlComputeThickEquation
2632 * Interface function stub of ComputeThickEquation
2636 ************************************************************************************************************************
2638 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThickEquation(
2639 AddrResourceType rsrcType
,
2640 AddrSwizzleMode swMode
,
2641 UINT_32 elementBytesLog2
,
2642 ADDR_EQUATION
* pEquation
) const
2644 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2646 ADDR_ASSERT(IsTex3d(rsrcType
));
2648 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2650 UINT_32 maxXorBits
= blockSizeLog2
;
2651 if (IsNonPrtXor(swMode
))
2653 // For non-prt-xor, maybe need to initialize some more bits for xor
2654 // The highest xor bit used in equation will be max the following 3:
2655 // 1. m_pipeInterleaveLog2 + 3 * pipeXorBits
2656 // 2. m_pipeInterleaveLog2 + pipeXorBits + 3 * bankXorBits
2659 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 3 * GetPipeXorBits(blockSizeLog2
));
2660 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2661 GetPipeXorBits(blockSizeLog2
) +
2662 3 * GetBankXorBits(blockSizeLog2
));
2665 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2667 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2670 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2672 const UINT_32 maxBitsUsed
= 12;
2673 ADDR_ASSERT((3 * maxBitsUsed
) >= maxXorBits
);
2674 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2675 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2676 ADDR_CHANNEL_SETTING z
[maxBitsUsed
] = {};
2678 const UINT_32 extraXorBits
= 24;
2679 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2680 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2682 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2684 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2685 InitChannel(1, 1, i
, &y
[i
]);
2686 InitChannel(1, 2, i
, &z
[i
]);
2689 if (IsZOrderSwizzle(swMode
))
2691 switch (elementBytesLog2
)
2744 ADDR_ASSERT_ALWAYS();
2745 ret
= ADDR_INVALIDPARAMS
;
2749 else if (IsStandardSwizzle(rsrcType
, swMode
))
2751 switch (elementBytesLog2
)
2804 ADDR_ASSERT_ALWAYS();
2805 ret
= ADDR_INVALIDPARAMS
;
2811 ADDR_ASSERT_ALWAYS();
2812 ret
= ADDR_INVALIDPARAMS
;
2817 Dim3d microBlockDim
= Block1K_3d
[elementBytesLog2
];
2818 UINT_32 xIdx
= Log2(microBlockDim
.w
);
2819 UINT_32 yIdx
= Log2(microBlockDim
.h
);
2820 UINT_32 zIdx
= Log2(microBlockDim
.d
);
2822 pixelBit
= pEquation
->addr
;
2824 const UINT_32 lowBits
= 10;
2825 ADDR_ASSERT(pEquation
->addr
[lowBits
- 1].valid
== 1);
2826 ADDR_ASSERT(pEquation
->addr
[lowBits
].valid
== 0);
2828 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2832 pixelBit
[i
] = x
[xIdx
++];
2834 else if ((i
% 3) == 1)
2836 pixelBit
[i
] = z
[zIdx
++];
2840 pixelBit
[i
] = y
[yIdx
++];
2844 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2848 xorExtra
[i
- blockSizeLog2
] = x
[xIdx
++];
2850 else if ((i
% 3) == 1)
2852 xorExtra
[i
- blockSizeLog2
] = z
[zIdx
++];
2856 xorExtra
[i
- blockSizeLog2
] = y
[yIdx
++];
2863 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2864 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2865 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2867 UINT_32 xor1BitPos
= pipeStart
+ (3 * pipeXorBits
) - 1 - (2 * i
);
2868 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2869 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2871 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2873 UINT_32 xor2BitPos
= pipeStart
+ (3 * pipeXorBits
) - 2 - (2 * i
);
2874 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2875 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2877 InitChannel(&pEquation
->xor2
[pipeStart
+ i
], pXor2Src
);
2880 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2881 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2882 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2884 UINT_32 xor1BitPos
= bankStart
+ (3 * bankXorBits
) - 1 - (2 * i
);
2885 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2886 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2888 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2890 UINT_32 xor2BitPos
= bankStart
+ (3 * bankXorBits
) - 2 - (2 * i
);
2891 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2892 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2894 InitChannel(&pEquation
->xor2
[bankStart
+ i
], pXor2Src
);
2898 pEquation
->numBits
= blockSizeLog2
;
2905 ************************************************************************************************************************
2906 * Gfx9Lib::IsValidDisplaySwizzleMode
2909 * Check if a swizzle mode is supported by display engine
2912 * TRUE is swizzle mode is supported by display engine
2913 ************************************************************************************************************************
2915 BOOL_32
Gfx9Lib::IsValidDisplaySwizzleMode(
2916 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
2918 BOOL_32 support
= FALSE
;
2920 if (m_settings
.isDce12
)
2922 switch (pIn
->swizzleMode
)
2924 case ADDR_SW_256B_D
:
2925 case ADDR_SW_256B_R
:
2926 support
= (pIn
->bpp
== 32);
2929 case ADDR_SW_LINEAR
:
2932 case ADDR_SW_64KB_D
:
2933 case ADDR_SW_64KB_R
:
2934 case ADDR_SW_4KB_D_X
:
2935 case ADDR_SW_4KB_R_X
:
2936 case ADDR_SW_64KB_D_X
:
2937 case ADDR_SW_64KB_R_X
:
2938 support
= (pIn
->bpp
<= 64);
2945 else if (m_settings
.isDcn1
)
2947 switch (pIn
->swizzleMode
)
2950 case ADDR_SW_64KB_D
:
2951 case ADDR_SW_64KB_D_T
:
2952 case ADDR_SW_4KB_D_X
:
2953 case ADDR_SW_64KB_D_X
:
2954 support
= (pIn
->bpp
== 64);
2957 case ADDR_SW_LINEAR
:
2959 case ADDR_SW_64KB_S
:
2960 case ADDR_SW_64KB_S_T
:
2961 case ADDR_SW_4KB_S_X
:
2962 case ADDR_SW_64KB_S_X
:
2963 support
= (pIn
->bpp
<= 64);
2972 ADDR_NOT_IMPLEMENTED();
2979 ************************************************************************************************************************
2980 * Gfx9Lib::HwlComputePipeBankXor
2983 * Generate a PipeBankXor value to be ORed into bits above pipeInterleaveBits of address
2987 ************************************************************************************************************************
2989 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputePipeBankXor(
2990 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
2991 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
) const
2993 if (IsXor(pIn
->swizzleMode
))
2995 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
2996 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
2997 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
2999 UINT_32 pipeXor
= 0;
3000 UINT_32 bankXor
= 0;
3002 const UINT_32 bankMask
= (1 << bankBits
) - 1;
3003 const UINT_32 index
= pIn
->surfIndex
& bankMask
;
3005 const UINT_32 bpp
= pIn
->flags
.fmask
?
3006 GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
) : GetElemLib()->GetBitsPerPixel(pIn
->format
);
3009 static const UINT_32 BankXorSmallBpp
[] = {0, 7, 4, 3, 8, 15, 12, 11, 1, 6, 5, 2, 9, 14, 13, 10};
3010 static const UINT_32 BankXorLargeBpp
[] = {0, 7, 8, 15, 4, 3, 12, 11, 1, 6, 9, 14, 5, 2, 13, 10};
3012 bankXor
= (bpp
<= 32) ? BankXorSmallBpp
[index
] : BankXorLargeBpp
[index
];
3014 else if (bankBits
> 0)
3016 UINT_32 bankIncrease
= (1 << (bankBits
- 1)) - 1;
3017 bankIncrease
= (bankIncrease
== 0) ? 1 : bankIncrease
;
3018 bankXor
= (index
* bankIncrease
) & bankMask
;
3021 pOut
->pipeBankXor
= (bankXor
<< pipeBits
) | pipeXor
;
3025 pOut
->pipeBankXor
= 0;
3032 ************************************************************************************************************************
3033 * Gfx9Lib::HwlComputeSlicePipeBankXor
3036 * Generate slice PipeBankXor value based on base PipeBankXor value and slice id
3040 ************************************************************************************************************************
3042 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSlicePipeBankXor(
3043 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
3044 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
) const
3046 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3047 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3048 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3050 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
3051 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
3053 pOut
->pipeBankXor
= pIn
->basePipeBankXor
^ (pipeXor
| (bankXor
<< pipeBits
));
3059 ************************************************************************************************************************
3060 * Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern
3063 * Compute sub resource offset to support swizzle pattern
3067 ************************************************************************************************************************
3069 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern(
3070 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
3071 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
) const
3073 ADDR_ASSERT(IsThin(pIn
->resourceType
, pIn
->swizzleMode
));
3075 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
3076 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
3077 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
3078 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
3079 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
3080 UINT_32 pipeBankXor
= ((pipeXor
| (bankXor
<< pipeBits
)) ^ (pIn
->pipeBankXor
)) << m_pipeInterleaveLog2
;
3082 pOut
->offset
= pIn
->slice
* pIn
->sliceSize
+
3083 pIn
->macroBlockOffset
+
3084 (pIn
->mipTailOffset
^ pipeBankXor
) -
3085 static_cast<UINT_64
>(pipeBankXor
);
3090 ************************************************************************************************************************
3091 * Gfx9Lib::ValidateNonSwModeParams
3094 * Validate compute surface info params except swizzle mode
3097 * TRUE if parameters are valid, FALSE otherwise
3098 ************************************************************************************************************************
3100 BOOL_32
Gfx9Lib::ValidateNonSwModeParams(
3101 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3103 BOOL_32 valid
= TRUE
;
3105 if ((pIn
->bpp
== 0) || (pIn
->bpp
> 128) || (pIn
->width
== 0) || (pIn
->numFrags
> 8) || (pIn
->numSamples
> 16))
3107 ADDR_ASSERT_ALWAYS();
3111 if (pIn
->resourceType
>= ADDR_RSRC_MAX_TYPE
)
3113 ADDR_ASSERT_ALWAYS();
3117 const BOOL_32 mipmap
= (pIn
->numMipLevels
> 1);
3118 const BOOL_32 msaa
= (pIn
->numFrags
> 1);
3119 const BOOL_32 isBc
= ElemLib::IsBlockCompressed(pIn
->format
);
3121 const AddrResourceType rsrcType
= pIn
->resourceType
;
3122 const BOOL_32 tex3d
= IsTex3d(rsrcType
);
3123 const BOOL_32 tex2d
= IsTex2d(rsrcType
);
3124 const BOOL_32 tex1d
= IsTex1d(rsrcType
);
3126 const ADDR2_SURFACE_FLAGS flags
= pIn
->flags
;
3127 const BOOL_32 zbuffer
= flags
.depth
|| flags
.stencil
;
3128 const BOOL_32 display
= flags
.display
|| flags
.rotated
;
3129 const BOOL_32 stereo
= flags
.qbStereo
;
3130 const BOOL_32 fmask
= flags
.fmask
;
3132 // Resource type check
3135 if (msaa
|| zbuffer
|| display
|| stereo
|| isBc
|| fmask
)
3137 ADDR_ASSERT_ALWAYS();
3143 if ((msaa
&& mipmap
) || (stereo
&& msaa
) || (stereo
&& mipmap
))
3145 ADDR_ASSERT_ALWAYS();
3151 if (msaa
|| zbuffer
|| display
|| stereo
|| fmask
)
3153 ADDR_ASSERT_ALWAYS();
3159 ADDR_ASSERT_ALWAYS();
3167 ************************************************************************************************************************
3168 * Gfx9Lib::ValidateSwModeParams
3171 * Validate compute surface info related to swizzle mode
3174 * TRUE if parameters are valid, FALSE otherwise
3175 ************************************************************************************************************************
3177 BOOL_32
Gfx9Lib::ValidateSwModeParams(
3178 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3180 BOOL_32 valid
= TRUE
;
3182 if ((pIn
->swizzleMode
>= ADDR_SW_MAX_TYPE
) || (IsValidSwMode(pIn
->swizzleMode
) == FALSE
))
3184 ADDR_ASSERT_ALWAYS();
3188 const BOOL_32 mipmap
= (pIn
->numMipLevels
> 1);
3189 const BOOL_32 msaa
= (pIn
->numFrags
> 1);
3190 const BOOL_32 isBc
= ElemLib::IsBlockCompressed(pIn
->format
);
3191 const BOOL_32 is422
= ElemLib::IsMacroPixelPacked(pIn
->format
);
3193 const AddrResourceType rsrcType
= pIn
->resourceType
;
3194 const BOOL_32 tex3d
= IsTex3d(rsrcType
);
3195 const BOOL_32 tex2d
= IsTex2d(rsrcType
);
3196 const BOOL_32 tex1d
= IsTex1d(rsrcType
);
3198 const AddrSwizzleMode swizzle
= pIn
->swizzleMode
;
3199 const BOOL_32 linear
= IsLinear(swizzle
);
3200 const BOOL_32 blk256B
= IsBlock256b(swizzle
);
3201 const BOOL_32 isNonPrtXor
= IsNonPrtXor(swizzle
);
3203 const ADDR2_SURFACE_FLAGS flags
= pIn
->flags
;
3204 const BOOL_32 zbuffer
= flags
.depth
|| flags
.stencil
;
3205 const BOOL_32 color
= flags
.color
;
3206 const BOOL_32 texture
= flags
.texture
;
3207 const BOOL_32 display
= flags
.display
|| flags
.rotated
;
3208 const BOOL_32 prt
= flags
.prt
;
3209 const BOOL_32 fmask
= flags
.fmask
;
3211 const BOOL_32 thin3d
= tex3d
&& flags
.view3dAs2dArray
;
3212 const BOOL_32 zMaxMip
= tex3d
&& mipmap
&&
3213 (pIn
->numSlices
>= pIn
->width
) && (pIn
->numSlices
>= pIn
->height
);
3216 if (msaa
&& (GetBlockSize(swizzle
) < (m_pipeInterleaveBytes
* pIn
->numFrags
)))
3218 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3219 ADDR_ASSERT_ALWAYS();
3223 if (display
&& (IsValidDisplaySwizzleMode(pIn
) == FALSE
))
3225 ADDR_ASSERT_ALWAYS();
3229 if ((pIn
->bpp
== 96) && (linear
== FALSE
))
3231 ADDR_ASSERT_ALWAYS();
3235 if (prt
&& isNonPrtXor
)
3237 ADDR_ASSERT_ALWAYS();
3241 // Resource type check
3244 if (linear
== FALSE
)
3246 ADDR_ASSERT_ALWAYS();
3251 // Swizzle type check
3254 if (((tex1d
== FALSE
) && prt
) || zbuffer
|| msaa
|| (pIn
->bpp
== 0) ||
3255 ((pIn
->bpp
% 8) != 0) || (isBc
&& texture
) || fmask
)
3257 ADDR_ASSERT_ALWAYS();
3261 else if (IsZOrderSwizzle(swizzle
))
3263 if ((color
&& msaa
) || thin3d
|| isBc
|| is422
|| (tex2d
&& (pIn
->bpp
> 64)) || (msaa
&& (pIn
->bpp
> 32)))
3265 ADDR_ASSERT_ALWAYS();
3269 else if (IsStandardSwizzle(swizzle
))
3271 if (zbuffer
|| thin3d
|| (tex3d
&& (pIn
->bpp
== 128) && color
) || fmask
)
3273 ADDR_ASSERT_ALWAYS();
3277 else if (IsDisplaySwizzle(swizzle
))
3279 if (zbuffer
|| (prt
&& tex3d
) || fmask
|| zMaxMip
)
3281 ADDR_ASSERT_ALWAYS();
3285 else if (IsRotateSwizzle(swizzle
))
3287 if (zbuffer
|| (pIn
->bpp
> 64) || tex3d
|| isBc
|| fmask
)
3289 ADDR_ASSERT_ALWAYS();
3295 ADDR_ASSERT_ALWAYS();
3302 if (prt
|| zbuffer
|| tex3d
|| mipmap
|| msaa
)
3304 ADDR_ASSERT_ALWAYS();
3313 ************************************************************************************************************************
3314 * Gfx9Lib::HwlComputeSurfaceInfoSanityCheck
3317 * Compute surface info sanity check
3320 * ADDR_OK if parameters are valid, ADDR_INVALIDPARAMS otherwise
3321 ************************************************************************************************************************
3323 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoSanityCheck(
3324 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
3326 return ValidateNonSwModeParams(pIn
) && ValidateSwModeParams(pIn
) ? ADDR_OK
: ADDR_INVALIDPARAMS
;
3330 ************************************************************************************************************************
3331 * Gfx9Lib::HwlGetPreferredSurfaceSetting
3334 * Internal function to get suggested surface information for cliet to use
3338 ************************************************************************************************************************
3340 ADDR_E_RETURNCODE
Gfx9Lib::HwlGetPreferredSurfaceSetting(
3341 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
3342 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const
3344 ADDR_E_RETURNCODE returnCode
= ADDR_INVALIDPARAMS
;
3345 ElemLib
* pElemLib
= GetElemLib();
3347 UINT_32 bpp
= pIn
->bpp
;
3348 UINT_32 width
= Max(pIn
->width
, 1u);
3349 UINT_32 height
= Max(pIn
->height
, 1u);
3350 UINT_32 numSamples
= Max(pIn
->numSamples
, 1u);
3351 UINT_32 numFrags
= (pIn
->numFrags
== 0) ? numSamples
: pIn
->numFrags
;
3353 if (pIn
->flags
.fmask
)
3355 bpp
= GetFmaskBpp(numSamples
, numFrags
);
3358 pOut
->resourceType
= ADDR_RSRC_TEX_2D
;
3362 // Set format to INVALID will skip this conversion
3363 if (pIn
->format
!= ADDR_FMT_INVALID
)
3365 UINT_32 expandX
, expandY
;
3367 // Don't care for this case
3368 ElemMode elemMode
= ADDR_UNCOMPRESSED
;
3370 // Get compression/expansion factors and element mode which indicates compression/expansion
3371 bpp
= pElemLib
->GetBitsPerPixel(pIn
->format
,
3376 UINT_32 basePitch
= 0;
3377 GetElemLib()->AdjustSurfaceInfo(elemMode
,
3386 // The output may get changed for volume(3D) texture resource in future
3387 pOut
->resourceType
= pIn
->resourceType
;
3390 const UINT_32 numSlices
= Max(pIn
->numSlices
, 1u);
3391 const UINT_32 numMipLevels
= Max(pIn
->numMipLevels
, 1u);
3392 const BOOL_32 msaa
= (numFrags
> 1) || (numSamples
> 1);
3393 const BOOL_32 displayRsrc
= pIn
->flags
.display
|| pIn
->flags
.rotated
;
3395 // Pre sanity check on non swizzle mode parameters
3396 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {};
3397 localIn
.flags
= pIn
->flags
;
3398 localIn
.resourceType
= pOut
->resourceType
;
3399 localIn
.format
= pIn
->format
;
3401 localIn
.width
= width
;
3402 localIn
.height
= height
;
3403 localIn
.numSlices
= numSlices
;
3404 localIn
.numMipLevels
= numMipLevels
;
3405 localIn
.numSamples
= numSamples
;
3406 localIn
.numFrags
= numFrags
;
3408 if (ValidateNonSwModeParams(&localIn
))
3410 // Forbid swizzle mode(s) by client setting
3411 ADDR2_SWMODE_SET allowedSwModeSet
= {};
3412 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.linear
? 0 : Gfx9LinearSwModeMask
;
3413 allowedSwModeSet
.value
|= pIn
->forbiddenBlock
.micro
? 0 : Gfx9Blk256BSwModeMask
;
3414 allowedSwModeSet
.value
|=
3415 pIn
->forbiddenBlock
.macroThin4KB
? 0 :
3416 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThin4KBSwModeMask
: Gfx9Blk4KBSwModeMask
);
3417 allowedSwModeSet
.value
|=
3418 pIn
->forbiddenBlock
.macroThick4KB
? 0 :
3419 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThick4KBSwModeMask
: 0);
3420 allowedSwModeSet
.value
|=
3421 pIn
->forbiddenBlock
.macroThin64KB
? 0 :
3422 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThin64KBSwModeMask
: Gfx9Blk64KBSwModeMask
);
3423 allowedSwModeSet
.value
|=
3424 pIn
->forbiddenBlock
.macroThick64KB
? 0 :
3425 ((pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ? Gfx9Rsrc3dThick64KBSwModeMask
: 0);
3427 if (pIn
->preferredSwSet
.value
!= 0)
3429 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_Z
? ~0 : ~Gfx9ZSwModeMask
;
3430 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_S
? ~0 : ~Gfx9StandardSwModeMask
;
3431 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_D
? ~0 : ~Gfx9DisplaySwModeMask
;
3432 allowedSwModeSet
.value
&= pIn
->preferredSwSet
.sw_R
? ~0 : ~Gfx9RotateSwModeMask
;
3437 allowedSwModeSet
.value
&= ~Gfx9XorSwModeMask
;
3440 if (pIn
->maxAlign
> 0)
3442 if (pIn
->maxAlign
< Size64K
)
3444 allowedSwModeSet
.value
&= ~Gfx9Blk64KBSwModeMask
;
3447 if (pIn
->maxAlign
< Size4K
)
3449 allowedSwModeSet
.value
&= ~Gfx9Blk4KBSwModeMask
;
3452 if (pIn
->maxAlign
< Size256
)
3454 allowedSwModeSet
.value
&= ~Gfx9Blk256BSwModeMask
;
3458 // Filter out invalid swizzle mode(s) by image attributes and HW restrictions
3459 switch (pOut
->resourceType
)
3461 case ADDR_RSRC_TEX_1D
:
3462 allowedSwModeSet
.value
&= Gfx9Rsrc1dSwModeMask
;
3465 case ADDR_RSRC_TEX_2D
:
3466 allowedSwModeSet
.value
&= pIn
->flags
.prt
? Gfx9Rsrc2dPrtSwModeMask
: Gfx9Rsrc2dSwModeMask
;
3470 allowedSwModeSet
.value
&= ~(Gfx9RotateSwModeMask
| Gfx9ZSwModeMask
);
3474 case ADDR_RSRC_TEX_3D
:
3475 allowedSwModeSet
.value
&= pIn
->flags
.prt
? Gfx9Rsrc3dPrtSwModeMask
: Gfx9Rsrc3dSwModeMask
;
3477 if ((numMipLevels
> 1) && (numSlices
>= width
) && (numSlices
>= height
))
3479 // SW_*_D for 3D mipmaps (maxmip > 0) is only supported for Xmajor or Ymajor mipmap
3480 // When depth (Z) is the maximum dimension then must use one of the SW_*_S
3481 // or SW_*_Z modes if mipmapping is desired on a 3D surface
3482 allowedSwModeSet
.value
&= ~Gfx9DisplaySwModeMask
;
3485 if ((bpp
== 128) && pIn
->flags
.color
)
3487 allowedSwModeSet
.value
&= ~Gfx9StandardSwModeMask
;
3490 if (pIn
->flags
.view3dAs2dArray
)
3492 allowedSwModeSet
.value
&= Gfx9Rsrc3dThinSwModeMask
| Gfx9LinearSwModeMask
;
3497 ADDR_ASSERT_ALWAYS();
3498 allowedSwModeSet
.value
= 0;
3502 if (pIn
->format
== ADDR_FMT_32_32_32
)
3504 allowedSwModeSet
.value
&= Gfx9LinearSwModeMask
;
3507 if (ElemLib::IsBlockCompressed(pIn
->format
))
3509 if (pIn
->flags
.texture
)
3511 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
| Gfx9DisplaySwModeMask
;
3515 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
| Gfx9DisplaySwModeMask
| Gfx9LinearSwModeMask
;
3519 if (ElemLib::IsMacroPixelPacked(pIn
->format
) ||
3520 (msaa
&& ((bpp
> 32) || pIn
->flags
.color
|| pIn
->flags
.unordered
)))
3522 allowedSwModeSet
.value
&= ~Gfx9ZSwModeMask
;
3525 if (pIn
->flags
.fmask
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
)
3527 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3529 if (pIn
->flags
.noMetadata
== FALSE
)
3531 if (pIn
->flags
.depth
&&
3532 pIn
->flags
.texture
&&
3533 (((bpp
== 16) && (numFrags
>= 4)) || ((bpp
== 32) && (numFrags
>= 2))))
3535 // When _X/_T swizzle mode was used for MSAA depth texture, TC will get zplane
3536 // equation from wrong address within memory range a tile covered and use the
3537 // garbage data for compressed Z reading which finally leads to corruption.
3538 allowedSwModeSet
.value
&= ~Gfx9XorSwModeMask
;
3541 if (m_settings
.htileCacheRbConflict
&&
3542 (pIn
->flags
.depth
|| pIn
->flags
.stencil
) &&
3544 (pIn
->flags
.metaRbUnaligned
== FALSE
) &&
3545 (pIn
->flags
.metaPipeUnaligned
== FALSE
))
3547 // Z_X 2D array with Rb/Pipe aligned HTile won't have metadata cache coherency
3548 allowedSwModeSet
.value
&= ~Gfx9XSwModeMask
;
3555 allowedSwModeSet
.value
&= Gfx9MsaaSwModeMask
;
3558 if ((numFrags
> 1) &&
3559 (Size4K
< (m_pipeInterleaveBytes
* numFrags
)))
3561 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3562 allowedSwModeSet
.value
&= Gfx9Blk64KBSwModeMask
;
3565 if (numMipLevels
> 1)
3567 allowedSwModeSet
.value
&= ~Gfx9Blk256BSwModeMask
;
3572 if (m_settings
.isDce12
)
3574 allowedSwModeSet
.value
&= (bpp
== 32) ? Dce12Bpp32SwModeMask
: Dce12NonBpp32SwModeMask
;
3576 else if (m_settings
.isDcn1
)
3578 allowedSwModeSet
.value
&= (bpp
== 64) ? Dcn1Bpp64SwModeMask
: Dcn1NonBpp64SwModeMask
;
3582 ADDR_NOT_IMPLEMENTED();
3586 if (allowedSwModeSet
.value
!= 0)
3589 // Post sanity check, at least AddrLib should accept the output generated by its own
3590 UINT_32 validateSwModeSet
= allowedSwModeSet
.value
;
3592 for (UINT_32 i
= 0; validateSwModeSet
!= 0; i
++)
3594 if (validateSwModeSet
& 1)
3596 localIn
.swizzleMode
= static_cast<AddrSwizzleMode
>(i
);
3597 ADDR_ASSERT(ValidateSwModeParams(&localIn
));
3600 validateSwModeSet
>>= 1;
3604 pOut
->validSwModeSet
= allowedSwModeSet
;
3605 pOut
->canXor
= (allowedSwModeSet
.value
& Gfx9XorSwModeMask
) ? TRUE
: FALSE
;
3606 pOut
->validBlockSet
= GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
);
3607 pOut
->validSwTypeSet
= GetAllowedSwSet(allowedSwModeSet
);
3609 pOut
->clientPreferredSwSet
= pIn
->preferredSwSet
;
3611 if (pOut
->clientPreferredSwSet
.value
== 0)
3613 pOut
->clientPreferredSwSet
.value
= AddrSwSetAll
;
3616 // Apply optional restrictions
3617 if (pIn
->flags
.needEquation
)
3619 FilterInvalidEqSwizzleMode(allowedSwModeSet
, pIn
->resourceType
, Log2(bpp
>> 3));
3622 if (allowedSwModeSet
.value
== Gfx9LinearSwModeMask
)
3624 pOut
->swizzleMode
= ADDR_SW_LINEAR
;
3628 // Always ignore linear swizzle mode if there is other choice.
3629 allowedSwModeSet
.swLinear
= 0;
3631 ADDR2_BLOCK_SET allowedBlockSet
= GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
);
3633 // Determine block size if there is 2 or more block type candidates
3634 if (IsPow2(allowedBlockSet
.value
) == FALSE
)
3636 AddrSwizzleMode swMode
[AddrBlockMaxTiledType
] = { ADDR_SW_LINEAR
};
3638 swMode
[AddrBlockMicro
] = ADDR_SW_256B_D
;
3639 swMode
[AddrBlockThin4KB
] = ADDR_SW_4KB_D
;
3640 swMode
[AddrBlockThin64KB
] = ADDR_SW_64KB_D
;
3642 if (pOut
->resourceType
== ADDR_RSRC_TEX_3D
)
3644 swMode
[AddrBlockThick4KB
] = ADDR_SW_4KB_S
;
3645 swMode
[AddrBlockThick64KB
] = ADDR_SW_64KB_S
;
3648 Dim3d blkDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}, {0}, {0}, {0}};
3649 Dim3d padDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}, {0}, {0}, {0}};
3650 UINT_64 padSize
[AddrBlockMaxTiledType
] = {0};
3652 const UINT_32 ratioLow
= pIn
->flags
.minimizeAlign
? 1 : (pIn
->flags
.opt4space
? 3 : 2);
3653 const UINT_32 ratioHi
= pIn
->flags
.minimizeAlign
? 1 : (pIn
->flags
.opt4space
? 2 : 1);
3654 const UINT_64 sizeAlignInElement
= Max(NextPow2(pIn
->minSizeAlign
) / (bpp
>> 3), 1u);
3655 UINT_32 minSizeBlk
= AddrBlockMicro
;
3656 UINT_64 minSize
= 0;
3658 for (UINT_32 i
= AddrBlockMicro
; i
< AddrBlockMaxTiledType
; i
++)
3660 if (allowedBlockSet
.value
& (1 << i
))
3662 ComputeBlockDimensionForSurf(&blkDim
[i
].w
,
3672 blkDim
[i
].w
= PowTwoAlign(blkDim
[i
].w
, 32);
3675 padSize
[i
] = ComputePadSize(&blkDim
[i
], width
, height
, numSlices
, &padDim
[i
]);
3676 padSize
[i
] = PowTwoAlign(padSize
[i
] * numFrags
, sizeAlignInElement
);
3678 if ((minSize
== 0) ||
3679 ((padSize
[i
] * ratioHi
) <= (minSize
* ratioLow
)))
3681 minSize
= padSize
[i
];
3687 if ((allowedBlockSet
.micro
== TRUE
) &&
3688 (width
<= blkDim
[AddrBlockMicro
].w
) &&
3689 (height
<= blkDim
[AddrBlockMicro
].h
) &&
3690 (NextPow2(pIn
->minSizeAlign
) <= Size256
))
3692 minSizeBlk
= AddrBlockMicro
;
3695 if (minSizeBlk
== AddrBlockMicro
)
3697 ADDR_ASSERT(pOut
->resourceType
!= ADDR_RSRC_TEX_3D
);
3698 allowedSwModeSet
.value
&= Gfx9Blk256BSwModeMask
;
3700 else if (minSizeBlk
== AddrBlockThick4KB
)
3702 ADDR_ASSERT(pOut
->resourceType
== ADDR_RSRC_TEX_3D
);
3703 allowedSwModeSet
.value
&= Gfx9Rsrc3dThick4KBSwModeMask
;
3705 else if (minSizeBlk
== AddrBlockThin4KB
)
3707 allowedSwModeSet
.value
&= (pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ?
3708 Gfx9Rsrc3dThin4KBSwModeMask
: Gfx9Blk4KBSwModeMask
;
3710 else if (minSizeBlk
== AddrBlockThick64KB
)
3712 ADDR_ASSERT(pOut
->resourceType
== ADDR_RSRC_TEX_3D
);
3713 allowedSwModeSet
.value
&= Gfx9Rsrc3dThick64KBSwModeMask
;
3717 ADDR_ASSERT(minSizeBlk
== AddrBlockThin64KB
);
3718 allowedSwModeSet
.value
&= (pOut
->resourceType
== ADDR_RSRC_TEX_3D
) ?
3719 Gfx9Rsrc3dThin64KBSwModeMask
: Gfx9Blk64KBSwModeMask
;
3723 // Block type should be determined.
3724 ADDR_ASSERT(IsPow2(GetAllowedBlockSet(allowedSwModeSet
, pOut
->resourceType
).value
));
3726 ADDR2_SWTYPE_SET allowedSwSet
= GetAllowedSwSet(allowedSwModeSet
);
3728 // Determine swizzle type if there is 2 or more swizzle type candidates
3729 if (IsPow2(allowedSwSet
.value
) == FALSE
)
3731 if (ElemLib::IsBlockCompressed(pIn
->format
))
3733 if (allowedSwSet
.sw_D
)
3735 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3739 ADDR_ASSERT(allowedSwSet
.sw_S
);
3740 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3743 else if (ElemLib::IsMacroPixelPacked(pIn
->format
))
3745 if (allowedSwSet
.sw_S
)
3747 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3749 else if (allowedSwSet
.sw_D
)
3751 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3755 ADDR_ASSERT(allowedSwSet
.sw_R
);
3756 allowedSwModeSet
.value
&= Gfx9RotateSwModeMask
;
3759 else if (pOut
->resourceType
== ADDR_RSRC_TEX_3D
)
3761 if (pIn
->flags
.color
&& allowedSwSet
.sw_D
)
3763 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3765 else if (allowedSwSet
.sw_Z
)
3767 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3771 ADDR_ASSERT(allowedSwSet
.sw_S
);
3772 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3777 if (pIn
->flags
.rotated
&& allowedSwSet
.sw_R
)
3779 allowedSwModeSet
.value
&= Gfx9RotateSwModeMask
;
3781 else if (allowedSwSet
.sw_D
)
3783 allowedSwModeSet
.value
&= Gfx9DisplaySwModeMask
;
3785 else if (allowedSwSet
.sw_S
)
3787 allowedSwModeSet
.value
&= Gfx9StandardSwModeMask
;
3791 ADDR_ASSERT(allowedSwSet
.sw_Z
);
3792 allowedSwModeSet
.value
&= Gfx9ZSwModeMask
;
3797 // Swizzle type should be determined.
3798 ADDR_ASSERT(IsPow2(GetAllowedSwSet(allowedSwModeSet
).value
));
3800 // Determine swizzle mode now. Always select the "largest" swizzle mode for a given block type + swizzle
3801 // type combination. For example, for AddrBlockThin64KB + ADDR_SW_S, select SW_64KB_S_X(25) if it's
3802 // available, or otherwise select SW_64KB_S_T(17) if it's available, or otherwise select SW_64KB_S(9).
3803 pOut
->swizzleMode
= static_cast<AddrSwizzleMode
>(Log2NonPow2(allowedSwModeSet
.value
));
3806 returnCode
= ADDR_OK
;
3810 // Invalid combination...
3811 ADDR_ASSERT_ALWAYS();
3816 // Invalid combination...
3817 ADDR_ASSERT_ALWAYS();
3824 ************************************************************************************************************************
3825 * Gfx9Lib::ComputeStereoInfo
3828 * Compute height alignment and right eye pipeBankXor for stereo surface
3833 ************************************************************************************************************************
3835 ADDR_E_RETURNCODE
Gfx9Lib::ComputeStereoInfo(
3836 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
3837 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
,
3838 UINT_32
* pHeightAlign
3841 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3843 UINT_32 eqIndex
= HwlGetEquationIndex(pIn
, pOut
);
3845 if (eqIndex
< m_numEquations
)
3847 if (IsXor(pIn
->swizzleMode
))
3849 const UINT_32 blkSizeLog2
= GetBlockSizeLog2(pIn
->swizzleMode
);
3850 const UINT_32 numPipeBits
= GetPipeXorBits(blkSizeLog2
);
3851 const UINT_32 numBankBits
= GetBankXorBits(blkSizeLog2
);
3852 const UINT_32 bppLog2
= Log2(pIn
->bpp
>> 3);
3853 const UINT_32 maxYCoordBlock256
= Log2(Block256_2d
[bppLog2
].h
) - 1;
3854 const ADDR_EQUATION
*pEqToCheck
= &m_equationTable
[eqIndex
];
3856 ADDR_ASSERT(maxYCoordBlock256
==
3857 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], Log2Size256
, 1));
3859 const UINT_32 maxYCoordInBaseEquation
=
3860 (blkSizeLog2
- Log2Size256
) / 2 + maxYCoordBlock256
;
3862 ADDR_ASSERT(maxYCoordInBaseEquation
==
3863 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], blkSizeLog2
, 1));
3865 const UINT_32 maxYCoordInPipeXor
= (numPipeBits
== 0) ? 0 : maxYCoordBlock256
+ numPipeBits
;
3867 ADDR_ASSERT(maxYCoordInPipeXor
==
3868 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
], numPipeBits
, 1));
3870 const UINT_32 maxYCoordInBankXor
= (numBankBits
== 0) ?
3871 0 : maxYCoordBlock256
+ (numPipeBits
+ 1) / 2 + numBankBits
;
3873 ADDR_ASSERT(maxYCoordInBankXor
==
3874 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
+ numPipeBits
], numBankBits
, 1));
3876 const UINT_32 maxYCoordInPipeBankXor
= Max(maxYCoordInPipeXor
, maxYCoordInBankXor
);
3878 if (maxYCoordInPipeBankXor
> maxYCoordInBaseEquation
)
3880 *pHeightAlign
= 1u << maxYCoordInPipeBankXor
;
3882 if (pOut
->pStereoInfo
!= NULL
)
3884 pOut
->pStereoInfo
->rightSwizzle
= 0;
3886 if ((PowTwoAlign(pIn
->height
, *pHeightAlign
) % (*pHeightAlign
* 2)) != 0)
3888 if (maxYCoordInPipeXor
== maxYCoordInPipeBankXor
)
3890 pOut
->pStereoInfo
->rightSwizzle
|= (1u << 1);
3893 if (maxYCoordInBankXor
== maxYCoordInPipeBankXor
)
3895 pOut
->pStereoInfo
->rightSwizzle
|=
3896 1u << ((numPipeBits
% 2) ? numPipeBits
: numPipeBits
+ 1);
3899 ADDR_ASSERT(pOut
->pStereoInfo
->rightSwizzle
==
3900 GetCoordActiveMask(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
],
3901 numPipeBits
+ numBankBits
, 1, maxYCoordInPipeBankXor
));
3909 ADDR_ASSERT_ALWAYS();
3910 returnCode
= ADDR_ERROR
;
3917 ************************************************************************************************************************
3918 * Gfx9Lib::HwlComputeSurfaceInfoTiled
3921 * Internal function to calculate alignment for tiled surface
3925 ************************************************************************************************************************
3927 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoTiled(
3928 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
3929 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
3932 ADDR_E_RETURNCODE returnCode
= ComputeBlockDimensionForSurf(&pOut
->blockWidth
,
3940 if (returnCode
== ADDR_OK
)
3942 UINT_32 pitchAlignInElement
= pOut
->blockWidth
;
3944 if ((IsTex2d(pIn
->resourceType
) == TRUE
) &&
3945 (pIn
->flags
.display
|| pIn
->flags
.rotated
) &&
3946 (pIn
->numMipLevels
<= 1) &&
3947 (pIn
->numSamples
<= 1) &&
3948 (pIn
->numFrags
<= 1))
3950 // Display engine needs pitch align to be at least 32 pixels.
3951 pitchAlignInElement
= PowTwoAlign(pitchAlignInElement
, 32);
3954 pOut
->pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
3956 if ((pIn
->numMipLevels
<= 1) && (pIn
->pitchInElement
> 0))
3958 if ((pIn
->pitchInElement
% pitchAlignInElement
) != 0)
3960 returnCode
= ADDR_INVALIDPARAMS
;
3962 else if (pIn
->pitchInElement
< pOut
->pitch
)
3964 returnCode
= ADDR_INVALIDPARAMS
;
3968 pOut
->pitch
= pIn
->pitchInElement
;
3972 UINT_32 heightAlign
= 0;
3974 if (pIn
->flags
.qbStereo
)
3976 returnCode
= ComputeStereoInfo(pIn
, pOut
, &heightAlign
);
3979 if (returnCode
== ADDR_OK
)
3981 pOut
->height
= PowTwoAlign(pIn
->height
, pOut
->blockHeight
);
3983 if (heightAlign
> 1)
3985 pOut
->height
= PowTwoAlign(pOut
->height
, heightAlign
);
3988 pOut
->numSlices
= PowTwoAlign(pIn
->numSlices
, pOut
->blockSlices
);
3990 pOut
->epitchIsHeight
= FALSE
;
3991 pOut
->mipChainInTail
= FALSE
;
3992 pOut
->firstMipIdInTail
= pIn
->numMipLevels
;
3994 pOut
->mipChainPitch
= pOut
->pitch
;
3995 pOut
->mipChainHeight
= pOut
->height
;
3996 pOut
->mipChainSlice
= pOut
->numSlices
;
3998 if (pIn
->numMipLevels
> 1)
4000 pOut
->firstMipIdInTail
= GetMipChainInfo(pIn
->resourceType
,
4012 const UINT_32 endingMipId
= Min(pOut
->firstMipIdInTail
, pIn
->numMipLevels
- 1);
4014 if (endingMipId
== 0)
4016 const Dim3d tailMaxDim
= GetMipTailDim(pIn
->resourceType
,
4022 pOut
->epitchIsHeight
= TRUE
;
4023 pOut
->pitch
= tailMaxDim
.w
;
4024 pOut
->height
= tailMaxDim
.h
;
4025 pOut
->numSlices
= IsThick(pIn
->resourceType
, pIn
->swizzleMode
) ?
4026 tailMaxDim
.d
: pIn
->numSlices
;
4027 pOut
->mipChainInTail
= TRUE
;
4031 UINT_32 mip0WidthInBlk
= pOut
->pitch
/ pOut
->blockWidth
;
4032 UINT_32 mip0HeightInBlk
= pOut
->height
/ pOut
->blockHeight
;
4034 AddrMajorMode majorMode
= GetMajorMode(pIn
->resourceType
,
4038 pOut
->numSlices
/ pOut
->blockSlices
);
4039 if (majorMode
== ADDR_MAJOR_Y
)
4041 UINT_32 mip1WidthInBlk
= RoundHalf(mip0WidthInBlk
);
4043 if ((mip1WidthInBlk
== 1) && (endingMipId
> 2))
4048 pOut
->mipChainPitch
+= (mip1WidthInBlk
* pOut
->blockWidth
);
4050 pOut
->epitchIsHeight
= FALSE
;
4054 UINT_32 mip1HeightInBlk
= RoundHalf(mip0HeightInBlk
);
4056 if ((mip1HeightInBlk
== 1) && (endingMipId
> 2))
4061 pOut
->mipChainHeight
+= (mip1HeightInBlk
* pOut
->blockHeight
);
4063 pOut
->epitchIsHeight
= TRUE
;
4067 if (pOut
->pMipInfo
!= NULL
)
4069 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
4071 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4073 Dim3d mipStartPos
= {0};
4074 UINT_32 mipTailOffsetInBytes
= 0;
4076 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
4086 &mipTailOffsetInBytes
);
4088 UINT_32 pitchInBlock
=
4089 pOut
->mipChainPitch
/ pOut
->blockWidth
;
4090 UINT_32 sliceInBlock
=
4091 (pOut
->mipChainHeight
/ pOut
->blockHeight
) * pitchInBlock
;
4092 UINT_64 blockIndex
=
4093 mipStartPos
.d
* sliceInBlock
+ mipStartPos
.h
* pitchInBlock
+ mipStartPos
.w
;
4094 UINT_64 macroBlockOffset
=
4095 blockIndex
<< GetBlockSizeLog2(pIn
->swizzleMode
);
4097 pOut
->pMipInfo
[i
].macroBlockOffset
= macroBlockOffset
;
4098 pOut
->pMipInfo
[i
].mipTailOffset
= mipTailOffsetInBytes
;
4102 else if (pOut
->pMipInfo
!= NULL
)
4104 pOut
->pMipInfo
[0].pitch
= pOut
->pitch
;
4105 pOut
->pMipInfo
[0].height
= pOut
->height
;
4106 pOut
->pMipInfo
[0].depth
= IsTex3d(pIn
->resourceType
)? pOut
->numSlices
: 1;
4107 pOut
->pMipInfo
[0].offset
= 0;
4110 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->mipChainPitch
) * pOut
->mipChainHeight
*
4111 (pIn
->bpp
>> 3) * pIn
->numFrags
;
4112 pOut
->surfSize
= pOut
->sliceSize
* pOut
->mipChainSlice
;
4113 pOut
->baseAlign
= ComputeSurfaceBaseAlignTiled(pIn
->swizzleMode
);
4115 if ((IsBlock256b(pIn
->swizzleMode
) == FALSE
) &&
4116 (pIn
->flags
.color
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
|| pIn
->flags
.fmask
) &&
4117 (pIn
->flags
.texture
== TRUE
) &&
4118 (pIn
->flags
.noMetadata
== FALSE
) &&
4119 (pIn
->flags
.metaPipeUnaligned
== FALSE
))
4121 // Assume client requires pipe aligned metadata, which is TcCompatible and will be accessed by TC...
4122 // Then we need extra padding for base surface. Otherwise, metadata and data surface for same pixel will
4123 // be flushed to different pipes, but texture engine only uses pipe id of data surface to fetch both of
4124 // them, which may cause invalid metadata to be fetched.
4125 pOut
->baseAlign
= Max(pOut
->baseAlign
, m_pipeInterleaveBytes
* m_pipes
* m_se
);
4130 pOut
->baseAlign
= Max(pOut
->baseAlign
, PrtAlignment
);
4139 ************************************************************************************************************************
4140 * Gfx9Lib::HwlComputeSurfaceInfoLinear
4143 * Internal function to calculate alignment for linear surface
4147 ************************************************************************************************************************
4149 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoLinear(
4150 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
4151 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
4154 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
4156 UINT_32 actualHeight
= 0;
4157 UINT_32 elementBytes
= pIn
->bpp
>> 3;
4158 const UINT_32 alignment
= pIn
->flags
.prt
? PrtAlignment
: 256;
4160 if (IsTex1d(pIn
->resourceType
))
4162 if (pIn
->height
> 1)
4164 returnCode
= ADDR_INVALIDPARAMS
;
4168 const UINT_32 pitchAlignInElement
= alignment
/ elementBytes
;
4170 pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
4171 actualHeight
= pIn
->numMipLevels
;
4173 if (pIn
->flags
.prt
== FALSE
)
4175 returnCode
= ApplyCustomizedPitchHeight(pIn
, elementBytes
, pitchAlignInElement
,
4176 &pitch
, &actualHeight
);
4179 if (returnCode
== ADDR_OK
)
4181 if (pOut
->pMipInfo
!= NULL
)
4183 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4185 pOut
->pMipInfo
[i
].offset
= pitch
* elementBytes
* i
;
4186 pOut
->pMipInfo
[i
].pitch
= pitch
;
4187 pOut
->pMipInfo
[i
].height
= 1;
4188 pOut
->pMipInfo
[i
].depth
= 1;
4196 returnCode
= ComputeSurfaceLinearPadding(pIn
, &pitch
, &actualHeight
, pOut
->pMipInfo
);
4199 if ((pitch
== 0) || (actualHeight
== 0))
4201 returnCode
= ADDR_INVALIDPARAMS
;
4204 if (returnCode
== ADDR_OK
)
4206 pOut
->pitch
= pitch
;
4207 pOut
->height
= pIn
->height
;
4208 pOut
->numSlices
= pIn
->numSlices
;
4209 pOut
->mipChainPitch
= pitch
;
4210 pOut
->mipChainHeight
= actualHeight
;
4211 pOut
->mipChainSlice
= pOut
->numSlices
;
4212 pOut
->epitchIsHeight
= (pIn
->numMipLevels
> 1) ? TRUE
: FALSE
;
4213 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->pitch
) * actualHeight
* elementBytes
;
4214 pOut
->surfSize
= pOut
->sliceSize
* pOut
->numSlices
;
4215 pOut
->baseAlign
= (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
) ? (pIn
->bpp
/ 8) : alignment
;
4216 pOut
->blockWidth
= (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
) ? 1 : (256 / elementBytes
);
4217 pOut
->blockHeight
= 1;
4218 pOut
->blockSlices
= 1;
4221 // Post calculation validate
4222 ADDR_ASSERT(pOut
->sliceSize
> 0);
4228 ************************************************************************************************************************
4229 * Gfx9Lib::GetMipChainInfo
4232 * Internal function to get out information about mip chain
4235 * Smaller value between Id of first mip fitted in mip tail and max Id of mip being created
4236 ************************************************************************************************************************
4238 UINT_32
Gfx9Lib::GetMipChainInfo(
4239 AddrResourceType resourceType
,
4240 AddrSwizzleMode swizzleMode
,
4246 UINT_32 blockHeight
,
4248 UINT_32 numMipLevel
,
4249 ADDR2_MIP_INFO
* pMipInfo
) const
4251 const Dim3d tailMaxDim
=
4252 GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4254 UINT_32 mipPitch
= mip0Width
;
4255 UINT_32 mipHeight
= mip0Height
;
4256 UINT_32 mipDepth
= IsTex3d(resourceType
) ? mip0Depth
: 1;
4258 UINT_32 firstMipIdInTail
= numMipLevel
;
4259 BOOL_32 inTail
= FALSE
;
4260 BOOL_32 finalDim
= FALSE
;
4261 BOOL_32 is3dThick
= IsThick(resourceType
, swizzleMode
);
4262 BOOL_32 is3dThin
= IsTex3d(resourceType
) && (is3dThick
== FALSE
);
4264 for (UINT_32 mipId
= 0; mipId
< numMipLevel
; mipId
++)
4268 if (finalDim
== FALSE
)
4274 mipSize
= mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3);
4278 mipSize
= mipPitch
* mipHeight
* (bpp
>> 3);
4283 UINT_32 index
= Log2(bpp
>> 3);
4287 mipPitch
= Block256_3dZ
[index
].w
;
4288 mipHeight
= Block256_3dZ
[index
].h
;
4289 mipDepth
= Block256_3dZ
[index
].d
;
4293 mipPitch
= Block256_2d
[index
].w
;
4294 mipHeight
= Block256_2d
[index
].h
;
4303 inTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
,
4304 mipPitch
, mipHeight
, mipDepth
);
4308 firstMipIdInTail
= mipId
;
4309 mipPitch
= tailMaxDim
.w
;
4310 mipHeight
= tailMaxDim
.h
;
4314 mipDepth
= tailMaxDim
.d
;
4319 mipPitch
= PowTwoAlign(mipPitch
, blockWidth
);
4320 mipHeight
= PowTwoAlign(mipHeight
, blockHeight
);
4324 mipDepth
= PowTwoAlign(mipDepth
, blockDepth
);
4329 if (pMipInfo
!= NULL
)
4331 pMipInfo
[mipId
].pitch
= mipPitch
;
4332 pMipInfo
[mipId
].height
= mipHeight
;
4333 pMipInfo
[mipId
].depth
= mipDepth
;
4334 pMipInfo
[mipId
].offset
= offset
;
4337 offset
+= (mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3));
4343 mipDepth
= Max(mipDepth
>> 1, 1u);
4348 mipPitch
= Max(mipPitch
>> 1, 1u);
4349 mipHeight
= Max(mipHeight
>> 1, 1u);
4351 if (is3dThick
|| is3dThin
)
4353 mipDepth
= Max(mipDepth
>> 1, 1u);
4358 return firstMipIdInTail
;
4362 ************************************************************************************************************************
4363 * Gfx9Lib::GetMetaMiptailInfo
4366 * Get mip tail coordinate information.
4370 ************************************************************************************************************************
4372 VOID
Gfx9Lib::GetMetaMiptailInfo(
4373 ADDR2_META_MIP_INFO
* pInfo
, ///< [out] output structure to store per mip coord
4374 Dim3d mipCoord
, ///< [in] mip tail base coord
4375 UINT_32 numMipInTail
, ///< [in] number of mips in tail
4376 Dim3d
* pMetaBlkDim
///< [in] meta block width/height/depth
4379 BOOL_32 isThick
= (pMetaBlkDim
->d
> 1);
4380 UINT_32 mipWidth
= pMetaBlkDim
->w
;
4381 UINT_32 mipHeight
= pMetaBlkDim
->h
>> 1;
4382 UINT_32 mipDepth
= pMetaBlkDim
->d
;
4387 minInc
= (pMetaBlkDim
->h
>= 512) ? 128 : ((pMetaBlkDim
->h
== 256) ? 64 : 32);
4389 else if (pMetaBlkDim
->h
>= 1024)
4393 else if (pMetaBlkDim
->h
== 512)
4402 UINT_32 blk32MipId
= 0xFFFFFFFF;
4404 for (UINT_32 mip
= 0; mip
< numMipInTail
; mip
++)
4406 pInfo
[mip
].inMiptail
= TRUE
;
4407 pInfo
[mip
].startX
= mipCoord
.w
;
4408 pInfo
[mip
].startY
= mipCoord
.h
;
4409 pInfo
[mip
].startZ
= mipCoord
.d
;
4410 pInfo
[mip
].width
= mipWidth
;
4411 pInfo
[mip
].height
= mipHeight
;
4412 pInfo
[mip
].depth
= mipDepth
;
4416 if (blk32MipId
== 0xFFFFFFFF)
4421 mipCoord
.w
= pInfo
[blk32MipId
].startX
;
4422 mipCoord
.h
= pInfo
[blk32MipId
].startY
;
4423 mipCoord
.d
= pInfo
[blk32MipId
].startZ
;
4425 switch (mip
- blk32MipId
)
4428 mipCoord
.w
+= 32; // 16x16
4431 mipCoord
.h
+= 32; // 8x8
4434 mipCoord
.h
+= 32; // 4x4
4438 mipCoord
.h
+= 32; // 2x2
4442 mipCoord
.h
+= 32; // 1x1
4445 // The following are for BC/ASTC formats
4447 mipCoord
.h
+= 48; // 1/2 x 1/2
4450 mipCoord
.h
+= 48; // 1/4 x 1/4
4454 mipCoord
.h
+= 48; // 1/8 x 1/8
4458 mipCoord
.h
+= 48; // 1/16 x 1/16
4462 ADDR_ASSERT_ALWAYS();
4466 mipWidth
= ((mip
- blk32MipId
) == 0) ? 16 : 8;
4467 mipHeight
= mipWidth
;
4471 mipDepth
= mipWidth
;
4476 if (mipWidth
<= minInc
)
4478 // if we're below the minimal increment...
4481 // For 3d, just go in z direction
4482 mipCoord
.d
+= mipDepth
;
4486 // For 2d, first go across, then down
4487 if ((mipWidth
* 2) == minInc
)
4489 // if we're 2 mips below, that's when we go back in x, and down in y
4490 mipCoord
.w
-= minInc
;
4491 mipCoord
.h
+= minInc
;
4495 // otherwise, just go across in x
4496 mipCoord
.w
+= minInc
;
4502 // On even mip, go down, otherwise, go across
4505 mipCoord
.w
+= mipWidth
;
4509 mipCoord
.h
+= mipHeight
;
4512 // Divide the width by 2
4514 // After the first mip in tail, the mip is always a square
4515 mipHeight
= mipWidth
;
4516 // ...or for 3d, a cube
4519 mipDepth
= mipWidth
;
4526 ************************************************************************************************************************
4527 * Gfx9Lib::GetMipStartPos
4530 * Internal function to get out information about mip logical start position
4533 * logical start position in macro block width/heith/depth of one mip level within one slice
4534 ************************************************************************************************************************
4536 Dim3d
Gfx9Lib::GetMipStartPos(
4537 AddrResourceType resourceType
,
4538 AddrSwizzleMode swizzleMode
,
4543 UINT_32 blockHeight
,
4546 UINT_32 log2ElementBytes
,
4547 UINT_32
* pMipTailBytesOffset
) const
4549 Dim3d mipStartPos
= {0};
4550 const Dim3d tailMaxDim
= GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4552 // Report mip in tail if Mip0 is already in mip tail
4553 BOOL_32 inMipTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
, width
, height
, depth
);
4554 UINT_32 log2BlkSize
= GetBlockSizeLog2(swizzleMode
);
4555 UINT_32 mipIndexInTail
= mipId
;
4557 if (inMipTail
== FALSE
)
4559 // Mip 0 dimension, unit in block
4560 UINT_32 mipWidthInBlk
= width
/ blockWidth
;
4561 UINT_32 mipHeightInBlk
= height
/ blockHeight
;
4562 UINT_32 mipDepthInBlk
= depth
/ blockDepth
;
4563 AddrMajorMode majorMode
= GetMajorMode(resourceType
,
4569 UINT_32 endingMip
= mipId
+ 1;
4571 for (UINT_32 i
= 1; i
<= mipId
; i
++)
4573 if ((i
== 1) || (i
== 3))
4575 if (majorMode
== ADDR_MAJOR_Y
)
4577 mipStartPos
.w
+= mipWidthInBlk
;
4581 mipStartPos
.h
+= mipHeightInBlk
;
4586 if (majorMode
== ADDR_MAJOR_X
)
4588 mipStartPos
.w
+= mipWidthInBlk
;
4590 else if (majorMode
== ADDR_MAJOR_Y
)
4592 mipStartPos
.h
+= mipHeightInBlk
;
4596 mipStartPos
.d
+= mipDepthInBlk
;
4600 BOOL_32 inTail
= FALSE
;
4602 if (IsThick(resourceType
, swizzleMode
))
4604 UINT_32 dim
= log2BlkSize
% 3;
4609 (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1) && (mipDepthInBlk
<= 2);
4614 (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
<= 2);
4619 (mipWidthInBlk
<= 2) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
== 1);
4624 if (log2BlkSize
& 1)
4626 inTail
= (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1);
4630 inTail
= (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2);
4640 mipWidthInBlk
= RoundHalf(mipWidthInBlk
);
4641 mipHeightInBlk
= RoundHalf(mipHeightInBlk
);
4642 mipDepthInBlk
= RoundHalf(mipDepthInBlk
);
4645 if (mipId
>= endingMip
)
4648 mipIndexInTail
= mipId
- endingMip
;
4654 UINT_32 index
= mipIndexInTail
+ MaxMacroBits
- log2BlkSize
;
4655 ADDR_ASSERT(index
< sizeof(MipTailOffset256B
) / sizeof(UINT_32
));
4656 *pMipTailBytesOffset
= MipTailOffset256B
[index
] << 8;
4663 ************************************************************************************************************************
4664 * Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled
4667 * Internal function to calculate address from coord for tiled swizzle surface
4671 ************************************************************************************************************************
4673 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled(
4674 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
4675 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
4678 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
4679 localIn
.swizzleMode
= pIn
->swizzleMode
;
4680 localIn
.flags
= pIn
->flags
;
4681 localIn
.resourceType
= pIn
->resourceType
;
4682 localIn
.bpp
= pIn
->bpp
;
4683 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
4684 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
4685 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
4686 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
4687 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
4688 localIn
.numFrags
= Max(pIn
->numFrags
, 1u);
4689 if (localIn
.numMipLevels
<= 1)
4691 localIn
.pitchInElement
= pIn
->pitchInElement
;
4694 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
4695 ADDR_E_RETURNCODE returnCode
= ComputeSurfaceInfoTiled(&localIn
, &localOut
);
4697 BOOL_32 valid
= (returnCode
== ADDR_OK
) &&
4698 (IsThin(pIn
->resourceType
, pIn
->swizzleMode
) ||
4699 IsThick(pIn
->resourceType
, pIn
->swizzleMode
)) &&
4700 ((pIn
->pipeBankXor
== 0) || (IsXor(pIn
->swizzleMode
)));
4704 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
4705 Dim3d mipStartPos
= {0};
4706 UINT_32 mipTailBytesOffset
= 0;
4708 if (pIn
->numMipLevels
> 1)
4710 // Mip-map chain cannot be MSAA surface
4711 ADDR_ASSERT((pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1));
4713 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
4718 localOut
.blockWidth
,
4719 localOut
.blockHeight
,
4720 localOut
.blockSlices
,
4723 &mipTailBytesOffset
);
4726 UINT_32 interleaveOffset
= 0;
4727 UINT_32 pipeBits
= 0;
4728 UINT_32 pipeXor
= 0;
4729 UINT_32 bankBits
= 0;
4730 UINT_32 bankXor
= 0;
4732 if (IsThin(pIn
->resourceType
, pIn
->swizzleMode
))
4734 UINT_32 blockOffset
= 0;
4735 UINT_32 log2BlkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4737 if (IsZOrderSwizzle(pIn
->swizzleMode
))
4739 // Morton generation
4740 if ((log2ElementBytes
== 0) || (log2ElementBytes
== 2))
4742 UINT_32 totalLowBits
= 6 - log2ElementBytes
;
4743 UINT_32 mortBits
= totalLowBits
/ 2;
4744 UINT_32 lowBitsValue
= MortonGen2d(pIn
->y
, pIn
->x
, mortBits
);
4745 // Are 9 bits enough?
4746 UINT_32 highBitsValue
=
4747 MortonGen2d(pIn
->x
>> mortBits
, pIn
->y
>> mortBits
, 9) << totalLowBits
;
4748 blockOffset
= lowBitsValue
| highBitsValue
;
4749 ADDR_ASSERT(blockOffset
== lowBitsValue
+ highBitsValue
);
4753 blockOffset
= MortonGen2d(pIn
->y
, pIn
->x
, 13);
4756 // Fill LSBs with sample bits
4757 if (pIn
->numSamples
> 1)
4759 blockOffset
*= pIn
->numSamples
;
4760 blockOffset
|= pIn
->sample
;
4763 // Shift according to BytesPP
4764 blockOffset
<<= log2ElementBytes
;
4768 // Micro block offset
4769 UINT_32 microBlockOffset
= ComputeSurface2DMicroBlockOffset(pIn
);
4770 blockOffset
= microBlockOffset
;
4772 // Micro block dimension
4773 ADDR_ASSERT(log2ElementBytes
< MaxNumOfBpp
);
4774 Dim2d microBlockDim
= Block256_2d
[log2ElementBytes
];
4775 // Morton generation, does 12 bit enough?
4777 MortonGen2d((pIn
->x
/ microBlockDim
.w
), (pIn
->y
/ microBlockDim
.h
), 12) << 8;
4779 // Sample bits start location
4780 UINT_32 sampleStart
= log2BlkSize
- Log2(pIn
->numSamples
);
4781 // Join sample bits information to the highest Macro block bits
4782 if (IsNonPrtXor(pIn
->swizzleMode
))
4784 // Non-prt-Xor : xor highest Macro block bits with sample bits
4785 blockOffset
= blockOffset
^ (pIn
->sample
<< sampleStart
);
4789 // Non-Xor or prt-Xor: replace highest Macro block bits with sample bits
4790 // after this op, the blockOffset only contains log2 Macro block size bits
4791 blockOffset
%= (1 << sampleStart
);
4792 blockOffset
|= (pIn
->sample
<< sampleStart
);
4793 ADDR_ASSERT((blockOffset
>> log2BlkSize
) == 0);
4797 if (IsXor(pIn
->swizzleMode
))
4799 // Mask off bits above Macro block bits to keep page synonyms working for prt
4800 if (IsPrt(pIn
->swizzleMode
))
4802 blockOffset
&= ((1 << log2BlkSize
) - 1);
4805 // Preserve offset inside pipe interleave
4806 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4807 blockOffset
>>= m_pipeInterleaveLog2
;
4810 pipeBits
= GetPipeXorBits(log2BlkSize
);
4812 pipeXor
= FoldXor2d(blockOffset
, pipeBits
);
4813 blockOffset
>>= pipeBits
;
4816 bankBits
= GetBankXorBits(log2BlkSize
);
4818 bankXor
= FoldXor2d(blockOffset
, bankBits
);
4819 blockOffset
>>= bankBits
;
4821 // Put all the part back together
4822 blockOffset
<<= bankBits
;
4823 blockOffset
|= bankXor
;
4824 blockOffset
<<= pipeBits
;
4825 blockOffset
|= pipeXor
;
4826 blockOffset
<<= m_pipeInterleaveLog2
;
4827 blockOffset
|= interleaveOffset
;
4830 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4831 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2BlkSize
)));
4833 blockOffset
|= mipTailBytesOffset
;
4835 if (IsNonPrtXor(pIn
->swizzleMode
) && (pIn
->numSamples
<= 1))
4837 // Apply slice xor if not MSAA/PRT
4838 blockOffset
^= (ReverseBitVector(pIn
->slice
, pipeBits
) << m_pipeInterleaveLog2
);
4839 blockOffset
^= (ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
) <<
4840 (m_pipeInterleaveLog2
+ pipeBits
));
4843 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4844 bankBits
, pipeBits
, &blockOffset
);
4846 blockOffset
%= (1 << log2BlkSize
);
4848 UINT_32 pitchInMacroBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4849 UINT_32 paddedHeightInMacroBlock
= localOut
.mipChainHeight
/ localOut
.blockHeight
;
4850 UINT_32 sliceSizeInMacroBlock
= pitchInMacroBlock
* paddedHeightInMacroBlock
;
4851 UINT_64 macroBlockIndex
=
4852 (pIn
->slice
+ mipStartPos
.d
) * sliceSizeInMacroBlock
+
4853 ((pIn
->y
/ localOut
.blockHeight
) + mipStartPos
.h
) * pitchInMacroBlock
+
4854 ((pIn
->x
/ localOut
.blockWidth
) + mipStartPos
.w
);
4856 pOut
->addr
= blockOffset
| (macroBlockIndex
<< log2BlkSize
);
4860 UINT_32 log2BlkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4862 Dim3d microBlockDim
= Block1K_3d
[log2ElementBytes
];
4864 UINT_32 blockOffset
= MortonGen3d((pIn
->x
/ microBlockDim
.w
),
4865 (pIn
->y
/ microBlockDim
.h
),
4866 (pIn
->slice
/ microBlockDim
.d
),
4870 blockOffset
|= ComputeSurface3DMicroBlockOffset(pIn
);
4872 if (IsXor(pIn
->swizzleMode
))
4874 // Mask off bits above Macro block bits to keep page synonyms working for prt
4875 if (IsPrt(pIn
->swizzleMode
))
4877 blockOffset
&= ((1 << log2BlkSize
) - 1);
4880 // Preserve offset inside pipe interleave
4881 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4882 blockOffset
>>= m_pipeInterleaveLog2
;
4885 pipeBits
= GetPipeXorBits(log2BlkSize
);
4887 pipeXor
= FoldXor3d(blockOffset
, pipeBits
);
4888 blockOffset
>>= pipeBits
;
4891 bankBits
= GetBankXorBits(log2BlkSize
);
4893 bankXor
= FoldXor3d(blockOffset
, bankBits
);
4894 blockOffset
>>= bankBits
;
4896 // Put all the part back together
4897 blockOffset
<<= bankBits
;
4898 blockOffset
|= bankXor
;
4899 blockOffset
<<= pipeBits
;
4900 blockOffset
|= pipeXor
;
4901 blockOffset
<<= m_pipeInterleaveLog2
;
4902 blockOffset
|= interleaveOffset
;
4905 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4906 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2BlkSize
)));
4907 blockOffset
|= mipTailBytesOffset
;
4909 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4910 bankBits
, pipeBits
, &blockOffset
);
4912 blockOffset
%= (1 << log2BlkSize
);
4914 UINT_32 xb
= pIn
->x
/ localOut
.blockWidth
+ mipStartPos
.w
;
4915 UINT_32 yb
= pIn
->y
/ localOut
.blockHeight
+ mipStartPos
.h
;
4916 UINT_32 zb
= pIn
->slice
/ localOut
.blockSlices
+ + mipStartPos
.d
;
4918 UINT_32 pitchInBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4919 UINT_32 sliceSizeInBlock
=
4920 (localOut
.mipChainHeight
/ localOut
.blockHeight
) * pitchInBlock
;
4921 UINT_64 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
4923 pOut
->addr
= blockOffset
| (blockIndex
<< log2BlkSize
);
4928 returnCode
= ADDR_INVALIDPARAMS
;
4935 ************************************************************************************************************************
4936 * Gfx9Lib::ComputeSurfaceInfoLinear
4939 * Internal function to calculate padding for linear swizzle 2D/3D surface
4943 ************************************************************************************************************************
4945 ADDR_E_RETURNCODE
Gfx9Lib::ComputeSurfaceLinearPadding(
4946 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input srtucture
4947 UINT_32
* pMipmap0PaddedWidth
, ///< [out] padded width in element
4948 UINT_32
* pSlice0PaddedHeight
, ///< [out] padded height for HW
4949 ADDR2_MIP_INFO
* pMipInfo
///< [out] per mip information
4952 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
4954 UINT_32 elementBytes
= pIn
->bpp
>> 3;
4955 UINT_32 pitchAlignInElement
= 0;
4957 if (pIn
->swizzleMode
== ADDR_SW_LINEAR_GENERAL
)
4959 ADDR_ASSERT(pIn
->numMipLevels
<= 1);
4960 ADDR_ASSERT(pIn
->numSlices
<= 1);
4961 pitchAlignInElement
= 1;
4965 pitchAlignInElement
= (256 / elementBytes
);
4968 UINT_32 mipChainWidth
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
4969 UINT_32 slice0PaddedHeight
= pIn
->height
;
4971 returnCode
= ApplyCustomizedPitchHeight(pIn
, elementBytes
, pitchAlignInElement
,
4972 &mipChainWidth
, &slice0PaddedHeight
);
4974 if (returnCode
== ADDR_OK
)
4976 UINT_32 mipChainHeight
= 0;
4977 UINT_32 mipHeight
= pIn
->height
;
4978 UINT_32 mipDepth
= (pIn
->resourceType
== ADDR_RSRC_TEX_3D
) ? pIn
->numSlices
: 1;
4980 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
4982 if (pMipInfo
!= NULL
)
4984 pMipInfo
[i
].offset
= mipChainWidth
* mipChainHeight
* elementBytes
;
4985 pMipInfo
[i
].pitch
= mipChainWidth
;
4986 pMipInfo
[i
].height
= mipHeight
;
4987 pMipInfo
[i
].depth
= mipDepth
;
4990 mipChainHeight
+= mipHeight
;
4991 mipHeight
= RoundHalf(mipHeight
);
4992 mipHeight
= Max(mipHeight
, 1u);
4995 *pMipmap0PaddedWidth
= mipChainWidth
;
4996 *pSlice0PaddedHeight
= (pIn
->numMipLevels
> 1) ? mipChainHeight
: slice0PaddedHeight
;
5003 ************************************************************************************************************************
5004 * Gfx9Lib::ComputeThinBlockDimension
5007 * Internal function to get thin block width/height/depth in element from surface input params.
5011 ************************************************************************************************************************
5013 VOID
Gfx9Lib::ComputeThinBlockDimension(
5019 AddrResourceType resourceType
,
5020 AddrSwizzleMode swizzleMode
) const
5022 ADDR_ASSERT(IsThin(resourceType
, swizzleMode
));
5024 const UINT_32 log2BlkSize
= GetBlockSizeLog2(swizzleMode
);
5025 const UINT_32 eleBytes
= bpp
>> 3;
5026 const UINT_32 microBlockSizeTableIndex
= Log2(eleBytes
);
5027 const UINT_32 log2blkSizeIn256B
= log2BlkSize
- 8;
5028 const UINT_32 widthAmp
= log2blkSizeIn256B
/ 2;
5029 const UINT_32 heightAmp
= log2blkSizeIn256B
- widthAmp
;
5031 ADDR_ASSERT(microBlockSizeTableIndex
< sizeof(Block256_2d
) / sizeof(Block256_2d
[0]));
5033 *pWidth
= (Block256_2d
[microBlockSizeTableIndex
].w
<< widthAmp
);
5034 *pHeight
= (Block256_2d
[microBlockSizeTableIndex
].h
<< heightAmp
);
5039 const UINT_32 log2sample
= Log2(numSamples
);
5040 const UINT_32 q
= log2sample
>> 1;
5041 const UINT_32 r
= log2sample
& 1;
5043 if (log2BlkSize
& 1)
5046 *pHeight
>>= (q
+ r
);
5050 *pWidth
>>= (q
+ r
);