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 Contgfx9ns the Gfx9Lib class definition.
31 ************************************************************************************************************************
34 #ifndef __GFX9_ADDR_LIB_H__
35 #define __GFX9_ADDR_LIB_H__
46 ************************************************************************************************************************
47 * @brief GFX9 specific settings structure.
48 ************************************************************************************************************************
50 struct Gfx9ChipSettings
54 // Asic/Generation name
55 UINT_32 isArcticIsland
: 1;
58 UINT_32 reserved0
: 29;
60 // Display engine IP version name
63 UINT_32 reserved1
: 29;
65 // Misc configuration bits
66 UINT_32 metaBaseAlignFix
: 1;
67 UINT_32 depthPipeXorDisable
: 1;
68 UINT_32 htileAlignFix
: 1;
69 UINT_32 applyAliasFix
: 1;
70 UINT_32 reserved2
: 28;
75 ************************************************************************************************************************
76 * @brief GFX9 data surface type.
77 ************************************************************************************************************************
87 ************************************************************************************************************************
88 * @brief GFX9 meta equation parameters
89 ************************************************************************************************************************
94 UINT_32 elementBytesLog2
;
95 UINT_32 numSamplesLog2
;
96 ADDR2_META_FLAGS metaFlag
;
97 Gfx9DataType dataSurfaceType
;
98 AddrSwizzleMode swizzleMode
;
99 AddrResourceType resourceType
;
100 UINT_32 metaBlkWidthLog2
;
101 UINT_32 metaBlkHeightLog2
;
102 UINT_32 metaBlkDepthLog2
;
103 UINT_32 compBlkWidthLog2
;
104 UINT_32 compBlkHeightLog2
;
105 UINT_32 compBlkDepthLog2
;
109 ************************************************************************************************************************
110 * @brief This class is the GFX9 specific address library
112 ************************************************************************************************************************
114 class Gfx9Lib
: public Lib
117 /// Creates Gfx9Lib object
118 static Addr::Lib
* CreateObj(const Client
* pClient
)
120 VOID
* pMem
= Object::ClientAlloc(sizeof(Gfx9Lib
), pClient
);
121 return (pMem
!= NULL
) ? new (pMem
) Gfx9Lib(pClient
) : NULL
;
124 virtual BOOL_32
IsValidDisplaySwizzleMode(
125 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const;
128 Gfx9Lib(const Client
* pClient
);
131 virtual BOOL_32
HwlIsStandardSwizzle(
132 AddrResourceType resourceType
,
133 AddrSwizzleMode swizzleMode
) const
135 return m_swizzleModeTable
[swizzleMode
].isStd
||
136 (IsTex3d(resourceType
) && m_swizzleModeTable
[swizzleMode
].isDisp
);
139 virtual BOOL_32
HwlIsDisplaySwizzle(
140 AddrResourceType resourceType
,
141 AddrSwizzleMode swizzleMode
) const
143 return IsTex2d(resourceType
) && m_swizzleModeTable
[swizzleMode
].isDisp
;
146 virtual BOOL_32
HwlIsThin(
147 AddrResourceType resourceType
,
148 AddrSwizzleMode swizzleMode
) const
150 return ((IsTex2d(resourceType
) == TRUE
) ||
151 ((IsTex3d(resourceType
) == TRUE
) &&
152 (m_swizzleModeTable
[swizzleMode
].isZ
== FALSE
) &&
153 (m_swizzleModeTable
[swizzleMode
].isStd
== FALSE
)));
156 virtual BOOL_32
HwlIsThick(
157 AddrResourceType resourceType
,
158 AddrSwizzleMode swizzleMode
) const
160 return (IsTex3d(resourceType
) &&
161 (m_swizzleModeTable
[swizzleMode
].isZ
|| m_swizzleModeTable
[swizzleMode
].isStd
));
164 virtual ADDR_E_RETURNCODE
HwlComputeHtileInfo(
165 const ADDR2_COMPUTE_HTILE_INFO_INPUT
* pIn
,
166 ADDR2_COMPUTE_HTILE_INFO_OUTPUT
* pOut
) const;
168 virtual ADDR_E_RETURNCODE
HwlComputeCmaskInfo(
169 const ADDR2_COMPUTE_CMASK_INFO_INPUT
* pIn
,
170 ADDR2_COMPUTE_CMASK_INFO_OUTPUT
* pOut
) const;
172 virtual ADDR_E_RETURNCODE
HwlComputeDccInfo(
173 const ADDR2_COMPUTE_DCCINFO_INPUT
* pIn
,
174 ADDR2_COMPUTE_DCCINFO_OUTPUT
* pOut
) const;
176 virtual ADDR_E_RETURNCODE
HwlComputeCmaskAddrFromCoord(
177 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
,
178 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
);
180 virtual ADDR_E_RETURNCODE
HwlComputeHtileAddrFromCoord(
181 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
,
182 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
);
184 virtual ADDR_E_RETURNCODE
HwlComputeHtileCoordFromAddr(
185 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
,
186 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
);
188 virtual ADDR_E_RETURNCODE
HwlComputeDccAddrFromCoord(
189 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
,
190 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
);
192 virtual UINT_32
HwlGetEquationIndex(
193 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
194 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
) const;
196 virtual ADDR_E_RETURNCODE
HwlComputeBlock256Equation(
197 AddrResourceType rsrcType
,
198 AddrSwizzleMode swMode
,
199 UINT_32 elementBytesLog2
,
200 ADDR_EQUATION
* pEquation
) const;
202 virtual ADDR_E_RETURNCODE
HwlComputeThinEquation(
203 AddrResourceType rsrcType
,
204 AddrSwizzleMode swMode
,
205 UINT_32 elementBytesLog2
,
206 ADDR_EQUATION
* pEquation
) const;
208 virtual ADDR_E_RETURNCODE
HwlComputeThickEquation(
209 AddrResourceType rsrcType
,
210 AddrSwizzleMode swMode
,
211 UINT_32 elementBytesLog2
,
212 ADDR_EQUATION
* pEquation
) const;
214 // Get equation table pointer and number of equations
215 virtual UINT_32
HwlGetEquationTableInfo(const ADDR_EQUATION
** ppEquationTable
) const
217 *ppEquationTable
= m_equationTable
;
219 return m_numEquations
;
222 virtual BOOL_32
IsEquationSupported(
223 AddrResourceType rsrcType
,
224 AddrSwizzleMode swMode
,
225 UINT_32 elementBytesLog2
) const;
227 virtual UINT_32
HwlComputeSurfaceBaseAlign(AddrSwizzleMode swizzleMode
) const
231 if (IsXor(swizzleMode
))
233 baseAlign
= GetBlockSize(swizzleMode
);
243 virtual ADDR_E_RETURNCODE
HwlComputePipeBankXor(
244 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
245 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
) const;
247 virtual ADDR_E_RETURNCODE
HwlComputeSlicePipeBankXor(
248 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
249 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
) const;
251 virtual ADDR_E_RETURNCODE
HwlComputeSubResourceOffsetForSwizzlePattern(
252 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
253 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
) const;
255 virtual ADDR_E_RETURNCODE
HwlGetPreferredSurfaceSetting(
256 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
257 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const;
259 virtual ADDR_E_RETURNCODE
HwlComputeSurfaceInfoSanityCheck(
260 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const;
262 virtual ADDR_E_RETURNCODE
HwlComputeSurfaceInfoTiled(
263 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
264 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
) const;
266 virtual ADDR_E_RETURNCODE
HwlComputeSurfaceInfoLinear(
267 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
268 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
) const;
270 virtual ADDR_E_RETURNCODE
HwlComputeSurfaceAddrFromCoordTiled(
271 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
,
272 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
) const;
274 // Initialize equation table
275 VOID
InitEquationTable();
277 ADDR_E_RETURNCODE
ComputeStereoInfo(
278 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
279 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
,
280 UINT_32
* pHeightAlign
) const;
282 UINT_32
GetMipChainInfo(
283 AddrResourceType resourceType
,
284 AddrSwizzleMode swizzleMode
,
293 ADDR2_MIP_INFO
* pMipInfo
) const;
295 VOID
GetMetaMiptailInfo(
296 ADDR2_META_MIP_INFO
* pInfo
,
298 UINT_32 numMipInTail
,
299 Dim3d
* pMetaBlkDim
) const;
301 Dim3d
GetMipStartPos(
302 AddrResourceType resourceType
,
303 AddrSwizzleMode swizzleMode
,
311 UINT_32 log2ElementBytes
,
312 UINT_32
* pMipTailBytesOffset
) const;
314 AddrMajorMode
GetMajorMode(
315 AddrResourceType resourceType
,
316 AddrSwizzleMode swizzleMode
,
317 UINT_32 mip0WidthInBlk
,
318 UINT_32 mip0HeightInBlk
,
319 UINT_32 mip0DepthInBlk
) const
321 BOOL_32 yMajor
= (mip0WidthInBlk
< mip0HeightInBlk
);
322 BOOL_32 xMajor
= (yMajor
== FALSE
);
324 if (IsThick(resourceType
, swizzleMode
))
326 yMajor
= yMajor
&& (mip0HeightInBlk
>= mip0DepthInBlk
);
327 xMajor
= xMajor
&& (mip0WidthInBlk
>= mip0DepthInBlk
);
330 AddrMajorMode majorMode
;
333 majorMode
= ADDR_MAJOR_X
;
337 majorMode
= ADDR_MAJOR_Y
;
341 majorMode
= ADDR_MAJOR_Z
;
347 Dim3d
GetDccCompressBlk(
348 AddrResourceType resourceType
,
349 AddrSwizzleMode swizzleMode
,
352 UINT_32 index
= Log2(bpp
>> 3);
353 Dim3d compressBlkDim
;
355 if (IsThin(resourceType
, swizzleMode
))
357 compressBlkDim
.w
= Block256_2d
[index
].w
;
358 compressBlkDim
.h
= Block256_2d
[index
].h
;
359 compressBlkDim
.d
= 1;
361 else if (IsStandardSwizzle(resourceType
, swizzleMode
))
363 compressBlkDim
= Block256_3dS
[index
];
367 compressBlkDim
= Block256_3dZ
[index
];
370 return compressBlkDim
;
374 static const UINT_32 MaxSeLog2
= 3;
375 static const UINT_32 MaxRbPerSeLog2
= 2;
377 static const Dim3d Block256_3dS
[MaxNumOfBpp
];
378 static const Dim3d Block256_3dZ
[MaxNumOfBpp
];
380 static const UINT_32 MipTailOffset256B
[];
382 static const SwizzleModeFlags SwizzleModeTable
[ADDR_SW_MAX_TYPE
];
384 // Max number of swizzle mode supported for equation
385 static const UINT_32 MaxSwMode
= 32;
386 // Max number of resource type (2D/3D) supported for equation
387 static const UINT_32 MaxRsrcType
= 2;
388 // Max number of bpp (8bpp/16bpp/32bpp/64bpp/128bpp)
389 static const UINT_32 MaxElementBytesLog2
= 5;
390 // Almost all swizzle mode + resource type support equation
391 static const UINT_32 EquationTableSize
= MaxElementBytesLog2
* MaxSwMode
* MaxRsrcType
;
393 ADDR_EQUATION m_equationTable
[EquationTableSize
];
395 // Number of equation entries in the table
396 UINT_32 m_numEquations
;
397 // Equation lookup table according to bpp and tile index
398 UINT_32 m_equationLookupTable
[MaxRsrcType
][MaxSwMode
][MaxElementBytesLog2
];
400 static const UINT_32 MaxCachedMetaEq
= 2;
403 virtual ADDR_E_RETURNCODE
HwlGetMaxAlignments(
404 ADDR_GET_MAX_ALIGNMENTS_OUTPUT
* pOut
) const;
406 virtual BOOL_32
HwlInitGlobalParams(
407 const ADDR_CREATE_INPUT
* pCreateIn
);
409 VOID
GetRbEquation(CoordEq
* pRbEq
, UINT_32 rbPerSeLog2
, UINT_32 seLog2
) const;
411 VOID
GetDataEquation(CoordEq
* pDataEq
, Gfx9DataType dataSurfaceType
,
412 AddrSwizzleMode swizzleMode
, AddrResourceType resourceType
,
413 UINT_32 elementBytesLog2
, UINT_32 numSamplesLog2
) const;
415 VOID
GetPipeEquation(CoordEq
* pPipeEq
, CoordEq
* pDataEq
,
416 UINT_32 pipeInterleaveLog2
, UINT_32 numPipesLog2
,
417 UINT_32 numSamplesLog2
, Gfx9DataType dataSurfaceType
,
418 AddrSwizzleMode swizzleMode
, AddrResourceType resourceType
) const;
420 VOID
GenMetaEquation(CoordEq
* pMetaEq
, UINT_32 maxMip
,
421 UINT_32 elementBytesLog2
, UINT_32 numSamplesLog2
,
422 ADDR2_META_FLAGS metaFlag
, Gfx9DataType dataSurfaceType
,
423 AddrSwizzleMode swizzleMode
, AddrResourceType resourceType
,
424 UINT_32 metaBlkWidthLog2
, UINT_32 metaBlkHeightLog2
,
425 UINT_32 metaBlkDepthLog2
, UINT_32 compBlkWidthLog2
,
426 UINT_32 compBlkHeightLog2
, UINT_32 compBlkDepthLog2
) const;
428 const CoordEq
* GetMetaEquation(const MetaEqParams
& metaEqParams
);
430 virtual ChipFamily
HwlConvertChipFamily(UINT_32 uChipFamily
, UINT_32 uChipRevision
);
432 VOID
GetMetaMipInfo(UINT_32 numMipLevels
, Dim3d
* pMetaBlkDim
,
433 BOOL_32 dataThick
, ADDR2_META_MIP_INFO
* pInfo
,
434 UINT_32 mip0Width
, UINT_32 mip0Height
, UINT_32 mip0Depth
,
435 UINT_32
* pNumMetaBlkX
, UINT_32
* pNumMetaBlkY
, UINT_32
* pNumMetaBlkZ
) const;
437 ADDR_E_RETURNCODE
ComputeSurfaceLinearPadding(
438 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
439 UINT_32
* pMipmap0PaddedWidth
,
440 UINT_32
* pSlice0PaddedHeight
,
441 ADDR2_MIP_INFO
* pMipInfo
= NULL
) const;
443 Gfx9ChipSettings m_settings
;
445 CoordEq m_cachedMetaEq
[MaxCachedMetaEq
];
446 MetaEqParams m_cachedMetaEqKey
[MaxCachedMetaEq
];
447 UINT_32 m_metaEqOverrideIndex
;