Debian Codegraph @

Source/GmmLib/inc/Internal/Common/Texture/GmmTextureCalc.h

raw
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 #ifdef __cplusplus
24 #include "External/Common/GmmMemAllocator.hpp"
25 #include "Internal/Common/GmmLibInc.h"
26 /////////////////////////////////////////////////////////////////////////////////////
27 /// @file GmmTextureCalc.h
28 /// @brief This file contains the common functions and members for texture calculations
29 /// on all GENs/Platforms
30 /////////////////////////////////////////////////////////////////////////////////////
31 namespace GmmLib
32 {
33
34 /////////////////////////////////////////////////////////////////////////
35 /// Contains texture calc functions and members that are common across all
36 /// platform implementation. This is an abstract class and provides a
37 /// uniform interface to all the texture clients and provides gen specific
38 /// texture allocation through derived concrete GmmGenXTextureCalc class.
39 /////////////////////////////////////////////////////////////////////////
40 class Context;
41 class NON_PAGED_SECTION GmmTextureCalc :
42 public GmmMemAllocator
43 {
44 private:
45
46 GMM_STATUS FillTexBlockMem(
47 GMM_TEXTURE_INFO *pTexInfo,
48 __GMM_BUFFER_TYPE *pRestrictions);
49 void ResetRestrictions(__GMM_BUFFER_TYPE *pRestriction);
50
51 void GetTexRestrictions(
52 GMM_TEXTURE_INFO* pTexInfo,
53 __GMM_BUFFER_TYPE* pBuff);
54
55 bool ValidateTexInfo(
56 GMM_TEXTURE_INFO *pTexInfo,
57 __GMM_BUFFER_TYPE *pRestrictions);
58
59 protected:
60 Context *pGmmLibContext;
61
62 /* Function prototypes */
63
64
65 virtual GMM_STATUS GMM_STDCALL FillTexPlanar(
66 GMM_TEXTURE_INFO *pTexInfo,
67 __GMM_BUFFER_TYPE *pRestrictions);
68
69 GMM_STATUS FillTexPitchAndSize(GMM_TEXTURE_INFO *pTexInfo,
70 GMM_GFX_SIZE_T WidthBytesPhysical,
71 uint32_t Height,
72 __GMM_BUFFER_TYPE *pBufferType);
73
74 void FillPlanarOffsetAddress(
75 GMM_TEXTURE_INFO *pTexInfo);
76
77 void FindMipTailStartLod(GMM_TEXTURE_INFO *pTexInfo);
78 GMM_VIRTUAL void GetGenericRestrictions(GMM_TEXTURE_INFO* pTexInfo,
79 __GMM_BUFFER_TYPE *pBuff);
80 GMM_VIRTUAL __GMM_BUFFER_TYPE* GetBestRestrictions(__GMM_BUFFER_TYPE *pFirstBuffer,
81 const __GMM_BUFFER_TYPE *pSecondBuffer);
82 /* Inline functions */
83 /////////////////////////////////////////////////////////////////////////////////////
84 /// Checks where the restrictions are invalid or not
85 /// @param[in] pRestriction Restrictions to check
86 /// @return true if restriction is invalid. false otherwise.
87 /////////////////////////////////////////////////////////////////////////////////////
88 GMM_INLINE_VIRTUAL GMM_INLINE bool IsRestrictionInvalid(__GMM_BUFFER_TYPE *pRestriction)
89 {
90 return ((pRestriction->MinDepth == 0xffffffff) ? true : false);
91 }
92 /////////////////////////////////////////////////////////////////////////////////////
93 /// Returns restrictions for a linear buffer.
94 /// @param[out] pBuff Restrictions are returned in this buffer
95 /////////////////////////////////////////////////////////////////////////////////////
96 GMM_INLINE_VIRTUAL GMM_INLINE void GetLinearRestrictions(GMM_TEXTURE_INFO* pTexInfo, __GMM_BUFFER_TYPE* pBuff)
97 {
98 *pBuff = GMM_OVERRIDE_PLATFORM_INFO(pTexInfo,pGmmLibContext)->Linear;
99 }
100 /////////////////////////////////////////////////////////////////////////////////////
101 /// Returns restrictions for the primary buffer.
102 /// @param[out] pBuff Restrictions are returned in this buffer
103 /////////////////////////////////////////////////////////////////////////////////////
104 GMM_INLINE_VIRTUAL GMM_INLINE void GetPrimaryRestrictions(GMM_TEXTURE_INFO* pTexInfo, __GMM_BUFFER_TYPE* pBuff)
105 {
106 *pBuff = GMM_OVERRIDE_PLATFORM_INFO(pTexInfo,pGmmLibContext)->ASyncFlipSurface;
107 }
108
109 virtual uint32_t Get2DMipMapHeight(GMM_TEXTURE_INFO *pTexInfo) = 0;
110
111 virtual void Fill2DTexOffsetAddress(GMM_TEXTURE_INFO *pTexInfo) = 0;
112
113 virtual GMM_GFX_SIZE_T Get2DTexOffsetAddressPerMip(
114 GMM_TEXTURE_INFO *pTexInfo,
115 uint32_t MipLevel) = 0;
116
117 virtual uint32_t GetMipTailByteOffset(
118 GMM_TEXTURE_INFO *pTexInfo,
119 uint32_t MipLevel)
120 {
121 GMM_UNREFERENCED_PARAMETER(pTexInfo);
122 GMM_UNREFERENCED_PARAMETER(MipLevel);
123 // Left empty
124 return 0;
125 }
126
127 virtual void GetMipTailGeometryOffset(
128 GMM_TEXTURE_INFO *pTexInfo,
129 uint32_t MipLevel,
130 uint32_t* OffsetX,
131 uint32_t* OffsetY,
132 uint32_t* OffsetZ)
133 {
134 GMM_UNREFERENCED_PARAMETER(pTexInfo);
135 GMM_UNREFERENCED_PARAMETER(MipLevel);
136 GMM_UNREFERENCED_PARAMETER(OffsetX);
137 GMM_UNREFERENCED_PARAMETER(OffsetY);
138 GMM_UNREFERENCED_PARAMETER(OffsetZ);
139
140 // Left empty
141 }
142
143 GMM_GFX_SIZE_T Get3DMipByteAddress(
144 GMM_TEXTURE_INFO* pTexInfo,
145 GMM_REQ_OFFSET_INFO *pReqInfo);
146
147 virtual uint32_t GetAligned3DBlockHeight(
148 GMM_TEXTURE_INFO* pTexInfo,
149 uint32_t BlockHeight,
150 uint32_t ExpandedArraySize)
151 {
152 GMM_UNREFERENCED_PARAMETER(pTexInfo);
153 GMM_UNREFERENCED_PARAMETER(BlockHeight);
154 GMM_UNREFERENCED_PARAMETER(ExpandedArraySize);
155
156 // Left empty
157 return 0;
158 }
159
160 public:
161 /* Constructors */
162 // "Creates GmmTextureCalc object based on platform ID"
163 void SetTileMode(GMM_TEXTURE_INFO* pTexInfo);
164
165 GmmTextureCalc(Context *pGmmLibContext)
166 {
167 this->pGmmLibContext = pGmmLibContext;
168 }
169
170 virtual ~GmmTextureCalc()
171 {
172
173 }
174
175 /* Function prototypes */
176 GMM_STATUS AllocateTexture(GMM_TEXTURE_INFO *pTexInfo);
177 virtual GMM_STATUS FillTexCCS(GMM_TEXTURE_INFO *pBaseSurf, GMM_TEXTURE_INFO *pTexInfo);
178 uint8_t SurfaceRequires64KBTileOptimization(
179 GMM_TEXTURE_INFO *pTexInfo);
180
181 uint32_t GetWastageTolerentFactorForTile64Surf(GMM_TEXTURE_INFO *pTexInfo);
182 uint8_t DenyComprsnIfSlicePaddingWasteful(GMM_TEXTURE_INFO *pTexInfo);
183 uint8_t DenyComprsnIfDisPackedMipTailWasteful(GMM_TEXTURE_INFO *pTexInfo);
184 void DoDenyCompression(GMM_TEXTURE_INFO *pTexInfo);
185 uint8_t DenyComprsnIf64KBGranularWasteful(GMM_TEXTURE_INFO *pTexInfo);
186
187 GMM_STATUS PreProcessTexSpecialCases(
188 GMM_TEXTURE_INFO* pTexInfo);
189
190 uint32_t ExpandHeight(
191 uint32_t Height,
192 uint32_t UnitAlignment,
193 uint32_t NumSamples);
194
195 uint32_t ExpandWidth(
196 uint32_t Width,
197 uint32_t UnitAlignment,
198 uint32_t NumSamples);
199
200 void GetCompressionBlockDimensions(
201 GMM_RESOURCE_FORMAT Format,
202 uint32_t *pWidth,
203 uint32_t *pHeight,
204 uint32_t *pDepth);
205
206 GMM_STATUS GetTexRenderOffset(
207 GMM_TEXTURE_INFO* pTexInfo,
208 GMM_REQ_OFFSET_INFO* pReqInfo);
209
210 virtual GMM_STATUS GetTexLockOffset(
211 GMM_TEXTURE_INFO* pTexInfo,
212 GMM_REQ_OFFSET_INFO *pReqInfo);
213
214 GMM_STATUS GetTexStdLayoutOffset(
215 GMM_TEXTURE_INFO* pTexInfo,
216 GMM_REQ_OFFSET_INFO *pReqInfo);
217
218 virtual GMM_GFX_SIZE_T GetMipMapByteAddress(
219 GMM_TEXTURE_INFO* pTexInfo,
220 GMM_REQ_OFFSET_INFO *pReqInfo);
221
222 void AlignTexHeightWidth(
223 GMM_TEXTURE_INFO* pTexInfo,
224 uint32_t* pHeight,
225 uint32_t* pWidth);
226
227 bool GmmGetD3DToHwTileConversion(
228 GMM_TEXTURE_INFO *pTexInfo,
229 uint32_t *pColFactor,
230 uint32_t *pRowFactor);
231 void GetResRestrictions(
232 GMM_TEXTURE_INFO* pTexInfo,
233 __GMM_BUFFER_TYPE& pBuff);
234
235 bool RedescribeTexturePlanes(GMM_TEXTURE_INFO *pTexInfo, uint32_t *pWidthBytesPhysical);
236
237 bool GetRedescribedPlaneParams(GMM_TEXTURE_INFO *pTexInfo, GMM_YUV_PLANE PlaneType, GMM_TEXTURE_INFO *pRedescribedTexInfo);
238
239 // Virtual functions
240 virtual GMM_STATUS GMM_STDCALL FillTex1D(
241 GMM_TEXTURE_INFO *pTexInfo,
242 __GMM_BUFFER_TYPE *pRestrictions) = 0;
243 virtual GMM_STATUS GMM_STDCALL FillTex2D(
244 GMM_TEXTURE_INFO *pTexInfo,
245 __GMM_BUFFER_TYPE *pRestrictions) = 0;
246 virtual GMM_STATUS GMM_STDCALL FillTex3D(
247 GMM_TEXTURE_INFO *pTexInfo,
248 __GMM_BUFFER_TYPE *pRestrictions) = 0;
249 virtual GMM_STATUS GMM_STDCALL FillTexCube(
250 GMM_TEXTURE_INFO *pTexInfo,
251 __GMM_BUFFER_TYPE *pRestrictions) = 0;
252
253 virtual GMM_STATUS GMM_STDCALL GetCCSExMode(GMM_TEXTURE_INFO * AuxSurf)
254 {
255 GMM_UNREFERENCED_PARAMETER(AuxSurf);
256
257 return GMM_SUCCESS;
258 }
259
260 virtual uint32_t GMM_STDCALL ScaleTextureWidth(GMM_TEXTURE_INFO* pTexInfo,
261 uint32_t Width)
262 {
263 __GMM_ASSERT(pTexInfo != NULL);
264
265 switch (pTexInfo->BitsPerPixel)
266 {
267 case 32: Width /= 8; break;
268 case 64: Width /= 4; break;
269 case 128: Width /= 2; break;
270 default: __GMM_ASSERT(0);
271 }
272
273 return Width;
274 }
275
276 virtual uint32_t GMM_STDCALL ScaleTextureHeight(GMM_TEXTURE_INFO* pTexInfo,
277 uint32_t Height)
278 {
279 GMM_UNREFERENCED_PARAMETER(pTexInfo);
280 return Height /= 16;
281 }
282
283 virtual GMM_GFX_SIZE_T GmmTexGetMipWidth(GMM_TEXTURE_INFO *pTexInfo, uint32_t MipLevel)
284 {
285 __GMM_ASSERTPTR(pTexInfo, 0);
286 return(GFX_MAX(1, pTexInfo->BaseWidth >> MipLevel));
287 }
288 virtual uint32_t GmmTexGetMipHeight(GMM_TEXTURE_INFO *pTexInfo, uint32_t MipLevel)
289 {
290 __GMM_ASSERTPTR(pTexInfo, 0);
291 return(GFX_MAX(1, pTexInfo->BaseHeight >> MipLevel));
292 }
293
294 virtual uint32_t GmmTexGetMipDepth(GMM_TEXTURE_INFO *pTexInfo, uint32_t MipLevel)
295 {
296 __GMM_ASSERTPTR(pTexInfo, 0);
297 return(GFX_MAX(1, pTexInfo->Depth >> MipLevel));
298 }
299
300 virtual uint32_t GMM_STDCALL ScaleFCRectHeight(GMM_TEXTURE_INFO * pTexInfo, uint32_t Height)
301 {
302 __GMM_ASSERTPTR(pTexInfo, 0);
303 uint32_t ScaledHeight = Height;
304
305 if (pTexInfo->TileMode == LEGACY_TILE_X)
306 {
307 const uint16_t FastClearRccTileXAlignHeight = 64; // lines - RCC ( Render Color Cache ) Alignment Sizes
308 const uint16_t TileXClearHeightScale = 32; // lines - Clear & Resolve Rect Scaling Sizes
309
310 ScaledHeight = GFX_ALIGN(ScaledHeight, FastClearRccTileXAlignHeight);
311 ScaledHeight /= TileXClearHeightScale;
312 }
313 else if (pTexInfo->TileMode == LEGACY_TILE_Y)
314 {
315 const uint16_t FastClearRccTileYAlignHeight = 128; // bits
316 const uint16_t TileYClearHeightScale = 64; // bits
317
318 ScaledHeight = GFX_ALIGN(ScaledHeight, FastClearRccTileYAlignHeight);
319 ScaledHeight /= TileYClearHeightScale;
320 }
321 return ScaledHeight;
322
323 }
324
325 virtual uint64_t GMM_STDCALL ScaleFCRectWidth(GMM_TEXTURE_INFO * pTexInfo, uint64_t Width)
326 {
327 __GMM_ASSERTPTR(pTexInfo, 0);
328 uint64_t ScaledWidth = Width;
329
330 if (pTexInfo->TileMode == LEGACY_TILE_X)
331 {
332 const uint32_t FastClearRccTileXAlignWidth = 8192; // bits - RCC ( Render Color Cache ) Alignment Sizes
333 const uint32_t TileXClearWidthScale = 4096; // bits - Clear & Resolve Rect Scaling Sizes
334
335 ScaledWidth = GFX_ALIGN(ScaledWidth, FastClearRccTileXAlignWidth / pTexInfo->BitsPerPixel);
336 ScaledWidth /= TileXClearWidthScale;
337 }
338 else if (pTexInfo->TileMode == LEGACY_TILE_Y)
339 {
340 const uint32_t FastClearRccTileYAlignWidth = 4096; // bits
341 const uint32_t TileYClearWidthScale = 2048; // bits
342
343 ScaledWidth = GFX_ALIGN(ScaledWidth, FastClearRccTileYAlignWidth / pTexInfo->BitsPerPixel);
344 ScaledWidth /= TileYClearWidthScale;
345 }
346 return ScaledWidth;
347 }
348
349 virtual GMM_STATUS GMM_STDCALL MSAACCSUsage(GMM_TEXTURE_INFO *pTexInfo);
350 virtual void GMM_STDCALL AllocateOneTileThanRequied(GMM_TEXTURE_INFO *pTexInfo,
351 GMM_GFX_SIZE_T &WidthBytesRender,
352 GMM_GFX_SIZE_T &WidthBytesPhysical,
353 GMM_GFX_SIZE_T &WidthBytesLock);
354 GMM_STATUS MSAACompression(GMM_TEXTURE_INFO *pTexInfo);
355 virtual uint64_t GMM_STDCALL Get2DFCSurfaceWidthFor3DSurface(GMM_TEXTURE_INFO *pTexInfo,
356 uint64_t Width)
357 {
358 GMM_UNREFERENCED_PARAMETER(pTexInfo);
359 return Width;
360 }
361 virtual uint64_t GMM_STDCALL Get2DFCSurfaceHeightFor3DSurface(GMM_TEXTURE_INFO *pTexInfo,
362 uint32_t Height,
363 uint32_t Depth)
364 {
365 GMM_UNREFERENCED_PARAMETER(pTexInfo);
366 GMM_UNREFERENCED_PARAMETER(Depth);
367 return Height;
368 }
369
370 uint32_t GMM_STDCALL GetDisplayFrameOffset(GMM_TEXTURE_INFO *pTexInfo,
371 GMM_REQ_OFFSET_INFO *pReqInfo);
372 virtual uint32_t GMM_STDCALL IsTileAlignedPlanes(GMM_TEXTURE_INFO *pTexInfo);
373 virtual uint32_t GMM_STDCALL GetNumberOfPlanes(GMM_TEXTURE_INFO *pTexInfo);
374 virtual void GMM_STDCALL SetPlanarOffsetInfo(GMM_TEXTURE_INFO *pTexInfo,
375 GMM_RESCREATE_CUSTOM_PARAMS &CreateParams);
376 #ifndef __GMM_KMD__
377 virtual void GMM_STDCALL SetPlanarOffsetInfo_2(GMM_TEXTURE_INFO *pTexInfo,
378 GMM_RESCREATE_CUSTOM_PARAMS_2 &CreateParams);
379 #endif
380 virtual void GMM_STDCALL SetPlaneUnAlignedTexOffsetInfo(GMM_TEXTURE_INFO *pTexInfo,
381 uint32_t YHeight,
382 uint32_t VHeight);
383 virtual void GMM_STDCALL GetPlaneIdForCpuBlt(GMM_TEXTURE_INFO *pTexInfo,
384 GMM_RES_COPY_BLT *pBlt,
385 uint32_t *PlaneId);
386 virtual void GMM_STDCALL GetBltInfoPerPlane(GMM_TEXTURE_INFO *pTexInfo,
387 GMM_RES_COPY_BLT *pBlt,
388 uint32_t PlaneId);
389 /* inline functions */
390 };
391
392 }
393 #endif // #ifdef __cplusplus