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_device_rt_os.cpp
24 //! \brief     Contains Linux-dependent CmDeviceRT member functions.
25 //!
26 
27 #include "cm_device_rt.h"
28 
29 #include "cm_hal.h"
30 #include "cm_surface_manager.h"
31 #include "cm_mem.h"
32 #include "cm_surface_2d_rt.h"
33 
34 extern int32_t CmFillMosResource(VASurfaceID, VADriverContext*, PMOS_RESOURCE);
35 
36 namespace CMRT_UMD
37 {
38 //*-----------------------------------------------------------------------------
39 //| Purpose:    Constructor of CmDevice
40 //| Returns:    None.
41 //*-----------------------------------------------------------------------------
CmDeviceRT(uint32_t options)42 CmDeviceRT::CmDeviceRT(uint32_t options) : CmDeviceRTBase(options)
43 {
44     ConstructOSSpecific(options);
45 }
46 
47 //*-----------------------------------------------------------------------------
48 //| Purpose:    Destructor of CmDevice
49 //| Returns:    None.
50 //*-----------------------------------------------------------------------------
~CmDeviceRT()51 CmDeviceRT::~CmDeviceRT()
52 {
53     m_mosContext->SkuTable.reset();
54     m_mosContext->WaTable.reset();
55 
56     DestructCommon();
57 
58     DestroyAuxDevice();
59 };
60 
61 //*-----------------------------------------------------------------------------
62 //| Purpose:    Create Cm Device
63 //| Returns:    Result of the operation.
64 //*-----------------------------------------------------------------------------
Create(MOS_CONTEXT * umdContext,CmDeviceRT * & device,uint32_t options)65 int32_t CmDeviceRT::Create(MOS_CONTEXT *umdContext,
66                            CmDeviceRT* &device,
67                            uint32_t options)
68 {
69     int32_t result = CM_FAILURE;
70 
71     if (device != nullptr)
72     {
73         // if the Cm Device exists
74         device->Acquire();
75         return CM_SUCCESS;
76     }
77 
78     device = new (std::nothrow) CmDeviceRT(options);
79     if (device)
80     {
81         device->Acquire(); // increase ref count
82         result = device->Initialize(umdContext);
83         if (result != CM_SUCCESS)
84         {
85             CM_ASSERTMESSAGE("Error: Failed to initialzie CmDevice.");
86             CmDeviceRT::Destroy(device);
87             device = nullptr;
88         }
89     }
90     else
91     {
92         CM_ASSERTMESSAGE("Error: Failed to create CmDevice due to out of system memory.");
93         result = CM_OUT_OF_HOST_MEMORY;
94     }
95 
96     return result;
97 }
98 
99 //*-----------------------------------------------------------------------------
100 //! Destroy the CmDevice_RT and kernels, samplers and the queue it created.
101 //! Also destroy all surfaces it created if the surface hasn't been explicitly destroyed.
102 //! Input :
103 //!     Reference to the pointer to the CmDevice_RT .
104 //! OUTPUT :
105 //!     CM_SUCCESS if CmDevice_RT is successfully destroyed.
106 //*-----------------------------------------------------------------------------
Destroy(CmDeviceRT * & device)107 int32_t CmDeviceRT::Destroy(CmDeviceRT* &device)
108 {
109     INSERT_API_CALL_LOG();
110 
111     int32_t result = CM_SUCCESS;
112 
113     int32_t refCount = device->Release();
114 
115     if (refCount == 0)
116     {
117         CmSafeDelete(device);
118     }
119 
120     return result;
121 }
122 
123 //*-----------------------------------------------------------------------------
124 //| Purpose:    Initialize the OS-Specific part in the Initialize() function
125 //| Returns:    None.
126 //*-----------------------------------------------------------------------------
InitializeOSSpecific(MOS_CONTEXT * mosContext)127 int32_t CmDeviceRT::InitializeOSSpecific(MOS_CONTEXT *mosContext)
128 {
129     return CreateAuxDevice( mosContext);
130 }
131 
ConstructOSSpecific(uint32_t devCreateOption)132 void CmDeviceRT::ConstructOSSpecific(uint32_t devCreateOption)
133 {
134     m_pfnReleaseVaSurface = nullptr;
135 
136     // If use dynamic states.
137     m_cmHalCreateOption.dynamicStateHeap = (devCreateOption & CM_DEVICE_CONFIG_DSH_DISABLE_MASK) ? false : true;
138     if (m_cmHalCreateOption.dynamicStateHeap)
139     {
140         m_cmHalCreateOption.maxTaskNumber = 64;
141     }
142     return;
143 }
144 
145 //*-----------------------------------------------------------------------------
146 //| Purpose:    Create Intel CM Device and Get maxValues and version of CM device
147 //| Returns:    Result of the operation.
148 //*-----------------------------------------------------------------------------
CreateAuxDevice(MOS_CONTEXT * mosContext)149 int32_t CmDeviceRT::CreateAuxDevice(MOS_CONTEXT *mosContext)  //VADriverContextP
150 {
151     int32_t                     hr = CM_SUCCESS;
152     PDDI_MEDIA_CONTEXT          mediaContext = nullptr;
153     VAContextID                 vaCtxID;
154     PCM_HAL_STATE               cmHalState;
155     PCM_CONTEXT                 cmContext;
156 
157     m_mosContext = mosContext;
158 
159     CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(HalCm_Create(mosContext, &m_cmHalCreateOption, &cmHalState ));
160 
161     CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->pfnCmAllocate(cmHalState));
162 
163     // allocate cmContext
164     cmContext = (PCM_CONTEXT)MOS_AllocAndZeroMemory(sizeof(CM_CONTEXT));
165     CM_CHK_NULL_GOTOFINISH_CMERROR(cmContext);
166     cmContext->mosCtx     = *mosContext; // mos context
167     cmContext->cmHalState = cmHalState;
168 
169     m_accelData =  (void *)cmContext;
170 
171     CM_CHK_CMSTATUS_GOTOFINISH_WITH_MSG(GetMaxValueFromCaps(m_halMaxValues, m_halMaxValuesEx), "Failed to get Max values.");
172     CM_CHK_CMSTATUS_GOTOFINISH_WITH_MSG(GetGenPlatform(m_platform), "Failed to get GPU type.");
173 
174     //  Get version from Driver
175     m_ddiVersion = CM_VERSION;
176 
177 finish:
178     return hr;
179 }
180 
181 //*-----------------------------------------------------------------------------
182 //| Purpose:    Destory Intel Aux Device : CM device
183 //| Returns:    Result of the operation.
184 //*-----------------------------------------------------------------------------
DestroyAuxDevice()185 int32_t CmDeviceRT::DestroyAuxDevice()
186 {
187     PCM_CONTEXT_DATA  cmData = (PCM_CONTEXT_DATA)m_accelData;
188 
189     // Delete VPHAL State
190     if (cmData && cmData->cmHalState)
191     {
192         cmData->mosCtx.SkuTable.reset();
193         cmData->mosCtx.WaTable.reset();
194         HalCm_Destroy(cmData->cmHalState);
195         // Delete CM Data itself
196         MOS_FreeMemory(cmData);
197 
198     }
199 
200     return CM_SUCCESS;
201 }
202 
203 //*-----------------------------------------------------------------------------
204 //| Purpose:    Create Surface 2D
205 //| Arguments :
206 //|               VASurfaceID :     [in]     index to MEDIASURFACE[], same as LIBVA SurfaceID
207 //|               umdContext           [in]     Va driver context
208 //|               surface          [out]    Reference to Pointer to CmSurface2D
209 //| Returns:    Result of the operation.
210 //*-----------------------------------------------------------------------------
CreateSurface2D(VASurfaceID vaSurface,VADriverContext * vaDriverCtx,CmSurface2D * & surface)211 CM_RT_API int32_t CmDeviceRT::CreateSurface2D(VASurfaceID vaSurface,
212                                               VADriverContext *vaDriverCtx,
213                                               CmSurface2D* & surface)
214 {
215     INSERT_API_CALL_LOG();
216 
217     MOS_RESOURCE mosResource;
218     int32_t hr = CmFillMosResource( vaSurface, vaDriverCtx, &mosResource);
219     if( hr != CM_SUCCESS)
220     {
221         CM_ASSERTMESSAGE("Error: Failed to fill MOS resource.");
222         return hr;
223     }
224 
225     CmSurface2DRT *surfaceRT = nullptr;
226     hr = m_surfaceMgr->CreateSurface2DFromMosResource(&mosResource, false, surfaceRT);
227     surface = surfaceRT;
228     return hr;
229 }
230 
231 //*----------------------------------------------------------------------------
232 //| Purpose:    Get JIT Compiler function from igfxcmjit64/32.dll
233 //| Returns:    Result of the operation.
234 //*-----------------------------------------------------------------------------
GetJITCompileFnt(pJITCompile & jitCompile)235 int32_t CmDeviceRT::GetJITCompileFnt(pJITCompile &jitCompile)
236 {
237     if (m_fJITCompile)
238     {
239         jitCompile = m_fJITCompile;
240     }
241     else
242     {
243         int ret = LoadJITDll();
244         if (ret != CM_SUCCESS)
245         {
246             return ret;
247         }
248         jitCompile = m_fJITCompile;
249     }
250     return CM_SUCCESS;
251 }
252 
GetJITCompileFntV2(pJITCompile_v2 & jitCompile_v2)253 int32_t CmDeviceRT::GetJITCompileFntV2(pJITCompile_v2 &jitCompile_v2)
254 {
255     if (m_fJITCompile_v2)
256     {
257         jitCompile_v2 = m_fJITCompile_v2;
258     }
259     else
260     {
261         int ret = LoadJITDll();
262         if (ret != CM_SUCCESS)
263         {
264             return ret;
265         }
266         jitCompile_v2 = m_fJITCompile_v2;
267     }
268     return CM_SUCCESS;
269 }
270 
271 
272 //*----------------------------------------------------------------------------
273 //| Purpose:    Get JIT Free Block function from igfxcmjit64/32.dll
274 //| Returns:    Result of the operation.
275 //*-----------------------------------------------------------------------------
GetFreeBlockFnt(pFreeBlock & freeBlock)276 int32_t CmDeviceRT::GetFreeBlockFnt(pFreeBlock &freeBlock)
277 {
278     if (m_fFreeBlock)
279     {
280         freeBlock = m_fFreeBlock;
281     }
282     else
283     {
284         int ret = LoadJITDll();
285         if (ret != CM_SUCCESS)
286         {
287             return ret;
288         }
289         freeBlock = m_fFreeBlock;
290     }
291     return CM_SUCCESS;
292 }
293 
294 //*----------------------------------------------------------------------------
295 //| Purpose:    Get JIT Version function from igfxcmjit64/32.dll, It used to get
296 //|             version from common isa
297 //| Returns:    Result of the operation.
298 //*-----------------------------------------------------------------------------
GetJITVersionFnt(pJITVersion & jitVersion)299 int32_t CmDeviceRT::GetJITVersionFnt(pJITVersion &jitVersion)
300 {
301     if (m_fJITVersion)
302     {
303         jitVersion = m_fJITVersion;
304     }
305     else
306     {
307         int ret = LoadJITDll();
308         if (ret != CM_SUCCESS)
309         {
310             return ret;
311         }
312         jitVersion = m_fJITVersion;
313     }
314     return CM_SUCCESS;
315 }
316 
317 //*----------------------------------------------------------------------------
318 //| Purpose:    Get all JIT  functions from igfxcmjit64/32.dll.
319 //|
320 //| Returns:    Result of the operation.
321 //*-----------------------------------------------------------------------------
LoadJITDll()322 int32_t CmDeviceRT::LoadJITDll()
323 {
324     int result = 0;
325 
326     if (nullptr == m_hJITDll)
327     {
328         m_hJITDll = dlopen( "libigc.so", RTLD_LAZY );
329         if (nullptr == m_hJITDll)
330         {
331             CM_NORMALMESSAGE("Warning: Failed to load IGC library, will try JIT library.");
332             if (sizeof(void *) == 4)  //32-bit
333             {
334                 m_hJITDll = dlopen( "igfxcmjit32.so", RTLD_LAZY );
335             }
336             else  //64-bit
337             {
338                 m_hJITDll = dlopen( "igfxcmjit64.so", RTLD_LAZY );
339             }
340         }
341         if (nullptr == m_hJITDll)
342         {
343             result = CM_JITDLL_LOAD_FAILURE;
344             CM_ASSERTMESSAGE("Error: Failed to load either IGC or JIT library.");
345             return result;
346         }
347         if ((nullptr == m_fJITCompile && nullptr == m_fJITCompile_v2) || nullptr == m_fFreeBlock || nullptr == m_fJITVersion)
348         {
349             m_fJITCompile = (pJITCompile)MOS_GetProcAddress(m_hJITDll, JITCOMPILE_FUNCTION_STR);
350             m_fJITCompile_v2 = (pJITCompile_v2)MOS_GetProcAddress(m_hJITDll, JITCOMPILEV2_FUNCTION_STR);
351             m_fFreeBlock = (pFreeBlock)MOS_GetProcAddress(m_hJITDll, FREEBLOCK_FUNCTION_STR);
352             m_fJITVersion = (pJITVersion)MOS_GetProcAddress(m_hJITDll, JITVERSION_FUNCTION_STR);
353         }
354 
355         if ((nullptr == m_fJITCompile && nullptr == m_fJITCompile_v2) || (nullptr == m_fFreeBlock) || (nullptr == m_fJITVersion))
356         {
357             result = CM_JITDLL_LOAD_FAILURE;
358             CM_ASSERTMESSAGE("Error: Failed to get JIT functions.");
359             return result;
360         }
361     }
362 
363     return result;
364 }
365 
366 //*-----------------------------------------------------------------------------
367 //| Purpose:    Get the GPU Infomations from Internal
368 //| Returns:    Result of the operation.
369 //*-----------------------------------------------------------------------------
QueryGPUInfoInternal(PCM_QUERY_CAPS queryCaps)370 CM_RETURN_CODE CmDeviceRT::QueryGPUInfoInternal(PCM_QUERY_CAPS queryCaps)
371 {
372     PCM_CONTEXT_DATA        cmData;
373     PCM_HAL_STATE           cmHalState;
374     CM_RETURN_CODE          hr = CM_SUCCESS;
375 
376     cmData = (PCM_CONTEXT_DATA)GetAccelData();
377     CM_CHK_NULL_GOTOFINISH_CMERROR(cmData);
378 
379     cmHalState = cmData->cmHalState;
380     CM_CHK_NULL_GOTOFINISH_CMERROR(cmHalState);
381 
382     switch(queryCaps->type)
383     {
384         case CM_QUERY_GPU:
385             queryCaps->genCore = cmHalState->platform.eRenderCoreFamily;
386             break;
387 
388         case CM_QUERY_GT:
389             cmHalState->cmHalInterface->GetGenPlatformInfo(nullptr, &queryCaps->genGT, nullptr);
390             break;
391 
392         case CM_QUERY_MIN_RENDER_FREQ:
393             queryCaps->minRenderFreq = 0;
394             break;
395 
396         case CM_QUERY_MAX_RENDER_FREQ:
397             queryCaps->maxRenderFreq = 0;
398             break;
399 
400         case CM_QUERY_STEP:
401             queryCaps->genStepId = cmHalState->platform.usRevId;
402             break;
403 
404         case CM_QUERY_GPU_FREQ:
405             CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->pfnGetGPUCurrentFrequency(cmHalState, &queryCaps->gpuCurrentFreq));
406             break;
407 
408         default:
409             hr = CM_FAILURE;
410             goto finish;
411         }
412 finish:
413     return hr;
414 }
415 
416 //*-----------------------------------------------------------------------------
417 //| Purpose:    Get the supported formats in Surface2D from Internal
418 //| Returns:    Result of the operation.
419 //*-----------------------------------------------------------------------------
420 CM_RETURN_CODE
QuerySurface2DFormatsInternal(PCM_QUERY_CAPS queryCaps)421 CmDeviceRT::QuerySurface2DFormatsInternal(PCM_QUERY_CAPS queryCaps)
422 {
423     if (queryCaps->surface2DFormats)
424     {
425         CM_SURFACE_FORMAT formats[ CM_MAX_SURFACE2D_FORMAT_COUNT_INTERNAL ] =
426         {
427             CM_SURFACE_FORMAT_X8R8G8B8,
428             CM_SURFACE_FORMAT_A8R8G8B8,
429             CM_SURFACE_FORMAT_A8B8G8R8,
430             CM_SURFACE_FORMAT_R32F,
431             CM_SURFACE_FORMAT_V8U8,
432             CM_SURFACE_FORMAT_P8,
433             CM_SURFACE_FORMAT_YUY2,
434             CM_SURFACE_FORMAT_A8,
435             CM_SURFACE_FORMAT_NV12,
436             CM_SURFACE_FORMAT_P010,
437             CM_SURFACE_FORMAT_P016,
438             CM_SURFACE_FORMAT_Y216,
439             CM_SURFACE_FORMAT_Y416,
440             CM_SURFACE_FORMAT_UYVY,
441             CM_SURFACE_FORMAT_V8U8,
442             CM_SURFACE_FORMAT_Y8_UNORM,
443             CM_SURFACE_FORMAT_YV12,
444             CM_SURFACE_FORMAT_R8_UINT,
445             CM_SURFACE_FORMAT_R16_UINT,
446             CM_SURFACE_FORMAT_P208,
447             CM_SURFACE_FORMAT_AYUV,
448             CM_SURFACE_FORMAT_Y210,
449             CM_SURFACE_FORMAT_Y410,
450         };
451         CmSafeMemCopy( queryCaps->surface2DFormats, formats, CM_MAX_SURFACE2D_FORMAT_COUNT_INTERNAL  * sizeof( GMM_RESOURCE_FORMAT ) );
452     }
453     else
454         return CM_FAILURE;
455 
456     return CM_SUCCESS;
457 }
458 
459 //*-----------------------------------------------------------------------------
460 //| Purpose:   Report all the supported formats for surface2D
461 //| Returns:    No
462 //*-----------------------------------------------------------------------------
QuerySurface2DFormats(void * capValue,uint32_t & capValueSize)463 int32_t CmDeviceRT::QuerySurface2DFormats(void *capValue,
464                                           uint32_t & capValueSize)
465 {
466     if( capValueSize >= CM_MAX_SURFACE2D_FORMAT_COUNT  * sizeof( GMM_RESOURCE_FORMAT ) )
467     {
468         capValueSize = CM_MAX_SURFACE2D_FORMAT_COUNT  * sizeof( GMM_RESOURCE_FORMAT ) ;
469         CM_SURFACE_FORMAT formats[ CM_MAX_SURFACE2D_FORMAT_COUNT ] =
470         {
471             CM_SURFACE_FORMAT_X8R8G8B8,
472             CM_SURFACE_FORMAT_A8R8G8B8,
473             CM_SURFACE_FORMAT_A8B8G8R8,
474             CM_SURFACE_FORMAT_R32F,
475             CM_SURFACE_FORMAT_V8U8,
476             CM_SURFACE_FORMAT_P8,
477             CM_SURFACE_FORMAT_YUY2,
478             CM_SURFACE_FORMAT_A8,
479             CM_SURFACE_FORMAT_NV12,
480             CM_SURFACE_FORMAT_P010,
481             CM_SURFACE_FORMAT_P016,
482             CM_SURFACE_FORMAT_Y216,
483             CM_SURFACE_FORMAT_Y416,
484             CM_SURFACE_FORMAT_UYVY,
485             CM_SURFACE_FORMAT_IMC3,
486             CM_SURFACE_FORMAT_411P,
487             CM_SURFACE_FORMAT_411R,
488             CM_SURFACE_FORMAT_422H,
489             CM_SURFACE_FORMAT_422V,
490             CM_SURFACE_FORMAT_444P,
491             CM_SURFACE_FORMAT_RGBP,
492             CM_SURFACE_FORMAT_BGRP,
493             CM_SURFACE_FORMAT_YV12,
494             CM_SURFACE_FORMAT_R8_UINT,
495             CM_SURFACE_FORMAT_R16_UINT,
496             CM_SURFACE_FORMAT_P208,
497             CM_SURFACE_FORMAT_AYUV,
498             CM_SURFACE_FORMAT_Y210,
499             CM_SURFACE_FORMAT_Y410,
500         };
501         CmSafeMemCopy( capValue, formats, capValueSize );
502         return CM_SUCCESS;
503     }
504     else
505     {
506         return CM_FAILURE;
507     }
508 }
509 
510 //*-----------------------------------------------------------------------------
511 //| Purpose:    Set CM Context ID in MediaContext
512 //| Arguments : Context ID
513 //| Returns:    Result of the operation.
514 //*-----------------------------------------------------------------------------
SetVaCtxID(uint32_t vaCtxID)515 int32_t CmDeviceRT::SetVaCtxID(uint32_t vaCtxID)
516 {
517     m_vaCtxID = vaCtxID;
518     return CM_SUCCESS;
519 }
520 
521 //*-----------------------------------------------------------------------------
522 //| Purpose:    Get CM Context ID in MediaContext
523 //| Arguments : Context ID
524 //| Returns:    Result of the operation.
525 //*-----------------------------------------------------------------------------
GetVaCtxID(uint32_t & vaCtxID)526 int32_t CmDeviceRT::GetVaCtxID(uint32_t &vaCtxID)
527 {
528     vaCtxID = m_vaCtxID;
529     return CM_SUCCESS;
530 }
531 
RegisterCallBack(pCallBackReleaseVaSurface callBack)532 int32_t CmDeviceRT::RegisterCallBack(pCallBackReleaseVaSurface callBack)
533 {
534     m_pfnReleaseVaSurface = callBack;
535     return CM_SUCCESS;
536 }
537 
ReleaseVASurface(void * vaDisplay,void * vaSurfaceID)538 int32_t CmDeviceRT::ReleaseVASurface(void *vaDisplay, void *vaSurfaceID)
539 {
540     if(m_pfnReleaseVaSurface)
541     {
542         m_pfnReleaseVaSurface( vaDisplay, vaSurfaceID);
543     }
544 
545     return CM_SUCCESS;
546 }
547 
ReadVtuneProfilingFlag()548 int32_t CmDeviceRT::ReadVtuneProfilingFlag()
549 {
550     //Aggrement with Vtune: <user home dir>/.mdf_trace
551     //if .mdf_trace does not exist, vtune log is off
552     //if .mdf_trace exists, read string "Output=<hexmask>"
553     //hexmask = 1 : enable; hexmask = 0: disable
554     m_vtuneOn = false;
555 
556     char *homeStr = getenv("HOME");
557     if (homeStr == nullptr)
558     {
559        //Even homeStr is not found, this function returns success.
560        //m_vtuneOn is still false.
561        return CM_SUCCESS;
562     }
563 
564     char traceFile[256];
565     int offset = snprintf(traceFile, 256, "%s", homeStr);
566     snprintf(traceFile+offset, 256-offset, "%s", "/.mdf_trace");
567 
568     FILE *traceFd = fopen(traceFile, "r");
569     int flag = 0;
570     if(traceFd )
571     {
572       //read data from file
573       int ret = fscanf(traceFd, "Output=%d", &flag);
574       if(ret >=0 && flag == 1)
575       {
576          m_vtuneOn = true;
577       }
578       fclose(traceFd);
579     }
580 
581     //Set flag in cm hal layer
582     PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)this->GetAccelData();
583     PCM_HAL_STATE cmHalState = cmData->cmHalState;
584     cmHalState->pfnSetVtuneProfilingFlag(cmHalState, m_vtuneOn);
585 
586     return CM_SUCCESS;
587 }
588 
589 //*-----------------------------------------------------------------------------
590 //| Purpose:    Create shared Surface 2D (OS agnostic)
591 //| Arguments :
592 //|               mosResource      [in]     Pointer to Mos resource
593 //|               surface          [out]    Reference to Pointer to CmSurface2D
594 //| Returns:    Result of the operation.
595 //*-----------------------------------------------------------------------------
CreateSurface2D(PMOS_RESOURCE mosResource,CmSurface2D * & surface)596 CM_RT_API int32_t CmDeviceRT::CreateSurface2D(PMOS_RESOURCE mosResource,
597                                               CmSurface2D* & surface)
598 {
599     INSERT_API_CALL_LOG();
600 
601     if (mosResource == nullptr)
602     {
603         return CM_INVALID_MOS_RESOURCE_HANDLE;
604     }
605 
606     CLock locker(m_criticalSectionSurface);
607 
608     CmSurface2DRT *surfaceRT = nullptr;
609     int ret = m_surfaceMgr->CreateSurface2DFromMosResource(mosResource, false, surfaceRT);
610     surface = surfaceRT;
611     return ret;
612 }
613 
614 //*-----------------------------------------------------------------------------
615 //| Purpose:    Create Surface 2D
616 //| Arguments :   width             [in]     width of the  CmSurface2D
617 //|               height            [in]     height of the CmSurface2D
618 //|               format            [in]     format of the CmSurface2D
619 //|               surface          [in/out]    Reference to Pointer to CmSurface2D
620 //| Returns:    Result of the operation.
621 //*-----------------------------------------------------------------------------
CreateSurface2D(uint32_t width,uint32_t height,CM_SURFACE_FORMAT format,CmSurface2D * & surface)622 CM_RT_API int32_t CmDeviceRT::CreateSurface2D(uint32_t width,
623                                               uint32_t height,
624                                               CM_SURFACE_FORMAT format,
625                                               CmSurface2D* & surface)
626 {
627     INSERT_API_CALL_LOG();
628 
629     CLock locker(m_criticalSectionSurface);
630 
631     CmSurface2DRT *surfaceRT = nullptr;
632     int ret = m_surfaceMgr->CreateSurface2D(width, height, 0, true, format, surfaceRT);
633     surface = surfaceRT;
634     return ret;
635 }
636 
637 //*-----------------------------------------------------------------------------
638 //| Purpose:    Create Surface 2D
639 //| NOTE: Called by CM Wrapper, from CMRT Thin
640 //*-----------------------------------------------------------------------------
CreateSurface2D(PMOS_RESOURCE mosResource,bool isCmCreated,CmSurface2D * & surface)641 int32_t CmDeviceRT::CreateSurface2D(PMOS_RESOURCE mosResource,
642                                     bool isCmCreated,
643                                     CmSurface2D* & surface)
644 {
645     INSERT_API_CALL_LOG();
646 
647     if (mosResource == nullptr)
648     {
649         return CM_INVALID_MOS_RESOURCE_HANDLE;
650     }
651 
652     CLock locker(m_criticalSectionSurface);
653 
654     CmSurface2DRT *surfaceRT = nullptr;
655     int ret = m_surfaceMgr->CreateSurface2DFromMosResource(mosResource, isCmCreated, surfaceRT);
656     surface = surfaceRT;
657     return ret;
658 }
659 }  // namespace
660