xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/inc/External/Common/GmmResourceInfoCommon.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 #ifdef __cplusplus
25 #include "GmmMemAllocator.hpp"
26 #include "GmmCachePolicy.h"
27 #include "GmmUtil.h"
28 #include "GmmInfoExt.h"
29 #include "GmmInfo.h"
30 #include "../../../Platform/GmmPlatforms.h"
31 #include "../../../../inc/common/gfxmacro.h"
32 #include "GmmClientContext.h"
33 
34 // Macro definitions
35 #ifndef __GMM_ASSERT
36     // Needs to be defined before including this file. If not defined, then
37     // we'll nop these macros.
38     #define __GMM_ASSERT(expr)
39     #define GMM_ASSERTDPF(expr, ret)
40     #define __GMM_ASSERTPTR(expr, ret)
41 #endif
42 
43 /////////////////////////////////////////////////////////////////////////////////////
44 /// @file GmmResourceInfoCommon.h
45 /// @brief This file contains the functions and members of GmmResourceInfo that is
46 ///       common for both Linux and Windows.
47 ///
48 /////////////////////////////////////////////////////////////////////////////////////
49 namespace GmmLib
50 {
51     /////////////////////////////////////////////////////////////////////////
52     /// Contains functions and members that are common between Linux and
53     /// Windows implementation.  This class is inherited by the Linux and
54     /// Windows specific class, so clients shouldn't have to ever interact
55     /// with this class directly.
56     /////////////////////////////////////////////////////////////////////////
57     class GMM_LIB_API NON_PAGED_SECTION GmmResourceInfoCommon:
58                             public GmmMemAllocator
59     {
60         protected:
61             /// Type of Client type using the library. Can be used by GmmLib to
62             /// implement client specific functionality.
63             GMM_CLIENT                          ClientType;
64             GMM_TEXTURE_INFO                    Surf;                       ///< Contains info about the surface being created
65             GMM_TEXTURE_INFO                    AuxSurf;                    ///< Contains info about the auxiliary surface if using Unified Auxiliary surfaces.
66             GMM_TEXTURE_INFO                    AuxSecSurf;                 ///< For multi-Aux surfaces, contains info about the secondary auxiliary surface
67 
68             uint32_t                            RotateInfo;
69             GMM_EXISTING_SYS_MEM                ExistingSysMem;     ///< Info about resources initialized with existing system memory
70             GMM_GFX_ADDRESS                     SvmAddress;         ///< Driver managed SVM address
71 
72             uint64_t                            pGmmUmdLibContext;     ///< Pointer to GmmLib context created in DLL passed in during Create()
73             uint64_t                            pGmmKmdLibContext;     ///< Pointer to GmmLib context created in KMD passed in during Create()
74             uint64_t                            pPrivateData;       ///< Allows clients to attach any private data to GmmResourceInfo
75 #ifdef __GMM_KMD__
76             void                               *pClientContext;    ///< void * in order to of same size for the ResInfo Object across KMD and UMD
77 #else
78             GmmClientContext                   *pClientContext;    ///< ClientContext of the client creating this Resource
79 #endif
80             GMM_MULTI_TILE_ARCH                MultiTileArch;
81 
82         private:
83             GMM_STATUS          ApplyExistingSysMemRestrictions();
84 
85         protected:
86             /* Function prototypes */
87             GMM_VIRTUAL bool                IsPresentableformat();
88             // Move GMM Restrictions to it's own class?
89             virtual bool        CopyClientParams(GMM_RESCREATE_PARAMS &CreateParams);
90             GMM_VIRTUAL const GMM_PLATFORM_INFO& GetPlatformInfo();
91 
92             /////////////////////////////////////////////////////////////////////////////////////
93             /// Returns tile mode for SURFACE_STATE programming.
94             /// @return     Tiled Mode
95             /////////////////////////////////////////////////////////////////////////////////////
GetTileModeSurfaceState(const GMM_TEXTURE_INFO * pTextureInfo)96             GMM_INLINE uint32_t GetTileModeSurfaceState(const GMM_TEXTURE_INFO *pTextureInfo)
97             {
98                 uint32_t TiledMode = 0;
99 
100                 if(GMM_IS_TILEY(GetGmmLibContext()))
101                 {
102                     TiledMode =
103                         pTextureInfo->Flags.Info.Linear ? 0 :
104                             pTextureInfo->Flags.Info.TiledW ? 1 :
105                             pTextureInfo->Flags.Info.TiledX ? 2 :
106                             /* Y/YF/YS */ 3;
107 
108                     __GMM_ASSERT((TiledMode != 3) || (pTextureInfo->Flags.Info.TiledY || pTextureInfo->Flags.Info.TiledYf || pTextureInfo->Flags.Info.TiledYs));
109                 }
110                 else
111                 {
112                     TiledMode =
113                         (GMM_IS_4KB_TILE(pTextureInfo->Flags)) ? 3 :
114                             (GMM_IS_64KB_TILE(pTextureInfo->Flags)) ? 1 :
115                             pTextureInfo->Flags.Info.TiledX ? 2 :
116                             /* Linear */ 0;
117 
118                     __GMM_ASSERT(TiledMode || pTextureInfo->Flags.Info.Linear);
119                 }
120 
121                 return TiledMode;
122             }
123 
124     public:
125             /* Constructors */
GmmResourceInfoCommon()126             GmmResourceInfoCommon():
127                 ClientType(),
128                 Surf(),
129                 AuxSurf(),
130                 AuxSecSurf(),
131                 RotateInfo(),
132                 ExistingSysMem(),
133                 SvmAddress(),
134                 pGmmUmdLibContext(),
135                 pGmmKmdLibContext(),
136                 pPrivateData(),
137                 pClientContext(),
138                 MultiTileArch()
139             {
140             }
141 
142 #ifndef __GMM_KMD__
GmmResourceInfoCommon(GmmClientContext * pClientContextIn)143             GmmResourceInfoCommon(GmmClientContext  *pClientContextIn) :
144                 ClientType(),
145                 Surf(),
146                 AuxSurf(),
147                 AuxSecSurf(),
148                 RotateInfo(),
149                 ExistingSysMem(),
150                 SvmAddress(),
151                 pGmmUmdLibContext(),
152                 pGmmKmdLibContext(),
153                 pPrivateData(),
154                 pClientContext(),
155                 MultiTileArch()
156             {
157                 pClientContext = pClientContextIn;
158 			}
159 #endif
160 
161             GmmResourceInfoCommon& operator=(const GmmResourceInfoCommon& rhs)
162             {
163                 ClientType          = rhs.ClientType;
164                 Surf                = rhs.Surf;
165                 AuxSurf             = rhs.AuxSurf;
166                 AuxSecSurf          = rhs.AuxSecSurf;
167                 RotateInfo          = rhs.RotateInfo;
168                 ExistingSysMem      = rhs.ExistingSysMem;
169                 SvmAddress          = rhs.SvmAddress;
170                 pPrivateData        = rhs.pPrivateData;
171                 MultiTileArch       = rhs.MultiTileArch;
172 
173                 return *this;
174             }
175 
~GmmResourceInfoCommon()176             virtual ~GmmResourceInfoCommon()
177             {
178                 if (ExistingSysMem.pVirtAddress && ExistingSysMem.IsGmmAllocated)
179                 {
180                     GMM_FREE((void *)ExistingSysMem.pVirtAddress);
181                 }
182             }
183 
184             /* Function prototypes */
185             // Overloaded Create function to keep backward compatible. This shall be deprecated soon
186             GMM_VIRTUAL GMM_STATUS              GMM_STDCALL Create(Context &GmmLibContext, GMM_RESCREATE_PARAMS &CreateParams);
187             GMM_VIRTUAL uint8_t                 GMM_STDCALL ValidateParams();
188             GMM_VIRTUAL GMM_STATUS              GMM_STDCALL Create(GMM_RESCREATE_PARAMS &CreateParams);
189             GMM_VIRTUAL void                    GMM_STDCALL GetRestrictions(__GMM_BUFFER_TYPE& Restrictions);
190             GMM_VIRTUAL uint32_t                GMM_STDCALL GetPaddedWidth(uint32_t MipLevel);
191             GMM_VIRTUAL uint32_t                GMM_STDCALL GetPaddedHeight(uint32_t MipLevel);
192             GMM_VIRTUAL uint32_t                GMM_STDCALL GetPaddedPitch(uint32_t MipLevel);
193             GMM_VIRTUAL uint32_t                GMM_STDCALL GetQPitch();
194             GMM_VIRTUAL GMM_STATUS              GMM_STDCALL GetOffset(GMM_REQ_OFFSET_INFO &ReqInfo);
195             GMM_VIRTUAL uint8_t                 GMM_STDCALL CpuBlt(GMM_RES_COPY_BLT *pBlt);
196             GMM_VIRTUAL uint8_t                 GMM_STDCALL GetMappingSpanDesc(GMM_GET_MAPPING *pMapping);
197             GMM_VIRTUAL uint8_t                 GMM_STDCALL Is64KBPageSuitable();
198             GMM_VIRTUAL void                    GMM_STDCALL GetTiledResourceMipPacking(uint32_t *pNumPackedMips,
199                                                                            uint32_t *pNumTilesForPackedMips);
200             GMM_VIRTUAL uint32_t                GMM_STDCALL GetPackedMipTailStartLod();
201             GMM_VIRTUAL bool                    GMM_STDCALL IsMipRCCAligned(uint8_t &MisAlignedLod);
202             GMM_VIRTUAL uint8_t                 GMM_STDCALL GetDisplayFastClearSupport();
203             GMM_VIRTUAL uint8_t                 GMM_STDCALL GetDisplayCompressionSupport();
204             GMM_VIRTUAL GMM_GFX_SIZE_T          GMM_STDCALL GetMipWidth(uint32_t MipLevel);
205             GMM_VIRTUAL uint32_t                GMM_STDCALL GetMipHeight(uint32_t MipLevel);
206             GMM_VIRTUAL uint32_t                GMM_STDCALL GetMipDepth(uint32_t MipLevel);
207             GMM_VIRTUAL uint64_t                GMM_STDCALL GetFastClearWidth(uint32_t MipLevel);
208             GMM_VIRTUAL uint32_t                GMM_STDCALL GetFastClearHeight(uint32_t MipLevel);
209 
210 
211 
212             /* inline functions */
213 
214 #ifndef __GMM_KMD__
215             /////////////////////////////////////////////////////////////////////////////////////
216             /// Returns GmmClientContext associated with this resource
217             /// @return ::GmmClientContext
218             /////////////////////////////////////////////////////////////////////////////////////
GetGmmClientContext()219             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GmmClientContext* GetGmmClientContext()
220             {
221                 return pClientContext;
222             }
223 
224             /////////////////////////////////////////////////////////////////////////////////////
225             /// Sets GmmClientContext to be associated with this resource
226             /// @return ::void
227             /////////////////////////////////////////////////////////////////////////////////////
SetGmmClientContext(GmmClientContext * pGmmClientContext)228             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void SetGmmClientContext(GmmClientContext* pGmmClientContext)
229             {
230                 pClientContext = pGmmClientContext;
231                 GET_GMM_CLIENT_TYPE(pGmmClientContext, ClientType);
232             }
233 
234 #endif
235 
236 
237 
238             /////////////////////////////////////////////////////////////////////////////////////
239             /// This function Sets GmmLibContext in GmmResInfo.
240             /// GMMResInfo gets passed as private data from UMDs to KMD during
241             //  GMMCreateAllocation and GmmOpenAllocation
242             /// Member functions of ResInfo class need to access the LibContext object. But since
243             /// the LibContext object present in ResInfo is created by UMDs in UMD space,
244             /// and this UMD space object cant be used in KMD space,
245             /// we need this API to set the KMD LibContext in ResInfo object.
246             /// @return ::void
247             /////////////////////////////////////////////////////////////////////////////////////
SetGmmLibContext(void * pLibContext)248             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void SetGmmLibContext(void *pLibContext)
249             {
250 #if(defined(__GMM_KMD__))
251                 pGmmKmdLibContext = reinterpret_cast<uint64_t>(pLibContext);
252 #else
253                 pGmmUmdLibContext = reinterpret_cast<uint64_t>(pLibContext);
254 #endif
255             }
256 
257             /////////////////////////////////////////////////////////////////////////////////////
258             /// Returns either UMD or KMD GMMLibContext that needs to be used when the ResInfo
259             /// Member functions are executed at KMD or UMD level
260             /// @return ::Context
261             /////////////////////////////////////////////////////////////////////////////////////
GetGmmLibContext()262             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED Context *GetGmmLibContext()
263             {
264 #if(defined(__GMM_KMD__))
265                 return ((Context *)pGmmKmdLibContext);
266 #else
267                 return ((Context *)pGmmUmdLibContext);
268 #endif
269             }
270 
271             /////////////////////////////////////////////////////////////////////////////////////
272             /// Returns GMM_CLIENT Type that has created this resource
273             /// @return ::GMM_CLIENT
274             /////////////////////////////////////////////////////////////////////////////////////
SetClientType(GMM_CLIENT Client)275             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void SetClientType(GMM_CLIENT Client)
276             {
277                 ClientType = Client;
278             }
279 
280             /////////////////////////////////////////////////////////////////////////////////////
281             /// Returns GMM_CLIENT Type that has created this resource
282             /// @return ::GMM_CLIENT
283             /////////////////////////////////////////////////////////////////////////////////////
GetClientType()284             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_CLIENT GetClientType()
285             {
286                 return ClientType;
287             }
288 
289             /////////////////////////////////////////////////////////////////////////////////////
290             /// Returns the system memory pointer. It selectively returns either the natural
291             /// pointer or a value appropriately page aligned for D3DDI_ALLOCATIONINFO,
292             /// depending on what the caller request.
293             /// @param[in]      IsD3DDdiAllocation: Specifies where allocation was made by a D3D client
294             /// @return         Pointer to system memory. NULL if not available.
295             /////////////////////////////////////////////////////////////////////////////////////
GetSystemMemPointer(uint8_t IsD3DDdiAllocation)296             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void* GMM_STDCALL GetSystemMemPointer(uint8_t IsD3DDdiAllocation)
297             {
298 	        if (IsD3DDdiAllocation)
299 	        {
300 		    return (void *)GMM_GFX_ADDRESS_CANONIZE(ExistingSysMem.pGfxAlignedVirtAddress);
301 	        }
302 	        else
303 	        {
304 		    return (void *)GMM_GFX_ADDRESS_CANONIZE(ExistingSysMem.pVirtAddress);
305 		}
306             }
307 
308             /////////////////////////////////////////////////////////////////////////////////////
309             /// Returns the system memory size.
310             /// @return     Size of memory.
311             /////////////////////////////////////////////////////////////////////////////////////
GetSystemMemSize()312             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetSystemMemSize()
313             {
314                 return ExistingSysMem.Size;
315             }
316 
317             /////////////////////////////////////////////////////////////////////////////////////
318             /// Returns a reference to the surface flags.
319             /// @return     Reference to ::GMM_RESOURCE_FLAGS
320             /////////////////////////////////////////////////////////////////////////////////////
GetResFlags()321             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_RESOURCE_FLAG& GMM_STDCALL GetResFlags()
322             {
323                 return Surf.Flags;
324             }
325 
326             /////////////////////////////////////////////////////////////////////////////////////
327             /// Returns the resource type
328             /// @return     ::GMM_RESOURCE_TYPE
329             /////////////////////////////////////////////////////////////////////////////////////
GetResourceType()330             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_RESOURCE_TYPE GMM_STDCALL GetResourceType()
331             {
332                 return Surf.Type;
333             }
334 
335             /////////////////////////////////////////////////////////////////////////////////////
336             /// Returns the resource format
337             /// @return     ::GMM_RESOURCE_FORMAT
338             /////////////////////////////////////////////////////////////////////////////////////
GetResourceFormat()339             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_RESOURCE_FORMAT GMM_STDCALL GetResourceFormat()
340             {
341                 return Surf.Format;
342             }
343 
344             /////////////////////////////////////////////////////////////////////////////////////
345             /// Returns the resource width
346             /// @return     width
347             /////////////////////////////////////////////////////////////////////////////////////
GetBaseWidth()348             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetBaseWidth()
349             {
350                 return Surf.BaseWidth;
351             }
352 
353             /////////////////////////////////////////////////////////////////////////////////////
354             /// Returns the resource height
355             /// @return     height
356             /////////////////////////////////////////////////////////////////////////////////////
GetBaseHeight()357             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetBaseHeight()
358             {
359                 return Surf.BaseHeight;
360             }
361 
362 
363             /////////////////////////////////////////////////////////////////////////////////////
364             /// Returns the resource depth
365             /// @return     depth
366             /////////////////////////////////////////////////////////////////////////////////////
GetBaseDepth()367             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetBaseDepth()
368             {
369                 return Surf.Depth;
370             }
371 
372             /////////////////////////////////////////////////////////////////////////////////////
373             /// Returns the resource's base alignment
374             /// @return     Base Alignment
375             /////////////////////////////////////////////////////////////////////////////////////
GetBaseAlignment()376             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetBaseAlignment()
377             {
378                 return Surf.Alignment.BaseAlignment;
379             }
380 
381             /////////////////////////////////////////////////////////////////////////////////////
382             /// Returns the resource's max lod
383             /// @return     Max Lod
384             /////////////////////////////////////////////////////////////////////////////////////
GetMaxLod()385             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetMaxLod()
386             {
387                 return Surf.MaxLod;
388             }
389 
390             /////////////////////////////////////////////////////////////////////////////////////
391             /// Returns the resource's max array size
392             /// @return     Max Array Size
393             /////////////////////////////////////////////////////////////////////////////////////
GetArraySize()394             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetArraySize()
395             {
396                 return Surf.ArraySize;
397             }
398 
399             /////////////////////////////////////////////////////////////////////////////////////
400             /// Returns the resource's rotation info
401             /// @return    rotation info
402             /////////////////////////////////////////////////////////////////////////////////////
GetRotateInfo()403             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetRotateInfo()
404             {
405                 return RotateInfo;
406             }
407 
408             /////////////////////////////////////////////////////////////////////////////////////
409             /// Returns the resource's maximum remaining list length
410             /// @return    maximum remaining list length
411             /////////////////////////////////////////////////////////////////////////////////////
GetMaximumRenamingListLength()412             GMM_INLINE_VIRTUAL uint32_t GMM_STDCALL GetMaximumRenamingListLength()
413             {
414                 return Surf.MaximumRenamingListLength;
415             }
416 
417             /////////////////////////////////////////////////////////////////////////////////////
418             /// Returns the auxiliary resource's QPitch
419             /// @return    Aux QPitch
420             /////////////////////////////////////////////////////////////////////////////////////
GetAuxQPitch()421             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetAuxQPitch()
422             {
423                 const GMM_PLATFORM_INFO   *pPlatform;
424 
425                 pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
426 
427 		if (Surf.Flags.Gpu.UnifiedAuxSurface)
428                 {
429                     if (GMM_IS_PLANAR(Surf.Format))
430                     {
431                         return static_cast<uint32_t>(AuxSurf.OffsetInfo.Plane.ArrayQPitch);
432                     }
433                     else if (AuxSurf.Flags.Gpu.HiZ)
434                     {
435                         // HiZ        ==> HZ_PxPerByte * HZ_QPitch
436                         return AuxSurf.Alignment.QPitch * pPlatform->HiZPixelsPerByte;
437                     }
438                     else
439                     {
440                         return AuxSurf.Alignment.QPitch;
441                     }
442                 }
443                 else
444                 {
445                     return GetQPitch();
446                 }
447             }
448 
449             /////////////////////////////////////////////////////////////////////////////////////
450             /// Returns the planar resource's QPitch
451             /// @return    planar QPitch in rows
452             /////////////////////////////////////////////////////////////////////////////////////
GetQPitchPlanar(GMM_YUV_PLANE Plane)453             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetQPitchPlanar(GMM_YUV_PLANE Plane)
454             {
455                 uint32_t               QPitch;
456                 const GMM_PLATFORM_INFO   *pPlatform;
457 
458                 __GMM_ASSERT(GMM_IS_PLANAR(Surf.Format));
459                 GMM_UNREFERENCED_LOCAL_VARIABLE(Plane);
460 
461                 pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
462 
463 	        __GMM_ASSERT(GFX_GET_CURRENT_RENDERCORE(pPlatform->Platform) >= IGFX_GEN8_CORE);
464 		GMM_UNREFERENCED_PARAMETER(pPlatform);
465 
466                 QPitch = static_cast<uint32_t>(Surf.OffsetInfo.Plane.ArrayQPitch / Surf.Pitch);
467 
468                 return QPitch;
469             }
470 
471             /////////////////////////////////////////////////////////////////////////////////////
472             /// Returns distance in bytes between array elements (or pseudo-array-elements--e.g.
473             /// cube faces, MSFMT_MSS sample planes).
474             /// @return    QPitch
475             /////////////////////////////////////////////////////////////////////////////////////
GetQPitchInBytes()476             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetQPitchInBytes()
477             {
478                 return Surf.OffsetInfo.Texture2DOffsetInfo.ArrayQPitchRender;
479             }
480 
481             /////////////////////////////////////////////////////////////////////////////////////
482             /// Returns resource's pitch
483             /// @return    Pitch
484             /////////////////////////////////////////////////////////////////////////////////////
GetRenderPitch()485             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetRenderPitch()
486             {
487                 return Surf.Pitch;
488             }
489 
490             /////////////////////////////////////////////////////////////////////////////////////
491             /// Returns resource's pitch in tiles
492             /// @return    Pitch in tiles
493             /////////////////////////////////////////////////////////////////////////////////////
GetRenderPitchTiles()494             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetRenderPitchTiles()
495             {
496                 uint32_t               PitchInTiles;
497                 const GMM_PLATFORM_INFO   *pPlatform;
498                 GMM_TILE_MODE       TileMode;
499 
500                 __GMM_ASSERT(!Surf.Flags.Info.Linear);
501 
502                 TileMode = Surf.TileMode;
503                 __GMM_ASSERT(TileMode < GMM_TILE_MODES);
504 
505                 pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
506                 if (pPlatform->TileInfo[TileMode].LogicalTileWidth != 0)
507                 {
508                     // In case of Depth/Stencil buffer MSAA TileYs surface, the LogicalTileWidth/Height is smaller than non-MSAA ones
509                     // Thus introducing the below variable to get the right PitchInTiles
510                     uint32_t MSAASpecialFactorForDepthAndStencil = 1;
511 
512                     if ((Surf.Flags.Gpu.Depth || Surf.Flags.Gpu.SeparateStencil) &&
513                          (Surf.MSAA.NumSamples > 1 && (GMM_IS_64KB_TILE(Surf.Flags) || Surf.Flags.Info.TiledYf)))
514                     {
515                         switch (Surf.MSAA.NumSamples)
516                         {
517                             case 2:
518 			                    MSAASpecialFactorForDepthAndStencil = 2;
519 			                    if (GetGmmLibContext()->GetSkuTable().FtrXe2PlusTiling && (Surf.BitsPerPixel == 128))
520 			                    {
521 			                        MSAASpecialFactorForDepthAndStencil = 1;
522 			                    }
523 			                    break;
524                             case 4:
525                                 MSAASpecialFactorForDepthAndStencil = 2;
526                                 break;
527                             case 8:
528 			                    MSAASpecialFactorForDepthAndStencil = 4;
529 			                    if (GetGmmLibContext()->GetSkuTable().FtrXe2PlusTiling)
530 			                    {
531 			                        if (Surf.BitsPerPixel == 32 || Surf.BitsPerPixel == 8)
532 			                        {
533 			                            MSAASpecialFactorForDepthAndStencil = 2;
534 			                        }
535 			                    }
536 			                    else if (!GetGmmLibContext()->GetSkuTable().FtrTileY && !GetGmmLibContext()->GetSkuTable().FtrXe2PlusTiling)
537 			                    {
538 			                        MSAASpecialFactorForDepthAndStencil = 2; // same as 4X
539 			                    }
540 			                    break;
541                             case 16:
542                                 MSAASpecialFactorForDepthAndStencil = 4;
543 			                    if (GetGmmLibContext()->GetSkuTable().FtrXe2PlusTiling)
544 			                    {
545 			                        if (Surf.BitsPerPixel == 64)
546 			                        {
547 			                            MSAASpecialFactorForDepthAndStencil = 8;
548 			                        }
549 			                    }
550 			                    else if (!GetGmmLibContext()->GetSkuTable().FtrTileY && !GetGmmLibContext()->GetSkuTable().FtrXe2PlusTiling)
551 			                    {
552 			                        MSAASpecialFactorForDepthAndStencil = 2; // same as 4X
553 			                    }
554                                 break;
555                             default:
556                                 break;
557                         }
558                     }
559 
560                     PitchInTiles = static_cast<uint32_t>(Surf.Pitch / pPlatform->TileInfo[TileMode].LogicalTileWidth);
561                     PitchInTiles /= MSAASpecialFactorForDepthAndStencil;
562                 }
563                 else
564                 {
565                     // Surf.TileMode not set correctly
566                     __GMM_ASSERT(false);
567                     PitchInTiles = 0;
568                 }
569 
570                 return PitchInTiles;
571             }
572 
573             /////////////////////////////////////////////////////////////////////////////////////
574             /// Returns unified auxiliary resource's pitch in tiles
575             /// @return    Aux Pitch in bytes
576             /////////////////////////////////////////////////////////////////////////////////////
GetUnifiedAuxPitch()577             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetUnifiedAuxPitch()
578             {
579                 return AuxSurf.Pitch;
580             }
581 
582             /////////////////////////////////////////////////////////////////////////////////////
583             /// Returns auxiliary resource's pitch in tiles
584             /// @return    Aux Pitch in tiles
585             /////////////////////////////////////////////////////////////////////////////////////
GetRenderAuxPitchTiles()586             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetRenderAuxPitchTiles()
587             {
588                 uint32_t               PitchInTiles = 0;
589                 const GMM_PLATFORM_INFO   *pPlatform;
590 
591                 __GMM_ASSERT(!AuxSurf.Flags.Info.Linear);
592 
593                 pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&AuxSurf, GetGmmLibContext());
594 
595                 if (Surf.Flags.Gpu.UnifiedAuxSurface)
596                 {
597                     const GMM_TILE_MODE TileMode = AuxSurf.TileMode;
598                     __GMM_ASSERT(TileMode < GMM_TILE_MODES);
599 
600                     if (pPlatform->TileInfo[TileMode].LogicalTileWidth)
601                     {
602                         PitchInTiles = static_cast<uint32_t>(AuxSurf.Pitch / pPlatform->TileInfo[TileMode].LogicalTileWidth);
603                     }
604                 }
605                 else
606                 {
607                     PitchInTiles = GetRenderPitchTiles();
608                 }
609 
610                 return PitchInTiles;
611             }
612 
613             /////////////////////////////////////////////////////////////////////////////////////
614             /// Returns resource's bits per pixel
615             /// @return    bpp
616             /////////////////////////////////////////////////////////////////////////////////////
GetBitsPerPixel()617             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetBitsPerPixel()
618             {
619                 return Surf.BitsPerPixel;
620             }
621 
622             /////////////////////////////////////////////////////////////////////////////////////
623             /// Returns unified aux resource's bits per pixel
624             /// @return    aux bpp
625             /////////////////////////////////////////////////////////////////////////////////////
GetUnifiedAuxBitsPerPixel()626             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetUnifiedAuxBitsPerPixel()
627             {
628                 __GMM_ASSERT(Surf.Flags.Gpu.UnifiedAuxSurface);
629                 return AuxSurf.BitsPerPixel;
630             }
631 
632             /////////////////////////////////////////////////////////////////////////////////////
633             /// Returns layout of the mips: right or below.
634             /// @return    ::GMM_TEXTURE_LAYOUT
635             /////////////////////////////////////////////////////////////////////////////////////
GetTextureLayout()636             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_TEXTURE_LAYOUT GMM_STDCALL GetTextureLayout()
637             {
638                 return Surf.Flags.Info.LayoutRight? GMM_2D_LAYOUT_RIGHT : GMM_2D_LAYOUT_BELOW;
639             }
640 
641             /////////////////////////////////////////////////////////////////////////////////////
642             /// Returns resource's tile type
643             /// @return    ::GMM_TILE_TYPE
644             /////////////////////////////////////////////////////////////////////////////////////
GetTileType()645             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_TILE_TYPE GMM_STDCALL GetTileType()
646             {
647                 if (Surf.Flags.Info.TiledW)
648                 {
649                     return GMM_TILED_W;
650                 }
651                 else if (Surf.Flags.Info.TiledX)
652                 {
653                     return GMM_TILED_X;
654                 }
655                 // Surf.Flags.Info.TiledYs/Yf tiling are only in
656                 // conjunction with Surf.Flags.Info.TiledY/Linear depending on resource type (1D).
657                 else if (Surf.Flags.Info.TiledY)
658                 {
659                     return GMM_TILED_Y;
660                 }
661                 else if (Surf.Flags.Info.Tile4)
662                 {
663                     return GMM_TILED_4;
664                 }
665                 else if (Surf.Flags.Info.Tile64)
666                 {
667                     return GMM_TILED_64;
668                 }
669 
670                 return GMM_NOT_TILED;
671             }
672 
673             /////////////////////////////////////////////////////////////////////////////////////
674             /// Returns resource's tile mode
675             /// @return    ::GMM_TILE_MODE
676             /////////////////////////////////////////////////////////////////////////////////////
GmmGetTileMode()677             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_TILE_MODE GMM_STDCALL GmmGetTileMode()
678             {
679                 return Surf.TileMode;
680             }
681 
682             /////////////////////////////////////////////////////////////////////////////////////
683             /// Returns CPU cacheability information
684             /// @return    ::GMM_CPU_CACHE_TYPE
685             /////////////////////////////////////////////////////////////////////////////////////
GetCpuCacheType()686             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_CPU_CACHE_TYPE GMM_STDCALL GetCpuCacheType()
687             {
688                 if (Surf.Flags.Info.Cacheable)
689                 {
690                     return GMM_CACHEABLE;
691                 }
692 
693                 return GMM_NOTCACHEABLE;
694             }
695 
696             /////////////////////////////////////////////////////////////////////////////////////
697             /// Returns Media Memory Compression mode.
698             /// @param[in] ArrayIndex ArrayIndex for which this info is needed
699             /// @return    Media Memory Compression Mode (Disabled, Horizontal, Vertical)
700             /////////////////////////////////////////////////////////////////////////////////////
GetMmcMode(uint32_t ArrayIndex)701             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_RESOURCE_MMC_INFO GMM_STDCALL GetMmcMode(uint32_t ArrayIndex)
702             {
703                 __GMM_ASSERT(ArrayIndex < GMM_MAX_MMC_INDEX);
704 
705                 return
706                     (ArrayIndex < GMM_MAX_MMC_INDEX) ?
707                         (GMM_RESOURCE_MMC_INFO)Surf.MmcMode[ArrayIndex] :
708                             GMM_MMC_DISABLED;
709             }
710 
711             /////////////////////////////////////////////////////////////////////////////////////
712             /// Sets Media Memory Compression mode.
713             /// @param[in] Mode Media Memory Compression Mode (Disabled, Horizontal, Vertical)
714             /// @param[in] ArrayIndex ArrayIndex for which this info needs to be set
715             /////////////////////////////////////////////////////////////////////////////////////
SetMmcMode(GMM_RESOURCE_MMC_INFO Mode,uint32_t ArrayIndex)716             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL SetMmcMode(GMM_RESOURCE_MMC_INFO Mode, uint32_t ArrayIndex)
717             {
718                 __GMM_ASSERT((Mode == GMM_MMC_DISABLED) || (Mode == GMM_MMC_HORIZONTAL) || (Mode == GMM_MMC_VERTICAL));
719 
720                 __GMM_ASSERT(ArrayIndex < GMM_MAX_MMC_INDEX);
721 
722                 if (ArrayIndex < GMM_MAX_MMC_INDEX)
723                 {
724                     Surf.MmcMode[ArrayIndex] = static_cast<uint8_t>(Mode);
725                 }
726             }
727 
728             /////////////////////////////////////////////////////////////////////////////////////
729             /// Returns whether Media Memory Compression enabled or not.
730             /// @param[in]  ArrayIndex ArrayIndex for which this info is needed
731             /// @return     1 (enabled), 0 (disabled)
732             /////////////////////////////////////////////////////////////////////////////////////
IsMediaMemoryCompressed(uint32_t ArrayIndex)733             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint8_t GMM_STDCALL IsMediaMemoryCompressed(uint32_t ArrayIndex)
734             {
735                 __GMM_ASSERT(ArrayIndex < GMM_MAX_MMC_INDEX);
736 
737                 return
738                     (ArrayIndex < GMM_MAX_MMC_INDEX) ?
739                         Surf.MmcMode[ArrayIndex] != GMM_MMC_DISABLED :
740                             0;
741             }
742 
743             /////////////////////////////////////////////////////////////////////////////////////
744             /// Returns mmc hints.
745             /// @param[in]  ArrayIndex ArrayIndex for which this info is needed
746             /// @return     1/0
747             /////////////////////////////////////////////////////////////////////////////////////
GetMmcHint(uint32_t ArrayIndex)748             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_RESOURCE_MMC_HINT GMM_STDCALL GetMmcHint(uint32_t ArrayIndex)
749             {
750                 __GMM_ASSERT(ArrayIndex < GMM_MAX_MMC_INDEX);
751                 return Surf.MmcHint[ArrayIndex] ? GMM_MMC_HINT_OFF : GMM_MMC_HINT_ON;
752             }
753 
754             /////////////////////////////////////////////////////////////////////////////////////
755             /// Sets mmc hints.
756             /// @param[in]  Hint Mmc hint to store
757             /// @param[in]  ArrayIndex ArrayIndex for which this info is needed
758             /// @return
759             /////////////////////////////////////////////////////////////////////////////////////
SetMmcHint(GMM_RESOURCE_MMC_HINT Hint,uint32_t ArrayIndex)760             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL SetMmcHint(GMM_RESOURCE_MMC_HINT Hint, uint32_t ArrayIndex)
761             {
762                 __GMM_ASSERT(ArrayIndex < GMM_MAX_MMC_INDEX);
763                 __GMM_ASSERT(GMM_MMC_HINT_ON == 0);
764                 __GMM_ASSERT(GMM_MMC_HINT_OFF == 1);
765 
766                 Surf.MmcHint[ArrayIndex] = static_cast<uint8_t>(Hint);
767             }
768 
769             /////////////////////////////////////////////////////////////////////////////////////
770             /// Returns the MSAA Sample Counter
771             /// @return     Sample count
772             /////////////////////////////////////////////////////////////////////////////////////
GetNumSamples()773             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetNumSamples()
774             {
775                 return Surf.MSAA.NumSamples;
776             }
777 
778             /////////////////////////////////////////////////////////////////////////////////////
779             /// Returns the MSAA Sample Pattern
780             /// @return     Sample pattern
781             /////////////////////////////////////////////////////////////////////////////////////
GetSamplePattern()782             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_MSAA_SAMPLE_PATTERN GMM_STDCALL GetSamplePattern()
783             {
784                 return Surf.MSAA.SamplePattern;
785             }
786 
787             /////////////////////////////////////////////////////////////////////////////////////
788             /// Returns the X offset of planar surface
789             /// @param[in]  Plane: Plane for which the offset is needed
790             /// @return     X offset
791             /////////////////////////////////////////////////////////////////////////////////////
GetPlanarXOffset(GMM_YUV_PLANE Plane)792             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetPlanarXOffset(GMM_YUV_PLANE Plane)
793             {
794                 __GMM_ASSERT(Plane < GMM_MAX_PLANE);
795                 return Surf.OffsetInfo.Plane.X[Plane];
796             }
797 
798             /////////////////////////////////////////////////////////////////////////////////////
799             /// Returns the Y offset of planar surface
800             /// @param[in]  Plane: Plane for which the offset is needed
801             /// @return     Y offset
802             /////////////////////////////////////////////////////////////////////////////////////
GetPlanarYOffset(GMM_YUV_PLANE Plane)803             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetPlanarYOffset(GMM_YUV_PLANE Plane)
804             {
805                 __GMM_ASSERT(Plane < GMM_MAX_PLANE);
806                 return Surf.OffsetInfo.Plane.Y[Plane];
807             }
808 
809             /////////////////////////////////////////////////////////////////////////////////////
810             /// Returns the Aux offset of planar surface
811             /// @param[in]  ArrayIndex: Surf index for which aux offset is required
812             /// @param[in]  GmmAuxType: Aux Plane for which the offset is needed
813             /// @return     Y_CCS offset/ UV_CCS offset/ Media compression state
814             /////////////////////////////////////////////////////////////////////////////////////
GetPlanarAuxOffset(uint32_t ArrayIndex,GMM_UNIFIED_AUX_TYPE GmmAuxType)815             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetPlanarAuxOffset(uint32_t ArrayIndex, GMM_UNIFIED_AUX_TYPE GmmAuxType)
816             {
817                 GMM_GFX_SIZE_T Offset = 0;
818 
819                 __GMM_ASSERT(ArrayIndex < Surf.ArraySize);
820                 __GMM_ASSERT(GMM_IS_PLANAR(Surf.Format));
821 
822                 if (Surf.Flags.Gpu.UnifiedAuxSurface  &&
823                     !(GetGmmLibContext()->GetSkuTable().FtrFlatPhysCCS))
824                 {
825                     if (GmmAuxType == GMM_AUX_Y_CCS)
826                     {
827                         Offset = Surf.Size;
828                     }
829                     else if (GmmAuxType == GMM_AUX_UV_CCS)
830                     {
831                         Offset = Surf.Size + (AuxSurf.Pitch * AuxSurf.OffsetInfo.Plane.Y[GMM_PLANE_U]); //Aux Offset in HwLayout
832 
833                         if (Surf.Flags.Gpu.CCS && AuxSurf.Flags.Gpu.__NonMsaaLinearCCS)
834                         {
835                             Offset = Surf.Size + AuxSurf.OffsetInfo.Plane.X[GMM_PLANE_U];
836                         }
837                         else if (Surf.Flags.Gpu.MMC && AuxSurf.Flags.Gpu.__NonMsaaLinearCCS )
838                         {
839                             Offset = Surf.Size + AuxSurf.OffsetInfo.Plane.X[GMM_PLANE_Y];
840                         }
841                     }
842                     else if (GmmAuxType == GMM_AUX_COMP_STATE)
843                     {
844                         Offset = Surf.Size + AuxSurf.OffsetInfo.Plane.X[GMM_PLANE_Y] + AuxSurf.OffsetInfo.Plane.X[GMM_PLANE_U];
845                     }
846 
847                     Offset += AuxSurf.OffsetInfo.Plane.ArrayQPitch * ArrayIndex;
848                 }
849                 else
850                 {
851                     Offset = 0;
852                 }
853 
854                 return Offset;
855             }
856 
857             /////////////////////////////////////////////////////////////////////////////////////
858             /// Returns the resource Horizontal alignment
859             /// @return     HAlign
860             /////////////////////////////////////////////////////////////////////////////////////
GetHAlign()861             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetHAlign()
862             {
863                 const __GMM_PLATFORM_RESOURCE   *pPlatformResource;
864                 uint32_t HAlign;
865 
866                 pPlatformResource = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
867 
868                 if ((GFX_GET_CURRENT_RENDERCORE(pPlatformResource->Platform) >= IGFX_GEN9_CORE) &&
869                     !(Surf.Flags.Info.TiledYf || GMM_IS_64KB_TILE(Surf.Flags)))
870                 {
871                     HAlign = Surf.Alignment.HAlign / GetCompressionBlockWidth();
872                 }
873                 else
874                 {
875                     HAlign = Surf.Alignment.HAlign;
876                 }
877 
878                 return HAlign;
879             }
880 
881             /////////////////////////////////////////////////////////////////////////////////////
882             /// Returns the resource Vertical alignment
883             /// @return     VAlign
884             /////////////////////////////////////////////////////////////////////////////////////
GetVAlign()885             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetVAlign()
886             {
887                 const __GMM_PLATFORM_RESOURCE   *pPlatformResource;
888                 uint32_t VAlign;
889                 pPlatformResource = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
890 
891                 if ((GFX_GET_CURRENT_RENDERCORE(pPlatformResource->Platform) >= IGFX_GEN9_CORE) &&
892                     !(GetResFlags().Info.TiledYf || GMM_IS_64KB_TILE(GetResFlags())))
893                 {
894                     VAlign = Surf.Alignment.VAlign / GetCompressionBlockHeight();
895                 }
896                 else
897                 {
898                     VAlign = Surf.Alignment.VAlign;
899                 }
900 
901                 return VAlign;
902             }
903 
904             /////////////////////////////////////////////////////////////////////////////////////
905             /// Returns the auxiliary resource Horizontal alignment
906             /// @return     HAlign
907             /////////////////////////////////////////////////////////////////////////////////////
GetAuxHAlign()908             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetAuxHAlign()
909             {
910                 if (Surf.Flags.Gpu.UnifiedAuxSurface)
911                 {
912                     return AuxSurf.Alignment.HAlign;
913                 }
914                 else
915                 {
916                     return GetHAlign();
917                 }
918             }
919 
920             /////////////////////////////////////////////////////////////////////////////////////
921             /// Returns the auxiliary resource Vertical alignment
922             /// @return     HAlign
923             /////////////////////////////////////////////////////////////////////////////////////
GetAuxVAlign()924             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetAuxVAlign()
925             {
926                 if (Surf.Flags.Gpu.UnifiedAuxSurface)
927                 {
928                     return AuxSurf.Alignment.VAlign;
929                 }
930                 else
931                 {
932                     return GetVAlign();
933                 }
934             }
935 
936             /////////////////////////////////////////////////////////////////////////////////////
937             /// Returns indication of whether resource uses the MSFMT_DEPTH_STENCIL Multisampled
938             /// Surface Storage Format.
939             /// @return     1/0
940             /////////////////////////////////////////////////////////////////////////////////////
IsMsaaFormatDepthStencil()941             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint8_t GMM_STDCALL IsMsaaFormatDepthStencil()
942             {
943                 // Gen7 MSAA (non-Depth/Stencil) render targets use (MSFMT_DEPTH_MSS) array
944                 // expansion instead of (MSFMT_DEPTH_STENCIL) Width/Height expansion.
945                 return (Surf.MSAA.NumSamples > 1) &&
946                         (Surf.Flags.Gpu.Depth ||
947                         Surf.Flags.Gpu.SeparateStencil);
948             }
949 
950             /////////////////////////////////////////////////////////////////////////////////////
951             /// Returns indication of whether resource is SVM or not
952             /// @return     1/0
953             /////////////////////////////////////////////////////////////////////////////////////
IsSvm()954             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint8_t GMM_STDCALL IsSvm()
955             {
956                 return static_cast<uint8_t>(Surf.Flags.Info.SVM);
957             }
958 
959             /////////////////////////////////////////////////////////////////////////////////////
960             /// Allows clients to attach a private data to the resource
961             /// @param[in]  pNewPrivateData: pointer to opaque private data from clients
962             /////////////////////////////////////////////////////////////////////////////////////
SetPrivateData(void * pNewPrivateData)963             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL SetPrivateData(void *pNewPrivateData)
964             {
965                 this->pPrivateData = reinterpret_cast<uint64_t>(pNewPrivateData);
966             }
967 
968             /////////////////////////////////////////////////////////////////////////////////////
969             /// Returns private data attached to the resource
970             /// @return     Pointer to opaque private data
971             /////////////////////////////////////////////////////////////////////////////////////
GetPrivateData()972             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void* GMM_STDCALL GetPrivateData()
973             {
974                 return reinterpret_cast<void*>(pPrivateData);
975             }
976 
977             /////////////////////////////////////////////////////////////////////////////////////
978             /// Returns the resource GFX address
979             /// @return     Gfx Address
980             /////////////////////////////////////////////////////////////////////////////////////
GetGfxAddress()981             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_ADDRESS GMM_STDCALL GetGfxAddress()
982             {
983                 // Support for Sparse/Tiled resources will be unified in later
984 	        if (SvmAddress)
985 	        {
986                     return GMM_GFX_ADDRESS_CANONIZE(SvmAddress);
987 		}
988 	        else
989 	        {
990 	            return 0;
991 	        }
992             }
993 
994             /////////////////////////////////////////////////////////////////////////////////////
995             /// This function returns the total height of an S3D tall buffer. For non-S3D
996             /// resources, it returns base height.
997             /// @return     Surface height
998             /////////////////////////////////////////////////////////////////////////////////////
GetTallBufferHeight()999             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetTallBufferHeight()
1000             {
1001                 if (Surf.Flags.Gpu.S3d)
1002                 {
1003                     return Surf.S3d.TallBufferHeight;
1004                 }
1005                 else
1006                 {
1007                     GMM_ASSERTDPF(0, "Unsupported S3D Resource Type!");
1008                     return Surf.BaseHeight;
1009                 }
1010             };
1011 
1012             /////////////////////////////////////////////////////////////////////////////////////
1013             /// Returns size of the surface depending on the surface parameters.
1014             /// @return     Size of surface
1015             ///
1016             /// Below legacy API to query surface size are deprecated and will be removed in
1017             /// later gmm releases. Client must move to unified GetSize() api.
1018             ///  - GmmResGetSizeSurface()/ pResInfo->GetSizeSurface()
1019             ///  - GmmResGetSizeMainSurface()/  pResInfo->GetSizeAllocation()
1020             ///  - GmmResGetSizeAllocation()/ pResInfo->GetSizeMainSurface()
1021             /////////////////////////////////////////////////////////////////////////////////////
GetSize(GMM_SIZE_PARAM GmmSizeParam)1022             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T  GMM_STDCALL GetSize(GMM_SIZE_PARAM GmmSizeParam)
1023             {
1024                 GMM_GFX_SIZE_T Size = 0;
1025 
1026                 switch (GmmSizeParam)
1027                 {
1028                     case GMM_MAIN_SURF:
1029                         Size =  Surf.Size;
1030                         break;
1031                     case GMM_MAIN_PLUS_AUX_SURF:
1032                         Size =  Surf.Size + AuxSurf.Size + AuxSecSurf.Size;
1033                         break;
1034                     case GMM_TOTAL_SURF:
1035                         Size = Surf.Size + AuxSurf.Size + AuxSecSurf.Size;
1036                         if (Is64KBPageSuitable())
1037                         {
1038                             Size = GFX_ALIGN(Surf.Size + AuxSurf.Size + AuxSecSurf.Size, GMM_KBYTE(64));
1039                         }
1040                         break;
1041                     case GMM_TOTAL_SURF_PHYSICAL:
1042                         if(GMM_IS_PLANAR(Surf.Format) && Is1MBAlignedAuxTPlanarSurface())
1043                         {
1044                             Size = (Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_Y] + Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_U] + Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_V]) * Surf.OffsetInfo.PlaneXe_LPG.PhysicalPitch;
1045                             Size *= GFX_MAX(Surf.ArraySize, 1);
1046                             Size += AuxSurf.Size + AuxSecSurf.Size;
1047                         }
1048                         else
1049                         {
1050                             // Physical Size = VA Size
1051                             Size = GetSize(GMM_TOTAL_SURF);
1052                         }
1053                         break;
1054                     case GMM_MAIN_SURF_PHYSICAL:
1055                         if(GMM_IS_PLANAR(Surf.Format) && Is1MBAlignedAuxTPlanarSurface())
1056                         {
1057                             Size = (Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_Y] + Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_U] + Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_V]) * Surf.OffsetInfo.PlaneXe_LPG.PhysicalPitch;
1058                             Size *= GFX_MAX(Surf.ArraySize, 1);
1059                         }
1060                         else
1061                         {
1062                             // Physical Size = VA Size
1063                             Size = GetSize(GMM_MAIN_SURF);
1064                         }
1065                         break;
1066                     default:
1067                         __GMM_ASSERT(0);
1068                 }
1069                 return Size;
1070             }
1071 
1072             /////////////////////////////////////////////////////////////////////////////////////
1073             /// Returns size of the main surface only. Aux surface size not included.
1074             /// @return     Size of main surface
1075             /////////////////////////////////////////////////////////////////////////////////////
GetSizeMainSurface()1076             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T  GMM_STDCALL GetSizeMainSurface() const
1077             {
1078                 return Surf.Size;
1079             }
1080 
1081 	    /////////////////////////////////////////////////////////////////////////////////////
1082             /// Returns the number of bytes that are required to back this padded and aligned
1083             /// resource. The calculation takes into consideration more than simply width
1084             /// height and bits per pixel. Width padding (stride), pixel formats, inter-plane
1085             /// padding depts/array-size and so on also for part of the list of factors.
1086             /// @return     Surface Size
1087             /////////////////////////////////////////////////////////////////////////////////////
GetSizeSurface()1088             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T  GMM_STDCALL GetSizeSurface()
1089             {
1090                 GMM_OVERRIDE_SIZE_64KB_ALLOC(GetGmmLibContext());
1091                 return (Surf.Size + AuxSurf.Size + AuxSecSurf.Size);
1092             }
1093 
1094             /////////////////////////////////////////////////////////////////////////////////////
1095             /// Returns surface size(GetSizeSurface) plus additional padding due to 64kb pages
1096             /// @return     Allocation Size
1097             /////////////////////////////////////////////////////////////////////////////////////
GetSizeAllocation()1098             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T  GMM_STDCALL GetSizeAllocation()
1099             {
1100                 if (Is64KBPageSuitable())
1101                 {
1102                     return(GFX_ALIGN(Surf.Size + AuxSurf.Size + AuxSecSurf.Size, GMM_KBYTE(64)));
1103                 }
1104                 else
1105                 {
1106                     return (Surf.Size + AuxSurf.Size + AuxSecSurf.Size);
1107                 }
1108             }
1109 
1110             /////////////////////////////////////////////////////////////////////////////////////
1111             /// Returns max no of GpuVa bits supported per resource on a given platform
1112             /// @return     Max # of GpuVA bits per resource
1113             /////////////////////////////////////////////////////////////////////////////////////
GetMaxGpuVirtualAddressBits()1114             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t  GMM_STDCALL GetMaxGpuVirtualAddressBits()
1115             {
1116                 const GMM_PLATFORM_INFO *pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
1117                 __GMM_ASSERTPTR(pPlatform, 0);
1118 
1119                 return pPlatform->MaxGpuVirtualAddressBitsPerResource;
1120             }
1121 
1122             /////////////////////////////////////////////////////////////////////////////////////
1123             /// Returns the surface offset for unified allocations
1124             /// @param[in]  GmmAuxType: the type of aux the offset is needed for
1125             /// @return     Surface Offset in bytes
1126             /////////////////////////////////////////////////////////////////////////////////////
GetUnifiedAuxSurfaceOffset(GMM_UNIFIED_AUX_TYPE GmmAuxType)1127             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetUnifiedAuxSurfaceOffset(GMM_UNIFIED_AUX_TYPE GmmAuxType)
1128             {
1129                 GMM_GFX_SIZE_T Offset = 0;
1130 		const GMM_PLATFORM_INFO *pPlatform;
1131 		pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
1132 		GMM_UNREFERENCED_PARAMETER(pPlatform);
1133 
1134                 if (Surf.Flags.Gpu.UnifiedAuxSurface)
1135                 {
1136                     if ((GmmAuxType == GMM_AUX_CCS) || (GmmAuxType == GMM_AUX_SURF) || (GmmAuxType == GMM_AUX_Y_CCS)
1137                         || (GmmAuxType == GMM_AUX_HIZ) || (GmmAuxType == GMM_AUX_MCS))
1138                     {
1139                         Offset = Surf.Size;
1140                         if (GmmAuxType == GMM_AUX_CCS && AuxSecSurf.Type != RESOURCE_INVALID
1141                             && (Surf.Flags.Gpu.CCS && (Surf.MSAA.NumSamples > 1 ||
1142                                 Surf.Flags.Gpu.Depth)))
1143                         {
1144                             Offset += AuxSurf.Size;
1145                         }
1146                     }
1147                     else if (GmmAuxType == GMM_AUX_UV_CCS)
1148                     {
1149                         Offset = Surf.Size + (AuxSurf.Pitch * AuxSurf.OffsetInfo.Plane.Y[GMM_PLANE_U]); //Aux Offset in HwLayout
1150 
1151                         if (Surf.Flags.Gpu.CCS && AuxSurf.Flags.Gpu.__NonMsaaLinearCCS)
1152                         {
1153                             Offset = Surf.Size + AuxSurf.OffsetInfo.Plane.X[GMM_PLANE_U];
1154                         }
1155                         else if (Surf.Flags.Gpu.MMC && AuxSurf.Flags.Gpu.__NonMsaaLinearCCS )
1156                         {
1157                             Offset = Surf.Size + AuxSurf.OffsetInfo.Plane.X[GMM_PLANE_Y];
1158                         }
1159                     }
1160                     else if ((GmmAuxType == GMM_AUX_CC) && (Surf.Flags.Gpu.IndirectClearColor || Surf.Flags.Gpu.ColorDiscard))
1161                     {
1162                         Offset = Surf.Size + AuxSurf.UnpaddedSize;
1163 	                if (GetGmmLibContext()->GetSkuTable().FtrXe2Compression)
1164 	                {
1165 	                    if (Surf.MSAA.NumSamples > 1)
1166 	                    {
1167 	                        Offset = Surf.Size; // Beginning of MCS which is first 4K of AuxSurf, Clear colour is stored only for MSAA surfaces
1168 	                    }
1169 	                }
1170                     }
1171                     else if (GmmAuxType == GMM_AUX_COMP_STATE)
1172                     {
1173                         Offset = Surf.Size + AuxSurf.OffsetInfo.Plane.X[GMM_PLANE_Y] + AuxSurf.OffsetInfo.Plane.X[GMM_PLANE_U];
1174                     }
1175                     else if ((GmmAuxType == GMM_AUX_ZCS) && Surf.Flags.Gpu.Depth && Surf.Flags.Gpu.CCS)
1176                     {
1177                         if (AuxSecSurf.Type != RESOURCE_INVALID)
1178                         {
1179                             Offset = Surf.Size + AuxSurf.Size;
1180                         }
1181                     }
1182                 }
1183                 else if(GmmAuxType == GMM_AUX_CC &&
1184                         Surf.Flags.Gpu.IndirectClearColor &&
1185                         Surf.Flags.Gpu.HiZ)
1186                 {
1187                     Offset = Surf.Size - GMM_HIZ_CLEAR_COLOR_SIZE;
1188                 }
1189                 else if (GmmAuxType == GMM_AUX_CC &&
1190                     Surf.Flags.Gpu.ColorDiscard &&
1191                     !Surf.Flags.Gpu.CCS)
1192                 {
1193                     Offset = Surf.Size;
1194                 }
1195                 else
1196                 {
1197                     Offset = 0;
1198                 }
1199 
1200                 if((GetGmmLibContext()->GetSkuTable().FtrFlatPhysCCS) && !Surf.Flags.Gpu.ProceduralTexture &&
1201                     (GmmAuxType == GMM_AUX_CCS || GmmAuxType == GMM_AUX_ZCS ||
1202                     GmmAuxType == GMM_AUX_Y_CCS || GmmAuxType == GMM_AUX_UV_CCS))
1203                 {
1204                     Offset = 0;
1205                 }
1206 
1207                 return Offset;
1208             }
1209 
1210             /////////////////////////////////////////////////////////////////////////////////////
1211             /// Returns the surface size for unified allocations
1212             /// @param[in]  GmmAuxType: the type of aux the size is needed for
1213             /// @return     Surface Size in bytes
1214             /////////////////////////////////////////////////////////////////////////////////////
GetSizeAuxSurface(GMM_UNIFIED_AUX_TYPE GmmAuxType)1215             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetSizeAuxSurface(GMM_UNIFIED_AUX_TYPE GmmAuxType)
1216             {
1217                 if (GmmAuxType == GMM_AUX_SURF)
1218                 {
1219                     return (AuxSurf.Size + AuxSecSurf.Size);
1220                 }
1221                 else if (GmmAuxType == GMM_AUX_CCS || GmmAuxType == GMM_AUX_HIZ || GmmAuxType == GMM_AUX_MCS)
1222                 {
1223                     if(GmmAuxType == GMM_AUX_CCS &&
1224                        GetGmmLibContext()->GetSkuTable().FtrFlatPhysCCS && !Surf.Flags.Gpu.ProceduralTexture)
1225                     {
1226                         return 0;
1227                     }
1228                     if (GmmAuxType == GMM_AUX_CCS && AuxSecSurf.Type != RESOURCE_INVALID &&
1229                         (Surf.Flags.Gpu.CCS && (Surf.MSAA.NumSamples > 1 ||
1230                             Surf.Flags.Gpu.Depth)))
1231                     {
1232                         return AuxSecSurf.Size;
1233                     }
1234                     else
1235                     {
1236                         return (AuxSurf.UnpaddedSize);
1237                     }
1238                 }
1239                 else if (GmmAuxType == GMM_AUX_COMP_STATE)
1240                 {
1241                     return GMM_MEDIA_COMPRESSION_STATE_SIZE;
1242                 }
1243                 else if (GmmAuxType == GMM_AUX_CC)
1244                 {
1245                     if (!Surf.Flags.Gpu.UnifiedAuxSurface && Surf.Flags.Gpu.HiZ)
1246                     {
1247                         return GMM_HIZ_CLEAR_COLOR_SIZE;
1248                     }
1249                     else
1250                     {
1251 
1252                         if (GetGmmLibContext()->GetSkuTable().FtrXe2Compression)
1253                         {
1254                             if (Surf.MSAA.NumSamples > 1)
1255                             {
1256                                 return (AuxSurf.UnpaddedSize); // CC is part of MCS
1257                             }
1258                             else
1259                             {
1260                                 return 0; // fixed CC values used, not stored as part of Aux
1261                             }
1262                         }
1263                         else
1264                         {
1265                             return (AuxSurf.CCSize);
1266                         }
1267                     }
1268                 }
1269                 else if (GmmAuxType == GMM_AUX_ZCS)
1270                 {
1271                     if (Surf.Flags.Gpu.UnifiedAuxSurface && AuxSecSurf.Type != RESOURCE_INVALID)
1272                     {
1273                         return AuxSecSurf.Size;
1274                     }
1275                     else
1276                     {
1277                         return 0;
1278                     }
1279                 }
1280                 else
1281                 {
1282                     return 0;
1283                 }
1284             }
1285 
1286             /////////////////////////////////////////////////////////////////////////
1287             /// This function returns or sets the value of the hardware protected flag
1288             /// associated with the given GMM resource within same process.
1289             /// @param[in]  GetIsEncrypted: Read encryption status
1290             /// @param[in]  SetIsEncrypted: Write encryption status
1291             /// @return     Whether surface is encrypted or not
1292             /////////////////////////////////////////////////////////////////////////
GetSetHardwareProtection(uint8_t GetIsEncrypted,uint8_t SetIsEncrypted)1293             virtual GMM_INLINE_EXPORTED uint8_t GMM_STDCALL GetSetHardwareProtection(uint8_t GetIsEncrypted, uint8_t SetIsEncrypted)
1294             {
1295                 uint8_t IsEncrypted = 0;
1296 
1297                 if (GetIsEncrypted)
1298                 {
1299                     IsEncrypted = Surf.Flags.Info.HardwareProtected;
1300                 }
1301                 else
1302                 {
1303                     Surf.Flags.Info.HardwareProtected = IsEncrypted = SetIsEncrypted;
1304                 }
1305 
1306                 return IsEncrypted;
1307             }
1308 
1309             /////////////////////////////////////////////////////////////////////////
1310             /// This function returns or sets the value of the Cp surface tag
1311             /// associated with the given GMM resource within same process.
1312             /// @param[in]  IsSet: true for updating tag in gmm
1313             /// @param[in]  CpTag: Cp surface tag value
1314             /// @return     current cp surface tag in gmm
1315             /////////////////////////////////////////////////////////////////////////
GetSetCpSurfTag(uint8_t IsSet,uint32_t CpTag)1316             GMM_INLINE_VIRTUAL GMM_INLINE uint32_t GMM_STDCALL GetSetCpSurfTag(uint8_t IsSet, uint32_t CpTag)
1317             {
1318                 if (IsSet)
1319                 {
1320                     Surf.CpTag = CpTag;
1321                 }
1322                 return Surf.CpTag;
1323             }
1324 
1325             /////////////////////////////////////////////////////////////////////////
1326             /// Returns the size of the surface in StdLayout format
1327             /// @return  Size in bytes of Standard Layout version of surface.
1328             /////////////////////////////////////////////////////////////////////////
GetStdLayoutSize()1329             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetStdLayoutSize()
1330             {
1331                 GMM_REQ_OFFSET_INFO GetOffset = {};
1332 
1333                 GetOffset.ReqStdLayout = 1;
1334                 GetOffset.StdLayout.Offset = static_cast<GMM_GFX_SIZE_T>(-1); // Special Req for StdLayout Size
1335                 this->GetOffset(GetOffset);
1336 
1337                 return GetOffset.StdLayout.Offset;
1338             }
1339 
1340             /////////////////////////////////////////////////////////////////////////
1341             /// Returns whether resource is color separated target
1342             /// @return  1 if the resource is color separated target, 0 otherwise
1343             /////////////////////////////////////////////////////////////////////////
IsColorSeparation()1344             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint8_t GMM_STDCALL IsColorSeparation()
1345             {
1346                 return Surf.Flags.Gpu.ColorSeparation || Surf.Flags.Gpu.ColorSeparationRGBX;
1347             }
1348 
1349             /////////////////////////////////////////////////////////////////////////
1350             /// Translate packed source x coordinate to color separation target x coordinate
1351             /// @param[in]  x: X coordinate
1352             /// @return   Translated color separation target x coordinate
1353             /////////////////////////////////////////////////////////////////////////
TranslateColorSeparationX(uint32_t x)1354             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL TranslateColorSeparationX(uint32_t x)
1355             {
1356                 uint32_t ret = x;
1357 
1358                 if (Surf.Flags.Gpu.ColorSeparation)
1359                 {
1360                     ret /= GMM_COLOR_SEPARATION_WIDTH_DIVISION;
1361                 }
1362                 else if (Surf.Flags.Gpu.ColorSeparationRGBX)
1363                 {
1364                     ret /= GMM_COLOR_SEPARATION_RGBX_WIDTH_DIVISION;
1365                 }
1366 
1367                 return ret;
1368             }
1369 
1370             /////////////////////////////////////////////////////////////////////////
1371             /// Returns the array size of a color separated target resource.
1372             /// @return   Array size of a color separated target resource
1373             /////////////////////////////////////////////////////////////////////////
GetColorSeparationArraySize()1374             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetColorSeparationArraySize()
1375             {
1376                 if (Surf.Flags.Gpu.ColorSeparation ||
1377                     Surf.Flags.Gpu.ColorSeparationRGBX)
1378                 {
1379                     return GMM_COLOR_SEPARATION_ARRAY_SIZE;
1380                 }
1381                 else
1382                 {
1383                     return Surf.ArraySize;
1384                 }
1385             }
1386 
1387             /////////////////////////////////////////////////////////////////////////
1388             /// Returns the physical width of a color separated target resource
1389             /// @return   physical width of a color separated target resource
1390             /////////////////////////////////////////////////////////////////////////
GetColorSeparationPhysicalWidth()1391             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetColorSeparationPhysicalWidth()
1392             {
1393                 if (Surf.Flags.Gpu.ColorSeparation)
1394                 {
1395                     return ((uint32_t)Surf.BaseWidth * Surf.ArraySize) / GMM_COLOR_SEPARATION_WIDTH_DIVISION;
1396                 }
1397                 else if (Surf.Flags.Gpu.ColorSeparationRGBX)
1398                 {
1399                     return ((uint32_t)Surf.BaseWidth * Surf.ArraySize) / GMM_COLOR_SEPARATION_RGBX_WIDTH_DIVISION;
1400                 }
1401                 else
1402                 {
1403                     return (uint32_t)Surf.BaseWidth;
1404                 }
1405             }
1406 
1407             /////////////////////////////////////////////////////////////////////////
1408             /// Returns whether surface can be faulted on
1409             /// @return   1 is surface can be faulted on
1410             /////////////////////////////////////////////////////////////////////////
IsSurfaceFaultable()1411             virtual GMM_INLINE_EXPORTED uint8_t GMM_STDCALL IsSurfaceFaultable()
1412             {
1413                 return 0;
1414             }
1415 
1416             /////////////////////////////////////////////////////////////////////////////////////
1417             /// Returns the cache policy usage associated with this surface.
1418             /// @return     Cache Policy Usage
1419             /////////////////////////////////////////////////////////////////////////////////////
GetCachePolicyUsage()1420             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_RESOURCE_USAGE_TYPE GMM_STDCALL GetCachePolicyUsage()
1421             {
1422                 return Surf.CachePolicy.Usage;
1423             }
1424 
1425             //##################################################################################
1426             // Functions that can help clients program the SURFACE_STATE with appropriate values.
1427             //##################################################################################
1428             /////////////////////////////////////////////////////////////////////////////////////
1429             /// Returns the surface state value for Mip Tail Start LOD
1430             /// @return     Mip Tail Start
1431             /////////////////////////////////////////////////////////////////////////////////////
GetMipTailStartLodSurfaceState()1432             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetMipTailStartLodSurfaceState()
1433             {
1434                 return Surf.Alignment.MipTailStartLod;
1435             }
1436 
1437             /////////////////////////////////////////////////////////////////////////////////////
1438             /// Returns the Tile Address Mapping Mode, for SURFACE_STATE programming and is
1439             /// applicable only for 3D surface
1440             /// @return     Tile Address Mapping Mode
1441             /////////////////////////////////////////////////////////////////////////////////////
GetTileAddressMappingModeSurfaceState()1442             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetTileAddressMappingModeSurfaceState()
1443             {
1444                 return 0;
1445             }
1446 
1447             /////////////////////////////////////////////////////////////////////////////////////
1448             /// Returns the horizontal alignment for SURFACE_STATE programming.
1449             /// @return     HAlign
1450             /////////////////////////////////////////////////////////////////////////////////////
GetHAlignSurfaceState()1451             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetHAlignSurfaceState()
1452             {
1453                 uint32_t               HAlign = 0;
1454                 const GMM_PLATFORM_INFO   *pPlatform;
1455 
1456                 pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
1457 
1458                 if (GFX_GET_CURRENT_RENDERCORE(pPlatform->Platform) >= IGFX_GEN8_CORE)
1459                 {
1460                     if (GetResFlags().Info.TiledYf || GMM_IS_64KB_TILE(GetResFlags()))
1461                     {
1462                         HAlign = 1; // Ignored, but we'll return valid encoding nonetheless.
1463                     }
1464                     else
1465                     {
1466                         if(GMM_IS_TILEY(GetGmmLibContext()))
1467                         {
1468                             switch (GetHAlign())
1469                             {
1470 			                case 4:
1471 			                    HAlign = 1;
1472 			                    break;
1473 			                case 8:
1474 			                    HAlign = 2;
1475 			                    break;
1476 			                case 16:
1477 			                    HAlign = 3;
1478 			                    break;
1479 			                default:
1480 			                    HAlign = 1; // Change back to 0 + assert after packed YUV handling corrected.
1481                             }
1482                         }
1483                         else
1484                         {
1485                             uint32_t Align = GetHAlign() * (GetBitsPerPixel() >> 3);
1486 
1487                             if (Surf.BitsPerPixel == 24 || Surf.BitsPerPixel == 48 || Surf.BitsPerPixel == 96)
1488                             {
1489                                 Align = GetHAlign();
1490                             }
1491 
1492 		                    switch (Align)
1493 		                    {
1494 		                    case 16:
1495 		                        HAlign = 0;
1496 		                        break;
1497 		                    case 32:
1498 		                        HAlign = 1;
1499 		                        break;
1500 		                    case 64:
1501 		                        HAlign = 2;
1502 		                        break;
1503 		                    case 128:
1504                             case 256:
1505 		                        HAlign = 3;
1506 		                        break;
1507 		                    default:
1508 		                        HAlign = 0;
1509 		                        __GMM_ASSERT(0);
1510                             }
1511                 }
1512             }
1513         }
1514         else
1515         {
1516             switch (Surf.Alignment.HAlign)
1517             {
1518             case 4:
1519                 HAlign = 0;
1520                 break;
1521             case 8:
1522                 HAlign = 1;
1523                 break;
1524             default:
1525                 HAlign = 0;
1526                 __GMM_ASSERT(0);
1527             }
1528         }
1529 
1530                 return HAlign;
1531             }
1532 
1533             /////////////////////////////////////////////////////////////////////////////////////
1534             /// Returns the vertical alignment for SURFACE_STATE programming.
1535             /// @return     HAlign
1536             /////////////////////////////////////////////////////////////////////////////////////
GetVAlignSurfaceState()1537             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetVAlignSurfaceState()
1538             {
1539                 uint32_t               VAlign;
1540                 const GMM_PLATFORM_INFO   *pPlatform;
1541 
1542                 pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
1543 
1544                 if (GFX_GET_CURRENT_RENDERCORE(pPlatform->Platform) >= IGFX_GEN8_CORE)
1545                 {
1546                     if (GetResFlags().Info.TiledYf || GMM_IS_64KB_TILE(GetResFlags()))
1547                     {
1548                         VAlign = 1; // Ignored, but we'll return valid encoding nonetheless.
1549                     }
1550                     else
1551                     {
1552                         switch (GetVAlign())
1553                         {
1554 		                case 4:
1555 		                    VAlign = 1;
1556 		                    break;
1557 		                case 8:
1558 		                    VAlign = 2;
1559 		                    break;
1560 		                case 16:
1561 		                    VAlign = 3;
1562 		                    break;
1563 		                default:
1564 		                    VAlign = 1;
1565                         }
1566                     }
1567                 }
1568                 else
1569                 {
1570                     switch (Surf.Alignment.VAlign)
1571                     {
1572 		            case 2:
1573 		                VAlign = 0;
1574 		                break;
1575 		            case 4:
1576 		                VAlign = 1;
1577 		                break;
1578 		            default:
1579 		                VAlign = 0;
1580 		                __GMM_ASSERT(0);
1581                     }
1582                 }
1583 
1584                 return VAlign;
1585             }
1586 
1587 
1588             /////////////////////////////////////////////////////////////////////////////////////
1589             /// Returns tile mode for SURFACE_STATE programming.
1590             /// @return     Tiled Mode
1591             /////////////////////////////////////////////////////////////////////////////////////
GetTileModeSurfaceState()1592             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetTileModeSurfaceState()
1593             {
1594                 return GetTileModeSurfaceState(&Surf);
1595 	    }
1596 
1597 	    /////////////////////////////////////////////////////////////////////////////////////
1598             /// Returns tile mode for AUX SURFACE_STATE programming.
1599             /// @return     Tiled Mode
1600             /////////////////////////////////////////////////////////////////////////////////////
GetAuxTileModeSurfaceState()1601             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetAuxTileModeSurfaceState()
1602             {
1603                 return GetTileModeSurfaceState(&AuxSurf);
1604             }
1605 
1606             /////////////////////////////////////////////////////////////////////////////////////
1607             /// Returns tiled resource mode for SURFACE_STATE programming.
1608             /// @return     Tiled Resource Mode
1609             /////////////////////////////////////////////////////////////////////////////////////
GetTiledResourceModeSurfaceState()1610             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetTiledResourceModeSurfaceState()
1611             {
1612                 uint32_t   TiledResourceMode = 0;
1613 
1614                 if(GMM_IS_TILEY(GetGmmLibContext()))
1615                 {
1616                     if (Surf.Flags.Info.TiledYf)
1617                     {
1618                         TiledResourceMode = 1;
1619                     }
1620                     else if (Surf.Flags.Info.TiledYs)
1621                     {
1622                         TiledResourceMode = 2;
1623                     }
1624                     else
1625                     {
1626                         TiledResourceMode = 0;
1627                     }
1628                 }
1629                 else
1630                 {
1631                     __GMM_ASSERT(0);
1632                 }
1633 
1634                 return TiledResourceMode;
1635             }
1636 
1637             //###################################################################################
1638             // Functions that allows clients to override certain members
1639             // of ResourceInfo. Client assumes the risk of using these functions.
1640             // May cause unintended side-affects.
1641             //##################################################################################
1642             /////////////////////////////////////////////////////////////////////////////////////
1643             /// Overrides the main surface size
1644             /// @param[in]  Size: new size of the resource
1645             /////////////////////////////////////////////////////////////////////////////////////
OverrideSize(GMM_GFX_SIZE_T Size)1646             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideSize(GMM_GFX_SIZE_T Size)
1647             {
1648                 Surf.Size = Size;
1649             }
1650 
1651             /////////////////////////////////////////////////////////////////////////////////////
1652             /// Overrides the surface pitch
1653             /// @param[in]  Pitch: new pitch of the resource
1654             /////////////////////////////////////////////////////////////////////////////////////
OverridePitch(GMM_GFX_SIZE_T Pitch)1655             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverridePitch(GMM_GFX_SIZE_T Pitch)
1656             {
1657                 Surf.Pitch = Pitch;
1658             }
1659 
1660             /////////////////////////////////////////////////////////////////////////////////////
1661             /// Overrides the aux surface pitch
1662             /// @param[in]  Pitch: new pitch of the aux surface
1663             /////////////////////////////////////////////////////////////////////////////////////
OverrideUnifiedAuxPitch(GMM_GFX_SIZE_T Pitch)1664             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideUnifiedAuxPitch(GMM_GFX_SIZE_T Pitch)
1665             {
1666                 __GMM_ASSERT(Surf.Flags.Gpu.UnifiedAuxSurface);
1667                 AuxSurf.Pitch = Pitch;
1668             }
1669 
1670             /////////////////////////////////////////////////////////////////////////////////////
1671             /// Overrides the allocation flags
1672             /// @param[in]  Flags: new set of flags for the resource
1673             /////////////////////////////////////////////////////////////////////////////////////
OverrideAllocationFlags(GMM_RESOURCE_FLAG & Flags)1674             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideAllocationFlags(GMM_RESOURCE_FLAG& Flags)
1675             {
1676                 Surf.Flags = Flags;
1677             }
1678 
1679             /////////////////////////////////////////////////////////////////////////////////////
1680             /// Overrides the resource HAlign
1681             /// @param[in]  HAlign: new HAlign for the resource
1682             /////////////////////////////////////////////////////////////////////////////////////
OverrideHAlign(uint32_t HAlign)1683             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideHAlign(uint32_t HAlign)
1684             {
1685                 Surf.Alignment.HAlign = HAlign;
1686             }
1687 
1688             /////////////////////////////////////////////////////////////////////////////////////
1689             /// Overrides the resource BaseAlignment
1690             /// @param[in]  Alignment: new BaseAlignment for the resource
1691             /////////////////////////////////////////////////////////////////////////////////////
OverrideBaseAlignment(uint32_t Alignment)1692             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideBaseAlignment(uint32_t Alignment)
1693             {
1694                 Surf.Alignment.BaseAlignment = Alignment;
1695             }
1696 
1697             /////////////////////////////////////////////////////////////////////////////////////
1698             /// Overrides the resource BaseWidth
1699             /// @param[in]  BaseWidth: new BaseWidth for the resource
1700             /////////////////////////////////////////////////////////////////////////////////////
OverrideBaseWidth(GMM_GFX_SIZE_T BaseWidth)1701             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideBaseWidth(GMM_GFX_SIZE_T BaseWidth)
1702             {
1703                 Surf.BaseWidth = BaseWidth;
1704             }
1705 
1706             /////////////////////////////////////////////////////////////////////////////////////
1707             /// Overrides the resource BaseHeight
1708             /// @param[in]  BaseHeight: new BaseHeight for the resource
1709             /////////////////////////////////////////////////////////////////////////////////////
OverrideBaseHeight(uint32_t BaseHeight)1710             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideBaseHeight(uint32_t BaseHeight)
1711             {
1712                 Surf.BaseHeight = BaseHeight;
1713             }
1714 
1715             /////////////////////////////////////////////////////////////////////////////////////
1716             /// Overrides the resource Depth
1717             /// @param[in]  Depth: new Depth for the resource
1718             /////////////////////////////////////////////////////////////////////////////////////
OverrideDepth(uint32_t Depth)1719             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideDepth(uint32_t Depth)
1720             {
1721                 Surf.Depth = Depth;
1722             }
1723 
1724             /////////////////////////////////////////////////////////////////////////////////////
1725             /// Overrides the resource tile mode
1726             /// @param[in]  TileMode: new tile mode for the resource
1727             /////////////////////////////////////////////////////////////////////////////////////
OverrideTileMode(GMM_TILE_MODE TileMode)1728             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideTileMode(GMM_TILE_MODE TileMode)
1729             {
1730                 Surf.TileMode = TileMode;
1731             }
1732 
1733             /////////////////////////////////////////////////////////////////////////////////////
1734             /// Overrides the resource tile mode
1735             /// @param[in]  TileMode: new tile mode for the resource
1736             /////////////////////////////////////////////////////////////////////////////////////
OverrideUnifiedAuxTileMode(GMM_TILE_MODE TileMode)1737             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideUnifiedAuxTileMode(GMM_TILE_MODE TileMode)
1738             {
1739                 __GMM_ASSERT(Surf.Flags.Gpu.UnifiedAuxSurface);
1740                 AuxSurf.TileMode = TileMode;
1741             }
1742 
1743             /////////////////////////////////////////////////////////////////////////////////////
1744             /// Overrides the surface format
1745             /// @param[in]  Format: new format for the resource
1746             /////////////////////////////////////////////////////////////////////////////////////
OverrideSurfaceFormat(GMM_RESOURCE_FORMAT Format)1747             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideSurfaceFormat(GMM_RESOURCE_FORMAT Format)
1748             {
1749                 Surf.Format = Format;
1750             }
1751 
1752             /////////////////////////////////////////////////////////////////////////////////////
1753             /// Overrides the surface type
1754             /// @param[in]  Type: new surface type for the resource
1755             /////////////////////////////////////////////////////////////////////////////////////
OverrideSurfaceType(GMM_RESOURCE_TYPE Type)1756             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideSurfaceType(GMM_RESOURCE_TYPE Type)
1757             {
1758                 Surf.Type = Type;
1759             }
1760 
1761             /////////////////////////////////////////////////////////////////////////////////////
1762             /// Overrides the svm gfx address
1763             /// @param[in]  SvmGfxAddress: new svm gfx address for the resource
1764             /////////////////////////////////////////////////////////////////////////////////////
OverrideSvmGfxAddress(GMM_GFX_ADDRESS SvmGfxAddress)1765             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideSvmGfxAddress(GMM_GFX_ADDRESS SvmGfxAddress)
1766             {
1767                 this->SvmAddress = SvmGfxAddress;
1768             }
1769 
1770             /////////////////////////////////////////////////////////////////////////////////////
1771             /// Overrides the resource array size
1772             /// @param[in]  ArraySize: new array size for the resource
1773             /////////////////////////////////////////////////////////////////////////////////////
OverrideArraySize(uint32_t ArraySize)1774             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideArraySize(uint32_t ArraySize)
1775             {
1776                 Surf.ArraySize = ArraySize;
1777             }
1778 
1779             /////////////////////////////////////////////////////////////////////////////////////
1780             /// Overrides the resource max LOD
1781             /// @param[in]  MaxLod: new max LOD for the resource
1782             /////////////////////////////////////////////////////////////////////////////////////
OverrideMaxLod(uint32_t MaxLod)1783             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideMaxLod(uint32_t MaxLod)
1784             {
1785                 Surf.MaxLod = MaxLod;
1786             }
1787 
1788             /////////////////////////////////////////////////////////////////////////////////////
1789             /// Overrides the resource cache policy usage
1790             /// @param[in]  Usage: new usage for the resource
1791             /////////////////////////////////////////////////////////////////////////////////////
OverrideCachePolicyUsage(GMM_RESOURCE_USAGE_TYPE Usage)1792             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideCachePolicyUsage(GMM_RESOURCE_USAGE_TYPE Usage)
1793             {
1794                 Surf.CachePolicy.Usage = Usage;
1795             }
1796 
1797             /////////////////////////////////////////////////////////////////////////////////////
1798             /// Overrides the platform associated with this resource
1799             /// @param[in]  Platform: new platform for the resource
1800             /// @note Function only available for Debug/Release-Internal builds.
1801             /////////////////////////////////////////////////////////////////////////////////////
1802             #if(_DEBUG || _RELEASE_INTERNAL)
OverridePlatform(PLATFORM Platform)1803             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverridePlatform(PLATFORM Platform)
1804                 {
1805                     Surf.Platform = Platform;
1806                 }
1807             #endif
1808 
1809             /////////////////////////////////////////////////////////////////////////////////////
1810             /// Overrides the GmmLibContext associated with this resource
1811             /// @param[in]  pNewGmmLibContext: new GmmLibContext for the resource
1812             /////////////////////////////////////////////////////////////////////////////////////
OverrideGmmLibContext(Context * pNewGmmLibContext)1813             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverrideGmmLibContext(Context *pNewGmmLibContext)
1814             {
1815 #if(defined(__GMM_KMD__))
1816                 this->pGmmKmdLibContext = reinterpret_cast<uint64_t>(pNewGmmLibContext);
1817 #else
1818                 this->pGmmUmdLibContext = reinterpret_cast<uint64_t>(pNewGmmLibContext);
1819 #endif
1820              }
1821 
1822             /////////////////////////////////////////////////////////////////////////////////////
1823             /// Overrides the X offset of planar surface
1824             /// @param[in]  Plane: Plane for which the offset needs to be overriden
1825             /// @param[in]  XOffset: X offset
1826             /////////////////////////////////////////////////////////////////////////////////////
OverridePlanarXOffset(GMM_YUV_PLANE Plane,GMM_GFX_SIZE_T XOffset)1827             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverridePlanarXOffset(GMM_YUV_PLANE Plane, GMM_GFX_SIZE_T XOffset)
1828             {
1829                 __GMM_ASSERT(Plane < GMM_MAX_PLANE);
1830                 Surf.OffsetInfo.Plane.X[Plane] = XOffset;
1831             }
1832 
1833             /////////////////////////////////////////////////////////////////////////////////////
1834             /// Overrides the Y offset of planar surface
1835             /// @param[in]  Plane: Plane for which the offset needs to be overriden
1836             /// @param[in]  YOffset: Y offset
1837             /////////////////////////////////////////////////////////////////////////////////////
OverridePlanarYOffset(GMM_YUV_PLANE Plane,GMM_GFX_SIZE_T YOffset)1838             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED void GMM_STDCALL OverridePlanarYOffset(GMM_YUV_PLANE Plane, GMM_GFX_SIZE_T YOffset)
1839             {
1840                 __GMM_ASSERT(Plane < GMM_MAX_PLANE);
1841                 Surf.OffsetInfo.Plane.Y[Plane] = YOffset;
1842             }
1843 
1844             GMM_VIRTUAL GMM_STATUS              GMM_STDCALL CreateCustomRes(Context& GmmLibContext, GMM_RESCREATE_CUSTOM_PARAMS& CreateParams);
1845             protected:
1846                 GMM_VIRTUAL void UpdateUnAlignedParams();
1847             public:
1848             /////////////////////////////////////////////////////////////////////////////////////
1849             /// Returns the resource's compressions block width
1850             /// @return    Compression block width
1851             /////////////////////////////////////////////////////////////////////////////////////
GetCompressionBlockWidth()1852             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetCompressionBlockWidth()
1853             {
1854                 GMM_RESOURCE_FORMAT Format;
1855                 Format = Surf.Format;
1856 
1857                 __GMM_ASSERT((Format > GMM_FORMAT_INVALID) &&
1858                              (Format < GMM_RESOURCE_FORMATS));
1859 
1860                 return GetGmmLibContext()->GetPlatformInfo().FormatTable[Format].Element.Width;
1861             }
1862 
1863             /////////////////////////////////////////////////////////////////////////////////////
1864             /// Returns the resource's compressions block height
1865             /// @return    Compression block width
1866             /////////////////////////////////////////////////////////////////////////////////////
GetCompressionBlockHeight()1867             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetCompressionBlockHeight()
1868             {
1869                 GMM_RESOURCE_FORMAT Format;
1870                 Format = Surf.Format;
1871 
1872                 __GMM_ASSERT((Format > GMM_FORMAT_INVALID) &&
1873                              (Format < GMM_RESOURCE_FORMATS));
1874 
1875                 return GetGmmLibContext()->GetPlatformInfo().FormatTable[Format].Element.Height;
1876             }
1877 
1878             /////////////////////////////////////////////////////////////////////////////////////
1879             /// Returns the resource's compressions block depth
1880             /// @return    Compression block width
1881             /////////////////////////////////////////////////////////////////////////////////////
GetCompressionBlockDepth()1882             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetCompressionBlockDepth()
1883             {
1884                 GMM_RESOURCE_FORMAT Format;
1885                 Format = Surf.Format;
1886 
1887                 __GMM_ASSERT((Format > GMM_FORMAT_INVALID) &&
1888                              (Format < GMM_RESOURCE_FORMATS));
1889 
1890                 return GetGmmLibContext()->GetPlatformInfo().FormatTable[Format].Element.Depth;
1891             }
1892 
1893             /////////////////////////////////////////////////////////////////////////////////////
1894             /// Returns whether resource uses LOD0-only or Full array spacing
1895             /// @return     1/0
1896             /////////////////////////////////////////////////////////////////////////////////////
IsArraySpacingSingleLod()1897             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint8_t GMM_STDCALL IsArraySpacingSingleLod()
1898             {
1899                 __GMM_ASSERT(GFX_GET_CURRENT_RENDERCORE(GetGmmLibContext()->GetPlatformInfo().Platform) < IGFX_GEN8_CORE);
1900                 return Surf.Alignment.ArraySpacingSingleLod;
1901             }
1902 
1903             /////////////////////////////////////////////////////////////////////////////////////
1904             /// Returns whether resource is ASTC
1905             /// @return     1/0
1906             /////////////////////////////////////////////////////////////////////////////////////
IsASTC()1907             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint8_t GMM_STDCALL IsASTC()
1908             {
1909                 GMM_RESOURCE_FORMAT Format;
1910                 Format = Surf.Format;
1911 
1912                 return (Format > GMM_FORMAT_INVALID) &&
1913                        (Format < GMM_RESOURCE_FORMATS) &&
1914                        GetGmmLibContext()->GetPlatformInfo().FormatTable[Format].ASTC;
1915             }
1916 
1917             /////////////////////////////////////////////////////////////////////////////////////
1918             /// Returns MOCS associated with the resource
1919             /// @param[in]     MOCS
1920             /////////////////////////////////////////////////////////////////////////////////////
GetMOCS()1921             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GetMOCS()
1922             {
1923                 const GMM_CACHE_POLICY_ELEMENT *CachePolicy = GetGmmLibContext()->GetCachePolicyUsage();
1924 
1925             GMM_RESOURCE_USAGE_TYPE Usage = GetCachePolicyUsage();
1926 
1927 		        __GMM_ASSERT(CachePolicy[Usage].Initialized);
1928 
1929                 // Prevent wrong Usage for XAdapter resources. UMD does not call GetMemoryObject on shader resources but,
1930                 // when they add it someone could call it without knowing the restriction.
1931                 if(Surf.Flags.Info.XAdapter &&
1932                    (Usage != GMM_RESOURCE_USAGE_XADAPTER_SHARED_RESOURCE))
1933                 {
1934                     __GMM_ASSERT(false);
1935                 }
1936 
1937                 if((CachePolicy[Usage].Override & CachePolicy[Usage].IDCode) ||
1938                    (CachePolicy[Usage].Override == ALWAYS_OVERRIDE))
1939                 {
1940                     return CachePolicy[Usage].MemoryObjectOverride;
1941                 }
1942 
1943                 return CachePolicy[Usage].MemoryObjectNoOverride;
1944             }
1945 
1946             /////////////////////////////////////////////////////////////////////////////////////
1947             /// Returns the surface state value for Standard Tiling Mode Extension
1948             /// @return     Standard Tiling Mode Extension
1949             /////////////////////////////////////////////////////////////////////////////////////
GetStdTilingModeExtSurfaceState()1950             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetStdTilingModeExtSurfaceState()
1951             {
1952                 __GMM_ASSERT(GFX_GET_CURRENT_RENDERCORE(GetGmmLibContext()->GetPlatformInfo().Platform) > IGFX_GEN10_CORE);
1953 
1954                 if(GetGmmLibContext()->GetSkuTable().FtrStandardMipTailFormat)
1955                 {
1956                     return 1;
1957                 }
1958 
1959                 return 0;
1960             }
1961 
1962             /////////////////////////////////////////////////////////////////////////////////////
1963             /// Returns the surface state value for Resource Format
1964             /// @return     Resource Format
1965             /////////////////////////////////////////////////////////////////////////////////////
GetResourceFormatSurfaceState()1966             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_SURFACESTATE_FORMAT GMM_STDCALL GetResourceFormatSurfaceState()
1967             {
1968                 GMM_RESOURCE_FORMAT Format;
1969 
1970                 Format = Surf.Format;
1971                 __GMM_ASSERT((Format > GMM_FORMAT_INVALID) && (Format < GMM_RESOURCE_FORMATS));
1972 
1973                 return GetGmmLibContext()->GetPlatformInfo().FormatTable[Format].SurfaceStateFormat;
1974             }
1975 
GetMultiTileArch()1976             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED const GMM_MULTI_TILE_ARCH& GetMultiTileArch()
1977             {
1978                 return MultiTileArch;
1979             }
1980 
1981 	    /////////////////////////////////////////////////////////////////////////////////////
1982             /// Returns the Flat Phys CCS Size for the resource
1983             /// @return     CCS size in bytes
1984             /////////////////////////////////////////////////////////////////////////////////////
GetFlatPhysCcsSize()1985             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetFlatPhysCcsSize()
1986             {
1987                 if((GetGmmLibContext()->GetSkuTable().FtrFlatPhysCCS) &&
1988                     !(Surf.Flags.Info.AllowVirtualPadding ||
1989                         Surf.Flags.Info.ExistingSysMem ||
1990                         Surf.Flags.Info.NonLocalOnly))
1991                 {
1992 		    if (GetGmmLibContext()->GetSkuTable().FtrXe2Compression)
1993 		    {
1994 			return GFX_CEIL_DIV(Surf.Size, 512);
1995 		    }
1996 		    else
1997 		    {
1998 			return GFX_CEIL_DIV(Surf.Size, 256);
1999 		    }
2000 		}
2001                 return 0;
2002             }
2003 			/////////////////////////////////////////////////////////////////////////////////////
2004             /// Returns Tiled mode for DEPTH_BUFFER_STATE/STENCIL_BUFFER_STATE/ HIER_DEPTH_BUFFER programming.
2005             /// HIZ is always 4kb tiling, XeHP+ TileMode for HIZ is Tile4 and main surface can be
2006             /// Tile64 , GMM_AUX_INVALID, will return data for main depth/stencil resource ,
2007             /// GMM_AUX_HiZ returns data for HIZ resource
2008             /// @return     Tiled Resource Mode(PreGen12) / Tiled Mode(Gen12+)
2009             /////////////////////////////////////////////////////////////////////////////////////
2010             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL GetTiledModeDepthStencilState( GMM_UNIFIED_AUX_TYPE  AuxType = GMM_AUX_INVALID)
2011             {
2012                 uint32_t TiledMode = 0;
2013 
2014                 if(GMM_IS_TILEY(GetGmmLibContext()))
2015                 {
2016                     TiledMode =
2017 				Surf.Flags.Info.TiledYf ? 1 :
2018 				Surf.Flags.Info.TiledYs ? 2 :
2019 			        /*TILE_NONE*/		  0;
2020                 }
2021                 else
2022                 {
2023                     //1 and 3 are only valid value , 0 and 2 are reserved for XeHP+
2024                     if( (AuxType == GMM_AUX_HIZ) && AuxSurf.Flags.Gpu.HiZ )
2025                     {
2026                         TiledMode =
2027                             AuxSurf.Flags.Info.Tile4    ? 3 :
2028                             AuxSurf.Flags.Info.Tile64   ? 1 :
2029                             /* Default */                 0;
2030 
2031                         __GMM_ASSERT(TiledMode == 3);
2032                     }
2033                     else
2034                     {
2035                         TiledMode =
2036                             Surf.Flags.Info.Tile4   ? 3 :
2037                             Surf.Flags.Info.Tile64  ? 1 :
2038                             /* Default */	      0;
2039 
2040                         __GMM_ASSERT( TiledMode );
2041 
2042                     }
2043 
2044                 }
2045 
2046                 return TiledMode;
2047             }
2048 #ifndef __GMM_KMD__
2049             GMM_VIRTUAL GMM_STATUS GMM_STDCALL CreateCustomRes_2(Context &GmmLibContext, GMM_RESCREATE_CUSTOM_PARAMS_2 &CreateParams);
2050 #endif
2051 
2052             /////////////////////////////////////////////////////////////////////////////////////
2053             /// Returns physical size of the main surface only. Aux surface size not included.
2054             /// @return     Physical Size of main surface
2055             /////////////////////////////////////////////////////////////////////////////////////
GetSizeMainSurfacePhysical()2056 	    GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetSizeMainSurfacePhysical()
2057             {
2058                 GMM_GFX_SIZE_T Size;
2059                 if(GMM_IS_PLANAR(Surf.Format) && Is1MBAlignedAuxTPlanarSurface())
2060                 {
2061                     Size = ((Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_Y] + Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_U] + Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_V]) * Surf.OffsetInfo.PlaneXe_LPG.PhysicalPitch);
2062                     Size *= GFX_MAX(Surf.ArraySize, 1);
2063                 }
2064                 else
2065                 {
2066                     // Physical Size = VA Size
2067                     Size = GetSizeMainSurface();
2068                 }
2069                 return Size;
2070             }
2071 
2072             /////////////////////////////////////////////////////////////////////////////////////
2073             /// Returns total physical size of surface.
2074             /// @return     Surface Size
2075             /////////////////////////////////////////////////////////////////////////////////////
GetSizeSurfacePhysical()2076             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_GFX_SIZE_T GMM_STDCALL GetSizeSurfacePhysical()
2077             {
2078                 GMM_GFX_SIZE_T Size;
2079                 if(GMM_IS_PLANAR(Surf.Format) && Is1MBAlignedAuxTPlanarSurface())
2080                 {
2081                     Size = (Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_Y] + Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_U] + Surf.OffsetInfo.PlaneXe_LPG.Physical.Height[GMM_PLANE_V]) * Surf.OffsetInfo.PlaneXe_LPG.PhysicalPitch;
2082                     Size *= GFX_MAX(Surf.ArraySize, 1);
2083                     Size += AuxSurf.Size + AuxSecSurf.Size;
2084                 }
2085                 else
2086                 {
2087                     // Physical Size = VA Size
2088                     Size = GetSizeSurface();
2089                 };
2090                 return Size;
2091             }
2092 
2093             /////////////////////////////////////////////////////////////////////////////////////
2094             /// Returns if a resource is 1MB aligned AuxT enabled planar surface
2095             /// @return              Is1MBAuxTAlignedPlanes Flag
2096 
2097             /////////////////////////////////////////////////////////////////////////////////////
Is1MBAlignedAuxTPlanarSurface()2098             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL Is1MBAlignedAuxTPlanarSurface()
2099             {
2100 	        const GMM_PLATFORM_INFO *pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
2101 
2102 	        if(GMM_IS_1MB_AUX_TILEALIGNEDPLANES(pPlatform->Platform, Surf))
2103 	        {
2104 	            return Surf.OffsetInfo.PlaneXe_LPG.Is1MBAuxTAlignedPlanes;
2105 	        }
2106 
2107 	        return 0;
2108             }
2109 
IsResourceMappedCompressible()2110             GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint32_t GMM_STDCALL IsResourceMappedCompressible()
2111             {
2112                 uint32_t CompressedRes = 0;
2113                 if (GetGmmLibContext()->GetSkuTable().FtrXe2Compression)
2114                 {
2115                     CompressedRes = !Surf.Flags.Info.NotCompressed;
2116                 }
2117                 else
2118                 {
2119                     CompressedRes = Surf.Flags.Info.RenderCompressed || Surf.Flags.Info.MediaCompressed;
2120                 }
2121 
2122                 return CompressedRes;
2123             }
2124 
2125 	    /////////////////////////////////////////////////////////////////////////////////////
2126 	    /// Returns true for displayable resources
2127 	    /// @return
2128 	    /////////////////////////////////////////////////////////////////////////////////////
IsDisplayable()2129 	    GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED bool GMM_STDCALL IsDisplayable()
2130 	    {
2131 	        return ((Surf.Type == RESOURCE_PRIMARY) || (Surf.Type == RESOURCE_CURSOR) || Surf.Flags.Gpu.FlipChain || Surf.Flags.Gpu.Overlay);
2132 	    }
2133 
GetDriverProtectionBits(GMM_OVERRIDE_VALUES OverrideData)2134 	    GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED uint64_t GMM_STDCALL GetDriverProtectionBits(GMM_OVERRIDE_VALUES OverrideData)
2135 	    {
2136 	        GMM_DRIVERPROTECTION     DriverProtection = {{0}};
2137 	        const GMM_PLATFORM_INFO *pPlatform;
2138 	        GMM_RESOURCE_USAGE_TYPE  Usage;
2139 
2140 	        pPlatform = (GMM_PLATFORM_INFO *)GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(&Surf, GetGmmLibContext());
2141 	        if (GFX_GET_CURRENT_PRODUCT(pPlatform->Platform) < IGFX_PVC)
2142 	        {
2143 	            return 0;
2144 	        }
2145 	        Usage = Surf.CachePolicy.Usage;
2146 	        if ((OverrideData.Usage > GMM_RESOURCE_USAGE_UNKNOWN) && (OverrideData.Usage < GMM_RESOURCE_USAGE_MAX))
2147 	        {
2148 	            Usage = (GMM_RESOURCE_USAGE_TYPE)OverrideData.Usage;
2149 	        }
2150 	        if (GetGmmLibContext()->GetSkuTable().FtrXe2Compression)
2151 	        {
2152 	            if (OverrideData.CompressionDis)
2153 	            {
2154 	                DriverProtection.CompressionEnReq = 0;
2155 	            }
2156 	            else
2157 	            {
2158 
2159 	                DriverProtection.CompressionEnReq = !Surf.Flags.Info.NotCompressed;
2160 	            }
2161 	        }
2162 
2163 	        bool IscompressionEn              = DriverProtection.CompressionEnReq ? true : false;
2164 	        DriverProtection.CacheableNoSnoop = false;
2165 
2166 	        DriverProtection.PATIndex = GetGmmLibContext()->GetCachePolicyObj()->CachePolicyGetPATIndex(NULL, Usage, &IscompressionEn, (bool)(Surf.Flags.Info.Cacheable));
2167 
2168 	        DriverProtection.CompressionEnReq = IscompressionEn ? true : false;
2169 
2170 	        return DriverProtection.Value;
2171 	    }
2172 
2173 	    GMM_VIRTUAL uint64_t GMM_STDCALL       Get2DFastClearSurfaceWidthFor3DSurface(uint32_t MipLevel);
2174 	    GMM_VIRTUAL uint64_t GMM_STDCALL       Get2DFastClearSurfaceHeightFor3DSurface(uint32_t MipLevel);
2175 
2176     };
2177 
2178 } // namespace GmmLib
2179 #endif // #ifdef __cplusplus
2180