| 1 |
/* |
| 2 |
* Copyright (c) 2007-2017, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file cm_wrapper_os.cpp |
| 24 |
//! \brief Contains implementations of Linux-dependent functions for executing |
| 25 |
//! commands from cmrtlib. |
| 26 |
//! |
| 27 |
|
| 28 |
#include "cm_wrapper.h" |
| 29 |
#include "cm_rt_umd.h" |
| 30 |
#include "cm_device_rt.h" |
| 31 |
#include "cm_surface_2d_rt.h" |
| 32 |
#include "media_libva_util.h" |
| 33 |
#include "cm_extension_creator.h" |
| 34 |
#include "mos_os_specific.h" |
| 35 |
|
| 36 |
using CMRT_UMD::CmDeviceRT; |
| 37 |
//! |
| 38 |
//! \brief Create Cm Device from VA Driver Context. |
| 39 |
//! \details Create a CmCtx and a associated MOS_CONTEXT. Put the CmCtx into |
| 40 |
//! the heap of VA Context. |
| 41 |
//! \param vaDriverCtx |
| 42 |
//! [in] pointer to va drv conetext. |
| 43 |
//! \param device |
| 44 |
//! [in,out] reference to cm device pointer. |
| 45 |
//! \param devOption |
| 46 |
//! [in] cm device creation option. |
| 47 |
//! \return int32_t |
| 48 |
//! CM_SUCCESS if success, else fail reason. |
| 49 |
//! |
| 50 |
int32_t CreateCmDeviceFromVA(VADriverContextP vaDriverCtx, |
| 51 |
CmDevice* &device, |
| 52 |
uint32_t devOption) |
| 53 |
{ |
| 54 |
int32_t hRes = CM_SUCCESS; |
| 55 |
PDDI_MEDIA_CONTEXT mediaCtx; |
| 56 |
PCM_CONTEXT cmCtx; |
| 57 |
uint32_t ctxIndex; |
| 58 |
PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT vaCtxHeapElement; |
| 59 |
VAContextID vaContextID; |
| 60 |
|
| 61 |
mediaCtx = DdiMedia_GetMediaContext(vaDriverCtx); |
| 62 |
|
| 63 |
// allocate cmCtx |
| 64 |
cmCtx = MOS_New(CM_CONTEXT); |
| 65 |
CM_CHK_NULL_RETURN_WITH_MSG(cmCtx, CM_INVALID_UMD_CONTEXT, "Null cmCtx!"); |
| 66 |
cmCtx->cmHal = nullptr; |
| 67 |
// init cmCtx |
| 68 |
cmCtx->mosCtx.bufmgr = mediaCtx->pDrmBufMgr; |
| 69 |
cmCtx->mosCtx.m_gpuContextMgr = mediaCtx->m_gpuContextMgr; |
| 70 |
cmCtx->mosCtx.m_cmdBufMgr = mediaCtx->m_cmdBufMgr; |
| 71 |
cmCtx->mosCtx.fd = mediaCtx->fd; |
| 72 |
cmCtx->mosCtx.wRevision = 0; |
| 73 |
cmCtx->mosCtx.iDeviceId = mediaCtx->iDeviceId; |
| 74 |
cmCtx->mosCtx.m_skuTable = mediaCtx->SkuTable; |
| 75 |
cmCtx->mosCtx.m_waTable = mediaCtx->WaTable; |
| 76 |
cmCtx->mosCtx.m_gtSystemInfo = *(mediaCtx->pGtSystemInfo); |
| 77 |
cmCtx->mosCtx.m_platform = mediaCtx->platform; |
| 78 |
cmCtx->mosCtx.pGmmClientContext = mediaCtx->pGmmClientContext; |
| 79 |
cmCtx->mosCtx.m_osDeviceContext = mediaCtx->m_osDeviceContext; |
| 80 |
cmCtx->mosCtx.m_apoMosEnabled = mediaCtx->m_apoMosEnabled; |
| 81 |
cmCtx->mosCtx.m_auxTableMgr = mediaCtx->m_auxTableMgr; |
| 82 |
cmCtx->mosCtx.pPerfData = (PERF_DATA *)MOS_AllocAndZeroMemory(sizeof(PERF_DATA)); |
| 83 |
cmCtx->mosCtx.m_userSettingPtr = mediaCtx->m_userSettingPtr; |
| 84 |
|
| 85 |
if (cmCtx->mosCtx.pPerfData == nullptr) |
| 86 |
{ |
| 87 |
MOS_Delete(cmCtx); // free cm ctx |
| 88 |
CM_ASSERTMESSAGE("Failed to allocate perfData in mos context \n"); |
| 89 |
return CM_OUT_OF_HOST_MEMORY; |
| 90 |
} |
| 91 |
|
| 92 |
// Create Cm Device |
| 93 |
hRes = CreateCmDevice(&(cmCtx->mosCtx), device, devOption); |
| 94 |
if(hRes != CM_SUCCESS) |
| 95 |
{ |
| 96 |
MOS_Delete(cmCtx); // free cm ctx |
| 97 |
CM_ASSERTMESSAGE("Failed to call CmDevice::Create Error %d \n",hRes); |
| 98 |
return hRes; |
| 99 |
} |
| 100 |
CmDeviceRT* deviceRT = static_cast<CmDeviceRT*>(device); |
| 101 |
DdiMediaUtil_LockMutex(&mediaCtx->CmMutex); |
| 102 |
|
| 103 |
// get Free Cm context index |
| 104 |
vaCtxHeapElement = DdiMediaUtil_AllocPVAContextFromHeap(mediaCtx->pCmCtxHeap); |
| 105 |
if (nullptr == vaCtxHeapElement) |
| 106 |
{ |
| 107 |
CmDeviceRT::Destroy(deviceRT); // destroy cm device |
| 108 |
device = nullptr; |
| 109 |
MOS_Delete(cmCtx); // free cm ctx |
| 110 |
DdiMediaUtil_UnLockMutex(&mediaCtx->CmMutex); |
| 111 |
CM_ASSERTMESSAGE("CM Context number exceeds maximum."); |
| 112 |
return VA_STATUS_ERROR_INVALID_CONTEXT; |
| 113 |
} |
| 114 |
|
| 115 |
// store cmCtx in pMedia |
| 116 |
vaCtxHeapElement->pVaContext = (void *)cmCtx; |
| 117 |
vaContextID = (VAContextID)(vaCtxHeapElement->uiVaContextID + DDI_MEDIA_VACONTEXTID_OFFSET_CM); |
| 118 |
|
| 119 |
//Set VaCtx ID to Cm device |
| 120 |
deviceRT->SetVaCtxID(vaContextID); |
| 121 |
|
| 122 |
// increate CM context number |
| 123 |
mediaCtx->uiNumCMs++; |
| 124 |
|
| 125 |
DdiMediaUtil_UnLockMutex(&mediaCtx->CmMutex); |
| 126 |
|
| 127 |
return hRes; |
| 128 |
} |
| 129 |
|
| 130 |
//! |
| 131 |
//! \brief Destroy Cm Device and free heap in VA context. |
| 132 |
//! \param vaDriverCtx |
| 133 |
//! [in] pointer to va drv conetext. |
| 134 |
//! \param device |
| 135 |
//! [in] pointer to cm device to release. |
| 136 |
//! \return int32_t |
| 137 |
//! CM_SUCCESS if success, else fail reason. |
| 138 |
//! |
| 139 |
int32_t DestroyCmDeviceFromVA(VADriverContextP vaDriverCtx, CmDevice *device) |
| 140 |
{ |
| 141 |
int32_t hr = CM_SUCCESS; |
| 142 |
uint32_t index; |
| 143 |
PDDI_MEDIA_CONTEXT mediaCtx; |
| 144 |
PCM_CONTEXT cmCtx; |
| 145 |
VAContextID vaContextID; |
| 146 |
uint32_t ctxType; |
| 147 |
VAStatus vaStatus; |
| 148 |
|
| 149 |
if (nullptr == vaDriverCtx) |
| 150 |
{ |
| 151 |
CM_ASSERTMESSAGE("Pointer to VADriverContext is invalid."); |
| 152 |
return CM_NULL_POINTER; |
| 153 |
} |
| 154 |
CmDeviceRT* deviceRT = static_cast<CmDeviceRT*>(device); |
| 155 |
if (nullptr == deviceRT) |
| 156 |
{ |
| 157 |
return CM_SUCCESS; |
| 158 |
} |
| 159 |
//Get VaCtx ID in MediaCtx |
| 160 |
deviceRT->GetVaCtxID(vaContextID); |
| 161 |
|
| 162 |
// Get Cm context index |
| 163 |
index = vaContextID & DDI_MEDIA_MASK_VACONTEXTID; |
| 164 |
|
| 165 |
//Get Cm Context |
| 166 |
cmCtx = (PCM_CONTEXT)DdiMedia_GetContextFromContextID(vaDriverCtx, vaContextID, &ctxType); |
| 167 |
CM_CHK_NULL_RETURN_WITH_MSG(cmCtx, VA_STATUS_ERROR_INVALID_CONTEXT, "Null cmCtx."); |
| 168 |
|
| 169 |
CM_CHK_CMSTATUS_GOTOFINISH(DestroyCmDevice(device)); |
| 170 |
|
| 171 |
// remove from context array |
| 172 |
mediaCtx = DdiMedia_GetMediaContext(vaDriverCtx); |
| 173 |
DdiMediaUtil_LockMutex(&mediaCtx->CmMutex); |
| 174 |
|
| 175 |
MOS_FreeMemAndSetNull(cmCtx->mosCtx.pPerfData); |
| 176 |
|
| 177 |
// destroy Cm context |
| 178 |
MOS_Delete(cmCtx); |
| 179 |
|
| 180 |
DdiMediaUtil_ReleasePVAContextFromHeap(mediaCtx->pCmCtxHeap, index); |
| 181 |
|
| 182 |
mediaCtx->uiNumCMs--; |
| 183 |
|
| 184 |
DdiMediaUtil_UnLockMutex(&mediaCtx->CmMutex); |
| 185 |
|
| 186 |
finish: |
| 187 |
return hr; |
| 188 |
} |
| 189 |
|
| 190 |
extern MOS_FORMAT VpGetFormatFromMediaFormat(DDI_MEDIA_FORMAT mf); |
| 191 |
//*----------------------------------------------------------------------------- |
| 192 |
//| Purpose: Get resource information from LibVA-created surface and fill into OsResource |
| 193 |
// vaSurfaceID is the index to VA's surface |
| 194 |
//| Returns: Result of the operation. |
| 195 |
//*----------------------------------------------------------------------------- |
| 196 |
int32_t CmFillMosResource( VASurfaceID vaSurfaceID, |
| 197 |
VADriverContext* vaDriverCtx, |
| 198 |
PMOS_RESOURCE osResource) |
| 199 |
{ |
| 200 |
PDDI_MEDIA_CONTEXT mediaCtx; |
| 201 |
DDI_MEDIA_SURFACE *surface; |
| 202 |
CmDevice *device; |
| 203 |
|
| 204 |
CM_CHK_NULL_RETURN_WITH_MSG(vaDriverCtx, CM_INVALID_UMD_CONTEXT, "Null umdCtx"); |
| 205 |
|
| 206 |
mediaCtx = DdiMedia_GetMediaContext(vaDriverCtx); |
| 207 |
CM_CHK_NULL_RETURN_WITH_MSG(mediaCtx, CM_INVALID_UMD_CONTEXT, "Null mediaCtx"); |
| 208 |
|
| 209 |
CM_CHK_NULL_RETURN_WITH_MSG(mediaCtx->pSurfaceHeap, CM_INVALID_UMD_CONTEXT, "Null mediaCtx->pSurfaceHeap"); |
| 210 |
CM_CHK_COND_RETURN(((uint32_t)vaSurfaceID >= mediaCtx->pSurfaceHeap->uiAllocatedHeapElements), CM_INVALID_LIBVA_SURFACE, "Invalid surface"); |
| 211 |
surface = DdiMedia_GetSurfaceFromVASurfaceID(mediaCtx, vaSurfaceID); |
| 212 |
CM_CHK_NULL_RETURN_WITH_MSG(surface, CM_INVALID_LIBVA_SURFACE, "Null surface"); |
| 213 |
CM_ASSERT(surface->iPitch == GFX_ULONG_CAST(surface->pGmmResourceInfo->GetRenderPitch())); |
| 214 |
CM_CHK_NULL_RETURN_WITH_MSG(surface->bo, CM_INVALID_LIBVA_SURFACE, "Null BO"); |
| 215 |
CM_CHK_NULL_RETURN_WITH_MSG(surface->pGmmResourceInfo, CM_INVALID_LIBVA_SURFACE, "Null GMMResInfo"); |
| 216 |
|
| 217 |
// Resets the Resource |
| 218 |
Mos_ResetResource(osResource); |
| 219 |
|
| 220 |
osResource->iWidth = surface->iWidth; |
| 221 |
osResource->iHeight = surface->iHeight; |
| 222 |
osResource->iDepth = 1; |
| 223 |
osResource->iPitch = surface->iPitch; |
| 224 |
|
| 225 |
osResource->iCount = 0; |
| 226 |
osResource->bufname = (char *)"Libva2DSurface"; |
| 227 |
|
| 228 |
osResource->Format = VpGetFormatFromMediaFormat(surface->format); |
| 229 |
osResource->bo = surface->bo; |
| 230 |
|
| 231 |
osResource->TileType = LinuxToMosTileType(surface->TileType); |
| 232 |
osResource->isTiled = surface->isTiled; |
| 233 |
|
| 234 |
osResource->bMapped = surface->bMapped; |
| 235 |
osResource->pData = (uint8_t*) surface->bo->virt; |
| 236 |
|
| 237 |
osResource->pGmmResInfo = surface->pGmmResourceInfo; |
| 238 |
|
| 239 |
// for wrapper to new MOS MODS interface |
| 240 |
osResource->bConvertedFromDDIResource = true; |
| 241 |
|
| 242 |
return CM_SUCCESS; |
| 243 |
} |
| 244 |
|
| 245 |
MOS_FORMAT CmOSFmtToMosFmt(CM_OSAL_SURFACE_FORMAT format) |
| 246 |
{ |
| 247 |
//CM_SURFACE_FORMAT_R8U/R16U are not valid va surface format. |
| 248 |
//These two formats are MDF specific, so we add the mapping here. |
| 249 |
switch(format) |
| 250 |
{ |
| 251 |
case CM_SURFACE_FORMAT_R8U: return Format_R8U; |
| 252 |
case CM_SURFACE_FORMAT_R16U: return Format_R16U; |
| 253 |
default: |
| 254 |
return MosInterface::OsFmtToMosFmt(format); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
CM_OSAL_SURFACE_FORMAT CmMosFmtToOSFmt(MOS_FORMAT format) |
| 259 |
{ |
| 260 |
//CM_SURFACE_FORMAT_R8U/R16U are not valid va surface format. |
| 261 |
//These two formats are MDF specific, so we add the mapping here. |
| 262 |
switch(format) |
| 263 |
{ |
| 264 |
case Format_R8U: return CM_SURFACE_FORMAT_R8U; |
| 265 |
case Format_R16U: return CM_SURFACE_FORMAT_R16U; |
| 266 |
default: |
| 267 |
return (CM_OSAL_SURFACE_FORMAT)MosInterface::MosFmtToOsFmt(format); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
int32_t ConvertToOperatingSystemAbstractionLayerFormat(void *src, uint32_t numOfFormats) |
| 272 |
{ |
| 273 |
uint32_t i = 0 ; |
| 274 |
if (src == nullptr || numOfFormats == 0) |
| 275 |
{ |
| 276 |
CM_ASSERTMESSAGE("Error: Invalid input arguments."); |
| 277 |
return CM_INVALID_ARG_VALUE; |
| 278 |
} |
| 279 |
|
| 280 |
for (i = 0; i < numOfFormats; ++i) |
| 281 |
{ |
| 282 |
*((CM_OSAL_SURFACE_FORMAT*)src + i) = CmMosFmtToOSFmt(*((CM_SURFACE_FORMAT*)src + i)); |
| 283 |
} |
| 284 |
return CM_SUCCESS; |
| 285 |
} |
| 286 |
|
| 287 |
struct CM_CREATESURFACE2DUP_PARAM |
| 288 |
{ |
| 289 |
uint32_t width; // [in] width of 2D texture in pixel |
| 290 |
uint32_t height; // [in] height of 2D texture in pixel |
| 291 |
CM_OSAL_SURFACE_FORMAT format; // [in] 2D texture foramt in OS layer. |
| 292 |
void *sysMem; // [in] Pointer to system memory |
| 293 |
void *surface2DUPHandle; // [out] pointer of CmSurface2D used in driver |
| 294 |
int32_t returnValue; // [out] the return value from driver |
| 295 |
}; |
| 296 |
typedef CM_CREATESURFACE2DUP_PARAM *PCM_CREATESURFACE2DUP_PARAM; |
| 297 |
|
| 298 |
struct CM_GETSURFACE2DINFO_PARAM |
| 299 |
{ |
| 300 |
uint32_t width; // [in] Surface Width |
| 301 |
uint32_t height; // [in] Surface Height |
| 302 |
CM_OSAL_SURFACE_FORMAT format; // [in] Surface Format |
| 303 |
uint32_t pitch; // [out] Pitch |
| 304 |
uint32_t physicalSize; // [out] Physical size |
| 305 |
uint32_t returnValue; // [out] Return value |
| 306 |
}; |
| 307 |
typedef CM_GETSURFACE2DINFO_PARAM *PCM_GETSURFACE2DINFO_PARAM; |
| 308 |
|
| 309 |
struct CM_CREATE_SURFACE3D_PARAM |
| 310 |
{ |
| 311 |
uint32_t width; // [in] width of 3D in pixel |
| 312 |
uint32_t height; // [in] height of 3D in pixel |
| 313 |
uint32_t depth; // [in] depth of 3D surface in pixel |
| 314 |
CM_OSAL_SURFACE_FORMAT format; // [in] 2D texture foramt in OS abstraction layer. |
| 315 |
void *surface3DHandle; // [out] pointer of CmSurface3D used in driver |
| 316 |
int32_t returnValue; // [out] the return value from driver |
| 317 |
}; |
| 318 |
typedef CM_CREATE_SURFACE3D_PARAM *PCM_CREATE_SURFACE3D_PARAM; |
| 319 |
|
| 320 |
using CMRT_UMD::CmSurface2DRT; |
| 321 |
using CMRT_UMD::CmWrapperEx; |
| 322 |
using CMRT_UMD::CmSurface2DUP; |
| 323 |
using CMRT_UMD::CmSurface3D; |
| 324 |
//*----------------------------------------------------------------------------- |
| 325 |
//| Purpose: CMRT thin layer library supported function execution |
| 326 |
//| Return: CM_SUCCESS if successful |
| 327 |
//*----------------------------------------------------------------------------- |
| 328 |
int32_t CmThinExecute(VADriverContextP vaDriverCtx, |
| 329 |
void *deviceHandle, |
| 330 |
uint32_t inputFunctionId, |
| 331 |
void *inputData, |
| 332 |
uint32_t inputDataLen) |
| 333 |
{ |
| 334 |
CmDevice *device = nullptr; |
| 335 |
CmDeviceRT *deviceRT = nullptr; |
| 336 |
VADriverContextP hUMDevice = nullptr; |
| 337 |
void *cmPrivateInputData = nullptr; |
| 338 |
uint32_t cmPrivateInputDataSize = 0 ; |
| 339 |
CMRT_UMD::CmSurface2D *pCmSurface2d = nullptr; |
| 340 |
SurfaceIndex *surfaceIndex = nullptr; |
| 341 |
CM_FUNCTION_ID cmFunctionID; |
| 342 |
int32_t hr = CM_SUCCESS; |
| 343 |
int32_t cmRet = CM_INVALID_PRIVATE_DATA; |
| 344 |
|
| 345 |
hUMDevice = vaDriverCtx; |
| 346 |
cmPrivateInputData = inputData; |
| 347 |
cmPrivateInputDataSize = inputDataLen; |
| 348 |
cmFunctionID = (CM_FUNCTION_ID)inputFunctionId; |
| 349 |
device = (CmDevice *)deviceHandle; |
| 350 |
deviceRT = static_cast<CmDeviceRT*>(device); |
| 351 |
|
| 352 |
switch(cmFunctionID) |
| 353 |
{ |
| 354 |
case CM_FN_CREATECMDEVICE: |
| 355 |
PCM_CREATECMDEVICE_PARAM cmDeviceParam; |
| 356 |
cmDeviceParam = (PCM_CREATECMDEVICE_PARAM)(cmPrivateInputData); |
| 357 |
//Create Cm Device |
| 358 |
cmRet = CreateCmDeviceFromVA(vaDriverCtx, device, cmDeviceParam->devCreateOption); |
| 359 |
if ( cmRet == CM_SUCCESS) |
| 360 |
{ |
| 361 |
CM_CHK_NULL_RETURN_WITH_MSG(device, VA_STATUS_ERROR_INVALID_CONTEXT, "Null device."); |
| 362 |
deviceRT = static_cast<CmDeviceRT*>(device); |
| 363 |
deviceRT->RegisterCallBack(cmDeviceParam->callbackReleaseVaSurf); |
| 364 |
cmDeviceParam->driverStoreEnabled = deviceRT->GetDriverStoreFlag(); |
| 365 |
} |
| 366 |
//Fill the output message |
| 367 |
cmDeviceParam->deviceHandle = device; |
| 368 |
cmDeviceParam->returnValue = cmRet; |
| 369 |
cmDeviceParam->version = CM_VERSION; |
| 370 |
break; |
| 371 |
|
| 372 |
case CM_FN_DESTROYCMDEVICE: |
| 373 |
PCM_DESTROYCMDEVICE_PARAM cmDevDestroyParam; |
| 374 |
cmDevDestroyParam = (PCM_DESTROYCMDEVICE_PARAM)(cmPrivateInputData); |
| 375 |
device = (CmDevice *)(cmDevDestroyParam->deviceHandle); |
| 376 |
cmRet = DestroyCmDeviceFromVA(vaDriverCtx,device); |
| 377 |
//Fill the output message |
| 378 |
cmDevDestroyParam->deviceHandle = nullptr; |
| 379 |
cmDevDestroyParam->returnValue = cmRet; |
| 380 |
break; |
| 381 |
|
| 382 |
case CM_FN_CMDEVICE_CREATESURFACE2D: |
| 383 |
PCM_CREATESURFACE2D_PARAM cmCreate2DParam; |
| 384 |
MOS_RESOURCE mosResource ; |
| 385 |
MOS_ZeroMemory(&mosResource, sizeof(MOS_RESOURCE)); |
| 386 |
cmCreate2DParam = (PCM_CREATESURFACE2D_PARAM)(cmPrivateInputData); |
| 387 |
if ( cmCreate2DParam->isLibvaCreated ) |
| 388 |
{ |
| 389 |
//LibVA-created Surface2D |
| 390 |
cmRet = CmFillMosResource(cmCreate2DParam->vaSurfaceID, |
| 391 |
vaDriverCtx, |
| 392 |
&mosResource); |
| 393 |
|
| 394 |
if( cmRet != CM_SUCCESS) |
| 395 |
{ |
| 396 |
CM_ASSERTMESSAGE("Error: Failed to fill MOS resource."); |
| 397 |
cmCreate2DParam->returnValue = cmRet; |
| 398 |
return cmRet; |
| 399 |
} |
| 400 |
|
| 401 |
cmRet = deviceRT->CreateSurface2D(&mosResource, cmCreate2DParam->isCmCreated, pCmSurface2d); |
| 402 |
if( cmRet != CM_SUCCESS) |
| 403 |
{ |
| 404 |
CM_ASSERTMESSAGE("Error: Failed to create surface 2D from MOS resource."); |
| 405 |
cmCreate2DParam->returnValue = cmRet; |
| 406 |
return cmRet; |
| 407 |
} |
| 408 |
|
| 409 |
CmSurface2DRT *surface2dRT = static_cast<CmSurface2DRT *>(pCmSurface2d); |
| 410 |
surface2dRT->SetVaSurfaceID(cmCreate2DParam->vaSurfaceID, cmCreate2DParam->vaDisplay); |
| 411 |
} |
| 412 |
else |
| 413 |
{ |
| 414 |
// CM Created Surface2D |
| 415 |
cmRet = device->CreateSurface2D( |
| 416 |
cmCreate2DParam->width, |
| 417 |
cmCreate2DParam->height, |
| 418 |
CmOSFmtToMosFmt(cmCreate2DParam->format), |
| 419 |
pCmSurface2d); |
| 420 |
} |
| 421 |
//Create Surface Index |
| 422 |
if( cmRet == CM_SUCCESS) |
| 423 |
{ |
| 424 |
cmCreate2DParam->cmSurface2DHandle = pCmSurface2d; |
| 425 |
} |
| 426 |
|
| 427 |
//Fill output message |
| 428 |
cmCreate2DParam->returnValue = cmRet; |
| 429 |
break; |
| 430 |
|
| 431 |
case CM_FN_CMDEVICE_CREATESURFACE2DUP: |
| 432 |
CM_CREATESURFACE2DUP_PARAM *cmCreate2DUpParam; |
| 433 |
CMRT_UMD::CmSurface2DUP *cmSurface2dup; |
| 434 |
cmCreate2DUpParam = static_cast<CM_CREATESURFACE2DUP_PARAM*>(inputData); |
| 435 |
cmRet = device->CreateSurface2DUP(cmCreate2DUpParam->width, |
| 436 |
cmCreate2DUpParam->height, |
| 437 |
CmOSFmtToMosFmt(cmCreate2DUpParam->format), |
| 438 |
cmCreate2DUpParam->sysMem, cmSurface2dup); |
| 439 |
if( cmRet == CM_SUCCESS) |
| 440 |
{ |
| 441 |
cmCreate2DUpParam->surface2DUPHandle = static_cast<CmSurface2DUP*>(cmSurface2dup); |
| 442 |
} |
| 443 |
cmCreate2DUpParam->returnValue = cmRet; |
| 444 |
break; |
| 445 |
|
| 446 |
case CM_FN_CMDEVICE_CREATESURFACE3D: |
| 447 |
CM_CREATE_SURFACE3D_PARAM *createSurf3dParam; |
| 448 |
createSurf3dParam = static_cast<CM_CREATE_SURFACE3D_PARAM*>(inputData); |
| 449 |
CMRT_UMD::CmSurface3D *cmSurface3d; |
| 450 |
cmRet = device->CreateSurface3D(createSurf3dParam->width, createSurf3dParam->height, |
| 451 |
createSurf3dParam->depth, |
| 452 |
CmOSFmtToMosFmt(createSurf3dParam->format), |
| 453 |
cmSurface3d); |
| 454 |
if(cmRet == CM_SUCCESS) |
| 455 |
{ |
| 456 |
createSurf3dParam->surface3DHandle = static_cast<CmSurface3D*>(cmSurface3d); |
| 457 |
} |
| 458 |
createSurf3dParam->returnValue = cmRet; |
| 459 |
break; |
| 460 |
|
| 461 |
case CM_FN_CMDEVICE_GETSURFACE2DINFO: |
| 462 |
CM_GETSURFACE2DINFO_PARAM *cmGet2DinfoParam; |
| 463 |
cmGet2DinfoParam = static_cast<CM_GETSURFACE2DINFO_PARAM*>(inputData); |
| 464 |
uint32_t pitch, physicalsize; |
| 465 |
cmRet = device->GetSurface2DInfo(cmGet2DinfoParam->width, cmGet2DinfoParam->height, |
| 466 |
CmOSFmtToMosFmt(cmGet2DinfoParam->format), |
| 467 |
pitch, physicalsize); |
| 468 |
cmGet2DinfoParam->pitch = pitch; |
| 469 |
cmGet2DinfoParam->physicalSize = physicalsize; |
| 470 |
cmGet2DinfoParam->returnValue = cmRet; |
| 471 |
break; |
| 472 |
|
| 473 |
default: |
| 474 |
hr = CmThinExecuteInternal(device, cmFunctionID, cmPrivateInputData, cmPrivateInputDataSize); |
| 475 |
if (hr == CM_INVALID_PRIVATE_DATA) |
| 476 |
{ |
| 477 |
CmWrapperEx *wrapperEx = CmExtensionCreator<CmWrapperEx>::CreateClass(); |
| 478 |
if (wrapperEx != nullptr) |
| 479 |
{ |
| 480 |
wrapperEx->Initialize((void *)vaDriverCtx); |
| 481 |
hr = wrapperEx->Execute(device,cmFunctionID, cmPrivateInputData, cmPrivateInputDataSize); |
| 482 |
MOS_Delete(wrapperEx); |
| 483 |
} |
| 484 |
else |
| 485 |
{ |
| 486 |
hr = CM_OUT_OF_HOST_MEMORY; |
| 487 |
} |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
return hr; |
| 492 |
} |