2 * Copyright © 2017 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"
37 #include "gfx9_enum.h"
40 #include "amdgpu_id.h"
46 ////////////////////////////////////////////////////////////////////////////////////////////////////
47 ////////////////////////////////////////////////////////////////////////////////////////////////////
53 ************************************************************************************************************************
57 * Creates an Gfx9Lib object.
60 * Returns an Gfx9Lib object pointer.
61 ************************************************************************************************************************
63 Addr::Lib
* Gfx9HwlInit(const Client
* pClient
)
65 return V2::Gfx9Lib::CreateObj(pClient
);
71 ////////////////////////////////////////////////////////////////////////////////////////////////////
72 // Static Const Member
73 ////////////////////////////////////////////////////////////////////////////////////////////////////
75 const SwizzleModeFlags
Gfx9Lib::SwizzleModeTable
[ADDR_SW_MAX_TYPE
] =
76 {//Linear 256B 4KB 64KB Var Z Std Disp Rot XOR T RtOpt
77 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // ADDR_SW_LINEAR
78 {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_256B_S
79 {0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_256B_D
80 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_256B_R
82 {0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, // ADDR_SW_4KB_Z
83 {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_4KB_S
84 {0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_4KB_D
85 {0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_4KB_R
87 {0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0}, // ADDR_SW_64KB_Z
88 {0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_64KB_S
89 {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_64KB_D
90 {0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_64KB_R
92 {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, // ADDR_SW_VAR_Z
93 {0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0}, // ADDR_SW_VAR_S
94 {0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0}, // ADDR_SW_VAR_D
95 {0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, // ADDR_SW_VAR_R
97 {0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0}, // ADDR_SW_64KB_Z_T
98 {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0}, // ADDR_SW_64KB_S_T
99 {0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0}, // ADDR_SW_64KB_D_T
100 {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0}, // ADDR_SW_64KB_R_T
102 {0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0}, // ADDR_SW_4KB_Z_x
103 {0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0}, // ADDR_SW_4KB_S_x
104 {0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0}, // ADDR_SW_4KB_D_x
105 {0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0}, // ADDR_SW_4KB_R_x
107 {0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0}, // ADDR_SW_64KB_Z_X
108 {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}, // ADDR_SW_64KB_S_X
109 {0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0}, // ADDR_SW_64KB_D_X
110 {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0}, // ADDR_SW_64KB_R_X
112 {0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0}, // ADDR_SW_VAR_Z_X
113 {0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0}, // ADDR_SW_VAR_S_X
114 {0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0}, // ADDR_SW_VAR_D_X
115 {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0}, // ADDR_SW_VAR_R_X
116 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // ADDR_SW_LINEAR_GENERAL
119 const UINT_32
Gfx9Lib::MipTailOffset256B
[] = {2048, 1024, 512, 256, 128, 64, 32, 16,
120 8, 6, 5, 4, 3, 2, 1, 0};
122 const Dim3d
Gfx9Lib::Block256_3dS
[] = {{16, 4, 4}, {8, 4, 4}, {4, 4, 4}, {2, 4, 4}, {1, 4, 4}};
124 const Dim3d
Gfx9Lib::Block256_3dZ
[] = {{8, 4, 8}, {4, 4, 8}, {4, 4, 4}, {4, 2, 4}, {2, 2, 4}};
127 ************************************************************************************************************************
133 ************************************************************************************************************************
135 Gfx9Lib::Gfx9Lib(const Client
* pClient
)
140 m_class
= AI_ADDRLIB
;
141 memset(&m_settings
, 0, sizeof(m_settings
));
142 memcpy(m_swizzleModeTable
, SwizzleModeTable
, sizeof(SwizzleModeTable
));
146 ************************************************************************************************************************
151 ************************************************************************************************************************
158 ************************************************************************************************************************
159 * Gfx9Lib::HwlComputeHtileInfo
162 * Interface function stub of AddrComputeHtilenfo
166 ************************************************************************************************************************
168 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileInfo(
169 const ADDR2_COMPUTE_HTILE_INFO_INPUT
* pIn
, ///< [in] input structure
170 ADDR2_COMPUTE_HTILE_INFO_OUTPUT
* pOut
///< [out] output structure
173 UINT_32 numPipeTotal
= GetPipeNumForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
176 UINT_32 numRbTotal
= pIn
->hTileFlags
.rbAligned
? m_se
* m_rbPerSe
: 1;
178 UINT_32 numCompressBlkPerMetaBlk
, numCompressBlkPerMetaBlkLog2
;
180 if ((numPipeTotal
== 1) && (numRbTotal
== 1))
182 numCompressBlkPerMetaBlkLog2
= 10;
186 numCompressBlkPerMetaBlkLog2
= m_seLog2
+ m_rbPerSeLog2
+ 10;
189 numCompressBlkPerMetaBlk
= 1 << numCompressBlkPerMetaBlkLog2
;
191 Dim3d metaBlkDim
= {8, 8, 1};
192 UINT_32 totalAmpBits
= numCompressBlkPerMetaBlkLog2
;
193 UINT_32 widthAmp
= (pIn
->numMipLevels
> 1) ? (totalAmpBits
>> 1) : RoundHalf(totalAmpBits
);
194 UINT_32 heightAmp
= totalAmpBits
- widthAmp
;
195 metaBlkDim
.w
<<= widthAmp
;
196 metaBlkDim
.h
<<= heightAmp
;
199 Dim3d metaBlkDimDbg
= {8, 8, 1};
200 for (UINT_32 index
= 0; index
< numCompressBlkPerMetaBlkLog2
; index
++)
202 if ((metaBlkDimDbg
.h
< metaBlkDimDbg
.w
) ||
203 ((pIn
->numMipLevels
> 1) && (metaBlkDimDbg
.h
== metaBlkDimDbg
.w
)))
205 metaBlkDimDbg
.h
<<= 1;
209 metaBlkDimDbg
.w
<<= 1;
212 ADDR_ASSERT((metaBlkDimDbg
.w
== metaBlkDim
.w
) && (metaBlkDimDbg
.h
== metaBlkDim
.h
));
219 GetMetaMipInfo(pIn
->numMipLevels
, &metaBlkDim
, FALSE
, pOut
->pMipInfo
,
220 pIn
->unalignedWidth
, pIn
->unalignedHeight
, pIn
->numSlices
,
221 &numMetaBlkX
, &numMetaBlkY
, &numMetaBlkZ
);
223 UINT_32 sizeAlign
= numPipeTotal
* numRbTotal
* m_pipeInterleaveBytes
;
225 pOut
->pitch
= numMetaBlkX
* metaBlkDim
.w
;
226 pOut
->height
= numMetaBlkY
* metaBlkDim
.h
;
227 pOut
->sliceSize
= numMetaBlkX
* numMetaBlkY
* numCompressBlkPerMetaBlk
* 4;
229 pOut
->metaBlkWidth
= metaBlkDim
.w
;
230 pOut
->metaBlkHeight
= metaBlkDim
.h
;
231 pOut
->metaBlkNumPerSlice
= numMetaBlkX
* numMetaBlkY
;
233 pOut
->baseAlign
= Max(numCompressBlkPerMetaBlk
* 4, sizeAlign
);
235 if (m_settings
.metaBaseAlignFix
)
237 pOut
->baseAlign
= Max(pOut
->baseAlign
, GetBlockSize(pIn
->swizzleMode
));
240 if ((IsXor(pIn
->swizzleMode
) == FALSE
) && (numPipeTotal
> 2))
242 UINT_32 additionalAlign
= numPipeTotal
* numCompressBlkPerMetaBlk
* 2;
244 if (additionalAlign
> sizeAlign
)
246 sizeAlign
= additionalAlign
;
250 pOut
->htileBytes
= PowTwoAlign(pOut
->sliceSize
* numMetaBlkZ
, sizeAlign
);
256 ************************************************************************************************************************
257 * Gfx9Lib::HwlComputeCmaskInfo
260 * Interface function stub of AddrComputeCmaskInfo
264 ************************************************************************************************************************
266 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeCmaskInfo(
267 const ADDR2_COMPUTE_CMASK_INFO_INPUT
* pIn
, ///< [in] input structure
268 ADDR2_COMPUTE_CMASK_INFO_OUTPUT
* pOut
///< [out] output structure
271 ADDR_ASSERT(pIn
->resourceType
== ADDR_RSRC_TEX_2D
);
273 UINT_32 numPipeTotal
= GetPipeNumForMetaAddressing(pIn
->cMaskFlags
.pipeAligned
,
276 UINT_32 numRbTotal
= pIn
->cMaskFlags
.rbAligned
? m_se
* m_rbPerSe
: 1;
278 UINT_32 numCompressBlkPerMetaBlkLog2
, numCompressBlkPerMetaBlk
;
280 if ((numPipeTotal
== 1) && (numRbTotal
== 1))
282 numCompressBlkPerMetaBlkLog2
= 13;
286 numCompressBlkPerMetaBlkLog2
= m_seLog2
+ m_rbPerSeLog2
+ 10;
288 numCompressBlkPerMetaBlkLog2
= Max(numCompressBlkPerMetaBlkLog2
, 13u);
291 numCompressBlkPerMetaBlk
= 1 << numCompressBlkPerMetaBlkLog2
;
293 Dim2d metaBlkDim
= {8, 8};
294 UINT_32 totalAmpBits
= numCompressBlkPerMetaBlkLog2
;
295 UINT_32 heightAmp
= totalAmpBits
>> 1;
296 UINT_32 widthAmp
= totalAmpBits
- heightAmp
;
297 metaBlkDim
.w
<<= widthAmp
;
298 metaBlkDim
.h
<<= heightAmp
;
301 Dim2d metaBlkDimDbg
= {8, 8};
302 for (UINT_32 index
= 0; index
< numCompressBlkPerMetaBlkLog2
; index
++)
304 if (metaBlkDimDbg
.h
< metaBlkDimDbg
.w
)
306 metaBlkDimDbg
.h
<<= 1;
310 metaBlkDimDbg
.w
<<= 1;
313 ADDR_ASSERT((metaBlkDimDbg
.w
== metaBlkDim
.w
) && (metaBlkDimDbg
.h
== metaBlkDim
.h
));
316 UINT_32 numMetaBlkX
= (pIn
->unalignedWidth
+ metaBlkDim
.w
- 1) / metaBlkDim
.w
;
317 UINT_32 numMetaBlkY
= (pIn
->unalignedHeight
+ metaBlkDim
.h
- 1) / metaBlkDim
.h
;
318 UINT_32 numMetaBlkZ
= Max(pIn
->numSlices
, 1u);
320 UINT_32 sizeAlign
= numPipeTotal
* numRbTotal
* m_pipeInterleaveBytes
;
322 pOut
->pitch
= numMetaBlkX
* metaBlkDim
.w
;
323 pOut
->height
= numMetaBlkY
* metaBlkDim
.h
;
324 pOut
->sliceSize
= (numMetaBlkX
* numMetaBlkY
* numCompressBlkPerMetaBlk
) >> 1;
325 pOut
->cmaskBytes
= PowTwoAlign(pOut
->sliceSize
* numMetaBlkZ
, sizeAlign
);
326 pOut
->baseAlign
= Max(numCompressBlkPerMetaBlk
>> 1, sizeAlign
);
328 if (m_settings
.metaBaseAlignFix
)
330 pOut
->baseAlign
= Max(pOut
->baseAlign
, GetBlockSize(pIn
->swizzleMode
));
333 pOut
->metaBlkWidth
= metaBlkDim
.w
;
334 pOut
->metaBlkHeight
= metaBlkDim
.h
;
336 pOut
->metaBlkNumPerSlice
= numMetaBlkX
* numMetaBlkY
;
342 ************************************************************************************************************************
343 * Gfx9Lib::GetMetaMipInfo
350 ************************************************************************************************************************
352 VOID
Gfx9Lib::GetMetaMipInfo(
353 UINT_32 numMipLevels
, ///< [in] number of mip levels
354 Dim3d
* pMetaBlkDim
, ///< [in] meta block dimension
355 BOOL_32 dataThick
, ///< [in] data surface is thick
356 ADDR2_META_MIP_INFO
* pInfo
, ///< [out] meta mip info
357 UINT_32 mip0Width
, ///< [in] mip0 width
358 UINT_32 mip0Height
, ///< [in] mip0 height
359 UINT_32 mip0Depth
, ///< [in] mip0 depth
360 UINT_32
* pNumMetaBlkX
, ///< [out] number of metablock X in mipchain
361 UINT_32
* pNumMetaBlkY
, ///< [out] number of metablock Y in mipchain
362 UINT_32
* pNumMetaBlkZ
) ///< [out] number of metablock Z in mipchain
365 UINT_32 numMetaBlkX
= (mip0Width
+ pMetaBlkDim
->w
- 1) / pMetaBlkDim
->w
;
366 UINT_32 numMetaBlkY
= (mip0Height
+ pMetaBlkDim
->h
- 1) / pMetaBlkDim
->h
;
367 UINT_32 numMetaBlkZ
= (mip0Depth
+ pMetaBlkDim
->d
- 1) / pMetaBlkDim
->d
;
368 UINT_32 tailWidth
= pMetaBlkDim
->w
;
369 UINT_32 tailHeight
= pMetaBlkDim
->h
>> 1;
370 UINT_32 tailDepth
= pMetaBlkDim
->d
;
371 BOOL_32 inTail
= FALSE
;
372 AddrMajorMode major
= ADDR_MAJOR_MAX_TYPE
;
374 if (numMipLevels
> 1)
376 if (dataThick
&& (numMetaBlkZ
> numMetaBlkX
) && (numMetaBlkZ
> numMetaBlkY
))
379 major
= ADDR_MAJOR_Z
;
381 else if (numMetaBlkX
>= numMetaBlkY
)
384 major
= ADDR_MAJOR_X
;
389 major
= ADDR_MAJOR_Y
;
392 inTail
= ((mip0Width
<= tailWidth
) &&
393 (mip0Height
<= tailHeight
) &&
394 ((dataThick
== FALSE
) || (mip0Depth
<= tailDepth
)));
402 if (major
== ADDR_MAJOR_Z
)
405 pMipDim
= &numMetaBlkY
;
406 pOrderDim
= &numMetaBlkZ
;
409 else if (major
== ADDR_MAJOR_X
)
412 pMipDim
= &numMetaBlkY
;
413 pOrderDim
= &numMetaBlkX
;
419 pMipDim
= &numMetaBlkX
;
420 pOrderDim
= &numMetaBlkY
;
424 if ((*pMipDim
< 3) && (*pOrderDim
> orderLimit
) && (numMipLevels
> 3))
430 *pMipDim
+= ((*pMipDim
/ 2) + (*pMipDim
& 1));
437 UINT_32 mipWidth
= mip0Width
;
438 UINT_32 mipHeight
= mip0Height
;
439 UINT_32 mipDepth
= mip0Depth
;
440 Dim3d mipCoord
= {0};
442 for (UINT_32 mip
= 0; mip
< numMipLevels
; mip
++)
446 GetMetaMiptailInfo(&pInfo
[mip
], mipCoord
, numMipLevels
- mip
,
452 mipWidth
= PowTwoAlign(mipWidth
, pMetaBlkDim
->w
);
453 mipHeight
= PowTwoAlign(mipHeight
, pMetaBlkDim
->h
);
454 mipDepth
= PowTwoAlign(mipDepth
, pMetaBlkDim
->d
);
456 pInfo
[mip
].inMiptail
= FALSE
;
457 pInfo
[mip
].startX
= mipCoord
.w
;
458 pInfo
[mip
].startY
= mipCoord
.h
;
459 pInfo
[mip
].startZ
= mipCoord
.d
;
460 pInfo
[mip
].width
= mipWidth
;
461 pInfo
[mip
].height
= mipHeight
;
462 pInfo
[mip
].depth
= dataThick
? mipDepth
: 1;
464 if ((mip
>= 3) || (mip
& 1))
469 mipCoord
.w
+= mipWidth
;
472 mipCoord
.h
+= mipHeight
;
475 mipCoord
.d
+= mipDepth
;
486 mipCoord
.h
+= mipHeight
;
489 mipCoord
.w
+= mipWidth
;
492 mipCoord
.h
+= mipHeight
;
499 mipWidth
= Max(mipWidth
>> 1, 1u);
500 mipHeight
= Max(mipHeight
>> 1, 1u);
501 mipDepth
= Max(mipDepth
>> 1, 1u);
503 inTail
= ((mipWidth
<= tailWidth
) &&
504 (mipHeight
<= tailHeight
) &&
505 ((dataThick
== FALSE
) || (mipDepth
<= tailDepth
)));
510 *pNumMetaBlkX
= numMetaBlkX
;
511 *pNumMetaBlkY
= numMetaBlkY
;
512 *pNumMetaBlkZ
= numMetaBlkZ
;
516 ************************************************************************************************************************
517 * Gfx9Lib::HwlComputeDccInfo
520 * Interface function to compute DCC key info
524 ************************************************************************************************************************
526 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeDccInfo(
527 const ADDR2_COMPUTE_DCCINFO_INPUT
* pIn
, ///< [in] input structure
528 ADDR2_COMPUTE_DCCINFO_OUTPUT
* pOut
///< [out] output structure
531 BOOL_32 dataLinear
= IsLinear(pIn
->swizzleMode
);
532 BOOL_32 metaLinear
= pIn
->dccKeyFlags
.linear
;
533 BOOL_32 pipeAligned
= pIn
->dccKeyFlags
.pipeAligned
;
539 else if (metaLinear
== TRUE
)
544 UINT_32 numPipeTotal
= GetPipeNumForMetaAddressing(pipeAligned
, pIn
->swizzleMode
);
548 // Linear metadata supporting was removed for GFX9! No one can use this feature on GFX9.
549 ADDR_ASSERT_ALWAYS();
551 pOut
->dccRamBaseAlign
= numPipeTotal
* m_pipeInterleaveBytes
;
552 pOut
->dccRamSize
= PowTwoAlign((pIn
->dataSurfaceSize
/ 256), pOut
->dccRamBaseAlign
);
556 BOOL_32 dataThick
= IsThick(pIn
->resourceType
, pIn
->swizzleMode
);
558 UINT_32 minMetaBlkSize
= dataThick
? 65536 : 4096;
560 UINT_32 numFrags
= Max(pIn
->numFrags
, 1u);
561 UINT_32 numSlices
= Max(pIn
->numSlices
, 1u);
563 minMetaBlkSize
/= numFrags
;
565 UINT_32 numCompressBlkPerMetaBlk
= minMetaBlkSize
;
567 UINT_32 numRbTotal
= pIn
->dccKeyFlags
.rbAligned
? m_se
* m_rbPerSe
: 1;
569 if ((numPipeTotal
> 1) || (numRbTotal
> 1))
571 numCompressBlkPerMetaBlk
=
572 Max(numCompressBlkPerMetaBlk
, m_se
* m_rbPerSe
* (dataThick
? 262144 : 1024));
574 if (numCompressBlkPerMetaBlk
> 65536 * pIn
->bpp
)
576 numCompressBlkPerMetaBlk
= 65536 * pIn
->bpp
;
580 Dim3d compressBlkDim
= GetDccCompressBlk(pIn
->resourceType
, pIn
->swizzleMode
, pIn
->bpp
);
581 Dim3d metaBlkDim
= compressBlkDim
;
583 for (UINT_32 index
= 1; index
< numCompressBlkPerMetaBlk
; index
<<= 1)
585 if ((metaBlkDim
.h
< metaBlkDim
.w
) ||
586 ((pIn
->numMipLevels
> 1) && (metaBlkDim
.h
== metaBlkDim
.w
)))
588 if ((dataThick
== FALSE
) || (metaBlkDim
.h
<= metaBlkDim
.d
))
599 if ((dataThick
== FALSE
) || (metaBlkDim
.w
<= metaBlkDim
.d
))
614 GetMetaMipInfo(pIn
->numMipLevels
, &metaBlkDim
, dataThick
, pOut
->pMipInfo
,
615 pIn
->unalignedWidth
, pIn
->unalignedHeight
, numSlices
,
616 &numMetaBlkX
, &numMetaBlkY
, &numMetaBlkZ
);
618 UINT_32 sizeAlign
= numPipeTotal
* numRbTotal
* m_pipeInterleaveBytes
;
620 if (numFrags
> m_maxCompFrag
)
622 sizeAlign
*= (numFrags
/ m_maxCompFrag
);
625 pOut
->dccRamSize
= numMetaBlkX
* numMetaBlkY
* numMetaBlkZ
*
626 numCompressBlkPerMetaBlk
* numFrags
;
627 pOut
->dccRamSize
= PowTwoAlign(pOut
->dccRamSize
, sizeAlign
);
628 pOut
->dccRamBaseAlign
= Max(numCompressBlkPerMetaBlk
, sizeAlign
);
630 if (m_settings
.metaBaseAlignFix
)
632 pOut
->dccRamBaseAlign
= Max(pOut
->dccRamBaseAlign
, GetBlockSize(pIn
->swizzleMode
));
635 pOut
->pitch
= numMetaBlkX
* metaBlkDim
.w
;
636 pOut
->height
= numMetaBlkY
* metaBlkDim
.h
;
637 pOut
->depth
= numMetaBlkZ
* metaBlkDim
.d
;
639 pOut
->compressBlkWidth
= compressBlkDim
.w
;
640 pOut
->compressBlkHeight
= compressBlkDim
.h
;
641 pOut
->compressBlkDepth
= compressBlkDim
.d
;
643 pOut
->metaBlkWidth
= metaBlkDim
.w
;
644 pOut
->metaBlkHeight
= metaBlkDim
.h
;
645 pOut
->metaBlkDepth
= metaBlkDim
.d
;
647 pOut
->metaBlkNumPerSlice
= numMetaBlkX
* numMetaBlkY
;
648 pOut
->fastClearSizePerSlice
=
649 pOut
->metaBlkNumPerSlice
* numCompressBlkPerMetaBlk
* Min(numFrags
, m_maxCompFrag
);
656 ************************************************************************************************************************
657 * Gfx9Lib::HwlGetMaxAlignments
660 * Gets maximum alignments
663 ************************************************************************************************************************
665 ADDR_E_RETURNCODE
Gfx9Lib::HwlGetMaxAlignments(
666 ADDR_GET_MAX_ALINGMENTS_OUTPUT
* pOut
///< [out] output structure
669 pOut
->baseAlign
= HwlComputeSurfaceBaseAlign(ADDR_SW_64KB
);
675 ************************************************************************************************************************
676 * Gfx9Lib::HwlComputeCmaskAddrFromCoord
679 * Interface function stub of AddrComputeCmaskAddrFromCoord
683 ************************************************************************************************************************
685 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeCmaskAddrFromCoord(
686 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
687 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
690 ADDR2_COMPUTE_CMASK_INFO_INPUT input
= {0};
691 input
.size
= sizeof(input
);
692 input
.cMaskFlags
= pIn
->cMaskFlags
;
693 input
.colorFlags
= pIn
->colorFlags
;
694 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
695 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
696 input
.numSlices
= Max(pIn
->numSlices
, 1u);
697 input
.swizzleMode
= pIn
->swizzleMode
;
698 input
.resourceType
= pIn
->resourceType
;
700 ADDR2_COMPUTE_CMASK_INFO_OUTPUT output
= {0};
701 output
.size
= sizeof(output
);
703 ADDR_E_RETURNCODE returnCode
= ComputeCmaskInfo(&input
, &output
);
705 if (returnCode
== ADDR_OK
)
707 UINT_32 fmaskBpp
= GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
);
708 UINT_32 fmaskElementBytesLog2
= Log2(fmaskBpp
>> 3);
709 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
710 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
714 GetMetaEquation(&metaEq
, 0, fmaskElementBytesLog2
, 0, pIn
->cMaskFlags
,
715 Gfx9DataFmask
, pIn
->swizzleMode
, pIn
->resourceType
,
716 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0);
718 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
719 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
720 UINT_32 zb
= pIn
->slice
;
722 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
723 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
724 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
726 UINT_64 address
= metaEq
.solve(pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
);
728 pOut
->addr
= address
>> 1;
729 pOut
->bitPosition
= static_cast<UINT_32
>((address
& 1) << 2);
732 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->cMaskFlags
.pipeAligned
,
735 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
737 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
744 ************************************************************************************************************************
745 * Gfx9Lib::HwlComputeHtileAddrFromCoord
748 * Interface function stub of AddrComputeHtileAddrFromCoord
752 ************************************************************************************************************************
754 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileAddrFromCoord(
755 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
756 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
759 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
761 if (pIn
->numMipLevels
> 1)
763 returnCode
= ADDR_NOTIMPLEMENTED
;
767 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
768 input
.size
= sizeof(input
);
769 input
.hTileFlags
= pIn
->hTileFlags
;
770 input
.depthFlags
= pIn
->depthflags
;
771 input
.swizzleMode
= pIn
->swizzleMode
;
772 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
773 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
774 input
.numSlices
= Max(pIn
->numSlices
, 1u);
775 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
777 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
778 output
.size
= sizeof(output
);
780 returnCode
= ComputeHtileInfo(&input
, &output
);
782 if (returnCode
== ADDR_OK
)
784 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
785 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
786 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
787 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
791 GetMetaEquation(&metaEq
, 0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
792 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
793 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0);
795 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
796 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
797 UINT_32 zb
= pIn
->slice
;
799 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
800 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
801 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
803 UINT_64 address
= metaEq
.solve(pIn
->x
, pIn
->y
, pIn
->slice
, 0, blockIndex
);
805 pOut
->addr
= address
>> 1;
807 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
810 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
812 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
820 ************************************************************************************************************************
821 * Gfx9Lib::HwlComputeHtileCoordFromAddr
824 * Interface function stub of AddrComputeHtileCoordFromAddr
828 ************************************************************************************************************************
830 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeHtileCoordFromAddr(
831 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
832 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
835 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
837 if (pIn
->numMipLevels
> 1)
839 returnCode
= ADDR_NOTIMPLEMENTED
;
843 ADDR2_COMPUTE_HTILE_INFO_INPUT input
= {0};
844 input
.size
= sizeof(input
);
845 input
.hTileFlags
= pIn
->hTileFlags
;
846 input
.swizzleMode
= pIn
->swizzleMode
;
847 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
848 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
849 input
.numSlices
= Max(pIn
->numSlices
, 1u);
850 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
852 ADDR2_COMPUTE_HTILE_INFO_OUTPUT output
= {0};
853 output
.size
= sizeof(output
);
855 returnCode
= ComputeHtileInfo(&input
, &output
);
857 if (returnCode
== ADDR_OK
)
859 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
860 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
861 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
862 UINT_32 numSamplesLog2
= Log2(pIn
->numSamples
);
866 GetMetaEquation(&metaEq
, 0, elementBytesLog2
, numSamplesLog2
, pIn
->hTileFlags
,
867 Gfx9DataDepthStencil
, pIn
->swizzleMode
, ADDR_RSRC_TEX_2D
,
868 metaBlkWidthLog2
, metaBlkHeightLog2
, 0, 3, 3, 0);
870 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->hTileFlags
.pipeAligned
,
873 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
875 UINT_64 nibbleAddress
= (pIn
->addr
^ (pipeXor
<< m_pipeInterleaveLog2
)) << 1;
877 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
878 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
880 UINT_32 x
, y
, z
, s
, m
;
881 metaEq
.solveAddr(nibbleAddress
, sliceSizeInBlock
, x
, y
, z
, s
, m
);
883 pOut
->slice
= m
/ sliceSizeInBlock
;
884 pOut
->y
= ((m
% sliceSizeInBlock
) / pitchInBlock
) * output
.metaBlkHeight
+ y
;
885 pOut
->x
= (m
% pitchInBlock
) * output
.metaBlkWidth
+ x
;
893 ************************************************************************************************************************
894 * Gfx9Lib::HwlComputeDccAddrFromCoord
897 * Interface function stub of AddrComputeDccAddrFromCoord
901 ************************************************************************************************************************
903 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeDccAddrFromCoord(
904 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
,
905 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
) const
907 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
909 if ((pIn
->numMipLevels
> 1) || (pIn
->mipId
> 1) || pIn
->dccKeyFlags
.linear
)
911 returnCode
= ADDR_NOTIMPLEMENTED
;
915 ADDR2_COMPUTE_DCCINFO_INPUT input
= {0};
916 input
.size
= sizeof(input
);
917 input
.dccKeyFlags
= pIn
->dccKeyFlags
;
918 input
.colorFlags
= pIn
->colorFlags
;
919 input
.swizzleMode
= pIn
->swizzleMode
;
920 input
.resourceType
= pIn
->resourceType
;
921 input
.bpp
= pIn
->bpp
;
922 input
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
923 input
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
924 input
.numSlices
= Max(pIn
->numSlices
, 1u);
925 input
.numFrags
= Max(pIn
->numFrags
, 1u);
926 input
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
928 ADDR2_COMPUTE_DCCINFO_OUTPUT output
= {0};
929 output
.size
= sizeof(output
);
931 returnCode
= ComputeDccInfo(&input
, &output
);
933 if (returnCode
== ADDR_OK
)
935 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
936 UINT_32 numSamplesLog2
= Log2(pIn
->numFrags
);
937 UINT_32 metaBlkWidthLog2
= Log2(output
.metaBlkWidth
);
938 UINT_32 metaBlkHeightLog2
= Log2(output
.metaBlkHeight
);
939 UINT_32 metaBlkDepthLog2
= Log2(output
.metaBlkDepth
);
940 UINT_32 compBlkWidthLog2
= Log2(output
.compressBlkWidth
);
941 UINT_32 compBlkHeightLog2
= Log2(output
.compressBlkHeight
);
942 UINT_32 compBlkDepthLog2
= Log2(output
.compressBlkDepth
);
946 GetMetaEquation(&metaEq
, pIn
->mipId
, elementBytesLog2
, numSamplesLog2
, pIn
->dccKeyFlags
,
947 Gfx9DataColor
, pIn
->swizzleMode
, pIn
->resourceType
,
948 metaBlkWidthLog2
, metaBlkHeightLog2
, metaBlkDepthLog2
,
949 compBlkWidthLog2
, compBlkHeightLog2
, compBlkDepthLog2
);
951 UINT_32 xb
= pIn
->x
/ output
.metaBlkWidth
;
952 UINT_32 yb
= pIn
->y
/ output
.metaBlkHeight
;
953 UINT_32 zb
= pIn
->slice
/ output
.metaBlkDepth
;
955 UINT_32 pitchInBlock
= output
.pitch
/ output
.metaBlkWidth
;
956 UINT_32 sliceSizeInBlock
= (output
.height
/ output
.metaBlkHeight
) * pitchInBlock
;
957 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
959 UINT_64 address
= metaEq
.solve(pIn
->x
, pIn
->y
, pIn
->slice
, pIn
->sample
, blockIndex
);
961 pOut
->addr
= address
>> 1;
963 UINT_32 numPipeBits
= GetPipeLog2ForMetaAddressing(pIn
->dccKeyFlags
.pipeAligned
,
966 UINT_64 pipeXor
= static_cast<UINT_64
>(pIn
->pipeXor
& ((1 << numPipeBits
) - 1));
968 pOut
->addr
^= (pipeXor
<< m_pipeInterleaveLog2
);
976 ************************************************************************************************************************
977 * Gfx9Lib::HwlInitGlobalParams
980 * Initializes global parameters
983 * TRUE if all settings are valid
985 ************************************************************************************************************************
987 BOOL_32
Gfx9Lib::HwlInitGlobalParams(
988 const ADDR_CREATE_INPUT
* pCreateIn
) ///< [in] create input
990 BOOL_32 valid
= TRUE
;
992 if (m_settings
.isArcticIsland
)
994 GB_ADDR_CONFIG gbAddrConfig
;
996 gbAddrConfig
.u32All
= pCreateIn
->regValue
.gbAddrConfig
;
998 // These values are copied from CModel code
999 switch (gbAddrConfig
.bits
.NUM_PIPES
)
1001 case ADDR_CONFIG_1_PIPE
:
1005 case ADDR_CONFIG_2_PIPE
:
1009 case ADDR_CONFIG_4_PIPE
:
1013 case ADDR_CONFIG_8_PIPE
:
1017 case ADDR_CONFIG_16_PIPE
:
1021 case ADDR_CONFIG_32_PIPE
:
1026 ADDR_ASSERT_ALWAYS();
1030 switch (gbAddrConfig
.bits
.PIPE_INTERLEAVE_SIZE
)
1032 case ADDR_CONFIG_PIPE_INTERLEAVE_256B
:
1033 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_256B
;
1034 m_pipeInterleaveLog2
= 8;
1036 case ADDR_CONFIG_PIPE_INTERLEAVE_512B
:
1037 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_512B
;
1038 m_pipeInterleaveLog2
= 9;
1040 case ADDR_CONFIG_PIPE_INTERLEAVE_1KB
:
1041 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_1KB
;
1042 m_pipeInterleaveLog2
= 10;
1044 case ADDR_CONFIG_PIPE_INTERLEAVE_2KB
:
1045 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_2KB
;
1046 m_pipeInterleaveLog2
= 11;
1049 ADDR_ASSERT_ALWAYS();
1053 switch (gbAddrConfig
.bits
.NUM_BANKS
)
1055 case ADDR_CONFIG_1_BANK
:
1059 case ADDR_CONFIG_2_BANK
:
1063 case ADDR_CONFIG_4_BANK
:
1067 case ADDR_CONFIG_8_BANK
:
1071 case ADDR_CONFIG_16_BANK
:
1076 ADDR_ASSERT_ALWAYS();
1080 switch (gbAddrConfig
.bits
.NUM_SHADER_ENGINES
)
1082 case ADDR_CONFIG_1_SHADER_ENGINE
:
1086 case ADDR_CONFIG_2_SHADER_ENGINE
:
1090 case ADDR_CONFIG_4_SHADER_ENGINE
:
1094 case ADDR_CONFIG_8_SHADER_ENGINE
:
1099 ADDR_ASSERT_ALWAYS();
1103 switch (gbAddrConfig
.bits
.NUM_RB_PER_SE
)
1105 case ADDR_CONFIG_1_RB_PER_SHADER_ENGINE
:
1109 case ADDR_CONFIG_2_RB_PER_SHADER_ENGINE
:
1113 case ADDR_CONFIG_4_RB_PER_SHADER_ENGINE
:
1118 ADDR_ASSERT_ALWAYS();
1122 switch (gbAddrConfig
.bits
.MAX_COMPRESSED_FRAGS
)
1124 case ADDR_CONFIG_1_MAX_COMPRESSED_FRAGMENTS
:
1126 m_maxCompFragLog2
= 0;
1128 case ADDR_CONFIG_2_MAX_COMPRESSED_FRAGMENTS
:
1130 m_maxCompFragLog2
= 1;
1132 case ADDR_CONFIG_4_MAX_COMPRESSED_FRAGMENTS
:
1134 m_maxCompFragLog2
= 2;
1136 case ADDR_CONFIG_8_MAX_COMPRESSED_FRAGMENTS
:
1138 m_maxCompFragLog2
= 3;
1141 ADDR_ASSERT_ALWAYS();
1145 m_blockVarSizeLog2
= pCreateIn
->regValue
.blockVarSizeLog2
;
1146 ADDR_ASSERT((m_blockVarSizeLog2
== 0) ||
1147 ((m_blockVarSizeLog2
>= 17u) && (m_blockVarSizeLog2
<= 20u)));
1148 m_blockVarSizeLog2
= Min(Max(17u, m_blockVarSizeLog2
), 20u);
1153 ADDR_NOT_IMPLEMENTED();
1158 InitEquationTable();
1165 ************************************************************************************************************************
1166 * Gfx9Lib::HwlConvertChipFamily
1169 * Convert familyID defined in atiid.h to ChipFamily and set m_chipFamily/m_chipRevision
1172 ************************************************************************************************************************
1174 ChipFamily
Gfx9Lib::HwlConvertChipFamily(
1175 UINT_32 uChipFamily
, ///< [in] chip family defined in atiih.h
1176 UINT_32 uChipRevision
) ///< [in] chip revision defined in "asic_family"_id.h
1178 ChipFamily family
= ADDR_CHIP_FAMILY_AI
;
1180 switch (uChipFamily
)
1183 m_settings
.isArcticIsland
= 1;
1184 m_settings
.isVega10
= ASICREV_IS_VEGA10_P(uChipRevision
);
1186 if (m_settings
.isVega10
)
1188 m_settings
.isDce12
= 1;
1191 m_settings
.metaBaseAlignFix
= 1;
1193 m_settings
.depthPipeXorDisable
= 1;
1197 m_settings
.isArcticIsland
= 1;
1198 m_settings
.isRaven
= ASICREV_IS_RAVEN(uChipRevision
);
1200 if (m_settings
.isRaven
)
1202 m_settings
.isDcn1
= 1;
1205 m_settings
.metaBaseAlignFix
= 1;
1207 m_settings
.depthPipeXorDisable
= 1;
1211 ADDR_ASSERT(!"This should be a Fusion");
1219 ************************************************************************************************************************
1220 * Gfx9Lib::InitRbEquation
1226 ************************************************************************************************************************
1228 VOID
Gfx9Lib::GetRbEquation(
1229 CoordEq
* pRbEq
, ///< [out] rb equation
1230 UINT_32 numRbPerSeLog2
, ///< [in] number of rb per shader engine
1231 UINT_32 numSeLog2
) ///< [in] number of shader engine
1233 // RB's are distributed on 16x16, except when we have 1 rb per se, in which case its 32x32
1234 UINT_32 rbRegion
= (numRbPerSeLog2
== 0) ? 5 : 4;
1235 Coordinate
cx('x', rbRegion
);
1236 Coordinate
cy('y', rbRegion
);
1239 UINT_32 numRbTotalLog2
= numRbPerSeLog2
+ numSeLog2
;
1241 // Clear the rb equation
1243 pRbEq
->resize(numRbTotalLog2
);
1245 if ((numSeLog2
> 0) && (numRbPerSeLog2
== 1))
1247 // Special case when more than 1 SE, and 2 RB per SE
1248 (*pRbEq
)[0].add(cx
);
1249 (*pRbEq
)[0].add(cy
);
1252 (*pRbEq
)[0].add(cy
);
1256 UINT_32 numBits
= 2 * (numRbTotalLog2
- start
);
1258 for (UINT_32 i
= 0; i
< numBits
; i
++)
1261 start
+ (((start
+ i
) >= numRbTotalLog2
) ? (2 * (numRbTotalLog2
- start
) - i
- 1) : i
);
1265 (*pRbEq
)[idx
].add(cx
);
1270 (*pRbEq
)[idx
].add(cy
);
1277 ************************************************************************************************************************
1278 * Gfx9Lib::GetDataEquation
1281 * Get data equation for fmask and Z
1284 ************************************************************************************************************************
1286 VOID
Gfx9Lib::GetDataEquation(
1287 CoordEq
* pDataEq
, ///< [out] data surface equation
1288 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1289 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1290 AddrResourceType resourceType
, ///< [in] data surface resource type
1291 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1292 UINT_32 numSamplesLog2
) ///< [in] data surface sample count
1295 Coordinate
cx('x', 0);
1296 Coordinate
cy('y', 0);
1297 Coordinate
cz('z', 0);
1298 Coordinate
cs('s', 0);
1300 // Clear the equation
1302 pDataEq
->resize(27);
1304 if (dataSurfaceType
== Gfx9DataColor
)
1306 if (IsLinear(swizzleMode
))
1308 Coordinate
cm('m', 0);
1310 pDataEq
->resize(49);
1312 for (UINT_32 i
= 0; i
< 49; i
++)
1314 (*pDataEq
)[i
].add(cm
);
1318 else if (IsThick(resourceType
, swizzleMode
))
1320 // Color 3d_S and 3d_Z modes, 3d_D is same as color 2d
1322 if (IsStandardSwizzle(resourceType
, swizzleMode
))
1324 // Standard 3d swizzle
1325 // Fill in bottom x bits
1326 for (i
= elementBytesLog2
; i
< 4; i
++)
1328 (*pDataEq
)[i
].add(cx
);
1331 // Fill in 2 bits of y and then z
1332 for (i
= 4; i
< 6; i
++)
1334 (*pDataEq
)[i
].add(cy
);
1337 for (i
= 6; i
< 8; i
++)
1339 (*pDataEq
)[i
].add(cz
);
1342 if (elementBytesLog2
< 2)
1344 // fill in z & y bit
1345 (*pDataEq
)[8].add(cz
);
1346 (*pDataEq
)[9].add(cy
);
1350 else if (elementBytesLog2
== 2)
1352 // fill in y and x bit
1353 (*pDataEq
)[8].add(cy
);
1354 (*pDataEq
)[9].add(cx
);
1361 (*pDataEq
)[8].add(cx
);
1363 (*pDataEq
)[9].add(cx
);
1370 UINT_32 m2dEnd
= (elementBytesLog2
==0) ? 3 : ((elementBytesLog2
< 4) ? 4 : 5);
1371 UINT_32 numZs
= (elementBytesLog2
== 0 || elementBytesLog2
== 4) ?
1372 2 : ((elementBytesLog2
== 1) ? 3 : 1);
1373 pDataEq
->mort2d(cx
, cy
, elementBytesLog2
, m2dEnd
);
1374 for (i
= m2dEnd
+ 1; i
<= m2dEnd
+ numZs
; i
++)
1376 (*pDataEq
)[i
].add(cz
);
1379 if ((elementBytesLog2
== 0) || (elementBytesLog2
== 3))
1382 (*pDataEq
)[6].add(cx
);
1383 (*pDataEq
)[7].add(cz
);
1387 else if (elementBytesLog2
== 2)
1390 (*pDataEq
)[6].add(cy
);
1391 (*pDataEq
)[7].add(cz
);
1396 (*pDataEq
)[8].add(cy
);
1397 (*pDataEq
)[9].add(cx
);
1401 // Fill in bit 10 and up
1402 pDataEq
->mort3d( cz
, cy
, cx
, 10 );
1404 else if (IsThin(resourceType
, swizzleMode
))
1406 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1408 UINT_32 microYBits
= (8 - elementBytesLog2
) / 2;
1409 UINT_32 tileSplitStart
= blockSizeLog2
- numSamplesLog2
;
1411 // Fill in bottom x bits
1412 for (i
= elementBytesLog2
; i
< 4; i
++)
1414 (*pDataEq
)[i
].add(cx
);
1417 // Fill in bottom y bits
1418 for (i
= 4; i
< 4 + microYBits
; i
++)
1420 (*pDataEq
)[i
].add(cy
);
1423 // Fill in last of the micro_x bits
1424 for (i
= 4 + microYBits
; i
< 8; i
++)
1426 (*pDataEq
)[i
].add(cx
);
1429 // Fill in x/y bits below sample split
1430 pDataEq
->mort2d(cy
, cx
, 8, tileSplitStart
- 1);
1431 // Fill in sample bits
1432 for (i
= 0; i
< numSamplesLog2
; i
++)
1435 (*pDataEq
)[tileSplitStart
+ i
].add(cs
);
1437 // Fill in x/y bits above sample split
1438 if ((numSamplesLog2
& 1) ^ (blockSizeLog2
& 1))
1440 pDataEq
->mort2d(cx
, cy
, blockSizeLog2
);
1444 pDataEq
->mort2d(cy
, cx
, blockSizeLog2
);
1449 ADDR_ASSERT_ALWAYS();
1455 UINT_32 sampleStart
= elementBytesLog2
;
1456 UINT_32 pixelStart
= elementBytesLog2
+ numSamplesLog2
;
1457 UINT_32 ymajStart
= 6 + numSamplesLog2
;
1459 for (UINT_32 s
= 0; s
< numSamplesLog2
; s
++)
1462 (*pDataEq
)[sampleStart
+ s
].add(cs
);
1465 // Put in the x-major order pixel bits
1466 pDataEq
->mort2d(cx
, cy
, pixelStart
, ymajStart
- 1);
1467 // Put in the y-major order pixel bits
1468 pDataEq
->mort2d(cy
, cx
, ymajStart
);
1473 ************************************************************************************************************************
1474 * Gfx9Lib::GetPipeEquation
1480 ************************************************************************************************************************
1482 VOID
Gfx9Lib::GetPipeEquation(
1483 CoordEq
* pPipeEq
, ///< [out] pipe equation
1484 CoordEq
* pDataEq
, ///< [in] data equation
1485 UINT_32 pipeInterleaveLog2
, ///< [in] pipe interleave
1486 UINT_32 numPipeLog2
, ///< [in] number of pipes
1487 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1488 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1489 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1490 AddrResourceType resourceType
///< [in] data surface resource type
1493 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
1496 pDataEq
->copy(dataEq
);
1498 if (dataSurfaceType
== Gfx9DataColor
)
1500 INT_32 shift
= static_cast<INT_32
>(numSamplesLog2
);
1501 dataEq
.shift(-shift
, blockSizeLog2
- numSamplesLog2
);
1504 dataEq
.copy(*pPipeEq
, pipeInterleaveLog2
, numPipeLog2
);
1506 // This section should only apply to z/stencil, maybe fmask
1507 // If the pipe bit is below the comp block size,
1508 // then keep moving up the address until we find a bit that is above
1509 UINT_32 pipeStart
= 0;
1511 if (dataSurfaceType
!= Gfx9DataColor
)
1513 Coordinate
tileMin('x', 3);
1515 while (dataEq
[pipeInterleaveLog2
+ pipeStart
][0] < tileMin
)
1520 // if pipe is 0, then the first pipe bit is above the comp block size,
1521 // so we don't need to do anything
1522 // Note, this if condition is not necessary, since if we execute the loop when pipe==0,
1523 // we will get the same pipe equation
1526 for (UINT_32 i
= 0; i
< numPipeLog2
; i
++)
1528 // Copy the jth bit above pipe interleave to the current pipe equation bit
1529 dataEq
[pipeInterleaveLog2
+ pipeStart
+ i
].copyto((*pPipeEq
)[i
]);
1534 if (IsPrt(swizzleMode
))
1536 // Clear out bits above the block size if prt's are enabled
1537 dataEq
.resize(blockSizeLog2
);
1541 if (IsXor(swizzleMode
))
1545 if (IsThick(resourceType
, swizzleMode
))
1549 dataEq
.copy(xorMask2
, pipeInterleaveLog2
+ numPipeLog2
, 2 * numPipeLog2
);
1551 xorMask
.resize(numPipeLog2
);
1553 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1555 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
]);
1556 xorMask
[pipeIdx
].add(xorMask2
[2 * pipeIdx
+ 1]);
1561 // Xor in the bits above the pipe+gpu bits
1562 dataEq
.copy(xorMask
, pipeInterleaveLog2
+ pipeStart
+ numPipeLog2
, numPipeLog2
);
1564 if ((numSamplesLog2
== 0) && (IsPrt(swizzleMode
) == FALSE
))
1568 // if 1xaa and not prt, then xor in the z bits
1570 xorMask2
.resize(numPipeLog2
);
1571 for (UINT_32 pipeIdx
= 0; pipeIdx
< numPipeLog2
; pipeIdx
++)
1573 co
.set('z', numPipeLog2
- 1 - pipeIdx
);
1574 xorMask2
[pipeIdx
].add(co
);
1577 pPipeEq
->xorin(xorMask2
);
1582 pPipeEq
->xorin(xorMask
);
1587 ************************************************************************************************************************
1588 * Gfx9Lib::GetMetaEquation
1591 * Get meta equation for cmask/htile/DCC
1594 ************************************************************************************************************************
1596 VOID
Gfx9Lib::GetMetaEquation(
1597 CoordEq
* pMetaEq
, ///< [out] meta equation
1598 UINT_32 maxMip
, ///< [in] max mip Id
1599 UINT_32 elementBytesLog2
, ///< [in] data surface element bytes
1600 UINT_32 numSamplesLog2
, ///< [in] data surface sample count
1601 ADDR2_META_FLAGS metaFlag
, ///< [in] meta falg
1602 Gfx9DataType dataSurfaceType
, ///< [in] data surface type
1603 AddrSwizzleMode swizzleMode
, ///< [in] data surface swizzle mode
1604 AddrResourceType resourceType
, ///< [in] data surface resource type
1605 UINT_32 metaBlkWidthLog2
, ///< [in] meta block width
1606 UINT_32 metaBlkHeightLog2
, ///< [in] meta block height
1607 UINT_32 metaBlkDepthLog2
, ///< [in] meta block depth
1608 UINT_32 compBlkWidthLog2
, ///< [in] compress block width
1609 UINT_32 compBlkHeightLog2
, ///< [in] compress block height
1610 UINT_32 compBlkDepthLog2
) ///< [in] compress block depth
1613 UINT_32 numPipeTotalLog2
= GetPipeLog2ForMetaAddressing(metaFlag
.pipeAligned
, swizzleMode
);
1614 UINT_32 pipeInterleaveLog2
= m_pipeInterleaveLog2
;
1615 //UINT_32 blockSizeLog2 = GetBlockSizeLog2(swizzleMode);
1617 // Get the correct data address and rb equation
1619 GetDataEquation(&dataEq
, dataSurfaceType
, swizzleMode
, resourceType
,
1620 elementBytesLog2
, numSamplesLog2
);
1622 // Get pipe and rb equations
1623 CoordEq pipeEquation
;
1624 GetPipeEquation(&pipeEquation
, &dataEq
, pipeInterleaveLog2
, numPipeTotalLog2
,
1625 numSamplesLog2
, dataSurfaceType
, swizzleMode
, resourceType
);
1626 numPipeTotalLog2
= pipeEquation
.getsize();
1628 if (metaFlag
.linear
)
1630 // Linear metadata supporting was removed for GFX9! No one can use this feature.
1631 ADDR_ASSERT_ALWAYS();
1633 ADDR_ASSERT(dataSurfaceType
== Gfx9DataColor
);
1635 dataEq
.copy(*pMetaEq
);
1637 if (IsLinear(swizzleMode
))
1639 if (metaFlag
.pipeAligned
)
1641 // Remove the pipe bits
1642 INT_32 shift
= static_cast<INT_32
>(numPipeTotalLog2
);
1643 pMetaEq
->shift(-shift
, pipeInterleaveLog2
);
1645 // Divide by comp block size, which for linear (which is always color) is 256 B
1648 if (metaFlag
.pipeAligned
)
1650 // Put pipe bits back in
1651 pMetaEq
->shift(numPipeTotalLog2
, pipeInterleaveLog2
);
1653 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1655 pipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ i
]);
1664 UINT_32 maxCompFragLog2
= static_cast<INT_32
>(m_maxCompFragLog2
);
1665 UINT_32 compFragLog2
=
1666 ((dataSurfaceType
== Gfx9DataColor
) && (numSamplesLog2
> maxCompFragLog2
)) ?
1667 maxCompFragLog2
: numSamplesLog2
;
1669 UINT_32 uncompFragLog2
= numSamplesLog2
- compFragLog2
;
1671 // Make sure the metaaddr is cleared
1673 pMetaEq
->resize(27);
1675 if (IsThick(resourceType
, swizzleMode
))
1677 Coordinate
cx('x', 0);
1678 Coordinate
cy('y', 0);
1679 Coordinate
cz('z', 0);
1683 pMetaEq
->mort3d(cy
, cx
, cz
);
1687 pMetaEq
->mort3d(cx
, cy
, cz
);
1692 Coordinate
cx('x', 0);
1693 Coordinate
cy('y', 0);
1698 pMetaEq
->mort2d(cy
, cx
, compFragLog2
);
1702 pMetaEq
->mort2d(cx
, cy
, compFragLog2
);
1705 //------------------------------------------------------------------------------------------------------------------------
1706 // Put the compressible fragments at the lsb
1707 // the uncompressible frags will be at the msb of the micro address
1708 //------------------------------------------------------------------------------------------------------------------------
1709 for (UINT_32 s
= 0; s
< compFragLog2
; s
++)
1712 (*pMetaEq
)[s
].add(cs
);
1716 // Keep a copy of the pipe equations
1717 CoordEq origPipeEquation
;
1718 pipeEquation
.copy(origPipeEquation
);
1721 // filter out everything under the compressed block size
1722 co
.set('x', compBlkWidthLog2
);
1723 pMetaEq
->Filter('<', co
, 0, 'x');
1724 co
.set('y', compBlkHeightLog2
);
1725 pMetaEq
->Filter('<', co
, 0, 'y');
1726 co
.set('z', compBlkDepthLog2
);
1727 pMetaEq
->Filter('<', co
, 0, 'z');
1729 // For non-color, filter out sample bits
1730 if (dataSurfaceType
!= Gfx9DataColor
)
1733 pMetaEq
->Filter('<', co
, 0, 's');
1736 // filter out everything above the metablock size
1737 co
.set('x', metaBlkWidthLog2
- 1);
1738 pMetaEq
->Filter('>', co
, 0, 'x');
1739 co
.set('y', metaBlkHeightLog2
- 1);
1740 pMetaEq
->Filter('>', co
, 0, 'y');
1741 co
.set('z', metaBlkDepthLog2
- 1);
1742 pMetaEq
->Filter('>', co
, 0, 'z');
1744 // filter out everything above the metablock size for the channel bits
1745 co
.set('x', metaBlkWidthLog2
- 1);
1746 pipeEquation
.Filter('>', co
, 0, 'x');
1747 co
.set('y', metaBlkHeightLog2
- 1);
1748 pipeEquation
.Filter('>', co
, 0, 'y');
1749 co
.set('z', metaBlkDepthLog2
- 1);
1750 pipeEquation
.Filter('>', co
, 0, 'z');
1752 // Make sure we still have the same number of channel bits
1753 if (pipeEquation
.getsize() != numPipeTotalLog2
)
1755 ADDR_ASSERT_ALWAYS();
1758 // Loop through all channel and rb bits,
1759 // and make sure these components exist in the metadata address
1760 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1762 for (UINT_32 j
= pipeEquation
[i
].getsize(); j
> 0; j
--)
1764 if (pMetaEq
->Exists(pipeEquation
[i
][j
- 1]) == FALSE
)
1766 ADDR_ASSERT_ALWAYS();
1771 UINT_32 numSeLog2
= metaFlag
.rbAligned
? m_seLog2
: 0;
1772 UINT_32 numRbPeSeLog2
= metaFlag
.rbAligned
? m_rbPerSeLog2
: 0;
1773 CoordEq origRbEquation
;
1775 GetRbEquation(&origRbEquation
, numRbPeSeLog2
, numSeLog2
);
1777 CoordEq rbEquation
= origRbEquation
;
1779 UINT_32 numRbTotalLog2
= numRbPeSeLog2
+ numSeLog2
;
1781 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1783 for (UINT_32 j
= rbEquation
[i
].getsize(); j
> 0; j
--)
1785 if (pMetaEq
->Exists(rbEquation
[i
][j
- 1]) == FALSE
)
1787 ADDR_ASSERT_ALWAYS();
1792 // Loop through each rb id bit; if it is equal to any of the filtered channel bits, clear it
1793 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1795 for (UINT_32 j
= 0; j
< numPipeTotalLog2
; j
++)
1797 if (rbEquation
[i
] == pipeEquation
[j
])
1799 rbEquation
[i
].Clear();
1804 // Loop through each bit of the channel, get the smallest coordinate,
1805 // and remove it from the metaaddr, and rb_equation
1806 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1808 pipeEquation
[i
].getsmallest(co
);
1810 UINT_32 old_size
= pMetaEq
->getsize();
1811 pMetaEq
->Filter('=', co
);
1812 UINT_32 new_size
= pMetaEq
->getsize();
1813 if (new_size
!= old_size
-1)
1815 ADDR_ASSERT_ALWAYS();
1817 pipeEquation
.remove(co
);
1818 for (UINT_32 j
= 0; j
< numRbTotalLog2
; j
++)
1820 if (rbEquation
[j
].remove(co
))
1822 // if we actually removed something from this bit, then add the remaining
1823 // channel bits, as these can be removed for this bit
1824 for (UINT_32 k
= 0; k
< pipeEquation
[i
].getsize(); k
++)
1826 if (pipeEquation
[i
][k
] != co
)
1828 rbEquation
[j
].add(pipeEquation
[i
][k
]);
1835 // Loop through the rb bits and see what remain;
1836 // filter out the smallest coordinate if it remains
1837 UINT_32 rbBitsLeft
= 0;
1838 for (UINT_32 i
= 0; i
< numRbTotalLog2
; i
++)
1840 if (rbEquation
[i
].getsize() > 0)
1843 rbEquation
[i
].getsmallest(co
);
1844 UINT_32 old_size
= pMetaEq
->getsize();
1845 pMetaEq
->Filter('=', co
);
1846 UINT_32 new_size
= pMetaEq
->getsize();
1847 if (new_size
!= old_size
- 1)
1851 for (UINT_32 j
= i
+ 1; j
< numRbTotalLog2
; j
++)
1853 if (rbEquation
[j
].remove(co
))
1855 // if we actually removed something from this bit, then add the remaining
1856 // rb bits, as these can be removed for this bit
1857 for (UINT_32 k
= 0; k
< rbEquation
[i
].getsize(); k
++)
1859 if (rbEquation
[i
][k
] != co
)
1861 rbEquation
[j
].add(rbEquation
[i
][k
]);
1869 // capture the size of the metaaddr
1870 UINT_32 metaSize
= pMetaEq
->getsize();
1871 // resize to 49 bits...make this a nibble address
1872 pMetaEq
->resize(49);
1873 // Concatenate the macro address above the current address
1874 for (UINT_32 i
= metaSize
, j
= 0; i
< 49; i
++, j
++)
1877 (*pMetaEq
)[i
].add(co
);
1880 // Multiply by meta element size (in nibbles)
1881 if (dataSurfaceType
== Gfx9DataColor
)
1885 else if (dataSurfaceType
== Gfx9DataDepthStencil
)
1890 //------------------------------------------------------------------------------------------
1891 // Note the pipeInterleaveLog2+1 is because address is a nibble address
1892 // Shift up from pipe interleave number of channel
1893 // and rb bits left, and uncompressed fragments
1894 //------------------------------------------------------------------------------------------
1896 pMetaEq
->shift(numPipeTotalLog2
+ rbBitsLeft
+ uncompFragLog2
, pipeInterleaveLog2
+ 1);
1898 // Put in the channel bits
1899 for (UINT_32 i
= 0; i
< numPipeTotalLog2
; i
++)
1901 origPipeEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+1 + i
]);
1904 // Put in remaining rb bits
1905 for (UINT_32 i
= 0, j
= 0; j
< rbBitsLeft
; i
= (i
+ 1) % numRbTotalLog2
)
1907 if (rbEquation
[i
].getsize() > 0)
1909 origRbEquation
[i
].copyto((*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ j
]);
1910 // Mark any rb bit we add in to the rb mask
1915 //------------------------------------------------------------------------------------------
1916 // Put in the uncompressed fragment bits
1917 //------------------------------------------------------------------------------------------
1918 for (UINT_32 i
= 0; i
< uncompFragLog2
; i
++)
1920 co
.set('s', compFragLog2
+ i
);
1921 (*pMetaEq
)[pipeInterleaveLog2
+ 1 + numPipeTotalLog2
+ rbBitsLeft
+ i
].add(co
);
1927 ************************************************************************************************************************
1928 * Gfx9Lib::IsEquationSupported
1931 * Check if equation is supported for given swizzle mode and resource type.
1935 ************************************************************************************************************************
1937 BOOL_32
Gfx9Lib::IsEquationSupported(
1938 AddrResourceType rsrcType
,
1939 AddrSwizzleMode swMode
,
1940 UINT_32 elementBytesLog2
) const
1942 BOOL_32 supported
= (elementBytesLog2
< MaxElementBytesLog2
) &&
1943 (IsLinear(swMode
) == FALSE
) &&
1944 (((IsTex2d(rsrcType
) == TRUE
) &&
1945 ((elementBytesLog2
< 4) ||
1946 ((IsRotateSwizzle(swMode
) == FALSE
) &&
1947 (IsZOrderSwizzle(swMode
) == FALSE
)))) ||
1948 ((IsTex3d(rsrcType
) == TRUE
) &&
1949 (IsRotateSwizzle(swMode
) == FALSE
) &&
1950 (IsBlock256b(swMode
) == FALSE
)));
1956 ************************************************************************************************************************
1957 * Gfx9Lib::InitEquationTable
1960 * Initialize Equation table.
1964 ************************************************************************************************************************
1966 VOID
Gfx9Lib::InitEquationTable()
1968 memset(m_equationTable
, 0, sizeof(m_equationTable
));
1970 // Loop all possible resource type (2D/3D)
1971 for (UINT_32 rsrcTypeIdx
= 0; rsrcTypeIdx
< MaxRsrcType
; rsrcTypeIdx
++)
1973 AddrResourceType rsrcType
= static_cast<AddrResourceType
>(rsrcTypeIdx
+ ADDR_RSRC_TEX_2D
);
1975 // Loop all possible swizzle mode
1976 for (UINT_32 swModeIdx
= 0; swModeIdx
< MaxSwMode
; swModeIdx
++)
1978 AddrSwizzleMode swMode
= static_cast<AddrSwizzleMode
>(swModeIdx
);
1980 // Loop all possible bpp
1981 for (UINT_32 bppIdx
= 0; bppIdx
< MaxElementBytesLog2
; bppIdx
++)
1983 UINT_32 equationIndex
= ADDR_INVALID_EQUATION_INDEX
;
1985 // Check if the input is supported
1986 if (IsEquationSupported(rsrcType
, swMode
, bppIdx
))
1988 ADDR_EQUATION equation
;
1989 ADDR_E_RETURNCODE retCode
;
1991 memset(&equation
, 0, sizeof(ADDR_EQUATION
));
1993 // Generate the equation
1994 if (IsBlock256b(swMode
) && IsTex2d(rsrcType
))
1996 retCode
= ComputeBlock256Equation(rsrcType
, swMode
, bppIdx
, &equation
);
1998 else if (IsThin(rsrcType
, swMode
))
2000 retCode
= ComputeThinEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2004 retCode
= ComputeThickEquation(rsrcType
, swMode
, bppIdx
, &equation
);
2007 // Only fill the equation into the table if the return code is ADDR_OK,
2008 // otherwise if the return code is not ADDR_OK, it indicates this is not
2009 // a valid input, we do nothing but just fill invalid equation index
2010 // into the lookup table.
2011 if (retCode
== ADDR_OK
)
2013 equationIndex
= m_numEquations
;
2014 ADDR_ASSERT(equationIndex
< EquationTableSize
);
2016 m_equationTable
[equationIndex
] = equation
;
2022 ADDR_ASSERT_ALWAYS();
2026 // Fill the index into the lookup table, if the combination is not supported
2027 // fill the invalid equation index
2028 m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][bppIdx
] = equationIndex
;
2035 ************************************************************************************************************************
2036 * Gfx9Lib::HwlGetEquationIndex
2039 * Interface function stub of GetEquationIndex
2043 ************************************************************************************************************************
2045 UINT_32
Gfx9Lib::HwlGetEquationIndex(
2046 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
2047 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
2050 AddrResourceType rsrcType
= pIn
->resourceType
;
2051 AddrSwizzleMode swMode
= pIn
->swizzleMode
;
2052 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
2053 UINT_32 index
= ADDR_INVALID_EQUATION_INDEX
;
2055 if (IsEquationSupported(rsrcType
, swMode
, elementBytesLog2
))
2057 UINT_32 rsrcTypeIdx
= static_cast<UINT_32
>(rsrcType
) - 1;
2058 UINT_32 swModeIdx
= static_cast<UINT_32
>(swMode
);
2060 index
= m_equationLookupTable
[rsrcTypeIdx
][swModeIdx
][elementBytesLog2
];
2063 if (pOut
->pMipInfo
!= NULL
)
2065 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
2067 pOut
->pMipInfo
[i
].equationIndex
= index
;
2075 ************************************************************************************************************************
2076 * Gfx9Lib::HwlComputeBlock256Equation
2079 * Interface function stub of ComputeBlock256Equation
2083 ************************************************************************************************************************
2085 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeBlock256Equation(
2086 AddrResourceType rsrcType
,
2087 AddrSwizzleMode swMode
,
2088 UINT_32 elementBytesLog2
,
2089 ADDR_EQUATION
* pEquation
) const
2091 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2093 pEquation
->numBits
= 8;
2096 for (; i
< elementBytesLog2
; i
++)
2098 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2101 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2103 const UINT_32 maxBitsUsed
= 4;
2104 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2105 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2107 for (i
= 0; i
< maxBitsUsed
; i
++)
2109 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2110 InitChannel(1, 1, i
, &y
[i
]);
2113 if (IsStandardSwizzle(rsrcType
, swMode
))
2115 switch (elementBytesLog2
)
2158 ADDR_ASSERT_ALWAYS();
2159 ret
= ADDR_INVALIDPARAMS
;
2163 else if (IsDisplaySwizzle(rsrcType
, swMode
))
2165 switch (elementBytesLog2
)
2208 ADDR_ASSERT_ALWAYS();
2209 ret
= ADDR_INVALIDPARAMS
;
2213 else if (IsRotateSwizzle(swMode
))
2215 switch (elementBytesLog2
)
2252 ADDR_ASSERT_ALWAYS();
2254 ret
= ADDR_INVALIDPARAMS
;
2260 ADDR_ASSERT_ALWAYS();
2261 ret
= ADDR_INVALIDPARAMS
;
2267 Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2268 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 0)) ==
2269 (microBlockDim
.w
* (1 << elementBytesLog2
)));
2270 ADDR_ASSERT((2u << GetMaxValidChannelIndex(pEquation
->addr
, 8, 1)) == microBlockDim
.h
);
2277 ************************************************************************************************************************
2278 * Gfx9Lib::HwlComputeThinEquation
2281 * Interface function stub of ComputeThinEquation
2285 ************************************************************************************************************************
2287 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThinEquation(
2288 AddrResourceType rsrcType
,
2289 AddrSwizzleMode swMode
,
2290 UINT_32 elementBytesLog2
,
2291 ADDR_EQUATION
* pEquation
) const
2293 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2295 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2297 UINT_32 maxXorBits
= blockSizeLog2
;
2298 if (IsNonPrtXor(swMode
))
2300 // For non-prt-xor, maybe need to initialize some more bits for xor
2301 // The highest xor bit used in equation will be max the following 3 items:
2302 // 1. m_pipeInterleaveLog2 + 2 * pipeXorBits
2303 // 2. m_pipeInterleaveLog2 + pipeXorBits + 2 * bankXorBits
2306 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 2 * GetPipeXorBits(blockSizeLog2
));
2307 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2308 GetPipeXorBits(blockSizeLog2
) +
2309 2 * GetBankXorBits(blockSizeLog2
));
2312 const UINT_32 maxBitsUsed
= 14;
2313 ADDR_ASSERT((2 * maxBitsUsed
) >= maxXorBits
);
2314 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2315 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2317 const UINT_32 extraXorBits
= 16;
2318 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2319 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2321 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2323 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2324 InitChannel(1, 1, i
, &y
[i
]);
2327 ADDR_CHANNEL_SETTING
* pixelBit
= pEquation
->addr
;
2329 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2331 InitChannel(1, 0 , i
, &pixelBit
[i
]);
2336 UINT_32 lowBits
= 0;
2338 if (IsZOrderSwizzle(swMode
))
2340 if (elementBytesLog2
<= 3)
2342 for (UINT_32 i
= elementBytesLog2
; i
< 6; i
++)
2344 pixelBit
[i
] = (((i
- elementBytesLog2
) & 1) == 0) ? x
[xIdx
++] : y
[yIdx
++];
2351 ret
= ADDR_INVALIDPARAMS
;
2356 ret
= HwlComputeBlock256Equation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
2360 Dim2d microBlockDim
= Block256_2d
[elementBytesLog2
];
2361 xIdx
= Log2(microBlockDim
.w
);
2362 yIdx
= Log2(microBlockDim
.h
);
2369 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2371 pixelBit
[i
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2374 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2376 xorExtra
[i
- blockSizeLog2
] = ((i
& 1) == 0) ? y
[yIdx
++] : x
[xIdx
++];
2382 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2383 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2385 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2386 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2388 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2390 UINT_32 xor1BitPos
= pipeStart
+ 2 * pipeXorBits
- 1 - i
;
2391 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2392 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2394 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2397 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2399 UINT_32 xor1BitPos
= bankStart
+ 2 * bankXorBits
- 1 - i
;
2400 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2401 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2403 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2406 if (IsPrt(swMode
) == FALSE
)
2408 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2410 InitChannel(1, 2, pipeXorBits
- i
- 1, &pEquation
->xor2
[pipeStart
+ i
]);
2413 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2415 InitChannel(1, 2, bankXorBits
- i
- 1 + pipeXorBits
, &pEquation
->xor2
[bankStart
+ i
]);
2420 pEquation
->numBits
= blockSizeLog2
;
2427 ************************************************************************************************************************
2428 * Gfx9Lib::HwlComputeThickEquation
2431 * Interface function stub of ComputeThickEquation
2435 ************************************************************************************************************************
2437 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeThickEquation(
2438 AddrResourceType rsrcType
,
2439 AddrSwizzleMode swMode
,
2440 UINT_32 elementBytesLog2
,
2441 ADDR_EQUATION
* pEquation
) const
2443 ADDR_E_RETURNCODE ret
= ADDR_OK
;
2445 ADDR_ASSERT(IsTex3d(rsrcType
));
2447 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swMode
);
2449 UINT_32 maxXorBits
= blockSizeLog2
;
2450 if (IsNonPrtXor(swMode
))
2452 // For non-prt-xor, maybe need to initialize some more bits for xor
2453 // The highest xor bit used in equation will be max the following 3:
2454 // 1. m_pipeInterleaveLog2 + 3 * pipeXorBits
2455 // 2. m_pipeInterleaveLog2 + pipeXorBits + 3 * bankXorBits
2458 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+ 3 * GetPipeXorBits(blockSizeLog2
));
2459 maxXorBits
= Max(maxXorBits
, m_pipeInterleaveLog2
+
2460 GetPipeXorBits(blockSizeLog2
) +
2461 3 * GetBankXorBits(blockSizeLog2
));
2464 for (UINT_32 i
= 0; i
< elementBytesLog2
; i
++)
2466 InitChannel(1, 0 , i
, &pEquation
->addr
[i
]);
2469 ADDR_CHANNEL_SETTING
* pixelBit
= &pEquation
->addr
[elementBytesLog2
];
2471 const UINT_32 maxBitsUsed
= 12;
2472 ADDR_ASSERT((3 * maxBitsUsed
) >= maxXorBits
);
2473 ADDR_CHANNEL_SETTING x
[maxBitsUsed
] = {};
2474 ADDR_CHANNEL_SETTING y
[maxBitsUsed
] = {};
2475 ADDR_CHANNEL_SETTING z
[maxBitsUsed
] = {};
2477 const UINT_32 extraXorBits
= 24;
2478 ADDR_ASSERT(extraXorBits
>= maxXorBits
- blockSizeLog2
);
2479 ADDR_CHANNEL_SETTING xorExtra
[extraXorBits
] = {};
2481 for (UINT_32 i
= 0; i
< maxBitsUsed
; i
++)
2483 InitChannel(1, 0, elementBytesLog2
+ i
, &x
[i
]);
2484 InitChannel(1, 1, i
, &y
[i
]);
2485 InitChannel(1, 2, i
, &z
[i
]);
2488 if (IsZOrderSwizzle(swMode
))
2490 switch (elementBytesLog2
)
2543 ADDR_ASSERT_ALWAYS();
2544 ret
= ADDR_INVALIDPARAMS
;
2548 else if (IsStandardSwizzle(rsrcType
, swMode
))
2550 switch (elementBytesLog2
)
2603 ADDR_ASSERT_ALWAYS();
2604 ret
= ADDR_INVALIDPARAMS
;
2610 ADDR_ASSERT_ALWAYS();
2611 ret
= ADDR_INVALIDPARAMS
;
2616 Dim3d microBlockDim
= Block1K_3d
[elementBytesLog2
];
2617 UINT_32 xIdx
= Log2(microBlockDim
.w
);
2618 UINT_32 yIdx
= Log2(microBlockDim
.h
);
2619 UINT_32 zIdx
= Log2(microBlockDim
.d
);
2621 pixelBit
= pEquation
->addr
;
2623 const UINT_32 lowBits
= 10;
2624 ADDR_ASSERT(pEquation
->addr
[lowBits
- 1].valid
== 1);
2625 ADDR_ASSERT(pEquation
->addr
[lowBits
].valid
== 0);
2627 for (UINT_32 i
= lowBits
; i
< blockSizeLog2
; i
++)
2631 pixelBit
[i
] = x
[xIdx
++];
2633 else if ((i
% 3) == 1)
2635 pixelBit
[i
] = z
[zIdx
++];
2639 pixelBit
[i
] = y
[yIdx
++];
2643 for (UINT_32 i
= blockSizeLog2
; i
< maxXorBits
; i
++)
2647 xorExtra
[i
- blockSizeLog2
] = x
[xIdx
++];
2649 else if ((i
% 3) == 1)
2651 xorExtra
[i
- blockSizeLog2
] = z
[zIdx
++];
2655 xorExtra
[i
- blockSizeLog2
] = y
[yIdx
++];
2662 UINT_32 pipeStart
= m_pipeInterleaveLog2
;
2663 UINT_32 pipeXorBits
= GetPipeXorBits(blockSizeLog2
);
2664 for (UINT_32 i
= 0; i
< pipeXorBits
; i
++)
2666 UINT_32 xor1BitPos
= pipeStart
+ (3 * pipeXorBits
) - 1 - (2 * i
);
2667 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2668 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2670 InitChannel(&pEquation
->xor1
[pipeStart
+ i
], pXor1Src
);
2672 UINT_32 xor2BitPos
= pipeStart
+ (3 * pipeXorBits
) - 2 - (2 * i
);
2673 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2674 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2676 InitChannel(&pEquation
->xor2
[pipeStart
+ i
], pXor2Src
);
2679 UINT_32 bankStart
= pipeStart
+ pipeXorBits
;
2680 UINT_32 bankXorBits
= GetBankXorBits(blockSizeLog2
);
2681 for (UINT_32 i
= 0; i
< bankXorBits
; i
++)
2683 UINT_32 xor1BitPos
= bankStart
+ (3 * bankXorBits
) - 1 - (2 * i
);
2684 ADDR_CHANNEL_SETTING
* pXor1Src
= (xor1BitPos
< blockSizeLog2
) ?
2685 &pEquation
->addr
[xor1BitPos
] : &xorExtra
[xor1BitPos
- blockSizeLog2
];
2687 InitChannel(&pEquation
->xor1
[bankStart
+ i
], pXor1Src
);
2689 UINT_32 xor2BitPos
= bankStart
+ (3 * bankXorBits
) - 2 - (2 * i
);
2690 ADDR_CHANNEL_SETTING
* pXor2Src
= (xor2BitPos
< blockSizeLog2
) ?
2691 &pEquation
->addr
[xor2BitPos
] : &xorExtra
[xor2BitPos
- blockSizeLog2
];
2693 InitChannel(&pEquation
->xor2
[bankStart
+ i
], pXor2Src
);
2697 pEquation
->numBits
= blockSizeLog2
;
2704 ************************************************************************************************************************
2705 * Gfx9Lib::IsValidDisplaySwizzleMode
2708 * Check if a swizzle mode is supported by display engine
2711 * TRUE is swizzle mode is supported by display engine
2712 ************************************************************************************************************************
2714 BOOL_32
Gfx9Lib::IsValidDisplaySwizzleMode(
2715 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
2717 BOOL_32 support
= FALSE
;
2719 //const AddrResourceType resourceType = pIn->resourceType;
2720 const AddrSwizzleMode swizzleMode
= pIn
->swizzleMode
;
2722 if (m_settings
.isDce12
)
2724 switch (swizzleMode
)
2726 case ADDR_SW_256B_D
:
2727 case ADDR_SW_256B_R
:
2728 support
= (pIn
->bpp
== 32);
2731 case ADDR_SW_LINEAR
:
2734 case ADDR_SW_64KB_D
:
2735 case ADDR_SW_64KB_R
:
2738 case ADDR_SW_4KB_D_X
:
2739 case ADDR_SW_4KB_R_X
:
2740 case ADDR_SW_64KB_D_X
:
2741 case ADDR_SW_64KB_R_X
:
2742 case ADDR_SW_VAR_D_X
:
2743 case ADDR_SW_VAR_R_X
:
2744 support
= (pIn
->bpp
<= 64);
2751 else if (m_settings
.isDcn1
)
2753 switch (swizzleMode
)
2756 case ADDR_SW_64KB_D
:
2758 case ADDR_SW_64KB_D_T
:
2759 case ADDR_SW_4KB_D_X
:
2760 case ADDR_SW_64KB_D_X
:
2761 case ADDR_SW_VAR_D_X
:
2762 support
= (pIn
->bpp
== 64);
2765 case ADDR_SW_LINEAR
:
2767 case ADDR_SW_64KB_S
:
2769 case ADDR_SW_64KB_S_T
:
2770 case ADDR_SW_4KB_S_X
:
2771 case ADDR_SW_64KB_S_X
:
2772 case ADDR_SW_VAR_S_X
:
2773 support
= (pIn
->bpp
<= 64);
2782 ADDR_NOT_IMPLEMENTED();
2789 ************************************************************************************************************************
2790 * Gfx9Lib::HwlComputePipeBankXor
2793 * Generate a PipeBankXor value to be ORed into bits above pipeInterleaveBits of address
2797 ************************************************************************************************************************
2799 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputePipeBankXor(
2800 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
2801 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
) const
2803 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
2804 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
2805 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
2807 UINT_32 pipeXor
= 0;
2808 UINT_32 bankXor
= 0;
2810 const UINT_32 bankMask
= (1 << bankBits
) - 1;
2811 const UINT_32 index
= pIn
->surfIndex
& bankMask
;
2813 const UINT_32 bpp
= pIn
->flags
.fmask
?
2814 GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
) : GetElemLib()->GetBitsPerPixel(pIn
->format
);
2817 static const UINT_32 BankXorSmallBpp
[] = {0, 7, 4, 3, 8, 15, 12, 11, 1, 6, 5, 2, 9, 14, 13, 10};
2818 static const UINT_32 BankXorLargeBpp
[] = {0, 7, 8, 15, 4, 3, 12, 11, 1, 6, 9, 14, 5, 2, 13, 10};
2820 bankXor
= (bpp
<= 32) ? BankXorSmallBpp
[index
] : BankXorLargeBpp
[index
];
2822 else if (bankBits
> 0)
2824 UINT_32 bankIncrease
= (1 << (bankBits
- 1)) - 1;
2825 bankIncrease
= (bankIncrease
== 0) ? 1 : bankIncrease
;
2826 bankXor
= (index
* bankIncrease
) & bankMask
;
2829 pOut
->pipeBankXor
= (bankXor
<< pipeBits
) | pipeXor
;
2835 ************************************************************************************************************************
2836 * Gfx9Lib::HwlComputeSlicePipeBankXor
2839 * Generate slice PipeBankXor value based on base PipeBankXor value and slice id
2843 ************************************************************************************************************************
2845 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSlicePipeBankXor(
2846 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
2847 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
) const
2849 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
2850 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
2851 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
2853 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
2854 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
2856 pOut
->pipeBankXor
= pIn
->basePipeBankXor
^ (pipeXor
| (bankXor
<< pipeBits
));
2862 ************************************************************************************************************************
2863 * Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern
2866 * Compute sub resource offset to support swizzle pattern
2870 ************************************************************************************************************************
2872 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSubResourceOffsetForSwizzlePattern(
2873 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
2874 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
) const
2876 ADDR_ASSERT(IsThin(pIn
->resourceType
, pIn
->swizzleMode
));
2878 UINT_32 macroBlockBits
= GetBlockSizeLog2(pIn
->swizzleMode
);
2879 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
2880 UINT_32 bankBits
= GetBankXorBits(macroBlockBits
);
2881 UINT_32 pipeXor
= ReverseBitVector(pIn
->slice
, pipeBits
);
2882 UINT_32 bankXor
= ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
);
2883 UINT_32 pipeBankXor
= ((pipeXor
| (bankXor
<< pipeBits
)) ^ (pIn
->pipeBankXor
)) << m_pipeInterleaveLog2
;
2885 pOut
->offset
= pIn
->slice
* pIn
->sliceSize
+
2886 pIn
->macroBlockOffset
+
2887 (pIn
->mipTailOffset
^ pipeBankXor
) -
2888 static_cast<UINT_64
>(pipeBankXor
);
2893 ************************************************************************************************************************
2894 * Gfx9Lib::HwlComputeSurfaceInfoSanityCheck
2897 * Compute surface info sanity check
2901 ************************************************************************************************************************
2903 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoSanityCheck(
2904 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const
2906 BOOL_32 invalid
= FALSE
;
2908 if ((pIn
->bpp
> 128) || (pIn
->width
== 0) || (pIn
->numFrags
> 8) || (pIn
->numSamples
> 16))
2912 else if ((pIn
->swizzleMode
>= ADDR_SW_MAX_TYPE
) ||
2913 (pIn
->resourceType
>= ADDR_RSRC_MAX_TYPE
))
2918 BOOL_32 mipmap
= (pIn
->numMipLevels
> 1);
2919 BOOL_32 msaa
= (pIn
->numFrags
> 1);
2921 ADDR2_SURFACE_FLAGS flags
= pIn
->flags
;
2922 BOOL_32 zbuffer
= (flags
.depth
|| flags
.stencil
);
2923 BOOL_32 color
= flags
.color
;
2924 BOOL_32 display
= flags
.display
|| flags
.rotated
;
2926 AddrResourceType rsrcType
= pIn
->resourceType
;
2927 BOOL_32 tex3d
= IsTex3d(rsrcType
);
2928 AddrSwizzleMode swizzle
= pIn
->swizzleMode
;
2929 BOOL_32 linear
= IsLinear(swizzle
);
2930 BOOL_32 blk256B
= IsBlock256b(swizzle
);
2931 BOOL_32 blkVar
= IsBlockVariable(swizzle
);
2932 BOOL_32 isNonPrtXor
= IsNonPrtXor(swizzle
);
2933 BOOL_32 prt
= flags
.prt
;
2934 BOOL_32 stereo
= flags
.qbStereo
;
2936 if (invalid
== FALSE
)
2938 if ((pIn
->numFrags
> 1) &&
2939 (GetBlockSize(swizzle
) < (m_pipeInterleaveBytes
* pIn
->numFrags
)))
2941 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
2946 if (invalid
== FALSE
)
2950 case ADDR_RSRC_TEX_1D
:
2951 invalid
= msaa
|| zbuffer
|| display
|| (linear
== FALSE
) || stereo
;
2953 case ADDR_RSRC_TEX_2D
:
2954 invalid
= (msaa
&& mipmap
) || (stereo
&& msaa
) || (stereo
&& mipmap
);
2956 case ADDR_RSRC_TEX_3D
:
2957 invalid
= msaa
|| zbuffer
|| display
|| stereo
;
2965 if (invalid
== FALSE
)
2969 invalid
= (IsValidDisplaySwizzleMode(pIn
) == FALSE
);
2973 if (invalid
== FALSE
)
2977 invalid
= ((ADDR_RSRC_TEX_1D
!= rsrcType
) && prt
) ||
2978 zbuffer
|| msaa
|| (pIn
->bpp
== 0) || ((pIn
->bpp
% 8) != 0);
2982 if (blk256B
|| blkVar
|| isNonPrtXor
)
2987 invalid
= invalid
|| zbuffer
|| tex3d
|| mipmap
|| msaa
;
2991 if (invalid
== FALSE
)
2993 if (IsZOrderSwizzle(swizzle
))
2995 invalid
= color
&& msaa
;
2997 else if (IsStandardSwizzle(rsrcType
, swizzle
))
3001 else if (IsDisplaySwizzle(rsrcType
, swizzle
))
3005 else if (IsRotateSwizzle(swizzle
))
3007 invalid
= zbuffer
|| (pIn
->bpp
> 64) || tex3d
;
3011 ADDR_ASSERT(!"invalid swizzle mode");
3018 ADDR_ASSERT(invalid
== FALSE
);
3020 return invalid
? ADDR_INVALIDPARAMS
: ADDR_OK
;
3024 ************************************************************************************************************************
3025 * Gfx9Lib::HwlGetPreferredSurfaceSetting
3028 * Internal function to get suggested surface information for cliet to use
3032 ************************************************************************************************************************
3034 ADDR_E_RETURNCODE
Gfx9Lib::HwlGetPreferredSurfaceSetting(
3035 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
3036 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const
3038 // Macro define resource block type
3041 AddrBlockMicro
= 0, // Resource uses 256B block
3042 AddrBlock4KB
= 1, // Resource uses 4KB block
3043 AddrBlock64KB
= 2, // Resource uses 64KB block
3044 AddrBlockVar
= 3, // Resource uses var blcok
3045 AddrBlockLinear
= 4, // Resource uses linear swizzle mode
3047 AddrBlockMaxTiledType
= AddrBlock64KB
+ 1,
3052 AddrBlockSetMicro
= 1 << AddrBlockMicro
,
3053 AddrBlockSetMacro4KB
= 1 << AddrBlock4KB
,
3054 AddrBlockSetMacro64KB
= 1 << AddrBlock64KB
,
3055 AddrBlockSetVar
= 1 << AddrBlockVar
,
3056 AddrBlockSetLinear
= 1 << AddrBlockLinear
,
3058 AddrBlockSetMacro
= AddrBlockSetMacro4KB
| AddrBlockSetMacro64KB
,
3061 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3062 ElemLib
* pElemLib
= GetElemLib();
3064 // Set format to INVALID will skip this conversion
3065 UINT_32 expandX
= 1;
3066 UINT_32 expandY
= 1;
3067 UINT_32 bpp
= pIn
->bpp
;
3068 UINT_32 width
= pIn
->width
;
3069 UINT_32 height
= pIn
->height
;
3071 if (pIn
->format
!= ADDR_FMT_INVALID
)
3073 // Don't care for this case
3074 ElemMode elemMode
= ADDR_UNCOMPRESSED
;
3076 // Get compression/expansion factors and element mode which indicates compression/expansion
3077 bpp
= pElemLib
->GetBitsPerPixel(pIn
->format
,
3082 UINT_32 basePitch
= 0;
3083 GetElemLib()->AdjustSurfaceInfo(elemMode
,
3092 UINT_32 numSamples
= Max(pIn
->numSamples
, 1u);
3093 UINT_32 numFrags
= (pIn
->numFrags
== 0) ? numSamples
: pIn
->numFrags
;
3094 UINT_32 slice
= Max(pIn
->numSlices
, 1u);
3095 UINT_32 numMipLevels
= Max(pIn
->numMipLevels
, 1u);
3096 UINT_32 minSizeAlign
= NextPow2(pIn
->minSizeAlign
);
3098 if (pIn
->flags
.fmask
)
3100 bpp
= GetFmaskBpp(numSamples
, numFrags
);
3103 pOut
->resourceType
= ADDR_RSRC_TEX_2D
;
3107 // The output may get changed for volume(3D) texture resource in future
3108 pOut
->resourceType
= pIn
->resourceType
;
3111 ADDR_ASSERT(bpp
>= 8u);
3112 UINT_64 minSizeAlignInElement
= Max(minSizeAlign
/ (bpp
>> 3), 1u);
3114 if (IsTex1d(pOut
->resourceType
))
3116 pOut
->swizzleMode
= ADDR_SW_LINEAR
;
3117 pOut
->validBlockSet
.value
= AddrBlockSetLinear
;
3118 pOut
->canXor
= FALSE
;
3122 ADDR2_BLOCK_SET blockSet
;
3125 AddrSwType swType
= ADDR_SW_S
;
3127 // prt Xor and non-xor will have less height align requirement for stereo surface
3128 BOOL_32 prtXor
= (pIn
->flags
.prt
|| pIn
->flags
.qbStereo
) && (pIn
->noXor
== FALSE
);
3129 BOOL_32 displayResource
= FALSE
;
3131 pOut
->canXor
= (pIn
->flags
.prt
== FALSE
) && (pIn
->noXor
== FALSE
);
3133 // Filter out improper swType and blockSet by HW restriction
3134 if (pIn
->flags
.fmask
|| pIn
->flags
.depth
|| pIn
->flags
.stencil
)
3136 ADDR_ASSERT(IsTex2d(pOut
->resourceType
));
3137 blockSet
.value
= AddrBlockSetMacro
;
3140 if (pIn
->flags
.depth
&& pIn
->flags
.texture
)
3142 if (((bpp
== 16) && (numFrags
>= 4)) ||
3143 ((bpp
== 32) && (numFrags
>= 2)))
3145 // When _X/_T swizzle mode was used for MSAA depth texture, TC will get zplane
3146 // equation from wrong address within memory range a tile covered and use the
3147 // garbage data for compressed Z reading which finally leads to corruption.
3148 pOut
->canXor
= FALSE
;
3153 else if (ElemLib::IsBlockCompressed(pIn
->format
))
3155 // block compressed formats (BCx, ASTC, ETC2) must be either S or D modes. Not sure
3156 // under what circumstances "_D" would be appropriate as these formats are not
3158 blockSet
.value
= AddrBlockSetMacro
;
3160 // This isn't to be used as texture and caller doesn't allow macro tiled.
3161 if ((pIn
->flags
.texture
== FALSE
) &&
3162 (pIn
->forbiddenBlock
.macro4KB
&& pIn
->forbiddenBlock
.macro64KB
))
3164 blockSet
.value
|= AddrBlockSetLinear
;
3168 else if (ElemLib::IsMacroPixelPacked(pIn
->format
))
3170 // macro pixel packed formats (BG_RG, GB_GR) does not support the Z modes. Its not
3171 // clear under what circumstances the D or R modes would be appropriate since
3172 // these formats are not displayable.
3173 blockSet
.value
= AddrBlockSetLinear
| AddrBlockSetMacro
;
3176 else if (IsTex3d(pOut
->resourceType
))
3178 blockSet
.value
= AddrBlockSetLinear
| AddrBlockSetMacro
;
3182 // PRT cannot use SW_D which gives an unexpected block dimension
3185 else if ((numMipLevels
> 1) && (slice
>= width
) && (slice
>= height
))
3187 // When depth (Z) is the maximum dimension then must use one of the SW_*_S
3188 // or SW_*_Z modes if mipmapping is desired on a 3D surface
3191 else if (pIn
->flags
.color
)
3202 swType
= ((pIn
->flags
.display
== TRUE
) ||
3203 (pIn
->flags
.overlay
== TRUE
) ||
3204 (pIn
->bpp
== 128)) ? ADDR_SW_D
: ADDR_SW_S
;
3206 if (numMipLevels
> 1)
3208 ADDR_ASSERT(numFrags
== 1);
3209 blockSet
.value
= AddrBlockSetLinear
| AddrBlockSetMacro
;
3211 else if ((numFrags
> 1) || (numSamples
> 1))
3213 ADDR_ASSERT(IsTex2d(pOut
->resourceType
));
3214 blockSet
.value
= AddrBlockSetMacro
;
3218 ADDR_ASSERT(IsTex2d(pOut
->resourceType
));
3219 blockSet
.value
= AddrBlockSetLinear
| AddrBlockSetMicro
| AddrBlockSetMacro
;
3221 displayResource
= pIn
->flags
.rotated
|| pIn
->flags
.display
;
3223 if (displayResource
)
3225 swType
= pIn
->flags
.rotated
? ADDR_SW_R
: ADDR_SW_D
;
3231 else if (m_settings
.isDce12
)
3235 blockSet
.micro
= FALSE
;
3238 // DCE12 does not support display surface to be _T swizzle mode
3241 else if (m_settings
.isDcn1
)
3243 // _R is not supported by Dcn1
3253 blockSet
.micro
= FALSE
;
3257 ADDR_NOT_IMPLEMENTED();
3258 returnCode
= ADDR_NOTSUPPORTED
;
3264 if ((numFrags
> 1) &&
3265 (GetBlockSize(ADDR_SW_4KB
) < (m_pipeInterleaveBytes
* numFrags
)))
3267 // MSAA surface must have blk_bytes/pipe_interleave >= num_samples
3268 blockSet
.macro4KB
= FALSE
;
3273 blockSet
.value
&= AddrBlockSetMacro64KB
;
3276 // Apply customized forbidden setting
3277 blockSet
.value
&= ~pIn
->forbiddenBlock
.value
;
3279 if (pIn
->maxAlign
> 0)
3281 if (pIn
->maxAlign
< GetBlockSize(ADDR_SW_64KB
))
3283 blockSet
.macro64KB
= FALSE
;
3286 if (pIn
->maxAlign
< GetBlockSize(ADDR_SW_4KB
))
3288 blockSet
.macro4KB
= FALSE
;
3291 if (pIn
->maxAlign
< GetBlockSize(ADDR_SW_256B
))
3293 blockSet
.micro
= FALSE
;
3297 Dim3d blkAlign
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}};
3298 Dim3d paddedDim
[AddrBlockMaxTiledType
] = {{0}, {0}, {0}};
3299 UINT_64 padSize
[AddrBlockMaxTiledType
] = {0};
3303 returnCode
= ComputeBlockDimensionForSurf(&blkAlign
[AddrBlockMicro
].w
,
3304 &blkAlign
[AddrBlockMicro
].h
,
3305 &blkAlign
[AddrBlockMicro
].d
,
3311 if (returnCode
== ADDR_OK
)
3313 if (displayResource
)
3315 blkAlign
[AddrBlockMicro
].w
= PowTwoAlign(blkAlign
[AddrBlockMicro
].w
, 32);
3317 else if ((blkAlign
[AddrBlockMicro
].w
>= width
) && (blkAlign
[AddrBlockMicro
].h
>= height
) &&
3318 (minSizeAlign
<= GetBlockSize(ADDR_SW_256B
)))
3320 // If one 256B block can contain the surface, don't bother bigger block type
3321 blockSet
.macro4KB
= FALSE
;
3322 blockSet
.macro64KB
= FALSE
;
3323 blockSet
.var
= FALSE
;
3326 padSize
[AddrBlockMicro
] = ComputePadSize(&blkAlign
[AddrBlockMicro
], width
, height
,
3327 slice
, &paddedDim
[AddrBlockMicro
]);
3331 if ((returnCode
== ADDR_OK
) && blockSet
.macro4KB
)
3333 returnCode
= ComputeBlockDimensionForSurf(&blkAlign
[AddrBlock4KB
].w
,
3334 &blkAlign
[AddrBlock4KB
].h
,
3335 &blkAlign
[AddrBlock4KB
].d
,
3341 if (returnCode
== ADDR_OK
)
3343 if (displayResource
)
3345 blkAlign
[AddrBlock4KB
].w
= PowTwoAlign(blkAlign
[AddrBlock4KB
].w
, 32);
3348 padSize
[AddrBlock4KB
] = ComputePadSize(&blkAlign
[AddrBlock4KB
], width
, height
,
3349 slice
, &paddedDim
[AddrBlock4KB
]);
3351 ADDR_ASSERT(padSize
[AddrBlock4KB
] >= padSize
[AddrBlockMicro
]);
3355 if ((returnCode
== ADDR_OK
) && blockSet
.macro64KB
)
3357 returnCode
= ComputeBlockDimensionForSurf(&blkAlign
[AddrBlock64KB
].w
,
3358 &blkAlign
[AddrBlock64KB
].h
,
3359 &blkAlign
[AddrBlock64KB
].d
,
3365 if (returnCode
== ADDR_OK
)
3367 if (displayResource
)
3369 blkAlign
[AddrBlock64KB
].w
= PowTwoAlign(blkAlign
[AddrBlock64KB
].w
, 32);
3372 padSize
[AddrBlock64KB
] = ComputePadSize(&blkAlign
[AddrBlock64KB
], width
, height
,
3373 slice
, &paddedDim
[AddrBlock64KB
]);
3375 ADDR_ASSERT(padSize
[AddrBlock64KB
] >= padSize
[AddrBlock4KB
]);
3376 ADDR_ASSERT(padSize
[AddrBlock64KB
] >= padSize
[AddrBlockMicro
]);
3380 if (returnCode
== ADDR_OK
)
3382 for (UINT_32 i
= AddrBlockMicro
; i
< AddrBlockMaxTiledType
; i
++)
3384 padSize
[i
] = PowTwoAlign(padSize
[i
], minSizeAlignInElement
);
3387 // Use minimum block type which meets all conditions above if flag minimizeAlign was set
3388 if (pIn
->flags
.minimizeAlign
)
3390 // If padded size of 64KB block is larger than padded size of 256B block or 4KB
3391 // block, filter out 64KB block from candidate list
3392 if (blockSet
.macro64KB
&&
3393 ((blockSet
.micro
&& (padSize
[AddrBlockMicro
] < padSize
[AddrBlock64KB
])) ||
3394 (blockSet
.macro4KB
&& (padSize
[AddrBlock4KB
] < padSize
[AddrBlock64KB
]))))
3396 blockSet
.macro64KB
= FALSE
;
3399 // If padded size of 4KB block is larger than padded size of 256B block,
3400 // filter out 4KB block from candidate list
3401 if (blockSet
.macro4KB
&&
3403 (padSize
[AddrBlockMicro
] < padSize
[AddrBlock4KB
]))
3405 blockSet
.macro4KB
= FALSE
;
3408 // Filter out 64KB/4KB block if a smaller block type has 2/3 or less memory footprint
3409 else if (pIn
->flags
.opt4space
)
3411 UINT_64 threshold
= blockSet
.micro
? padSize
[AddrBlockMicro
] :
3412 (blockSet
.macro4KB
? padSize
[AddrBlock4KB
] : padSize
[AddrBlock64KB
]);
3414 threshold
+= threshold
>> 1;
3416 if (blockSet
.macro64KB
&& (padSize
[AddrBlock64KB
] > threshold
))
3418 blockSet
.macro64KB
= FALSE
;
3421 if (blockSet
.macro4KB
&& (padSize
[AddrBlock4KB
] > threshold
))
3423 blockSet
.macro4KB
= FALSE
;
3428 if (blockSet
.macro64KB
&&
3429 (padSize
[AddrBlock64KB
] >= static_cast<UINT_64
>(width
) * height
* slice
* 2) &&
3430 ((blockSet
.value
& ~AddrBlockSetMacro64KB
) != 0))
3432 // If 64KB block waste more than half memory on padding, filter it out from
3433 // candidate list when it is not the only choice left
3434 blockSet
.macro64KB
= FALSE
;
3438 if (blockSet
.value
== 0)
3440 // Bad things happen, client will not get any useful information from AddrLib.
3441 // Maybe we should fill in some output earlier instead of outputing nothing?
3442 ADDR_ASSERT_ALWAYS();
3443 returnCode
= ADDR_INVALIDPARAMS
;
3447 pOut
->validBlockSet
= blockSet
;
3448 pOut
->canXor
= pOut
->canXor
&&
3449 (blockSet
.macro4KB
|| blockSet
.macro64KB
|| blockSet
.var
);
3451 if (blockSet
.macro64KB
|| blockSet
.macro4KB
)
3453 if (swType
== ADDR_SW_Z
)
3455 pOut
->swizzleMode
= blockSet
.macro64KB
? ADDR_SW_64KB_Z
: ADDR_SW_4KB_Z
;
3457 else if (swType
== ADDR_SW_S
)
3459 pOut
->swizzleMode
= blockSet
.macro64KB
? ADDR_SW_64KB_S
: ADDR_SW_4KB_S
;
3461 else if (swType
== ADDR_SW_D
)
3463 pOut
->swizzleMode
= blockSet
.macro64KB
? ADDR_SW_64KB_D
: ADDR_SW_4KB_D
;
3467 ADDR_ASSERT(swType
== ADDR_SW_R
);
3468 pOut
->swizzleMode
= blockSet
.macro64KB
? ADDR_SW_64KB_R
: ADDR_SW_4KB_R
;
3471 if (prtXor
&& blockSet
.macro64KB
)
3473 // Client wants PRTXOR, give back _T swizzle mode if 64KB is available
3474 const UINT_32 prtGap
= ADDR_SW_64KB_Z_T
- ADDR_SW_64KB_Z
;
3475 pOut
->swizzleMode
= static_cast<AddrSwizzleMode
>(pOut
->swizzleMode
+ prtGap
);
3477 else if (pOut
->canXor
)
3479 // Client wants XOR and this is allowed, return XOR version swizzle mode
3480 const UINT_32 xorGap
= ADDR_SW_4KB_Z_X
- ADDR_SW_4KB_Z
;
3481 pOut
->swizzleMode
= static_cast<AddrSwizzleMode
>(pOut
->swizzleMode
+ xorGap
);
3484 else if (blockSet
.micro
)
3486 if (swType
== ADDR_SW_S
)
3488 pOut
->swizzleMode
= ADDR_SW_256B_S
;
3490 else if (swType
== ADDR_SW_D
)
3492 pOut
->swizzleMode
= ADDR_SW_256B_D
;
3496 ADDR_ASSERT(swType
== ADDR_SW_R
);
3497 pOut
->swizzleMode
= ADDR_SW_256B_R
;
3500 else if (blockSet
.linear
)
3502 // Fall into this branch doesn't mean linear is suitable, only no other choices!
3503 pOut
->swizzleMode
= ADDR_SW_LINEAR
;
3507 ADDR_ASSERT(blockSet
.var
);
3509 // Designer consider VAR swizzle mode is usless for most cases
3510 ADDR_UNHANDLED_CASE();
3512 returnCode
= ADDR_NOTSUPPORTED
;
3516 // Post sanity check, at least AddrLib should accept the output generated by its own
3517 if (pOut
->swizzleMode
!= ADDR_SW_LINEAR
)
3519 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
3520 localIn
.flags
= pIn
->flags
;
3521 localIn
.swizzleMode
= pOut
->swizzleMode
;
3522 localIn
.resourceType
= pOut
->resourceType
;
3523 localIn
.format
= pIn
->format
;
3525 localIn
.width
= width
;
3526 localIn
.height
= height
;
3527 localIn
.numSlices
= slice
;
3528 localIn
.numMipLevels
= numMipLevels
;
3529 localIn
.numSamples
= numSamples
;
3530 localIn
.numFrags
= numFrags
;
3532 HwlComputeSurfaceInfoSanityCheck(&localIn
);
3534 // TODO : check all valid block type available in validBlockSet?
3545 ************************************************************************************************************************
3546 * Gfx9Lib::ComputeStereoInfo
3549 * Compute height alignment and right eye pipeBankXor for stereo surface
3554 ************************************************************************************************************************
3556 ADDR_E_RETURNCODE
Gfx9Lib::ComputeStereoInfo(
3557 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
3558 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
,
3559 UINT_32
* pHeightAlign
3562 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3564 UINT_32 eqIndex
= HwlGetEquationIndex(pIn
, pOut
);
3566 if (eqIndex
< m_numEquations
)
3568 if (IsXor(pIn
->swizzleMode
))
3570 const UINT_32 blkSizeLog2
= GetBlockSizeLog2(pIn
->swizzleMode
);
3571 const UINT_32 numPipeBits
= GetPipeXorBits(blkSizeLog2
);
3572 const UINT_32 numBankBits
= GetBankXorBits(blkSizeLog2
);
3573 const UINT_32 bppLog2
= Log2(pIn
->bpp
>> 3);
3574 const UINT_32 maxYCoordBlock256
= Log2(Block256_2d
[bppLog2
].h
) - 1;
3575 const ADDR_EQUATION
*pEqToCheck
= &m_equationTable
[eqIndex
];
3577 ADDR_ASSERT(maxYCoordBlock256
==
3578 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], GetBlockSizeLog2(ADDR_SW_256B
), 1));
3580 const UINT_32 maxYCoordInBaseEquation
=
3581 (blkSizeLog2
- GetBlockSizeLog2(ADDR_SW_256B
)) / 2 + maxYCoordBlock256
;
3583 ADDR_ASSERT(maxYCoordInBaseEquation
==
3584 GetMaxValidChannelIndex(&pEqToCheck
->addr
[0], blkSizeLog2
, 1));
3586 const UINT_32 maxYCoordInPipeXor
= (numPipeBits
== 0) ? 0 : maxYCoordBlock256
+ numPipeBits
;
3588 ADDR_ASSERT(maxYCoordInPipeXor
==
3589 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
], numPipeBits
, 1));
3591 const UINT_32 maxYCoordInBankXor
= (numBankBits
== 0) ?
3592 0 : maxYCoordBlock256
+ (numPipeBits
+ 1) / 2 + numBankBits
;
3594 ADDR_ASSERT(maxYCoordInBankXor
==
3595 GetMaxValidChannelIndex(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
+ numPipeBits
], numBankBits
, 1));
3597 const UINT_32 maxYCoordInPipeBankXor
= Max(maxYCoordInPipeXor
, maxYCoordInBankXor
);
3599 if (maxYCoordInPipeBankXor
> maxYCoordInBaseEquation
)
3601 *pHeightAlign
= 1u << maxYCoordInPipeBankXor
;
3603 if (pOut
->pStereoInfo
!= NULL
)
3605 pOut
->pStereoInfo
->rightSwizzle
= 0;
3607 if ((PowTwoAlign(pIn
->height
, *pHeightAlign
) % (*pHeightAlign
* 2)) != 0)
3609 if (maxYCoordInPipeXor
== maxYCoordInPipeBankXor
)
3611 pOut
->pStereoInfo
->rightSwizzle
|= (1u << 1);
3614 if (maxYCoordInBankXor
== maxYCoordInPipeBankXor
)
3616 pOut
->pStereoInfo
->rightSwizzle
|=
3617 1u << ((numPipeBits
% 2) ? numPipeBits
: numPipeBits
+ 1);
3620 ADDR_ASSERT(pOut
->pStereoInfo
->rightSwizzle
==
3621 GetCoordActiveMask(&pEqToCheck
->xor1
[m_pipeInterleaveLog2
],
3622 numPipeBits
+ numBankBits
, 1, maxYCoordInPipeBankXor
));
3630 ADDR_ASSERT_ALWAYS();
3631 returnCode
= ADDR_ERROR
;
3638 ************************************************************************************************************************
3639 * Gfx9Lib::HwlComputeSurfaceInfoTiled
3642 * Internal function to calculate alignment for tiled surface
3646 ************************************************************************************************************************
3648 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceInfoTiled(
3649 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
3650 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
3653 ADDR_E_RETURNCODE returnCode
= ComputeBlockDimensionForSurf(&pOut
->blockWidth
,
3661 if (returnCode
== ADDR_OK
)
3663 UINT_32 pitchAlignInElement
= pOut
->blockWidth
;
3665 if ((IsTex2d(pIn
->resourceType
) == TRUE
) &&
3666 (pIn
->flags
.display
|| pIn
->flags
.rotated
) &&
3667 (pIn
->numMipLevels
<= 1) &&
3668 (pIn
->numSamples
<= 1) &&
3669 (pIn
->numFrags
<= 1))
3671 // Display engine needs pitch align to be at least 32 pixels.
3672 pitchAlignInElement
= PowTwoAlign(pitchAlignInElement
, 32);
3675 pOut
->pitch
= PowTwoAlign(pIn
->width
, pitchAlignInElement
);
3677 if ((pIn
->numMipLevels
<= 1) && (pIn
->pitchInElement
> 0))
3679 if ((pIn
->pitchInElement
% pitchAlignInElement
) != 0)
3681 returnCode
= ADDR_INVALIDPARAMS
;
3683 else if (pIn
->pitchInElement
< pOut
->pitch
)
3685 returnCode
= ADDR_INVALIDPARAMS
;
3689 pOut
->pitch
= pIn
->pitchInElement
;
3693 UINT_32 heightAlign
= 0;
3695 if (pIn
->flags
.qbStereo
)
3697 returnCode
= ComputeStereoInfo(pIn
, pOut
, &heightAlign
);
3700 if (returnCode
== ADDR_OK
)
3702 pOut
->height
= PowTwoAlign(pIn
->height
, pOut
->blockHeight
);
3704 if (heightAlign
> 1)
3706 pOut
->height
= PowTwoAlign(pOut
->height
, heightAlign
);
3709 pOut
->numSlices
= PowTwoAlign(pIn
->numSlices
, pOut
->blockSlices
);
3711 pOut
->epitchIsHeight
= FALSE
;
3712 pOut
->mipChainInTail
= FALSE
;
3714 pOut
->mipChainPitch
= pOut
->pitch
;
3715 pOut
->mipChainHeight
= pOut
->height
;
3716 pOut
->mipChainSlice
= pOut
->numSlices
;
3718 if (pIn
->numMipLevels
> 1)
3720 UINT_32 numMipLevel
;
3721 ADDR2_MIP_INFO
*pMipInfo
;
3722 ADDR2_MIP_INFO mipInfo
[4];
3724 if (pOut
->pMipInfo
!= NULL
)
3726 pMipInfo
= pOut
->pMipInfo
;
3727 numMipLevel
= pIn
->numMipLevels
;
3732 numMipLevel
= Min(pIn
->numMipLevels
, 4u);
3735 UINT_32 endingMip
= GetMipChainInfo(pIn
->resourceType
,
3749 pOut
->epitchIsHeight
= TRUE
;
3750 pOut
->pitch
= pMipInfo
[0].pitch
;
3751 pOut
->height
= pMipInfo
[0].height
;
3752 pOut
->numSlices
= pMipInfo
[0].depth
;
3753 pOut
->mipChainInTail
= TRUE
;
3757 UINT_32 mip0WidthInBlk
= pOut
->pitch
/ pOut
->blockWidth
;
3758 UINT_32 mip0HeightInBlk
= pOut
->height
/ pOut
->blockHeight
;
3760 AddrMajorMode majorMode
= GetMajorMode(pIn
->resourceType
,
3764 pOut
->numSlices
/ pOut
->blockSlices
);
3765 if (majorMode
== ADDR_MAJOR_Y
)
3767 UINT_32 mip1WidthInBlk
= RoundHalf(mip0WidthInBlk
);
3769 if ((mip1WidthInBlk
== 1) && (endingMip
> 2))
3774 pOut
->mipChainPitch
+= (mip1WidthInBlk
* pOut
->blockWidth
);
3776 pOut
->epitchIsHeight
= FALSE
;
3780 UINT_32 mip1HeightInBlk
= RoundHalf(mip0HeightInBlk
);
3782 if ((mip1HeightInBlk
== 1) && (endingMip
> 2))
3787 pOut
->mipChainHeight
+= (mip1HeightInBlk
* pOut
->blockHeight
);
3789 pOut
->epitchIsHeight
= TRUE
;
3793 if (pOut
->pMipInfo
!= NULL
)
3795 UINT_32 elementBytesLog2
= Log2(pIn
->bpp
>> 3);
3797 for (UINT_32 i
= 0; i
< pIn
->numMipLevels
; i
++)
3799 Dim3d mipStartPos
= {0};
3800 UINT_32 mipTailOffsetInBytes
= 0;
3802 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
3812 &mipTailOffsetInBytes
);
3814 UINT_32 pitchInBlock
=
3815 pOut
->mipChainPitch
/ pOut
->blockWidth
;
3816 UINT_32 sliceInBlock
=
3817 (pOut
->mipChainHeight
/ pOut
->blockHeight
) * pitchInBlock
;
3818 UINT_64 blockIndex
=
3819 mipStartPos
.d
* sliceInBlock
+ mipStartPos
.h
* pitchInBlock
+ mipStartPos
.w
;
3820 UINT_64 macroBlockOffset
=
3821 blockIndex
<< GetBlockSizeLog2(pIn
->swizzleMode
);
3823 pMipInfo
[i
].macroBlockOffset
= macroBlockOffset
;
3824 pMipInfo
[i
].mipTailOffset
= mipTailOffsetInBytes
;
3828 else if (pOut
->pMipInfo
!= NULL
)
3830 pOut
->pMipInfo
[0].pitch
= pOut
->pitch
;
3831 pOut
->pMipInfo
[0].height
= pOut
->height
;
3832 pOut
->pMipInfo
[0].depth
= IsTex3d(pIn
->resourceType
)? pOut
->numSlices
: 1;
3833 pOut
->pMipInfo
[0].offset
= 0;
3836 pOut
->sliceSize
= static_cast<UINT_64
>(pOut
->mipChainPitch
) * pOut
->mipChainHeight
*
3837 (pIn
->bpp
>> 3) * pIn
->numFrags
;
3838 pOut
->surfSize
= pOut
->sliceSize
* pOut
->mipChainSlice
;
3839 pOut
->baseAlign
= HwlComputeSurfaceBaseAlign(pIn
->swizzleMode
);
3843 pOut
->baseAlign
= Max(pOut
->baseAlign
, PrtAlignment
);
3852 ************************************************************************************************************************
3853 * Gfx9Lib::GetMipChainInfo
3856 * Internal function to get out information about mip chain
3859 * Smaller value between Id of first mip fitted in mip tail and max Id of mip being created
3860 ************************************************************************************************************************
3862 UINT_32
Gfx9Lib::GetMipChainInfo(
3863 AddrResourceType resourceType
,
3864 AddrSwizzleMode swizzleMode
,
3870 UINT_32 blockHeight
,
3872 UINT_32 numMipLevel
,
3873 ADDR2_MIP_INFO
* pMipInfo
) const
3875 const Dim3d tailMaxDim
=
3876 GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
3878 UINT_32 mipPitch
= mip0Width
;
3879 UINT_32 mipHeight
= mip0Height
;
3880 UINT_32 mipDepth
= IsTex3d(resourceType
) ? mip0Depth
: 1;
3882 UINT_32 endingMip
= numMipLevel
- 1;
3883 BOOL_32 inTail
= FALSE
;
3884 BOOL_32 finalDim
= FALSE
;
3886 BOOL_32 is3dThick
= IsThick(resourceType
, swizzleMode
);
3887 BOOL_32 is3dThin
= IsTex3d(resourceType
) && (is3dThick
== FALSE
);
3889 for (UINT_32 mipId
= 0; mipId
< numMipLevel
; mipId
++)
3893 if (finalDim
== FALSE
)
3899 mipSize
= mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3);
3903 mipSize
= mipPitch
* mipHeight
* (bpp
>> 3);
3908 UINT_32 index
= Log2(bpp
>> 3);
3912 mipPitch
= Block256_3dZ
[index
].w
;
3913 mipHeight
= Block256_3dZ
[index
].h
;
3914 mipDepth
= Block256_3dZ
[index
].d
;
3918 mipPitch
= Block256_2d
[index
].w
;
3919 mipHeight
= Block256_2d
[index
].h
;
3928 inTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
,
3929 mipPitch
, mipHeight
, mipDepth
);
3935 mipPitch
= tailMaxDim
.w
;
3936 mipHeight
= tailMaxDim
.h
;
3940 mipDepth
= tailMaxDim
.d
;
3945 mipPitch
= PowTwoAlign(mipPitch
, blockWidth
);
3946 mipHeight
= PowTwoAlign(mipHeight
, blockHeight
);
3950 mipDepth
= PowTwoAlign(mipDepth
, blockDepth
);
3955 pMipInfo
[mipId
].pitch
= mipPitch
;
3956 pMipInfo
[mipId
].height
= mipHeight
;
3957 pMipInfo
[mipId
].depth
= mipDepth
;
3958 pMipInfo
[mipId
].offset
= offset
;
3959 offset
+= (mipPitch
* mipHeight
* mipDepth
* (bpp
>> 3));
3965 mipDepth
= Max(mipDepth
>> 1, 1u);
3970 mipPitch
= Max(mipPitch
>> 1, 1u);
3971 mipHeight
= Max(mipHeight
>> 1, 1u);
3973 if (is3dThick
|| is3dThin
)
3975 mipDepth
= Max(mipDepth
>> 1, 1u);
3984 ************************************************************************************************************************
3985 * Gfx9Lib::GetMetaMiptailInfo
3988 * Get mip tail coordinate information.
3992 ************************************************************************************************************************
3994 VOID
Gfx9Lib::GetMetaMiptailInfo(
3995 ADDR2_META_MIP_INFO
* pInfo
, ///< [out] output structure to store per mip coord
3996 Dim3d mipCoord
, ///< [in] mip tail base coord
3997 UINT_32 numMipInTail
, ///< [in] number of mips in tail
3998 Dim3d
* pMetaBlkDim
///< [in] meta block width/height/depth
4001 BOOL_32 isThick
= (pMetaBlkDim
->d
> 1);
4002 UINT_32 mipWidth
= pMetaBlkDim
->w
;
4003 UINT_32 mipHeight
= pMetaBlkDim
->h
>> 1;
4004 UINT_32 mipDepth
= pMetaBlkDim
->d
;
4009 minInc
= (pMetaBlkDim
->h
>= 512) ? 128 : ((pMetaBlkDim
->h
== 256) ? 64 : 32);
4011 else if (pMetaBlkDim
->h
>= 1024)
4015 else if (pMetaBlkDim
->h
== 512)
4024 UINT_32 blk32MipId
= 0xFFFFFFFF;
4026 for (UINT_32 mip
= 0; mip
< numMipInTail
; mip
++)
4028 pInfo
[mip
].inMiptail
= TRUE
;
4029 pInfo
[mip
].startX
= mipCoord
.w
;
4030 pInfo
[mip
].startY
= mipCoord
.h
;
4031 pInfo
[mip
].startZ
= mipCoord
.d
;
4032 pInfo
[mip
].width
= mipWidth
;
4033 pInfo
[mip
].height
= mipHeight
;
4034 pInfo
[mip
].depth
= mipDepth
;
4038 if (blk32MipId
== 0xFFFFFFFF)
4043 mipCoord
.w
= pInfo
[blk32MipId
].startX
;
4044 mipCoord
.h
= pInfo
[blk32MipId
].startY
;
4045 mipCoord
.d
= pInfo
[blk32MipId
].startZ
;
4047 switch (mip
- blk32MipId
)
4050 mipCoord
.w
+= 32; // 16x16
4053 mipCoord
.h
+= 32; // 8x8
4056 mipCoord
.h
+= 32; // 4x4
4060 mipCoord
.h
+= 32; // 2x2
4064 mipCoord
.h
+= 32; // 1x1
4067 // The following are for BC/ASTC formats
4069 mipCoord
.h
+= 48; // 1/2 x 1/2
4072 mipCoord
.h
+= 48; // 1/4 x 1/4
4076 mipCoord
.h
+= 48; // 1/8 x 1/8
4080 mipCoord
.h
+= 48; // 1/16 x 1/16
4084 ADDR_ASSERT_ALWAYS();
4088 mipWidth
= ((mip
- blk32MipId
) == 0) ? 16 : 8;
4089 mipHeight
= mipWidth
;
4093 mipDepth
= mipWidth
;
4098 if (mipWidth
<= minInc
)
4100 // if we're below the minimal increment...
4103 // For 3d, just go in z direction
4104 mipCoord
.d
+= mipDepth
;
4108 // For 2d, first go across, then down
4109 if ((mipWidth
* 2) == minInc
)
4111 // if we're 2 mips below, that's when we go back in x, and down in y
4112 mipCoord
.w
-= minInc
;
4113 mipCoord
.h
+= minInc
;
4117 // otherwise, just go across in x
4118 mipCoord
.w
+= minInc
;
4124 // On even mip, go down, otherwise, go across
4127 mipCoord
.w
+= mipWidth
;
4131 mipCoord
.h
+= mipHeight
;
4134 // Divide the width by 2
4136 // After the first mip in tail, the mip is always a square
4137 mipHeight
= mipWidth
;
4138 // ...or for 3d, a cube
4141 mipDepth
= mipWidth
;
4148 ************************************************************************************************************************
4149 * Gfx9Lib::GetMipStartPos
4152 * Internal function to get out information about mip logical start position
4155 * logical start position in macro block width/heith/depth of one mip level within one slice
4156 ************************************************************************************************************************
4158 Dim3d
Gfx9Lib::GetMipStartPos(
4159 AddrResourceType resourceType
,
4160 AddrSwizzleMode swizzleMode
,
4165 UINT_32 blockHeight
,
4168 UINT_32 log2ElementBytes
,
4169 UINT_32
* pMipTailBytesOffset
) const
4171 Dim3d mipStartPos
= {0};
4172 const Dim3d tailMaxDim
= GetMipTailDim(resourceType
, swizzleMode
, blockWidth
, blockHeight
, blockDepth
);
4174 // Report mip in tail if Mip0 is already in mip tail
4175 BOOL_32 inMipTail
= IsInMipTail(resourceType
, swizzleMode
, tailMaxDim
, width
, height
, depth
);
4176 UINT_32 log2blkSize
= GetBlockSizeLog2(swizzleMode
);
4177 UINT_32 mipIndexInTail
= mipId
;
4179 if (inMipTail
== FALSE
)
4181 // Mip 0 dimension, unit in block
4182 UINT_32 mipWidthInBlk
= width
/ blockWidth
;
4183 UINT_32 mipHeightInBlk
= height
/ blockHeight
;
4184 UINT_32 mipDepthInBlk
= depth
/ blockDepth
;
4185 AddrMajorMode majorMode
= GetMajorMode(resourceType
,
4191 UINT_32 endingMip
= mipId
+ 1;
4193 for (UINT_32 i
= 1; i
<= mipId
; i
++)
4195 if ((i
== 1) || (i
== 3))
4197 if (majorMode
== ADDR_MAJOR_Y
)
4199 mipStartPos
.w
+= mipWidthInBlk
;
4203 mipStartPos
.h
+= mipHeightInBlk
;
4208 if (majorMode
== ADDR_MAJOR_X
)
4210 mipStartPos
.w
+= mipWidthInBlk
;
4212 else if (majorMode
== ADDR_MAJOR_Y
)
4214 mipStartPos
.h
+= mipHeightInBlk
;
4218 mipStartPos
.d
+= mipDepthInBlk
;
4222 BOOL_32 inTail
= FALSE
;
4224 if (IsThick(resourceType
, swizzleMode
))
4226 UINT_32 dim
= log2blkSize
% 3;
4231 (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1) && (mipDepthInBlk
<= 2);
4236 (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
<= 2);
4241 (mipWidthInBlk
<= 2) && (mipHeightInBlk
<= 2) && (mipDepthInBlk
== 1);
4246 if (log2blkSize
& 1)
4248 inTail
= (mipWidthInBlk
<= 2) && (mipHeightInBlk
== 1);
4252 inTail
= (mipWidthInBlk
== 1) && (mipHeightInBlk
<= 2);
4262 mipWidthInBlk
= RoundHalf(mipWidthInBlk
);
4263 mipHeightInBlk
= RoundHalf(mipHeightInBlk
);
4264 mipDepthInBlk
= RoundHalf(mipDepthInBlk
);
4267 if (mipId
>= endingMip
)
4270 mipIndexInTail
= mipId
- endingMip
;
4276 UINT_32 index
= mipIndexInTail
+ MaxMacroBits
- log2blkSize
;
4277 ADDR_ASSERT(index
< sizeof(MipTailOffset256B
) / sizeof(UINT_32
));
4278 *pMipTailBytesOffset
= MipTailOffset256B
[index
] << 8;
4285 ************************************************************************************************************************
4286 * Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled
4289 * Internal function to calculate address from coord for tiled swizzle surface
4293 ************************************************************************************************************************
4295 ADDR_E_RETURNCODE
Gfx9Lib::HwlComputeSurfaceAddrFromCoordTiled(
4296 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
4297 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
4300 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
4301 localIn
.swizzleMode
= pIn
->swizzleMode
;
4302 localIn
.flags
= pIn
->flags
;
4303 localIn
.resourceType
= pIn
->resourceType
;
4304 localIn
.bpp
= pIn
->bpp
;
4305 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
4306 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
4307 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
4308 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
4309 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
4310 localIn
.numFrags
= Max(pIn
->numFrags
, 1u);
4311 if (localIn
.numMipLevels
<= 1)
4313 localIn
.pitchInElement
= pIn
->pitchInElement
;
4316 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
4317 ADDR_E_RETURNCODE returnCode
= ComputeSurfaceInfoTiled(&localIn
, &localOut
);
4319 BOOL_32 valid
= (returnCode
== ADDR_OK
) &&
4320 (IsThin(pIn
->resourceType
, pIn
->swizzleMode
) ||
4321 IsThick(pIn
->resourceType
, pIn
->swizzleMode
)) &&
4322 ((pIn
->pipeBankXor
== 0) || (IsXor(pIn
->swizzleMode
)));
4326 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
4327 Dim3d mipStartPos
= {0};
4328 UINT_32 mipTailBytesOffset
= 0;
4330 if (pIn
->numMipLevels
> 1)
4332 // Mip-map chain cannot be MSAA surface
4333 ADDR_ASSERT((pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1));
4335 mipStartPos
= GetMipStartPos(pIn
->resourceType
,
4340 localOut
.blockWidth
,
4341 localOut
.blockHeight
,
4342 localOut
.blockSlices
,
4345 &mipTailBytesOffset
);
4348 UINT_32 interleaveOffset
= 0;
4349 UINT_32 pipeBits
= 0;
4350 UINT_32 pipeXor
= 0;
4351 UINT_32 bankBits
= 0;
4352 UINT_32 bankXor
= 0;
4354 if (IsThin(pIn
->resourceType
, pIn
->swizzleMode
))
4356 UINT_32 blockOffset
= 0;
4357 UINT_32 log2blkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4359 if (IsZOrderSwizzle(pIn
->swizzleMode
))
4361 // Morton generation
4362 if ((log2ElementBytes
== 0) || (log2ElementBytes
== 2))
4364 UINT_32 totalLowBits
= 6 - log2ElementBytes
;
4365 UINT_32 mortBits
= totalLowBits
/ 2;
4366 UINT_32 lowBitsValue
= MortonGen2d(pIn
->y
, pIn
->x
, mortBits
);
4367 // Are 9 bits enough?
4368 UINT_32 highBitsValue
=
4369 MortonGen2d(pIn
->x
>> mortBits
, pIn
->y
>> mortBits
, 9) << totalLowBits
;
4370 blockOffset
= lowBitsValue
| highBitsValue
;
4371 ADDR_ASSERT(blockOffset
== lowBitsValue
+ highBitsValue
);
4375 blockOffset
= MortonGen2d(pIn
->y
, pIn
->x
, 13);
4378 // Fill LSBs with sample bits
4379 if (pIn
->numSamples
> 1)
4381 blockOffset
*= pIn
->numSamples
;
4382 blockOffset
|= pIn
->sample
;
4385 // Shift according to BytesPP
4386 blockOffset
<<= log2ElementBytes
;
4390 // Micro block offset
4391 UINT_32 microBlockOffset
= ComputeSurface2DMicroBlockOffset(pIn
);
4392 blockOffset
= microBlockOffset
;
4394 // Micro block dimension
4395 ADDR_ASSERT(log2ElementBytes
< MaxNumOfBpp
);
4396 Dim2d microBlockDim
= Block256_2d
[log2ElementBytes
];
4397 // Morton generation, does 12 bit enough?
4399 MortonGen2d((pIn
->x
/ microBlockDim
.w
), (pIn
->y
/ microBlockDim
.h
), 12) << 8;
4401 // Sample bits start location
4402 UINT_32 sampleStart
= log2blkSize
- Log2(pIn
->numSamples
);
4403 // Join sample bits information to the highest Macro block bits
4404 if (IsNonPrtXor(pIn
->swizzleMode
))
4406 // Non-prt-Xor : xor highest Macro block bits with sample bits
4407 blockOffset
= blockOffset
^ (pIn
->sample
<< sampleStart
);
4411 // Non-Xor or prt-Xor: replace highest Macro block bits with sample bits
4412 // after this op, the blockOffset only contains log2 Macro block size bits
4413 blockOffset
%= (1 << sampleStart
);
4414 blockOffset
|= (pIn
->sample
<< sampleStart
);
4415 ADDR_ASSERT((blockOffset
>> log2blkSize
) == 0);
4419 if (IsXor(pIn
->swizzleMode
))
4421 // Mask off bits above Macro block bits to keep page synonyms working for prt
4422 if (IsPrt(pIn
->swizzleMode
))
4424 blockOffset
&= ((1 << log2blkSize
) - 1);
4427 // Preserve offset inside pipe interleave
4428 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4429 blockOffset
>>= m_pipeInterleaveLog2
;
4432 pipeBits
= GetPipeXorBits(log2blkSize
);
4434 pipeXor
= FoldXor2d(blockOffset
, pipeBits
);
4435 blockOffset
>>= pipeBits
;
4438 bankBits
= GetBankXorBits(log2blkSize
);
4440 bankXor
= FoldXor2d(blockOffset
, bankBits
);
4441 blockOffset
>>= bankBits
;
4443 // Put all the part back together
4444 blockOffset
<<= bankBits
;
4445 blockOffset
|= bankXor
;
4446 blockOffset
<<= pipeBits
;
4447 blockOffset
|= pipeXor
;
4448 blockOffset
<<= m_pipeInterleaveLog2
;
4449 blockOffset
|= interleaveOffset
;
4452 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4453 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2blkSize
)));
4455 blockOffset
|= mipTailBytesOffset
;
4457 if (IsNonPrtXor(pIn
->swizzleMode
) && (pIn
->numSamples
<= 1))
4459 // Apply slice xor if not MSAA/PRT
4460 blockOffset
^= (ReverseBitVector(pIn
->slice
, pipeBits
) << m_pipeInterleaveLog2
);
4461 blockOffset
^= (ReverseBitVector(pIn
->slice
>> pipeBits
, bankBits
) <<
4462 (m_pipeInterleaveLog2
+ pipeBits
));
4465 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4466 bankBits
, pipeBits
, &blockOffset
);
4468 blockOffset
%= (1 << log2blkSize
);
4470 UINT_32 pitchInMacroBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4471 UINT_32 paddedHeightInMacroBlock
= localOut
.mipChainHeight
/ localOut
.blockHeight
;
4472 UINT_32 sliceSizeInMacroBlock
= pitchInMacroBlock
* paddedHeightInMacroBlock
;
4473 UINT_32 macroBlockIndex
=
4474 (pIn
->slice
+ mipStartPos
.d
) * sliceSizeInMacroBlock
+
4475 ((pIn
->y
/ localOut
.blockHeight
) + mipStartPos
.h
) * pitchInMacroBlock
+
4476 ((pIn
->x
/ localOut
.blockWidth
) + mipStartPos
.w
);
4478 UINT_64 macroBlockOffset
= (static_cast<UINT_64
>(macroBlockIndex
) <<
4479 GetBlockSizeLog2(pIn
->swizzleMode
));
4481 pOut
->addr
= blockOffset
| macroBlockOffset
;
4485 UINT_32 log2blkSize
= GetBlockSizeLog2(pIn
->swizzleMode
);
4487 Dim3d microBlockDim
= Block1K_3d
[log2ElementBytes
];
4489 UINT_32 blockOffset
= MortonGen3d((pIn
->x
/ microBlockDim
.w
),
4490 (pIn
->y
/ microBlockDim
.h
),
4491 (pIn
->slice
/ microBlockDim
.d
),
4495 blockOffset
|= ComputeSurface3DMicroBlockOffset(pIn
);
4497 if (IsXor(pIn
->swizzleMode
))
4499 // Mask off bits above Macro block bits to keep page synonyms working for prt
4500 if (IsPrt(pIn
->swizzleMode
))
4502 blockOffset
&= ((1 << log2blkSize
) - 1);
4505 // Preserve offset inside pipe interleave
4506 interleaveOffset
= blockOffset
& ((1 << m_pipeInterleaveLog2
) - 1);
4507 blockOffset
>>= m_pipeInterleaveLog2
;
4510 pipeBits
= GetPipeXorBits(log2blkSize
);
4512 pipeXor
= FoldXor3d(blockOffset
, pipeBits
);
4513 blockOffset
>>= pipeBits
;
4516 bankBits
= GetBankXorBits(log2blkSize
);
4518 bankXor
= FoldXor3d(blockOffset
, bankBits
);
4519 blockOffset
>>= bankBits
;
4521 // Put all the part back together
4522 blockOffset
<<= bankBits
;
4523 blockOffset
|= bankXor
;
4524 blockOffset
<<= pipeBits
;
4525 blockOffset
|= pipeXor
;
4526 blockOffset
<<= m_pipeInterleaveLog2
;
4527 blockOffset
|= interleaveOffset
;
4530 ADDR_ASSERT((blockOffset
| mipTailBytesOffset
) == (blockOffset
+ mipTailBytesOffset
));
4531 ADDR_ASSERT((mipTailBytesOffset
== 0u) || (blockOffset
< (1u << log2blkSize
)));
4532 blockOffset
|= mipTailBytesOffset
;
4534 returnCode
= ApplyCustomerPipeBankXor(pIn
->swizzleMode
, pIn
->pipeBankXor
,
4535 bankBits
, pipeBits
, &blockOffset
);
4537 blockOffset
%= (1 << log2blkSize
);
4539 UINT_32 xb
= pIn
->x
/ localOut
.blockWidth
+ mipStartPos
.w
;
4540 UINT_32 yb
= pIn
->y
/ localOut
.blockHeight
+ mipStartPos
.h
;
4541 UINT_32 zb
= pIn
->slice
/ localOut
.blockSlices
+ + mipStartPos
.d
;
4543 UINT_32 pitchInBlock
= localOut
.mipChainPitch
/ localOut
.blockWidth
;
4544 UINT_32 sliceSizeInBlock
=
4545 (localOut
.mipChainHeight
/ localOut
.blockHeight
) * pitchInBlock
;
4546 UINT_32 blockIndex
= zb
* sliceSizeInBlock
+ yb
* pitchInBlock
+ xb
;
4548 pOut
->addr
= blockOffset
| (blockIndex
<< log2blkSize
);
4553 returnCode
= ADDR_INVALIDPARAMS
;