418ccac51421aeeea7bf85e8f45518de6ccd2dbe
[mesa.git] / src / amd / addrlib / gfx9 / gfx9addrlib.h
1 /*
2 * Copyright © 2017 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
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:
12 *
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.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 */
26
27 /**
28 ************************************************************************************************************************
29 * @file gfx9addrlib.h
30 * @brief Contgfx9ns the Gfx9Lib class definition.
31 ************************************************************************************************************************
32 */
33
34 #ifndef __GFX9_ADDR_LIB_H__
35 #define __GFX9_ADDR_LIB_H__
36
37 #include "addrlib2.h"
38 #include "coord.h"
39
40 namespace Addr
41 {
42 namespace V2
43 {
44
45 /**
46 ************************************************************************************************************************
47 * @brief GFX9 specific settings structure.
48 ************************************************************************************************************************
49 */
50 struct Gfx9ChipSettings
51 {
52 struct
53 {
54 // Asic/Generation name
55 UINT_32 isArcticIsland : 1;
56 UINT_32 isVega10 : 1;
57 UINT_32 isRaven : 1;
58 UINT_32 reserved0 : 29;
59
60 // Display engine IP version name
61 UINT_32 isDce12 : 1;
62 UINT_32 isDcn1 : 1;
63 UINT_32 reserved1 : 29;
64
65 // Misc configuration bits
66 UINT_32 metaBaseAlignFix : 1;
67 UINT_32 depthPipeXorDisable : 1;
68 UINT_32 reserved2 : 30;
69 };
70 };
71
72 /**
73 ************************************************************************************************************************
74 * @brief GFX9 data surface type.
75 ************************************************************************************************************************
76 */
77 enum Gfx9DataType
78 {
79 Gfx9DataColor,
80 Gfx9DataDepthStencil,
81 Gfx9DataFmask
82 };
83
84 /**
85 ************************************************************************************************************************
86 * @brief This class is the GFX9 specific address library
87 * function set.
88 ************************************************************************************************************************
89 */
90 class Gfx9Lib : public Lib
91 {
92 public:
93 /// Creates Gfx9Lib object
94 static Addr::Lib* CreateObj(const Client* pClient)
95 {
96 VOID* pMem = Object::ClientAlloc(sizeof(Gfx9Lib), pClient);
97 return (pMem != NULL) ? new (pMem) Gfx9Lib(pClient) : NULL;
98 }
99
100 virtual BOOL_32 IsValidDisplaySwizzleMode(
101 const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn) const;
102
103 protected:
104 Gfx9Lib(const Client* pClient);
105 virtual ~Gfx9Lib();
106
107 virtual BOOL_32 HwlIsStandardSwizzle(
108 AddrResourceType resourceType,
109 AddrSwizzleMode swizzleMode) const
110 {
111 return m_swizzleModeTable[swizzleMode].isStd ||
112 (IsTex3d(resourceType) && m_swizzleModeTable[swizzleMode].isDisp);
113 }
114
115 virtual BOOL_32 HwlIsDisplaySwizzle(
116 AddrResourceType resourceType,
117 AddrSwizzleMode swizzleMode) const
118 {
119 return IsTex2d(resourceType) && m_swizzleModeTable[swizzleMode].isDisp;
120 }
121
122 virtual BOOL_32 HwlIsThin(
123 AddrResourceType resourceType,
124 AddrSwizzleMode swizzleMode) const
125 {
126 return ((IsTex2d(resourceType) == TRUE) ||
127 ((IsTex3d(resourceType) == TRUE) &&
128 (m_swizzleModeTable[swizzleMode].isZ == FALSE) &&
129 (m_swizzleModeTable[swizzleMode].isStd == FALSE)));
130 }
131
132 virtual BOOL_32 HwlIsThick(
133 AddrResourceType resourceType,
134 AddrSwizzleMode swizzleMode) const
135 {
136 return (IsTex3d(resourceType) &&
137 (m_swizzleModeTable[swizzleMode].isZ || m_swizzleModeTable[swizzleMode].isStd));
138 }
139
140 virtual ADDR_E_RETURNCODE HwlComputeHtileInfo(
141 const ADDR2_COMPUTE_HTILE_INFO_INPUT* pIn,
142 ADDR2_COMPUTE_HTILE_INFO_OUTPUT* pOut) const;
143
144 virtual ADDR_E_RETURNCODE HwlComputeCmaskInfo(
145 const ADDR2_COMPUTE_CMASK_INFO_INPUT* pIn,
146 ADDR2_COMPUTE_CMASK_INFO_OUTPUT* pOut) const;
147
148 virtual ADDR_E_RETURNCODE HwlComputeDccInfo(
149 const ADDR2_COMPUTE_DCCINFO_INPUT* pIn,
150 ADDR2_COMPUTE_DCCINFO_OUTPUT* pOut) const;
151
152 virtual ADDR_E_RETURNCODE HwlComputeCmaskAddrFromCoord(
153 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT* pIn,
154 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT* pOut) const;
155
156 virtual ADDR_E_RETURNCODE HwlComputeHtileAddrFromCoord(
157 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT* pIn,
158 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT* pOut) const;
159
160 virtual ADDR_E_RETURNCODE HwlComputeHtileCoordFromAddr(
161 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT* pIn,
162 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT* pOut) const;
163
164 virtual ADDR_E_RETURNCODE HwlComputeDccAddrFromCoord(
165 const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT* pIn,
166 ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT* pOut) const;
167
168 virtual UINT_32 HwlGetEquationIndex(
169 const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn,
170 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
171
172 virtual ADDR_E_RETURNCODE HwlComputeBlock256Equation(
173 AddrResourceType rsrcType,
174 AddrSwizzleMode swMode,
175 UINT_32 elementBytesLog2,
176 ADDR_EQUATION* pEquation) const;
177
178 virtual ADDR_E_RETURNCODE HwlComputeThinEquation(
179 AddrResourceType rsrcType,
180 AddrSwizzleMode swMode,
181 UINT_32 elementBytesLog2,
182 ADDR_EQUATION* pEquation) const;
183
184 virtual ADDR_E_RETURNCODE HwlComputeThickEquation(
185 AddrResourceType rsrcType,
186 AddrSwizzleMode swMode,
187 UINT_32 elementBytesLog2,
188 ADDR_EQUATION* pEquation) const;
189
190 // Get equation table pointer and number of equations
191 virtual UINT_32 HwlGetEquationTableInfo(const ADDR_EQUATION** ppEquationTable) const
192 {
193 *ppEquationTable = m_equationTable;
194
195 return m_numEquations;
196 }
197
198 virtual BOOL_32 IsEquationSupported(
199 AddrResourceType rsrcType,
200 AddrSwizzleMode swMode,
201 UINT_32 elementBytesLog2) const;
202
203 virtual UINT_32 HwlComputeSurfaceBaseAlign(AddrSwizzleMode swizzleMode) const
204 {
205 UINT_32 baseAlign;
206
207 if (IsXor(swizzleMode))
208 {
209 if (m_settings.isVega10 || m_settings.isRaven)
210 {
211 baseAlign = GetBlockSize(swizzleMode);
212 }
213 else
214 {
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));
219 }
220 }
221 else
222 {
223 baseAlign = 256;
224 }
225
226 return baseAlign;
227 }
228
229 virtual ADDR_E_RETURNCODE HwlComputePipeBankXor(
230 const ADDR2_COMPUTE_PIPEBANKXOR_INPUT* pIn,
231 ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT* pOut) const;
232
233 virtual ADDR_E_RETURNCODE HwlComputeSlicePipeBankXor(
234 const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT* pIn,
235 ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT* pOut) const;
236
237 virtual ADDR_E_RETURNCODE HwlComputeSubResourceOffsetForSwizzlePattern(
238 const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT* pIn,
239 ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT* pOut) const;
240
241 virtual ADDR_E_RETURNCODE HwlGetPreferredSurfaceSetting(
242 const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT* pIn,
243 ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT* pOut) const;
244
245 virtual ADDR_E_RETURNCODE HwlComputeSurfaceInfoSanityCheck(
246 const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn) const;
247
248 virtual ADDR_E_RETURNCODE HwlComputeSurfaceInfoTiled(
249 const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn,
250 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
251
252 virtual ADDR_E_RETURNCODE HwlComputeSurfaceAddrFromCoordTiled(
253 const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT* pIn,
254 ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT* pOut) const;
255
256 // Initialize equation table
257 VOID InitEquationTable();
258
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;
263
264 UINT_32 GetMipChainInfo(
265 AddrResourceType resourceType,
266 AddrSwizzleMode swizzleMode,
267 UINT_32 bpp,
268 UINT_32 mip0Width,
269 UINT_32 mip0Height,
270 UINT_32 mip0Depth,
271 UINT_32 blockWidth,
272 UINT_32 blockHeight,
273 UINT_32 blockDepth,
274 UINT_32 numMipLevel,
275 ADDR2_MIP_INFO* pMipInfo) const;
276
277 VOID GetMetaMiptailInfo(
278 ADDR2_META_MIP_INFO* pInfo,
279 Dim3d mipCoord,
280 UINT_32 numMipInTail,
281 Dim3d* pMetaBlkDim) const;
282
283 Dim3d GetMipStartPos(
284 AddrResourceType resourceType,
285 AddrSwizzleMode swizzleMode,
286 UINT_32 width,
287 UINT_32 height,
288 UINT_32 depth,
289 UINT_32 blockWidth,
290 UINT_32 blockHeight,
291 UINT_32 blockDepth,
292 UINT_32 mipId,
293 UINT_32 log2ElementBytes,
294 UINT_32* pMipTailBytesOffset) const;
295
296 AddrMajorMode GetMajorMode(
297 AddrResourceType resourceType,
298 AddrSwizzleMode swizzleMode,
299 UINT_32 mip0WidthInBlk,
300 UINT_32 mip0HeightInBlk,
301 UINT_32 mip0DepthInBlk) const
302 {
303 BOOL_32 yMajor = (mip0WidthInBlk < mip0HeightInBlk);
304 BOOL_32 xMajor = (yMajor == FALSE);
305
306 if (IsThick(resourceType, swizzleMode))
307 {
308 yMajor = yMajor && (mip0HeightInBlk >= mip0DepthInBlk);
309 xMajor = xMajor && (mip0WidthInBlk >= mip0DepthInBlk);
310 }
311
312 AddrMajorMode majorMode;
313 if (xMajor)
314 {
315 majorMode = ADDR_MAJOR_X;
316 }
317 else if (yMajor)
318 {
319 majorMode = ADDR_MAJOR_Y;
320 }
321 else
322 {
323 majorMode = ADDR_MAJOR_Z;
324 }
325
326 return majorMode;
327 }
328
329 Dim3d GetDccCompressBlk(
330 AddrResourceType resourceType,
331 AddrSwizzleMode swizzleMode,
332 UINT_32 bpp) const
333 {
334 UINT_32 index = Log2(bpp >> 3);
335 Dim3d compressBlkDim;
336
337 if (IsThin(resourceType, swizzleMode))
338 {
339 compressBlkDim.w = Block256_2d[index].w;
340 compressBlkDim.h = Block256_2d[index].h;
341 compressBlkDim.d = 1;
342 }
343 else if (IsStandardSwizzle(resourceType, swizzleMode))
344 {
345 compressBlkDim = Block256_3dS[index];
346 }
347 else
348 {
349 compressBlkDim = Block256_3dZ[index];
350 }
351
352 return compressBlkDim;
353 }
354
355 static const Dim3d Block256_3dS[MaxNumOfBpp];
356 static const Dim3d Block256_3dZ[MaxNumOfBpp];
357
358 static const UINT_32 MipTailOffset256B[];
359
360 static const SwizzleModeFlags SwizzleModeTable[ADDR_SW_MAX_TYPE];
361
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;
370 // Equation table
371 ADDR_EQUATION m_equationTable[EquationTableSize];
372
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];
377
378 private:
379 virtual ADDR_E_RETURNCODE HwlGetMaxAlignments(
380 ADDR_GET_MAX_ALIGNMENTS_OUTPUT* pOut) const;
381
382 virtual BOOL_32 HwlInitGlobalParams(
383 const ADDR_CREATE_INPUT* pCreateIn);
384
385 static VOID GetRbEquation(CoordEq* pRbEq, UINT_32 rbPerSeLog2, UINT_32 seLog2);
386
387 VOID GetDataEquation(CoordEq* pDataEq, Gfx9DataType dataSurfaceType,
388 AddrSwizzleMode swizzleMode, AddrResourceType resourceType,
389 UINT_32 elementBytesLog2, UINT_32 numSamplesLog2) const;
390
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;
395
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;
403
404 virtual ChipFamily HwlConvertChipFamily(UINT_32 uChipFamily, UINT_32 uChipRevision);
405
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;
410
411 Gfx9ChipSettings m_settings;
412 };
413
414 } // V2
415 } // Addr
416
417 #endif
418