1 /*==============================================================================
2 Copyright(c) 2022 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 #include "External/Common/GmmCachePolicy.h"
25 #include "External/Common/CachePolicy/GmmCachePolicyXe_LPG.h"
26 //=============================================================================
27 //
28 // Function: __:GmmXe_LPGInitCachePolicy
29 //
30 // Desc: This function initializes the cache policy
31 //
32 // Parameters: pCachePolicy -> Ptr to array to be populated with the
33 // mapping of usages -> cache settings.
34 //
35 // Return: GMM_STATUS
36 //
37 //-----------------------------------------------------------------------------
InitCachePolicy()38 GMM_STATUS GmmLib::GmmXe_LPGCachePolicy::InitCachePolicy()
39 {
40 __GMM_ASSERTPTR(pCachePolicy, GMM_ERROR);
41
42 #define DEFINE_CACHE_ELEMENT(usage, l3, l3_scc, go, uclookup, l1cc, l2cc, l4cc, coherency) DEFINE_CP_ELEMENT(usage, 0, 0, l3, 0, 0, 0, 0, l3_scc, 0, 0, 0, 0, 0, 0, go, uclookup, l1cc, l2cc, l4cc, coherency, l3, 0, 0)
43
44 #include "GmmXe_LPGCachePolicy.h"
45
46 #define L3_UNCACHEABLE (0x1)
47 #define L3_WB_CACHEABLE (0x3)
48
49 #define DISABLE_SKIP_CACHING_CONTROL (0x0)
50 #define ENABLE_SKIP_CACHING_CONTROL (0x1)
51
52 #define ONE_WAY_COHERENT (0x2)
53
54
55 SetUpMOCSTable();
56 SetupPAT();
57
58 // Define index of cache element
59 uint32_t Usage = 0;
60 uint32_t ReservedMocsIdx = 10; /* Rsvd MOCS section 10-12 */
61
62 #if(_WIN32 && (_DEBUG || _RELEASE_INTERNAL))
63 void *pKmdGmmContext = NULL;
64 #if(defined(__GMM_KMD__))
65 pKmdGmmContext = pGmmLibContext->GetGmmKmdContext();
66 #endif
67 OverrideCachePolicy(pKmdGmmContext);
68 #endif
69 // Process the cache policy and fill in the look up table
70 for(; Usage < GMM_RESOURCE_USAGE_MAX; Usage++)
71 {
72 bool CachePolicyError = false;
73 int32_t CPTblIdx = -1, PATIdx = -1, CoherentPATIdx = -1;
74 uint32_t i, j, k;
75 GMM_CACHE_POLICY_TBL_ELEMENT UsageEle = {0};
76 uint32_t StartMocsIdx = 0;
77 GMM_L4_CACHING_POLICY PATCachePolicy;
78 GMM_PRIVATE_PAT UsagePATElement = {0};
79 GMM_PTE_CACHE_CONTROL_BITS PTE = {0};
80
81 // MOCS data
82 {
83 //L3
84 UsageEle.L3.Reserved = 0; // Reserved bits zeroe'd, this is so we
85 // we can compare the unioned L3.UshortValue.
86 UsageEle.L3.ESC = DISABLE_SKIP_CACHING_CONTROL;
87 UsageEle.L3.SCC = 0;
88 UsageEle.L3.Cacheability = pCachePolicy[Usage].L3 ? L3_WB_CACHEABLE : L3_UNCACHEABLE;
89
90
91 if(pCachePolicy[Usage].L3 == 0)
92 {
93 UsageEle.L3.GlobalGo = pCachePolicy[Usage].GlbGo;
94 }
95 UsageEle.L3.UCLookup = pCachePolicy[Usage].UcLookup;
96 __GMM_ASSERT((pCachePolicy[Usage].UcLookup) || (pCachePolicy[Usage].L3 == 0 && pCachePolicy[Usage].UcLookup == 0));
97
98
99 // L4 Data
100 UsageEle.LeCC.Xe_LPG.L4CC = (pCachePolicy[Usage].L4CC - 1) % 4; // coverting indicator values to actual regiser values 0->3(GMM_CP_NON_COHERENT_UC), 2->1(GMM_CP_NON_COHERENT_WT) 1->0(GMM_CP_NON_COHERENT_WB)
101
102 /* Valid MOCS Index starts from 1 */
103 for(j = 1; j <= CurrentMaxMocsIndex; j++)
104 {
105 GMM_CACHE_POLICY_TBL_ELEMENT *TblEle = &pGmmLibContext->GetCachePolicyTlbElement()[j];
106 if((TblEle->L3.UshortValue == UsageEle.L3.UshortValue) &&
107 (TblEle->LeCC.Xe_LPG.L4CC == UsageEle.LeCC.Xe_LPG.L4CC))
108 {
109 CPTblIdx = j;
110 break;
111 }
112 }
113 if(CPTblIdx == -1)
114 {
115 #if(_WIN32 && (_DEBUG || _RELEASE_INTERNAL))
116 // If the Cache Policy setting is overriden through regkey
117 if((pCachePolicy[Usage].IsOverridenByRegkey) && (ReservedMocsIdx < 13)) /* Reserved MOCS 10-12 */
118 {
119 /*Use the Reserved Section to add new MOCS settings,*/
120 GMM_CACHE_POLICY_TBL_ELEMENT *TblEle = &(pGmmLibContext->GetCachePolicyTlbElement()[ReservedMocsIdx++]);
121 CPTblIdx = ReservedMocsIdx;
122 TblEle->L3.UshortValue = UsageEle.L3.UshortValue;
123 TblEle->LeCC.Xe_LPG.DwordValue = UsageEle.LeCC.Xe_LPG.DwordValue;
124 GMM_ASSERTDPF(false, "CRITICAL: Cache Policy Usage value for L3/L4 specified by Client is not defined in Fixed MOCS Table and added to reserved MOCS section !!");
125 }
126 else
127 #endif
128 {
129 // Log Error using regkey to indicate the above error
130 #if(_WIN32 && (_DEBUG || _RELEASE_INTERNAL) && __GMM_KMD__)
131 REGISTRY_OVERRIDE_WRITE(pKmdGmmContext, Usage, UnSupportedMOCSEntryL3Value, UsageEle.L3.UshortValue);
132 #endif
133 CachePolicyError = true;
134 GMM_ASSERTDPF(false, "CRITICAL ERROR: Cache Policy Usage value for L3 specified by Client is not defined in Fixed MOCS Table!");
135 // Set cache policy index to default MOCS.
136 CPTblIdx = 0;
137 }
138 }
139 }
140
141 // PAT data
142 {
143 UsagePATElement.Xe_LPG.Reserved = 0;
144
145 UsagePATElement.Xe_LPG.L4CC = (pCachePolicy[Usage].L4CC - 1) % 4; // coverting indicator values to actual regiser values 0->3(GMM_CP_NON_COHERENT_UC), 2->1(GMM_CP_NON_COHERENT_WT) 1->0(GMM_CP_NON_COHERENT_WB)
146
147
148 UsagePATElement.Xe_LPG.Coherency = pCachePolicy[Usage].Coherency ? (pCachePolicy[Usage].Coherency + 1) : GMM_GFX_NON_COHERENT_NO_SNOOP; // pCachePolicy[Usage].Coherency -> UsagePATElement.Xe_LPG.Coherency : 0 -> GMM_GFX_NON_COHERENT_NO_SNOOP, 1 -> GMM_GFX_COHERENT_ONE_WAY_IA_SNOOP(2), 2 -> GMM_GFX_COHERENT_TWO_WAY_IA_GPU_SNOOP(3)
149
150 if((UsagePATElement.Xe_LPG.L4CC >= GMM_CP_NON_COHERENT_WT) && (UsagePATElement.Xe_LPG.Coherency >= GMM_GFX_COHERENT_ONE_WAY_IA_SNOOP))
151 {
152 // restrictions
153 // __GMM_ASSERT(FALSE); // disable assert till there is more clarity on Snoop + UC combination support in PAT register
154
155 // unsupported combination of coherency and L4cachepolicy
156 // Promote caching to _WB and support snoop
157 UsagePATElement.Xe_LPG.L4CC = GMM_CP_COHERENT_WB;
158 }
159 // try to find a match in static PAT table
160 for(i = 0; i <= CurrentMaxPATIndex; i++)
161 {
162 GMM_PRIVATE_PAT PAT = GetPrivatePATEntry(i);
163 if(UsagePATElement.Xe_LPG.L4CC == PAT.Xe_LPG.L4CC &&
164 UsagePATElement.Xe_LPG.Coherency == PAT.Xe_LPG.Coherency)
165 {
166 PATIdx = i;
167 break;
168 }
169 }
170
171 if(PATIdx == -1)
172 {
173 // Didn't find the caching settings in one of the already programmed PAT table entries.
174 // Need to add a new lookup table entry.
175 #if(_WIN32 && (_DEBUG || _RELEASE_INTERNAL))
176 // If the Cache Policy setting is overriden through regkey,
177 if(pCachePolicy[Usage].IsOverridenByRegkey)
178 {
179 if(CurrentMaxPATIndex < NumPATRegisters)
180 {
181 SetPrivatePATEntry(++CurrentMaxPATIndex, UsagePATElement); // updates private PAT table
182 PATIdx = CurrentMaxPATIndex;
183 }
184 else
185 {
186 GMM_ASSERTDPF(
187 "Cache Policy Init Error: Invalid Cache Programming, too many unique caching combinations"
188 "(we only support NumPATRegisters = %d)",
189 NumPATRegisters - 1);
190 CachePolicyError = true;
191 // add rterror here <ToDo>
192 PATIdx = PAT2; //default to uncached PAT index 2: GMM_CP_NON_COHERENT_UC
193 }
194 }
195 #else
196 {
197 GMM_ASSERTDPF(
198 "Cache Policy Init Error: Invalid Cache Programming, too many unique caching combinations"
199 "(we only support NumPATRegisters = %d)",
200 CurrentMaxPATIndex);
201 CachePolicyError = true;
202 // add rterror here <ToDo>
203 PATIdx = PAT2; // default to uncached PAT index 2: GMM_CP_NON_COHERENT_UC
204 // Log Error using regkey to indicate the above error
205 #if(_WIN32 && (_DEBUG || _RELEASE_INTERNAL) && __GMM_KMD__)
206 REGISTRY_OVERRIDE_WRITE(pKmdGmmContext, Usage, NewPATCachingPolicy, UsagePATElement.Xe_LPG.L4CC);
207 REGISTRY_OVERRIDE_WRITE(pKmdGmmContext, Usage, NewPATCoherency, UsagePATElement.Xe_LPG.Coherency);
208 #endif
209 }
210 #endif
211 }
212
213
214 // Find PATIndex matching coherency value of 2 in static PAT table (1 way coherent)
215 for(k = 0; k <= CurrentMaxPATIndex; k++)
216 {
217 GMM_PRIVATE_PAT PAT = GetPrivatePATEntry(k);
218 if(UsagePATElement.Xe_LPG.L4CC == PAT.Xe_LPG.L4CC &&
219 (ONE_WAY_COHERENT == PAT.Xe_LPG.Coherency))
220 {
221 CoherentPATIdx = k;
222 break;
223 }
224 }
225 if(CoherentPATIdx == -1)
226 {
227 // redo PAT idnex mathcing with just coherency value,
228 // ignore L4 cache setting since MTL is MOCS centric and only the coherency value comes from PAT anyways, caching policy is bound to come from MOCS on MTL
229 for(k = 0; k <= CurrentMaxPATIndex; k++)
230 {
231 GMM_PRIVATE_PAT PAT = GetPrivatePATEntry(k);
232 if(ONE_WAY_COHERENT == PAT.Xe_LPG.Coherency)
233 {
234 CoherentPATIdx = k;
235 break;
236 }
237 }
238 }
239
240 if(CoherentPATIdx == -1) // no match, switch to PATIndex
241 {
242 CachePolicyError = true;
243 CoherentPATIdx = PATIdx;
244 }
245 }
246
247 pCachePolicy[Usage].PATIndex = PATIdx;
248 pCachePolicy[Usage].CoherentPATIndex = GET_COHERENT_PATINDEX_LOWER_BITS(CoherentPATIdx);
249 pCachePolicy[Usage].CoherentPATIndexHigherBit = GET_COHERENT_PATINDEX_HIGHER_BIT(CoherentPATIdx);
250 pCachePolicy[Usage].PTE.DwordValue = GMM_GET_PTE_BITS_FROM_PAT_IDX(PATIdx) & 0xFFFFFFFF;
251 pCachePolicy[Usage].PTE.HighDwordValue = GMM_GET_PTE_BITS_FROM_PAT_IDX(PATIdx) >> 32;
252 pCachePolicy[Usage].MemoryObjectOverride.XE_LPG.Index = CPTblIdx;
253 pCachePolicy[Usage].Override = ALWAYS_OVERRIDE;
254
255 if(CachePolicyError)
256 {
257 GMM_ASSERTDPF(false, "Cache Policy Init Error: Invalid Cache Programming ");
258 // add rterror here <ToDo>
259 }
260 }
261 return GMM_SUCCESS;
262 }
263
264 //=============================================================================
265 //
266 // Function: __:SetL1CachePolicy
267 //
268 // Desc: This function converting indicator values to actual register values and store into pCachePolicy to return to UMD's.
269 // Gmm not using this values. UMD's queries for this values.
270 //
271 // Parameters: Usage
272 //
273 // Return: VOID
274 //
275 //-----------------------------------------------------------------------------
SetL1CachePolicy(uint32_t Usage)276 void GmmLib::GmmXe_LPGCachePolicy::SetL1CachePolicy(uint32_t Usage)
277 {
278
279 // As per HW, L1 cache control(L1CC) values (0: WBP write bypass mode, 1: 0 uncached, 2: WB Write back, 3:WT write-through, 4: WS Write-Streaming).
280 #define L1_WBP_CACHEABLE (0x0)
281 #define L1_UNCACHEABLE (0x1)
282 #define L1_WB_CACHEABLE (0x2)
283 #define L1_WT_CACHEABLE (0x3)
284 #define L1_WS_CACHEABLE (0x4)
285
286 switch (pCachePolicy[Usage].L1CC)
287 {
288 case GMM_UC:
289 pCachePolicy[Usage].L1CC = L1_UNCACHEABLE;
290 break;
291 case GMM_WB:
292 pCachePolicy[Usage].L1CC = L1_WB_CACHEABLE;
293 break;
294 case GMM_WT:
295 pCachePolicy[Usage].L1CC = L1_WT_CACHEABLE;
296 break;
297 case GMM_WBP:
298 pCachePolicy[Usage].L1CC = L1_WBP_CACHEABLE;
299 break;
300 case GMM_WS:
301 pCachePolicy[Usage].L1CC = L1_WS_CACHEABLE;
302 break;
303 default:
304 pCachePolicy[Usage].L1CC = L1_UNCACHEABLE;
305 }
306
307 #undef L1_WBP_CACHEABLE
308 #undef L1_UNCACHEABLE
309 #undef L1_WB_CACHEABLE
310 #undef L1_WT_CACHEABLE
311 #undef L1_WS_CACHEABLE
312 }
313 /////////////////////////////////////////////////////////////////////////////////////
314 /// A simple getter function returning the PAT (cache policy) for a given
315 /// use Usage of the named resource pResInfo.
316 /// Typically used to populate PPGTT/GGTT.
317 ///
318 /// @param[in] pResInfo: Resource info for resource, can be NULL.
319 /// @param[in] Usage: Current usage for resource.
320 /// @param[Optional] Not Applicable for MTL
321 /// @param[in] Applicable for MTL
322 /// @return PATIndex
323 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetPATIndex(GMM_RESOURCE_INFO * pResInfo,GMM_RESOURCE_USAGE_TYPE Usage,bool * pCompressionEnable,bool IsCpuCacheable)324 uint32_t GMM_STDCALL GmmLib::GmmXe_LPGCachePolicy::CachePolicyGetPATIndex(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage, bool *pCompressionEnable, bool IsCpuCacheable)
325 {
326 __GMM_ASSERT(pGmmLibContext->GetCachePolicyElement(Usage).Initialized);
327 GMM_UNREFERENCED_PARAMETER(pCompressionEnable);
328
329 // Prevent wrong Usage for XAdapter resources. UMD does not call GetMemoryObject on shader resources but,
330 // when they add it someone could call it without knowing the restriction.
331 if(pResInfo &&
332 pResInfo->GetResFlags().Info.XAdapter &&
333 Usage != GMM_RESOURCE_USAGE_XADAPTER_SHARED_RESOURCE)
334 {
335 __GMM_ASSERT(false);
336 }
337
338 if(IsCpuCacheable)
339 {
340 return (uint32_t)(GET_COHERENT_PATINDEX_VALUE(pGmmLibContext, Usage));
341 }
342 else
343 {
344 return pGmmLibContext->GetCachePolicyElement(Usage).PATIndex;
345 }
346 }
347
348 //=============================================================================
349 //
350 // Function: SetUpMOCSTable
351 //
352 // Desc:
353 //
354 // Parameters:
355 //
356 // Return: GMM_STATUS
357 //
358 //-----------------------------------------------------------------------------
SetUpMOCSTable()359 void GmmLib::GmmXe_LPGCachePolicy::SetUpMOCSTable()
360 {
361 GMM_CACHE_POLICY_TBL_ELEMENT *pCachePolicyTlbElement = &(pGmmLibContext->GetCachePolicyTlbElement()[0]);
362 CurrentMaxL1HdcMocsIndex = 0;
363 CurrentMaxSpecialMocsIndex = 0;
364
365 #define L3_UC (0x1)
366 #define L3_WB (0x3)
367
368 #define L4_WB (0x0)
369 #define L4_WT (0x1)
370 #define L4_UC (0x3)
371
372 #define GMM_DEFINE_MOCS(Index, L3_LookUp, L3_Go, L3_CC, L4Caching, ignorePAT) \
373 { \
374 pCachePolicyTlbElement[Index].L3.Cacheability = L3_CC; \
375 pCachePolicyTlbElement[Index].L3.GlobalGo = L3_Go; \
376 pCachePolicyTlbElement[Index].L3.UCLookup = L3_LookUp; \
377 pCachePolicyTlbElement[Index].LeCC.Xe_LPG.L4CC = L4Caching; \
378 pCachePolicyTlbElement[Index].LeCC.Xe_LPG.igPAT = ignorePAT; \
379 }
380 // clang-format off
381
382 //Default MOCS Table
383 for(int index = 0; index < GMM_MAX_NUMBER_MOCS_INDEXES; index++)
384 { // Index LookUp Go L3CC L4CC ignorePAT
385 GMM_DEFINE_MOCS( index , 1 , 0 , L3_UC , L4_UC , 0)
386 }
387 // Fixed MOCS Table
388 // Index LookUp Go L3CC L4CC ignorePAT
389 GMM_DEFINE_MOCS( 0 , 1 , 0 , L3_WB , L4_WB , 1)
390 GMM_DEFINE_MOCS( 1 , 1 , 0 , L3_WB , L4_WB , 1)
391 GMM_DEFINE_MOCS( 2 , 1 , 0 , L3_UC , L4_WB , 1)
392 GMM_DEFINE_MOCS( 3 , 1 , 0 , L3_UC , L4_UC , 1)
393 GMM_DEFINE_MOCS( 4 , 1 , 1 , L3_UC , L4_WB , 1)
394 GMM_DEFINE_MOCS( 5 , 1 , 1 , L3_UC , L4_UC , 1)
395 GMM_DEFINE_MOCS( 6 , 0 , 0 , L3_UC , L4_WB , 1)
396 GMM_DEFINE_MOCS( 7 , 0 , 0 , L3_UC , L4_UC , 1)
397 GMM_DEFINE_MOCS( 8 , 0 , 1 , L3_UC , L4_WB , 1)
398 GMM_DEFINE_MOCS( 9 , 0 , 1 , L3_UC , L4_UC , 1)
399 //Reserved 10-13
400 GMM_DEFINE_MOCS( 14 , 1 , 0 , L3_WB , L4_WT , 1) /* Note Update GMM_CC_DISP_MOCS_INDEX*/
401 GMM_DEFINE_MOCS( 15 , 0 , 1 , L3_UC , L4_WB , 1) /* Note Update GMM_NON_CC_DISP_MOCS_INDEX */
402
403 CurrentMaxMocsIndex = 15;
404 CurrentMaxL1HdcMocsIndex = 0;
405 CurrentMaxSpecialMocsIndex = 0;
406
407 // clang-format on
408 #undef GMM_DEFINE_MOCS
409 #undef L4_WB
410 #undef L4_WT
411 #undef L4_UC
412 #undef L3_UC
413 #undef L3_WB
414 }
415
416 //=============================================================================
417 //
418 // Function: SetupPAT
419 //
420 // Desc:
421 //
422 // Parameters:
423 //
424 // Return: GMM_STATUS
425 //
426 //-----------------------------------------------------------------------------
SetupPAT()427 GMM_STATUS GmmLib::GmmXe_LPGCachePolicy::SetupPAT()
428 {
429 GMM_PRIVATE_PAT *pPATTlbElement = &(pGmmLibContext->GetPrivatePATTable()[0]);
430
431 #define L4_WB (0x0)
432 #define L4_WT (0x1)
433 #define L4_UC (0x3)
434
435 #define GMM_DEFINE_PAT_ELEMENT(indx, L4Caching, Coh) \
436 { \
437 pPATTlbElement[indx].Xe_LPG.Coherency = Coh; \
438 pPATTlbElement[indx].Xe_LPG.L4CC = L4Caching; \
439 pPATTlbElement[indx].Xe_LPG.Reserved = 0; \
440 }
441
442 // clang-format off
443
444 // Default PAT Table
445 for (uint32_t i = 0; i < NumPATRegisters; i++)
446 { // Index CachingPolicy Coherency
447 GMM_DEFINE_PAT_ELEMENT( i, L4_UC , 0 );
448 }
449
450 // Fixed PAT Table
451 // Index CachingPolicy Coherency
452 GMM_DEFINE_PAT_ELEMENT( 0 , L4_WB , 0) // PATRegValue = 0x0
453 GMM_DEFINE_PAT_ELEMENT( 1 , L4_WT , 0) // PATRegValue = 0x4
454 GMM_DEFINE_PAT_ELEMENT( 2 , L4_UC , 0) // PATRegValue = 0xC
455 GMM_DEFINE_PAT_ELEMENT( 3 , L4_WB , 2) // PATRegValue = 0x2
456 GMM_DEFINE_PAT_ELEMENT( 4 , L4_WB , 3) // PATRegValue = 0x3
457
458 CurrentMaxPATIndex = 4;
459
460 // clang-format on
461 #undef GMM_DEFINE_PAT
462 #undef L4_WB
463 #undef L4_WT
464 #undef L4_UC
465 return GMM_SUCCESS;
466 }
467
GetSurfaceStateL1CachePolicy(GMM_RESOURCE_USAGE_TYPE Usage)468 uint32_t GMM_STDCALL GmmLib::GmmXe_LPGCachePolicy::GetSurfaceStateL1CachePolicy(GMM_RESOURCE_USAGE_TYPE Usage)
469 {
470 __GMM_ASSERT(pCachePolicy[Usage].Initialized);
471
472 return pCachePolicy[Usage].L1CC;
473 }
474
475 /////////////////////////////////////////////////////////////////////////////////////
476 /// A simple getter function returning the MOCS (cache policy) for a given
477 /// use Usage of the named resource pResInfo.
478 /// Typically used to populate a SURFACE_STATE for a GPU task.
479 ///
480 /// @param[in] pResInfo: Resource info for resource, can be NULL.
481 /// @param[in] Usage: Current usage for resource.
482 ///
483 /// @return MEMORY_OBJECT_CONTROL_STATE: Gen adjusted MOCS structure (cache
484 /// policy) for the given buffer use.
485 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetMemoryObject(GMM_RESOURCE_INFO * pResInfo,GMM_RESOURCE_USAGE_TYPE Usage)486 MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmLib::GmmXe_LPGCachePolicy::CachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage)
487 {
488 __GMM_ASSERT(pCachePolicy[Usage].Initialized);
489
490 // Prevent wrong Usage for XAdapter resources. UMD does not call GetMemoryObject on shader resources but,
491 // when they add it someone could call it without knowing the restriction.
492 if (pResInfo &&
493 pResInfo->GetResFlags().Info.XAdapter &&
494 (Usage != GMM_RESOURCE_USAGE_XADAPTER_SHARED_RESOURCE))
495 {
496 __GMM_ASSERT(false);
497 }
498
499 if (!pResInfo ||
500 (pCachePolicy[Usage].Override & pCachePolicy[Usage].IDCode) ||
501 (pCachePolicy[Usage].Override == ALWAYS_OVERRIDE))
502 {
503 return pCachePolicy[Usage].MemoryObjectOverride;
504 }
505 else
506 {
507 return pCachePolicy[Usage].MemoryObjectNoOverride;
508 }
509 }
510
511