| 1 |
/* |
| 2 |
* Copyright (c) 2021, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
//! |
| 24 |
//! \file media_scalability_singlepipe_next.cpp |
| 25 |
//! \brief Defines the common interface for media scalability singlepipe mode. |
| 26 |
//! \details The media scalability singlepipe interface is further sub-divided by component, |
| 27 |
//! this file is for the base interface which is shared by all components. |
| 28 |
//! |
| 29 |
|
| 30 |
#include <stddef.h> |
| 31 |
#include <memory> |
| 32 |
#include "media_scalability_option.h" |
| 33 |
#include "mos_os_virtualengine_next.h" |
| 34 |
#include "mos_interface.h" |
| 35 |
#include "mos_os_virtualengine_specific.h" |
| 36 |
#include "mos_utilities.h" |
| 37 |
#include <typeinfo> |
| 38 |
#include "mos_os.h" |
| 39 |
#include "media_scalability_defs.h" |
| 40 |
#include "media_scalability_singlepipe_next.h" |
| 41 |
#include "mhw_mi_itf.h" |
| 42 |
class MediaContext; |
| 43 |
|
| 44 |
MediaScalabilitySinglePipeNext::MediaScalabilitySinglePipeNext(void *hwInterface, MediaContext *mediaContext, uint8_t componentType) : |
| 45 |
MediaScalability(mediaContext) |
| 46 |
{ |
| 47 |
m_componentType = componentType; |
| 48 |
} |
| 49 |
|
| 50 |
MOS_STATUS MediaScalabilitySinglePipeNext::Initialize(const MediaScalabilityOption &option) |
| 51 |
{ |
| 52 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 53 |
#if !EMUL |
| 54 |
if (MOS_VE_SUPPORTED(m_osInterface)) |
| 55 |
{ |
| 56 |
MOS_VIRTUALENGINE_INIT_PARAMS veInitParms; |
| 57 |
MOS_ZeroMemory(&veInitParms, sizeof(veInitParms)); |
| 58 |
veInitParms.bScalabilitySupported = false; |
| 59 |
MOS_STATUS status = m_osInterface->pfnVirtualEngineInit(m_osInterface, &m_veHitParams, veInitParms); |
| 60 |
SCALABILITY_CHK_STATUS_MESSAGE_RETURN(status, "Virtual Engine Init failed"); |
| 61 |
m_veInterface = m_osInterface->pVEInterf; |
| 62 |
if (m_osInterface->osStreamState && m_osInterface->osStreamState->virtualEngineInterface) |
| 63 |
{ |
| 64 |
// we set m_veState here when pOsInterface->apoMosEnabled is true |
| 65 |
m_veState = m_osInterface->osStreamState->virtualEngineInterface; |
| 66 |
} |
| 67 |
} |
| 68 |
#endif |
| 69 |
|
| 70 |
PMOS_GPUCTX_CREATOPTIONS_ENHANCED gpuCtxCreateOption = MOS_New(MOS_GPUCTX_CREATOPTIONS_ENHANCED); |
| 71 |
SCALABILITY_CHK_NULL_RETURN(gpuCtxCreateOption); |
| 72 |
|
| 73 |
gpuCtxCreateOption->RAMode = option.GetRAMode(); |
| 74 |
gpuCtxCreateOption->ProtectMode = option.GetProtectMode(); |
| 75 |
gpuCtxCreateOption->LRCACount = 1; |
| 76 |
// This setting is only for encode, please override it in decode/vpp |
| 77 |
gpuCtxCreateOption->UsingSFC = false; |
| 78 |
#if (_DEBUG || _RELEASE_INTERNAL) && !EMUL |
| 79 |
if (m_osInterface->bEnableDbgOvrdInVE) |
| 80 |
{ |
| 81 |
gpuCtxCreateOption->DebugOverride = true; |
| 82 |
uint8_t engineLogicId = 0; |
| 83 |
if (m_osInterface->pfnGetEngineLogicId(m_osInterface, engineLogicId) == MOS_STATUS_SUCCESS) |
| 84 |
{ |
| 85 |
gpuCtxCreateOption->EngineInstance[0] = engineLogicId; |
| 86 |
} |
| 87 |
} |
| 88 |
#endif |
| 89 |
m_gpuCtxCreateOption = (PMOS_GPUCTX_CREATOPTIONS)gpuCtxCreateOption; |
| 90 |
|
| 91 |
return MOS_STATUS_SUCCESS; |
| 92 |
} |
| 93 |
|
| 94 |
MOS_STATUS MediaScalabilitySinglePipeNext::Destroy() |
| 95 |
{ |
| 96 |
SCALABILITY_FUNCTION_ENTER; |
| 97 |
|
| 98 |
SCALABILITY_CHK_STATUS_RETURN(MediaScalability::Destroy()); |
| 99 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 100 |
|
| 101 |
if (m_gpuCtxCreateOption != nullptr) |
| 102 |
{ |
| 103 |
MOS_Delete(m_gpuCtxCreateOption); |
| 104 |
} |
| 105 |
|
| 106 |
if (m_scalabilityOption != nullptr) |
| 107 |
{ |
| 108 |
MOS_Delete(m_scalabilityOption); |
| 109 |
} |
| 110 |
#if !EMUL |
| 111 |
m_osInterface->pfnDestroyVeInterface(&m_veInterface); |
| 112 |
#endif |
| 113 |
return MOS_STATUS_SUCCESS; |
| 114 |
} |
| 115 |
|
| 116 |
MOS_STATUS MediaScalabilitySinglePipeNext::GetGpuCtxCreationOption(MOS_GPUCTX_CREATOPTIONS *gpuCtxCreateOption) |
| 117 |
{ |
| 118 |
SCALABILITY_FUNCTION_ENTER; |
| 119 |
SCALABILITY_CHK_NULL_RETURN(gpuCtxCreateOption); |
| 120 |
SCALABILITY_CHK_NULL_RETURN(m_gpuCtxCreateOption); |
| 121 |
|
| 122 |
size_t size = sizeof(MOS_GPUCTX_CREATOPTIONS); |
| 123 |
|
| 124 |
if (typeid(*gpuCtxCreateOption) == typeid(MOS_GPUCTX_CREATOPTIONS_ENHANCED)) |
| 125 |
{ |
| 126 |
size = sizeof(MOS_GPUCTX_CREATOPTIONS_ENHANCED); |
| 127 |
} |
| 128 |
|
| 129 |
SCALABILITY_CHK_STATUS_MESSAGE_RETURN(MOS_SecureMemcpy( |
| 130 |
(void *)gpuCtxCreateOption, |
| 131 |
size, |
| 132 |
(void *)m_gpuCtxCreateOption, |
| 133 |
size), |
| 134 |
"Failed to copy gpu ctx create option"); |
| 135 |
|
| 136 |
return MOS_STATUS_SUCCESS; |
| 137 |
} |
| 138 |
|
| 139 |
MOS_STATUS MediaScalabilitySinglePipeNext::VerifyCmdBuffer(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak) |
| 140 |
{ |
| 141 |
// legacy mode & resize CommandBuffer Size for every BRC pass |
| 142 |
return VerifySpaceAvailable(requestedSize, requestedPatchListSize, singleTaskPhaseSupportedInPak); |
| 143 |
} |
| 144 |
|
| 145 |
MOS_STATUS MediaScalabilitySinglePipeNext::GetCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer, bool frameTrackingRequested) |
| 146 |
{ |
| 147 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 148 |
SCALABILITY_CHK_NULL_RETURN(cmdBuffer); |
| 149 |
SCALABILITY_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, cmdBuffer, 0)); |
| 150 |
|
| 151 |
if (!m_attrReady) |
| 152 |
{ |
| 153 |
SCALABILITY_CHK_STATUS_RETURN(SendAttrWithFrameTracking(*cmdBuffer, frameTrackingRequested)); |
| 154 |
m_attrReady = true; |
| 155 |
} |
| 156 |
|
| 157 |
return MOS_STATUS_SUCCESS; |
| 158 |
} |
| 159 |
|
| 160 |
MOS_STATUS MediaScalabilitySinglePipeNext::ReturnCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer) |
| 161 |
{ |
| 162 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 163 |
SCALABILITY_CHK_NULL_RETURN(cmdBuffer); |
| 164 |
|
| 165 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, cmdBuffer, 0); |
| 166 |
|
| 167 |
return MOS_STATUS_SUCCESS; |
| 168 |
} |
| 169 |
|
| 170 |
MOS_STATUS MediaScalabilitySinglePipeNext::SetHintParams() |
| 171 |
{ |
| 172 |
SCALABILITY_FUNCTION_ENTER; |
| 173 |
|
| 174 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 175 |
|
| 176 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 177 |
MOS_VIRTUALENGINE_SET_PARAMS veParams; |
| 178 |
MOS_ZeroMemory(&veParams, sizeof(veParams)); |
| 179 |
|
| 180 |
veParams.ucScalablePipeNum = 1; |
| 181 |
veParams.bScalableMode = false; |
| 182 |
|
| 183 |
if (!MOS_VE_CTXBASEDSCHEDULING_SUPPORTED(m_osInterface)) |
| 184 |
{ |
| 185 |
//not used by VE2.0 |
| 186 |
veParams.bNeedSyncWithPrevious = true; |
| 187 |
veParams.bSameEngineAsLastSubmission = false; |
| 188 |
veParams.bSFCInUse = false; |
| 189 |
} |
| 190 |
m_osInterface->pVEInterf = m_veInterface; |
| 191 |
#if !EMUL |
| 192 |
eStatus = m_osInterface->pfnSetHintParams(m_osInterface, &veParams); |
| 193 |
#endif |
| 194 |
SCALABILITY_CHK_STATUS_MESSAGE_RETURN(eStatus, "SetHintParams failed"); |
| 195 |
|
| 196 |
return eStatus; |
| 197 |
} |
| 198 |
|
| 199 |
MOS_STATUS MediaScalabilitySinglePipeNext::PopulateHintParams(PMOS_COMMAND_BUFFER cmdBuffer) |
| 200 |
{ |
| 201 |
SCALABILITY_FUNCTION_ENTER; |
| 202 |
SCALABILITY_CHK_NULL_RETURN(cmdBuffer); |
| 203 |
SCALABILITY_CHK_NULL_RETURN(m_veHitParams); |
| 204 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 205 |
|
| 206 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 207 |
PMOS_CMD_BUF_ATTRI_VE attriVe = m_osInterface->pfnGetAttributeVeBuffer(cmdBuffer); |
| 208 |
if (attriVe) |
| 209 |
{ |
| 210 |
attriVe->VEngineHintParams = *(m_veHitParams); |
| 211 |
attriVe->bUseVirtualEngineHint = true; |
| 212 |
} |
| 213 |
return eStatus; |
| 214 |
} |
| 215 |
|
| 216 |
MOS_STATUS MediaScalabilitySinglePipeNext::SubmitCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer) |
| 217 |
{ |
| 218 |
SCALABILITY_FUNCTION_ENTER; |
| 219 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 220 |
SCALABILITY_CHK_NULL_RETURN(cmdBuffer); |
| 221 |
|
| 222 |
SCALABILITY_CHK_STATUS_RETURN(GetCmdBuffer(cmdBuffer)); |
| 223 |
|
| 224 |
if (!m_osInterface->pfnIsMismatchOrderProgrammingSupported()) |
| 225 |
{ |
| 226 |
SCALABILITY_CHK_STATUS_RETURN(m_miItf->AddMiBatchBufferEnd(cmdBuffer, nullptr)); |
| 227 |
} |
| 228 |
|
| 229 |
SCALABILITY_CHK_STATUS_RETURN(Oca1stLevelBBEnd(*cmdBuffer)); |
| 230 |
|
| 231 |
SCALABILITY_CHK_STATUS_RETURN(ReturnCmdBuffer(cmdBuffer)); |
| 232 |
|
| 233 |
if (MOS_VE_SUPPORTED(m_osInterface)) |
| 234 |
{ |
| 235 |
SCALABILITY_CHK_STATUS_RETURN(SetHintParams()); |
| 236 |
if(cmdBuffer && m_veHitParams) |
| 237 |
{ |
| 238 |
SCALABILITY_CHK_STATUS_RETURN(PopulateHintParams(cmdBuffer)); |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
m_attrReady = false; |
| 243 |
return m_osInterface->pfnSubmitCommandBuffer(m_osInterface, cmdBuffer, false); |
| 244 |
} |