| 1 |
/* Copyright (c) 2022, Intel Corporation |
| 2 |
* |
| 3 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 4 |
* copy of this software and associated documentation files (the "Software"), |
| 5 |
* to deal in the Software without restriction, including without limitation |
| 6 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 7 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 8 |
* Software is furnished to do so, subject to the following conditions: |
| 9 |
* |
| 10 |
* The above copyright notice and this permission notice shall be included |
| 11 |
* in all copies or substantial portions of the Software. |
| 12 |
* |
| 13 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 14 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 16 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 17 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 18 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 19 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
*/ |
| 21 |
//! |
| 22 |
//! \file vp_hdr_resource_manager.cpp |
| 23 |
//! \brief The source file of the extention class of vp hdr resource manager |
| 24 |
//! \details all the vp hdr resources will be traced here for usages using intermeida |
| 25 |
//! surfaces. |
| 26 |
//! |
| 27 |
|
| 28 |
#include "vp_hdr_resource_manager.h" |
| 29 |
#include "vp_allocator.h" |
| 30 |
#include "vp_hdr_filter.h" |
| 31 |
|
| 32 |
using namespace vp; |
| 33 |
|
| 34 |
VphdrResourceManager::VphdrResourceManager(VpAllocator &allocator) : m_allocator(allocator) |
| 35 |
{ |
| 36 |
VP_FUNC_CALL(); |
| 37 |
} |
| 38 |
|
| 39 |
VphdrResourceManager::~VphdrResourceManager() |
| 40 |
{ |
| 41 |
VP_FUNC_CALL(); |
| 42 |
FreeHdrRenderResource(); |
| 43 |
} |
| 44 |
|
| 45 |
MOS_STATUS VphdrResourceManager::AssignRenderResource(VP_EXECUTE_CAPS &caps, std::vector<VP_SURFACE *> &inputSurfaces, VP_SURFACE *outputSurface, RESOURCE_ASSIGNMENT_HINT resHint, |
| 46 |
VP_SURFACE_SETTING &surfSetting, SwFilterPipe &executedFilters, MOS_INTERFACE &osInterface, VphalFeatureReport &reporting, bool deferredDestroyed) |
| 47 |
{ |
| 48 |
VP_FUNC_CALL(); |
| 49 |
|
| 50 |
bool allocated = false; |
| 51 |
auto *skuTable = osInterface.pfnGetSkuTable(&osInterface); |
| 52 |
Mos_MemPool memTypeSurfVideoMem = MOS_MEMPOOL_VIDEOMEMORY; |
| 53 |
uint32_t dwWidth = 0; |
| 54 |
uint32_t dwHeight = 0; |
| 55 |
uint32_t dwDepth = 0; |
| 56 |
bool bAllocated = false; |
| 57 |
SwFilterHdr *hdr = dynamic_cast<SwFilterHdr *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeHdrOnRender)); |
| 58 |
VP_PUBLIC_CHK_NULL_RETURN(hdr); |
| 59 |
auto params = hdr->GetSwFilterParams(); |
| 60 |
MOS_ALLOC_GFXRES_PARAMS AllocParams = {}; |
| 61 |
VPHAL_GET_SURFACE_INFO Info = {}; |
| 62 |
MOS_STATUS eStatus; |
| 63 |
|
| 64 |
if (skuTable && MEDIA_IS_SKU(skuTable, FtrLimitedLMemBar)) |
| 65 |
{ |
| 66 |
memTypeSurfVideoMem = MOS_MEMPOOL_DEVICEMEMORY; |
| 67 |
} |
| 68 |
|
| 69 |
// Allocate CSC CCM Coeff Surface |
| 70 |
dwWidth = VPHAL_HDR_COEF_SURFACE_WIDTH; |
| 71 |
dwHeight = VPHAL_HDR_COEF_SURFACE_HEIGHT; |
| 72 |
|
| 73 |
surfSetting.pHDRStageConfigTable = HDRStageConfigTable; |
| 74 |
|
| 75 |
VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface( |
| 76 |
m_hdrCoeff, |
| 77 |
"HdrCoeffSurface", |
| 78 |
Format_A8R8G8B8, |
| 79 |
MOS_GFXRES_2D, |
| 80 |
MOS_TILE_LINEAR, |
| 81 |
dwWidth, |
| 82 |
dwHeight, |
| 83 |
false, |
| 84 |
MOS_MMC_DISABLED, |
| 85 |
allocated, |
| 86 |
false, |
| 87 |
deferredDestroyed, |
| 88 |
MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_RENDER)); |
| 89 |
|
| 90 |
surfSetting.coeffAllocated = allocated; |
| 91 |
surfSetting.surfGroup.emplace(SurfaceTypeHdrCoeff, m_hdrCoeff); |
| 92 |
|
| 93 |
// Allocate auto mode CSC CCM Coeff Surface |
| 94 |
VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface( |
| 95 |
m_hdrAutoModeCoeffSurface, |
| 96 |
"AutoModeCoeffSurface", |
| 97 |
Format_A8R8G8B8, |
| 98 |
MOS_GFXRES_2D, |
| 99 |
MOS_TILE_LINEAR, |
| 100 |
dwWidth, |
| 101 |
dwHeight, |
| 102 |
false, |
| 103 |
MOS_MMC_DISABLED, |
| 104 |
allocated, |
| 105 |
false, |
| 106 |
deferredDestroyed, |
| 107 |
MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_RENDER)); |
| 108 |
|
| 109 |
surfSetting.surfGroup.emplace(SurfaceTypeHdrAutoModeCoeff, m_hdrAutoModeCoeffSurface); |
| 110 |
|
| 111 |
// Allocate auto mode iir temp Surface |
| 112 |
dwWidth = VPHAL_HDR_AUTO_MODE_IIR_TEMP_SIZE; |
| 113 |
dwHeight = 1; |
| 114 |
|
| 115 |
VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface( |
| 116 |
m_hdrAutoModeIirTempSurface, |
| 117 |
"AutoModeIirTempSurface", |
| 118 |
Format_L8, |
| 119 |
MOS_GFXRES_BUFFER, |
| 120 |
MOS_TILE_LINEAR, |
| 121 |
dwWidth, |
| 122 |
dwHeight, |
| 123 |
false, |
| 124 |
MOS_MMC_DISABLED, |
| 125 |
allocated, |
| 126 |
false, |
| 127 |
deferredDestroyed, |
| 128 |
MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_RENDER)); |
| 129 |
|
| 130 |
surfSetting.surfGroup.emplace(SurfaceTypeHdrAutoModeIirTempSurface, m_hdrAutoModeIirTempSurface); |
| 131 |
|
| 132 |
// Allocate OETF 1D LUT Surface |
| 133 |
dwWidth = VPHAL_HDR_OETF_1DLUT_WIDTH; |
| 134 |
dwHeight = VPHAL_HDR_OETF_1DLUT_WIDTH; |
| 135 |
|
| 136 |
size_t cnt = MOS_MIN(inputSurfaces.size(), VPHAL_MAX_HDR_INPUT_LAYER); |
| 137 |
for (size_t i = 0; i < cnt; ++i) |
| 138 |
{ |
| 139 |
surfSetting.surfGroup.emplace((SurfaceType)(SurfaceTypeHdrInputLayer0 + i), inputSurfaces[i]); |
| 140 |
|
| 141 |
SwFilterHdr *hdr = dynamic_cast<SwFilterHdr *>(executedFilters.GetSwFilter(true, i, FeatureType::FeatureTypeHdrOnRender)); |
| 142 |
FeatureParamHdr params = {}; |
| 143 |
if (hdr) |
| 144 |
{ |
| 145 |
params = hdr->GetSwFilterParams(); |
| 146 |
} |
| 147 |
|
| 148 |
// If LUTMode is not 2D, then there is no need to allocate OETF LUT surface. |
| 149 |
// One exception is that, LUTMode is 3D, but bGpuGenerate3DLUT user feature key is set to force using GPU to generate 3D LUT. |
| 150 |
// In this case, it has to go through the full pipe first for 3D LUT generation. |
| 151 |
if ((params.lutMode != VPHAL_HDR_LUT_MODE_2D) && |
| 152 |
!(params.lutMode == VPHAL_HDR_LUT_MODE_3D && params.bGpuGenerate3DLUT)) |
| 153 |
{ |
| 154 |
continue; |
| 155 |
} |
| 156 |
|
| 157 |
VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface( |
| 158 |
m_hdrOETF1DLUTSurface[i], |
| 159 |
"OETF1DLUTSurface", |
| 160 |
Format_R16F, |
| 161 |
MOS_GFXRES_2D, |
| 162 |
MOS_TILE_LINEAR, |
| 163 |
dwWidth, |
| 164 |
dwHeight, |
| 165 |
false, |
| 166 |
MOS_MMC_DISABLED, |
| 167 |
allocated, |
| 168 |
false, |
| 169 |
deferredDestroyed, |
| 170 |
MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_RENDER)); |
| 171 |
|
| 172 |
surfSetting.OETF1DLUTAllocated = allocated; |
| 173 |
surfSetting.surfGroup.emplace((SurfaceType)(SurfaceTypeHdrOETF1DLUTSurface0 + i), m_hdrOETF1DLUTSurface[i]); |
| 174 |
} |
| 175 |
|
| 176 |
dwWidth = dwHeight = dwDepth = VPHAL_HDR_CRI_3DLUT_SIZE; |
| 177 |
for (size_t i = 0; i < VPHAL_MAX_HDR_INPUT_LAYER; ++i) |
| 178 |
{ |
| 179 |
SwFilterHdr *hdr = dynamic_cast<SwFilterHdr *>(executedFilters.GetSwFilter(true, i, FeatureType::FeatureTypeHdrOnRender)); |
| 180 |
FeatureParamHdr params = {}; |
| 181 |
if (hdr) |
| 182 |
{ |
| 183 |
params = hdr->GetSwFilterParams(); |
| 184 |
} |
| 185 |
if (params.lutMode != VPHAL_HDR_LUT_MODE_3D) |
| 186 |
{ |
| 187 |
continue; |
| 188 |
} |
| 189 |
|
| 190 |
VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface( |
| 191 |
m_hdrCri3DLUTSurface[i], |
| 192 |
"Cri3DLUTSurface", |
| 193 |
params.bGpuGenerate3DLUT ? Format_R10G10B10A2 : Format_A16B16G16R16, |
| 194 |
MOS_GFXRES_VOLUME, |
| 195 |
MOS_TILE_LINEAR, |
| 196 |
dwWidth, |
| 197 |
dwHeight, |
| 198 |
false, |
| 199 |
MOS_MMC_DISABLED, |
| 200 |
allocated, |
| 201 |
false, |
| 202 |
deferredDestroyed, |
| 203 |
MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_RENDER, |
| 204 |
MOS_TILE_UNSET_GMM, |
| 205 |
MOS_MEMPOOL_VIDEOMEMORY, |
| 206 |
false, |
| 207 |
nullptr, |
| 208 |
dwDepth)); |
| 209 |
|
| 210 |
surfSetting.Cri3DLUTAllocated = allocated; |
| 211 |
surfSetting.surfGroup.emplace((SurfaceType)(SurfaceTypeHdrCRI3DLUTSurface0 + i), m_hdrCri3DLUTSurface[i]); |
| 212 |
} |
| 213 |
|
| 214 |
surfSetting.surfGroup.emplace(SurfaceTypeHdrTarget0, outputSurface); |
| 215 |
surfSetting.dumpPostSurface = false; |
| 216 |
reporting.GetFeatures().hdrMode = params.hdrMode; |
| 217 |
|
| 218 |
return MOS_STATUS_SUCCESS; |
| 219 |
} |
| 220 |
|
| 221 |
MOS_STATUS VphdrResourceManager::FreeHdrRenderResource() |
| 222 |
{ |
| 223 |
VP_FUNC_CALL(); |
| 224 |
|
| 225 |
if (m_hdrCoeff) |
| 226 |
{ |
| 227 |
m_allocator.DestroyVpSurface(m_hdrCoeff); |
| 228 |
} |
| 229 |
|
| 230 |
if (m_hdrAutoModeCoeffSurface) |
| 231 |
{ |
| 232 |
m_allocator.DestroyVpSurface(m_hdrAutoModeCoeffSurface); |
| 233 |
} |
| 234 |
|
| 235 |
if (m_hdrAutoModeIirTempSurface) |
| 236 |
{ |
| 237 |
m_allocator.DestroyVpSurface(m_hdrAutoModeIirTempSurface); |
| 238 |
} |
| 239 |
|
| 240 |
for (uint32_t i = 0; i < VP_MAX_HDR_INPUT_LAYER; i++) |
| 241 |
{ |
| 242 |
if (m_hdrOETF1DLUTSurface[i]) |
| 243 |
{ |
| 244 |
m_allocator.DestroyVpSurface(m_hdrOETF1DLUTSurface[i]); |
| 245 |
} |
| 246 |
|
| 247 |
if (m_hdrCri3DLUTSurface[i]) |
| 248 |
{ |
| 249 |
m_allocator.DestroyVpSurface(m_hdrCri3DLUTSurface[i]); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
return MOS_STATUS_SUCCESS; |
| 254 |
} |