2 * Copyright © 2007-2018 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 AddrLib2 base class.
31 ************************************************************************************************************************
34 #include "addrinterface.h"
36 #include "addrcommon.h"
43 ////////////////////////////////////////////////////////////////////////////////////////////////////
44 // Static Const Member
45 ////////////////////////////////////////////////////////////////////////////////////////////////////
47 const Dim2d
Lib::Block256_2d
[] = {{16, 16}, {16, 8}, {8, 8}, {8, 4}, {4, 4}};
49 const Dim3d
Lib::Block1K_3d
[] = {{16, 8, 8}, {8, 8, 8}, {8, 8, 4}, {8, 4, 4}, {4, 4, 4}};
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
52 // Constructor/Destructor
53 ////////////////////////////////////////////////////////////////////////////////////////////////////
56 ************************************************************************************************************************
60 * Constructor for the Addr::V2::Lib class
62 ************************************************************************************************************************
71 ************************************************************************************************************************
75 * Constructor for the AddrLib2 class with hClient as parameter
77 ************************************************************************************************************************
79 Lib::Lib(const Client
* pClient
)
86 ************************************************************************************************************************
90 * Destructor for the AddrLib2 class
92 ************************************************************************************************************************
99 ************************************************************************************************************************
103 * Get Addr::V2::Lib pointer
106 * An Addr::V2::Lib class pointer
107 ************************************************************************************************************************
110 ADDR_HANDLE hLib
) ///< [in] handle of ADDR_HANDLE
112 Addr::Lib
* pAddrLib
= Addr::Lib::GetLib(hLib
);
113 if ((pAddrLib
!= NULL
) &&
114 (pAddrLib
->GetChipFamily() <= ADDR_CHIP_FAMILY_VI
))
116 // only valid and GFX9+ ASIC can use AddrLib2 function.
117 ADDR_ASSERT_ALWAYS();
120 return static_cast<Lib
*>(hLib
);
123 ////////////////////////////////////////////////////////////////////////////////////////////////////
125 ////////////////////////////////////////////////////////////////////////////////////////////////////
128 ************************************************************************************************************************
129 * Lib::ComputeSurfaceInfo
132 * Interface function stub of AddrComputeSurfaceInfo.
136 ************************************************************************************************************************
138 ADDR_E_RETURNCODE
Lib::ComputeSurfaceInfo(
139 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
140 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
143 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
145 if (GetFillSizeFieldsFlags() == TRUE
)
147 if ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_INFO_INPUT
)) ||
148 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
)))
150 returnCode
= ADDR_PARAMSIZEMISMATCH
;
154 // Adjust coming parameters.
155 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= *pIn
;
156 localIn
.width
= Max(pIn
->width
, 1u);
157 localIn
.height
= Max(pIn
->height
, 1u);
158 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
159 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
160 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
161 localIn
.numFrags
= (localIn
.numFrags
== 0) ? localIn
.numSamples
: pIn
->numFrags
;
165 ElemMode elemMode
= ADDR_UNCOMPRESSED
;
167 if (returnCode
== ADDR_OK
)
169 // Set format to INVALID will skip this conversion
170 if (localIn
.format
!= ADDR_FMT_INVALID
)
172 // Get compression/expansion factors and element mode which indicates compression/expansion
173 localIn
.bpp
= GetElemLib()->GetBitsPerPixel(localIn
.format
,
178 // Special flag for 96 bit surface. 96 (or 48 if we support) bit surface's width is
179 // pre-multiplied by 3 and bpp is divided by 3. So pitch alignment for linear-
180 // aligned does not meet 64-pixel in real. We keep special handling in hwl since hw
181 // restrictions are different.
182 // Also Mip 1+ needs an element pitch of 32 bits so we do not need this workaround
183 // but we use this flag to skip RestoreSurfaceInfo below
185 if ((elemMode
== ADDR_EXPANDED
) && (expandX
> 1))
187 ADDR_ASSERT(IsLinear(localIn
.swizzleMode
));
190 UINT_32 basePitch
= 0;
191 GetElemLib()->AdjustSurfaceInfo(elemMode
,
199 // Overwrite these parameters if we have a valid format
202 if (localIn
.bpp
!= 0)
204 localIn
.width
= Max(localIn
.width
, 1u);
205 localIn
.height
= Max(localIn
.height
, 1u);
207 else // Rule out some invalid parameters
209 ADDR_ASSERT_ALWAYS();
211 returnCode
= ADDR_INVALIDPARAMS
;
215 if (returnCode
== ADDR_OK
)
217 returnCode
= ComputeSurfaceInfoSanityCheck(&localIn
);
220 if (returnCode
== ADDR_OK
)
222 VerifyMipLevelInfo(pIn
);
224 if (IsLinear(pIn
->swizzleMode
))
227 returnCode
= ComputeSurfaceInfoLinear(&localIn
, pOut
);
232 returnCode
= ComputeSurfaceInfoTiled(&localIn
, pOut
);
235 if (returnCode
== ADDR_OK
)
237 pOut
->bpp
= localIn
.bpp
;
238 pOut
->pixelPitch
= pOut
->pitch
;
239 pOut
->pixelHeight
= pOut
->height
;
240 pOut
->pixelMipChainPitch
= pOut
->mipChainPitch
;
241 pOut
->pixelMipChainHeight
= pOut
->mipChainHeight
;
242 pOut
->pixelBits
= localIn
.bpp
;
244 if (localIn
.format
!= ADDR_FMT_INVALID
)
246 UINT_32 pixelBits
= pOut
->pixelBits
;
248 GetElemLib()->RestoreSurfaceInfo(elemMode
,
255 GetElemLib()->RestoreSurfaceInfo(elemMode
,
259 &pOut
->pixelMipChainPitch
,
260 &pOut
->pixelMipChainHeight
);
262 if ((localIn
.numMipLevels
> 1) && (pOut
->pMipInfo
!= NULL
))
264 for (UINT_32 i
= 0; i
< localIn
.numMipLevels
; i
++)
266 pOut
->pMipInfo
[i
].pixelPitch
= pOut
->pMipInfo
[i
].pitch
;
267 pOut
->pMipInfo
[i
].pixelHeight
= pOut
->pMipInfo
[i
].height
;
269 GetElemLib()->RestoreSurfaceInfo(elemMode
,
273 &pOut
->pMipInfo
[i
].pixelPitch
,
274 &pOut
->pMipInfo
[i
].pixelHeight
);
279 if (localIn
.flags
.needEquation
&& (Log2(localIn
.numFrags
) == 0))
281 pOut
->equationIndex
= GetEquationIndex(&localIn
, pOut
);
284 if (localIn
.flags
.qbStereo
)
286 if (pOut
->pStereoInfo
!= NULL
)
288 ComputeQbStereoInfo(pOut
);
294 ADDR_ASSERT(pOut
->surfSize
!= 0);
296 ValidBaseAlignments(pOut
->baseAlign
);
302 ************************************************************************************************************************
303 * Lib::ComputeSurfaceInfo
306 * Interface function stub of AddrComputeSurfaceInfo.
310 ************************************************************************************************************************
312 ADDR_E_RETURNCODE
Lib::ComputeSurfaceAddrFromCoord(
313 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
314 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
317 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
319 if (GetFillSizeFieldsFlags() == TRUE
)
321 if ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
)) ||
322 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
)))
324 returnCode
= ADDR_PARAMSIZEMISMATCH
;
328 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT localIn
= *pIn
;
329 localIn
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
330 localIn
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
331 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
332 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
333 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
334 localIn
.numFrags
= Max(pIn
->numFrags
, 1u);
336 if ((localIn
.bpp
< 8) ||
337 (localIn
.bpp
> 128) ||
338 ((localIn
.bpp
% 8) != 0) ||
339 (localIn
.sample
>= localIn
.numSamples
) ||
340 (localIn
.slice
>= localIn
.numSlices
) ||
341 (localIn
.mipId
>= localIn
.numMipLevels
) ||
342 (IsTex3d(localIn
.resourceType
) &&
343 (Valid3DMipSliceIdConstraint(localIn
.numSlices
, localIn
.mipId
, localIn
.slice
) == FALSE
)))
345 returnCode
= ADDR_INVALIDPARAMS
;
348 if (returnCode
== ADDR_OK
)
350 if (IsLinear(localIn
.swizzleMode
))
352 returnCode
= ComputeSurfaceAddrFromCoordLinear(&localIn
, pOut
);
356 returnCode
= ComputeSurfaceAddrFromCoordTiled(&localIn
, pOut
);
359 if (returnCode
== ADDR_OK
)
361 pOut
->prtBlockIndex
= static_cast<UINT_32
>(pOut
->addr
/ (64 * 1024));
369 ************************************************************************************************************************
370 * Lib::ComputeSurfaceCoordFromAddr
373 * Interface function stub of ComputeSurfaceCoordFromAddr.
377 ************************************************************************************************************************
379 ADDR_E_RETURNCODE
Lib::ComputeSurfaceCoordFromAddr(
380 const ADDR2_COMPUTE_SURFACE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
381 ADDR2_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
384 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
386 if (GetFillSizeFieldsFlags() == TRUE
)
388 if ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_COORDFROMADDR_INPUT
)) ||
389 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
)))
391 returnCode
= ADDR_PARAMSIZEMISMATCH
;
395 if ((pIn
->bpp
< 8) ||
397 ((pIn
->bpp
% 8) != 0) ||
398 (pIn
->bitPosition
>= 8))
400 returnCode
= ADDR_INVALIDPARAMS
;
403 if (returnCode
== ADDR_OK
)
405 if (IsLinear(pIn
->swizzleMode
))
407 returnCode
= ComputeSurfaceCoordFromAddrLinear(pIn
, pOut
);
411 returnCode
= ComputeSurfaceCoordFromAddrTiled(pIn
, pOut
);
418 ////////////////////////////////////////////////////////////////////////////////////////////////////
420 ////////////////////////////////////////////////////////////////////////////////////////////////////
423 ************************************************************************************************************************
424 * Lib::ComputeHtileInfo
427 * Interface function stub of AddrComputeHtilenfo
431 ************************************************************************************************************************
433 ADDR_E_RETURNCODE
Lib::ComputeHtileInfo(
434 const ADDR2_COMPUTE_HTILE_INFO_INPUT
* pIn
, ///< [in] input structure
435 ADDR2_COMPUTE_HTILE_INFO_OUTPUT
* pOut
///< [out] output structure
438 ADDR_E_RETURNCODE returnCode
;
440 if ((GetFillSizeFieldsFlags() == TRUE
) &&
441 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_HTILE_INFO_INPUT
)) ||
442 (pOut
->size
!= sizeof(ADDR2_COMPUTE_HTILE_INFO_OUTPUT
))))
444 returnCode
= ADDR_INVALIDPARAMS
;
448 returnCode
= HwlComputeHtileInfo(pIn
, pOut
);
450 ValidMetaBaseAlignments(pOut
->baseAlign
);
457 ************************************************************************************************************************
458 * Lib::ComputeHtileAddrFromCoord
461 * Interface function stub of AddrComputeHtileAddrFromCoord
465 ************************************************************************************************************************
467 ADDR_E_RETURNCODE
Lib::ComputeHtileAddrFromCoord(
468 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
469 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
471 ADDR_E_RETURNCODE returnCode
;
473 if ((GetFillSizeFieldsFlags() == TRUE
) &&
474 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
)) ||
475 (pOut
->size
!= sizeof(ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
))))
477 returnCode
= ADDR_INVALIDPARAMS
;
481 returnCode
= HwlComputeHtileAddrFromCoord(pIn
, pOut
);
488 ************************************************************************************************************************
489 * Lib::ComputeHtileCoordFromAddr
492 * Interface function stub of AddrComputeHtileCoordFromAddr
496 ************************************************************************************************************************
498 ADDR_E_RETURNCODE
Lib::ComputeHtileCoordFromAddr(
499 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
500 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
) ///< [out] output structure
502 ADDR_E_RETURNCODE returnCode
;
504 if ((GetFillSizeFieldsFlags() == TRUE
) &&
505 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
)) ||
506 (pOut
->size
!= sizeof(ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
))))
508 returnCode
= ADDR_INVALIDPARAMS
;
512 returnCode
= HwlComputeHtileCoordFromAddr(pIn
, pOut
);
519 ************************************************************************************************************************
520 * Lib::ComputeCmaskInfo
523 * Interface function stub of AddrComputeCmaskInfo
527 ************************************************************************************************************************
529 ADDR_E_RETURNCODE
Lib::ComputeCmaskInfo(
530 const ADDR2_COMPUTE_CMASK_INFO_INPUT
* pIn
, ///< [in] input structure
531 ADDR2_COMPUTE_CMASK_INFO_OUTPUT
* pOut
///< [out] output structure
534 ADDR_E_RETURNCODE returnCode
;
536 if ((GetFillSizeFieldsFlags() == TRUE
) &&
537 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_CMASK_INFO_INPUT
)) ||
538 (pOut
->size
!= sizeof(ADDR2_COMPUTE_CMASK_INFO_OUTPUT
))))
540 returnCode
= ADDR_INVALIDPARAMS
;
542 else if (pIn
->cMaskFlags
.linear
)
544 returnCode
= ADDR_INVALIDPARAMS
;
548 returnCode
= HwlComputeCmaskInfo(pIn
, pOut
);
550 ValidMetaBaseAlignments(pOut
->baseAlign
);
557 ************************************************************************************************************************
558 * Lib::ComputeCmaskAddrFromCoord
561 * Interface function stub of AddrComputeCmaskAddrFromCoord
565 ************************************************************************************************************************
567 ADDR_E_RETURNCODE
Lib::ComputeCmaskAddrFromCoord(
568 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
569 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
571 ADDR_E_RETURNCODE returnCode
;
573 if ((GetFillSizeFieldsFlags() == TRUE
) &&
574 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
)) ||
575 (pOut
->size
!= sizeof(ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
))))
577 returnCode
= ADDR_INVALIDPARAMS
;
581 returnCode
= HwlComputeCmaskAddrFromCoord(pIn
, pOut
);
588 ************************************************************************************************************************
589 * Lib::ComputeCmaskCoordFromAddr
592 * Interface function stub of AddrComputeCmaskCoordFromAddr
596 ************************************************************************************************************************
598 ADDR_E_RETURNCODE
Lib::ComputeCmaskCoordFromAddr(
599 const ADDR2_COMPUTE_CMASK_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
600 ADDR2_COMPUTE_CMASK_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
603 ADDR_E_RETURNCODE returnCode
= ADDR_NOTIMPLEMENTED
;
605 ADDR_NOT_IMPLEMENTED();
611 ************************************************************************************************************************
612 * Lib::ComputeFmaskInfo
615 * Interface function stub of ComputeFmaskInfo.
619 ************************************************************************************************************************
621 ADDR_E_RETURNCODE
Lib::ComputeFmaskInfo(
622 const ADDR2_COMPUTE_FMASK_INFO_INPUT
* pIn
, ///< [in] input structure
623 ADDR2_COMPUTE_FMASK_INFO_OUTPUT
* pOut
///< [out] output structure
626 ADDR_E_RETURNCODE returnCode
;
628 BOOL_32 valid
= (IsZOrderSwizzle(pIn
->swizzleMode
) == TRUE
) &&
629 ((pIn
->numSamples
> 0) || (pIn
->numFrags
> 0));
631 if (GetFillSizeFieldsFlags())
633 if ((pIn
->size
!= sizeof(ADDR2_COMPUTE_FMASK_INFO_INPUT
)) ||
634 (pOut
->size
!= sizeof(ADDR2_COMPUTE_FMASK_INFO_OUTPUT
)))
642 returnCode
= ADDR_INVALIDPARAMS
;
646 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
647 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
649 localIn
.size
= sizeof(ADDR2_COMPUTE_SURFACE_INFO_INPUT
);
650 localOut
.size
= sizeof(ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
);
652 localIn
.swizzleMode
= pIn
->swizzleMode
;
653 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
654 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
655 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
656 localIn
.bpp
= GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
);
657 localIn
.flags
.fmask
= 1;
658 localIn
.numFrags
= 1;
659 localIn
.numSamples
= 1;
660 localIn
.resourceType
= ADDR_RSRC_TEX_2D
;
662 if (localIn
.bpp
== 8)
664 localIn
.format
= ADDR_FMT_8
;
666 else if (localIn
.bpp
== 16)
668 localIn
.format
= ADDR_FMT_16
;
670 else if (localIn
.bpp
== 32)
672 localIn
.format
= ADDR_FMT_32
;
676 localIn
.format
= ADDR_FMT_32_32
;
679 returnCode
= ComputeSurfaceInfo(&localIn
, &localOut
);
681 if (returnCode
== ADDR_OK
)
683 pOut
->pitch
= localOut
.pitch
;
684 pOut
->height
= localOut
.height
;
685 pOut
->baseAlign
= localOut
.baseAlign
;
686 pOut
->numSlices
= localOut
.numSlices
;
687 pOut
->fmaskBytes
= static_cast<UINT_32
>(localOut
.surfSize
);
688 pOut
->sliceSize
= static_cast<UINT_32
>(localOut
.sliceSize
);
689 pOut
->bpp
= localIn
.bpp
;
690 pOut
->numSamples
= 1;
694 ValidBaseAlignments(pOut
->baseAlign
);
700 ************************************************************************************************************************
701 * Lib::ComputeFmaskAddrFromCoord
704 * Interface function stub of ComputeFmaskAddrFromCoord.
708 ************************************************************************************************************************
710 ADDR_E_RETURNCODE
Lib::ComputeFmaskAddrFromCoord(
711 const ADDR2_COMPUTE_FMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
712 ADDR2_COMPUTE_FMASK_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
715 ADDR_E_RETURNCODE returnCode
= ADDR_NOTIMPLEMENTED
;
717 ADDR_NOT_IMPLEMENTED();
723 ************************************************************************************************************************
724 * Lib::ComputeFmaskCoordFromAddr
727 * Interface function stub of ComputeFmaskAddrFromCoord.
731 ************************************************************************************************************************
733 ADDR_E_RETURNCODE
Lib::ComputeFmaskCoordFromAddr(
734 const ADDR2_COMPUTE_FMASK_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
735 ADDR2_COMPUTE_FMASK_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
738 ADDR_E_RETURNCODE returnCode
= ADDR_NOTIMPLEMENTED
;
740 ADDR_NOT_IMPLEMENTED();
746 ************************************************************************************************************************
747 * Lib::ComputeDccInfo
750 * Interface function to compute DCC key info
753 * return code of HwlComputeDccInfo
754 ************************************************************************************************************************
756 ADDR_E_RETURNCODE
Lib::ComputeDccInfo(
757 const ADDR2_COMPUTE_DCCINFO_INPUT
* pIn
, ///< [in] input structure
758 ADDR2_COMPUTE_DCCINFO_OUTPUT
* pOut
///< [out] output structure
761 ADDR_E_RETURNCODE returnCode
;
763 if ((GetFillSizeFieldsFlags() == TRUE
) &&
764 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_DCCINFO_INPUT
)) ||
765 (pOut
->size
!= sizeof(ADDR2_COMPUTE_DCCINFO_OUTPUT
))))
767 returnCode
= ADDR_INVALIDPARAMS
;
771 returnCode
= HwlComputeDccInfo(pIn
, pOut
);
773 ValidMetaBaseAlignments(pOut
->dccRamBaseAlign
);
780 ************************************************************************************************************************
781 * Lib::ComputeDccAddrFromCoord
784 * Interface function stub of ComputeDccAddrFromCoord
788 ************************************************************************************************************************
790 ADDR_E_RETURNCODE
Lib::ComputeDccAddrFromCoord(
791 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
792 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
794 ADDR_E_RETURNCODE returnCode
;
796 if ((GetFillSizeFieldsFlags() == TRUE
) &&
797 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
)) ||
798 (pOut
->size
!= sizeof(ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
))))
800 returnCode
= ADDR_INVALIDPARAMS
;
804 returnCode
= HwlComputeDccAddrFromCoord(pIn
, pOut
);
811 ************************************************************************************************************************
812 * Lib::ComputePipeBankXor
815 * Interface function stub of Addr2ComputePipeBankXor.
819 ************************************************************************************************************************
821 ADDR_E_RETURNCODE
Lib::ComputePipeBankXor(
822 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
823 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
)
825 ADDR_E_RETURNCODE returnCode
;
827 if ((GetFillSizeFieldsFlags() == TRUE
) &&
828 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_PIPEBANKXOR_INPUT
)) ||
829 (pOut
->size
!= sizeof(ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
))))
831 returnCode
= ADDR_INVALIDPARAMS
;
835 returnCode
= HwlComputePipeBankXor(pIn
, pOut
);
842 ************************************************************************************************************************
843 * Lib::ComputeSlicePipeBankXor
846 * Interface function stub of Addr2ComputeSlicePipeBankXor.
850 ************************************************************************************************************************
852 ADDR_E_RETURNCODE
Lib::ComputeSlicePipeBankXor(
853 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
854 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
)
856 ADDR_E_RETURNCODE returnCode
;
858 if ((GetFillSizeFieldsFlags() == TRUE
) &&
859 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
)) ||
860 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
))))
862 returnCode
= ADDR_INVALIDPARAMS
;
864 else if ((IsThin(pIn
->resourceType
, pIn
->swizzleMode
) == FALSE
) ||
865 (IsNonPrtXor(pIn
->swizzleMode
) == FALSE
) ||
866 (pIn
->numSamples
> 1))
868 returnCode
= ADDR_NOTSUPPORTED
;
872 returnCode
= HwlComputeSlicePipeBankXor(pIn
, pOut
);
879 ************************************************************************************************************************
880 * Lib::ComputeSubResourceOffsetForSwizzlePattern
883 * Interface function stub of Addr2ComputeSubResourceOffsetForSwizzlePattern.
887 ************************************************************************************************************************
889 ADDR_E_RETURNCODE
Lib::ComputeSubResourceOffsetForSwizzlePattern(
890 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
891 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
)
893 ADDR_E_RETURNCODE returnCode
;
895 if ((GetFillSizeFieldsFlags() == TRUE
) &&
896 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
)) ||
897 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
))))
899 returnCode
= ADDR_INVALIDPARAMS
;
903 returnCode
= HwlComputeSubResourceOffsetForSwizzlePattern(pIn
, pOut
);
910 ************************************************************************************************************************
911 * Lib::ExtractPipeBankXor
914 * Internal function to extract bank and pipe xor bits from combined xor bits.
918 ************************************************************************************************************************
920 ADDR_E_RETURNCODE
Lib::ExtractPipeBankXor(
927 ADDR_E_RETURNCODE returnCode
;
929 if (pipeBankXor
< (1u << (pipeBits
+ bankBits
)))
931 *pPipeX
= pipeBankXor
% (1 << pipeBits
);
932 *pBankX
= pipeBankXor
>> pipeBits
;
933 returnCode
= ADDR_OK
;
937 ADDR_ASSERT_ALWAYS();
938 returnCode
= ADDR_INVALIDPARAMS
;
945 ************************************************************************************************************************
946 * Lib::ComputeSurfaceInfoSanityCheck
949 * Internal function to do basic sanity check before compute surface info
953 ************************************************************************************************************************
955 ADDR_E_RETURNCODE
Lib::ComputeSurfaceInfoSanityCheck(
956 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
///< [in] input structure
959 ADDR_E_RETURNCODE returnCode
;
961 if ((GetFillSizeFieldsFlags() == TRUE
) &&
962 (pIn
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_INFO_INPUT
)))
964 returnCode
= ADDR_INVALIDPARAMS
;
968 returnCode
= HwlComputeSurfaceInfoSanityCheck(pIn
);
975 ************************************************************************************************************************
976 * Lib::ApplyCustomizedPitchHeight
979 * Helper function to override hw required row pitch/slice pitch by customrized one
983 ************************************************************************************************************************
985 ADDR_E_RETURNCODE
Lib::ApplyCustomizedPitchHeight(
986 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
987 UINT_32 elementBytes
, ///< [in] element bytes per element
988 UINT_32 pitchAlignInElement
, ///< [in] pitch alignment in element
989 UINT_32
* pPitch
, ///< [in/out] pitch
990 UINT_32
* pHeight
///< [in/out] height
993 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
995 if (pIn
->numMipLevels
<= 1)
997 if (pIn
->pitchInElement
> 0)
999 if ((pIn
->pitchInElement
% pitchAlignInElement
) != 0)
1001 returnCode
= ADDR_INVALIDPARAMS
;
1003 else if (pIn
->pitchInElement
< (*pPitch
))
1005 returnCode
= ADDR_INVALIDPARAMS
;
1009 *pPitch
= pIn
->pitchInElement
;
1013 if (returnCode
== ADDR_OK
)
1015 if (pIn
->sliceAlign
> 0)
1017 UINT_32 customizedHeight
= pIn
->sliceAlign
/ elementBytes
/ (*pPitch
);
1019 if (customizedHeight
* elementBytes
* (*pPitch
) != pIn
->sliceAlign
)
1021 returnCode
= ADDR_INVALIDPARAMS
;
1023 else if ((pIn
->numSlices
> 1) && ((*pHeight
) != customizedHeight
))
1025 returnCode
= ADDR_INVALIDPARAMS
;
1029 *pHeight
= customizedHeight
;
1039 ************************************************************************************************************************
1040 * Lib::ComputeSurfaceInfoLinear
1043 * Internal function to calculate alignment for linear swizzle surface
1047 ************************************************************************************************************************
1049 ADDR_E_RETURNCODE
Lib::ComputeSurfaceInfoLinear(
1050 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
1051 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
1054 return HwlComputeSurfaceInfoLinear(pIn
, pOut
);
1058 ************************************************************************************************************************
1059 * Lib::ComputeSurfaceInfoTiled
1062 * Internal function to calculate alignment for tiled swizzle surface
1066 ************************************************************************************************************************
1068 ADDR_E_RETURNCODE
Lib::ComputeSurfaceInfoTiled(
1069 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
1070 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
1073 return HwlComputeSurfaceInfoTiled(pIn
, pOut
);
1077 ************************************************************************************************************************
1078 * Lib::ComputeSurfaceAddrFromCoordLinear
1081 * Internal function to calculate address from coord for linear swizzle surface
1085 ************************************************************************************************************************
1087 ADDR_E_RETURNCODE
Lib::ComputeSurfaceAddrFromCoordLinear(
1088 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1089 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1092 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1093 BOOL_32 valid
= (pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1) && (pIn
->pipeBankXor
== 0);
1097 if (IsTex1d(pIn
->resourceType
))
1099 valid
= (pIn
->y
== 0);
1105 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
1106 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
1107 ADDR2_MIP_INFO mipInfo
[MaxMipLevels
];
1109 localIn
.bpp
= pIn
->bpp
;
1110 localIn
.flags
= pIn
->flags
;
1111 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
1112 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
1113 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
1114 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
1115 localIn
.resourceType
= pIn
->resourceType
;
1117 if (localIn
.numMipLevels
<= 1)
1119 localIn
.pitchInElement
= pIn
->pitchInElement
;
1122 localOut
.pMipInfo
= mipInfo
;
1124 returnCode
= ComputeSurfaceInfoLinear(&localIn
, &localOut
);
1126 if (returnCode
== ADDR_OK
)
1128 pOut
->addr
= (localOut
.sliceSize
* pIn
->slice
) +
1129 mipInfo
[pIn
->mipId
].offset
+
1130 (pIn
->y
* mipInfo
[pIn
->mipId
].pitch
+ pIn
->x
) * (pIn
->bpp
>> 3);
1131 pOut
->bitPosition
= 0;
1141 returnCode
= ADDR_INVALIDPARAMS
;
1148 ************************************************************************************************************************
1149 * Lib::ComputeSurfaceAddrFromCoordTiled
1152 * Internal function to calculate address from coord for tiled swizzle surface
1156 ************************************************************************************************************************
1158 ADDR_E_RETURNCODE
Lib::ComputeSurfaceAddrFromCoordTiled(
1159 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1160 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1163 return HwlComputeSurfaceAddrFromCoordTiled(pIn
, pOut
);
1167 ************************************************************************************************************************
1168 * Lib::ComputeSurfaceCoordFromAddrLinear
1171 * Internal function to calculate coord from address for linear swizzle surface
1175 ************************************************************************************************************************
1177 ADDR_E_RETURNCODE
Lib::ComputeSurfaceCoordFromAddrLinear(
1178 const ADDR2_COMPUTE_SURFACE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1179 ADDR2_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1182 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1184 BOOL_32 valid
= (pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1);
1188 if (IsTex1d(pIn
->resourceType
))
1190 valid
= (pIn
->unalignedHeight
== 1);
1196 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
1197 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
1198 localIn
.bpp
= pIn
->bpp
;
1199 localIn
.flags
= pIn
->flags
;
1200 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
1201 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
1202 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
1203 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
1204 localIn
.resourceType
= pIn
->resourceType
;
1205 if (localIn
.numMipLevels
<= 1)
1207 localIn
.pitchInElement
= pIn
->pitchInElement
;
1209 returnCode
= ComputeSurfaceInfoLinear(&localIn
, &localOut
);
1211 if (returnCode
== ADDR_OK
)
1213 pOut
->slice
= static_cast<UINT_32
>(pIn
->addr
/ localOut
.sliceSize
);
1216 UINT_32 offsetInSlice
= static_cast<UINT_32
>(pIn
->addr
% localOut
.sliceSize
);
1217 UINT_32 elementBytes
= pIn
->bpp
>> 3;
1218 UINT_32 mipOffsetInSlice
= 0;
1219 UINT_32 mipSize
= 0;
1221 for (; mipId
< pIn
->numMipLevels
; mipId
++)
1223 if (IsTex1d(pIn
->resourceType
))
1225 mipSize
= localOut
.pitch
* elementBytes
;
1229 UINT_32 currentMipHeight
= (PowTwoAlign(localIn
.height
, (1 << mipId
))) >> mipId
;
1230 mipSize
= currentMipHeight
* localOut
.pitch
* elementBytes
;
1238 else if ((mipSize
+ mipOffsetInSlice
) > offsetInSlice
)
1244 mipOffsetInSlice
+= mipSize
;
1245 if ((mipId
== (pIn
->numMipLevels
- 1)) ||
1246 (mipOffsetInSlice
>= localOut
.sliceSize
))
1255 pOut
->mipId
= mipId
;
1257 UINT_32 elemOffsetInMip
= (offsetInSlice
- mipOffsetInSlice
) / elementBytes
;
1258 if (IsTex1d(pIn
->resourceType
))
1260 if (elemOffsetInMip
< localOut
.pitch
)
1262 pOut
->x
= elemOffsetInMip
;
1272 pOut
->y
= elemOffsetInMip
/ localOut
.pitch
;
1273 pOut
->x
= elemOffsetInMip
% localOut
.pitch
;
1276 if ((pOut
->slice
>= pIn
->numSlices
) ||
1277 (pOut
->mipId
>= pIn
->numMipLevels
) ||
1278 (pOut
->x
>= Max((pIn
->unalignedWidth
>> pOut
->mipId
), 1u)) ||
1279 (pOut
->y
>= Max((pIn
->unalignedHeight
>> pOut
->mipId
), 1u)) ||
1280 (IsTex3d(pIn
->resourceType
) &&
1281 (FALSE
== Valid3DMipSliceIdConstraint(pIn
->numSlices
,
1297 returnCode
= ADDR_INVALIDPARAMS
;
1304 ************************************************************************************************************************
1305 * Lib::ComputeSurfaceCoordFromAddrTiled
1308 * Internal function to calculate coord from address for tiled swizzle surface
1312 ************************************************************************************************************************
1314 ADDR_E_RETURNCODE
Lib::ComputeSurfaceCoordFromAddrTiled(
1315 const ADDR2_COMPUTE_SURFACE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1316 ADDR2_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1319 ADDR_E_RETURNCODE returnCode
= ADDR_NOTIMPLEMENTED
;
1321 ADDR_NOT_IMPLEMENTED();
1327 ************************************************************************************************************************
1328 * Lib::ComputeBlockDimensionForSurf
1331 * Internal function to get block width/height/depth in element from surface input params.
1335 ************************************************************************************************************************
1337 ADDR_E_RETURNCODE
Lib::ComputeBlockDimensionForSurf(
1343 AddrResourceType resourceType
,
1344 AddrSwizzleMode swizzleMode
) const
1346 ADDR_E_RETURNCODE returnCode
= ComputeBlockDimension(pWidth
,
1353 if ((returnCode
== ADDR_OK
) && (numSamples
> 1) && IsThin(resourceType
, swizzleMode
))
1355 const UINT_32 log2blkSize
= GetBlockSizeLog2(swizzleMode
);
1356 const UINT_32 log2sample
= Log2(numSamples
);
1357 const UINT_32 q
= log2sample
>> 1;
1358 const UINT_32 r
= log2sample
& 1;
1360 if (log2blkSize
& 1)
1363 *pHeight
>>= (q
+ r
);
1367 *pWidth
>>= (q
+ r
);
1376 ************************************************************************************************************************
1377 * Lib::ComputeBlockDimension
1380 * Internal function to get block width/height/depth in element without considering MSAA case
1384 ************************************************************************************************************************
1386 ADDR_E_RETURNCODE
Lib::ComputeBlockDimension(
1391 AddrResourceType resourceType
,
1392 AddrSwizzleMode swizzleMode
) const
1394 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1396 UINT_32 eleBytes
= bpp
>> 3;
1397 UINT_32 microBlockSizeTableIndex
= Log2(eleBytes
);
1398 UINT_32 log2blkSize
= GetBlockSizeLog2(swizzleMode
);
1400 if (IsThin(resourceType
, swizzleMode
))
1402 UINT_32 log2blkSizeIn256B
= log2blkSize
- 8;
1403 UINT_32 widthAmp
= log2blkSizeIn256B
/ 2;
1404 UINT_32 heightAmp
= log2blkSizeIn256B
- widthAmp
;
1406 ADDR_ASSERT(microBlockSizeTableIndex
< sizeof(Block256_2d
) / sizeof(Block256_2d
[0]));
1408 *pWidth
= (Block256_2d
[microBlockSizeTableIndex
].w
<< widthAmp
);
1409 *pHeight
= (Block256_2d
[microBlockSizeTableIndex
].h
<< heightAmp
);
1412 else if (IsThick(resourceType
, swizzleMode
))
1414 UINT_32 log2blkSizeIn1KB
= log2blkSize
- 10;
1415 UINT_32 averageAmp
= log2blkSizeIn1KB
/ 3;
1416 UINT_32 restAmp
= log2blkSizeIn1KB
% 3;
1418 ADDR_ASSERT(microBlockSizeTableIndex
< sizeof(Block1K_3d
) / sizeof(Block1K_3d
[0]));
1420 *pWidth
= Block1K_3d
[microBlockSizeTableIndex
].w
<< averageAmp
;
1421 *pHeight
= Block1K_3d
[microBlockSizeTableIndex
].h
<< (averageAmp
+ (restAmp
/ 2));
1422 *pDepth
= Block1K_3d
[microBlockSizeTableIndex
].d
<< (averageAmp
+ ((restAmp
!= 0) ? 1 : 0));
1426 ADDR_ASSERT_ALWAYS();
1427 returnCode
= ADDR_INVALIDPARAMS
;
1434 ************************************************************************************************************************
1435 * Lib::GetMipTailDim
1438 * Internal function to get out max dimension of first level in mip tail
1441 * Max Width/Height/Depth value of the first mip fitted in mip tail
1442 ************************************************************************************************************************
1444 Dim3d
Lib::GetMipTailDim(
1445 AddrResourceType resourceType
,
1446 AddrSwizzleMode swizzleMode
,
1448 UINT_32 blockHeight
,
1449 UINT_32 blockDepth
) const
1451 Dim3d out
= {blockWidth
, blockHeight
, blockDepth
};
1452 UINT_32 log2blkSize
= GetBlockSizeLog2(swizzleMode
);
1454 if (IsThick(resourceType
, swizzleMode
))
1456 UINT_32 dim
= log2blkSize
% 3;
1473 if (log2blkSize
& 1)
1487 ************************************************************************************************************************
1488 * Lib::ComputeSurface2DMicroBlockOffset
1491 * Internal function to calculate micro block (256B) offset from coord for 2D resource
1494 * micro block (256B) offset for 2D resource
1495 ************************************************************************************************************************
1497 UINT_32
Lib::ComputeSurface2DMicroBlockOffset(
1498 const _ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
) const
1500 ADDR_ASSERT(IsThin(pIn
->resourceType
, pIn
->swizzleMode
));
1502 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
1503 UINT_32 microBlockOffset
= 0;
1504 if (IsStandardSwizzle(pIn
->resourceType
, pIn
->swizzleMode
))
1506 UINT_32 xBits
= pIn
->x
<< log2ElementBytes
;
1507 microBlockOffset
= (xBits
& 0xf) | ((pIn
->y
& 0x3) << 4);
1508 if (log2ElementBytes
< 3)
1510 microBlockOffset
|= (pIn
->y
& 0x4) << 4;
1511 if (log2ElementBytes
== 0)
1513 microBlockOffset
|= (pIn
->y
& 0x8) << 4;
1517 microBlockOffset
|= (xBits
& 0x10) << 3;
1522 microBlockOffset
|= (xBits
& 0x30) << 2;
1525 else if (IsDisplaySwizzle(pIn
->resourceType
, pIn
->swizzleMode
))
1527 if (log2ElementBytes
== 4)
1529 microBlockOffset
= (GetBit(pIn
->x
, 0) << 4) |
1530 (GetBit(pIn
->y
, 0) << 5) |
1531 (GetBit(pIn
->x
, 1) << 6) |
1532 (GetBit(pIn
->y
, 1) << 7);
1536 microBlockOffset
= GetBits(pIn
->x
, 0, 3, log2ElementBytes
) |
1537 GetBits(pIn
->y
, 1, 2, 3 + log2ElementBytes
) |
1538 GetBits(pIn
->x
, 3, 1, 5 + log2ElementBytes
) |
1539 GetBits(pIn
->y
, 3, 1, 6 + log2ElementBytes
);
1540 microBlockOffset
= GetBits(microBlockOffset
, 0, 4, 0) |
1541 (GetBit(pIn
->y
, 0) << 4) |
1542 GetBits(microBlockOffset
, 4, 3, 5);
1545 else if (IsRotateSwizzle(pIn
->swizzleMode
))
1547 microBlockOffset
= GetBits(pIn
->y
, 0, 3, log2ElementBytes
) |
1548 GetBits(pIn
->x
, 1, 2, 3 + log2ElementBytes
) |
1549 GetBits(pIn
->x
, 3, 1, 5 + log2ElementBytes
) |
1550 GetBits(pIn
->y
, 3, 1, 6 + log2ElementBytes
);
1551 microBlockOffset
= GetBits(microBlockOffset
, 0, 4, 0) |
1552 (GetBit(pIn
->x
, 0) << 4) |
1553 GetBits(microBlockOffset
, 4, 3, 5);
1554 if (log2ElementBytes
== 3)
1556 microBlockOffset
= GetBits(microBlockOffset
, 0, 6, 0) |
1557 GetBits(pIn
->x
, 1, 2, 6);
1561 return microBlockOffset
;
1565 ************************************************************************************************************************
1566 * Lib::ComputeSurface3DMicroBlockOffset
1569 * Internal function to calculate micro block (1KB) offset from coord for 3D resource
1572 * micro block (1KB) offset for 3D resource
1573 ************************************************************************************************************************
1575 UINT_32
Lib::ComputeSurface3DMicroBlockOffset(
1576 const _ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
) const
1578 ADDR_ASSERT(IsThick(pIn
->resourceType
, pIn
->swizzleMode
));
1580 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
1581 UINT_32 microBlockOffset
= 0;
1582 if (IsStandardSwizzle(pIn
->resourceType
, pIn
->swizzleMode
))
1584 if (log2ElementBytes
== 0)
1586 microBlockOffset
= ((pIn
->slice
& 4) >> 2) | ((pIn
->y
& 4) >> 1);
1588 else if (log2ElementBytes
== 1)
1590 microBlockOffset
= ((pIn
->slice
& 4) >> 2) | ((pIn
->y
& 4) >> 1);
1592 else if (log2ElementBytes
== 2)
1594 microBlockOffset
= ((pIn
->y
& 4) >> 2) | ((pIn
->x
& 4) >> 1);
1596 else if (log2ElementBytes
== 3)
1598 microBlockOffset
= (pIn
->x
& 6) >> 1;
1602 microBlockOffset
= pIn
->x
& 3;
1605 microBlockOffset
<<= 8;
1607 UINT_32 xBits
= pIn
->x
<< log2ElementBytes
;
1608 microBlockOffset
|= (xBits
& 0xf) | ((pIn
->y
& 0x3) << 4) | ((pIn
->slice
& 0x3) << 6);
1610 else if (IsZOrderSwizzle(pIn
->swizzleMode
))
1614 if (log2ElementBytes
== 0)
1617 (pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->x
& 2) << 1) | ((pIn
->y
& 2) << 2);
1618 microBlockOffset
= microBlockOffset
| ((pIn
->slice
& 3) << 4) | ((pIn
->x
& 4) << 4);
1622 zh
= pIn
->slice
>> 2;
1624 else if (log2ElementBytes
== 1)
1627 (pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->x
& 2) << 1) | ((pIn
->y
& 2) << 2);
1628 microBlockOffset
= (microBlockOffset
<< 1) | ((pIn
->slice
& 3) << 5);
1632 zh
= pIn
->slice
>> 2;
1634 else if (log2ElementBytes
== 2)
1637 (pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->x
& 2) << 1) | ((pIn
->slice
& 1) << 3);
1638 microBlockOffset
= (microBlockOffset
<< 2) | ((pIn
->y
& 2) << 5);
1642 zh
= pIn
->slice
>> 1;
1644 else if (log2ElementBytes
== 3)
1647 (pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->slice
& 1) << 2) | ((pIn
->x
& 2) << 2);
1648 microBlockOffset
<<= 3;
1652 zh
= pIn
->slice
>> 1;
1657 (((pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->slice
& 1) << 2)) << 4);
1661 zh
= pIn
->slice
>> 1;
1664 microBlockOffset
|= ((MortonGen3d(xh
, yh
, zh
, 1) << 7) & 0x380);
1667 return microBlockOffset
;
1671 ************************************************************************************************************************
1672 * Lib::GetPipeXorBits
1675 * Internal function to get bits number for pipe/se xor operation
1679 ************************************************************************************************************************
1681 UINT_32
Lib::GetPipeXorBits(
1682 UINT_32 macroBlockBits
) const
1684 ADDR_ASSERT(macroBlockBits
>= m_pipeInterleaveLog2
);
1686 // Total available xor bits
1687 UINT_32 xorBits
= macroBlockBits
- m_pipeInterleaveLog2
;
1690 UINT_32 pipeBits
= Min(xorBits
, m_pipesLog2
+ m_seLog2
);
1696 ************************************************************************************************************************
1697 * Lib::GetBankXorBits
1700 * Internal function to get bits number for pipe/se xor operation
1704 ************************************************************************************************************************
1706 UINT_32
Lib::GetBankXorBits(
1707 UINT_32 macroBlockBits
) const
1709 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
1712 UINT_32 bankBits
= Min(macroBlockBits
- pipeBits
- m_pipeInterleaveLog2
, m_banksLog2
);
1718 ************************************************************************************************************************
1719 * Lib::Addr2GetPreferredSurfaceSetting
1722 * Internal function to get suggested surface information for cliet to use
1726 ************************************************************************************************************************
1728 ADDR_E_RETURNCODE
Lib::Addr2GetPreferredSurfaceSetting(
1729 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
1730 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const
1732 ADDR_E_RETURNCODE returnCode
;
1734 if ((GetFillSizeFieldsFlags() == TRUE
) &&
1735 ((pIn
->size
!= sizeof(ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
)) ||
1736 (pOut
->size
!= sizeof(ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
))))
1738 returnCode
= ADDR_INVALIDPARAMS
;
1742 returnCode
= HwlGetPreferredSurfaceSetting(pIn
, pOut
);
1749 ************************************************************************************************************************
1750 * Lib::ComputeBlock256Equation
1753 * Compute equation for block 256B
1756 * If equation computed successfully
1758 ************************************************************************************************************************
1760 ADDR_E_RETURNCODE
Lib::ComputeBlock256Equation(
1761 AddrResourceType rsrcType
,
1762 AddrSwizzleMode swMode
,
1763 UINT_32 elementBytesLog2
,
1764 ADDR_EQUATION
* pEquation
) const
1766 ADDR_E_RETURNCODE ret
;
1768 if (IsBlock256b(swMode
))
1770 ret
= HwlComputeBlock256Equation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
1774 ADDR_ASSERT_ALWAYS();
1775 ret
= ADDR_INVALIDPARAMS
;
1782 ************************************************************************************************************************
1783 * Lib::ComputeThinEquation
1786 * Compute equation for 2D/3D resource which use THIN mode
1789 * If equation computed successfully
1791 ************************************************************************************************************************
1793 ADDR_E_RETURNCODE
Lib::ComputeThinEquation(
1794 AddrResourceType rsrcType
,
1795 AddrSwizzleMode swMode
,
1796 UINT_32 elementBytesLog2
,
1797 ADDR_EQUATION
* pEquation
) const
1799 ADDR_E_RETURNCODE ret
;
1801 if (IsThin(rsrcType
, swMode
))
1803 ret
= HwlComputeThinEquation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
1807 ADDR_ASSERT_ALWAYS();
1808 ret
= ADDR_INVALIDPARAMS
;
1815 ************************************************************************************************************************
1816 * Lib::ComputeThickEquation
1819 * Compute equation for 3D resource which use THICK mode
1822 * If equation computed successfully
1824 ************************************************************************************************************************
1826 ADDR_E_RETURNCODE
Lib::ComputeThickEquation(
1827 AddrResourceType rsrcType
,
1828 AddrSwizzleMode swMode
,
1829 UINT_32 elementBytesLog2
,
1830 ADDR_EQUATION
* pEquation
) const
1832 ADDR_E_RETURNCODE ret
;
1834 if (IsThick(rsrcType
, swMode
))
1836 ret
= HwlComputeThickEquation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
1840 ADDR_ASSERT_ALWAYS();
1841 ret
= ADDR_INVALIDPARAMS
;
1848 ************************************************************************************************************************
1849 * Lib::ComputeQbStereoInfo
1852 * Get quad buffer stereo information
1855 ************************************************************************************************************************
1857 VOID
Lib::ComputeQbStereoInfo(
1858 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [in,out] updated pOut+pStereoInfo
1861 ADDR_ASSERT(pOut
->bpp
>= 8);
1862 ADDR_ASSERT((pOut
->surfSize
% pOut
->baseAlign
) == 0);
1864 // Save original height
1865 pOut
->pStereoInfo
->eyeHeight
= pOut
->height
;
1868 pOut
->pStereoInfo
->rightOffset
= static_cast<UINT_32
>(pOut
->surfSize
);
1873 ADDR_ASSERT(pOut
->height
<= MaxSurfaceHeight
);
1875 pOut
->pixelHeight
<<= 1;
1878 pOut
->surfSize
<<= 1;