2 * Copyright © 2017 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
17 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
28 ************************************************************************************************************************
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+ AISC can use AddrLib2 function.
117 ADDR_ASSERT_ALWAYS();
120 return static_cast<Lib
*>(hLib
);
124 ////////////////////////////////////////////////////////////////////////////////////////////////////
126 ////////////////////////////////////////////////////////////////////////////////////////////////////
130 ************************************************************************************************************************
131 * Lib::ComputeSurfaceInfo
134 * Interface function stub of AddrComputeSurfaceInfo.
138 ************************************************************************************************************************
140 ADDR_E_RETURNCODE
Lib::ComputeSurfaceInfo(
141 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
142 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
145 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
147 if (GetFillSizeFieldsFlags() == TRUE
)
149 if ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_INFO_INPUT
)) ||
150 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
)))
152 returnCode
= ADDR_PARAMSIZEMISMATCH
;
156 // Adjust coming parameters.
157 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= *pIn
;
158 localIn
.width
= Max(pIn
->width
, 1u);
159 localIn
.height
= Max(pIn
->height
, 1u);
160 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
161 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
162 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
163 localIn
.numFrags
= (localIn
.numFrags
== 0) ? localIn
.numSamples
: pIn
->numFrags
;
167 ElemMode elemMode
= ADDR_UNCOMPRESSED
;
169 if (returnCode
== ADDR_OK
)
171 // Set format to INVALID will skip this conversion
172 if (localIn
.format
!= ADDR_FMT_INVALID
)
174 // Get compression/expansion factors and element mode which indicates compression/expansion
175 localIn
.bpp
= GetElemLib()->GetBitsPerPixel(localIn
.format
,
180 // Special flag for 96 bit surface. 96 (or 48 if we support) bit surface's width is
181 // pre-multiplied by 3 and bpp is divided by 3. So pitch alignment for linear-
182 // aligned does not meet 64-pixel in real. We keep special handling in hwl since hw
183 // restrictions are different.
184 // Also Mip 1+ needs an element pitch of 32 bits so we do not need this workaround
185 // but we use this flag to skip RestoreSurfaceInfo below
187 if ((elemMode
== ADDR_EXPANDED
) && (expandX
> 1))
189 ADDR_ASSERT(IsLinear(localIn
.swizzleMode
));
192 UINT_32 basePitch
= 0;
193 GetElemLib()->AdjustSurfaceInfo(elemMode
,
201 // Overwrite these parameters if we have a valid format
204 if (localIn
.bpp
!= 0)
206 localIn
.width
= Max(localIn
.width
, 1u);
207 localIn
.height
= Max(localIn
.height
, 1u);
209 else // Rule out some invalid parameters
211 ADDR_ASSERT_ALWAYS();
213 returnCode
= ADDR_INVALIDPARAMS
;
217 if (returnCode
== ADDR_OK
)
219 returnCode
= ComputeSurfaceInfoSanityCheck(&localIn
);
222 if (returnCode
== ADDR_OK
)
224 VerifyMipLevelInfo(pIn
);
226 if (IsLinear(pIn
->swizzleMode
))
229 returnCode
= ComputeSurfaceInfoLinear(&localIn
, pOut
);
234 returnCode
= ComputeSurfaceInfoTiled(&localIn
, pOut
);
237 if (returnCode
== ADDR_OK
)
239 pOut
->bpp
= localIn
.bpp
;
240 pOut
->pixelPitch
= pOut
->pitch
;
241 pOut
->pixelHeight
= pOut
->height
;
242 pOut
->pixelMipChainPitch
= pOut
->mipChainPitch
;
243 pOut
->pixelMipChainHeight
= pOut
->mipChainHeight
;
244 pOut
->pixelBits
= localIn
.bpp
;
246 if (localIn
.format
!= ADDR_FMT_INVALID
)
248 UINT_32 pixelBits
= pOut
->pixelBits
;
250 GetElemLib()->RestoreSurfaceInfo(elemMode
,
257 GetElemLib()->RestoreSurfaceInfo(elemMode
,
261 &pOut
->pixelMipChainPitch
,
262 &pOut
->pixelMipChainHeight
);
264 if ((localIn
.numMipLevels
> 1) && (pOut
->pMipInfo
!= NULL
))
266 for (UINT_32 i
= 0; i
< localIn
.numMipLevels
; i
++)
268 pOut
->pMipInfo
[i
].pixelPitch
= pOut
->pMipInfo
[i
].pitch
;
269 pOut
->pMipInfo
[i
].pixelHeight
= pOut
->pMipInfo
[i
].height
;
271 GetElemLib()->RestoreSurfaceInfo(elemMode
,
275 &pOut
->pMipInfo
[i
].pixelPitch
,
276 &pOut
->pMipInfo
[i
].pixelHeight
);
281 if (localIn
.flags
.needEquation
&& (Log2(localIn
.numFrags
) == 0))
283 pOut
->equationIndex
= GetEquationIndex(&localIn
, pOut
);
286 if (localIn
.flags
.qbStereo
)
288 if (pOut
->pStereoInfo
!= NULL
)
290 ComputeQbStereoInfo(pOut
);
296 ADDR_ASSERT(pOut
->surfSize
!= 0);
298 ValidBaseAlignments(pOut
->baseAlign
);
304 ************************************************************************************************************************
305 * Lib::ComputeSurfaceInfo
308 * Interface function stub of AddrComputeSurfaceInfo.
312 ************************************************************************************************************************
314 ADDR_E_RETURNCODE
Lib::ComputeSurfaceAddrFromCoord(
315 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
316 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
319 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
321 if (GetFillSizeFieldsFlags() == TRUE
)
323 if ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
)) ||
324 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
)))
326 returnCode
= ADDR_PARAMSIZEMISMATCH
;
330 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT localIn
= *pIn
;
331 localIn
.unalignedWidth
= Max(pIn
->unalignedWidth
, 1u);
332 localIn
.unalignedHeight
= Max(pIn
->unalignedHeight
, 1u);
333 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
334 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
335 localIn
.numSamples
= Max(pIn
->numSamples
, 1u);
336 localIn
.numFrags
= Max(pIn
->numFrags
, 1u);
338 if ((localIn
.bpp
< 8) ||
339 (localIn
.bpp
> 128) ||
340 ((localIn
.bpp
% 8) != 0) ||
341 (localIn
.sample
>= localIn
.numSamples
) ||
342 (localIn
.slice
>= localIn
.numSlices
) ||
343 (localIn
.mipId
>= localIn
.numMipLevels
) ||
344 (IsTex3d(localIn
.resourceType
) &&
345 (Valid3DMipSliceIdConstraint(localIn
.numSlices
, localIn
.mipId
, localIn
.slice
) == FALSE
)))
347 returnCode
= ADDR_INVALIDPARAMS
;
350 if (returnCode
== ADDR_OK
)
352 if (IsLinear(localIn
.swizzleMode
))
354 returnCode
= ComputeSurfaceAddrFromCoordLinear(&localIn
, pOut
);
358 returnCode
= ComputeSurfaceAddrFromCoordTiled(&localIn
, pOut
);
361 if (returnCode
== ADDR_OK
)
363 pOut
->prtBlockIndex
= static_cast<UINT_32
>(pOut
->addr
/ (64 * 1024));
371 ************************************************************************************************************************
372 * Lib::ComputeSurfaceCoordFromAddr
375 * Interface function stub of ComputeSurfaceCoordFromAddr.
379 ************************************************************************************************************************
381 ADDR_E_RETURNCODE
Lib::ComputeSurfaceCoordFromAddr(
382 const ADDR2_COMPUTE_SURFACE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
383 ADDR2_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
386 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
388 if (GetFillSizeFieldsFlags() == TRUE
)
390 if ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_COORDFROMADDR_INPUT
)) ||
391 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
)))
393 returnCode
= ADDR_PARAMSIZEMISMATCH
;
397 if ((pIn
->bpp
< 8) ||
399 ((pIn
->bpp
% 8) != 0) ||
400 (pIn
->bitPosition
>= 8))
402 returnCode
= ADDR_INVALIDPARAMS
;
405 if (returnCode
== ADDR_OK
)
407 if (IsLinear(pIn
->swizzleMode
))
409 returnCode
= ComputeSurfaceCoordFromAddrLinear(pIn
, pOut
);
413 returnCode
= ComputeSurfaceCoordFromAddrTiled(pIn
, pOut
);
421 ////////////////////////////////////////////////////////////////////////////////////////////////////
423 ////////////////////////////////////////////////////////////////////////////////////////////////////
426 ************************************************************************************************************************
427 * Lib::ComputeHtileInfo
430 * Interface function stub of AddrComputeHtilenfo
434 ************************************************************************************************************************
436 ADDR_E_RETURNCODE
Lib::ComputeHtileInfo(
437 const ADDR2_COMPUTE_HTILE_INFO_INPUT
* pIn
, ///< [in] input structure
438 ADDR2_COMPUTE_HTILE_INFO_OUTPUT
* pOut
///< [out] output structure
441 ADDR_E_RETURNCODE returnCode
;
443 if ((GetFillSizeFieldsFlags() == TRUE
) &&
444 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_HTILE_INFO_INPUT
)) ||
445 (pOut
->size
!= sizeof(ADDR2_COMPUTE_HTILE_INFO_OUTPUT
))))
447 returnCode
= ADDR_INVALIDPARAMS
;
451 returnCode
= HwlComputeHtileInfo(pIn
, pOut
);
453 ValidMetaBaseAlignments(pOut
->baseAlign
);
460 ************************************************************************************************************************
461 * Lib::ComputeHtileAddrFromCoord
464 * Interface function stub of AddrComputeHtileAddrFromCoord
468 ************************************************************************************************************************
470 ADDR_E_RETURNCODE
Lib::ComputeHtileAddrFromCoord(
471 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
472 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
474 ADDR_E_RETURNCODE returnCode
;
476 if ((GetFillSizeFieldsFlags() == TRUE
) &&
477 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
)) ||
478 (pOut
->size
!= sizeof(ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
))))
480 returnCode
= ADDR_INVALIDPARAMS
;
484 returnCode
= HwlComputeHtileAddrFromCoord(pIn
, pOut
);
491 ************************************************************************************************************************
492 * Lib::ComputeHtileCoordFromAddr
495 * Interface function stub of AddrComputeHtileCoordFromAddr
499 ************************************************************************************************************************
501 ADDR_E_RETURNCODE
Lib::ComputeHtileCoordFromAddr(
502 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
503 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
) ///< [out] output structure
505 ADDR_E_RETURNCODE returnCode
;
507 if ((GetFillSizeFieldsFlags() == TRUE
) &&
508 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
)) ||
509 (pOut
->size
!= sizeof(ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
))))
511 returnCode
= ADDR_INVALIDPARAMS
;
515 returnCode
= HwlComputeHtileCoordFromAddr(pIn
, pOut
);
522 ************************************************************************************************************************
523 * Lib::ComputeCmaskInfo
526 * Interface function stub of AddrComputeCmaskInfo
530 ************************************************************************************************************************
532 ADDR_E_RETURNCODE
Lib::ComputeCmaskInfo(
533 const ADDR2_COMPUTE_CMASK_INFO_INPUT
* pIn
, ///< [in] input structure
534 ADDR2_COMPUTE_CMASK_INFO_OUTPUT
* pOut
///< [out] output structure
537 ADDR_E_RETURNCODE returnCode
;
539 if ((GetFillSizeFieldsFlags() == TRUE
) &&
540 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_CMASK_INFO_INPUT
)) ||
541 (pOut
->size
!= sizeof(ADDR2_COMPUTE_CMASK_INFO_OUTPUT
))))
543 returnCode
= ADDR_INVALIDPARAMS
;
545 else if (pIn
->cMaskFlags
.linear
)
547 returnCode
= ADDR_INVALIDPARAMS
;
551 returnCode
= HwlComputeCmaskInfo(pIn
, pOut
);
553 ValidMetaBaseAlignments(pOut
->baseAlign
);
560 ************************************************************************************************************************
561 * Lib::ComputeCmaskAddrFromCoord
564 * Interface function stub of AddrComputeCmaskAddrFromCoord
568 ************************************************************************************************************************
570 ADDR_E_RETURNCODE
Lib::ComputeCmaskAddrFromCoord(
571 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
572 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
574 ADDR_E_RETURNCODE returnCode
;
576 if ((GetFillSizeFieldsFlags() == TRUE
) &&
577 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
)) ||
578 (pOut
->size
!= sizeof(ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
))))
580 returnCode
= ADDR_INVALIDPARAMS
;
584 returnCode
= HwlComputeCmaskAddrFromCoord(pIn
, pOut
);
591 ************************************************************************************************************************
592 * Lib::ComputeCmaskCoordFromAddr
595 * Interface function stub of AddrComputeCmaskCoordFromAddr
599 ************************************************************************************************************************
601 ADDR_E_RETURNCODE
Lib::ComputeCmaskCoordFromAddr(
602 const ADDR2_COMPUTE_CMASK_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
603 ADDR2_COMPUTE_CMASK_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
606 ADDR_E_RETURNCODE returnCode
= ADDR_NOTIMPLEMENTED
;
608 ADDR_NOT_IMPLEMENTED();
614 ************************************************************************************************************************
615 * Lib::ComputeFmaskInfo
618 * Interface function stub of ComputeFmaskInfo.
622 ************************************************************************************************************************
624 ADDR_E_RETURNCODE
Lib::ComputeFmaskInfo(
625 const ADDR2_COMPUTE_FMASK_INFO_INPUT
* pIn
, ///< [in] input structure
626 ADDR2_COMPUTE_FMASK_INFO_OUTPUT
* pOut
///< [out] output structure
629 ADDR_E_RETURNCODE returnCode
;
631 BOOL_32 valid
= (IsZOrderSwizzle(pIn
->swizzleMode
) == TRUE
) &&
632 ((pIn
->numSamples
> 0) || (pIn
->numFrags
> 0));
634 if (GetFillSizeFieldsFlags())
636 if ((pIn
->size
!= sizeof(ADDR2_COMPUTE_FMASK_INFO_INPUT
)) ||
637 (pOut
->size
!= sizeof(ADDR2_COMPUTE_FMASK_INFO_OUTPUT
)))
645 returnCode
= ADDR_INVALIDPARAMS
;
649 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
650 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
652 localIn
.size
= sizeof(ADDR2_COMPUTE_SURFACE_INFO_INPUT
);
653 localOut
.size
= sizeof(ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
);
655 localIn
.swizzleMode
= pIn
->swizzleMode
;
656 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
657 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
658 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
659 localIn
.bpp
= GetFmaskBpp(pIn
->numSamples
, pIn
->numFrags
);
660 localIn
.flags
.fmask
= 1;
661 localIn
.numFrags
= 1;
662 localIn
.numSamples
= 1;
663 localIn
.resourceType
= ADDR_RSRC_TEX_2D
;
665 if (localIn
.bpp
== 8)
667 localIn
.format
= ADDR_FMT_8
;
669 else if (localIn
.bpp
== 16)
671 localIn
.format
= ADDR_FMT_16
;
673 else if (localIn
.bpp
== 32)
675 localIn
.format
= ADDR_FMT_32
;
679 localIn
.format
= ADDR_FMT_32_32
;
682 returnCode
= ComputeSurfaceInfo(&localIn
, &localOut
);
684 if (returnCode
== ADDR_OK
)
686 pOut
->pitch
= localOut
.pitch
;
687 pOut
->height
= localOut
.height
;
688 pOut
->baseAlign
= localOut
.baseAlign
;
689 pOut
->numSlices
= localOut
.numSlices
;
690 pOut
->fmaskBytes
= static_cast<UINT_32
>(localOut
.surfSize
);
691 pOut
->sliceSize
= static_cast<UINT_32
>(localOut
.sliceSize
);
692 pOut
->bpp
= localIn
.bpp
;
693 pOut
->numSamples
= 1;
697 ValidBaseAlignments(pOut
->baseAlign
);
703 ************************************************************************************************************************
704 * Lib::ComputeFmaskAddrFromCoord
707 * Interface function stub of ComputeFmaskAddrFromCoord.
711 ************************************************************************************************************************
713 ADDR_E_RETURNCODE
Lib::ComputeFmaskAddrFromCoord(
714 const ADDR2_COMPUTE_FMASK_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
715 ADDR2_COMPUTE_FMASK_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
718 ADDR_E_RETURNCODE returnCode
= ADDR_NOTIMPLEMENTED
;
720 ADDR_NOT_IMPLEMENTED();
726 ************************************************************************************************************************
727 * Lib::ComputeFmaskCoordFromAddr
730 * Interface function stub of ComputeFmaskAddrFromCoord.
734 ************************************************************************************************************************
736 ADDR_E_RETURNCODE
Lib::ComputeFmaskCoordFromAddr(
737 const ADDR2_COMPUTE_FMASK_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
738 ADDR2_COMPUTE_FMASK_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
741 ADDR_E_RETURNCODE returnCode
= ADDR_NOTIMPLEMENTED
;
743 ADDR_NOT_IMPLEMENTED();
749 ************************************************************************************************************************
750 * Lib::ComputeDccInfo
753 * Interface function to compute DCC key info
756 * return code of HwlComputeDccInfo
757 ************************************************************************************************************************
759 ADDR_E_RETURNCODE
Lib::ComputeDccInfo(
760 const ADDR2_COMPUTE_DCCINFO_INPUT
* pIn
, ///< [in] input structure
761 ADDR2_COMPUTE_DCCINFO_OUTPUT
* pOut
///< [out] output structure
764 ADDR_E_RETURNCODE returnCode
;
766 if ((GetFillSizeFieldsFlags() == TRUE
) &&
767 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_DCCINFO_INPUT
)) ||
768 (pOut
->size
!= sizeof(ADDR2_COMPUTE_DCCINFO_OUTPUT
))))
770 returnCode
= ADDR_INVALIDPARAMS
;
774 returnCode
= HwlComputeDccInfo(pIn
, pOut
);
776 ValidMetaBaseAlignments(pOut
->dccRamBaseAlign
);
783 ************************************************************************************************************************
784 * Lib::ComputeDccAddrFromCoord
787 * Interface function stub of ComputeDccAddrFromCoord
791 ************************************************************************************************************************
793 ADDR_E_RETURNCODE
Lib::ComputeDccAddrFromCoord(
794 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
795 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
) ///< [out] output structure
797 ADDR_E_RETURNCODE returnCode
;
799 if ((GetFillSizeFieldsFlags() == TRUE
) &&
800 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
)) ||
801 (pOut
->size
!= sizeof(ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
))))
803 returnCode
= ADDR_INVALIDPARAMS
;
807 returnCode
= HwlComputeDccAddrFromCoord(pIn
, pOut
);
814 ************************************************************************************************************************
815 * Lib::ComputePipeBankXor
818 * Interface function stub of Addr2ComputePipeBankXor.
822 ************************************************************************************************************************
824 ADDR_E_RETURNCODE
Lib::ComputePipeBankXor(
825 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
826 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
)
828 ADDR_E_RETURNCODE returnCode
;
830 if ((GetFillSizeFieldsFlags() == TRUE
) &&
831 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_PIPEBANKXOR_INPUT
)) ||
832 (pOut
->size
!= sizeof(ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
))))
834 returnCode
= ADDR_INVALIDPARAMS
;
836 else if (IsXor(pIn
->swizzleMode
) == FALSE
)
838 returnCode
= ADDR_NOTSUPPORTED
;
842 returnCode
= HwlComputePipeBankXor(pIn
, pOut
);
849 ************************************************************************************************************************
850 * Lib::ComputeSlicePipeBankXor
853 * Interface function stub of Addr2ComputeSlicePipeBankXor.
857 ************************************************************************************************************************
859 ADDR_E_RETURNCODE
Lib::ComputeSlicePipeBankXor(
860 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
861 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
)
863 ADDR_E_RETURNCODE returnCode
;
865 if ((GetFillSizeFieldsFlags() == TRUE
) &&
866 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
)) ||
867 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
))))
869 returnCode
= ADDR_INVALIDPARAMS
;
871 else if ((IsThin(pIn
->resourceType
, pIn
->swizzleMode
) == FALSE
) ||
872 (IsNonPrtXor(pIn
->swizzleMode
) == FALSE
) ||
873 (pIn
->numSamples
> 1))
875 returnCode
= ADDR_NOTSUPPORTED
;
879 returnCode
= HwlComputeSlicePipeBankXor(pIn
, pOut
);
886 ************************************************************************************************************************
887 * Lib::ComputeSubResourceOffsetForSwizzlePattern
890 * Interface function stub of Addr2ComputeSubResourceOffsetForSwizzlePattern.
894 ************************************************************************************************************************
896 ADDR_E_RETURNCODE
Lib::ComputeSubResourceOffsetForSwizzlePattern(
897 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
898 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
)
900 ADDR_E_RETURNCODE returnCode
;
902 if ((GetFillSizeFieldsFlags() == TRUE
) &&
903 ((pIn
->size
!= sizeof(ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
)) ||
904 (pOut
->size
!= sizeof(ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
))))
906 returnCode
= ADDR_INVALIDPARAMS
;
910 returnCode
= HwlComputeSubResourceOffsetForSwizzlePattern(pIn
, pOut
);
917 ************************************************************************************************************************
918 * Lib::ExtractPipeBankXor
921 * Internal function to extract bank and pipe xor bits from combined xor bits.
925 ************************************************************************************************************************
927 ADDR_E_RETURNCODE
Lib::ExtractPipeBankXor(
934 ADDR_E_RETURNCODE returnCode
;
936 if (pipeBankXor
< (1u << (pipeBits
+ bankBits
)))
938 *pPipeX
= pipeBankXor
% (1 << pipeBits
);
939 *pBankX
= pipeBankXor
>> pipeBits
;
940 returnCode
= ADDR_OK
;
944 ADDR_ASSERT_ALWAYS();
945 returnCode
= ADDR_INVALIDPARAMS
;
952 ************************************************************************************************************************
953 * Lib::ComputeSurfaceInfoSanityCheck
956 * Internal function to do basic sanity check before compute surface info
960 ************************************************************************************************************************
962 ADDR_E_RETURNCODE
Lib::ComputeSurfaceInfoSanityCheck(
963 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
///< [in] input structure
966 ADDR_E_RETURNCODE returnCode
;
968 if ((GetFillSizeFieldsFlags() == TRUE
) &&
969 (pIn
->size
!= sizeof(ADDR2_COMPUTE_SURFACE_INFO_INPUT
)))
971 returnCode
= ADDR_INVALIDPARAMS
;
975 returnCode
= HwlComputeSurfaceInfoSanityCheck(pIn
);
982 ************************************************************************************************************************
983 * Lib::ApplyCustomizedPitchHeight
986 * Helper function to override hw required row pitch/slice pitch by customrized one
990 ************************************************************************************************************************
992 ADDR_E_RETURNCODE
Lib::ApplyCustomizedPitchHeight(
993 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
994 UINT_32 elementBytes
, ///< [in] element bytes per element
995 UINT_32 pitchAlignInElement
, ///< [in] pitch alignment in element
996 UINT_32
* pPitch
, ///< [in/out] pitch
997 UINT_32
* pHeight
///< [in/out] height
1000 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1002 if (pIn
->numMipLevels
<= 1)
1004 if (pIn
->pitchInElement
> 0)
1006 if ((pIn
->pitchInElement
% pitchAlignInElement
) != 0)
1008 returnCode
= ADDR_INVALIDPARAMS
;
1010 else if (pIn
->pitchInElement
< (*pPitch
))
1012 returnCode
= ADDR_INVALIDPARAMS
;
1016 *pPitch
= pIn
->pitchInElement
;
1020 if (returnCode
== ADDR_OK
)
1022 if (pIn
->sliceAlign
> 0)
1024 UINT_32 customizedHeight
= pIn
->sliceAlign
/ elementBytes
/ (*pPitch
);
1026 if (customizedHeight
* elementBytes
* (*pPitch
) != pIn
->sliceAlign
)
1028 returnCode
= ADDR_INVALIDPARAMS
;
1030 else if ((pIn
->numSlices
> 1) && ((*pHeight
) != customizedHeight
))
1032 returnCode
= ADDR_INVALIDPARAMS
;
1036 *pHeight
= customizedHeight
;
1046 ************************************************************************************************************************
1047 * Lib::ComputeSurfaceInfoLinear
1050 * Internal function to calculate alignment for linear swizzle surface
1054 ************************************************************************************************************************
1056 ADDR_E_RETURNCODE
Lib::ComputeSurfaceInfoLinear(
1057 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
1058 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
1061 return HwlComputeSurfaceInfoLinear(pIn
, pOut
);
1065 ************************************************************************************************************************
1066 * Lib::ComputeSurfaceInfoTiled
1069 * Internal function to calculate alignment for tiled swizzle surface
1073 ************************************************************************************************************************
1075 ADDR_E_RETURNCODE
Lib::ComputeSurfaceInfoTiled(
1076 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
1077 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
1080 return HwlComputeSurfaceInfoTiled(pIn
, pOut
);
1084 ************************************************************************************************************************
1085 * Lib::ComputeSurfaceAddrFromCoordLinear
1088 * Internal function to calculate address from coord for linear swizzle surface
1092 ************************************************************************************************************************
1094 ADDR_E_RETURNCODE
Lib::ComputeSurfaceAddrFromCoordLinear(
1095 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1096 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1099 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1100 BOOL_32 valid
= (pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1) && (pIn
->pipeBankXor
== 0);
1104 if (IsTex1d(pIn
->resourceType
))
1106 valid
= (pIn
->y
== 0);
1112 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
1113 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
1114 ADDR2_MIP_INFO mipInfo
[MaxMipLevels
];
1116 localIn
.bpp
= pIn
->bpp
;
1117 localIn
.flags
= pIn
->flags
;
1118 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
1119 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
1120 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
1121 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
1122 localIn
.resourceType
= pIn
->resourceType
;
1124 if (localIn
.numMipLevels
<= 1)
1126 localIn
.pitchInElement
= pIn
->pitchInElement
;
1129 localOut
.pMipInfo
= mipInfo
;
1131 returnCode
= ComputeSurfaceInfoLinear(&localIn
, &localOut
);
1133 if (returnCode
== ADDR_OK
)
1135 pOut
->addr
= (localOut
.sliceSize
* pIn
->slice
) +
1136 mipInfo
[pIn
->mipId
].offset
+
1137 (pIn
->y
* mipInfo
[pIn
->mipId
].pitch
+ pIn
->x
) * (pIn
->bpp
>> 3);
1138 pOut
->bitPosition
= 0;
1148 returnCode
= ADDR_INVALIDPARAMS
;
1155 ************************************************************************************************************************
1156 * Lib::ComputeSurfaceAddrFromCoordTiled
1159 * Internal function to calculate address from coord for tiled swizzle surface
1163 ************************************************************************************************************************
1165 ADDR_E_RETURNCODE
Lib::ComputeSurfaceAddrFromCoordTiled(
1166 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
, ///< [in] input structure
1167 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
///< [out] output structure
1170 return HwlComputeSurfaceAddrFromCoordTiled(pIn
, pOut
);
1174 ************************************************************************************************************************
1175 * Lib::ComputeSurfaceCoordFromAddrLinear
1178 * Internal function to calculate coord from address for linear swizzle surface
1182 ************************************************************************************************************************
1184 ADDR_E_RETURNCODE
Lib::ComputeSurfaceCoordFromAddrLinear(
1185 const ADDR2_COMPUTE_SURFACE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1186 ADDR2_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1189 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1191 BOOL_32 valid
= (pIn
->numSamples
<= 1) && (pIn
->numFrags
<= 1);
1195 if (IsTex1d(pIn
->resourceType
))
1197 valid
= (pIn
->unalignedHeight
== 1);
1203 ADDR2_COMPUTE_SURFACE_INFO_INPUT localIn
= {0};
1204 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT localOut
= {0};
1205 localIn
.bpp
= pIn
->bpp
;
1206 localIn
.flags
= pIn
->flags
;
1207 localIn
.width
= Max(pIn
->unalignedWidth
, 1u);
1208 localIn
.height
= Max(pIn
->unalignedHeight
, 1u);
1209 localIn
.numSlices
= Max(pIn
->numSlices
, 1u);
1210 localIn
.numMipLevels
= Max(pIn
->numMipLevels
, 1u);
1211 localIn
.resourceType
= pIn
->resourceType
;
1212 if (localIn
.numMipLevels
<= 1)
1214 localIn
.pitchInElement
= pIn
->pitchInElement
;
1216 returnCode
= ComputeSurfaceInfoLinear(&localIn
, &localOut
);
1218 if (returnCode
== ADDR_OK
)
1220 pOut
->slice
= static_cast<UINT_32
>(pIn
->addr
/ localOut
.sliceSize
);
1223 UINT_32 offsetInSlice
= static_cast<UINT_32
>(pIn
->addr
% localOut
.sliceSize
);
1224 UINT_32 elementBytes
= pIn
->bpp
>> 3;
1225 UINT_32 mipOffsetInSlice
= 0;
1226 UINT_32 mipSize
= 0;
1228 for (; mipId
< pIn
->numMipLevels
; mipId
++)
1230 if (IsTex1d(pIn
->resourceType
))
1232 mipSize
= localOut
.pitch
* elementBytes
;
1236 UINT_32 currentMipHeight
= (PowTwoAlign(localIn
.height
, (1 << mipId
))) >> mipId
;
1237 mipSize
= currentMipHeight
* localOut
.pitch
* elementBytes
;
1245 else if ((mipSize
+ mipOffsetInSlice
) > offsetInSlice
)
1251 mipOffsetInSlice
+= mipSize
;
1252 if ((mipId
== (pIn
->numMipLevels
- 1)) ||
1253 (mipOffsetInSlice
>= localOut
.sliceSize
))
1262 pOut
->mipId
= mipId
;
1264 UINT_32 elemOffsetInMip
= (offsetInSlice
- mipOffsetInSlice
) / elementBytes
;
1265 if (IsTex1d(pIn
->resourceType
))
1267 if (elemOffsetInMip
< localOut
.pitch
)
1269 pOut
->x
= elemOffsetInMip
;
1279 pOut
->y
= elemOffsetInMip
/ localOut
.pitch
;
1280 pOut
->x
= elemOffsetInMip
% localOut
.pitch
;
1283 if ((pOut
->slice
>= pIn
->numSlices
) ||
1284 (pOut
->mipId
>= pIn
->numMipLevels
) ||
1285 (pOut
->x
>= Max((pIn
->unalignedWidth
>> pOut
->mipId
), 1u)) ||
1286 (pOut
->y
>= Max((pIn
->unalignedHeight
>> pOut
->mipId
), 1u)) ||
1287 (IsTex3d(pIn
->resourceType
) &&
1288 (FALSE
== Valid3DMipSliceIdConstraint(pIn
->numSlices
,
1304 returnCode
= ADDR_INVALIDPARAMS
;
1311 ************************************************************************************************************************
1312 * Lib::ComputeSurfaceCoordFromAddrTiled
1315 * Internal function to calculate coord from address for tiled swizzle surface
1319 ************************************************************************************************************************
1321 ADDR_E_RETURNCODE
Lib::ComputeSurfaceCoordFromAddrTiled(
1322 const ADDR2_COMPUTE_SURFACE_COORDFROMADDR_INPUT
* pIn
, ///< [in] input structure
1323 ADDR2_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT
* pOut
///< [out] output structure
1326 ADDR_E_RETURNCODE returnCode
= ADDR_NOTIMPLEMENTED
;
1328 ADDR_NOT_IMPLEMENTED();
1334 ************************************************************************************************************************
1335 * Lib::ComputeBlockDimensionForSurf
1338 * Internal function to get block width/height/depth in element from surface input params.
1342 ************************************************************************************************************************
1344 ADDR_E_RETURNCODE
Lib::ComputeBlockDimensionForSurf(
1350 AddrResourceType resourceType
,
1351 AddrSwizzleMode swizzleMode
) const
1353 ADDR_E_RETURNCODE returnCode
= ComputeBlockDimension(pWidth
,
1360 if ((returnCode
== ADDR_OK
) && (numSamples
> 1) && IsThin(resourceType
, swizzleMode
))
1362 const UINT_32 log2blkSize
= GetBlockSizeLog2(swizzleMode
);
1363 const UINT_32 log2sample
= Log2(numSamples
);
1364 const UINT_32 q
= log2sample
>> 1;
1365 const UINT_32 r
= log2sample
& 1;
1367 if (log2blkSize
& 1)
1370 *pHeight
>>= (q
+ r
);
1374 *pWidth
>>= (q
+ r
);
1383 ************************************************************************************************************************
1384 * Lib::ComputeBlockDimension
1387 * Internal function to get block width/height/depth in element without considering MSAA case
1391 ************************************************************************************************************************
1393 ADDR_E_RETURNCODE
Lib::ComputeBlockDimension(
1398 AddrResourceType resourceType
,
1399 AddrSwizzleMode swizzleMode
) const
1401 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
1403 UINT_32 eleBytes
= bpp
>> 3;
1404 UINT_32 microBlockSizeTableIndex
= Log2(eleBytes
);
1405 UINT_32 log2blkSize
= GetBlockSizeLog2(swizzleMode
);
1407 if (IsThin(resourceType
, swizzleMode
))
1409 UINT_32 log2blkSizeIn256B
= log2blkSize
- 8;
1410 UINT_32 widthAmp
= log2blkSizeIn256B
/ 2;
1411 UINT_32 heightAmp
= log2blkSizeIn256B
- widthAmp
;
1413 ADDR_ASSERT(microBlockSizeTableIndex
< sizeof(Block256_2d
) / sizeof(Block256_2d
[0]));
1415 *pWidth
= (Block256_2d
[microBlockSizeTableIndex
].w
<< widthAmp
);
1416 *pHeight
= (Block256_2d
[microBlockSizeTableIndex
].h
<< heightAmp
);
1419 else if (IsThick(resourceType
, swizzleMode
))
1421 UINT_32 log2blkSizeIn1KB
= log2blkSize
- 10;
1422 UINT_32 averageAmp
= log2blkSizeIn1KB
/ 3;
1423 UINT_32 restAmp
= log2blkSizeIn1KB
% 3;
1425 ADDR_ASSERT(microBlockSizeTableIndex
< sizeof(Block1K_3d
) / sizeof(Block1K_3d
[0]));
1427 *pWidth
= Block1K_3d
[microBlockSizeTableIndex
].w
<< averageAmp
;
1428 *pHeight
= Block1K_3d
[microBlockSizeTableIndex
].h
<< (averageAmp
+ (restAmp
/ 2));
1429 *pDepth
= Block1K_3d
[microBlockSizeTableIndex
].d
<< (averageAmp
+ ((restAmp
!= 0) ? 1 : 0));
1433 ADDR_ASSERT_ALWAYS();
1434 returnCode
= ADDR_INVALIDPARAMS
;
1441 ************************************************************************************************************************
1442 * Lib::GetMipTailDim
1445 * Internal function to get out max dimension of first level in mip tail
1448 * Max Width/Height/Depth value of the first mip fitted in mip tail
1449 ************************************************************************************************************************
1451 Dim3d
Lib::GetMipTailDim(
1452 AddrResourceType resourceType
,
1453 AddrSwizzleMode swizzleMode
,
1455 UINT_32 blockHeight
,
1456 UINT_32 blockDepth
) const
1458 Dim3d out
= {blockWidth
, blockHeight
, blockDepth
};
1459 UINT_32 log2blkSize
= GetBlockSizeLog2(swizzleMode
);
1461 if (IsThick(resourceType
, swizzleMode
))
1463 UINT_32 dim
= log2blkSize
% 3;
1480 if (log2blkSize
& 1)
1494 ************************************************************************************************************************
1495 * Lib::ComputeSurface2DMicroBlockOffset
1498 * Internal function to calculate micro block (256B) offset from coord for 2D resource
1501 * micro block (256B) offset for 2D resource
1502 ************************************************************************************************************************
1504 UINT_32
Lib::ComputeSurface2DMicroBlockOffset(
1505 const _ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
) const
1507 ADDR_ASSERT(IsThin(pIn
->resourceType
, pIn
->swizzleMode
));
1509 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
1510 UINT_32 microBlockOffset
= 0;
1511 if (IsStandardSwizzle(pIn
->resourceType
, pIn
->swizzleMode
))
1513 UINT_32 xBits
= pIn
->x
<< log2ElementBytes
;
1514 microBlockOffset
= (xBits
& 0xf) | ((pIn
->y
& 0x3) << 4);
1515 if (log2ElementBytes
< 3)
1517 microBlockOffset
|= (pIn
->y
& 0x4) << 4;
1518 if (log2ElementBytes
== 0)
1520 microBlockOffset
|= (pIn
->y
& 0x8) << 4;
1524 microBlockOffset
|= (xBits
& 0x10) << 3;
1529 microBlockOffset
|= (xBits
& 0x30) << 2;
1532 else if (IsDisplaySwizzle(pIn
->resourceType
, pIn
->swizzleMode
))
1534 if (log2ElementBytes
== 4)
1536 microBlockOffset
= (GetBit(pIn
->x
, 0) << 4) |
1537 (GetBit(pIn
->y
, 0) << 5) |
1538 (GetBit(pIn
->x
, 1) << 6) |
1539 (GetBit(pIn
->y
, 1) << 7);
1543 microBlockOffset
= GetBits(pIn
->x
, 0, 3, log2ElementBytes
) |
1544 GetBits(pIn
->y
, 1, 2, 3 + log2ElementBytes
) |
1545 GetBits(pIn
->x
, 3, 1, 5 + log2ElementBytes
) |
1546 GetBits(pIn
->y
, 3, 1, 6 + log2ElementBytes
);
1547 microBlockOffset
= GetBits(microBlockOffset
, 0, 4, 0) |
1548 (GetBit(pIn
->y
, 0) << 4) |
1549 GetBits(microBlockOffset
, 4, 3, 5);
1552 else if (IsRotateSwizzle(pIn
->swizzleMode
))
1554 microBlockOffset
= GetBits(pIn
->y
, 0, 3, log2ElementBytes
) |
1555 GetBits(pIn
->x
, 1, 2, 3 + log2ElementBytes
) |
1556 GetBits(pIn
->x
, 3, 1, 5 + log2ElementBytes
) |
1557 GetBits(pIn
->y
, 3, 1, 6 + log2ElementBytes
);
1558 microBlockOffset
= GetBits(microBlockOffset
, 0, 4, 0) |
1559 (GetBit(pIn
->x
, 0) << 4) |
1560 GetBits(microBlockOffset
, 4, 3, 5);
1561 if (log2ElementBytes
== 3)
1563 microBlockOffset
= GetBits(microBlockOffset
, 0, 6, 0) |
1564 GetBits(pIn
->x
, 1, 2, 6);
1568 return microBlockOffset
;
1572 ************************************************************************************************************************
1573 * Lib::ComputeSurface3DMicroBlockOffset
1576 * Internal function to calculate micro block (1KB) offset from coord for 3D resource
1579 * micro block (1KB) offset for 3D resource
1580 ************************************************************************************************************************
1582 UINT_32
Lib::ComputeSurface3DMicroBlockOffset(
1583 const _ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
) const
1585 ADDR_ASSERT(IsThick(pIn
->resourceType
, pIn
->swizzleMode
));
1587 UINT_32 log2ElementBytes
= Log2(pIn
->bpp
>> 3);
1588 UINT_32 microBlockOffset
= 0;
1589 if (IsStandardSwizzle(pIn
->resourceType
, pIn
->swizzleMode
))
1591 if (log2ElementBytes
== 0)
1593 microBlockOffset
= ((pIn
->slice
& 4) >> 2) | ((pIn
->y
& 4) >> 1);
1595 else if (log2ElementBytes
== 1)
1597 microBlockOffset
= ((pIn
->slice
& 4) >> 2) | ((pIn
->y
& 4) >> 1);
1599 else if (log2ElementBytes
== 2)
1601 microBlockOffset
= ((pIn
->y
& 4) >> 2) | ((pIn
->x
& 4) >> 1);
1603 else if (log2ElementBytes
== 3)
1605 microBlockOffset
= (pIn
->x
& 6) >> 1;
1609 microBlockOffset
= pIn
->x
& 3;
1612 microBlockOffset
<<= 8;
1614 UINT_32 xBits
= pIn
->x
<< log2ElementBytes
;
1615 microBlockOffset
|= (xBits
& 0xf) | ((pIn
->y
& 0x3) << 4) | ((pIn
->slice
& 0x3) << 6);
1617 else if (IsZOrderSwizzle(pIn
->swizzleMode
))
1621 if (log2ElementBytes
== 0)
1624 (pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->x
& 2) << 1) | ((pIn
->y
& 2) << 2);
1625 microBlockOffset
= microBlockOffset
| ((pIn
->slice
& 3) << 4) | ((pIn
->x
& 4) << 4);
1629 zh
= pIn
->slice
>> 2;
1631 else if (log2ElementBytes
== 1)
1634 (pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->x
& 2) << 1) | ((pIn
->y
& 2) << 2);
1635 microBlockOffset
= (microBlockOffset
<< 1) | ((pIn
->slice
& 3) << 5);
1639 zh
= pIn
->slice
>> 2;
1641 else if (log2ElementBytes
== 2)
1644 (pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->x
& 2) << 1) | ((pIn
->slice
& 1) << 3);
1645 microBlockOffset
= (microBlockOffset
<< 2) | ((pIn
->y
& 2) << 5);
1649 zh
= pIn
->slice
>> 1;
1651 else if (log2ElementBytes
== 3)
1654 (pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->slice
& 1) << 2) | ((pIn
->x
& 2) << 2);
1655 microBlockOffset
<<= 3;
1659 zh
= pIn
->slice
>> 1;
1664 (((pIn
->x
& 1) | ((pIn
->y
& 1) << 1) | ((pIn
->slice
& 1) << 2)) << 4);
1668 zh
= pIn
->slice
>> 1;
1671 microBlockOffset
|= ((MortonGen3d(xh
, yh
, zh
, 1) << 7) & 0x380);
1674 return microBlockOffset
;
1678 ************************************************************************************************************************
1679 * Lib::GetPipeXorBits
1682 * Internal function to get bits number for pipe/se xor operation
1686 ************************************************************************************************************************
1688 UINT_32
Lib::GetPipeXorBits(
1689 UINT_32 macroBlockBits
) const
1691 ADDR_ASSERT(macroBlockBits
>= m_pipeInterleaveLog2
);
1693 // Total available xor bits
1694 UINT_32 xorBits
= macroBlockBits
- m_pipeInterleaveLog2
;
1697 UINT_32 pipeBits
= Min(xorBits
, m_pipesLog2
+ m_seLog2
);
1703 ************************************************************************************************************************
1704 * Lib::GetBankXorBits
1707 * Internal function to get bits number for pipe/se xor operation
1711 ************************************************************************************************************************
1713 UINT_32
Lib::GetBankXorBits(
1714 UINT_32 macroBlockBits
) const
1716 UINT_32 pipeBits
= GetPipeXorBits(macroBlockBits
);
1719 UINT_32 bankBits
= Min(macroBlockBits
- pipeBits
- m_pipeInterleaveLog2
, m_banksLog2
);
1725 ************************************************************************************************************************
1726 * Lib::Addr2GetPreferredSurfaceSetting
1729 * Internal function to get suggested surface information for cliet to use
1733 ************************************************************************************************************************
1735 ADDR_E_RETURNCODE
Lib::Addr2GetPreferredSurfaceSetting(
1736 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
1737 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const
1739 ADDR_E_RETURNCODE returnCode
;
1741 if ((GetFillSizeFieldsFlags() == TRUE
) &&
1742 ((pIn
->size
!= sizeof(ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
)) ||
1743 (pOut
->size
!= sizeof(ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
))))
1745 returnCode
= ADDR_INVALIDPARAMS
;
1749 returnCode
= HwlGetPreferredSurfaceSetting(pIn
, pOut
);
1756 ************************************************************************************************************************
1757 * Lib::ComputeBlock256Equation
1760 * Compute equation for block 256B
1763 * If equation computed successfully
1765 ************************************************************************************************************************
1767 ADDR_E_RETURNCODE
Lib::ComputeBlock256Equation(
1768 AddrResourceType rsrcType
,
1769 AddrSwizzleMode swMode
,
1770 UINT_32 elementBytesLog2
,
1771 ADDR_EQUATION
* pEquation
) const
1773 ADDR_E_RETURNCODE ret
;
1775 if (IsBlock256b(swMode
))
1777 ret
= HwlComputeBlock256Equation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
1781 ADDR_ASSERT_ALWAYS();
1782 ret
= ADDR_INVALIDPARAMS
;
1789 ************************************************************************************************************************
1790 * Lib::ComputeThinEquation
1793 * Compute equation for 2D/3D resource which use THIN mode
1796 * If equation computed successfully
1798 ************************************************************************************************************************
1800 ADDR_E_RETURNCODE
Lib::ComputeThinEquation(
1801 AddrResourceType rsrcType
,
1802 AddrSwizzleMode swMode
,
1803 UINT_32 elementBytesLog2
,
1804 ADDR_EQUATION
* pEquation
) const
1806 ADDR_E_RETURNCODE ret
;
1808 if (IsThin(rsrcType
, swMode
))
1810 ret
= HwlComputeThinEquation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
1814 ADDR_ASSERT_ALWAYS();
1815 ret
= ADDR_INVALIDPARAMS
;
1822 ************************************************************************************************************************
1823 * Lib::ComputeThickEquation
1826 * Compute equation for 3D resource which use THICK mode
1829 * If equation computed successfully
1831 ************************************************************************************************************************
1833 ADDR_E_RETURNCODE
Lib::ComputeThickEquation(
1834 AddrResourceType rsrcType
,
1835 AddrSwizzleMode swMode
,
1836 UINT_32 elementBytesLog2
,
1837 ADDR_EQUATION
* pEquation
) const
1839 ADDR_E_RETURNCODE ret
;
1841 if (IsThick(rsrcType
, swMode
))
1843 ret
= HwlComputeThickEquation(rsrcType
, swMode
, elementBytesLog2
, pEquation
);
1847 ADDR_ASSERT_ALWAYS();
1848 ret
= ADDR_INVALIDPARAMS
;
1855 ************************************************************************************************************************
1856 * Lib::ComputeQbStereoInfo
1859 * Get quad buffer stereo information
1862 ************************************************************************************************************************
1864 VOID
Lib::ComputeQbStereoInfo(
1865 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [in,out] updated pOut+pStereoInfo
1868 ADDR_ASSERT(pOut
->bpp
>= 8);
1869 ADDR_ASSERT((pOut
->surfSize
% pOut
->baseAlign
) == 0);
1871 // Save original height
1872 pOut
->pStereoInfo
->eyeHeight
= pOut
->height
;
1875 pOut
->pStereoInfo
->rightOffset
= static_cast<UINT_32
>(pOut
->surfSize
);
1880 ADDR_ASSERT(pOut
->height
<= MaxSurfaceHeight
);
1882 pOut
->pixelHeight
<<= 1;
1885 pOut
->surfSize
<<= 1;