xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/inc/External/Common/GmmTextureExt.h (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2017 Intel Corporation
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files(the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and / or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 ============================================================================*/
22 #pragma once
23 
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /*__cplusplus*/
28 
29 // Set packing alignment
30 #pragma pack(push, 8)
31 
32 #define GMM_MAX_MIPMAP      15
33 #define GMM_MAX_MMC_INDEX   64
34 
35 //===========================================================================
36 // typedef:
37 //        GMM_PLANAR_OFFSET_INFO
38 //
39 // Description:
40 //     This structure stores the offset address of each level
41 //---------------------------------------------------------------------------
42 typedef struct GMM_PLANAR_OFFSET_INFO_REC
43 {
44     GMM_GFX_SIZE_T   ArrayQPitch;
45     GMM_GFX_SIZE_T   X[GMM_MAX_PLANE];
46     GMM_GFX_SIZE_T   Y[GMM_MAX_PLANE];
47     struct
48     {
49         GMM_GFX_SIZE_T   Height[GMM_MAX_PLANE];
50     } UnAligned, Aligned;
51     uint32_t            NoOfPlanes;
52     bool                IsTileAlignedPlanes;
53 }GMM_PLANAR_OFFSET_INFO;
54 
55 //===========================================================================
56 // typedef:
57 //        GMM_PLANAR_OFFSET_INFO
58 //
59 // Description:
60 //     This structure stores the offset address of each level
61 //---------------------------------------------------------------------------
62 typedef struct GMM_PLANAR_OFFSET_INFO_V2_REC
63 {
64     GMM_GFX_SIZE_T ArrayQPitch;
65     GMM_GFX_SIZE_T X[GMM_MAX_PLANE];
66     GMM_GFX_SIZE_T Y[GMM_MAX_PLANE];
67     struct
68     {
69         uint32_t Height[GMM_MAX_PLANE];
70     } UnAligned, Aligned, Physical;
71     uint32_t                      NoOfPlanes;
72     bool                          IsTileAlignedPlanes;
73     bool                          Is1MBAuxTAlignedPlanes;
74     GMM_GFX_SIZE_T PhysicalPitch;
75 } GMM_PLANAR_OFFSET_INFO_V2;
76 
77 //===========================================================================
78 // typedef:
79 //        GMM_2D_TEXTURE_OFFSET_INFO
80 //
81 // Description:
82 //     This structure stores the offset address of each level
83 //---------------------------------------------------------------------------
84 typedef struct GMM_2D_TEXTURE_OFFSET_INFO_REC
85 {
86     GMM_GFX_SIZE_T              ArrayQPitchLock;
87     GMM_GFX_SIZE_T              ArrayQPitchRender;
88     GMM_GFX_SIZE_T              Offset[GMM_MAX_MIPMAP];
89 }GMM_2D_TEXTURE_OFFSET_INFO_T;
90 
91 //===========================================================================
92 // typedef:
93 //        GMM_3D_TEXTURE_OFFSET_INFO
94 //
95 // Description:
96 //     This structure stores the offset address of each level
97 //---------------------------------------------------------------------------
98 typedef struct GMM_3D_TEXTURE_OFFSET_INFO_REC
99 {
100     GMM_GFX_SIZE_T     Mip0SlicePitch;
101     GMM_GFX_SIZE_T     Offset[GMM_MAX_MIPMAP];
102 }GMM_3D_TEXTURE_OFFSET_INFO_T;
103 
104 //===========================================================================
105 // typedef:
106 //        GMM_OFFSET_INFO
107 //
108 // Description:
109 //     This structure stores the offset address of each level
110 //---------------------------------------------------------------------------
111 typedef struct GMM_OFFSET_INFO_REC
112 {
113     union
114     {
115         GMM_3D_TEXTURE_OFFSET_INFO_T    Texture3DOffsetInfo;
116         GMM_2D_TEXTURE_OFFSET_INFO_T    Texture2DOffsetInfo;
117         GMM_PLANAR_OFFSET_INFO          Plane;
118         GMM_PLANAR_OFFSET_INFO_V2       PlaneXe_LPG;
119     };
120 }GMM_OFFSET_INFO, GMM_OFFSET_INFO_T;
121 
122 //===========================================================================
123 // typedef:
124 //        GMM_TEXTURE_CALC
125 //
126 // Description:
127 //     This struct is used to texture calculator.
128 //     Forward Declaration: Defined in GmmGenXXTextureCalc*.h
129 //---------------------------------------------------------------------------
130 #ifdef __cplusplus
131 namespace GmmLib
132 {
133     class GmmTextureCalc;
134 }
135 
136 typedef GmmLib::GmmTextureCalc GMM_TEXTURE_CALC;
137 #else
138 struct GmmTextureCalc;
139 typedef struct GmmTextureCalc GMM_TEXTURE_CALC;
140 #endif
141 
142 //===========================================================================
143 // typedef:
144 //      GMM_TEXTURE_INFO_REC
145 //
146 // Description:
147 //      This structure used to request mipmap offset information
148 //---------------------------------------------------------------------------
149 typedef struct GMM_TEXTURE_INFO_REC
150 {
151      // Input ----------------------------------
152     GMM_RESOURCE_TYPE       Type;
153     GMM_RESOURCE_FORMAT     Format;
154     uint32_t                BitsPerPixel;
155     GMM_RESOURCE_FLAG       Flags;
156 
157     uint64_t                BaseWidth;
158     uint32_t                BaseHeight;
159     uint32_t                Depth;
160     uint32_t                MaxLod;
161     uint32_t                ArraySize;
162     uint32_t                CpTag;
163 
164     struct{
165         GMM_RESOURCE_USAGE_TYPE Usage;
166     }                       CachePolicy;
167 
168     GMM_RESOURCE_MSAA_INFO  MSAA;
169 
170     // Output ---------------------------------
171     GMM_RESOURCE_ALIGNMENT  Alignment;
172 
173     uint8_t                 MmcMode[GMM_MAX_MMC_INDEX];
174     uint8_t                 MmcHint[GMM_MAX_MMC_INDEX];
175 
176     GMM_GFX_SIZE_T          Pitch;
177     GMM_GFX_SIZE_T          OverridePitch;   // VirtualPadding
178 
179     GMM_GFX_SIZE_T          Size;            // For AuxSurf Size = CCS + CC + Padding
180     GMM_GFX_SIZE_T          CCSize;          // 4kb => 128 bit Float + 32bit Native RT + Padding. Usage : Gpu.IndirectClearColor
181     GMM_GFX_SIZE_T          UnpaddedSize;    // Unpadded CCS Size for Flags.Gpu.UnifiedAuxSurface only
182     GMM_GFX_SIZE_T          SizeReportToOS;  // For Non-aligned ESM
183 
184     GMM_OFFSET_INFO         OffsetInfo;      // (X,Y) offsets to each mipmap/plane
185     GMM_TILE_MODE           TileMode;
186     uint32_t                CCSModeAlign;    // For AUX_CCS, TexAlign.CCSEx index derived from main surface tiling
187     uint32_t                LegacyFlags;
188 
189     GMM_S3D_INFO            S3d;
190 
191     #if(LHDM)
192         D3DDDIFORMAT        MsFormat;
193 
194     #endif
195 
196     struct{
197         uint32_t               Seg1    : 8;
198         uint32_t               Evict   : 8;
199     }                   SegmentOverride; // Used for tuning the Vista driver
200 
201     uint32_t               MaximumRenamingListLength;
202 
203     #if(_DEBUG || _RELEASE_INTERNAL)
204         PLATFORM        Platform;
205     #else
206         PLATFORM        __Platform; // Do not use--For size preservation only.
207     #endif
208 
209     struct{
210         uint8_t          IsGmmAllocated;
211         uint8_t          IsPageAligned;
212     }                   ExistingSysMem;
213 
214 }GMM_TEXTURE_INFO;
215 
216 //***************************************************************************
217 //
218 //                      GMM_TEXTURE API
219 //
220 //***************************************************************************
221 #if(defined(__GMM_KMD__))
222 GMM_STATUS GmmTexAlloc(GMM_LIB_CONTEXT *pGmmLibContext, GMM_TEXTURE_INFO* pTexInfo);
223 GMM_STATUS GmmTexLinearCCS(GMM_LIB_CONTEXT *pGmmLibContext, GMM_TEXTURE_INFO* pTexInfo, GMM_TEXTURE_INFO *pAuxTexInfo);
224 #endif
225 GMM_STATUS GmmTexGetMipMapOffset(GMM_TEXTURE_INFO* pTexInfo, GMM_REQ_OFFSET_INFO* pReqInfo , GMM_LIB_CONTEXT* pGmmLibContext);
226 
227 #define GMM_ISNOT_TILED(TileInfo) ((TileInfo).LogicalSize == 0)
228 #define GMM_IS_TILED(TileInfo)    ((TileInfo).LogicalSize > 0)
229 #define GMM_CLEAR_TILEINFO(TileInfo)            \
230 {                                               \
231         (TileInfo).LogicalSize = 0;             \
232         (TileInfo).LogicalTileHeight = 0;       \
233         (TileInfo).LogicalTileWidth = 0;        \
234         (TileInfo).MaxPitch = 0;                \
235 }
236 
237 #define GMM_IS_4KB_TILE(Flags)  ((Flags).Info.TiledY || (Flags).Info.Tile4)
238 #define GMM_IS_64KB_TILE(Flags) (Flags.Info.TiledYs || Flags.Info.Tile64)
239 #define GMM_IS_SUPPORTED_BPP_ON_TILE_64_YF_YS(bpp) ((bpp == 8) || (bpp == 16) || (bpp == 32) || (bpp == 64) || (bpp == 128))
240 
241 #define GMM_SET_4KB_TILE(Flags, Value,pGmmLibContext) if (pGmmLibContext->GetSkuTable().FtrTileY) ((Flags).Info.TiledY = (Value)); else ((Flags).Info.Tile4 = (Value))
242 #define GMM_SET_64KB_TILE(Flags, Value,pGmmLibContext) if (pGmmLibContext->GetSkuTable().FtrTileY) ((Flags).Info.TiledYs = (Value)); else ((Flags).Info.Tile64 = (Value))
243 #define GMM_SET_4KB_TILE_MODE(TileMode,pGmmLibContext) if (pGmmLibContext->GetSkuTable().FtrTileY) (TileMode = LEGACY_TILE_Y); else (TileMode = TILE4)
244 #define GMM_IS_TILEY(pGmmLibContext) (((GmmClientContext*)pClientContext)->GetSkuTable().FtrTileY)
245 
246 // Reset packing alignment to project default
247 #pragma pack(pop)
248 
249 #ifdef __cplusplus
250 }
251 #endif /*__cplusplus*/
252