xref: /aosp_15_r20/external/mesa3d/src/amd/addrlib/src/r800/siaddrlib.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2 ************************************************************************************************************************
3 *
4 *  Copyright (C) 2007-2022 Advanced Micro Devices, Inc.  All rights reserved.
5 *  SPDX-License-Identifier: MIT
6 *
7 ***********************************************************************************************************************/
8 
9 /**
10 ****************************************************************************************************
11 * @file  siaddrlib.h
12 * @brief Contains the R800Lib class definition.
13 ****************************************************************************************************
14 */
15 
16 #ifndef __SI_ADDR_LIB_H__
17 #define __SI_ADDR_LIB_H__
18 
19 #include "addrlib1.h"
20 #include "egbaddrlib.h"
21 
22 namespace Addr
23 {
24 namespace V1
25 {
26 
27 /**
28 ****************************************************************************************************
29 * @brief Describes the information in tile mode table
30 ****************************************************************************************************
31 */
32 struct TileConfig
33 {
34     AddrTileMode  mode;
35     AddrTileType  type;
36     ADDR_TILEINFO info;
37 };
38 
39 /**
40 ****************************************************************************************************
41 * @brief SI specific settings structure.
42 ****************************************************************************************************
43 */
44 struct SiChipSettings
45 {
46     UINT_32 isSouthernIsland  : 1;
47     UINT_32 isTahiti          : 1;
48     UINT_32 isPitCairn        : 1;
49     UINT_32 isCapeVerde       : 1;
50     // Oland/Hainan are of GFXIP 6.0, similar with SI
51     UINT_32 isOland           : 1;
52     UINT_32 isHainan          : 1;
53 
54     // CI
55     UINT_32 isSeaIsland       : 1;
56     UINT_32 isBonaire         : 1;
57     UINT_32 isKaveri          : 1;
58     UINT_32 isSpectre         : 1;
59     UINT_32 isSpooky          : 1;
60     UINT_32 isKalindi         : 1;
61     UINT_32 isHawaii          : 1;
62 
63     // VI
64     UINT_32 isVolcanicIslands : 1;
65     UINT_32 isIceland         : 1;
66     UINT_32 isTonga           : 1;
67     UINT_32 isFiji            : 1;
68     UINT_32 isPolaris10       : 1;
69     UINT_32 isPolaris11       : 1;
70     UINT_32 isPolaris12       : 1;
71     // VI fusion
72     UINT_32 isVegaM           : 1;
73     UINT_32 isCarrizo         : 1;
74 
75     UINT_32                   : 2;
76 };
77 
78 /**
79 ****************************************************************************************************
80 * @brief This class is the SI specific address library
81 *        function set.
82 ****************************************************************************************************
83 */
84 class SiLib : public EgBasedLib
85 {
86 public:
87     /// Creates SiLib object
CreateObj(const Client * pClient)88     static Addr::Lib* CreateObj(const Client* pClient)
89     {
90         VOID* pMem = Object::ClientAlloc(sizeof(SiLib), pClient);
91         return (pMem != NULL) ? new (pMem) SiLib(pClient) : NULL;
92     }
93 
94 protected:
95     SiLib(const Client* pClient);
96     virtual ~SiLib();
97 
98     // Hwl interface - defined in AddrLib1
99     virtual ADDR_E_RETURNCODE HwlComputeSurfaceInfo(
100         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn,
101         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
102 
103     virtual ADDR_E_RETURNCODE HwlConvertTileInfoToHW(
104         const ADDR_CONVERT_TILEINFOTOHW_INPUT* pIn,
105         ADDR_CONVERT_TILEINFOTOHW_OUTPUT* pOut) const;
106 
107     virtual UINT_64 HwlComputeXmaskAddrFromCoord(
108         UINT_32 pitch, UINT_32 height, UINT_32 x, UINT_32 y, UINT_32 slice, UINT_32 numSlices,
109         UINT_32 factor, BOOL_32 isLinear, BOOL_32 isWidth8, BOOL_32 isHeight8,
110         ADDR_TILEINFO* pTileInfo, UINT_32* pBitPosition) const;
111 
112     virtual VOID HwlComputeXmaskCoordFromAddr(
113         UINT_64 addr, UINT_32 bitPosition, UINT_32 pitch, UINT_32 height, UINT_32 numSlices,
114         UINT_32 factor, BOOL_32 isLinear, BOOL_32 isWidth8, BOOL_32 isHeight8,
115         ADDR_TILEINFO* pTileInfo, UINT_32* pX, UINT_32* pY, UINT_32* pSlice) const;
116 
117     virtual ADDR_E_RETURNCODE HwlGetTileIndex(
118         const ADDR_GET_TILEINDEX_INPUT* pIn,
119         ADDR_GET_TILEINDEX_OUTPUT*      pOut) const;
120 
121     virtual BOOL_32 HwlComputeMipLevel(
122         ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn) const;
123 
124     virtual ChipFamily HwlConvertChipFamily(
125         UINT_32 uChipFamily, UINT_32 uChipRevision);
126 
127     virtual BOOL_32 HwlInitGlobalParams(
128         const ADDR_CREATE_INPUT* pCreateIn);
129 
130     virtual ADDR_E_RETURNCODE HwlSetupTileCfg(
131         UINT_32 bpp, INT_32 index, INT_32 macroModeIndex,
132         ADDR_TILEINFO* pInfo, AddrTileMode* pMode = 0, AddrTileType* pType = 0) const;
133 
134     virtual VOID HwlComputeTileDataWidthAndHeightLinear(
135         UINT_32* pMacroWidth, UINT_32* pMacroHeight,
136         UINT_32 bpp, ADDR_TILEINFO* pTileInfo) const;
137 
138     virtual UINT_64 HwlComputeHtileBytes(
139         UINT_32 pitch, UINT_32 height, UINT_32 bpp,
140         BOOL_32 isLinear, UINT_32 numSlices, UINT_64* pSliceBytes, UINT_32 baseAlign) const;
141 
142     virtual ADDR_E_RETURNCODE ComputeBankEquation(
143         UINT_32 log2BytesPP, UINT_32 threshX, UINT_32 threshY,
144         ADDR_TILEINFO* pTileInfo, ADDR_EQUATION* pEquation) const;
145 
146     virtual ADDR_E_RETURNCODE ComputePipeEquation(
147         UINT_32 log2BytesPP, UINT_32 threshX, UINT_32 threshY,
148         ADDR_TILEINFO* pTileInfo, ADDR_EQUATION* pEquation) const;
149 
150     virtual UINT_32 ComputePipeFromCoord(
151         UINT_32 x, UINT_32 y, UINT_32 slice,
152         AddrTileMode tileMode, UINT_32 pipeSwizzle, BOOL_32 ignoreSE,
153         ADDR_TILEINFO* pTileInfo) const;
154 
155     virtual UINT_32 HwlGetPipes(const ADDR_TILEINFO* pTileInfo) const;
156 
157     /// Pre-handler of 3x pitch (96 bit) adjustment
158     virtual UINT_32 HwlPreHandleBaseLvl3xPitch(
159         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn, UINT_32 expPitch) const;
160     /// Post-handler of 3x pitch adjustment
161     virtual UINT_32 HwlPostHandleBaseLvl3xPitch(
162         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn, UINT_32 expPitch) const;
163 
164     /// Dummy function to finalize the inheritance
165     virtual UINT_32 HwlComputeXmaskCoordYFrom8Pipe(
166         UINT_32 pipe, UINT_32 x) const;
167 
168     // Sub-hwl interface - defined in EgBasedLib
169     virtual VOID HwlSetupTileInfo(
170         AddrTileMode tileMode, ADDR_SURFACE_FLAGS flags,
171         UINT_32 bpp, UINT_32 pitch, UINT_32 height, UINT_32 numSamples,
172         ADDR_TILEINFO* inputTileInfo, ADDR_TILEINFO* outputTileInfo,
173         AddrTileType inTileType, ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
174 
175     virtual UINT_32 HwlGetPitchAlignmentMicroTiled(
176         AddrTileMode tileMode, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples) const;
177 
178     virtual UINT_64 HwlGetSizeAdjustmentMicroTiled(
179         UINT_32 thickness, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples,
180         UINT_32 baseAlign, UINT_32 pitchAlign,
181         UINT_32 *pPitch, UINT_32 *pHeight) const;
182 
183     virtual VOID HwlCheckLastMacroTiledLvl(
184         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn, ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
185 
186     virtual BOOL_32 HwlTileInfoEqual(
187         const ADDR_TILEINFO* pLeft, const ADDR_TILEINFO* pRight) const;
188 
189     virtual AddrTileMode HwlDegradeThickTileMode(
190         AddrTileMode baseTileMode, UINT_32 numSlices, UINT_32* pBytesPerTile) const;
191 
192     virtual VOID HwlOverrideTileMode(ADDR_COMPUTE_SURFACE_INFO_INPUT* pInOut) const;
193 
194     virtual VOID HwlOptimizeTileMode(ADDR_COMPUTE_SURFACE_INFO_INPUT* pInOut) const;
195 
196     virtual VOID HwlSelectTileMode(ADDR_COMPUTE_SURFACE_INFO_INPUT* pInOut) const;
197 
198     /// Overwrite tile setting to PRT
199     virtual VOID HwlSetPrtTileMode(ADDR_COMPUTE_SURFACE_INFO_INPUT* pInOut) const;
200 
HwlSanityCheckMacroTiled(ADDR_TILEINFO * pTileInfo)201     virtual BOOL_32 HwlSanityCheckMacroTiled(
202         ADDR_TILEINFO* pTileInfo) const
203     {
204         return TRUE;
205     }
206 
207     virtual UINT_32 HwlGetPitchAlignmentLinear(UINT_32 bpp, ADDR_SURFACE_FLAGS flags) const;
208 
209     virtual UINT_64 HwlGetSizeAdjustmentLinear(
210         AddrTileMode tileMode,
211         UINT_32 bpp, UINT_32 numSamples, UINT_32 baseAlign, UINT_32 pitchAlign,
212         UINT_32 *pPitch, UINT_32 *pHeight, UINT_32 *pHeightAlign) const;
213 
214     virtual VOID HwlComputeSurfaceCoord2DFromBankPipe(
215         AddrTileMode tileMode, UINT_32* pX, UINT_32* pY, UINT_32 slice,
216         UINT_32 bank, UINT_32 pipe,
217         UINT_32 bankSwizzle, UINT_32 pipeSwizzle, UINT_32 tileSlices,
218         BOOL_32 ignoreSE,
219         ADDR_TILEINFO* pTileInfo) const;
220 
221     virtual UINT_32 HwlPreAdjustBank(
222         UINT_32 tileX, UINT_32 bank, ADDR_TILEINFO* pTileInfo) const;
223 
224     virtual INT_32 HwlPostCheckTileIndex(
225         const ADDR_TILEINFO* pInfo, AddrTileMode mode, AddrTileType type,
226         INT curIndex = TileIndexInvalid) const;
227 
228     virtual VOID HwlFmaskPreThunkSurfInfo(
229         const ADDR_COMPUTE_FMASK_INFO_INPUT* pFmaskIn,
230         const ADDR_COMPUTE_FMASK_INFO_OUTPUT* pFmaskOut,
231         ADDR_COMPUTE_SURFACE_INFO_INPUT* pSurfIn,
232         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pSurfOut) const;
233 
234     virtual VOID HwlFmaskPostThunkSurfInfo(
235         const ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pSurfOut,
236         ADDR_COMPUTE_FMASK_INFO_OUTPUT* pFmaskOut) const;
237 
238     virtual UINT_32 HwlComputeFmaskBits(
239         const ADDR_COMPUTE_FMASK_INFO_INPUT* pIn,
240         UINT_32* pNumSamples) const;
241 
HwlReduceBankWidthHeight(UINT_32 tileSize,UINT_32 bpp,ADDR_SURFACE_FLAGS flags,UINT_32 numSamples,UINT_32 bankHeightAlign,UINT_32 pipes,ADDR_TILEINFO * pTileInfo)242     virtual BOOL_32 HwlReduceBankWidthHeight(
243         UINT_32 tileSize, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples,
244         UINT_32 bankHeightAlign, UINT_32 pipes,
245         ADDR_TILEINFO* pTileInfo) const
246     {
247         return TRUE;
248     }
249 
250     virtual UINT_32 HwlComputeMaxBaseAlignments() const;
251 
252     virtual UINT_32 HwlComputeMaxMetaBaseAlignments() const;
253 
254     virtual VOID HwlComputeSurfaceAlignmentsMacroTiled(
255         AddrTileMode tileMode, UINT_32 bpp, ADDR_SURFACE_FLAGS flags,
256         UINT_32 mipLevel, UINT_32 numSamples, ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
257 
258     // Get equation table pointer and number of equations
HwlGetEquationTableInfo(const ADDR_EQUATION ** ppEquationTable)259     virtual UINT_32 HwlGetEquationTableInfo(const ADDR_EQUATION** ppEquationTable) const
260     {
261         *ppEquationTable = m_equationTable;
262 
263         return m_numEquations;
264     }
265 
266     // Check if it is supported for given bpp and tile config to generate an equation
267     BOOL_32 IsEquationSupported(
268         UINT_32 bpp, TileConfig tileConfig, INT_32 tileIndex, UINT_32 elementBytesLog2) const;
269 
270     // Protected non-virtual functions
271     VOID ComputeTileCoordFromPipeAndElemIdx(
272         UINT_32 elemIdx, UINT_32 pipe, AddrPipeCfg pipeCfg, UINT_32 pitchInMacroTile,
273         UINT_32 x, UINT_32 y, UINT_32* pX, UINT_32* pY) const;
274 
275     UINT_32 TileCoordToMaskElementIndex(
276         UINT_32 tx, UINT_32 ty, AddrPipeCfg  pipeConfig,
277         UINT_32 *macroShift, UINT_32 *elemIdxBits) const;
278 
279     BOOL_32 DecodeGbRegs(
280         const ADDR_REGISTER_VALUE* pRegValue);
281 
282     const TileConfig* GetTileSetting(
283         UINT_32 index) const;
284 
285     // Initialize equation table
286     VOID InitEquationTable();
287 
288     UINT_32 GetPipePerSurf(AddrPipeCfg pipeConfig) const;
289 
290     static const UINT_32    TileTableSize = 32;
291     TileConfig              m_tileTable[TileTableSize];
292     UINT_32                 m_noOfEntries;
293 
294     // Max number of bpp (8bpp/16bpp/32bpp/64bpp/128bpp)
295     static const UINT_32    MaxNumElementBytes  = 5;
296 
297     static const BOOL_32    m_EquationSupport[TileTableSize][MaxNumElementBytes];
298 
299     // Prt tile mode index mask
300     static const UINT_32    SiPrtTileIndexMask = ((1 << 3)  | (1 << 5)  | (1 << 6)  | (1 << 7)  |
301                                                   (1 << 21) | (1 << 22) | (1 << 23) | (1 << 24) |
302                                                   (1 << 25) | (1 << 30));
303 
304     // More than half slots in tile mode table can't support equation
305     static const UINT_32    EquationTableSize   = (MaxNumElementBytes * TileTableSize) / 2;
306     // Equation table
307     ADDR_EQUATION           m_equationTable[EquationTableSize];
308     UINT_32                 m_numMacroBits[EquationTableSize];
309     UINT_32                 m_blockWidth[EquationTableSize];
310     UINT_32                 m_blockHeight[EquationTableSize];
311     UINT_32                 m_blockSlices[EquationTableSize];
312     // Number of equation entries in the table
313     UINT_32                 m_numEquations;
314     // Equation lookup table according to bpp and tile index
315     UINT_32                 m_equationLookupTable[MaxNumElementBytes][TileTableSize];
316 
317     UINT_32                 m_uncompressDepthEqIndex;
318 
319     SiChipSettings          m_settings;
320 
321 private:
322 
323     VOID ReadGbTileMode(UINT_32 regValue, TileConfig* pCfg) const;
324     BOOL_32 InitTileSettingTable(const UINT_32 *pSetting, UINT_32 noOfEntries);
325 };
326 
327 } // V1
328 } // Addr
329 
330 #endif
331 
332