• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2014 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  egbaddrlib.h
30 * @brief Contains the EgBasedAddrLib class definition.
31 ***************************************************************************************************
32 */
33 
34 #ifndef __EG_BASED_ADDR_LIB_H__
35 #define __EG_BASED_ADDR_LIB_H__
36 
37 #include "addrlib.h"
38 
39 
40 /// Structures for functions
41 struct CoordFromBankPipe
42 {
43     UINT_32 xBits : 3;
44     UINT_32 yBits : 4;
45 
46     UINT_32 xBit3 : 1;
47     UINT_32 xBit4 : 1;
48     UINT_32 xBit5 : 1;
49     UINT_32 yBit3 : 1;
50     UINT_32 yBit4 : 1;
51     UINT_32 yBit5 : 1;
52     UINT_32 yBit6 : 1;
53 };
54 
55 /**
56 ***************************************************************************************************
57 * @brief This class is the Evergreen based address library
58 * @note  Abstract class
59 ***************************************************************************************************
60 */
61 class EgBasedAddrLib : public AddrLib
62 {
63 protected:
64     EgBasedAddrLib(const AddrClient* pClient);
65     virtual ~EgBasedAddrLib();
66 
67 public:
68 
69     /// Surface info functions
70 
71     // NOTE: DispatchComputeSurfaceInfo using TileInfo takes both an input and an output.
72     //       On input:
73     //       One or more fields may be 0 to be calculated/defaulted - pre-SI h/w.
74     //       H/W using tile mode index only accepts none or all 0's - SI and newer h/w.
75     //       It then returns the actual tiling configuration used.
76     //       Other methods' TileInfo must be valid on entry
77     BOOL_32 DispatchComputeSurfaceInfo(
78         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn,
79         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
80 
81     ADDR_E_RETURNCODE DispatchComputeFmaskInfo(
82         const ADDR_COMPUTE_FMASK_INFO_INPUT* pIn,
83         ADDR_COMPUTE_FMASK_INFO_OUTPUT* pOut);
84 
85 protected:
86     // Hwl interface
87     virtual ADDR_E_RETURNCODE HwlComputeSurfaceInfo(
88         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn,
89         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
90 
91     virtual ADDR_E_RETURNCODE HwlComputeSurfaceAddrFromCoord(
92         const ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT* pIn,
93         ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT* pOut) const;
94 
95     virtual ADDR_E_RETURNCODE HwlComputeSurfaceCoordFromAddr(
96         const ADDR_COMPUTE_SURFACE_COORDFROMADDR_INPUT* pIn,
97         ADDR_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT* pOut) const;
98 
99     virtual ADDR_E_RETURNCODE HwlComputeSliceTileSwizzle(
100         const ADDR_COMPUTE_SLICESWIZZLE_INPUT* pIn,
101         ADDR_COMPUTE_SLICESWIZZLE_OUTPUT* pOut) const;
102 
103     virtual ADDR_E_RETURNCODE HwlExtractBankPipeSwizzle(
104         const ADDR_EXTRACT_BANKPIPE_SWIZZLE_INPUT* pIn,
105         ADDR_EXTRACT_BANKPIPE_SWIZZLE_OUTPUT* pOut) const;
106 
107     virtual ADDR_E_RETURNCODE HwlCombineBankPipeSwizzle(
108         UINT_32 bankSwizzle, UINT_32 pipeSwizzle, ADDR_TILEINFO*  pTileInfo,
109         UINT_64 baseAddr, UINT_32* pTileSwizzle) const;
110 
111     virtual ADDR_E_RETURNCODE HwlComputeBaseSwizzle(
112         const ADDR_COMPUTE_BASE_SWIZZLE_INPUT* pIn,
113         ADDR_COMPUTE_BASE_SWIZZLE_OUTPUT* pOut) const;
114 
115     virtual ADDR_E_RETURNCODE HwlConvertTileInfoToHW(
116         const ADDR_CONVERT_TILEINFOTOHW_INPUT* pIn,
117         ADDR_CONVERT_TILEINFOTOHW_OUTPUT* pOut) const;
118 
119     virtual UINT_32 HwlComputeHtileBpp(
120         BOOL_32 isWidth8, BOOL_32 isHeight8) const;
121 
122     virtual UINT_32 HwlComputeHtileBaseAlign(
123         BOOL_32 isTcCompatible, BOOL_32 isLinear, ADDR_TILEINFO* pTileInfo) const;
124 
125     virtual ADDR_E_RETURNCODE HwlComputeFmaskInfo(
126         const ADDR_COMPUTE_FMASK_INFO_INPUT* pIn,
127         ADDR_COMPUTE_FMASK_INFO_OUTPUT* pOut);
128 
129     virtual ADDR_E_RETURNCODE HwlComputeFmaskAddrFromCoord(
130         const ADDR_COMPUTE_FMASK_ADDRFROMCOORD_INPUT* pIn,
131         ADDR_COMPUTE_FMASK_ADDRFROMCOORD_OUTPUT* pOut) const;
132 
133     virtual ADDR_E_RETURNCODE HwlComputeFmaskCoordFromAddr(
134         const ADDR_COMPUTE_FMASK_COORDFROMADDR_INPUT* pIn,
135         ADDR_COMPUTE_FMASK_COORDFROMADDR_OUTPUT* pOut) const;
136 
137     virtual BOOL_32 HwlDegradeBaseLevel(
138         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn) const;
139 
140     virtual UINT_32 HwlComputeQbStereoRightSwizzle(
141         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pInfo) const;
142 
143     virtual VOID HwlComputePixelCoordFromOffset(
144         UINT_32 offset, UINT_32 bpp, UINT_32 numSamples,
145         AddrTileMode tileMode, UINT_32 tileBase, UINT_32 compBits,
146         UINT_32* pX, UINT_32* pY, UINT_32* pSlice, UINT_32* pSample,
147         AddrTileType microTileType, BOOL_32 isDepthSampleOrder) const;
148 
149     /// Return Cmask block max
HwlGetMaxCmaskBlockMax()150     virtual BOOL_32 HwlGetMaxCmaskBlockMax() const
151     {
152         return 16383; // 14 bits
153     }
154 
155     // Sub-hwl interface
156     /// Pure virtual function to setup tile info (indices) if client requests to do so
157     virtual VOID HwlSetupTileInfo(
158         AddrTileMode tileMode, ADDR_SURFACE_FLAGS flags,
159         UINT_32 bpp, UINT_32 pitch, UINT_32 height, UINT_32 numSamples,
160         ADDR_TILEINFO* inputTileInfo, ADDR_TILEINFO* outputTileInfo,
161         AddrTileType inTileType, ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const = 0;
162 
163     /// Pure virtual function to get pitch alignment for linear modes
164     virtual UINT_32 HwlGetPitchAlignmentLinear(UINT_32 bpp, ADDR_SURFACE_FLAGS flags) const = 0;
165 
166     /// Pure virtual function to get size adjustment for linear modes
167     virtual UINT_64 HwlGetSizeAdjustmentLinear(
168         AddrTileMode tileMode,
169         UINT_32 bpp, UINT_32 numSamples, UINT_32 baseAlign, UINT_32 pitchAlign,
170         UINT_32 *pPitch, UINT_32 *pHeight, UINT_32 *pHeightAlign) const = 0;
171 
172     virtual UINT_32 HwlGetPitchAlignmentMicroTiled(
173         AddrTileMode tileMode, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples) const;
174 
175     virtual UINT_64 HwlGetSizeAdjustmentMicroTiled(
176         UINT_32 thickness, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples,
177         UINT_32 baseAlign, UINT_32 pitchAlign,
178         UINT_32 *pPitch, UINT_32 *pHeight) const;
179 
180         /// Pure virtual function to do extra sanity check
181     virtual BOOL_32 HwlSanityCheckMacroTiled(
182         ADDR_TILEINFO* pTileInfo) const = 0;
183 
184     /// Pure virtual function to check current level to be the last macro tiled one
185     virtual VOID HwlCheckLastMacroTiledLvl(
186         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn,
187         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const = 0;
188 
189     /// Adjusts bank before bank is modified by rotation
190     virtual UINT_32 HwlPreAdjustBank(
191         UINT_32 tileX, UINT_32 bank, ADDR_TILEINFO*  pTileInfo) const = 0;
192 
193     virtual VOID HwlComputeSurfaceCoord2DFromBankPipe(
194         AddrTileMode tileMode, UINT_32* pX, UINT_32* pY, UINT_32 slice,
195         UINT_32 bank, UINT_32 pipe,
196         UINT_32 bankSwizzle, UINT_32 pipeSwizzle, UINT_32 tileSlices,
197         BOOL_32 ignoreSE,
198         ADDR_TILEINFO* pTileInfo) const = 0;
199 
200     virtual BOOL_32 HwlTileInfoEqual(
201         const ADDR_TILEINFO* pLeft, const ADDR_TILEINFO* pRight) const;
202 
203     virtual AddrTileMode HwlDegradeThickTileMode(
204         AddrTileMode baseTileMode, UINT_32 numSlices, UINT_32* pBytesPerTile) const;
205 
206     virtual INT_32 HwlPostCheckTileIndex(
207         const ADDR_TILEINFO* pInfo, AddrTileMode mode, AddrTileType type,
208         INT curIndex = TileIndexInvalid) const
209     {
210         return TileIndexInvalid;
211     }
212 
HwlFmaskPreThunkSurfInfo(const ADDR_COMPUTE_FMASK_INFO_INPUT * pFmaskIn,const ADDR_COMPUTE_FMASK_INFO_OUTPUT * pFmaskOut,ADDR_COMPUTE_SURFACE_INFO_INPUT * pSurfIn,ADDR_COMPUTE_SURFACE_INFO_OUTPUT * pSurfOut)213     virtual VOID HwlFmaskPreThunkSurfInfo(
214         const ADDR_COMPUTE_FMASK_INFO_INPUT* pFmaskIn,
215         const ADDR_COMPUTE_FMASK_INFO_OUTPUT* pFmaskOut,
216         ADDR_COMPUTE_SURFACE_INFO_INPUT* pSurfIn,
217         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pSurfOut) const
218     {
219     }
220 
HwlFmaskPostThunkSurfInfo(const ADDR_COMPUTE_SURFACE_INFO_OUTPUT * pSurfOut,ADDR_COMPUTE_FMASK_INFO_OUTPUT * pFmaskOut)221     virtual VOID HwlFmaskPostThunkSurfInfo(
222         const ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pSurfOut,
223         ADDR_COMPUTE_FMASK_INFO_OUTPUT* pFmaskOut) const
224     {
225     }
226 
227     /// Virtual function to check if the height needs extra padding
228     /// for stereo right eye offset, to avoid bank pipe swizzle
HwlStereoCheckRightOffsetPadding()229     virtual BOOL_32 HwlStereoCheckRightOffsetPadding() const
230     {
231         return FALSE;
232     }
233 
234     virtual BOOL_32 HwlReduceBankWidthHeight(
235         UINT_32 tileSize, UINT_32 bpp, ADDR_SURFACE_FLAGS flags, UINT_32 numSamples,
236         UINT_32 bankHeightAlign, UINT_32 pipes,
237         ADDR_TILEINFO* pTileInfo) const;
238 
239     // Protected non-virtual functions
240 
241     /// Mip level functions
242     AddrTileMode ComputeSurfaceMipLevelTileMode(
243         AddrTileMode baseTileMode, UINT_32 bpp,
244         UINT_32 pitch, UINT_32 height, UINT_32 numSlices, UINT_32 numSamples,
245         UINT_32 pitchAlign, UINT_32 heightAlign,
246         ADDR_TILEINFO* pTileInfo) const;
247 
248     /// Swizzle functions
249     VOID ExtractBankPipeSwizzle(
250         UINT_32 base256b, ADDR_TILEINFO* pTileInfo,
251         UINT_32* pBankSwizzle, UINT_32* pPipeSwizzle) const;
252 
253     UINT_32 GetBankPipeSwizzle(
254         UINT_32 bankSwizzle, UINT_32 pipeSwizzle,
255         UINT_64 baseAddr, ADDR_TILEINFO*  pTileInfo) const;
256 
257     UINT_32 ComputeSliceTileSwizzle(
258         AddrTileMode tileMode, UINT_32 baseSwizzle, UINT_32 slice, UINT_64 baseAddr,
259         ADDR_TILEINFO* pTileInfo) const;
260 
261     /// Addressing functions
262     UINT_32 ComputeBankFromCoord(
263         UINT_32 x, UINT_32 y, UINT_32 slice,
264         AddrTileMode tileMode, UINT_32 bankSwizzle, UINT_32 tileSpitSlice,
265         ADDR_TILEINFO* pTileInfo) const;
266 
267     UINT_32 ComputeBankFromAddr(
268         UINT_64 addr, UINT_32 numBanks, UINT_32 numPipes) const;
269 
270     UINT_32 ComputePipeRotation(
271         AddrTileMode tileMode, UINT_32 numPipes) const;
272 
273     UINT_32 ComputeBankRotation(
274         AddrTileMode tileMode, UINT_32 numBanks,
275         UINT_32 numPipes) const;
276 
277     VOID ComputeSurfaceCoord2DFromBankPipe(
278         AddrTileMode tileMode, UINT_32 x, UINT_32 y, UINT_32 slice,
279         UINT_32 bank, UINT_32 pipe,
280         UINT_32 bankSwizzle, UINT_32 pipeSwizzle, UINT_32 tileSlices,
281         ADDR_TILEINFO* pTileInfo,
282         CoordFromBankPipe *pOutput) const;
283 
284     /// Htile/Cmask functions
285     UINT_64 ComputeHtileBytes(
286         UINT_32 pitch, UINT_32 height, UINT_32 bpp,
287         BOOL_32 isLinear, UINT_32 numSlices, UINT_64* sliceBytes, UINT_32 baseAlign) const;
288 
289     // Static functions
290     static BOOL_32 IsTileInfoAllZero(ADDR_TILEINFO* pTileInfo);
291     static UINT_32 ComputeFmaskNumPlanesFromNumSamples(UINT_32 numSamples);
292     static UINT_32 ComputeFmaskResolvedBppFromNumSamples(UINT_32 numSamples);
293 
294 private:
295 
296     BOOL_32 ComputeSurfaceInfoLinear(
297         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn,
298         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut,
299         UINT_32 padDims) const;
300 
301     BOOL_32 ComputeSurfaceInfoMicroTiled(
302         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn,
303         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut,
304         UINT_32 padDims,
305         AddrTileMode expTileMode) const;
306 
307     BOOL_32 ComputeSurfaceInfoMacroTiled(
308         const ADDR_COMPUTE_SURFACE_INFO_INPUT* pIn,
309         ADDR_COMPUTE_SURFACE_INFO_OUTPUT* pOut,
310         UINT_32 padDims,
311         AddrTileMode expTileMode) const;
312 
313     BOOL_32 ComputeSurfaceAlignmentsLinear(
314         AddrTileMode tileMode, UINT_32 bpp, ADDR_SURFACE_FLAGS flags,
315         UINT_32* pBaseAlign, UINT_32* pPitchAlign, UINT_32* pHeightAlign) const;
316 
317     BOOL_32 ComputeSurfaceAlignmentsMicroTiled(
318         AddrTileMode tileMode, UINT_32 bpp, ADDR_SURFACE_FLAGS flags,
319         UINT_32 mipLevel, UINT_32 numSamples,
320         UINT_32* pBaseAlign, UINT_32* pPitchAlign, UINT_32* pHeightAlign) const;
321 
322     BOOL_32 ComputeSurfaceAlignmentsMacroTiled(
323         AddrTileMode tileMode, UINT_32 bpp, ADDR_SURFACE_FLAGS flags,
324         UINT_32 mipLevel, UINT_32 numSamples,
325         ADDR_TILEINFO* pTileInfo,
326         UINT_32* pBaseAlign, UINT_32* pPitchAlign, UINT_32* pHeightAlign) const;
327 
328     /// Surface addressing functions
329     UINT_64 DispatchComputeSurfaceAddrFromCoord(
330         const ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_INPUT* pIn,
331         ADDR_COMPUTE_SURFACE_ADDRFROMCOORD_OUTPUT* pOut) const;
332 
333     VOID    DispatchComputeSurfaceCoordFromAddr(
334         const ADDR_COMPUTE_SURFACE_COORDFROMADDR_INPUT* pIn,
335         ADDR_COMPUTE_SURFACE_COORDFROMADDR_OUTPUT* pOut) const;
336 
337     UINT_64 ComputeSurfaceAddrFromCoordMicroTiled(
338         UINT_32 x, UINT_32 y, UINT_32 slice, UINT_32 sample,
339         UINT_32 bpp, UINT_32 pitch, UINT_32 height, UINT_32 numSamples,
340         AddrTileMode tileMode,
341         AddrTileType microTileType, BOOL_32 isDepthSampleOrder,
342         UINT_32* pBitPosition) const;
343 
344     UINT_64 ComputeSurfaceAddrFromCoordMacroTiled(
345         UINT_32 x, UINT_32 y, UINT_32 slice, UINT_32 sample,
346         UINT_32 bpp, UINT_32 pitch, UINT_32 height, UINT_32 numSamples,
347         AddrTileMode tileMode,
348         AddrTileType microTileType, BOOL_32 ignoreSE, BOOL_32 isDepthSampleOrder,
349         UINT_32 pipeSwizzle, UINT_32 bankSwizzle,
350         ADDR_TILEINFO* pTileInfo,
351         UINT_32* pBitPosition) const;
352 
353     VOID    ComputeSurfaceCoordFromAddrMacroTiled(
354         UINT_64 addr, UINT_32 bitPosition,
355         UINT_32 bpp, UINT_32 pitch, UINT_32 height, UINT_32 numSamples,
356         AddrTileMode tileMode, UINT_32 tileBase, UINT_32 compBits,
357         AddrTileType microTileType, BOOL_32 ignoreSE, BOOL_32 isDepthSampleOrder,
358         UINT_32 pipeSwizzle, UINT_32 bankSwizzle,
359         ADDR_TILEINFO* pTileInfo,
360         UINT_32* pX, UINT_32* pY, UINT_32* pSlice, UINT_32* pSample) const;
361 
362     /// Fmask functions
363     UINT_64 DispatchComputeFmaskAddrFromCoord(
364         const ADDR_COMPUTE_FMASK_ADDRFROMCOORD_INPUT* pIn,
365         ADDR_COMPUTE_FMASK_ADDRFROMCOORD_OUTPUT* pOut) const;
366 
367     VOID    DispatchComputeFmaskCoordFromAddr(
368         const ADDR_COMPUTE_FMASK_COORDFROMADDR_INPUT* pIn,
369         ADDR_COMPUTE_FMASK_COORDFROMADDR_OUTPUT* pOut) const;
370 
371     // FMASK related methods - private
372     UINT_64 ComputeFmaskAddrFromCoordMicroTiled(
373         UINT_32 x, UINT_32 y, UINT_32 slice, UINT_32 sample, UINT_32 plane,
374         UINT_32 pitch, UINT_32 height, UINT_32 numSamples, AddrTileMode tileMode,
375         BOOL_32 resolved, UINT_32* pBitPosition) const;
376 
377     VOID    ComputeFmaskCoordFromAddrMicroTiled(
378         UINT_64 addr, UINT_32 bitPosition,
379         UINT_32 pitch, UINT_32 height, UINT_32 numSamples,
380         AddrTileMode tileMode, BOOL_32 resolved,
381         UINT_32* pX, UINT_32* pY, UINT_32* pSlice, UINT_32* pSample, UINT_32* pPlane) const;
382 
383     VOID    ComputeFmaskCoordFromAddrMacroTiled(
384         UINT_64 addr, UINT_32 bitPosition,
385         UINT_32 pitch, UINT_32 height, UINT_32 numSamples, AddrTileMode tileMode,
386         UINT_32 pipeSwizzle, UINT_32 bankSwizzle,
387         BOOL_32 ignoreSE,
388         ADDR_TILEINFO* pTileInfo,
389         BOOL_32 resolved,
390         UINT_32* pX, UINT_32* pY, UINT_32* pSlice, UINT_32* pSample, UINT_32* pPlane) const;
391 
392     UINT_64 ComputeFmaskAddrFromCoordMacroTiled(
393         UINT_32 x, UINT_32 y, UINT_32 slice, UINT_32 sample, UINT_32 plane,
394         UINT_32 pitch, UINT_32 height, UINT_32 numSamples,
395         AddrTileMode tileMode, UINT_32 pipeSwizzle, UINT_32 bankSwizzle,
396         BOOL_32 ignoreSE,
397         ADDR_TILEINFO* pTileInfo,
398         BOOL_32 resolved,
399         UINT_32* pBitPosition) const;
400 
401     /// Sanity check functions
402     BOOL_32 SanityCheckMacroTiled(
403         ADDR_TILEINFO* pTileInfo) const;
404 
405 protected:
406     UINT_32 m_ranks;                ///< Number of ranks - MC_ARB_RAMCFG.NOOFRANK
407     UINT_32 m_logicalBanks;         ///< Logical banks = m_banks * m_ranks if m_banks != 16
408     UINT_32 m_bankInterleave;       ///< Bank interleave, as a multiple of pipe interleave size
409 };
410 
411 #endif
412 
413