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