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