• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 htileAlignFix       : 1;
69         UINT_32 applyAliasFix       : 1;
70         UINT_32 reserved2           : 28;
71     };
72 };
73 
74 /**
75 ************************************************************************************************************************
76 * @brief GFX9 data surface type.
77 ************************************************************************************************************************
78 */
79 enum Gfx9DataType
80 {
81     Gfx9DataColor,
82     Gfx9DataDepthStencil,
83     Gfx9DataFmask
84 };
85 
86 /**
87 ************************************************************************************************************************
88 * @brief GFX9 meta equation parameters
89 ************************************************************************************************************************
90 */
91 struct MetaEqParams
92 {
93     UINT_32          maxMip;
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;
106 };
107 
108 /**
109 ************************************************************************************************************************
110 * @brief This class is the GFX9 specific address library
111 *        function set.
112 ************************************************************************************************************************
113 */
114 class Gfx9Lib : public Lib
115 {
116 public:
117     /// Creates Gfx9Lib object
CreateObj(const Client * pClient)118     static Addr::Lib* CreateObj(const Client* pClient)
119     {
120         VOID* pMem = Object::ClientAlloc(sizeof(Gfx9Lib), pClient);
121         return (pMem != NULL) ? new (pMem) Gfx9Lib(pClient) : NULL;
122     }
123 
124     virtual BOOL_32 IsValidDisplaySwizzleMode(
125         const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn) const;
126 
127 protected:
128     Gfx9Lib(const Client* pClient);
129     virtual ~Gfx9Lib();
130 
HwlIsStandardSwizzle(AddrResourceType resourceType,AddrSwizzleMode swizzleMode)131     virtual BOOL_32 HwlIsStandardSwizzle(
132         AddrResourceType resourceType,
133         AddrSwizzleMode  swizzleMode) const
134     {
135         return m_swizzleModeTable[swizzleMode].isStd ||
136                (IsTex3d(resourceType) && m_swizzleModeTable[swizzleMode].isDisp);
137     }
138 
HwlIsDisplaySwizzle(AddrResourceType resourceType,AddrSwizzleMode swizzleMode)139     virtual BOOL_32 HwlIsDisplaySwizzle(
140         AddrResourceType resourceType,
141         AddrSwizzleMode  swizzleMode) const
142     {
143         return IsTex2d(resourceType) && m_swizzleModeTable[swizzleMode].isDisp;
144     }
145 
HwlIsThin(AddrResourceType resourceType,AddrSwizzleMode swizzleMode)146     virtual BOOL_32 HwlIsThin(
147         AddrResourceType resourceType,
148         AddrSwizzleMode  swizzleMode) const
149     {
150         return ((IsTex2d(resourceType)  == TRUE) ||
151                 ((IsTex3d(resourceType) == TRUE)                  &&
152                  (m_swizzleModeTable[swizzleMode].isZ   == FALSE) &&
153                  (m_swizzleModeTable[swizzleMode].isStd == FALSE)));
154     }
155 
HwlIsThick(AddrResourceType resourceType,AddrSwizzleMode swizzleMode)156     virtual BOOL_32 HwlIsThick(
157         AddrResourceType resourceType,
158         AddrSwizzleMode  swizzleMode) const
159     {
160         return (IsTex3d(resourceType) &&
161                 (m_swizzleModeTable[swizzleMode].isZ || m_swizzleModeTable[swizzleMode].isStd));
162     }
163 
164     virtual ADDR_E_RETURNCODE HwlComputeHtileInfo(
165         const ADDR2_COMPUTE_HTILE_INFO_INPUT* pIn,
166         ADDR2_COMPUTE_HTILE_INFO_OUTPUT*      pOut) const;
167 
168     virtual ADDR_E_RETURNCODE HwlComputeCmaskInfo(
169         const ADDR2_COMPUTE_CMASK_INFO_INPUT* pIn,
170         ADDR2_COMPUTE_CMASK_INFO_OUTPUT*      pOut) const;
171 
172     virtual ADDR_E_RETURNCODE HwlComputeDccInfo(
173         const ADDR2_COMPUTE_DCCINFO_INPUT* pIn,
174         ADDR2_COMPUTE_DCCINFO_OUTPUT*      pOut) const;
175 
176     virtual ADDR_E_RETURNCODE HwlComputeCmaskAddrFromCoord(
177         const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT* pIn,
178         ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT*      pOut);
179 
180     virtual ADDR_E_RETURNCODE HwlComputeHtileAddrFromCoord(
181         const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT* pIn,
182         ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT*      pOut);
183 
184     virtual ADDR_E_RETURNCODE HwlComputeHtileCoordFromAddr(
185         const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT* pIn,
186         ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT*      pOut);
187 
188     virtual ADDR_E_RETURNCODE HwlComputeDccAddrFromCoord(
189         const ADDR2_COMPUTE_DCC_ADDRFROMCOORD_INPUT* pIn,
190         ADDR2_COMPUTE_DCC_ADDRFROMCOORD_OUTPUT*      pOut);
191 
192     virtual UINT_32 HwlGetEquationIndex(
193         const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn,
194         ADDR2_COMPUTE_SURFACE_INFO_OUTPUT*      pOut) const;
195 
196     virtual ADDR_E_RETURNCODE HwlComputeBlock256Equation(
197         AddrResourceType rsrcType,
198         AddrSwizzleMode swMode,
199         UINT_32 elementBytesLog2,
200         ADDR_EQUATION* pEquation) const;
201 
202     virtual ADDR_E_RETURNCODE HwlComputeThinEquation(
203         AddrResourceType rsrcType,
204         AddrSwizzleMode swMode,
205         UINT_32 elementBytesLog2,
206         ADDR_EQUATION* pEquation) const;
207 
208     virtual ADDR_E_RETURNCODE HwlComputeThickEquation(
209         AddrResourceType rsrcType,
210         AddrSwizzleMode swMode,
211         UINT_32 elementBytesLog2,
212         ADDR_EQUATION* pEquation) const;
213 
214     // Get equation table pointer and number of equations
HwlGetEquationTableInfo(const ADDR_EQUATION ** ppEquationTable)215     virtual UINT_32 HwlGetEquationTableInfo(const ADDR_EQUATION** ppEquationTable) const
216     {
217         *ppEquationTable = m_equationTable;
218 
219         return m_numEquations;
220     }
221 
222     virtual BOOL_32 IsEquationSupported(
223         AddrResourceType rsrcType,
224         AddrSwizzleMode swMode,
225         UINT_32 elementBytesLog2) const;
226 
HwlComputeSurfaceBaseAlign(AddrSwizzleMode swizzleMode)227     virtual UINT_32 HwlComputeSurfaceBaseAlign(AddrSwizzleMode swizzleMode) const
228     {
229         UINT_32 baseAlign;
230 
231         if (IsXor(swizzleMode))
232         {
233             baseAlign = GetBlockSize(swizzleMode);
234         }
235         else
236         {
237             baseAlign = 256;
238         }
239 
240         return baseAlign;
241     }
242 
243     virtual ADDR_E_RETURNCODE HwlComputePipeBankXor(
244         const ADDR2_COMPUTE_PIPEBANKXOR_INPUT* pIn,
245         ADDR2_COMPUTE_PIPEBANKXOR_OUTPUT*      pOut) const;
246 
247     virtual ADDR_E_RETURNCODE HwlComputeSlicePipeBankXor(
248         const ADDR2_COMPUTE_SLICE_PIPEBANKXOR_INPUT* pIn,
249         ADDR2_COMPUTE_SLICE_PIPEBANKXOR_OUTPUT*      pOut) const;
250 
251     virtual ADDR_E_RETURNCODE HwlComputeSubResourceOffsetForSwizzlePattern(
252         const ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_INPUT* pIn,
253         ADDR2_COMPUTE_SUBRESOURCE_OFFSET_FORSWIZZLEPATTERN_OUTPUT*      pOut) const;
254 
255     virtual ADDR_E_RETURNCODE HwlGetPreferredSurfaceSetting(
256         const ADDR2_GET_PREFERRED_SURF_SETTING_INPUT* pIn,
257         ADDR2_GET_PREFERRED_SURF_SETTING_OUTPUT*      pOut) const;
258 
259     virtual ADDR_E_RETURNCODE HwlComputeSurfaceInfoSanityCheck(
260         const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn) const;
261 
262     virtual ADDR_E_RETURNCODE HwlComputeSurfaceInfoTiled(
263          const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn,
264          ADDR2_COMPUTE_SURFACE_INFO_OUTPUT*      pOut) const;
265 
266     virtual ADDR_E_RETURNCODE HwlComputeSurfaceInfoLinear(
267          const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn,
268          ADDR2_COMPUTE_SURFACE_INFO_OUTPUT*      pOut) const;
269 
270     virtual ADDR_E_RETURNCODE HwlComputeSurfaceAddrFromCoordTiled(
271         const ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT* pIn,
272         ADDR2_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT*      pOut) const;
273 
274     // Initialize equation table
275     VOID InitEquationTable();
276 
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;
281 
282     UINT_32 GetMipChainInfo(
283         AddrResourceType  resourceType,
284         AddrSwizzleMode   swizzleMode,
285         UINT_32           bpp,
286         UINT_32           mip0Width,
287         UINT_32           mip0Height,
288         UINT_32           mip0Depth,
289         UINT_32           blockWidth,
290         UINT_32           blockHeight,
291         UINT_32           blockDepth,
292         UINT_32           numMipLevel,
293         ADDR2_MIP_INFO*   pMipInfo) const;
294 
295     VOID GetMetaMiptailInfo(
296         ADDR2_META_MIP_INFO*    pInfo,
297         Dim3d                   mipCoord,
298         UINT_32                 numMipInTail,
299         Dim3d*                  pMetaBlkDim) const;
300 
301     Dim3d GetMipStartPos(
302         AddrResourceType  resourceType,
303         AddrSwizzleMode   swizzleMode,
304         UINT_32           width,
305         UINT_32           height,
306         UINT_32           depth,
307         UINT_32           blockWidth,
308         UINT_32           blockHeight,
309         UINT_32           blockDepth,
310         UINT_32           mipId,
311         UINT_32           log2ElementBytes,
312         UINT_32*          pMipTailBytesOffset) const;
313 
GetMajorMode(AddrResourceType resourceType,AddrSwizzleMode swizzleMode,UINT_32 mip0WidthInBlk,UINT_32 mip0HeightInBlk,UINT_32 mip0DepthInBlk)314     AddrMajorMode GetMajorMode(
315         AddrResourceType resourceType,
316         AddrSwizzleMode  swizzleMode,
317         UINT_32          mip0WidthInBlk,
318         UINT_32          mip0HeightInBlk,
319         UINT_32          mip0DepthInBlk) const
320     {
321         BOOL_32 yMajor = (mip0WidthInBlk < mip0HeightInBlk);
322         BOOL_32 xMajor = (yMajor == FALSE);
323 
324         if (IsThick(resourceType, swizzleMode))
325         {
326             yMajor = yMajor && (mip0HeightInBlk >= mip0DepthInBlk);
327             xMajor = xMajor && (mip0WidthInBlk >= mip0DepthInBlk);
328         }
329 
330         AddrMajorMode majorMode;
331         if (xMajor)
332         {
333             majorMode = ADDR_MAJOR_X;
334         }
335         else if (yMajor)
336         {
337             majorMode = ADDR_MAJOR_Y;
338         }
339         else
340         {
341             majorMode = ADDR_MAJOR_Z;
342         }
343 
344         return majorMode;
345     }
346 
GetDccCompressBlk(AddrResourceType resourceType,AddrSwizzleMode swizzleMode,UINT_32 bpp)347     Dim3d GetDccCompressBlk(
348         AddrResourceType resourceType,
349         AddrSwizzleMode  swizzleMode,
350         UINT_32          bpp) const
351     {
352         UINT_32 index = Log2(bpp >> 3);
353         Dim3d   compressBlkDim;
354 
355         if (IsThin(resourceType, swizzleMode))
356         {
357             compressBlkDim.w = Block256_2d[index].w;
358             compressBlkDim.h = Block256_2d[index].h;
359             compressBlkDim.d = 1;
360         }
361         else if (IsStandardSwizzle(resourceType, swizzleMode))
362         {
363             compressBlkDim = Block256_3dS[index];
364         }
365         else
366         {
367             compressBlkDim = Block256_3dZ[index];
368         }
369 
370         return compressBlkDim;
371     }
372 
373 
374     static const UINT_32          MaxSeLog2      = 3;
375     static const UINT_32          MaxRbPerSeLog2 = 2;
376 
377     static const Dim3d            Block256_3dS[MaxNumOfBpp];
378     static const Dim3d            Block256_3dZ[MaxNumOfBpp];
379 
380     static const UINT_32          MipTailOffset256B[];
381 
382     static const SwizzleModeFlags SwizzleModeTable[ADDR_SW_MAX_TYPE];
383 
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;
392     // Equation table
393     ADDR_EQUATION           m_equationTable[EquationTableSize];
394 
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];
399 
400     static const UINT_32    MaxCachedMetaEq = 2;
401 
402 private:
403     virtual ADDR_E_RETURNCODE HwlGetMaxAlignments(
404         ADDR_GET_MAX_ALIGNMENTS_OUTPUT* pOut) const;
405 
406     virtual BOOL_32 HwlInitGlobalParams(
407         const ADDR_CREATE_INPUT* pCreateIn);
408 
409     VOID GetRbEquation(CoordEq* pRbEq, UINT_32 rbPerSeLog2, UINT_32 seLog2) const;
410 
411     VOID GetDataEquation(CoordEq* pDataEq, Gfx9DataType dataSurfaceType,
412                          AddrSwizzleMode swizzleMode, AddrResourceType resourceType,
413                          UINT_32 elementBytesLog2, UINT_32 numSamplesLog2) const;
414 
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;
419 
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;
427 
428     const CoordEq* GetMetaEquation(const MetaEqParams& metaEqParams);
429 
430     virtual ChipFamily HwlConvertChipFamily(UINT_32 uChipFamily, UINT_32 uChipRevision);
431 
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;
436 
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;
442 
443     Gfx9ChipSettings m_settings;
444 
445     CoordEq      m_cachedMetaEq[MaxCachedMetaEq];
446     MetaEqParams m_cachedMetaEqKey[MaxCachedMetaEq];
447     UINT_32      m_metaEqOverrideIndex;
448 };
449 
450 } // V2
451 } // Addr
452 
453 #endif
454 
455