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 reserved2
: 30;
73 ************************************************************************************************************************
74 * @brief GFX9 data surface type.
75 ************************************************************************************************************************
85 ************************************************************************************************************************
86 * @brief This class is the GFX9 specific address library
88 ************************************************************************************************************************
90 class Gfx9Lib
: public Lib
93 /// Creates Gfx9Lib object
94 static Addr::Lib
* CreateObj(const Client
* pClient
)
96 VOID
* pMem
= Object::ClientAlloc(sizeof(Gfx9Lib
), pClient
);
97 return (pMem
!= NULL
) ? new (pMem
) Gfx9Lib(pClient
) : NULL
;
100 virtual BOOL_32
IsValidDisplaySwizzleMode(
101 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const;
104 Gfx9Lib(const Client
* pClient
);
107 virtual BOOL_32
HwlIsStandardSwizzle(
108 AddrResourceType resourceType
,
109 AddrSwizzleMode swizzleMode
) const
111 return m_swizzleModeTable
[swizzleMode
].isStd
||
112 (IsTex3d(resourceType
) && m_swizzleModeTable
[swizzleMode
].isDisp
);
115 virtual BOOL_32
HwlIsDisplaySwizzle(
116 AddrResourceType resourceType
,
117 AddrSwizzleMode swizzleMode
) const
119 return IsTex2d(resourceType
) && m_swizzleModeTable
[swizzleMode
].isDisp
;
122 virtual BOOL_32
HwlIsThin(
123 AddrResourceType resourceType
,
124 AddrSwizzleMode swizzleMode
) const
126 return ((IsTex2d(resourceType
) == TRUE
) ||
127 ((IsTex3d(resourceType
) == TRUE
) &&
128 (m_swizzleModeTable
[swizzleMode
].isZ
== FALSE
) &&
129 (m_swizzleModeTable
[swizzleMode
].isStd
== FALSE
)));
132 virtual BOOL_32
HwlIsThick(
133 AddrResourceType resourceType
,
134 AddrSwizzleMode swizzleMode
) const
136 return (IsTex3d(resourceType
) &&
137 (m_swizzleModeTable
[swizzleMode
].isZ
|| m_swizzleModeTable
[swizzleMode
].isStd
));
140 virtual ADDR_E_RETURNCODE
HwlComputeHtileInfo(
141 const ADDR2_COMPUTE_HTILE_INFO_INPUT
* pIn
,
142 ADDR2_COMPUTE_HTILE_INFO_OUTPUT
* pOut
) const;
144 virtual ADDR_E_RETURNCODE
HwlComputeCmaskInfo(
145 const ADDR2_COMPUTE_CMASK_INFO_INPUT
* pIn
,
146 ADDR2_COMPUTE_CMASK_INFO_OUTPUT
* pOut
) const;
148 virtual ADDR_E_RETURNCODE
HwlComputeDccInfo(
149 const ADDR2_COMPUTE_DCCINFO_INPUT
* pIn
,
150 ADDR2_COMPUTE_DCCINFO_OUTPUT
* pOut
) const;
152 virtual ADDR_E_RETURNCODE
HwlComputeCmaskAddrFromCoord(
153 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT
* pIn
,
154 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT
* pOut
) const;
156 virtual ADDR_E_RETURNCODE
HwlComputeHtileAddrFromCoord(
157 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT
* pIn
,
158 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT
* pOut
) const;
160 virtual ADDR_E_RETURNCODE
HwlComputeHtileCoordFromAddr(
161 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT
* pIn
,
162 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT
* pOut
) const;
164 virtual ADDR_E_RETURNCODE
HwlComputeDccAddrFromCoord(
165 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT
* pIn
,
166 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT
* pOut
) const;
168 virtual UINT_32
HwlGetEquationIndex(
169 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
170 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
) const;
172 virtual ADDR_E_RETURNCODE
HwlComputeBlock256Equation(
173 AddrResourceType rsrcType
,
174 AddrSwizzleMode swMode
,
175 UINT_32 elementBytesLog2
,
176 ADDR_EQUATION
* pEquation
) const;
178 virtual ADDR_E_RETURNCODE
HwlComputeThinEquation(
179 AddrResourceType rsrcType
,
180 AddrSwizzleMode swMode
,
181 UINT_32 elementBytesLog2
,
182 ADDR_EQUATION
* pEquation
) const;
184 virtual ADDR_E_RETURNCODE
HwlComputeThickEquation(
185 AddrResourceType rsrcType
,
186 AddrSwizzleMode swMode
,
187 UINT_32 elementBytesLog2
,
188 ADDR_EQUATION
* pEquation
) const;
190 // Get equation table pointer and number of equations
191 virtual UINT_32
HwlGetEquationTableInfo(const ADDR_EQUATION
** ppEquationTable
) const
193 *ppEquationTable
= m_equationTable
;
195 return m_numEquations
;
198 virtual BOOL_32
IsEquationSupported(
199 AddrResourceType rsrcType
,
200 AddrSwizzleMode swMode
,
201 UINT_32 elementBytesLog2
) const;
203 virtual UINT_32
HwlComputeSurfaceBaseAlign(AddrSwizzleMode swizzleMode
) const
207 if (IsXor(swizzleMode
))
209 if (m_settings
.isVega10
|| m_settings
.isRaven
)
211 baseAlign
= GetBlockSize(swizzleMode
);
215 UINT_32 blockSizeLog2
= GetBlockSizeLog2(swizzleMode
);
216 UINT_32 pipeBits
= GetPipeXorBits(blockSizeLog2
);
217 UINT_32 bankBits
= GetBankXorBits(blockSizeLog2
);
218 baseAlign
= 1 << (Min(blockSizeLog2
, m_pipeInterleaveLog2
+ pipeBits
+ bankBits
));
229 virtual ADDR_E_RETURNCODE
HwlComputePipeBankXor(
230 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT
* pIn
,
231 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT
* pOut
) const;
233 virtual ADDR_E_RETURNCODE
HwlComputeSlicePipeBankXor(
234 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT
* pIn
,
235 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT
* pOut
) const;
237 virtual ADDR_E_RETURNCODE
HwlComputeSubResourceOffsetForSwizzlePattern(
238 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT
* pIn
,
239 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT
* pOut
) const;
241 virtual ADDR_E_RETURNCODE
HwlGetPreferredSurfaceSetting(
242 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT
* pIn
,
243 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT
* pOut
) const;
245 virtual ADDR_E_RETURNCODE
HwlComputeSurfaceInfoSanityCheck(
246 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
) const;
248 virtual ADDR_E_RETURNCODE
HwlComputeSurfaceInfoTiled(
249 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
250 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
) const;
252 virtual ADDR_E_RETURNCODE
HwlComputeSurfaceAddrFromCoordTiled(
253 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT
* pIn
,
254 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT
* pOut
) const;
256 // Initialize equation table
257 VOID
InitEquationTable();
259 ADDR_E_RETURNCODE
ComputeStereoInfo(
260 const ADDR2_COMPUTE_SURFACE_INFO_INPUT
* pIn
,
261 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
,
262 UINT_32
* pHeightAlign
) const;
264 UINT_32
GetMipChainInfo(
265 AddrResourceType resourceType
,
266 AddrSwizzleMode swizzleMode
,
275 ADDR2_MIP_INFO
* pMipInfo
) const;
277 VOID
GetMetaMiptailInfo(
278 ADDR2_META_MIP_INFO
* pInfo
,
280 UINT_32 numMipInTail
,
281 Dim3d
* pMetaBlkDim
) const;
283 Dim3d
GetMipStartPos(
284 AddrResourceType resourceType
,
285 AddrSwizzleMode swizzleMode
,
293 UINT_32 log2ElementBytes
,
294 UINT_32
* pMipTailBytesOffset
) const;
296 AddrMajorMode
GetMajorMode(
297 AddrResourceType resourceType
,
298 AddrSwizzleMode swizzleMode
,
299 UINT_32 mip0WidthInBlk
,
300 UINT_32 mip0HeightInBlk
,
301 UINT_32 mip0DepthInBlk
) const
303 BOOL_32 yMajor
= (mip0WidthInBlk
< mip0HeightInBlk
);
304 BOOL_32 xMajor
= (yMajor
== FALSE
);
306 if (IsThick(resourceType
, swizzleMode
))
308 yMajor
= yMajor
&& (mip0HeightInBlk
>= mip0DepthInBlk
);
309 xMajor
= xMajor
&& (mip0WidthInBlk
>= mip0DepthInBlk
);
312 AddrMajorMode majorMode
;
315 majorMode
= ADDR_MAJOR_X
;
319 majorMode
= ADDR_MAJOR_Y
;
323 majorMode
= ADDR_MAJOR_Z
;
329 Dim3d
GetDccCompressBlk(
330 AddrResourceType resourceType
,
331 AddrSwizzleMode swizzleMode
,
334 UINT_32 index
= Log2(bpp
>> 3);
335 Dim3d compressBlkDim
;
337 if (IsThin(resourceType
, swizzleMode
))
339 compressBlkDim
.w
= Block256_2d
[index
].w
;
340 compressBlkDim
.h
= Block256_2d
[index
].h
;
341 compressBlkDim
.d
= 1;
343 else if (IsStandardSwizzle(resourceType
, swizzleMode
))
345 compressBlkDim
= Block256_3dS
[index
];
349 compressBlkDim
= Block256_3dZ
[index
];
352 return compressBlkDim
;
355 static const Dim3d Block256_3dS
[MaxNumOfBpp
];
356 static const Dim3d Block256_3dZ
[MaxNumOfBpp
];
358 static const UINT_32 MipTailOffset256B
[];
360 static const SwizzleModeFlags SwizzleModeTable
[ADDR_SW_MAX_TYPE
];
362 // Max number of swizzle mode supported for equation
363 static const UINT_32 MaxSwMode
= 32;
364 // Max number of resource type (2D/3D) supported for equation
365 static const UINT_32 MaxRsrcType
= 2;
366 // Max number of bpp (8bpp/16bpp/32bpp/64bpp/128bpp)
367 static const UINT_32 MaxElementBytesLog2
= 5;
368 // Almost all swizzle mode + resource type support equation
369 static const UINT_32 EquationTableSize
= MaxElementBytesLog2
* MaxSwMode
* MaxRsrcType
;
371 ADDR_EQUATION m_equationTable
[EquationTableSize
];
373 // Number of equation entries in the table
374 UINT_32 m_numEquations
;
375 // Equation lookup table according to bpp and tile index
376 UINT_32 m_equationLookupTable
[MaxRsrcType
][MaxSwMode
][MaxElementBytesLog2
];
379 virtual ADDR_E_RETURNCODE
HwlGetMaxAlignments(
380 ADDR_GET_MAX_ALIGNMENTS_OUTPUT
* pOut
) const;
382 virtual BOOL_32
HwlInitGlobalParams(
383 const ADDR_CREATE_INPUT
* pCreateIn
);
385 static VOID
GetRbEquation(CoordEq
* pRbEq
, UINT_32 rbPerSeLog2
, UINT_32 seLog2
);
387 VOID
GetDataEquation(CoordEq
* pDataEq
, Gfx9DataType dataSurfaceType
,
388 AddrSwizzleMode swizzleMode
, AddrResourceType resourceType
,
389 UINT_32 elementBytesLog2
, UINT_32 numSamplesLog2
) const;
391 VOID
GetPipeEquation(CoordEq
* pPipeEq
, CoordEq
* pDataEq
,
392 UINT_32 pipeInterleaveLog2
, UINT_32 numPipesLog2
,
393 UINT_32 numSamplesLog2
, Gfx9DataType dataSurfaceType
,
394 AddrSwizzleMode swizzleMode
, AddrResourceType resourceType
) const;
396 VOID
GetMetaEquation(CoordEq
* pMetaEq
, UINT_32 maxMip
,
397 UINT_32 elementBytesLog2
, UINT_32 numSamplesLog2
,
398 ADDR2_META_FLAGS metaFlag
, Gfx9DataType dataSurfaceType
,
399 AddrSwizzleMode swizzleMode
, AddrResourceType resourceType
,
400 UINT_32 metaBlkWidthLog2
, UINT_32 metaBlkHeightLog2
,
401 UINT_32 metaBlkDepthLog2
, UINT_32 compBlkWidthLog2
,
402 UINT_32 compBlkHeightLog2
, UINT_32 compBlkDepthLog2
) const;
404 virtual ChipFamily
HwlConvertChipFamily(UINT_32 uChipFamily
, UINT_32 uChipRevision
);
406 VOID
GetMetaMipInfo(UINT_32 numMipLevels
, Dim3d
* pMetaBlkDim
,
407 BOOL_32 dataThick
, ADDR2_META_MIP_INFO
* pInfo
,
408 UINT_32 mip0Width
, UINT_32 mip0Height
, UINT_32 mip0Depth
,
409 UINT_32
* pNumMetaBlkX
, UINT_32
* pNumMetaBlkY
, UINT_32
* pNumMetaBlkZ
) const;
411 Gfx9ChipSettings m_settings
;