| 1 |
/* |
| 2 |
* Copyright (c) 2011-2023, 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 |
//! \file codechal_decoder.cpp |
| 24 |
//! \brief Implements the decode interface for CodecHal. |
| 25 |
//! \details The decode interface is further sub-divided by standard, this file is for the base interface which is shared by all decode standards. |
| 26 |
//! |
| 27 |
|
| 28 |
#include "codechal_decoder.h" |
| 29 |
#include "codechal_secure_decode_interface.h" |
| 30 |
#include "mos_solo_generic.h" |
| 31 |
#include "codechal_debug.h" |
| 32 |
#include "codechal_decode_histogram.h" |
| 33 |
|
| 34 |
#ifdef _HEVC_DECODE_SUPPORTED |
| 35 |
#include "codechal_decode_hevc.h" |
| 36 |
#endif |
| 37 |
|
| 38 |
#ifdef _VP9_DECODE_SUPPORTED |
| 39 |
#include "codechal_decode_vp9.h" |
| 40 |
#endif |
| 41 |
|
| 42 |
#ifdef _HYBRID_HEVC_DECODE_SUPPORTED |
| 43 |
#include "codechal_decode_hybrid_hevc.h" |
| 44 |
#endif |
| 45 |
|
| 46 |
#ifdef _HYBRID_VP9_DECODE_SUPPORTED |
| 47 |
#include "codechal_decode_hybrid_vp9.h" |
| 48 |
#endif |
| 49 |
|
| 50 |
#ifdef _AVC_DECODE_SUPPORTED |
| 51 |
#include "codechal_decode_avc.h" |
| 52 |
#endif |
| 53 |
|
| 54 |
#ifdef _JPEG_DECODE_SUPPORTED |
| 55 |
#include "codechal_decode_jpeg.h" |
| 56 |
#endif |
| 57 |
|
| 58 |
#ifdef _VC1_DECODE_SUPPORTED |
| 59 |
#include "codechal_decode_vc1.h" |
| 60 |
#endif |
| 61 |
|
| 62 |
#ifdef _VP8_DECODE_SUPPORTED |
| 63 |
#include "codechal_decode_vp8.h" |
| 64 |
#endif |
| 65 |
|
| 66 |
#ifdef _MPEG2_DECODE_SUPPORTED |
| 67 |
#include "codechal_decode_mpeg2.h" |
| 68 |
#endif |
| 69 |
|
| 70 |
MOS_STATUS CodechalDecode::AllocateBuffer( |
| 71 |
PMOS_RESOURCE resource, |
| 72 |
uint32_t size, |
| 73 |
const char *name, |
| 74 |
bool initialize, |
| 75 |
uint8_t value, |
| 76 |
bool bPersistent) |
| 77 |
{ |
| 78 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 79 |
|
| 80 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 81 |
|
| 82 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_osInterface); |
| 83 |
CODECHAL_DECODE_CHK_NULL_RETURN(resource); |
| 84 |
|
| 85 |
MOS_ALLOC_GFXRES_PARAMS allocParams; |
| 86 |
MOS_ZeroMemory(&allocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 87 |
allocParams.Type = MOS_GFXRES_BUFFER; |
| 88 |
allocParams.TileType = MOS_TILE_LINEAR; |
| 89 |
allocParams.Format = Format_Buffer; |
| 90 |
allocParams.dwBytes = size; |
| 91 |
allocParams.pBufName = name; |
| 92 |
allocParams.bIsPersistent = bPersistent; |
| 93 |
|
| 94 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(m_osInterface->pfnAllocateResource( |
| 95 |
m_osInterface, |
| 96 |
&allocParams, |
| 97 |
resource), |
| 98 |
"Failed to allocate %s.", name); |
| 99 |
|
| 100 |
if (initialize) |
| 101 |
{ |
| 102 |
CodechalResLock ResourceLock(m_osInterface, resource); |
| 103 |
auto data = (uint8_t*)ResourceLock.Lock(CodechalResLock::writeOnly); |
| 104 |
CODECHAL_DECODE_CHK_NULL_RETURN(data); |
| 105 |
|
| 106 |
MOS_FillMemory(data, size, value); |
| 107 |
} |
| 108 |
|
| 109 |
return eStatus; |
| 110 |
} |
| 111 |
|
| 112 |
MOS_STATUS CodechalDecode::AllocateSurface( |
| 113 |
PMOS_SURFACE surface, |
| 114 |
uint32_t width, |
| 115 |
uint32_t height, |
| 116 |
const char *name, |
| 117 |
MOS_FORMAT format, |
| 118 |
bool isCompressible) |
| 119 |
{ |
| 120 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 121 |
|
| 122 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 123 |
|
| 124 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_osInterface); |
| 125 |
CODECHAL_DECODE_CHK_NULL_RETURN(surface); |
| 126 |
|
| 127 |
MOS_ALLOC_GFXRES_PARAMS allocParams; |
| 128 |
MOS_ZeroMemory(&allocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 129 |
allocParams.Type = MOS_GFXRES_2D; |
| 130 |
allocParams.TileType = MOS_TILE_Y; |
| 131 |
allocParams.Format = format; |
| 132 |
allocParams.dwWidth = width; |
| 133 |
allocParams.dwHeight = height; |
| 134 |
allocParams.dwArraySize = 1; |
| 135 |
allocParams.pBufName = name; |
| 136 |
allocParams.bIsCompressible = isCompressible; |
| 137 |
|
| 138 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(m_osInterface->pfnAllocateResource( |
| 139 |
m_osInterface, |
| 140 |
&allocParams, |
| 141 |
&surface->OsResource), |
| 142 |
"Failed to allocate %s.", name); |
| 143 |
|
| 144 |
CODECHAL_DECODE_CHK_STATUS_RETURN(CodecHalGetResourceInfo( |
| 145 |
m_osInterface, |
| 146 |
surface)); |
| 147 |
|
| 148 |
return eStatus; |
| 149 |
} |
| 150 |
|
| 151 |
MOS_STATUS CodechalDecode::HucCopy( |
| 152 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 153 |
PMOS_RESOURCE src, |
| 154 |
PMOS_RESOURCE dst, |
| 155 |
uint32_t copyLength, |
| 156 |
uint32_t copyInputOffset, |
| 157 |
uint32_t copyOutputOffset) |
| 158 |
{ |
| 159 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 160 |
|
| 161 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 162 |
|
| 163 |
CODECHAL_DECODE_CHK_NULL_RETURN(cmdBuffer); |
| 164 |
CODECHAL_DECODE_CHK_NULL_RETURN(src); |
| 165 |
CODECHAL_DECODE_CHK_NULL_RETURN(dst); |
| 166 |
|
| 167 |
CodechalHucStreamoutParams hucStreamOutParams; |
| 168 |
MOS_ZeroMemory(&hucStreamOutParams, sizeof(hucStreamOutParams)); |
| 169 |
|
| 170 |
// Ind Obj Addr command |
| 171 |
hucStreamOutParams.dataBuffer = src; |
| 172 |
hucStreamOutParams.dataSize = copyLength + copyInputOffset; |
| 173 |
hucStreamOutParams.dataOffset = MOS_ALIGN_FLOOR(copyInputOffset, MHW_PAGE_SIZE); |
| 174 |
hucStreamOutParams.streamOutObjectBuffer = dst; |
| 175 |
hucStreamOutParams.streamOutObjectSize = copyLength + copyOutputOffset; |
| 176 |
hucStreamOutParams.streamOutObjectOffset = MOS_ALIGN_FLOOR(copyOutputOffset, MHW_PAGE_SIZE); |
| 177 |
|
| 178 |
// Stream object params |
| 179 |
hucStreamOutParams.indStreamInLength = copyLength; |
| 180 |
hucStreamOutParams.inputRelativeOffset = copyInputOffset - hucStreamOutParams.dataOffset; |
| 181 |
hucStreamOutParams.outputRelativeOffset = copyOutputOffset - hucStreamOutParams.streamOutObjectOffset; |
| 182 |
|
| 183 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_hwInterface->PerformHucStreamOut( |
| 184 |
&hucStreamOutParams, |
| 185 |
cmdBuffer)); |
| 186 |
|
| 187 |
return eStatus; |
| 188 |
} |
| 189 |
|
| 190 |
uint32_t CodechalDecode::LinearToYTiledAddress( |
| 191 |
uint32_t x, |
| 192 |
uint32_t y, |
| 193 |
uint32_t pitch) |
| 194 |
{ |
| 195 |
uint32_t tileW = 128; |
| 196 |
uint32_t tileH = 32; |
| 197 |
|
| 198 |
uint32_t tileSize = tileW * tileH; |
| 199 |
|
| 200 |
uint32_t rowSize = (pitch / tileW) * tileSize; |
| 201 |
|
| 202 |
uint32_t xOffWithinTile = x % tileW; |
| 203 |
uint32_t yOffWithinTile = y % tileH; |
| 204 |
|
| 205 |
uint32_t tileNumberInX = x / tileW; |
| 206 |
uint32_t tileNumberInY = y / tileH; |
| 207 |
|
| 208 |
uint32_t tileOffset = |
| 209 |
rowSize * tileNumberInY + |
| 210 |
tileSize * tileNumberInX + |
| 211 |
tileH * 16 * (xOffWithinTile / 16) + |
| 212 |
yOffWithinTile * 16 + |
| 213 |
(xOffWithinTile % 16); |
| 214 |
|
| 215 |
return tileOffset; |
| 216 |
} |
| 217 |
|
| 218 |
CodechalDecode::CodechalDecode ( |
| 219 |
CodechalHwInterface *hwInterface, |
| 220 |
CodechalDebugInterface *debugInterface, |
| 221 |
PCODECHAL_STANDARD_INFO standardInfo): |
| 222 |
Codechal(*hwInterface, debugInterface) |
| 223 |
{ |
| 224 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 225 |
|
| 226 |
CODECHAL_PUBLIC_CHK_NULL_NO_STATUS_RETURN(hwInterface); |
| 227 |
CODECHAL_PUBLIC_CHK_NULL_NO_STATUS_RETURN(hwInterface->GetOsInterface()); |
| 228 |
MOS_UNUSED(debugInterface); |
| 229 |
|
| 230 |
m_hwInterface = hwInterface; |
| 231 |
m_osInterface = hwInterface->GetOsInterface(); |
| 232 |
|
| 233 |
if (m_hwInterface->bEnableVdboxBalancingbyUMD && m_osInterface->bEnableVdboxBalancing) |
| 234 |
{ |
| 235 |
m_hwInterface->m_getVdboxNodeByUMD = true; |
| 236 |
} |
| 237 |
m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface); |
| 238 |
|
| 239 |
#if USE_CODECHAL_DEBUG_TOOL |
| 240 |
CODECHAL_PUBLIC_CHK_NULL_NO_STATUS_RETURN(debugInterface); |
| 241 |
m_debugInterface = debugInterface; |
| 242 |
#endif // USE_CODECHAL_DEBUG_TOOL |
| 243 |
|
| 244 |
MOS_ZeroMemory(&m_dummyReference, sizeof(MOS_SURFACE)); |
| 245 |
|
| 246 |
CODECHAL_DECODE_CHK_NULL_NO_STATUS_RETURN(hwInterface); |
| 247 |
CODECHAL_DECODE_CHK_NULL_NO_STATUS_RETURN(hwInterface->GetOsInterface()); |
| 248 |
CODECHAL_DECODE_CHK_NULL_NO_STATUS_RETURN(hwInterface->GetMiInterface()); |
| 249 |
CODECHAL_DECODE_CHK_NULL_NO_STATUS_RETURN(hwInterface->GetCpInterface()); |
| 250 |
CODECHAL_DECODE_CHK_NULL_NO_STATUS_RETURN(standardInfo); |
| 251 |
|
| 252 |
m_mfxInterface = hwInterface->GetMfxInterface(); |
| 253 |
m_hcpInterface = hwInterface->GetHcpInterface(); |
| 254 |
m_hucInterface = hwInterface->GetHucInterface(); |
| 255 |
m_vdencInterface = hwInterface->GetVdencInterface(); |
| 256 |
m_miInterface = hwInterface->GetMiInterface(); |
| 257 |
m_cpInterface = hwInterface->GetCpInterface(); |
| 258 |
m_hwInterface = hwInterface; |
| 259 |
|
| 260 |
PLATFORM platform; |
| 261 |
m_osInterface->pfnGetPlatform(m_osInterface, &platform); |
| 262 |
m_waTable = m_osInterface->pfnGetWaTable(m_osInterface); |
| 263 |
CODECHAL_DECODE_CHK_NULL_NO_STATUS_RETURN(m_waTable); |
| 264 |
m_skuTable = m_osInterface->pfnGetSkuTable(m_osInterface); |
| 265 |
CODECHAL_DECODE_CHK_NULL_NO_STATUS_RETURN(m_skuTable); |
| 266 |
|
| 267 |
m_mode = standardInfo->Mode; |
| 268 |
m_isHybridDecoder = standardInfo->bIsHybridCodec ? true : false; |
| 269 |
|
| 270 |
m_pCodechalOcaDumper = MOS_New(CodechalOcaDumper); |
| 271 |
CODECHAL_DECODE_CHK_NULL_NO_STATUS_RETURN(m_pCodechalOcaDumper); |
| 272 |
|
| 273 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 274 |
AllocateDecodeOutputBuf(); |
| 275 |
#endif |
| 276 |
} |
| 277 |
|
| 278 |
MOS_STATUS CodechalDecode::SetGpuCtxCreatOption( |
| 279 |
CodechalSetting * codecHalSetting) |
| 280 |
{ |
| 281 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 282 |
|
| 283 |
MOS_UNUSED(codecHalSetting); |
| 284 |
|
| 285 |
m_gpuCtxCreatOpt = MOS_New(MOS_GPUCTX_CREATOPTIONS); |
| 286 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_gpuCtxCreatOpt); |
| 287 |
|
| 288 |
return eStatus; |
| 289 |
} |
| 290 |
|
| 291 |
MOS_STATUS CodechalDecode::CreateGpuContexts( |
| 292 |
CodechalSetting *codecHalSettings) |
| 293 |
{ |
| 294 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 295 |
|
| 296 |
CODECHAL_DECODE_CHK_NULL_RETURN(codecHalSettings); |
| 297 |
|
| 298 |
MHW_VDBOX_GPUNODE_LIMIT gpuNodeLimit; |
| 299 |
gpuNodeLimit.bHuCInUse = false; |
| 300 |
gpuNodeLimit.bHcpInUse = m_hcpInUse; |
| 301 |
gpuNodeLimit.bSfcInUse = IsSfcInUse(codecHalSettings); |
| 302 |
|
| 303 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_mfxInterface->FindGpuNodeToUse( |
| 304 |
&gpuNodeLimit)); |
| 305 |
|
| 306 |
m_videoGpuNode = (MOS_GPU_NODE)(gpuNodeLimit.dwGpuNodeToUse); |
| 307 |
|
| 308 |
CODECHAL_UPDATE_VDBOX_USER_FEATURE(m_videoGpuNode, m_osInterface->pOsContext); |
| 309 |
CodecHalDecodeMapGpuNodeToGpuContex(m_videoGpuNode, m_videoContext, false); |
| 310 |
|
| 311 |
CODECHAL_DECODE_CHK_STATUS_RETURN(SetGpuCtxCreatOption(codecHalSettings)); |
| 312 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_osInterface->pfnCreateGpuContext( |
| 313 |
m_osInterface, |
| 314 |
m_videoContext, |
| 315 |
m_videoGpuNode, |
| 316 |
m_gpuCtxCreatOpt)); |
| 317 |
|
| 318 |
// Create Video2 Context for MPEG2 WA and JPEG incomplete bitstream & VP9 / HEVC DRC support |
| 319 |
// For decode device, we use VDBOX0 always for the WA context |
| 320 |
// For AVC,VC1,VP9, use WA context for huc stream out copy |
| 321 |
if (Mos_Solo_IsInUse(m_osInterface)) |
| 322 |
{ |
| 323 |
Mos_Solo_DecodeMapGpuNodeToGpuContex(MOS_GPU_NODE_VIDEO, m_videoContextForWa, true, false); |
| 324 |
} |
| 325 |
else |
| 326 |
{ |
| 327 |
CodecHalDecodeMapGpuNodeToGpuContex(MOS_GPU_NODE_VIDEO, m_videoContextForWa, true); |
| 328 |
} |
| 329 |
|
| 330 |
MOS_GPUCTX_CREATOPTIONS_ENHANCED createOption; |
| 331 |
createOption.UsingSFC = codecHalSettings->sfcInUseHinted && codecHalSettings->downsamplingHinted |
| 332 |
&& (MEDIA_IS_SKU(m_skuTable, FtrSFCPipe)) && !(MEDIA_IS_SKU(m_skuTable, FtrDisableVDBox2SFC)); |
| 333 |
eStatus = (MOS_STATUS)m_osInterface->pfnCreateGpuContext( |
| 334 |
m_osInterface, |
| 335 |
m_videoContextForWa, |
| 336 |
MOS_GPU_NODE_VIDEO, |
| 337 |
&createOption); |
| 338 |
|
| 339 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 340 |
{ |
| 341 |
// use context Video1. It should be valid |
| 342 |
if (Mos_Solo_IsInUse(m_osInterface)) |
| 343 |
{ |
| 344 |
Mos_Solo_DecodeMapGpuNodeToGpuContex(MOS_GPU_NODE_VIDEO, m_videoContextForWa, false, false); |
| 345 |
} |
| 346 |
else |
| 347 |
{ |
| 348 |
CodecHalDecodeMapGpuNodeToGpuContex(MOS_GPU_NODE_VIDEO, m_videoContextForWa, false); |
| 349 |
} |
| 350 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_osInterface->pfnIsGpuContextValid( |
| 351 |
m_osInterface, |
| 352 |
m_videoContextForWa)); |
| 353 |
} |
| 354 |
|
| 355 |
// Do not need to create render context here, it will be created by standard specific decoder |
| 356 |
|
| 357 |
return eStatus; |
| 358 |
} |
| 359 |
|
| 360 |
// Decoder Public Interface Functions |
| 361 |
MOS_STATUS CodechalDecode::Allocate (CodechalSetting * codecHalSettings) |
| 362 |
{ |
| 363 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 364 |
|
| 365 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 366 |
|
| 367 |
CODECHAL_PUBLIC_CHK_NULL_RETURN(codecHalSettings); |
| 368 |
CODECHAL_PUBLIC_CHK_NULL_RETURN(m_hwInterface); |
| 369 |
CODECHAL_PUBLIC_CHK_NULL_RETURN(m_osInterface); |
| 370 |
|
| 371 |
MOS_TraceEvent(EVENT_CODECHAL_CREATE, |
| 372 |
EVENT_TYPE_INFO, |
| 373 |
&codecHalSettings->codecFunction, |
| 374 |
sizeof(uint32_t), |
| 375 |
nullptr, |
| 376 |
0); |
| 377 |
|
| 378 |
CODECHAL_PUBLIC_CHK_STATUS_RETURN(m_hwInterface->Initialize(codecHalSettings)); |
| 379 |
|
| 380 |
MOS_NULL_RENDERING_FLAGS nullHWAccelerationEnable; |
| 381 |
nullHWAccelerationEnable.Value = 0; |
| 382 |
|
| 383 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 384 |
if (!m_statusReportDebugInterface) |
| 385 |
{ |
| 386 |
m_statusReportDebugInterface = MOS_New(CodechalDebugInterface); |
| 387 |
CODECHAL_PUBLIC_CHK_NULL_RETURN(m_statusReportDebugInterface); |
| 388 |
CODECHAL_PUBLIC_CHK_STATUS_RETURN( |
| 389 |
m_statusReportDebugInterface->Initialize(m_hwInterface, codecHalSettings->codecFunction)); |
| 390 |
} |
| 391 |
|
| 392 |
ReadUserSettingForDebug( |
| 393 |
m_userSettingPtr, |
| 394 |
nullHWAccelerationEnable.Value, |
| 395 |
__MEDIA_USER_FEATURE_VALUE_NULL_HW_ACCELERATION_ENABLE, |
| 396 |
MediaUserSetting::Group::Device); |
| 397 |
|
| 398 |
m_useNullHw[MOS_GPU_CONTEXT_VIDEO] = |
| 399 |
(nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVideo); |
| 400 |
m_useNullHw[MOS_GPU_CONTEXT_VIDEO2] = |
| 401 |
(nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVideo2); |
| 402 |
m_useNullHw[MOS_GPU_CONTEXT_VIDEO3] = |
| 403 |
(nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVideo3); |
| 404 |
m_useNullHw[MOS_GPU_CONTEXT_VDBOX2_VIDEO] = |
| 405 |
(nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVDBox2Video); |
| 406 |
m_useNullHw[MOS_GPU_CONTEXT_VDBOX2_VIDEO2] = |
| 407 |
(nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVDBox2Video2); |
| 408 |
m_useNullHw[MOS_GPU_CONTEXT_VDBOX2_VIDEO3] = |
| 409 |
(nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVDBox2Video3); |
| 410 |
m_useNullHw[MOS_GPU_CONTEXT_RENDER] = |
| 411 |
(nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxRender); |
| 412 |
m_useNullHw[MOS_GPU_CONTEXT_RENDER2] = |
| 413 |
(nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxRender2); |
| 414 |
#endif // _DEBUG || _RELEASE_INTERNAL |
| 415 |
|
| 416 |
m_standard = codecHalSettings->standard; |
| 417 |
m_mode = codecHalSettings->mode; |
| 418 |
m_disableDecodeSyncLock = codecHalSettings->disableDecodeSyncLock ? true : false; |
| 419 |
m_disableLockForTranscode = MEDIA_IS_WA(m_waTable, WaDisableLockForTranscodePerf); |
| 420 |
|
| 421 |
// register cp params via codechal_Setting |
| 422 |
m_cpInterface->RegisterParams(codecHalSettings->GetCpParams()); |
| 423 |
|
| 424 |
{ |
| 425 |
MOS_USER_FEATURE_VALUE_DATA userFeatureData; |
| 426 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 427 |
userFeatureData.u32Data = MOS_STATUS_REPORT_DEFAULT; |
| 428 |
userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE; |
| 429 |
MOS_UserFeature_ReadValue_ID( |
| 430 |
nullptr, |
| 431 |
__MEDIA_USER_FEATURE_VALUE_STATUS_REPORTING_ENABLE_ID, |
| 432 |
&userFeatureData, |
| 433 |
m_osInterface->pOsContext); |
| 434 |
m_statusQueryReportingEnabled = (userFeatureData.u32Data) ? true : false; |
| 435 |
|
| 436 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 437 |
if (m_statusQueryReportingEnabled) |
| 438 |
{ |
| 439 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 440 |
MOS_UserFeature_ReadValue_ID( |
| 441 |
nullptr, |
| 442 |
__MEDIA_USER_FEATURE_VALUE_STREAM_OUT_ENABLE_ID, |
| 443 |
&userFeatureData, |
| 444 |
m_osInterface->pOsContext); |
| 445 |
m_streamOutEnabled = (userFeatureData.u32Data) ? true : false; |
| 446 |
|
| 447 |
} |
| 448 |
|
| 449 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 450 |
MOS_UserFeature_ReadValue_ID( |
| 451 |
nullptr, |
| 452 |
__MEDIA_USER_FEATURE_VALUE_PERF_PROFILER_FE_BE_TIMING, |
| 453 |
&userFeatureData, |
| 454 |
m_osInterface->pOsContext); |
| 455 |
m_perfFEBETimingEnabled = userFeatureData.bData; |
| 456 |
|
| 457 |
#endif // _DEBUG || _RELEASE_INTERNAL |
| 458 |
} |
| 459 |
|
| 460 |
// Set decoder running flag to OS context so that VPP driver can query this flag and use |
| 461 |
// this flag to decide if disable VPP DNDI feature in VEBOX for power saving. |
| 462 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_osInterface->pfnSetHybridDecoderRunningFlag( |
| 463 |
m_osInterface, |
| 464 |
m_isHybridDecoder)); |
| 465 |
|
| 466 |
// eStatus Query reporting |
| 467 |
if (m_statusQueryReportingEnabled) |
| 468 |
{ |
| 469 |
uint32_t statusBufferSize = sizeof(CodechalDecodeStatus) * CODECHAL_DECODE_STATUS_NUM + sizeof(uint32_t) * 2; |
| 470 |
|
| 471 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(AllocateBuffer( |
| 472 |
&m_decodeStatusBuf.m_statusBuffer, |
| 473 |
statusBufferSize, |
| 474 |
"StatusQueryBuffer"), |
| 475 |
"Failed to allocate decode eStatus buffer."); |
| 476 |
|
| 477 |
MOS_LOCK_PARAMS lockFlagsNoOverWrite; |
| 478 |
MOS_ZeroMemory(&lockFlagsNoOverWrite, sizeof(MOS_LOCK_PARAMS)); |
| 479 |
lockFlagsNoOverWrite.WriteOnly = 1; |
| 480 |
lockFlagsNoOverWrite.NoOverWrite = 1; |
| 481 |
|
| 482 |
uint8_t *data = (uint8_t *)m_osInterface->pfnLockResource( |
| 483 |
m_osInterface, |
| 484 |
&m_decodeStatusBuf.m_statusBuffer, |
| 485 |
&lockFlagsNoOverWrite); |
| 486 |
|
| 487 |
CODECHAL_DECODE_CHK_NULL_RETURN(data); |
| 488 |
MOS_ZeroMemory(data, statusBufferSize); |
| 489 |
m_decodeStatusBuf.m_data = (uint32_t *)data; |
| 490 |
m_decodeStatusBuf.m_decodeStatus = (CodechalDecodeStatus *)(data + sizeof(uint32_t) * 2); |
| 491 |
m_decodeStatusBuf.m_currIndex = 0; |
| 492 |
m_decodeStatusBuf.m_firstIndex = 0; |
| 493 |
m_decodeStatusBuf.m_swStoreData = 1; |
| 494 |
|
| 495 |
m_decodeStatusBuf.m_storeDataOffset = 0; |
| 496 |
m_decodeStatusBuf.m_decErrorStatusOffset = CODECHAL_OFFSETOF(CodechalDecodeStatus, m_mmioErrorStatusReg); |
| 497 |
m_decodeStatusBuf.m_decFrameCrcOffset = CODECHAL_OFFSETOF(CodechalDecodeStatus, m_mmioFrameCrcReg); |
| 498 |
m_decodeStatusBuf.m_decMBCountOffset = CODECHAL_OFFSETOF(CodechalDecodeStatus, m_mmioMBCountReg); |
| 499 |
m_decodeStatusBuf.m_csEngineIdOffset = CODECHAL_OFFSETOF(CodechalDecodeStatus, m_mmioCsEngineIdReg); |
| 500 |
m_decodeStatusBuf.m_hucErrorStatus2MaskOffset = CODECHAL_OFFSETOF(CodechalDecodeStatus, m_hucErrorStatus2); |
| 501 |
m_decodeStatusBuf.m_hucErrorStatus2RegOffset = CODECHAL_OFFSETOF(CodechalDecodeStatus, m_hucErrorStatus2) + sizeof(uint32_t); |
| 502 |
m_decodeStatusBuf.m_hucErrorStatusMaskOffset = CODECHAL_OFFSETOF(CodechalDecodeStatus, m_hucErrorStatus); |
| 503 |
m_decodeStatusBuf.m_hucErrorStatusRegOffset = CODECHAL_OFFSETOF(CodechalDecodeStatus, m_hucErrorStatus) + sizeof(uint32_t); |
| 504 |
|
| 505 |
// Set IMEM Loaded bit (in DW1) to 1 by default in the first status buffer |
| 506 |
// Set None Critical Error bit to 1 by default in the first status buffer |
| 507 |
// These bits will be changed later after storing register |
| 508 |
if (m_hucInterface) |
| 509 |
{ |
| 510 |
m_decodeStatusBuf.m_decodeStatus->m_hucErrorStatus = (uint64_t)m_hucInterface->GetHucStatusHevcS2lFailureMask() << 32; |
| 511 |
m_decodeStatusBuf.m_decodeStatus->m_hucErrorStatus2 = (uint64_t)m_hucInterface->GetHucStatus2ImemLoadedMask() << 32; |
| 512 |
} |
| 513 |
|
| 514 |
//if kernels are used update the media state heap with status pointers to keep track of when buffers are done |
| 515 |
if (m_hwInterface->GetRenderInterface() != nullptr && |
| 516 |
m_hwInterface->GetRenderInterface()->m_stateHeapInterface != nullptr) |
| 517 |
{ |
| 518 |
PMHW_STATE_HEAP_INTERFACE pStateHeapInterface = |
| 519 |
m_hwInterface->GetRenderInterface()->m_stateHeapInterface; |
| 520 |
|
| 521 |
CODECHAL_DECODE_CHK_STATUS_RETURN(pStateHeapInterface->pfnSetCmdBufStatusPtr( |
| 522 |
pStateHeapInterface, |
| 523 |
m_decodeStatusBuf.m_data)); |
| 524 |
} |
| 525 |
|
| 526 |
// StreamOut Buffer Allocation |
| 527 |
if (m_streamOutEnabled) |
| 528 |
{ |
| 529 |
uint32_t numMacroblocks = |
| 530 |
(codecHalSettings->height / CODECHAL_MACROBLOCK_HEIGHT) * |
| 531 |
(codecHalSettings->width / CODECHAL_MACROBLOCK_WIDTH); |
| 532 |
uint32_t streamOutBufSize = MOS_ALIGN_CEIL(numMacroblocks * CODEC_SIZE_MFX_STREAMOUT_DATA, 64); |
| 533 |
|
| 534 |
m_streamOutCurrBufIdx = 0; |
| 535 |
|
| 536 |
for (auto i = 0; i < CODECHAL_DECODE_NUM_STREAM_OUT_BUFFERS; i++) |
| 537 |
{ |
| 538 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(AllocateBuffer( |
| 539 |
&(m_streamOutBuffer[i]), |
| 540 |
streamOutBufSize, |
| 541 |
"StreamOutBuffer", |
| 542 |
true, |
| 543 |
0), |
| 544 |
"Failed to allocate streamout buffer."); |
| 545 |
|
| 546 |
m_streamOutCurrStatusIdx[i] = CODECHAL_DECODE_STATUS_NUM; |
| 547 |
} |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(AllocateBuffer( |
| 552 |
&m_predicationBuffer, |
| 553 |
sizeof(uint32_t), |
| 554 |
"PredicationBuffer", |
| 555 |
true, |
| 556 |
0), |
| 557 |
"Failed to allocate predication buffer."); |
| 558 |
|
| 559 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(AllocateBuffer( |
| 560 |
&m_frameCountTypeBuf, |
| 561 |
sizeof(uint32_t), |
| 562 |
"FrameCountBuffer", |
| 563 |
true, |
| 564 |
0), |
| 565 |
"Failed to allocate FrameCountBuffer buffer."); |
| 566 |
|
| 567 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(AllocateBuffer( |
| 568 |
&m_crcBuf, |
| 569 |
sizeof(uint32_t), |
| 570 |
"crcBuffer", |
| 571 |
true, |
| 572 |
0), |
| 573 |
"Failed to allocate crcBuffer"); |
| 574 |
|
| 575 |
CODECHAL_DECODE_CHK_STATUS_RETURN(AllocateStandard(codecHalSettings)); |
| 576 |
|
| 577 |
if(!m_isHybridDecoder) |
| 578 |
{ |
| 579 |
// Create Video Contexts |
| 580 |
CODECHAL_DECODE_CHK_STATUS_RETURN(CreateGpuContexts(codecHalSettings)); |
| 581 |
// Set Vdbox index in use |
| 582 |
m_vdboxIndex = (m_videoGpuNode == MOS_GPU_NODE_VIDEO2)? MHW_VDBOX_NODE_2 : MHW_VDBOX_NODE_1; |
| 583 |
|
| 584 |
// Set FrameCrc reg offset |
| 585 |
if (m_standard == CODECHAL_HEVC || m_standard == CODECHAL_VP9) |
| 586 |
{ |
| 587 |
m_hcpFrameCrcRegOffset = m_hcpInterface->GetMmioRegisters(m_vdboxIndex)->hcpFrameCrcRegOffset; |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
if (!m_mmc) |
| 592 |
{ |
| 593 |
m_mmc = MOS_New(CodecHalMmcState, m_hwInterface); |
| 594 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_mmc); |
| 595 |
} |
| 596 |
|
| 597 |
if (codecHalSettings->secureMode) |
| 598 |
{ |
| 599 |
m_secureDecoder = m_osInterface->pfnCreateSecureDecodeInterface(codecHalSettings, m_hwInterface); |
| 600 |
} |
| 601 |
|
| 602 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 603 |
m_downsamplingHinted = codecHalSettings->downsamplingHinted ? true : false; |
| 604 |
if (CodecHalIsEnableFieldScaling(codecHalSettings->codecFunction, m_standard, m_downsamplingHinted)) |
| 605 |
{ |
| 606 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_fieldScalingInterface); |
| 607 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_fieldScalingInterface->InitializeKernelState( |
| 608 |
this, |
| 609 |
m_hwInterface, |
| 610 |
m_osInterface)); |
| 611 |
} |
| 612 |
#endif |
| 613 |
|
| 614 |
m_renderContextUsesNullHw = m_useNullHw[m_renderContext]; |
| 615 |
if(!m_isHybridDecoder) |
| 616 |
{ |
| 617 |
m_videoContextUsesNullHw = m_useNullHw[m_videoContext]; |
| 618 |
m_videoContextForWaUsesNullHw = m_useNullHw[m_videoContextForWa]; |
| 619 |
|
| 620 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_osInterface->pfnRegisterBBCompleteNotifyEvent( |
| 621 |
m_osInterface, |
| 622 |
m_videoContext)); |
| 623 |
} |
| 624 |
|
| 625 |
if (!m_perfProfiler) |
| 626 |
{ |
| 627 |
m_perfProfiler = MediaPerfProfiler::Instance(); |
| 628 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_perfProfiler); |
| 629 |
|
| 630 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_perfProfiler->Initialize((void*)this, m_osInterface)); |
| 631 |
} |
| 632 |
|
| 633 |
return eStatus; |
| 634 |
} |
| 635 |
|
| 636 |
MOS_STATUS CodechalDecode::AllocateRefSurfaces( |
| 637 |
uint32_t allocWidth, |
| 638 |
uint32_t allocHeight, |
| 639 |
MOS_FORMAT format) |
| 640 |
{ |
| 641 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 642 |
|
| 643 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 644 |
|
| 645 |
if (allocWidth == 0 || allocHeight == 0) |
| 646 |
{ |
| 647 |
CODECHAL_DECODE_ASSERTMESSAGE("Invalid Downsampling Reference Frame Width or Height !"); |
| 648 |
return MOS_STATUS_INVALID_PARAMETER; |
| 649 |
} |
| 650 |
|
| 651 |
m_refSurfaces = (MOS_SURFACE*)MOS_AllocAndZeroMemory(sizeof(MOS_SURFACE) * m_refFrmCnt); |
| 652 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_refSurfaces); |
| 653 |
|
| 654 |
CODECHAL_DEBUG_TOOL( |
| 655 |
m_downsampledSurfaces = (MOS_SURFACE*)MOS_AllocAndZeroMemory(m_refFrmCnt * sizeof(MOS_SURFACE)); |
| 656 |
) |
| 657 |
|
| 658 |
for (uint32_t i = 0; i < m_refFrmCnt; i++) |
| 659 |
{ |
| 660 |
eStatus = AllocateSurface( |
| 661 |
&m_refSurfaces[i], |
| 662 |
allocWidth, |
| 663 |
allocHeight, |
| 664 |
"DownsamplingRefSurface", |
| 665 |
format, |
| 666 |
m_mmc->IsMmcEnabled()); |
| 667 |
|
| 668 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 669 |
{ |
| 670 |
CODECHAL_DECODE_ASSERTMESSAGE("Failed to allocate decode downsampling reference surface."); |
| 671 |
DeallocateRefSurfaces(); |
| 672 |
return eStatus; |
| 673 |
} |
| 674 |
} |
| 675 |
|
| 676 |
return MOS_STATUS_SUCCESS; |
| 677 |
} |
| 678 |
|
| 679 |
bool CodechalDecode::isSyncFreeNeededForMMCSurface(PMOS_SURFACE surface) |
| 680 |
{ |
| 681 |
if (nullptr == surface || nullptr == m_osInterface) |
| 682 |
{ |
| 683 |
return false; |
| 684 |
} |
| 685 |
//Compressed surface aux table update is after resource dealloction, aux table update need wait the WLs complete |
| 686 |
//the sync deallocation flag will make sure deallocation API return after all surface related WL been completed and resource been destroyed by OS |
| 687 |
auto *pSkuTable = m_hwInterface->GetSkuTable(); |
| 688 |
GMM_RESOURCE_FLAG gmmFlags; |
| 689 |
bool hasAuxSurf = false; |
| 690 |
gmmFlags = (&surface->OsResource)->pGmmResInfo->GetResFlags(); |
| 691 |
hasAuxSurf = (gmmFlags.Gpu.CCS || gmmFlags.Info.MediaCompressed) && gmmFlags.Gpu.UnifiedAuxSurface; |
| 692 |
|
| 693 |
if (pSkuTable && |
| 694 |
MEDIA_IS_SKU(pSkuTable, FtrE2ECompression) && //Compression enabled platform |
| 695 |
!MEDIA_IS_SKU(pSkuTable, FtrFlatPhysCCS) && //NOT DGPU compression |
| 696 |
(surface->bCompressible) && ((surface->CompressionMode != MOS_MMC_DISABLED) || hasAuxSurf)) //Compressed enabled surface |
| 697 |
{ |
| 698 |
return true; |
| 699 |
} |
| 700 |
|
| 701 |
return false; |
| 702 |
} |
| 703 |
|
| 704 |
MOS_STATUS CodechalDecode::DestroySurface(PMOS_SURFACE surface) |
| 705 |
{ |
| 706 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 707 |
MOS_GFXRES_FREE_FLAGS resFreeFlags = {0}; |
| 708 |
|
| 709 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 710 |
|
| 711 |
if (nullptr == surface) |
| 712 |
{ |
| 713 |
return MOS_STATUS_SUCCESS; |
| 714 |
} |
| 715 |
|
| 716 |
if (surface && isSyncFreeNeededForMMCSurface(surface)) |
| 717 |
{ |
| 718 |
resFreeFlags.SynchronousDestroy = 1; |
| 719 |
CODECHAL_DECODE_NORMALMESSAGE("Set SynchronousDestroy flag for compressed resource\n"); |
| 720 |
} |
| 721 |
|
| 722 |
m_osInterface->pfnFreeResourceWithFlag(m_osInterface, &surface->OsResource, resFreeFlags.Value); |
| 723 |
surface = nullptr; |
| 724 |
|
| 725 |
return eStatus; |
| 726 |
} |
| 727 |
|
| 728 |
MOS_STATUS CodechalDecode::RefSurfacesResize( |
| 729 |
uint32_t frameIdx, |
| 730 |
uint32_t width, |
| 731 |
uint32_t height, |
| 732 |
MOS_FORMAT format) |
| 733 |
{ |
| 734 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 735 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 736 |
|
| 737 |
if (m_refSurfaces[frameIdx].dwWidth == 0 || m_refSurfaces[frameIdx].dwHeight == 0) |
| 738 |
{ |
| 739 |
CODECHAL_DECODE_ASSERTMESSAGE("Invalid Downsampling Reference Frame Width or Height !"); |
| 740 |
return MOS_STATUS_INVALID_PARAMETER; |
| 741 |
} |
| 742 |
|
| 743 |
DeallocateSpecificRefSurfaces(frameIdx); |
| 744 |
|
| 745 |
eStatus = AllocateSurface( |
| 746 |
&m_refSurfaces[frameIdx], |
| 747 |
width, |
| 748 |
height, |
| 749 |
"DownsamplingRefSurface", |
| 750 |
format, |
| 751 |
m_mmc->IsMmcEnabled()); |
| 752 |
|
| 753 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 754 |
{ |
| 755 |
CODECHAL_DECODE_ASSERTMESSAGE("Failed to allocate decode downsampling reference surface."); |
| 756 |
DeallocateRefSurfaces(); |
| 757 |
return eStatus; |
| 758 |
} |
| 759 |
|
| 760 |
return MOS_STATUS_SUCCESS; |
| 761 |
} |
| 762 |
|
| 763 |
void CodechalDecode::DeallocateSpecificRefSurfaces(uint32_t frameIdx) |
| 764 |
{ |
| 765 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 766 |
|
| 767 |
if (m_refSurfaces != nullptr) |
| 768 |
{ |
| 769 |
if (!Mos_ResourceIsNull(&m_refSurfaces[frameIdx].OsResource)) |
| 770 |
{ |
| 771 |
DestroySurface(&m_refSurfaces[frameIdx]); |
| 772 |
} |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
void CodechalDecode::DeallocateRefSurfaces() |
| 777 |
{ |
| 778 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 779 |
|
| 780 |
if (m_refSurfaces != nullptr && m_refFrmCnt != 0) |
| 781 |
{ |
| 782 |
CODECHAL_DEBUG_TOOL( |
| 783 |
MOS_FreeMemAndSetNull(m_downsampledSurfaces); |
| 784 |
) |
| 785 |
|
| 786 |
for (uint32_t i = 0; i < m_refFrmCnt; i++) |
| 787 |
{ |
| 788 |
if (!Mos_ResourceIsNull(&m_refSurfaces[i].OsResource)) |
| 789 |
{ |
| 790 |
DestroySurface(&m_refSurfaces[i]); |
| 791 |
|
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
MOS_FreeMemory(m_refSurfaces); |
| 796 |
m_refSurfaces = nullptr; |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
MOS_STATUS CodechalDecode::SetDummyReference() |
| 801 |
{ |
| 802 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 803 |
|
| 804 |
if (MEDIA_IS_WA(m_waTable, WaDummyReference)) |
| 805 |
{ |
| 806 |
// If can't find valid dummy reference, create one or use current decode output surface |
| 807 |
if (Mos_ResourceIsNull(&m_dummyReference.OsResource)) |
| 808 |
{ |
| 809 |
// If MMC enabled |
| 810 |
if (m_mmc != nullptr && m_mmc->IsMmcEnabled() && |
| 811 |
!m_mmc->IsMmcExtensionEnabled() && |
| 812 |
m_decodeParams.m_destSurface->bIsCompressed) |
| 813 |
{ |
| 814 |
if (m_mode == CODECHAL_DECODE_MODE_HEVCVLD) |
| 815 |
{ |
| 816 |
eStatus = AllocateSurface( |
| 817 |
&m_dummyReference, |
| 818 |
m_decodeParams.m_destSurface->dwWidth, |
| 819 |
m_decodeParams.m_destSurface->dwHeight, |
| 820 |
"dummy reference resource", |
| 821 |
m_decodeParams.m_destSurface->Format, |
| 822 |
m_decodeParams.m_destSurface->bIsCompressed); |
| 823 |
|
| 824 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 825 |
{ |
| 826 |
CODECHAL_DECODE_ASSERTMESSAGE("Failed to create dummy reference!"); |
| 827 |
return eStatus; |
| 828 |
} |
| 829 |
else |
| 830 |
{ |
| 831 |
m_dummyReferenceStatus = CODECHAL_DUMMY_REFERENCE_ALLOCATED; |
| 832 |
CODECHAL_DECODE_VERBOSEMESSAGE("Dummy reference is created!"); |
| 833 |
} |
| 834 |
} |
| 835 |
} |
| 836 |
else // Use decode output surface as dummy reference |
| 837 |
{ |
| 838 |
m_dummyReference.OsResource = m_decodeParams.m_destSurface->OsResource; |
| 839 |
m_dummyReferenceStatus = CODECHAL_DUMMY_REFERENCE_DEST_SURFACE; |
| 840 |
} |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
return eStatus; |
| 845 |
} |
| 846 |
|
| 847 |
CodechalDecode::~CodechalDecode() |
| 848 |
{ |
| 849 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 850 |
|
| 851 |
if (m_osInterface) |
| 852 |
{ |
| 853 |
m_osInterface->pfnDeleteSecureDecodeInterface(m_secureDecoder); |
| 854 |
m_secureDecoder = nullptr; |
| 855 |
} |
| 856 |
else |
| 857 |
{ |
| 858 |
CODECHAL_DECODE_ASSERTMESSAGE("Failed to destroy secureDecoder."); |
| 859 |
} |
| 860 |
|
| 861 |
if (m_mmc) |
| 862 |
{ |
| 863 |
MOS_Delete(m_mmc); |
| 864 |
m_mmc = nullptr; |
| 865 |
} |
| 866 |
|
| 867 |
// Destroy decode histogram |
| 868 |
if (m_decodeHistogram != nullptr) |
| 869 |
{ |
| 870 |
MOS_Delete(m_decodeHistogram); |
| 871 |
m_decodeHistogram = nullptr; |
| 872 |
} |
| 873 |
if (m_decodeOutputBuf != nullptr) |
| 874 |
{ |
| 875 |
MOS_DeleteArray(m_decodeOutputBuf); |
| 876 |
m_decodeOutputBuf = nullptr; |
| 877 |
} |
| 878 |
if (MEDIA_IS_SKU(m_skuTable, FtrVcs2) && (m_videoGpuNode < MOS_GPU_NODE_MAX)) |
| 879 |
{ |
| 880 |
// Destroy decode video node association |
| 881 |
if (m_osInterface) |
| 882 |
{ |
| 883 |
m_osInterface->pfnDestroyVideoNodeAssociation(m_osInterface, m_videoGpuNode); |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
if (m_statusQueryReportingEnabled && m_osInterface) |
| 888 |
{ |
| 889 |
m_osInterface->pfnUnlockResource( |
| 890 |
m_osInterface, |
| 891 |
&(m_decodeStatusBuf.m_statusBuffer)); |
| 892 |
|
| 893 |
m_osInterface->pfnFreeResource( |
| 894 |
m_osInterface, |
| 895 |
&(m_decodeStatusBuf.m_statusBuffer)); |
| 896 |
|
| 897 |
if (m_streamOutEnabled) |
| 898 |
{ |
| 899 |
for (auto i = 0; i < CODECHAL_DECODE_NUM_STREAM_OUT_BUFFERS; i++) |
| 900 |
{ |
| 901 |
m_osInterface->pfnFreeResource( |
| 902 |
m_osInterface, |
| 903 |
&(m_streamOutBuffer[i])); |
| 904 |
} |
| 905 |
} |
| 906 |
} |
| 907 |
|
| 908 |
if (m_gpuCtxCreatOpt) |
| 909 |
{ |
| 910 |
MOS_Delete(m_gpuCtxCreatOpt); |
| 911 |
} |
| 912 |
|
| 913 |
if (m_osInterface) |
| 914 |
{ |
| 915 |
m_osInterface->pfnFreeResource( |
| 916 |
m_osInterface, |
| 917 |
&m_predicationBuffer); |
| 918 |
|
| 919 |
m_osInterface->pfnFreeResource( |
| 920 |
m_osInterface, |
| 921 |
&m_frameCountTypeBuf); |
| 922 |
|
| 923 |
m_osInterface->pfnFreeResource( |
| 924 |
m_osInterface, |
| 925 |
&m_crcBuf); |
| 926 |
} |
| 927 |
|
| 928 |
if (m_pCodechalOcaDumper) |
| 929 |
{ |
| 930 |
MOS_Delete(m_pCodechalOcaDumper); |
| 931 |
} |
| 932 |
|
| 933 |
#if (_DEBUG || _RELEASE_INTERNAL) && (!WDDM_LINUX) |
| 934 |
m_debugInterface->PackGoldenReferences({m_debugInterface->GetCrcGoldenReference()}); |
| 935 |
m_debugInterface->DumpGoldenReference(); |
| 936 |
#endif |
| 937 |
|
| 938 |
DeallocateRefSurfaces(); |
| 939 |
|
| 940 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 941 |
if (CodecHalIsEnableFieldScaling(CODECHAL_FUNCTION_DECODE, m_standard, m_downsamplingHinted)) |
| 942 |
{ |
| 943 |
if (m_fieldScalingInterface != nullptr) |
| 944 |
{ |
| 945 |
MOS_Delete(m_fieldScalingInterface); |
| 946 |
m_fieldScalingInterface = nullptr; |
| 947 |
} |
| 948 |
} |
| 949 |
#endif |
| 950 |
|
| 951 |
if (m_perfProfiler) |
| 952 |
{ |
| 953 |
MediaPerfProfiler::Destroy(m_perfProfiler, (void*)this, m_osInterface); |
| 954 |
m_perfProfiler = nullptr; |
| 955 |
} |
| 956 |
|
| 957 |
if (m_dummyReferenceStatus == CODECHAL_DUMMY_REFERENCE_ALLOCATED && |
| 958 |
!Mos_ResourceIsNull(&m_dummyReference.OsResource) && |
| 959 |
m_osInterface) |
| 960 |
{ |
| 961 |
m_osInterface->pfnFreeResource(m_osInterface, &m_dummyReference.OsResource); |
| 962 |
} |
| 963 |
|
| 964 |
if (m_hwInterface) |
| 965 |
{ |
| 966 |
MOS_Delete(m_hwInterface); |
| 967 |
Codechal::m_hwInterface = nullptr; |
| 968 |
} |
| 969 |
} |
| 970 |
|
| 971 |
void CodechalDecode::CalcRequestedSpace( |
| 972 |
uint32_t &requestedSize, |
| 973 |
uint32_t &additionalSizeNeeded, |
| 974 |
uint32_t &requestedPatchListSize) |
| 975 |
{ |
| 976 |
requestedSize = m_commandBufferSizeNeeded + |
| 977 |
(m_standardDecodeSizeNeeded * (m_decodeParams.m_numSlices + 1)); |
| 978 |
requestedPatchListSize = m_commandPatchListSizeNeeded + |
| 979 |
(m_standardDecodePatchListSizeNeeded * (m_decodeParams.m_numSlices + 1)); |
| 980 |
additionalSizeNeeded = COMMAND_BUFFER_RESERVED_SPACE; |
| 981 |
} |
| 982 |
|
| 983 |
MOS_STATUS CodechalDecode::VerifySpaceAvailable () |
| 984 |
{ |
| 985 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 986 |
|
| 987 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 988 |
|
| 989 |
uint32_t requestedSize = 0, additionalSizeNeeded = 0, requestedPatchListSize = 0; |
| 990 |
CalcRequestedSpace(requestedSize, additionalSizeNeeded, requestedPatchListSize); |
| 991 |
|
| 992 |
uint32_t primRequestedSize = RequestedSpaceSize(requestedSize); |
| 993 |
|
| 994 |
// Try a maximum of 3 attempts to request the required sizes from OS |
| 995 |
// OS could reset the sizes if necessary, therefore, requires to re-verify |
| 996 |
for (auto i = 0; i < 3; i++) |
| 997 |
{ |
| 998 |
if (m_osInterface->bUsesPatchList || MEDIA_IS_SKU(m_skuTable, FtrMediaPatchless)) |
| 999 |
{ |
| 1000 |
eStatus = (MOS_STATUS)m_osInterface->pfnVerifyPatchListSize( |
| 1001 |
m_osInterface, |
| 1002 |
requestedPatchListSize); |
| 1003 |
|
| 1004 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 1005 |
{ |
| 1006 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_hwInterface->ResizeCommandBufferAndPatchList( |
| 1007 |
0, |
| 1008 |
requestedPatchListSize)); |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
eStatus = (MOS_STATUS)m_osInterface->pfnVerifyCommandBufferSize( |
| 1013 |
m_osInterface, |
| 1014 |
primRequestedSize, |
| 1015 |
0); |
| 1016 |
|
| 1017 |
if (eStatus == MOS_STATUS_SUCCESS) |
| 1018 |
{ |
| 1019 |
break; |
| 1020 |
} |
| 1021 |
else |
| 1022 |
{ |
| 1023 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_hwInterface->ResizeCommandBufferAndPatchList( |
| 1024 |
primRequestedSize + additionalSizeNeeded, |
| 1025 |
0)); |
| 1026 |
} |
| 1027 |
} |
| 1028 |
|
| 1029 |
CODECHAL_DECODE_CHK_STATUS_RETURN(VerifyExtraSpace(requestedSize, additionalSizeNeeded)); |
| 1030 |
|
| 1031 |
return eStatus; |
| 1032 |
} |
| 1033 |
|
| 1034 |
MOS_STATUS CodechalDecode::EndFrame () |
| 1035 |
{ |
| 1036 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1037 |
|
| 1038 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 1039 |
|
| 1040 |
CODECHAL_DEBUG_TOOL( |
| 1041 |
CodechalDecodeStatusReport * decodeStatusReport; |
| 1042 |
auto tempSurfNum = m_debugInterface->m_decodeSurfDumpFrameNum; // to handle BB_END data not written case |
| 1043 |
uint16_t preIndex = m_debugInterface->m_preIndex; |
| 1044 |
uint32_t numReportsAvailable = (m_decodeStatusBuf.m_currIndex - preIndex) & (CODECHAL_DECODE_STATUS_NUM - 1); |
| 1045 |
CODECHAL_DECODE_VERBOSEMESSAGE("NumReportsAvailable = %d", numReportsAvailable); |
| 1046 |
|
| 1047 |
for (uint32_t i = 0; i < numReportsAvailable; i++) { |
| 1048 |
uint16_t index = (m_debugInterface->m_preIndex + i) % CODECHAL_DECODE_STATUS_NUM; |
| 1049 |
decodeStatusReport = |
| 1050 |
&(m_decodeStatusBuf.m_decodeStatus[index].m_decodeStatusReport); |
| 1051 |
|
| 1052 |
// record SurfDumpFrameNum to handle BB_END data not written case |
| 1053 |
if (CodecHal_PictureIsFrame(decodeStatusReport->m_currDecodedPic) || |
| 1054 |
CodecHal_PictureIsInterlacedFrame(decodeStatusReport->m_currDecodedPic) || |
| 1055 |
decodeStatusReport->m_secondField) |
| 1056 |
{ |
| 1057 |
tempSurfNum++; |
| 1058 |
} |
| 1059 |
|
| 1060 |
if (m_standard == CODECHAL_HEVC && |
| 1061 |
m_isHybridDecoder && |
| 1062 |
(m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDecodeReferenceSurfaces) || m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDecodeOutputSurface))) |
| 1063 |
{ |
| 1064 |
CODECHAL_DECODE_CHK_STATUS_BREAK(DecodeGetHybridStatus( |
| 1065 |
m_decodeStatusBuf.m_decodeStatus, index, CODECHAL_STATUS_QUERY_START_FLAG)); |
| 1066 |
} |
| 1067 |
|
| 1068 |
auto tempFrameNum = m_debugInterface->m_bufferDumpFrameNum; |
| 1069 |
auto tempPic = m_debugInterface->m_currPic; |
| 1070 |
auto tempFrameType = m_debugInterface->m_frameType; |
| 1071 |
m_debugInterface->m_bufferDumpFrameNum = m_debugInterface->m_decodeSurfDumpFrameNum; |
| 1072 |
m_debugInterface->m_currPic = decodeStatusReport->m_currDecodedPic; |
| 1073 |
m_debugInterface->m_frameType = decodeStatusReport->m_frameType; |
| 1074 |
bool olpDump = false; |
| 1075 |
|
| 1076 |
MOS_SURFACE dstSurface; |
| 1077 |
if ((CodecHal_PictureIsFrame(decodeStatusReport->m_currDecodedPic) || |
| 1078 |
CodecHal_PictureIsInterlacedFrame(decodeStatusReport->m_currDecodedPic) || |
| 1079 |
CodecHal_PictureIsField(decodeStatusReport->m_currDecodedPic)) && |
| 1080 |
(m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDecodeBltOutput) || |
| 1081 |
m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDecodeOutputSurface) || |
| 1082 |
m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrStreamOut))) |
| 1083 |
{ |
| 1084 |
MOS_ZeroMemory(&dstSurface, sizeof(dstSurface)); |
| 1085 |
dstSurface.Format = Format_NV12; |
| 1086 |
dstSurface.OsResource = decodeStatusReport->m_currDecodedPicRes; |
| 1087 |
CODECHAL_DECODE_CHK_STATUS_BREAK(CodecHalGetResourceInfo( |
| 1088 |
m_osInterface, |
| 1089 |
&dstSurface)); |
| 1090 |
|
| 1091 |
m_debugInterface->DumpBltOutput( |
| 1092 |
&dstSurface, |
| 1093 |
CodechalDbgAttr::attrDecodeBltOutput); |
| 1094 |
|
| 1095 |
CODECHAL_DECODE_CHK_STATUS_BREAK(m_debugInterface->DumpYUVSurface( |
| 1096 |
&dstSurface, |
| 1097 |
CodechalDbgAttr::attrDecodeOutputSurface, |
| 1098 |
"DstSurf")); |
| 1099 |
|
| 1100 |
if (m_streamOutEnabled) |
| 1101 |
{ |
| 1102 |
//dump streamout buffer |
| 1103 |
CODECHAL_DECODE_CHK_STATUS_BREAK(m_debugInterface->DumpBuffer( |
| 1104 |
decodeStatusReport->m_streamOutBuf, |
| 1105 |
CodechalDbgAttr::attrStreamOut, |
| 1106 |
"StreamOut", |
| 1107 |
dstSurface.dwWidth)); |
| 1108 |
// reset the capture status of the streamout buffer |
| 1109 |
m_streamOutCurrStatusIdx[decodeStatusReport->m_streamoutIdx] = CODECHAL_DECODE_STATUS_NUM; |
| 1110 |
} |
| 1111 |
|
| 1112 |
olpDump = true; |
| 1113 |
} |
| 1114 |
|
| 1115 |
MOS_USER_FEATURE_VALUE_DATA userFeatureData; |
| 1116 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 1117 |
MOS_UserFeature_ReadValue_ID( |
| 1118 |
nullptr, |
| 1119 |
__MEDIA_USER_FEATURE_VALUE_DECOMPRESS_DECODE_OUTPUT_ID, |
| 1120 |
&userFeatureData, |
| 1121 |
m_osInterface->pOsContext); |
| 1122 |
if (userFeatureData.u32Data) |
| 1123 |
{ |
| 1124 |
CODECHAL_DECODE_VERBOSEMESSAGE("force ve decompress decode output"); |
| 1125 |
MOS_ZeroMemory(&dstSurface, sizeof(dstSurface)); |
| 1126 |
dstSurface.Format = Format_NV12; |
| 1127 |
dstSurface.OsResource = decodeStatusReport->m_currDecodedPicRes; |
| 1128 |
CODECHAL_DECODE_CHK_STATUS_BREAK(CodecHalGetResourceInfo( |
| 1129 |
m_osInterface, |
| 1130 |
&dstSurface)); |
| 1131 |
MOS_LOCK_PARAMS lockFlags {}; |
| 1132 |
lockFlags.ReadOnly = 1; |
| 1133 |
lockFlags.TiledAsTiled = 1; |
| 1134 |
lockFlags.NoDecompress = 0; |
| 1135 |
m_osInterface->pfnLockResource(m_osInterface, &dstSurface.OsResource, &lockFlags); |
| 1136 |
m_osInterface->pfnUnlockResource(m_osInterface, &dstSurface.OsResource); |
| 1137 |
} |
| 1138 |
|
| 1139 |
if (m_standard == CODECHAL_VC1 && |
| 1140 |
decodeStatusReport->m_olpNeeded && |
| 1141 |
olpDump && |
| 1142 |
m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDecodeOutputSurface)) |
| 1143 |
{ |
| 1144 |
MOS_ZeroMemory(&dstSurface, sizeof(dstSurface)); |
| 1145 |
dstSurface.Format = Format_NV12; |
| 1146 |
dstSurface.OsResource = decodeStatusReport->m_deblockedPicResOlp; |
| 1147 |
|
| 1148 |
CODECHAL_DECODE_CHK_STATUS_BREAK(CodecHalGetResourceInfo( |
| 1149 |
m_osInterface, |
| 1150 |
&dstSurface)); |
| 1151 |
|
| 1152 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 1153 |
&dstSurface, |
| 1154 |
CodechalDbgAttr::attrDecodeOutputSurface, |
| 1155 |
"OLP_DstSurf")); |
| 1156 |
} |
| 1157 |
|
| 1158 |
if ((m_standard == CODECHAL_HEVC || m_standard == CODECHAL_VP9) && |
| 1159 |
(decodeStatusReport->m_currSfcOutputPicRes != nullptr) && |
| 1160 |
m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSfcOutputSurface)) |
| 1161 |
{ |
| 1162 |
MOS_ZeroMemory(&dstSurface, sizeof(dstSurface)); |
| 1163 |
dstSurface.Format = Format_NV12; |
| 1164 |
dstSurface.OsResource = *decodeStatusReport->m_currSfcOutputPicRes; |
| 1165 |
|
| 1166 |
CODECHAL_DECODE_CHK_STATUS_BREAK(CodecHalGetResourceInfo( |
| 1167 |
m_osInterface, |
| 1168 |
&dstSurface)); |
| 1169 |
|
| 1170 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 1171 |
&dstSurface, |
| 1172 |
CodechalDbgAttr::attrSfcOutputSurface, |
| 1173 |
"SfcDstSurf")); |
| 1174 |
} |
| 1175 |
|
| 1176 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 1177 |
MOS_UserFeature_ReadValue_ID( |
| 1178 |
nullptr, |
| 1179 |
__MEDIA_USER_FEATURE_VALUE_DECOMPRESS_DECODE_SFC_OUTPUT_ID, |
| 1180 |
&userFeatureData, |
| 1181 |
m_osInterface->pOsContext); |
| 1182 |
if (userFeatureData.u32Data) |
| 1183 |
{ |
| 1184 |
CODECHAL_DECODE_VERBOSEMESSAGE("force ve decompress sfc output"); |
| 1185 |
MOS_ZeroMemory(&dstSurface, sizeof(dstSurface)); |
| 1186 |
dstSurface.Format = Format_NV12; |
| 1187 |
dstSurface.OsResource = *decodeStatusReport->m_currSfcOutputPicRes; |
| 1188 |
CODECHAL_DECODE_CHK_STATUS_BREAK(CodecHalGetResourceInfo( |
| 1189 |
m_osInterface, |
| 1190 |
&dstSurface)); |
| 1191 |
|
| 1192 |
MOS_LOCK_PARAMS lockFlags {}; |
| 1193 |
lockFlags.ReadOnly = 1; |
| 1194 |
lockFlags.TiledAsTiled = 1; |
| 1195 |
lockFlags.NoDecompress = 0; |
| 1196 |
m_osInterface->pfnLockResource(m_osInterface, &dstSurface.OsResource, &lockFlags); |
| 1197 |
m_osInterface->pfnUnlockResource(m_osInterface, &dstSurface.OsResource); |
| 1198 |
|
| 1199 |
} |
| 1200 |
|
| 1201 |
if (CodecHal_PictureIsFrame(decodeStatusReport->m_currDecodedPic) || |
| 1202 |
CodecHal_PictureIsInterlacedFrame(decodeStatusReport->m_currDecodedPic) || |
| 1203 |
CodecHal_PictureIsField(decodeStatusReport->m_currDecodedPic)) |
| 1204 |
{ |
| 1205 |
CODECHAL_DECODE_CHK_STATUS_BREAK(m_debugInterface->DeleteCfgLinkNode(m_debugInterface->m_decodeSurfDumpFrameNum)); |
| 1206 |
m_debugInterface->m_decodeSurfDumpFrameNum = tempSurfNum; |
| 1207 |
} |
| 1208 |
m_debugInterface->m_bufferDumpFrameNum = tempFrameNum; |
| 1209 |
m_debugInterface->m_currPic = tempPic; |
| 1210 |
m_debugInterface->m_frameType = tempFrameType; |
| 1211 |
|
| 1212 |
if (m_decodeStatusBuf.m_decodeStatus[index].m_hwStoredData == CODECHAL_STATUS_QUERY_END_FLAG) |
| 1213 |
{ |
| 1214 |
// report the CS Engine ID to user feature |
| 1215 |
for (auto j = 0; j < CODECHAL_CS_INSTANCE_ID_MAX; j++) |
| 1216 |
{ |
| 1217 |
CODECHAL_CS_ENGINE_ID csEngineIdValue; |
| 1218 |
csEngineIdValue.value = m_decodeStatusBuf.m_decodeStatus[index].m_mmioCsEngineIdReg[j]; |
| 1219 |
|
| 1220 |
//validate the user feature value |
| 1221 |
if (csEngineIdValue.value) |
| 1222 |
{ |
| 1223 |
CODECHAL_DECODE_ASSERT(csEngineIdValue.fields.ClassId == CODECHAL_CLASS_ID_VIDEO_ENGINE); |
| 1224 |
CODECHAL_DECODE_ASSERT(csEngineIdValue.fields.InstanceId < CODECHAL_CS_INSTANCE_ID_MAX); |
| 1225 |
CODECHAL_UPDATE_USED_VDBOX_ID_USER_FEATURE(csEngineIdValue.fields.InstanceId, m_osInterface->pOsContext); |
| 1226 |
} |
| 1227 |
} |
| 1228 |
preIndex = index + 1; |
| 1229 |
} |
| 1230 |
} |
| 1231 |
|
| 1232 |
m_debugInterface->m_preIndex = preIndex; |
| 1233 |
) |
| 1234 |
|
| 1235 |
if (m_consecutiveMbErrorConcealmentInUse && |
| 1236 |
m_incompletePicture) |
| 1237 |
{ |
| 1238 |
CODECHAL_DECODE_VERBOSEMESSAGE("Processing incomplete frame MBs"); |
| 1239 |
|
| 1240 |
if (!m_isHybridDecoder) |
| 1241 |
{ |
| 1242 |
m_osInterface->pfnSetGpuContext(m_osInterface, m_videoContext); |
| 1243 |
} |
| 1244 |
|
| 1245 |
m_decodePhantomMbs = true; |
| 1246 |
|
| 1247 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(DecodePrimitiveLevel(), |
| 1248 |
"Primitive level decoding failed."); |
| 1249 |
} |
| 1250 |
|
| 1251 |
DecodeFrameIndex++; |
| 1252 |
m_frameNum = DecodeFrameIndex; |
| 1253 |
|
| 1254 |
m_decodePhantomMbs = false; |
| 1255 |
|
| 1256 |
return eStatus; |
| 1257 |
} |
| 1258 |
|
| 1259 |
MOS_STATUS CodechalDecode::Execute(void *params) |
| 1260 |
{ |
| 1261 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1262 |
|
| 1263 |
PERF_UTILITY_AUTO(__FUNCTION__, PERF_DECODE, PERF_LEVEL_HAL); |
| 1264 |
|
| 1265 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 1266 |
|
| 1267 |
CODECHAL_DECODE_CHK_STATUS_RETURN(Codechal::Execute(params)); |
| 1268 |
|
| 1269 |
CodechalDecodeParams *decodeParams = (CodechalDecodeParams *)params; |
| 1270 |
m_executeCallIndex = decodeParams->m_executeCallIndex; |
| 1271 |
|
| 1272 |
// MSDK event handling |
| 1273 |
Mos_Solo_SetGpuAppTaskEvent(m_osInterface, decodeParams->m_gpuAppTaskEvent); |
| 1274 |
|
| 1275 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 1276 |
|
| 1277 |
MOS_TraceEvent(EVENT_CODEC_DECODE, EVENT_TYPE_START, &m_standard, sizeof(uint32_t), &m_frameNum, sizeof(uint32_t)); |
| 1278 |
|
| 1279 |
#endif // _DEBUG || _RELEASE_INTERNAL |
| 1280 |
|
| 1281 |
CODECHAL_DEBUG_TOOL( |
| 1282 |
m_debugInterface->m_bufferDumpFrameNum = m_frameNum;) |
| 1283 |
|
| 1284 |
if (m_cencBuf!= nullptr) |
| 1285 |
{ |
| 1286 |
CODECHAL_DECODE_CHK_STATUS_RETURN(Mos_Solo_DisableAubcaptureOptimizations( |
| 1287 |
m_osInterface, |
| 1288 |
IsFirstExecuteCall())); |
| 1289 |
} |
| 1290 |
|
| 1291 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 1292 |
if (decodeParams->m_refFrameCnt != 0) |
| 1293 |
{ |
| 1294 |
DecodeProcessingParams *procParams; |
| 1295 |
uint32_t allocWidth; |
| 1296 |
uint32_t allocHeight; |
| 1297 |
MOS_FORMAT format; |
| 1298 |
uint8_t frameIdx; |
| 1299 |
|
| 1300 |
CODECHAL_DECODE_CHK_NULL_RETURN(decodeParams->m_picParams); |
| 1301 |
CODECHAL_DECODE_CHK_NULL_RETURN(decodeParams->m_procParams); |
| 1302 |
|
| 1303 |
procParams = (DecodeProcessingParams *)decodeParams->m_procParams; |
| 1304 |
CODECHAL_DECODE_CHK_STATUS_RETURN(CodecHalGetResourceInfo( |
| 1305 |
m_osInterface, |
| 1306 |
procParams->m_outputSurface)); |
| 1307 |
|
| 1308 |
if (procParams->m_isSourceSurfAllocated) |
| 1309 |
{ |
| 1310 |
procParams->m_outputSurfaceRegion.m_width = procParams->m_outputSurface->dwWidth; |
| 1311 |
procParams->m_outputSurfaceRegion.m_height = procParams->m_outputSurface->dwHeight; |
| 1312 |
frameIdx = 0; |
| 1313 |
|
| 1314 |
m_refSurfaces = procParams->m_inputSurface; |
| 1315 |
CODECHAL_DECODE_CHK_STATUS_RETURN(CodecHalGetResourceInfo( |
| 1316 |
m_osInterface, |
| 1317 |
m_refSurfaces)); |
| 1318 |
|
| 1319 |
procParams->m_inputSurfaceRegion.m_x = 0; |
| 1320 |
procParams->m_inputSurfaceRegion.m_y = 0; |
| 1321 |
procParams->m_inputSurfaceRegion.m_width = m_refSurfaces->dwWidth; |
| 1322 |
procParams->m_inputSurfaceRegion.m_height = m_refSurfaces->dwHeight; |
| 1323 |
} |
| 1324 |
else |
| 1325 |
{ |
| 1326 |
CODECHAL_DECODE_CHK_STATUS_RETURN(CalcDownsamplingParams( |
| 1327 |
decodeParams->m_picParams, &allocWidth, &allocHeight, &format, &frameIdx)); |
| 1328 |
|
| 1329 |
if (frameIdx >= decodeParams->m_refFrameCnt) |
| 1330 |
{ |
| 1331 |
CODECHAL_DECODE_ASSERTMESSAGE("Invalid Downsampling Reference Frame Index !"); |
| 1332 |
return MOS_STATUS_INVALID_PARAMETER; |
| 1333 |
} |
| 1334 |
|
| 1335 |
if (m_refSurfaces == nullptr) |
| 1336 |
{ |
| 1337 |
m_refFrmCnt = decodeParams->m_refFrameCnt; |
| 1338 |
CODECHAL_DECODE_CHK_STATUS_RETURN(AllocateRefSurfaces(allocWidth, allocHeight, format)); |
| 1339 |
} |
| 1340 |
else |
| 1341 |
{ |
| 1342 |
PMOS_SURFACE currSurface = &m_refSurfaces[frameIdx]; |
| 1343 |
if (currSurface->dwHeight < allocHeight || currSurface->dwWidth < allocWidth) |
| 1344 |
{ |
| 1345 |
CODECHAL_DECODE_CHK_STATUS_RETURN(RefSurfacesResize(frameIdx, allocWidth, allocHeight, format)); |
| 1346 |
} |
| 1347 |
} |
| 1348 |
|
| 1349 |
procParams->m_inputSurfaceRegion.m_x = 0; |
| 1350 |
procParams->m_inputSurfaceRegion.m_y = 0; |
| 1351 |
procParams->m_inputSurfaceRegion.m_width = allocWidth; |
| 1352 |
procParams->m_inputSurfaceRegion.m_height = allocHeight; |
| 1353 |
|
| 1354 |
procParams->m_inputSurface = &m_refSurfaces[frameIdx]; |
| 1355 |
} |
| 1356 |
decodeParams->m_destSurface = &m_refSurfaces[frameIdx]; |
| 1357 |
} |
| 1358 |
#endif |
| 1359 |
m_decodeParams = *decodeParams; |
| 1360 |
|
| 1361 |
CODECHAL_DECODE_CHK_STATUS_RETURN(Mos_Solo_PreProcessDecode( |
| 1362 |
m_osInterface, |
| 1363 |
m_decodeParams.m_destSurface)); |
| 1364 |
|
| 1365 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_cpInterface->UpdateParams(true)); |
| 1366 |
|
| 1367 |
CODECHAL_DECODE_CHK_STATUS_RETURN(CodecHalGetResourceInfo( |
| 1368 |
m_osInterface, |
| 1369 |
decodeParams->m_destSurface)); |
| 1370 |
|
| 1371 |
if(!m_isHybridDecoder) |
| 1372 |
{ |
| 1373 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_osInterface->pfnSetGpuContext( |
| 1374 |
m_osInterface, |
| 1375 |
m_videoContext)); |
| 1376 |
} |
| 1377 |
if (!m_incompletePicture) |
| 1378 |
{ |
| 1379 |
m_osInterface->pfnResetOsStates(m_osInterface); |
| 1380 |
} |
| 1381 |
|
| 1382 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(SetFrameStates(), |
| 1383 |
"Decoding initialization failed."); |
| 1384 |
|
| 1385 |
CODECHAL_DECODE_CHK_STATUS_RETURN(VerifySpaceAvailable()); |
| 1386 |
|
| 1387 |
CODECHAL_DECODE_CHK_STATUS_RETURN(SetDummyReference()); |
| 1388 |
|
| 1389 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->SetWatchdogTimerThreshold(m_width, m_height, false)); |
| 1390 |
|
| 1391 |
if ((!m_incompletePicture) && (!m_isHybridDecoder)) |
| 1392 |
{ |
| 1393 |
m_osInterface->pfnIncPerfFrameID(m_osInterface); |
| 1394 |
m_osInterface->pfnSetPerfTag( |
| 1395 |
m_osInterface, |
| 1396 |
(uint16_t)(((m_mode << 4) & 0xF0) | (m_perfType & 0xF))); |
| 1397 |
m_osInterface->pfnResetPerfBufferID(m_osInterface); |
| 1398 |
} |
| 1399 |
|
| 1400 |
CODECHAL_DEBUG_TOOL( |
| 1401 |
|
| 1402 |
if (decodeParams->m_dataBuffer && |
| 1403 |
(m_standard != CODECHAL_JPEG && m_cencBuf == nullptr) && |
| 1404 |
!(m_standard == CODECHAL_HEVC && m_isHybridDecoder) && |
| 1405 |
!(m_standard == CODECHAL_HEVC && (m_incompletePicture || !IsFirstExecuteCall()))) |
| 1406 |
{ |
| 1407 |
if (m_mode == CODECHAL_DECODE_MODE_MPEG2VLD || |
| 1408 |
m_mode == CODECHAL_DECODE_MODE_VC1VLD || |
| 1409 |
m_mode == CODECHAL_DECODE_MODE_AVCVLD || |
| 1410 |
m_mode == CODECHAL_DECODE_MODE_VP8VLD || |
| 1411 |
m_mode == CODECHAL_DECODE_MODE_HEVCVLD || |
| 1412 |
m_mode == CODECHAL_DECODE_MODE_VP9VLD) |
| 1413 |
{ |
| 1414 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 1415 |
decodeParams->m_dataBuffer, |
| 1416 |
CodechalDbgAttr::attrDecodeBitstream, |
| 1417 |
"_DEC", |
| 1418 |
decodeParams->m_dataSize, |
| 1419 |
decodeParams->m_dataOffset, |
| 1420 |
CODECHAL_NUM_MEDIA_STATES |
| 1421 |
)); |
| 1422 |
} |
| 1423 |
else |
| 1424 |
{ |
| 1425 |
// Dump ResidualDifference |
| 1426 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 1427 |
decodeParams->m_dataBuffer, |
| 1428 |
CodechalDbgAttr::attrResidualDifference, |
| 1429 |
"_DEC", |
| 1430 |
decodeParams->m_dataSize)); |
| 1431 |
} |
| 1432 |
} |
| 1433 |
) |
| 1434 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 1435 |
CODECHAL_DEBUG_TOOL( |
| 1436 |
|
| 1437 |
if (decodeParams->m_procParams) |
| 1438 |
{ |
| 1439 |
CODECHAL_DECODE_CHK_STATUS_RETURN(DumpProcessingParams( |
| 1440 |
(DecodeProcessingParams *)decodeParams->m_procParams)); |
| 1441 |
} |
| 1442 |
) |
| 1443 |
#endif |
| 1444 |
for(auto i = 0; i < m_decodePassNum; i++) |
| 1445 |
{ |
| 1446 |
if (!m_incompletePicture) |
| 1447 |
{ |
| 1448 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(DecodeStateLevel(), |
| 1449 |
"State level decoding failed."); |
| 1450 |
} |
| 1451 |
|
| 1452 |
CODECHAL_DECODE_CHK_STATUS_MESSAGE_RETURN(DecodePrimitiveLevel(), |
| 1453 |
"Primitive level decoding failed."); |
| 1454 |
} |
| 1455 |
|
| 1456 |
if (m_secureDecoder != nullptr) |
| 1457 |
{ |
| 1458 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_secureDecoder->UpdateHuCStreamoutBufferIndex()); |
| 1459 |
} |
| 1460 |
|
| 1461 |
*decodeParams = m_decodeParams; |
| 1462 |
|
| 1463 |
if (m_decodeHistogram != nullptr) |
| 1464 |
{ |
| 1465 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_decodeHistogram->RenderHistogram(this, m_decodeParams.m_destSurface)); |
| 1466 |
} |
| 1467 |
|
| 1468 |
CODECHAL_DEBUG_TOOL( |
| 1469 |
if (CodecHal_PictureIsFrame(m_debugInterface->m_currPic) || |
| 1470 |
CodecHal_PictureIsInterlacedFrame(m_debugInterface->m_currPic) || |
| 1471 |
m_debugInterface->m_secondField) { |
| 1472 |
if (!m_statusQueryReportingEnabled) |
| 1473 |
{ |
| 1474 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_debugInterface->DeleteCfgLinkNode(m_debugInterface->m_bufferDumpFrameNum)); |
| 1475 |
} |
| 1476 |
}) |
| 1477 |
|
| 1478 |
if (CodecHal_PictureIsFrame(m_crrPic) || |
| 1479 |
CodecHal_PictureIsInterlacedFrame(m_crrPic) || |
| 1480 |
m_secondField) |
| 1481 |
{ |
| 1482 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 1483 |
if (m_debugInterface->IsHwDebugHooksEnable()) |
| 1484 |
{ |
| 1485 |
CodecHalGetResourceInfo(m_osInterface, decodeParams->m_destSurface); |
| 1486 |
uint32_t yuvSize = 0; |
| 1487 |
|
| 1488 |
CheckDecodeOutputBufSize(*decodeParams->m_destSurface); |
| 1489 |
if (!m_debugInterface->m_swCRC) //HW CRC |
| 1490 |
{ |
| 1491 |
uint32_t curIdx = (m_decodeStatusBuf.m_currIndex + CODECHAL_DECODE_STATUS_NUM - 1) % CODECHAL_DECODE_STATUS_NUM; |
| 1492 |
while (true) |
| 1493 |
{ |
| 1494 |
uint32_t globalHWStoredData = *(m_decodeStatusBuf.m_data); |
| 1495 |
uint32_t globalCount = m_decodeStatusBuf.m_swStoreData - globalHWStoredData; |
| 1496 |
uint32_t localCount = m_decodeStatusBuf.m_decodeStatus[curIdx].m_swStoredData - globalHWStoredData; |
| 1497 |
if (localCount == 0 || localCount > globalCount) //Decode OK |
| 1498 |
{ |
| 1499 |
m_debugInterface->CaptureGoldenReference(m_decodeOutputBuf, yuvSize, m_decodeStatusBuf.m_decodeStatus[curIdx].m_mmioFrameCrcReg); |
| 1500 |
break; |
| 1501 |
} |
| 1502 |
MosUtilities::MosSleep(1); |
| 1503 |
} |
| 1504 |
} |
| 1505 |
else //sw crc |
| 1506 |
{ |
| 1507 |
m_debugInterface->DumpYUVSurfaceToBuffer(decodeParams->m_destSurface, |
| 1508 |
m_decodeOutputBuf, |
| 1509 |
yuvSize); |
| 1510 |
m_debugInterface->CaptureGoldenReference(m_decodeOutputBuf, yuvSize, 0); |
| 1511 |
std::vector<MOS_RESOURCE> vRes = {m_crcBuf}; |
| 1512 |
m_debugInterface->DetectCorruptionSw(vRes, &m_frameCountTypeBuf, m_decodeOutputBuf, yuvSize, m_frameNum); |
| 1513 |
} |
| 1514 |
} |
| 1515 |
#endif |
| 1516 |
} |
| 1517 |
|
| 1518 |
CODECHAL_DECODE_CHK_STATUS_RETURN(Mos_Solo_PostProcessDecode(m_osInterface, m_decodeParams.m_destSurface)); |
| 1519 |
|
| 1520 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 1521 |
|
| 1522 |
MOS_TraceEvent(EVENT_CODEC_DECODE, EVENT_TYPE_END, &eStatus, sizeof(eStatus), nullptr, 0); |
| 1523 |
|
| 1524 |
#endif // _DEBUG || _RELEASE_INTERNAL |
| 1525 |
|
| 1526 |
return eStatus; |
| 1527 |
} |
| 1528 |
|
| 1529 |
MOS_STATUS CodechalDecode::StartStatusReport( |
| 1530 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 1531 |
{ |
| 1532 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1533 |
|
| 1534 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 1535 |
|
| 1536 |
CODECHAL_DECODE_CHK_NULL_RETURN(cmdBuffer); |
| 1537 |
|
| 1538 |
uint32_t offset = |
| 1539 |
(m_decodeStatusBuf.m_currIndex * sizeof(CodechalDecodeStatus)) + |
| 1540 |
m_decodeStatusBuf.m_storeDataOffset + |
| 1541 |
sizeof(uint32_t) * 2; |
| 1542 |
|
| 1543 |
MHW_MI_STORE_DATA_PARAMS params; |
| 1544 |
params.pOsResource = &m_decodeStatusBuf.m_statusBuffer; |
| 1545 |
params.dwResourceOffset = offset; |
| 1546 |
params.dwValue = CODECHAL_STATUS_QUERY_START_FLAG; |
| 1547 |
|
| 1548 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreDataImmCmd( |
| 1549 |
cmdBuffer, |
| 1550 |
¶ms)); |
| 1551 |
|
| 1552 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectStartCmd((void *)this, m_osInterface, m_miInterface, cmdBuffer)); |
| 1553 |
CODECHAL_DECODE_CHK_STATUS_RETURN(NullHW::StartPredicate(m_osInterface, m_miInterface, cmdBuffer)); |
| 1554 |
|
| 1555 |
return eStatus; |
| 1556 |
} |
| 1557 |
|
| 1558 |
MOS_STATUS StopExecutionAtFrame(CodechalHwInterface *hwInterface, PMOS_RESOURCE statusBuffer, PMOS_COMMAND_BUFFER pCmdBuffer, uint32_t numFrame) |
| 1559 |
{ |
| 1560 |
CODECHAL_DECODE_ASSERTMESSAGE("Will stop to frame: %d!!!", numFrame); |
| 1561 |
|
| 1562 |
CODECHAL_DECODE_CHK_STATUS_RETURN(hwInterface->SendHwSemaphoreWaitCmd( |
| 1563 |
statusBuffer, |
| 1564 |
0x7f7f7f7f, |
| 1565 |
MHW_MI_SAD_EQUAL_SDD, |
| 1566 |
pCmdBuffer)); |
| 1567 |
return MOS_STATUS_SUCCESS; |
| 1568 |
} |
| 1569 |
|
| 1570 |
MOS_STATUS CodechalDecode::EndStatusReport( |
| 1571 |
CodechalDecodeStatusReport &decodeStatusReport, |
| 1572 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 1573 |
{ |
| 1574 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1575 |
|
| 1576 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 1577 |
|
| 1578 |
CODECHAL_DECODE_CHK_COND_RETURN((m_vdboxIndex > m_mfxInterface->GetMaxVdboxIndex()), |
| 1579 |
"ERROR - vdbox index exceed the maximum"); |
| 1580 |
auto mmioRegistersMfx = m_hwInterface->SelectVdboxAndGetMmioRegister(m_vdboxIndex, cmdBuffer); |
| 1581 |
auto mmioRegistersHcp = m_hcpInterface ? m_hcpInterface->GetMmioRegisters(m_vdboxIndex) : nullptr; |
| 1582 |
|
| 1583 |
CODECHAL_DECODE_CHK_STATUS_RETURN(NullHW::StopPredicate(m_osInterface, m_miInterface, cmdBuffer)); |
| 1584 |
|
| 1585 |
uint32_t currIndex = m_decodeStatusBuf.m_currIndex; |
| 1586 |
//Error Status report |
| 1587 |
uint32_t errStatusOffset = |
| 1588 |
currIndex * sizeof(CodechalDecodeStatus) + |
| 1589 |
m_decodeStatusBuf.m_decErrorStatusOffset + |
| 1590 |
sizeof(uint32_t) * 2; |
| 1591 |
|
| 1592 |
MHW_MI_STORE_REGISTER_MEM_PARAMS regParams; |
| 1593 |
MOS_ZeroMemory(®Params, sizeof(regParams)); |
| 1594 |
|
| 1595 |
regParams.presStoreBuffer = &m_decodeStatusBuf.m_statusBuffer; |
| 1596 |
regParams.dwOffset = errStatusOffset; |
| 1597 |
regParams.dwRegister = ((m_standard == CODECHAL_HEVC || m_standard == CODECHAL_VP9) && mmioRegistersHcp) ? |
| 1598 |
mmioRegistersHcp->hcpCabacStatusRegOffset : mmioRegistersMfx->mfxErrorFlagsRegOffset; |
| 1599 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreRegisterMemCmd( |
| 1600 |
cmdBuffer, |
| 1601 |
®Params)); |
| 1602 |
|
| 1603 |
//Frame CRC |
| 1604 |
if (m_reportFrameCrc) |
| 1605 |
{ |
| 1606 |
uint32_t frameCrcOffset = |
| 1607 |
currIndex * sizeof(CodechalDecodeStatus) + |
| 1608 |
m_decodeStatusBuf.m_decFrameCrcOffset + |
| 1609 |
sizeof(uint32_t) * 2; |
| 1610 |
|
| 1611 |
regParams.presStoreBuffer = &m_decodeStatusBuf.m_statusBuffer; |
| 1612 |
regParams.dwOffset = frameCrcOffset; |
| 1613 |
if (m_standard == CODECHAL_AVC || m_standard == CODECHAL_VC1 || m_standard == CODECHAL_MPEG2 || m_standard == CODECHAL_JPEG) |
| 1614 |
{ |
| 1615 |
regParams.dwRegister = mmioRegistersMfx->mfxFrameCrcRegOffset; |
| 1616 |
} |
| 1617 |
else if(m_standard == CODECHAL_HEVC || m_standard == CODECHAL_VP9) |
| 1618 |
{ |
| 1619 |
CODECHAL_DECODE_CHK_NULL_RETURN(mmioRegistersHcp); |
| 1620 |
regParams.dwRegister = mmioRegistersHcp->hcpFrameCrcRegOffset; |
| 1621 |
} |
| 1622 |
|
| 1623 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreRegisterMemCmd( |
| 1624 |
cmdBuffer, |
| 1625 |
®Params)); |
| 1626 |
} |
| 1627 |
|
| 1628 |
//MB Count |
| 1629 |
uint32_t mbCountOffset = |
| 1630 |
currIndex * sizeof(CodechalDecodeStatus) + |
| 1631 |
m_decodeStatusBuf.m_decMBCountOffset + |
| 1632 |
sizeof(uint32_t) * 2; |
| 1633 |
|
| 1634 |
regParams.presStoreBuffer = &m_decodeStatusBuf.m_statusBuffer; |
| 1635 |
regParams.dwOffset = mbCountOffset; |
| 1636 |
regParams.dwRegister = ((m_standard == CODECHAL_HEVC || m_standard == CODECHAL_VP9) && mmioRegistersHcp) ? |
| 1637 |
mmioRegistersHcp->hcpDecStatusRegOffset : mmioRegistersMfx->mfxMBCountRegOffset; |
| 1638 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreRegisterMemCmd( |
| 1639 |
cmdBuffer, |
| 1640 |
®Params)); |
| 1641 |
|
| 1642 |
// First copy all the SW data in to the eStatus buffer |
| 1643 |
m_decodeStatusBuf.m_decodeStatus[currIndex].m_swStoredData = m_decodeStatusBuf.m_swStoreData; |
| 1644 |
m_decodeStatusBuf.m_decodeStatus[currIndex].m_decodeStatusReport = decodeStatusReport; |
| 1645 |
|
| 1646 |
uint32_t storeDataOffset = |
| 1647 |
currIndex * sizeof(CodechalDecodeStatus) + |
| 1648 |
m_decodeStatusBuf.m_storeDataOffset + |
| 1649 |
sizeof(uint32_t) * 2; |
| 1650 |
|
| 1651 |
MHW_MI_STORE_DATA_PARAMS dataParams; |
| 1652 |
dataParams.pOsResource = &m_decodeStatusBuf.m_statusBuffer; |
| 1653 |
dataParams.dwResourceOffset = storeDataOffset; |
| 1654 |
dataParams.dwValue = CODECHAL_STATUS_QUERY_END_FLAG; |
| 1655 |
|
| 1656 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreDataImmCmd( |
| 1657 |
cmdBuffer, |
| 1658 |
&dataParams)); |
| 1659 |
|
| 1660 |
m_decodeStatusBuf.m_currIndex = (m_decodeStatusBuf.m_currIndex + 1) % CODECHAL_DECODE_STATUS_NUM; |
| 1661 |
|
| 1662 |
CodechalDecodeStatus *decodeStatus = &m_decodeStatusBuf.m_decodeStatus[m_decodeStatusBuf.m_currIndex]; |
| 1663 |
MOS_ZeroMemory(decodeStatus, sizeof(CodechalDecodeStatus)); |
| 1664 |
|
| 1665 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectEndCmd((void*)this, m_osInterface, m_miInterface, cmdBuffer)); |
| 1666 |
if (!m_osInterface->bEnableKmdMediaFrameTracking && m_osInterface->bInlineCodecStatusUpdate) |
| 1667 |
{ |
| 1668 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 1669 |
// Send MI_FLUSH with protection bit off, which will FORCE exit protected mode for MFX |
| 1670 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 1671 |
flushDwParams.bVideoPipelineCacheInvalidate = true; |
| 1672 |
flushDwParams.pOsResource = &m_decodeStatusBuf.m_statusBuffer; |
| 1673 |
flushDwParams.dwDataDW1 = m_decodeStatusBuf.m_swStoreData; |
| 1674 |
MHW_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd( |
| 1675 |
cmdBuffer, |
| 1676 |
&flushDwParams)); |
| 1677 |
} |
| 1678 |
|
| 1679 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 1680 |
if (m_debugInterface->GetStopFrameNumber() == m_frameNum) |
| 1681 |
{ |
| 1682 |
StopExecutionAtFrame(m_hwInterface, &GetDecodeStatusBuf()->m_statusBuffer, cmdBuffer, m_frameNum); //Hang at specific frame. |
| 1683 |
} |
| 1684 |
#endif |
| 1685 |
|
| 1686 |
return eStatus; |
| 1687 |
} |
| 1688 |
|
| 1689 |
MOS_STATUS CodechalDecode::ResetStatusReport( |
| 1690 |
bool nullHwInUse) |
| 1691 |
{ |
| 1692 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1693 |
|
| 1694 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 1695 |
|
| 1696 |
if (!m_osInterface->bEnableKmdMediaFrameTracking && |
| 1697 |
!m_osInterface->bInlineCodecStatusUpdate) |
| 1698 |
{ |
| 1699 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 1700 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer( |
| 1701 |
m_osInterface, |
| 1702 |
&cmdBuffer, |
| 1703 |
0)); |
| 1704 |
|
| 1705 |
// initialize command buffer attributes |
| 1706 |
cmdBuffer.Attributes.bTurboMode = m_hwInterface->m_turboMode; |
| 1707 |
|
| 1708 |
CODECHAL_DECODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking( |
| 1709 |
&cmdBuffer, |
| 1710 |
false)); |
| 1711 |
|
| 1712 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd( |
| 1713 |
&cmdBuffer, |
| 1714 |
nullptr)); |
| 1715 |
|
| 1716 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, &cmdBuffer, 0); |
| 1717 |
|
| 1718 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_osInterface->pfnSubmitCommandBuffer( |
| 1719 |
m_osInterface, |
| 1720 |
&cmdBuffer, |
| 1721 |
nullHwInUse)); |
| 1722 |
} |
| 1723 |
|
| 1724 |
m_decodeStatusBuf.m_swStoreData++; |
| 1725 |
|
| 1726 |
return eStatus; |
| 1727 |
} |
| 1728 |
|
| 1729 |
MOS_STATUS CodechalDecode::GetStatusReport( |
| 1730 |
void *status, |
| 1731 |
uint16_t numStatus) |
| 1732 |
{ |
| 1733 |
uint16_t reportsGenerated = 0; |
| 1734 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1735 |
|
| 1736 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 1737 |
|
| 1738 |
CODECHAL_DECODE_CHK_NULL_RETURN(status); |
| 1739 |
CodechalDecodeStatusReport *codecStatus = (CodechalDecodeStatusReport *)status; |
| 1740 |
|
| 1741 |
uint32_t numReportsAvailable = |
| 1742 |
(m_decodeStatusBuf.m_currIndex - m_decodeStatusBuf.m_firstIndex) & |
| 1743 |
(CODECHAL_DECODE_STATUS_NUM - 1); |
| 1744 |
uint32_t globalHWStoredData = *(m_decodeStatusBuf.m_data); |
| 1745 |
uint32_t globalCount = m_decodeStatusBuf.m_swStoreData - globalHWStoredData; |
| 1746 |
|
| 1747 |
CODECHAL_DECODE_VERBOSEMESSAGE(" numStatus = %d, numReportsAvailable = %d.", |
| 1748 |
numStatus, numReportsAvailable); |
| 1749 |
CODECHAL_DECODE_VERBOSEMESSAGE(" HWStoreData = %d, globalCount = %d", |
| 1750 |
globalHWStoredData, globalCount); |
| 1751 |
|
| 1752 |
if (numReportsAvailable < numStatus) |
| 1753 |
{ |
| 1754 |
for (auto i = numReportsAvailable ; i < numStatus && i < CODECHAL_DECODE_STATUS_NUM ; i ++) |
| 1755 |
{ |
| 1756 |
// These buffers are not yet received by driver. Just don't report anything back. |
| 1757 |
codecStatus[i].m_codecStatus = CODECHAL_STATUS_UNAVAILABLE; |
| 1758 |
} |
| 1759 |
|
| 1760 |
numStatus = (uint16_t)numReportsAvailable; |
| 1761 |
} |
| 1762 |
|
| 1763 |
if (numReportsAvailable == 0) |
| 1764 |
{ |
| 1765 |
CODECHAL_DECODE_ASSERTMESSAGE("No reports available, m_currIndex = %d, m_firstIndex = %d", |
| 1766 |
m_decodeStatusBuf.m_currIndex, |
| 1767 |
m_decodeStatusBuf.m_firstIndex); |
| 1768 |
return eStatus; |
| 1769 |
} |
| 1770 |
|
| 1771 |
if (m_videoContextUsesNullHw || |
| 1772 |
m_videoContextForWaUsesNullHw || |
| 1773 |
m_renderContextUsesNullHw) |
| 1774 |
{ |
| 1775 |
for (auto j = 0 ; j < numStatus ; j++) |
| 1776 |
{ |
| 1777 |
uint32_t i = (m_decodeStatusBuf.m_firstIndex + numStatus - j - 1) & (CODECHAL_DECODE_STATUS_NUM - 1); |
| 1778 |
codecStatus[j] = m_decodeStatusBuf.m_decodeStatus[i].m_decodeStatusReport; |
| 1779 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_SUCCESSFUL; |
| 1780 |
reportsGenerated++; |
| 1781 |
} |
| 1782 |
|
| 1783 |
m_decodeStatusBuf.m_firstIndex = |
| 1784 |
(m_decodeStatusBuf.m_firstIndex + reportsGenerated) % CODECHAL_DECODE_STATUS_NUM; |
| 1785 |
|
| 1786 |
return eStatus; |
| 1787 |
} |
| 1788 |
|
| 1789 |
// Report eStatus in reverse temporal order |
| 1790 |
for (auto j = 0; j < numStatus; j ++) |
| 1791 |
{ |
| 1792 |
uint32_t i = (m_decodeStatusBuf.m_firstIndex + numStatus - j - 1) & (CODECHAL_DECODE_STATUS_NUM - 1); |
| 1793 |
CodechalDecodeStatusReport decodeStatusReport = m_decodeStatusBuf.m_decodeStatus[i].m_decodeStatusReport; |
| 1794 |
uint32_t localCount = m_decodeStatusBuf.m_decodeStatus[i].m_swStoredData - globalHWStoredData; |
| 1795 |
|
| 1796 |
if (m_isHybridDecoder) |
| 1797 |
{ |
| 1798 |
codecStatus[j] = decodeStatusReport; |
| 1799 |
// Consider the decode finished if the event dosen't present. |
| 1800 |
CODECHAL_DECODE_CHK_STATUS_RETURN(DecodeGetHybridStatus( |
| 1801 |
m_decodeStatusBuf.m_decodeStatus, i, CODECHAL_STATUS_QUERY_END_FLAG)); |
| 1802 |
|
| 1803 |
if (m_decodeStatusBuf.m_decodeStatus[i].m_hwStoredData == CODECHAL_STATUS_QUERY_END_FLAG) |
| 1804 |
{ |
| 1805 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_SUCCESSFUL; |
| 1806 |
reportsGenerated ++; |
| 1807 |
} |
| 1808 |
else |
| 1809 |
{ |
| 1810 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_INCOMPLETE; |
| 1811 |
} |
| 1812 |
} |
| 1813 |
else |
| 1814 |
{ |
| 1815 |
if (localCount == 0 || localCount > globalCount) |
| 1816 |
{ |
| 1817 |
codecStatus[j] = decodeStatusReport; |
| 1818 |
|
| 1819 |
// HW execution of these commands is complete. |
| 1820 |
if (m_osInterface->pfnIsGPUHung(m_osInterface)) |
| 1821 |
{ |
| 1822 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_INCOMPLETE; |
| 1823 |
} |
| 1824 |
else if (m_decodeStatusBuf.m_decodeStatus[i].m_hwStoredData == CODECHAL_STATUS_QUERY_END_FLAG) |
| 1825 |
{ |
| 1826 |
// No problem in execution |
| 1827 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_SUCCESSFUL; |
| 1828 |
|
| 1829 |
if (m_standard == CODECHAL_HEVC || m_standard == CODECHAL_VP9) |
| 1830 |
{ |
| 1831 |
if ((m_decodeStatusBuf.m_decodeStatus[i].m_mmioErrorStatusReg & |
| 1832 |
m_hcpInterface->GetHcpCabacErrorFlagsMask()) != 0 |
| 1833 |
&& ((m_decodeStatusBuf.m_decodeStatus[i].m_mmioMBCountReg & 0xFFFC0000) >> 18) != 0) |
| 1834 |
{ |
| 1835 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_ERROR; |
| 1836 |
codecStatus[j].m_numMbsAffected = |
| 1837 |
(m_decodeStatusBuf.m_decodeStatus[i].m_mmioMBCountReg & 0xFFFC0000) >> 18; |
| 1838 |
} |
| 1839 |
|
| 1840 |
if (m_reportFrameCrc) |
| 1841 |
{ |
| 1842 |
codecStatus[j].m_frameCrc = m_decodeStatusBuf.m_decodeStatus[i].m_mmioFrameCrcReg; |
| 1843 |
CODECHAL_DECODE_NORMALMESSAGE("HCP CRC:: %d\n", codecStatus[j].m_frameCrc); |
| 1844 |
} |
| 1845 |
} |
| 1846 |
else |
| 1847 |
{ |
| 1848 |
// Check to see if decoding error occurs |
| 1849 |
if (m_standard != CODECHAL_JPEG) |
| 1850 |
{ |
| 1851 |
if ((m_decodeStatusBuf.m_decodeStatus[i].m_mmioErrorStatusReg & |
| 1852 |
m_mfxInterface->GetMfxErrorFlagsMask()) != 0) |
| 1853 |
{ |
| 1854 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_ERROR; |
| 1855 |
} |
| 1856 |
//MB Count bit[15:0] is error concealment MB count for none JPEG decoder. |
| 1857 |
codecStatus[j].m_numMbsAffected = |
| 1858 |
m_decodeStatusBuf.m_decodeStatus[i].m_mmioMBCountReg & 0xFFFF; |
| 1859 |
} |
| 1860 |
if (m_standard == CODECHAL_AVC) |
| 1861 |
{ |
| 1862 |
codecStatus[j].m_frameCrc = m_decodeStatusBuf.m_decodeStatus[i].m_mmioFrameCrcReg; |
| 1863 |
} |
| 1864 |
} |
| 1865 |
} |
| 1866 |
else if (m_decodeStatusBuf.m_decodeStatus[i].m_hwStoredData == CODECHAL_STATUS_QUERY_SKIPPED) |
| 1867 |
{ |
| 1868 |
// In the case of AVC PR3.0 it is possible to drop a batch buffer execution |
| 1869 |
CODECHAL_DECODE_NORMALMESSAGE("Decode skipped."); |
| 1870 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_SUCCESSFUL; |
| 1871 |
} |
| 1872 |
else |
| 1873 |
{ |
| 1874 |
// BB_END data not written. Media reset might have occurred. |
| 1875 |
CODECHAL_DECODE_NORMALMESSAGE("Media reset may have occured."); |
| 1876 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_RESET; |
| 1877 |
} |
| 1878 |
|
| 1879 |
if (m_standard == CODECHAL_HEVC) |
| 1880 |
{ |
| 1881 |
// Print HuC_Status and HuC_Status2 registers |
| 1882 |
CODECHAL_DECODE_VERBOSEMESSAGE("Index = %d", i); |
| 1883 |
CODECHAL_DECODE_VERBOSEMESSAGE("HUC_STATUS register = 0x%x", |
| 1884 |
m_decodeStatusBuf.m_decodeStatus[i].m_hucErrorStatus >> 32); |
| 1885 |
CODECHAL_DECODE_VERBOSEMESSAGE("HUC_STATUS2 register = 0x%x", |
| 1886 |
m_decodeStatusBuf.m_decodeStatus[i].m_hucErrorStatus2 >> 32); |
| 1887 |
} |
| 1888 |
|
| 1889 |
CODECHAL_DECODE_VERBOSEMESSAGE("Incrementing reports generated to %d.", |
| 1890 |
(reportsGenerated + 1)); |
| 1891 |
reportsGenerated ++; |
| 1892 |
} |
| 1893 |
else |
| 1894 |
{ |
| 1895 |
CODECHAL_DECODE_VERBOSEMESSAGE("status buffer %d is INCOMPLETE.", j); |
| 1896 |
codecStatus[j] = decodeStatusReport; |
| 1897 |
codecStatus[j].m_codecStatus = CODECHAL_STATUS_INCOMPLETE; |
| 1898 |
if(m_osInterface->bInlineCodecStatusUpdate) |
| 1899 |
{ |
| 1900 |
// In Linux/Android, inline decode status reporting is enabled. |
| 1901 |
// If still received CODECHAL_STATUS_INCOMPLETE, |
| 1902 |
// it will be treat as GPU Hang. so need generate a report. |
| 1903 |
reportsGenerated ++; |
| 1904 |
} |
| 1905 |
} |
| 1906 |
} |
| 1907 |
} |
| 1908 |
|
| 1909 |
m_decodeStatusBuf.m_firstIndex = |
| 1910 |
(m_decodeStatusBuf.m_firstIndex + reportsGenerated) % CODECHAL_DECODE_STATUS_NUM; |
| 1911 |
CODECHAL_DECODE_VERBOSEMESSAGE("m_firstIndex now becomes %d.", m_decodeStatusBuf.m_firstIndex); |
| 1912 |
|
| 1913 |
return eStatus; |
| 1914 |
} |
| 1915 |
|
| 1916 |
MOS_STATUS CodechalDecode::CheckDecodeOutputBufSize(MOS_SURFACE &dstSurface) |
| 1917 |
{ |
| 1918 |
uint32_t size = (uint32_t)dstSurface.OsResource.pGmmResInfo->GetSizeMainSurface(); |
| 1919 |
//Realloc if m_decodeOutputBufSize < gmm query size in case of resolution change. |
| 1920 |
if (m_decodeOutputBufSize < size) |
| 1921 |
{ |
| 1922 |
if(m_decodeOutputBuf != nullptr) |
| 1923 |
{ |
| 1924 |
MOS_DeleteArray(m_decodeOutputBuf); |
| 1925 |
m_decodeOutputBuf = MOS_NewArray(uint8_t, size); |
| 1926 |
} |
| 1927 |
else |
| 1928 |
{ |
| 1929 |
m_decodeOutputBuf = MOS_NewArray(uint8_t, size); |
| 1930 |
} |
| 1931 |
m_decodeOutputBufSize = size; |
| 1932 |
} |
| 1933 |
|
| 1934 |
return MOS_STATUS_SUCCESS; |
| 1935 |
} |
| 1936 |
MOS_STATUS CodechalDecode::AllocateDecodeOutputBuf() |
| 1937 |
{ |
| 1938 |
if (m_decodeOutputBuf == nullptr) |
| 1939 |
{ |
| 1940 |
m_decodeOutputBuf = MOS_NewArray(uint8_t, m_decodeOutputBufSize); |
| 1941 |
} |
| 1942 |
return MOS_STATUS_SUCCESS; |
| 1943 |
} |
| 1944 |
|
| 1945 |
MOS_STATUS CodechalDecode::SendPrologWithFrameTracking( |
| 1946 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 1947 |
bool frameTrackingRequested) |
| 1948 |
{ |
| 1949 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1950 |
|
| 1951 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 1952 |
|
| 1953 |
CODECHAL_DECODE_CHK_NULL_RETURN(cmdBuffer); |
| 1954 |
|
| 1955 |
MOS_GPU_CONTEXT gpuContext = m_osInterface->pfnGetGpuContext(m_osInterface); |
| 1956 |
|
| 1957 |
// Send Start Marker command |
| 1958 |
if (m_decodeParams.m_setMarkerEnabled) |
| 1959 |
{ |
| 1960 |
CODECHAL_DECODE_CHK_STATUS_RETURN(SendMarkerCommand(cmdBuffer, MOS_RCS_ENGINE_USED(gpuContext))); |
| 1961 |
} |
| 1962 |
|
| 1963 |
if (frameTrackingRequested) |
| 1964 |
{ |
| 1965 |
// initialize command buffer attributes |
| 1966 |
cmdBuffer->Attributes.bTurboMode = m_hwInterface->m_turboMode; |
| 1967 |
cmdBuffer->Attributes.bMediaPreemptionEnabled = MOS_RCS_ENGINE_USED(gpuContext) ? |
| 1968 |
m_hwInterface->GetRenderInterface()->IsPreemptionEnabled() : 0; |
| 1969 |
cmdBuffer->Attributes.bEnableMediaFrameTracking = true; |
| 1970 |
cmdBuffer->Attributes.resMediaFrameTrackingSurface = &m_decodeStatusBuf.m_statusBuffer; |
| 1971 |
cmdBuffer->Attributes.dwMediaFrameTrackingTag = m_decodeStatusBuf.m_swStoreData; |
| 1972 |
// Set media frame tracking address offset(the offset from the decoder status buffer page, refer to CodecHalDecode_Initialize) |
| 1973 |
cmdBuffer->Attributes.dwMediaFrameTrackingAddrOffset = 0; |
| 1974 |
} |
| 1975 |
|
| 1976 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_mmc->SendPrologCmd(m_miInterface, cmdBuffer, gpuContext)); |
| 1977 |
|
| 1978 |
MHW_GENERIC_PROLOG_PARAMS genericPrologParams; |
| 1979 |
MOS_ZeroMemory(&genericPrologParams, sizeof(genericPrologParams)); |
| 1980 |
genericPrologParams.pOsInterface = m_osInterface; |
| 1981 |
genericPrologParams.pvMiInterface = m_miInterface; |
| 1982 |
genericPrologParams.bMmcEnabled = m_mmc->IsMmcEnabled(); |
| 1983 |
|
| 1984 |
CODECHAL_DECODE_CHK_STATUS_RETURN(Mhw_SendGenericPrologCmd( |
| 1985 |
cmdBuffer, |
| 1986 |
&genericPrologParams)); |
| 1987 |
|
| 1988 |
// Send predication command |
| 1989 |
if (m_decodeParams.m_predicationEnabled) |
| 1990 |
{ |
| 1991 |
CODECHAL_DECODE_CHK_STATUS_RETURN(SendPredicationCommand( |
| 1992 |
cmdBuffer)); |
| 1993 |
} |
| 1994 |
|
| 1995 |
return eStatus; |
| 1996 |
} |
| 1997 |
|
| 1998 |
MOS_STATUS CodechalDecode::SendPredicationCommand( |
| 1999 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 2000 |
{ |
| 2001 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2002 |
|
| 2003 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 2004 |
|
| 2005 |
CODECHAL_DECODE_CHK_NULL_RETURN(cmdBuffer); |
| 2006 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_miInterface); |
| 2007 |
|
| 2008 |
MHW_MI_CONDITIONAL_BATCH_BUFFER_END_PARAMS condBBEndParams; |
| 2009 |
MOS_ZeroMemory(&condBBEndParams, sizeof(condBBEndParams)); |
| 2010 |
|
| 2011 |
// Skip current frame if presPredication is not equal to zero |
| 2012 |
if (m_decodeParams.m_predicationNotEqualZero) |
| 2013 |
{ |
| 2014 |
auto mmioRegistersMfx = m_hwInterface->SelectVdboxAndGetMmioRegister(m_vdboxIndex, cmdBuffer); |
| 2015 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 2016 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 2017 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(cmdBuffer, &flushDwParams)); |
| 2018 |
|
| 2019 |
// load presPredication to general purpose register0 |
| 2020 |
MHW_MI_STORE_REGISTER_MEM_PARAMS loadRegisterMemParams; |
| 2021 |
MOS_ZeroMemory(&loadRegisterMemParams, sizeof(loadRegisterMemParams)); |
| 2022 |
loadRegisterMemParams.presStoreBuffer = m_decodeParams.m_presPredication; |
| 2023 |
loadRegisterMemParams.dwOffset = (uint32_t)m_decodeParams.m_predicationResOffset; |
| 2024 |
loadRegisterMemParams.dwRegister = mmioRegistersMfx->generalPurposeRegister0LoOffset; |
| 2025 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiLoadRegisterMemCmd( |
| 2026 |
cmdBuffer, |
| 2027 |
&loadRegisterMemParams)); |
| 2028 |
MHW_MI_LOAD_REGISTER_IMM_PARAMS loadRegisterImmParams; |
| 2029 |
MOS_ZeroMemory(&loadRegisterImmParams, sizeof(loadRegisterImmParams)); |
| 2030 |
loadRegisterImmParams.dwData = 0; |
| 2031 |
loadRegisterImmParams.dwRegister = mmioRegistersMfx->generalPurposeRegister0HiOffset; |
| 2032 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiLoadRegisterImmCmd( |
| 2033 |
cmdBuffer, |
| 2034 |
&loadRegisterImmParams)); |
| 2035 |
|
| 2036 |
// load 0 to general purpose register4 |
| 2037 |
MOS_ZeroMemory(&loadRegisterImmParams, sizeof(loadRegisterImmParams)); |
| 2038 |
loadRegisterImmParams.dwData = 0; |
| 2039 |
loadRegisterImmParams.dwRegister = mmioRegistersMfx->generalPurposeRegister4LoOffset; |
| 2040 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiLoadRegisterImmCmd( |
| 2041 |
cmdBuffer, |
| 2042 |
&loadRegisterImmParams)); |
| 2043 |
MOS_ZeroMemory(&loadRegisterImmParams, sizeof(loadRegisterImmParams)); |
| 2044 |
loadRegisterImmParams.dwData = 0; |
| 2045 |
loadRegisterImmParams.dwRegister = mmioRegistersMfx->generalPurposeRegister4HiOffset; |
| 2046 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiLoadRegisterImmCmd( |
| 2047 |
cmdBuffer, |
| 2048 |
&loadRegisterImmParams)); |
| 2049 |
|
| 2050 |
//perform the add operation |
| 2051 |
MHW_MI_MATH_PARAMS miMathParams; |
| 2052 |
MHW_MI_ALU_PARAMS miAluParams[4]; |
| 2053 |
MOS_ZeroMemory(&miMathParams, sizeof(miMathParams)); |
| 2054 |
MOS_ZeroMemory(&miAluParams, sizeof(miAluParams)); |
| 2055 |
// load srcA, reg0 |
| 2056 |
miAluParams[0].AluOpcode = MHW_MI_ALU_LOAD; |
| 2057 |
miAluParams[0].Operand1 = MHW_MI_ALU_SRCA; |
| 2058 |
miAluParams[0].Operand2 = MHW_MI_ALU_GPREG0; |
| 2059 |
// load srcB, reg4 |
| 2060 |
miAluParams[1].AluOpcode = MHW_MI_ALU_LOAD; |
| 2061 |
miAluParams[1].Operand1 = MHW_MI_ALU_SRCB; |
| 2062 |
miAluParams[1].Operand2 = MHW_MI_ALU_GPREG4; |
| 2063 |
// add srcA, srcB |
| 2064 |
miAluParams[2].AluOpcode = MHW_MI_ALU_ADD; |
| 2065 |
miAluParams[2].Operand1 = MHW_MI_ALU_SRCB; |
| 2066 |
miAluParams[2].Operand2 = MHW_MI_ALU_GPREG4; |
| 2067 |
// store reg0, ZF |
| 2068 |
miAluParams[3].AluOpcode = MHW_MI_ALU_STORE; |
| 2069 |
miAluParams[3].Operand1 = MHW_MI_ALU_GPREG0; |
| 2070 |
miAluParams[3].Operand2 = MHW_MI_ALU_ZF; |
| 2071 |
miMathParams.pAluPayload = miAluParams; |
| 2072 |
miMathParams.dwNumAluParams = 4; // four ALU commands needed for this substract opertaion. see following ALU commands. |
| 2073 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiMathCmd( |
| 2074 |
cmdBuffer, |
| 2075 |
&miMathParams)); |
| 2076 |
|
| 2077 |
// if zero, the zero flag will be 0xFFFFFFFF, else zero flag will be 0x0. |
| 2078 |
MHW_MI_STORE_REGISTER_MEM_PARAMS storeRegParams; |
| 2079 |
MOS_ZeroMemory(&storeRegParams, sizeof(storeRegParams)); |
| 2080 |
storeRegParams.presStoreBuffer = &m_predicationBuffer; |
| 2081 |
storeRegParams.dwOffset = 0; |
| 2082 |
storeRegParams.dwRegister = mmioRegistersMfx->generalPurposeRegister0LoOffset; |
| 2083 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreRegisterMemCmd( |
| 2084 |
cmdBuffer, |
| 2085 |
&storeRegParams)); |
| 2086 |
|
| 2087 |
condBBEndParams.presSemaphoreBuffer = &m_predicationBuffer; |
| 2088 |
condBBEndParams.dwOffset = 0; |
| 2089 |
condBBEndParams.dwValue = 0; |
| 2090 |
condBBEndParams.bDisableCompareMask = true; |
| 2091 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiConditionalBatchBufferEndCmd( |
| 2092 |
cmdBuffer, |
| 2093 |
&condBBEndParams)); |
| 2094 |
|
| 2095 |
*m_decodeParams.m_tempPredicationBuffer = &m_predicationBuffer; |
| 2096 |
} |
| 2097 |
else |
| 2098 |
{ |
| 2099 |
// Skip current frame if presPredication is equal to zero |
| 2100 |
condBBEndParams.presSemaphoreBuffer = m_decodeParams.m_presPredication; |
| 2101 |
condBBEndParams.dwOffset = (uint32_t)m_decodeParams.m_predicationResOffset; |
| 2102 |
condBBEndParams.bDisableCompareMask = true; |
| 2103 |
condBBEndParams.dwValue = 0; |
| 2104 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiConditionalBatchBufferEndCmd( |
| 2105 |
cmdBuffer, |
| 2106 |
&condBBEndParams)); |
| 2107 |
} |
| 2108 |
|
| 2109 |
return eStatus; |
| 2110 |
} |
| 2111 |
|
| 2112 |
MOS_STATUS CodechalDecode::SendMarkerCommand( |
| 2113 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 2114 |
bool isRender) |
| 2115 |
{ |
| 2116 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2117 |
|
| 2118 |
CODECHAL_DECODE_FUNCTION_ENTER; |
| 2119 |
|
| 2120 |
CODECHAL_DECODE_CHK_NULL_RETURN(cmdBuffer); |
| 2121 |
CODECHAL_DECODE_CHK_NULL_RETURN(m_miInterface); |
| 2122 |
|
| 2123 |
if (isRender) |
| 2124 |
{ |
| 2125 |
// Send pipe_control to get the timestamp |
| 2126 |
MHW_PIPE_CONTROL_PARAMS pipeControlParams; |
| 2127 |
MOS_ZeroMemory(&pipeControlParams, sizeof(pipeControlParams)); |
| 2128 |
pipeControlParams.presDest = (PMOS_RESOURCE)m_decodeParams.m_presSetMarker; |
| 2129 |
pipeControlParams.dwResourceOffset = 0; |
| 2130 |
pipeControlParams.dwPostSyncOp = MHW_FLUSH_WRITE_TIMESTAMP_REG; |
| 2131 |
pipeControlParams.dwFlushMode = MHW_FLUSH_WRITE_CACHE; |
| 2132 |
|
| 2133 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddPipeControl(cmdBuffer, NULL, &pipeControlParams)); |
| 2134 |
} |
| 2135 |
else |
| 2136 |
{ |
| 2137 |
// Send flush_dw to get the timestamp |
| 2138 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 2139 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 2140 |
flushDwParams.pOsResource = (PMOS_RESOURCE)m_decodeParams.m_presSetMarker; |
| 2141 |
flushDwParams.dwResourceOffset = 0; |
| 2142 |
flushDwParams.postSyncOperation = MHW_FLUSH_WRITE_TIMESTAMP_REG; |
| 2143 |
flushDwParams.bQWordEnable = 1; |
| 2144 |
|
| 2145 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(cmdBuffer, &flushDwParams)); |
| 2146 |
} |
| 2147 |
|
| 2148 |
return eStatus; |
| 2149 |
} |
| 2150 |
|
| 2151 |
MOS_STATUS CodechalDecode::SetCencBatchBuffer( |
| 2152 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 2153 |
{ |
| 2154 |
CODECHAL_DECODE_CHK_NULL_RETURN(cmdBuffer); |
| 2155 |
|
| 2156 |
MHW_BATCH_BUFFER batchBuffer; |
| 2157 |
MOS_ZeroMemory(&batchBuffer, sizeof(MHW_BATCH_BUFFER)); |
| 2158 |
MOS_RESOURCE *resHeap = nullptr; |
| 2159 |
CODECHAL_DECODE_CHK_NULL_RETURN(resHeap = m_cencBuf->secondLvlBbBlock->GetResource()); |
| 2160 |
batchBuffer.OsResource = *resHeap; |
| 2161 |
batchBuffer.dwOffset = m_cencBuf->secondLvlBbBlock->GetOffset(); |
| 2162 |
batchBuffer.iSize = m_cencBuf->secondLvlBbBlock->GetSize(); |
| 2163 |
batchBuffer.bSecondLevel = true; |
| 2164 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 2165 |
batchBuffer.iLastCurrent = batchBuffer.iSize; |
| 2166 |
#endif // (_DEBUG || _RELEASE_INTERNAL) |
| 2167 |
|
| 2168 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd( |
| 2169 |
cmdBuffer, |
| 2170 |
&batchBuffer)); |
| 2171 |
|
| 2172 |
CODECHAL_DEBUG_TOOL( |
| 2173 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_debugInterface->Dump2ndLvlBatch( |
| 2174 |
&batchBuffer, |
| 2175 |
CODECHAL_NUM_MEDIA_STATES, |
| 2176 |
"_2ndLvlBatch"));) |
| 2177 |
|
| 2178 |
// Update GlobalCmdBufId |
| 2179 |
MHW_MI_STORE_DATA_PARAMS miStoreDataParams; |
| 2180 |
MOS_ZeroMemory(&miStoreDataParams, sizeof(miStoreDataParams)); |
| 2181 |
miStoreDataParams.pOsResource = m_cencBuf->resTracker; |
| 2182 |
miStoreDataParams.dwValue = m_cencBuf->trackerId; |
| 2183 |
CODECHAL_DECODE_VERBOSEMESSAGE("dwCmdBufId = %d", miStoreDataParams.dwValue); |
| 2184 |
CODECHAL_DECODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreDataImmCmd( |
| 2185 |
cmdBuffer, |
| 2186 |
&miStoreDataParams)); |
| 2187 |
return MOS_STATUS_SUCCESS; |
| 2188 |
} |
| 2189 |
|
| 2190 |
#if USE_CODECHAL_DEBUG_TOOL |
| 2191 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 2192 |
MOS_STATUS CodechalDecode::DumpProcessingParams(DecodeProcessingParams *decProcParams) |
| 2193 |
{ |
| 2194 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 2195 |
|
| 2196 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDecodeProcParams)) |
| 2197 |
{ |
| 2198 |
return MOS_STATUS_SUCCESS; |
| 2199 |
} |
| 2200 |
|
| 2201 |
CODECHAL_DEBUG_CHK_NULL(decProcParams); |
| 2202 |
CODECHAL_DEBUG_CHK_NULL(decProcParams->m_inputSurface); |
| 2203 |
CODECHAL_DEBUG_CHK_NULL(decProcParams->m_outputSurface); |
| 2204 |
|
| 2205 |
std::ostringstream oss; |
| 2206 |
oss.setf(std::ios::showbase | std::ios::uppercase); |
| 2207 |
|
| 2208 |
oss << "Input Surface Resolution: " |
| 2209 |
<< +decProcParams->m_inputSurface->dwWidth << " x " << +decProcParams->m_inputSurface->dwHeight << std::endl; |
| 2210 |
oss << "Input Region Resolution: " |
| 2211 |
<< +decProcParams->m_inputSurfaceRegion.m_width << " x " << +decProcParams->m_inputSurfaceRegion.m_height << std::endl; |
| 2212 |
oss << "Input Region Offset: (" |
| 2213 |
<< +decProcParams->m_inputSurfaceRegion.m_x << "," << +decProcParams->m_inputSurfaceRegion.m_y << ")" << std::endl; |
| 2214 |
oss << "Input Surface Format: " |
| 2215 |
<< (decProcParams->m_inputSurface->Format == Format_NV12 ? "NV12" : "P010" )<< std::endl; |
| 2216 |
oss << "Output Surface Resolution: " |
| 2217 |
<< +decProcParams->m_outputSurface->dwWidth << " x " << +decProcParams->m_outputSurface->dwHeight << std::endl; |
| 2218 |
oss << "Output Region Resolution: " |
| 2219 |
<< +decProcParams->m_outputSurfaceRegion.m_width << " x " << +decProcParams->m_outputSurfaceRegion.m_height << std::endl; |
| 2220 |
oss << "Output Region Offset: (" |
| 2221 |
<< +decProcParams->m_outputSurfaceRegion.m_x << ", " << +decProcParams->m_outputSurfaceRegion.m_y << ")" << std::endl; |
| 2222 |
oss << "Output Surface Format: " |
| 2223 |
<< (decProcParams->m_outputSurface->Format == Format_NV12 ? "NV12" : "YUY2" )<< std::endl; |
| 2224 |
|
| 2225 |
const char* filePath = m_debugInterface->CreateFileName( |
| 2226 |
"_DEC", |
| 2227 |
CodechalDbgBufferType::bufDecProcParams, |
| 2228 |
CodechalDbgExtType::txt); |
| 2229 |
|
| 2230 |
std::ofstream ofs(filePath, std::ios::out); |
| 2231 |
ofs << oss.str(); |
| 2232 |
ofs.close(); |
| 2233 |
|
| 2234 |
return MOS_STATUS_SUCCESS; |
| 2235 |
} |
| 2236 |
|
| 2237 |
#endif |
| 2238 |
#endif |
| 2239 |
|