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
.degradeBaseLevel
= pCreateIn
->createFlags
.degradeBaseLevel
;
268 pLib
->m_configFlags
.allowLargeThickTile
= pCreateIn
->createFlags
.allowLargeThickTile
;
270 pLib
->SetAddrChipFamily(pCreateIn
->chipFamily
, pCreateIn
->chipRevision
);
272 pLib
->SetMinPitchAlignPixels(pCreateIn
->minPitchAlignPixels
);
274 // Global parameters initialized and remaining configFlags bits are set as well
275 initValid
= pLib
->HwlInitGlobalParams(pCreateIn
);
279 pLib
->m_pElemLib
= AddrElemLib::Create(pLib
);
283 pLib
->m_pElemLib
= NULL
; // Don't go on allocating element lib
284 returnCode
= ADDR_INVALIDGBREGVALUES
;
287 if (pLib
->m_pElemLib
== NULL
)
291 ADDR_ASSERT_ALWAYS();
295 pLib
->m_pElemLib
->SetConfigFlags(pLib
->m_configFlags
);
299 pCreateOut
->hLib
= pLib
;
301 if ((pLib
== NULL
) &&
302 (returnCode
== ADDR_OK
))
304 // Unknown failures, we return the general error code
305 returnCode
= ADDR_ERROR
;
312 ***************************************************************************************************
313 * AddrLib::SetAddrChipFamily
316 * Convert familyID defined in atiid.h to AddrChipFamily and set m_chipFamily/m_chipRevision
319 ***************************************************************************************************
321 VOID
AddrLib::SetAddrChipFamily(
322 UINT_32 uChipFamily
, ///< [in] chip family defined in atiih.h
323 UINT_32 uChipRevision
) ///< [in] chip revision defined in "asic_family"_id.h
325 AddrChipFamily family
= ADDR_CHIP_FAMILY_IVLD
;
327 family
= HwlConvertChipFamily(uChipFamily
, uChipRevision
);
329 ADDR_ASSERT(family
!= ADDR_CHIP_FAMILY_IVLD
);
331 m_chipFamily
= family
;
332 m_chipRevision
= uChipRevision
;
336 ***************************************************************************************************
337 * AddrLib::SetMinPitchAlignPixels
340 * Set m_minPitchAlignPixels with input param
344 ***************************************************************************************************
346 VOID
AddrLib::SetMinPitchAlignPixels(
347 UINT_32 minPitchAlignPixels
) ///< [in] minmum pitch alignment in pixels
349 m_minPitchAlignPixels
= (minPitchAlignPixels
== 0)? 1 : minPitchAlignPixels
;
353 ***************************************************************************************************
354 * AddrLib::GetAddrLib
357 * Get AddrLib pointer
360 * An AddrLib class pointer
361 ***************************************************************************************************
363 AddrLib
* AddrLib::GetAddrLib(
364 ADDR_HANDLE hLib
) ///< [in] handle of ADDR_HANDLE
366 return static_cast<AddrLib
*>(hLib
);
371 ///////////////////////////////////////////////////////////////////////////////////////////////////
373 ///////////////////////////////////////////////////////////////////////////////////////////////////
377 ***************************************************************************************************
378 * AddrLib::ComputeSurfaceInfo
381 * Interface function stub of AddrComputeSurfaceInfo.
385 ***************************************************************************************************
387 ADDR_E_RETURNCODE
AddrLib::ComputeSurfaceInfo(
388 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
389 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
392 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
394 if (GetFillSizeFieldsFlags() == TRUE
)
396 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_SURFACE_INFO_INPUT
)) ||
397 (pOut
->size
!= sizeof(ADDR_COMPUTE_SURFACE_INFO_OUTPUT
)))
399 returnCode
= ADDR_PARAMSIZEMISMATCH
;
403 // We suggest client do sanity check but a check here is also good
406 returnCode
= ADDR_INVALIDPARAMS
;
409 // Thick modes don't support multisample
410 if (ComputeSurfaceThickness(pIn
->tileMode
) > 1 && pIn
->numSamples
> 1)
412 returnCode
= ADDR_INVALIDPARAMS
;
415 if (returnCode
== ADDR_OK
)
417 // Get a local copy of input structure and only reference pIn for unadjusted values
418 ADDR_COMPUTE_SURFACE_INFO_INPUT localIn
= *pIn
;
419 ADDR_TILEINFO tileInfoNull
= {0};
423 // If the original input has a valid ADDR_TILEINFO pointer then copy its contents.
424 // Otherwise the default 0's in tileInfoNull are used.
427 tileInfoNull
= *pIn
->pTileInfo
;
429 localIn
.pTileInfo
= &tileInfoNull
;
432 localIn
.numSamples
= pIn
->numSamples
== 0 ? 1 : pIn
->numSamples
;
434 // Do mipmap check first
435 // If format is BCn, pre-pad dimension to power-of-two according to HWL
436 ComputeMipLevel(&localIn
);
438 if (m_configFlags
.checkLast2DLevel
)
440 // Save this level's original height in pixels
441 pOut
->height
= pIn
->height
;
446 AddrElemMode elemMode
;
448 // Save outputs that may not go through HWL
449 pOut
->pixelBits
= localIn
.bpp
;
450 pOut
->numSamples
= localIn
.numSamples
;
451 pOut
->last2DLevel
= 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
));
548 if (returnCode
== ADDR_OK
)
550 AddrTileMode tileMode
= localIn
.tileMode
;
551 AddrTileType tileType
= localIn
.tileType
;
553 // HWL layer may override tile mode if necessary
554 if (HwlOverrideTileMode(&localIn
, &tileMode
, &tileType
))
556 localIn
.tileMode
= tileMode
;
557 localIn
.tileType
= tileType
;
559 // Degrade base level if applicable
560 if (DegradeBaseLevel(&localIn
, &tileMode
))
562 localIn
.tileMode
= tileMode
;
566 // Call main function to compute surface info
567 if (returnCode
== ADDR_OK
)
569 returnCode
= HwlComputeSurfaceInfo(&localIn
, pOut
);
572 if (returnCode
== ADDR_OK
)
574 // Since bpp might be changed we just pass it through
575 pOut
->bpp
= localIn
.bpp
;
577 // Also original width/height/bpp
578 pOut
->pixelPitch
= pOut
->pitch
;
579 pOut
->pixelHeight
= pOut
->height
;
582 if (localIn
.flags
.display
)
584 ADDR_ASSERT((pOut
->pitchAlign
% 32) == 0);
588 if (localIn
.format
!= ADDR_FMT_INVALID
)
591 // 96 bits surface of level 1+ requires element pitch of 32 bits instead
592 // In hwl function we skip multiplication of 3 then we should skip division of 3
593 // We keep pitch that represents 32 bit element instead of 96 bits since we
594 // will get an odd number if divided by 3.
596 if (!((expandX
== 3) && (localIn
.mipLevel
> 0)))
599 GetElemLib()->RestoreSurfaceInfo(elemMode
,
608 if (localIn
.flags
.qbStereo
)
610 if (pOut
->pStereoInfo
)
612 ComputeQbStereoInfo(pOut
);
616 if (localIn
.flags
.volume
) // For volume sliceSize equals to all z-slices
618 pOut
->sliceSize
= pOut
->surfSize
;
620 else // For array: sliceSize is likely to have slice-padding (the last one)
622 pOut
->sliceSize
= pOut
->surfSize
/ pOut
->depth
;
625 if (pIn
->numSlices
> 1)
627 // If this is the last slice then add the padding size to this slice
628 if (pIn
->slice
== (pIn
->numSlices
- 1))
630 pOut
->sliceSize
+= pOut
->sliceSize
* (pOut
->depth
- pIn
->numSlices
);
632 else if (m_configFlags
.checkLast2DLevel
)
634 // Reset last2DLevel flag if this is not the last array slice
635 pOut
->last2DLevel
= FALSE
;
640 pOut
->pitchTileMax
= pOut
->pitch
/ 8 - 1;
641 pOut
->heightTileMax
= pOut
->height
/ 8 - 1;
642 pOut
->sliceTileMax
= pOut
->pitch
* pOut
->height
/ 64 - 1;
650 ***************************************************************************************************
651 * AddrLib::ComputeSurfaceInfo
654 * Interface function stub of AddrComputeSurfaceInfo.
658 ***************************************************************************************************
660 ADDR_E_RETURNCODE
AddrLib::ComputeSurfaceAddrFromCoord(
661 const ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
662 ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
665 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
667 if (GetFillSizeFieldsFlags() == TRUE
)
669 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
)) ||
670 (pOut
->size
!= sizeof(ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
)))
672 returnCode
= ADDR_PARAMSIZEMISMATCH
;
676 if (returnCode
== ADDR_OK
)
678 ADDR_TILEINFO tileInfoNull
;
679 ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT input
;
681 if (UseTileIndex(pIn
->tileIndex
))
684 // Use temp tile info for calcalation
685 input
.pTileInfo
= &tileInfoNull
;
687 const ADDR_SURFACE_FLAGS flags
= {{0}};
688 UINT_32 numSamples
= GetNumFragments(pIn
->numSamples
, pIn
->numFrags
);
690 // Try finding a macroModeIndex
691 INT_32 macroModeIndex
= HwlComputeMacroModeIndex(input
.tileIndex
,
699 // If macroModeIndex is not needed, then call HwlSetupTileCfg to get tile info
700 if (macroModeIndex
== TileIndexNoMacroIndex
)
702 returnCode
= HwlSetupTileCfg(input
.tileIndex
, macroModeIndex
,
703 input
.pTileInfo
, &input
.tileMode
, &input
.tileType
);
705 // If macroModeIndex is invalid, then assert this is not macro tiled
706 else if (macroModeIndex
== TileIndexInvalid
)
708 ADDR_ASSERT(!IsMacroTiled(input
.tileMode
));
711 // Change the input structure
715 if (returnCode
== ADDR_OK
)
717 returnCode
= HwlComputeSurfaceAddrFromCoord(pIn
, pOut
);
719 if (returnCode
== ADDR_OK
)
721 pOut
->prtBlockIndex
= static_cast<UINT_32
>(pOut
->addr
/ (64 * 1024));
730 ***************************************************************************************************
731 * AddrLib::ComputeSurfaceCoordFromAddr
734 * Interface function stub of ComputeSurfaceCoordFromAddr.
738 ***************************************************************************************************
740 ADDR_E_RETURNCODE
AddrLib::ComputeSurfaceCoordFromAddr(
741 const ADDR_COMPUTE_SURFACE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
742 ADDR_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
745 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
747 if (GetFillSizeFieldsFlags() == TRUE
)
749 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_SURFACE_COORDFROMADDR_INPUT
)) ||
750 (pOut
->size
!= sizeof(ADDR_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
)))
752 returnCode
= ADDR_PARAMSIZEMISMATCH
;
756 if (returnCode
== ADDR_OK
)
758 ADDR_TILEINFO tileInfoNull
;
759 ADDR_COMPUTE_SURFACE_COORDFROMADDR_INPUT input
;
761 if (UseTileIndex(pIn
->tileIndex
))
764 // Use temp tile info for calcalation
765 input
.pTileInfo
= &tileInfoNull
;
767 const ADDR_SURFACE_FLAGS flags
= {{0}};
768 UINT_32 numSamples
= GetNumFragments(pIn
->numSamples
, pIn
->numFrags
);
770 // Try finding a macroModeIndex
771 INT_32 macroModeIndex
= HwlComputeMacroModeIndex(input
.tileIndex
,
779 // If macroModeIndex is not needed, then call HwlSetupTileCfg to get tile info
780 if (macroModeIndex
== TileIndexNoMacroIndex
)
782 returnCode
= HwlSetupTileCfg(input
.tileIndex
, macroModeIndex
,
783 input
.pTileInfo
, &input
.tileMode
, &input
.tileType
);
785 // If macroModeIndex is invalid, then assert this is not macro tiled
786 else if (macroModeIndex
== TileIndexInvalid
)
788 ADDR_ASSERT(!IsMacroTiled(input
.tileMode
));
791 // Change the input structure
795 if (returnCode
== ADDR_OK
)
797 returnCode
= HwlComputeSurfaceCoordFromAddr(pIn
, pOut
);
805 ***************************************************************************************************
806 * AddrLib::ComputeSliceTileSwizzle
809 * Interface function stub of ComputeSliceTileSwizzle.
813 ***************************************************************************************************
815 ADDR_E_RETURNCODE
AddrLib::ComputeSliceTileSwizzle(
816 const ADDR_COMPUTE_SLICESWIZZLE_INPUT
* pIn
, ///< [in] input structure
817 ADDR_COMPUTE_SLICESWIZZLE_OUTPUT
* pOut
///< [out] output structure
820 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
822 if (GetFillSizeFieldsFlags() == TRUE
)
824 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_SLICESWIZZLE_INPUT
)) ||
825 (pOut
->size
!= sizeof(ADDR_COMPUTE_SLICESWIZZLE_OUTPUT
)))
827 returnCode
= ADDR_PARAMSIZEMISMATCH
;
831 if (returnCode
== ADDR_OK
)
833 ADDR_TILEINFO tileInfoNull
;
834 ADDR_COMPUTE_SLICESWIZZLE_INPUT input
;
836 if (UseTileIndex(pIn
->tileIndex
))
839 // Use temp tile info for calcalation
840 input
.pTileInfo
= &tileInfoNull
;
842 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
,
843 input
.pTileInfo
, &input
.tileMode
);
844 // Change the input structure
848 if (returnCode
== ADDR_OK
)
850 returnCode
= HwlComputeSliceTileSwizzle(pIn
, pOut
);
858 ***************************************************************************************************
859 * AddrLib::ExtractBankPipeSwizzle
862 * Interface function stub of AddrExtractBankPipeSwizzle.
866 ***************************************************************************************************
868 ADDR_E_RETURNCODE
AddrLib::ExtractBankPipeSwizzle(
869 const ADDR_EXTRACT_BANKPIPE_SWIZZLE_INPUT
* pIn
, ///< [in] input structure
870 ADDR_EXTRACT_BANKPIPE_SWIZZLE_OUTPUT
* pOut
///< [out] output structure
873 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
875 if (GetFillSizeFieldsFlags() == TRUE
)
877 if ((pIn
->size
!= sizeof(ADDR_EXTRACT_BANKPIPE_SWIZZLE_INPUT
)) ||
878 (pOut
->size
!= sizeof(ADDR_EXTRACT_BANKPIPE_SWIZZLE_OUTPUT
)))
880 returnCode
= ADDR_PARAMSIZEMISMATCH
;
884 if (returnCode
== ADDR_OK
)
886 ADDR_TILEINFO tileInfoNull
;
887 ADDR_EXTRACT_BANKPIPE_SWIZZLE_INPUT input
;
889 if (UseTileIndex(pIn
->tileIndex
))
892 // Use temp tile info for calcalation
893 input
.pTileInfo
= &tileInfoNull
;
895 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
896 // Change the input structure
900 if (returnCode
== ADDR_OK
)
902 returnCode
= HwlExtractBankPipeSwizzle(pIn
, pOut
);
910 ***************************************************************************************************
911 * AddrLib::CombineBankPipeSwizzle
914 * Interface function stub of AddrCombineBankPipeSwizzle.
918 ***************************************************************************************************
920 ADDR_E_RETURNCODE
AddrLib::CombineBankPipeSwizzle(
921 const ADDR_COMBINE_BANKPIPE_SWIZZLE_INPUT
* pIn
, ///< [in] input structure
922 ADDR_COMBINE_BANKPIPE_SWIZZLE_OUTPUT
* pOut
///< [out] output structure
925 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
927 if (GetFillSizeFieldsFlags() == TRUE
)
929 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_FMASK_INFO_INPUT
)) ||
930 (pOut
->size
!= sizeof(ADDR_COMPUTE_FMASK_INFO_OUTPUT
)))
932 returnCode
= ADDR_PARAMSIZEMISMATCH
;
936 if (returnCode
== ADDR_OK
)
938 ADDR_TILEINFO tileInfoNull
;
939 ADDR_COMBINE_BANKPIPE_SWIZZLE_INPUT input
;
941 if (UseTileIndex(pIn
->tileIndex
))
944 // Use temp tile info for calcalation
945 input
.pTileInfo
= &tileInfoNull
;
947 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
948 // Change the input structure
952 if (returnCode
== ADDR_OK
)
954 returnCode
= HwlCombineBankPipeSwizzle(pIn
->bankSwizzle
,
966 ***************************************************************************************************
967 * AddrLib::ComputeBaseSwizzle
970 * Interface function stub of AddrCompueBaseSwizzle.
973 ***************************************************************************************************
975 ADDR_E_RETURNCODE
AddrLib::ComputeBaseSwizzle(
976 const ADDR_COMPUTE_BASE_SWIZZLE_INPUT
* pIn
,
977 ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT
* pOut
) const
979 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
981 if (GetFillSizeFieldsFlags() == TRUE
)
983 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_BASE_SWIZZLE_INPUT
)) ||
984 (pOut
->size
!= sizeof(ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT
)))
986 returnCode
= ADDR_PARAMSIZEMISMATCH
;
990 if (returnCode
== ADDR_OK
)
992 ADDR_TILEINFO tileInfoNull
;
993 ADDR_COMPUTE_BASE_SWIZZLE_INPUT input
;
995 if (UseTileIndex(pIn
->tileIndex
))
998 // Use temp tile info for calcalation
999 input
.pTileInfo
= &tileInfoNull
;
1001 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1002 // Change the input structure
1006 if (returnCode
== ADDR_OK
)
1008 if (IsMacroTiled(pIn
->tileMode
))
1010 returnCode
= HwlComputeBaseSwizzle(pIn
, pOut
);
1014 pOut
->tileSwizzle
= 0;
1023 ***************************************************************************************************
1024 * AddrLib::ComputeFmaskInfo
1027 * Interface function stub of ComputeFmaskInfo.
1031 ***************************************************************************************************
1033 ADDR_E_RETURNCODE
AddrLib::ComputeFmaskInfo(
1034 const ADDR_COMPUTE_FMASK_INFO_INPUT
* pIn
, ///< [in] input structure
1035 ADDR_COMPUTE_FMASK_INFO_OUTPUT
* pOut
///< [out] output structure
1038 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1040 if (GetFillSizeFieldsFlags() == TRUE
)
1042 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_FMASK_INFO_INPUT
)) ||
1043 (pOut
->size
!= sizeof(ADDR_COMPUTE_FMASK_INFO_OUTPUT
)))
1045 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1050 if (ComputeSurfaceThickness(pIn
->tileMode
) > 1)
1052 returnCode
= ADDR_INVALIDPARAMS
;
1055 if (returnCode
== ADDR_OK
)
1057 ADDR_TILEINFO tileInfoNull
;
1058 ADDR_COMPUTE_FMASK_INFO_INPUT input
;
1060 if (UseTileIndex(pIn
->tileIndex
))
1064 if (pOut
->pTileInfo
)
1066 // Use temp tile info for calcalation
1067 input
.pTileInfo
= pOut
->pTileInfo
;
1071 input
.pTileInfo
= &tileInfoNull
;
1074 ADDR_SURFACE_FLAGS flags
= {{0}};
1077 // Try finding a macroModeIndex
1078 INT_32 macroModeIndex
= HwlComputeMacroModeIndex(pIn
->tileIndex
,
1080 HwlComputeFmaskBits(pIn
, NULL
),
1085 // If macroModeIndex is not needed, then call HwlSetupTileCfg to get tile info
1086 if (macroModeIndex
== TileIndexNoMacroIndex
)
1088 returnCode
= HwlSetupTileCfg(input
.tileIndex
, macroModeIndex
,
1089 input
.pTileInfo
, &input
.tileMode
);
1092 ADDR_ASSERT(macroModeIndex
!= TileIndexInvalid
);
1094 // Change the input structure
1098 if (returnCode
== ADDR_OK
)
1100 if (pIn
->numSamples
> 1)
1102 returnCode
= HwlComputeFmaskInfo(pIn
, pOut
);
1106 memset(pOut
, 0, sizeof(ADDR_COMPUTE_FMASK_INFO_OUTPUT
));
1108 returnCode
= ADDR_INVALIDPARAMS
;
1117 ***************************************************************************************************
1118 * AddrLib::ComputeFmaskAddrFromCoord
1121 * Interface function stub of ComputeFmaskAddrFromCoord.
1125 ***************************************************************************************************
1127 ADDR_E_RETURNCODE
AddrLib::ComputeFmaskAddrFromCoord(
1128 const ADDR_COMPUTE_FMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1129 ADDR_COMPUTE_FMASK_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1132 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1134 if (GetFillSizeFieldsFlags() == TRUE
)
1136 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_FMASK_ADDRFROMCOORD_INPUT
)) ||
1137 (pOut
->size
!= sizeof(ADDR_COMPUTE_FMASK_ADDRFROMCOORD_OUTPUT
)))
1139 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1143 if (returnCode
== ADDR_OK
)
1145 ADDR_ASSERT(pIn
->numSamples
> 1);
1147 if (pIn
->numSamples
> 1)
1149 returnCode
= HwlComputeFmaskAddrFromCoord(pIn
, pOut
);
1153 returnCode
= ADDR_INVALIDPARAMS
;
1161 ***************************************************************************************************
1162 * AddrLib::ComputeFmaskCoordFromAddr
1165 * Interface function stub of ComputeFmaskAddrFromCoord.
1169 ***************************************************************************************************
1171 ADDR_E_RETURNCODE
AddrLib::ComputeFmaskCoordFromAddr(
1172 const ADDR_COMPUTE_FMASK_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1173 ADDR_COMPUTE_FMASK_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1176 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1178 if (GetFillSizeFieldsFlags() == TRUE
)
1180 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_FMASK_COORDFROMADDR_INPUT
)) ||
1181 (pOut
->size
!= sizeof(ADDR_COMPUTE_FMASK_COORDFROMADDR_OUTPUT
)))
1183 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1187 if (returnCode
== ADDR_OK
)
1189 ADDR_ASSERT(pIn
->numSamples
> 1);
1191 if (pIn
->numSamples
> 1)
1193 returnCode
= HwlComputeFmaskCoordFromAddr(pIn
, pOut
);
1197 returnCode
= ADDR_INVALIDPARAMS
;
1205 ***************************************************************************************************
1206 * AddrLib::ConvertTileInfoToHW
1209 * Convert tile info from real value to HW register value in HW layer
1213 ***************************************************************************************************
1215 ADDR_E_RETURNCODE
AddrLib::ConvertTileInfoToHW(
1216 const ADDR_CONVERT_TILEINFOTOHW_INPUT
* pIn
, ///< [in] input structure
1217 ADDR_CONVERT_TILEINFOTOHW_OUTPUT
* pOut
///< [out] output structure
1220 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1222 if (GetFillSizeFieldsFlags() == TRUE
)
1224 if ((pIn
->size
!= sizeof(ADDR_CONVERT_TILEINFOTOHW_INPUT
)) ||
1225 (pOut
->size
!= sizeof(ADDR_CONVERT_TILEINFOTOHW_OUTPUT
)))
1227 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1231 if (returnCode
== ADDR_OK
)
1233 ADDR_TILEINFO tileInfoNull
;
1234 ADDR_CONVERT_TILEINFOTOHW_INPUT input
;
1235 // if pIn->reverse is TRUE, indices are ignored
1236 if (pIn
->reverse
== FALSE
&& UseTileIndex(pIn
->tileIndex
))
1239 input
.pTileInfo
= &tileInfoNull
;
1241 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1246 if (returnCode
== ADDR_OK
)
1248 returnCode
= HwlConvertTileInfoToHW(pIn
, pOut
);
1256 ***************************************************************************************************
1257 * AddrLib::ConvertTileIndex
1260 * Convert tile index to tile mode/type/info
1264 ***************************************************************************************************
1266 ADDR_E_RETURNCODE
AddrLib::ConvertTileIndex(
1267 const ADDR_CONVERT_TILEINDEX_INPUT
* pIn
, ///< [in] input structure
1268 ADDR_CONVERT_TILEINDEX_OUTPUT
* pOut
///< [out] output structure
1271 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1273 if (GetFillSizeFieldsFlags() == TRUE
)
1275 if ((pIn
->size
!= sizeof(ADDR_CONVERT_TILEINDEX_INPUT
)) ||
1276 (pOut
->size
!= sizeof(ADDR_CONVERT_TILEINDEX_OUTPUT
)))
1278 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1282 if (returnCode
== ADDR_OK
)
1285 returnCode
= HwlSetupTileCfg(pIn
->tileIndex
, pIn
->macroModeIndex
,
1286 pOut
->pTileInfo
, &pOut
->tileMode
, &pOut
->tileType
);
1288 if (returnCode
== ADDR_OK
&& pIn
->tileInfoHw
)
1290 ADDR_CONVERT_TILEINFOTOHW_INPUT hwInput
= {0};
1291 ADDR_CONVERT_TILEINFOTOHW_OUTPUT hwOutput
= {0};
1293 hwInput
.pTileInfo
= pOut
->pTileInfo
;
1294 hwInput
.tileIndex
= -1;
1295 hwOutput
.pTileInfo
= pOut
->pTileInfo
;
1297 returnCode
= HwlConvertTileInfoToHW(&hwInput
, &hwOutput
);
1305 ***************************************************************************************************
1306 * AddrLib::ConvertTileIndex1
1309 * Convert tile index to tile mode/type/info
1313 ***************************************************************************************************
1315 ADDR_E_RETURNCODE
AddrLib::ConvertTileIndex1(
1316 const ADDR_CONVERT_TILEINDEX1_INPUT
* pIn
, ///< [in] input structure
1317 ADDR_CONVERT_TILEINDEX_OUTPUT
* pOut
///< [out] output structure
1320 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1322 if (GetFillSizeFieldsFlags() == TRUE
)
1324 if ((pIn
->size
!= sizeof(ADDR_CONVERT_TILEINDEX1_INPUT
)) ||
1325 (pOut
->size
!= sizeof(ADDR_CONVERT_TILEINDEX_OUTPUT
)))
1327 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1331 if (returnCode
== ADDR_OK
)
1333 ADDR_SURFACE_FLAGS flags
= {{0}};
1335 HwlComputeMacroModeIndex(pIn
->tileIndex
, flags
, pIn
->bpp
, pIn
->numSamples
,
1336 pOut
->pTileInfo
, &pOut
->tileMode
, &pOut
->tileType
);
1338 if (pIn
->tileInfoHw
)
1340 ADDR_CONVERT_TILEINFOTOHW_INPUT hwInput
= {0};
1341 ADDR_CONVERT_TILEINFOTOHW_OUTPUT hwOutput
= {0};
1343 hwInput
.pTileInfo
= pOut
->pTileInfo
;
1344 hwInput
.tileIndex
= -1;
1345 hwOutput
.pTileInfo
= pOut
->pTileInfo
;
1347 returnCode
= HwlConvertTileInfoToHW(&hwInput
, &hwOutput
);
1355 ***************************************************************************************************
1356 * AddrLib::GetTileIndex
1359 * Get tile index from tile mode/type/info
1363 ***************************************************************************************************
1365 ADDR_E_RETURNCODE
AddrLib::GetTileIndex(
1366 const ADDR_GET_TILEINDEX_INPUT
* pIn
, ///< [in] input structure
1367 ADDR_GET_TILEINDEX_OUTPUT
* pOut
///< [out] output structure
1370 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1372 if (GetFillSizeFieldsFlags() == TRUE
)
1374 if ((pIn
->size
!= sizeof(ADDR_GET_TILEINDEX_INPUT
)) ||
1375 (pOut
->size
!= sizeof(ADDR_GET_TILEINDEX_OUTPUT
)))
1377 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1381 if (returnCode
== ADDR_OK
)
1383 returnCode
= HwlGetTileIndex(pIn
, pOut
);
1390 ***************************************************************************************************
1391 * AddrLib::ComputeSurfaceThickness
1394 * Compute surface thickness
1398 ***************************************************************************************************
1400 UINT_32
AddrLib::ComputeSurfaceThickness(
1401 AddrTileMode tileMode
) ///< [in] tile mode
1403 return m_modeFlags
[tileMode
].thickness
;
1408 ///////////////////////////////////////////////////////////////////////////////////////////////////
1410 ///////////////////////////////////////////////////////////////////////////////////////////////////
1413 ***************************************************************************************************
1414 * AddrLib::ComputeHtileInfo
1417 * Interface function stub of AddrComputeHtilenfo
1421 ***************************************************************************************************
1423 ADDR_E_RETURNCODE
AddrLib::ComputeHtileInfo(
1424 const ADDR_COMPUTE_HTILE_INFO_INPUT
* pIn
, ///< [in] input structure
1425 ADDR_COMPUTE_HTILE_INFO_OUTPUT
* pOut
///< [out] output structure
1428 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1430 BOOL_32 isWidth8
= (pIn
->blockWidth
== 8) ? TRUE
: FALSE
;
1431 BOOL_32 isHeight8
= (pIn
->blockHeight
== 8) ? TRUE
: FALSE
;
1433 if (GetFillSizeFieldsFlags() == TRUE
)
1435 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_HTILE_INFO_INPUT
)) ||
1436 (pOut
->size
!= sizeof(ADDR_COMPUTE_HTILE_INFO_OUTPUT
)))
1438 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1442 if (returnCode
== ADDR_OK
)
1444 ADDR_TILEINFO tileInfoNull
;
1445 ADDR_COMPUTE_HTILE_INFO_INPUT input
;
1447 if (UseTileIndex(pIn
->tileIndex
))
1450 // Use temp tile info for calcalation
1451 input
.pTileInfo
= &tileInfoNull
;
1453 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1455 // Change the input structure
1459 if (returnCode
== ADDR_OK
)
1461 pOut
->bpp
= ComputeHtileInfo(pIn
->flags
,
1483 ***************************************************************************************************
1484 * AddrLib::ComputeCmaskInfo
1487 * Interface function stub of AddrComputeCmaskInfo
1491 ***************************************************************************************************
1493 ADDR_E_RETURNCODE
AddrLib::ComputeCmaskInfo(
1494 const ADDR_COMPUTE_CMASK_INFO_INPUT
* pIn
, ///< [in] input structure
1495 ADDR_COMPUTE_CMASK_INFO_OUTPUT
* pOut
///< [out] output structure
1498 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1500 if (GetFillSizeFieldsFlags() == TRUE
)
1502 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_CMASK_INFO_INPUT
)) ||
1503 (pOut
->size
!= sizeof(ADDR_COMPUTE_CMASK_INFO_OUTPUT
)))
1505 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1509 if (returnCode
== ADDR_OK
)
1511 ADDR_TILEINFO tileInfoNull
;
1512 ADDR_COMPUTE_CMASK_INFO_INPUT input
;
1514 if (UseTileIndex(pIn
->tileIndex
))
1517 // Use temp tile info for calcalation
1518 input
.pTileInfo
= &tileInfoNull
;
1520 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1522 // Change the input structure
1526 if (returnCode
== ADDR_OK
)
1528 returnCode
= ComputeCmaskInfo(pIn
->flags
,
1549 ***************************************************************************************************
1550 * AddrLib::ComputeDccInfo
1553 * Interface function to compute DCC key info
1556 * return code of HwlComputeDccInfo
1557 ***************************************************************************************************
1559 ADDR_E_RETURNCODE
AddrLib::ComputeDccInfo(
1560 const ADDR_COMPUTE_DCCINFO_INPUT
* pIn
, ///< [in] input structure
1561 ADDR_COMPUTE_DCCINFO_OUTPUT
* pOut
///< [out] output structure
1564 ADDR_E_RETURNCODE ret
= ADDR_OK
;
1566 if (GetFillSizeFieldsFlags() == TRUE
)
1568 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_DCCINFO_INPUT
)) ||
1569 (pOut
->size
!= sizeof(ADDR_COMPUTE_DCCINFO_OUTPUT
)))
1571 ret
= ADDR_PARAMSIZEMISMATCH
;
1577 ADDR_COMPUTE_DCCINFO_INPUT input
;
1579 if (UseTileIndex(pIn
->tileIndex
))
1583 ret
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
,
1584 &input
.tileInfo
, &input
.tileMode
);
1591 ret
= HwlComputeDccInfo(pIn
, pOut
);
1599 ***************************************************************************************************
1600 * AddrLib::ComputeHtileAddrFromCoord
1603 * Interface function stub of AddrComputeHtileAddrFromCoord
1607 ***************************************************************************************************
1609 ADDR_E_RETURNCODE
AddrLib::ComputeHtileAddrFromCoord(
1610 const ADDR_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1611 ADDR_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1614 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1616 BOOL_32 isWidth8
= (pIn
->blockWidth
== 8) ? TRUE
: FALSE
;
1617 BOOL_32 isHeight8
= (pIn
->blockHeight
== 8) ? TRUE
: FALSE
;
1619 if (GetFillSizeFieldsFlags() == TRUE
)
1621 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
)) ||
1622 (pOut
->size
!= sizeof(ADDR_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
)))
1624 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1628 if (returnCode
== ADDR_OK
)
1630 ADDR_TILEINFO tileInfoNull
;
1631 ADDR_COMPUTE_HTILE_ADDRFROMCOORD_INPUT input
;
1633 if (UseTileIndex(pIn
->tileIndex
))
1636 // Use temp tile info for calcalation
1637 input
.pTileInfo
= &tileInfoNull
;
1639 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1641 // Change the input structure
1645 if (returnCode
== ADDR_OK
)
1647 pOut
->addr
= HwlComputeXmaskAddrFromCoord(pIn
->pitch
,
1658 &pOut
->bitPosition
);
1667 ***************************************************************************************************
1668 * AddrLib::ComputeHtileCoordFromAddr
1671 * Interface function stub of AddrComputeHtileCoordFromAddr
1675 ***************************************************************************************************
1677 ADDR_E_RETURNCODE
AddrLib::ComputeHtileCoordFromAddr(
1678 const ADDR_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1679 ADDR_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1682 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1684 BOOL_32 isWidth8
= (pIn
->blockWidth
== 8) ? TRUE
: FALSE
;
1685 BOOL_32 isHeight8
= (pIn
->blockHeight
== 8) ? TRUE
: FALSE
;
1687 if (GetFillSizeFieldsFlags() == TRUE
)
1689 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_HTILE_COORDFROMADDR_INPUT
)) ||
1690 (pOut
->size
!= sizeof(ADDR_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
)))
1692 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1696 if (returnCode
== ADDR_OK
)
1698 ADDR_TILEINFO tileInfoNull
;
1699 ADDR_COMPUTE_HTILE_COORDFROMADDR_INPUT input
;
1701 if (UseTileIndex(pIn
->tileIndex
))
1704 // Use temp tile info for calcalation
1705 input
.pTileInfo
= &tileInfoNull
;
1707 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1709 // Change the input structure
1713 if (returnCode
== ADDR_OK
)
1715 HwlComputeXmaskCoordFromAddr(pIn
->addr
,
1735 ***************************************************************************************************
1736 * AddrLib::ComputeCmaskAddrFromCoord
1739 * Interface function stub of AddrComputeCmaskAddrFromCoord
1743 ***************************************************************************************************
1745 ADDR_E_RETURNCODE
AddrLib::ComputeCmaskAddrFromCoord(
1746 const ADDR_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1747 ADDR_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1750 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1752 if (GetFillSizeFieldsFlags() == TRUE
)
1754 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
)) ||
1755 (pOut
->size
!= sizeof(ADDR_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
)))
1757 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1761 if (returnCode
== ADDR_OK
)
1763 ADDR_TILEINFO tileInfoNull
;
1764 ADDR_COMPUTE_CMASK_ADDRFROMCOORD_INPUT input
;
1766 if (UseTileIndex(pIn
->tileIndex
))
1769 // Use temp tile info for calcalation
1770 input
.pTileInfo
= &tileInfoNull
;
1772 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1774 // Change the input structure
1778 if (returnCode
== ADDR_OK
)
1780 if (pIn
->flags
.tcCompatible
== TRUE
)
1782 returnCode
= HwlComputeCmaskAddrFromCoord(pIn
, pOut
);
1786 pOut
->addr
= HwlComputeXmaskAddrFromCoord(pIn
->pitch
,
1794 FALSE
, //this is cmask, isWidth8 is not needed
1795 FALSE
, //this is cmask, isHeight8 is not needed
1797 &pOut
->bitPosition
);
1807 ***************************************************************************************************
1808 * AddrLib::ComputeCmaskCoordFromAddr
1811 * Interface function stub of AddrComputeCmaskCoordFromAddr
1815 ***************************************************************************************************
1817 ADDR_E_RETURNCODE
AddrLib::ComputeCmaskCoordFromAddr(
1818 const ADDR_COMPUTE_CMASK_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1819 ADDR_COMPUTE_CMASK_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1822 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1824 if (GetFillSizeFieldsFlags() == TRUE
)
1826 if ((pIn
->size
!= sizeof(ADDR_COMPUTE_CMASK_COORDFROMADDR_INPUT
)) ||
1827 (pOut
->size
!= sizeof(ADDR_COMPUTE_CMASK_COORDFROMADDR_OUTPUT
)))
1829 returnCode
= ADDR_PARAMSIZEMISMATCH
;
1833 if (returnCode
== ADDR_OK
)
1835 ADDR_TILEINFO tileInfoNull
;
1836 ADDR_COMPUTE_CMASK_COORDFROMADDR_INPUT input
;
1838 if (UseTileIndex(pIn
->tileIndex
))
1841 // Use temp tile info for calcalation
1842 input
.pTileInfo
= &tileInfoNull
;
1844 returnCode
= HwlSetupTileCfg(input
.tileIndex
, input
.macroModeIndex
, input
.pTileInfo
);
1846 // Change the input structure
1850 if (returnCode
== ADDR_OK
)
1852 HwlComputeXmaskCoordFromAddr(pIn
->addr
,
1872 ***************************************************************************************************
1873 * AddrLib::ComputeTileDataWidthAndHeight
1876 * Compute the squared cache shape for per-tile data (CMASK and HTILE)
1882 * MacroWidth and macroHeight are measured in pixels
1883 ***************************************************************************************************
1885 VOID
AddrLib::ComputeTileDataWidthAndHeight(
1886 UINT_32 bpp
, ///< [in] bits per pixel
1887 UINT_32 cacheBits
, ///< [in] bits of cache
1888 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
1889 UINT_32
* pMacroWidth
, ///< [out] macro tile width
1890 UINT_32
* pMacroHeight
///< [out] macro tile height
1894 UINT_32 width
= cacheBits
/ bpp
;
1895 UINT_32 pipes
= HwlGetPipes(pTileInfo
);
1897 // Double height until the macro-tile is close to square
1898 // Height can only be doubled if width is even
1900 while ((width
> height
* 2 * pipes
) && !(width
& 1))
1906 *pMacroWidth
= 8 * width
;
1907 *pMacroHeight
= 8 * height
* pipes
;
1909 // Note: The above iterative comptuation is equivalent to the following
1911 //int log2_height = ((log2(cacheBits)-log2(bpp)-log2(pipes))/2);
1912 //int macroHeight = pow2( 3+log2(pipes)+log2_height );
1916 ***************************************************************************************************
1917 * AddrLib::HwlComputeTileDataWidthAndHeightLinear
1920 * Compute the squared cache shape for per-tile data (CMASK and HTILE) for linear layout
1926 * MacroWidth and macroHeight are measured in pixels
1927 ***************************************************************************************************
1929 VOID
AddrLib::HwlComputeTileDataWidthAndHeightLinear(
1930 UINT_32
* pMacroWidth
, ///< [out] macro tile width
1931 UINT_32
* pMacroHeight
, ///< [out] macro tile height
1932 UINT_32 bpp
, ///< [in] bits per pixel
1933 ADDR_TILEINFO
* pTileInfo
///< [in] tile info
1936 ADDR_ASSERT(bpp
!= 4); // Cmask does not support linear layout prior to SI
1937 *pMacroWidth
= 8 * 512 / bpp
; // Align width to 512-bit memory accesses
1938 *pMacroHeight
= 8 * m_pipes
; // Align height to number of pipes
1942 ***************************************************************************************************
1943 * AddrLib::ComputeHtileInfo
1946 * Compute htile pitch,width, bytes per 2D slice
1949 * Htile bpp i.e. How many bits for an 8x8 tile
1950 * Also returns by output parameters:
1951 * *Htile pitch, height, total size in bytes, macro-tile dimensions and slice size*
1952 ***************************************************************************************************
1954 UINT_32
AddrLib::ComputeHtileInfo(
1955 ADDR_HTILE_FLAGS flags
, ///< [in] htile flags
1956 UINT_32 pitchIn
, ///< [in] pitch input
1957 UINT_32 heightIn
, ///< [in] height input
1958 UINT_32 numSlices
, ///< [in] number of slices
1959 BOOL_32 isLinear
, ///< [in] if it is linear mode
1960 BOOL_32 isWidth8
, ///< [in] if htile block width is 8
1961 BOOL_32 isHeight8
, ///< [in] if htile block height is 8
1962 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
1963 UINT_32
* pPitchOut
, ///< [out] pitch output
1964 UINT_32
* pHeightOut
, ///< [out] height output
1965 UINT_64
* pHtileBytes
, ///< [out] bytes per 2D slice
1966 UINT_32
* pMacroWidth
, ///< [out] macro-tile width in pixels
1967 UINT_32
* pMacroHeight
, ///< [out] macro-tile width in pixels
1968 UINT_64
* pSliceSize
, ///< [out] slice size in bytes
1969 UINT_32
* pBaseAlign
///< [out] base alignment
1974 UINT_32 macroHeight
;
1979 numSlices
= Max(1u, numSlices
);
1981 const UINT_32 bpp
= HwlComputeHtileBpp(isWidth8
, isHeight8
);
1982 const UINT_32 cacheBits
= HtileCacheBits
;
1986 HwlComputeTileDataWidthAndHeightLinear(¯oWidth
,
1993 ComputeTileDataWidthAndHeight(bpp
,
2000 *pPitchOut
= PowTwoAlign(pitchIn
, macroWidth
);
2001 *pHeightOut
= PowTwoAlign(heightIn
, macroHeight
);
2003 baseAlign
= HwlComputeHtileBaseAlign(flags
.tcCompatible
, isLinear
, pTileInfo
);
2005 surfBytes
= HwlComputeHtileBytes(*pPitchOut
,
2013 *pHtileBytes
= surfBytes
;
2016 // Use SafeAssign since they are optional
2018 SafeAssign(pMacroWidth
, macroWidth
);
2020 SafeAssign(pMacroHeight
, macroHeight
);
2022 SafeAssign(pSliceSize
, sliceBytes
);
2024 SafeAssign(pBaseAlign
, baseAlign
);
2030 ***************************************************************************************************
2031 * AddrLib::ComputeCmaskBaseAlign
2034 * Compute cmask base alignment
2037 * Cmask base alignment
2038 ***************************************************************************************************
2040 UINT_32
AddrLib::ComputeCmaskBaseAlign(
2041 ADDR_CMASK_FLAGS flags
, ///< [in] Cmask flags
2042 ADDR_TILEINFO
* pTileInfo
///< [in] Tile info
2045 UINT_32 baseAlign
= m_pipeInterleaveBytes
* HwlGetPipes(pTileInfo
);
2047 if (flags
.tcCompatible
)
2049 ADDR_ASSERT(pTileInfo
!= NULL
);
2052 baseAlign
*= pTileInfo
->banks
;
2060 ***************************************************************************************************
2061 * AddrLib::ComputeCmaskBytes
2064 * Compute cmask size in bytes
2067 * Cmask size in bytes
2068 ***************************************************************************************************
2070 UINT_64
AddrLib::ComputeCmaskBytes(
2071 UINT_32 pitch
, ///< [in] pitch
2072 UINT_32 height
, ///< [in] height
2073 UINT_32 numSlices
///< [in] number of slices
2076 return BITS_TO_BYTES(static_cast<UINT_64
>(pitch
) * height
* numSlices
* CmaskElemBits
) /
2081 ***************************************************************************************************
2082 * AddrLib::ComputeCmaskInfo
2085 * Compute cmask pitch,width, bytes per 2D slice
2088 * BlockMax. Also by output parameters: Cmask pitch,height, total size in bytes,
2089 * macro-tile dimensions
2090 ***************************************************************************************************
2092 ADDR_E_RETURNCODE
AddrLib::ComputeCmaskInfo(
2093 ADDR_CMASK_FLAGS flags
, ///< [in] cmask flags
2094 UINT_32 pitchIn
, ///< [in] pitch input
2095 UINT_32 heightIn
, ///< [in] height input
2096 UINT_32 numSlices
, ///< [in] number of slices
2097 BOOL_32 isLinear
, ///< [in] is linear mode
2098 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
2099 UINT_32
* pPitchOut
, ///< [out] pitch output
2100 UINT_32
* pHeightOut
, ///< [out] height output
2101 UINT_64
* pCmaskBytes
, ///< [out] bytes per 2D slice
2102 UINT_32
* pMacroWidth
, ///< [out] macro-tile width in pixels
2103 UINT_32
* pMacroHeight
, ///< [out] macro-tile width in pixels
2104 UINT_64
* pSliceSize
, ///< [out] slice size in bytes
2105 UINT_32
* pBaseAlign
, ///< [out] base alignment
2106 UINT_32
* pBlockMax
///< [out] block max == slice / 128 / 128 - 1
2110 UINT_32 macroHeight
;
2115 numSlices
= Max(1u, numSlices
);
2117 const UINT_32 bpp
= CmaskElemBits
;
2118 const UINT_32 cacheBits
= CmaskCacheBits
;
2120 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
2124 HwlComputeTileDataWidthAndHeightLinear(¯oWidth
,
2131 ComputeTileDataWidthAndHeight(bpp
,
2138 *pPitchOut
= (pitchIn
+ macroWidth
- 1) & ~(macroWidth
- 1);
2139 *pHeightOut
= (heightIn
+ macroHeight
- 1) & ~(macroHeight
- 1);
2142 sliceBytes
= ComputeCmaskBytes(*pPitchOut
,
2146 baseAlign
= ComputeCmaskBaseAlign(flags
, pTileInfo
);
2148 while (sliceBytes
% baseAlign
)
2150 *pHeightOut
+= macroHeight
;
2152 sliceBytes
= ComputeCmaskBytes(*pPitchOut
,
2157 surfBytes
= sliceBytes
* numSlices
;
2159 *pCmaskBytes
= surfBytes
;
2162 // Use SafeAssign since they are optional
2164 SafeAssign(pMacroWidth
, macroWidth
);
2166 SafeAssign(pMacroHeight
, macroHeight
);
2168 SafeAssign(pBaseAlign
, baseAlign
);
2170 SafeAssign(pSliceSize
, sliceBytes
);
2172 UINT_32 slice
= (*pPitchOut
) * (*pHeightOut
);
2173 UINT_32 blockMax
= slice
/ 128 / 128 - 1;
2176 if (slice
% (64*256) != 0)
2178 ADDR_ASSERT_ALWAYS();
2182 UINT_32 maxBlockMax
= HwlGetMaxCmaskBlockMax();
2184 if (blockMax
> maxBlockMax
)
2186 blockMax
= maxBlockMax
;
2187 returnCode
= ADDR_INVALIDPARAMS
;
2190 SafeAssign(pBlockMax
, blockMax
);
2196 ***************************************************************************************************
2197 * AddrLib::ComputeXmaskCoordYFromPipe
2200 * Compute the Y coord from pipe number for cmask/htile
2205 ***************************************************************************************************
2207 UINT_32
AddrLib::ComputeXmaskCoordYFromPipe(
2208 UINT_32 pipe
, ///< [in] pipe number
2209 UINT_32 x
///< [in] x coordinate
2221 UINT_32 numPipes
= m_pipes
; // SI has its implementation
2223 // Convert pipe + x to y coordinate.
2243 pipeBit0
= pipe
& 0x1;
2247 yBit0
= pipeBit0
^ xBit0
;
2261 pipeBit0
= pipe
& 0x1;
2262 pipeBit1
= (pipe
& 0x2) >> 1;
2265 xBit1
= (x
& 0x2) >> 1;
2267 yBit0
= pipeBit0
^ xBit1
;
2268 yBit1
= pipeBit1
^ xBit0
;
2277 // r600 and r800 have different method
2279 y
= HwlComputeXmaskCoordYFrom8Pipe(pipe
, x
);
2288 ***************************************************************************************************
2289 * AddrLib::HwlComputeXmaskCoordFromAddr
2292 * Compute the coord from an address of a cmask/htile
2298 * This method is reused by htile, so rename to Xmask
2299 ***************************************************************************************************
2301 VOID
AddrLib::HwlComputeXmaskCoordFromAddr(
2302 UINT_64 addr
, ///< [in] address
2303 UINT_32 bitPosition
, ///< [in] bitPosition in a byte
2304 UINT_32 pitch
, ///< [in] pitch
2305 UINT_32 height
, ///< [in] height
2306 UINT_32 numSlices
, ///< [in] number of slices
2307 UINT_32 factor
, ///< [in] factor that indicates cmask or htile
2308 BOOL_32 isLinear
, ///< [in] linear or tiled HTILE layout
2309 BOOL_32 isWidth8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
2310 BOOL_32 isHeight8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
2311 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
2312 UINT_32
* pX
, ///< [out] x coord
2313 UINT_32
* pY
, ///< [out] y coord
2314 UINT_32
* pSlice
///< [out] slice index
2319 UINT_32 numPipeBits
;
2320 UINT_32 macroTilePitch
;
2321 UINT_32 macroTileHeight
;
2325 UINT_32 microTileCoordY
;
2329 UINT_32 pitchAligned
= pitch
;
2330 UINT_32 heightAligned
= height
;
2338 UINT_64 macroNumber
;
2339 UINT_32 microNumber
;
2348 UINT_32 tilesPerMacro
;
2349 UINT_32 macrosPerPitch
;
2350 UINT_32 macrosPerSlice
;
2355 numPipes
= HwlGetPipes(pTileInfo
);
2356 pipe
= ComputePipeFromAddr(addr
, numPipes
);
2359 // Compute the number of group and pipe bits.
2361 numPipeBits
= Log2(numPipes
);
2363 UINT_32 groupBits
= 8 * m_pipeInterleaveBytes
;
2364 UINT_32 pipes
= numPipes
;
2368 // Compute the micro tile size, in bits. And macro tile pitch and height.
2370 if (factor
== 2) //CMASK
2372 ADDR_CMASK_FLAGS flags
= {{0}};
2374 elemBits
= CmaskElemBits
;
2376 ComputeCmaskInfo(flags
,
2390 ADDR_HTILE_FLAGS flags
= {{0}};
2397 elemBits
= HwlComputeHtileBpp(isWidth8
, isHeight8
);
2399 ComputeHtileInfo(flags
,
2414 // Should use aligned dims
2416 pitch
= pitchAligned
;
2417 height
= heightAligned
;
2421 // Convert byte address to bit address.
2423 bitAddr
= BYTES_TO_BITS(addr
) + bitPosition
;
2427 // Remove pipe bits from address.
2430 bitAddr
= (bitAddr
% groupBits
) + ((bitAddr
/groupBits
/pipes
)*groupBits
);
2433 elemOffset
= bitAddr
/ elemBits
;
2435 tilesPerMacro
= (macroTilePitch
/factor
) * macroTileHeight
/ MicroTilePixels
>> numPipeBits
;
2437 macrosPerPitch
= pitch
/ (macroTilePitch
/factor
);
2438 macrosPerSlice
= macrosPerPitch
* height
/ macroTileHeight
;
2440 macroIndex
= elemOffset
/ factor
/ tilesPerMacro
;
2441 microIndex
= static_cast<UINT_32
>(elemOffset
% (tilesPerMacro
* factor
));
2443 macroNumber
= macroIndex
* factor
+ microIndex
% factor
;
2444 microNumber
= microIndex
/ factor
;
2446 macroX
= static_cast<UINT_32
>((macroNumber
% macrosPerPitch
));
2447 macroY
= static_cast<UINT_32
>((macroNumber
% macrosPerSlice
) / macrosPerPitch
);
2448 macroZ
= static_cast<UINT_32
>((macroNumber
/ macrosPerSlice
));
2451 microX
= microNumber
% (macroTilePitch
/ factor
/ MicroTileWidth
);
2452 microY
= (microNumber
/ (macroTilePitch
/ factor
/ MicroTileHeight
));
2454 *pX
= macroX
* (macroTilePitch
/factor
) + microX
* MicroTileWidth
;
2455 *pY
= macroY
* macroTileHeight
+ (microY
* MicroTileHeight
<< numPipeBits
);
2458 microTileCoordY
= ComputeXmaskCoordYFromPipe(pipe
,
2459 *pX
/MicroTileWidth
);
2463 // Assemble final coordinates.
2465 *pY
+= microTileCoordY
* MicroTileHeight
;
2470 ***************************************************************************************************
2471 * AddrLib::HwlComputeXmaskAddrFromCoord
2474 * Compute the address from an address of cmask (prior to si)
2479 ***************************************************************************************************
2481 UINT_64
AddrLib::HwlComputeXmaskAddrFromCoord(
2482 UINT_32 pitch
, ///< [in] pitch
2483 UINT_32 height
, ///< [in] height
2484 UINT_32 x
, ///< [in] x coord
2485 UINT_32 y
, ///< [in] y coord
2486 UINT_32 slice
, ///< [in] slice/depth index
2487 UINT_32 numSlices
, ///< [in] number of slices
2488 UINT_32 factor
, ///< [in] factor that indicates cmask(2) or htile(1)
2489 BOOL_32 isLinear
, ///< [in] linear or tiled HTILE layout
2490 BOOL_32 isWidth8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
2491 BOOL_32 isHeight8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
2492 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
2493 UINT_32
* pBitPosition
///< [out] bit position inside a byte
2497 UINT_32 numGroupBits
;
2498 UINT_32 numPipeBits
;
2499 UINT_32 newPitch
= 0;
2500 UINT_32 newHeight
= 0;
2501 UINT_64 sliceBytes
= 0;
2502 UINT_64 totalBytes
= 0;
2503 UINT_64 sliceOffset
;
2505 UINT_32 macroTileWidth
;
2506 UINT_32 macroTileHeight
;
2507 UINT_32 macroTilesPerRow
;
2508 UINT_32 macroTileBytes
;
2509 UINT_32 macroTileIndexX
;
2510 UINT_32 macroTileIndexY
;
2511 UINT_64 macroTileOffset
;
2512 UINT_32 pixelBytesPerRow
;
2513 UINT_32 pixelOffsetX
;
2514 UINT_32 pixelOffsetY
;
2515 UINT_32 pixelOffset
;
2516 UINT_64 totalOffset
;
2522 UINT_32 elemBits
= 0;
2524 UINT_32 numPipes
= m_pipes
; // This function is accessed prior to si only
2526 if (factor
== 2) //CMASK
2528 elemBits
= CmaskElemBits
;
2530 // For asics before SI, cmask is always tiled
2535 if (factor
!= 1) // Fix compile warning
2540 elemBits
= HwlComputeHtileBpp(isWidth8
, isHeight8
);
2544 // Compute the number of group bits and pipe bits.
2546 numGroupBits
= Log2(m_pipeInterleaveBytes
);
2547 numPipeBits
= Log2(numPipes
);
2550 // Compute macro tile dimensions.
2552 if (factor
== 2) // CMASK
2554 ADDR_CMASK_FLAGS flags
= {{0}};
2556 ComputeCmaskInfo(flags
,
2568 sliceBytes
= totalBytes
/ numSlices
;
2572 ADDR_HTILE_FLAGS flags
= {{0}};
2574 ComputeHtileInfo(flags
,
2590 sliceOffset
= slice
* sliceBytes
;
2593 // Get the pipe. Note that neither slice rotation nor pipe swizzling apply for CMASK.
2595 pipe
= ComputePipeFromCoord(x
,
2598 ADDR_TM_2D_TILED_THIN1
,
2604 // Compute the number of macro tiles per row.
2606 macroTilesPerRow
= newPitch
/ macroTileWidth
;
2609 // Compute the number of bytes per macro tile.
2611 macroTileBytes
= BITS_TO_BYTES((macroTileWidth
* macroTileHeight
* elemBits
) / MicroTilePixels
);
2614 // Compute the offset to the macro tile containing the specified coordinate.
2616 macroTileIndexX
= x
/ macroTileWidth
;
2617 macroTileIndexY
= y
/ macroTileHeight
;
2618 macroTileOffset
= ((macroTileIndexY
* macroTilesPerRow
) + macroTileIndexX
) * macroTileBytes
;
2621 // Compute the pixel offset within the macro tile.
2623 pixelBytesPerRow
= BITS_TO_BYTES(macroTileWidth
* elemBits
) / MicroTileWidth
;
2626 // The nibbles are interleaved (see below), so the part of the offset relative to the x
2627 // coordinate repeats halfway across the row. (Not for HTILE)
2631 pixelOffsetX
= (x
% (macroTileWidth
/ 2)) / MicroTileWidth
;
2635 pixelOffsetX
= (x
% (macroTileWidth
)) / MicroTileWidth
* BITS_TO_BYTES(elemBits
);
2639 // Compute the y offset within the macro tile.
2641 pixelOffsetY
= (((y
% macroTileHeight
) / MicroTileHeight
) / numPipes
) * pixelBytesPerRow
;
2643 pixelOffset
= pixelOffsetX
+ pixelOffsetY
;
2646 // Combine the slice offset and macro tile offset with the pixel offset, accounting for the
2647 // pipe bits in the middle of the address.
2649 totalOffset
= ((sliceOffset
+ macroTileOffset
) >> numPipeBits
) + pixelOffset
;
2652 // Split the offset to put some bits below the pipe bits and some above.
2654 groupMask
= (1 << numGroupBits
) - 1;
2655 offsetLo
= totalOffset
& groupMask
;
2656 offsetHi
= (totalOffset
& ~groupMask
) << numPipeBits
;
2659 // Assemble the address from its components.
2663 // This is to remove warning with /analyze option
2664 UINT_32 pipeBits
= pipe
<< numGroupBits
;
2668 // Compute the bit position. The lower nibble is used when the x coordinate within the macro
2669 // tile is less than half of the macro tile width, and the upper nibble is used when the x
2670 // coordinate within the macro tile is greater than or equal to half the macro tile width.
2672 *pBitPosition
= ((x
% macroTileWidth
) < (macroTileWidth
/ factor
)) ? 0 : 4;
2677 ///////////////////////////////////////////////////////////////////////////////////////////////////
2678 // Surface Addressing Shared
2679 ///////////////////////////////////////////////////////////////////////////////////////////////////
2682 ***************************************************************************************************
2683 * AddrLib::ComputeSurfaceAddrFromCoordLinear
2686 * Compute address from coord for linear surface
2691 ***************************************************************************************************
2693 UINT_64
AddrLib::ComputeSurfaceAddrFromCoordLinear(
2694 UINT_32 x
, ///< [in] x coord
2695 UINT_32 y
, ///< [in] y coord
2696 UINT_32 slice
, ///< [in] slice/depth index
2697 UINT_32 sample
, ///< [in] sample index
2698 UINT_32 bpp
, ///< [in] bits per pixel
2699 UINT_32 pitch
, ///< [in] pitch
2700 UINT_32 height
, ///< [in] height
2701 UINT_32 numSlices
, ///< [in] number of slices
2702 UINT_32
* pBitPosition
///< [out] bit position inside a byte
2705 const UINT_64 sliceSize
= static_cast<UINT_64
>(pitch
) * height
;
2707 UINT_64 sliceOffset
= (slice
+ sample
* numSlices
)* sliceSize
;
2708 UINT_64 rowOffset
= static_cast<UINT_64
>(y
) * pitch
;
2709 UINT_64 pixOffset
= x
;
2711 UINT_64 addr
= (sliceOffset
+ rowOffset
+ pixOffset
) * bpp
;
2713 *pBitPosition
= static_cast<UINT_32
>(addr
% 8);
2720 ***************************************************************************************************
2721 * AddrLib::ComputeSurfaceCoordFromAddrLinear
2724 * Compute the coord from an address of a linear surface
2728 ***************************************************************************************************
2730 VOID
AddrLib::ComputeSurfaceCoordFromAddrLinear(
2731 UINT_64 addr
, ///< [in] address
2732 UINT_32 bitPosition
, ///< [in] bitPosition in a byte
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
* pX
, ///< [out] x coord
2738 UINT_32
* pY
, ///< [out] y coord
2739 UINT_32
* pSlice
, ///< [out] slice/depth index
2740 UINT_32
* pSample
///< [out] sample index
2743 const UINT_64 sliceSize
= static_cast<UINT_64
>(pitch
) * height
;
2744 const UINT_64 linearOffset
= (BYTES_TO_BITS(addr
) + bitPosition
) / bpp
;
2746 *pX
= static_cast<UINT_32
>((linearOffset
% sliceSize
) % pitch
);
2747 *pY
= static_cast<UINT_32
>((linearOffset
% sliceSize
) / pitch
% height
);
2748 *pSlice
= static_cast<UINT_32
>((linearOffset
/ sliceSize
) % numSlices
);
2749 *pSample
= static_cast<UINT_32
>((linearOffset
/ sliceSize
) / numSlices
);
2753 ***************************************************************************************************
2754 * AddrLib::ComputeSurfaceCoordFromAddrMicroTiled
2757 * Compute the coord from an address of a micro tiled surface
2761 ***************************************************************************************************
2763 VOID
AddrLib::ComputeSurfaceCoordFromAddrMicroTiled(
2764 UINT_64 addr
, ///< [in] address
2765 UINT_32 bitPosition
, ///< [in] bitPosition in a byte
2766 UINT_32 bpp
, ///< [in] bits per pixel
2767 UINT_32 pitch
, ///< [in] pitch
2768 UINT_32 height
, ///< [in] height
2769 UINT_32 numSamples
, ///< [in] number of samples
2770 AddrTileMode tileMode
, ///< [in] tile mode
2771 UINT_32 tileBase
, ///< [in] base offset within a tile
2772 UINT_32 compBits
, ///< [in] component bits actually needed(for planar surface)
2773 UINT_32
* pX
, ///< [out] x coord
2774 UINT_32
* pY
, ///< [out] y coord
2775 UINT_32
* pSlice
, ///< [out] slice/depth index
2776 UINT_32
* pSample
, ///< [out] sample index,
2777 AddrTileType microTileType
, ///< [in] micro tiling order
2778 BOOL_32 isDepthSampleOrder
///< [in] TRUE if in depth sample order
2782 UINT_32 microTileThickness
;
2783 UINT_32 microTileBits
;
2787 UINT_32 microTileCoordX
;
2788 UINT_32 microTileCoordY
;
2789 UINT_32 pixelOffset
;
2790 UINT_32 pixelCoordX
= 0;
2791 UINT_32 pixelCoordY
= 0;
2792 UINT_32 pixelCoordZ
= 0;
2793 UINT_32 pixelCoordS
= 0;
2796 // Convert byte address to bit address.
2798 bitAddr
= BYTES_TO_BITS(addr
) + bitPosition
;
2801 // Compute the micro tile size, in bits.
2805 case ADDR_TM_1D_TILED_THICK
:
2806 microTileThickness
= ThickTileThickness
;
2809 microTileThickness
= 1;
2813 microTileBits
= MicroTilePixels
* microTileThickness
* bpp
* numSamples
;
2816 // Compute number of bits per slice and number of bits per row of micro tiles.
2818 sliceBits
= static_cast<UINT_64
>(pitch
) * height
* microTileThickness
* bpp
* numSamples
;
2820 rowBits
= (pitch
/ MicroTileWidth
) * microTileBits
;
2823 // Extract the slice index.
2825 sliceIndex
= static_cast<UINT_32
>(bitAddr
/ sliceBits
);
2826 bitAddr
-= sliceIndex
* sliceBits
;
2829 // Extract the y coordinate of the micro tile.
2831 microTileCoordY
= static_cast<UINT_32
>(bitAddr
/ rowBits
) * MicroTileHeight
;
2832 bitAddr
-= (microTileCoordY
/ MicroTileHeight
) * rowBits
;
2835 // Extract the x coordinate of the micro tile.
2837 microTileCoordX
= static_cast<UINT_32
>(bitAddr
/ microTileBits
) * MicroTileWidth
;
2840 // Compute the pixel offset within the micro tile.
2842 pixelOffset
= static_cast<UINT_32
>(bitAddr
% microTileBits
);
2845 // Extract pixel coordinates from the offset.
2847 HwlComputePixelCoordFromOffset(pixelOffset
,
2858 isDepthSampleOrder
);
2861 // Assemble final coordinates.
2863 *pX
= microTileCoordX
+ pixelCoordX
;
2864 *pY
= microTileCoordY
+ pixelCoordY
;
2865 *pSlice
= (sliceIndex
* microTileThickness
) + pixelCoordZ
;
2866 *pSample
= pixelCoordS
;
2868 if (microTileThickness
> 1)
2875 ***************************************************************************************************
2876 * AddrLib::ComputePipeFromAddr
2879 * Compute the pipe number from an address
2884 ***************************************************************************************************
2886 UINT_32
AddrLib::ComputePipeFromAddr(
2887 UINT_64 addr
, ///< [in] address
2888 UINT_32 numPipes
///< [in] number of banks
2893 UINT_32 groupBytes
= m_pipeInterleaveBytes
; //just different terms
2896 // The LSBs of the address are arranged as follows:
2897 // bank | pipe | group
2899 // To get the pipe number, shift off the group bits and mask the pipe bits.
2903 // The LSBs of the address are arranged as follows:
2904 // bank | bankInterleave | pipe | pipeInterleave
2906 // To get the pipe number, shift off the pipe interleave bits and mask the pipe bits.
2909 pipe
= static_cast<UINT_32
>(addr
>> Log2(groupBytes
)) & (numPipes
- 1);
2915 ***************************************************************************************************
2916 * AddrLib::ComputePixelIndexWithinMicroTile
2919 * Compute the pixel index inside a micro tile of surface
2924 ***************************************************************************************************
2926 UINT_32
AddrLib::ComputePixelIndexWithinMicroTile(
2927 UINT_32 x
, ///< [in] x coord
2928 UINT_32 y
, ///< [in] y coord
2929 UINT_32 z
, ///< [in] slice/depth index
2930 UINT_32 bpp
, ///< [in] bits per pixel
2931 AddrTileMode tileMode
, ///< [in] tile mode
2932 AddrTileType microTileType
///< [in] pixel order in display/non-display mode
2935 UINT_32 pixelBit0
= 0;
2936 UINT_32 pixelBit1
= 0;
2937 UINT_32 pixelBit2
= 0;
2938 UINT_32 pixelBit3
= 0;
2939 UINT_32 pixelBit4
= 0;
2940 UINT_32 pixelBit5
= 0;
2941 UINT_32 pixelBit6
= 0;
2942 UINT_32 pixelBit7
= 0;
2943 UINT_32 pixelBit8
= 0;
2944 UINT_32 pixelNumber
;
2946 UINT_32 x0
= _BIT(x
, 0);
2947 UINT_32 x1
= _BIT(x
, 1);
2948 UINT_32 x2
= _BIT(x
, 2);
2949 UINT_32 y0
= _BIT(y
, 0);
2950 UINT_32 y1
= _BIT(y
, 1);
2951 UINT_32 y2
= _BIT(y
, 2);
2952 UINT_32 z0
= _BIT(z
, 0);
2953 UINT_32 z1
= _BIT(z
, 1);
2954 UINT_32 z2
= _BIT(z
, 2);
2956 UINT_32 thickness
= ComputeSurfaceThickness(tileMode
);
2958 // Compute the pixel number within the micro tile.
2960 if (microTileType
!= ADDR_THICK
)
2962 if (microTileType
== ADDR_DISPLAYABLE
)
3007 ADDR_ASSERT_ALWAYS();
3011 else if (microTileType
== ADDR_NON_DISPLAYABLE
|| microTileType
== ADDR_DEPTH_SAMPLE_ORDER
)
3020 else if (microTileType
== ADDR_ROTATED
)
3022 ADDR_ASSERT(thickness
== 1);
3059 ADDR_ASSERT_ALWAYS();
3072 ADDR_ASSERT(thickness
> 1);
3103 ADDR_ASSERT_ALWAYS();
3116 pixelNumber
= ((pixelBit0
) |
3130 ***************************************************************************************************
3131 * AddrLib::AdjustPitchAlignment
3134 * Adjusts pitch alignment for flipping surface
3139 ***************************************************************************************************
3141 VOID
AddrLib::AdjustPitchAlignment(
3142 ADDR_SURFACE_FLAGS flags
, ///< [in] Surface flags
3143 UINT_32
* pPitchAlign
///< [out] Pointer to pitch alignment
3146 // Display engine hardwires lower 5 bit of GRPH_PITCH to ZERO which means 32 pixel alignment
3147 // Maybe it will be fixed in future but let's make it general for now.
3148 if (flags
.display
|| flags
.overlay
)
3150 *pPitchAlign
= PowTwoAlign(*pPitchAlign
, 32);
3154 *pPitchAlign
= Max(m_minPitchAlignPixels
, *pPitchAlign
);
3160 ***************************************************************************************************
3161 * AddrLib::PadDimensions
3164 * Helper function to pad dimensions
3169 ***************************************************************************************************
3171 VOID
AddrLib::PadDimensions(
3172 AddrTileMode tileMode
, ///< [in] tile mode
3173 UINT_32 bpp
, ///< [in] bits per pixel
3174 ADDR_SURFACE_FLAGS flags
, ///< [in] surface flags
3175 UINT_32 numSamples
, ///< [in] number of samples
3176 ADDR_TILEINFO
* pTileInfo
, ///< [in/out] bank structure.
3177 UINT_32 padDims
, ///< [in] Dimensions to pad valid value 1,2,3
3178 UINT_32 mipLevel
, ///< [in] MipLevel
3179 UINT_32
* pPitch
, ///< [in/out] pitch in pixels
3180 UINT_32 pitchAlign
, ///< [in] pitch alignment
3181 UINT_32
* pHeight
, ///< [in/out] height in pixels
3182 UINT_32 heightAlign
, ///< [in] height alignment
3183 UINT_32
* pSlices
, ///< [in/out] number of slices
3184 UINT_32 sliceAlign
///< [in] number of slice alignment
3187 UINT_32 thickness
= ComputeSurfaceThickness(tileMode
);
3189 ADDR_ASSERT(padDims
<= 3);
3192 // Override padding for mip levels
3198 // for cubemap, we only pad when client call with 6 faces as an identity
3201 padDims
= 3; // we should pad cubemap sub levels when we treat it as 3d texture
3210 // Any possibilities that padDims is 0?
3216 if (IsPow2(pitchAlign
))
3218 *pPitch
= PowTwoAlign((*pPitch
), pitchAlign
);
3220 else // add this code to pass unit test, r600 linear mode is not align bpp to pow2 for linear
3222 *pPitch
+= pitchAlign
- 1;
3223 *pPitch
/= pitchAlign
;
3224 *pPitch
*= pitchAlign
;
3229 *pHeight
= PowTwoAlign((*pHeight
), heightAlign
);
3232 if (padDims
> 2 || thickness
> 1)
3234 // for cubemap single face, we do not pad slices.
3235 // if we pad it, the slice number should be set to 6 and current mip level > 1
3236 if (flags
.cube
&& (!m_configFlags
.noCubeMipSlicesPad
|| flags
.cubeAsArray
))
3238 *pSlices
= NextPow2(*pSlices
);
3241 // normal 3D texture or arrays or cubemap has a thick mode? (Just pass unit test)
3244 *pSlices
= PowTwoAlign((*pSlices
), sliceAlign
);
3249 HwlPadDimensions(tileMode
,
3266 ***************************************************************************************************
3267 * AddrLib::HwlPreHandleBaseLvl3xPitch
3270 * Pre-handler of 3x pitch (96 bit) adjustment
3274 ***************************************************************************************************
3276 UINT_32
AddrLib::HwlPreHandleBaseLvl3xPitch(
3277 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input
3278 UINT_32 expPitch
///< [in] pitch
3281 ADDR_ASSERT(pIn
->width
== expPitch
);
3283 // If pitch is pre-multiplied by 3, we retrieve original one here to get correct miplevel size
3285 if (AddrElemLib::IsExpand3x(pIn
->format
) &&
3286 pIn
->mipLevel
== 0 &&
3287 pIn
->tileMode
== ADDR_TM_LINEAR_ALIGNED
)
3290 expPitch
= NextPow2(expPitch
);
3297 ***************************************************************************************************
3298 * AddrLib::HwlPostHandleBaseLvl3xPitch
3301 * Post-handler of 3x pitch adjustment
3305 ***************************************************************************************************
3307 UINT_32
AddrLib::HwlPostHandleBaseLvl3xPitch(
3308 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input
3309 UINT_32 expPitch
///< [in] pitch
3313 // 96 bits surface of sub levels require element pitch of 32 bits instead
3314 // So we just return pitch in 32 bit pixels without timing 3
3316 if (AddrElemLib::IsExpand3x(pIn
->format
) &&
3317 pIn
->mipLevel
== 0 &&
3318 pIn
->tileMode
== ADDR_TM_LINEAR_ALIGNED
)
3328 ***************************************************************************************************
3329 * AddrLib::IsMacroTiled
3332 * Check if the tile mode is macro tiled
3335 * TRUE if it is macro tiled (2D/2B/3D/3B)
3336 ***************************************************************************************************
3338 BOOL_32
AddrLib::IsMacroTiled(
3339 AddrTileMode tileMode
) ///< [in] tile mode
3341 return m_modeFlags
[tileMode
].isMacro
;
3345 ***************************************************************************************************
3346 * AddrLib::IsMacro3dTiled
3349 * Check if the tile mode is 3D macro tiled
3352 * TRUE if it is 3D macro tiled
3353 ***************************************************************************************************
3355 BOOL_32
AddrLib::IsMacro3dTiled(
3356 AddrTileMode tileMode
) ///< [in] tile mode
3358 return m_modeFlags
[tileMode
].isMacro3d
;
3362 ***************************************************************************************************
3363 * AddrLib::IsMicroTiled
3366 * Check if the tile mode is micro tiled
3369 * TRUE if micro tiled
3370 ***************************************************************************************************
3372 BOOL_32
AddrLib::IsMicroTiled(
3373 AddrTileMode tileMode
) ///< [in] tile mode
3375 return m_modeFlags
[tileMode
].isMicro
;
3379 ***************************************************************************************************
3383 * Check if the tile mode is linear
3387 ***************************************************************************************************
3389 BOOL_32
AddrLib::IsLinear(
3390 AddrTileMode tileMode
) ///< [in] tile mode
3392 return m_modeFlags
[tileMode
].isLinear
;
3396 ***************************************************************************************************
3397 * AddrLib::IsPrtNoRotationTileMode
3400 * Return TRUE if it is prt tile without rotation
3402 * This function just used by CI
3403 ***************************************************************************************************
3405 BOOL_32
AddrLib::IsPrtNoRotationTileMode(
3406 AddrTileMode tileMode
)
3408 return m_modeFlags
[tileMode
].isPrtNoRotation
;
3412 ***************************************************************************************************
3413 * AddrLib::IsPrtTileMode
3416 * Return TRUE if it is prt tile
3418 * This function just used by CI
3419 ***************************************************************************************************
3421 BOOL_32
AddrLib::IsPrtTileMode(
3422 AddrTileMode tileMode
)
3424 return m_modeFlags
[tileMode
].isPrt
;
3428 ***************************************************************************************************
3429 * AddrLib::Bits2Number
3432 * Cat a array of binary bit to a number
3435 * The number combined with the array of bits
3436 ***************************************************************************************************
3438 UINT_32
AddrLib::Bits2Number(
3439 UINT_32 bitNum
, ///< [in] how many bits
3440 ...) ///< [in] varaible bits value starting from MSB
3446 va_start(bits_ptr
, bitNum
);
3448 for(i
= 0; i
< bitNum
; i
++)
3450 number
|= va_arg(bits_ptr
, UINT_32
);
3462 ***************************************************************************************************
3463 * AddrLib::ComputeMipLevel
3466 * Compute mipmap level width/height/slices
3469 ***************************************************************************************************
3471 VOID
AddrLib::ComputeMipLevel(
3472 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
///< [in/out] Input structure
3475 if (AddrElemLib::IsBlockCompressed(pIn
->format
))
3477 if (pIn
->mipLevel
== 0)
3479 // DXTn's level 0 must be multiple of 4
3480 // But there are exceptions:
3481 // 1. Internal surface creation in hostblt/vsblt/etc...
3482 // 2. Runtime doesn't reject ATI1/ATI2 whose width/height are not multiple of 4
3483 pIn
->width
= PowTwoAlign(pIn
->width
, 4);
3484 pIn
->height
= PowTwoAlign(pIn
->height
, 4);
3488 HwlComputeMipLevel(pIn
);
3492 ***************************************************************************************************
3493 * AddrLib::DegradeBaseLevel
3496 * Check if base level's tile mode can be degraded
3498 * TRUE if degraded, also returns degraded tile mode (unchanged if not degraded)
3499 ***************************************************************************************************
3501 BOOL_32
AddrLib::DegradeBaseLevel(
3502 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] Input structure for surface info
3503 AddrTileMode
* pTileMode
///< [out] Degraded tile mode
3506 BOOL_32 degraded
= FALSE
;
3507 AddrTileMode tileMode
= pIn
->tileMode
;
3508 UINT_32 thickness
= ComputeSurfaceThickness(tileMode
);
3510 if (m_configFlags
.degradeBaseLevel
) // This is a global setting
3512 if (pIn
->flags
.degrade4Space
&& // Degradation per surface
3513 pIn
->mipLevel
== 0 &&
3514 pIn
->numSamples
== 1 &&
3515 IsMacroTiled(tileMode
))
3517 if (HwlDegradeBaseLevel(pIn
))
3519 *pTileMode
= thickness
== 1 ? ADDR_TM_1D_TILED_THIN1
: ADDR_TM_1D_TILED_THICK
;
3522 else if (thickness
> 1)
3524 // As in the following HwlComputeSurfaceInfo, thick modes may be degraded to
3525 // thinner modes, we should re-evaluate whether the corresponding thinner modes
3526 // need to be degraded. If so, we choose 1D thick mode instead.
3527 tileMode
= DegradeLargeThickTile(pIn
->tileMode
, pIn
->bpp
);
3528 if (tileMode
!= pIn
->tileMode
)
3530 ADDR_COMPUTE_SURFACE_INFO_INPUT input
= *pIn
;
3531 input
.tileMode
= tileMode
;
3532 if (HwlDegradeBaseLevel(&input
))
3534 *pTileMode
= ADDR_TM_1D_TILED_THICK
;
3546 ***************************************************************************************************
3547 * AddrLib::DegradeLargeThickTile
3550 * Check if the thickness needs to be reduced if a tile is too large
3552 * The degraded tile mode (unchanged if not degraded)
3553 ***************************************************************************************************
3555 AddrTileMode
AddrLib::DegradeLargeThickTile(
3556 AddrTileMode tileMode
,
3559 // Override tilemode
3560 // When tile_width (8) * tile_height (8) * thickness * element_bytes is > row_size,
3561 // it is better to just use THIN mode in this case
3562 UINT_32 thickness
= ComputeSurfaceThickness(tileMode
);
3564 if (thickness
> 1 && m_configFlags
.allowLargeThickTile
== 0)
3566 UINT_32 tileSize
= MicroTilePixels
* thickness
* (bpp
>> 3);
3568 if (tileSize
> m_rowSize
)
3572 case ADDR_TM_2D_TILED_XTHICK
:
3573 if ((tileSize
>> 1) <= m_rowSize
)
3575 tileMode
= ADDR_TM_2D_TILED_THICK
;
3578 // else fall through
3579 case ADDR_TM_2D_TILED_THICK
:
3580 tileMode
= ADDR_TM_2D_TILED_THIN1
;
3583 case ADDR_TM_3D_TILED_XTHICK
:
3584 if ((tileSize
>> 1) <= m_rowSize
)
3586 tileMode
= ADDR_TM_3D_TILED_THICK
;
3589 // else fall through
3590 case ADDR_TM_3D_TILED_THICK
:
3591 tileMode
= ADDR_TM_3D_TILED_THIN1
;
3594 case ADDR_TM_PRT_TILED_THICK
:
3595 tileMode
= ADDR_TM_PRT_TILED_THIN1
;
3598 case ADDR_TM_PRT_2D_TILED_THICK
:
3599 tileMode
= ADDR_TM_PRT_2D_TILED_THIN1
;
3602 case ADDR_TM_PRT_3D_TILED_THICK
:
3603 tileMode
= ADDR_TM_PRT_3D_TILED_THIN1
;
3616 ***************************************************************************************************
3617 * AddrLib::PostComputeMipLevel
3619 * Compute MipLevel info (including level 0) after surface adjustment
3622 ***************************************************************************************************
3624 ADDR_E_RETURNCODE
AddrLib::PostComputeMipLevel(
3625 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in/out] Input structure
3626 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] Output structure
3629 // Mipmap including level 0 must be pow2 padded since either SI hw expects so or it is
3630 // required by CFX for Hw Compatibility between NI and SI. Otherwise it is only needed for
3631 // mipLevel > 0. Any h/w has different requirement should implement its own virtual function
3633 if (pIn
->flags
.pow2Pad
)
3635 pIn
->width
= NextPow2(pIn
->width
);
3636 pIn
->height
= NextPow2(pIn
->height
);
3637 pIn
->numSlices
= NextPow2(pIn
->numSlices
);
3639 else if (pIn
->mipLevel
> 0)
3641 pIn
->width
= NextPow2(pIn
->width
);
3642 pIn
->height
= NextPow2(pIn
->height
);
3644 if (!pIn
->flags
.cube
)
3646 pIn
->numSlices
= NextPow2(pIn
->numSlices
);
3649 // for cubemap, we keep its value at first
3656 ***************************************************************************************************
3657 * AddrLib::HwlSetupTileCfg
3660 * Map tile index to tile setting.
3663 ***************************************************************************************************
3665 ADDR_E_RETURNCODE
AddrLib::HwlSetupTileCfg(
3666 INT_32 index
, ///< [in] Tile index
3667 INT_32 macroModeIndex
, ///< [in] Index in macro tile mode table(CI)
3668 ADDR_TILEINFO
* pInfo
, ///< [out] Tile Info
3669 AddrTileMode
* pMode
, ///< [out] Tile mode
3670 AddrTileType
* pType
///< [out] Tile type
3673 return ADDR_NOTSUPPORTED
;
3677 ***************************************************************************************************
3678 * AddrLib::HwlGetPipes
3684 ***************************************************************************************************
3686 UINT_32
AddrLib::HwlGetPipes(
3687 const ADDR_TILEINFO
* pTileInfo
///< [in] Tile info
3690 //pTileInfo can be NULL when asic is 6xx and 8xx.
3695 ***************************************************************************************************
3696 * AddrLib::ComputeQbStereoInfo
3699 * Get quad buffer stereo information
3702 ***************************************************************************************************
3704 BOOL_32
AddrLib::ComputeQbStereoInfo(
3705 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [in/out] updated pOut+pStereoInfo
3708 BOOL_32 success
= FALSE
;
3710 if (pOut
->pStereoInfo
)
3712 ADDR_ASSERT(pOut
->bpp
>= 8);
3713 ADDR_ASSERT((pOut
->surfSize
% pOut
->baseAlign
) == 0);
3715 // Save original height
3716 pOut
->pStereoInfo
->eyeHeight
= pOut
->height
;
3719 pOut
->pStereoInfo
->rightOffset
= static_cast<UINT_32
>(pOut
->surfSize
);
3721 pOut
->pStereoInfo
->rightSwizzle
= HwlComputeQbStereoRightSwizzle(pOut
);
3724 pOut
->pixelHeight
<<= 1;
3727 pOut
->surfSize
<<= 1;
3729 // Right start address meets the base align since it is guaranteed by AddrLib
3731 // 1D surface on SI may break this rule, but we can force it to meet by checking .qbStereo.
3738 ///////////////////////////////////////////////////////////////////////////////////////////////////
3740 ///////////////////////////////////////////////////////////////////////////////////////////////////
3744 ***************************************************************************************************
3745 * AddrLib::Flt32ToColorPixel
3748 * Convert a FLT_32 value to a depth/stencil pixel value
3751 ***************************************************************************************************
3753 ADDR_E_RETURNCODE
AddrLib::Flt32ToDepthPixel(
3754 const ELEM_FLT32TODEPTHPIXEL_INPUT
* pIn
,
3755 ELEM_FLT32TODEPTHPIXEL_OUTPUT
* pOut
) const
3757 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3759 if (GetFillSizeFieldsFlags() == TRUE
)
3761 if ((pIn
->size
!= sizeof(ELEM_FLT32TODEPTHPIXEL_INPUT
)) ||
3762 (pOut
->size
!= sizeof(ELEM_FLT32TODEPTHPIXEL_OUTPUT
)))
3764 returnCode
= ADDR_PARAMSIZEMISMATCH
;
3768 if (returnCode
== ADDR_OK
)
3770 GetElemLib()->Flt32ToDepthPixel(pIn
->format
,
3773 UINT_32 depthBase
= 0;
3774 UINT_32 stencilBase
= 0;
3775 UINT_32 depthBits
= 0;
3776 UINT_32 stencilBits
= 0;
3778 switch (pIn
->format
)
3783 case ADDR_DEPTH_X8_24
:
3784 case ADDR_DEPTH_8_24
:
3785 case ADDR_DEPTH_X8_24_FLOAT
:
3786 case ADDR_DEPTH_8_24_FLOAT
:
3791 case ADDR_DEPTH_32_FLOAT
:
3794 case ADDR_DEPTH_X24_8_32_FLOAT
:
3803 // Overwrite base since R800 has no "tileBase"
3804 if (GetElemLib()->IsDepthStencilTilePlanar() == FALSE
)
3813 pOut
->stencilBase
= stencilBase
;
3814 pOut
->depthBase
= depthBase
;
3815 pOut
->depthBits
= depthBits
;
3816 pOut
->stencilBits
= stencilBits
;
3823 ***************************************************************************************************
3824 * AddrLib::Flt32ToColorPixel
3827 * Convert a FLT_32 value to a red/green/blue/alpha pixel value
3830 ***************************************************************************************************
3832 ADDR_E_RETURNCODE
AddrLib::Flt32ToColorPixel(
3833 const ELEM_FLT32TOCOLORPIXEL_INPUT
* pIn
,
3834 ELEM_FLT32TOCOLORPIXEL_OUTPUT
* pOut
) const
3836 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3838 if (GetFillSizeFieldsFlags() == TRUE
)
3840 if ((pIn
->size
!= sizeof(ELEM_FLT32TOCOLORPIXEL_INPUT
)) ||
3841 (pOut
->size
!= sizeof(ELEM_FLT32TOCOLORPIXEL_OUTPUT
)))
3843 returnCode
= ADDR_PARAMSIZEMISMATCH
;
3847 if (returnCode
== ADDR_OK
)
3849 GetElemLib()->Flt32ToColorPixel(pIn
->format
,
3861 ***************************************************************************************************
3862 * AddrLib::GetExportNorm
3865 * Check one format can be EXPORT_NUM
3867 * TRUE if EXPORT_NORM can be used
3868 ***************************************************************************************************
3870 BOOL_32
AddrLib::GetExportNorm(
3871 const ELEM_GETEXPORTNORM_INPUT
* pIn
) const
3873 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3875 BOOL_32 enabled
= FALSE
;
3877 if (GetFillSizeFieldsFlags() == TRUE
)
3879 if (pIn
->size
!= sizeof(ELEM_GETEXPORTNORM_INPUT
))
3881 returnCode
= ADDR_PARAMSIZEMISMATCH
;
3885 if (returnCode
== ADDR_OK
)
3887 enabled
= GetElemLib()->PixGetExportNorm(pIn
->format
,
3896 ***************************************************************************************************
3897 * AddrLib::ComputePrtInfo
3900 * Compute prt surface related info
3904 ***************************************************************************************************
3906 ADDR_E_RETURNCODE
AddrLib::ComputePrtInfo(
3907 const ADDR_PRT_INFO_INPUT
* pIn
,
3908 ADDR_PRT_INFO_OUTPUT
* pOut
) const
3910 ADDR_ASSERT(pOut
!= NULL
);
3912 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3914 UINT_32 expandX
= 1;
3915 UINT_32 expandY
= 1;
3916 AddrElemMode elemMode
;
3918 UINT_32 bpp
= GetElemLib()->GetBitsPerPixel(pIn
->format
,
3923 if (bpp
<8 || bpp
== 24 || bpp
== 48 || bpp
== 96 )
3925 returnCode
= ADDR_INVALIDPARAMS
;
3928 UINT_32 numFrags
= pIn
->numFrags
;
3929 ADDR_ASSERT(numFrags
<= 8);
3931 UINT_32 tileWidth
= 0;
3932 UINT_32 tileHeight
= 0;
3933 if (returnCode
== ADDR_OK
)
3935 // 3D texture without depth or 2d texture
3936 if (pIn
->baseMipDepth
> 1 || pIn
->baseMipHeight
> 1)
3955 // assume it is BC1/4
3959 if (elemMode
== ADDR_UNCOMPRESSED
)
3965 else if (bpp
== 128)
3967 // assume it is BC2/3/5/6H/7
3971 if (elemMode
== ADDR_UNCOMPRESSED
)
3980 tileWidth
= tileWidth
/ 2;
3982 else if (numFrags
== 4)
3984 tileWidth
= tileWidth
/ 2;
3985 tileHeight
= tileHeight
/ 2;
3987 else if (numFrags
== 8)
3989 tileWidth
= tileWidth
/ 4;
3990 tileHeight
= tileHeight
/ 2;
4012 else if (bpp
== 128)
4019 pOut
->prtTileWidth
= tileWidth
;
4020 pOut
->prtTileHeight
= tileHeight
;