1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*==============================================================================
Copyright(c) 2017 Intel Corporation
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files(the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and / or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
============================================================================*/
#include "Internal/Common/GmmLibInc.h"
#include "External/Common/GmmCachePolicy.h"
/////////////////////////////////////////////////////////////////////////////////////
/// Constructor for the GmmCachePolicyCommon Class, initializes the CachePolicy
/// @param[in] pCachePolicy
/////////////////////////////////////////////////////////////////////////////////////
GmmLib::GmmCachePolicyCommon::GmmCachePolicyCommon(GMM_CACHE_POLICY_ELEMENT *pCachePolicy, Context *pGmmLibContext)
{
this->pCachePolicy = pCachePolicy;
this->pGmmLibContext = pGmmLibContext;
NumPATRegisters = GMM_NUM_PAT_ENTRIES_LEGACY;
NumMOCSRegisters = GMM_MAX_NUMBER_MOCS_INDEXES;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Returns the wanted memory type for this usage.
///
/// @param[in] CachePolicy: cache policy for a usage
///
/// @return wanted memory type
/////////////////////////////////////////////////////////////////////////////////////
GMM_GFX_MEMORY_TYPE GmmLib::GmmCachePolicyCommon::GetWantedMemoryType(GMM_CACHE_POLICY_ELEMENT CachePolicy)
{
GMM_GFX_MEMORY_TYPE WantedMemoryType = GMM_GFX_UC_WITH_FENCE;
if(CachePolicy.WT)
{
WantedMemoryType = GMM_GFX_WT;
}
else if(!(CachePolicy.LLC || CachePolicy.ELLC))
{
WantedMemoryType = GMM_GFX_UC_WITH_FENCE;
}
else
{
WantedMemoryType = GMM_GFX_WB;
}
return WantedMemoryType;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Generates memory object based on resource usage
///
/// @param[in] pResInfo: Resource info for resource , can be null
/// @param[in] Usage: Current usage for resource
///
/// @return MEMORY_OBJECT_CONTROL_STATE: Populated memory object
///
/////////////////////////////////////////////////////////////////////////////////////
MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmLib::GmmCachePolicyCommon::CachePolicyGetOriginalMemoryObject(GMM_RESOURCE_INFO *pResInfo)
{
MEMORY_OBJECT_CONTROL_STATE MOCS = pGmmLibContext->GetCachePolicyElement(GMM_RESOURCE_USAGE_UNKNOWN).MemoryObjectOverride;
if(pResInfo)
{
MOCS = pResInfo->GetMOCS();
}
return MOCS;
}
/////////////////////////////////////////////////////////////////////////////////////
/// A simple getter function returning the MOCS (cache policy) for a given
/// use Usage of the named resource pResInfo.
/// Typically used to populate a SURFACE_STATE for a GPU task.
///
/// @param[in] pResInfo: Resource info for resource, can be NULL.
/// @param[in] Usage: Current usage for resource.
///
/// @return MEMORY_OBJECT_CONTROL_STATE: Gen adjusted MOCS structure (cache
/// policy) for the given buffer use.
/////////////////////////////////////////////////////////////////////////////////////
MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmLib::GmmCachePolicyCommon::CachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage)
{
const GMM_CACHE_POLICY_ELEMENT *CachePolicy = NULL;
__GMM_ASSERT(pGmmLibContext->GetCachePolicyElement(Usage).Initialized);
CachePolicy = pGmmLibContext->GetCachePolicyUsage();
// Prevent wrong Usage for XAdapter resources. UMD does not call GetMemoryObject on shader resources but,
// when they add it someone could call it without knowing the restriction.
if(pResInfo &&
pResInfo->GetResFlags().Info.XAdapter &&
(Usage != GMM_RESOURCE_USAGE_XADAPTER_SHARED_RESOURCE))
{
__GMM_ASSERT(false);
}
if(!pResInfo ||
(CachePolicy[Usage].Override & CachePolicy[pResInfo->GetCachePolicyUsage()].IDCode) ||
(CachePolicy[Usage].Override == ALWAYS_OVERRIDE))
{
return CachePolicy[Usage].MemoryObjectOverride;
}
else
{
return CachePolicy[Usage].MemoryObjectNoOverride;
}
}
/////////////////////////////////////////////////////////////////////////////////////
/// A simple getter function returning the PAT (cache policy) for a given
/// use Usage of the named resource pResInfo.
/// Typically used to populate PPGTT/GGTT.
///
/// @param[in] pResInfo: Resource info for resource, can be NULL.
/// @param[in] Usage: Current usage for resource.
///
/// @return PATIndex
/////////////////////////////////////////////////////////////////////////////////////
uint32_t GMM_STDCALL GmmLib::GmmCachePolicyCommon::CachePolicyGetPATIndex(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage, bool *pCompressionEnable, bool IsCpuCacheable)
{
GMM_UNREFERENCED_PARAMETER(pResInfo);
GMM_UNREFERENCED_PARAMETER(Usage);
GMM_UNREFERENCED_PARAMETER(pCompressionEnable);
GMM_UNREFERENCED_PARAMETER(IsCpuCacheable);
return GMM_PAT_ERROR;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Generates PTE based on resource usage
///
/// @param[in] Usage: type of usage
///
/// @return GMM_PTE_CACHE_CONTROL_BITS: Populated PTE
/////////////////////////////////////////////////////////////////////////////////////
GMM_PTE_CACHE_CONTROL_BITS GMM_STDCALL GmmLib::GmmCachePolicyCommon::CachePolicyGetPteType(GMM_RESOURCE_USAGE_TYPE Usage)
{
__GMM_ASSERT(pGmmLibContext->GetCachePolicyElement(Usage).Initialized);
return pGmmLibContext->GetCachePolicyElement(Usage).PTE;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Returns number of PAT entries possible on that platform
///
/// @return uint32_t
/////////////////////////////////////////////////////////////////////////////////////
uint32_t GMM_STDCALL GmmLib::GmmCachePolicyCommon::CachePolicyGetNumPATRegisters()
{
return NumPATRegisters;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Returns L1 cache attribute based on resource usage
///
/// @return uint32_t
/////////////////////////////////////////////////////////////////////////////////////
uint32_t GMM_STDCALL GmmLib::GmmCachePolicyCommon::GetSurfaceStateL1CachePolicy(GMM_RESOURCE_USAGE_TYPE Usage)
{
__GMM_ASSERT(pCachePolicy[Usage].Initialized);
return pCachePolicy[Usage].L1CC;
}
|