| 1 |
/* |
| 2 |
* Copyright (c) 2018-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 |
//! |
| 24 |
//! \file media_mem_compression.cpp |
| 25 |
//! \brief Defines the common interface for media memory compression |
| 26 |
//! \details The mmc is to handle mmc operations, |
| 27 |
//! |
| 28 |
|
| 29 |
#include "media_mem_compression.h" |
| 30 |
#include "mos_interface.h" |
| 31 |
|
| 32 |
MediaMemComp::MediaMemComp(PMOS_INTERFACE osInterface) : |
| 33 |
m_osInterface(osInterface), |
| 34 |
m_mmcEnabled(false) |
| 35 |
{ |
| 36 |
if (nullptr == m_osInterface) |
| 37 |
{ |
| 38 |
return; |
| 39 |
} |
| 40 |
MEDIA_FEATURE_TABLE *skuTable = m_osInterface->pfnGetSkuTable(m_osInterface); |
| 41 |
m_isCompSurfAllocable = m_osInterface->pfnIsCompressibelSurfaceSupported(skuTable); |
| 42 |
m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface); |
| 43 |
} |
| 44 |
|
| 45 |
MOS_STATUS MediaMemComp::InitMmcEnabled() |
| 46 |
{ |
| 47 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, m_osInterface); |
| 48 |
|
| 49 |
if (MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrE2ECompression)) |
| 50 |
{ |
| 51 |
m_mmcEnabled = IsMmcFeatureEnabled(); |
| 52 |
UpdateMmcInUseFeature(); |
| 53 |
} |
| 54 |
return MOS_STATUS_SUCCESS; |
| 55 |
} |
| 56 |
|
| 57 |
MOS_STATUS MediaMemComp::DecompressResource(PMOS_RESOURCE resource) |
| 58 |
{ |
| 59 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 60 |
|
| 61 |
if (resource) |
| 62 |
{ |
| 63 |
status = m_osInterface->pfnDecompResource(m_osInterface, resource); |
| 64 |
} |
| 65 |
|
| 66 |
return status; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
bool MediaMemComp::IsMmcFeatureEnabled() |
| 71 |
{ |
| 72 |
if (m_userSettingPtr != nullptr) |
| 73 |
{ |
| 74 |
ReadUserSetting( |
| 75 |
m_userSettingPtr, |
| 76 |
m_mmcEnabled, |
| 77 |
m_mmcEnabledKey, |
| 78 |
MediaUserSetting::Group::Device, |
| 79 |
m_bComponentMmcEnabled, |
| 80 |
true); |
| 81 |
} |
| 82 |
else |
| 83 |
{ |
| 84 |
m_mmcEnabled = m_bComponentMmcEnabled; |
| 85 |
} |
| 86 |
|
| 87 |
if (m_osInterface && m_osInterface->bNullHwIsEnabled) |
| 88 |
{ |
| 89 |
m_mmcEnabled = false; |
| 90 |
} |
| 91 |
|
| 92 |
return m_mmcEnabled; |
| 93 |
} |
| 94 |
|
| 95 |
// For VP, there is no such feature id, if need to add 1? |
| 96 |
MOS_STATUS MediaMemComp::UpdateMmcInUseFeature() |
| 97 |
{ |
| 98 |
return ReportUserSetting( |
| 99 |
m_userSettingPtr, |
| 100 |
m_mmcInUseKey, |
| 101 |
m_mmcEnabled, |
| 102 |
MediaUserSetting::Group::Device); |
| 103 |
} |
| 104 |
|
| 105 |
bool MediaMemComp::IsMmcEnabled() |
| 106 |
{ |
| 107 |
return m_mmcEnabled; |
| 108 |
} |
| 109 |
|
| 110 |
void MediaMemComp::DisableMmc() |
| 111 |
{ |
| 112 |
m_mmcEnabled = false; |
| 113 |
} |
| 114 |
|
| 115 |
bool MediaMemComp::IsCompressibelSurfaceSupported() |
| 116 |
{ |
| 117 |
return m_isCompSurfAllocable; |
| 118 |
} |
| 119 |
|
| 120 |
MOS_STATUS MediaMemComp::SetSurfaceMmcMode( |
| 121 |
PMOS_SURFACE surface) |
| 122 |
{ |
| 123 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 124 |
|
| 125 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, surface); |
| 126 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, m_osInterface); |
| 127 |
|
| 128 |
if(m_mmcEnabled) |
| 129 |
status = m_osInterface->pfnGetMemoryCompressionMode(m_osInterface, &surface->OsResource, (PMOS_MEMCOMP_STATE)&surface->CompressionMode); |
| 130 |
else |
| 131 |
surface->CompressionMode = MOS_MMC_DISABLED; |
| 132 |
|
| 133 |
return status; |
| 134 |
} |
| 135 |
|
| 136 |
MOS_STATUS MediaMemComp::SetSurfaceMmcState( |
| 137 |
PMOS_SURFACE surface) |
| 138 |
{ |
| 139 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 140 |
|
| 141 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, surface); |
| 142 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, m_osInterface); |
| 143 |
|
| 144 |
if(m_mmcEnabled) |
| 145 |
status = m_osInterface->pfnGetMemoryCompressionMode(m_osInterface, &surface->OsResource, &surface->MmcState); |
| 146 |
else |
| 147 |
surface->MmcState = MOS_MEMCOMP_DISABLED; |
| 148 |
|
| 149 |
return status; |
| 150 |
} |
| 151 |
|
| 152 |
MOS_STATUS MediaMemComp::GetSurfaceMmcState( |
| 153 |
PMOS_SURFACE surface, |
| 154 |
MOS_MEMCOMP_STATE *mmcState) |
| 155 |
{ |
| 156 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 157 |
|
| 158 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, surface); |
| 159 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, mmcState); |
| 160 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, m_osInterface); |
| 161 |
|
| 162 |
if (m_mmcEnabled) |
| 163 |
status = m_osInterface->pfnGetMemoryCompressionMode(m_osInterface, &surface->OsResource, mmcState); |
| 164 |
else |
| 165 |
*mmcState = MOS_MEMCOMP_DISABLED; |
| 166 |
|
| 167 |
return status; |
| 168 |
} |
| 169 |
|
| 170 |
MOS_STATUS MediaMemComp::GetSurfaceMmcFormat( |
| 171 |
PMOS_SURFACE surface, |
| 172 |
uint32_t *mmcFormat) |
| 173 |
{ |
| 174 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 175 |
|
| 176 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, surface); |
| 177 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, mmcFormat); |
| 178 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, m_osInterface); |
| 179 |
|
| 180 |
if (m_mmcEnabled) |
| 181 |
status = m_osInterface->pfnGetMemoryCompressionFormat(m_osInterface, &surface->OsResource, mmcFormat); |
| 182 |
else |
| 183 |
*mmcFormat = 0; |
| 184 |
|
| 185 |
return status; |
| 186 |
} |
| 187 |
|
| 188 |
MOS_STATUS MediaMemComp::GetResourceMmcFormat( |
| 189 |
PMOS_RESOURCE resource, |
| 190 |
uint32_t &mmcFormat) |
| 191 |
{ |
| 192 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 193 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, resource); |
| 194 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, m_osInterface); |
| 195 |
|
| 196 |
if (m_mmcEnabled) |
| 197 |
status = m_osInterface->pfnGetMemoryCompressionFormat(m_osInterface, resource, &mmcFormat); |
| 198 |
else |
| 199 |
mmcFormat = 0; |
| 200 |
|
| 201 |
return status; |
| 202 |
} |
| 203 |
|
| 204 |
MOS_STATUS MediaMemComp::SetSurfaceMmcFormat( |
| 205 |
PMOS_SURFACE surface) |
| 206 |
{ |
| 207 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 208 |
|
| 209 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, surface); |
| 210 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, m_osInterface); |
| 211 |
|
| 212 |
if(m_mmcEnabled) |
| 213 |
status = m_osInterface->pfnGetMemoryCompressionFormat(m_osInterface, &surface->OsResource, &surface->CompressionFormat); |
| 214 |
else |
| 215 |
surface->CompressionFormat = 0; |
| 216 |
|
| 217 |
return status; |
| 218 |
} |
| 219 |
|
| 220 |
MOS_STATUS MediaMemComp::GetResourceMmcState( |
| 221 |
PMOS_RESOURCE resource, |
| 222 |
MOS_MEMCOMP_STATE &mmcMode) |
| 223 |
{ |
| 224 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 225 |
|
| 226 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, resource); |
| 227 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_MMC, MOS_MMC_SUBCOMP_SELF, m_osInterface); |
| 228 |
//Need to Check its default value m_mmcEnable |
| 229 |
if (m_mmcEnabled) |
| 230 |
status = m_osInterface->pfnGetMemoryCompressionMode(m_osInterface, resource, &mmcMode); |
| 231 |
else |
| 232 |
mmcMode = MOS_MEMCOMP_DISABLED; |
| 233 |
|
| 234 |
return status; |
| 235 |
} |