1 /*
2 * Copyright (c) 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 #include "cm_device.h"
23 #include <cstdarg>
24 #include "cm_debug.h"
25 #include "cm_mem.h"
26 #if USE_EXTENSION_CODE
27 #include "cm_gtpin_external_interface.h"
28 #endif
29 #include "cm_printf_host.h"
30 #include "cm_surface_manager.h"
31 #include "cm_queue.h"
32 #include "cm_perf_statistics.h"
33 #include "cm_timer.h"
34
35 class CmBuffer;
36 class CmBufferUP;
37 class CmBufferSVM;
38 class CmBufferStateless;
39
40 #if MDF_PROFILER_ENABLED
41 CmPerfStatistics gCmPerfStatistics; // global instance to record API's perf
42 #endif
43
CreateBuffer(uint32_t size,CmBuffer * & buffer)44 CM_RT_API int32_t CmDevice_RT::CreateBuffer(uint32_t size, CmBuffer* &buffer)
45 {
46 INSERT_PROFILER_RECORD();
47
48 return m_surfaceManager->CreateBuffer(size, buffer);
49 }
50
CreateBufferUP(uint32_t size,void * sysMem,CmBufferUP * & buffer)51 CM_RT_API int32_t CmDevice_RT::CreateBufferUP(uint32_t size, void* sysMem, CmBufferUP* &buffer)
52 {
53 INSERT_PROFILER_RECORD();
54
55 return m_surfaceManager->CreateBufferUP( size, sysMem, buffer);
56 }
57
DestroySurface(CmBuffer * & buffer)58 CM_RT_API int32_t CmDevice_RT::DestroySurface(CmBuffer* &buffer)
59 {
60 INSERT_PROFILER_RECORD();
61
62 return m_surfaceManager->DestroyBuffer(buffer);
63 }
64
DestroyBufferUP(CmBufferUP * & buffer)65 CM_RT_API int32_t CmDevice_RT::DestroyBufferUP(CmBufferUP* &buffer)
66 {
67 INSERT_PROFILER_RECORD();
68
69 return m_surfaceManager->DestroyBufferUP(buffer);
70 }
71
72 //!
73 //! Create a CmSurface2D
74 //! Input :
75 //! Surface width, height and format;
76 //! Reference to the pointer to the CmSurface2D .
77 //! Output:
78 //! CM_SUCCESS if the CmSurface2D is successfully created;
79 //! CM_OUT_OF_HOST_MEMORY if out of system memory;
80 //! CM_SURFACE_ALLOCATION_FAILURE if surface creation fails;
81 //! CM_FAILURE otherwise;
82 //!NOTES: general API
CreateSurface2D(uint32_t width,uint32_t height,CM_SURFACE_FORMAT format,CmSurface2D * & surface)83 CM_RT_API int32_t CmDevice_RT::CreateSurface2D(uint32_t width, uint32_t height, CM_SURFACE_FORMAT format, CmSurface2D* & surface )
84 {
85 INSERT_PROFILER_RECORD();
86
87 return m_surfaceManager->CreateSurface2D( width, height, format, surface);;
88 }
89
CreateSurface2DUP(uint32_t width,uint32_t height,CM_SURFACE_FORMAT format,void * sysMem,CmSurface2DUP * & surface)90 CM_RT_API int32_t CmDevice_RT::CreateSurface2DUP( uint32_t width, uint32_t height, CM_SURFACE_FORMAT format, void* sysMem, CmSurface2DUP* &surface )
91 {
92 INSERT_PROFILER_RECORD();
93
94 return m_surfaceManager->CreateSurface2DUP( width, height, format, sysMem, surface);
95 }
96
DestroySurface2DUP(CmSurface2DUP * & surface)97 CM_RT_API int32_t CmDevice_RT::DestroySurface2DUP( CmSurface2DUP* &surface)
98 {
99 INSERT_PROFILER_RECORD();
100
101 return m_surfaceManager->DestroySurface2DUP(surface);
102 }
103
DestroySurface(CmSurface2D * & surface2d)104 CM_RT_API int32_t CmDevice_RT::DestroySurface( CmSurface2D* &surface2d)
105 {
106 INSERT_PROFILER_RECORD();
107
108 return m_surfaceManager->DestroySurface(surface2d);
109 }
110
GetSurface2DInfo(uint32_t width,uint32_t height,CM_SURFACE_FORMAT format,uint32_t & pitch,uint32_t & physicalSize)111 CM_RT_API int32_t CmDevice_RT::GetSurface2DInfo( uint32_t width, uint32_t height, CM_SURFACE_FORMAT format, uint32_t & pitch, uint32_t & physicalSize)
112 {
113 INSERT_PROFILER_RECORD();
114
115 CM_GETSURFACE2DINFO_PARAM inParam;
116 CmSafeMemSet( &inParam, 0, sizeof( CM_GETSURFACE2DINFO_PARAM ) );
117 inParam.width = width;
118 inParam.height = height;
119 inParam.format = format;
120
121 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_GETSURFACE2DINFO,
122 &inParam, sizeof(inParam));
123 CHK_FAILURE_RETURN(hr);
124 CHK_FAILURE_RETURN(inParam.returnValue);
125
126 pitch = inParam.pitch;
127 physicalSize = inParam.physicalSize;
128 return CM_SUCCESS;
129 }
130
131 //!
132 //! Load the code of one or more kernels in common ISA.
133 //! Jit-ting of the common ISA code can happen either in LoadProgram or CreateKernel.
134 //! Jit options set in LoadProgram are for all kernels within the code.
135 //! Jit options set in CreateKernel are for the specific kernel, overwriting the jit options set in program level. LoadProgram can be called multiple times for the same code.
136 //! Jit options is a null terminated string. string length ( excluding the null terminater )shoudl be
137 //! less than 512 (CM_MAX_OPTION_SIZE_IN_BYTE ). Otherwise the option is ignored.
138 //! Each time a now CmProgram object is generated.
139 //!
140 //! Input:
141 //! 1) Pointer pointing to the common ISA code
142 //! 2) code size in byte
143 //! 3) Reference to the pointer to the CmProgram.
144 //! 4) Jit options. This argument is optional.
145 //! Output:
146 //! CM_SUCCESS if the CmProgram is successfully created;
147 //! CM_INVALID_KERNELS if any kernel is invalid;
148 //! CM_OUT_OF_HOST_MEMORY if out of system memory;
149 //! CM_FAILURE otherwise;
150 //!
151
LoadProgram(void * commonISACode,const uint32_t size,CmProgram * & program,const char * options)152 CM_RT_API int32_t CmDevice_RT::LoadProgram( void* commonISACode, const uint32_t size, CmProgram*& program, const char* options )
153 {
154 INSERT_PROFILER_RECORD();
155
156 if( (commonISACode == nullptr) || (size == 0) )
157 {
158 CmAssert( 0 );
159 return CM_INVALID_COMMON_ISA;
160 }
161
162 return CreateProgram(commonISACode, size, program, options);
163 }
164
CreateProgram(void * commonISACode,const uint32_t size,CmProgram * & program,const char * options)165 int32_t CmDevice_RT::CreateProgram(void* commonISACode,
166 const uint32_t size,
167 CmProgram*& program,
168 const char* options)
169 {
170 CM_LOADPROGRAM_PARAM inParam;
171 CmSafeMemSet( &inParam, 0, sizeof( CM_LOADPROGRAM_PARAM ) );
172 inParam.cisaCode = commonISACode;
173 inParam.cisaCodeSize = size;
174 inParam.options = (char *)options;
175
176 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_LOADPROGRAM,
177 &inParam, sizeof(inParam));
178
179 CHK_FAILURE_RETURN(hr);
180 CHK_FAILURE_RETURN(inParam.returnValue);
181
182 program = (CmProgram *)inParam.cmProgramHandle;
183
184 return CM_SUCCESS;
185 }
186
DestroyProgram(CmProgram * & program)187 CM_RT_API int32_t CmDevice_RT::DestroyProgram(CmProgram* & program )
188 {
189 INSERT_PROFILER_RECORD();
190
191 if( program == nullptr )
192 {
193 return CM_FAILURE;
194 }
195
196 CM_DESTROYPROGRAM_PARAM inParam;
197 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYPROGRAM_PARAM ) );
198 inParam.cmProgramHandle = program;
199
200 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYPROGRAM,
201 &inParam, sizeof(inParam));
202
203 CHK_FAILURE_RETURN(hr);
204 CHK_FAILURE_RETURN(inParam.returnValue);
205
206 program = nullptr;
207
208 return CM_SUCCESS;
209 }
210
211 //!
212 //! Create a CmKernel_RT. Each kernel can run in multiple threads.
213 //! If CreateKernel is called multiple times using the same CmProgram,
214 //! the same kernel name, and the same options, only in the first time a new CmKernel_RT is generated,
215 //! all following calls only return the existing CmKernel_RT.
216 //! Otherwise, each time a new CmKernel_RT is generated.
217 //! Input :
218 //! 1) CM Program from which the kernel is created
219 //! 2) CM kernel function (genx_main) name
220 //! 3) Reference to the pointer to the CmKernel_RT .
221 //! 4) Jit options for this kernel, overwriting the jit options in
222 //! CmProgram level for this specific kernel. This argument is optional.
223 //! Output:
224 //! CM_SUCCESS if the CmKernel_RT is successfully created;
225 //! CM_OUT_OF_HOST_MEMORY if out of system memory;
226 //! CM_FAILURE otherwise;
227 //!
CreateKernel(CmProgram * program,const char * kernelName,CmKernel * & kernel,const char * options)228 CM_RT_API int32_t CmDevice_RT::CreateKernel( CmProgram* program, const char* kernelName, CmKernel* & kernel, const char* options )
229 {
230 INSERT_PROFILER_RECORD();
231
232 if(program == nullptr)
233 {
234 CmAssert( 0 );
235 return CM_INVALID_ARG_VALUE;
236 }
237
238 CM_CREATEKERNEL_PARAM inParam;
239 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATEKERNEL_PARAM ) );
240 inParam.cmProgramHandle = program;
241 inParam.kernelName = (char*)kernelName;
242 inParam.options = (char *)options;
243
244 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CREATEKERNEL,
245 &inParam, sizeof(inParam));
246
247 CHK_FAILURE_RETURN(hr);
248 CHK_FAILURE_RETURN(inParam.returnValue);
249 kernel = (CmKernel *)inParam.cmKernelHandle; // Got Object from CMRT@UMD directly.
250
251 return CM_SUCCESS;
252 }
253
DestroyKernel(CmKernel * & kernel)254 CM_RT_API int32_t CmDevice_RT::DestroyKernel( CmKernel*& kernel)
255 {
256 INSERT_PROFILER_RECORD();
257
258 CM_DESTROYKERNEL_PARAM inParam;
259 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYKERNEL_PARAM ) );
260 inParam.cmKernelHandle = kernel;
261
262 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYKERNEL,
263 &inParam, sizeof(inParam));
264
265 CHK_FAILURE_RETURN(hr);
266 CHK_FAILURE_RETURN(inParam.returnValue);
267 kernel = nullptr;
268 return CM_SUCCESS;
269 }
270
CreateTask(CmTask * & task)271 CM_RT_API int32_t CmDevice_RT::CreateTask(CmTask *& task)
272 {
273 INSERT_PROFILER_RECORD();
274
275 CM_CREATETASK_PARAM inParam;
276 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATETASK_PARAM ) );
277
278 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CREATETASK,
279 &inParam, sizeof(inParam));
280
281 CHK_FAILURE_RETURN(hr);
282 CHK_FAILURE_RETURN(inParam.returnValue);
283 task = (CmTask *)inParam.cmTaskHandle;
284
285 #if USE_EXTENSION_CODE
286 GTPIN_MAKER_FUNCTION(CmrtCodeMarkerForGTPin_CreateTask(this, task));
287 #endif
288 return CM_SUCCESS;
289 }
290
DestroyTask(CmTask * & task)291 CM_RT_API int32_t CmDevice_RT::DestroyTask( CmTask*& task)
292 {
293 INSERT_PROFILER_RECORD();
294
295 #if USE_EXTENSION_CODE
296 GTPIN_MAKER_FUNCTION(CmrtCodeMarkerForGTPin_DestroyTask(this, task));
297 #endif
298
299 CM_DESTROYTASK_PARAM inParam;
300 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYTASK_PARAM ) );
301 inParam.cmTaskHandle = task;
302
303 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYTASK,
304 &inParam, sizeof(inParam));
305
306 CHK_FAILURE_RETURN(hr);
307 CHK_FAILURE_RETURN(inParam.returnValue);
308 task = nullptr;
309
310 return CM_SUCCESS;
311
312 }
313
314 //!
315 //! Create a task queue, CmQueue_RT. It is an in-order queue of tasks. Each task can
316 //! have multiple kernels running concurrently, each kernel can run in multiple threads.
317 //! For now only one CmQueue_RT is supported. Trying to create a second CmQueue_RT will fail.
318 //! Input :
319 //! Reference to the pointer to the CmQueue_RT .
320 //! Output:
321 //! CM_SUCCESS if the CmQueue_RT is successfully created;
322 //! CM_OUT_OF_HOST_MEMORY if out of system memory;
323 //! CM_FAILURE otherwise;
324 //!
CreateQueue(CmQueue * & queue)325 CM_RT_API int32_t CmDevice_RT::CreateQueue(CmQueue* &queue)
326 {
327 INSERT_PROFILER_RECORD();
328
329 CM_QUEUE_CREATE_OPTION option = CM_DEFAULT_QUEUE_CREATE_OPTION;
330 int32_t result = CreateQueueEx(queue, option);
331
332 #if USE_EXTENSION_CODE
333 GTPIN_MAKER_FUNCTION(CmrtCodeMarkerForGTPin_CreateQueue(this, queue));
334 #endif
335
336 return result;
337 }
338
339 CM_RT_API int32_t
CreateQueueEx(CmQueue * & queue,CM_QUEUE_CREATE_OPTION queueCreateOption)340 CmDevice_RT::CreateQueueEx(CmQueue* &queue,
341 CM_QUEUE_CREATE_OPTION queueCreateOption)
342 {
343 INSERT_PROFILER_RECORD();
344 m_criticalSectionQueue.Acquire();
345
346 CmQueue_RT *queueRT = nullptr;
347 if (CM_QUEUE_TYPE_RENDER == queueCreateOption.QueueType)
348 {
349 for (auto iter = m_queue.begin(); iter != m_queue.end(); ++iter)
350 {
351 CM_QUEUE_TYPE queueType = (*iter)->GetQueueOption().QueueType;
352 unsigned int gpuContext = (*iter)->GetQueueOption().GPUContext;
353 if (queueType == CM_QUEUE_TYPE_RENDER
354 && gpuContext == queueCreateOption.GPUContext)
355 {
356 queue = (*iter);
357 m_criticalSectionQueue.Release();
358 return CM_SUCCESS;
359 }
360 }
361 }
362
363 int32_t result = CmQueue_RT::Create(this, queueRT, queueCreateOption);
364 if (CM_SUCCESS != result || nullptr == queueRT)
365 {
366 CmAssert(0);
367 CmDebugMessage(("Failed to create queue!"));
368 m_criticalSectionQueue.Release();
369 return result;
370 }
371 m_queue.push_back(queueRT);
372 queue = queueRT;
373 m_criticalSectionQueue.Release();
374
375 return result;
376 }
377
CreateThreadSpace(uint32_t width,uint32_t height,CmThreadSpace * & threadSpace)378 CM_RT_API int32_t CmDevice_RT::CreateThreadSpace( uint32_t width, uint32_t height, CmThreadSpace* &threadSpace)
379 {
380 INSERT_PROFILER_RECORD();
381
382 CM_CREATETHREADSPACE_PARAM inParam;
383 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATETHREADSPACE_PARAM ) );
384 inParam.tsWidth = width;
385 inParam.tsHeight = height;
386
387 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CREATETHREADSPACE,
388 &inParam, sizeof(inParam));
389
390 CHK_FAILURE_RETURN(hr);
391 CHK_FAILURE_RETURN(inParam.returnValue);
392 threadSpace = (CmThreadSpace *)inParam.cmTsHandle;
393
394 return CM_SUCCESS;
395 }
396
DestroyThreadSpace(CmThreadSpace * & threadSpace)397 CM_RT_API int32_t CmDevice_RT::DestroyThreadSpace( CmThreadSpace* &threadSpace)
398 {
399 INSERT_PROFILER_RECORD();
400
401 CM_DESTROYTHREADSPACE_PARAM inParam;
402 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYTHREADSPACE_PARAM ) );
403 inParam.cmTsHandle = threadSpace;
404
405 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYTHREADSPACE,
406 &inParam, sizeof(inParam));
407
408 CHK_FAILURE_RETURN(hr);
409 CHK_FAILURE_RETURN(inParam.returnValue);
410 threadSpace = nullptr;
411 return CM_SUCCESS;
412 }
413
CreateVmeSurfaceG7_5(CmSurface2D * currentSurface,CmSurface2D ** forwardSurfaceArray,CmSurface2D ** backwardSurfaceArray,const uint32_t surfaceCountForward,const uint32_t surfaceCountBackward,SurfaceIndex * & vmeSurfaceIndex)414 CM_RT_API int32_t CmDevice_RT::CreateVmeSurfaceG7_5( CmSurface2D* currentSurface,
415 CmSurface2D **forwardSurfaceArray,
416 CmSurface2D **backwardSurfaceArray,
417 const uint32_t surfaceCountForward,
418 const uint32_t surfaceCountBackward,
419 SurfaceIndex* & vmeSurfaceIndex )
420 {
421 INSERT_PROFILER_RECORD();
422
423 return CreateVmeSurface( currentSurface, forwardSurfaceArray, backwardSurfaceArray, surfaceCountForward, surfaceCountBackward, vmeSurfaceIndex, CM_FN_CMDEVICE_CREATEVMESURFACEG7_5 );
424 }
425
DestroyVmeSurfaceG7_5(SurfaceIndex * & vmeSurfaceIndex)426 CM_RT_API int32_t CmDevice_RT::DestroyVmeSurfaceG7_5( SurfaceIndex* & vmeSurfaceIndex )
427 {
428 INSERT_PROFILER_RECORD();
429
430 return DestroyVmeSurface( vmeSurfaceIndex );
431 }
432
SetVmeSurfaceStateParam(SurfaceIndex * vmeIndex,CM_VME_SURFACE_STATE_PARAM * surfStateParam)433 CM_RT_API int32_t CmDevice_RT::SetVmeSurfaceStateParam(SurfaceIndex* vmeIndex, CM_VME_SURFACE_STATE_PARAM *surfStateParam)
434 {
435 INSERT_PROFILER_RECORD();
436
437 if(vmeIndex == nullptr || surfStateParam == nullptr)
438 {
439 CmAssert( 0 );
440 return CM_INVALID_ARG_VALUE;
441 }
442
443 CM_CONFIGVMESURFACEDIMENSION_PARAM inParam;
444 CmSafeMemSet( &inParam, 0, sizeof( CM_CONFIGVMESURFACEDIMENSION_PARAM ) );
445 inParam.cmVmeSurfHandle = (void *)vmeIndex;
446 inParam.surfDimPara = surfStateParam;
447
448 int32_t result
449 = OSALExtensionExecute(CM_FN_CMDEVICE_CONFIGVMESURFACEDIMENSION,
450 &inParam, sizeof(inParam));
451
452 CHK_FAILURE_RETURN(result);
453
454 return inParam.returnValue;
455 }
456
CreateSampler(const CM_SAMPLER_STATE & samplerState,CmSampler * & sampler)457 CM_RT_API int32_t CmDevice_RT::CreateSampler( const CM_SAMPLER_STATE& samplerState, CmSampler* &sampler )
458 {
459 INSERT_PROFILER_RECORD();
460
461 CM_CREATESAMPLER_PARAM inParam;
462 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATESAMPLER_PARAM ) );
463 inParam.samplerState = samplerState;
464
465 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLER,
466 &inParam, sizeof(inParam));
467
468 CHK_FAILURE_RETURN(result);
469 CHK_FAILURE_RETURN(inParam.returnValue);
470 sampler = (CmSampler *)inParam.cmSamplerHandle;
471
472 return CM_SUCCESS;
473 }
474
CreateSamplerEx(const CM_SAMPLER_STATE_EX & samplerState,CmSampler * & sampler)475 CM_RT_API int32_t CmDevice_RT::CreateSamplerEx( const CM_SAMPLER_STATE_EX& samplerState, CmSampler* &sampler )
476 {
477 INSERT_PROFILER_RECORD();
478
479 CM_CREATESAMPLER_PARAM_EX inParam;
480 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATESAMPLER_PARAM_EX ) );
481 inParam.samplerState = samplerState;
482
483 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLER_EX,
484 &inParam, sizeof(inParam));
485
486 CHK_FAILURE_RETURN(result);
487 CHK_FAILURE_RETURN(inParam.returnValue);
488 sampler = (CmSampler *)inParam.cmSamplerHandle;
489
490 return CM_SUCCESS;
491 }
492
DestroySampler(CmSampler * & sampler)493 CM_RT_API int32_t CmDevice_RT::DestroySampler( CmSampler* &sampler )
494 {
495 INSERT_PROFILER_RECORD();
496
497 CM_DESTROYSAMPLER_PARAM inParam;
498 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYSAMPLER_PARAM ) );
499 inParam.cmSamplerHandle = sampler;
500
501 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYSAMPLER,
502 &inParam, sizeof(inParam));
503
504 CHK_FAILURE_RETURN(result);
505 CHK_FAILURE_RETURN(inParam.returnValue);
506 sampler = nullptr;
507
508 return CM_SUCCESS;
509 }
510
CreateThreadGroupSpace(uint32_t threadSpaceWidth,uint32_t threadSpaceHeight,uint32_t groupSpaceWidth,uint32_t groupSpaceHeight,CmThreadGroupSpace * & threadGroupSpace)511 CM_RT_API int32_t CmDevice_RT::CreateThreadGroupSpace( uint32_t threadSpaceWidth, uint32_t threadSpaceHeight, uint32_t groupSpaceWidth, uint32_t groupSpaceHeight, CmThreadGroupSpace* &threadGroupSpace)
512 {
513 INSERT_PROFILER_RECORD();
514
515 CM_CREATETGROUPSPACE_PARAM inParam;
516 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATETGROUPSPACE_PARAM ) );
517 inParam.thrdSpaceWidth = threadSpaceWidth;
518 inParam.thrdSpaceHeight = threadSpaceHeight;
519 inParam.thrdSpaceDepth = 1;
520 inParam.grpSpaceWidth = groupSpaceWidth;
521 inParam.grpSpaceHeight = groupSpaceHeight;
522 inParam.grpSpaceDepth = 1;
523
524 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CREATETHREADGROUPSPACE,
525 &inParam, sizeof(inParam));
526
527 CHK_FAILURE_RETURN(hr);
528 CHK_FAILURE_RETURN(inParam.returnValue);
529 threadGroupSpace = (CmThreadGroupSpace *)inParam.cmGrpSpaceHandle;
530
531 return CM_SUCCESS;
532 }
533
CreateThreadGroupSpaceEx(uint32_t threadSpaceWidth,uint32_t threadSpaceHeight,uint32_t threadSpaceDepth,uint32_t groupSpaceWidth,uint32_t groupSpaceHeight,uint32_t groupSpaceDepth,CmThreadGroupSpace * & threadGroupSpace)534 CM_RT_API int32_t CmDevice_RT::CreateThreadGroupSpaceEx(uint32_t threadSpaceWidth, uint32_t threadSpaceHeight, uint32_t threadSpaceDepth, uint32_t groupSpaceWidth, uint32_t groupSpaceHeight, uint32_t groupSpaceDepth, CmThreadGroupSpace* &threadGroupSpace)
535 {
536 INSERT_PROFILER_RECORD();
537
538 CM_CREATETGROUPSPACE_PARAM inParam;
539 CmSafeMemSet(&inParam, 0, sizeof(CM_CREATETGROUPSPACE_PARAM));
540 inParam.thrdSpaceWidth = threadSpaceWidth;
541 inParam.thrdSpaceHeight = threadSpaceHeight;
542 inParam.thrdSpaceDepth = threadSpaceDepth;
543 inParam.grpSpaceWidth = groupSpaceWidth;
544 inParam.grpSpaceHeight = groupSpaceHeight;
545 inParam.grpSpaceDepth = groupSpaceDepth;
546
547 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CREATETHREADGROUPSPACE,
548 &inParam, sizeof(inParam));
549
550 CHK_FAILURE_RETURN(hr);
551 CHK_FAILURE_RETURN(inParam.returnValue);
552 threadGroupSpace = (CmThreadGroupSpace *)inParam.cmGrpSpaceHandle;
553
554 return CM_SUCCESS;
555 }
556
DestroyThreadGroupSpace(CmThreadGroupSpace * & threadGroupSpace)557 CM_RT_API int32_t CmDevice_RT::DestroyThreadGroupSpace(CmThreadGroupSpace* &threadGroupSpace)
558 {
559 INSERT_PROFILER_RECORD();
560
561 CM_DESTROYTGROPUSPACE_PARAM inParam;
562 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYTGROPUSPACE_PARAM ) );
563 inParam.cmGrpSpaceHandle = threadGroupSpace;
564
565 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYTHREADGROUPSPACE,
566 &inParam, sizeof(inParam));
567
568 CHK_FAILURE_RETURN(hr);
569 CHK_FAILURE_RETURN(inParam.returnValue);
570 threadGroupSpace = nullptr;
571 return CM_SUCCESS;
572 }
573
GetCaps(CM_DEVICE_CAP_NAME capName,size_t & capValueSize,void * capValue)574 CM_RT_API int32_t CmDevice_RT::GetCaps(CM_DEVICE_CAP_NAME capName, size_t& capValueSize, void* capValue )
575 {
576 INSERT_PROFILER_RECORD();
577
578 CM_GETCAPS_PARAM inParam;
579 CmSafeMemSet( &inParam, 0, sizeof( CM_GETCAPS_PARAM ) );
580 inParam.capName = capName;
581 inParam.capValueSize = (uint32_t)capValueSize;
582 inParam.capValue = capValue;
583
584 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_GETCAPS,
585 &inParam, sizeof(inParam));
586
587 CHK_FAILURE_RETURN(result);
588 CHK_FAILURE_RETURN(inParam.returnValue);
589 return CM_SUCCESS;
590 }
591
CreateSurface3D(uint32_t width,uint32_t height,uint32_t depth,CM_SURFACE_FORMAT format,CmSurface3D * & surface)592 CM_RT_API int32_t CmDevice_RT::CreateSurface3D(uint32_t width, uint32_t height, uint32_t depth, CM_SURFACE_FORMAT format, CmSurface3D* & surface )
593 {
594 INSERT_PROFILER_RECORD();
595
596 return m_surfaceManager->CreateSurface3D( width, height, depth, format, surface);
597 }
598
CreateSampler8x8(const CM_SAMPLER_8X8_DESCR & samplerDescriptor,CmSampler8x8 * & sampler)599 CM_RT_API int32_t CmDevice_RT::CreateSampler8x8(const CM_SAMPLER_8X8_DESCR &samplerDescriptor, CmSampler8x8* &sampler)
600 {
601 INSERT_PROFILER_RECORD();
602
603 if((samplerDescriptor.stateType == CM_SAMPLER8X8_AVS && samplerDescriptor.avs == nullptr) ||
604 (samplerDescriptor.stateType == CM_SAMPLER8X8_CONV && samplerDescriptor.conv == nullptr) ||
605 (samplerDescriptor.stateType == CM_SAMPLER8X8_CONV1DH && samplerDescriptor.conv == nullptr) ||
606 (samplerDescriptor.stateType == CM_SAMPLER8X8_CONV1DV && samplerDescriptor.conv == nullptr) ||
607 (samplerDescriptor.stateType == CM_SAMPLER8X8_MISC && samplerDescriptor.misc == nullptr) ||
608 (samplerDescriptor.stateType == CM_SAMPLER8X8_NONE && samplerDescriptor.conv != nullptr) ||
609 sampler != nullptr)
610 {
611 CmAssert( 0 );
612 return CM_INVALID_ARG_VALUE;
613 }
614
615 CM_CREATESAMPLER8x8_PARAM inParam;
616 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATESAMPLER8x8_PARAM ) );
617 inParam.sampler8x8Desc = samplerDescriptor;
618
619 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLER8X8,
620 &inParam, sizeof(inParam));
621
622 CHK_FAILURE_RETURN(result);
623 CHK_FAILURE_RETURN(inParam.returnValue);
624 sampler = (CmSampler8x8 *)inParam.cmSampler8x8Handle;
625
626 return CM_SUCCESS;
627 }
628
DestroySampler8x8(CmSampler8x8 * & sampler8x8)629 CM_RT_API int32_t CmDevice_RT::DestroySampler8x8( CmSampler8x8 *& sampler8x8 )
630 {
631 INSERT_PROFILER_RECORD();
632
633 CM_DESTROYSAMPLER8x8_PARAM inParam;
634
635 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYSAMPLER8x8_PARAM ) );
636 inParam.cmSampler8x8Handle = sampler8x8;
637
638 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYSAMPLER8X8,
639 &inParam, sizeof(inParam));
640
641 CHK_FAILURE_RETURN(result);
642 CHK_FAILURE_RETURN(inParam.returnValue);
643 sampler8x8 = nullptr;
644
645 return CM_SUCCESS;
646 }
647
CreateSampler8x8Surface(CmSurface2D * surface2d,SurfaceIndex * & sampler8x8SurfaceIndex,CM_SAMPLER8x8_SURFACE surfaceType,CM_SURFACE_ADDRESS_CONTROL_MODE addressControl)648 CM_RT_API int32_t CmDevice_RT::CreateSampler8x8Surface(CmSurface2D* surface2d, SurfaceIndex* &sampler8x8SurfaceIndex, CM_SAMPLER8x8_SURFACE surfaceType, CM_SURFACE_ADDRESS_CONTROL_MODE addressControl)
649 {
650 INSERT_PROFILER_RECORD();
651
652 CmSurface2D* currentRT = static_cast< CmSurface2D* >( surface2d );
653 if( ! currentRT ) {
654 CmAssert( 0 );
655 return CM_FAILURE;
656 }
657
658 CM_CREATESAMPLER8x8SURF_PARAM inParam;
659 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATESAMPLER8x8SURF_PARAM ) );
660 inParam.cmSurf2DHandle = currentRT;
661 inParam.cmSampler8x8Type = surfaceType;
662 inParam.sampler8x8Mode = addressControl;
663
664 int32_t result
665 = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLER8X8SURFACE,
666 &inParam, sizeof(inParam));
667
668 CHK_FAILURE_RETURN(result);
669 CHK_FAILURE_RETURN(inParam.returnValue);
670 sampler8x8SurfaceIndex = inParam.cmSurfIndexHandle;
671
672 return CM_SUCCESS;
673 }
674
CreateSampler8x8SurfaceEx(CmSurface2D * surface2d,SurfaceIndex * & sampler8x8SurfaceIndex,CM_SAMPLER8x8_SURFACE surfaceType,CM_SURFACE_ADDRESS_CONTROL_MODE addressControl,CM_FLAG * flag)675 CM_RT_API int32_t CmDevice_RT::CreateSampler8x8SurfaceEx(CmSurface2D* surface2d, SurfaceIndex* &sampler8x8SurfaceIndex, CM_SAMPLER8x8_SURFACE surfaceType, CM_SURFACE_ADDRESS_CONTROL_MODE addressControl, CM_FLAG* flag)
676 {
677 INSERT_PROFILER_RECORD();
678
679 CmSurface2D* currentRT = static_cast< CmSurface2D* >(surface2d);
680 if (!currentRT) {
681 CmAssert(0);
682 return CM_FAILURE;
683 }
684
685 CM_CREATESAMPLER8x8SURFEX_PARAM inParam;
686 CmSafeMemSet(&inParam, 0, sizeof(inParam));
687 inParam.cmSurf2DHandle = currentRT;
688 inParam.cmSampler8x8Type = surfaceType;
689 inParam.sampler8x8Mode = addressControl;
690 inParam.flag = flag;
691
692 int32_t result
693 = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLER8X8SURFACE_EX,
694 &inParam, sizeof(inParam));
695
696 CHK_FAILURE_RETURN(result);
697 CHK_FAILURE_RETURN(inParam.returnValue);
698 sampler8x8SurfaceIndex = inParam.cmSurfIndexHandle;
699
700 return CM_SUCCESS;
701 }
702
CreateSamplerSurface2DEx(CmSurface2D * surface2d,SurfaceIndex * & samplerSurface2dIndex,CM_FLAG * flag)703 CM_RT_API int32_t CmDevice_RT::CreateSamplerSurface2DEx(CmSurface2D* surface2d, SurfaceIndex* & samplerSurface2dIndex, CM_FLAG* flag)
704 {
705 INSERT_PROFILER_RECORD();
706
707 CmSurface2D* surface2dRT = static_cast< CmSurface2D* >(surface2d);
708 if (!surface2dRT) {
709 CmAssert(0);
710 return CM_INVALID_ARG_VALUE;
711 }
712
713 CM_CREATESAMPLER2DEX_PARAM inParam;
714 CmSafeMemSet(&inParam, 0, sizeof(inParam));
715 inParam.cmSurface2DHandle = surface2dRT;
716 inParam.flag = flag;
717
718 int32_t result
719 = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLERSURFACE2D_EX,
720 &inParam, sizeof(inParam));
721
722 CHK_FAILURE_RETURN(result);
723 CHK_FAILURE_RETURN(inParam.returnValue);
724 samplerSurface2dIndex = (SurfaceIndex*)inParam.samplerSurfIndexHandle;
725 return CM_SUCCESS;
726 }
727
DestroySampler8x8Surface(SurfaceIndex * & sampler8x8SurfaceIndex)728 CM_RT_API int32_t CmDevice_RT::DestroySampler8x8Surface(SurfaceIndex* &sampler8x8SurfaceIndex)
729 {
730 INSERT_PROFILER_RECORD();
731
732 CM_DESTROYSAMPLER8x8SURF_PARAM inParam;
733 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYSAMPLER8x8SURF_PARAM ) );
734 inParam.cmSurfIndexHandle = sampler8x8SurfaceIndex;
735
736 int32_t result
737 = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYSAMPLER8X8SURFACE,
738 &inParam, sizeof(inParam));
739
740 CHK_FAILURE_RETURN(result);
741 CHK_FAILURE_RETURN(inParam.returnValue);
742 sampler8x8SurfaceIndex = nullptr;
743
744 return CM_SUCCESS;
745 }
746
SetL3Config(const L3ConfigRegisterValues * registerValues)747 CM_RT_API int32_t CmDevice_RT::SetL3Config(const L3ConfigRegisterValues *registerValues)
748 {
749 INSERT_PROFILER_RECORD();
750
751 m_l3Config = *registerValues;
752
753 SetCapsInternal(CAP_L3_CONFIG, sizeof(L3ConfigRegisterValues), &m_l3Config);
754
755 return CM_SUCCESS;
756 }
757
SetSuggestedL3Config(L3_SUGGEST_CONFIG configIndex)758 CM_RT_API int32_t CmDevice_RT::SetSuggestedL3Config( L3_SUGGEST_CONFIG configIndex)
759 {
760 INSERT_PROFILER_RECORD();
761
762 //Call into UMD
763 CM_DEVICE_SETSUGGESTEDL3_PARAM setL3IndexParam;
764 CmSafeMemSet(&setL3IndexParam, 0 , sizeof(CM_DEVICE_SETSUGGESTEDL3_PARAM));
765 setL3IndexParam.l3SuggestConfig = configIndex;
766
767 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_SETSUGGESTEDL3CONFIG,
768 &setL3IndexParam,
769 sizeof(setL3IndexParam));
770
771 CHK_FAILURE_RETURN(result);
772 CHK_FAILURE_RETURN(setL3IndexParam.returnValue);
773 return CM_SUCCESS;
774 }
775
SetCaps(CM_DEVICE_CAP_NAME capName,size_t capValueSize,void * capValue)776 CM_RT_API int32_t CmDevice_RT::SetCaps(CM_DEVICE_CAP_NAME capName, size_t capValueSize, void* capValue )
777 {
778 INSERT_PROFILER_RECORD();
779
780 switch(capName)
781 {
782 case CAP_HW_THREAD_COUNT:
783 return SetCapsInternal(capName, capValueSize, capValue);
784
785 default:
786 return CM_INVALID_CAP_NAME;
787 }
788 }
789
SetCapsInternal(CM_DEVICE_CAP_NAME capName,size_t capValueSize,void * capValue)790 int32_t CmDevice_RT::SetCapsInternal(CM_DEVICE_CAP_NAME capName, size_t capValueSize, void* capValue)
791 {
792
793 //Call into UMD
794 CM_DEVICE_SETCAP_PARAM setCapParam;
795 CmSafeMemSet(&setCapParam, 0 , sizeof(setCapParam));
796 setCapParam.capName = capName;
797 setCapParam.capValueSize = capValueSize;
798 setCapParam.capValue = capValue;
799
800 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_SETCAPS,
801 &setCapParam, sizeof(setCapParam));
802
803 CHK_FAILURE_RETURN(result);
804 CHK_FAILURE_RETURN(setCapParam.returnValue);
805 return CM_SUCCESS;
806 }
807
CreateSamplerSurface2D(CmSurface2D * surface2d,SurfaceIndex * & samplerSurface2dIndex)808 CM_RT_API int32_t CmDevice_RT::CreateSamplerSurface2D(CmSurface2D* surface2d, SurfaceIndex* & samplerSurface2dIndex)
809 {
810 INSERT_PROFILER_RECORD();
811
812 CmSurface2D* surface2dRT = static_cast< CmSurface2D* >( surface2d );
813 if( ! surface2dRT ) {
814 CmAssert( 0 );
815 return CM_FAILURE;
816 }
817
818 CM_CREATESAMPLER2D_PARAM inParam;
819 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATESAMPLER2D_PARAM ) );
820 inParam.cmSurface2DHandle = surface2dRT;
821
822 int32_t result
823 = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLERSURFACE2D,
824 &inParam, sizeof(inParam));
825
826 CHK_FAILURE_RETURN(result);
827 CHK_FAILURE_RETURN(inParam.returnValue);
828 samplerSurface2dIndex = (SurfaceIndex* )inParam.samplerSurfIndexHandle;
829 return CM_SUCCESS;
830 }
831
CreateSamplerSurface2DUP(CmSurface2DUP * surface2dUP,SurfaceIndex * & samplerSurface2dUPIndex)832 CM_RT_API int32_t CmDevice_RT::CreateSamplerSurface2DUP(CmSurface2DUP* surface2dUP, SurfaceIndex* & samplerSurface2dUPIndex)
833 {
834 INSERT_PROFILER_RECORD();
835
836 CM_CREATESAMPLER2DUP_PARAM inParam;
837 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATESAMPLER2DUP_PARAM ) );
838 inParam.cmSurface2DHandle = surface2dUP;
839
840 int32_t result
841 = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLERSURFACE2DUP,
842 &inParam, sizeof(inParam));
843
844 CHK_FAILURE_RETURN(result);
845 CHK_FAILURE_RETURN(inParam.returnValue);
846 samplerSurface2dUPIndex = (SurfaceIndex* )inParam.samplerSurfIndexHandle;
847 return CM_SUCCESS;
848 }
849
CreateSamplerSurface3D(CmSurface3D * surface3d,SurfaceIndex * & samplerSurface3dIndex)850 CM_RT_API int32_t CmDevice_RT::CreateSamplerSurface3D(CmSurface3D* surface3d, SurfaceIndex* & samplerSurface3dIndex)
851 {
852 INSERT_PROFILER_RECORD();
853
854 CM_CREATESAMPLER3D_PARAM inParam;
855 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATESAMPLER3D_PARAM ) );
856 inParam.cmSurface3DHandle = surface3d;
857
858 int32_t result
859 = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESAMPLERSURFACE3D,
860 &inParam, sizeof(inParam));
861
862 CHK_FAILURE_RETURN(result);
863 CHK_FAILURE_RETURN(inParam.returnValue);
864 samplerSurface3dIndex = (SurfaceIndex* )inParam.samplerSurfIndexHandle;
865 return CM_SUCCESS;
866 }
867
DestroySamplerSurface(SurfaceIndex * & samplerSurfaceIndex)868 CM_RT_API int32_t CmDevice_RT::DestroySamplerSurface(SurfaceIndex* & samplerSurfaceIndex)
869 {
870 INSERT_PROFILER_RECORD();
871
872 CM_DESTROYSAMPLERSURF_PARAM inParam;
873 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYSAMPLERSURF_PARAM ) );
874 inParam.samplerSurfIndexHandle = samplerSurfaceIndex;
875
876 int32_t result = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYSAMPLERSURFACE,
877 &inParam, sizeof(inParam));
878
879 CHK_FAILURE_RETURN(result);
880 CHK_FAILURE_RETURN(inParam.returnValue);
881
882 return CM_SUCCESS;
883 }
884
DestroySurface(CmSurface3D * & surface3d)885 CM_RT_API int32_t CmDevice_RT:: DestroySurface( CmSurface3D* &surface3d)
886 {
887 INSERT_PROFILER_RECORD();
888
889 return m_surfaceManager->DestroySurface3D(surface3d);
890 }
891
CheckDdiVersionSupported(const uint32_t ddiVersion)892 int32_t CmDevice_RT::CheckDdiVersionSupported(const uint32_t ddiVersion)
893 {
894 if( ( ddiVersion >= CM_DDI_7_2 ))
895 {
896 return CM_SUCCESS;
897 }
898 else
899 {
900 return CM_UMD_DRIVER_NOT_SUPPORTED;
901 }
902 }
903
InitPrintBuffer(size_t size)904 CM_RT_API int32_t CmDevice_RT::InitPrintBuffer(size_t size)
905 {
906 INSERT_PROFILER_RECORD();
907
908 CM_DEVICE_INIT_PRINT_BUFFER_PARAM initPrintBufferParam;
909 CmSafeMemSet(&initPrintBufferParam, 0, sizeof(CM_DEVICE_INIT_PRINT_BUFFER_PARAM));
910 initPrintBufferParam.printBufferSize = (uint32_t)size;
911
912 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_INIT_PRINT_BUFFER,
913 &initPrintBufferParam,
914 sizeof(initPrintBufferParam));
915
916 CHK_FAILURE_RETURN(hr);
917 CHK_FAILURE_RETURN(initPrintBufferParam.returnValue);
918
919 return CM_SUCCESS;
920 }
921
922 //*-----------------------------------------------------------------------------
923 //| Purpose: Flush the print buffer and dump it on the file
924 //| Returns: result of operation.
925 //*-----------------------------------------------------------------------------
FlushPrintBufferIntoFile(const char * filename)926 CM_RT_API int32_t CmDevice_RT::FlushPrintBufferIntoFile(const char *filename)
927 {
928 INSERT_PROFILER_RECORD();
929
930 return FlushPrintBufferInternal(filename);
931 }
932
933 //*-----------------------------------------------------------------------------
934 //| Purpose: Flush the print buffer and dump it on stdout
935 //| Returns: result of operation.
936 //*-----------------------------------------------------------------------------
FlushPrintBuffer()937 CM_RT_API int32_t CmDevice_RT::FlushPrintBuffer()
938 {
939 INSERT_PROFILER_RECORD();
940
941 return FlushPrintBufferInternal(nullptr);
942 }
943
944 //*-----------------------------------------------------------------------------
945 //| Purpose: Internal function to flush print buffer on stdout or file.
946 //| Returns: result of operation.
947 //*-----------------------------------------------------------------------------
FlushPrintBufferInternal(const char * filename)948 int32_t CmDevice_RT::FlushPrintBufferInternal(const char *filename)
949 {
950 INSERT_PROFILER_RECORD();
951
952 CM_DEVICE_FLUSH_PRINT_BUFFER_PARAM flushPrintBufferParam;
953 CmSafeMemSet(&flushPrintBufferParam, 0, sizeof(CM_DEVICE_FLUSH_PRINT_BUFFER_PARAM));
954 flushPrintBufferParam.fileName = filename;
955
956 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_FLUSH_PRINT_BUFFER,
957 &flushPrintBufferParam,
958 sizeof(flushPrintBufferParam));
959
960 CHK_FAILURE_RETURN(hr);
961 CHK_FAILURE_RETURN(flushPrintBufferParam.returnValue);
962
963 return CM_SUCCESS;
964 }
965
CreateVebox(CmVebox * & vebox)966 CM_RT_API int32_t CmDevice_RT::CreateVebox( CmVebox* & vebox )
967 {
968 INSERT_PROFILER_RECORD();
969
970 CM_CREATEVEBOX_PARAM inParam;
971 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATEVEBOX_PARAM ) );
972
973 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CREATEVEBOX,
974 &inParam, sizeof(inParam));
975
976 CHK_FAILURE_RETURN(hr);
977 CHK_FAILURE_RETURN(inParam.returnValue);
978 vebox = (CmVebox *)inParam.cmVeboxHandle;
979 return CM_SUCCESS;
980 }
981
DestroyVebox(CmVebox * & vebox)982 CM_RT_API int32_t CmDevice_RT::DestroyVebox( CmVebox* & vebox )
983 {
984 INSERT_PROFILER_RECORD();
985
986 CM_DESTROYVEBOX_PARAM inParam;
987 CmSafeMemSet( &inParam, 0, sizeof( inParam ) );
988 inParam.cmVeboxHandle = vebox;
989
990 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYVEBOX,
991 &inParam, sizeof(inParam));
992
993 CHK_FAILURE_RETURN(hr);
994 CHK_FAILURE_RETURN(inParam.returnValue);
995 vebox = nullptr;
996 return CM_SUCCESS;
997 }
998
CreateBufferSVM(uint32_t size,void * & sysMem,uint32_t accessFlag,CmBufferSVM * & buffer)999 CM_RT_API int32_t CmDevice_RT::CreateBufferSVM(uint32_t size, void* &sysMem, uint32_t accessFlag, CmBufferSVM* & buffer)
1000 {
1001 INSERT_PROFILER_RECORD();
1002
1003 return m_surfaceManager->CreateBufferSVM(size, sysMem, accessFlag, buffer);
1004 }
1005
DestroyBufferSVM(CmBufferSVM * & buffer)1006 CM_RT_API int32_t CmDevice_RT::DestroyBufferSVM( CmBufferSVM* &buffer)
1007 {
1008 INSERT_PROFILER_RECORD();
1009
1010 return m_surfaceManager->DestroyBufferSVM(buffer);
1011 }
1012
CreateBufferStateless(size_t size,uint32_t option,void * sysMem,CmBufferStateless * & buffer)1013 CM_RT_API int32_t CmDevice_RT::CreateBufferStateless(size_t size,
1014 uint32_t option,
1015 void *sysMem,
1016 CmBufferStateless *&buffer)
1017 {
1018 INSERT_PROFILER_RECORD();
1019
1020 return m_surfaceManager->CreateBufferStateless(size, option, sysMem, buffer);
1021 }
1022
DestroyBufferStateless(CmBufferStateless * & buffer)1023 CM_RT_API int32_t CmDevice_RT::DestroyBufferStateless(CmBufferStateless* &buffer)
1024 {
1025 INSERT_PROFILER_RECORD();
1026
1027 return m_surfaceManager->DestroyBufferStateless(buffer);
1028 }
1029
CreateSurface2DAlias(CmSurface2D * originalSurface,SurfaceIndex * & aliasIndex)1030 CM_RT_API int32_t CmDevice_RT::CreateSurface2DAlias(CmSurface2D* originalSurface, SurfaceIndex* &aliasIndex)
1031 {
1032 INSERT_PROFILER_RECORD();
1033
1034 CM_DEVICE_CREATE_SURF2D_ALIAS_PARAM inParam;
1035 CmSafeMemSet( &inParam, 0, sizeof(inParam) );
1036
1037 inParam.cmSurface2DHandle = originalSurface;
1038 inParam.surfaceIndexHandle = aliasIndex;
1039
1040 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CREATESURFACE2D_ALIAS,
1041 &inParam, sizeof(inParam));
1042
1043 CHK_FAILURE_RETURN(hr);
1044 CHK_FAILURE_RETURN(inParam.returnValue);
1045 aliasIndex = (SurfaceIndex*)inParam.surfaceIndexHandle;
1046
1047 return CM_SUCCESS;
1048 }
1049
CreateBufferAlias(CmBuffer * originalBuffer,SurfaceIndex * & aliasIndex)1050 CM_RT_API int32_t CmDevice_RT::CreateBufferAlias(CmBuffer *originalBuffer, SurfaceIndex* &aliasIndex)
1051 {
1052 INSERT_PROFILER_RECORD();
1053
1054 CM_DEVICE_CREATE_BUFFER_ALIAS_PARAM inParam;
1055 CmSafeMemSet( &inParam, 0, sizeof(inParam) );
1056
1057 inParam.cmBufferHandle = originalBuffer;
1058 inParam.surfaceIndexHandle = aliasIndex;
1059
1060 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CREATEBUFFER_ALIAS,
1061 &inParam, sizeof(inParam));
1062
1063 CHK_FAILURE_RETURN(hr);
1064 CHK_FAILURE_RETURN(inParam.returnValue);
1065 aliasIndex = (SurfaceIndex*)inParam.surfaceIndexHandle;
1066
1067 return CM_SUCCESS;
1068 }
1069
1070 //*-----------------------------------------------------------------------------
1071 //| Purpose: Duplicate the kernel member values
1072 //| Arguments :
1073 //| destKernel [in/out] pointer to output kernel, must be nullptr
1074 //| srcKernel [in] pointer to input kernel
1075 //|
1076 //| Returns: Result of the operation.
1077 //*-----------------------------------------------------------------------------
CloneKernel(CmKernel * & destKernel,CmKernel * srcKernel)1078 CM_RT_API int32_t CmDevice_RT::CloneKernel( CmKernel * &destKernel, CmKernel *srcKernel )
1079 {
1080 INSERT_PROFILER_RECORD();
1081
1082 CM_CLONE_KERNEL_PARAM inParam;
1083 CmSafeMemSet( &inParam, 0, sizeof( CM_CLONE_KERNEL_PARAM ) );
1084 inParam.cmKernelHandleSrc = srcKernel;
1085 inParam.cmKernelHandleDest = destKernel;
1086
1087 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_CLONEKERNEL,
1088 &inParam, sizeof(inParam));
1089
1090 CHK_FAILURE_RETURN(hr);
1091 CHK_FAILURE_RETURN(inParam.returnValue);
1092 destKernel = (CmKernel *)inParam.cmKernelHandleDest;
1093
1094 return CM_SUCCESS;
1095 }
1096
CreateHevcVmeSurfaceG10(CmSurface2D * currentSurface,CmSurface2D ** forwardSurfaceArray,CmSurface2D ** backwardSurfaceArray,const uint32_t surfaceCountForward,const uint32_t surfaceCountBackward,SurfaceIndex * & vmeSurfaceIndex)1097 CM_RT_API int32_t CmDevice_RT::CreateHevcVmeSurfaceG10(CmSurface2D* currentSurface, CmSurface2D** forwardSurfaceArray, CmSurface2D** backwardSurfaceArray, const uint32_t surfaceCountForward, const uint32_t surfaceCountBackward, SurfaceIndex* & vmeSurfaceIndex)
1098 {
1099 INSERT_PROFILER_RECORD();
1100
1101 return CreateVmeSurface( currentSurface, forwardSurfaceArray, backwardSurfaceArray, surfaceCountForward, surfaceCountBackward, vmeSurfaceIndex, CM_FN_CMDEVICE_CREATEHEVCVMESURFACEG10 );
1102 }
1103
DestroyHevcVmeSurfaceG10(SurfaceIndex * & vmeSurfaceIndex)1104 CM_RT_API int32_t CmDevice_RT::DestroyHevcVmeSurfaceG10(SurfaceIndex* & vmeSurfaceIndex)
1105 {
1106 INSERT_PROFILER_RECORD();
1107
1108 return DestroyVmeSurface( vmeSurfaceIndex );
1109 }
1110
CreateVmeSurface(CmSurface2D * currentSurface,CmSurface2D ** forwardSurfaceArray,CmSurface2D ** backwardSurfaceArray,const uint32_t surfaceCountForward,const uint32_t surfaceCountBackward,SurfaceIndex * & vmeSurfaceIndex,CM_FUNCTION_ID functionName)1111 int32_t CmDevice_RT::CreateVmeSurface( CmSurface2D* currentSurface, CmSurface2D** forwardSurfaceArray, CmSurface2D** backwardSurfaceArray, const uint32_t surfaceCountForward, const uint32_t surfaceCountBackward, SurfaceIndex* & vmeSurfaceIndex, CM_FUNCTION_ID functionName)
1112 {
1113 if ( currentSurface == nullptr )
1114 {
1115 CmAssert( 0 );
1116 return CM_NULL_POINTER;
1117 }
1118
1119 CM_CREATEVMESURFACE_PARAM inParam;
1120 CmSafeMemSet( &inParam, 0, sizeof( CM_CREATEVMESURFACE_PARAM ) );
1121 inParam.cmCurSurfHandle = currentSurface;
1122 inParam.cmForwardSurfArray = forwardSurfaceArray;
1123 inParam.cmBackwardSurfArray = backwardSurfaceArray;
1124 inParam.forwardSurfCount = surfaceCountForward;
1125 inParam.backwardSurfCount = surfaceCountBackward;
1126
1127 int32_t result = OSALExtensionExecute(functionName,
1128 &inParam, sizeof(inParam));
1129
1130 CHK_FAILURE_RETURN(result);
1131 CHK_FAILURE_RETURN(inParam.returnValue);
1132
1133 vmeSurfaceIndex = ( SurfaceIndex* )inParam.cmVmeSurfIndexHandle;
1134
1135 return CM_SUCCESS;
1136 }
1137
DestroyVmeSurface(SurfaceIndex * & vmeSurfaceIndex)1138 int32_t CmDevice_RT::DestroyVmeSurface( SurfaceIndex* & vmeSurfaceIndex )
1139 {
1140 //Call into driver
1141 CM_DESTROYVMESURFACE_PARAM inParam;
1142 CmSafeMemSet( &inParam, 0, sizeof( CM_DESTROYVMESURFACE_PARAM ) );
1143 inParam.cmVmeSurfIndexHandle = ( void *)vmeSurfaceIndex;
1144
1145 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_DESTROYVMESURFACE,
1146 &inParam, sizeof(inParam));
1147
1148 CHK_FAILURE_RETURN(hr);
1149 CHK_FAILURE_RETURN(inParam.returnValue);
1150 vmeSurfaceIndex = nullptr;
1151
1152 return CM_SUCCESS;
1153 }
1154
GetVISAVersion(uint32_t & majorVersion,uint32_t & minorVersion)1155 CM_RT_API int32_t CmDevice_RT::GetVISAVersion(uint32_t& majorVersion, uint32_t& minorVersion)
1156 {
1157 INSERT_PROFILER_RECORD();
1158
1159 CM_DEVICE_GET_VISA_VERSION_PARAM inParam;
1160 CmSafeMemSet(&inParam, 0, sizeof(CM_DEVICE_GET_VISA_VERSION_PARAM));
1161
1162 int32_t hr = OSALExtensionExecute(CM_FN_CMDEVICE_GETVISAVERSION,
1163 &inParam, sizeof(inParam));
1164
1165 CHK_FAILURE_RETURN(hr);
1166 CHK_FAILURE_RETURN(inParam.returnValue);
1167 majorVersion = inParam.majorVersion;
1168 minorVersion = inParam.minorVersion;
1169 return CM_SUCCESS;
1170 }
1171
1172
1173 CM_RT_API int32_t
CreateSurface2DStateless(uint32_t width,uint32_t height,uint32_t & pitch,CmSurface2DStateless * & pSurface)1174 CmDevice_RT::CreateSurface2DStateless(uint32_t width,
1175 uint32_t height,
1176 uint32_t &pitch,
1177 CmSurface2DStateless *&pSurface)
1178 {
1179 return CM_NOT_IMPLEMENTED;
1180 }
1181
DestroySurface2DStateless(CmSurface2DStateless * & pSurface)1182 CM_RT_API int32_t CmDevice_RT::DestroySurface2DStateless(CmSurface2DStateless *&pSurface)
1183 {
1184 return CM_NOT_IMPLEMENTED;
1185 }
1186