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 
23 #include "Internal/Common/GmmLibInc.h"
24 
PlatformInfo(PLATFORM & Platform,Context * pGmmLibContext)25 GmmLib::PlatformInfo::PlatformInfo(PLATFORM &Platform, Context *pGmmLibContext)
26 {
27     GMM_DPF_ENTER;
28 
29     memset(&Data, 0, sizeof(Data));
30     Data.Platform = Platform;
31 
32     this->pGmmLibContext = pGmmLibContext;
33 
34     GMM_RESOURCE_FORMAT GmmFormat;
35 #define GMM_FORMAT_GEN(X) (GFX_GET_CURRENT_RENDERCORE(Data.Platform) >= IGFX_GEN##X##_CORE)
36 #define GMM_FORMAT_SKU(FtrXxx) (pGmmLibContext->GetSkuTable().FtrXxx != 0)
37 #define GMM_FORMAT_WA(WaXxx) (pGmmLibContext->GetWaTable().WaXxx != 0)
38 #define GMM_COMPR_FORMAT_INVALID GMM_E2ECOMP_FORMAT_INVALID
39 #define GMM_FORMAT(Name, bpe, _Width, _Height, _Depth, IsRT, IsASTC, RcsSurfaceFormat, SSCompressionFmt, Availability)        \
40                                                                                                                          \
41     {                                                                                                                    \
42         GmmFormat                                                       = GMM_FORMAT_##Name;                             \
43         Data.FormatTable[GmmFormat].ASTC                                = (IsASTC);                                      \
44         Data.FormatTable[GmmFormat].Element.BitsPer                     = (bpe);                                         \
45         Data.FormatTable[GmmFormat].Element.Depth                       = (_Depth);                                      \
46         Data.FormatTable[GmmFormat].Element.Height                      = (_Height);                                     \
47         Data.FormatTable[GmmFormat].Element.Width                       = (_Width);                                      \
48         Data.FormatTable[GmmFormat].RenderTarget                        = ((IsRT) != 0);                                 \
49         Data.FormatTable[GmmFormat].SurfaceStateFormat                  = ((GMM_SURFACESTATE_FORMAT)(RcsSurfaceFormat)); \
50         Data.FormatTable[GmmFormat].CompressionFormat.CompressionFormat = (SSCompressionFmt);                            \
51         Data.FormatTable[GmmFormat].Supported                           = ((Availability) != 0);                         \
52         if(((_Depth) > 1) || ((_Height) > 1) || ((_Width) > 1))                                                          \
53         {                                                                                                                \
54             Data.FormatTable[GmmFormat].Compressed = 1;                                                                  \
55         }                                                                                                                \
56     }
57 
58 #include "External/Common/GmmFormatTable.h"
59 }
60 
61 /////////////////////////////////////////////////////////////////////////////////////
62 /// Copies parameters or sets flags based on info sent by the client.
63 ///
64 /// @param[in]  CreateParams: Flags which specify what sort of resource to create
65 /////////////////////////////////////////////////////////////////////////////////////
SetCCSFlag(GMM_RESOURCE_FLAG & Flags)66 void GmmLib::PlatformInfo::SetCCSFlag(GMM_RESOURCE_FLAG &Flags)
67 {
68     if(Flags.Gpu.MCS)
69     {
70         Flags.Gpu.CCS = Flags.Gpu.MCS;
71     }
72     Flags.Info.RenderCompressed = Flags.Info.MediaCompressed = 0;
73 }
74 
75 /////////////////////////////////////////////////////////////////////////////////////
76 /// Validates the MMC parameters passed in by clients to make sure they do not
77 /// conflict or ask for unsupporting combinations/features.
78 ///
79 /// @param[in]  GMM_TEXTURE_INFO which specify what sort of resource to create
80 /// @return     1 is validation passed. 0 otherwise.
81 /////////////////////////////////////////////////////////////////////////////////////
ValidateMMC(GMM_TEXTURE_INFO & Surf)82 uint8_t GmmLib::PlatformInfo::ValidateMMC(GMM_TEXTURE_INFO &Surf)
83 {
84     if(Surf.Flags.Gpu.MMC && //For Media Memory Compression --
85        ((!(GMM_IS_4KB_TILE(Surf.Flags) || GMM_IS_64KB_TILE(Surf.Flags))) ||
86         Surf.ArraySize > GMM_MAX_MMC_INDEX))
87     {
88         return 0;
89     }
90     return 1;
91 }
92 
93 /////////////////////////////////////////////////////////////////////////////////////
94 /// Validates the parameters passed in by clients to make sure they do not
95 /// conflict or ask for unsupporting combinations/features.
96 ///
97 /// @param[in]  GMM_TEXTURE_INFO which specify what sort of resource to create
98 /// @return     1 is validation passed. 0 otherwise.
99 /////////////////////////////////////////////////////////////////////////////////////
ValidateCCS(GMM_TEXTURE_INFO & Surf)100 uint8_t GmmLib::PlatformInfo::ValidateCCS(GMM_TEXTURE_INFO &Surf)
101 {
102     if(!(                                                             //--- Legitimate CCS Case ----------------------------------------
103        ((Surf.Type >= RESOURCE_2D && Surf.Type <= RESOURCE_BUFFER) && //Not supported: 1D; Supported: Buffer, 2D, 3D, cube, Arrays, mip-maps, MSAA, Depth/Stencil
104         (Surf.Type <= RESOURCE_CUBE)) ||
105        (Surf.Type == RESOURCE_2D && Surf.MaxLod == 0)))
106     {
107         GMM_ASSERTDPF(0, "Invalid CCS usage!");
108         return 0;
109     }
110 
111     if(Surf.Flags.Info.RenderCompressed && Surf.Flags.Info.MediaCompressed)
112     {
113         GMM_ASSERTDPF(0, "Invalid CCS usage - can't be both RC and MC!");
114         return 0;
115     }
116 
117     return 1;
118 }
119 
120 /////////////////////////////////////////////////////////////////////////////////////
121 /// Validates the UnifiedAuxSurface parameters passed in by clients to make sure they do not
122 /// conflict or ask for unsupporting combinations/features.
123 ///
124 /// @param[in]  GMM_TEXTURE_INFO which specify what sort of resource to create
125 /// @return     1 is validation passed. 0 otherwise.
126 /////////////////////////////////////////////////////////////////////////////////////
ValidateUnifiedAuxSurface(GMM_TEXTURE_INFO & Surf)127 uint8_t GmmLib::PlatformInfo::ValidateUnifiedAuxSurface(GMM_TEXTURE_INFO &Surf)
128 {
129     if((Surf.Flags.Gpu.UnifiedAuxSurface) &&
130        !( //--- Legitimate UnifiedAuxSurface Case ------------------------------------------
131        Surf.Flags.Gpu.CCS &&
132        (Surf.MSAA.NumSamples <= 1 && (Surf.Flags.Gpu.RenderTarget || Surf.Flags.Gpu.Texture))))
133     {
134         GMM_ASSERTDPF(0, "Invalid UnifiedAuxSurface usage!");
135         return 0;
136     }
137     return 1;
138 }
139 
140 //=============================================================================
141 //
142 // Function: CheckFmtDisplayDecompressible
143 //
144 // Desc: Returns true if display hw supports lossless render/media decompression
145 //       else returns false.
146 //       Umds can call it to decide if full resolve is required
147 //
148 // Parameters:
149 //      See function arguments.
150 //
151 // Returns:
152 //      uint8_t
153 //-----------------------------------------------------------------------------
CheckFmtDisplayDecompressible(GMM_TEXTURE_INFO & Surf,bool IsSupportedRGB64_16_16_16_16,bool IsSupportedRGB32_8_8_8_8,bool IsSupportedRGB32_2_10_10_10,bool IsSupportedMediaFormats)154 uint8_t GmmLib::PlatformInfo::CheckFmtDisplayDecompressible(GMM_TEXTURE_INFO &Surf,
155                                                             bool              IsSupportedRGB64_16_16_16_16,
156                                                             bool              IsSupportedRGB32_8_8_8_8,
157                                                             bool              IsSupportedRGB32_2_10_10_10,
158                                                             bool              IsSupportedMediaFormats)
159 {
160     bool IsRenderCompressed = false;
161     GMM_UNREFERENCED_PARAMETER(IsSupportedMediaFormats);
162     GMM_UNREFERENCED_PARAMETER(IsSupportedRGB64_16_16_16_16);
163     GMM_UNREFERENCED_PARAMETER(Surf);
164 
165     if(IsSupportedRGB32_8_8_8_8 || //RGB32 8 : 8 : 8 : 8
166        (GFX_GET_CURRENT_DISPLAYCORE(pGmmLibContext->GetPlatformInfo().Platform) >= IGFX_GEN10_CORE &&
167         IsSupportedRGB32_2_10_10_10)) //RGB32 2 : 10 : 10 : 10))
168     {
169         IsRenderCompressed = true;
170     }
171     return IsRenderCompressed;
172 }
173 
174 /////////////////////////////////////////////////////////////////////////////////////
175 /// C wrapper to get platform info data pointer (non-override platform info)
176 ///
177 /// @return Pointer to platform info data
178 /////////////////////////////////////////////////////////////////////////////////////
__GmmGetPlatformInfo(void * pLibContext)179 const GMM_PLATFORM_INFO *GMM_STDCALL __GmmGetPlatformInfo(void *pLibContext)
180 {
181     GMM_LIB_CONTEXT *pGmmLibContext = (GMM_LIB_CONTEXT *)pLibContext;
182     __GMM_ASSERTPTR(pGmmLibContext, NULL)
183 
184     if(pGmmLibContext->GetPlatformInfoObj() != NULL)
185     {
186         return (const GMM_PLATFORM_INFO *)(&(pGmmLibContext->GetPlatformInfo()));
187     }
188 
189     return NULL;
190 }
191 /////////////////////////////////////////////////////////////////////////////////////
192 /// @param[in] Number: Number of Fence Registers
193 /////////////////////////////////////////////////////////////////////////////////////
__SetNumberFenceRegisters(void * pLibContext,uint32_t Number)194 void GMM_STDCALL __SetNumberFenceRegisters(void *pLibContext, uint32_t Number)
195 {
196     GMM_LIB_CONTEXT *pGmmLibContext = (GMM_LIB_CONTEXT *)pLibContext;
197     __GMM_ASSERT(pGmmLibContext != NULL)
198 
199     if(pGmmLibContext != NULL && pGmmLibContext->GetPlatformInfoObj() != NULL)
200     {
201         pGmmLibContext->GetPlatformInfoObj()->SetDataNumberFenceRegisters(Number);
202     }
203 }
204 
GmmPlatformGetBppFromGmmResourceFormat(void * pLibContext,GMM_RESOURCE_FORMAT Format)205 uint32_t GMM_STDCALL GmmPlatformGetBppFromGmmResourceFormat(void *pLibContext, GMM_RESOURCE_FORMAT Format)
206 {
207     GMM_LIB_CONTEXT *pGmmLibContext = (GMM_LIB_CONTEXT *)pLibContext;
208 
209     __GMM_ASSERT((Format > GMM_FORMAT_INVALID) && (Format < GMM_RESOURCE_FORMATS));
210     __GMM_ASSERT(pGmmLibContext);
211     __GMM_ASSERT(pGmmLibContext->GetPlatformInfo().FormatTable[Format].Element.BitsPer >> 3);
212     return pGmmLibContext->GetPlatformInfo().FormatTable[Format].Element.BitsPer;
213 }
214