amd/addrlib: import gfx9 support
[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 reserved0 : 30;
58
59 // Display engine IP version name
60 UINT_32 isDce12 : 1;
61 UINT_32 reserved1 : 31;
62
63 // Misc configuration bits
64 UINT_32 metaBaseAlignFix : 1;
65 UINT_32 reserved2 : 31;
66 };
67 };
68
69 /**
70 ****************************************************************************************************
71 * @brief GFX9 data surface type.
72 ****************************************************************************************************
73 */
74 enum Gfx9DataType
75 {
76 Gfx9DataColor,
77 Gfx9DataDepthStencil,
78 Gfx9DataFmask
79 };
80
81 /**
82 ****************************************************************************************************
83 * @brief This class is the GFX9 specific address library
84 * function set.
85 ****************************************************************************************************
86 */
87 class Gfx9Lib : public Lib
88 {
89 public:
90 /// Creates Gfx9Lib object
91 static Addr::Lib* CreateObj(const Client* pClient)
92 {
93 VOID* pMem = Object::ClientAlloc(sizeof(Gfx9Lib), pClient);
94 return (pMem != NULL) ? new (pMem) Gfx9Lib(pClient) : NULL;
95 }
96
97 protected:
98 Gfx9Lib(const Client* pClient);
99 virtual ~Gfx9Lib();
100
101 virtual ADDR_E_RETURNCODE HwlComputeHtileInfo(
102 const ADDR2_COMPUTE_HTILE_INFO_INPUT* pIn,
103 ADDR2_COMPUTE_HTILE_INFO_OUTPUT* pOut) const;
104
105 virtual ADDR_E_RETURNCODE HwlComputeCmaskInfo(
106 const ADDR2_COMPUTE_CMASK_INFO_INPUT* pIn,
107 ADDR2_COMPUTE_CMASK_INFO_OUTPUT* pOut) const;
108
109 virtual ADDR_E_RETURNCODE HwlComputeDccInfo(
110 const ADDR2_COMPUTE_DCCINFO_INPUT* pIn,
111 ADDR2_COMPUTE_DCCINFO_OUTPUT* pOut) const;
112
113 virtual ADDR_E_RETURNCODE HwlComputeCmaskAddrFromCoord(
114 const ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_INPUT* pIn,
115 ADDR2_COMPUTE_CMASK_ADDRFROMCOORD_OUTPUT* pOut) const;
116
117 virtual ADDR_E_RETURNCODE HwlComputeHtileAddrFromCoord(
118 const ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_INPUT* pIn,
119 ADDR2_COMPUTE_HTILE_ADDRFROMCOORD_OUTPUT* pOut) const;
120
121 virtual ADDR_E_RETURNCODE HwlComputeHtileCoordFromAddr(
122 const ADDR2_COMPUTE_HTILE_COORDFROMADDR_INPUT* pIn,
123 ADDR2_COMPUTE_HTILE_COORDFROMADDR_OUTPUT* pOut) const;
124
125 virtual UINT_32 HwlGetEquationIndex(
126 const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn,
127 ADDR2_COMPUTE_SURFACE_INFO_OUTPUT* pOut) const;
128
129 virtual ADDR_E_RETURNCODE HwlComputeBlock256Equation(
130 AddrResourceType rsrcType,
131 AddrSwizzleMode swMode,
132 UINT_32 elementBytesLog2,
133 ADDR_EQUATION* pEquation) const;
134
135 virtual ADDR_E_RETURNCODE HwlComputeThinEquation(
136 AddrResourceType rsrcType,
137 AddrSwizzleMode swMode,
138 UINT_32 elementBytesLog2,
139 ADDR_EQUATION* pEquation) const;
140
141 virtual ADDR_E_RETURNCODE HwlComputeThickEquation(
142 AddrResourceType rsrcType,
143 AddrSwizzleMode swMode,
144 UINT_32 elementBytesLog2,
145 ADDR_EQUATION* pEquation) const;
146
147 // Get equation table pointer and number of equations
148 virtual UINT_32 HwlGetEquationTableInfo(const ADDR_EQUATION** ppEquationTable) const
149 {
150 *ppEquationTable = m_equationTable;
151
152 return m_numEquations;
153 }
154
155 virtual BOOL_32 IsEquationSupported(
156 AddrResourceType rsrcType,
157 AddrSwizzleMode swMode,
158 UINT_32 elementBytesLog2) const;
159
160 virtual UINT_32 HwlComputeSurfaceBaseAlign(AddrSwizzleMode swizzleMode) const
161 {
162 UINT_32 baseAlign;
163
164 if (IsXor(swizzleMode))
165 {
166 if (m_settings.isVega10)
167 {
168 baseAlign = GetBlockSize(swizzleMode);
169 }
170 else
171 {
172 UINT_32 blockSizeLog2 = GetBlockSizeLog2(swizzleMode);
173 UINT_32 pipeBits = GetPipeXorBits(blockSizeLog2);
174 UINT_32 bankBits = GetBankXorBits(blockSizeLog2);
175 baseAlign = 1 << (Min(blockSizeLog2, m_pipeInterleaveLog2 + pipeBits+ bankBits));
176 }
177 }
178 else
179 {
180 baseAlign = 256;
181 }
182
183 return baseAlign;
184 }
185
186 virtual BOOL_32 HwlIsValidDisplaySwizzleMode(const ADDR2_COMPUTE_SURFACE_INFO_INPUT* pIn) const;
187
188 virtual BOOL_32 HwlIsDce12() const { return m_settings.isDce12; }
189
190 // Initialize equation table
191 VOID InitEquationTable();
192
193 // Max number of swizzle mode supported for equation
194 static const UINT_32 MaxSwMode = 32;
195 // Max number of resource type (2D/3D) supported for equation
196 static const UINT_32 MaxRsrcType = 2;
197 // Max number of bpp (8bpp/16bpp/32bpp/64bpp/128bpp)
198 static const UINT_32 MaxElementBytesLog2 = 5;
199 // Almost all swizzle mode + resource type support equation
200 static const UINT_32 EquationTableSize = MaxElementBytesLog2 * MaxSwMode * MaxRsrcType;
201 // Equation table
202 ADDR_EQUATION m_equationTable[EquationTableSize];
203
204 // Number of equation entries in the table
205 UINT_32 m_numEquations;
206 // Equation lookup table according to bpp and tile index
207 UINT_32 m_equationLookupTable[MaxRsrcType][MaxSwMode][MaxElementBytesLog2];
208
209 private:
210 virtual ADDR_E_RETURNCODE HwlGetMaxAlignments(
211 ADDR_GET_MAX_ALINGMENTS_OUTPUT* pOut) const;
212
213 virtual BOOL_32 HwlInitGlobalParams(
214 const ADDR_CREATE_INPUT* pCreateIn);
215
216 static VOID GetRbEquation(CoordEq* pRbEq, UINT_32 rbPerSeLog2, UINT_32 seLog2);
217
218 VOID GetDataEquation(CoordEq* pDataEq, Gfx9DataType dataSurfaceType,
219 AddrSwizzleMode swizzleMode, AddrResourceType resourceType,
220 UINT_32 elementBytesLog2, UINT_32 numSamplesLog2) const;
221
222 VOID GetPipeEquation(CoordEq* pPipeEq, CoordEq* pDataEq,
223 UINT_32 pipeInterleaveLog2, UINT_32 numPipesLog2,
224 UINT_32 numSamplesLog2, Gfx9DataType dataSurfaceType,
225 AddrSwizzleMode swizzleMode, AddrResourceType resourceType) const;
226
227 VOID GetMetaEquation(CoordEq* pMetaEq, UINT_32 maxMip,
228 UINT_32 elementBytesLog2, UINT_32 numSamplesLog2,
229 ADDR2_META_FLAGS metaFlag, Gfx9DataType dataSurfaceType,
230 AddrSwizzleMode swizzleMode, AddrResourceType resourceType,
231 UINT_32 metaBlkWidthLog2, UINT_32 metaBlkHeightLog2,
232 UINT_32 metaBlkDepthLog2, UINT_32 compBlkWidthLog2,
233 UINT_32 compBlkHeightLog2, UINT_32 compBlkDepthLog2) const;
234
235 virtual ChipFamily HwlConvertChipFamily(UINT_32 uChipFamily, UINT_32 uChipRevision);
236
237 VOID GetMetaMipInfo(UINT_32 numMipLevels, Dim3d* pMetaBlkDim,
238 BOOL_32 dataThick, ADDR2_META_MIP_INFO* pInfo,
239 UINT_32 mip0Width, UINT_32 mip0Height, UINT_32 mip0Depth,
240 UINT_32* pNumMetaBlkX, UINT_32* pNumMetaBlkY, UINT_32* pNumMetaBlkZ) const;
241
242 Gfx9ChipSettings m_settings;
243 };
244
245 } // V2
246 } // Addr
247
248 #endif
249