| 1 |
/* |
| 2 |
* Copyright (c) 2017-2022, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
//! |
| 24 |
//! \file codechal_vdenc_vp9_g12.cpp |
| 25 |
//! \brief VP9 VDENC encoder for GEN12. |
| 26 |
//! |
| 27 |
|
| 28 |
#include "codechal_vdenc_vp9_g12.h" |
| 29 |
#include "codechal_kernel_header_g12.h" |
| 30 |
#include "codechal_kernel_hme_g12.h" |
| 31 |
#include "codeckrnheader.h" |
| 32 |
#if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE) |
| 33 |
#include "igcodeckrn_g12.h" |
| 34 |
#endif |
| 35 |
#include "mhw_vdbox_hcp_g12_X.h" |
| 36 |
#include "mhw_vdbox_vdenc_g12_X.h" |
| 37 |
#include "mhw_vdbox_g12_X.h" |
| 38 |
#include "mhw_vdbox_vdenc_hwcmd_g12_X.h" |
| 39 |
#include "mhw_mi_g12_X.h" |
| 40 |
#include "mhw_render_g12_X.h" |
| 41 |
#include "codechal_mmc_encode_vp9_g12.h" |
| 42 |
#include "codechal_hw_g12_X.h" |
| 43 |
|
| 44 |
#define MAXPATH 512 |
| 45 |
|
| 46 |
const uint32_t CodechalVdencVp9StateG12::meCurbeInit[48] = |
| 47 |
{ |
| 48 |
0x00000000, 0x00200010, 0x00003939, 0x77a43000, 0x00000000, 0x28300000, 0x00000000, 0x00000000, |
| 49 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| 50 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| 51 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| 52 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| 53 |
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff |
| 54 |
}; |
| 55 |
|
| 56 |
MOS_STATUS CodechalVdencVp9StateG12::UserFeatureKeyReport() |
| 57 |
{ |
| 58 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 59 |
|
| 60 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 61 |
|
| 62 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalVdencVp9State::UserFeatureKeyReport()); |
| 63 |
|
| 64 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 65 |
CodecHalEncodeWriteKey(__MEDIA_USER_FEATURE_VALUE_ENCODE_USED_VDBOX_NUM_ID, m_numPipe, m_osInterface->pOsContext); |
| 66 |
CodecHalEncodeWriteKey(__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_ENABLE_HW_STITCH, m_enableTileStitchByHW, m_osInterface->pOsContext); |
| 67 |
CodecHalEncodeWriteKey(__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_SINGLE_PASS_DYS_ENABLE_ID, m_singlePassDys, m_osInterface->pOsContext); |
| 68 |
#endif |
| 69 |
|
| 70 |
return eStatus; |
| 71 |
} |
| 72 |
|
| 73 |
CodechalVdencVp9StateG12::CodechalVdencVp9StateG12( |
| 74 |
CodechalHwInterface* hwInterface, |
| 75 |
CodechalDebugInterface* debugInterface, |
| 76 |
PCODECHAL_STANDARD_INFO standardInfo) |
| 77 |
:CodechalVdencVp9State(hwInterface, debugInterface, standardInfo) |
| 78 |
{ |
| 79 |
m_useCommonKernel = true; |
| 80 |
m_isTilingSupported = true; |
| 81 |
|
| 82 |
// We need the DYS kernel inside AllVP9Enc_CNLA0, for SHME we need kernels inside |
| 83 |
// HME_DS_SCOREBOARD_KERNEL, so we need to allocate enough size in ISH for both. |
| 84 |
|
| 85 |
uint8_t* binary = nullptr; |
| 86 |
m_scalabilityState = nullptr; |
| 87 |
uint32_t combinedKernelSize = 0; |
| 88 |
|
| 89 |
pfnGetKernelHeaderAndSize = GetCommonKernelHeaderAndSizeG12; |
| 90 |
|
| 91 |
m_hwInterface->GetStateHeapSettings()->dwNumSyncTags = CODECHAL_ENCODE_VP9_NUM_SYNC_TAGS; |
| 92 |
m_hwInterface->GetStateHeapSettings()->dwDshSize = CODECHAL_ENCODE_VP9_INIT_DSH_SIZE; |
| 93 |
|
| 94 |
m_kuid = IDR_CODEC_AllVP9Enc; |
| 95 |
|
| 96 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 97 |
|
| 98 |
if (m_useCommonKernel) |
| 99 |
{ |
| 100 |
m_kuidCommon = IDR_CODEC_HME_DS_SCOREBOARD_KERNEL; |
| 101 |
eStatus = CodecHalGetKernelBinaryAndSize( |
| 102 |
#if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE) |
| 103 |
(uint8_t*)IGCODECKRN_G12, |
| 104 |
#else |
| 105 |
nullptr, |
| 106 |
#endif |
| 107 |
m_kuidCommon, |
| 108 |
&binary, |
| 109 |
&combinedKernelSize); |
| 110 |
CODECHAL_ENCODE_ASSERT(eStatus == MOS_STATUS_SUCCESS); |
| 111 |
|
| 112 |
m_hwInterface->GetStateHeapSettings()->dwIshSize += |
| 113 |
MOS_ALIGN_CEIL(combinedKernelSize, (1 << MHW_KERNEL_OFFSET_SHIFT)); |
| 114 |
} |
| 115 |
|
| 116 |
// Initialize to 0 |
| 117 |
MOS_ZeroMemory(&m_realCmdBuffer, sizeof(m_realCmdBuffer)); |
| 118 |
MOS_ZeroMemory(m_veBatchBuffer, sizeof(m_veBatchBuffer)); |
| 119 |
MOS_ZeroMemory(&m_hcpScalabilitySyncBuffer, sizeof(m_hcpScalabilitySyncBuffer)); |
| 120 |
|
| 121 |
for (auto i = 0; i < m_numUncompressedSurface; i++) |
| 122 |
{ |
| 123 |
MOS_ZeroMemory(&m_tileRecordBuffer[i].sResource, sizeof(m_tileRecordBuffer[i].sResource)); |
| 124 |
} |
| 125 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(m_osInterface); |
| 126 |
m_osInterface->pfnVirtualEngineSupported(m_osInterface, false, true); |
| 127 |
Mos_SetVirtualEngineSupported(m_osInterface, true); |
| 128 |
for (auto i = 0; i < m_numUncompressedSurface; i++) |
| 129 |
{ |
| 130 |
MOS_ZeroMemory(&m_tileStatsPakIntegrationBuffer[i].sResource, sizeof(m_tileStatsPakIntegrationBuffer[i].sResource)); |
| 131 |
} |
| 132 |
MOS_ZeroMemory(&m_frameStatsPakIntegrationBuffer.sResource, sizeof(m_frameStatsPakIntegrationBuffer.sResource)); |
| 133 |
for (auto i = 0; i < CODECHAL_ENCODE_RECYCLED_BUFFER_NUM; i++) |
| 134 |
{ |
| 135 |
for (auto j = 0; j < m_brcMaxNumPasses; j++) |
| 136 |
{ |
| 137 |
MOS_ZeroMemory(&m_hucPakIntDmemBuffer[i][j], sizeof(m_hucPakIntDmemBuffer[i][j])); |
| 138 |
} |
| 139 |
} |
| 140 |
MOS_ZeroMemory(&m_hucPakIntDummyBuffer, sizeof(m_hucPakIntDummyBuffer)); |
| 141 |
MOS_ZeroMemory(&m_hucPakIntBrcDataBuffer, sizeof(m_hucPakIntBrcDataBuffer)); |
| 142 |
for (auto i = 0; i < m_maxNumPipes; i++) |
| 143 |
{ |
| 144 |
MOS_ZeroMemory(&m_stitchWaitSemaphoreMem[i], sizeof(m_stitchWaitSemaphoreMem[i])); |
| 145 |
MOS_ZeroMemory(&m_hucDoneSemaphoreMem[i], sizeof(m_hucDoneSemaphoreMem[i])); |
| 146 |
} |
| 147 |
MOS_ZeroMemory(&m_pakIntDoneSemaphoreMem, sizeof(m_pakIntDoneSemaphoreMem)); |
| 148 |
} |
| 149 |
|
| 150 |
CodechalVdencVp9StateG12::~CodechalVdencVp9StateG12() |
| 151 |
{ |
| 152 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 153 |
|
| 154 |
if (m_scalabilityState) |
| 155 |
{ |
| 156 |
MOS_FreeMemAndSetNull(m_scalabilityState); |
| 157 |
} |
| 158 |
//Note: virtual engine interface destroy is done in MOS layer |
| 159 |
return; |
| 160 |
} |
| 161 |
|
| 162 |
// This is used only for DynamicScaling |
| 163 |
MOS_STATUS CodechalVdencVp9StateG12::ExecuteDysPictureLevel() |
| 164 |
{ |
| 165 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 166 |
|
| 167 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 168 |
|
| 169 |
CODECHAL_ENCODE_CHK_COND_RETURN((m_vdboxIndex > m_hwInterface->GetMfxInterface()->GetMaxVdboxIndex()), "ERROR - vdbox index exceed the maximum"); |
| 170 |
auto mmioRegisters = m_hcpInterface->GetMmioRegisters(m_vdboxIndex); |
| 171 |
CODECHAL_ENCODE_CHK_NULL_RETURN(mmioRegisters); |
| 172 |
PerfTagSetting perfTag; |
| 173 |
perfTag.Value = 0; |
| 174 |
perfTag.Mode = (uint16_t)m_mode & CODECHAL_ENCODE_MODE_BIT_MASK; |
| 175 |
perfTag.CallType = CODECHAL_ENCODE_PERFTAG_CALL_PAK_ENGINE; |
| 176 |
perfTag.PictureCodingType = m_pictureCodingType; |
| 177 |
m_osInterface->pfnSetPerfTag(m_osInterface, perfTag.Value); |
| 178 |
|
| 179 |
// We only need to update Huc PAK insert object and picture state for the first pass |
| 180 |
if (IsFirstPass()) |
| 181 |
{ |
| 182 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ConstructPakInsertObjBatchBuf(&m_resHucPakInsertUncompressedHeaderReadBuffer[m_currRecycledBufIdx])); |
| 183 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(PakConstructPicStateBatchBuf( |
| 184 |
&m_brcBuffers.resPicStateBrcWriteHucReadBuffer)); |
| 185 |
|
| 186 |
} |
| 187 |
|
| 188 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 189 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, &cmdBuffer, 0)); |
| 190 |
|
| 191 |
if (!m_singleTaskPhaseSupported || m_firstTaskInPhase) |
| 192 |
{ |
| 193 |
bool requestFrameTracking = false; |
| 194 |
MHW_MI_FORCE_WAKEUP_PARAMS forceWakeupParams; |
| 195 |
MOS_ZeroMemory(&forceWakeupParams, sizeof(MHW_MI_FORCE_WAKEUP_PARAMS)); |
| 196 |
forceWakeupParams.bMFXPowerWellControl = true; |
| 197 |
forceWakeupParams.bMFXPowerWellControlMask = true; |
| 198 |
forceWakeupParams.bHEVCPowerWellControl = true; |
| 199 |
forceWakeupParams.bHEVCPowerWellControlMask = true; |
| 200 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiForceWakeupCmd(&cmdBuffer, &forceWakeupParams)); |
| 201 |
// Send command buffer header at the beginning (OS dependent) |
| 202 |
// frame tracking tag is only added in the last command buffer header |
| 203 |
requestFrameTracking = m_singleTaskPhaseSupported ? m_firstTaskInPhase : m_lastTaskInPhase; |
| 204 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking(&cmdBuffer, requestFrameTracking)); |
| 205 |
} |
| 206 |
|
| 207 |
// Making sure ImgStatusCtrl is zeroed out before first PAK pass. HW supposedly does this before start of each frame. Remove this after confirming. |
| 208 |
if (m_currPass == 0) |
| 209 |
{ |
| 210 |
MHW_MI_LOAD_REGISTER_IMM_PARAMS miLoadRegImmParams; |
| 211 |
MOS_ZeroMemory(&miLoadRegImmParams, sizeof(miLoadRegImmParams)); |
| 212 |
miLoadRegImmParams.dwData = 0; |
| 213 |
miLoadRegImmParams.dwRegister = mmioRegisters->hcpVp9EncImageStatusCtrlRegOffset; |
| 214 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->GetMiInterface()->AddMiLoadRegisterImmCmd(&cmdBuffer, &miLoadRegImmParams)); |
| 215 |
} |
| 216 |
|
| 217 |
// Read Image status before running PAK, to get correct cumulative delta applied for final pass. |
| 218 |
if (m_currPass != m_numPasses) // Don't read it for Repak |
| 219 |
{ |
| 220 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReadImageStatus(&cmdBuffer)); |
| 221 |
} |
| 222 |
|
| 223 |
//updating the numberofpakpasses in encode staus buffer. should not update for repak. |
| 224 |
if (m_currPass < m_numPasses) |
| 225 |
{ |
| 226 |
uint32_t offset = |
| 227 |
(m_encodeStatusBuf.wCurrIndex * m_encodeStatusBuf.dwReportSize) + |
| 228 |
m_encodeStatusBuf.dwNumPassesOffset + |
| 229 |
sizeof(uint32_t) * 2; // encode status doesn't start until 3rd DW |
| 230 |
|
| 231 |
MHW_MI_STORE_DATA_PARAMS storeDataParams; |
| 232 |
MOS_ZeroMemory(&storeDataParams, sizeof(storeDataParams)); |
| 233 |
storeDataParams.pOsResource = &m_encodeStatusBuf.resStatusBuffer; |
| 234 |
storeDataParams.dwResourceOffset = offset; |
| 235 |
storeDataParams.dwValue = m_currPass + 1; |
| 236 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreDataImmCmd(&cmdBuffer, &storeDataParams)); |
| 237 |
} |
| 238 |
|
| 239 |
if (!m_currPass && m_osInterface->bTagResourceSync) |
| 240 |
{ |
| 241 |
// This is a short term WA to solve the sync tag issue: the sync tag write for PAK is inserted at the end of 2nd pass PAK BB |
| 242 |
// which may be skipped in multi-pass PAK enabled case. The idea here is to insert the previous frame's tag at the beginning |
| 243 |
// of the BB and keep the current frame's tag at the end of the BB. There will be a delay for tag update but it should be fine |
| 244 |
// as long as Dec/VP/Enc won't depend on this PAK so soon. |
| 245 |
PMOS_RESOURCE globalGpuContextSyncTagBuffer = nullptr; |
| 246 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnGetGpuStatusBufferResource( |
| 247 |
m_osInterface, |
| 248 |
globalGpuContextSyncTagBuffer)); |
| 249 |
CODECHAL_ENCODE_CHK_NULL_RETURN(globalGpuContextSyncTagBuffer); |
| 250 |
|
| 251 |
uint32_t value = m_osInterface->pfnGetGpuStatusTag(m_osInterface, m_osInterface->CurrentGpuContextOrdinal); |
| 252 |
MHW_MI_STORE_DATA_PARAMS params; |
| 253 |
params.pOsResource = globalGpuContextSyncTagBuffer; |
| 254 |
params.dwResourceOffset = m_osInterface->pfnGetGpuStatusTagOffset(m_osInterface, m_osInterface->CurrentGpuContextOrdinal); |
| 255 |
params.dwValue = (value > 0) ? (value - 1) : 0; |
| 256 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->GetMiInterface()->AddMiStoreDataImmCmd(&cmdBuffer, ¶ms)); |
| 257 |
} |
| 258 |
|
| 259 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StartStatusReport(&cmdBuffer, CODECHAL_NUM_MEDIA_STATES)); |
| 260 |
|
| 261 |
//Send VD_CONTROL_STATE Pipe Initialization |
| 262 |
MHW_MI_VD_CONTROL_STATE_PARAMS vdCtrlParam; |
| 263 |
MOS_ZeroMemory(&vdCtrlParam, sizeof(MHW_MI_VD_CONTROL_STATE_PARAMS)); |
| 264 |
vdCtrlParam.initialization = true; |
| 265 |
MhwMiInterfaceG12* miInterfaceG12 = static_cast <MhwMiInterfaceG12 *>(m_miInterface); |
| 266 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((miInterfaceG12)->AddMiVdControlStateCmd(&cmdBuffer, &vdCtrlParam)); |
| 267 |
|
| 268 |
// set HCP_PIPE_MODE_SELECT values |
| 269 |
PMHW_VDBOX_PIPE_MODE_SELECT_PARAMS pipeModeSelectParams = nullptr; |
| 270 |
pipeModeSelectParams = m_vdencInterface->CreateMhwVdboxPipeModeSelectParams(); |
| 271 |
CODECHAL_ENCODE_CHK_NULL_RETURN(pipeModeSelectParams); |
| 272 |
|
| 273 |
SetHcpPipeModeSelectParams(*pipeModeSelectParams); |
| 274 |
|
| 275 |
pipeModeSelectParams->Mode = m_mode; |
| 276 |
pipeModeSelectParams->bStreamOutEnabled = false; |
| 277 |
pipeModeSelectParams->bVdencEnabled = false; |
| 278 |
pipeModeSelectParams->ChromaType = m_vp9SeqParams->SeqFlags.fields.EncodedFormat; |
| 279 |
pipeModeSelectParams->bDynamicScalingEnabled = m_dysRefFrameFlags && !m_dysVdencMultiPassEnabled; |
| 280 |
|
| 281 |
eStatus = m_hcpInterface->AddHcpPipeModeSelectCmd(&cmdBuffer, pipeModeSelectParams); |
| 282 |
m_vdencInterface->ReleaseMhwVdboxPipeModeSelectParams(pipeModeSelectParams); |
| 283 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus); |
| 284 |
|
| 285 |
// set HCP_SURFACE_STATE values |
| 286 |
MHW_VDBOX_SURFACE_PARAMS surfaceParams[CODECHAL_HCP_ALTREF_SURFACE_ID + 1]; |
| 287 |
for (uint8_t i = 0; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++) |
| 288 |
{ |
| 289 |
MOS_ZeroMemory(&surfaceParams[i], sizeof(surfaceParams[i])); |
| 290 |
surfaceParams[i].Mode = m_mode; |
| 291 |
surfaceParams[i].ucSurfaceStateId = i; |
| 292 |
surfaceParams[i].ChromaType = m_outputChromaFormat; |
| 293 |
|
| 294 |
switch (m_vp9SeqParams->SeqFlags.fields.EncodedBitDepth) |
| 295 |
{ |
| 296 |
case VP9_ENCODED_BIT_DEPTH_10: //10 bit encoding |
| 297 |
{ |
| 298 |
surfaceParams[i].ucBitDepthChromaMinus8 = 2; |
| 299 |
surfaceParams[i].ucBitDepthLumaMinus8 = 2; |
| 300 |
break; |
| 301 |
} |
| 302 |
default: |
| 303 |
{ |
| 304 |
surfaceParams[i].ucBitDepthChromaMinus8 = 0; |
| 305 |
surfaceParams[i].ucBitDepthLumaMinus8 = 0; |
| 306 |
break; |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
// For PAK engine, we do NOT use scaled reference images even if dynamic scaling is enabled |
| 312 |
PMOS_SURFACE refSurface[3]; |
| 313 |
for (auto i = 0; i < 3; i++) |
| 314 |
{ |
| 315 |
refSurface[i] = nullptr; |
| 316 |
} |
| 317 |
|
| 318 |
if (m_pictureCodingType != I_TYPE) |
| 319 |
{ |
| 320 |
uint8_t refPicIndex; |
| 321 |
if (m_refFrameFlags & 0x01) |
| 322 |
{ |
| 323 |
refPicIndex = m_vp9PicParams->RefFlags.fields.LastRefIdx; |
| 324 |
|
| 325 |
CODECHAL_ENCODE_ASSERT((refPicIndex < CODEC_VP9_NUM_REF_FRAMES) && (!CodecHal_PictureIsInvalid(m_vp9PicParams->RefFrameList[refPicIndex]))); |
| 326 |
refSurface[0] = &(m_refList[m_vp9PicParams->RefFrameList[refPicIndex].FrameIdx]->sRefBuffer); |
| 327 |
} |
| 328 |
|
| 329 |
if (m_refFrameFlags & 0x02) |
| 330 |
{ |
| 331 |
refPicIndex = m_vp9PicParams->RefFlags.fields.GoldenRefIdx; |
| 332 |
|
| 333 |
CODECHAL_ENCODE_ASSERT((refPicIndex < CODEC_VP9_NUM_REF_FRAMES) && (!CodecHal_PictureIsInvalid(m_vp9PicParams->RefFrameList[refPicIndex]))); |
| 334 |
refSurface[1] = &(m_refList[m_vp9PicParams->RefFrameList[refPicIndex].FrameIdx]->sRefBuffer); |
| 335 |
} |
| 336 |
|
| 337 |
if (m_refFrameFlags & 0x04) |
| 338 |
{ |
| 339 |
refPicIndex = m_vp9PicParams->RefFlags.fields.AltRefIdx; |
| 340 |
|
| 341 |
CODECHAL_ENCODE_ASSERT((refPicIndex < CODEC_VP9_NUM_REF_FRAMES) && (!CodecHal_PictureIsInvalid(m_vp9PicParams->RefFrameList[refPicIndex]))) |
| 342 |
refSurface[2] = &(m_refList[m_vp9PicParams->RefFrameList[refPicIndex].FrameIdx]->sRefBuffer); |
| 343 |
} |
| 344 |
|
| 345 |
if (!refSurface[0]) |
| 346 |
{ |
| 347 |
refSurface[0] = (refSurface[1]) ? refSurface[1] : refSurface[2]; |
| 348 |
} |
| 349 |
|
| 350 |
if (!refSurface[1]) |
| 351 |
{ |
| 352 |
refSurface[1] = (refSurface[0]) ? refSurface[0] : refSurface[2]; |
| 353 |
} |
| 354 |
|
| 355 |
if (!refSurface[2]) |
| 356 |
{ |
| 357 |
refSurface[2] = (refSurface[0]) ? refSurface[0] : refSurface[1]; |
| 358 |
} |
| 359 |
|
| 360 |
// Program Surface params for Last/Golen/Alt Reference surface |
| 361 |
surfaceParams[CODECHAL_HCP_LAST_SURFACE_ID].psSurface = refSurface[0]; |
| 362 |
surfaceParams[CODECHAL_HCP_GOLDEN_SURFACE_ID].psSurface = refSurface[1]; |
| 363 |
surfaceParams[CODECHAL_HCP_ALTREF_SURFACE_ID].psSurface = refSurface[2]; |
| 364 |
|
| 365 |
surfaceParams[CODECHAL_HCP_LAST_SURFACE_ID].dwReconSurfHeight = MOS_ALIGN_CEIL((refSurface[0] ? refSurface[0]->dwHeight : 0), CODEC_VP9_MIN_BLOCK_WIDTH); |
| 366 |
surfaceParams[CODECHAL_HCP_GOLDEN_SURFACE_ID].dwReconSurfHeight = MOS_ALIGN_CEIL((refSurface[1] ? refSurface[1]->dwHeight : 0), CODEC_VP9_MIN_BLOCK_WIDTH); |
| 367 |
surfaceParams[CODECHAL_HCP_ALTREF_SURFACE_ID].dwReconSurfHeight = MOS_ALIGN_CEIL((refSurface[2] ? refSurface[2]->dwHeight : 0), CODEC_VP9_MIN_BLOCK_WIDTH); |
| 368 |
} |
| 369 |
|
| 370 |
// recon |
| 371 |
surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID].psSurface = &m_reconSurface; |
| 372 |
surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID].dwReconSurfHeight = m_rawSurfaceToPak->dwHeight; |
| 373 |
|
| 374 |
// raw |
| 375 |
surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID].psSurface = m_rawSurfaceToPak; |
| 376 |
surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID].bDisplayFormatSwizzle = m_vp9SeqParams->SeqFlags.fields.DisplayFormatSwizzle; |
| 377 |
surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID].dwActualWidth = MOS_ALIGN_CEIL(m_oriFrameWidth, CODEC_VP9_MIN_BLOCK_WIDTH); |
| 378 |
surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID].dwActualHeight = MOS_ALIGN_CEIL(m_oriFrameHeight, CODEC_VP9_MIN_BLOCK_WIDTH); |
| 379 |
|
| 380 |
// Decoded picture |
| 381 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState); |
| 382 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID])); |
| 383 |
|
| 384 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID])); |
| 385 |
|
| 386 |
// Source input |
| 387 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState); |
| 388 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID])); |
| 389 |
|
| 390 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID])); |
| 391 |
|
| 392 |
if (m_pictureCodingType != I_TYPE) |
| 393 |
{ |
| 394 |
//Get each reference surface state and be recorded by skipMask if current surface state is mmc disabled |
| 395 |
//In VP9 mode, Bit 8is (here is bit0 in skipMask ) for Previous Reference; |
| 396 |
//Bit 9is (here is bit1 in skipMask ) for Golden Reference and Bit 10is (here is bit2 in skipMask ) for Alterante Reference; |
| 397 |
//Bits11-15are unused and should be programmed to 0 (skipped) |
| 398 |
uint8_t skipMask = 0xf8; |
| 399 |
for (uint8_t i = CODECHAL_HCP_LAST_SURFACE_ID; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++) |
| 400 |
{ |
| 401 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState); |
| 402 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[i])); |
| 403 |
if (surfaceParams[i].mmcState == MOS_MEMCOMP_DISABLED) |
| 404 |
{ |
| 405 |
skipMask |= (1 << (i - 2)); |
| 406 |
} |
| 407 |
} |
| 408 |
CODECHAL_ENCODE_NORMALMESSAGE("MMC skip mask is %d\n", skipMask); |
| 409 |
for (uint8_t i = CODECHAL_HCP_LAST_SURFACE_ID; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++) |
| 410 |
{ |
| 411 |
//Set each ref surface state as MOS_MEMCOMP_MC to satisfy MmcEnable in AddHcpSurfaceCmd |
| 412 |
//Because each ref surface state should be programmed as the same |
| 413 |
//The actual mmc state is recorded by skipMask and set each ref surface too |
| 414 |
surfaceParams[i].mmcState = MOS_MEMCOMP_MC; |
| 415 |
surfaceParams[i].mmcSkipMask = skipMask; |
| 416 |
} |
| 417 |
|
| 418 |
for (uint8_t i = CODECHAL_HCP_LAST_SURFACE_ID; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++) |
| 419 |
{ |
| 420 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[i])); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
// set HCP_PIPE_BUF_ADDR_STATE values |
| 425 |
PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams = nullptr; |
| 426 |
pipeBufAddrParams = CreateHcpPipeBufAddrParams(pipeBufAddrParams); |
| 427 |
if (pipeBufAddrParams) |
| 428 |
{ |
| 429 |
auto delete_func = [&]() |
| 430 |
{ |
| 431 |
MOS_Delete(pipeBufAddrParams); |
| 432 |
pipeBufAddrParams = nullptr; |
| 433 |
}; |
| 434 |
|
| 435 |
pipeBufAddrParams->Mode = m_mode; |
| 436 |
pipeBufAddrParams->psPreDeblockSurface = &m_reconSurface; |
| 437 |
pipeBufAddrParams->psPostDeblockSurface = &m_reconSurface; |
| 438 |
pipeBufAddrParams->psRawSurface = m_rawSurfaceToPak; |
| 439 |
|
| 440 |
pipeBufAddrParams->presStreamOutBuffer = nullptr; |
| 441 |
pipeBufAddrParams->presMfdDeblockingFilterRowStoreScratchBuffer = |
| 442 |
&m_resDeblockingFilterLineBuffer; |
| 443 |
|
| 444 |
pipeBufAddrParams->presDeblockingFilterTileRowStoreScratchBuffer = |
| 445 |
&m_resDeblockingFilterTileLineBuffer; |
| 446 |
|
| 447 |
pipeBufAddrParams->presDeblockingFilterColumnRowStoreScratchBuffer = |
| 448 |
&m_resDeblockingFilterTileColumnBuffer; |
| 449 |
|
| 450 |
pipeBufAddrParams->presMetadataLineBuffer = &m_resMetadataLineBuffer; |
| 451 |
pipeBufAddrParams->presMetadataTileLineBuffer = &m_resMetadataTileLineBuffer; |
| 452 |
pipeBufAddrParams->presMetadataTileColumnBuffer = &m_resMetadataTileColumnBuffer; |
| 453 |
pipeBufAddrParams->presCurMvTempBuffer = m_trackedBuf->GetMvTemporalBuffer(m_currMvTemporalBufferIndex); |
| 454 |
|
| 455 |
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, delete_func); |
| 456 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetPipeBufAddr(pipeBufAddrParams), delete_func); |
| 457 |
|
| 458 |
//Huc is disabled for ref frame scaling, use input region |
| 459 |
uint8_t frameCtxIdx = m_vp9PicParams->PicFlags.fields.frame_context_idx; |
| 460 |
CODECHAL_ENCODE_ASSERT(frameCtxIdx < CODEC_VP9_NUM_CONTEXTS); |
| 461 |
pipeBufAddrParams->presVp9ProbBuffer = &m_resProbBuffer[frameCtxIdx]; |
| 462 |
pipeBufAddrParams->presVp9SegmentIdBuffer = &m_resSegmentIdBuffer; |
| 463 |
|
| 464 |
if (m_pictureCodingType != I_TYPE) |
| 465 |
{ |
| 466 |
for (auto i = 0; i < 3; i++) |
| 467 |
{ |
| 468 |
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(refSurface[i], delete_func); |
| 469 |
|
| 470 |
pipeBufAddrParams->presReferences[i] = &refSurface[i]->OsResource; |
| 471 |
} |
| 472 |
|
| 473 |
pipeBufAddrParams->presColMvTempBuffer[0] = m_trackedBuf->GetMvTemporalBuffer(m_currMvTemporalBufferIndex ^ 0x01); |
| 474 |
} |
| 475 |
|
| 476 |
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, delete_func); |
| 477 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetPipeBufAddr(pipeBufAddrParams), delete_func); |
| 478 |
|
| 479 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpPipeBufAddrCmd(&cmdBuffer, pipeBufAddrParams), delete_func); |
| 480 |
|
| 481 |
MOS_Delete(pipeBufAddrParams); |
| 482 |
} |
| 483 |
|
| 484 |
// set HCP_IND_OBJ_BASE_ADDR_STATE values |
| 485 |
MHW_VDBOX_IND_OBJ_BASE_ADDR_PARAMS indObjBaseAddrParams; |
| 486 |
MOS_ZeroMemory(&indObjBaseAddrParams, sizeof(indObjBaseAddrParams)); |
| 487 |
indObjBaseAddrParams.Mode = m_mode; |
| 488 |
indObjBaseAddrParams.presMvObjectBuffer = &m_resMbCodeSurface; |
| 489 |
indObjBaseAddrParams.dwMvObjectOffset = m_mvOffset; |
| 490 |
indObjBaseAddrParams.dwMvObjectSize = m_mbCodeSize - m_mvOffset; |
| 491 |
indObjBaseAddrParams.presPakBaseObjectBuffer = &m_resBitstreamBuffer; |
| 492 |
indObjBaseAddrParams.dwPakBaseObjectSize = m_bitstreamUpperBound; |
| 493 |
indObjBaseAddrParams.presProbabilityDeltaBuffer = &m_resProbabilityDeltaBuffer; |
| 494 |
indObjBaseAddrParams.dwProbabilityDeltaSize = 29 * CODECHAL_CACHELINE_SIZE; |
| 495 |
indObjBaseAddrParams.presCompressedHeaderBuffer = &m_resCompressedHeaderBuffer; |
| 496 |
indObjBaseAddrParams.dwCompressedHeaderSize = 32 * CODECHAL_CACHELINE_SIZE; |
| 497 |
indObjBaseAddrParams.presProbabilityCounterBuffer = &m_resProbabilityCounterBuffer; |
| 498 |
indObjBaseAddrParams.dwProbabilityCounterSize = 193 * CODECHAL_CACHELINE_SIZE; |
| 499 |
indObjBaseAddrParams.presTileRecordBuffer = &m_resTileRecordStrmOutBuffer; |
| 500 |
indObjBaseAddrParams.dwTileRecordSize = m_picSizeInSb * CODECHAL_CACHELINE_SIZE; |
| 501 |
indObjBaseAddrParams.presCuStatsBuffer = &m_resCuStatsStrmOutBuffer; |
| 502 |
indObjBaseAddrParams.dwCuStatsSize = MOS_ALIGN_CEIL(m_picSizeInSb * 64 * 8, CODECHAL_CACHELINE_SIZE); |
| 503 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpIndObjBaseAddrCmd(&cmdBuffer, &indObjBaseAddrParams)); |
| 504 |
|
| 505 |
// Using picstate zero with updated QP and LF deltas by HuC for repak, irrespective of how many Pak passes were run in multi-pass mode. |
| 506 |
MHW_BATCH_BUFFER secondLevelBatchBuffer; |
| 507 |
MOS_ZeroMemory(&secondLevelBatchBuffer, sizeof(secondLevelBatchBuffer)); |
| 508 |
secondLevelBatchBuffer.dwOffset = (m_numPasses > 0) ? CODECHAL_ENCODE_VP9_PIC_STATE_BUFFER_SIZE_PER_PASS * (m_currPass % m_numPasses) : 0; |
| 509 |
secondLevelBatchBuffer.bSecondLevel = true; |
| 510 |
//As Huc is disabled for Ref frame scaling, use the ReadBuffer |
| 511 |
secondLevelBatchBuffer.OsResource = m_brcBuffers.resPicStateBrcWriteHucReadBuffer; |
| 512 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd( |
| 513 |
&cmdBuffer, |
| 514 |
&secondLevelBatchBuffer)); |
| 515 |
|
| 516 |
// HCP_VP9_SEGMENT_STATE |
| 517 |
uint8_t segmentCount = (m_vp9PicParams->PicFlags.fields.segmentation_enabled) ? CODEC_VP9_MAX_SEGMENTS : 1; |
| 518 |
|
| 519 |
MHW_VDBOX_VP9_SEGMENT_STATE segmentState; |
| 520 |
MOS_ZeroMemory(&segmentState, sizeof(segmentState)); |
| 521 |
segmentState.Mode = m_mode; |
| 522 |
segmentState.pVp9EncodeSegmentParams = m_vp9SegmentParams; |
| 523 |
segmentState.ucQPIndexLumaAC = m_vp9PicParams->LumaACQIndex; |
| 524 |
|
| 525 |
// For BRC with segmentation, seg state commands for PAK are copied from BRC seg state buffer |
| 526 |
// For CQP or BRC with no segmentation, PAK still needs seg state commands and driver prepares those commands. |
| 527 |
segmentState.pbSegStateBufferPtr = nullptr; // Set this to nullptr, for commands to be prepared by driver |
| 528 |
segmentState.pcucLfQpLookup = &LF_VALUE_QP_LOOKUP[0]; |
| 529 |
for (uint8_t i = 0; i < segmentCount; i++) |
| 530 |
{ |
| 531 |
segmentState.ucCurrentSegmentId = i; |
| 532 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpVp9SegmentStateCmd(&cmdBuffer, nullptr, &segmentState)); |
| 533 |
} |
| 534 |
|
| 535 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, &cmdBuffer, 0); |
| 536 |
|
| 537 |
return eStatus; |
| 538 |
} |
| 539 |
MOS_STATUS CodechalVdencVp9StateG12::ExecuteDysSliceLevel() |
| 540 |
{ |
| 541 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 542 |
|
| 543 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 544 |
|
| 545 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_nalUnitParams); |
| 546 |
|
| 547 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 548 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 549 |
|
| 550 |
MHW_BATCH_BUFFER secondLevelBatchBuffer; |
| 551 |
MOS_ZeroMemory(&secondLevelBatchBuffer, sizeof(secondLevelBatchBuffer)); |
| 552 |
secondLevelBatchBuffer.dwOffset = 0; |
| 553 |
secondLevelBatchBuffer.bSecondLevel = true; |
| 554 |
if (!m_hucEnabled) |
| 555 |
{ |
| 556 |
secondLevelBatchBuffer.OsResource = m_resHucPakInsertUncompressedHeaderReadBuffer[m_currRecycledBufIdx]; |
| 557 |
} |
| 558 |
else |
| 559 |
{ |
| 560 |
secondLevelBatchBuffer.OsResource = m_resHucPakInsertUncompressedHeaderWriteBuffer; |
| 561 |
} |
| 562 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd( |
| 563 |
&cmdBuffer, |
| 564 |
&secondLevelBatchBuffer)); |
| 565 |
|
| 566 |
// Setup Tile level PAK commands |
| 567 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_tileParams); |
| 568 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalVdencVp9StateG12::SetTileData()); |
| 569 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(static_cast<MhwVdboxHcpInterfaceG12 *>(m_hcpInterface)->AddHcpTileCodingCmd(&cmdBuffer, &m_tileParams[0])); |
| 570 |
|
| 571 |
//Reset Frame Tracking header for this submission as this is not the last submission |
| 572 |
bool isFrameTrackingHeaderSet = cmdBuffer.Attributes.bEnableMediaFrameTracking; |
| 573 |
cmdBuffer.Attributes.bEnableMediaFrameTracking = false; |
| 574 |
|
| 575 |
MOS_ZeroMemory(&secondLevelBatchBuffer, sizeof(MHW_BATCH_BUFFER)); |
| 576 |
secondLevelBatchBuffer.OsResource = m_resMbCodeSurface; |
| 577 |
secondLevelBatchBuffer.dwOffset = 0; |
| 578 |
secondLevelBatchBuffer.bSecondLevel = true; |
| 579 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd(&cmdBuffer, &secondLevelBatchBuffer)); |
| 580 |
|
| 581 |
MHW_VDBOX_VD_PIPE_FLUSH_PARAMS vdPipelineFlushParams; |
| 582 |
MOS_ZeroMemory(&vdPipelineFlushParams, sizeof(vdPipelineFlushParams)); |
| 583 |
// MFXPipeDone should not be set for tail insertion |
| 584 |
vdPipelineFlushParams.Flags.bWaitDoneMFX = |
| 585 |
(m_lastPicInStream || m_lastPicInSeq) ? 0 : 1; |
| 586 |
vdPipelineFlushParams.Flags.bWaitDoneHEVC = 1; |
| 587 |
vdPipelineFlushParams.Flags.bFlushHEVC = 1; |
| 588 |
vdPipelineFlushParams.Flags.bWaitDoneVDCmdMsgParser = 1; |
| 589 |
|
| 590 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdPipelineFlushCmd(&cmdBuffer, &vdPipelineFlushParams)); |
| 591 |
|
| 592 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 593 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 594 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(&cmdBuffer, &flushDwParams)); |
| 595 |
|
| 596 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EndStatusReport(&cmdBuffer, CODECHAL_NUM_MEDIA_STATES)); |
| 597 |
|
| 598 |
if (!m_scalableMode) |
| 599 |
{ |
| 600 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReadHcpStatus(&cmdBuffer)); |
| 601 |
} |
| 602 |
|
| 603 |
if (m_currPass >= (m_numPasses - 1)) // Last pass and the one before last |
| 604 |
{ |
| 605 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd(&cmdBuffer, nullptr)); |
| 606 |
} |
| 607 |
|
| 608 |
std::string currPassName = "PAK_PASS_DYS" + std::to_string((int)m_currPass); |
| 609 |
CODECHAL_DEBUG_TOOL(CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCmdBuffer( |
| 610 |
&cmdBuffer, |
| 611 |
CODECHAL_NUM_MEDIA_STATES, |
| 612 |
currPassName.data()))); |
| 613 |
|
| 614 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReturnCommandBuffer(&cmdBuffer)); |
| 615 |
|
| 616 |
if (m_waitForEnc && |
| 617 |
!Mos_ResourceIsNull(&m_resSyncObjectRenderContextInUse)) |
| 618 |
{ |
| 619 |
MOS_SYNC_PARAMS syncParams = g_cInitSyncParams; |
| 620 |
syncParams.GpuContext = m_videoContext; |
| 621 |
syncParams.presSyncResource = &m_resSyncObjectRenderContextInUse; |
| 622 |
|
| 623 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineWait(m_osInterface, &syncParams)); |
| 624 |
m_waitForEnc = false; |
| 625 |
} |
| 626 |
|
| 627 |
if (m_currPass >= (m_numPasses - 1)) // Last pass and the one before last |
| 628 |
{ |
| 629 |
bool renderFlags; |
| 630 |
|
| 631 |
renderFlags = m_videoContextUsesNullHw; |
| 632 |
|
| 633 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SubmitCommandBuffer(&cmdBuffer, renderFlags)); |
| 634 |
} |
| 635 |
|
| 636 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 637 |
cmdBuffer.Attributes.bEnableMediaFrameTracking = isFrameTrackingHeaderSet; |
| 638 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReturnCommandBuffer(&cmdBuffer)); |
| 639 |
|
| 640 |
CODECHAL_DEBUG_TOOL( |
| 641 |
if (m_vp9PicParams->PicFlags.fields.segmentation_enabled) { |
| 642 |
//CodecHal_DbgDumpEncodeVp9SegmentStreamout(m_debugInterface, m_encoder); |
| 643 |
//m_debugInterface->DumpBuffer( |
| 644 |
// (PCODECHAL_ENCODE_VP9_STATE)pvStandardState.resVdencSegmentMapStreamOut, |
| 645 |
// CodechalDbgAttr::attrOutput, |
| 646 |
// "SegMap_Out", |
| 647 |
// CODECHAL_CACHELINE_SIZE * MOS_ROUNDUP_DIVIDE(pEncoder->dwFrameHeight, 64) * MOS_ROUNDUP_DIVIDE(pEncoder->dwFrameWidth, 64), |
| 648 |
// 0, |
| 649 |
// CODECHAL_MEDIA_STATE_VP9_PAK_LUMA_RECON); |
| 650 |
} if (m_mmcState) { |
| 651 |
m_mmcState->UpdateUserFeatureKey(&m_reconSurface); |
| 652 |
}); |
| 653 |
|
| 654 |
return eStatus; |
| 655 |
} |
| 656 |
|
| 657 |
MOS_STATUS CodechalVdencVp9StateG12::InitKernelStates() |
| 658 |
{ |
| 659 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 660 |
|
| 661 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 662 |
|
| 663 |
#if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE) |
| 664 |
m_kernelBase = (uint8_t*)IGCODECKRN_G12; |
| 665 |
#endif |
| 666 |
|
| 667 |
// KUID for HME + DS + SW SCOREBOARD Kernel |
| 668 |
m_kuidCommon = IDR_CODEC_HME_DS_SCOREBOARD_KERNEL; |
| 669 |
|
| 670 |
#if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE) |
| 671 |
// DYS |
| 672 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitKernelStateDys()); |
| 673 |
|
| 674 |
// SHME |
| 675 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitKernelStateMe()); |
| 676 |
#endif |
| 677 |
|
| 678 |
return eStatus; |
| 679 |
} |
| 680 |
|
| 681 |
uint32_t CodechalVdencVp9StateG12::GetMaxBtCount() |
| 682 |
{ |
| 683 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 684 |
|
| 685 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 686 |
uint32_t maxBtCount = 0; |
| 687 |
|
| 688 |
#if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE) |
| 689 |
if (m_hmeSupported) |
| 690 |
{ |
| 691 |
uint32_t scalingBtCount = 0; |
| 692 |
uint32_t numKernelsToLoad = m_interlacedFieldDisabled ? 1 : CODEC_NUM_FIELDS_PER_FRAME; |
| 693 |
uint16_t btIdxAlignment = m_stateHeapInterface->pStateHeapInterface->GetBtIdxAlignment(); |
| 694 |
for (uint32_t krnStateIdx = 0; krnStateIdx < numKernelsToLoad; krnStateIdx++) |
| 695 |
{ |
| 696 |
scalingBtCount += MOS_ALIGN_CEIL( |
| 697 |
m_scaling4xKernelStates[krnStateIdx].KernelParams.iBTCount, |
| 698 |
btIdxAlignment); |
| 699 |
} |
| 700 |
uint32_t meBtCount = 0; |
| 701 |
// 4xME + Streamin kernel btcount |
| 702 |
meBtCount += MOS_ALIGN_CEIL(m_meKernelStates[CODECHAL_ENCODE_ME_IDX_VDENC].KernelParams.iBTCount, btIdxAlignment); |
| 703 |
|
| 704 |
//16xME streamin kernel count added to ME count and scaling kernel 16x added to scaling count |
| 705 |
if (m_16xMeSupported) |
| 706 |
{ |
| 707 |
meBtCount += MOS_ALIGN_CEIL(m_meKernelStates[CODECHAL_ENCODE_ME_IDX_P].KernelParams.iBTCount, btIdxAlignment); |
| 708 |
for (uint32_t krnStateIdx = 0; krnStateIdx < numKernelsToLoad; krnStateIdx++) |
| 709 |
{ |
| 710 |
scalingBtCount += MOS_ALIGN_CEIL( |
| 711 |
m_scaling4xKernelStates[krnStateIdx].KernelParams.iBTCount, |
| 712 |
btIdxAlignment); |
| 713 |
} |
| 714 |
} |
| 715 |
maxBtCount = scalingBtCount + meBtCount; |
| 716 |
} |
| 717 |
#endif |
| 718 |
|
| 719 |
return maxBtCount; |
| 720 |
} |
| 721 |
|
| 722 |
// DYS kernel state init |
| 723 |
MOS_STATUS CodechalVdencVp9StateG12::InitKernelStateDys() |
| 724 |
{ |
| 725 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 726 |
|
| 727 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 728 |
|
| 729 |
#if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE) |
| 730 |
uint32_t combinedKernelSize = 0; |
| 731 |
uint8_t* binary = nullptr; |
| 732 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalGetKernelBinaryAndSize( |
| 733 |
(uint8_t*)IGCODECKRN_G12, |
| 734 |
m_kuidCommon, |
| 735 |
&binary, |
| 736 |
&combinedKernelSize)); |
| 737 |
|
| 738 |
uint32_t kernelSize = combinedKernelSize; |
| 739 |
CODECHAL_KERNEL_HEADER currKrnHeader; |
| 740 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommonKernelHeaderAndSizeG12( |
| 741 |
binary, |
| 742 |
ENC_DYS, |
| 743 |
0, |
| 744 |
&currKrnHeader, |
| 745 |
&kernelSize)); |
| 746 |
|
| 747 |
PMHW_KERNEL_STATE kernelState = &m_dysKernelState; |
| 748 |
kernelState->KernelParams.iBTCount = MOS_ALIGN_CEIL(m_dysNumSurfaces, m_stateHeapInterface->pStateHeapInterface->GetBtIdxAlignment()); |
| 749 |
kernelState->KernelParams.iThreadCount = m_renderEngineInterface->GetHwCaps()->dwMaxThreads; |
| 750 |
kernelState->KernelParams.iCurbeLength = MOS_ALIGN_CEIL(m_dysStaticDataSize, m_stateHeapInterface->pStateHeapInterface->GetCurbeAlignment()); |
| 751 |
kernelState->KernelParams.iBlockWidth = CODECHAL_MACROBLOCK_WIDTH;// just assign this to 16, the block resolution for the kernel is decided when its launched depending on the std. |
| 752 |
kernelState->KernelParams.iBlockHeight = CODECHAL_MACROBLOCK_HEIGHT;// just assign this to 16, the block resolution for the kernel is decided when its launched depending on the std. |
| 753 |
kernelState->KernelParams.iIdCount = 1; |
| 754 |
kernelState->KernelParams.iSamplerCount = 1; |
| 755 |
kernelState->KernelParams.iSamplerLength = m_stateHeapInterface->pStateHeapInterface->GetSizeofSamplerStateAvs(); |
| 756 |
|
| 757 |
kernelState->dwCurbeOffset = m_stateHeapInterface->pStateHeapInterface->GetSizeofCmdInterfaceDescriptorData(); |
| 758 |
kernelState->dwSamplerOffset = MOS_ALIGN_CEIL(kernelState->dwCurbeOffset + kernelState->KernelParams.iCurbeLength, MHW_SAMPLER_STATE_AVS_ALIGN_G9); |
| 759 |
kernelState->KernelParams.pBinary = |
| 760 |
binary + |
| 761 |
(currKrnHeader.KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT); |
| 762 |
kernelState->KernelParams.iSize = kernelSize; |
| 763 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnCalculateSshAndBtSizesRequested( |
| 764 |
m_stateHeapInterface, |
| 765 |
kernelState->KernelParams.iBTCount, |
| 766 |
&kernelState->dwSshSize, |
| 767 |
&kernelState->dwBindingTableSize)); |
| 768 |
|
| 769 |
m_dysDshSize = kernelState->dwSamplerOffset + |
| 770 |
MOS_ALIGN_CEIL(kernelState->KernelParams.iSamplerLength * kernelState->KernelParams.iSamplerCount, MHW_SAMPLER_STATE_AVS_ALIGN); |
| 771 |
|
| 772 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->MhwInitISH(m_stateHeapInterface, kernelState)); |
| 773 |
#endif |
| 774 |
|
| 775 |
return eStatus; |
| 776 |
} |
| 777 |
|
| 778 |
MOS_STATUS CodechalVdencVp9StateG12::SetupSegmentationStreamIn() |
| 779 |
{ |
| 780 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 781 |
|
| 782 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 783 |
|
| 784 |
if (!m_segmentMapProvided && !m_hmeEnabled) // If we're not going to use the streamin surface leave now |
| 785 |
{ |
| 786 |
return eStatus; |
| 787 |
} |
| 788 |
|
| 789 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_osInterface); |
| 790 |
MOS_LOCK_PARAMS lockFlagsWriteOnly; |
| 791 |
MOS_ZeroMemory(&lockFlagsWriteOnly, sizeof(MOS_LOCK_PARAMS)); |
| 792 |
lockFlagsWriteOnly.WriteOnly = 1; |
| 793 |
|
| 794 |
MOS_LOCK_PARAMS lockFlagsReadOnly; |
| 795 |
MOS_ZeroMemory(&lockFlagsReadOnly, sizeof(MOS_LOCK_PARAMS)); |
| 796 |
lockFlagsReadOnly.ReadOnly = 1; |
| 797 |
|
| 798 |
mhw_vdbox_vdenc_g12_X::VDENC_HEVC_VP9_STREAMIN_STATE_CMD * |
| 799 |
streamIn = (mhw_vdbox_vdenc_g12_X::VDENC_HEVC_VP9_STREAMIN_STATE_CMD *)m_osInterface->pfnLockResource( |
| 800 |
m_osInterface, |
| 801 |
&m_resVdencStreamInBuffer[m_currRecycledBufIdx], |
| 802 |
&lockFlagsWriteOnly); |
| 803 |
CODECHAL_ENCODE_CHK_NULL_RETURN(streamIn); |
| 804 |
|
| 805 |
// align to cache line size is OK since streamin state is padded to cacheline size - HW uses cacheline size to read, not command size |
| 806 |
uint32_t blockWidth = MOS_ALIGN_CEIL(m_frameWidth, CODEC_VP9_SUPER_BLOCK_WIDTH) / 32; |
| 807 |
uint32_t blockHeight = MOS_ALIGN_CEIL(m_frameHeight, CODEC_VP9_SUPER_BLOCK_HEIGHT) / 32; |
| 808 |
uint32_t streamInSize = blockHeight * blockWidth * CODECHAL_CACHELINE_SIZE; |
| 809 |
MOS_ZeroMemory(streamIn, streamInSize); |
| 810 |
|
| 811 |
// If segment map isn't provided then we unlock surface and exit function here. |
| 812 |
// Reason why check isn't done before function call is to take advantage of the fact that |
| 813 |
// we need the surface locked here if seg map is provided and we want it 0'd either way. |
| 814 |
// This saves us from doing 2 locks on this buffer per frame. |
| 815 |
if (!m_segmentMapProvided) |
| 816 |
{ |
| 817 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnUnlockResource( |
| 818 |
m_osInterface, |
| 819 |
&m_resVdencStreamInBuffer[m_currRecycledBufIdx])); |
| 820 |
return eStatus; |
| 821 |
} |
| 822 |
|
| 823 |
char *data = (char *)m_osInterface->pfnLockResource( |
| 824 |
m_osInterface, |
| 825 |
&m_mbSegmentMapSurface.OsResource, |
| 826 |
&lockFlagsReadOnly); |
| 827 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 828 |
|
| 829 |
// Rasterization is done within a tile and then for each tile within the frame in raster order. |
| 830 |
if (m_isTilingSupported) |
| 831 |
{ |
| 832 |
uint32_t numTileColumns = (1 << m_vp9PicParams->log2_tile_columns); |
| 833 |
uint32_t numTileRows = (1 << m_vp9PicParams->log2_tile_rows); |
| 834 |
uint32_t numTiles = numTileColumns * numTileRows; |
| 835 |
uint32_t currTileStartX64Aligned = 0, dwCurrTileStartY64Aligned = 0; //Set tile Y coordinate 0 |
| 836 |
m_32BlocksRasterized = 0; //Count of rasterized blocks for this frame |
| 837 |
uint32_t tileX = 0; |
| 838 |
uint32_t tileY = 0; |
| 839 |
for (uint32_t tileIdx = 0; tileIdx < numTiles; tileIdx++) |
| 840 |
{ |
| 841 |
tileX = tileIdx % numTileColumns; //Current tile column position |
| 842 |
tileY = tileIdx / numTileColumns; //Current tile row position |
| 843 |
|
| 844 |
currTileStartX64Aligned = ((tileX * m_picWidthInSb) >> m_vp9PicParams->log2_tile_columns) * CODEC_VP9_SUPER_BLOCK_WIDTH; |
| 845 |
dwCurrTileStartY64Aligned = ((tileY * m_picHeightInSb) >> m_vp9PicParams->log2_tile_rows) * CODEC_VP9_SUPER_BLOCK_HEIGHT; |
| 846 |
|
| 847 |
uint32_t tileWidth64Aligned = (((tileX == (numTileColumns - 1)) ? m_picWidthInSb : (((tileX + 1) * m_picWidthInSb) >> m_vp9PicParams->log2_tile_columns)) * |
| 848 |
CODEC_VP9_SUPER_BLOCK_WIDTH) - |
| 849 |
currTileStartX64Aligned; |
| 850 |
|
| 851 |
uint32_t tileHeight64Aligned = (((tileY == (numTileRows - 1)) ? m_picHeightInSb : (((tileY + 1) * m_picHeightInSb) >> m_vp9PicParams->log2_tile_rows)) * |
| 852 |
CODEC_VP9_SUPER_BLOCK_HEIGHT) - |
| 853 |
dwCurrTileStartY64Aligned; |
| 854 |
|
| 855 |
// last tile col raw width and raw height not necessarily 64 aligned, use this length to duplicate values from segmap for empty padding blocks in last tiles. |
| 856 |
uint32_t lastTileColWidth = (tileX == (numTileColumns - 1)) ? (m_frameWidth - currTileStartX64Aligned) : tileWidth64Aligned; |
| 857 |
uint32_t lastTileRowHeight = (tileY == (numTileRows - 1)) ? (m_frameHeight - dwCurrTileStartY64Aligned) : tileHeight64Aligned; |
| 858 |
|
| 859 |
uint32_t tileWidth = (tileX == (numTileColumns - 1)) ? lastTileColWidth : tileWidth64Aligned; |
| 860 |
uint32_t tileHeight = (tileY == (numTileRows - 1)) ? lastTileRowHeight : tileHeight64Aligned; |
| 861 |
|
| 862 |
// Recreate the mapbuffer and remap it if, for this frame, tile height and width have changed from previous tile |
| 863 |
// which was processed from this frame or previous, |
| 864 |
// or if map buffer is created for previous frame and tile map has changed from previous frame (numtilerows and cols) |
| 865 |
if (!m_mapBuffer || |
| 866 |
tileHeight != m_segStreamInHeight || |
| 867 |
tileWidth != m_segStreamInWidth || |
| 868 |
numTileColumns != m_tileParams[tileIdx].NumOfTileColumnsInFrame || |
| 869 |
m_tileParams[tileIdx].NumOfTilesInFrame != numTiles) |
| 870 |
{ |
| 871 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitZigZagToRasterLUTPerTile(tileHeight, |
| 872 |
tileWidth, |
| 873 |
dwCurrTileStartY64Aligned, |
| 874 |
currTileStartX64Aligned)); |
| 875 |
} |
| 876 |
m_tileParams[tileIdx].NumOfTileColumnsInFrame = numTileColumns; |
| 877 |
m_tileParams[tileIdx].NumOfTilesInFrame = numTiles; |
| 878 |
} |
| 879 |
} |
| 880 |
|
| 881 |
uint32_t dwPitch = m_mbSegmentMapSurface.dwPitch; |
| 882 |
if (m_osInterface->pfnGetResType(&m_mbSegmentMapSurface.OsResource) == MOS_GFXRES_BUFFER) |
| 883 |
{ |
| 884 |
//application can send 1D or 2D buffer, based on that change the pitch to correctly access the map buffer |
| 885 |
//driver reads the seg ids from the buffer for each 16x16 block. Reads 4 values for each 32x32 block |
| 886 |
dwPitch = MOS_ALIGN_CEIL(m_frameWidth, CODECHAL_MACROBLOCK_WIDTH) / CODECHAL_MACROBLOCK_WIDTH; |
| 887 |
} |
| 888 |
// set seg ID's of streamin states |
| 889 |
for (uint32_t i = 0; i < blockHeight * blockWidth; ++i) |
| 890 |
{ |
| 891 |
uint32_t addrOffset = CalculateBufferOffset( |
| 892 |
m_mapBuffer[i], |
| 893 |
m_frameWidth, |
| 894 |
m_vp9PicParams->PicFlags.fields.seg_id_block_size, |
| 895 |
dwPitch); |
| 896 |
uint32_t segId = *(data + addrOffset); |
| 897 |
streamIn[i].DW7.SegidEnable = 1; |
| 898 |
streamIn[i].DW7.Segid32X32016X1603Vp9Only = segId | (segId << 4) | (segId << 8) | (segId << 12); |
| 899 |
|
| 900 |
// TU functions copied from there. |
| 901 |
streamIn[i].DW0.Maxtusize = 3; |
| 902 |
streamIn[i].DW0.Maxcusize = 3; |
| 903 |
|
| 904 |
// For InterFrames we change the CUsize to 32x32 if we have sub 32 blocks with different segids in superblock |
| 905 |
if ((i % 4) == 3 && m_pictureCodingType == P_TYPE) |
| 906 |
{ |
| 907 |
if (!(streamIn[i - 3].DW7.Segid32X32016X1603Vp9Only == streamIn[i - 2].DW7.Segid32X32016X1603Vp9Only && |
| 908 |
streamIn[i - 2].DW7.Segid32X32016X1603Vp9Only == streamIn[i - 1].DW7.Segid32X32016X1603Vp9Only && |
| 909 |
streamIn[i - 1].DW7.Segid32X32016X1603Vp9Only == streamIn[i].DW7.Segid32X32016X1603Vp9Only)) |
| 910 |
{ |
| 911 |
streamIn[i - 3].DW0.Maxcusize = streamIn[i - 2].DW0.Maxcusize = streamIn[i - 1].DW0.Maxcusize = streamIn[i].DW0.Maxcusize = 2; |
| 912 |
} |
| 913 |
} |
| 914 |
|
| 915 |
streamIn[i].DW0.Numimepredictors = CODECHAL_VDENC_NUMIMEPREDICTORS; |
| 916 |
|
| 917 |
switch (m_vp9SeqParams->TargetUsage) |
| 918 |
{ |
| 919 |
case 1: // Quality mode |
| 920 |
case 2: |
| 921 |
case 4: // Normal mode |
| 922 |
streamIn[i].DW6.Nummergecandidatecu8X8 = 1; |
| 923 |
streamIn[i].DW6.Nummergecandidatecu16X16 = 2; |
| 924 |
streamIn[i].DW6.Nummergecandidatecu32X32 = 3; |
| 925 |
streamIn[i].DW6.Nummergecandidatecu64X64 = 4; |
| 926 |
break; |
| 927 |
case 7: // Speed mode |
| 928 |
streamIn[i].DW0.Numimepredictors = CODECHAL_VDENC_NUMIMEPREDICTORS_SPEED; |
| 929 |
streamIn[i].DW6.Nummergecandidatecu8X8 = 0; |
| 930 |
streamIn[i].DW6.Nummergecandidatecu16X16 = 2; |
| 931 |
streamIn[i].DW6.Nummergecandidatecu32X32 = 2; |
| 932 |
streamIn[i].DW6.Nummergecandidatecu64X64 = 2; |
| 933 |
break; |
| 934 |
default: |
| 935 |
MHW_ASSERTMESSAGE("Invalid TU provided!"); |
| 936 |
return MOS_STATUS_INVALID_PARAMETER; |
| 937 |
} |
| 938 |
} |
| 939 |
|
| 940 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnUnlockResource( |
| 941 |
m_osInterface, |
| 942 |
&m_mbSegmentMapSurface.OsResource)); |
| 943 |
|
| 944 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnUnlockResource( |
| 945 |
m_osInterface, |
| 946 |
&m_resVdencStreamInBuffer[m_currRecycledBufIdx])); |
| 947 |
|
| 948 |
return eStatus; |
| 949 |
} |
| 950 |
|
| 951 |
MOS_STATUS CodechalVdencVp9StateG12::GetSystemPipeNumberCommon() |
| 952 |
{ |
| 953 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 954 |
MOS_STATUS statusKey = MOS_STATUS_SUCCESS; |
| 955 |
|
| 956 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 957 |
|
| 958 |
MOS_USER_FEATURE_VALUE_DATA userFeatureData; |
| 959 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 960 |
statusKey = MOS_UserFeature_ReadValue_ID( |
| 961 |
NULL, |
| 962 |
__MEDIA_USER_FEATURE_VALUE_ENCODE_DISABLE_SCALABILITY, |
| 963 |
&userFeatureData, |
| 964 |
m_osInterface->pOsContext); |
| 965 |
|
| 966 |
bool disableScalability = m_hwInterface->IsDisableScalability(); |
| 967 |
if (statusKey == MOS_STATUS_SUCCESS) |
| 968 |
{ |
| 969 |
disableScalability = userFeatureData.i32Data ? true : false; |
| 970 |
} |
| 971 |
|
| 972 |
MEDIA_SYSTEM_INFO *gtSystemInfo = m_gtSystemInfo; |
| 973 |
|
| 974 |
if (gtSystemInfo && disableScalability == false) |
| 975 |
{ |
| 976 |
// Both VE mode and media solo mode should be able to get the VDBOX number via the same interface |
| 977 |
m_numVdbox = (uint8_t)(gtSystemInfo->VDBoxInfo.NumberOfVDBoxEnabled); |
| 978 |
} |
| 979 |
else |
| 980 |
{ |
| 981 |
m_numVdbox = 1; |
| 982 |
} |
| 983 |
|
| 984 |
return eStatus; |
| 985 |
} |
| 986 |
|
| 987 |
MOS_STATUS CodechalVdencVp9StateG12::InitKernelStateMe() |
| 988 |
{ |
| 989 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 990 |
|
| 991 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 992 |
|
| 993 |
#if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE) |
| 994 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_renderEngineInterface->GetHwCaps()); |
| 995 |
|
| 996 |
uint32_t combinedKernelSize = 0; |
| 997 |
uint8_t* binary = nullptr; |
| 998 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalGetKernelBinaryAndSize( |
| 999 |
m_kernelBase, |
| 1000 |
m_kuidCommon, |
| 1001 |
&binary, |
| 1002 |
&combinedKernelSize)); |
| 1003 |
|
| 1004 |
for (uint32_t krnStateIdx = 0; krnStateIdx < 2; krnStateIdx++) |
| 1005 |
{ |
| 1006 |
CODECHAL_KERNEL_HEADER currKrnHeader; |
| 1007 |
PMHW_KERNEL_STATE kernelStatePtr = &m_meKernelStates[krnStateIdx]; |
| 1008 |
uint32_t kernelSize = combinedKernelSize; |
| 1009 |
EncOperation encOperation = (krnStateIdx > 0 && m_vdencEnabled) ? |
| 1010 |
(m_useNonLegacyStreamin ? VDENC_STREAMIN_HEVC : VDENC_ME) : ENC_ME; |
| 1011 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommonKernelHeaderAndSizeG12( |
| 1012 |
binary, |
| 1013 |
encOperation, |
| 1014 |
(encOperation != ENC_ME) ? 0 : krnStateIdx, |
| 1015 |
&currKrnHeader, |
| 1016 |
&kernelSize)); |
| 1017 |
|
| 1018 |
kernelStatePtr->KernelParams.iBTCount = CODECHAL_ENCODE_ME_NUM_SURFACES_G12; |
| 1019 |
kernelStatePtr->KernelParams.iThreadCount = m_renderEngineInterface->GetHwCaps()->dwMaxThreads; |
| 1020 |
kernelStatePtr->KernelParams.iCurbeLength = sizeof(MeCurbe); |
| 1021 |
kernelStatePtr->KernelParams.iBlockWidth = CODECHAL_MACROBLOCK_WIDTH; |
| 1022 |
kernelStatePtr->KernelParams.iBlockHeight = CODECHAL_MACROBLOCK_HEIGHT; |
| 1023 |
kernelStatePtr->KernelParams.iIdCount = 1; |
| 1024 |
|
| 1025 |
kernelStatePtr->dwCurbeOffset = m_stateHeapInterface->pStateHeapInterface->GetSizeofCmdInterfaceDescriptorData(); |
| 1026 |
kernelStatePtr->KernelParams.pBinary = binary + (currKrnHeader.KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT); |
| 1027 |
kernelStatePtr->KernelParams.iSize = kernelSize; |
| 1028 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnCalculateSshAndBtSizesRequested( |
| 1029 |
m_stateHeapInterface, |
| 1030 |
kernelStatePtr->KernelParams.iBTCount, |
| 1031 |
&kernelStatePtr->dwSshSize, |
| 1032 |
&kernelStatePtr->dwBindingTableSize)); |
| 1033 |
|
| 1034 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->MhwInitISH(m_stateHeapInterface, kernelStatePtr)); |
| 1035 |
if (m_noMeKernelForPFrame) |
| 1036 |
{ |
| 1037 |
m_meKernelStates[1] = m_meKernelStates[0]; |
| 1038 |
break; |
| 1039 |
} |
| 1040 |
} |
| 1041 |
|
| 1042 |
// Until a better way can be found, maintain old binding table structures |
| 1043 |
MeKernelBindingTable* bindingTable = &m_meBindingTable; |
| 1044 |
bindingTable->dwMEMVDataSurface = CODECHAL_ENCODE_ME_MV_DATA_SURFACE_G12; |
| 1045 |
bindingTable->dw16xMEMVDataSurface = CODECHAL_ENCODE_16xME_MV_DATA_SURFACE_G12; |
| 1046 |
bindingTable->dw32xMEMVDataSurface = CODECHAL_ENCODE_32xME_MV_DATA_SURFACE_G12; |
| 1047 |
bindingTable->dwMEDist = CODECHAL_ENCODE_ME_DISTORTION_SURFACE_G12; |
| 1048 |
bindingTable->dwMEBRCDist = CODECHAL_ENCODE_ME_BRC_DISTORTION_G12; |
| 1049 |
bindingTable->dwMECurrForFwdRef = CODECHAL_ENCODE_ME_CURR_FOR_FWD_REF_G12; |
| 1050 |
bindingTable->dwMEFwdRefPicIdx[0] = CODECHAL_ENCODE_ME_FWD_REF_IDX0_G12; |
| 1051 |
bindingTable->dwMEFwdRefPicIdx[1] = CODECHAL_ENCODE_ME_FWD_REF_IDX1_G12; |
| 1052 |
bindingTable->dwMEFwdRefPicIdx[2] = CODECHAL_ENCODE_ME_FWD_REF_IDX2_G12; |
| 1053 |
bindingTable->dwMEFwdRefPicIdx[3] = CODECHAL_ENCODE_ME_FWD_REF_IDX3_G12; |
| 1054 |
bindingTable->dwMEFwdRefPicIdx[4] = CODECHAL_ENCODE_ME_FWD_REF_IDX4_G12; |
| 1055 |
bindingTable->dwMEFwdRefPicIdx[5] = CODECHAL_ENCODE_ME_FWD_REF_IDX5_G12; |
| 1056 |
bindingTable->dwMEFwdRefPicIdx[6] = CODECHAL_ENCODE_ME_FWD_REF_IDX6_G12; |
| 1057 |
bindingTable->dwMEFwdRefPicIdx[7] = CODECHAL_ENCODE_ME_FWD_REF_IDX7_G12; |
| 1058 |
bindingTable->dwMECurrForBwdRef = CODECHAL_ENCODE_ME_CURR_FOR_BWD_REF_G12; |
| 1059 |
bindingTable->dwMEBwdRefPicIdx[0] = CODECHAL_ENCODE_ME_BWD_REF_IDX0_G12; |
| 1060 |
bindingTable->dwMEBwdRefPicIdx[1] = CODECHAL_ENCODE_ME_BWD_REF_IDX1_G12; |
| 1061 |
bindingTable->dwVdencStreamInSurface = CODECHAL_ENCODE_ME_VDENC_STREAMIN_OUTPUT_G12; |
| 1062 |
bindingTable->dwVdencStreamInInputSurface = CODECHAL_ENCODE_ME_VDENC_STREAMIN_INPUT_G12; |
| 1063 |
#endif |
| 1064 |
|
| 1065 |
return eStatus; |
| 1066 |
} |
| 1067 |
|
| 1068 |
MOS_STATUS CodechalVdencVp9StateG12::SetCurbeMe( |
| 1069 |
MeCurbeParams* params) |
| 1070 |
{ |
| 1071 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1072 |
|
| 1073 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1074 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pKernelState); |
| 1075 |
|
| 1076 |
CODECHAL_ENCODE_ASSERT(params->TargetUsage <= NUM_TARGET_USAGE_MODES); |
| 1077 |
|
| 1078 |
uint32_t scaleFactor = 0; |
| 1079 |
bool useMvFromPrevStep = false, writeDistortions = false; |
| 1080 |
uint8_t mvShiftFactor = 0, prevMvReadPosFactor = 0; |
| 1081 |
bool framePicture = CodecHal_PictureIsFrame(params->CurrOriginalPic); |
| 1082 |
char qpPrimeY = (params->pic_init_qp_minus26 + 26) + params->slice_qp_delta; |
| 1083 |
|
| 1084 |
switch (params->hmeLvl) |
| 1085 |
{ |
| 1086 |
case HME_LEVEL_32x: |
| 1087 |
useMvFromPrevStep = m_hmeFirstStep; |
| 1088 |
writeDistortions = false; |
| 1089 |
scaleFactor = SCALE_FACTOR_32x; |
| 1090 |
mvShiftFactor = m_mvShiftFactor32x; |
| 1091 |
break; |
| 1092 |
case HME_LEVEL_16x: |
| 1093 |
useMvFromPrevStep = (params->b32xMeEnabled) ? m_hmeFollowingStep : m_hmeFirstStep; |
| 1094 |
writeDistortions = false; |
| 1095 |
scaleFactor = SCALE_FACTOR_16x; |
| 1096 |
mvShiftFactor = m_mvShiftFactor16x; |
| 1097 |
prevMvReadPosFactor = m_prevMvReadPosition16x; |
| 1098 |
break; |
| 1099 |
case HME_LEVEL_4x: |
| 1100 |
useMvFromPrevStep = (params->b16xMeEnabled) ? m_hmeFollowingStep : m_hmeFirstStep; |
| 1101 |
writeDistortions = true; |
| 1102 |
scaleFactor = SCALE_FACTOR_4x; |
| 1103 |
mvShiftFactor = m_mvShiftFactor4x; |
| 1104 |
prevMvReadPosFactor = m_prevMvReadPosition4x; |
| 1105 |
break; |
| 1106 |
default: |
| 1107 |
return MOS_STATUS_INVALID_PARAMETER; |
| 1108 |
} |
| 1109 |
|
| 1110 |
MeCurbe cmd; |
| 1111 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1112 |
&cmd, |
| 1113 |
sizeof(MeCurbe), |
| 1114 |
meCurbeInit, |
| 1115 |
sizeof(MeCurbe))); |
| 1116 |
|
| 1117 |
cmd.DW3.SubPelMode = 3; |
| 1118 |
if (m_fieldScalingOutputInterleaved) |
| 1119 |
{ |
| 1120 |
cmd.DW3.SrcAccess = |
| 1121 |
cmd.DW3.RefAccess = CodecHal_PictureIsField(params->CurrOriginalPic) ? 1 : 0; |
| 1122 |
cmd.DW7.SrcFieldPolarity = CodecHal_PictureIsBottomField(params->CurrOriginalPic) ? 1 : 0; |
| 1123 |
} |
| 1124 |
|
| 1125 |
cmd.DW4.PictureHeightMinus1 = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameFieldHeight / scaleFactor) - 1; |
| 1126 |
cmd.DW4.PictureWidth = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameWidth / scaleFactor); |
| 1127 |
cmd.DW5.QpPrimeY = qpPrimeY; |
| 1128 |
cmd.DW6.WriteDistortions = writeDistortions; |
| 1129 |
cmd.DW6.UseMvFromPrevStep = useMvFromPrevStep; |
| 1130 |
|
| 1131 |
cmd.DW6.SuperCombineDist = m_superCombineDistGeneric[params->TargetUsage]; |
| 1132 |
cmd.DW6.MaxVmvR = (framePicture) ? |
| 1133 |
params->MaxMvLen * 4 : (params->MaxMvLen >> 1) * 4; |
| 1134 |
|
| 1135 |
if (m_pictureCodingType == B_TYPE) |
| 1136 |
{ |
| 1137 |
// This field is irrelevant since we are not using the bi-direct search. |
| 1138 |
cmd.DW1.BiWeight = 32; |
| 1139 |
cmd.DW13.NumRefIdxL1MinusOne = params->num_ref_idx_l1_active_minus1; |
| 1140 |
} |
| 1141 |
|
| 1142 |
if (m_pictureCodingType == P_TYPE || |
| 1143 |
m_pictureCodingType == B_TYPE) |
| 1144 |
{ |
| 1145 |
if (params->hmeLvl == HME_LEVEL_4x && m_useNonLegacyStreamin) |
| 1146 |
{ |
| 1147 |
cmd.DW30.ActualMBHeight = m_frameHeight; |
| 1148 |
cmd.DW30.ActualMBWidth = m_frameWidth; |
| 1149 |
} |
| 1150 |
else if (m_vdencEnabled && m_16xMeSupported) |
| 1151 |
{ |
| 1152 |
cmd.DW30.ActualMBHeight = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameFieldHeight); |
| 1153 |
cmd.DW30.ActualMBWidth = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameWidth); |
| 1154 |
} |
| 1155 |
cmd.DW13.NumRefIdxL0MinusOne = |
| 1156 |
params->num_ref_idx_l0_active_minus1; |
| 1157 |
} |
| 1158 |
|
| 1159 |
cmd.DW13.RefStreaminCost = 5; |
| 1160 |
// This flag is to indicate the ROI source type instead of indicating ROI is enabled or not |
| 1161 |
cmd.DW13.ROIEnable = 0; |
| 1162 |
|
| 1163 |
if (!framePicture) |
| 1164 |
{ |
| 1165 |
if (m_pictureCodingType != I_TYPE) |
| 1166 |
{ |
| 1167 |
cmd.DW14.List0RefID0FieldParity = params->List0RefID0FieldParity; |
| 1168 |
cmd.DW14.List0RefID1FieldParity = params->List0RefID1FieldParity; |
| 1169 |
cmd.DW14.List0RefID2FieldParity = params->List0RefID2FieldParity; |
| 1170 |
cmd.DW14.List0RefID3FieldParity = params->List0RefID3FieldParity; |
| 1171 |
cmd.DW14.List0RefID4FieldParity = params->List0RefID4FieldParity; |
| 1172 |
cmd.DW14.List0RefID5FieldParity = params->List0RefID5FieldParity; |
| 1173 |
cmd.DW14.List0RefID6FieldParity = params->List0RefID6FieldParity; |
| 1174 |
cmd.DW14.List0RefID7FieldParity = params->List0RefID7FieldParity; |
| 1175 |
} |
| 1176 |
if (m_pictureCodingType == B_TYPE) |
| 1177 |
{ |
| 1178 |
cmd.DW14.List1RefID0FieldParity = params->List1RefID0FieldParity; |
| 1179 |
cmd.DW14.List1RefID1FieldParity = params->List1RefID1FieldParity; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
cmd.DW15.MvShiftFactor = mvShiftFactor; |
| 1184 |
cmd.DW15.PrevMvReadPosFactor = prevMvReadPosFactor; |
| 1185 |
|
| 1186 |
// r3 & r4 |
| 1187 |
uint8_t targetUsage = params->TargetUsage; |
| 1188 |
uint8_t meMethod = 0; |
| 1189 |
if (m_pictureCodingType == B_TYPE) |
| 1190 |
{ |
| 1191 |
meMethod = params->pBMEMethodTable ? |
| 1192 |
params->pBMEMethodTable[targetUsage] |
| 1193 |
: m_bMeMethodGeneric[targetUsage]; |
| 1194 |
} |
| 1195 |
else |
| 1196 |
{ |
| 1197 |
meMethod = params->pMEMethodTable ? |
| 1198 |
params->pMEMethodTable[targetUsage] |
| 1199 |
: m_meMethodGeneric[targetUsage]; |
| 1200 |
} |
| 1201 |
|
| 1202 |
uint8_t tableIdx = (m_pictureCodingType == B_TYPE) ? 1 : 0; |
| 1203 |
eStatus = MOS_SecureMemcpy(&(cmd.SPDelta), 14 * sizeof(uint32_t), m_encodeSearchPath[tableIdx][meMethod], 14 * sizeof(uint32_t)); |
| 1204 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 1205 |
{ |
| 1206 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to copy memory."); |
| 1207 |
return eStatus; |
| 1208 |
} |
| 1209 |
|
| 1210 |
// Non legacy stream in is for hevc vp9 streamin kernel |
| 1211 |
if (params->hmeLvl == HME_LEVEL_4x && m_useNonLegacyStreamin) |
| 1212 |
{ |
| 1213 |
//StreamIn CURBE |
| 1214 |
cmd.DW6.LCUSize = 1;//Only LCU64 supported by the VDEnc HW |
| 1215 |
cmd.DW6.InputStreamInSurfaceEnable = params->segmapProvided; |
| 1216 |
cmd.DW31.MaxCuSize = 3; |
| 1217 |
cmd.DW31.MaxTuSize = 3; |
| 1218 |
cmd.DW31.NumImePredictors = CODECHAL_VDENC_NUMIMEPREDICTORS; |
| 1219 |
switch (params->TargetUsage) |
| 1220 |
{ |
| 1221 |
case 1: // Quality mode |
| 1222 |
case 2: |
| 1223 |
case 4: // Normal mode |
| 1224 |
cmd.DW36.NumMergeCandidateCu64x64 = 4; |
| 1225 |
cmd.DW36.NumMergeCandidateCu32x32 = 3; |
| 1226 |
cmd.DW36.NumMergeCandidateCu16x16 = 2; |
| 1227 |
cmd.DW36.NumMergeCandidateCu8x8 = 1; |
| 1228 |
break; |
| 1229 |
case 7: // Speed mode |
| 1230 |
cmd.DW36.NumMergeCandidateCu64x64 = 2; |
| 1231 |
cmd.DW36.NumMergeCandidateCu32x32 = 2; |
| 1232 |
cmd.DW36.NumMergeCandidateCu16x16 = 2; |
| 1233 |
cmd.DW36.NumMergeCandidateCu8x8 = 0; |
| 1234 |
cmd.DW31.NumImePredictors = CODECHAL_VDENC_NUMIMEPREDICTORS_SPEED; |
| 1235 |
break; |
| 1236 |
default: |
| 1237 |
MHW_ASSERTMESSAGE("Invalid TU provided!"); |
| 1238 |
return MOS_STATUS_INVALID_PARAMETER; |
| 1239 |
} |
| 1240 |
} |
| 1241 |
|
| 1242 |
// r5 |
| 1243 |
cmd.DW40._4xMeMvOutputDataSurfIndex = CODECHAL_ENCODE_ME_MV_DATA_SURFACE_G12; |
| 1244 |
cmd.DW41._16xOr32xMeMvInputDataSurfIndex = (params->hmeLvl == HME_LEVEL_32x) ? |
| 1245 |
CODECHAL_ENCODE_32xME_MV_DATA_SURFACE_G12 : CODECHAL_ENCODE_16xME_MV_DATA_SURFACE_G12; |
| 1246 |
cmd.DW42._4xMeOutputDistSurfIndex = CODECHAL_ENCODE_ME_DISTORTION_SURFACE_G12; |
| 1247 |
cmd.DW43._4xMeOutputBrcDistSurfIndex = CODECHAL_ENCODE_ME_BRC_DISTORTION_G12; |
| 1248 |
cmd.DW44.VMEFwdInterPredictionSurfIndex = CODECHAL_ENCODE_ME_CURR_FOR_FWD_REF_G12; |
| 1249 |
cmd.DW45.VMEBwdInterPredictionSurfIndex = CODECHAL_ENCODE_ME_CURR_FOR_BWD_REF_G12; |
| 1250 |
cmd.DW46.VDEncStreamInOutputSurfIndex = CODECHAL_ENCODE_ME_VDENC_STREAMIN_OUTPUT_G12; |
| 1251 |
cmd.DW47.VDEncStreamInInputSurfIndex = CODECHAL_ENCODE_ME_VDENC_STREAMIN_INPUT_G12; |
| 1252 |
|
| 1253 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(params->pKernelState->m_dshRegion.AddData( |
| 1254 |
&cmd, |
| 1255 |
params->pKernelState->dwCurbeOffset, |
| 1256 |
sizeof(cmd))); |
| 1257 |
|
| 1258 |
return eStatus; |
| 1259 |
} |
| 1260 |
|
| 1261 |
MOS_STATUS CodechalVdencVp9StateG12::SendMeSurfaces( |
| 1262 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 1263 |
MeSurfaceParams* params) |
| 1264 |
{ |
| 1265 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1266 |
|
| 1267 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 1268 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1269 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pKernelState); |
| 1270 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pCurrOriginalPic); |
| 1271 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->ps4xMeMvDataBuffer); |
| 1272 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->psMeDistortionBuffer); |
| 1273 |
|
| 1274 |
if (!params->bVdencStreamInEnabled) |
| 1275 |
{ |
| 1276 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->psMeBrcDistortionBuffer); |
| 1277 |
} |
| 1278 |
else |
| 1279 |
{ |
| 1280 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->psMeVdencStreamInBuffer); |
| 1281 |
} |
| 1282 |
|
| 1283 |
CODECHAL_MEDIA_STATE_TYPE encMediaStateType = (params->b32xMeInUse) ? CODECHAL_MEDIA_STATE_32X_ME : |
| 1284 |
params->b16xMeInUse ? CODECHAL_MEDIA_STATE_16X_ME : CODECHAL_MEDIA_STATE_4X_ME; |
| 1285 |
|
| 1286 |
if (params->bVdencStreamInEnabled && encMediaStateType == CODECHAL_MEDIA_STATE_4X_ME) |
| 1287 |
{ |
| 1288 |
encMediaStateType = CODECHAL_MEDIA_STATE_ME_VDENC_STREAMIN; |
| 1289 |
} |
| 1290 |
|
| 1291 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pMeBindingTable); |
| 1292 |
MeKernelBindingTable* meBindingTable = params->pMeBindingTable; |
| 1293 |
|
| 1294 |
bool isFieldPicture = CodecHal_PictureIsField(*(params->pCurrOriginalPic)) ? 1 : 0; |
| 1295 |
bool isBottomField = CodecHal_PictureIsBottomField(*(params->pCurrOriginalPic)) ? 1 : 0; |
| 1296 |
uint8_t currVDirection = (!isFieldPicture) ? CODECHAL_VDIRECTION_FRAME : |
| 1297 |
((isBottomField) ? CODECHAL_VDIRECTION_BOT_FIELD : CODECHAL_VDIRECTION_TOP_FIELD); |
| 1298 |
|
| 1299 |
PMOS_SURFACE currScaledSurface = nullptr, meMvDataBuffer = nullptr; |
| 1300 |
uint32_t meMvBottomFieldOffset = 0, currScaledBottomFieldOffset = 0; |
| 1301 |
if (params->b32xMeInUse) |
| 1302 |
{ |
| 1303 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->ps32xMeMvDataBuffer); |
| 1304 |
currScaledSurface = m_trackedBuf->Get32xDsSurface(CODEC_CURR_TRACKED_BUFFER); |
| 1305 |
meMvDataBuffer = params->ps32xMeMvDataBuffer; |
| 1306 |
meMvBottomFieldOffset = params->dw32xMeMvBottomFieldOffset; |
| 1307 |
currScaledBottomFieldOffset = params->dw32xScaledBottomFieldOffset; |
| 1308 |
} |
| 1309 |
else if (params->b16xMeInUse) |
| 1310 |
{ |
| 1311 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->ps16xMeMvDataBuffer); |
| 1312 |
currScaledSurface = m_trackedBuf->Get16xDsSurface(CODEC_CURR_TRACKED_BUFFER); |
| 1313 |
meMvDataBuffer = params->ps16xMeMvDataBuffer; |
| 1314 |
meMvBottomFieldOffset = params->dw16xMeMvBottomFieldOffset; |
| 1315 |
currScaledBottomFieldOffset = params->dw16xScaledBottomFieldOffset; |
| 1316 |
} |
| 1317 |
else |
| 1318 |
{ |
| 1319 |
currScaledSurface = m_trackedBuf->Get4xDsSurface(CODEC_CURR_TRACKED_BUFFER); |
| 1320 |
meMvDataBuffer = params->ps4xMeMvDataBuffer; |
| 1321 |
meMvBottomFieldOffset = params->dw4xMeMvBottomFieldOffset; |
| 1322 |
currScaledBottomFieldOffset = params->dw4xScaledBottomFieldOffset; |
| 1323 |
} |
| 1324 |
|
| 1325 |
// Reference height and width information should be taken from the current scaled surface rather |
| 1326 |
// than from the reference scaled surface in the case of PAFF. |
| 1327 |
|
| 1328 |
uint32_t width = MOS_ALIGN_CEIL(params->dwDownscaledWidthInMb * 32, 64); |
| 1329 |
uint32_t height = params->dwDownscaledHeightInMb * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER; |
| 1330 |
|
| 1331 |
// Force the values |
| 1332 |
meMvDataBuffer->dwWidth = width; |
| 1333 |
meMvDataBuffer->dwHeight = height; |
| 1334 |
meMvDataBuffer->dwPitch = width; |
| 1335 |
|
| 1336 |
CODECHAL_SURFACE_CODEC_PARAMS surfaceParams; |
| 1337 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1338 |
surfaceParams.bIs2DSurface = true; |
| 1339 |
surfaceParams.bMediaBlockRW = true; |
| 1340 |
surfaceParams.psSurface = meMvDataBuffer; |
| 1341 |
surfaceParams.dwOffset = meMvBottomFieldOffset; |
| 1342 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_MV_DATA_ENCODE].Value; |
| 1343 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwMEMVDataSurface; |
| 1344 |
surfaceParams.bIsWritable = true; |
| 1345 |
surfaceParams.bRenderTarget = true; |
| 1346 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1347 |
m_hwInterface, |
| 1348 |
cmdBuffer, |
| 1349 |
&surfaceParams, |
| 1350 |
params->pKernelState)); |
| 1351 |
|
| 1352 |
if (params->b16xMeInUse && params->b32xMeEnabled) |
| 1353 |
{ |
| 1354 |
// Pass 32x MV to 16x ME operation |
| 1355 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1356 |
surfaceParams.bIs2DSurface = true; |
| 1357 |
surfaceParams.bMediaBlockRW = true; |
| 1358 |
surfaceParams.psSurface = params->ps32xMeMvDataBuffer; |
| 1359 |
surfaceParams.dwOffset = |
| 1360 |
isBottomField ? params->dw32xMeMvBottomFieldOffset : 0; |
| 1361 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_MV_DATA_ENCODE].Value; |
| 1362 |
surfaceParams.dwBindingTableOffset = meBindingTable->dw32xMEMVDataSurface; |
| 1363 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1364 |
m_hwInterface, |
| 1365 |
cmdBuffer, |
| 1366 |
&surfaceParams, |
| 1367 |
params->pKernelState)); |
| 1368 |
} |
| 1369 |
else if (!params->b32xMeInUse && params->b16xMeEnabled) |
| 1370 |
{ |
| 1371 |
// Pass 16x MV to 4x ME operation |
| 1372 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1373 |
surfaceParams.bIs2DSurface = true; |
| 1374 |
surfaceParams.bMediaBlockRW = true; |
| 1375 |
surfaceParams.psSurface = params->ps16xMeMvDataBuffer; |
| 1376 |
surfaceParams.dwOffset = |
| 1377 |
isBottomField ? params->dw16xMeMvBottomFieldOffset : 0; |
| 1378 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_MV_DATA_ENCODE].Value; |
| 1379 |
surfaceParams.dwBindingTableOffset = meBindingTable->dw16xMEMVDataSurface; |
| 1380 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1381 |
m_hwInterface, |
| 1382 |
cmdBuffer, |
| 1383 |
&surfaceParams, |
| 1384 |
params->pKernelState)); |
| 1385 |
} |
| 1386 |
|
| 1387 |
// Insert Distortion buffers only for 4xMe case |
| 1388 |
if (!params->b32xMeInUse && !params->b16xMeInUse) |
| 1389 |
{ |
| 1390 |
if (!params->bVdencStreamInEnabled) |
| 1391 |
{ |
| 1392 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1393 |
surfaceParams.bIs2DSurface = true; |
| 1394 |
surfaceParams.bMediaBlockRW = true; |
| 1395 |
surfaceParams.psSurface = params->psMeBrcDistortionBuffer; |
| 1396 |
surfaceParams.dwOffset = params->dwMeBrcDistortionBottomFieldOffset; |
| 1397 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwMEBRCDist; |
| 1398 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_BRC_ME_DISTORTION_ENCODE].Value; |
| 1399 |
surfaceParams.bIsWritable = true; |
| 1400 |
surfaceParams.bRenderTarget = true; |
| 1401 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1402 |
m_hwInterface, |
| 1403 |
cmdBuffer, |
| 1404 |
&surfaceParams, |
| 1405 |
params->pKernelState)); |
| 1406 |
} |
| 1407 |
|
| 1408 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1409 |
surfaceParams.bIs2DSurface = true; |
| 1410 |
surfaceParams.bMediaBlockRW = true; |
| 1411 |
surfaceParams.psSurface = params->psMeDistortionBuffer; |
| 1412 |
surfaceParams.dwOffset = params->dwMeDistortionBottomFieldOffset; |
| 1413 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwMEDist; |
| 1414 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ME_DISTORTION_ENCODE].Value; |
| 1415 |
surfaceParams.bIsWritable = true; |
| 1416 |
surfaceParams.bRenderTarget = true; |
| 1417 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1418 |
m_hwInterface, |
| 1419 |
cmdBuffer, |
| 1420 |
&surfaceParams, |
| 1421 |
params->pKernelState)); |
| 1422 |
} |
| 1423 |
|
| 1424 |
// Setup references 1...n |
| 1425 |
// LIST 0 references |
| 1426 |
CODEC_PICTURE refPic; |
| 1427 |
bool isRefFieldPicture = false, isRefBottomField = false; |
| 1428 |
uint8_t refPicIdx = 0; |
| 1429 |
if (params->pL0RefFrameList) |
| 1430 |
{ |
| 1431 |
for (uint8_t refIdx = 0; refIdx <= params->dwNumRefIdxL0ActiveMinus1; refIdx++) |
| 1432 |
{ |
| 1433 |
refPic = params->pL0RefFrameList[refIdx]; |
| 1434 |
|
| 1435 |
if (!CodecHal_PictureIsInvalid(refPic) && params->pPicIdx[refPic.FrameIdx].bValid) |
| 1436 |
{ |
| 1437 |
if (refIdx == 0) |
| 1438 |
{ |
| 1439 |
// Current Picture Y - VME |
| 1440 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1441 |
surfaceParams.bUseAdvState = true; |
| 1442 |
surfaceParams.psSurface = currScaledSurface; |
| 1443 |
surfaceParams.dwOffset = isBottomField ? currScaledBottomFieldOffset : 0; |
| 1444 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE].Value; |
| 1445 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwMECurrForFwdRef; |
| 1446 |
surfaceParams.ucVDirection = currVDirection; |
| 1447 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1448 |
m_hwInterface, |
| 1449 |
cmdBuffer, |
| 1450 |
&surfaceParams, |
| 1451 |
params->pKernelState)); |
| 1452 |
} |
| 1453 |
|
| 1454 |
isRefFieldPicture = CodecHal_PictureIsField(refPic) ? 1 : 0; |
| 1455 |
isRefBottomField = (CodecHal_PictureIsBottomField(refPic)) ? 1 : 0; |
| 1456 |
refPicIdx = params->pPicIdx[refPic.FrameIdx].ucPicIdx; |
| 1457 |
uint8_t scaledIdx = params->ppRefList[refPicIdx]->ucScalingIdx; |
| 1458 |
uint32_t refScaledBottomFieldOffset = 0; |
| 1459 |
MOS_SURFACE *refScaledSurface; |
| 1460 |
if (params->b32xMeInUse) |
| 1461 |
{ |
| 1462 |
refScaledSurface = m_trackedBuf->Get32xDsSurface(scaledIdx); |
| 1463 |
} |
| 1464 |
else if (params->b16xMeInUse) |
| 1465 |
{ |
| 1466 |
refScaledSurface = m_trackedBuf->Get16xDsSurface(scaledIdx); |
| 1467 |
} |
| 1468 |
else |
| 1469 |
{ |
| 1470 |
refScaledSurface = m_trackedBuf->Get4xDsSurface(scaledIdx); |
| 1471 |
} |
| 1472 |
refScaledBottomFieldOffset = isRefBottomField ? currScaledBottomFieldOffset : 0; |
| 1473 |
|
| 1474 |
// L0 Reference Picture Y - VME |
| 1475 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1476 |
surfaceParams.bUseAdvState = true; |
| 1477 |
surfaceParams.psSurface = refScaledSurface; |
| 1478 |
surfaceParams.dwOffset = isRefBottomField ? refScaledBottomFieldOffset : 0; |
| 1479 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE].Value; |
| 1480 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwMEFwdRefPicIdx[refIdx]; |
| 1481 |
surfaceParams.ucVDirection = !isFieldPicture ? CODECHAL_VDIRECTION_FRAME : |
| 1482 |
((isRefBottomField) ? CODECHAL_VDIRECTION_BOT_FIELD : CODECHAL_VDIRECTION_TOP_FIELD); |
| 1483 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1484 |
m_hwInterface, |
| 1485 |
cmdBuffer, |
| 1486 |
&surfaceParams, |
| 1487 |
params->pKernelState)); |
| 1488 |
|
| 1489 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwMEFwdRefPicIdx[refIdx] + 1; |
| 1490 |
surfaceParams.ucVDirection = !isFieldPicture ? CODECHAL_VDIRECTION_FRAME : |
| 1491 |
((isRefBottomField) ? CODECHAL_VDIRECTION_BOT_FIELD : CODECHAL_VDIRECTION_TOP_FIELD); |
| 1492 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1493 |
m_hwInterface, |
| 1494 |
cmdBuffer, |
| 1495 |
&surfaceParams, |
| 1496 |
params->pKernelState)); |
| 1497 |
} |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
// Setup references 1...n |
| 1502 |
// LIST 1 references |
| 1503 |
if (params->pL1RefFrameList) |
| 1504 |
{ |
| 1505 |
for (uint8_t refIdx = 0; refIdx <= params->dwNumRefIdxL1ActiveMinus1; refIdx++) |
| 1506 |
{ |
| 1507 |
refPic = params->pL1RefFrameList[refIdx]; |
| 1508 |
|
| 1509 |
if (!CodecHal_PictureIsInvalid(refPic) && params->pPicIdx[refPic.FrameIdx].bValid) |
| 1510 |
{ |
| 1511 |
if (refIdx == 0) |
| 1512 |
{ |
| 1513 |
// Current Picture Y - VME |
| 1514 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1515 |
surfaceParams.bUseAdvState = true; |
| 1516 |
surfaceParams.psSurface = currScaledSurface; |
| 1517 |
surfaceParams.dwOffset = isBottomField ? currScaledBottomFieldOffset : 0; |
| 1518 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE].Value; |
| 1519 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwMECurrForBwdRef; |
| 1520 |
surfaceParams.ucVDirection = currVDirection; |
| 1521 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1522 |
m_hwInterface, |
| 1523 |
cmdBuffer, |
| 1524 |
&surfaceParams, |
| 1525 |
params->pKernelState)); |
| 1526 |
} |
| 1527 |
|
| 1528 |
isRefFieldPicture = CodecHal_PictureIsField(refPic) ? 1 : 0; |
| 1529 |
isRefBottomField = (CodecHal_PictureIsBottomField(refPic)) ? 1 : 0; |
| 1530 |
refPicIdx = params->pPicIdx[refPic.FrameIdx].ucPicIdx; |
| 1531 |
uint8_t scaledIdx = params->ppRefList[refPicIdx]->ucScalingIdx; |
| 1532 |
uint32_t refScaledBottomFieldOffset = 0; |
| 1533 |
MOS_SURFACE *refScaledSurface; |
| 1534 |
if (params->b32xMeInUse) |
| 1535 |
{ |
| 1536 |
refScaledSurface = m_trackedBuf->Get32xDsSurface(scaledIdx); |
| 1537 |
} |
| 1538 |
else if (params->b16xMeInUse) |
| 1539 |
{ |
| 1540 |
refScaledSurface = m_trackedBuf->Get16xDsSurface(scaledIdx); |
| 1541 |
} |
| 1542 |
else |
| 1543 |
{ |
| 1544 |
refScaledSurface = m_trackedBuf->Get4xDsSurface(scaledIdx); |
| 1545 |
} |
| 1546 |
refScaledBottomFieldOffset = isRefBottomField ? currScaledBottomFieldOffset : 0; |
| 1547 |
|
| 1548 |
|
| 1549 |
// L1 Reference Picture Y - VME |
| 1550 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1551 |
surfaceParams.bUseAdvState = true; |
| 1552 |
surfaceParams.psSurface = refScaledSurface; |
| 1553 |
surfaceParams.dwOffset = isRefBottomField ? refScaledBottomFieldOffset : 0; |
| 1554 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE].Value; |
| 1555 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwMEBwdRefPicIdx[refIdx]; |
| 1556 |
surfaceParams.ucVDirection = (!isFieldPicture) ? CODECHAL_VDIRECTION_FRAME : |
| 1557 |
((isRefBottomField) ? CODECHAL_VDIRECTION_BOT_FIELD : CODECHAL_VDIRECTION_TOP_FIELD); |
| 1558 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1559 |
m_hwInterface, |
| 1560 |
cmdBuffer, |
| 1561 |
&surfaceParams, |
| 1562 |
params->pKernelState)); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
} |
| 1566 |
|
| 1567 |
if (encMediaStateType == CODECHAL_MEDIA_STATE_ME_VDENC_STREAMIN) |
| 1568 |
{ |
| 1569 |
// Output buffer |
| 1570 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1571 |
surfaceParams.dwSize = params->dwVDEncStreamInSurfaceSize; |
| 1572 |
surfaceParams.bIs2DSurface = false; |
| 1573 |
surfaceParams.presBuffer = params->psMeVdencStreamInBuffer; |
| 1574 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwVdencStreamInSurface; |
| 1575 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_BRC_ME_DISTORTION_ENCODE].Value; |
| 1576 |
surfaceParams.bIsWritable = true; |
| 1577 |
surfaceParams.bRenderTarget = true; |
| 1578 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1579 |
m_hwInterface, |
| 1580 |
cmdBuffer, |
| 1581 |
&surfaceParams, |
| 1582 |
params->pKernelState)); |
| 1583 |
|
| 1584 |
// Input buffer (for AVC case we only read the surface and update data) |
| 1585 |
MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams)); |
| 1586 |
surfaceParams.dwSize = params->dwVDEncStreamInSurfaceSize; |
| 1587 |
surfaceParams.bIs2DSurface = false; |
| 1588 |
surfaceParams.presBuffer = params->psMeVdencStreamInBuffer; |
| 1589 |
surfaceParams.dwBindingTableOffset = meBindingTable->dwVdencStreamInInputSurface; |
| 1590 |
surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_BRC_ME_DISTORTION_ENCODE].Value; |
| 1591 |
surfaceParams.bIsWritable = true; |
| 1592 |
surfaceParams.bRenderTarget = true; |
| 1593 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1594 |
m_hwInterface, |
| 1595 |
cmdBuffer, |
| 1596 |
&surfaceParams, |
| 1597 |
params->pKernelState)); |
| 1598 |
} |
| 1599 |
|
| 1600 |
return eStatus; |
| 1601 |
} |
| 1602 |
|
| 1603 |
MOS_STATUS CodechalVdencVp9StateG12::InitInterface() |
| 1604 |
{ |
| 1605 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1606 |
|
| 1607 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1608 |
|
| 1609 |
uint8_t* binary = nullptr; |
| 1610 |
uint32_t kernelSize = 0; |
| 1611 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalGetKernelBinaryAndSize( |
| 1612 |
m_kernelBase, |
| 1613 |
m_kuidCommon, |
| 1614 |
&binary, |
| 1615 |
&kernelSize)); |
| 1616 |
|
| 1617 |
GetHwInterface()->GetStateHeapSettings()->dwIshSize += |
| 1618 |
MOS_ALIGN_CEIL(kernelSize, (1 << MHW_KERNEL_OFFSET_SHIFT)); |
| 1619 |
|
| 1620 |
return eStatus; |
| 1621 |
} |
| 1622 |
|
| 1623 |
MOS_STATUS CodechalVdencVp9StateG12::SetMeSurfaceParams(MeSurfaceParams *meSurfaceParams) |
| 1624 |
{ |
| 1625 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1626 |
|
| 1627 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1628 |
|
| 1629 |
CODECHAL_ENCODE_CHK_NULL_RETURN(meSurfaceParams); |
| 1630 |
|
| 1631 |
meSurfaceParams->bMbaff = false; |
| 1632 |
meSurfaceParams->b4xMeDistortionBufferSupported = true; |
| 1633 |
meSurfaceParams->dwNumRefIdxL0ActiveMinus1 = (m_vp9PicParams->PicFlags.fields.frame_type) ? m_numRefFrames - 1 : 0; |
| 1634 |
meSurfaceParams->dwNumRefIdxL1ActiveMinus1 = 0; |
| 1635 |
|
| 1636 |
MOS_ZeroMemory(&m_refPicList0, sizeof(m_refPicList0)); |
| 1637 |
|
| 1638 |
if (m_lastRefPic) |
| 1639 |
{ |
| 1640 |
m_refPicList0[0].FrameIdx = m_vp9PicParams->RefFlags.fields.LastRefIdx; |
| 1641 |
m_refPicList0[0].PicFlags = PICTURE_FRAME; |
| 1642 |
} |
| 1643 |
if (m_goldenRefPic) |
| 1644 |
{ |
| 1645 |
m_refPicList0[1].FrameIdx = m_vp9PicParams->RefFlags.fields.GoldenRefIdx; |
| 1646 |
m_refPicList0[1].PicFlags = PICTURE_FRAME; |
| 1647 |
} |
| 1648 |
if (m_altRefPic) |
| 1649 |
{ |
| 1650 |
m_refPicList0[2].FrameIdx = m_vp9PicParams->RefFlags.fields.AltRefIdx; |
| 1651 |
m_refPicList0[2].PicFlags = PICTURE_FRAME; |
| 1652 |
} |
| 1653 |
|
| 1654 |
meSurfaceParams->pL0RefFrameList = &(m_refPicList0[0]); |
| 1655 |
meSurfaceParams->ppRefList = &m_refList[0]; |
| 1656 |
meSurfaceParams->pPicIdx = &m_picIdx[0]; |
| 1657 |
meSurfaceParams->pCurrOriginalPic = &m_currOriginalPic; |
| 1658 |
meSurfaceParams->ps4xMeMvDataBuffer = &m_4xMeMvDataBuffer; |
| 1659 |
meSurfaceParams->ps16xMeMvDataBuffer = &m_16xMeMvDataBuffer; |
| 1660 |
meSurfaceParams->psMeDistortionBuffer = &m_4xMeDistortionBuffer; |
| 1661 |
meSurfaceParams->dwVerticalLineStride = m_verticalLineStride; |
| 1662 |
meSurfaceParams->dwVerticalLineStrideOffset = m_verticalLineStrideOffset; |
| 1663 |
meSurfaceParams->b32xMeEnabled = m_32xMeSupported; |
| 1664 |
meSurfaceParams->b16xMeEnabled = m_16xMeEnabled; |
| 1665 |
meSurfaceParams->pMeBindingTable = &m_meBindingTable; |
| 1666 |
meSurfaceParams->bVdencStreamInEnabled = true; |
| 1667 |
meSurfaceParams->psMeVdencStreamInBuffer = &m_resVdencStreamInBuffer[m_currRecycledBufIdx]; |
| 1668 |
meSurfaceParams->dwVDEncStreamInSurfaceSize = MOS_BYTES_TO_DWORDS((MOS_ALIGN_CEIL(m_frameWidth, CODEC_VP9_SUPER_BLOCK_WIDTH) / 32) * |
| 1669 |
(MOS_ALIGN_CEIL(m_frameHeight, CODEC_VP9_SUPER_BLOCK_HEIGHT) / 32) * |
| 1670 |
CODECHAL_CACHELINE_SIZE); |
| 1671 |
return eStatus; |
| 1672 |
} |
| 1673 |
|
| 1674 |
MOS_STATUS CodechalVdencVp9StateG12::SetMeCurbeParams(MeCurbeParams *meParams) |
| 1675 |
{ |
| 1676 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1677 |
|
| 1678 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1679 |
|
| 1680 |
CODECHAL_ENCODE_CHK_NULL_RETURN(meParams); |
| 1681 |
|
| 1682 |
meParams->b16xMeEnabled = m_16xMeEnabled; |
| 1683 |
meParams->b32xMeEnabled = m_32xMeSupported; |
| 1684 |
meParams->TargetUsage = TU_QUALITY; |
| 1685 |
meParams->MaxMvLen = m_hmeMaxMvLength; |
| 1686 |
meParams->CurrOriginalPic.FrameIdx = m_vp9PicParams->CurrOriginalPic.FrameIdx; |
| 1687 |
meParams->CurrOriginalPic.PicEntry = m_vp9PicParams->CurrOriginalPic.PicEntry; |
| 1688 |
meParams->CurrOriginalPic.PicFlags = m_vp9PicParams->CurrOriginalPic.PicFlags; |
| 1689 |
meParams->pic_init_qp_minus26 = m_vp9PicParams->LumaACQIndex - 26; |
| 1690 |
meParams->num_ref_idx_l0_active_minus1 = (m_vp9PicParams->PicFlags.fields.frame_type) ? m_numRefFrames - 1 : 0; |
| 1691 |
meParams->num_ref_idx_l1_active_minus1 = 0; |
| 1692 |
|
| 1693 |
return eStatus; |
| 1694 |
} |
| 1695 |
|
| 1696 |
MOS_STATUS CodechalVdencVp9StateG12::ExecuteMeKernel( |
| 1697 |
MeCurbeParams *meParams, |
| 1698 |
MeSurfaceParams *meSurfaceParams, |
| 1699 |
HmeLevel hmeLevel) |
| 1700 |
{ |
| 1701 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1702 |
|
| 1703 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1704 |
|
| 1705 |
CODECHAL_ENCODE_CHK_NULL_RETURN(meParams); |
| 1706 |
CODECHAL_ENCODE_CHK_NULL_RETURN(meSurfaceParams); |
| 1707 |
|
| 1708 |
PerfTagSetting perfTag; |
| 1709 |
perfTag.Value = 0; |
| 1710 |
perfTag.Mode = (uint16_t)m_mode & CODECHAL_ENCODE_MODE_BIT_MASK; |
| 1711 |
perfTag.CallType = m_singleTaskPhaseSupported ? CODECHAL_ENCODE_PERFTAG_CALL_SCALING_KERNEL : CODECHAL_ENCODE_PERFTAG_CALL_ME_KERNEL; |
| 1712 |
perfTag.PictureCodingType = m_pictureCodingType; |
| 1713 |
m_osInterface->pfnSetPerfTag(m_osInterface, perfTag.Value); |
| 1714 |
// Each ME kernel buffer counts as a separate perf task |
| 1715 |
m_osInterface->pfnResetPerfBufferID(m_osInterface); |
| 1716 |
|
| 1717 |
CODECHAL_MEDIA_STATE_TYPE encFunctionType = (hmeLevel == HME_LEVEL_32x) ? CODECHAL_MEDIA_STATE_32X_ME : |
| 1718 |
(hmeLevel == HME_LEVEL_16x) ? CODECHAL_MEDIA_STATE_16X_ME : CODECHAL_MEDIA_STATE_4X_ME; |
| 1719 |
|
| 1720 |
bool vdencMeInUse = false; |
| 1721 |
if (m_vdencEnabled && (encFunctionType == CODECHAL_MEDIA_STATE_4X_ME)) |
| 1722 |
{ |
| 1723 |
vdencMeInUse = true; |
| 1724 |
// Non legacy stream in is for hevc vp9 streamin kernel |
| 1725 |
encFunctionType = m_useNonLegacyStreamin ? CODECHAL_MEDIA_STATE_4X_ME : CODECHAL_MEDIA_STATE_ME_VDENC_STREAMIN; |
| 1726 |
} |
| 1727 |
|
| 1728 |
uint32_t krnStateIdx = vdencMeInUse ? |
| 1729 |
CODECHAL_ENCODE_ME_IDX_VDENC : |
| 1730 |
((m_pictureCodingType == P_TYPE) ? CODECHAL_ENCODE_ME_IDX_P : CODECHAL_ENCODE_ME_IDX_B); |
| 1731 |
|
| 1732 |
PMHW_KERNEL_STATE kernelState = &m_meKernelStates[krnStateIdx]; |
| 1733 |
|
| 1734 |
// If Single Task Phase is not enabled, use BT count for the kernel state. |
| 1735 |
if (m_firstTaskInPhase == true || !m_singleTaskPhaseSupported) |
| 1736 |
{ |
| 1737 |
uint32_t maxBtCount = m_singleTaskPhaseSupported ? |
| 1738 |
m_maxBtCount : kernelState->KernelParams.iBTCount; |
| 1739 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnRequestSshSpaceForCmdBuf( |
| 1740 |
m_stateHeapInterface, |
| 1741 |
maxBtCount)); |
| 1742 |
m_vmeStatesSize = m_hwInterface->GetKernelLoadCommandSize(maxBtCount); |
| 1743 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(VerifySpaceAvailable()); |
| 1744 |
} |
| 1745 |
|
| 1746 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->AssignDshAndSshSpace( |
| 1747 |
m_stateHeapInterface, |
| 1748 |
kernelState, |
| 1749 |
false, |
| 1750 |
0, |
| 1751 |
false, |
| 1752 |
m_storeData)); |
| 1753 |
MHW_INTERFACE_DESCRIPTOR_PARAMS idParams; |
| 1754 |
MOS_ZeroMemory(&idParams, sizeof(idParams)); |
| 1755 |
idParams.pKernelState = kernelState; |
| 1756 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnSetInterfaceDescriptor( |
| 1757 |
m_stateHeapInterface, |
| 1758 |
1, |
| 1759 |
&idParams)); |
| 1760 |
|
| 1761 |
// Setup Additional MeParams (Most of them set up in codec specific function, so don't zero out here) |
| 1762 |
meParams->hmeLvl = hmeLevel; |
| 1763 |
meParams->pKernelState = kernelState; |
| 1764 |
|
| 1765 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetCurbeMe(meParams)); |
| 1766 |
|
| 1767 |
CODECHAL_DEBUG_TOOL( |
| 1768 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpKernelRegion( |
| 1769 |
encFunctionType, |
| 1770 |
MHW_DSH_TYPE, |
| 1771 |
kernelState)); |
| 1772 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCurbe( |
| 1773 |
encFunctionType, |
| 1774 |
kernelState)); |
| 1775 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpKernelRegion( |
| 1776 |
encFunctionType, |
| 1777 |
MHW_ISH_TYPE, |
| 1778 |
kernelState)); |
| 1779 |
) |
| 1780 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 1781 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, &cmdBuffer, 0)); |
| 1782 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectStartCmd((void *)this, m_osInterface, m_miInterface, &cmdBuffer)); |
| 1783 |
SendKernelCmdsParams sendKernelCmdsParams; |
| 1784 |
sendKernelCmdsParams = SendKernelCmdsParams(); |
| 1785 |
sendKernelCmdsParams.EncFunctionType = encFunctionType; |
| 1786 |
sendKernelCmdsParams.pKernelState = kernelState; |
| 1787 |
|
| 1788 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendGenericKernelCmds(&cmdBuffer, &sendKernelCmdsParams)); |
| 1789 |
|
| 1790 |
// Add binding table |
| 1791 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnSetBindingTable( |
| 1792 |
m_stateHeapInterface, |
| 1793 |
kernelState)); |
| 1794 |
|
| 1795 |
// Setup Additional ME surface params (Most of them set up in codec specific function, so don't zero out here) |
| 1796 |
meSurfaceParams->dwDownscaledWidthInMb = (hmeLevel == HME_LEVEL_32x) ? m_downscaledWidthInMb32x : |
| 1797 |
(hmeLevel == HME_LEVEL_16x) ? m_downscaledWidthInMb16x : m_downscaledWidthInMb4x; |
| 1798 |
meSurfaceParams->dwDownscaledHeightInMb = (hmeLevel == HME_LEVEL_32x) ? m_downscaledFrameFieldHeightInMb32x : |
| 1799 |
(hmeLevel == HME_LEVEL_16x) ? m_downscaledFrameFieldHeightInMb16x : m_downscaledFrameFieldHeightInMb4x; |
| 1800 |
meSurfaceParams->b32xMeInUse = (hmeLevel == HME_LEVEL_32x) ? true : false; |
| 1801 |
meSurfaceParams->b16xMeInUse = (hmeLevel == HME_LEVEL_16x) ? true : false; |
| 1802 |
meSurfaceParams->pKernelState = kernelState; |
| 1803 |
|
| 1804 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendMeSurfaces(&cmdBuffer, meSurfaceParams)); |
| 1805 |
|
| 1806 |
// Dump SSH for ME kernel |
| 1807 |
CODECHAL_DEBUG_TOOL( |
| 1808 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpKernelRegion( |
| 1809 |
encFunctionType, |
| 1810 |
MHW_SSH_TYPE, |
| 1811 |
kernelState))); |
| 1812 |
|
| 1813 |
/* zero out the mv data memory and me distortion buffer for the driver ULT |
| 1814 |
kernel only writes out this data used for current frame, in some cases the the data used for |
| 1815 |
previous frames would be left in the buffer (for example, the L1 mv for B frame would still show |
| 1816 |
in the P frame mv data buffer */ |
| 1817 |
|
| 1818 |
// Zeroing out the buffers has perf impact, so zero it out only when dumps are actually enabled |
| 1819 |
CODECHAL_DEBUG_TOOL( |
| 1820 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_debugInterface); |
| 1821 |
uint8_t* data = NULL; |
| 1822 |
uint32_t size = 0; |
| 1823 |
bool driverMeDumpEnabled = m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrOutput, encFunctionType); |
| 1824 |
|
| 1825 |
if (driverMeDumpEnabled) |
| 1826 |
{ |
| 1827 |
MOS_LOCK_PARAMS lockFlags; |
| 1828 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 1829 |
lockFlags.WriteOnly = 1; |
| 1830 |
|
| 1831 |
switch (hmeLevel) |
| 1832 |
{ |
| 1833 |
case HME_LEVEL_32x: |
| 1834 |
data = (uint8_t*)m_osInterface->pfnLockResource( |
| 1835 |
m_osInterface, |
| 1836 |
&meSurfaceParams->ps32xMeMvDataBuffer->OsResource, |
| 1837 |
&lockFlags); |
| 1838 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 1839 |
size = MOS_ALIGN_CEIL((m_downscaledWidthInMb32x * 32), 64) * |
| 1840 |
(m_downscaledHeightInMb32x * 2 * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 1841 |
MOS_ZeroMemory(data, size); |
| 1842 |
m_osInterface->pfnUnlockResource( |
| 1843 |
m_osInterface, |
| 1844 |
&meSurfaceParams->ps32xMeMvDataBuffer->OsResource); |
| 1845 |
break; |
| 1846 |
case HME_LEVEL_16x: |
| 1847 |
data = (uint8_t*)m_osInterface->pfnLockResource( |
| 1848 |
m_osInterface, |
| 1849 |
&meSurfaceParams->ps16xMeMvDataBuffer->OsResource, |
| 1850 |
&lockFlags); |
| 1851 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 1852 |
size = MOS_ALIGN_CEIL((m_downscaledWidthInMb16x * 32), 64) * |
| 1853 |
(m_downscaledHeightInMb16x * 2 * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 1854 |
MOS_ZeroMemory(data, size); |
| 1855 |
m_osInterface->pfnUnlockResource( |
| 1856 |
m_osInterface, |
| 1857 |
&meSurfaceParams->ps16xMeMvDataBuffer->OsResource); |
| 1858 |
break; |
| 1859 |
case HME_LEVEL_4x: |
| 1860 |
if (!m_vdencEnabled) |
| 1861 |
{ |
| 1862 |
data = (uint8_t*)m_osInterface->pfnLockResource( |
| 1863 |
m_osInterface, |
| 1864 |
&meSurfaceParams->ps4xMeMvDataBuffer->OsResource, |
| 1865 |
&lockFlags); |
| 1866 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 1867 |
size = MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 32), 64) * |
| 1868 |
(m_downscaledHeightInMb4x * 2 * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 1869 |
MOS_ZeroMemory(data, size); |
| 1870 |
m_osInterface->pfnUnlockResource( |
| 1871 |
m_osInterface, |
| 1872 |
&meSurfaceParams->ps4xMeMvDataBuffer->OsResource); |
| 1873 |
} |
| 1874 |
break; |
| 1875 |
default: |
| 1876 |
return MOS_STATUS_INVALID_PARAMETER; |
| 1877 |
} |
| 1878 |
|
| 1879 |
// zeroing out ME dist buffer |
| 1880 |
if (meSurfaceParams->b4xMeDistortionBufferSupported) |
| 1881 |
{ |
| 1882 |
data = (uint8_t*)m_osInterface->pfnLockResource( |
| 1883 |
m_osInterface, &meSurfaceParams->psMeDistortionBuffer->OsResource, &lockFlags); |
| 1884 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 1885 |
size = meSurfaceParams->psMeDistortionBuffer->dwHeight * meSurfaceParams->psMeDistortionBuffer->dwPitch; |
| 1886 |
MOS_ZeroMemory(data, size); |
| 1887 |
m_osInterface->pfnUnlockResource( |
| 1888 |
m_osInterface, |
| 1889 |
&meSurfaceParams->psMeDistortionBuffer->OsResource); |
| 1890 |
} |
| 1891 |
} |
| 1892 |
); |
| 1893 |
|
| 1894 |
uint32_t scalingFactor = (hmeLevel == HME_LEVEL_32x) ? SCALE_FACTOR_32x : |
| 1895 |
(hmeLevel == HME_LEVEL_16x) ? SCALE_FACTOR_16x : SCALE_FACTOR_4x; |
| 1896 |
|
| 1897 |
uint32_t resolutionX = CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_frameWidth / scalingFactor); |
| 1898 |
uint32_t resolutionY = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameFieldHeight / scalingFactor); |
| 1899 |
|
| 1900 |
CODECHAL_WALKER_CODEC_PARAMS walkerCodecParams; |
| 1901 |
MOS_ZeroMemory(&walkerCodecParams, sizeof(walkerCodecParams)); |
| 1902 |
walkerCodecParams.WalkerMode = m_walkerMode; |
| 1903 |
walkerCodecParams.dwResolutionX = resolutionX; |
| 1904 |
walkerCodecParams.dwResolutionY = resolutionY; |
| 1905 |
walkerCodecParams.bNoDependency = true; |
| 1906 |
walkerCodecParams.bMbaff = meSurfaceParams->bMbaff; |
| 1907 |
walkerCodecParams.bGroupIdSelectSupported = m_groupIdSelectSupported; |
| 1908 |
walkerCodecParams.ucGroupId = m_groupId; |
| 1909 |
|
| 1910 |
MHW_WALKER_PARAMS walkerParams; |
| 1911 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalInitMediaObjectWalkerParams( |
| 1912 |
m_hwInterface, |
| 1913 |
&walkerParams, |
| 1914 |
&walkerCodecParams)); |
| 1915 |
|
| 1916 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_renderEngineInterface->AddMediaObjectWalkerCmd( |
| 1917 |
&cmdBuffer, |
| 1918 |
&walkerParams)); |
| 1919 |
|
| 1920 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EndStatusReport(&cmdBuffer, encFunctionType)); |
| 1921 |
|
| 1922 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnSubmitBlocks( |
| 1923 |
m_stateHeapInterface, |
| 1924 |
kernelState)); |
| 1925 |
|
| 1926 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectEndCmd((void *)this, m_osInterface, m_miInterface, &cmdBuffer)); |
| 1927 |
|
| 1928 |
if (!m_singleTaskPhaseSupported || m_lastTaskInPhase) |
| 1929 |
{ |
| 1930 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnUpdateGlobalCmdBufId( |
| 1931 |
m_stateHeapInterface)); |
| 1932 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd(&cmdBuffer, nullptr)); |
| 1933 |
} |
| 1934 |
|
| 1935 |
CODECHAL_DEBUG_TOOL(CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCmdBuffer( |
| 1936 |
&cmdBuffer, |
| 1937 |
encFunctionType, |
| 1938 |
nullptr))); |
| 1939 |
|
| 1940 |
m_hwInterface->UpdateSSEuForCmdBuffer(&cmdBuffer, m_singleTaskPhaseSupported, m_lastTaskInPhase); |
| 1941 |
|
| 1942 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, &cmdBuffer, 0); |
| 1943 |
|
| 1944 |
if (!m_singleTaskPhaseSupported || m_lastTaskInPhase) |
| 1945 |
{ |
| 1946 |
m_osInterface->pfnSubmitCommandBuffer(m_osInterface, &cmdBuffer, m_renderContextUsesNullHw); |
| 1947 |
m_lastTaskInPhase = false; |
| 1948 |
} |
| 1949 |
|
| 1950 |
return eStatus; |
| 1951 |
} |
| 1952 |
|
| 1953 |
MOS_STATUS CodechalVdencVp9StateG12::ExecuteKernelFunctions() |
| 1954 |
{ |
| 1955 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1956 |
|
| 1957 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1958 |
|
| 1959 |
#if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE) |
| 1960 |
uint32_t dumpFormat = 0; |
| 1961 |
CODECHAL_DEBUG_TOOL( |
| 1962 |
// CodecHal_DbgMapSurfaceFormatToDumpFormat(m_rawSurfaceToEnc->Format, &dumpFormat); |
| 1963 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 1964 |
m_rawSurfaceToEnc, |
| 1965 |
CodechalDbgAttr::attrEncodeRawInputSurface, |
| 1966 |
"SrcSurf")); |
| 1967 |
|
| 1968 |
if (m_lastRefPic) |
| 1969 |
{ |
| 1970 |
// CodecHal_DbgMapSurfaceFormatToDumpFormat(m_lastRefPic->Format, &dumpFormat); |
| 1971 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 1972 |
m_lastRefPic, |
| 1973 |
CodechalDbgAttr::attrReferenceSurfaces, |
| 1974 |
"LastRefSurface")); |
| 1975 |
} |
| 1976 |
|
| 1977 |
if (m_goldenRefPic) |
| 1978 |
{ |
| 1979 |
// CodecHal_DbgMapSurfaceFormatToDumpFormat(m_goldenRefPic->Format, &dumpFormat); |
| 1980 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 1981 |
m_goldenRefPic, |
| 1982 |
CodechalDbgAttr::attrReferenceSurfaces, |
| 1983 |
"GoldenRefSurface")); |
| 1984 |
} |
| 1985 |
|
| 1986 |
if (m_altRefPic) |
| 1987 |
{ |
| 1988 |
// CodecHal_DbgMapSurfaceFormatToDumpFormat(m_altRefPic->Format, &dumpFormat); |
| 1989 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 1990 |
m_altRefPic, |
| 1991 |
CodechalDbgAttr::attrReferenceSurfaces, |
| 1992 |
"_AltRefSurface")); |
| 1993 |
} |
| 1994 |
); |
| 1995 |
|
| 1996 |
m_setRequestedEUSlices = ((m_frameHeight * m_frameWidth) >= m_ssdResolutionThreshold && |
| 1997 |
m_targetUsage <= m_ssdTargetUsageThreshold) ? true : false; |
| 1998 |
|
| 1999 |
m_hwInterface->m_numRequestedEuSlices = (m_setRequestedEUSlices) ? |
| 2000 |
m_sliceShutdownRequestState : m_sliceShutdownDefaultState; |
| 2001 |
|
| 2002 |
// While this streamin isn't a kernel function, we 0 the surface here which is needed before HME kernel |
| 2003 |
SetupSegmentationStreamIn(); |
| 2004 |
if (m_16xMeSupported) |
| 2005 |
{ |
| 2006 |
//4x Downscaling |
| 2007 |
CodechalEncodeCscDs::KernelParams cscScalingKernelParams; |
| 2008 |
MOS_ZeroMemory(&cscScalingKernelParams, sizeof(cscScalingKernelParams)); |
| 2009 |
cscScalingKernelParams.bLastTaskInPhaseCSC = |
| 2010 |
cscScalingKernelParams.bLastTaskInPhase4xDS = !(m_16xMeSupported || m_hmeEnabled); |
| 2011 |
cscScalingKernelParams.bLastTaskInPhase16xDS = !(m_32xMeSupported || m_hmeEnabled); |
| 2012 |
cscScalingKernelParams.bLastTaskInPhase32xDS = !m_hmeEnabled; |
| 2013 |
|
| 2014 |
m_firstTaskInPhase = true; |
| 2015 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_cscDsState->KernelFunctions(&cscScalingKernelParams)); |
| 2016 |
} |
| 2017 |
|
| 2018 |
if (m_16xMeEnabled) |
| 2019 |
{ |
| 2020 |
//Initialize the ME struct for HME kernel calls |
| 2021 |
MeCurbeParams meParams; |
| 2022 |
MOS_ZeroMemory(&meParams, sizeof(MeCurbeParams)); |
| 2023 |
SetMeCurbeParams(&meParams); |
| 2024 |
|
| 2025 |
MeSurfaceParams meSurfaceParams; |
| 2026 |
MOS_ZeroMemory(&meSurfaceParams, sizeof(MeSurfaceParams)); |
| 2027 |
SetMeSurfaceParams(&meSurfaceParams); |
| 2028 |
|
| 2029 |
// P_HME kernel (16x HME) |
| 2030 |
m_lastTaskInPhase = false; |
| 2031 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ExecuteMeKernel(&meParams, &meSurfaceParams, HME_LEVEL_16x)); |
| 2032 |
|
| 2033 |
//StreamIn kernel, 4xME |
| 2034 |
m_lastTaskInPhase = true; |
| 2035 |
meParams.segmapProvided = m_segmentMapProvided; |
| 2036 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ExecuteMeKernel(&meParams, &meSurfaceParams, HME_LEVEL_4x)); |
| 2037 |
} |
| 2038 |
|
| 2039 |
if (!Mos_ResourceIsNull(&m_resSyncObjectRenderContextInUse)) |
| 2040 |
{ |
| 2041 |
MOS_SYNC_PARAMS syncParams = g_cInitSyncParams; |
| 2042 |
syncParams.GpuContext = m_renderContext; |
| 2043 |
syncParams.presSyncResource = &m_resSyncObjectRenderContextInUse; |
| 2044 |
|
| 2045 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineSignal(m_osInterface, &syncParams)); |
| 2046 |
m_waitForEnc = true; |
| 2047 |
} |
| 2048 |
#endif |
| 2049 |
|
| 2050 |
return eStatus; |
| 2051 |
} |
| 2052 |
|
| 2053 |
static void StatusReportCleanup( |
| 2054 |
EncodeStatusReport* encodeStatusReport, |
| 2055 |
HCPPakHWTileSizeRecord_G12* tileStatusReport, |
| 2056 |
CODECHAL_ENCODE_BUFFER* tileSizeStreamoutBuffer, |
| 2057 |
PMOS_INTERFACE osInterface, |
| 2058 |
uint8_t* tempBsBuffer, |
| 2059 |
uint8_t* bitstream) |
| 2060 |
{ |
| 2061 |
|
| 2062 |
if (tempBsBuffer) |
| 2063 |
{ |
| 2064 |
MOS_FreeMemory(tempBsBuffer); |
| 2065 |
} |
| 2066 |
|
| 2067 |
if (bitstream) |
| 2068 |
{ |
| 2069 |
osInterface->pfnUnlockResource(osInterface, &encodeStatusReport->pCurrRefList->resBitstreamBuffer); |
| 2070 |
} |
| 2071 |
|
| 2072 |
if (tileStatusReport) |
| 2073 |
{ |
| 2074 |
// clean-up the tile status report buffer |
| 2075 |
if (encodeStatusReport->CodecStatus == CODECHAL_STATUS_SUCCESSFUL) |
| 2076 |
{ |
| 2077 |
for (uint32_t i = 0; i < encodeStatusReport->NumberTilesInFrame; i++) |
| 2078 |
{ |
| 2079 |
MOS_ZeroMemory(&tileStatusReport[i], sizeof(tileStatusReport[i])); |
| 2080 |
} |
| 2081 |
} |
| 2082 |
|
| 2083 |
osInterface->pfnUnlockResource(osInterface, &tileSizeStreamoutBuffer->sResource); |
| 2084 |
} |
| 2085 |
} |
| 2086 |
|
| 2087 |
MOS_STATUS CodechalVdencVp9StateG12::GetStatusReport( |
| 2088 |
EncodeStatus* encodeStatus, |
| 2089 |
EncodeStatusReport* encodeStatusReport) |
| 2090 |
{ |
| 2091 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2092 |
|
| 2093 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2094 |
|
| 2095 |
CODECHAL_ENCODE_CHK_NULL_RETURN(encodeStatus); |
| 2096 |
CODECHAL_ENCODE_CHK_NULL_RETURN(encodeStatusReport); |
| 2097 |
|
| 2098 |
if (encodeStatusReport->UsedVdBoxNumber == 1) |
| 2099 |
{ |
| 2100 |
encodeStatusReport->bitstreamSize = encodeStatus->dwMFCBitstreamByteCountPerFrame + encodeStatus->dwHeaderBytesInserted; |
| 2101 |
encodeStatusReport->NumberPasses = (uint8_t)encodeStatus->dwNumberPasses; |
| 2102 |
ENCODE_VERBOSEMESSAGE("statusReportData->numberPasses: %d\n", encodeStatusReport->NumberPasses); |
| 2103 |
encodeStatusReport->CodecStatus = CODECHAL_STATUS_SUCCESSFUL; |
| 2104 |
return eStatus; |
| 2105 |
} |
| 2106 |
|
| 2107 |
// Tile record always in m_tileRecordBuffer even in scala mode |
| 2108 |
PCODECHAL_ENCODE_BUFFER presTileSizeStatusReport = &m_tileRecordBuffer[encodeStatusReport->CurrOriginalPic.FrameIdx]; |
| 2109 |
|
| 2110 |
MOS_LOCK_PARAMS lockFlags; |
| 2111 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 2112 |
HCPPakHWTileSizeRecord_G12* tileStatusReport = (HCPPakHWTileSizeRecord_G12*)m_osInterface->pfnLockResource( |
| 2113 |
m_osInterface, |
| 2114 |
&presTileSizeStatusReport->sResource, |
| 2115 |
&lockFlags); |
| 2116 |
CODECHAL_ENCODE_CHK_NULL_RETURN(tileStatusReport); |
| 2117 |
|
| 2118 |
encodeStatusReport->CodecStatus = CODECHAL_STATUS_SUCCESSFUL; |
| 2119 |
encodeStatusReport->PanicMode = false; |
| 2120 |
encodeStatusReport->AverageQp = 0; |
| 2121 |
encodeStatusReport->QpY = 0; |
| 2122 |
encodeStatusReport->SuggestedQpYDelta = 0; |
| 2123 |
encodeStatusReport->NumberPasses = 1; |
| 2124 |
encodeStatusReport->bitstreamSize = 0; |
| 2125 |
encodeStatus->ImageStatusCtrlOfLastBRCPass.hcpCumulativeFrameDeltaQp = 0; |
| 2126 |
|
| 2127 |
double sum_qp = 0.0; |
| 2128 |
uint32_t totalCU = 0; |
| 2129 |
CODECHAL_ENCODE_CHK_COND_RETURN((encodeStatusReport->NumberTilesInFrame == 0), "ERROR - invalid number of tiles in frame"); |
| 2130 |
for (uint32_t i = 0; i < encodeStatusReport->NumberTilesInFrame; i++) |
| 2131 |
{ |
| 2132 |
if (tileStatusReport[i].Length == 0) |
| 2133 |
{ |
| 2134 |
encodeStatusReport->CodecStatus = CODECHAL_STATUS_INCOMPLETE; |
| 2135 |
StatusReportCleanup(encodeStatusReport, tileStatusReport, presTileSizeStatusReport, m_osInterface, nullptr, nullptr); |
| 2136 |
return eStatus; |
| 2137 |
} |
| 2138 |
|
| 2139 |
encodeStatusReport->bitstreamSize += tileStatusReport[i].Length; |
| 2140 |
totalCU += (m_tileParams[i].TileHeightInMinCbMinus1 + 1) * (m_tileParams[i].TileWidthInMinCbMinus1 + 1); |
| 2141 |
sum_qp += tileStatusReport[i].Hcp_Qp_Status_Count; |
| 2142 |
} |
| 2143 |
|
| 2144 |
encodeStatusReport->QpY = encodeStatusReport->AverageQp = |
| 2145 |
(uint8_t)((sum_qp / (double)totalCU) / 4.0); // due to TU is 4x4 and there are 4 TUs in one CU |
| 2146 |
|
| 2147 |
if (m_enableTileStitchByHW) |
| 2148 |
{ |
| 2149 |
StatusReportCleanup(encodeStatusReport, tileStatusReport, presTileSizeStatusReport, m_osInterface, nullptr, nullptr); |
| 2150 |
return eStatus; |
| 2151 |
} |
| 2152 |
|
| 2153 |
uint8_t* bufPtr = (uint8_t*)MOS_AllocAndZeroMemory(encodeStatusReport->bitstreamSize); |
| 2154 |
uint8_t* tempBsBuffer = bufPtr; |
| 2155 |
CODECHAL_ENCODE_CHK_NULL_RETURN(tempBsBuffer); |
| 2156 |
|
| 2157 |
CODEC_REF_LIST currRefList = *(encodeStatus->encodeStatusReport.pCurrRefList); |
| 2158 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 2159 |
lockFlags.ReadOnly = 1; |
| 2160 |
uint8_t* bitstream = (uint8_t*)m_osInterface->pfnLockResource( |
| 2161 |
m_osInterface, |
| 2162 |
&currRefList.resBitstreamBuffer, |
| 2163 |
&lockFlags); |
| 2164 |
if (bitstream == nullptr) |
| 2165 |
{ |
| 2166 |
MOS_SafeFreeMemory(tempBsBuffer); |
| 2167 |
CODECHAL_ENCODE_CHK_NULL_RETURN(nullptr); |
| 2168 |
} |
| 2169 |
|
| 2170 |
for (uint32_t i = 0; i < encodeStatusReport->NumberTilesInFrame; i++) |
| 2171 |
{ |
| 2172 |
uint32_t offset = m_tileParams[i].BitstreamByteOffset * CODECHAL_CACHELINE_SIZE; |
| 2173 |
uint32_t len = tileStatusReport[i].Length; |
| 2174 |
|
| 2175 |
if (offset + len >= m_bitstreamUpperBound) |
| 2176 |
{ |
| 2177 |
eStatus = MOS_STATUS_INVALID_FILE_SIZE; |
| 2178 |
CODECHAL_ENCODE_ASSERTMESSAGE("Error: Tile offset and length add up to more than bitstream upper bound"); |
| 2179 |
encodeStatusReport->CodecStatus = CODECHAL_STATUS_ERROR; |
| 2180 |
encodeStatusReport->bitstreamSize = 0; |
| 2181 |
StatusReportCleanup(encodeStatusReport, tileStatusReport, presTileSizeStatusReport, m_osInterface, tempBsBuffer, bitstream); |
| 2182 |
return eStatus; |
| 2183 |
} |
| 2184 |
|
| 2185 |
MOS_SecureMemcpy(bufPtr, len, &bitstream[offset], len); |
| 2186 |
bufPtr += len; |
| 2187 |
} |
| 2188 |
|
| 2189 |
MOS_SecureMemcpy(bitstream, encodeStatusReport->bitstreamSize, tempBsBuffer, encodeStatusReport->bitstreamSize); |
| 2190 |
MOS_ZeroMemory(&bitstream[encodeStatusReport->bitstreamSize], |
| 2191 |
m_bitstreamUpperBound - encodeStatusReport->bitstreamSize); |
| 2192 |
|
| 2193 |
StatusReportCleanup(encodeStatusReport, tileStatusReport, presTileSizeStatusReport, m_osInterface, tempBsBuffer, bitstream); |
| 2194 |
|
| 2195 |
return eStatus; |
| 2196 |
} |
| 2197 |
|
| 2198 |
MOS_STATUS CodechalVdencVp9StateG12::DecideEncodingPipeNumber() |
| 2199 |
{ |
| 2200 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2201 |
|
| 2202 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2203 |
|
| 2204 |
m_numPipe = m_numVdbox; |
| 2205 |
|
| 2206 |
uint8_t num_tile_columns = (1 << m_vp9PicParams->log2_tile_columns); |
| 2207 |
|
| 2208 |
if (num_tile_columns > m_numPipe) |
| 2209 |
{ |
| 2210 |
m_numPipe = 1; |
| 2211 |
} |
| 2212 |
|
| 2213 |
if (num_tile_columns < m_numPipe) |
| 2214 |
{ |
| 2215 |
if (num_tile_columns >= 1 && num_tile_columns <= 4) |
| 2216 |
{ |
| 2217 |
m_numPipe = num_tile_columns; |
| 2218 |
} |
| 2219 |
else |
| 2220 |
{ |
| 2221 |
m_numPipe = 1; // invalid tile column test cases and switch back to the single VDBOX mode |
| 2222 |
} |
| 2223 |
} |
| 2224 |
|
| 2225 |
if (m_numPipe == 0 || m_numPipe > CODECHAL_ENCODE_VP9_MAX_NUM_HCP_PIPE) |
| 2226 |
{ |
| 2227 |
m_numPipe = 1; |
| 2228 |
} |
| 2229 |
|
| 2230 |
if (m_numPipe > 1) |
| 2231 |
{ |
| 2232 |
m_scalableMode = true; // KMD VE is now enabled by default. Mediasolo can also use the VE interface. |
| 2233 |
} |
| 2234 |
else |
| 2235 |
{ |
| 2236 |
m_scalableMode = false; |
| 2237 |
} |
| 2238 |
|
| 2239 |
if (m_scalabilityState) |
| 2240 |
{ |
| 2241 |
// Create/ re-use a GPU context with 2 pipes |
| 2242 |
m_scalabilityState->ucScalablePipeNum = m_numPipe; |
| 2243 |
} |
| 2244 |
|
| 2245 |
return eStatus; |
| 2246 |
} |
| 2247 |
|
| 2248 |
MOS_STATUS CodechalVdencVp9StateG12::PlatformCapabilityCheck() |
| 2249 |
{ |
| 2250 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2251 |
|
| 2252 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2253 |
|
| 2254 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(DecideEncodingPipeNumber()); |
| 2255 |
|
| 2256 |
if (MOS_VE_CTXBASEDSCHEDULING_SUPPORTED(m_osInterface)) |
| 2257 |
{ |
| 2258 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncodeScalability_ChkGpuCtxReCreation(this, m_scalabilityState, |
| 2259 |
(PMOS_GPUCTX_CREATOPTIONS_ENHANCED)m_gpuCtxCreatOpt)); |
| 2260 |
} |
| 2261 |
|
| 2262 |
|
| 2263 |
if (m_numPipe > 1) |
| 2264 |
{ |
| 2265 |
m_singleTaskPhaseSupported = m_singleTaskPhaseSupportedInPak = false; |
| 2266 |
} |
| 2267 |
|
| 2268 |
//so far only validate Tiling for VDEnc VP9 |
| 2269 |
uint8_t col = (1 << (m_vp9PicParams->log2_tile_columns)); |
| 2270 |
uint8_t row = (1 << (m_vp9PicParams->log2_tile_rows)); |
| 2271 |
|
| 2272 |
// Handling invalid tiling and scalability cases. When NumTilingColumn does not match NumPipe fall back to single pipe mode |
| 2273 |
if (m_numPipe > 1 && (col != m_numPipe)) |
| 2274 |
{ |
| 2275 |
if ((col == 1) || (row == 1)) |
| 2276 |
{ |
| 2277 |
m_numPipe = 1; // number of tile columns cannot be greater than number of pipes (VDBOX), run in single pipe mode |
| 2278 |
m_scalableMode = false; |
| 2279 |
} |
| 2280 |
else |
| 2281 |
{ |
| 2282 |
CODECHAL_ENCODE_ASSERTMESSAGE("Number of tile columns cannot be greater than number of pipes (VDBOX) when number of rows > 1"); |
| 2283 |
return MOS_STATUS_INVALID_PARAMETER; |
| 2284 |
} |
| 2285 |
} |
| 2286 |
|
| 2287 |
//num columns must be either 2 or 4 for scalability mode, H/W limitation |
| 2288 |
if ((m_numPipe > 1) && (m_numPipe != 2) && (m_numPipe != 4)) |
| 2289 |
{ |
| 2290 |
CODECHAL_ENCODE_ASSERTMESSAGE("Num pipes must be either 2 or 4 for scalability mode, H/W limitation"); |
| 2291 |
return MOS_STATUS_INVALID_PARAMETER; |
| 2292 |
} |
| 2293 |
|
| 2294 |
// Tile width needs to be minimum size 256, error out if less |
| 2295 |
if ((col != 1) && ((m_vp9PicParams->SrcFrameWidthMinus1 + 1) < col * CODECHAL_ENCODE_VP9_MIN_TILE_SIZE_WIDTH)) |
| 2296 |
{ |
| 2297 |
CODECHAL_ENCODE_ASSERTMESSAGE("Incorrect number of columns input parameter, Tile width is < 256"); |
| 2298 |
return MOS_STATUS_INVALID_PARAMETER; |
| 2299 |
} |
| 2300 |
|
| 2301 |
if (row > 4) |
| 2302 |
{ |
| 2303 |
CODECHAL_ENCODE_ASSERTMESSAGE("Max number of rows cannot exceeds 4 by VP9 Spec."); |
| 2304 |
return MOS_STATUS_INVALID_PARAMETER; |
| 2305 |
} |
| 2306 |
|
| 2307 |
// number of tiles for this frame |
| 2308 |
m_numberTilesInFrame = col * row; |
| 2309 |
m_numUsedVdbox = m_numPipe; |
| 2310 |
|
| 2311 |
if (!m_newSeq) |
| 2312 |
{ |
| 2313 |
// If there is no new SEQ header, then the number of passes is decided here. |
| 2314 |
// Otherwise, it is done in SetSequenceStructs. For example, BRC setting may be changed. |
| 2315 |
m_numPasses = (m_numPassesInOnePipe + 1) * m_numPipe - 1; |
| 2316 |
} |
| 2317 |
|
| 2318 |
//Last place where scalable mode is decided |
| 2319 |
if(m_frameNum == 0) |
| 2320 |
{ |
| 2321 |
m_lastFrameScalableMode = m_scalableMode; |
| 2322 |
} |
| 2323 |
|
| 2324 |
return eStatus; |
| 2325 |
} |
| 2326 |
|
| 2327 |
MOS_STATUS CodechalVdencVp9StateG12::SetGpuCtxCreatOption() |
| 2328 |
{ |
| 2329 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2330 |
|
| 2331 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2332 |
|
| 2333 |
if (!MOS_VE_CTXBASEDSCHEDULING_SUPPORTED(m_osInterface)) |
| 2334 |
{ |
| 2335 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncoderState::SetGpuCtxCreatOption()); |
| 2336 |
} |
| 2337 |
else |
| 2338 |
{ |
| 2339 |
m_gpuCtxCreatOpt = MOS_New(MOS_GPUCTX_CREATOPTIONS_ENHANCED); |
| 2340 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_gpuCtxCreatOpt); |
| 2341 |
|
| 2342 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncodeScalability_ConstructParmsForGpuCtxCreation( |
| 2343 |
m_scalabilityState, |
| 2344 |
(PMOS_GPUCTX_CREATOPTIONS_ENHANCED)m_gpuCtxCreatOpt)); |
| 2345 |
} |
| 2346 |
|
| 2347 |
return eStatus; |
| 2348 |
} |
| 2349 |
|
| 2350 |
MOS_STATUS CodechalVdencVp9StateG12::SetAndPopulateVEHintParams( |
| 2351 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 2352 |
{ |
| 2353 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2354 |
|
| 2355 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2356 |
|
| 2357 |
if (!MOS_VE_SUPPORTED(m_osInterface)) |
| 2358 |
{ |
| 2359 |
return eStatus; |
| 2360 |
} |
| 2361 |
|
| 2362 |
CODECHAL_ENCODE_SCALABILITY_SETHINT_PARMS scalSetParms; |
| 2363 |
MOS_ZeroMemory(&scalSetParms, sizeof(CODECHAL_ENCODE_SCALABILITY_SETHINT_PARMS)); |
| 2364 |
|
| 2365 |
if (!MOS_VE_CTXBASEDSCHEDULING_SUPPORTED(m_osInterface)) |
| 2366 |
{ |
| 2367 |
scalSetParms.bNeedSyncWithPrevious = true; |
| 2368 |
} |
| 2369 |
|
| 2370 |
int32_t currentPass = GetCurrentPass(); |
| 2371 |
uint8_t passIndex = m_singleTaskPhaseSupported ? 0 : currentPass; |
| 2372 |
// Scalable mode only |
| 2373 |
if (m_scalableMode) |
| 2374 |
{ |
| 2375 |
for (auto i = 0; i < m_numPipe; i++) |
| 2376 |
{ |
| 2377 |
scalSetParms.veBatchBuffer[i] = m_veBatchBuffer[m_virtualEngineBBIndex][i][passIndex].OsResource; |
| 2378 |
} |
| 2379 |
} |
| 2380 |
|
| 2381 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalEncodeScalability_SetHintParams(this, m_scalabilityState, &scalSetParms)); |
| 2382 |
|
| 2383 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 2384 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalEncodeScalability_PopulateHintParams(m_scalabilityState, cmdBuffer)); |
| 2385 |
|
| 2386 |
return eStatus; |
| 2387 |
} |
| 2388 |
|
| 2389 |
MOS_STATUS CodechalVdencVp9StateG12::SetTileData() |
| 2390 |
{ |
| 2391 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2392 |
|
| 2393 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2394 |
|
| 2395 |
MHW_VDBOX_HCP_TILE_CODING_PARAMS_G12 *tileCodingParams = m_tileParams; |
| 2396 |
|
| 2397 |
tileCodingParams->Mode = CODECHAL_ENCODE_MODE_VP9; |
| 2398 |
|
| 2399 |
uint32_t numTileRows = (1 << m_vp9PicParams->log2_tile_rows); |
| 2400 |
uint32_t numTileColumns = (1 << m_vp9PicParams->log2_tile_columns); |
| 2401 |
uint32_t numTiles = numTileRows * numTileColumns; |
| 2402 |
|
| 2403 |
uint32_t bitstreamSizePerTile = m_bitstreamUpperBound / (numTiles * CODECHAL_CACHELINE_SIZE); |
| 2404 |
uint32_t numLcusInTiles = 0, numCuRecord = 64; |
| 2405 |
uint32_t cuLevelStreamoutOffset = 0, sliceSizeStreamoutOffset = 0, bitstreamByteOffset = 0, sseRowstoreOffset = 0; |
| 2406 |
|
| 2407 |
for (uint32_t tileCntr = 0; tileCntr < numTiles; tileCntr++) |
| 2408 |
{ |
| 2409 |
uint32_t tileX, tileY, tileStartSbX, tileStartSbY, tileWidthInSb, tileHeightInSb, lastTileColWidth, lastTileRowHeight, numLcuInTile; |
| 2410 |
bool isLastTileCol, isLastTileRow; |
| 2411 |
|
| 2412 |
tileX = tileCntr % numTileColumns; |
| 2413 |
tileY = tileCntr / numTileColumns; |
| 2414 |
|
| 2415 |
isLastTileCol = ((numTileColumns - 1) == tileX); |
| 2416 |
isLastTileRow = ((numTileRows - 1) == tileY); |
| 2417 |
|
| 2418 |
tileStartSbX = (tileX * m_picWidthInSb) >> m_vp9PicParams->log2_tile_columns; |
| 2419 |
tileStartSbY = (tileY * m_picHeightInSb) >> m_vp9PicParams->log2_tile_rows; |
| 2420 |
|
| 2421 |
tileWidthInSb = (isLastTileCol ? m_picWidthInSb : (((tileX + 1) * m_picWidthInSb) >> m_vp9PicParams->log2_tile_columns)) - tileStartSbX; |
| 2422 |
tileHeightInSb = (isLastTileRow ? m_picHeightInSb : (((tileY + 1) * m_picHeightInSb) >> m_vp9PicParams->log2_tile_rows)) - tileStartSbY; |
| 2423 |
|
| 2424 |
lastTileColWidth = (MOS_ALIGN_CEIL((m_vp9PicParams->SrcFrameWidthMinus1 + 1 - tileStartSbX * CODEC_VP9_SUPER_BLOCK_WIDTH), CODEC_VP9_MIN_BLOCK_WIDTH) / CODEC_VP9_MIN_BLOCK_WIDTH) - 1; |
| 2425 |
lastTileRowHeight = (MOS_ALIGN_CEIL((m_vp9PicParams->SrcFrameHeightMinus1 + 1 - tileStartSbY * CODEC_VP9_SUPER_BLOCK_HEIGHT), CODEC_VP9_MIN_BLOCK_HEIGHT) / CODEC_VP9_MIN_BLOCK_HEIGHT) - 1; |
| 2426 |
|
| 2427 |
numLcuInTile = tileWidthInSb * tileHeightInSb; |
| 2428 |
tileCodingParams[tileCntr].NumberOfActiveBePipes = m_numPipe; |
| 2429 |
tileCodingParams[tileCntr].NumOfTilesInFrame = numTiles; |
| 2430 |
tileCodingParams[tileCntr].NumOfTileColumnsInFrame = numTileColumns; |
| 2431 |
tileCodingParams[tileCntr].TileStartLCUX = tileStartSbX; |
| 2432 |
tileCodingParams[tileCntr].TileStartLCUY = tileStartSbY; |
| 2433 |
tileCodingParams[tileCntr].IsLastTileofColumn = isLastTileRow; |
| 2434 |
tileCodingParams[tileCntr].IsLastTileofRow = isLastTileCol; |
| 2435 |
|
| 2436 |
tileCodingParams[tileCntr].TileWidthInMinCbMinus1 = isLastTileCol ? lastTileColWidth : (tileWidthInSb * CODEC_VP9_MIN_BLOCK_WIDTH) - 1; |
| 2437 |
tileCodingParams[tileCntr].TileHeightInMinCbMinus1 = isLastTileRow ? lastTileRowHeight : (tileHeightInSb * CODEC_VP9_MIN_BLOCK_HEIGHT) - 1; |
| 2438 |
|
| 2439 |
if (m_scalableMode) |
| 2440 |
{ |
| 2441 |
sseRowstoreOffset = (tileStartSbX + (3 * tileX)) << 5; |
| 2442 |
|
| 2443 |
tileCodingParams[tileCntr].CuRecordOffset = MOS_ALIGN_CEIL(((numCuRecord * numLcusInTiles) * 64), |
| 2444 |
CODECHAL_CACHELINE_SIZE) / CODECHAL_CACHELINE_SIZE; |
| 2445 |
tileCodingParams[tileCntr].presHcpSyncBuffer = &m_hcpScalabilitySyncBuffer.sResource; |
| 2446 |
tileCodingParams[tileCntr].SliceSizeStreamoutOffset = sliceSizeStreamoutOffset; |
| 2447 |
tileCodingParams[tileCntr].SseRowstoreOffset = sseRowstoreOffset; |
| 2448 |
tileCodingParams[tileCntr].BitstreamByteOffset = bitstreamByteOffset; |
| 2449 |
tileCodingParams[tileCntr].CuLevelStreamoutOffset = cuLevelStreamoutOffset; |
| 2450 |
|
| 2451 |
cuLevelStreamoutOffset += (tileCodingParams[tileCntr].TileWidthInMinCbMinus1 + 1) * (tileCodingParams[tileCntr].TileHeightInMinCbMinus1 + 1); |
| 2452 |
sliceSizeStreamoutOffset += (tileCodingParams[tileCntr].TileWidthInMinCbMinus1 + 1) * (tileCodingParams[tileCntr].TileHeightInMinCbMinus1 + 1); |
| 2453 |
sseRowstoreOffset += (numLcuInTile * m_sizeOfSseSrcPixelRowStoreBufferPerLcu) / CODECHAL_CACHELINE_SIZE; |
| 2454 |
bitstreamByteOffset += bitstreamSizePerTile; |
| 2455 |
numLcusInTiles += numLcuInTile; |
| 2456 |
|
| 2457 |
tileCodingParams[tileCntr].TileSizeStreamoutOffset = (tileCntr*m_hcpInterface->GetPakHWTileSizeRecordSize() + CODECHAL_CACHELINE_SIZE - 1) / CODECHAL_CACHELINE_SIZE; |
| 2458 |
|
| 2459 |
//DW5 |
| 2460 |
const uint32_t frameStatsStreamoutSize = m_brcPakStatsBufSize; |
| 2461 |
tileCodingParams[tileCntr].PakTileStatisticsOffset = (tileCntr*frameStatsStreamoutSize + CODECHAL_CACHELINE_SIZE - 1) / CODECHAL_CACHELINE_SIZE; |
| 2462 |
|
| 2463 |
//DW12 |
| 2464 |
tileCodingParams[tileCntr].Vp9ProbabilityCounterStreamoutOffset = ((tileCntr * m_probabilityCounterBufferSize) + (CODECHAL_CACHELINE_SIZE - 1)) / CODECHAL_CACHELINE_SIZE; |
| 2465 |
} |
| 2466 |
else |
| 2467 |
{ |
| 2468 |
tileCodingParams[tileCntr].CuRecordOffset = 0; |
| 2469 |
tileCodingParams[tileCntr].presHcpSyncBuffer = nullptr; |
| 2470 |
tileCodingParams[tileCntr].SliceSizeStreamoutOffset = 0; |
| 2471 |
tileCodingParams[tileCntr].SseRowstoreOffset = 0; |
| 2472 |
tileCodingParams[tileCntr].BitstreamByteOffset = 0; |
| 2473 |
tileCodingParams[tileCntr].CuLevelStreamoutOffset = 0; |
| 2474 |
tileCodingParams[tileCntr].TileSizeStreamoutOffset = 0; |
| 2475 |
|
| 2476 |
//DW5 |
| 2477 |
tileCodingParams[tileCntr].PakTileStatisticsOffset = 0; |
| 2478 |
|
| 2479 |
//DW12 |
| 2480 |
tileCodingParams[tileCntr].Vp9ProbabilityCounterStreamoutOffset = 0; |
| 2481 |
} |
| 2482 |
} |
| 2483 |
|
| 2484 |
return eStatus; |
| 2485 |
} |
| 2486 |
|
| 2487 |
MOS_STATUS CodechalVdencVp9StateG12::SetTileCommands( |
| 2488 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 2489 |
{ |
| 2490 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2491 |
|
| 2492 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2493 |
|
| 2494 |
MHW_VDBOX_VDENC_WALKER_STATE_PARAMS_G12 vdencWalkerStateParams; |
| 2495 |
vdencWalkerStateParams.Mode = CODECHAL_ENCODE_MODE_VP9; |
| 2496 |
vdencWalkerStateParams.pVp9EncPicParams = m_vp9PicParams; |
| 2497 |
vdencWalkerStateParams.dwNumberOfPipes = VDENC_PIPE_SINGLE_PIPE; |
| 2498 |
|
| 2499 |
MHW_VDBOX_VD_PIPE_FLUSH_PARAMS vdPipelineFlushParams; |
| 2500 |
MOS_ZeroMemory(&vdPipelineFlushParams, sizeof(vdPipelineFlushParams)); |
| 2501 |
// MFXPipeDone should not be set for tail insertion |
| 2502 |
vdPipelineFlushParams.Flags.bWaitDoneMFX = |
| 2503 |
(m_lastPicInStream || m_lastPicInSeq) ? 0 : 1; |
| 2504 |
vdPipelineFlushParams.Flags.bWaitDoneVDENC = 1; |
| 2505 |
vdPipelineFlushParams.Flags.bFlushVDENC = 1; |
| 2506 |
vdPipelineFlushParams.Flags.bFlushHEVC = 1; |
| 2507 |
vdPipelineFlushParams.Flags.bWaitDoneVDCmdMsgParser = 1; |
| 2508 |
|
| 2509 |
if (IsFirstPipe() && IsFirstPass()) |
| 2510 |
{ |
| 2511 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetTileData()); |
| 2512 |
} |
| 2513 |
|
| 2514 |
MHW_VDBOX_VDENC_WEIGHT_OFFSET_PARAMS vdencWeightOffsetParams; |
| 2515 |
uint32_t numTileColumns = (1 << m_vp9PicParams->log2_tile_columns); |
| 2516 |
uint32_t numTileRows = (1 << m_vp9PicParams->log2_tile_rows); |
| 2517 |
int currentPipe = GetCurrentPipe(); |
| 2518 |
for (uint32_t tileRow = 0, tileIdx = 0; tileRow < numTileRows; tileRow++) |
| 2519 |
{ |
| 2520 |
for (uint32_t tileCol = 0; tileCol < numTileColumns; tileCol++, tileIdx++) |
| 2521 |
{ |
| 2522 |
if (m_numPipe > 1) |
| 2523 |
{ |
| 2524 |
if (tileCol != currentPipe) |
| 2525 |
{ |
| 2526 |
continue; |
| 2527 |
} |
| 2528 |
} |
| 2529 |
|
| 2530 |
if (m_scalableMode) |
| 2531 |
{ |
| 2532 |
MHW_MI_VD_CONTROL_STATE_PARAMS vdCtrlParam; |
| 2533 |
//in scalability mode |
| 2534 |
MOS_ZeroMemory(&vdCtrlParam, sizeof(MHW_MI_VD_CONTROL_STATE_PARAMS)); |
| 2535 |
vdCtrlParam.scalableModePipeLock = true; |
| 2536 |
MhwMiInterfaceG12 *miInterfaceG12 = static_cast <MhwMiInterfaceG12 *>(m_miInterface); |
| 2537 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((miInterfaceG12)->AddMiVdControlStateCmd(cmdBuffer, &vdCtrlParam)); |
| 2538 |
} |
| 2539 |
|
| 2540 |
// HCP_TILE_CODING commmand |
| 2541 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(static_cast<MhwVdboxHcpInterfaceG12 *>(m_hcpInterface)->AddHcpTileCodingCmd(cmdBuffer, &m_tileParams[tileIdx])); |
| 2542 |
|
| 2543 |
MOS_ZeroMemory(&vdencWeightOffsetParams, sizeof(vdencWeightOffsetParams)); |
| 2544 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdencWeightsOffsetsStateCmd(cmdBuffer, nullptr, &vdencWeightOffsetParams)); |
| 2545 |
|
| 2546 |
vdencWalkerStateParams.pTileCodingParams = &m_tileParams[tileIdx]; |
| 2547 |
vdencWalkerStateParams.dwTileId = tileIdx; |
| 2548 |
switch (m_numPipe) |
| 2549 |
{ |
| 2550 |
case 0: |
| 2551 |
case 1: |
| 2552 |
vdencWalkerStateParams.dwNumberOfPipes = VDENC_PIPE_SINGLE_PIPE; |
| 2553 |
break; |
| 2554 |
case 2: |
| 2555 |
vdencWalkerStateParams.dwNumberOfPipes = VDENC_PIPE_TWO_PIPE; |
| 2556 |
break; |
| 2557 |
case 4: |
| 2558 |
vdencWalkerStateParams.dwNumberOfPipes = VDENC_PIPE_FOUR_PIPE; |
| 2559 |
break; |
| 2560 |
default: |
| 2561 |
vdencWalkerStateParams.dwNumberOfPipes = VDENC_PIPE_INVALID; |
| 2562 |
CODECHAL_ENCODE_ASSERTMESSAGE("Num Pipes invalid"); |
| 2563 |
return eStatus; |
| 2564 |
break; |
| 2565 |
} |
| 2566 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdencWalkerStateCmd(cmdBuffer, &vdencWalkerStateParams)); |
| 2567 |
|
| 2568 |
if (m_scalableMode) |
| 2569 |
{ |
| 2570 |
MHW_MI_VD_CONTROL_STATE_PARAMS vdCtrlParam; |
| 2571 |
MOS_ZeroMemory(&vdCtrlParam, sizeof(MHW_MI_VD_CONTROL_STATE_PARAMS)); |
| 2572 |
vdCtrlParam.scalableModePipeUnlock = true; |
| 2573 |
MhwMiInterfaceG12 *miInterfaceG12 = static_cast <MhwMiInterfaceG12 *>(m_miInterface); |
| 2574 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((miInterfaceG12)->AddMiVdControlStateCmd(cmdBuffer, &vdCtrlParam)); |
| 2575 |
} |
| 2576 |
|
| 2577 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdPipelineFlushCmd(cmdBuffer, &vdPipelineFlushParams)); |
| 2578 |
// Send MI_FLUSH command |
| 2579 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 2580 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 2581 |
flushDwParams.bVideoPipelineCacheInvalidate = true; |
| 2582 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(cmdBuffer, &flushDwParams)); |
| 2583 |
} |
| 2584 |
} |
| 2585 |
|
| 2586 |
return eStatus; |
| 2587 |
} |
| 2588 |
|
| 2589 |
MOS_STATUS CodechalVdencVp9StateG12::StoreNumPasses( |
| 2590 |
EncodeStatusBuffer *encodeStatusBuf, |
| 2591 |
MhwMiInterface *miInterface, |
| 2592 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 2593 |
uint32_t currPass) |
| 2594 |
{ |
| 2595 |
MHW_MI_STORE_DATA_PARAMS storeDataParams; |
| 2596 |
uint32_t offset; |
| 2597 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2598 |
|
| 2599 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2600 |
|
| 2601 |
CODECHAL_ENCODE_CHK_NULL_RETURN(encodeStatusBuf); |
| 2602 |
CODECHAL_ENCODE_CHK_NULL_RETURN(miInterface); |
| 2603 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 2604 |
|
| 2605 |
offset = |
| 2606 |
(encodeStatusBuf->wCurrIndex * encodeStatusBuf->dwReportSize) + |
| 2607 |
encodeStatusBuf->dwNumPassesOffset + // Num passes offset |
| 2608 |
sizeof(uint32_t) * 2; // pEncodeStatus is offset by 2 DWs in the resource |
| 2609 |
|
| 2610 |
storeDataParams.pOsResource = &encodeStatusBuf->resStatusBuffer; |
| 2611 |
storeDataParams.dwResourceOffset = offset; |
| 2612 |
storeDataParams.dwValue = currPass + 1; |
| 2613 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(miInterface->AddMiStoreDataImmCmd(cmdBuffer, &storeDataParams)); |
| 2614 |
|
| 2615 |
return MOS_STATUS_SUCCESS; |
| 2616 |
} |
| 2617 |
MOS_STATUS CodechalVdencVp9StateG12::ExecuteTileLevel() |
| 2618 |
{ |
| 2619 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2620 |
|
| 2621 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2622 |
|
| 2623 |
int currentPipe = GetCurrentPipe(); |
| 2624 |
int currentPass = GetCurrentPass(); |
| 2625 |
|
| 2626 |
if (currentPipe < 0 || currentPass < 0) |
| 2627 |
{ |
| 2628 |
return MOS_STATUS_INVALID_PARAMETER; |
| 2629 |
} |
| 2630 |
|
| 2631 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 2632 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 2633 |
|
| 2634 |
if (IsFirstPipe()) |
| 2635 |
{ |
| 2636 |
MHW_BATCH_BUFFER secondLevelBatchBuffer; |
| 2637 |
MOS_ZeroMemory(&secondLevelBatchBuffer, sizeof(secondLevelBatchBuffer)); |
| 2638 |
secondLevelBatchBuffer.dwOffset = 0; |
| 2639 |
secondLevelBatchBuffer.bSecondLevel = true; |
| 2640 |
|
| 2641 |
if (!m_hucEnabled) |
| 2642 |
{ |
| 2643 |
secondLevelBatchBuffer.OsResource = m_resHucPakInsertUncompressedHeaderReadBuffer[m_currRecycledBufIdx]; |
| 2644 |
} |
| 2645 |
else |
| 2646 |
{ |
| 2647 |
secondLevelBatchBuffer.OsResource = m_resHucPakInsertUncompressedHeaderWriteBuffer; |
| 2648 |
} |
| 2649 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd( |
| 2650 |
&cmdBuffer, |
| 2651 |
&secondLevelBatchBuffer)); |
| 2652 |
} |
| 2653 |
|
| 2654 |
// Setup Tile level PAK commands |
| 2655 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetTileCommands(&cmdBuffer)); |
| 2656 |
|
| 2657 |
MHW_MI_VD_CONTROL_STATE_PARAMS vdCtrlParam; |
| 2658 |
MOS_ZeroMemory(&vdCtrlParam, sizeof(MHW_MI_VD_CONTROL_STATE_PARAMS)); |
| 2659 |
vdCtrlParam.memoryImplicitFlush = true; |
| 2660 |
MhwMiInterfaceG12 *miInterfaceG12 = static_cast <MhwMiInterfaceG12 *>(m_miInterface); |
| 2661 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((miInterfaceG12)->AddMiVdControlStateCmd(&cmdBuffer, &vdCtrlParam)); |
| 2662 |
|
| 2663 |
// Send VD_PIPELINE_FLUSH command |
| 2664 |
MHW_VDBOX_VD_PIPE_FLUSH_PARAMS vdPipelineFlushParams; |
| 2665 |
MOS_ZeroMemory(&vdPipelineFlushParams, sizeof(vdPipelineFlushParams)); |
| 2666 |
// MFXPipeDone should not be set for tail insertion |
| 2667 |
vdPipelineFlushParams.Flags.bWaitDoneMFX = 1; |
| 2668 |
vdPipelineFlushParams.Flags.bWaitDoneHEVC = 1; |
| 2669 |
vdPipelineFlushParams.Flags.bFlushHEVC = 1; |
| 2670 |
vdPipelineFlushParams.Flags.bWaitDoneVDCmdMsgParser = 1; |
| 2671 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdPipelineFlushCmd(&cmdBuffer, &vdPipelineFlushParams)); |
| 2672 |
|
| 2673 |
// Send MI_FLUSH command |
| 2674 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 2675 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 2676 |
flushDwParams.bVideoPipelineCacheInvalidate = true; |
| 2677 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(&cmdBuffer, &flushDwParams)); |
| 2678 |
|
| 2679 |
if (IsFirstPipe()) |
| 2680 |
{ |
| 2681 |
if (m_numPipe > 1 && m_enableTileStitchByHW) |
| 2682 |
{ |
| 2683 |
for (auto i = 1; i < m_numPipe; i++) |
| 2684 |
{ |
| 2685 |
if (!Mos_ResourceIsNull(&m_stitchWaitSemaphoreMem[i].sResource) && m_hucEnabled) |
| 2686 |
{ |
| 2687 |
// This semaphore waits for all pipes except pipe 1 vdenc+pak to finish processing before stitching bitstream |
| 2688 |
SendHWWaitCommand(&m_stitchWaitSemaphoreMem[i].sResource, &cmdBuffer, (currentPass + 1)); |
| 2689 |
SetSemaphoreMem(&m_stitchWaitSemaphoreMem[i].sResource, &cmdBuffer, 0); // Reset above semaphore |
| 2690 |
} |
| 2691 |
} |
| 2692 |
} |
| 2693 |
// PAK integration kernel to integrate stats for next HUC pass |
| 2694 |
if (m_scalableMode && m_hucEnabled && m_isTilingSupported && IsFirstPipe()) |
| 2695 |
{ |
| 2696 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(HuCVp9PakInt(&cmdBuffer)); |
| 2697 |
// Signal pak int done semaphore here for next pass to proceed |
| 2698 |
if (!IsLastPass()) |
| 2699 |
{ |
| 2700 |
SetSemaphoreMem(&m_pakIntDoneSemaphoreMem.sResource, &cmdBuffer, (currentPass + 1)); |
| 2701 |
} |
| 2702 |
|
| 2703 |
if (m_enableTileStitchByHW) |
| 2704 |
{ |
| 2705 |
// 2nd level BB buffer for stitching cmd |
| 2706 |
// current location to add cmds in 2nd level batch buffer |
| 2707 |
m_HucStitchCmdBatchBuffer.iCurrent = 0; |
| 2708 |
// reset starting location (offset) executing 2nd level batch buffer for each frame & each pass |
| 2709 |
m_HucStitchCmdBatchBuffer.dwOffset = 0; |
| 2710 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd(&cmdBuffer, &m_HucStitchCmdBatchBuffer)); |
| 2711 |
// This wait cmd is needed to make sure copy command is done as suggested by HW folk in encode cases |
| 2712 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMfxWaitCmd(&cmdBuffer, nullptr, m_osInterface->osCpInterface->IsCpEnabled() ? true : false)); |
| 2713 |
} |
| 2714 |
} |
| 2715 |
|
| 2716 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EndStatusReport(&cmdBuffer, CODECHAL_NUM_MEDIA_STATES)); |
| 2717 |
|
| 2718 |
if (!m_scalableMode) // single pipe mode can read the info from MMIO register. Otherwise, we have to use the tile size statistic buffer |
| 2719 |
{ |
| 2720 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReadHcpStatus(&cmdBuffer)); |
| 2721 |
} |
| 2722 |
} |
| 2723 |
else // 2nd Pipe |
| 2724 |
{ |
| 2725 |
// Signal stitch command to proceed because vdenc+pak is done in this pipe and we can stitch bs |
| 2726 |
if (m_hucEnabled && m_isTilingSupported && !Mos_ResourceIsNull(&m_stitchWaitSemaphoreMem[currentPipe].sResource)) |
| 2727 |
{ |
| 2728 |
SetSemaphoreMem(&m_stitchWaitSemaphoreMem[currentPipe].sResource, &cmdBuffer, (currentPass + 1)); |
| 2729 |
} |
| 2730 |
} |
| 2731 |
|
| 2732 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 2733 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(&cmdBuffer, &flushDwParams)); |
| 2734 |
if (m_singleTaskPhaseSupported && m_hucEnabled && IsLastPass()) |
| 2735 |
{ |
| 2736 |
m_lastTaskInPhase = true; //HPU singletask phase mode only |
| 2737 |
} |
| 2738 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreNumPasses( |
| 2739 |
&(m_encodeStatusBuf), |
| 2740 |
m_miInterface, |
| 2741 |
&cmdBuffer, |
| 2742 |
m_currPass)); |
| 2743 |
|
| 2744 |
if (!m_singleTaskPhaseSupported || m_lastTaskInPhase || m_scalableMode) |
| 2745 |
{ |
| 2746 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd(&cmdBuffer, nullptr)); |
| 2747 |
} |
| 2748 |
|
| 2749 |
std::string currPassName = "PAK_PASS" + std::to_string((int)m_currPass); |
| 2750 |
if ((m_dysRefFrameFlags != DYS_REF_NONE) && m_dysVdencMultiPassEnabled) |
| 2751 |
{ |
| 2752 |
// Added extra symbol into log to avoid log's file overwrite on the next pass |
| 2753 |
// For DYS Mutlipass mode next pass should run with "m_currPass = 0" again |
| 2754 |
// See ExecutePictureLevel() function for all details |
| 2755 |
currPassName.append("_0"); |
| 2756 |
} |
| 2757 |
CODECHAL_DEBUG_TOOL(CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCmdBuffer( |
| 2758 |
&cmdBuffer, |
| 2759 |
CODECHAL_NUM_MEDIA_STATES, |
| 2760 |
currPassName.data()))); |
| 2761 |
|
| 2762 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReturnCommandBuffer(&cmdBuffer)); |
| 2763 |
|
| 2764 |
if (IsLastPipe()) |
| 2765 |
{ |
| 2766 |
if (m_hucEnabled) |
| 2767 |
{ |
| 2768 |
// We save the index of the 2nd level batch buffer in case there is a pass that needs the last SLBB |
| 2769 |
m_lastVdencPictureState2ndLevelBBIndex = m_vdencPictureState2ndLevelBBIndex; |
| 2770 |
} |
| 2771 |
m_vdencPictureState2ndLevelBBIndex = (m_vdencPictureState2ndLevelBBIndex + 1) % CODECHAL_VP9_ENCODE_RECYCLED_BUFFER_NUM; |
| 2772 |
} |
| 2773 |
|
| 2774 |
if (IsFirstPipe() && |
| 2775 |
m_waitForEnc && |
| 2776 |
IsFirstPass() && |
| 2777 |
!Mos_ResourceIsNull(&m_resSyncObjectRenderContextInUse)) |
| 2778 |
{ |
| 2779 |
MOS_SYNC_PARAMS syncParams; |
| 2780 |
syncParams = g_cInitSyncParams; |
| 2781 |
syncParams.GpuContext = m_videoContext; |
| 2782 |
syncParams.presSyncResource = &m_resSyncObjectRenderContextInUse; |
| 2783 |
|
| 2784 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineWait(m_osInterface, &syncParams)); |
| 2785 |
m_waitForEnc = false; |
| 2786 |
} |
| 2787 |
|
| 2788 |
if (!m_singleTaskPhaseSupported || m_lastTaskInPhase) |
| 2789 |
{ |
| 2790 |
bool renderFlags = m_videoContextUsesNullHw; |
| 2791 |
|
| 2792 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SubmitCommandBuffer(&cmdBuffer, renderFlags)); |
| 2793 |
m_lastTaskInPhase = false; |
| 2794 |
|
| 2795 |
CODECHAL_DEBUG_TOOL( |
| 2796 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2797 |
m_resVdencPakObjCmdStreamOutBuffer, |
| 2798 |
CodechalDbgAttr::attrPakObjStreamout, |
| 2799 |
currPassName.data(), |
| 2800 |
m_mbCodeSize + 8 * CODECHAL_CACHELINE_SIZE, |
| 2801 |
0, |
| 2802 |
CODECHAL_NUM_MEDIA_STATES)); |
| 2803 |
|
| 2804 |
if (m_vp9PicParams->PicFlags.fields.segmentation_enabled) { |
| 2805 |
//CodecHal_DbgDumpEncodeVp9SegmentStreamout(m_debugInterface, m_encoder); |
| 2806 |
//m_debugInterface->DumpBuffer( |
| 2807 |
// (PCODECHAL_ENCODE_VP9_STATE)pvStandardState.resVdencSegmentMapStreamOut, |
| 2808 |
// CodechalDbgAttr::attrOutput, |
| 2809 |
// "SegMap_Out", |
| 2810 |
// CODECHAL_CACHELINE_SIZE * MOS_ROUNDUP_DIVIDE(pEncoder->dwFrameHeight, 64) * MOS_ROUNDUP_DIVIDE(pEncoder->dwFrameWidth, 64), |
| 2811 |
// 0, |
| 2812 |
// CODECHAL_MEDIA_STATE_VP9_PAK_LUMA_RECON); |
| 2813 |
} |
| 2814 |
|
| 2815 |
if (m_mmcState && !m_mmcUserFeatureUpdated) { |
| 2816 |
m_mmcState->UpdateUserFeatureKey(&m_reconSurface); |
| 2817 |
m_mmcUserFeatureUpdated = true; |
| 2818 |
}); |
| 2819 |
} |
| 2820 |
|
| 2821 |
// Reset parameters for next PAK execution |
| 2822 |
if (IsLastPipe() && IsLastPass()) |
| 2823 |
{ |
| 2824 |
if (m_vp9PicParams->PicFlags.fields.super_frame && m_tsEnabled) |
| 2825 |
{ |
| 2826 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ConstructSuperFrame()); |
| 2827 |
} |
| 2828 |
|
| 2829 |
if ((currentPipe == 0) && |
| 2830 |
m_signalEnc && |
| 2831 |
!Mos_ResourceIsNull(&m_resSyncObjectVideoContextInUse)) |
| 2832 |
{ |
| 2833 |
// signal semaphore |
| 2834 |
MOS_SYNC_PARAMS syncParams; |
| 2835 |
syncParams = g_cInitSyncParams; |
| 2836 |
syncParams.GpuContext = m_videoContext; |
| 2837 |
syncParams.presSyncResource = &m_resSyncObjectVideoContextInUse; |
| 2838 |
|
| 2839 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineSignal(m_osInterface, &syncParams)); |
| 2840 |
m_semaphoreObjCount++; |
| 2841 |
} |
| 2842 |
|
| 2843 |
m_prevFrameInfo.KeyFrame = !m_vp9PicParams->PicFlags.fields.frame_type; |
| 2844 |
m_prevFrameInfo.IntraOnly = (m_vp9PicParams->PicFlags.fields.frame_type == CODEC_VP9_KEY_FRAME) || m_vp9PicParams->PicFlags.fields.intra_only; |
| 2845 |
m_prevFrameInfo.ShowFrame = m_vp9PicParams->PicFlags.fields.show_frame; |
| 2846 |
m_prevFrameInfo.FrameWidth = m_oriFrameWidth; |
| 2847 |
m_prevFrameInfo.FrameHeight = m_oriFrameHeight; |
| 2848 |
m_currMvTemporalBufferIndex ^= 0x01; |
| 2849 |
m_contextFrameTypes[m_vp9PicParams->PicFlags.fields.frame_context_idx] = m_vp9PicParams->PicFlags.fields.frame_type; |
| 2850 |
m_prevFrameSegEnabled = m_vp9PicParams->PicFlags.fields.segmentation_enabled; |
| 2851 |
|
| 2852 |
// Reset parameters for next PAK execution |
| 2853 |
if ((!m_singleTaskPhaseSupported) && (IsLastPass())) |
| 2854 |
{ |
| 2855 |
m_osInterface->pfnResetPerfBufferID(m_osInterface); |
| 2856 |
} |
| 2857 |
|
| 2858 |
m_newPpsHeader = 0; |
| 2859 |
m_newSeqHeader = 0; |
| 2860 |
m_frameNum++; |
| 2861 |
//Save the last frame's scalable mode flag to prevent switching buffers when doing next pass |
| 2862 |
m_lastFrameScalableMode = m_scalableMode; |
| 2863 |
} |
| 2864 |
|
| 2865 |
return eStatus; |
| 2866 |
} |
| 2867 |
|
| 2868 |
MOS_STATUS CodechalVdencVp9StateG12::ExecuteSliceLevel() |
| 2869 |
{ |
| 2870 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2871 |
|
| 2872 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2873 |
|
| 2874 |
return ExecuteTileLevel(); |
| 2875 |
} |
| 2876 |
|
| 2877 |
void CodechalVdencVp9StateG12::SetHcpPipeModeSelectParams(MHW_VDBOX_PIPE_MODE_SELECT_PARAMS& pipeModeSelectParams) |
| 2878 |
{ |
| 2879 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2880 |
|
| 2881 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2882 |
|
| 2883 |
CodechalVdencVp9State::SetHcpPipeModeSelectParams(pipeModeSelectParams); |
| 2884 |
|
| 2885 |
MHW_VDBOX_PIPE_MODE_SELECT_PARAMS_G12& pipeModeSelectParamsG12 = static_cast<MHW_VDBOX_PIPE_MODE_SELECT_PARAMS_G12&>(pipeModeSelectParams); |
| 2886 |
|
| 2887 |
pipeModeSelectParamsG12.MultiEngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_FE_LEGACY; |
| 2888 |
pipeModeSelectParamsG12.PipeWorkMode = MHW_VDBOX_HCP_PIPE_WORK_MODE_LEGACY; |
| 2889 |
pipeModeSelectParamsG12.bDynamicScalingEnabled = (m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled; |
| 2890 |
if (m_scalableMode) |
| 2891 |
{ |
| 2892 |
// Running in the multiple VDBOX mode |
| 2893 |
if (IsFirstPipe()) |
| 2894 |
{ |
| 2895 |
pipeModeSelectParamsG12.MultiEngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_LEFT; |
| 2896 |
} |
| 2897 |
else |
| 2898 |
{ |
| 2899 |
if (IsLastPipe()) |
| 2900 |
{ |
| 2901 |
pipeModeSelectParamsG12.MultiEngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_RIGHT; |
| 2902 |
} |
| 2903 |
else |
| 2904 |
{ |
| 2905 |
pipeModeSelectParamsG12.MultiEngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_MIDDLE; |
| 2906 |
} |
| 2907 |
} |
| 2908 |
|
| 2909 |
pipeModeSelectParamsG12.PipeWorkMode = MHW_VDBOX_HCP_PIPE_WORK_MODE_CODEC_BE; |
| 2910 |
} |
| 2911 |
|
| 2912 |
return; |
| 2913 |
} |
| 2914 |
|
| 2915 |
void CodechalVdencVp9StateG12::SetHcpIndObjBaseAddrParams(MHW_VDBOX_IND_OBJ_BASE_ADDR_PARAMS& indObjBaseAddrParams) |
| 2916 |
{ |
| 2917 |
CodechalVdencVp9State::SetHcpIndObjBaseAddrParams(indObjBaseAddrParams); |
| 2918 |
|
| 2919 |
PCODECHAL_ENCODE_BUFFER tileRecordBuffer = &m_tileRecordBuffer[m_virtualEngineBBIndex]; |
| 2920 |
bool useTileRecordBuffer = !Mos_ResourceIsNull(&tileRecordBuffer->sResource); |
| 2921 |
|
| 2922 |
if (m_scalableMode && m_hucEnabled && m_isTilingSupported) |
| 2923 |
{ |
| 2924 |
// overwrite presProbabilityCounterBuffer and it's params for scalable mode |
| 2925 |
indObjBaseAddrParams.presProbabilityCounterBuffer = &m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex].sResource; |
| 2926 |
indObjBaseAddrParams.dwProbabilityCounterOffset = m_tileStatsOffset.counterBuffer; |
| 2927 |
indObjBaseAddrParams.dwProbabilityCounterSize = m_statsSize.counterBuffer; |
| 2928 |
} |
| 2929 |
|
| 2930 |
// Need to use presPakTileSizeStasBuffer instead of presTileRecordBuffer, so setting to null |
| 2931 |
indObjBaseAddrParams.presTileRecordBuffer = nullptr; |
| 2932 |
indObjBaseAddrParams.dwTileRecordSize = 0; |
| 2933 |
indObjBaseAddrParams.presPakTileSizeStasBuffer = useTileRecordBuffer? &tileRecordBuffer->sResource : nullptr; |
| 2934 |
indObjBaseAddrParams.dwPakTileSizeStasBufferSize = useTileRecordBuffer? ((m_statsSize.tileSizeRecord) * GetNumTilesInFrame()) : 0; |
| 2935 |
indObjBaseAddrParams.dwPakTileSizeRecordOffset = useTileRecordBuffer? m_tileStatsOffset.tileSizeRecord: 0; |
| 2936 |
} |
| 2937 |
|
| 2938 |
MOS_STATUS CodechalVdencVp9StateG12::VerifyCommandBufferSize() |
| 2939 |
{ |
| 2940 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2941 |
|
| 2942 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2943 |
|
| 2944 |
if (UseLegacyCommandBuffer()) // legacy mode & resize CommandBuffer Size for every BRC pass |
| 2945 |
{ |
| 2946 |
if (!m_singleTaskPhaseSupported) |
| 2947 |
{ |
| 2948 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(VerifySpaceAvailable()); |
| 2949 |
} |
| 2950 |
} |
| 2951 |
else // virtual engine |
| 2952 |
{ |
| 2953 |
uint32_t requestedSize = |
| 2954 |
m_pictureStatesSize + |
| 2955 |
m_picturePatchListSize + |
| 2956 |
m_extraPictureStatesSize + |
| 2957 |
(m_sliceStatesSize * m_numSlices); |
| 2958 |
requestedSize += requestedSize*m_numPassesInOnePipe; |
| 2959 |
if (m_hucEnabled && m_brcEnabled) |
| 2960 |
{ |
| 2961 |
requestedSize += m_brcMaxNumPasses*(m_defaultHucCmdsSize + m_defaultHucPatchListSize); |
| 2962 |
} |
| 2963 |
// Running in the multiple VDBOX mode |
| 2964 |
int currentPipe = GetCurrentPipe(); |
| 2965 |
int currentPass = GetCurrentPass(); |
| 2966 |
if (currentPipe < 0 || currentPipe >= m_numPipe) |
| 2967 |
{ |
| 2968 |
return MOS_STATUS_INVALID_PARAMETER; |
| 2969 |
} |
| 2970 |
if (currentPass < 0 || currentPass >= m_brcMaxNumPasses) |
| 2971 |
{ |
| 2972 |
return MOS_STATUS_INVALID_PARAMETER; |
| 2973 |
} |
| 2974 |
|
| 2975 |
if (IsFirstPipe() && m_osInterface->bUsesPatchList) |
| 2976 |
{ |
| 2977 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(VerifySpaceAvailable()); |
| 2978 |
} |
| 2979 |
uint8_t passIndex = m_singleTaskPhaseSupported ? 0 : currentPass; |
| 2980 |
PMOS_COMMAND_BUFFER cmdBuffer; |
| 2981 |
if (m_osInterface->phasedSubmission) |
| 2982 |
{ |
| 2983 |
m_osInterface->pfnVerifyCommandBufferSize(m_osInterface, requestedSize, 0); |
| 2984 |
return eStatus; |
| 2985 |
} |
| 2986 |
else |
| 2987 |
{ |
| 2988 |
cmdBuffer = &m_veBatchBuffer[m_virtualEngineBBIndex][(uint32_t)currentPipe][passIndex]; |
| 2989 |
} |
| 2990 |
|
| 2991 |
if (Mos_ResourceIsNull(&cmdBuffer->OsResource) || |
| 2992 |
m_sizeOfVEBatchBuffer < requestedSize) |
| 2993 |
{ |
| 2994 |
MOS_ALLOC_GFXRES_PARAMS allocParamsForBufferLinear; |
| 2995 |
|
| 2996 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 2997 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 2998 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 2999 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 3000 |
allocParamsForBufferLinear.dwBytes = requestedSize; |
| 3001 |
allocParamsForBufferLinear.pBufName = "Batch buffer for each VDBOX"; |
| 3002 |
|
| 3003 |
if (!Mos_ResourceIsNull(&cmdBuffer->OsResource)) |
| 3004 |
{ |
| 3005 |
if (cmdBuffer->pCmdBase) |
| 3006 |
{ |
| 3007 |
m_osInterface->pfnUnlockResource(m_osInterface, &cmdBuffer->OsResource); |
| 3008 |
} |
| 3009 |
m_osInterface->pfnFreeResource(m_osInterface, &cmdBuffer->OsResource); |
| 3010 |
} |
| 3011 |
|
| 3012 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 3013 |
m_osInterface, |
| 3014 |
&allocParamsForBufferLinear, |
| 3015 |
&cmdBuffer->OsResource); |
| 3016 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus); |
| 3017 |
|
| 3018 |
m_sizeOfVEBatchBuffer = requestedSize; |
| 3019 |
} |
| 3020 |
|
| 3021 |
if (cmdBuffer->pCmdBase == 0) |
| 3022 |
{ |
| 3023 |
MOS_LOCK_PARAMS lockParams; |
| 3024 |
MOS_ZeroMemory(&lockParams, sizeof(lockParams)); |
| 3025 |
lockParams.WriteOnly = true; |
| 3026 |
cmdBuffer->pCmdPtr = cmdBuffer->pCmdBase = (uint32_t *)m_osInterface->pfnLockResource(m_osInterface, &cmdBuffer->OsResource, &lockParams); |
| 3027 |
cmdBuffer->iRemaining = m_sizeOfVEBatchBuffer; |
| 3028 |
cmdBuffer->iOffset = 0; |
| 3029 |
|
| 3030 |
if (cmdBuffer->pCmdBase == nullptr) |
| 3031 |
{ |
| 3032 |
return MOS_STATUS_NULL_POINTER; |
| 3033 |
} |
| 3034 |
} |
| 3035 |
} |
| 3036 |
|
| 3037 |
return eStatus; |
| 3038 |
} |
| 3039 |
|
| 3040 |
MOS_STATUS CodechalVdencVp9StateG12::GetCommandBuffer( |
| 3041 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 3042 |
{ |
| 3043 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3044 |
|
| 3045 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3046 |
|
| 3047 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 3048 |
|
| 3049 |
if (UseLegacyCommandBuffer()) // legacy mode |
| 3050 |
{ |
| 3051 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, cmdBuffer, 0)); |
| 3052 |
} |
| 3053 |
else // virtual engine |
| 3054 |
{ |
| 3055 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, &m_realCmdBuffer, 0)); |
| 3056 |
if (m_osInterface->phasedSubmission) |
| 3057 |
{ |
| 3058 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, cmdBuffer, GetCurrentPipe() + 1)); |
| 3059 |
|
| 3060 |
CodecHalEncodeScalability_EncodePhaseToSubmissionType(IsFirstPipe(), cmdBuffer); |
| 3061 |
if (IsLastPipe()) |
| 3062 |
{ |
| 3063 |
cmdBuffer->iSubmissionType |= SUBMISSION_TYPE_MULTI_PIPE_FLAGS_LAST_PIPE; |
| 3064 |
} |
| 3065 |
} |
| 3066 |
else |
| 3067 |
{ |
| 3068 |
int currentPipe = GetCurrentPipe(); |
| 3069 |
int currentPass = GetCurrentPass(); |
| 3070 |
if (currentPipe < 0 || currentPipe >= m_numPipe) |
| 3071 |
{ |
| 3072 |
return MOS_STATUS_INVALID_PARAMETER; |
| 3073 |
} |
| 3074 |
uint8_t passIndex = m_singleTaskPhaseSupported ? 0 : currentPass; |
| 3075 |
*cmdBuffer = m_veBatchBuffer[m_virtualEngineBBIndex][currentPipe][passIndex]; |
| 3076 |
} |
| 3077 |
} |
| 3078 |
|
| 3079 |
return eStatus; |
| 3080 |
} |
| 3081 |
|
| 3082 |
MOS_STATUS CodechalVdencVp9StateG12::ReturnCommandBuffer( |
| 3083 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 3084 |
{ |
| 3085 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3086 |
|
| 3087 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3088 |
|
| 3089 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 3090 |
|
| 3091 |
if (UseLegacyCommandBuffer()) // legacy mode |
| 3092 |
{ |
| 3093 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, cmdBuffer, 0); |
| 3094 |
} |
| 3095 |
else // virtual engine |
| 3096 |
{ |
| 3097 |
if (m_osInterface->phasedSubmission) |
| 3098 |
{ |
| 3099 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, cmdBuffer, GetCurrentPipe() + 1); |
| 3100 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, &m_realCmdBuffer, 0); |
| 3101 |
} |
| 3102 |
else |
| 3103 |
{ |
| 3104 |
|
| 3105 |
int currentPipe = GetCurrentPipe(); |
| 3106 |
int currentPass = GetCurrentPass(); |
| 3107 |
if (currentPipe < 0 || currentPipe >= m_numPipe) |
| 3108 |
{ |
| 3109 |
return MOS_STATUS_INVALID_PARAMETER; |
| 3110 |
} |
| 3111 |
|
| 3112 |
if (eStatus == MOS_STATUS_SUCCESS) |
| 3113 |
{ |
| 3114 |
uint8_t passIndex = m_singleTaskPhaseSupported ? 0 : currentPass; |
| 3115 |
m_veBatchBuffer[m_virtualEngineBBIndex][currentPipe][passIndex] = *cmdBuffer; |
| 3116 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, &m_realCmdBuffer, 0); |
| 3117 |
} |
| 3118 |
} |
| 3119 |
} |
| 3120 |
|
| 3121 |
return eStatus; |
| 3122 |
} |
| 3123 |
|
| 3124 |
MOS_STATUS CodechalVdencVp9StateG12::SubmitCommandBuffer( |
| 3125 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 3126 |
bool bNullRendering) |
| 3127 |
{ |
| 3128 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3129 |
|
| 3130 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3131 |
|
| 3132 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 3133 |
|
| 3134 |
if (UseLegacyCommandBuffer()) // legacy mode |
| 3135 |
{ |
| 3136 |
if (!IsRenderContext()) // Set VE Hints for video contexts only |
| 3137 |
{ |
| 3138 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetAndPopulateVEHintParams(cmdBuffer)); |
| 3139 |
} |
| 3140 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnSubmitCommandBuffer(m_osInterface, cmdBuffer, bNullRendering)); |
| 3141 |
} |
| 3142 |
else // virtual engine |
| 3143 |
{ |
| 3144 |
if (!IsLastPipe()) |
| 3145 |
{ |
| 3146 |
return eStatus; |
| 3147 |
} |
| 3148 |
|
| 3149 |
if (m_osInterface->phasedSubmission) |
| 3150 |
{ |
| 3151 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnSubmitCommandBuffer(m_osInterface, &m_realCmdBuffer, bNullRendering)); |
| 3152 |
} |
| 3153 |
else |
| 3154 |
{ |
| 3155 |
int currentPass = GetCurrentPass(); |
| 3156 |
for (auto i = 0; i < m_numPipe; i++) |
| 3157 |
{ |
| 3158 |
uint8_t passIndex = m_singleTaskPhaseSupported ? 0 : currentPass; |
| 3159 |
PMOS_COMMAND_BUFFER cmdBuffer = &m_veBatchBuffer[m_virtualEngineBBIndex][i][passIndex]; |
| 3160 |
|
| 3161 |
if (cmdBuffer->pCmdBase) |
| 3162 |
{ |
| 3163 |
m_osInterface->pfnUnlockResource(m_osInterface, &cmdBuffer->OsResource); |
| 3164 |
} |
| 3165 |
|
| 3166 |
cmdBuffer->pCmdBase = 0; |
| 3167 |
cmdBuffer->iOffset = cmdBuffer->iRemaining = 0; |
| 3168 |
} |
| 3169 |
|
| 3170 |
if (eStatus == MOS_STATUS_SUCCESS) |
| 3171 |
{ |
| 3172 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetAndPopulateVEHintParams(&m_realCmdBuffer)); |
| 3173 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnSubmitCommandBuffer(m_osInterface, &m_realCmdBuffer, bNullRendering)); |
| 3174 |
} |
| 3175 |
} |
| 3176 |
} |
| 3177 |
|
| 3178 |
return eStatus; |
| 3179 |
} |
| 3180 |
|
| 3181 |
MOS_STATUS CodechalVdencVp9StateG12::SendPrologWithFrameTracking( |
| 3182 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 3183 |
bool frameTrackingRequested, |
| 3184 |
MHW_MI_MMIOREGISTERS *mmioRegister) |
| 3185 |
{ |
| 3186 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3187 |
|
| 3188 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3189 |
|
| 3190 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 3191 |
|
| 3192 |
MOS_GPU_CONTEXT gpuContext = m_osInterface->pfnGetGpuContext(m_osInterface); |
| 3193 |
|
| 3194 |
if (IsRenderContext()) //Render context only |
| 3195 |
{ |
| 3196 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncoderState::SendPrologWithFrameTracking(cmdBuffer, frameTrackingRequested, mmioRegister)); |
| 3197 |
return eStatus; |
| 3198 |
} |
| 3199 |
else // Legacy mode or virtual engine |
| 3200 |
{ |
| 3201 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState); |
| 3202 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mmcState->SendPrologCmd(m_miInterface, cmdBuffer, gpuContext)); |
| 3203 |
|
| 3204 |
if (!IsLastPipe()) |
| 3205 |
{ |
| 3206 |
return eStatus; |
| 3207 |
} |
| 3208 |
PMOS_COMMAND_BUFFER commandBufferInUse; |
| 3209 |
if (m_realCmdBuffer.pCmdBase) |
| 3210 |
{ |
| 3211 |
commandBufferInUse = &m_realCmdBuffer; //virtual engine mode |
| 3212 |
} |
| 3213 |
else |
| 3214 |
{ |
| 3215 |
if (cmdBuffer && cmdBuffer->pCmdBase) |
| 3216 |
{ |
| 3217 |
commandBufferInUse = cmdBuffer; //legacy mode |
| 3218 |
} |
| 3219 |
else |
| 3220 |
{ |
| 3221 |
eStatus = MOS_STATUS_INVALID_PARAMETER; |
| 3222 |
return eStatus; |
| 3223 |
} |
| 3224 |
} |
| 3225 |
|
| 3226 |
commandBufferInUse->Attributes.bTurboMode = m_hwInterface->m_turboMode; |
| 3227 |
commandBufferInUse->Attributes.dwNumRequestedEUSlices = m_hwInterface->m_numRequestedEuSlices; |
| 3228 |
commandBufferInUse->Attributes.dwNumRequestedSubSlices = m_hwInterface->m_numRequestedSubSlices; |
| 3229 |
commandBufferInUse->Attributes.dwNumRequestedEUs = m_hwInterface->m_numRequestedEus; |
| 3230 |
commandBufferInUse->Attributes.bValidPowerGatingRequest = true; |
| 3231 |
|
| 3232 |
if (frameTrackingRequested && m_frameTrackingEnabled) |
| 3233 |
{ |
| 3234 |
commandBufferInUse->Attributes.bEnableMediaFrameTracking = true; |
| 3235 |
commandBufferInUse->Attributes.resMediaFrameTrackingSurface = |
| 3236 |
&m_encodeStatusBuf.resStatusBuffer; |
| 3237 |
commandBufferInUse->Attributes.dwMediaFrameTrackingTag = m_storeData; |
| 3238 |
// Set media frame tracking address offset(the offset from the encoder status buffer page) |
| 3239 |
commandBufferInUse->Attributes.dwMediaFrameTrackingAddrOffset = 0; |
| 3240 |
} |
| 3241 |
|
| 3242 |
MHW_GENERIC_PROLOG_PARAMS genericPrologParams; |
| 3243 |
MOS_ZeroMemory(&genericPrologParams, sizeof(genericPrologParams)); |
| 3244 |
genericPrologParams.pOsInterface = m_hwInterface->GetOsInterface(); |
| 3245 |
genericPrologParams.pvMiInterface = m_hwInterface->GetMiInterface(); |
| 3246 |
genericPrologParams.bMmcEnabled = m_mmcState ? m_mmcState->IsMmcEnabled() : false; |
| 3247 |
genericPrologParams.dwStoreDataValue = m_storeData - 1; |
| 3248 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(Mhw_SendGenericPrologCmd(commandBufferInUse, &genericPrologParams)); |
| 3249 |
} |
| 3250 |
|
| 3251 |
return eStatus; |
| 3252 |
} |
| 3253 |
|
| 3254 |
MOS_STATUS CodechalVdencVp9StateG12::SetSemaphoreMem( |
| 3255 |
PMOS_RESOURCE semaphoreMem, |
| 3256 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 3257 |
uint32_t value) |
| 3258 |
{ |
| 3259 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3260 |
|
| 3261 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3262 |
|
| 3263 |
CODECHAL_ENCODE_CHK_NULL_RETURN(semaphoreMem); |
| 3264 |
MHW_MI_STORE_DATA_PARAMS storeDataParams; |
| 3265 |
MOS_ZeroMemory(&storeDataParams, sizeof(storeDataParams)); |
| 3266 |
storeDataParams.pOsResource = semaphoreMem; |
| 3267 |
storeDataParams.dwResourceOffset = 0; |
| 3268 |
storeDataParams.dwValue = value; |
| 3269 |
|
| 3270 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreDataImmCmd( |
| 3271 |
cmdBuffer, |
| 3272 |
&storeDataParams)); |
| 3273 |
|
| 3274 |
return eStatus; |
| 3275 |
} |
| 3276 |
|
| 3277 |
MOS_STATUS CodechalVdencVp9StateG12::SendHWWaitCommand( |
| 3278 |
PMOS_RESOURCE semaphoreMem, |
| 3279 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 3280 |
uint32_t value) |
| 3281 |
{ |
| 3282 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3283 |
|
| 3284 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3285 |
CODECHAL_ENCODE_CHK_NULL_RETURN(semaphoreMem); |
| 3286 |
|
| 3287 |
MHW_MI_SEMAPHORE_WAIT_PARAMS semaphoreWaitParams; |
| 3288 |
MOS_ZeroMemory(&semaphoreWaitParams, sizeof(semaphoreWaitParams)); |
| 3289 |
semaphoreWaitParams.presSemaphoreMem = semaphoreMem; |
| 3290 |
semaphoreWaitParams.bPollingWaitMode = true; |
| 3291 |
semaphoreWaitParams.dwSemaphoreData = value; |
| 3292 |
semaphoreWaitParams.CompareOperation = MHW_MI_SAD_EQUAL_SDD; |
| 3293 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiSemaphoreWaitCmd(cmdBuffer, &semaphoreWaitParams)); |
| 3294 |
|
| 3295 |
return eStatus; |
| 3296 |
} |
| 3297 |
|
| 3298 |
MOS_STATUS CodechalVdencVp9StateG12::SetDmemHuCPakInt() |
| 3299 |
{ |
| 3300 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3301 |
|
| 3302 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3303 |
|
| 3304 |
uint8_t currPass = (uint8_t)GetCurrentPass(); |
| 3305 |
|
| 3306 |
MOS_LOCK_PARAMS lockFlags; |
| 3307 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 3308 |
lockFlags.WriteOnly = 1; |
| 3309 |
// All bytes in below dmem for fields not used by VP9 to be set to 0xFF. |
| 3310 |
HucPakIntDmem* dmem = (HucPakIntDmem*)m_osInterface->pfnLockResource( |
| 3311 |
m_osInterface, &m_hucPakIntDmemBuffer[m_currRecycledBufIdx][currPass], &lockFlags); |
| 3312 |
CODECHAL_ENCODE_CHK_NULL_RETURN(dmem); |
| 3313 |
|
| 3314 |
MOS_ZeroMemory(dmem, sizeof(HucPakIntDmem)); |
| 3315 |
// CODECHAL_VDENC_VP9_PAK_INT_DMEM_OFFSETS_SIZE size of offsets in the CODECHAL_VDENC_VP9_HUC_PAK_INT_DMEM struct. |
| 3316 |
// Reset offsets to 0xFFFFFFFF as unavailable |
| 3317 |
memset(dmem, 0xFF, m_pakIntDmemOffsetsSize); |
| 3318 |
|
| 3319 |
dmem->totalSizeInCommandBuffer = GetNumTilesInFrame() * CODECHAL_CACHELINE_SIZE; |
| 3320 |
dmem->offsetInCommandBuffer = 0xFFFF; // Not used for VP9, all bytes in dmem for fields not used are 0xFF |
| 3321 |
dmem->picWidthInPixel = (uint16_t)m_frameWidth; |
| 3322 |
dmem->picHeightInPixel = (uint16_t)m_frameHeight; |
| 3323 |
dmem->totalNumberOfPaks = m_numPipe; |
| 3324 |
dmem->codec = m_pakIntVp9CodecId; |
| 3325 |
dmem->maxPass = m_brcMaxNumPasses; // Only VDEnc CQP and BRC |
| 3326 |
dmem->currentPass = currPass + 1; |
| 3327 |
dmem->lastTileBSStartInBytes = m_tileParams[GetNumTilesInFrame() - 1].TileSizeStreamoutOffset * CODECHAL_CACHELINE_SIZE + 8; |
| 3328 |
dmem->picStateStartInBytes = 0xFFFF; |
| 3329 |
|
| 3330 |
if (m_enableTileStitchByHW) |
| 3331 |
{ |
| 3332 |
dmem->StitchEnable = true; |
| 3333 |
dmem->StitchCommandOffset = 0; |
| 3334 |
dmem->BBEndforStitch = HUC_BATCH_BUFFER_END; |
| 3335 |
} |
| 3336 |
|
| 3337 |
// Offset 0 is for region 1 - output of integrated frame stats from PAK integration kernel |
| 3338 |
|
| 3339 |
dmem->tileSizeRecordOffset[0] = m_frameStatsOffset.tileSizeRecord; |
| 3340 |
dmem->vdencStatOffset[0] = m_frameStatsOffset.vdencStats; |
| 3341 |
dmem->vp9PakStatOffset[0] = m_frameStatsOffset.pakStats; |
| 3342 |
dmem->vp9CounterBufferOffset[0] = m_frameStatsOffset.counterBuffer; |
| 3343 |
|
| 3344 |
//Offset 1 - 4 is for region 0 - Input to PAK integration kernel for all tile statistics per pipe |
| 3345 |
for (auto i = 1; i <= m_numPipe; i++) |
| 3346 |
{ |
| 3347 |
dmem->numTiles[i - 1] = (GetNumTilesInFrame()) / m_numPipe; |
| 3348 |
dmem->tileSizeRecordOffset[i] = m_tileStatsOffset.tileSizeRecord + ((i - 1)*(dmem->numTiles[i - 1])*m_statsSize.tileSizeRecord); |
| 3349 |
dmem->vdencStatOffset[i] = m_tileStatsOffset.vdencStats + ((i - 1)*(dmem->numTiles[i - 1])*m_statsSize.vdencStats); |
| 3350 |
dmem->vp9PakStatOffset[i] = m_tileStatsOffset.pakStats + ((i - 1)*(dmem->numTiles[i - 1])*m_statsSize.pakStats); |
| 3351 |
dmem->vp9CounterBufferOffset[i] = m_tileStatsOffset.counterBuffer + ((i - 1)*(dmem->numTiles[i - 1])*m_statsSize.counterBuffer); |
| 3352 |
} |
| 3353 |
m_osInterface->pfnUnlockResource(m_osInterface, &m_hucPakIntDmemBuffer[m_currRecycledBufIdx][currPass]); |
| 3354 |
|
| 3355 |
return eStatus; |
| 3356 |
} |
| 3357 |
|
| 3358 |
MOS_STATUS CodechalVdencVp9StateG12::SetSequenceStructs() |
| 3359 |
{ |
| 3360 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3361 |
|
| 3362 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3363 |
|
| 3364 |
#if defined(LINUX) && !defined(WDDM_LINUX) |
| 3365 |
MOS_SURFACE rawSurface; |
| 3366 |
PCODEC_VP9_ENCODE_SEQUENCE_PARAMS seqParams = (PCODEC_VP9_ENCODE_SEQUENCE_PARAMS)m_encodeParams.pSeqParams; |
| 3367 |
rawSurface = *(m_encodeParams.psRawSurface); |
| 3368 |
|
| 3369 |
if (rawSurface.OsResource.Format == Format_A8R8G8B8 || |
| 3370 |
rawSurface.OsResource.Format == Format_B10G10R10A2) |
| 3371 |
{ |
| 3372 |
seqParams->SeqFlags.fields.DisplayFormatSwizzle = 1; |
| 3373 |
} |
| 3374 |
#endif |
| 3375 |
|
| 3376 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalVdencVp9State::SetSequenceStructs()); |
| 3377 |
|
| 3378 |
// All pipe need to go through the picture-level and slice-level commands |
| 3379 |
m_numPassesInOnePipe = m_numPasses; |
| 3380 |
m_numPasses = (m_numPasses + 1) * m_numPipe - 1; |
| 3381 |
|
| 3382 |
return eStatus; |
| 3383 |
} |
| 3384 |
|
| 3385 |
MOS_STATUS CodechalVdencVp9StateG12::SetPictureStructs() |
| 3386 |
{ |
| 3387 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3388 |
|
| 3389 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3390 |
|
| 3391 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalVdencVp9State::SetPictureStructs()); |
| 3392 |
|
| 3393 |
m_virtualEngineBBIndex = m_currOriginalPic.FrameIdx; |
| 3394 |
m_picWidthInMinBlk = |
| 3395 |
MOS_ALIGN_CEIL(m_oriFrameWidth, CODEC_VP9_MIN_BLOCK_WIDTH); |
| 3396 |
m_picHeightInMinBlk = |
| 3397 |
MOS_ALIGN_CEIL(m_oriFrameHeight, CODEC_VP9_MIN_BLOCK_WIDTH); |
| 3398 |
|
| 3399 |
// When buffers start recycling , we need to know the index of last buffer for next frame. |
| 3400 |
if (m_dysRefFrameFlags != DYS_REF_NONE && m_dysVdencMultiPassEnabled) |
| 3401 |
{ |
| 3402 |
if (!m_hucEnabled) |
| 3403 |
{ |
| 3404 |
m_numPassesInOnePipe = (m_dysRefFrameFlags != DYS_REF_NONE); |
| 3405 |
} |
| 3406 |
if (m_vdencBrcEnabled) |
| 3407 |
{ |
| 3408 |
//Reduce per pipe passes by 1, as m_numPassesInOnePipe == 1 becomes m_numPassesInOnePipe = 0 for Huc to run |
| 3409 |
m_dysBrc = true; |
| 3410 |
m_numPassesInOnePipe = (m_numPassesInOnePipe > 0 ) ? m_numPassesInOnePipe - 1 : m_numPassesInOnePipe; |
| 3411 |
} |
| 3412 |
else |
| 3413 |
{ |
| 3414 |
m_dysCqp = true; |
| 3415 |
} |
| 3416 |
m_numPasses = (m_numPassesInOnePipe + 1) * m_numPipe - 1; |
| 3417 |
} |
| 3418 |
// This is BRC DYS SinglePass case |
| 3419 |
// Actually, repak is disabled |
| 3420 |
if (m_vdencBrcEnabled && (m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled) |
| 3421 |
{ |
| 3422 |
m_dysBrc = true; |
| 3423 |
m_numPassesInOnePipe = 1; |
| 3424 |
m_numPasses = (m_numPassesInOnePipe + 1) * m_numPipe - 1; |
| 3425 |
} |
| 3426 |
if (!m_vdencBrcEnabled && (m_dysRefFrameFlags != DYS_REF_NONE)) |
| 3427 |
{ |
| 3428 |
m_dysCqp = true; |
| 3429 |
} |
| 3430 |
|
| 3431 |
//WA to clear CCS by VE resolve |
| 3432 |
if (MEDIA_IS_WA(m_waTable, Wa_1408785368)) |
| 3433 |
{ |
| 3434 |
bool clearccswa = false; |
| 3435 |
MOS_SURFACE surfaceDetails = {}; |
| 3436 |
m_osInterface->pfnGetResourceInfo(m_osInterface, &m_reconSurface.OsResource, &surfaceDetails); |
| 3437 |
|
| 3438 |
// Restore CCS if the surface's width/height is not aligned with that of current frame due to resolution change |
| 3439 |
if ((m_frameNum != 0) && |
| 3440 |
((surfaceDetails.dwWidth != m_picWidthInMinBlk) || |
| 3441 |
(surfaceDetails.dwHeight != m_picHeightInMinBlk))) |
| 3442 |
{ |
| 3443 |
clearccswa = true; |
| 3444 |
} |
| 3445 |
|
| 3446 |
if (clearccswa && m_mmcState && m_mmcState->IsMmcEnabled()) |
| 3447 |
{ |
| 3448 |
m_osInterface->pfnDecompResource(m_osInterface, &m_reconSurface.OsResource); |
| 3449 |
m_osInterface->pfnSetGpuContext(m_osInterface, m_renderContext); |
| 3450 |
} |
| 3451 |
} |
| 3452 |
|
| 3453 |
return eStatus; |
| 3454 |
} |
| 3455 |
|
| 3456 |
MOS_STATUS CodechalVdencVp9StateG12::ExecutePictureLevel() |
| 3457 |
{ |
| 3458 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3459 |
|
| 3460 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3461 |
|
| 3462 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(VerifyCommandBufferSize()); |
| 3463 |
|
| 3464 |
PerfTagSetting perfTag; |
| 3465 |
perfTag.Value = 0; |
| 3466 |
perfTag.Mode = (uint16_t)m_mode & CODECHAL_ENCODE_MODE_BIT_MASK; |
| 3467 |
perfTag.CallType = CODECHAL_ENCODE_PERFTAG_CALL_PAK_ENGINE; |
| 3468 |
perfTag.PictureCodingType = m_pictureCodingType; |
| 3469 |
m_osInterface->pfnSetPerfTag(m_osInterface, perfTag.Value); |
| 3470 |
|
| 3471 |
if ((m_dysRefFrameFlags == DYS_REF_NONE) && m_pakOnlyModeEnabledForLastPass) |
| 3472 |
{ |
| 3473 |
//This flag sets pak-only mode in slbb for RePak pass. In single-pass mode, this flag should be disabled. |
| 3474 |
m_vdencPakonlyMultipassEnabled = ((m_numPasses > 0) && (IsLastPass())) ? true : false; |
| 3475 |
} |
| 3476 |
|
| 3477 |
// Scalable Mode header |
| 3478 |
if (m_scalableMode) |
| 3479 |
{ |
| 3480 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 3481 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 3482 |
|
| 3483 |
MHW_MI_FORCE_WAKEUP_PARAMS forceWakeupParams; |
| 3484 |
MOS_ZeroMemory(&forceWakeupParams, sizeof(MHW_MI_FORCE_WAKEUP_PARAMS)); |
| 3485 |
forceWakeupParams.bMFXPowerWellControl = true; |
| 3486 |
forceWakeupParams.bMFXPowerWellControlMask = true; |
| 3487 |
forceWakeupParams.bHEVCPowerWellControl = true; |
| 3488 |
forceWakeupParams.bHEVCPowerWellControlMask = true; |
| 3489 |
|
| 3490 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiForceWakeupCmd( |
| 3491 |
&cmdBuffer, |
| 3492 |
&forceWakeupParams)); |
| 3493 |
|
| 3494 |
bool requestFrameTracking = m_singleTaskPhaseSupported ? IsFirstPass() : IsLastPass(); |
| 3495 |
// In scalable mode, command buffer header is sent on last pipe only |
| 3496 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking(&cmdBuffer, requestFrameTracking)); |
| 3497 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReturnCommandBuffer(&cmdBuffer)); |
| 3498 |
} |
| 3499 |
|
| 3500 |
// for VDENC dynamic scaling, here are the steps we need to process |
| 3501 |
// 1. Use PAK to down scale the reference picture (PASS 0) |
| 3502 |
// 2. Run VDENC to stream out PakObjCmd (PASS 0) |
| 3503 |
// 3. Run VDENC (with PAK only multi pass enabled) to stream in PakObjCmd from previous pass (PASS 0) |
| 3504 |
// 4. Repak (PASS 1) - it is only for CQP mode |
| 3505 |
// 5. Extra note: Repak is disabled for BRC Dynamic scaling single pass mode |
| 3506 |
if (m_dysRefFrameFlags != DYS_REF_NONE) |
| 3507 |
{ |
| 3508 |
if (m_currPass == 0) |
| 3509 |
{ |
| 3510 |
// Turn off scalability and Tiling for Dynamic scaling pass 0 for reference scaling |
| 3511 |
uint8_t logTileRows = m_vp9PicParams->log2_tile_rows; |
| 3512 |
uint8_t logTileColumns = m_vp9PicParams->log2_tile_columns; |
| 3513 |
bool scalableMode = m_scalableMode; |
| 3514 |
uint8_t numPipe = m_numPipe; |
| 3515 |
m_vp9PicParams->log2_tile_rows = 0; |
| 3516 |
m_vp9PicParams->log2_tile_columns = 0; |
| 3517 |
m_scalableMode = false; |
| 3518 |
m_numPipe = 1; |
| 3519 |
// Execute Reference scaling pass |
| 3520 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(DysRefFrames()); |
| 3521 |
|
| 3522 |
// Restore scalability and Tiling status for subsequent passes |
| 3523 |
m_vp9PicParams->log2_tile_rows = logTileRows; |
| 3524 |
m_vp9PicParams->log2_tile_columns = logTileColumns; |
| 3525 |
m_scalableMode = scalableMode; |
| 3526 |
m_numPipe = numPipe; |
| 3527 |
|
| 3528 |
if (m_dysVdencMultiPassEnabled) |
| 3529 |
{ |
| 3530 |
m_vdencPakObjCmdStreamOutEnabled = true; |
| 3531 |
m_resVdencPakObjCmdStreamOutBuffer = &m_resMbCodeSurface; |
| 3532 |
// enable single task phase here since we need to combine the pakobj streamout and pakonly pass into one batch buffer |
| 3533 |
m_singleTaskPhaseSupported = true; |
| 3534 |
m_firstTaskInPhase = true; |
| 3535 |
|
| 3536 |
if (Mos_ResourceIsNull(&m_resVdencDysPictureState2NdLevelBatchBuffer)) |
| 3537 |
{ |
| 3538 |
MOS_ALLOC_GFXRES_PARAMS allocParamsForBufferLinear; |
| 3539 |
|
| 3540 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 3541 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 3542 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 3543 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 3544 |
allocParamsForBufferLinear.dwBytes = m_vdencPicStateSecondLevelBatchBufferSize; |
| 3545 |
allocParamsForBufferLinear.pBufName = "VDEnc DYS Picture Second Level Batch Buffer"; |
| 3546 |
|
| 3547 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 3548 |
m_osInterface, |
| 3549 |
&allocParamsForBufferLinear, |
| 3550 |
&m_resVdencDysPictureState2NdLevelBatchBuffer); |
| 3551 |
|
| 3552 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 3553 |
{ |
| 3554 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to allocate VDEnc DYS Picture Second Level Batch Buffer."); |
| 3555 |
return eStatus; |
| 3556 |
} |
| 3557 |
} |
| 3558 |
|
| 3559 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(VerifySpaceAvailable()); |
| 3560 |
} |
| 3561 |
else |
| 3562 |
{ |
| 3563 |
m_hucEnabled = m_dysHucEnabled; // recover huc state |
| 3564 |
} |
| 3565 |
} |
| 3566 |
else if (m_currPass == 1 && m_dysVdencMultiPassEnabled) |
| 3567 |
{ |
| 3568 |
m_hucEnabled = m_dysHucEnabled; // recover huc state |
| 3569 |
m_vdencPakonlyMultipassEnabled = true; |
| 3570 |
m_dysRefFrameFlags = DYS_REF_NONE; |
| 3571 |
m_currPass = 0; // reset ucCurrPass = 0 to run the Huc |
| 3572 |
m_lastTaskInPhase = false; |
| 3573 |
} |
| 3574 |
} |
| 3575 |
else |
| 3576 |
{ |
| 3577 |
if (!(IsLastPass())) |
| 3578 |
{ |
| 3579 |
m_vdencPakObjCmdStreamOutEnabled = true; |
| 3580 |
m_resVdencPakObjCmdStreamOutBuffer = &m_resMbCodeSurface; |
| 3581 |
} |
| 3582 |
else |
| 3583 |
{ |
| 3584 |
m_vdencPakObjCmdStreamOutEnabled = false; |
| 3585 |
} |
| 3586 |
} |
| 3587 |
|
| 3588 |
if (m_isTilingSupported) |
| 3589 |
{ |
| 3590 |
MOS_LOCK_PARAMS lockFlagsWriteOnly; |
| 3591 |
uint8_t* tileStatsData = nullptr; |
| 3592 |
MOS_ZeroMemory(&lockFlagsWriteOnly, sizeof(MOS_LOCK_PARAMS)); |
| 3593 |
lockFlagsWriteOnly.WriteOnly = 1; |
| 3594 |
if (Mos_ResourceIsNull(&m_tileRecordBuffer[m_virtualEngineBBIndex].sResource)) |
| 3595 |
{ |
| 3596 |
// Allocate Tile Stats Buffer for PAK integration and to be used everywhere for tile stats |
| 3597 |
MOS_ALLOC_GFXRES_PARAMS allocParamsForBufferLinear; |
| 3598 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 3599 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 3600 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 3601 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 3602 |
auto size = m_maxTileNumber * MOS_ALIGN_CEIL(m_hcpInterface->GetPakHWTileSizeRecordSize(), CODECHAL_CACHELINE_SIZE); |
| 3603 |
allocParamsForBufferLinear.dwBytes = size; |
| 3604 |
allocParamsForBufferLinear.pBufName = "Tile Record Buffer"; |
| 3605 |
|
| 3606 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 3607 |
m_osInterface, |
| 3608 |
&allocParamsForBufferLinear, |
| 3609 |
&m_tileRecordBuffer[m_virtualEngineBBIndex].sResource)); |
| 3610 |
m_tileRecordBuffer[m_virtualEngineBBIndex].dwSize = size; |
| 3611 |
auto tileRecordData = (uint8_t*)m_osInterface->pfnLockResource(m_osInterface, &m_tileRecordBuffer[m_virtualEngineBBIndex].sResource, &lockFlagsWriteOnly); |
| 3612 |
|
| 3613 |
MOS_ZeroMemory(tileRecordData, allocParamsForBufferLinear.dwBytes); |
| 3614 |
m_osInterface->pfnUnlockResource(m_osInterface, &m_tileRecordBuffer[m_virtualEngineBBIndex].sResource); |
| 3615 |
} |
| 3616 |
} |
| 3617 |
|
| 3618 |
if (m_isTilingSupported && m_scalableMode && m_hucEnabled && IsFirstPipe() && IsFirstPass()) |
| 3619 |
{ |
| 3620 |
// Max row is 4 by VP9 Spec |
| 3621 |
uint32_t m_maxScalableModeRows = 4; |
| 3622 |
uint32_t m_maxScalableModeTiles = m_numVdbox * m_maxScalableModeRows; |
| 3623 |
|
| 3624 |
// Fill Pak integration kernel input tile stats structure |
| 3625 |
MOS_ZeroMemory(&m_tileStatsOffset, sizeof(StatsInfo)); |
| 3626 |
// TileSizeRecord has to be 4k aligned |
| 3627 |
m_tileStatsOffset.tileSizeRecord = 0; |
| 3628 |
// VdencStats has to be 4k aligned |
| 3629 |
m_tileStatsOffset.vdencStats = MOS_ALIGN_CEIL((m_tileStatsOffset.tileSizeRecord + (m_maxScalableModeTiles * m_statsSize.tileSizeRecord)), CODECHAL_PAGE_SIZE); |
| 3630 |
// VP9PAKStats has to be 64 byte aligned |
| 3631 |
m_tileStatsOffset.pakStats = MOS_ALIGN_CEIL((m_tileStatsOffset.vdencStats + (m_maxScalableModeTiles * m_statsSize.vdencStats)), CODECHAL_PAGE_SIZE); |
| 3632 |
// VP9CounterBuffer has to be 4k aligned |
| 3633 |
m_tileStatsOffset.counterBuffer = MOS_ALIGN_CEIL((m_tileStatsOffset.pakStats + (m_maxScalableModeTiles * m_statsSize.pakStats)), CODECHAL_PAGE_SIZE); |
| 3634 |
|
| 3635 |
MOS_LOCK_PARAMS lockFlagsWriteOnly; |
| 3636 |
uint8_t* tileStatsData = nullptr; |
| 3637 |
MOS_ZeroMemory(&lockFlagsWriteOnly, sizeof(MOS_LOCK_PARAMS)); |
| 3638 |
lockFlagsWriteOnly.WriteOnly = 1; |
| 3639 |
|
| 3640 |
if (Mos_ResourceIsNull(&m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex].sResource)) |
| 3641 |
{ |
| 3642 |
// Allocate Tile Stats Buffer for PAK integration and to be used everywhere for tile stats |
| 3643 |
MOS_ALLOC_GFXRES_PARAMS allocParamsForBufferLinear; |
| 3644 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 3645 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 3646 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 3647 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 3648 |
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL((m_tileStatsOffset.counterBuffer + (m_maxScalableModeTiles * m_statsSize.counterBuffer)), CODECHAL_PAGE_SIZE); |
| 3649 |
allocParamsForBufferLinear.pBufName = "GEN12 Tile Level Statistics Buffer"; |
| 3650 |
|
| 3651 |
m_tileStatsPakIntegrationBufferSize = allocParamsForBufferLinear.dwBytes; |
| 3652 |
|
| 3653 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 3654 |
m_osInterface, |
| 3655 |
&allocParamsForBufferLinear, |
| 3656 |
&m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex].sResource)); |
| 3657 |
m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex].dwSize = allocParamsForBufferLinear.dwBytes; |
| 3658 |
|
| 3659 |
tileStatsData = (uint8_t*)m_osInterface->pfnLockResource(m_osInterface, &m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex].sResource, &lockFlagsWriteOnly); |
| 3660 |
|
| 3661 |
MOS_ZeroMemory(tileStatsData, allocParamsForBufferLinear.dwBytes); |
| 3662 |
m_osInterface->pfnUnlockResource(m_osInterface, &m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex].sResource); |
| 3663 |
} |
| 3664 |
} |
| 3665 |
|
| 3666 |
if (IsFirstPass()) |
| 3667 |
{ |
| 3668 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ConstructPakInsertObjBatchBuf(&m_resHucPakInsertUncompressedHeaderReadBuffer[m_currRecycledBufIdx])); |
| 3669 |
} |
| 3670 |
int currPass = GetCurrentPass(); |
| 3671 |
if ((m_dysRefFrameFlags != DYS_REF_NONE) && m_dysVdencMultiPassEnabled) |
| 3672 |
{ |
| 3673 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ConstructPicStateBatchBuf(&m_resVdencDysPictureState2NdLevelBatchBuffer)); |
| 3674 |
} |
| 3675 |
else |
| 3676 |
{ |
| 3677 |
if (IsFirstPipe()) |
| 3678 |
{ |
| 3679 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ConstructPicStateBatchBuf(&m_resVdencPictureState2NdLevelBatchBufferRead[currPass][m_vdencPictureState2ndLevelBBIndex])); |
| 3680 |
} |
| 3681 |
|
| 3682 |
if (!m_scalableMode) |
| 3683 |
{ |
| 3684 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 3685 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 3686 |
MHW_MI_FORCE_WAKEUP_PARAMS forceWakeupParams; |
| 3687 |
MOS_ZeroMemory(&forceWakeupParams, sizeof(MHW_MI_FORCE_WAKEUP_PARAMS)); |
| 3688 |
forceWakeupParams.bMFXPowerWellControl = true; |
| 3689 |
forceWakeupParams.bMFXPowerWellControlMask = true; |
| 3690 |
forceWakeupParams.bHEVCPowerWellControl = true; |
| 3691 |
forceWakeupParams.bHEVCPowerWellControlMask = true; |
| 3692 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiForceWakeupCmd(&cmdBuffer, &forceWakeupParams)); |
| 3693 |
ReturnCommandBuffer(&cmdBuffer); |
| 3694 |
} |
| 3695 |
} |
| 3696 |
|
| 3697 |
if (m_dysRefFrameFlags != DYS_REF_NONE) |
| 3698 |
{ |
| 3699 |
m_brcReset = 1; |
| 3700 |
} |
| 3701 |
|
| 3702 |
if (m_vdencBrcEnabled && IsFirstPipe()) |
| 3703 |
{ |
| 3704 |
// Invoke BRC init/reset FW |
| 3705 |
if (m_brcInit || m_brcReset) |
| 3706 |
{ |
| 3707 |
CODECHAL_ENCODE_SET_PERFTAG_INFO(perfTag, CODECHAL_ENCODE_PERFTAG_CALL_BRC_INIT_RESET); |
| 3708 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(HuCBrcInitReset()); |
| 3709 |
m_brcInit = m_brcReset = false; |
| 3710 |
} |
| 3711 |
// For multipass and singlepass+RePAK we call BRC update for all passes except last pass (RePAK) |
| 3712 |
// For single pass w/o RePAK (1 total pass) we call BRC update on one and only pass |
| 3713 |
if (!IsLastPass() || (m_currPass == 0 && m_numPasses == 0)) |
| 3714 |
{ |
| 3715 |
bool origFrameTrackingHeader = false; |
| 3716 |
bool origSingleTaskPhase = m_singleTaskPhaseSupported; |
| 3717 |
// If this is the case of Dynamic Scaling + BRC Pass 0' VDENC + Pak pass |
| 3718 |
// Disable SingleTaskPhase before running 1st BRC update |
| 3719 |
// To run HPU0 on the next pass i.e Pak only pass, we make Pass 1 as Pass 0 in which case the |
| 3720 |
// BRC dmem buffer( resVdencBrcUpdateDmemBuffer[0] ) will get overridden if we do not submit BRC command now. |
| 3721 |
if (m_dysBrc && m_dysRefFrameFlags != DYS_REF_NONE) |
| 3722 |
{ |
| 3723 |
//Reset Frame Tracking Header for this submission |
| 3724 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 3725 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 3726 |
origFrameTrackingHeader = cmdBuffer.Attributes.bEnableMediaFrameTracking; |
| 3727 |
cmdBuffer.Attributes.bEnableMediaFrameTracking = false; |
| 3728 |
ReturnCommandBuffer(&cmdBuffer); |
| 3729 |
m_singleTaskPhaseSupported = false; |
| 3730 |
} |
| 3731 |
|
| 3732 |
CODECHAL_ENCODE_SET_PERFTAG_INFO(perfTag, CODECHAL_ENCODE_PERFTAG_CALL_BRC_UPDATE); |
| 3733 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(HuCBrcUpdate()); |
| 3734 |
//Restore Original Frame Tracking Header |
| 3735 |
if (m_dysBrc && m_dysRefFrameFlags != DYS_REF_NONE) |
| 3736 |
{ |
| 3737 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 3738 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 3739 |
cmdBuffer.Attributes.bEnableMediaFrameTracking = origFrameTrackingHeader; |
| 3740 |
ReturnCommandBuffer(&cmdBuffer); |
| 3741 |
} |
| 3742 |
//Restore the original state of SingleTaskPhaseSupported flag |
| 3743 |
m_singleTaskPhaseSupported = origSingleTaskPhase; |
| 3744 |
} |
| 3745 |
} |
| 3746 |
|
| 3747 |
// run HuC_VP9Prob first pass (it runs in parallel with ENC) |
| 3748 |
if (m_hucEnabled) |
| 3749 |
{ |
| 3750 |
if (IsFirstPipe() && (IsFirstPass() || IsLastPass() || m_vdencBrcEnabled)) // Before the first PAK pass and for RePak pass |
| 3751 |
{ |
| 3752 |
CODECHAL_ENCODE_SET_PERFTAG_INFO(perfTag, CODECHAL_ENCODE_PERFTAG_CALL_8X8_PU); |
| 3753 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(HuCVp9Prob()); |
| 3754 |
// restore perf tag to PAK |
| 3755 |
CODECHAL_ENCODE_SET_PERFTAG_INFO(perfTag, CODECHAL_ENCODE_PERFTAG_CALL_PAK_ENGINE); |
| 3756 |
} |
| 3757 |
} |
| 3758 |
else |
| 3759 |
{ |
| 3760 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(RefreshFrameInternalBuffers()); |
| 3761 |
} |
| 3762 |
|
| 3763 |
// set HCP_SURFACE_STATE values |
| 3764 |
MHW_VDBOX_SURFACE_PARAMS surfaceParams[CODECHAL_HCP_ALTREF_SURFACE_ID + 1]; |
| 3765 |
for (uint8_t i = 0; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++) |
| 3766 |
{ |
| 3767 |
MOS_ZeroMemory(&surfaceParams[i], sizeof(surfaceParams[i])); |
| 3768 |
surfaceParams[i].Mode = m_mode; |
| 3769 |
surfaceParams[i].ucSurfaceStateId = i; |
| 3770 |
surfaceParams[i].ChromaType = m_outputChromaFormat; |
| 3771 |
surfaceParams[i].bSrc8Pak10Mode = (m_vp9SeqParams->SeqFlags.fields.EncodedBitDepth) && (!m_vp9SeqParams->SeqFlags.fields.SourceBitDepth); |
| 3772 |
|
| 3773 |
switch (m_vp9SeqParams->SeqFlags.fields.EncodedBitDepth) |
| 3774 |
{ |
| 3775 |
case VP9_ENCODED_BIT_DEPTH_10: //10 bit encoding |
| 3776 |
{ |
| 3777 |
surfaceParams[i].ucBitDepthChromaMinus8 = 2; |
| 3778 |
surfaceParams[i].ucBitDepthLumaMinus8 = 2; |
| 3779 |
break; |
| 3780 |
} |
| 3781 |
default: |
| 3782 |
{ |
| 3783 |
surfaceParams[i].ucBitDepthChromaMinus8 = 0; |
| 3784 |
surfaceParams[i].ucBitDepthLumaMinus8 = 0; |
| 3785 |
break; |
| 3786 |
} |
| 3787 |
} |
| 3788 |
} |
| 3789 |
|
| 3790 |
// For PAK engine, we do NOT use scaled reference images even if dynamic scaling is enabled |
| 3791 |
PMOS_SURFACE refSurface[3], refSurfaceNonScaled[3], dsRefSurface4x[3], dsRefSurface8x[3]; |
| 3792 |
for (auto i = 0; i < 3; i++) |
| 3793 |
{ |
| 3794 |
refSurface[i] = refSurfaceNonScaled[i] = dsRefSurface4x[i] = dsRefSurface8x[i] = nullptr; |
| 3795 |
} |
| 3796 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetHcpSrcSurfaceParams(surfaceParams, refSurface, refSurfaceNonScaled, dsRefSurface4x, dsRefSurface8x)); |
| 3797 |
|
| 3798 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 3799 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 3800 |
|
| 3801 |
// Non scalable mode header |
| 3802 |
if ((!m_singleTaskPhaseSupported || m_firstTaskInPhase) && !m_scalableMode) |
| 3803 |
{ |
| 3804 |
// Send command buffer header at the beginning (OS dependent) |
| 3805 |
// frame tracking tag is only added in the last command buffer header |
| 3806 |
bool requestFrameTracking = m_singleTaskPhaseSupported ? m_firstTaskInPhase : m_lastTaskInPhase; |
| 3807 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking(&cmdBuffer, requestFrameTracking)); |
| 3808 |
} |
| 3809 |
|
| 3810 |
// Place hw semaphore on all other pipe to wait for first pipe HUC to finish. |
| 3811 |
int currPipe = GetCurrentPipe(); |
| 3812 |
if (m_scalableMode && m_hucEnabled && m_isTilingSupported) |
| 3813 |
{ |
| 3814 |
if (!IsFirstPipe()) |
| 3815 |
{ |
| 3816 |
if (!Mos_ResourceIsNull(&m_hucDoneSemaphoreMem[currPipe].sResource)) |
| 3817 |
{ |
| 3818 |
// On second pipe, wait here for huc to finish on first pipe |
| 3819 |
SendHWWaitCommand(&m_hucDoneSemaphoreMem[currPipe].sResource, &cmdBuffer, (currPass + 1)); |
| 3820 |
SetSemaphoreMem(&m_hucDoneSemaphoreMem[currPipe].sResource, &cmdBuffer, 0); |
| 3821 |
} |
| 3822 |
} |
| 3823 |
} |
| 3824 |
|
| 3825 |
// Repak conditional batch buffer end based on repak flag written by Huc to HUC_STATUS regster |
| 3826 |
if (m_hucEnabled && (m_numPasses > 0) && IsLastPass()) |
| 3827 |
{ |
| 3828 |
// Insert conditional batch buffer end |
| 3829 |
// Bit 30 has been added as a success condition, therefore this needs to be masked to only check 31 for RePAK |
| 3830 |
// or else if HuC decides not to do RePAK for conditional RePAK yet terminates successfully RePAK will still happen. |
| 3831 |
// Success = bit 30 set to 1, Do RePAK = bit 31 set to 1, value is always 0; if 0 < memory, continue |
| 3832 |
MHW_MI_CONDITIONAL_BATCH_BUFFER_END_PARAMS miConditionalBatchBufferEndParams; |
| 3833 |
MOS_ZeroMemory( |
| 3834 |
&miConditionalBatchBufferEndParams, |
| 3835 |
sizeof(MHW_MI_CONDITIONAL_BATCH_BUFFER_END_PARAMS)); |
| 3836 |
|
| 3837 |
miConditionalBatchBufferEndParams.presSemaphoreBuffer = |
| 3838 |
&m_resHucPakMmioBuffer; |
| 3839 |
// Make the DisableCompareMask 0, so that the HW will do AND operation on DW0 with Mask DW1, refer to HuCVp9Prob() for the settings |
| 3840 |
// and compare the result against the Semaphore data which in our case dwValue = 0. |
| 3841 |
// If result > dwValue then continue execution otherwise terminate the batch buffer |
| 3842 |
miConditionalBatchBufferEndParams.bDisableCompareMask = false; |
| 3843 |
|
| 3844 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiConditionalBatchBufferEndCmd( |
| 3845 |
&cmdBuffer, |
| 3846 |
&miConditionalBatchBufferEndParams)); |
| 3847 |
} |
| 3848 |
|
| 3849 |
if (IsFirstPipe()) |
| 3850 |
{ |
| 3851 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StartStatusReport(&cmdBuffer, CODECHAL_NUM_MEDIA_STATES)); |
| 3852 |
} |
| 3853 |
|
| 3854 |
// Send VDENC_CONTROL_STATE Pipe Initialization |
| 3855 |
MHW_VDBOX_VDENC_CONTROL_STATE_PARAMS vdencControlStateParams; |
| 3856 |
{ |
| 3857 |
MOS_ZeroMemory(&vdencControlStateParams, sizeof(MHW_VDBOX_VDENC_CONTROL_STATE_PARAMS)); |
| 3858 |
vdencControlStateParams.bVdencInitialization = true; |
| 3859 |
CODECHAL_ENCODE_CHK_STATUS_RETURN( |
| 3860 |
static_cast<MhwVdboxVdencInterfaceG12X *>(m_vdencInterface)->AddVdencControlStateCmd(&cmdBuffer, &vdencControlStateParams)); |
| 3861 |
} |
| 3862 |
|
| 3863 |
//Send VD_CONTROL_STATE Pipe Initialization |
| 3864 |
MHW_MI_VD_CONTROL_STATE_PARAMS vdCtrlParam; |
| 3865 |
MOS_ZeroMemory(&vdCtrlParam, sizeof(MHW_MI_VD_CONTROL_STATE_PARAMS)); |
| 3866 |
vdCtrlParam.initialization = true; |
| 3867 |
MhwMiInterfaceG12 *miInterfaceG12 = static_cast <MhwMiInterfaceG12 *>(m_miInterface); |
| 3868 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((miInterfaceG12)->AddMiVdControlStateCmd(&cmdBuffer, &vdCtrlParam)); |
| 3869 |
|
| 3870 |
// set HCP_PIPE_MODE_SELECT values |
| 3871 |
PMHW_VDBOX_PIPE_MODE_SELECT_PARAMS pipeModeSelectParams = nullptr; |
| 3872 |
pipeModeSelectParams = m_vdencInterface->CreateMhwVdboxPipeModeSelectParams(); |
| 3873 |
CODECHAL_ENCODE_CHK_NULL_RETURN(pipeModeSelectParams); |
| 3874 |
|
| 3875 |
auto release_func = [&]() |
| 3876 |
{ |
| 3877 |
m_vdencInterface->ReleaseMhwVdboxPipeModeSelectParams(pipeModeSelectParams); |
| 3878 |
pipeModeSelectParams = nullptr; |
| 3879 |
}; |
| 3880 |
|
| 3881 |
SetHcpPipeModeSelectParams(*pipeModeSelectParams); |
| 3882 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpPipeModeSelectCmd(&cmdBuffer, pipeModeSelectParams), release_func); |
| 3883 |
|
| 3884 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_miInterface->AddMfxWaitCmd(&cmdBuffer, nullptr, false), release_func); |
| 3885 |
|
| 3886 |
// Decoded picture |
| 3887 |
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, release_func); |
| 3888 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID]), release_func); |
| 3889 |
|
| 3890 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID]), release_func); |
| 3891 |
|
| 3892 |
// Source input |
| 3893 |
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, release_func); |
| 3894 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID]), release_func); |
| 3895 |
|
| 3896 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID]), release_func); |
| 3897 |
|
| 3898 |
if (MEDIA_IS_WA(m_waTable, Wa_Vp9UnalignedHeight)) |
| 3899 |
{ |
| 3900 |
uint32_t real_height = m_oriFrameHeight; |
| 3901 |
uint32_t aligned_height = MOS_ALIGN_CEIL(real_height, CODEC_VP9_MIN_BLOCK_HEIGHT); |
| 3902 |
|
| 3903 |
fill_pad_with_value(m_rawSurfaceToPak, real_height, aligned_height); |
| 3904 |
} |
| 3905 |
|
| 3906 |
if (m_pictureCodingType != I_TYPE) |
| 3907 |
{ |
| 3908 |
//Get each reference surface state and be recorded by skipMask if current surface state is mmc disabled |
| 3909 |
//In VP9 mode, Bit 8is (here is bit0 in skipMask ) for Previous Reference; |
| 3910 |
//Bit 9is (here is bit1 in skipMask ) for Golden Reference and Bit 10is (here is bit2 in skipMask ) for Alterante Reference; |
| 3911 |
//Bits11-15are unused and should be programmed to 0 (skipped) |
| 3912 |
uint8_t skipMask = 0xf8; |
| 3913 |
for (uint8_t i = CODECHAL_HCP_LAST_SURFACE_ID; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++) |
| 3914 |
{ |
| 3915 |
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, release_func); |
| 3916 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[i]), release_func); |
| 3917 |
if (surfaceParams[i].mmcState == MOS_MEMCOMP_DISABLED) |
| 3918 |
{ |
| 3919 |
skipMask |= (1 << (i - 2)); |
| 3920 |
} |
| 3921 |
} |
| 3922 |
CODECHAL_ENCODE_NORMALMESSAGE("MMC skip mask is %d\n", skipMask); |
| 3923 |
for (uint8_t i = CODECHAL_HCP_LAST_SURFACE_ID; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++) |
| 3924 |
{ |
| 3925 |
//Set each ref surface state as MOS_MEMCOMP_MC to satisfy MmcEnable in AddHcpSurfaceCmd |
| 3926 |
//Because each ref surface state should be programmed as the same |
| 3927 |
//The actual mmc state is recorded by skipMask and set each ref surface too |
| 3928 |
surfaceParams[i].mmcState = MOS_MEMCOMP_MC; |
| 3929 |
surfaceParams[i].mmcSkipMask = skipMask; |
| 3930 |
} |
| 3931 |
|
| 3932 |
for (uint8_t i = CODECHAL_HCP_LAST_SURFACE_ID; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++) |
| 3933 |
{ |
| 3934 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[i]), release_func); |
| 3935 |
} |
| 3936 |
} |
| 3937 |
|
| 3938 |
// set HCP_PIPE_BUF_ADDR_STATE values |
| 3939 |
PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams = nullptr; |
| 3940 |
pipeBufAddrParams = CreateHcpPipeBufAddrParams(pipeBufAddrParams); |
| 3941 |
|
| 3942 |
auto delete_func = [&]() |
| 3943 |
{ |
| 3944 |
if (pipeModeSelectParams) |
| 3945 |
{ |
| 3946 |
m_vdencInterface->ReleaseMhwVdboxPipeModeSelectParams(pipeModeSelectParams); |
| 3947 |
pipeModeSelectParams = nullptr; |
| 3948 |
} |
| 3949 |
if (pipeBufAddrParams) |
| 3950 |
{ |
| 3951 |
MOS_Delete(pipeBufAddrParams); |
| 3952 |
pipeBufAddrParams = nullptr; |
| 3953 |
} |
| 3954 |
}; |
| 3955 |
|
| 3956 |
if (pipeBufAddrParams) |
| 3957 |
{ |
| 3958 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(SetHcpPipeBufAddrParams(*pipeBufAddrParams, refSurface, refSurfaceNonScaled, dsRefSurface4x, dsRefSurface8x), delete_func); |
| 3959 |
|
| 3960 |
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, delete_func); |
| 3961 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetPipeBufAddr(pipeBufAddrParams), delete_func); |
| 3962 |
|
| 3963 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpPipeBufAddrCmd(&cmdBuffer, pipeBufAddrParams), delete_func); |
| 3964 |
} |
| 3965 |
|
| 3966 |
// set HCP_IND_OBJ_BASE_ADDR_STATE values |
| 3967 |
MHW_VDBOX_IND_OBJ_BASE_ADDR_PARAMS indObjBaseAddrParams; |
| 3968 |
SetHcpIndObjBaseAddrParams(indObjBaseAddrParams); |
| 3969 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpIndObjBaseAddrCmd(&cmdBuffer, &indObjBaseAddrParams), delete_func); |
| 3970 |
|
| 3971 |
// Send VD_CONTROL_STATE Pipe Initialization |
| 3972 |
MOS_ZeroMemory(&vdCtrlParam, sizeof(MHW_MI_VD_CONTROL_STATE_PARAMS)); |
| 3973 |
vdCtrlParam.vdencEnabled = true; |
| 3974 |
vdCtrlParam.vdencInitialization = true; |
| 3975 |
miInterfaceG12 = static_cast <MhwMiInterfaceG12 *>(m_miInterface); |
| 3976 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN((miInterfaceG12)->AddMiVdControlStateCmd(&cmdBuffer, &vdCtrlParam), delete_func); |
| 3977 |
|
| 3978 |
// Change ref surfaces to scaled for VDENC for DYS |
| 3979 |
if ((m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled) |
| 3980 |
{ |
| 3981 |
surfaceParams[CODECHAL_HCP_LAST_SURFACE_ID].psSurface = refSurface[0]; |
| 3982 |
surfaceParams[CODECHAL_HCP_GOLDEN_SURFACE_ID].psSurface = refSurface[1]; |
| 3983 |
surfaceParams[CODECHAL_HCP_ALTREF_SURFACE_ID].psSurface = refSurface[2]; |
| 3984 |
} |
| 3985 |
|
| 3986 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_vdencInterface->AddVdencPipeModeSelectCmd(&cmdBuffer, pipeModeSelectParams), delete_func); |
| 3987 |
if (pipeModeSelectParams) |
| 3988 |
{ |
| 3989 |
MOS_Delete(pipeModeSelectParams); |
| 3990 |
pipeModeSelectParams = nullptr; |
| 3991 |
} |
| 3992 |
|
| 3993 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_vdencInterface->AddVdencSrcSurfaceStateCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID]), delete_func); |
| 3994 |
if (m_pictureCodingType == I_TYPE) |
| 3995 |
{ |
| 3996 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_vdencInterface->AddVdencRefSurfaceStateCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID]), delete_func); |
| 3997 |
} |
| 3998 |
else |
| 3999 |
{ |
| 4000 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_vdencInterface->AddVdencRefSurfaceStateCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_LAST_SURFACE_ID]), delete_func); |
| 4001 |
if ((m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled) |
| 4002 |
{ |
| 4003 |
if (m_refFrameFlags & 0x02) |
| 4004 |
{ |
| 4005 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_vdencInterface->AddVdencRefSurfaceStateCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_GOLDEN_SURFACE_ID]), delete_func); |
| 4006 |
} |
| 4007 |
if (m_refFrameFlags & 0x04) |
| 4008 |
{ |
| 4009 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_vdencInterface->AddVdencRefSurfaceStateCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_ALTREF_SURFACE_ID]), delete_func); |
| 4010 |
} |
| 4011 |
} |
| 4012 |
} |
| 4013 |
|
| 4014 |
MHW_VDBOX_SURFACE_PARAMS dsSurfaceParams[2]; // 8x and 4x DS surfaces |
| 4015 |
SetHcpDsSurfaceParams(&dsSurfaceParams[0]); |
| 4016 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_vdencInterface->AddVdencDsRefSurfaceStateCmd(&cmdBuffer, &dsSurfaceParams[0], 2), delete_func); |
| 4017 |
|
| 4018 |
if (pipeBufAddrParams) |
| 4019 |
{ |
| 4020 |
pipeBufAddrParams->presVdencTileRowStoreBuffer = &m_vdencTileRowStoreBuffer; |
| 4021 |
pipeBufAddrParams->presVdencCumulativeCuCountStreamoutSurface = &m_vdencCumulativeCuCountStreamoutSurface; |
| 4022 |
pipeBufAddrParams->bDynamicScalingEnable = (m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled; |
| 4023 |
pipeBufAddrParams->pRawSurfParam = &surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID]; |
| 4024 |
pipeBufAddrParams->pDecodedReconParam = &surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID]; |
| 4025 |
pipeBufAddrParams->isIFrame = (m_vp9PicParams->PicFlags.fields.frame_type == 0); |
| 4026 |
|
| 4027 |
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, delete_func); |
| 4028 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetPipeBufAddr(pipeBufAddrParams), delete_func); |
| 4029 |
|
| 4030 |
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_vdencInterface->AddVdencPipeBufAddrCmd(&cmdBuffer, pipeBufAddrParams), delete_func); |
| 4031 |
MOS_Delete(pipeBufAddrParams); |
| 4032 |
pipeBufAddrParams = nullptr; |
| 4033 |
} |
| 4034 |
|
| 4035 |
MHW_BATCH_BUFFER secondLevelBatchBuffer; |
| 4036 |
MOS_ZeroMemory(&secondLevelBatchBuffer, sizeof(secondLevelBatchBuffer)); |
| 4037 |
secondLevelBatchBuffer.dwOffset = 0; |
| 4038 |
secondLevelBatchBuffer.bSecondLevel = true; |
| 4039 |
if (m_hucEnabled) |
| 4040 |
{ |
| 4041 |
secondLevelBatchBuffer.OsResource = m_resVdencPictureState2NdLevelBatchBufferWrite[0]; |
| 4042 |
} |
| 4043 |
else |
| 4044 |
{ |
| 4045 |
if (m_dysRefFrameFlags != DYS_REF_NONE && m_dysVdencMultiPassEnabled) |
| 4046 |
{ |
| 4047 |
secondLevelBatchBuffer.OsResource = m_resVdencDysPictureState2NdLevelBatchBuffer; |
| 4048 |
} |
| 4049 |
else |
| 4050 |
{ |
| 4051 |
secondLevelBatchBuffer.OsResource = m_resVdencPictureState2NdLevelBatchBufferRead[currPass][m_vdencPictureState2ndLevelBBIndex]; |
| 4052 |
} |
| 4053 |
} |
| 4054 |
|
| 4055 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd( |
| 4056 |
&cmdBuffer, |
| 4057 |
&secondLevelBatchBuffer)); |
| 4058 |
|
| 4059 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReturnCommandBuffer(&cmdBuffer)); |
| 4060 |
|
| 4061 |
return eStatus; |
| 4062 |
} |
| 4063 |
|
| 4064 |
MOS_STATUS CodechalVdencVp9StateG12::SetHcpPipeBufAddrParams(MHW_VDBOX_PIPE_BUF_ADDR_PARAMS& pipeBufAddrParams, |
| 4065 |
PMOS_SURFACE* refSurface, |
| 4066 |
PMOS_SURFACE* refSurfaceNonScaled, |
| 4067 |
PMOS_SURFACE* dsRefSurface4x, |
| 4068 |
PMOS_SURFACE* dsRefSurface8x) |
| 4069 |
{ |
| 4070 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 4071 |
|
| 4072 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 4073 |
|
| 4074 |
pipeBufAddrParams = {}; |
| 4075 |
pipeBufAddrParams.Mode = m_mode; |
| 4076 |
pipeBufAddrParams.psPreDeblockSurface = &m_reconSurface; |
| 4077 |
pipeBufAddrParams.psPostDeblockSurface = &m_reconSurface; |
| 4078 |
pipeBufAddrParams.psRawSurface = m_rawSurfaceToPak; |
| 4079 |
|
| 4080 |
pipeBufAddrParams.presMfdDeblockingFilterRowStoreScratchBuffer = |
| 4081 |
&m_resDeblockingFilterLineBuffer; |
| 4082 |
|
| 4083 |
pipeBufAddrParams.presDeblockingFilterTileRowStoreScratchBuffer = |
| 4084 |
&m_resDeblockingFilterTileLineBuffer; |
| 4085 |
|
| 4086 |
pipeBufAddrParams.presDeblockingFilterColumnRowStoreScratchBuffer = |
| 4087 |
&m_resDeblockingFilterTileColumnBuffer; |
| 4088 |
|
| 4089 |
pipeBufAddrParams.presMetadataLineBuffer = &m_resMetadataLineBuffer; |
| 4090 |
pipeBufAddrParams.presMetadataTileLineBuffer = &m_resMetadataTileLineBuffer; |
| 4091 |
pipeBufAddrParams.presMetadataTileColumnBuffer = &m_resMetadataTileColumnBuffer; |
| 4092 |
pipeBufAddrParams.presCurMvTempBuffer = m_trackedBuf->GetMvTemporalBuffer(m_currMvTemporalBufferIndex); |
| 4093 |
pipeBufAddrParams.bDynamicScalingEnable = (m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled; |
| 4094 |
|
| 4095 |
if (m_mmcState && m_mmcState->IsMmcEnabled() && m_reconSurface.bCompressible) |
| 4096 |
{ |
| 4097 |
pipeBufAddrParams.PreDeblockSurfMmcState = MOS_MEMCOMP_HORIZONTAL; |
| 4098 |
pipeBufAddrParams.PostDeblockSurfMmcState = pipeBufAddrParams.PreDeblockSurfMmcState; |
| 4099 |
} |
| 4100 |
else |
| 4101 |
{ |
| 4102 |
pipeBufAddrParams.PreDeblockSurfMmcState = MOS_MEMCOMP_DISABLED; |
| 4103 |
} |
| 4104 |
|
| 4105 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState); |
| 4106 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mmcState->SetPipeBufAddr(&pipeBufAddrParams)); |
| 4107 |
|
| 4108 |
// Huc first pass doesn't write probabilities to output prob region but only updates to the input region. HuC run before repak writes to the ouput region. |
| 4109 |
uint8_t frameCtxIdx = 0; |
| 4110 |
if (m_hucEnabled && IsLastPass()) |
| 4111 |
{ |
| 4112 |
pipeBufAddrParams.presVp9ProbBuffer = &m_resHucProbOutputBuffer; |
| 4113 |
} |
| 4114 |
else |
| 4115 |
{ |
| 4116 |
frameCtxIdx = m_vp9PicParams->PicFlags.fields.frame_context_idx; |
| 4117 |
CODECHAL_ENCODE_ASSERT(frameCtxIdx < CODEC_VP9_NUM_CONTEXTS); |
| 4118 |
pipeBufAddrParams.presVp9ProbBuffer = &m_resProbBuffer[frameCtxIdx]; |
| 4119 |
} |
| 4120 |
|
| 4121 |
pipeBufAddrParams.presVp9SegmentIdBuffer = &m_resSegmentIdBuffer; |
| 4122 |
pipeBufAddrParams.presHvdTileRowStoreBuffer = &m_resHvcTileRowstoreBuffer; |
| 4123 |
pipeBufAddrParams.ps4xDsSurface = m_trackedBuf->Get4xDsReconSurface(CODEC_CURR_TRACKED_BUFFER); |
| 4124 |
pipeBufAddrParams.ps8xDsSurface = m_trackedBuf->Get8xDsReconSurface(CODEC_CURR_TRACKED_BUFFER); |
| 4125 |
pipeBufAddrParams.presVdencIntraRowStoreScratchBuffer = &m_resVdencIntraRowStoreScratchBuffer; |
| 4126 |
pipeBufAddrParams.dwNumRefIdxL0ActiveMinus1 = (m_vp9PicParams->PicFlags.fields.frame_type) ? m_numRefFrames - 1 : 0; |
| 4127 |
|
| 4128 |
if (m_scalableMode && m_hucEnabled && m_isTilingSupported) |
| 4129 |
{ |
| 4130 |
pipeBufAddrParams.presVdencStreamOutBuffer = &m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex].sResource; |
| 4131 |
pipeBufAddrParams.dwVdencStatsStreamOutOffset = m_tileStatsOffset.vdencStats; |
| 4132 |
} |
| 4133 |
else |
| 4134 |
{ |
| 4135 |
pipeBufAddrParams.presVdencStreamOutBuffer = &m_resVdencBrcStatsBuffer; |
| 4136 |
pipeBufAddrParams.dwVdencStatsStreamOutOffset = 0; |
| 4137 |
} |
| 4138 |
|
| 4139 |
pipeBufAddrParams.presStreamOutBuffer = nullptr; |
| 4140 |
|
| 4141 |
if (m_scalableMode && m_hucEnabled && m_isTilingSupported) |
| 4142 |
{ |
| 4143 |
PCODECHAL_ENCODE_BUFFER tileStatisticsBuffer = &m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex]; |
| 4144 |
bool useTileStatisticsBuffer = tileStatisticsBuffer && !Mos_ResourceIsNull(&tileStatisticsBuffer->sResource); |
| 4145 |
// the new framestats streamout will now be the tile level stats buffer because each pak is spewing out tile level stats |
| 4146 |
pipeBufAddrParams.presFrameStatStreamOutBuffer = useTileStatisticsBuffer ? &tileStatisticsBuffer->sResource : nullptr; |
| 4147 |
pipeBufAddrParams.dwFrameStatStreamOutOffset = useTileStatisticsBuffer ? m_tileStatsOffset.pakStats : 0; |
| 4148 |
//Main Frame Stats are integrated by PAK integration kernel |
| 4149 |
} |
| 4150 |
else |
| 4151 |
{ |
| 4152 |
pipeBufAddrParams.presFrameStatStreamOutBuffer = &m_resFrameStatStreamOutBuffer; |
| 4153 |
pipeBufAddrParams.dwFrameStatStreamOutOffset = 0; |
| 4154 |
} |
| 4155 |
|
| 4156 |
pipeBufAddrParams.presSseSrcPixelRowStoreBuffer = &m_resSseSrcPixelRowStoreBuffer; |
| 4157 |
pipeBufAddrParams.presVdencStreamInBuffer = &m_resVdencStreamInBuffer[m_currRecycledBufIdx]; |
| 4158 |
pipeBufAddrParams.presSegmentMapStreamOut = &m_resVdencSegmentMapStreamOut; |
| 4159 |
pipeBufAddrParams.presPakCuLevelStreamoutBuffer = |
| 4160 |
Mos_ResourceIsNull(&m_resPakcuLevelStreamoutData.sResource) ? nullptr : &m_resPakcuLevelStreamoutData.sResource; |
| 4161 |
if (m_dysRefFrameFlags != DYS_REF_NONE) |
| 4162 |
{ |
| 4163 |
pipeBufAddrParams.presVdencPakObjCmdStreamOutBuffer = |
| 4164 |
(m_vdencPakObjCmdStreamOutEnabled) ? m_resVdencPakObjCmdStreamOutBuffer : nullptr; |
| 4165 |
} |
| 4166 |
else |
| 4167 |
{ |
| 4168 |
pipeBufAddrParams.presVdencPakObjCmdStreamOutBuffer = m_resVdencPakObjCmdStreamOutBuffer = &m_resMbCodeSurface; |
| 4169 |
} |
| 4170 |
|
| 4171 |
if (m_pictureCodingType != I_TYPE) |
| 4172 |
{ |
| 4173 |
for (auto i = 0; i < 3; i++) |
| 4174 |
{ |
| 4175 |
CODECHAL_ENCODE_CHK_NULL_RETURN(refSurface[i]); |
| 4176 |
CODECHAL_ENCODE_CHK_NULL_RETURN(dsRefSurface4x[i]); |
| 4177 |
CODECHAL_ENCODE_CHK_NULL_RETURN(dsRefSurface8x[i]); |
| 4178 |
if ((m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled) |
| 4179 |
{ |
| 4180 |
pipeBufAddrParams.presReferences[i] = &refSurfaceNonScaled[i]->OsResource; |
| 4181 |
pipeBufAddrParams.presReferences[i+4] = &refSurfaceNonScaled[i]->OsResource; |
| 4182 |
} |
| 4183 |
else |
| 4184 |
{ |
| 4185 |
pipeBufAddrParams.presReferences[i] = &refSurface[i]->OsResource; |
| 4186 |
} |
| 4187 |
pipeBufAddrParams.presVdencReferences[i] = &refSurface[i]->OsResource; |
| 4188 |
pipeBufAddrParams.presVdenc4xDsSurface[i] = &dsRefSurface4x[i]->OsResource; |
| 4189 |
pipeBufAddrParams.presVdenc8xDsSurface[i] = &dsRefSurface8x[i]->OsResource; |
| 4190 |
} |
| 4191 |
if ((m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled) |
| 4192 |
{ |
| 4193 |
pipeBufAddrParams.psFwdRefSurface0 = refSurface[0]; |
| 4194 |
pipeBufAddrParams.psFwdRefSurface1 = refSurface[1]; |
| 4195 |
pipeBufAddrParams.psFwdRefSurface2 = refSurface[2]; |
| 4196 |
} |
| 4197 |
|
| 4198 |
pipeBufAddrParams.presColMvTempBuffer[0] = m_trackedBuf->GetMvTemporalBuffer(m_currMvTemporalBufferIndex ^ 0x01); |
| 4199 |
} |
| 4200 |
|
| 4201 |
return eStatus; |
| 4202 |
} |
| 4203 |
|
| 4204 |
uint16_t CodechalVdencVp9StateG12::GetNumTilesInFrame() |
| 4205 |
{ |
| 4206 |
return ((1 << m_vp9PicParams->log2_tile_rows) * (1 << m_vp9PicParams->log2_tile_columns)); |
| 4207 |
} |
| 4208 |
|
| 4209 |
MOS_STATUS CodechalVdencVp9StateG12::AllocateResources() |
| 4210 |
{ |
| 4211 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 4212 |
|
| 4213 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 4214 |
|
| 4215 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalVdencVp9State::AllocateResources()); |
| 4216 |
|
| 4217 |
// create the tile coding state parameters |
| 4218 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_tileParams = |
| 4219 |
(PMHW_VDBOX_HCP_TILE_CODING_PARAMS_G12)MOS_AllocAndZeroMemory(sizeof(MHW_VDBOX_HCP_TILE_CODING_PARAMS_G12) * m_maxTileNumber)); |
| 4220 |
|
| 4221 |
if (m_isTilingSupported) |
| 4222 |
{ |
| 4223 |
|
| 4224 |
// VDENC tile row store buffer |
| 4225 |
MOS_ALLOC_GFXRES_PARAMS allocParamsForBufferLinear; |
| 4226 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 4227 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 4228 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 4229 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 4230 |
allocParamsForBufferLinear.dwBytes = MOS_ROUNDUP_DIVIDE(m_frameWidth, 32) * CODECHAL_CACHELINE_SIZE * 2; |
| 4231 |
allocParamsForBufferLinear.pBufName = "VDENC Tile Row Store Buffer"; |
| 4232 |
|
| 4233 |
CODECHAL_ENCODE_CHK_STATUS_MESSAGE_RETURN(m_osInterface->pfnAllocateResource( |
| 4234 |
m_osInterface, |
| 4235 |
&allocParamsForBufferLinear, |
| 4236 |
&m_vdencTileRowStoreBuffer), |
| 4237 |
"Failed to allocate VDENC Tile Row Store Buffer"); |
| 4238 |
|
| 4239 |
uint32_t maxPicWidthInSb = MOS_ROUNDUP_DIVIDE(m_maxPicWidth, CODEC_VP9_SUPER_BLOCK_WIDTH); |
| 4240 |
uint32_t maxPicHeightInSb = MOS_ROUNDUP_DIVIDE(m_maxPicHeight, CODEC_VP9_SUPER_BLOCK_HEIGHT); |
| 4241 |
|
| 4242 |
//PAK CU Level Streamout Data: DW57-59 in HCP pipe buffer address command |
| 4243 |
uint32_t size = maxPicWidthInSb * maxPicHeightInSb * 64 * CODECHAL_CACHELINE_SIZE; // One CU has 16-byte, and there are 64 CU in one SB. But, each tile needs to be aliged to the cache line |
| 4244 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 4245 |
allocParamsForBufferLinear.dwBytes = size; |
| 4246 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 4247 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 4248 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 4249 |
allocParamsForBufferLinear.pBufName = "PAK CU Level Streamout Data"; |
| 4250 |
|
| 4251 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 4252 |
m_osInterface, |
| 4253 |
&allocParamsForBufferLinear, |
| 4254 |
&m_resPakcuLevelStreamoutData.sResource); |
| 4255 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus); |
| 4256 |
|
| 4257 |
//PAK Slice Level Streamut Data. DW60-DW62 in HCP pipe buffer address command |
| 4258 |
// one LCU has one cache line. Use CU as LCU during creation |
| 4259 |
allocParamsForBufferLinear.dwBytes = size; |
| 4260 |
allocParamsForBufferLinear.pBufName = "PAK Slice Level Streamout Data"; |
| 4261 |
|
| 4262 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 4263 |
m_osInterface, |
| 4264 |
&allocParamsForBufferLinear, |
| 4265 |
&m_resPakSliceLevelStreamutData.sResource); |
| 4266 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus); |
| 4267 |
|
| 4268 |
//HCP scalability Sync buffer |
| 4269 |
size = CODECHAL_ENCODE_VP9_MAX_NUM_HCP_PIPE * CODECHAL_CACHELINE_SIZE; |
| 4270 |
allocParamsForBufferLinear.dwBytes = size; |
| 4271 |
allocParamsForBufferLinear.pBufName = "Hcp scalability Sync buffer "; |
| 4272 |
|
| 4273 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 4274 |
m_osInterface, |
| 4275 |
&allocParamsForBufferLinear, |
| 4276 |
&m_hcpScalabilitySyncBuffer.sResource); |
| 4277 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus); |
| 4278 |
m_hcpScalabilitySyncBuffer.dwSize = size; |
| 4279 |
|
| 4280 |
//HCP Tile Size Streamout Buffer. Use in HCP_IND_OBJ_CMD |
| 4281 |
size = m_maxTileNumber * MOS_ALIGN_CEIL(m_hcpInterface->GetPakHWTileSizeRecordSize(), CODECHAL_CACHELINE_SIZE); |
| 4282 |
allocParamsForBufferLinear.dwBytes = size; |
| 4283 |
allocParamsForBufferLinear.pBufName = "HCP Tile Record Buffer"; |
| 4284 |
|
| 4285 |
if (m_scalableMode && m_hucEnabled) |
| 4286 |
{ |
| 4287 |
//Sizes of each buffer to be loaded into the region 0 as input and 1 loaded out as output. |
| 4288 |
|
| 4289 |
MOS_ZeroMemory(&m_statsSize, sizeof(StatsInfo)); |
| 4290 |
m_statsSize.tileSizeRecord = m_hcpInterface->GetPakHWTileSizeRecordSize(); |
| 4291 |
m_statsSize.vdencStats = m_brcStatsBufSize; // VDEnc stats size |
| 4292 |
m_statsSize.pakStats = m_brcPakStatsBufSize; // Frame stats size |
| 4293 |
m_statsSize.counterBuffer = m_probabilityCounterBufferSize; |
| 4294 |
|
| 4295 |
// HUC Pak Int DMEM buffer |
| 4296 |
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(sizeof(HucPakIntDmem), CODECHAL_CACHELINE_SIZE); |
| 4297 |
allocParamsForBufferLinear.pBufName = "Huc Pak Int Dmem Buffer"; |
| 4298 |
for (auto i = 0; i < CODECHAL_ENCODE_RECYCLED_BUFFER_NUM; i++) |
| 4299 |
{ |
| 4300 |
for (auto j = 0; j < m_brcMaxNumPasses; j++) |
| 4301 |
{ |
| 4302 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 4303 |
m_osInterface, |
| 4304 |
&allocParamsForBufferLinear, |
| 4305 |
&m_hucPakIntDmemBuffer[i][j]); |
| 4306 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus); |
| 4307 |
} |
| 4308 |
} |
| 4309 |
|
| 4310 |
// HuC PAK Int Region 1 programming related stats |
| 4311 |
MOS_ZeroMemory(&m_frameStatsOffset, sizeof(StatsInfo)); |
| 4312 |
m_frameStatsOffset.tileSizeRecord = 0; |
| 4313 |
m_frameStatsOffset.vdencStats = MOS_ALIGN_CEIL((m_frameStatsOffset.tileSizeRecord + (m_maxTileNumber * m_statsSize.tileSizeRecord)), CODECHAL_PAGE_SIZE); |
| 4314 |
m_frameStatsOffset.pakStats = MOS_ALIGN_CEIL((m_frameStatsOffset.vdencStats + m_statsSize.vdencStats), CODECHAL_PAGE_SIZE); |
| 4315 |
m_frameStatsOffset.counterBuffer = MOS_ALIGN_CEIL((m_frameStatsOffset.pakStats + m_statsSize.pakStats), CODECHAL_PAGE_SIZE); |
| 4316 |
|
| 4317 |
// HuC PAK Int DMEM region 1 buffer allocation |
| 4318 |
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(m_frameStatsOffset.counterBuffer + m_statsSize.counterBuffer, CODECHAL_PAGE_SIZE); |
| 4319 |
allocParamsForBufferLinear.pBufName = "PAK HUC Integrated Frame Stats Buffer"; |
| 4320 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 4321 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 4322 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 4323 |
|
| 4324 |
m_frameStatsPakIntegrationBufferSize = allocParamsForBufferLinear.dwBytes; |
| 4325 |
|
| 4326 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnAllocateResource( |
| 4327 |
m_osInterface, |
| 4328 |
&allocParamsForBufferLinear, |
| 4329 |
&m_frameStatsPakIntegrationBuffer.sResource)); |
| 4330 |
m_frameStatsPakIntegrationBuffer.dwSize = allocParamsForBufferLinear.dwBytes; |
| 4331 |
|
| 4332 |
MOS_LOCK_PARAMS lockFlags; |
| 4333 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 4334 |
lockFlags.WriteOnly = 1; |
| 4335 |
uint8_t* data = nullptr; |
| 4336 |
|
| 4337 |
data = (uint8_t*)m_osInterface->pfnLockResource(m_osInterface, &m_frameStatsPakIntegrationBuffer.sResource, &lockFlags); |
| 4338 |
MOS_ZeroMemory(data, allocParamsForBufferLinear.dwBytes); |
| 4339 |
m_osInterface->pfnUnlockResource(m_osInterface, &m_frameStatsPakIntegrationBuffer.sResource); |
| 4340 |
|
| 4341 |
// HuC PAK Int region 7, 8 |
| 4342 |
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(64, CODECHAL_PAGE_SIZE); |
| 4343 |
allocParamsForBufferLinear.pBufName = "HUC PAK Int Dummy Buffer"; |
| 4344 |
|
| 4345 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 4346 |
m_osInterface, |
| 4347 |
&allocParamsForBufferLinear, |
| 4348 |
&m_hucPakIntDummyBuffer); |
| 4349 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus); |
| 4350 |
|
| 4351 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 4352 |
lockFlags.WriteOnly = 1; |
| 4353 |
|
| 4354 |
data = (uint8_t*)m_osInterface->pfnLockResource( |
| 4355 |
m_osInterface, |
| 4356 |
&m_hucPakIntDummyBuffer, |
| 4357 |
&lockFlags); |
| 4358 |
|
| 4359 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 4360 |
MOS_ZeroMemory( |
| 4361 |
data, |
| 4362 |
allocParamsForBufferLinear.dwBytes); |
| 4363 |
m_osInterface->pfnUnlockResource(m_osInterface, &m_hucPakIntDummyBuffer); |
| 4364 |
|
| 4365 |
// Allocate region 9 of pak integration to be fed as input to HUC BRC region 7 |
| 4366 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 4367 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 4368 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 4369 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 4370 |
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(CODECHAL_ENCODE_VP9_HUC_BRC_DATA_BUFFER_SIZE, CODECHAL_PAGE_SIZE); |
| 4371 |
allocParamsForBufferLinear.pBufName = "GEN12 PAK Integration FrameByteCount output"; |
| 4372 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnAllocateResource( |
| 4373 |
m_osInterface, |
| 4374 |
&allocParamsForBufferLinear, |
| 4375 |
&m_hucPakIntBrcDataBuffer)); |
| 4376 |
|
| 4377 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 4378 |
lockFlags.WriteOnly = 1; |
| 4379 |
data = (uint8_t*)m_osInterface->pfnLockResource(m_osInterface, &m_hucPakIntBrcDataBuffer, &lockFlags); |
| 4380 |
MOS_ZeroMemory(data, allocParamsForBufferLinear.dwBytes); |
| 4381 |
m_osInterface->pfnUnlockResource(m_osInterface, &m_hucPakIntBrcDataBuffer); |
| 4382 |
|
| 4383 |
// Allocate Semaphore memory for HUC to signal other pipe VDENC/PAK to continue |
| 4384 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 4385 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 4386 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 4387 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 4388 |
allocParamsForBufferLinear.dwBytes = sizeof(uint32_t); |
| 4389 |
allocParamsForBufferLinear.pBufName = "GEN12 HUC done Semaphore Memory"; |
| 4390 |
|
| 4391 |
for (auto i = 0; i < m_numPipe; i++) |
| 4392 |
{ |
| 4393 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 4394 |
m_osInterface, |
| 4395 |
&allocParamsForBufferLinear, |
| 4396 |
&m_hucDoneSemaphoreMem[i].sResource)); |
| 4397 |
m_hucDoneSemaphoreMem[i].dwSize = allocParamsForBufferLinear.dwBytes; |
| 4398 |
} |
| 4399 |
|
| 4400 |
// Allocate Semaphore memory for VDEnc/PAK on all pipes to signal stitch command to stop waiting |
| 4401 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 4402 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 4403 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 4404 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 4405 |
allocParamsForBufferLinear.dwBytes = sizeof(uint32_t); |
| 4406 |
allocParamsForBufferLinear.pBufName = "GEN12 VDEnc PAK done Semaphore Memory"; |
| 4407 |
|
| 4408 |
for (auto i = 0; i < m_numPipe; i++) |
| 4409 |
{ |
| 4410 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 4411 |
m_osInterface, |
| 4412 |
&allocParamsForBufferLinear, |
| 4413 |
&m_stitchWaitSemaphoreMem[i].sResource)); |
| 4414 |
m_stitchWaitSemaphoreMem[i].dwSize = allocParamsForBufferLinear.dwBytes; |
| 4415 |
} |
| 4416 |
|
| 4417 |
// Allocate semaphore memory for HUC HPU or BRC to wait on previous pass' PAK Integration command to finish |
| 4418 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 4419 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 4420 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 4421 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 4422 |
allocParamsForBufferLinear.dwBytes = sizeof(uint32_t); |
| 4423 |
allocParamsForBufferLinear.pBufName = "GEN12 VDEnc PAK Int done Semaphore Memory"; |
| 4424 |
|
| 4425 |
CODECHAL_ENCODE_CHK_STATUS_RETURN((MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 4426 |
m_osInterface, |
| 4427 |
&allocParamsForBufferLinear, |
| 4428 |
&m_pakIntDoneSemaphoreMem.sResource)); |
| 4429 |
m_pakIntDoneSemaphoreMem.dwSize = allocParamsForBufferLinear.dwBytes; |
| 4430 |
} |
| 4431 |
} |
| 4432 |
|
| 4433 |
if (m_enableTileStitchByHW) |
| 4434 |
{ |
| 4435 |
MOS_ALLOC_GFXRES_PARAMS allocParamsForBufferLinear; |
| 4436 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 4437 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 4438 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 4439 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 4440 |
|
| 4441 |
for (auto i = 0; i < CODECHAL_ENCODE_RECYCLED_BUFFER_NUM; i++) |
| 4442 |
{ |
| 4443 |
for (auto j = 0; j < CODECHAL_ENCODE_VP9_BRC_MAX_NUM_OF_PASSES; j++) |
| 4444 |
{ |
| 4445 |
// HuC stitching Data buffer |
| 4446 |
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(sizeof(HucCommandData), CODECHAL_PAGE_SIZE); |
| 4447 |
allocParamsForBufferLinear.pBufName = "VP9 HuC Stitch Data Buffer"; |
| 4448 |
CODECHAL_ENCODE_CHK_STATUS_RETURN( |
| 4449 |
m_osInterface->pfnAllocateResource( |
| 4450 |
m_osInterface, |
| 4451 |
&allocParamsForBufferLinear, |
| 4452 |
&m_resHucStitchDataBuffer[i][j])); |
| 4453 |
MOS_LOCK_PARAMS lockFlagsWriteOnly; |
| 4454 |
MOS_ZeroMemory(&lockFlagsWriteOnly, sizeof(MOS_LOCK_PARAMS)); |
| 4455 |
lockFlagsWriteOnly.WriteOnly = 1; |
| 4456 |
uint8_t *pData = (uint8_t *)m_osInterface->pfnLockResource( |
| 4457 |
m_osInterface, |
| 4458 |
&m_resHucStitchDataBuffer[i][j], |
| 4459 |
&lockFlagsWriteOnly); |
| 4460 |
CODECHAL_ENCODE_CHK_NULL_RETURN(pData); |
| 4461 |
MOS_ZeroMemory(pData, allocParamsForBufferLinear.dwBytes); |
| 4462 |
m_osInterface->pfnUnlockResource(m_osInterface, &m_resHucStitchDataBuffer[i][j]); |
| 4463 |
} |
| 4464 |
} |
| 4465 |
//Second level BB for huc stitching cmd |
| 4466 |
MOS_ZeroMemory(&m_HucStitchCmdBatchBuffer, sizeof(m_HucStitchCmdBatchBuffer)); |
| 4467 |
m_HucStitchCmdBatchBuffer.bSecondLevel = true; |
| 4468 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(Mhw_AllocateBb( |
| 4469 |
m_osInterface, |
| 4470 |
&m_HucStitchCmdBatchBuffer, |
| 4471 |
nullptr, |
| 4472 |
m_hwInterface->m_HucStitchCmdBatchBufferSize)); |
| 4473 |
} |
| 4474 |
|
| 4475 |
uint32_t aligned_width = MOS_ALIGN_CEIL(m_frameWidth, 64); |
| 4476 |
uint32_t aligned_height = MOS_ALIGN_CEIL(m_frameHeight, 64); |
| 4477 |
uint32_t num_lcu = (aligned_width * aligned_height) / (64 * 64); |
| 4478 |
|
| 4479 |
MOS_ALLOC_GFXRES_PARAMS allocParamsForSurface; |
| 4480 |
MOS_ZeroMemory(&allocParamsForSurface, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 4481 |
allocParamsForSurface.Type = MOS_GFXRES_BUFFER; |
| 4482 |
allocParamsForSurface.TileType = MOS_TILE_LINEAR; |
| 4483 |
allocParamsForSurface.Format = Format_Buffer; |
| 4484 |
allocParamsForSurface.dwBytes = num_lcu * 4; |
| 4485 |
allocParamsForSurface.pBufName = "VDEnc Cumulative CU Count Streamout Surface"; |
| 4486 |
|
| 4487 |
CODECHAL_ENCODE_CHK_STATUS_MESSAGE_RETURN(m_osInterface->pfnAllocateResource( |
| 4488 |
m_osInterface, |
| 4489 |
&allocParamsForSurface, |
| 4490 |
&m_vdencCumulativeCuCountStreamoutSurface), |
| 4491 |
"Failed to allocate VDEnc Cumulative CU Count Streamout Surface"); |
| 4492 |
|
| 4493 |
return eStatus; |
| 4494 |
} |
| 4495 |
|
| 4496 |
void CodechalVdencVp9StateG12::FreeResources() |
| 4497 |
{ |
| 4498 |
CodechalVdencVp9State::FreeResources(); |
| 4499 |
|
| 4500 |
MOS_FreeMemory(m_tileParams); |
| 4501 |
if (m_isTilingSupported) |
| 4502 |
{ |
| 4503 |
if (!Mos_ResourceIsNull(&m_vdencTileRowStoreBuffer)) |
| 4504 |
{ |
| 4505 |
m_osInterface->pfnFreeResource( |
| 4506 |
m_osInterface, |
| 4507 |
&m_vdencTileRowStoreBuffer); |
| 4508 |
} |
| 4509 |
|
| 4510 |
if (!Mos_ResourceIsNull(&m_resPakcuLevelStreamoutData.sResource)) |
| 4511 |
{ |
| 4512 |
m_osInterface->pfnFreeResource( |
| 4513 |
m_osInterface, |
| 4514 |
&m_resPakcuLevelStreamoutData.sResource); |
| 4515 |
} |
| 4516 |
|
| 4517 |
if (!Mos_ResourceIsNull(&m_resPakSliceLevelStreamutData.sResource)) |
| 4518 |
{ |
| 4519 |
m_osInterface->pfnFreeResource( |
| 4520 |
m_osInterface, |
| 4521 |
&m_resPakSliceLevelStreamutData.sResource); |
| 4522 |
} |
| 4523 |
|
| 4524 |
// Release Hcp scalability Sync buffer |
| 4525 |
if (!Mos_ResourceIsNull(&m_hcpScalabilitySyncBuffer.sResource)) |
| 4526 |
{ |
| 4527 |
m_osInterface->pfnFreeResource( |
| 4528 |
m_osInterface, |
| 4529 |
&m_hcpScalabilitySyncBuffer.sResource); |
| 4530 |
} |
| 4531 |
|
| 4532 |
for (auto i = 0; i < CODECHAL_GET_ARRAY_LENGTH(m_tileRecordBuffer); i++) |
| 4533 |
{ |
| 4534 |
if (!Mos_ResourceIsNull(&m_tileRecordBuffer[i].sResource)) |
| 4535 |
{ |
| 4536 |
m_osInterface->pfnFreeResource( |
| 4537 |
m_osInterface, |
| 4538 |
&m_tileRecordBuffer[i].sResource); |
| 4539 |
} |
| 4540 |
} |
| 4541 |
|
| 4542 |
for (auto i = 0; i < CODECHAL_GET_ARRAY_LENGTH(m_tileStatsPakIntegrationBuffer); i++) |
| 4543 |
{ |
| 4544 |
if (!Mos_ResourceIsNull(&m_tileStatsPakIntegrationBuffer[i].sResource)) |
| 4545 |
{ |
| 4546 |
m_osInterface->pfnFreeResource( |
| 4547 |
m_osInterface, |
| 4548 |
&m_tileStatsPakIntegrationBuffer[i].sResource); |
| 4549 |
} |
| 4550 |
} |
| 4551 |
|
| 4552 |
if (!Mos_ResourceIsNull(&m_frameStatsPakIntegrationBuffer.sResource)) |
| 4553 |
{ |
| 4554 |
m_osInterface->pfnFreeResource( |
| 4555 |
m_osInterface, |
| 4556 |
&m_frameStatsPakIntegrationBuffer.sResource); |
| 4557 |
} |
| 4558 |
|
| 4559 |
if (!Mos_ResourceIsNull(&m_hucPakIntBrcDataBuffer)) |
| 4560 |
{ |
| 4561 |
m_osInterface->pfnFreeResource( |
| 4562 |
m_osInterface, |
| 4563 |
&m_hucPakIntBrcDataBuffer); |
| 4564 |
} |
| 4565 |
|
| 4566 |
for (auto i = 0; i < CODECHAL_ENCODE_RECYCLED_BUFFER_NUM; i++) |
| 4567 |
{ |
| 4568 |
for (auto j = 0; j < m_brcMaxNumPasses; j++) |
| 4569 |
{ |
| 4570 |
if (!Mos_ResourceIsNull(&m_hucPakIntDmemBuffer[i][j])) |
| 4571 |
{ |
| 4572 |
m_osInterface->pfnFreeResource( |
| 4573 |
m_osInterface, |
| 4574 |
&m_hucPakIntDmemBuffer[i][j]); |
| 4575 |
} |
| 4576 |
} |
| 4577 |
} |
| 4578 |
|
| 4579 |
if (!Mos_ResourceIsNull(&m_hucPakIntDummyBuffer)) |
| 4580 |
{ |
| 4581 |
m_osInterface->pfnFreeResource( |
| 4582 |
m_osInterface, |
| 4583 |
&m_hucPakIntDummyBuffer); |
| 4584 |
} |
| 4585 |
|
| 4586 |
for (auto i = 0; i < CODECHAL_GET_ARRAY_LENGTH(m_stitchWaitSemaphoreMem); i++) |
| 4587 |
{ |
| 4588 |
if (!Mos_ResourceIsNull(&m_stitchWaitSemaphoreMem[i].sResource)) |
| 4589 |
{ |
| 4590 |
m_osInterface->pfnFreeResource( |
| 4591 |
m_osInterface, |
| 4592 |
&m_stitchWaitSemaphoreMem[i].sResource); |
| 4593 |
} |
| 4594 |
} |
| 4595 |
|
| 4596 |
if (!Mos_ResourceIsNull(&m_pakIntDoneSemaphoreMem.sResource)) |
| 4597 |
{ |
| 4598 |
m_osInterface->pfnFreeResource( |
| 4599 |
m_osInterface, |
| 4600 |
&m_pakIntDoneSemaphoreMem.sResource); |
| 4601 |
} |
| 4602 |
|
| 4603 |
for (auto i = 0; i < CODECHAL_GET_ARRAY_LENGTH(m_hucDoneSemaphoreMem); i++) |
| 4604 |
{ |
| 4605 |
if (!Mos_ResourceIsNull(&m_hucDoneSemaphoreMem[i].sResource)) |
| 4606 |
{ |
| 4607 |
m_osInterface->pfnFreeResource( |
| 4608 |
m_osInterface, |
| 4609 |
&m_hucDoneSemaphoreMem[i].sResource); |
| 4610 |
} |
| 4611 |
} |
| 4612 |
|
| 4613 |
for (auto i = 0; i < m_numUncompressedSurface; i++) |
| 4614 |
{ |
| 4615 |
for (auto j = 0; j < CODECHAL_ENCODE_VP9_MAX_NUM_HCP_PIPE; j++) |
| 4616 |
{ |
| 4617 |
for (auto k = 0; k < 3; k++) |
| 4618 |
{ |
| 4619 |
PMOS_COMMAND_BUFFER cmdBuffer = &m_veBatchBuffer[i][j][k]; |
| 4620 |
|
| 4621 |
if (!Mos_ResourceIsNull(&cmdBuffer->OsResource)) |
| 4622 |
{ |
| 4623 |
if (cmdBuffer->pCmdBase) |
| 4624 |
{ |
| 4625 |
m_osInterface->pfnUnlockResource(m_osInterface, &cmdBuffer->OsResource); |
| 4626 |
} |
| 4627 |
m_osInterface->pfnFreeResource(m_osInterface, &cmdBuffer->OsResource); |
| 4628 |
} |
| 4629 |
} |
| 4630 |
} |
| 4631 |
} |
| 4632 |
} |
| 4633 |
|
| 4634 |
if (m_enableTileStitchByHW) |
| 4635 |
{ |
| 4636 |
for (auto i = 0; i < CODECHAL_ENCODE_RECYCLED_BUFFER_NUM; i++) |
| 4637 |
{ |
| 4638 |
for (auto j = 0; j < CODECHAL_ENCODE_VP9_BRC_MAX_NUM_OF_PASSES; j++) |
| 4639 |
{ |
| 4640 |
// HuC stitching Data buffer |
| 4641 |
m_osInterface->pfnFreeResource( |
| 4642 |
m_osInterface, |
| 4643 |
&m_resHucStitchDataBuffer[i][j]); |
| 4644 |
} |
| 4645 |
} |
| 4646 |
//Second level BB for huc stitching cmd |
| 4647 |
Mhw_FreeBb(m_osInterface, &m_HucStitchCmdBatchBuffer, nullptr); |
| 4648 |
} |
| 4649 |
|
| 4650 |
if (!Mos_ResourceIsNull(&m_vdencCumulativeCuCountStreamoutSurface)) |
| 4651 |
{ |
| 4652 |
m_osInterface->pfnFreeResource( |
| 4653 |
m_osInterface, |
| 4654 |
&m_vdencCumulativeCuCountStreamoutSurface); |
| 4655 |
} |
| 4656 |
|
| 4657 |
return; |
| 4658 |
} |
| 4659 |
|
| 4660 |
MOS_STATUS CodechalVdencVp9StateG12::SetRowstoreCachingOffsets() |
| 4661 |
{ |
| 4662 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 4663 |
// Add row store cache support for VDENC Gen12. |
| 4664 |
if (m_hwInterface->GetHcpInterface()->IsRowStoreCachingSupported()) |
| 4665 |
{ |
| 4666 |
//add row store cache support. |
| 4667 |
MHW_VDBOX_ROWSTORE_PARAMS rowstoreParams; |
| 4668 |
rowstoreParams.Mode = m_mode; |
| 4669 |
rowstoreParams.dwPicWidth = m_frameWidth; |
| 4670 |
rowstoreParams.ucChromaFormat = ToHCPChromaFormat(m_chromaFormat); |
| 4671 |
rowstoreParams.ucBitDepthMinus8 = m_bitDepth * 2; // 0(8bit) -> 0, 1(10bit)->2, 2(12bit)->4 |
| 4672 |
m_hwInterface->SetRowstoreCachingOffsets(&rowstoreParams); |
| 4673 |
} |
| 4674 |
return eStatus; |
| 4675 |
} |
| 4676 |
|
| 4677 |
MOS_STATUS CodechalVdencVp9StateG12::Initialize(CodechalSetting * settings) |
| 4678 |
{ |
| 4679 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 4680 |
uint32_t maxRows = 1; |
| 4681 |
|
| 4682 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 4683 |
|
| 4684 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalVdencVp9State::Initialize(settings)); |
| 4685 |
|
| 4686 |
GetSystemPipeNumberCommon(); |
| 4687 |
|
| 4688 |
if (MOS_VE_SUPPORTED(m_osInterface)) |
| 4689 |
{ |
| 4690 |
m_scalabilityState = (PCODECHAL_ENCODE_SCALABILITY_STATE)MOS_AllocAndZeroMemory(sizeof(CODECHAL_ENCODE_SCALABILITY_STATE)); |
| 4691 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_scalabilityState); |
| 4692 |
//scalability initialize |
| 4693 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalEncodeScalability_InitializeState(m_scalabilityState, m_hwInterface)); |
| 4694 |
} |
| 4695 |
|
| 4696 |
m_adaptiveRepakSupported = true; |
| 4697 |
//This flag enables pak-only mode for RePak pass |
| 4698 |
m_pakOnlyModeEnabledForLastPass = true; |
| 4699 |
|
| 4700 |
maxRows = MOS_ALIGN_CEIL(m_frameHeight, CODECHAL_ENCODE_VP9_MIN_TILE_SIZE_HEIGHT) / CODECHAL_ENCODE_VP9_MIN_TILE_SIZE_HEIGHT; |
| 4701 |
//Max num of rows = 4 by VP9 Spec |
| 4702 |
maxRows = MOS_MIN(maxRows, 4); |
| 4703 |
|
| 4704 |
//Max tile numbers = max of number tiles for single pipe or max muber of tiles for scalable pipes |
| 4705 |
m_maxTileNumber = MOS_MAX((MOS_ALIGN_CEIL(m_frameWidth, CODECHAL_ENCODE_VP9_MIN_TILE_SIZE_WIDTH) / CODECHAL_ENCODE_VP9_MIN_TILE_SIZE_WIDTH), m_numVdbox) * maxRows; |
| 4706 |
|
| 4707 |
m_numPipe = m_numVdbox; |
| 4708 |
|
| 4709 |
m_scalableMode = (m_numPipe > 1); |
| 4710 |
|
| 4711 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetRowstoreCachingOffsets()); |
| 4712 |
|
| 4713 |
MOS_USER_FEATURE_VALUE_DATA userFeatureData; |
| 4714 |
|
| 4715 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4716 |
MOS_STATUS eStatusKey = MOS_UserFeature_ReadValue_ID( |
| 4717 |
nullptr, |
| 4718 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_ENABLE_HW_STITCH, |
| 4719 |
&userFeatureData, |
| 4720 |
m_osInterface->pOsContext); |
| 4721 |
m_enableTileStitchByHW = userFeatureData.i32Data ? true : false; |
| 4722 |
|
| 4723 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4724 |
userFeatureData.i32Data = 1; |
| 4725 |
userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE; |
| 4726 |
MOS_UserFeature_ReadValue_ID( |
| 4727 |
nullptr, |
| 4728 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_HUC_ENABLE_ID, |
| 4729 |
&userFeatureData, |
| 4730 |
m_osInterface->pOsContext); |
| 4731 |
m_hucEnabled = (userFeatureData.i32Data) ? true : false; |
| 4732 |
|
| 4733 |
//Enable single pass dynamic scaling by default |
| 4734 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4735 |
userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE; |
| 4736 |
userFeatureData.i32Data = 1; |
| 4737 |
MOS_UserFeature_ReadValue_ID( |
| 4738 |
nullptr, |
| 4739 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_SINGLE_PASS_DYS_ENABLE_ID, |
| 4740 |
&userFeatureData, |
| 4741 |
m_osInterface->pOsContext); |
| 4742 |
m_dysVdencMultiPassEnabled = (userFeatureData.i32Data) ? false : true; |
| 4743 |
m_singlePassDys = !m_dysVdencMultiPassEnabled; |
| 4744 |
|
| 4745 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4746 |
userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE; |
| 4747 |
userFeatureData.i32Data = 1; |
| 4748 |
MOS_UserFeature_ReadValue_ID( |
| 4749 |
nullptr, |
| 4750 |
__MEDIA_USER_FEATURE_VALUE_SINGLE_TASK_PHASE_ENABLE_ID, |
| 4751 |
&userFeatureData, |
| 4752 |
m_osInterface->pOsContext); |
| 4753 |
m_singleTaskPhaseSupported = (userFeatureData.i32Data) ? true : false; |
| 4754 |
m_singleTaskPhaseSupportedInPak = m_singleTaskPhaseSupported; |
| 4755 |
// For dynamic scaling, the SingleTaskPhaseSupported is set to true and it does not get restored |
| 4756 |
// to the original value after encoding of the frame. So need to restore to the original state |
| 4757 |
m_storeSingleTaskPhaseSupported = m_singleTaskPhaseSupported; //Save the SingleTaskPhase state here |
| 4758 |
|
| 4759 |
// Multi-Pass BRC: currently disabled by default |
| 4760 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4761 |
MOS_UserFeature_ReadValue_ID( |
| 4762 |
nullptr, |
| 4763 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_MULTIPASS_BRC_ENABLE_ID, |
| 4764 |
&userFeatureData, |
| 4765 |
m_osInterface->pOsContext); |
| 4766 |
m_multipassBrcSupported = (userFeatureData.i32Data) ? true : false; |
| 4767 |
|
| 4768 |
m_vdencBrcStatsBufferSize = m_brcStatsBufSize; |
| 4769 |
m_vdencBrcPakStatsBufferSize = m_brcPakStatsBufSize; |
| 4770 |
m_brcHistoryBufferSize = m_brcHistoryBufSize; |
| 4771 |
// HME enabled by default for VP9 |
| 4772 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4773 |
MOS_UserFeature_ReadValue_ID( |
| 4774 |
NULL, |
| 4775 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_ME_ENABLE_ID, |
| 4776 |
&userFeatureData, |
| 4777 |
m_osInterface->pOsContext); |
| 4778 |
m_hmeSupported = (userFeatureData.i32Data) ? true : false; |
| 4779 |
|
| 4780 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4781 |
MOS_UserFeature_ReadValue_ID( |
| 4782 |
NULL, |
| 4783 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_16xME_ENABLE_ID, |
| 4784 |
&userFeatureData, |
| 4785 |
m_osInterface->pOsContext); |
| 4786 |
m_16xMeSupported = (userFeatureData.i32Data) ? true : false; |
| 4787 |
|
| 4788 |
// disable superHME when HME is disabled |
| 4789 |
if (m_hmeSupported == false) |
| 4790 |
{ |
| 4791 |
m_16xMeSupported = false; |
| 4792 |
} |
| 4793 |
|
| 4794 |
// UHME disabled |
| 4795 |
m_32xMeSupported = false; |
| 4796 |
|
| 4797 |
// VP9 uses a different streamin kernel |
| 4798 |
m_useNonLegacyStreamin = true; |
| 4799 |
|
| 4800 |
// Initialize kernel State |
| 4801 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitKernelStates()); |
| 4802 |
|
| 4803 |
// Get max binding table count |
| 4804 |
m_maxBtCount = GetMaxBtCount(); // Need to add the correct BTcount when HME is enabled |
| 4805 |
|
| 4806 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 4807 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4808 |
MOS_UserFeature_ReadValue_ID( |
| 4809 |
nullptr, |
| 4810 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_ENABLE_BRC_DLL, |
| 4811 |
&userFeatureData, |
| 4812 |
m_osInterface->pOsContext); |
| 4813 |
|
| 4814 |
if (userFeatureData.i32Data) |
| 4815 |
{ |
| 4816 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4817 |
MOS_UserFeature_ReadValue_ID( |
| 4818 |
nullptr, |
| 4819 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_ENABLE_BRC_DLL_CUSTOMPATH, |
| 4820 |
&userFeatureData, |
| 4821 |
m_osInterface->pOsContext); |
| 4822 |
|
| 4823 |
if (!userFeatureData.i32Data) |
| 4824 |
{ |
| 4825 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MosUtilities::MosLoadLibrary(VP9SWBRCLIB, &m_swBrcMode)); // Load Dependency (use on RS1) |
| 4826 |
} |
| 4827 |
else |
| 4828 |
{ |
| 4829 |
char path_buffer[MAXPATH]; |
| 4830 |
MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData)); |
| 4831 |
MOS_ZeroMemory(path_buffer, MAXPATH); |
| 4832 |
userFeatureData.StringData.pStringData = path_buffer; |
| 4833 |
MOS_UserFeature_ReadValue_ID( |
| 4834 |
nullptr, |
| 4835 |
__MEDIA_USER_FEATURE_VALUE_VP9_ENCODE_BRC_DLL_PATH, |
| 4836 |
&userFeatureData, |
| 4837 |
m_osInterface->pOsContext); |
| 4838 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnLoadLibrary(m_osInterface, path_buffer, &m_swBrcMode)); |
| 4839 |
} |
| 4840 |
} |
| 4841 |
#endif // (_DEBUG || _RELEASE_INTERNAL) |
| 4842 |
|
| 4843 |
return eStatus; |
| 4844 |
} |
| 4845 |
|
| 4846 |
/*---------------------------------------------------------------------------- |
| 4847 |
| Name : GetSegmentBlockIndexInFrame |
| 4848 |
| Purpose : Returns the offset of 32x32 block in the frame based on current x,y 32 block location in current tile |
| 4849 |
| |
| 4850 |
| Returns : MOS_STATUS |
| 4851 |
\---------------------------------------------------------------------------*/ |
| 4852 |
uint32_t CodechalVdencVp9StateG12::GetSegmentBlockIndexInFrame( |
| 4853 |
uint32_t frameWidth, |
| 4854 |
uint32_t curr32XInTile, |
| 4855 |
uint32_t curr32YInTile, |
| 4856 |
uint32_t currTileStartY64aligned, |
| 4857 |
uint32_t currTileStartX64aligned) |
| 4858 |
{ |
| 4859 |
uint32_t frameWidthIn32 = MOS_ALIGN_CEIL(frameWidth, CODEC_VP9_SUPER_BLOCK_WIDTH) / 32; |
| 4860 |
uint32_t curr32XInFrame = currTileStartX64aligned / 32 + curr32XInTile; |
| 4861 |
uint32_t curr32YInFrame = currTileStartY64aligned / 32 + curr32YInTile; |
| 4862 |
uint32_t curr32BlockInFrame = curr32YInFrame * frameWidthIn32 + curr32XInFrame; |
| 4863 |
return curr32BlockInFrame; |
| 4864 |
} |
| 4865 |
|
| 4866 |
/*---------------------------------------------------------------------------- |
| 4867 |
| Name : InitZigZagToRasterLUTPerTile |
| 4868 |
| Purpose : Rasterize a tile's 32 blocks' segmap indices, add to frame mapbuffer created for these indices |
| 4869 |
| |
| 4870 |
| Returns : MOS_STATUS |
| 4871 |
\---------------------------------------------------------------------------*/ |
| 4872 |
MOS_STATUS CodechalVdencVp9StateG12::InitZigZagToRasterLUTPerTile( |
| 4873 |
uint32_t tileHeight, |
| 4874 |
uint32_t tileWidth, |
| 4875 |
uint32_t currTileStartYInFrame, |
| 4876 |
uint32_t currTileStartXInFrame) |
| 4877 |
{ |
| 4878 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 4879 |
|
| 4880 |
// Allocate space for zig-zag to raster LUT used for vdenc streamin (1 int32_t for every 32x32 block (pic 64 aligned)) |
| 4881 |
// We only do this when the 1st tile of new frame is being processed and keep it the same unless tile resolutions changed. |
| 4882 |
// We keep this map around until sequence is finished, it's deleted at device destruction. |
| 4883 |
if (currTileStartXInFrame == 0 && currTileStartYInFrame == 0) |
| 4884 |
{ |
| 4885 |
if (m_mapBuffer) // free previous if it exists - it may exist if this isn't first seg streamin frame, but it's a new tile with different res |
| 4886 |
{ |
| 4887 |
MOS_FreeMemory(m_mapBuffer); |
| 4888 |
} |
| 4889 |
// Allocate one integer space for each 32*32 block in the whole frame to hold the segmentation index. |
| 4890 |
m_mapBuffer = (uint32_t*)MOS_AllocAndZeroMemory( |
| 4891 |
(MOS_ALIGN_CEIL(m_frameWidth, CODEC_VP9_SUPER_BLOCK_WIDTH) / 32) * |
| 4892 |
(MOS_ALIGN_CEIL(m_frameHeight, CODEC_VP9_SUPER_BLOCK_HEIGHT) / 32) * |
| 4893 |
sizeof(int32_t)); //Framewidth and height are 64 aligned already |
| 4894 |
} |
| 4895 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mapBuffer); |
| 4896 |
|
| 4897 |
uint32_t align64Width32 = MOS_ALIGN_CEIL(tileWidth, CODEC_VP9_SUPER_BLOCK_WIDTH) / 32; |
| 4898 |
uint32_t align64Height32 = MOS_ALIGN_CEIL(tileHeight, CODEC_VP9_SUPER_BLOCK_HEIGHT) / 32; |
| 4899 |
uint32_t* mapBufferZigZagPerTile = (uint32_t*)MOS_AllocAndZeroMemory(align64Width32*align64Height32 * sizeof(uint32_t)); |
| 4900 |
CODECHAL_ENCODE_CHK_NULL_RETURN(mapBufferZigZagPerTile); |
| 4901 |
|
| 4902 |
m_segStreamInHeight = m_frameHeight; |
| 4903 |
m_segStreamInWidth = m_frameWidth; |
| 4904 |
|
| 4905 |
uint32_t dwCount32 = 0; //Number of 32 by 32 blocks that will be processed here |
| 4906 |
for (uint32_t curr32YInTile = 0; curr32YInTile< align64Height32; curr32YInTile++) |
| 4907 |
{ |
| 4908 |
for (uint32_t curr32XInTile = 0; curr32XInTile < align64Width32; curr32XInTile++) |
| 4909 |
{ |
| 4910 |
mapBufferZigZagPerTile[dwCount32++] = GetSegmentBlockIndexInFrame( |
| 4911 |
m_frameWidth, |
| 4912 |
curr32XInTile, |
| 4913 |
curr32YInTile, |
| 4914 |
currTileStartYInFrame, |
| 4915 |
currTileStartXInFrame); |
| 4916 |
} |
| 4917 |
} |
| 4918 |
|
| 4919 |
// mapBufferZigZagPerTile ---> m_mapBuffer |
| 4920 |
// | a b c d ... ---> | a b W X c d Y Z .... |
| 4921 |
// | W X Y Z ... |
| 4922 |
uint32_t num32blocks = align64Width32 * align64Height32; |
| 4923 |
uint32_t tileOffsetIndex = m_32BlocksRasterized; |
| 4924 |
for (uint32_t i = 0, dwRasterCount = 0; i < num32blocks; i += (align64Width32 * 2)) |
| 4925 |
{ |
| 4926 |
for (uint32_t j = i; j < i + (align64Width32 * 2); j += 4) |
| 4927 |
{ |
| 4928 |
m_mapBuffer[j + tileOffsetIndex] = mapBufferZigZagPerTile[dwRasterCount++]; |
| 4929 |
m_mapBuffer[j + tileOffsetIndex + 1] = mapBufferZigZagPerTile[dwRasterCount++]; |
| 4930 |
} |
| 4931 |
for (uint32_t j = i + 2; j < i + (align64Width32 * 2); j += 4) |
| 4932 |
{ |
| 4933 |
m_mapBuffer[j + tileOffsetIndex] = mapBufferZigZagPerTile[dwRasterCount++]; |
| 4934 |
m_mapBuffer[j + tileOffsetIndex + 1] = mapBufferZigZagPerTile[dwRasterCount++]; |
| 4935 |
} |
| 4936 |
} |
| 4937 |
if (mapBufferZigZagPerTile) // free per tile map buffer as it has been rasterized and copied into the mapbuffer |
| 4938 |
{ |
| 4939 |
MOS_FreeMemory(mapBufferZigZagPerTile); |
| 4940 |
} |
| 4941 |
|
| 4942 |
// ^ Zig-zag pattern filled to SB aligned (CEIL), if unaligned then we base seg ID address on previous row/column (data replication) |
| 4943 |
uint32_t width32 = CODECHAL_GET_WIDTH_IN_BLOCKS(tileWidth, 32); |
| 4944 |
if (width32 != align64Width32) // replicate last column |
| 4945 |
{ |
| 4946 |
for (auto i = (align64Width32 * 2) - 1 - 2; i < num32blocks; i += (align64Width32 * 2)) |
| 4947 |
{ |
| 4948 |
m_mapBuffer[i + tileOffsetIndex] = m_mapBuffer[i + tileOffsetIndex - 1]; |
| 4949 |
m_mapBuffer[i + tileOffsetIndex + 2] = m_mapBuffer[i + tileOffsetIndex + 1]; |
| 4950 |
} |
| 4951 |
} |
| 4952 |
|
| 4953 |
uint32_t height32 = CODECHAL_GET_HEIGHT_IN_BLOCKS(tileHeight, 32); |
| 4954 |
if (height32 != align64Height32) // replicate last row |
| 4955 |
{ |
| 4956 |
for (auto i = num32blocks - (align64Width32 * 2) + 2; i < num32blocks; i += 4) |
| 4957 |
{ |
| 4958 |
m_mapBuffer[i + tileOffsetIndex] = m_mapBuffer[i + tileOffsetIndex - 2]; |
| 4959 |
m_mapBuffer[i + tileOffsetIndex + 1] = m_mapBuffer[i + tileOffsetIndex + 1 - 2]; |
| 4960 |
} |
| 4961 |
} |
| 4962 |
//Index offset to be added to the buffer for the next tile depending on how many blocks were rasterized already in this tile |
| 4963 |
m_32BlocksRasterized += dwCount32; |
| 4964 |
|
| 4965 |
return eStatus; |
| 4966 |
} |
| 4967 |
|
| 4968 |
MOS_STATUS CodechalVdencVp9StateG12::CalculateVdencPictureStateCommandSize() |
| 4969 |
{ |
| 4970 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 4971 |
|
| 4972 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 4973 |
|
| 4974 |
MHW_VDBOX_STATE_CMDSIZE_PARAMS_G12 stateCmdSizeParams; |
| 4975 |
uint32_t vdencPictureStatesSize = 0, vdencPicturePatchListSize = 0; |
| 4976 |
stateCmdSizeParams.bHucDummyStream = true; |
| 4977 |
m_hwInterface->GetHxxStateCommandSize( |
| 4978 |
CODECHAL_ENCODE_MODE_VP9, |
| 4979 |
&vdencPictureStatesSize, |
| 4980 |
&vdencPicturePatchListSize, |
| 4981 |
&stateCmdSizeParams); |
| 4982 |
|
| 4983 |
m_defaultPictureStatesSize += vdencPictureStatesSize; |
| 4984 |
m_defaultPicturePatchListSize += vdencPicturePatchListSize; |
| 4985 |
|
| 4986 |
m_hwInterface->GetVdencStateCommandsDataSize( |
| 4987 |
CODECHAL_ENCODE_MODE_VP9, |
| 4988 |
&vdencPictureStatesSize, |
| 4989 |
&vdencPicturePatchListSize); |
| 4990 |
|
| 4991 |
m_defaultPictureStatesSize += vdencPictureStatesSize; |
| 4992 |
m_defaultPicturePatchListSize += vdencPicturePatchListSize; |
| 4993 |
|
| 4994 |
return eStatus; |
| 4995 |
} |
| 4996 |
|
| 4997 |
PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS CodechalVdencVp9StateG12::CreateHcpPipeBufAddrParams(PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams) |
| 4998 |
{ |
| 4999 |
pipeBufAddrParams = MOS_New(MHW_VDBOX_PIPE_BUF_ADDR_PARAMS_G12); |
| 5000 |
|
| 5001 |
return pipeBufAddrParams; |
| 5002 |
} |
| 5003 |
|
| 5004 |
MOS_STATUS CodechalVdencVp9StateG12::UpdateCmdBufAttribute( |
| 5005 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 5006 |
bool renderEngineInUse) |
| 5007 |
{ |
| 5008 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 5009 |
|
| 5010 |
// should not be there. Will remove it in the next change |
| 5011 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 5012 |
if (MOS_VE_SUPPORTED(m_osInterface) && cmdBuffer->Attributes.pAttriVe) |
| 5013 |
{ |
| 5014 |
PMOS_CMD_BUF_ATTRI_VE attriExt = |
| 5015 |
(PMOS_CMD_BUF_ATTRI_VE)(cmdBuffer->Attributes.pAttriVe); |
| 5016 |
|
| 5017 |
memset(attriExt, 0, sizeof(MOS_CMD_BUF_ATTRI_VE)); |
| 5018 |
attriExt->bUseVirtualEngineHint = |
| 5019 |
attriExt->VEngineHintParams.NeedSyncWithPrevious = !renderEngineInUse; |
| 5020 |
} |
| 5021 |
|
| 5022 |
return eStatus; |
| 5023 |
} |
| 5024 |
|
| 5025 |
MOS_STATUS CodechalVdencVp9StateG12::AddMediaVfeCmd( |
| 5026 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 5027 |
SendKernelCmdsParams *params) |
| 5028 |
{ |
| 5029 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 5030 |
|
| 5031 |
MHW_VFE_PARAMS_G12 vfeParams = {}; |
| 5032 |
vfeParams.pKernelState = params->pKernelState; |
| 5033 |
vfeParams.eVfeSliceDisable = MHW_VFE_SLICE_ALL; |
| 5034 |
vfeParams.dwMaximumNumberofThreads = m_encodeVfeMaxThreads; |
| 5035 |
vfeParams.bFusedEuDispatch = false; // legacy mode |
| 5036 |
|
| 5037 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_renderEngineInterface->AddMediaVfeCmd(cmdBuffer, &vfeParams)); |
| 5038 |
|
| 5039 |
return MOS_STATUS_SUCCESS; |
| 5040 |
} |
| 5041 |
|
| 5042 |
MOS_STATUS CodechalVdencVp9StateG12::HuCVp9PakInt( |
| 5043 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 5044 |
{ |
| 5045 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 5046 |
|
| 5047 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 5048 |
|
| 5049 |
if (!IsFirstPipe()) |
| 5050 |
{ |
| 5051 |
return eStatus; |
| 5052 |
} |
| 5053 |
|
| 5054 |
CODECHAL_DEBUG_TOOL( |
| 5055 |
uint32_t hucRegionSize[16] = { 0 }; |
| 5056 |
const char* hucRegionName[16] = { "\0" }; |
| 5057 |
|
| 5058 |
hucRegionName[0] = "_MultiPakStreamout_input"; |
| 5059 |
hucRegionSize[0] = m_tileStatsPakIntegrationBufferSize; |
| 5060 |
hucRegionName[1] = "_IntegratedStreamout_output"; |
| 5061 |
hucRegionSize[1] = m_frameStatsPakIntegrationBufferSize; |
| 5062 |
hucRegionName[4] = "_HCPPICSTATEInputDummy"; |
| 5063 |
hucRegionSize[4] = sizeof(m_hucPakIntDummyBuffer); |
| 5064 |
hucRegionName[5] = "_HCPPICSTATEInputDummy"; |
| 5065 |
hucRegionSize[5] = sizeof(m_hucPakIntDummyBuffer); |
| 5066 |
hucRegionName[6] = "_HCPPICSTATEInputDummy"; |
| 5067 |
hucRegionSize[6] = sizeof(m_hucPakIntDummyBuffer); |
| 5068 |
hucRegionName[7] = "_HCPPICSTATEInputDummy"; |
| 5069 |
hucRegionSize[7] = sizeof(m_hucPakIntDummyBuffer); |
| 5070 |
hucRegionName[8] = "_HucStitchDataBuffer"; |
| 5071 |
hucRegionSize[8] = MOS_ALIGN_CEIL(sizeof(HucCommandData), CODECHAL_PAGE_SIZE); |
| 5072 |
hucRegionName[9] = "_BrcDataOutputBuffer"; // This is the pak MMIO region 7 , not 4, of BRC update |
| 5073 |
hucRegionSize[9] = MOS_ALIGN_CEIL(CODECHAL_ENCODE_VP9_HUC_BRC_DATA_BUFFER_SIZE, CODECHAL_PAGE_SIZE); |
| 5074 |
hucRegionName[15] = "_TileRecordBuffer"; |
| 5075 |
hucRegionSize[15] = m_maxTileNumber * MOS_ALIGN_CEIL(m_hcpInterface->GetPakHWTileSizeRecordSize(), CODECHAL_CACHELINE_SIZE); |
| 5076 |
) |
| 5077 |
|
| 5078 |
MHW_VDBOX_HUC_IMEM_STATE_PARAMS imemParams; |
| 5079 |
MOS_ZeroMemory(&imemParams, sizeof(imemParams)); |
| 5080 |
imemParams.dwKernelDescriptor = m_vdboxHucPakIntegrationKernelDescriptor; |
| 5081 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucImemStateCmd(cmdBuffer, &imemParams)); |
| 5082 |
|
| 5083 |
// pipe mode select |
| 5084 |
MHW_VDBOX_PIPE_MODE_SELECT_PARAMS pipeModeSelectParams; |
| 5085 |
pipeModeSelectParams.Mode = m_mode; |
| 5086 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucPipeModeSelectCmd(cmdBuffer, &pipeModeSelectParams)); |
| 5087 |
|
| 5088 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetDmemHuCPakInt()); |
| 5089 |
|
| 5090 |
MHW_VDBOX_HUC_DMEM_STATE_PARAMS dmemParams; |
| 5091 |
MOS_ZeroMemory(&dmemParams, sizeof(dmemParams)); |
| 5092 |
dmemParams.presHucDataSource = &m_hucPakIntDmemBuffer[m_currRecycledBufIdx][GetCurrentPass()]; |
| 5093 |
dmemParams.dwDataLength = MOS_ALIGN_CEIL(sizeof(HucPakIntDmem), CODECHAL_CACHELINE_SIZE); |
| 5094 |
dmemParams.dwDmemOffset = HUC_DMEM_OFFSET_RTOS_GEMS; |
| 5095 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucDmemStateCmd(cmdBuffer, &dmemParams)); |
| 5096 |
|
| 5097 |
if (m_enableTileStitchByHW) |
| 5098 |
{ |
| 5099 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ConfigStitchDataBuffer()); |
| 5100 |
} |
| 5101 |
|
| 5102 |
MHW_VDBOX_HUC_VIRTUAL_ADDR_PARAMS virtualAddrParams; |
| 5103 |
MOS_ZeroMemory(&virtualAddrParams, sizeof(MHW_VDBOX_HUC_VIRTUAL_ADDR_PARAMS)); |
| 5104 |
virtualAddrParams.regionParams[0].presRegion = &m_tileStatsPakIntegrationBuffer[m_virtualEngineBBIndex].sResource; // Region 0 - Tile based input statistics from PAK/ VDEnc |
| 5105 |
virtualAddrParams.regionParams[0].dwOffset = 0; |
| 5106 |
virtualAddrParams.regionParams[1].presRegion = &m_frameStatsPakIntegrationBuffer.sResource; // Region 1 - HuC Frame statistics output |
| 5107 |
virtualAddrParams.regionParams[1].isWritable = true; |
| 5108 |
virtualAddrParams.regionParams[4].presRegion = &m_hucPakIntDummyBuffer; // Region 4 - Not used for VP9 |
| 5109 |
virtualAddrParams.regionParams[5].presRegion = &m_hucPakIntDummyBuffer; // Region 5 - Not used for VP9 |
| 5110 |
virtualAddrParams.regionParams[5].isWritable = true; |
| 5111 |
virtualAddrParams.regionParams[6].presRegion = &m_hucPakIntDummyBuffer; // Region 6 - Not used for VP9 |
| 5112 |
virtualAddrParams.regionParams[6].isWritable = true; |
| 5113 |
virtualAddrParams.regionParams[7].presRegion = &m_hucPakIntDummyBuffer; // Region 7 - Not used for VP9 |
| 5114 |
if (m_enableTileStitchByHW) |
| 5115 |
{ |
| 5116 |
virtualAddrParams.regionParams[8].presRegion = &m_resHucStitchDataBuffer[m_currRecycledBufIdx][GetCurrentPass()]; // Region 8 - data buffer read by HUC for stitching cmd generation |
| 5117 |
virtualAddrParams.regionParams[8].isWritable = true; |
| 5118 |
} |
| 5119 |
virtualAddrParams.regionParams[9].presRegion = &m_hucPakIntBrcDataBuffer; // Region 9 - HuC outputs BRC data |
| 5120 |
virtualAddrParams.regionParams[9].isWritable = true; |
| 5121 |
if (m_enableTileStitchByHW) |
| 5122 |
{ |
| 5123 |
virtualAddrParams.regionParams[10].presRegion = &m_HucStitchCmdBatchBuffer.OsResource; // Region 10 - SLB for stitching cmd output from Huc |
| 5124 |
virtualAddrParams.regionParams[10].isWritable = true; |
| 5125 |
} |
| 5126 |
virtualAddrParams.regionParams[15].presRegion = &m_tileRecordBuffer[m_virtualEngineBBIndex].sResource; // Region 15 [In/Out] - Tile Record Buffer |
| 5127 |
virtualAddrParams.regionParams[15].dwOffset = 0; |
| 5128 |
|
| 5129 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucVirtualAddrStateCmd(cmdBuffer, &virtualAddrParams)); |
| 5130 |
|
| 5131 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHuCStatus2Report(cmdBuffer)); |
| 5132 |
|
| 5133 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucStartCmd(cmdBuffer, true)); |
| 5134 |
|
| 5135 |
// wait Huc completion (use HEVC bit for now) |
| 5136 |
MHW_VDBOX_VD_PIPE_FLUSH_PARAMS vdPipeFlushParams; |
| 5137 |
MOS_ZeroMemory(&vdPipeFlushParams, sizeof(vdPipeFlushParams)); |
| 5138 |
vdPipeFlushParams.Flags.bFlushHEVC = 1; |
| 5139 |
vdPipeFlushParams.Flags.bWaitDoneHEVC = 1; |
| 5140 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdPipelineFlushCmd(cmdBuffer, &vdPipeFlushParams)); |
| 5141 |
|
| 5142 |
// Flush the engine to ensure memory written out |
| 5143 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 5144 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 5145 |
flushDwParams.bVideoPipelineCacheInvalidate = true; |
| 5146 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(cmdBuffer, &flushDwParams)); |
| 5147 |
|
| 5148 |
auto mmioRegisters = m_hucInterface->GetMmioRegisters(MHW_VDBOX_NODE_1); |
| 5149 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHucErrorStatus(mmioRegisters, cmdBuffer, false)); |
| 5150 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InsertConditionalBBEndWithHucErrorStatus(cmdBuffer)); |
| 5151 |
|
| 5152 |
CODECHAL_DEBUG_TOOL( |
| 5153 |
// Dump input Pak Integration buffers before running HuC |
| 5154 |
m_debugInterface->DumpHucRegion( |
| 5155 |
virtualAddrParams.regionParams[0].presRegion, |
| 5156 |
0, |
| 5157 |
hucRegionSize[0], |
| 5158 |
0, |
| 5159 |
"_PakIntStitchBuffer", |
| 5160 |
(virtualAddrParams.regionParams[0].isWritable ? true : false), |
| 5161 |
GetCurrentPass(), |
| 5162 |
CodechalHucRegionDumpType::hucRegionDumpPakIntegrate); |
| 5163 |
|
| 5164 |
m_debugInterface->DumpHucDmem( |
| 5165 |
&m_hucPakIntDmemBuffer[m_currRecycledBufIdx][GetCurrentPass()], |
| 5166 |
sizeof(HucPakIntDmem), |
| 5167 |
GetCurrentPass(), |
| 5168 |
CodechalHucRegionDumpType::hucRegionDumpPakIntegrate); |
| 5169 |
|
| 5170 |
for (auto i = 0; i < 16; i++) |
| 5171 |
{ |
| 5172 |
if (virtualAddrParams.regionParams[i].presRegion) |
| 5173 |
{ |
| 5174 |
if (m_scalableMode && m_isTilingSupported && virtualAddrParams.regionParams[i].isWritable && i != 11) |
| 5175 |
{ |
| 5176 |
continue; |
| 5177 |
} |
| 5178 |
m_debugInterface->DumpHucRegion( |
| 5179 |
virtualAddrParams.regionParams[i].presRegion, |
| 5180 |
virtualAddrParams.regionParams[i].dwOffset, |
| 5181 |
hucRegionSize[i], |
| 5182 |
i, |
| 5183 |
hucRegionName[i], |
| 5184 |
!virtualAddrParams.regionParams[i].isWritable, |
| 5185 |
GetCurrentPass(), |
| 5186 |
CodechalHucRegionDumpType::hucRegionDumpPakIntegrate); |
| 5187 |
} |
| 5188 |
} |
| 5189 |
) |
| 5190 |
|
| 5191 |
return eStatus; |
| 5192 |
} |
| 5193 |
|
| 5194 |
MOS_STATUS CodechalVdencVp9StateG12::ConstructPicStateBatchBuf( |
| 5195 |
PMOS_RESOURCE picStateBuffer) |
| 5196 |
{ |
| 5197 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 5198 |
|
| 5199 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 5200 |
|
| 5201 |
CODECHAL_ENCODE_CHK_NULL_RETURN(picStateBuffer); |
| 5202 |
|
| 5203 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 5204 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 5205 |
|
| 5206 |
if (!m_singleTaskPhaseSupported || m_firstTaskInPhase) |
| 5207 |
{ |
| 5208 |
// Send command buffer header at the beginning (OS dependent) |
| 5209 |
bool requestFrameTracking = false; |
| 5210 |
if (!m_vp9PicParams->PicFlags.fields.super_frame) { |
| 5211 |
requestFrameTracking = m_singleTaskPhaseSupported ? m_firstTaskInPhase : m_lastTaskInPhase; |
| 5212 |
} |
| 5213 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking(&cmdBuffer, requestFrameTracking)); |
| 5214 |
m_firstTaskInPhase = false; |
| 5215 |
} |
| 5216 |
|
| 5217 |
ReturnCommandBuffer(&cmdBuffer); |
| 5218 |
|
| 5219 |
MOS_LOCK_PARAMS lockFlagsWriteOnly; |
| 5220 |
MOS_ZeroMemory(&lockFlagsWriteOnly, sizeof(MOS_LOCK_PARAMS)); |
| 5221 |
lockFlagsWriteOnly.WriteOnly = 1; |
| 5222 |
uint8_t* data = (uint8_t*)m_osInterface->pfnLockResource(m_osInterface, picStateBuffer, &lockFlagsWriteOnly); |
| 5223 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 5224 |
|
| 5225 |
MOS_COMMAND_BUFFER constructedCmdBuf; |
| 5226 |
MOS_ZeroMemory(&constructedCmdBuf, sizeof(constructedCmdBuf)); |
| 5227 |
constructedCmdBuf.pCmdBase = (uint32_t *)data; |
| 5228 |
constructedCmdBuf.pCmdPtr = (uint32_t *)data; |
| 5229 |
constructedCmdBuf.iOffset = 0; |
| 5230 |
constructedCmdBuf.iRemaining = m_vdencPicStateSecondLevelBatchBufferSize; |
| 5231 |
|
| 5232 |
eStatus = AddCommandsVp9(CODECHAL_CMD1, &constructedCmdBuf); |
| 5233 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 5234 |
{ |
| 5235 |
m_osInterface->pfnUnlockResource(m_osInterface, picStateBuffer); |
| 5236 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to add CODECHAL_CMD1 command."); |
| 5237 |
return eStatus; |
| 5238 |
} |
| 5239 |
|
| 5240 |
// HCP_VP9_PIC_STATE |
| 5241 |
MHW_VDBOX_VP9_ENCODE_PIC_STATE picState; |
| 5242 |
MOS_ZeroMemory(&picState, sizeof(picState)); |
| 5243 |
picState.pVp9PicParams = m_vp9PicParams; |
| 5244 |
picState.pVp9SeqParams = m_vp9SeqParams; |
| 5245 |
picState.ppVp9RefList = &(m_refList[0]); |
| 5246 |
picState.PrevFrameParams.fields.KeyFrame = m_prevFrameInfo.KeyFrame; |
| 5247 |
picState.PrevFrameParams.fields.IntraOnly = m_prevFrameInfo.IntraOnly; |
| 5248 |
picState.PrevFrameParams.fields.Display = m_prevFrameInfo.ShowFrame; |
| 5249 |
picState.dwPrevFrmWidth = m_prevFrameInfo.FrameWidth; |
| 5250 |
picState.dwPrevFrmHeight = m_prevFrameInfo.FrameHeight; |
| 5251 |
picState.ucTxMode = m_txMode; |
| 5252 |
picState.bSSEEnable = m_vdencBrcEnabled; |
| 5253 |
picState.bUseDysRefSurface = (m_dysRefFrameFlags != DYS_REF_NONE) && m_dysVdencMultiPassEnabled; |
| 5254 |
picState.bVdencPakOnlyPassFlag = m_vdencPakonlyMultipassEnabled; |
| 5255 |
picState.uiMaxBitRate = m_vp9SeqParams->MaxBitRate * CODECHAL_ENCODE_BRC_KBPS; |
| 5256 |
picState.uiMinBitRate = m_vp9SeqParams->MinBitRate * CODECHAL_ENCODE_BRC_KBPS; |
| 5257 |
m_hucPicStateOffset = (uint16_t)constructedCmdBuf.iOffset; |
| 5258 |
|
| 5259 |
eStatus = m_hcpInterface->AddHcpVp9PicStateEncCmd(&constructedCmdBuf, nullptr, &picState); |
| 5260 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 5261 |
{ |
| 5262 |
m_osInterface->pfnUnlockResource(m_osInterface, picStateBuffer); |
| 5263 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to add HCP_VP9_PIC_STATE command."); |
| 5264 |
return eStatus; |
| 5265 |
} |
| 5266 |
|
| 5267 |
// HCP_VP9_SEGMENT_STATE |
| 5268 |
MHW_VDBOX_VP9_SEGMENT_STATE segmentState; |
| 5269 |
MOS_ZeroMemory(&segmentState, sizeof(segmentState)); |
| 5270 |
segmentState.Mode = m_mode; |
| 5271 |
segmentState.pVp9EncodeSegmentParams = m_vp9SegmentParams; |
| 5272 |
uint8_t segmentCount = (m_vp9PicParams->PicFlags.fields.segmentation_enabled) ? CODEC_VP9_MAX_SEGMENTS : 1; |
| 5273 |
|
| 5274 |
for (uint8_t i = 0; i < segmentCount; i++) |
| 5275 |
{ |
| 5276 |
segmentState.ucCurrentSegmentId = i; |
| 5277 |
eStatus = m_hcpInterface->AddHcpVp9SegmentStateCmd(&constructedCmdBuf, nullptr, &segmentState); |
| 5278 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 5279 |
{ |
| 5280 |
m_osInterface->pfnUnlockResource(m_osInterface, picStateBuffer); |
| 5281 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to add MHW_VDBOX_VP9_SEGMENT_STATE command."); |
| 5282 |
return eStatus; |
| 5283 |
} |
| 5284 |
} |
| 5285 |
|
| 5286 |
// Adjust cmd buffer offset to have 8 segment state blocks |
| 5287 |
if (segmentCount < CODEC_VP9_MAX_SEGMENTS) |
| 5288 |
{ |
| 5289 |
// Max 7 segments, 32 bytes each |
| 5290 |
uint8_t zeroBlock[m_segmentStateBlockSize * (CODEC_VP9_MAX_SEGMENTS - 1)]; |
| 5291 |
MOS_ZeroMemory(zeroBlock, sizeof(zeroBlock)); |
| 5292 |
Mhw_AddCommandCmdOrBB(m_osInterface, &constructedCmdBuf, nullptr, zeroBlock, (CODEC_VP9_MAX_SEGMENTS - segmentCount) * m_segmentStateBlockSize); |
| 5293 |
} |
| 5294 |
|
| 5295 |
m_slbbImgStateOffset = (uint16_t)constructedCmdBuf.iOffset; |
| 5296 |
eStatus = AddCommandsVp9(CODECHAL_CMD2, &constructedCmdBuf); |
| 5297 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 5298 |
{ |
| 5299 |
m_osInterface->pfnUnlockResource(m_osInterface, picStateBuffer); |
| 5300 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to add CODECHAL_CMD2 command."); |
| 5301 |
return eStatus; |
| 5302 |
} |
| 5303 |
|
| 5304 |
// BB_END |
| 5305 |
eStatus = m_miInterface->AddMiBatchBufferEnd(&constructedCmdBuf, nullptr); |
| 5306 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 5307 |
{ |
| 5308 |
m_osInterface->pfnUnlockResource(m_osInterface, picStateBuffer); |
| 5309 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to add MI Batch Buffer End command."); |
| 5310 |
return eStatus; |
| 5311 |
} |
| 5312 |
m_hucSlbbSize = (uint16_t)constructedCmdBuf.iOffset; |
| 5313 |
|
| 5314 |
m_osInterface->pfnUnlockResource(m_osInterface, picStateBuffer); |
| 5315 |
|
| 5316 |
return eStatus; |
| 5317 |
} |
| 5318 |
|
| 5319 |
MOS_STATUS CodechalVdencVp9StateG12::HuCVp9Prob() |
| 5320 |
{ |
| 5321 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 5322 |
|
| 5323 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 5324 |
if (!IsFirstPipe()) |
| 5325 |
{ |
| 5326 |
return eStatus; |
| 5327 |
} |
| 5328 |
|
| 5329 |
CODECHAL_DEBUG_TOOL( |
| 5330 |
uint32_t hucRegionSize[16] = { 0 }; |
| 5331 |
const char* hucRegionName[16] = { "\0" }; |
| 5332 |
|
| 5333 |
hucRegionName[0] = "_UpdatedProbBuffer"; // hucRegionName[0] is used to dump region 0 after HuC is run, which has updated probabilities. Input Region 0 is dumped separetely before HuC. |
| 5334 |
hucRegionSize[0] = 32 * CODECHAL_CACHELINE_SIZE; |
| 5335 |
hucRegionName[1] = "_CountersBuffer"; |
| 5336 |
hucRegionSize[1] = 193 * CODECHAL_CACHELINE_SIZE; |
| 5337 |
hucRegionName[2] = "_ProbBuffer"; |
| 5338 |
hucRegionSize[2] = 32 * CODECHAL_CACHELINE_SIZE; |
| 5339 |
hucRegionName[3] = "_ProbDeltaBuffer"; |
| 5340 |
hucRegionSize[3] = 29 * CODECHAL_CACHELINE_SIZE; |
| 5341 |
hucRegionName[4] = "_UncompressedHdr"; |
| 5342 |
hucRegionSize[4] = CODECHAL_ENCODE_VP9_PAK_INSERT_UNCOMPRESSED_HEADER; |
| 5343 |
hucRegionName[5] = "_CompressedHdr"; |
| 5344 |
hucRegionSize[5] = 32 * CODECHAL_CACHELINE_SIZE; |
| 5345 |
hucRegionName[6] = "_SecondLevelBatchBuffer"; |
| 5346 |
hucRegionSize[6] = m_vdencPicStateSecondLevelBatchBufferSize; |
| 5347 |
hucRegionName[7] = "_SecondLevelBatchBuffer"; |
| 5348 |
hucRegionSize[7] = m_vdencPicStateSecondLevelBatchBufferSize; |
| 5349 |
hucRegionName[8] = "_UncompressedHdr"; |
| 5350 |
hucRegionSize[8] = CODECHAL_ENCODE_VP9_PAK_INSERT_UNCOMPRESSED_HEADER; |
| 5351 |
hucRegionName[9] = "_DefaultProbs"; |
| 5352 |
hucRegionSize[9] = sizeof(Keyframe_Default_Probs) + sizeof(Inter_Default_Probs); |
| 5353 |
hucRegionName[10] = "_SuperFrameBuffer"; |
| 5354 |
hucRegionSize[10] = CODECHAL_ENCODE_VP9_BRC_SUPER_FRAME_BUFFER_SIZE; |
| 5355 |
hucRegionName[11] = "_DataExtension"; |
| 5356 |
hucRegionSize[11] = CODECHAL_ENCODE_VP9_VDENC_DATA_EXTENSION_SIZE; |
| 5357 |
) |
| 5358 |
|
| 5359 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 5360 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 5361 |
|
| 5362 |
if ((!m_singleTaskPhaseSupported || m_firstTaskInPhase) && !m_scalableMode) |
| 5363 |
{ |
| 5364 |
bool requestFrameTracking = false; |
| 5365 |
// Send command buffer header at the beginning (OS dependent) |
| 5366 |
// frame tracking tag is only added in the last command buffer header |
| 5367 |
requestFrameTracking = m_singleTaskPhaseSupported ? m_firstTaskInPhase : m_lastTaskInPhase; |
| 5368 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking(&cmdBuffer, requestFrameTracking)); |
| 5369 |
m_firstTaskInPhase = false; |
| 5370 |
} |
| 5371 |
// Collect of HuC BRC Update kernel performance data |
| 5372 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectStartCmd((void *)this, m_osInterface, m_miInterface, &cmdBuffer)); |
| 5373 |
|
| 5374 |
int currPass = GetCurrentPass(); |
| 5375 |
if (m_scalableMode && m_isTilingSupported) |
| 5376 |
{ |
| 5377 |
// Define huc done semaphore to be empty at the start |
| 5378 |
for (auto i = 0; i < m_numPipe; i++) |
| 5379 |
{ |
| 5380 |
SetSemaphoreMem(&m_hucDoneSemaphoreMem[i].sResource, &cmdBuffer, 0); |
| 5381 |
} |
| 5382 |
// Wait here for pak int done from previous pass |
| 5383 |
if (IsLastPass()) |
| 5384 |
{ |
| 5385 |
SendHWWaitCommand(&m_pakIntDoneSemaphoreMem.sResource, &cmdBuffer, currPass); |
| 5386 |
SetSemaphoreMem(&m_pakIntDoneSemaphoreMem.sResource, &cmdBuffer, 0); |
| 5387 |
} |
| 5388 |
} |
| 5389 |
|
| 5390 |
// load kernel from WOPCM into L2 storage RAM |
| 5391 |
MHW_VDBOX_HUC_IMEM_STATE_PARAMS imemParams; |
| 5392 |
MOS_ZeroMemory(&imemParams, sizeof(imemParams)); |
| 5393 |
imemParams.dwKernelDescriptor = m_vdboxHucVp9VdencProbKernelDescriptor; |
| 5394 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucImemStateCmd(&cmdBuffer, &imemParams)); |
| 5395 |
|
| 5396 |
// pipe mode select |
| 5397 |
MHW_VDBOX_PIPE_MODE_SELECT_PARAMS pipeModeSelectParams; |
| 5398 |
pipeModeSelectParams.Mode = m_mode; |
| 5399 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucPipeModeSelectCmd(&cmdBuffer, &pipeModeSelectParams)); |
| 5400 |
|
| 5401 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetDmemHuCVp9Prob()); |
| 5402 |
|
| 5403 |
MHW_VDBOX_HUC_DMEM_STATE_PARAMS dmemParams; |
| 5404 |
MOS_ZeroMemory(&dmemParams, sizeof(dmemParams)); |
| 5405 |
dmemParams.presHucDataSource = &m_resHucProbDmemBuffer[currPass][m_currRecycledBufIdx]; |
| 5406 |
dmemParams.dwDataLength = MOS_ALIGN_CEIL(sizeof(HucProbDmem), CODECHAL_CACHELINE_SIZE); |
| 5407 |
dmemParams.dwDmemOffset = HUC_DMEM_OFFSET_RTOS_GEMS; |
| 5408 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucDmemStateCmd(&cmdBuffer, &dmemParams)); |
| 5409 |
|
| 5410 |
// Add Virtual addr |
| 5411 |
MHW_VDBOX_HUC_VIRTUAL_ADDR_PARAMS virtualAddrParams; |
| 5412 |
MOS_ZeroMemory(&virtualAddrParams, sizeof(virtualAddrParams)); |
| 5413 |
// Input regions |
| 5414 |
virtualAddrParams.regionParams[0].presRegion = &m_resProbBuffer[m_vp9PicParams->PicFlags.fields.frame_context_idx]; |
| 5415 |
virtualAddrParams.regionParams[0].isWritable = true; // Region 0 is both read and write for HuC. Has input probabilities before running HuC and updated probabilities after running HuC, which will then be input to next pass |
| 5416 |
if (m_scalableMode) |
| 5417 |
{ |
| 5418 |
virtualAddrParams.regionParams[1].presRegion = &m_frameStatsPakIntegrationBuffer.sResource; |
| 5419 |
virtualAddrParams.regionParams[1].dwOffset = m_frameStatsOffset.counterBuffer; |
| 5420 |
} |
| 5421 |
else |
| 5422 |
{ |
| 5423 |
virtualAddrParams.regionParams[1].presRegion = &m_resProbabilityCounterBuffer; |
| 5424 |
virtualAddrParams.regionParams[1].dwOffset = 0; |
| 5425 |
} |
| 5426 |
// If BRC enabled, BRC Pass 2 output SLBB -> input SLBB for HPU on pass 2 (HPU pass 1 and 3. BRC Update pass 1 and 2) |
| 5427 |
// BRC Pass 1 output SLBB -> input SLBB for HPU on pass 1 |
| 5428 |
// If BRC not on, Driver prepared SLBB -> input to HPU on both passes |
| 5429 |
|
| 5430 |
if (m_vdencBrcEnabled) |
| 5431 |
{ |
| 5432 |
virtualAddrParams.regionParams[7].presRegion = &m_resVdencPictureState2NdLevelBatchBufferWrite[0]; |
| 5433 |
} |
| 5434 |
else |
| 5435 |
{ |
| 5436 |
virtualAddrParams.regionParams[7].presRegion = &m_resVdencPictureState2NdLevelBatchBufferRead[currPass][m_vdencPictureState2ndLevelBBIndex]; |
| 5437 |
} |
| 5438 |
|
| 5439 |
virtualAddrParams.regionParams[8].presRegion = &m_resHucPakInsertUncompressedHeaderReadBuffer[m_currRecycledBufIdx]; |
| 5440 |
virtualAddrParams.regionParams[9].presRegion = &m_resHucDefaultProbBuffer; |
| 5441 |
|
| 5442 |
// Output regions |
| 5443 |
virtualAddrParams.regionParams[2].presRegion = &m_resHucProbOutputBuffer; // Final probability output from HuC after each pass |
| 5444 |
virtualAddrParams.regionParams[2].isWritable = true; |
| 5445 |
virtualAddrParams.regionParams[3].presRegion = &m_resProbabilityDeltaBuffer; |
| 5446 |
virtualAddrParams.regionParams[3].isWritable = true; |
| 5447 |
virtualAddrParams.regionParams[4].presRegion = &m_resHucPakInsertUncompressedHeaderWriteBuffer; |
| 5448 |
virtualAddrParams.regionParams[4].isWritable = true; |
| 5449 |
virtualAddrParams.regionParams[5].presRegion = &m_resCompressedHeaderBuffer; |
| 5450 |
virtualAddrParams.regionParams[5].isWritable = true; |
| 5451 |
virtualAddrParams.regionParams[6].presRegion = &m_resVdencPictureState2NdLevelBatchBufferWrite[0]; |
| 5452 |
virtualAddrParams.regionParams[6].isWritable = true; |
| 5453 |
virtualAddrParams.regionParams[10].presRegion = &m_resBitstreamBuffer; |
| 5454 |
virtualAddrParams.regionParams[10].isWritable = true; |
| 5455 |
virtualAddrParams.regionParams[11].presRegion = &m_resVdencDataExtensionBuffer; |
| 5456 |
virtualAddrParams.regionParams[11].isWritable = true; |
| 5457 |
|
| 5458 |
m_hpuVirtualAddrParams = virtualAddrParams; |
| 5459 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucVirtualAddrStateCmd(&cmdBuffer, &virtualAddrParams)); |
| 5460 |
// Store HUC_STATUS2 register bit 6 before HUC_Start command |
| 5461 |
// This bit will be cleared by HW at the end of a HUC workload |
| 5462 |
// (HUC_Start command with last start bit set). |
| 5463 |
CODECHAL_DEBUG_TOOL( |
| 5464 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHuCStatus2Register(&cmdBuffer)); |
| 5465 |
) |
| 5466 |
|
| 5467 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHuCStatus2Report(&cmdBuffer)); |
| 5468 |
|
| 5469 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucStartCmd(&cmdBuffer, true)); |
| 5470 |
|
| 5471 |
// wait Huc completion (use HEVC bit for now) |
| 5472 |
MHW_VDBOX_VD_PIPE_FLUSH_PARAMS vdPipeFlushParams; |
| 5473 |
MOS_ZeroMemory(&vdPipeFlushParams, sizeof(vdPipeFlushParams)); |
| 5474 |
vdPipeFlushParams.Flags.bFlushHEVC = 1; |
| 5475 |
vdPipeFlushParams.Flags.bWaitDoneHEVC = 1; |
| 5476 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdPipelineFlushCmd(&cmdBuffer, &vdPipeFlushParams)); |
| 5477 |
|
| 5478 |
// Flush the engine to ensure memory written out |
| 5479 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 5480 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 5481 |
flushDwParams.bVideoPipelineCacheInvalidate = true; |
| 5482 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(&cmdBuffer, &flushDwParams)); |
| 5483 |
|
| 5484 |
// Write HUC_STATUS mask: DW1 (mask value) |
| 5485 |
MHW_MI_STORE_DATA_PARAMS storeDataParams; |
| 5486 |
MOS_ZeroMemory(&storeDataParams, sizeof(storeDataParams)); |
| 5487 |
storeDataParams.pOsResource = &m_resHucPakMmioBuffer; |
| 5488 |
storeDataParams.dwResourceOffset = sizeof(uint32_t); |
| 5489 |
storeDataParams.dwValue = 1 << 31; //Repak bit for HUC is bit 31 |
| 5490 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreDataImmCmd(&cmdBuffer, &storeDataParams)); |
| 5491 |
|
| 5492 |
// store HUC_STATUS register |
| 5493 |
MHW_MI_STORE_REGISTER_MEM_PARAMS storeRegParams; |
| 5494 |
MOS_ZeroMemory(&storeRegParams, sizeof(storeRegParams)); |
| 5495 |
storeRegParams.presStoreBuffer = &m_resHucPakMmioBuffer; |
| 5496 |
storeRegParams.dwOffset = 0; |
| 5497 |
storeRegParams.dwRegister = m_hucInterface->GetMmioRegisters(MHW_VDBOX_NODE_1)->hucStatusRegOffset; |
| 5498 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreRegisterMemCmd(&cmdBuffer, &storeRegParams)); |
| 5499 |
|
| 5500 |
auto mmioRegisters = m_hucInterface->GetMmioRegisters(MHW_VDBOX_NODE_1); |
| 5501 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHucErrorStatus(mmioRegisters, &cmdBuffer, false)); |
| 5502 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InsertConditionalBBEndWithHucErrorStatus(&cmdBuffer)); |
| 5503 |
|
| 5504 |
// In case of other pipes running other tiles, signal the vdenc/pak hw commands there to proceed because huc done |
| 5505 |
if (m_scalableMode && m_isTilingSupported) |
| 5506 |
{ |
| 5507 |
for (auto i = 1; i < m_numPipe; i++) |
| 5508 |
{ |
| 5509 |
if (!Mos_ResourceIsNull(&m_hucDoneSemaphoreMem[i].sResource)) |
| 5510 |
{ |
| 5511 |
CODECHAL_ENCODE_CHK_STATUS_RETURN( |
| 5512 |
SetSemaphoreMem( |
| 5513 |
&m_hucDoneSemaphoreMem[i].sResource, |
| 5514 |
&cmdBuffer, |
| 5515 |
(currPass + 1)) |
| 5516 |
); |
| 5517 |
} |
| 5518 |
} |
| 5519 |
} |
| 5520 |
|
| 5521 |
// For superframe pass, after HuC executes, write the updated size (combined frame size) to status report |
| 5522 |
// So app knows total size instead of just the showframe size |
| 5523 |
if (m_superFrameHucPass) |
| 5524 |
{ |
| 5525 |
EncodeStatusBuffer* encodeStatusBuf = &m_encodeStatusBuf; |
| 5526 |
uint32_t baseOffset = |
| 5527 |
(encodeStatusBuf->wCurrIndex * m_encodeStatusBuf.dwReportSize) + |
| 5528 |
sizeof(uint32_t) * 2; // encodeStatus is offset by 2 DWs in the resource |
| 5529 |
|
| 5530 |
MHW_MI_COPY_MEM_MEM_PARAMS copyMemMemParams; |
| 5531 |
MOS_ZeroMemory(©MemMemParams, sizeof(copyMemMemParams)); |
| 5532 |
|
| 5533 |
copyMemMemParams.presSrc = virtualAddrParams.regionParams[11].presRegion; |
| 5534 |
copyMemMemParams.dwSrcOffset = 0; // Updated framesize is 1st DW in buffer |
| 5535 |
copyMemMemParams.presDst = &encodeStatusBuf->resStatusBuffer; |
| 5536 |
copyMemMemParams.dwDstOffset = baseOffset + encodeStatusBuf->dwBSByteCountOffset; |
| 5537 |
|
| 5538 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiCopyMemMemCmd( |
| 5539 |
&cmdBuffer, |
| 5540 |
©MemMemParams)); |
| 5541 |
} |
| 5542 |
// Ending collect of HuC BRC Update kernel performance data |
| 5543 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectEndCmd((void *)this, m_osInterface, m_miInterface, &cmdBuffer)); |
| 5544 |
|
| 5545 |
if ((!m_singleTaskPhaseSupported && !m_scalableMode) || m_superFrameHucPass) |
| 5546 |
{ |
| 5547 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd(&cmdBuffer, nullptr)); |
| 5548 |
} |
| 5549 |
|
| 5550 |
// Dump input probabilites before running HuC |
| 5551 |
CODECHAL_DEBUG_TOOL( |
| 5552 |
CodechalHucRegionDumpType dumpType = m_superFrameHucPass ? CodechalHucRegionDumpType::hucRegionDumpHpuSuperFrame : CodechalHucRegionDumpType::hucRegionDumpHpu; |
| 5553 |
m_debugInterface->DumpHucRegion( |
| 5554 |
virtualAddrParams.regionParams[0].presRegion, |
| 5555 |
0, |
| 5556 |
hucRegionSize[0], |
| 5557 |
0, |
| 5558 |
"_ProbBuffer", |
| 5559 |
(virtualAddrParams.regionParams[0].isWritable ? true : false), |
| 5560 |
currPass, |
| 5561 |
dumpType); |
| 5562 |
) |
| 5563 |
|
| 5564 |
ReturnCommandBuffer(&cmdBuffer); |
| 5565 |
|
| 5566 |
// For Temporal scaling, super frame pass is initiated after the command buffer submission in ExecuteSliceLevel. |
| 5567 |
// So if Single Task Phase is enabled, then we need to explicitly submit the command buffer here to call HuC |
| 5568 |
if ((!m_singleTaskPhaseSupported && !m_scalableMode) || m_superFrameHucPass) |
| 5569 |
{ |
| 5570 |
bool renderFlags = m_videoContextUsesNullHw; |
| 5571 |
|
| 5572 |
CODECHAL_DEBUG_TOOL( |
| 5573 |
std::string nameCmdPass = (m_superFrameHucPass ? "HPU_SuperFramePass" : "HPU_Pass") + std::to_string(currPass); |
| 5574 |
|
| 5575 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCmdBuffer( |
| 5576 |
&cmdBuffer, |
| 5577 |
CODECHAL_NUM_MEDIA_STATES, |
| 5578 |
nameCmdPass.c_str())); |
| 5579 |
) |
| 5580 |
|
| 5581 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 5582 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking(&cmdBuffer, m_vp9PicParams->PicFlags.fields.super_frame)); |
| 5583 |
ReturnCommandBuffer(&cmdBuffer); |
| 5584 |
|
| 5585 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SubmitCommandBuffer(&cmdBuffer, renderFlags)); |
| 5586 |
|
| 5587 |
CODECHAL_DEBUG_TOOL( |
| 5588 |
CodechalHucRegionDumpType dumpType = m_superFrameHucPass ? CodechalHucRegionDumpType::hucRegionDumpHpuSuperFrame : CodechalHucRegionDumpType::hucRegionDumpHpu; |
| 5589 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpHucDmem( |
| 5590 |
&m_resHucProbDmemBuffer[currPass][m_currRecycledBufIdx], |
| 5591 |
sizeof(HucProbDmem), |
| 5592 |
currPass, |
| 5593 |
dumpType)); |
| 5594 |
|
| 5595 |
for (auto i = 0; i < 16; i++) |
| 5596 |
{ |
| 5597 |
if (virtualAddrParams.regionParams[i].presRegion) |
| 5598 |
{ |
| 5599 |
if (m_scalableMode && m_isTilingSupported && virtualAddrParams.regionParams[i].isWritable && i != 11) |
| 5600 |
{ |
| 5601 |
continue; |
| 5602 |
} |
| 5603 |
m_debugInterface->DumpHucRegion( |
| 5604 |
virtualAddrParams.regionParams[i].presRegion, |
| 5605 |
virtualAddrParams.regionParams[i].dwOffset, |
| 5606 |
hucRegionSize[i], |
| 5607 |
i, |
| 5608 |
hucRegionName[i], |
| 5609 |
!virtualAddrParams.regionParams[i].isWritable, |
| 5610 |
currPass, |
| 5611 |
dumpType); |
| 5612 |
} |
| 5613 |
}) |
| 5614 |
} |
| 5615 |
|
| 5616 |
return eStatus; |
| 5617 |
} |
| 5618 |
|
| 5619 |
/*---------------------------------------------------------------------------- |
| 5620 |
| Name : HuCBrcInitReset |
| 5621 |
| Purpose : Start/Submit VP9 HuC BrcInit kernel to HW |
| 5622 |
| |
| 5623 |
| Returns : MOS_STATUS |
| 5624 |
\---------------------------------------------------------------------------*/ |
| 5625 |
MOS_STATUS CodechalVdencVp9StateG12::HuCBrcInitReset() |
| 5626 |
{ |
| 5627 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 5628 |
|
| 5629 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 5630 |
|
| 5631 |
int currPass = GetCurrentPass(); |
| 5632 |
|
| 5633 |
CODECHAL_DEBUG_TOOL( |
| 5634 |
uint32_t hucRegionSize[16]; |
| 5635 |
const char* hucRegionName[16]; |
| 5636 |
|
| 5637 |
hucRegionName[0] = "_BrcHistoryBuffer"; |
| 5638 |
hucRegionSize[0] = m_brcHistoryBufferSize; |
| 5639 |
) |
| 5640 |
|
| 5641 |
MHW_VDBOX_HUC_VIRTUAL_ADDR_PARAMS virtualAddrParams; |
| 5642 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 5643 |
if (m_swBrcMode) |
| 5644 |
{ |
| 5645 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetDmemHuCBrcInitReset()); |
| 5646 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SoftwareBRC(false)); |
| 5647 |
// Set region params for dumping only |
| 5648 |
MOS_ZeroMemory(&virtualAddrParams, sizeof(virtualAddrParams)); |
| 5649 |
virtualAddrParams.regionParams[0].presRegion = &m_brcBuffers.resBrcHistoryBuffer; |
| 5650 |
virtualAddrParams.regionParams[0].isWritable = true; |
| 5651 |
m_inputBitsPerFrame = ((m_vp9SeqParams->MaxBitRate * CODECHAL_ENCODE_BRC_KBPS) * 100.) / ((m_vp9SeqParams->FrameRate[m_vp9SeqParams->NumTemporalLayersMinus1].uiNumerator * 100.) / m_vp9SeqParams->FrameRate[m_vp9SeqParams->NumTemporalLayersMinus1].uiDenominator); |
| 5652 |
m_curTargetFullness = m_vp9SeqParams->TargetBitRate[m_vp9SeqParams->NumTemporalLayersMinus1] * CODECHAL_ENCODE_BRC_KBPS; |
| 5653 |
|
| 5654 |
CODECHAL_DEBUG_TOOL( |
| 5655 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpHucDmem( |
| 5656 |
&m_resVdencBrcInitDmemBuffer, |
| 5657 |
sizeof(HucBrcInitDmem), |
| 5658 |
0, |
| 5659 |
CodechalHucRegionDumpType::hucRegionDumpInit)); |
| 5660 |
|
| 5661 |
for (auto i = 0; i < 16; i++) |
| 5662 |
{ |
| 5663 |
if (virtualAddrParams.regionParams[i].presRegion) |
| 5664 |
{ |
| 5665 |
m_debugInterface->DumpHucRegion( |
| 5666 |
virtualAddrParams.regionParams[i].presRegion, |
| 5667 |
virtualAddrParams.regionParams[i].dwOffset, |
| 5668 |
hucRegionSize[i], |
| 5669 |
i, |
| 5670 |
hucRegionName[i], |
| 5671 |
!virtualAddrParams.regionParams[i].isWritable, |
| 5672 |
currPass, |
| 5673 |
CodechalHucRegionDumpType::hucRegionDumpInit); |
| 5674 |
} |
| 5675 |
} |
| 5676 |
) |
| 5677 |
return eStatus; |
| 5678 |
} |
| 5679 |
#endif |
| 5680 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 5681 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 5682 |
|
| 5683 |
if ((!m_singleTaskPhaseSupported || m_firstTaskInPhase) && !m_scalableMode) |
| 5684 |
{ |
| 5685 |
// Send command buffer header at the beginning (OS dependent) |
| 5686 |
bool requestFrameTracking = m_singleTaskPhaseSupported ? m_firstTaskInPhase : false; |
| 5687 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking(&cmdBuffer, requestFrameTracking)); |
| 5688 |
|
| 5689 |
m_firstTaskInPhase = false; |
| 5690 |
} |
| 5691 |
// Collect HuC Init/Reset kernel performance data |
| 5692 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectStartCmd((void *)this, m_osInterface, m_miInterface, &cmdBuffer)); |
| 5693 |
|
| 5694 |
// load kernel from WOPCM into L2 storage RAM |
| 5695 |
MHW_VDBOX_HUC_IMEM_STATE_PARAMS imemParams; |
| 5696 |
MOS_ZeroMemory(&imemParams, sizeof(imemParams)); |
| 5697 |
imemParams.dwKernelDescriptor = m_vdboxHucVp9VdencBrcInitKernelDescriptor; |
| 5698 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucImemStateCmd(&cmdBuffer, &imemParams)); |
| 5699 |
|
| 5700 |
// pipe mode select |
| 5701 |
MHW_VDBOX_PIPE_MODE_SELECT_PARAMS pipeModeSelectParams; |
| 5702 |
pipeModeSelectParams.Mode = m_mode; |
| 5703 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucPipeModeSelectCmd(&cmdBuffer, &pipeModeSelectParams)); |
| 5704 |
|
| 5705 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetDmemHuCBrcInitReset()); |
| 5706 |
|
| 5707 |
m_inputBitsPerFrame = ((m_vp9SeqParams->MaxBitRate * CODECHAL_ENCODE_BRC_KBPS) * 100.) / ((m_vp9SeqParams->FrameRate[m_vp9SeqParams->NumTemporalLayersMinus1].uiNumerator * 100.) / m_vp9SeqParams->FrameRate[m_vp9SeqParams->NumTemporalLayersMinus1].uiDenominator); |
| 5708 |
m_curTargetFullness = m_vp9SeqParams->TargetBitRate[m_vp9SeqParams->NumTemporalLayersMinus1] * CODECHAL_ENCODE_BRC_KBPS; |
| 5709 |
|
| 5710 |
// set HuC DMEM param |
| 5711 |
MHW_VDBOX_HUC_DMEM_STATE_PARAMS dmemParams; |
| 5712 |
MOS_ZeroMemory(&dmemParams, sizeof(dmemParams)); |
| 5713 |
dmemParams.presHucDataSource = &m_resVdencBrcInitDmemBuffer; |
| 5714 |
dmemParams.dwDataLength = MOS_ALIGN_CEIL(sizeof(HucBrcInitDmem), CODECHAL_CACHELINE_SIZE); |
| 5715 |
dmemParams.dwDmemOffset = HUC_DMEM_OFFSET_RTOS_GEMS; |
| 5716 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucDmemStateCmd(&cmdBuffer, &dmemParams)); |
| 5717 |
|
| 5718 |
MOS_ZeroMemory(&virtualAddrParams, sizeof(virtualAddrParams)); |
| 5719 |
virtualAddrParams.regionParams[0].presRegion = &m_brcBuffers.resBrcHistoryBuffer; |
| 5720 |
virtualAddrParams.regionParams[0].isWritable = true; |
| 5721 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucVirtualAddrStateCmd(&cmdBuffer, &virtualAddrParams)); |
| 5722 |
|
| 5723 |
// Store HUC_STATUS2 register bit 6 before HUC_Start command |
| 5724 |
// This bit will be cleared by HW at the end of a HUC workload |
| 5725 |
// (HUC_Start command with last start bit set). |
| 5726 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHuCStatus2Register(&cmdBuffer)); |
| 5727 |
|
| 5728 |
// HuC Status 2 report in Status Report |
| 5729 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHuCStatus2Report(&cmdBuffer)); |
| 5730 |
|
| 5731 |
// Check HuC_STATUS2 bit6, if bit6 > 0 HW continue execution following cmd, otherwise it send a COND BB END cmd. |
| 5732 |
uint32_t compareOperation = mhw_mi_g12_X::MI_CONDITIONAL_BATCH_BUFFER_END_CMD::COMPARE_OPERATION_MADGREATERTHANIDD; |
| 5733 |
auto hwInterface = dynamic_cast<CodechalHwInterfaceG12 *>(m_hwInterface); |
| 5734 |
CODECHAL_ENCODE_CHK_NULL_RETURN(hwInterface); |
| 5735 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(hwInterface->SendCondBbEndCmd( |
| 5736 |
&m_resHucStatus2Buffer, 0, 0, false, false, compareOperation, &cmdBuffer)); |
| 5737 |
|
| 5738 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucStartCmd(&cmdBuffer, true)); |
| 5739 |
|
| 5740 |
// wait Huc completion (use HEVC bit for now) |
| 5741 |
MHW_VDBOX_VD_PIPE_FLUSH_PARAMS vdPipeFlushParams; |
| 5742 |
MOS_ZeroMemory(&vdPipeFlushParams, sizeof(vdPipeFlushParams)); |
| 5743 |
vdPipeFlushParams.Flags.bFlushHEVC = 1; |
| 5744 |
vdPipeFlushParams.Flags.bWaitDoneHEVC = 1; |
| 5745 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdPipelineFlushCmd(&cmdBuffer, &vdPipeFlushParams)); |
| 5746 |
|
| 5747 |
// Flush the engine to ensure memory written out |
| 5748 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 5749 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 5750 |
flushDwParams.bVideoPipelineCacheInvalidate = true; |
| 5751 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(&cmdBuffer, &flushDwParams)); |
| 5752 |
|
| 5753 |
auto mmioRegisters = m_hucInterface->GetMmioRegisters(MHW_VDBOX_NODE_1); |
| 5754 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHucErrorStatus(mmioRegisters, &cmdBuffer, false)); |
| 5755 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InsertConditionalBBEndWithHucErrorStatus(&cmdBuffer)); |
| 5756 |
// End: Collect HuC Init/Reset kernel performance data |
| 5757 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectEndCmd((void *)this, m_osInterface, m_miInterface, &cmdBuffer)); |
| 5758 |
|
| 5759 |
if (!m_singleTaskPhaseSupported && (m_osInterface->bNoParsingAssistanceInKmd) && !m_scalableMode) |
| 5760 |
{ |
| 5761 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd(&cmdBuffer, nullptr)); |
| 5762 |
} |
| 5763 |
|
| 5764 |
ReturnCommandBuffer(&cmdBuffer); |
| 5765 |
|
| 5766 |
if (!m_singleTaskPhaseSupported) |
| 5767 |
{ |
| 5768 |
bool renderingFlags = m_videoContextUsesNullHw; |
| 5769 |
|
| 5770 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SubmitCommandBuffer(&cmdBuffer, renderingFlags)); |
| 5771 |
|
| 5772 |
CODECHAL_DEBUG_TOOL( |
| 5773 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpHucDmem( |
| 5774 |
&m_resVdencBrcInitDmemBuffer, |
| 5775 |
sizeof(HucBrcInitDmem), |
| 5776 |
0, |
| 5777 |
CodechalHucRegionDumpType::hucRegionDumpInit)); |
| 5778 |
|
| 5779 |
for (auto i = 0; i < 16; i++) |
| 5780 |
{ |
| 5781 |
if (virtualAddrParams.regionParams[i].presRegion) |
| 5782 |
{ |
| 5783 |
m_debugInterface->DumpHucRegion( |
| 5784 |
virtualAddrParams.regionParams[i].presRegion, |
| 5785 |
virtualAddrParams.regionParams[i].dwOffset, |
| 5786 |
hucRegionSize[i], |
| 5787 |
i, |
| 5788 |
hucRegionName[i], |
| 5789 |
!virtualAddrParams.regionParams[i].isWritable, |
| 5790 |
0, |
| 5791 |
CodechalHucRegionDumpType::hucRegionDumpInit); |
| 5792 |
} |
| 5793 |
} |
| 5794 |
) |
| 5795 |
} |
| 5796 |
|
| 5797 |
return eStatus; |
| 5798 |
} |
| 5799 |
|
| 5800 |
/*---------------------------------------------------------------------------- |
| 5801 |
| Name : HuCBrcUpdate |
| 5802 |
| Purpose : Start/Submit VP9 HuC BrcUpdate kernel to HW |
| 5803 |
| |
| 5804 |
| Returns : MOS_STATUS |
| 5805 |
\---------------------------------------------------------------------------*/ |
| 5806 |
MOS_STATUS CodechalVdencVp9StateG12::HuCBrcUpdate() |
| 5807 |
{ |
| 5808 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 5809 |
|
| 5810 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 5811 |
|
| 5812 |
int currPass = GetCurrentPass(); |
| 5813 |
|
| 5814 |
CODECHAL_DEBUG_TOOL( |
| 5815 |
uint32_t hucRegionSize[16]; |
| 5816 |
const char* hucRegionName[16]; |
| 5817 |
|
| 5818 |
hucRegionName[0] = "_BrcHistory"; |
| 5819 |
hucRegionSize[0] = m_brcHistoryBufferSize; |
| 5820 |
hucRegionName[1] = "_VDEncStats"; |
| 5821 |
hucRegionSize[1] = m_vdencBrcStatsBufferSize; |
| 5822 |
hucRegionName[2] = "_PAKStats"; |
| 5823 |
hucRegionSize[2] = m_vdencBrcPakStatsBufferSize; |
| 5824 |
hucRegionName[3] = "_InputSLBB"; |
| 5825 |
hucRegionSize[3] = m_vdencPicStateSecondLevelBatchBufferSize; |
| 5826 |
hucRegionName[4] = "_BRCData"; |
| 5827 |
hucRegionSize[4] = CODECHAL_ENCODE_VP9_HUC_BRC_DATA_BUFFER_SIZE; |
| 5828 |
hucRegionName[5] = "_ConstData"; |
| 5829 |
hucRegionSize[5] = m_brcConstantSurfaceSize; |
| 5830 |
hucRegionName[6] = "_OutputSLBB"; |
| 5831 |
hucRegionSize[6] = m_vdencPicStateSecondLevelBatchBufferSize; |
| 5832 |
hucRegionName[7] = "_PAKMMIO"; |
| 5833 |
hucRegionSize[7] = MOS_ALIGN_CEIL(CODECHAL_ENCODE_VP9_HUC_BRC_DATA_BUFFER_SIZE, CODECHAL_PAGE_SIZE); |
| 5834 |
) |
| 5835 |
|
| 5836 |
MHW_VDBOX_HUC_VIRTUAL_ADDR_PARAMS virtualAddrParams; |
| 5837 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 5838 |
if (m_swBrcMode) |
| 5839 |
{ |
| 5840 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetDmemHuCBrcUpdate()); |
| 5841 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitBrcConstantBuffer(&m_brcBuffers.resBrcConstantDataBuffer[0], m_pictureCodingType)); |
| 5842 |
// Set region params for dumping only |
| 5843 |
MOS_ZeroMemory(&virtualAddrParams, sizeof(virtualAddrParams)); |
| 5844 |
virtualAddrParams.regionParams[0].presRegion = &m_brcBuffers.resBrcHistoryBuffer; |
| 5845 |
virtualAddrParams.regionParams[0].isWritable = true; |
| 5846 |
virtualAddrParams.regionParams[1].presRegion = &m_resVdencBrcStatsBuffer; |
| 5847 |
virtualAddrParams.regionParams[2].presRegion = &m_resFrameStatStreamOutBuffer; |
| 5848 |
virtualAddrParams.regionParams[3].presRegion = &m_resVdencPictureState2NdLevelBatchBufferRead[currPass][m_vdencPictureState2ndLevelBBIndex]; |
| 5849 |
virtualAddrParams.regionParams[4].presRegion = &m_brcBuffers.resBrcHucDataBuffer; |
| 5850 |
virtualAddrParams.regionParams[4].isWritable = true; |
| 5851 |
virtualAddrParams.regionParams[5].presRegion = GetBrcConstantBuffer(&m_brcBuffers.resBrcConstantDataBuffer[0], m_pictureCodingType); |
| 5852 |
virtualAddrParams.regionParams[6].presRegion = &m_resVdencPictureState2NdLevelBatchBufferWrite[0]; |
| 5853 |
virtualAddrParams.regionParams[6].isWritable = true; |
| 5854 |
virtualAddrParams.regionParams[7].presRegion = &m_brcBuffers.resBrcBitstreamSizeBuffer; |
| 5855 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpHucRegion(// Dump history IN since it's both IN/OUT, OUT will dump at end of function, rest of buffers are IN XOR OUT (not both) |
| 5856 |
virtualAddrParams.regionParams[0].presRegion, |
| 5857 |
virtualAddrParams.regionParams[0].dwOffset, |
| 5858 |
hucRegionSize[0], |
| 5859 |
0, |
| 5860 |
hucRegionName[0], |
| 5861 |
true, |
| 5862 |
currPass, |
| 5863 |
CodechalHucRegionDumpType::hucRegionDumpUpdate)); |
| 5864 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SoftwareBRC(true)); |
| 5865 |
|
| 5866 |
CODECHAL_DEBUG_TOOL( |
| 5867 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpHucDmem( |
| 5868 |
&m_resVdencBrcUpdateDmemBuffer[currPass][m_currRecycledBufIdx], |
| 5869 |
sizeof(HucBrcUpdateDmem), // Change buffer and size to update dmem |
| 5870 |
currPass, |
| 5871 |
CodechalHucRegionDumpType::hucRegionDumpUpdate)); |
| 5872 |
|
| 5873 |
for (auto i = 0; i < 16; i++) |
| 5874 |
{ |
| 5875 |
if (virtualAddrParams.regionParams[i].presRegion) |
| 5876 |
{ |
| 5877 |
m_debugInterface->DumpHucRegion( |
| 5878 |
virtualAddrParams.regionParams[i].presRegion, |
| 5879 |
virtualAddrParams.regionParams[i].dwOffset, |
| 5880 |
hucRegionSize[i], |
| 5881 |
i, |
| 5882 |
hucRegionName[i], |
| 5883 |
!virtualAddrParams.regionParams[i].isWritable, |
| 5884 |
currPass, |
| 5885 |
CodechalHucRegionDumpType::hucRegionDumpUpdate); |
| 5886 |
} |
| 5887 |
} |
| 5888 |
); |
| 5889 |
// We increment by the average frame value once for each frame |
| 5890 |
if (IsFirstPass()) |
| 5891 |
{ |
| 5892 |
m_curTargetFullness += m_inputBitsPerFrame; |
| 5893 |
} |
| 5894 |
|
| 5895 |
return eStatus; |
| 5896 |
} |
| 5897 |
#endif |
| 5898 |
|
| 5899 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 5900 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommandBuffer(&cmdBuffer)); |
| 5901 |
|
| 5902 |
if ((!m_singleTaskPhaseSupported || (m_firstTaskInPhase && !m_brcInit)) && !m_scalableMode) |
| 5903 |
{ |
| 5904 |
// Send command buffer header at the beginning (OS dependent) |
| 5905 |
bool requestFrameTracking = m_singleTaskPhaseSupported ? m_firstTaskInPhase : false; |
| 5906 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendPrologWithFrameTracking(&cmdBuffer, requestFrameTracking)); |
| 5907 |
|
| 5908 |
m_firstTaskInPhase = false; |
| 5909 |
} |
| 5910 |
// Collect HuC BRC Update kernel performance data |
| 5911 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectStartCmd((void *)this, m_osInterface, m_miInterface, &cmdBuffer)); |
| 5912 |
|
| 5913 |
// For Scalability, wait here for previous pass PAK int done |
| 5914 |
if (m_scalableMode && !IsFirstPass() && m_isTilingSupported && !m_brcInit && !m_brcReset) |
| 5915 |
{ |
| 5916 |
SendHWWaitCommand(&m_pakIntDoneSemaphoreMem.sResource, &cmdBuffer, currPass); |
| 5917 |
SetSemaphoreMem(&m_pakIntDoneSemaphoreMem.sResource, &cmdBuffer, 0); |
| 5918 |
} |
| 5919 |
|
| 5920 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitBrcConstantBuffer(&m_brcBuffers.resBrcConstantDataBuffer[0], m_pictureCodingType)); |
| 5921 |
|
| 5922 |
// load kernel from WOPCM into L2 storage RAM |
| 5923 |
MHW_VDBOX_HUC_IMEM_STATE_PARAMS imemParams; |
| 5924 |
MOS_ZeroMemory(&imemParams, sizeof(imemParams)); |
| 5925 |
imemParams.dwKernelDescriptor = m_vdboxHucVp9VdencBrcUpdateKernelDescriptor; |
| 5926 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucImemStateCmd(&cmdBuffer, &imemParams)); |
| 5927 |
|
| 5928 |
// pipe mode select |
| 5929 |
MHW_VDBOX_PIPE_MODE_SELECT_PARAMS pipeModeSelectParams; |
| 5930 |
pipeModeSelectParams.Mode = m_mode; |
| 5931 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucPipeModeSelectCmd(&cmdBuffer, &pipeModeSelectParams)); |
| 5932 |
|
| 5933 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetDmemHuCBrcUpdate()); |
| 5934 |
|
| 5935 |
// set HuC DMEM param |
| 5936 |
MHW_VDBOX_HUC_DMEM_STATE_PARAMS dmemParams; |
| 5937 |
MOS_ZeroMemory(&dmemParams, sizeof(dmemParams)); |
| 5938 |
dmemParams.presHucDataSource = &m_resVdencBrcUpdateDmemBuffer[currPass][m_currRecycledBufIdx]; |
| 5939 |
dmemParams.dwDataLength = MOS_ALIGN_CEIL(sizeof(HucBrcUpdateDmem), CODECHAL_CACHELINE_SIZE); |
| 5940 |
dmemParams.dwDmemOffset = HUC_DMEM_OFFSET_RTOS_GEMS; // how to set? |
| 5941 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucDmemStateCmd(&cmdBuffer, &dmemParams)); |
| 5942 |
|
| 5943 |
// Set surfaces to HuC regions |
| 5944 |
MOS_ZeroMemory(&virtualAddrParams, sizeof(virtualAddrParams)); |
| 5945 |
|
| 5946 |
// History Buffer - IN/OUT |
| 5947 |
virtualAddrParams.regionParams[0].presRegion = &m_brcBuffers.resBrcHistoryBuffer; |
| 5948 |
virtualAddrParams.regionParams[0].isWritable = true; |
| 5949 |
|
| 5950 |
if (IsFirstPass()) //First BRC pass needs stats from last frame |
| 5951 |
{ |
| 5952 |
if (m_lastFrameScalableMode) // Frame (n-1) Scalable mode output -> input for frame n, BRC pass 0 |
| 5953 |
{ |
| 5954 |
//VDEnc Stats Buffer - IN |
| 5955 |
virtualAddrParams.regionParams[1].presRegion = &m_frameStatsPakIntegrationBuffer.sResource; |
| 5956 |
virtualAddrParams.regionParams[1].dwOffset = m_frameStatsOffset.vdencStats; |
| 5957 |
// Frame (not PAK) Stats Buffer - IN |
| 5958 |
virtualAddrParams.regionParams[2].presRegion = &m_frameStatsPakIntegrationBuffer.sResource; |
| 5959 |
virtualAddrParams.regionParams[2].dwOffset = m_frameStatsOffset.pakStats; |
| 5960 |
// PAK MMIO - IN |
| 5961 |
virtualAddrParams.regionParams[7].presRegion = &m_hucPakIntBrcDataBuffer; |
| 5962 |
} |
| 5963 |
else |
| 5964 |
{ |
| 5965 |
virtualAddrParams.regionParams[1].presRegion = &m_resVdencBrcStatsBuffer; |
| 5966 |
virtualAddrParams.regionParams[1].dwOffset = 0; |
| 5967 |
virtualAddrParams.regionParams[2].presRegion = &m_resFrameStatStreamOutBuffer; |
| 5968 |
virtualAddrParams.regionParams[2].dwOffset = 0; |
| 5969 |
virtualAddrParams.regionParams[7].presRegion = &m_brcBuffers.resBrcBitstreamSizeBuffer; |
| 5970 |
} |
| 5971 |
} |
| 5972 |
else // Second BRC Update Pass |
| 5973 |
{ |
| 5974 |
if (m_scalableMode) |
| 5975 |
{ |
| 5976 |
// VDEnc Stats Buffer - IN |
| 5977 |
virtualAddrParams.regionParams[1].presRegion = &m_frameStatsPakIntegrationBuffer.sResource; |
| 5978 |
virtualAddrParams.regionParams[1].dwOffset = m_frameStatsOffset.vdencStats; |
| 5979 |
// Frame (not PAK) Stats Buffer - IN |
| 5980 |
virtualAddrParams.regionParams[2].presRegion = &m_frameStatsPakIntegrationBuffer.sResource; |
| 5981 |
virtualAddrParams.regionParams[2].dwOffset = m_frameStatsOffset.pakStats; |
| 5982 |
// PAK MMIO - IN |
| 5983 |
virtualAddrParams.regionParams[7].presRegion = &m_hucPakIntBrcDataBuffer; |
| 5984 |
} |
| 5985 |
else |
| 5986 |
{ |
| 5987 |
virtualAddrParams.regionParams[1].presRegion = &m_resVdencBrcStatsBuffer; |
| 5988 |
virtualAddrParams.regionParams[1].dwOffset = 0; |
| 5989 |
virtualAddrParams.regionParams[2].presRegion = &m_resFrameStatStreamOutBuffer; |
| 5990 |
virtualAddrParams.regionParams[2].dwOffset = 0; |
| 5991 |
virtualAddrParams.regionParams[7].presRegion = &m_brcBuffers.resBrcBitstreamSizeBuffer; |
| 5992 |
} |
| 5993 |
} |
| 5994 |
|
| 5995 |
// Input SLBB (second level batch buffer) - IN |
| 5996 |
virtualAddrParams.regionParams[3].presRegion = &m_resVdencPictureState2NdLevelBatchBufferRead[currPass][m_vdencPictureState2ndLevelBBIndex]; |
| 5997 |
|
| 5998 |
// BRC Data - OUT |
| 5999 |
virtualAddrParams.regionParams[4].presRegion = &m_brcBuffers.resBrcHucDataBuffer; |
| 6000 |
virtualAddrParams.regionParams[4].isWritable = true; |
| 6001 |
|
| 6002 |
// Const Data - IN |
| 6003 |
virtualAddrParams.regionParams[5].presRegion = GetBrcConstantBuffer(&m_brcBuffers.resBrcConstantDataBuffer[0], m_pictureCodingType); |
| 6004 |
|
| 6005 |
// Output SLBB - OUT |
| 6006 |
virtualAddrParams.regionParams[6].presRegion = &m_resVdencPictureState2NdLevelBatchBufferWrite[0]; |
| 6007 |
virtualAddrParams.regionParams[6].isWritable = true; |
| 6008 |
|
| 6009 |
// Load HuC Regions into Cmd Buf |
| 6010 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucVirtualAddrStateCmd(&cmdBuffer, &virtualAddrParams)); |
| 6011 |
|
| 6012 |
// Store HUC_STATUS2 register bit 6 before HUC_Start command |
| 6013 |
// This bit will be cleared by HW at the end of a HUC workload |
| 6014 |
// (HUC_Start command with last start bit set). |
| 6015 |
CODECHAL_DEBUG_TOOL( |
| 6016 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHuCStatus2Register(&cmdBuffer)); |
| 6017 |
) |
| 6018 |
|
| 6019 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHuCStatus2Report(&cmdBuffer)); |
| 6020 |
|
| 6021 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hucInterface->AddHucStartCmd(&cmdBuffer, true)); |
| 6022 |
|
| 6023 |
// wait Huc completion (use HEVC bit for now) |
| 6024 |
MHW_VDBOX_VD_PIPE_FLUSH_PARAMS vdPipeFlushParams; |
| 6025 |
MOS_ZeroMemory(&vdPipeFlushParams, sizeof(vdPipeFlushParams)); |
| 6026 |
vdPipeFlushParams.Flags.bFlushHEVC = 1; |
| 6027 |
vdPipeFlushParams.Flags.bWaitDoneHEVC = 1; |
| 6028 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdPipelineFlushCmd(&cmdBuffer, &vdPipeFlushParams)); |
| 6029 |
|
| 6030 |
// Flush the engine to ensure memory written out |
| 6031 |
MHW_MI_FLUSH_DW_PARAMS flushDwParams; |
| 6032 |
MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); |
| 6033 |
flushDwParams.bVideoPipelineCacheInvalidate = true; |
| 6034 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiFlushDwCmd(&cmdBuffer, &flushDwParams)); |
| 6035 |
|
| 6036 |
MHW_MI_STORE_DATA_PARAMS storeDataParams; |
| 6037 |
MOS_ZeroMemory(&storeDataParams, sizeof(storeDataParams)); |
| 6038 |
storeDataParams.pOsResource = &m_resHucPakMmioBuffer; |
| 6039 |
storeDataParams.dwResourceOffset = sizeof(uint32_t); |
| 6040 |
storeDataParams.dwValue = 1 << 31; |
| 6041 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreDataImmCmd(&cmdBuffer, &storeDataParams)); |
| 6042 |
|
| 6043 |
MHW_MI_STORE_REGISTER_MEM_PARAMS storeRegParams; |
| 6044 |
MOS_ZeroMemory(&storeRegParams, sizeof(storeRegParams)); |
| 6045 |
storeRegParams.presStoreBuffer = &m_resHucPakMmioBuffer; |
| 6046 |
storeRegParams.dwOffset = 0; |
| 6047 |
storeRegParams.dwRegister = m_hucInterface->GetMmioRegisters(MHW_VDBOX_NODE_1)->hucStatusRegOffset; |
| 6048 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreRegisterMemCmd(&cmdBuffer, &storeRegParams)); |
| 6049 |
|
| 6050 |
auto mmioRegisters = m_hucInterface->GetMmioRegisters(MHW_VDBOX_NODE_1); |
| 6051 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(StoreHucErrorStatus(mmioRegisters, &cmdBuffer, false)); |
| 6052 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InsertConditionalBBEndWithHucErrorStatus(&cmdBuffer)); |
| 6053 |
|
| 6054 |
// Ending collect of HuC BRC Update kernel performance data |
| 6055 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_perfProfiler->AddPerfCollectEndCmd((void *)this, m_osInterface, m_miInterface, &cmdBuffer)); |
| 6056 |
|
| 6057 |
if (!m_singleTaskPhaseSupported && (m_osInterface->bNoParsingAssistanceInKmd) && !m_scalableMode) |
| 6058 |
{ |
| 6059 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd(&cmdBuffer, nullptr)); |
| 6060 |
} |
| 6061 |
|
| 6062 |
ReturnCommandBuffer(&cmdBuffer); |
| 6063 |
|
| 6064 |
if (!m_singleTaskPhaseSupported) |
| 6065 |
{ |
| 6066 |
bool renderingFlags = m_videoContextUsesNullHw; |
| 6067 |
|
| 6068 |
// Dump history input before HuC runs |
| 6069 |
CODECHAL_DEBUG_TOOL( |
| 6070 |
m_debugInterface->DumpHucRegion( |
| 6071 |
virtualAddrParams.regionParams[0].presRegion, |
| 6072 |
0, |
| 6073 |
hucRegionSize[0], |
| 6074 |
0, |
| 6075 |
hucRegionName[0], |
| 6076 |
true, |
| 6077 |
currPass, |
| 6078 |
CodechalHucRegionDumpType::hucRegionDumpUpdate); |
| 6079 |
); |
| 6080 |
|
| 6081 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SubmitCommandBuffer(&cmdBuffer, renderingFlags)); |
| 6082 |
|
| 6083 |
CODECHAL_DEBUG_TOOL( |
| 6084 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpHucDmem( |
| 6085 |
&m_resVdencBrcUpdateDmemBuffer[currPass][m_currRecycledBufIdx], |
| 6086 |
sizeof(HucBrcUpdateDmem), // Change buffer and size to update dmem |
| 6087 |
currPass, |
| 6088 |
CodechalHucRegionDumpType::hucRegionDumpUpdate)); |
| 6089 |
|
| 6090 |
for (auto i = 0; i < 16; i++) |
| 6091 |
{ |
| 6092 |
if (virtualAddrParams.regionParams[i].presRegion) |
| 6093 |
{ |
| 6094 |
m_debugInterface->DumpHucRegion( |
| 6095 |
virtualAddrParams.regionParams[i].presRegion, |
| 6096 |
virtualAddrParams.regionParams[i].dwOffset, |
| 6097 |
hucRegionSize[i], |
| 6098 |
i, |
| 6099 |
hucRegionName[i], |
| 6100 |
!virtualAddrParams.regionParams[i].isWritable, |
| 6101 |
currPass, |
| 6102 |
CodechalHucRegionDumpType::hucRegionDumpUpdate); |
| 6103 |
} |
| 6104 |
} |
| 6105 |
) |
| 6106 |
} |
| 6107 |
|
| 6108 |
// We increment by the average frame value once for each frame |
| 6109 |
if (IsFirstPass()) |
| 6110 |
{ |
| 6111 |
m_curTargetFullness += m_inputBitsPerFrame; |
| 6112 |
} |
| 6113 |
|
| 6114 |
return eStatus; |
| 6115 |
} |
| 6116 |
|
| 6117 |
MOS_STATUS CodechalVdencVp9StateG12::InitMmcState() |
| 6118 |
{ |
| 6119 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 6120 |
|
| 6121 |
m_mmcState = MOS_New(CodechalMmcEncodeVp9G12, m_hwInterface, &m_reconSurface, &m_rawSurface); |
| 6122 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState); |
| 6123 |
|
| 6124 |
return MOS_STATUS_SUCCESS; |
| 6125 |
} |
| 6126 |
|
| 6127 |
MOS_STATUS CodechalVdencVp9StateG12::AddCommandsVp9(uint32_t commandType, PMOS_COMMAND_BUFFER cmdBuffer ) |
| 6128 |
{ |
| 6129 |
auto qp = m_vp9PicParams->LumaACQIndex; |
| 6130 |
auto vp9FrameType = m_vp9PicParams->PicFlags.fields.frame_type; |
| 6131 |
double QPScale = (vp9FrameType == CODEC_VP9_KEY_FRAME) ? 0.31 : 0.33; |
| 6132 |
double lambda = QPScale * CODECHAL_VP9_QUANT_AC[qp] / 8; |
| 6133 |
|
| 6134 |
auto sadQpLambda = lambda * 4 + 0.5; |
| 6135 |
auto rdQpLambda = lambda * lambda *4 + 0.5; |
| 6136 |
|
| 6137 |
if (commandType == CODECHAL_CMD1) |
| 6138 |
{ |
| 6139 |
MHW_VDBOX_VDENC_CMD1_PARAMS cmd1Params; |
| 6140 |
MOS_ZeroMemory(&cmd1Params, sizeof(cmd1Params)); |
| 6141 |
cmd1Params.Mode = CODECHAL_ENCODE_MODE_VP9; |
| 6142 |
cmd1Params.usSADQPLambda = (uint16_t)sadQpLambda; |
| 6143 |
cmd1Params.usRDQPLambda = (uint16_t)rdQpLambda; |
| 6144 |
cmd1Params.pVp9EncPicParams = m_vp9PicParams; |
| 6145 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdencCmd1Cmd(cmdBuffer, nullptr, &cmd1Params)); |
| 6146 |
|
| 6147 |
} |
| 6148 |
else if (commandType == CODECHAL_CMD2) |
| 6149 |
{ |
| 6150 |
PMHW_VDBOX_VDENC_CMD2_STATE cmd2Params(new MHW_VDBOX_VDENC_CMD2_STATE); |
| 6151 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmd2Params); |
| 6152 |
|
| 6153 |
MHW_VDBOX_VP9_SEGMENT_STATE segmentState; |
| 6154 |
MOS_ZeroMemory(&segmentState, sizeof(segmentState)); |
| 6155 |
segmentState.Mode = m_mode; |
| 6156 |
segmentState.pVp9EncodeSegmentParams = m_vp9SegmentParams; |
| 6157 |
cmd2Params->Mode = m_mode; |
| 6158 |
cmd2Params->pVp9EncPicParams = m_vp9PicParams; |
| 6159 |
cmd2Params->pVp9EncSeqParams = m_vp9SeqParams; |
| 6160 |
cmd2Params->bSegmentationEnabled = m_vp9PicParams->PicFlags.fields.segmentation_enabled; |
| 6161 |
cmd2Params->pVp9SegmentState = &segmentState; |
| 6162 |
cmd2Params->bPrevFrameSegEnabled = m_prevFrameSegEnabled; |
| 6163 |
cmd2Params->bStreamInEnabled = m_segmentMapProvided || m_16xMeEnabled; |
| 6164 |
cmd2Params->ucNumRefIdxL0ActiveMinus1 = (m_vp9PicParams->PicFlags.fields.frame_type) ? m_numRefFrames - 1 : 0; |
| 6165 |
cmd2Params->usSADQPLambda = (uint16_t)sadQpLambda; |
| 6166 |
cmd2Params->usRDQPLambda = (uint16_t)rdQpLambda; |
| 6167 |
cmd2Params->bPakOnlyMultipassEnable = m_vdencPakonlyMultipassEnabled; |
| 6168 |
cmd2Params->bDynamicScalingEnabled = ((m_dysRefFrameFlags != DYS_REF_NONE) && !m_dysVdencMultiPassEnabled); |
| 6169 |
cmd2Params->temporalMVpEnable = m_vp9PicParams->PicFlags.fields.frame_type && !m_prevFrameInfo.KeyFrame; |
| 6170 |
if ((m_vp9PicParams->RefFlags.fields.LastRefIdx == m_vp9PicParams->RefFlags.fields.AltRefIdx |
| 6171 |
&& m_vp9PicParams->RefFlags.fields.AltRefIdx == m_vp9PicParams->RefFlags.fields.GoldenRefIdx |
| 6172 |
&& m_vp9PicParams->RefFlags.fields.GoldenRefIdx == m_vp9PicParams->RefFlags.fields.LastRefIdx) |
| 6173 |
|| (m_vp9SeqParams->TargetUsage == TU_QUALITY)) { |
| 6174 |
cmd2Params->temporalMVpEnable = 0; |
| 6175 |
} |
| 6176 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdencCmd2Cmd(cmdBuffer, nullptr, cmd2Params)); |
| 6177 |
} |
| 6178 |
|
| 6179 |
return MOS_STATUS_SUCCESS; |
| 6180 |
} |
| 6181 |
|
| 6182 |
MOS_STATUS CodechalVdencVp9StateG12::ConfigStitchDataBuffer() |
| 6183 |
{ |
| 6184 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 6185 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 6186 |
int32_t currentPass = GetCurrentPass(); |
| 6187 |
|
| 6188 |
MOS_LOCK_PARAMS lockFlagsWriteOnly; |
| 6189 |
MOS_ZeroMemory(&lockFlagsWriteOnly, sizeof(MOS_LOCK_PARAMS)); |
| 6190 |
lockFlagsWriteOnly.WriteOnly = 1; |
| 6191 |
|
| 6192 |
HucCommandData *hucStitchDataBuf = (HucCommandData *)m_osInterface->pfnLockResource(m_osInterface, &m_resHucStitchDataBuffer[m_currRecycledBufIdx][currentPass], &lockFlagsWriteOnly); |
| 6193 |
CODECHAL_ENCODE_CHK_NULL_RETURN(hucStitchDataBuf); |
| 6194 |
|
| 6195 |
MOS_ZeroMemory(hucStitchDataBuf, sizeof(HucCommandData)); |
| 6196 |
hucStitchDataBuf->TotalCommands = 1; |
| 6197 |
hucStitchDataBuf->InputCOM[0].SizeOfData = 0xF; |
| 6198 |
|
| 6199 |
HucInputCmdG12 hucInputCmd; |
| 6200 |
MOS_ZeroMemory(&hucInputCmd, sizeof(HucInputCmdG12)); |
| 6201 |
|
| 6202 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_osInterface->osCpInterface); |
| 6203 |
hucInputCmd.SelectionForIndData = m_osInterface->osCpInterface->IsCpEnabled() ? 4 : 0; |
| 6204 |
hucInputCmd.CmdMode = HUC_CMD_LIST_MODE; |
| 6205 |
hucInputCmd.LengthOfTable = (uint8_t)GetNumTilesInFrame(); |
| 6206 |
hucInputCmd.CopySize = m_hwInterface->m_tileRecordSize; |
| 6207 |
|
| 6208 |
PMOS_RESOURCE presSrc = &m_tileRecordBuffer[m_virtualEngineBBIndex].sResource; |
| 6209 |
|
| 6210 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource( |
| 6211 |
m_osInterface, |
| 6212 |
presSrc, |
| 6213 |
false, |
| 6214 |
false)); |
| 6215 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource( |
| 6216 |
m_osInterface, |
| 6217 |
&m_resBitstreamBuffer, |
| 6218 |
true, |
| 6219 |
true)); |
| 6220 |
|
| 6221 |
uint64_t srcAddr = m_osInterface->pfnGetResourceGfxAddress(m_osInterface, presSrc); |
| 6222 |
uint64_t destAddr = m_osInterface->pfnGetResourceGfxAddress(m_osInterface, &m_resBitstreamBuffer); |
| 6223 |
hucInputCmd.SrcAddrBottom = (uint32_t)(srcAddr & 0x00000000FFFFFFFF); |
| 6224 |
hucInputCmd.SrcAddrTop = (uint32_t)((srcAddr & 0xFFFFFFFF00000000) >> 32); |
| 6225 |
|
| 6226 |
hucInputCmd.DestAddrBottom = (uint32_t)(destAddr & 0x00000000FFFFFFFF); |
| 6227 |
hucInputCmd.DestAddrTop = (uint32_t)((destAddr & 0xFFFFFFFF00000000) >> 32); |
| 6228 |
|
| 6229 |
MOS_SecureMemcpy(hucStitchDataBuf->InputCOM[0].data, sizeof(HucInputCmdG12), &hucInputCmd, sizeof(HucInputCmdG12)); |
| 6230 |
|
| 6231 |
m_osInterface->pfnUnlockResource(m_osInterface, &m_resHucStitchDataBuffer[m_currRecycledBufIdx][currentPass]); |
| 6232 |
|
| 6233 |
return eStatus; |
| 6234 |
} |
| 6235 |
|
| 6236 |
MOS_STATUS CodechalVdencVp9StateG12::SetDmemHuCVp9Prob() |
| 6237 |
{ |
| 6238 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 6239 |
|
| 6240 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 6241 |
|
| 6242 |
MOS_LOCK_PARAMS lockFlagsWriteOnly; |
| 6243 |
MOS_ZeroMemory(&lockFlagsWriteOnly, sizeof(MOS_LOCK_PARAMS)); |
| 6244 |
lockFlagsWriteOnly.WriteOnly = 1; |
| 6245 |
|
| 6246 |
HucProbDmem *dmem = nullptr; |
| 6247 |
HucProbDmem *dmemTemp = nullptr; |
| 6248 |
int currPass = GetCurrentPass(); |
| 6249 |
if (IsFirstPass()) |
| 6250 |
{ |
| 6251 |
for (auto i = 0; i < 3; i++) |
| 6252 |
{ |
| 6253 |
dmem = (HucProbDmem *)m_osInterface->pfnLockResource( |
| 6254 |
m_osInterface, &m_resHucProbDmemBuffer[i][m_currRecycledBufIdx], &lockFlagsWriteOnly); |
| 6255 |
CODECHAL_ENCODE_CHK_NULL_RETURN(dmem); |
| 6256 |
|
| 6257 |
if (i == 0) |
| 6258 |
{ |
| 6259 |
dmemTemp = dmem; |
| 6260 |
} |
| 6261 |
|
| 6262 |
MOS_SecureMemcpy(dmem, sizeof(HucProbDmem), m_probDmem, sizeof(HucProbDmem)); |
| 6263 |
|
| 6264 |
if (i != 0) |
| 6265 |
{ |
| 6266 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnUnlockResource(m_osInterface, &m_resHucProbDmemBuffer[i][m_currRecycledBufIdx])); |
| 6267 |
dmem = dmemTemp; |
| 6268 |
} |
| 6269 |
} |
| 6270 |
} |
| 6271 |
else |
| 6272 |
{ |
| 6273 |
dmem = (HucProbDmem *)m_osInterface->pfnLockResource( |
| 6274 |
m_osInterface, &m_resHucProbDmemBuffer[currPass][m_currRecycledBufIdx], &lockFlagsWriteOnly); |
| 6275 |
CODECHAL_ENCODE_CHK_NULL_RETURN(dmem); |
| 6276 |
} |
| 6277 |
|
| 6278 |
// for BRC cases, HuC needs to be called on Pass 1 |
| 6279 |
if (m_superFrameHucPass) |
| 6280 |
{ |
| 6281 |
dmem->HuCPassNum = CODECHAL_ENCODE_VP9_HUC_SUPERFRAME_PASS; |
| 6282 |
} |
| 6283 |
else |
| 6284 |
{ |
| 6285 |
if (m_dysBrc) |
| 6286 |
{ |
| 6287 |
//For BRC+Dynamic Scaling, we need to run as HUC pass 1 in the last pass since the curr_pass was changed to 0. |
| 6288 |
dmem->HuCPassNum = currPass != 0; |
| 6289 |
} |
| 6290 |
else |
| 6291 |
{ |
| 6292 |
//For Non-dynamic scaling BRC cases, HuC needs to run as HuC pass one only in last pass. |
| 6293 |
dmem->HuCPassNum = ((m_vdencBrcEnabled && currPass == 1) ? 0 : (currPass != 0)); |
| 6294 |
} |
| 6295 |
} |
| 6296 |
|
| 6297 |
dmem->FrameWidth = m_oriFrameWidth; |
| 6298 |
dmem->FrameHeight = m_oriFrameHeight; |
| 6299 |
|
| 6300 |
for (auto i = 0; i < CODEC_VP9_MAX_SEGMENTS; i++) |
| 6301 |
{ |
| 6302 |
dmem->SegmentRef[i] = (m_vp9SegmentParams->SegData[i].SegmentFlags.fields.SegmentReferenceEnabled == true) ? m_vp9SegmentParams->SegData[i].SegmentFlags.fields.SegmentReference : CODECHAL_ENCODE_VP9_REF_SEGMENT_DISABLED; |
| 6303 |
dmem->SegmentSkip[i] = m_vp9SegmentParams->SegData[i].SegmentFlags.fields.SegmentSkipped; |
| 6304 |
} |
| 6305 |
|
| 6306 |
if (m_vp9PicParams->PicFlags.fields.frame_type == CODEC_VP9_KEY_FRAME && m_currPass == 0) |
| 6307 |
{ |
| 6308 |
for (auto i = 1; i < CODEC_VP9_NUM_CONTEXTS; i++) |
| 6309 |
{ |
| 6310 |
uint8_t *data = (uint8_t *)m_osInterface->pfnLockResource( |
| 6311 |
m_osInterface, |
| 6312 |
&m_resProbBuffer[i], |
| 6313 |
&lockFlagsWriteOnly); |
| 6314 |
|
| 6315 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 6316 |
|
| 6317 |
ContextBufferInit(data, 0); |
| 6318 |
CtxBufDiffInit(data, 0); |
| 6319 |
|
| 6320 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnUnlockResource( |
| 6321 |
m_osInterface, |
| 6322 |
&m_resProbBuffer[i])); |
| 6323 |
} |
| 6324 |
} |
| 6325 |
|
| 6326 |
// in multipasses, only delta seg qp (SegCodeAbs = 0) is supported, confirmed by the arch team |
| 6327 |
dmem->SegCodeAbs = 0; |
| 6328 |
dmem->SegTemporalUpdate = m_vp9PicParams->PicFlags.fields.segmentation_temporal_update; |
| 6329 |
dmem->LastRefIndex = m_vp9PicParams->RefFlags.fields.LastRefIdx; |
| 6330 |
dmem->GoldenRefIndex = m_vp9PicParams->RefFlags.fields.GoldenRefIdx; |
| 6331 |
dmem->AltRefIndex = m_vp9PicParams->RefFlags.fields.AltRefIdx; |
| 6332 |
dmem->RefreshFrameFlags = m_vp9PicParams->RefFlags.fields.refresh_frame_flags; |
| 6333 |
dmem->RefFrameFlags = m_refFrameFlags; |
| 6334 |
dmem->ContextFrameTypes = m_contextFrameTypes[m_vp9PicParams->PicFlags.fields.frame_context_idx]; |
| 6335 |
dmem->FrameToShow = GetReferenceBufferSlotIndex(dmem->RefreshFrameFlags); |
| 6336 |
|
| 6337 |
dmem->FrameCtrl.FrameType = m_vp9PicParams->PicFlags.fields.frame_type; |
| 6338 |
dmem->FrameCtrl.ShowFrame = m_vp9PicParams->PicFlags.fields.show_frame; |
| 6339 |
dmem->FrameCtrl.ErrorResilientMode = m_vp9PicParams->PicFlags.fields.error_resilient_mode; |
| 6340 |
dmem->FrameCtrl.IntraOnly = m_vp9PicParams->PicFlags.fields.intra_only; |
| 6341 |
dmem->FrameCtrl.ContextReset = m_vp9PicParams->PicFlags.fields.reset_frame_context; |
| 6342 |
dmem->FrameCtrl.LastRefFrameBias = m_vp9PicParams->RefFlags.fields.LastRefSignBias; |
| 6343 |
dmem->FrameCtrl.GoldenRefFrameBias = m_vp9PicParams->RefFlags.fields.GoldenRefSignBias; |
| 6344 |
dmem->FrameCtrl.AltRefFrameBias = m_vp9PicParams->RefFlags.fields.AltRefSignBias; |
| 6345 |
dmem->FrameCtrl.AllowHighPrecisionMv = m_vp9PicParams->PicFlags.fields.allow_high_precision_mv; |
| 6346 |
dmem->FrameCtrl.McompFilterMode = m_vp9PicParams->PicFlags.fields.mcomp_filter_type; |
| 6347 |
dmem->FrameCtrl.TxMode = m_txMode; |
| 6348 |
dmem->FrameCtrl.RefreshFrameContext = m_vp9PicParams->PicFlags.fields.refresh_frame_context; |
| 6349 |
dmem->FrameCtrl.FrameParallelDecode = m_vp9PicParams->PicFlags.fields.frame_parallel_decoding_mode; |
| 6350 |
dmem->FrameCtrl.CompPredMode = m_vp9PicParams->PicFlags.fields.comp_prediction_mode; |
| 6351 |
dmem->FrameCtrl.FrameContextIdx = m_vp9PicParams->PicFlags.fields.frame_context_idx; |
| 6352 |
dmem->FrameCtrl.SharpnessLevel = m_vp9PicParams->sharpness_level; |
| 6353 |
dmem->FrameCtrl.SegOn = m_vp9PicParams->PicFlags.fields.segmentation_enabled; |
| 6354 |
dmem->FrameCtrl.SegMapUpdate = m_vp9PicParams->PicFlags.fields.segmentation_update_map; |
| 6355 |
dmem->FrameCtrl.SegUpdateData = m_vp9PicParams->PicFlags.fields.seg_update_data; |
| 6356 |
dmem->StreamInSegEnable = (uint8_t)m_segmentMapProvided; |
| 6357 |
dmem->StreamInEnable = (uint8_t)m_segmentMapProvided; // Currently unused, if used may || with HME enabled |
| 6358 |
|
| 6359 |
dmem->FrameCtrl.log2TileRows = m_vp9PicParams->log2_tile_rows; |
| 6360 |
dmem->FrameCtrl.log2TileCols = m_vp9PicParams->log2_tile_columns; |
| 6361 |
|
| 6362 |
dmem->PrevFrameInfo = m_prevFrameInfo; |
| 6363 |
|
| 6364 |
// For DyS CQP or BRC case, there is no Repak on last pass. So Repak flag is disabled here. |
| 6365 |
// We also disable repak pass in TU7 speed mode usage for performance reasons. |
| 6366 |
dmem->RePak = (m_numPasses > 0 && IsLastPass() && !(m_dysCqp || m_dysBrc) && (m_vp9SeqParams->TargetUsage != TU_PERFORMANCE)); |
| 6367 |
|
| 6368 |
if (dmem->RePak && m_adaptiveRepakSupported) |
| 6369 |
{ |
| 6370 |
MOS_SecureMemcpy(dmem->RePakThreshold, sizeof(uint32_t) * CODEC_VP9_QINDEX_RANGE, m_rePakThreshold, sizeof(uint32_t) * CODEC_VP9_QINDEX_RANGE); |
| 6371 |
} |
| 6372 |
|
| 6373 |
dmem->LFLevelBitOffset = m_vp9PicParams->BitOffsetForLFLevel; |
| 6374 |
dmem->QIndexBitOffset = m_vp9PicParams->BitOffsetForQIndex; |
| 6375 |
dmem->SegBitOffset = m_vp9PicParams->BitOffsetForSegmentation + 1; // exclude segment_enable bit |
| 6376 |
dmem->SegLengthInBits = m_vp9PicParams->BitSizeForSegmentation - 1; // exclude segment_enable bit |
| 6377 |
dmem->UnCompHdrTotalLengthInBits = m_vp9PicParams->BitOffsetForFirstPartitionSize + 16; |
| 6378 |
dmem->PicStateOffset = m_hucPicStateOffset; |
| 6379 |
dmem->SLBBSize = m_hucSlbbSize; |
| 6380 |
dmem->IVFHeaderSize = (m_frameNum == 0) ? 44 : 12; |
| 6381 |
dmem->VDEncImgStateOffset = m_slbbImgStateOffset; |
| 6382 |
dmem->PakOnlyEnable = ((dmem->RePak) && m_vdencPakonlyMultipassEnabled) ? 1 : 0; |
| 6383 |
|
| 6384 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnUnlockResource(m_osInterface, &m_resHucProbDmemBuffer[currPass][m_currRecycledBufIdx])); |
| 6385 |
|
| 6386 |
return eStatus; |
| 6387 |
} |
| 6388 |
|
| 6389 |
MOS_STATUS CodechalVdencVp9StateG12::InsertConditionalBBEndWithHucErrorStatus(PMOS_COMMAND_BUFFER cmdBuffer) |
| 6390 |
{ |
| 6391 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 6392 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 6393 |
|
| 6394 |
MHW_MI_ENHANCED_CONDITIONAL_BATCH_BUFFER_END_PARAMS miEnhancedConditionalBatchBufferEndParams; |
| 6395 |
|
| 6396 |
MOS_ZeroMemory( |
| 6397 |
&miEnhancedConditionalBatchBufferEndParams, |
| 6398 |
sizeof(MHW_MI_ENHANCED_CONDITIONAL_BATCH_BUFFER_END_PARAMS)); |
| 6399 |
|
| 6400 |
miEnhancedConditionalBatchBufferEndParams.presSemaphoreBuffer = &m_resHucErrorStatusBuffer; |
| 6401 |
|
| 6402 |
miEnhancedConditionalBatchBufferEndParams.dwParamsType = MHW_MI_ENHANCED_CONDITIONAL_BATCH_BUFFER_END_PARAMS::ENHANCED_PARAMS; |
| 6403 |
miEnhancedConditionalBatchBufferEndParams.enableEndCurrentBatchBuffLevel = false; |
| 6404 |
miEnhancedConditionalBatchBufferEndParams.compareOperation = MAD_EQUAL_IDD; |
| 6405 |
miEnhancedConditionalBatchBufferEndParams.bDisableCompareMask = false; |
| 6406 |
|
| 6407 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiConditionalBatchBufferEndCmd( |
| 6408 |
cmdBuffer, |
| 6409 |
(PMHW_MI_CONDITIONAL_BATCH_BUFFER_END_PARAMS)(&miEnhancedConditionalBatchBufferEndParams))); |
| 6410 |
|
| 6411 |
return eStatus; |
| 6412 |
} |