2 * Copyright © 2014 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 ***************************************************************************************************
30 * @brief Contains the implementation for the AddrLib base class..
31 ***************************************************************************************************
34 #include "addrinterface.h"
36 #include "addrcommon.h"
38 #if defined(__APPLE__)
40 UINT_32
div64_32(UINT_64 n
, UINT_32 base
)
45 UINT_32 high
= rem
>> 32;
51 res
= (UINT_64
) high
<< 32;
52 rem
-= (UINT_64
) (high
*base
) << 32;
55 while ((INT_64
)b
> 0 && b
< rem
)
77 UINT_32
__umoddi3(UINT_64 n
, UINT_32 base
)
79 return div64_32(n
, base
);
84 ///////////////////////////////////////////////////////////////////////////////////////////////////
85 // Static Const Member
86 ///////////////////////////////////////////////////////////////////////////////////////////////////
88 const AddrTileModeFlags
AddrLib::m_modeFlags
[ADDR_TM_COUNT
] =
90 {1, 1, 0, 0, 0, 0, 0, 0}, // ADDR_TM_LINEAR_GENERAL
91 {1, 1, 0, 0, 0, 0, 0, 0}, // ADDR_TM_LINEAR_ALIGNED
92 {1, 0, 1, 0, 0, 0, 0, 0}, // ADDR_TM_1D_TILED_THIN1
93 {4, 0, 1, 0, 0, 0, 0, 0}, // ADDR_TM_1D_TILED_THICK
94 {1, 0, 0, 1, 0, 0, 0, 0}, // ADDR_TM_2D_TILED_THIN1
95 {1, 0, 0, 1, 0, 0, 0, 0}, // ADDR_TM_2D_TILED_THIN2
96 {1, 0, 0, 1, 0, 0, 0, 0}, // ADDR_TM_2D_TILED_THIN4
97 {4, 0, 0, 1, 0, 0, 0, 0}, // ADDR_TM_2D_TILED_THICK
98 {1, 0, 0, 1, 0, 0, 0, 1}, // ADDR_TM_2B_TILED_THIN1
99 {1, 0, 0, 1, 0, 0, 0, 1}, // ADDR_TM_2B_TILED_THIN2
100 {1, 0, 0, 1, 0, 0, 0, 1}, // ADDR_TM_2B_TILED_THIN4
101 {4, 0, 0, 1, 0, 0, 0, 1}, // ADDR_TM_2B_TILED_THICK
102 {1, 0, 0, 1, 1, 0, 0, 0}, // ADDR_TM_3D_TILED_THIN1
103 {4, 0, 0, 1, 1, 0, 0, 0}, // ADDR_TM_3D_TILED_THICK
104 {1, 0, 0, 1, 1, 0, 0, 1}, // ADDR_TM_3B_TILED_THIN1
105 {4, 0, 0, 1, 1, 0, 0, 1}, // ADDR_TM_3B_TILED_THICK
106 {8, 0, 0, 1, 0, 0, 0, 0}, // ADDR_TM_2D_TILED_XTHICK
107 {8, 0, 0, 1, 1, 0, 0, 0}, // ADDR_TM_3D_TILED_XTHICK
108 {1, 0, 0, 0, 0, 0, 0, 0}, // ADDR_TM_POWER_SAVE
109 {1, 0, 0, 1, 0, 1, 1, 0}, // ADDR_TM_PRT_TILED_THIN1
110 {1, 0, 0, 1, 0, 1, 0, 0}, // ADDR_TM_PRT_2D_TILED_THIN1
111 {1, 0, 0, 1, 1, 1, 0, 0}, // ADDR_TM_PRT_3D_TILED_THIN1
112 {4, 0, 0, 1, 0, 1, 1, 0}, // ADDR_TM_PRT_TILED_THICK
113 {4, 0, 0, 1, 0, 1, 0, 0}, // ADDR_TM_PRT_2D_TILED_THICK
114 {4, 0, 0, 1, 1, 1, 0, 0}, // ADDR_TM_PRT_3D_TILED_THICK
117 ///////////////////////////////////////////////////////////////////////////////////////////////////
118 // Constructor/Destructor
119 ///////////////////////////////////////////////////////////////////////////////////////////////////
122 ***************************************************************************************************
126 * Constructor for the AddrLib class
128 ***************************************************************************************************
131 m_class(BASE_ADDRLIB
),
132 m_chipFamily(ADDR_CHIP_FAMILY_IVLD
),
134 m_version(ADDRLIB_VERSION
),
137 m_pipeInterleaveBytes(0),
139 m_minPitchAlignPixels(1),
143 m_configFlags
.value
= 0;
147 ***************************************************************************************************
151 * Constructor for the AddrLib class with hClient as parameter
153 ***************************************************************************************************
155 AddrLib::AddrLib(const AddrClient
* pClient
) :
157 m_class(BASE_ADDRLIB
),
158 m_chipFamily(ADDR_CHIP_FAMILY_IVLD
),
160 m_version(ADDRLIB_VERSION
),
163 m_pipeInterleaveBytes(0),
165 m_minPitchAlignPixels(1),
169 m_configFlags
.value
= 0;
173 ***************************************************************************************************
177 * Destructor for the AddrLib class
179 ***************************************************************************************************
191 ///////////////////////////////////////////////////////////////////////////////////////////////////
192 // Initialization/Helper
193 ///////////////////////////////////////////////////////////////////////////////////////////////////
196 ***************************************************************************************************
200 * Creates and initializes AddrLib object.
204 ***************************************************************************************************
206 ADDR_E_RETURNCODE
AddrLib::Create(
207 const ADDR_CREATE_INPUT
* pCreateIn
, ///< [in] pointer to ADDR_CREATE_INPUT
208 ADDR_CREATE_OUTPUT
* pCreateOut
) ///< [out] pointer to ADDR_CREATE_OUTPUT
210 AddrLib
* pLib
= NULL
;
211 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
213 if (pCreateIn
->createFlags
.fillSizeFields
== TRUE
)
215 if ((pCreateIn
->size
!= sizeof(ADDR_CREATE_INPUT
)) ||
216 (pCreateOut
->size
!= sizeof(ADDR_CREATE_OUTPUT
)))
218 returnCode
= ADDR_PARAMSIZEMISMATCH
;
222 if ((returnCode
== ADDR_OK
) &&
223 (pCreateIn
->callbacks
.allocSysMem
!= NULL
) &&
224 (pCreateIn
->callbacks
.freeSysMem
!= NULL
))
226 AddrClient client
= {
231 switch (pCreateIn
->chipEngine
)
233 case CIASICIDGFXENGINE_SOUTHERNISLAND
:
234 switch (pCreateIn
->chipFamily
)
237 pLib
= AddrSIHwlInit(&client
);
240 case FAMILY_CZ
: // VI based fusion(carrizo)
242 case FAMILY_KV
: // CI based fusion
243 pLib
= AddrCIHwlInit(&client
);
246 ADDR_ASSERT_ALWAYS();
251 ADDR_ASSERT_ALWAYS();
260 // Pass createFlags to configFlags first since these flags may be overwritten
261 pLib
->m_configFlags
.noCubeMipSlicesPad
= pCreateIn
->createFlags
.noCubeMipSlicesPad
;
262 pLib
->m_configFlags
.fillSizeFields
= pCreateIn
->createFlags
.fillSizeFields
;
263 pLib
->m_configFlags
.useTileIndex
= pCreateIn
->createFlags
.useTileIndex
;
264 pLib
->m_configFlags
.useCombinedSwizzle
= pCreateIn
->createFlags
.useCombinedSwizzle
;
265 pLib
->m_configFlags
.checkLast2DLevel
= pCreateIn
->createFlags
.checkLast2DLevel
;
266 pLib
->m_configFlags
.useHtileSliceAlign
= pCreateIn
->createFlags
.useHtileSliceAlign
;
267 pLib
->m_configFlags
.allowLargeThickTile
= pCreateIn
->createFlags
.allowLargeThickTile
;
269 pLib
->SetAddrChipFamily(pCreateIn
->chipFamily
, pCreateIn
->chipRevision
);
271 pLib
->SetMinPitchAlignPixels(pCreateIn
->minPitchAlignPixels
);
273 // Global parameters initialized and remaining configFlags bits are set as well
274 initValid
= pLib
->HwlInitGlobalParams(pCreateIn
);
278 pLib
->m_pElemLib
= AddrElemLib::Create(pLib
);
282 pLib
->m_pElemLib
= NULL
; // Don't go on allocating element lib
283 returnCode
= ADDR_INVALIDGBREGVALUES
;
286 if (pLib
->m_pElemLib
== NULL
)
290 ADDR_ASSERT_ALWAYS();
294 pLib
->m_pElemLib
->SetConfigFlags(pLib
->m_configFlags
);
298 pCreateOut
->hLib
= pLib
;
300 if ((pLib
== NULL
) &&
301 (returnCode
== ADDR_OK
))
303 // Unknown failures, we return the general error code
304 returnCode
= ADDR_ERROR
;
311 ***************************************************************************************************
312 * AddrLib::SetAddrChipFamily
315 * Convert familyID defined in atiid.h to AddrChipFamily and set m_chipFamily/m_chipRevision
318 ***************************************************************************************************
320 VOID
AddrLib::SetAddrChipFamily(
321 UINT_32 uChipFamily
, ///< [in] chip family defined in atiih.h
322 UINT_32 uChipRevision
) ///< [in] chip revision defined in "asic_family"_id.h
324 AddrChipFamily family
= ADDR_CHIP_FAMILY_IVLD
;
326 family
= HwlConvertChipFamily(uChipFamily
, uChipRevision
);
328 ADDR_ASSERT(family
!= ADDR_CHIP_FAMILY_IVLD
);
330 m_chipFamily
= family
;
331 m_chipRevision
= uChipRevision
;
335 ***************************************************************************************************
336 * AddrLib::SetMinPitchAlignPixels
339 * Set m_minPitchAlignPixels with input param
343 ***************************************************************************************************
345 VOID
AddrLib::SetMinPitchAlignPixels(
346 UINT_32 minPitchAlignPixels
) ///< [in] minmum pitch alignment in pixels
348 m_minPitchAlignPixels
= (minPitchAlignPixels
== 0)? 1 : minPitchAlignPixels
;
352 ***************************************************************************************************
353 * AddrLib::GetAddrLib
356 * Get AddrLib pointer
359 * An AddrLib class pointer
360 ***************************************************************************************************
362 AddrLib
* AddrLib::GetAddrLib(
363 ADDR_HANDLE hLib
) ///< [in] handle of ADDR_HANDLE
365 return static_cast<AddrLib
*>(hLib
);
370 ///////////////////////////////////////////////////////////////////////////////////////////////////
372 ///////////////////////////////////////////////////////////////////////////////////////////////////
376 ***************************************************************************************************
377 * AddrLib::ComputeSurfaceInfo
380 * Interface function stub of AddrComputeSurfaceInfo.
384 ***************************************************************************************************
386 ADDR_E_RETURNCODE
AddrLib::ComputeSurfaceInfo(
387 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
388 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
391 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
393 if (GetFillSizeFieldsFlags() == TRUE
)
395 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_SURFACE_INFO_INPUT
)) ||
396 (pOut
->size
!= sizeof(ADDR_COMPUTE_SURFACE_INFO_OUTPUT
)))
398 returnCode
= ADDR_PARAMSIZEMISMATCH
;
402 // We suggest client do sanity check but a check here is also good
405 returnCode
= ADDR_INVALIDPARAMS
;
408 // Thick modes don't support multisample
409 if (ComputeSurfaceThickness(pIn
->tileMode
) > 1 && pIn
->numSamples
> 1)
411 returnCode
= ADDR_INVALIDPARAMS
;
414 if (returnCode
== ADDR_OK
)
416 // Get a local copy of input structure and only reference pIn for unadjusted values
417 ADDR_COMPUTE_SURFACE_INFO_INPUT localIn
= *pIn
;
418 ADDR_TILEINFO tileInfoNull
= {0};
422 // If the original input has a valid ADDR_TILEINFO pointer then copy its contents.
423 // Otherwise the default 0's in tileInfoNull are used.
426 tileInfoNull
= *pIn
->pTileInfo
;
428 localIn
.pTileInfo
= &tileInfoNull
;
431 localIn
.numSamples
= pIn
->numSamples
== 0 ? 1 : pIn
->numSamples
;
433 // Do mipmap check first
434 // If format is BCn, pre-pad dimension to power-of-two according to HWL
435 ComputeMipLevel(&localIn
);
437 if (m_configFlags
.checkLast2DLevel
)
439 // Save this level's original height in pixels
440 pOut
->height
= pIn
->height
;
445 AddrElemMode elemMode
;
447 // Save outputs that may not go through HWL
448 pOut
->pixelBits
= localIn
.bpp
;
449 pOut
->numSamples
= localIn
.numSamples
;
450 pOut
->last2DLevel
= FALSE
;
451 pOut
->tcCompatible
= FALSE
;
454 if (localIn
.numSamples
> 1)
456 ADDR_ASSERT(localIn
.mipLevel
== 0);
460 if (localIn
.format
!= ADDR_FMT_INVALID
) // Set format to INVALID will skip this conversion
462 // Get compression/expansion factors and element mode
463 // (which indicates compression/expansion
464 localIn
.bpp
= GetElemLib()->GetBitsPerPixel(localIn
.format
,
469 // Special flag for 96 bit surface. 96 (or 48 if we support) bit surface's width is
470 // pre-multiplied by 3 and bpp is divided by 3. So pitch alignment for linear-
471 // aligned does not meet 64-pixel in real. We keep special handling in hwl since hw
472 // restrictions are different.
473 // Also Mip 1+ needs an element pitch of 32 bits so we do not need this workaround
474 // but we use this flag to skip RestoreSurfaceInfo below
476 if ((elemMode
== ADDR_EXPANDED
) &&
479 ADDR_ASSERT(localIn
.tileMode
== ADDR_TM_LINEAR_ALIGNED
|| localIn
.height
== 1);
482 GetElemLib()->AdjustSurfaceInfo(elemMode
,
490 // Overwrite these parameters if we have a valid format
492 else if (localIn
.bpp
!= 0)
494 localIn
.width
= (localIn
.width
!= 0) ? localIn
.width
: 1;
495 localIn
.height
= (localIn
.height
!= 0) ? localIn
.height
: 1;
497 else // Rule out some invalid parameters
499 ADDR_ASSERT_ALWAYS();
501 returnCode
= ADDR_INVALIDPARAMS
;
504 // Check mipmap after surface expansion
505 if (returnCode
== ADDR_OK
)
507 returnCode
= PostComputeMipLevel(&localIn
, pOut
);
510 if (returnCode
== ADDR_OK
)
512 if (UseTileIndex(localIn
.tileIndex
))
514 // Make sure pTileInfo is not NULL
515 ADDR_ASSERT(localIn
.pTileInfo
);
517 UINT_32 numSamples
= GetNumFragments(localIn
.numSamples
, localIn
.numFrags
);
519 INT_32 macroModeIndex
= TileIndexNoMacroIndex
;
521 if (localIn
.tileIndex
!= TileIndexLinearGeneral
)
523 // Try finding a macroModeIndex
524 macroModeIndex
= HwlComputeMacroModeIndex(localIn
.tileIndex
,
533 // If macroModeIndex is not needed, then call HwlSetupTileCfg to get tile info
534 if (macroModeIndex
== TileIndexNoMacroIndex
)
536 returnCode
= HwlSetupTileCfg(localIn
.tileIndex
, macroModeIndex
,
538 &localIn
.tileMode
, &localIn
.tileType
);
540 // If macroModeIndex is invalid, then assert this is not macro tiled
541 else if (macroModeIndex
== TileIndexInvalid
)
543 ADDR_ASSERT(!IsMacroTiled(localIn
.tileMode
));
546 pOut
->macroModeIndex
= macroModeIndex
;
550 if (returnCode
== ADDR_OK
)
552 AddrTileMode tileMode
= localIn
.tileMode
;
553 AddrTileType tileType
= localIn
.tileType
;
555 // HWL layer may override tile mode if necessary
556 if (HwlOverrideTileMode(&localIn
, &tileMode
, &tileType
))
558 localIn
.tileMode
= tileMode
;
559 localIn
.tileType
= tileType
;
561 // Optimize tile mode if possible
562 if (OptimizeTileMode(&localIn
, &tileMode
))
564 localIn
.tileMode
= tileMode
;
568 // Call main function to compute surface info
569 if (returnCode
== ADDR_OK
)
571 returnCode
= HwlComputeSurfaceInfo(&localIn
, pOut
);
574 if (returnCode
== ADDR_OK
)
576 // Since bpp might be changed we just pass it through
577 pOut
->bpp
= localIn
.bpp
;
579 // Also original width/height/bpp
580 pOut
->pixelPitch
= pOut
->pitch
;
581 pOut
->pixelHeight
= pOut
->height
;
584 if (localIn
.flags
.display
)
586 ADDR_ASSERT((pOut
->pitchAlign
% 32) == 0);
590 if (localIn
.format
!= ADDR_FMT_INVALID
)
593 // 96 bits surface of level 1+ requires element pitch of 32 bits instead
594 // In hwl function we skip multiplication of 3 then we should skip division of 3
595 // We keep pitch that represents 32 bit element instead of 96 bits since we
596 // will get an odd number if divided by 3.
598 if (!((expandX
== 3) && (localIn
.mipLevel
> 0)))
601 GetElemLib()->RestoreSurfaceInfo(elemMode
,
610 if (localIn
.flags
.qbStereo
)
612 if (pOut
->pStereoInfo
)
614 ComputeQbStereoInfo(pOut
);
618 if (localIn
.flags
.volume
) // For volume sliceSize equals to all z-slices
620 pOut
->sliceSize
= pOut
->surfSize
;
622 else // For array: sliceSize is likely to have slice-padding (the last one)
624 pOut
->sliceSize
= pOut
->surfSize
/ pOut
->depth
;
627 if (pIn
->numSlices
> 1)
629 // If this is the last slice then add the padding size to this slice
630 if (pIn
->slice
== (pIn
->numSlices
- 1))
632 pOut
->sliceSize
+= pOut
->sliceSize
* (pOut
->depth
- pIn
->numSlices
);
634 else if (m_configFlags
.checkLast2DLevel
)
636 // Reset last2DLevel flag if this is not the last array slice
637 pOut
->last2DLevel
= FALSE
;
642 pOut
->pitchTileMax
= pOut
->pitch
/ 8 - 1;
643 pOut
->heightTileMax
= pOut
->height
/ 8 - 1;
644 pOut
->sliceTileMax
= pOut
->pitch
* pOut
->height
/ 64 - 1;
652 ***************************************************************************************************
653 * AddrLib::ComputeSurfaceInfo
656 * Interface function stub of AddrComputeSurfaceInfo.
660 ***************************************************************************************************
662 ADDR_E_RETURNCODE
AddrLib::ComputeSurfaceAddrFromCoord(
663 const ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
664 ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
667 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
669 if (GetFillSizeFieldsFlags() == TRUE
)
671 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
)) ||
672 (pOut
->size
!= sizeof(ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
)))
674 returnCode
= ADDR_PARAMSIZEMISMATCH
;
678 if (returnCode
== ADDR_OK
)
680 ADDR_TILEINFO tileInfoNull
;
681 ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT input
;
683 if (UseTileIndex(pIn
->tileIndex
))
686 // Use temp tile info for calcalation
687 input
.pTileInfo
= &tileInfoNull
;
689 const ADDR_SURFACE_FLAGS flags
= {{0}};
690 UINT_32 numSamples
= GetNumFragments(pIn
->numSamples
, pIn
->numFrags
);
692 // Try finding a macroModeIndex
693 INT_32 macroModeIndex
= HwlComputeMacroModeIndex(input
.tileIndex
,
701 // If macroModeIndex is not needed, then call HwlSetupTileCfg to get tile info
702 if (macroModeIndex
== TileIndexNoMacroIndex
)
704 returnCode
= HwlSetupTileCfg(input
.tileIndex
, macroModeIndex
,
705 input
.pTileInfo
, &input
.tileMode
, &input
.tileType
);
707 // If macroModeIndex is invalid, then assert this is not macro tiled
708 else if (macroModeIndex
== TileIndexInvalid
)
710 ADDR_ASSERT(!IsMacroTiled(input
.tileMode
));
713 // Change the input structure
717 if (returnCode
== ADDR_OK
)
719 returnCode
= HwlComputeSurfaceAddrFromCoord(pIn
, pOut
);
721 if (returnCode
== ADDR_OK
)
723 pOut
->prtBlockIndex
= static_cast<UINT_32
>(pOut
->addr
/ (64 * 1024));
732 ***************************************************************************************************
733 * AddrLib::ComputeSurfaceCoordFromAddr
736 * Interface function stub of ComputeSurfaceCoordFromAddr.
740 ***************************************************************************************************
742 ADDR_E_RETURNCODE
AddrLib::ComputeSurfaceCoordFromAddr(
743 const ADDR_COMPUTE_SURFACE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
744 ADDR_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
747 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
749 if (GetFillSizeFieldsFlags() == TRUE
)
751 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_SURFACE_COORDFROMADDR_INPUT
)) ||
752 (pOut
->size
!= sizeof(ADDR_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
)))
754 returnCode
= ADDR_PARAMSIZEMISMATCH
;
758 if (returnCode
== ADDR_OK
)
760 ADDR_TILEINFO tileInfoNull
;
761 ADDR_COMPUTE_SURFACE_COORDFROMADDR_INPUT input
;
763 if (UseTileIndex(pIn
->tileIndex
))
766 // Use temp tile info for calcalation
767 input
.pTileInfo
= &tileInfoNull
;
769 const ADDR_SURFACE_FLAGS flags
= {{0}};
770 UINT_32 numSamples
= GetNumFragments(pIn
->numSamples
, pIn
->numFrags
);
772 // Try finding a macroModeIndex
773 INT_32 macroModeIndex
= HwlComputeMacroModeIndex(input
.tileIndex
,
781 // If macroModeIndex is not needed, then call HwlSetupTileCfg to get tile info
782 if (macroModeIndex
== TileIndexNoMacroIndex
)
784 returnCode
= HwlSetupTileCfg(input
.tileIndex
, macroModeIndex
,
785 input
.pTileInfo
, &input
.tileMode
, &input
.tileType
);
787 // If macroModeIndex is invalid, then assert this is not macro tiled
788 else if (macroModeIndex
== TileIndexInvalid
)
790 ADDR_ASSERT(!IsMacroTiled(input
.tileMode
));
793 // Change the input structure
797 if (returnCode
== ADDR_OK
)
799 returnCode
= HwlComputeSurfaceCoordFromAddr(pIn
, pOut
);
807 ***************************************************************************************************
808 * AddrLib::ComputeSliceTileSwizzle
811 * Interface function stub of ComputeSliceTileSwizzle.
815 ***************************************************************************************************
817 ADDR_E_RETURNCODE
AddrLib::ComputeSliceTileSwizzle(
818 const ADDR_COMPUTE_SLICESWIZZLE_INPUT
* pIn
, ///< [in] input structure
819 ADDR_COMPUTE_SLICESWIZZLE_OUTPUT
* pOut
///< [out] output structure
822 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
824 if (GetFillSizeFieldsFlags() == TRUE
)
826 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_SLICESWIZZLE_INPUT
)) ||
827 (pOut
->size
!= sizeof(ADDR_COMPUTE_SLICESWIZZLE_OUTPUT
)))
829 returnCode
= ADDR_PARAMSIZEMISMATCH
;
833 if (returnCode
== ADDR_OK
)
835 ADDR_TILEINFO tileInfoNull
;
836 ADDR_COMPUTE_SLICESWIZZLE_INPUT input
;
838 if (UseTileIndex(pIn
->tileIndex
))
841 // Use temp tile info for calcalation
842 input
.pTileInfo
= &tileInfoNull
;
844 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
,
845 input
.pTileInfo
, &input
.tileMode
);
846 // Change the input structure
850 if (returnCode
== ADDR_OK
)
852 returnCode
= HwlComputeSliceTileSwizzle(pIn
, pOut
);
860 ***************************************************************************************************
861 * AddrLib::ExtractBankPipeSwizzle
864 * Interface function stub of AddrExtractBankPipeSwizzle.
868 ***************************************************************************************************
870 ADDR_E_RETURNCODE
AddrLib::ExtractBankPipeSwizzle(
871 const ADDR_EXTRACT_BANKPIPE_SWIZZLE_INPUT
* pIn
, ///< [in] input structure
872 ADDR_EXTRACT_BANKPIPE_SWIZZLE_OUTPUT
* pOut
///< [out] output structure
875 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
877 if (GetFillSizeFieldsFlags() == TRUE
)
879 if ((pIn
->size
!= sizeof(ADDR_EXTRACT_BANKPIPE_SWIZZLE_INPUT
)) ||
880 (pOut
->size
!= sizeof(ADDR_EXTRACT_BANKPIPE_SWIZZLE_OUTPUT
)))
882 returnCode
= ADDR_PARAMSIZEMISMATCH
;
886 if (returnCode
== ADDR_OK
)
888 ADDR_TILEINFO tileInfoNull
;
889 ADDR_EXTRACT_BANKPIPE_SWIZZLE_INPUT input
;
891 if (UseTileIndex(pIn
->tileIndex
))
894 // Use temp tile info for calcalation
895 input
.pTileInfo
= &tileInfoNull
;
897 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
898 // Change the input structure
902 if (returnCode
== ADDR_OK
)
904 returnCode
= HwlExtractBankPipeSwizzle(pIn
, pOut
);
912 ***************************************************************************************************
913 * AddrLib::CombineBankPipeSwizzle
916 * Interface function stub of AddrCombineBankPipeSwizzle.
920 ***************************************************************************************************
922 ADDR_E_RETURNCODE
AddrLib::CombineBankPipeSwizzle(
923 const ADDR_COMBINE_BANKPIPE_SWIZZLE_INPUT
* pIn
, ///< [in] input structure
924 ADDR_COMBINE_BANKPIPE_SWIZZLE_OUTPUT
* pOut
///< [out] output structure
927 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
929 if (GetFillSizeFieldsFlags() == TRUE
)
931 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_FMASK_INFO_INPUT
)) ||
932 (pOut
->size
!= sizeof(ADDR_COMPUTE_FMASK_INFO_OUTPUT
)))
934 returnCode
= ADDR_PARAMSIZEMISMATCH
;
938 if (returnCode
== ADDR_OK
)
940 ADDR_TILEINFO tileInfoNull
;
941 ADDR_COMBINE_BANKPIPE_SWIZZLE_INPUT input
;
943 if (UseTileIndex(pIn
->tileIndex
))
946 // Use temp tile info for calcalation
947 input
.pTileInfo
= &tileInfoNull
;
949 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
950 // Change the input structure
954 if (returnCode
== ADDR_OK
)
956 returnCode
= HwlCombineBankPipeSwizzle(pIn
->bankSwizzle
,
968 ***************************************************************************************************
969 * AddrLib::ComputeBaseSwizzle
972 * Interface function stub of AddrCompueBaseSwizzle.
975 ***************************************************************************************************
977 ADDR_E_RETURNCODE
AddrLib::ComputeBaseSwizzle(
978 const ADDR_COMPUTE_BASE_SWIZZLE_INPUT
* pIn
,
979 ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT
* pOut
) const
981 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
983 if (GetFillSizeFieldsFlags() == TRUE
)
985 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_BASE_SWIZZLE_INPUT
)) ||
986 (pOut
->size
!= sizeof(ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT
)))
988 returnCode
= ADDR_PARAMSIZEMISMATCH
;
992 if (returnCode
== ADDR_OK
)
994 ADDR_TILEINFO tileInfoNull
;
995 ADDR_COMPUTE_BASE_SWIZZLE_INPUT input
;
997 if (UseTileIndex(pIn
->tileIndex
))
1000 // Use temp tile info for calcalation
1001 input
.pTileInfo
= &tileInfoNull
;
1003 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1004 // Change the input structure
1008 if (returnCode
== ADDR_OK
)
1010 if (IsMacroTiled(pIn
->tileMode
))
1012 returnCode
= HwlComputeBaseSwizzle(pIn
, pOut
);
1016 pOut
->tileSwizzle
= 0;
1025 ***************************************************************************************************
1026 * AddrLib::ComputeFmaskInfo
1029 * Interface function stub of ComputeFmaskInfo.
1033 ***************************************************************************************************
1035 ADDR_E_RETURNCODE
AddrLib::ComputeFmaskInfo(
1036 const ADDR_COMPUTE_FMASK_INFO_INPUT
* pIn
, ///< [in] input structure
1037 ADDR_COMPUTE_FMASK_INFO_OUTPUT
* pOut
///< [out] output structure
1040 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1042 if (GetFillSizeFieldsFlags() == TRUE
)
1044 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_FMASK_INFO_INPUT
)) ||
1045 (pOut
->size
!= sizeof(ADDR_COMPUTE_FMASK_INFO_OUTPUT
)))
1047 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1052 if (ComputeSurfaceThickness(pIn
->tileMode
) > 1)
1054 returnCode
= ADDR_INVALIDPARAMS
;
1057 if (returnCode
== ADDR_OK
)
1059 ADDR_TILEINFO tileInfoNull
;
1060 ADDR_COMPUTE_FMASK_INFO_INPUT input
;
1062 if (UseTileIndex(pIn
->tileIndex
))
1066 if (pOut
->pTileInfo
)
1068 // Use temp tile info for calcalation
1069 input
.pTileInfo
= pOut
->pTileInfo
;
1073 input
.pTileInfo
= &tileInfoNull
;
1076 ADDR_SURFACE_FLAGS flags
= {{0}};
1079 // Try finding a macroModeIndex
1080 INT_32 macroModeIndex
= HwlComputeMacroModeIndex(pIn
->tileIndex
,
1082 HwlComputeFmaskBits(pIn
, NULL
),
1087 // If macroModeIndex is not needed, then call HwlSetupTileCfg to get tile info
1088 if (macroModeIndex
== TileIndexNoMacroIndex
)
1090 returnCode
= HwlSetupTileCfg(input
.tileIndex
, macroModeIndex
,
1091 input
.pTileInfo
, &input
.tileMode
);
1094 ADDR_ASSERT(macroModeIndex
!= TileIndexInvalid
);
1096 // Change the input structure
1100 if (returnCode
== ADDR_OK
)
1102 if (pIn
->numSamples
> 1)
1104 returnCode
= HwlComputeFmaskInfo(pIn
, pOut
);
1108 memset(pOut
, 0, sizeof(ADDR_COMPUTE_FMASK_INFO_OUTPUT
));
1110 returnCode
= ADDR_INVALIDPARAMS
;
1119 ***************************************************************************************************
1120 * AddrLib::ComputeFmaskAddrFromCoord
1123 * Interface function stub of ComputeFmaskAddrFromCoord.
1127 ***************************************************************************************************
1129 ADDR_E_RETURNCODE
AddrLib::ComputeFmaskAddrFromCoord(
1130 const ADDR_COMPUTE_FMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1131 ADDR_COMPUTE_FMASK_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1134 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1136 if (GetFillSizeFieldsFlags() == TRUE
)
1138 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_FMASK_ADDRFROMCOORD_INPUT
)) ||
1139 (pOut
->size
!= sizeof(ADDR_COMPUTE_FMASK_ADDRFROMCOORD_OUTPUT
)))
1141 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1145 if (returnCode
== ADDR_OK
)
1147 ADDR_ASSERT(pIn
->numSamples
> 1);
1149 if (pIn
->numSamples
> 1)
1151 returnCode
= HwlComputeFmaskAddrFromCoord(pIn
, pOut
);
1155 returnCode
= ADDR_INVALIDPARAMS
;
1163 ***************************************************************************************************
1164 * AddrLib::ComputeFmaskCoordFromAddr
1167 * Interface function stub of ComputeFmaskAddrFromCoord.
1171 ***************************************************************************************************
1173 ADDR_E_RETURNCODE
AddrLib::ComputeFmaskCoordFromAddr(
1174 const ADDR_COMPUTE_FMASK_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1175 ADDR_COMPUTE_FMASK_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1178 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1180 if (GetFillSizeFieldsFlags() == TRUE
)
1182 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_FMASK_COORDFROMADDR_INPUT
)) ||
1183 (pOut
->size
!= sizeof(ADDR_COMPUTE_FMASK_COORDFROMADDR_OUTPUT
)))
1185 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1189 if (returnCode
== ADDR_OK
)
1191 ADDR_ASSERT(pIn
->numSamples
> 1);
1193 if (pIn
->numSamples
> 1)
1195 returnCode
= HwlComputeFmaskCoordFromAddr(pIn
, pOut
);
1199 returnCode
= ADDR_INVALIDPARAMS
;
1207 ***************************************************************************************************
1208 * AddrLib::ConvertTileInfoToHW
1211 * Convert tile info from real value to HW register value in HW layer
1215 ***************************************************************************************************
1217 ADDR_E_RETURNCODE
AddrLib::ConvertTileInfoToHW(
1218 const ADDR_CONVERT_TILEINFOTOHW_INPUT
* pIn
, ///< [in] input structure
1219 ADDR_CONVERT_TILEINFOTOHW_OUTPUT
* pOut
///< [out] output structure
1222 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1224 if (GetFillSizeFieldsFlags() == TRUE
)
1226 if ((pIn
->size
!= sizeof(ADDR_CONVERT_TILEINFOTOHW_INPUT
)) ||
1227 (pOut
->size
!= sizeof(ADDR_CONVERT_TILEINFOTOHW_OUTPUT
)))
1229 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1233 if (returnCode
== ADDR_OK
)
1235 ADDR_TILEINFO tileInfoNull
;
1236 ADDR_CONVERT_TILEINFOTOHW_INPUT input
;
1237 // if pIn->reverse is TRUE, indices are ignored
1238 if (pIn
->reverse
== FALSE
&& UseTileIndex(pIn
->tileIndex
))
1241 input
.pTileInfo
= &tileInfoNull
;
1243 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1248 if (returnCode
== ADDR_OK
)
1250 returnCode
= HwlConvertTileInfoToHW(pIn
, pOut
);
1258 ***************************************************************************************************
1259 * AddrLib::ConvertTileIndex
1262 * Convert tile index to tile mode/type/info
1266 ***************************************************************************************************
1268 ADDR_E_RETURNCODE
AddrLib::ConvertTileIndex(
1269 const ADDR_CONVERT_TILEINDEX_INPUT
* pIn
, ///< [in] input structure
1270 ADDR_CONVERT_TILEINDEX_OUTPUT
* pOut
///< [out] output structure
1273 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1275 if (GetFillSizeFieldsFlags() == TRUE
)
1277 if ((pIn
->size
!= sizeof(ADDR_CONVERT_TILEINDEX_INPUT
)) ||
1278 (pOut
->size
!= sizeof(ADDR_CONVERT_TILEINDEX_OUTPUT
)))
1280 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1284 if (returnCode
== ADDR_OK
)
1287 returnCode
= HwlSetupTileCfg(pIn
->tileIndex
, pIn
->macroModeIndex
,
1288 pOut
->pTileInfo
, &pOut
->tileMode
, &pOut
->tileType
);
1290 if (returnCode
== ADDR_OK
&& pIn
->tileInfoHw
)
1292 ADDR_CONVERT_TILEINFOTOHW_INPUT hwInput
= {0};
1293 ADDR_CONVERT_TILEINFOTOHW_OUTPUT hwOutput
= {0};
1295 hwInput
.pTileInfo
= pOut
->pTileInfo
;
1296 hwInput
.tileIndex
= -1;
1297 hwOutput
.pTileInfo
= pOut
->pTileInfo
;
1299 returnCode
= HwlConvertTileInfoToHW(&hwInput
, &hwOutput
);
1307 ***************************************************************************************************
1308 * AddrLib::ConvertTileIndex1
1311 * Convert tile index to tile mode/type/info
1315 ***************************************************************************************************
1317 ADDR_E_RETURNCODE
AddrLib::ConvertTileIndex1(
1318 const ADDR_CONVERT_TILEINDEX1_INPUT
* pIn
, ///< [in] input structure
1319 ADDR_CONVERT_TILEINDEX_OUTPUT
* pOut
///< [out] output structure
1322 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1324 if (GetFillSizeFieldsFlags() == TRUE
)
1326 if ((pIn
->size
!= sizeof(ADDR_CONVERT_TILEINDEX1_INPUT
)) ||
1327 (pOut
->size
!= sizeof(ADDR_CONVERT_TILEINDEX_OUTPUT
)))
1329 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1333 if (returnCode
== ADDR_OK
)
1335 ADDR_SURFACE_FLAGS flags
= {{0}};
1337 HwlComputeMacroModeIndex(pIn
->tileIndex
, flags
, pIn
->bpp
, pIn
->numSamples
,
1338 pOut
->pTileInfo
, &pOut
->tileMode
, &pOut
->tileType
);
1340 if (pIn
->tileInfoHw
)
1342 ADDR_CONVERT_TILEINFOTOHW_INPUT hwInput
= {0};
1343 ADDR_CONVERT_TILEINFOTOHW_OUTPUT hwOutput
= {0};
1345 hwInput
.pTileInfo
= pOut
->pTileInfo
;
1346 hwInput
.tileIndex
= -1;
1347 hwOutput
.pTileInfo
= pOut
->pTileInfo
;
1349 returnCode
= HwlConvertTileInfoToHW(&hwInput
, &hwOutput
);
1357 ***************************************************************************************************
1358 * AddrLib::GetTileIndex
1361 * Get tile index from tile mode/type/info
1365 ***************************************************************************************************
1367 ADDR_E_RETURNCODE
AddrLib::GetTileIndex(
1368 const ADDR_GET_TILEINDEX_INPUT
* pIn
, ///< [in] input structure
1369 ADDR_GET_TILEINDEX_OUTPUT
* pOut
///< [out] output structure
1372 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1374 if (GetFillSizeFieldsFlags() == TRUE
)
1376 if ((pIn
->size
!= sizeof(ADDR_GET_TILEINDEX_INPUT
)) ||
1377 (pOut
->size
!= sizeof(ADDR_GET_TILEINDEX_OUTPUT
)))
1379 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1383 if (returnCode
== ADDR_OK
)
1385 returnCode
= HwlGetTileIndex(pIn
, pOut
);
1392 ***************************************************************************************************
1393 * AddrLib::ComputeSurfaceThickness
1396 * Compute surface thickness
1400 ***************************************************************************************************
1402 UINT_32
AddrLib::ComputeSurfaceThickness(
1403 AddrTileMode tileMode
) ///< [in] tile mode
1405 return m_modeFlags
[tileMode
].thickness
;
1410 ///////////////////////////////////////////////////////////////////////////////////////////////////
1412 ///////////////////////////////////////////////////////////////////////////////////////////////////
1415 ***************************************************************************************************
1416 * AddrLib::ComputeHtileInfo
1419 * Interface function stub of AddrComputeHtilenfo
1423 ***************************************************************************************************
1425 ADDR_E_RETURNCODE
AddrLib::ComputeHtileInfo(
1426 const ADDR_COMPUTE_HTILE_INFO_INPUT
* pIn
, ///< [in] input structure
1427 ADDR_COMPUTE_HTILE_INFO_OUTPUT
* pOut
///< [out] output structure
1430 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1432 BOOL_32 isWidth8
= (pIn
->blockWidth
== 8) ? TRUE
: FALSE
;
1433 BOOL_32 isHeight8
= (pIn
->blockHeight
== 8) ? TRUE
: FALSE
;
1435 if (GetFillSizeFieldsFlags() == TRUE
)
1437 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_HTILE_INFO_INPUT
)) ||
1438 (pOut
->size
!= sizeof(ADDR_COMPUTE_HTILE_INFO_OUTPUT
)))
1440 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1444 if (returnCode
== ADDR_OK
)
1446 ADDR_TILEINFO tileInfoNull
;
1447 ADDR_COMPUTE_HTILE_INFO_INPUT input
;
1449 if (UseTileIndex(pIn
->tileIndex
))
1452 // Use temp tile info for calcalation
1453 input
.pTileInfo
= &tileInfoNull
;
1455 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1457 // Change the input structure
1461 if (returnCode
== ADDR_OK
)
1463 pOut
->bpp
= ComputeHtileInfo(pIn
->flags
,
1485 ***************************************************************************************************
1486 * AddrLib::ComputeCmaskInfo
1489 * Interface function stub of AddrComputeCmaskInfo
1493 ***************************************************************************************************
1495 ADDR_E_RETURNCODE
AddrLib::ComputeCmaskInfo(
1496 const ADDR_COMPUTE_CMASK_INFO_INPUT
* pIn
, ///< [in] input structure
1497 ADDR_COMPUTE_CMASK_INFO_OUTPUT
* pOut
///< [out] output structure
1500 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1502 if (GetFillSizeFieldsFlags() == TRUE
)
1504 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_CMASK_INFO_INPUT
)) ||
1505 (pOut
->size
!= sizeof(ADDR_COMPUTE_CMASK_INFO_OUTPUT
)))
1507 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1511 if (returnCode
== ADDR_OK
)
1513 ADDR_TILEINFO tileInfoNull
;
1514 ADDR_COMPUTE_CMASK_INFO_INPUT input
;
1516 if (UseTileIndex(pIn
->tileIndex
))
1519 // Use temp tile info for calcalation
1520 input
.pTileInfo
= &tileInfoNull
;
1522 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1524 // Change the input structure
1528 if (returnCode
== ADDR_OK
)
1530 returnCode
= ComputeCmaskInfo(pIn
->flags
,
1551 ***************************************************************************************************
1552 * AddrLib::ComputeDccInfo
1555 * Interface function to compute DCC key info
1558 * return code of HwlComputeDccInfo
1559 ***************************************************************************************************
1561 ADDR_E_RETURNCODE
AddrLib::ComputeDccInfo(
1562 const ADDR_COMPUTE_DCCINFO_INPUT
* pIn
, ///< [in] input structure
1563 ADDR_COMPUTE_DCCINFO_OUTPUT
* pOut
///< [out] output structure
1566 ADDR_E_RETURNCODE ret
= ADDR_OK
;
1568 if (GetFillSizeFieldsFlags() == TRUE
)
1570 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_DCCINFO_INPUT
)) ||
1571 (pOut
->size
!= sizeof(ADDR_COMPUTE_DCCINFO_OUTPUT
)))
1573 ret
= ADDR_PARAMSIZEMISMATCH
;
1579 ADDR_COMPUTE_DCCINFO_INPUT input
;
1581 if (UseTileIndex(pIn
->tileIndex
))
1585 ret
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
,
1586 &input
.tileInfo
, &input
.tileMode
);
1593 ret
= HwlComputeDccInfo(pIn
, pOut
);
1601 ***************************************************************************************************
1602 * AddrLib::ComputeHtileAddrFromCoord
1605 * Interface function stub of AddrComputeHtileAddrFromCoord
1609 ***************************************************************************************************
1611 ADDR_E_RETURNCODE
AddrLib::ComputeHtileAddrFromCoord(
1612 const ADDR_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1613 ADDR_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1616 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1618 BOOL_32 isWidth8
= (pIn
->blockWidth
== 8) ? TRUE
: FALSE
;
1619 BOOL_32 isHeight8
= (pIn
->blockHeight
== 8) ? TRUE
: FALSE
;
1621 if (GetFillSizeFieldsFlags() == TRUE
)
1623 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
)) ||
1624 (pOut
->size
!= sizeof(ADDR_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
)))
1626 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1630 if (returnCode
== ADDR_OK
)
1632 ADDR_TILEINFO tileInfoNull
;
1633 ADDR_COMPUTE_HTILE_ADDRFROMCOORD_INPUT input
;
1635 if (UseTileIndex(pIn
->tileIndex
))
1638 // Use temp tile info for calcalation
1639 input
.pTileInfo
= &tileInfoNull
;
1641 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1643 // Change the input structure
1647 if (returnCode
== ADDR_OK
)
1649 pOut
->addr
= HwlComputeXmaskAddrFromCoord(pIn
->pitch
,
1660 &pOut
->bitPosition
);
1669 ***************************************************************************************************
1670 * AddrLib::ComputeHtileCoordFromAddr
1673 * Interface function stub of AddrComputeHtileCoordFromAddr
1677 ***************************************************************************************************
1679 ADDR_E_RETURNCODE
AddrLib::ComputeHtileCoordFromAddr(
1680 const ADDR_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1681 ADDR_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1684 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1686 BOOL_32 isWidth8
= (pIn
->blockWidth
== 8) ? TRUE
: FALSE
;
1687 BOOL_32 isHeight8
= (pIn
->blockHeight
== 8) ? TRUE
: FALSE
;
1689 if (GetFillSizeFieldsFlags() == TRUE
)
1691 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_HTILE_COORDFROMADDR_INPUT
)) ||
1692 (pOut
->size
!= sizeof(ADDR_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
)))
1694 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1698 if (returnCode
== ADDR_OK
)
1700 ADDR_TILEINFO tileInfoNull
;
1701 ADDR_COMPUTE_HTILE_COORDFROMADDR_INPUT input
;
1703 if (UseTileIndex(pIn
->tileIndex
))
1706 // Use temp tile info for calcalation
1707 input
.pTileInfo
= &tileInfoNull
;
1709 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1711 // Change the input structure
1715 if (returnCode
== ADDR_OK
)
1717 HwlComputeXmaskCoordFromAddr(pIn
->addr
,
1737 ***************************************************************************************************
1738 * AddrLib::ComputeCmaskAddrFromCoord
1741 * Interface function stub of AddrComputeCmaskAddrFromCoord
1745 ***************************************************************************************************
1747 ADDR_E_RETURNCODE
AddrLib::ComputeCmaskAddrFromCoord(
1748 const ADDR_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1749 ADDR_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1752 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1754 if (GetFillSizeFieldsFlags() == TRUE
)
1756 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
)) ||
1757 (pOut
->size
!= sizeof(ADDR_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
)))
1759 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1763 if (returnCode
== ADDR_OK
)
1765 ADDR_TILEINFO tileInfoNull
;
1766 ADDR_COMPUTE_CMASK_ADDRFROMCOORD_INPUT input
;
1768 if (UseTileIndex(pIn
->tileIndex
))
1771 // Use temp tile info for calcalation
1772 input
.pTileInfo
= &tileInfoNull
;
1774 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1776 // Change the input structure
1780 if (returnCode
== ADDR_OK
)
1782 if (pIn
->flags
.tcCompatible
== TRUE
)
1784 returnCode
= HwlComputeCmaskAddrFromCoord(pIn
, pOut
);
1788 pOut
->addr
= HwlComputeXmaskAddrFromCoord(pIn
->pitch
,
1796 FALSE
, //this is cmask, isWidth8 is not needed
1797 FALSE
, //this is cmask, isHeight8 is not needed
1799 &pOut
->bitPosition
);
1809 ***************************************************************************************************
1810 * AddrLib::ComputeCmaskCoordFromAddr
1813 * Interface function stub of AddrComputeCmaskCoordFromAddr
1817 ***************************************************************************************************
1819 ADDR_E_RETURNCODE
AddrLib::ComputeCmaskCoordFromAddr(
1820 const ADDR_COMPUTE_CMASK_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1821 ADDR_COMPUTE_CMASK_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1824 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1826 if (GetFillSizeFieldsFlags() == TRUE
)
1828 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_CMASK_COORDFROMADDR_INPUT
)) ||
1829 (pOut
->size
!= sizeof(ADDR_COMPUTE_CMASK_COORDFROMADDR_OUTPUT
)))
1831 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1835 if (returnCode
== ADDR_OK
)
1837 ADDR_TILEINFO tileInfoNull
;
1838 ADDR_COMPUTE_CMASK_COORDFROMADDR_INPUT input
;
1840 if (UseTileIndex(pIn
->tileIndex
))
1843 // Use temp tile info for calcalation
1844 input
.pTileInfo
= &tileInfoNull
;
1846 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1848 // Change the input structure
1852 if (returnCode
== ADDR_OK
)
1854 HwlComputeXmaskCoordFromAddr(pIn
->addr
,
1874 ***************************************************************************************************
1875 * AddrLib::GetMaxAlignments
1878 * Gets maximum alignments
1882 ***************************************************************************************************
1884 ADDR_E_RETURNCODE
AddrLib::GetMaxAlignments(
1885 ADDR_GET_MAX_ALINGMENTS_OUTPUT
* pOut
///< [out] output structure
1888 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1890 if (GetFillSizeFieldsFlags() == TRUE
)
1892 if (pOut
->size
!= sizeof(ADDR_GET_MAX_ALINGMENTS_OUTPUT
))
1894 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1898 if (returnCode
== ADDR_OK
)
1900 returnCode
= HwlGetMaxAlignments(pOut
);
1907 ***************************************************************************************************
1908 * AddrLib::ComputeTileDataWidthAndHeight
1911 * Compute the squared cache shape for per-tile data (CMASK and HTILE)
1917 * MacroWidth and macroHeight are measured in pixels
1918 ***************************************************************************************************
1920 VOID
AddrLib::ComputeTileDataWidthAndHeight(
1921 UINT_32 bpp
, ///< [in] bits per pixel
1922 UINT_32 cacheBits
, ///< [in] bits of cache
1923 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
1924 UINT_32
* pMacroWidth
, ///< [out] macro tile width
1925 UINT_32
* pMacroHeight
///< [out] macro tile height
1929 UINT_32 width
= cacheBits
/ bpp
;
1930 UINT_32 pipes
= HwlGetPipes(pTileInfo
);
1932 // Double height until the macro-tile is close to square
1933 // Height can only be doubled if width is even
1935 while ((width
> height
* 2 * pipes
) && !(width
& 1))
1941 *pMacroWidth
= 8 * width
;
1942 *pMacroHeight
= 8 * height
* pipes
;
1944 // Note: The above iterative comptuation is equivalent to the following
1946 //int log2_height = ((log2(cacheBits)-log2(bpp)-log2(pipes))/2);
1947 //int macroHeight = pow2( 3+log2(pipes)+log2_height );
1951 ***************************************************************************************************
1952 * AddrLib::HwlComputeTileDataWidthAndHeightLinear
1955 * Compute the squared cache shape for per-tile data (CMASK and HTILE) for linear layout
1961 * MacroWidth and macroHeight are measured in pixels
1962 ***************************************************************************************************
1964 VOID
AddrLib::HwlComputeTileDataWidthAndHeightLinear(
1965 UINT_32
* pMacroWidth
, ///< [out] macro tile width
1966 UINT_32
* pMacroHeight
, ///< [out] macro tile height
1967 UINT_32 bpp
, ///< [in] bits per pixel
1968 ADDR_TILEINFO
* pTileInfo
///< [in] tile info
1971 ADDR_ASSERT(bpp
!= 4); // Cmask does not support linear layout prior to SI
1972 *pMacroWidth
= 8 * 512 / bpp
; // Align width to 512-bit memory accesses
1973 *pMacroHeight
= 8 * m_pipes
; // Align height to number of pipes
1977 ***************************************************************************************************
1978 * AddrLib::ComputeHtileInfo
1981 * Compute htile pitch,width, bytes per 2D slice
1984 * Htile bpp i.e. How many bits for an 8x8 tile
1985 * Also returns by output parameters:
1986 * *Htile pitch, height, total size in bytes, macro-tile dimensions and slice size*
1987 ***************************************************************************************************
1989 UINT_32
AddrLib::ComputeHtileInfo(
1990 ADDR_HTILE_FLAGS flags
, ///< [in] htile flags
1991 UINT_32 pitchIn
, ///< [in] pitch input
1992 UINT_32 heightIn
, ///< [in] height input
1993 UINT_32 numSlices
, ///< [in] number of slices
1994 BOOL_32 isLinear
, ///< [in] if it is linear mode
1995 BOOL_32 isWidth8
, ///< [in] if htile block width is 8
1996 BOOL_32 isHeight8
, ///< [in] if htile block height is 8
1997 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
1998 UINT_32
* pPitchOut
, ///< [out] pitch output
1999 UINT_32
* pHeightOut
, ///< [out] height output
2000 UINT_64
* pHtileBytes
, ///< [out] bytes per 2D slice
2001 UINT_32
* pMacroWidth
, ///< [out] macro-tile width in pixels
2002 UINT_32
* pMacroHeight
, ///< [out] macro-tile width in pixels
2003 UINT_64
* pSliceSize
, ///< [out] slice size in bytes
2004 UINT_32
* pBaseAlign
///< [out] base alignment
2009 UINT_32 macroHeight
;
2014 numSlices
= Max(1u, numSlices
);
2016 const UINT_32 bpp
= HwlComputeHtileBpp(isWidth8
, isHeight8
);
2017 const UINT_32 cacheBits
= HtileCacheBits
;
2021 HwlComputeTileDataWidthAndHeightLinear(¯oWidth
,
2028 ComputeTileDataWidthAndHeight(bpp
,
2035 *pPitchOut
= PowTwoAlign(pitchIn
, macroWidth
);
2036 *pHeightOut
= PowTwoAlign(heightIn
, macroHeight
);
2038 baseAlign
= HwlComputeHtileBaseAlign(flags
.tcCompatible
, isLinear
, pTileInfo
);
2040 surfBytes
= HwlComputeHtileBytes(*pPitchOut
,
2048 *pHtileBytes
= surfBytes
;
2051 // Use SafeAssign since they are optional
2053 SafeAssign(pMacroWidth
, macroWidth
);
2055 SafeAssign(pMacroHeight
, macroHeight
);
2057 SafeAssign(pSliceSize
, sliceBytes
);
2059 SafeAssign(pBaseAlign
, baseAlign
);
2065 ***************************************************************************************************
2066 * AddrLib::ComputeCmaskBaseAlign
2069 * Compute cmask base alignment
2072 * Cmask base alignment
2073 ***************************************************************************************************
2075 UINT_32
AddrLib::ComputeCmaskBaseAlign(
2076 ADDR_CMASK_FLAGS flags
, ///< [in] Cmask flags
2077 ADDR_TILEINFO
* pTileInfo
///< [in] Tile info
2080 UINT_32 baseAlign
= m_pipeInterleaveBytes
* HwlGetPipes(pTileInfo
);
2082 if (flags
.tcCompatible
)
2084 ADDR_ASSERT(pTileInfo
!= NULL
);
2087 baseAlign
*= pTileInfo
->banks
;
2095 ***************************************************************************************************
2096 * AddrLib::ComputeCmaskBytes
2099 * Compute cmask size in bytes
2102 * Cmask size in bytes
2103 ***************************************************************************************************
2105 UINT_64
AddrLib::ComputeCmaskBytes(
2106 UINT_32 pitch
, ///< [in] pitch
2107 UINT_32 height
, ///< [in] height
2108 UINT_32 numSlices
///< [in] number of slices
2111 return BITS_TO_BYTES(static_cast<UINT_64
>(pitch
) * height
* numSlices
* CmaskElemBits
) /
2116 ***************************************************************************************************
2117 * AddrLib::ComputeCmaskInfo
2120 * Compute cmask pitch,width, bytes per 2D slice
2123 * BlockMax. Also by output parameters: Cmask pitch,height, total size in bytes,
2124 * macro-tile dimensions
2125 ***************************************************************************************************
2127 ADDR_E_RETURNCODE
AddrLib::ComputeCmaskInfo(
2128 ADDR_CMASK_FLAGS flags
, ///< [in] cmask flags
2129 UINT_32 pitchIn
, ///< [in] pitch input
2130 UINT_32 heightIn
, ///< [in] height input
2131 UINT_32 numSlices
, ///< [in] number of slices
2132 BOOL_32 isLinear
, ///< [in] is linear mode
2133 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
2134 UINT_32
* pPitchOut
, ///< [out] pitch output
2135 UINT_32
* pHeightOut
, ///< [out] height output
2136 UINT_64
* pCmaskBytes
, ///< [out] bytes per 2D slice
2137 UINT_32
* pMacroWidth
, ///< [out] macro-tile width in pixels
2138 UINT_32
* pMacroHeight
, ///< [out] macro-tile width in pixels
2139 UINT_64
* pSliceSize
, ///< [out] slice size in bytes
2140 UINT_32
* pBaseAlign
, ///< [out] base alignment
2141 UINT_32
* pBlockMax
///< [out] block max == slice / 128 / 128 - 1
2145 UINT_32 macroHeight
;
2150 numSlices
= Max(1u, numSlices
);
2152 const UINT_32 bpp
= CmaskElemBits
;
2153 const UINT_32 cacheBits
= CmaskCacheBits
;
2155 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
2159 HwlComputeTileDataWidthAndHeightLinear(¯oWidth
,
2166 ComputeTileDataWidthAndHeight(bpp
,
2173 *pPitchOut
= (pitchIn
+ macroWidth
- 1) & ~(macroWidth
- 1);
2174 *pHeightOut
= (heightIn
+ macroHeight
- 1) & ~(macroHeight
- 1);
2177 sliceBytes
= ComputeCmaskBytes(*pPitchOut
,
2181 baseAlign
= ComputeCmaskBaseAlign(flags
, pTileInfo
);
2183 while (sliceBytes
% baseAlign
)
2185 *pHeightOut
+= macroHeight
;
2187 sliceBytes
= ComputeCmaskBytes(*pPitchOut
,
2192 surfBytes
= sliceBytes
* numSlices
;
2194 *pCmaskBytes
= surfBytes
;
2197 // Use SafeAssign since they are optional
2199 SafeAssign(pMacroWidth
, macroWidth
);
2201 SafeAssign(pMacroHeight
, macroHeight
);
2203 SafeAssign(pBaseAlign
, baseAlign
);
2205 SafeAssign(pSliceSize
, sliceBytes
);
2207 UINT_32 slice
= (*pPitchOut
) * (*pHeightOut
);
2208 UINT_32 blockMax
= slice
/ 128 / 128 - 1;
2211 if (slice
% (64*256) != 0)
2213 ADDR_ASSERT_ALWAYS();
2217 UINT_32 maxBlockMax
= HwlGetMaxCmaskBlockMax();
2219 if (blockMax
> maxBlockMax
)
2221 blockMax
= maxBlockMax
;
2222 returnCode
= ADDR_INVALIDPARAMS
;
2225 SafeAssign(pBlockMax
, blockMax
);
2231 ***************************************************************************************************
2232 * AddrLib::ComputeXmaskCoordYFromPipe
2235 * Compute the Y coord from pipe number for cmask/htile
2240 ***************************************************************************************************
2242 UINT_32
AddrLib::ComputeXmaskCoordYFromPipe(
2243 UINT_32 pipe
, ///< [in] pipe number
2244 UINT_32 x
///< [in] x coordinate
2256 UINT_32 numPipes
= m_pipes
; // SI has its implementation
2258 // Convert pipe + x to y coordinate.
2278 pipeBit0
= pipe
& 0x1;
2282 yBit0
= pipeBit0
^ xBit0
;
2296 pipeBit0
= pipe
& 0x1;
2297 pipeBit1
= (pipe
& 0x2) >> 1;
2300 xBit1
= (x
& 0x2) >> 1;
2302 yBit0
= pipeBit0
^ xBit1
;
2303 yBit1
= pipeBit1
^ xBit0
;
2312 // r600 and r800 have different method
2314 y
= HwlComputeXmaskCoordYFrom8Pipe(pipe
, x
);
2323 ***************************************************************************************************
2324 * AddrLib::HwlComputeXmaskCoordFromAddr
2327 * Compute the coord from an address of a cmask/htile
2333 * This method is reused by htile, so rename to Xmask
2334 ***************************************************************************************************
2336 VOID
AddrLib::HwlComputeXmaskCoordFromAddr(
2337 UINT_64 addr
, ///< [in] address
2338 UINT_32 bitPosition
, ///< [in] bitPosition in a byte
2339 UINT_32 pitch
, ///< [in] pitch
2340 UINT_32 height
, ///< [in] height
2341 UINT_32 numSlices
, ///< [in] number of slices
2342 UINT_32 factor
, ///< [in] factor that indicates cmask or htile
2343 BOOL_32 isLinear
, ///< [in] linear or tiled HTILE layout
2344 BOOL_32 isWidth8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
2345 BOOL_32 isHeight8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
2346 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
2347 UINT_32
* pX
, ///< [out] x coord
2348 UINT_32
* pY
, ///< [out] y coord
2349 UINT_32
* pSlice
///< [out] slice index
2354 UINT_32 numPipeBits
;
2355 UINT_32 macroTilePitch
;
2356 UINT_32 macroTileHeight
;
2360 UINT_32 microTileCoordY
;
2364 UINT_32 pitchAligned
= pitch
;
2365 UINT_32 heightAligned
= height
;
2373 UINT_64 macroNumber
;
2374 UINT_32 microNumber
;
2383 UINT_32 tilesPerMacro
;
2384 UINT_32 macrosPerPitch
;
2385 UINT_32 macrosPerSlice
;
2390 numPipes
= HwlGetPipes(pTileInfo
);
2391 pipe
= ComputePipeFromAddr(addr
, numPipes
);
2394 // Compute the number of group and pipe bits.
2396 numPipeBits
= Log2(numPipes
);
2398 UINT_32 groupBits
= 8 * m_pipeInterleaveBytes
;
2399 UINT_32 pipes
= numPipes
;
2403 // Compute the micro tile size, in bits. And macro tile pitch and height.
2405 if (factor
== 2) //CMASK
2407 ADDR_CMASK_FLAGS flags
= {{0}};
2409 elemBits
= CmaskElemBits
;
2411 ComputeCmaskInfo(flags
,
2425 ADDR_HTILE_FLAGS flags
= {{0}};
2432 elemBits
= HwlComputeHtileBpp(isWidth8
, isHeight8
);
2434 ComputeHtileInfo(flags
,
2449 // Should use aligned dims
2451 pitch
= pitchAligned
;
2452 height
= heightAligned
;
2456 // Convert byte address to bit address.
2458 bitAddr
= BYTES_TO_BITS(addr
) + bitPosition
;
2462 // Remove pipe bits from address.
2465 bitAddr
= (bitAddr
% groupBits
) + ((bitAddr
/groupBits
/pipes
)*groupBits
);
2468 elemOffset
= bitAddr
/ elemBits
;
2470 tilesPerMacro
= (macroTilePitch
/factor
) * macroTileHeight
/ MicroTilePixels
>> numPipeBits
;
2472 macrosPerPitch
= pitch
/ (macroTilePitch
/factor
);
2473 macrosPerSlice
= macrosPerPitch
* height
/ macroTileHeight
;
2475 macroIndex
= elemOffset
/ factor
/ tilesPerMacro
;
2476 microIndex
= static_cast<UINT_32
>(elemOffset
% (tilesPerMacro
* factor
));
2478 macroNumber
= macroIndex
* factor
+ microIndex
% factor
;
2479 microNumber
= microIndex
/ factor
;
2481 macroX
= static_cast<UINT_32
>((macroNumber
% macrosPerPitch
));
2482 macroY
= static_cast<UINT_32
>((macroNumber
% macrosPerSlice
) / macrosPerPitch
);
2483 macroZ
= static_cast<UINT_32
>((macroNumber
/ macrosPerSlice
));
2486 microX
= microNumber
% (macroTilePitch
/ factor
/ MicroTileWidth
);
2487 microY
= (microNumber
/ (macroTilePitch
/ factor
/ MicroTileHeight
));
2489 *pX
= macroX
* (macroTilePitch
/factor
) + microX
* MicroTileWidth
;
2490 *pY
= macroY
* macroTileHeight
+ (microY
* MicroTileHeight
<< numPipeBits
);
2493 microTileCoordY
= ComputeXmaskCoordYFromPipe(pipe
,
2494 *pX
/MicroTileWidth
);
2498 // Assemble final coordinates.
2500 *pY
+= microTileCoordY
* MicroTileHeight
;
2505 ***************************************************************************************************
2506 * AddrLib::HwlComputeXmaskAddrFromCoord
2509 * Compute the address from an address of cmask (prior to si)
2514 ***************************************************************************************************
2516 UINT_64
AddrLib::HwlComputeXmaskAddrFromCoord(
2517 UINT_32 pitch
, ///< [in] pitch
2518 UINT_32 height
, ///< [in] height
2519 UINT_32 x
, ///< [in] x coord
2520 UINT_32 y
, ///< [in] y coord
2521 UINT_32 slice
, ///< [in] slice/depth index
2522 UINT_32 numSlices
, ///< [in] number of slices
2523 UINT_32 factor
, ///< [in] factor that indicates cmask(2) or htile(1)
2524 BOOL_32 isLinear
, ///< [in] linear or tiled HTILE layout
2525 BOOL_32 isWidth8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
2526 BOOL_32 isHeight8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
2527 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
2528 UINT_32
* pBitPosition
///< [out] bit position inside a byte
2532 UINT_32 numGroupBits
;
2533 UINT_32 numPipeBits
;
2534 UINT_32 newPitch
= 0;
2535 UINT_32 newHeight
= 0;
2536 UINT_64 sliceBytes
= 0;
2537 UINT_64 totalBytes
= 0;
2538 UINT_64 sliceOffset
;
2540 UINT_32 macroTileWidth
;
2541 UINT_32 macroTileHeight
;
2542 UINT_32 macroTilesPerRow
;
2543 UINT_32 macroTileBytes
;
2544 UINT_32 macroTileIndexX
;
2545 UINT_32 macroTileIndexY
;
2546 UINT_64 macroTileOffset
;
2547 UINT_32 pixelBytesPerRow
;
2548 UINT_32 pixelOffsetX
;
2549 UINT_32 pixelOffsetY
;
2550 UINT_32 pixelOffset
;
2551 UINT_64 totalOffset
;
2557 UINT_32 elemBits
= 0;
2559 UINT_32 numPipes
= m_pipes
; // This function is accessed prior to si only
2561 if (factor
== 2) //CMASK
2563 elemBits
= CmaskElemBits
;
2565 // For asics before SI, cmask is always tiled
2570 if (factor
!= 1) // Fix compile warning
2575 elemBits
= HwlComputeHtileBpp(isWidth8
, isHeight8
);
2579 // Compute the number of group bits and pipe bits.
2581 numGroupBits
= Log2(m_pipeInterleaveBytes
);
2582 numPipeBits
= Log2(numPipes
);
2585 // Compute macro tile dimensions.
2587 if (factor
== 2) // CMASK
2589 ADDR_CMASK_FLAGS flags
= {{0}};
2591 ComputeCmaskInfo(flags
,
2603 sliceBytes
= totalBytes
/ numSlices
;
2607 ADDR_HTILE_FLAGS flags
= {{0}};
2609 ComputeHtileInfo(flags
,
2625 sliceOffset
= slice
* sliceBytes
;
2628 // Get the pipe. Note that neither slice rotation nor pipe swizzling apply for CMASK.
2630 pipe
= ComputePipeFromCoord(x
,
2633 ADDR_TM_2D_TILED_THIN1
,
2639 // Compute the number of macro tiles per row.
2641 macroTilesPerRow
= newPitch
/ macroTileWidth
;
2644 // Compute the number of bytes per macro tile.
2646 macroTileBytes
= BITS_TO_BYTES((macroTileWidth
* macroTileHeight
* elemBits
) / MicroTilePixels
);
2649 // Compute the offset to the macro tile containing the specified coordinate.
2651 macroTileIndexX
= x
/ macroTileWidth
;
2652 macroTileIndexY
= y
/ macroTileHeight
;
2653 macroTileOffset
= ((macroTileIndexY
* macroTilesPerRow
) + macroTileIndexX
) * macroTileBytes
;
2656 // Compute the pixel offset within the macro tile.
2658 pixelBytesPerRow
= BITS_TO_BYTES(macroTileWidth
* elemBits
) / MicroTileWidth
;
2661 // The nibbles are interleaved (see below), so the part of the offset relative to the x
2662 // coordinate repeats halfway across the row. (Not for HTILE)
2666 pixelOffsetX
= (x
% (macroTileWidth
/ 2)) / MicroTileWidth
;
2670 pixelOffsetX
= (x
% (macroTileWidth
)) / MicroTileWidth
* BITS_TO_BYTES(elemBits
);
2674 // Compute the y offset within the macro tile.
2676 pixelOffsetY
= (((y
% macroTileHeight
) / MicroTileHeight
) / numPipes
) * pixelBytesPerRow
;
2678 pixelOffset
= pixelOffsetX
+ pixelOffsetY
;
2681 // Combine the slice offset and macro tile offset with the pixel offset, accounting for the
2682 // pipe bits in the middle of the address.
2684 totalOffset
= ((sliceOffset
+ macroTileOffset
) >> numPipeBits
) + pixelOffset
;
2687 // Split the offset to put some bits below the pipe bits and some above.
2689 groupMask
= (1 << numGroupBits
) - 1;
2690 offsetLo
= totalOffset
& groupMask
;
2691 offsetHi
= (totalOffset
& ~groupMask
) << numPipeBits
;
2694 // Assemble the address from its components.
2698 // This is to remove warning with /analyze option
2699 UINT_32 pipeBits
= pipe
<< numGroupBits
;
2703 // Compute the bit position. The lower nibble is used when the x coordinate within the macro
2704 // tile is less than half of the macro tile width, and the upper nibble is used when the x
2705 // coordinate within the macro tile is greater than or equal to half the macro tile width.
2707 *pBitPosition
= ((x
% macroTileWidth
) < (macroTileWidth
/ factor
)) ? 0 : 4;
2712 ///////////////////////////////////////////////////////////////////////////////////////////////////
2713 // Surface Addressing Shared
2714 ///////////////////////////////////////////////////////////////////////////////////////////////////
2717 ***************************************************************************************************
2718 * AddrLib::ComputeSurfaceAddrFromCoordLinear
2721 * Compute address from coord for linear surface
2726 ***************************************************************************************************
2728 UINT_64
AddrLib::ComputeSurfaceAddrFromCoordLinear(
2729 UINT_32 x
, ///< [in] x coord
2730 UINT_32 y
, ///< [in] y coord
2731 UINT_32 slice
, ///< [in] slice/depth index
2732 UINT_32 sample
, ///< [in] sample index
2733 UINT_32 bpp
, ///< [in] bits per pixel
2734 UINT_32 pitch
, ///< [in] pitch
2735 UINT_32 height
, ///< [in] height
2736 UINT_32 numSlices
, ///< [in] number of slices
2737 UINT_32
* pBitPosition
///< [out] bit position inside a byte
2740 const UINT_64 sliceSize
= static_cast<UINT_64
>(pitch
) * height
;
2742 UINT_64 sliceOffset
= (slice
+ sample
* numSlices
)* sliceSize
;
2743 UINT_64 rowOffset
= static_cast<UINT_64
>(y
) * pitch
;
2744 UINT_64 pixOffset
= x
;
2746 UINT_64 addr
= (sliceOffset
+ rowOffset
+ pixOffset
) * bpp
;
2748 *pBitPosition
= static_cast<UINT_32
>(addr
% 8);
2755 ***************************************************************************************************
2756 * AddrLib::ComputeSurfaceCoordFromAddrLinear
2759 * Compute the coord from an address of a linear surface
2763 ***************************************************************************************************
2765 VOID
AddrLib::ComputeSurfaceCoordFromAddrLinear(
2766 UINT_64 addr
, ///< [in] address
2767 UINT_32 bitPosition
, ///< [in] bitPosition in a byte
2768 UINT_32 bpp
, ///< [in] bits per pixel
2769 UINT_32 pitch
, ///< [in] pitch
2770 UINT_32 height
, ///< [in] height
2771 UINT_32 numSlices
, ///< [in] number of slices
2772 UINT_32
* pX
, ///< [out] x coord
2773 UINT_32
* pY
, ///< [out] y coord
2774 UINT_32
* pSlice
, ///< [out] slice/depth index
2775 UINT_32
* pSample
///< [out] sample index
2778 const UINT_64 sliceSize
= static_cast<UINT_64
>(pitch
) * height
;
2779 const UINT_64 linearOffset
= (BYTES_TO_BITS(addr
) + bitPosition
) / bpp
;
2781 *pX
= static_cast<UINT_32
>((linearOffset
% sliceSize
) % pitch
);
2782 *pY
= static_cast<UINT_32
>((linearOffset
% sliceSize
) / pitch
% height
);
2783 *pSlice
= static_cast<UINT_32
>((linearOffset
/ sliceSize
) % numSlices
);
2784 *pSample
= static_cast<UINT_32
>((linearOffset
/ sliceSize
) / numSlices
);
2788 ***************************************************************************************************
2789 * AddrLib::ComputeSurfaceCoordFromAddrMicroTiled
2792 * Compute the coord from an address of a micro tiled surface
2796 ***************************************************************************************************
2798 VOID
AddrLib::ComputeSurfaceCoordFromAddrMicroTiled(
2799 UINT_64 addr
, ///< [in] address
2800 UINT_32 bitPosition
, ///< [in] bitPosition in a byte
2801 UINT_32 bpp
, ///< [in] bits per pixel
2802 UINT_32 pitch
, ///< [in] pitch
2803 UINT_32 height
, ///< [in] height
2804 UINT_32 numSamples
, ///< [in] number of samples
2805 AddrTileMode tileMode
, ///< [in] tile mode
2806 UINT_32 tileBase
, ///< [in] base offset within a tile
2807 UINT_32 compBits
, ///< [in] component bits actually needed(for planar surface)
2808 UINT_32
* pX
, ///< [out] x coord
2809 UINT_32
* pY
, ///< [out] y coord
2810 UINT_32
* pSlice
, ///< [out] slice/depth index
2811 UINT_32
* pSample
, ///< [out] sample index,
2812 AddrTileType microTileType
, ///< [in] micro tiling order
2813 BOOL_32 isDepthSampleOrder
///< [in] TRUE if in depth sample order
2817 UINT_32 microTileThickness
;
2818 UINT_32 microTileBits
;
2822 UINT_32 microTileCoordX
;
2823 UINT_32 microTileCoordY
;
2824 UINT_32 pixelOffset
;
2825 UINT_32 pixelCoordX
= 0;
2826 UINT_32 pixelCoordY
= 0;
2827 UINT_32 pixelCoordZ
= 0;
2828 UINT_32 pixelCoordS
= 0;
2831 // Convert byte address to bit address.
2833 bitAddr
= BYTES_TO_BITS(addr
) + bitPosition
;
2836 // Compute the micro tile size, in bits.
2840 case ADDR_TM_1D_TILED_THICK
:
2841 microTileThickness
= ThickTileThickness
;
2844 microTileThickness
= 1;
2848 microTileBits
= MicroTilePixels
* microTileThickness
* bpp
* numSamples
;
2851 // Compute number of bits per slice and number of bits per row of micro tiles.
2853 sliceBits
= static_cast<UINT_64
>(pitch
) * height
* microTileThickness
* bpp
* numSamples
;
2855 rowBits
= (pitch
/ MicroTileWidth
) * microTileBits
;
2858 // Extract the slice index.
2860 sliceIndex
= static_cast<UINT_32
>(bitAddr
/ sliceBits
);
2861 bitAddr
-= sliceIndex
* sliceBits
;
2864 // Extract the y coordinate of the micro tile.
2866 microTileCoordY
= static_cast<UINT_32
>(bitAddr
/ rowBits
) * MicroTileHeight
;
2867 bitAddr
-= (microTileCoordY
/ MicroTileHeight
) * rowBits
;
2870 // Extract the x coordinate of the micro tile.
2872 microTileCoordX
= static_cast<UINT_32
>(bitAddr
/ microTileBits
) * MicroTileWidth
;
2875 // Compute the pixel offset within the micro tile.
2877 pixelOffset
= static_cast<UINT_32
>(bitAddr
% microTileBits
);
2880 // Extract pixel coordinates from the offset.
2882 HwlComputePixelCoordFromOffset(pixelOffset
,
2893 isDepthSampleOrder
);
2896 // Assemble final coordinates.
2898 *pX
= microTileCoordX
+ pixelCoordX
;
2899 *pY
= microTileCoordY
+ pixelCoordY
;
2900 *pSlice
= (sliceIndex
* microTileThickness
) + pixelCoordZ
;
2901 *pSample
= pixelCoordS
;
2903 if (microTileThickness
> 1)
2910 ***************************************************************************************************
2911 * AddrLib::ComputePipeFromAddr
2914 * Compute the pipe number from an address
2919 ***************************************************************************************************
2921 UINT_32
AddrLib::ComputePipeFromAddr(
2922 UINT_64 addr
, ///< [in] address
2923 UINT_32 numPipes
///< [in] number of banks
2928 UINT_32 groupBytes
= m_pipeInterleaveBytes
; //just different terms
2931 // The LSBs of the address are arranged as follows:
2932 // bank | pipe | group
2934 // To get the pipe number, shift off the group bits and mask the pipe bits.
2938 // The LSBs of the address are arranged as follows:
2939 // bank | bankInterleave | pipe | pipeInterleave
2941 // To get the pipe number, shift off the pipe interleave bits and mask the pipe bits.
2944 pipe
= static_cast<UINT_32
>(addr
>> Log2(groupBytes
)) & (numPipes
- 1);
2950 ***************************************************************************************************
2951 * AddrLib::ComputePixelIndexWithinMicroTile
2954 * Compute the pixel index inside a micro tile of surface
2959 ***************************************************************************************************
2961 UINT_32
AddrLib::ComputePixelIndexWithinMicroTile(
2962 UINT_32 x
, ///< [in] x coord
2963 UINT_32 y
, ///< [in] y coord
2964 UINT_32 z
, ///< [in] slice/depth index
2965 UINT_32 bpp
, ///< [in] bits per pixel
2966 AddrTileMode tileMode
, ///< [in] tile mode
2967 AddrTileType microTileType
///< [in] pixel order in display/non-display mode
2970 UINT_32 pixelBit0
= 0;
2971 UINT_32 pixelBit1
= 0;
2972 UINT_32 pixelBit2
= 0;
2973 UINT_32 pixelBit3
= 0;
2974 UINT_32 pixelBit4
= 0;
2975 UINT_32 pixelBit5
= 0;
2976 UINT_32 pixelBit6
= 0;
2977 UINT_32 pixelBit7
= 0;
2978 UINT_32 pixelBit8
= 0;
2979 UINT_32 pixelNumber
;
2981 UINT_32 x0
= _BIT(x
, 0);
2982 UINT_32 x1
= _BIT(x
, 1);
2983 UINT_32 x2
= _BIT(x
, 2);
2984 UINT_32 y0
= _BIT(y
, 0);
2985 UINT_32 y1
= _BIT(y
, 1);
2986 UINT_32 y2
= _BIT(y
, 2);
2987 UINT_32 z0
= _BIT(z
, 0);
2988 UINT_32 z1
= _BIT(z
, 1);
2989 UINT_32 z2
= _BIT(z
, 2);
2991 UINT_32 thickness
= ComputeSurfaceThickness(tileMode
);
2993 // Compute the pixel number within the micro tile.
2995 if (microTileType
!= ADDR_THICK
)
2997 if (microTileType
== ADDR_DISPLAYABLE
)
3042 ADDR_ASSERT_ALWAYS();
3046 else if (microTileType
== ADDR_NON_DISPLAYABLE
|| microTileType
== ADDR_DEPTH_SAMPLE_ORDER
)
3055 else if (microTileType
== ADDR_ROTATED
)
3057 ADDR_ASSERT(thickness
== 1);
3094 ADDR_ASSERT_ALWAYS();
3107 ADDR_ASSERT(thickness
> 1);
3138 ADDR_ASSERT_ALWAYS();
3151 pixelNumber
= ((pixelBit0
) |
3165 ***************************************************************************************************
3166 * AddrLib::AdjustPitchAlignment
3169 * Adjusts pitch alignment for flipping surface
3174 ***************************************************************************************************
3176 VOID
AddrLib::AdjustPitchAlignment(
3177 ADDR_SURFACE_FLAGS flags
, ///< [in] Surface flags
3178 UINT_32
* pPitchAlign
///< [out] Pointer to pitch alignment
3181 // Display engine hardwires lower 5 bit of GRPH_PITCH to ZERO which means 32 pixel alignment
3182 // Maybe it will be fixed in future but let's make it general for now.
3183 if (flags
.display
|| flags
.overlay
)
3185 *pPitchAlign
= PowTwoAlign(*pPitchAlign
, 32);
3189 *pPitchAlign
= Max(m_minPitchAlignPixels
, *pPitchAlign
);
3195 ***************************************************************************************************
3196 * AddrLib::PadDimensions
3199 * Helper function to pad dimensions
3204 ***************************************************************************************************
3206 VOID
AddrLib::PadDimensions(
3207 AddrTileMode tileMode
, ///< [in] tile mode
3208 UINT_32 bpp
, ///< [in] bits per pixel
3209 ADDR_SURFACE_FLAGS flags
, ///< [in] surface flags
3210 UINT_32 numSamples
, ///< [in] number of samples
3211 ADDR_TILEINFO
* pTileInfo
, ///< [in/out] bank structure.
3212 UINT_32 padDims
, ///< [in] Dimensions to pad valid value 1,2,3
3213 UINT_32 mipLevel
, ///< [in] MipLevel
3214 UINT_32
* pPitch
, ///< [in/out] pitch in pixels
3215 UINT_32 pitchAlign
, ///< [in] pitch alignment
3216 UINT_32
* pHeight
, ///< [in/out] height in pixels
3217 UINT_32 heightAlign
, ///< [in] height alignment
3218 UINT_32
* pSlices
, ///< [in/out] number of slices
3219 UINT_32 sliceAlign
///< [in] number of slice alignment
3222 UINT_32 thickness
= ComputeSurfaceThickness(tileMode
);
3224 ADDR_ASSERT(padDims
<= 3);
3227 // Override padding for mip levels
3233 // for cubemap, we only pad when client call with 6 faces as an identity
3236 padDims
= 3; // we should pad cubemap sub levels when we treat it as 3d texture
3245 // Any possibilities that padDims is 0?
3251 if (IsPow2(pitchAlign
))
3253 *pPitch
= PowTwoAlign((*pPitch
), pitchAlign
);
3255 else // add this code to pass unit test, r600 linear mode is not align bpp to pow2 for linear
3257 *pPitch
+= pitchAlign
- 1;
3258 *pPitch
/= pitchAlign
;
3259 *pPitch
*= pitchAlign
;
3264 *pHeight
= PowTwoAlign((*pHeight
), heightAlign
);
3267 if (padDims
> 2 || thickness
> 1)
3269 // for cubemap single face, we do not pad slices.
3270 // if we pad it, the slice number should be set to 6 and current mip level > 1
3271 if (flags
.cube
&& (!m_configFlags
.noCubeMipSlicesPad
|| flags
.cubeAsArray
))
3273 *pSlices
= NextPow2(*pSlices
);
3276 // normal 3D texture or arrays or cubemap has a thick mode? (Just pass unit test)
3279 *pSlices
= PowTwoAlign((*pSlices
), sliceAlign
);
3284 HwlPadDimensions(tileMode
,
3301 ***************************************************************************************************
3302 * AddrLib::HwlPreHandleBaseLvl3xPitch
3305 * Pre-handler of 3x pitch (96 bit) adjustment
3309 ***************************************************************************************************
3311 UINT_32
AddrLib::HwlPreHandleBaseLvl3xPitch(
3312 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input
3313 UINT_32 expPitch
///< [in] pitch
3316 ADDR_ASSERT(pIn
->width
== expPitch
);
3318 // If pitch is pre-multiplied by 3, we retrieve original one here to get correct miplevel size
3320 if (AddrElemLib::IsExpand3x(pIn
->format
) &&
3321 pIn
->mipLevel
== 0 &&
3322 pIn
->tileMode
== ADDR_TM_LINEAR_ALIGNED
)
3325 expPitch
= NextPow2(expPitch
);
3332 ***************************************************************************************************
3333 * AddrLib::HwlPostHandleBaseLvl3xPitch
3336 * Post-handler of 3x pitch adjustment
3340 ***************************************************************************************************
3342 UINT_32
AddrLib::HwlPostHandleBaseLvl3xPitch(
3343 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input
3344 UINT_32 expPitch
///< [in] pitch
3348 // 96 bits surface of sub levels require element pitch of 32 bits instead
3349 // So we just return pitch in 32 bit pixels without timing 3
3351 if (AddrElemLib::IsExpand3x(pIn
->format
) &&
3352 pIn
->mipLevel
== 0 &&
3353 pIn
->tileMode
== ADDR_TM_LINEAR_ALIGNED
)
3363 ***************************************************************************************************
3364 * AddrLib::IsMacroTiled
3367 * Check if the tile mode is macro tiled
3370 * TRUE if it is macro tiled (2D/2B/3D/3B)
3371 ***************************************************************************************************
3373 BOOL_32
AddrLib::IsMacroTiled(
3374 AddrTileMode tileMode
) ///< [in] tile mode
3376 return m_modeFlags
[tileMode
].isMacro
;
3380 ***************************************************************************************************
3381 * AddrLib::IsMacro3dTiled
3384 * Check if the tile mode is 3D macro tiled
3387 * TRUE if it is 3D macro tiled
3388 ***************************************************************************************************
3390 BOOL_32
AddrLib::IsMacro3dTiled(
3391 AddrTileMode tileMode
) ///< [in] tile mode
3393 return m_modeFlags
[tileMode
].isMacro3d
;
3397 ***************************************************************************************************
3398 * AddrLib::IsMicroTiled
3401 * Check if the tile mode is micro tiled
3404 * TRUE if micro tiled
3405 ***************************************************************************************************
3407 BOOL_32
AddrLib::IsMicroTiled(
3408 AddrTileMode tileMode
) ///< [in] tile mode
3410 return m_modeFlags
[tileMode
].isMicro
;
3414 ***************************************************************************************************
3418 * Check if the tile mode is linear
3422 ***************************************************************************************************
3424 BOOL_32
AddrLib::IsLinear(
3425 AddrTileMode tileMode
) ///< [in] tile mode
3427 return m_modeFlags
[tileMode
].isLinear
;
3431 ***************************************************************************************************
3432 * AddrLib::IsPrtNoRotationTileMode
3435 * Return TRUE if it is prt tile without rotation
3437 * This function just used by CI
3438 ***************************************************************************************************
3440 BOOL_32
AddrLib::IsPrtNoRotationTileMode(
3441 AddrTileMode tileMode
)
3443 return m_modeFlags
[tileMode
].isPrtNoRotation
;
3447 ***************************************************************************************************
3448 * AddrLib::IsPrtTileMode
3451 * Return TRUE if it is prt tile
3453 * This function just used by CI
3454 ***************************************************************************************************
3456 BOOL_32
AddrLib::IsPrtTileMode(
3457 AddrTileMode tileMode
)
3459 return m_modeFlags
[tileMode
].isPrt
;
3463 ***************************************************************************************************
3464 * AddrLib::Bits2Number
3467 * Cat a array of binary bit to a number
3470 * The number combined with the array of bits
3471 ***************************************************************************************************
3473 UINT_32
AddrLib::Bits2Number(
3474 UINT_32 bitNum
, ///< [in] how many bits
3475 ...) ///< [in] varaible bits value starting from MSB
3481 va_start(bits_ptr
, bitNum
);
3483 for(i
= 0; i
< bitNum
; i
++)
3485 number
|= va_arg(bits_ptr
, UINT_32
);
3497 ***************************************************************************************************
3498 * AddrLib::ComputeMipLevel
3501 * Compute mipmap level width/height/slices
3504 ***************************************************************************************************
3506 VOID
AddrLib::ComputeMipLevel(
3507 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
///< [in/out] Input structure
3510 if (AddrElemLib::IsBlockCompressed(pIn
->format
))
3512 if (pIn
->mipLevel
== 0)
3514 // DXTn's level 0 must be multiple of 4
3515 // But there are exceptions:
3516 // 1. Internal surface creation in hostblt/vsblt/etc...
3517 // 2. Runtime doesn't reject ATI1/ATI2 whose width/height are not multiple of 4
3518 pIn
->width
= PowTwoAlign(pIn
->width
, 4);
3519 pIn
->height
= PowTwoAlign(pIn
->height
, 4);
3523 HwlComputeMipLevel(pIn
);
3527 ***************************************************************************************************
3528 * AddrLib::OptimizeTileMode
3531 * Check if base level's tile mode can be optimized (degraded)
3533 * TRUE if degraded, also returns degraded tile mode (unchanged if not degraded)
3534 ***************************************************************************************************
3536 BOOL_32
AddrLib::OptimizeTileMode(
3537 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] Input structure for surface info
3538 AddrTileMode
* pTileMode
///< [out] Degraded tile mode
3541 AddrTileMode tileMode
= pIn
->tileMode
;
3542 UINT_32 thickness
= ComputeSurfaceThickness(tileMode
);
3544 // Optimization can only be done on level 0 and samples <= 1
3545 if ((pIn
->flags
.opt4Space
== TRUE
) &&
3546 (pIn
->mipLevel
== 0) &&
3547 (pIn
->numSamples
<= 1) &&
3548 (pIn
->flags
.display
== FALSE
) &&
3549 (IsPrtTileMode(tileMode
) == FALSE
) &&
3550 (pIn
->flags
.prt
== FALSE
))
3552 // Check if linear mode is optimal
3553 if ((pIn
->height
== 1) &&
3554 (IsLinear(tileMode
) == FALSE
) &&
3555 (AddrElemLib::IsBlockCompressed(pIn
->format
) == FALSE
) &&
3556 (pIn
->flags
.depth
== FALSE
) &&
3557 (pIn
->flags
.stencil
== FALSE
))
3559 tileMode
= ADDR_TM_LINEAR_ALIGNED
;
3561 else if (IsMacroTiled(tileMode
))
3563 if (HwlDegradeBaseLevel(pIn
))
3565 tileMode
= (thickness
== 1) ? ADDR_TM_1D_TILED_THIN1
: ADDR_TM_1D_TILED_THICK
;
3567 else if (thickness
> 1)
3569 // As in the following HwlComputeSurfaceInfo, thick modes may be degraded to
3570 // thinner modes, we should re-evaluate whether the corresponding thinner modes
3571 // need to be degraded. If so, we choose 1D thick mode instead.
3572 tileMode
= DegradeLargeThickTile(pIn
->tileMode
, pIn
->bpp
);
3573 if (tileMode
!= pIn
->tileMode
)
3575 ADDR_COMPUTE_SURFACE_INFO_INPUT input
= *pIn
;
3576 input
.tileMode
= tileMode
;
3577 if (HwlDegradeBaseLevel(&input
))
3579 tileMode
= ADDR_TM_1D_TILED_THICK
;
3586 BOOL_32 optimized
= (tileMode
!= pIn
->tileMode
);
3589 *pTileMode
= tileMode
;
3595 ***************************************************************************************************
3596 * AddrLib::DegradeLargeThickTile
3599 * Check if the thickness needs to be reduced if a tile is too large
3601 * The degraded tile mode (unchanged if not degraded)
3602 ***************************************************************************************************
3604 AddrTileMode
AddrLib::DegradeLargeThickTile(
3605 AddrTileMode tileMode
,
3608 // Override tilemode
3609 // When tile_width (8) * tile_height (8) * thickness * element_bytes is > row_size,
3610 // it is better to just use THIN mode in this case
3611 UINT_32 thickness
= ComputeSurfaceThickness(tileMode
);
3613 if (thickness
> 1 && m_configFlags
.allowLargeThickTile
== 0)
3615 UINT_32 tileSize
= MicroTilePixels
* thickness
* (bpp
>> 3);
3617 if (tileSize
> m_rowSize
)
3621 case ADDR_TM_2D_TILED_XTHICK
:
3622 if ((tileSize
>> 1) <= m_rowSize
)
3624 tileMode
= ADDR_TM_2D_TILED_THICK
;
3627 // else fall through
3628 case ADDR_TM_2D_TILED_THICK
:
3629 tileMode
= ADDR_TM_2D_TILED_THIN1
;
3632 case ADDR_TM_3D_TILED_XTHICK
:
3633 if ((tileSize
>> 1) <= m_rowSize
)
3635 tileMode
= ADDR_TM_3D_TILED_THICK
;
3638 // else fall through
3639 case ADDR_TM_3D_TILED_THICK
:
3640 tileMode
= ADDR_TM_3D_TILED_THIN1
;
3643 case ADDR_TM_PRT_TILED_THICK
:
3644 tileMode
= ADDR_TM_PRT_TILED_THIN1
;
3647 case ADDR_TM_PRT_2D_TILED_THICK
:
3648 tileMode
= ADDR_TM_PRT_2D_TILED_THIN1
;
3651 case ADDR_TM_PRT_3D_TILED_THICK
:
3652 tileMode
= ADDR_TM_PRT_3D_TILED_THIN1
;
3665 ***************************************************************************************************
3666 * AddrLib::PostComputeMipLevel
3668 * Compute MipLevel info (including level 0) after surface adjustment
3671 ***************************************************************************************************
3673 ADDR_E_RETURNCODE
AddrLib::PostComputeMipLevel(
3674 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in/out] Input structure
3675 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] Output structure
3678 // Mipmap including level 0 must be pow2 padded since either SI hw expects so or it is
3679 // required by CFX for Hw Compatibility between NI and SI. Otherwise it is only needed for
3680 // mipLevel > 0. Any h/w has different requirement should implement its own virtual function
3682 if (pIn
->flags
.pow2Pad
)
3684 pIn
->width
= NextPow2(pIn
->width
);
3685 pIn
->height
= NextPow2(pIn
->height
);
3686 pIn
->numSlices
= NextPow2(pIn
->numSlices
);
3688 else if (pIn
->mipLevel
> 0)
3690 pIn
->width
= NextPow2(pIn
->width
);
3691 pIn
->height
= NextPow2(pIn
->height
);
3693 if (!pIn
->flags
.cube
)
3695 pIn
->numSlices
= NextPow2(pIn
->numSlices
);
3698 // for cubemap, we keep its value at first
3705 ***************************************************************************************************
3706 * AddrLib::HwlSetupTileCfg
3709 * Map tile index to tile setting.
3712 ***************************************************************************************************
3714 ADDR_E_RETURNCODE
AddrLib::HwlSetupTileCfg(
3715 INT_32 index
, ///< [in] Tile index
3716 INT_32 macroModeIndex
, ///< [in] Index in macro tile mode table(CI)
3717 ADDR_TILEINFO
* pInfo
, ///< [out] Tile Info
3718 AddrTileMode
* pMode
, ///< [out] Tile mode
3719 AddrTileType
* pType
///< [out] Tile type
3722 return ADDR_NOTSUPPORTED
;
3726 ***************************************************************************************************
3727 * AddrLib::HwlGetPipes
3733 ***************************************************************************************************
3735 UINT_32
AddrLib::HwlGetPipes(
3736 const ADDR_TILEINFO
* pTileInfo
///< [in] Tile info
3739 //pTileInfo can be NULL when asic is 6xx and 8xx.
3744 ***************************************************************************************************
3745 * AddrLib::ComputeQbStereoInfo
3748 * Get quad buffer stereo information
3751 ***************************************************************************************************
3753 BOOL_32
AddrLib::ComputeQbStereoInfo(
3754 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [in/out] updated pOut+pStereoInfo
3757 BOOL_32 success
= FALSE
;
3759 if (pOut
->pStereoInfo
)
3761 ADDR_ASSERT(pOut
->bpp
>= 8);
3762 ADDR_ASSERT((pOut
->surfSize
% pOut
->baseAlign
) == 0);
3764 // Save original height
3765 pOut
->pStereoInfo
->eyeHeight
= pOut
->height
;
3768 pOut
->pStereoInfo
->rightOffset
= static_cast<UINT_32
>(pOut
->surfSize
);
3770 pOut
->pStereoInfo
->rightSwizzle
= HwlComputeQbStereoRightSwizzle(pOut
);
3773 pOut
->pixelHeight
<<= 1;
3776 pOut
->surfSize
<<= 1;
3778 // Right start address meets the base align since it is guaranteed by AddrLib
3780 // 1D surface on SI may break this rule, but we can force it to meet by checking .qbStereo.
3787 ///////////////////////////////////////////////////////////////////////////////////////////////////
3789 ///////////////////////////////////////////////////////////////////////////////////////////////////
3793 ***************************************************************************************************
3794 * AddrLib::Flt32ToColorPixel
3797 * Convert a FLT_32 value to a depth/stencil pixel value
3800 ***************************************************************************************************
3802 ADDR_E_RETURNCODE
AddrLib::Flt32ToDepthPixel(
3803 const ELEM_FLT32TODEPTHPIXEL_INPUT
* pIn
,
3804 ELEM_FLT32TODEPTHPIXEL_OUTPUT
* pOut
) const
3806 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3808 if (GetFillSizeFieldsFlags() == TRUE
)
3810 if ((pIn
->size
!= sizeof(ELEM_FLT32TODEPTHPIXEL_INPUT
)) ||
3811 (pOut
->size
!= sizeof(ELEM_FLT32TODEPTHPIXEL_OUTPUT
)))
3813 returnCode
= ADDR_PARAMSIZEMISMATCH
;
3817 if (returnCode
== ADDR_OK
)
3819 GetElemLib()->Flt32ToDepthPixel(pIn
->format
,
3822 UINT_32 depthBase
= 0;
3823 UINT_32 stencilBase
= 0;
3824 UINT_32 depthBits
= 0;
3825 UINT_32 stencilBits
= 0;
3827 switch (pIn
->format
)
3832 case ADDR_DEPTH_X8_24
:
3833 case ADDR_DEPTH_8_24
:
3834 case ADDR_DEPTH_X8_24_FLOAT
:
3835 case ADDR_DEPTH_8_24_FLOAT
:
3840 case ADDR_DEPTH_32_FLOAT
:
3843 case ADDR_DEPTH_X24_8_32_FLOAT
:
3852 // Overwrite base since R800 has no "tileBase"
3853 if (GetElemLib()->IsDepthStencilTilePlanar() == FALSE
)
3862 pOut
->stencilBase
= stencilBase
;
3863 pOut
->depthBase
= depthBase
;
3864 pOut
->depthBits
= depthBits
;
3865 pOut
->stencilBits
= stencilBits
;
3872 ***************************************************************************************************
3873 * AddrLib::Flt32ToColorPixel
3876 * Convert a FLT_32 value to a red/green/blue/alpha pixel value
3879 ***************************************************************************************************
3881 ADDR_E_RETURNCODE
AddrLib::Flt32ToColorPixel(
3882 const ELEM_FLT32TOCOLORPIXEL_INPUT
* pIn
,
3883 ELEM_FLT32TOCOLORPIXEL_OUTPUT
* pOut
) const
3885 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3887 if (GetFillSizeFieldsFlags() == TRUE
)
3889 if ((pIn
->size
!= sizeof(ELEM_FLT32TOCOLORPIXEL_INPUT
)) ||
3890 (pOut
->size
!= sizeof(ELEM_FLT32TOCOLORPIXEL_OUTPUT
)))
3892 returnCode
= ADDR_PARAMSIZEMISMATCH
;
3896 if (returnCode
== ADDR_OK
)
3898 GetElemLib()->Flt32ToColorPixel(pIn
->format
,
3910 ***************************************************************************************************
3911 * AddrLib::GetExportNorm
3914 * Check one format can be EXPORT_NUM
3916 * TRUE if EXPORT_NORM can be used
3917 ***************************************************************************************************
3919 BOOL_32
AddrLib::GetExportNorm(
3920 const ELEM_GETEXPORTNORM_INPUT
* pIn
) const
3922 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3924 BOOL_32 enabled
= FALSE
;
3926 if (GetFillSizeFieldsFlags() == TRUE
)
3928 if (pIn
->size
!= sizeof(ELEM_GETEXPORTNORM_INPUT
))
3930 returnCode
= ADDR_PARAMSIZEMISMATCH
;
3934 if (returnCode
== ADDR_OK
)
3936 enabled
= GetElemLib()->PixGetExportNorm(pIn
->format
,
3945 ***************************************************************************************************
3946 * AddrLib::ComputePrtInfo
3949 * Compute prt surface related info
3953 ***************************************************************************************************
3955 ADDR_E_RETURNCODE
AddrLib::ComputePrtInfo(
3956 const ADDR_PRT_INFO_INPUT
* pIn
,
3957 ADDR_PRT_INFO_OUTPUT
* pOut
) const
3959 ADDR_ASSERT(pOut
!= NULL
);
3961 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3963 UINT_32 expandX
= 1;
3964 UINT_32 expandY
= 1;
3965 AddrElemMode elemMode
;
3967 UINT_32 bpp
= GetElemLib()->GetBitsPerPixel(pIn
->format
,
3972 if (bpp
<8 || bpp
== 24 || bpp
== 48 || bpp
== 96 )
3974 returnCode
= ADDR_INVALIDPARAMS
;
3977 UINT_32 numFrags
= pIn
->numFrags
;
3978 ADDR_ASSERT(numFrags
<= 8);
3980 UINT_32 tileWidth
= 0;
3981 UINT_32 tileHeight
= 0;
3982 if (returnCode
== ADDR_OK
)
3984 // 3D texture without depth or 2d texture
3985 if (pIn
->baseMipDepth
> 1 || pIn
->baseMipHeight
> 1)
4004 // assume it is BC1/4
4008 if (elemMode
== ADDR_UNCOMPRESSED
)
4014 else if (bpp
== 128)
4016 // assume it is BC2/3/5/6H/7
4020 if (elemMode
== ADDR_UNCOMPRESSED
)
4029 tileWidth
= tileWidth
/ 2;
4031 else if (numFrags
== 4)
4033 tileWidth
= tileWidth
/ 2;
4034 tileHeight
= tileHeight
/ 2;
4036 else if (numFrags
== 8)
4038 tileWidth
= tileWidth
/ 4;
4039 tileHeight
= tileHeight
/ 2;
4061 else if (bpp
== 128)
4068 pOut
->prtTileWidth
= tileWidth
;
4069 pOut
->prtTileHeight
= tileHeight
;