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 //!
23 //! \file      cm_rt_api_os.h
24 //! \brief     Contains Linux Specific APIs and Definitions for CM
25 //!
26 
27 #ifndef __CM_RT_API_OS_H__
28 #define __CM_RT_API_OS_H__
29 
30 class CmSurface2D
31 {
32 public:
33     CM_RT_API virtual INT GetIndex( SurfaceIndex*& pIndex ) = 0;
34 
35     CM_RT_API virtual INT ReadSurface( unsigned char* pSysMem, CmEvent* pEvent, UINT64 sysMemSize = 0xFFFFFFFFFFFFFFFFULL ) = 0;
36     CM_RT_API virtual INT WriteSurface( const unsigned char* pSysMem, CmEvent* pEvent, UINT64 sysMemSize = 0xFFFFFFFFFFFFFFFFULL ) = 0;
37     CM_RT_API virtual INT ReadSurfaceStride( unsigned char* pSysMem, CmEvent* pEvent, const UINT stride, UINT64 sysMemSize = 0xFFFFFFFFFFFFFFFFULL ) = 0;
38     CM_RT_API virtual INT WriteSurfaceStride( const unsigned char* pSysMem, CmEvent* pEvent, const UINT stride, UINT64 sysMemSize = 0xFFFFFFFFFFFFFFFFULL ) = 0;
39     CM_RT_API virtual INT InitSurface(const DWORD initValue, CmEvent* pEvent, unsigned int useGPU = 0 ) = 0;
40 
41     CM_RT_API virtual INT GetVaSurfaceID( VASurfaceID  &iVASurface) = 0;
42 
43     CM_RT_API virtual INT ReadSurfaceHybridStrides( unsigned char* pSysMem, CmEvent* pEvent, const UINT iWidthStride, const UINT iHeightStride, UINT64 sysMemSize = 0xFFFFFFFFFFFFFFFFULL, UINT uiOption = 0 ) = 0;
44     CM_RT_API virtual INT WriteSurfaceHybridStrides( const unsigned char* pSysMem, CmEvent* pEvent, const UINT iWidthStride, const UINT iHeightStride, UINT64 sysMemSize = 0xFFFFFFFFFFFFFFFFULL, UINT uiOption = 0 ) = 0;
45     CM_RT_API virtual INT SelectMemoryObjectControlSetting(MEMORY_OBJECT_CONTROL option) = 0;
46     CM_RT_API virtual INT SetProperty(CM_FRAME_TYPE frameType) = 0;
47     CM_RT_API virtual INT SetSurfaceStateParam( SurfaceIndex *pSurfIndex, const CM_SURFACE2D_STATE_PARAM *pSSParam ) = 0;
48 protected:
~CmSurface2D()49     ~CmSurface2D(){}
50 };
51 
52 class CmDevice
53 {
54 public:
55 
56     CM_RT_API virtual INT CreateBuffer(UINT size, CmBuffer* & pSurface )=0;
57     CM_RT_API virtual INT CreateSurface2D(UINT width, UINT height, CM_SURFACE_FORMAT format, CmSurface2D* & pSurface ) = 0;
58     CM_RT_API virtual INT CreateSurface3D(UINT width, UINT height, UINT depth, CM_SURFACE_FORMAT format, CmSurface3D* & pSurface ) = 0;
59 
60     CM_RT_API virtual INT CreateSurface2D( VASurfaceID iVASurface, CmSurface2D* & pSurface ) = 0;
61     CM_RT_API virtual INT CreateSurface2D( VASurfaceID* iVASurface, const UINT surfaceCount, CmSurface2D** pSurface ) = 0;
62 
63     CM_RT_API virtual INT DestroySurface( CmBuffer* & pSurface) = 0;
64     CM_RT_API virtual INT DestroySurface( CmSurface2D* & pSurface) = 0;
65     CM_RT_API virtual INT DestroySurface( CmSurface3D* & pSurface) = 0;
66 
67     CM_RT_API virtual INT CreateQueue( CmQueue* & pQueue) = 0;
68     CM_RT_API virtual INT LoadProgram( void* pCommonISACode, const UINT size, CmProgram*& pProgram, const char* options = nullptr ) = 0;
69     CM_RT_API virtual INT CreateKernel( CmProgram* pProgram, const char* kernelName, CmKernel* & pKernel, const char* options = nullptr) = 0;
70     CM_RT_API virtual INT CreateKernel( CmProgram* pProgram, const char* kernelName, const void * fncPnt, CmKernel* & pKernel, const char* options = nullptr) = 0;
71     CM_RT_API virtual INT CreateSampler( const CM_SAMPLER_STATE & sampleState, CmSampler* & pSampler ) = 0;
72 
73     CM_RT_API virtual INT DestroyKernel( CmKernel*& pKernel) = 0;
74     CM_RT_API virtual INT DestroySampler( CmSampler*& pSampler ) = 0;
75     CM_RT_API virtual INT DestroyProgram( CmProgram*& pProgram ) = 0;
76     CM_RT_API virtual INT DestroyThreadSpace( CmThreadSpace* & pTS ) = 0;
77 
78     CM_RT_API virtual INT CreateTask(CmTask *& pTask)=0;
79     CM_RT_API virtual INT DestroyTask(CmTask*& pTask)=0;
80 
81     CM_RT_API virtual INT GetCaps(CM_DEVICE_CAP_NAME capName, size_t& capValueSize, void* pCapValue ) = 0;
82 
83     CM_RT_API virtual INT CreateThreadSpace( UINT width, UINT height, CmThreadSpace* & pTS ) = 0;
84 
85     CM_RT_API virtual INT CreateBufferUP(UINT size, void* pSystMem, CmBufferUP* & pSurface )=0;
86     CM_RT_API virtual INT DestroyBufferUP( CmBufferUP* & pSurface) = 0;
87 
88     CM_RT_API virtual INT GetSurface2DInfo( UINT width, UINT height, CM_SURFACE_FORMAT format, UINT & pitch, UINT & physicalSize)= 0;
89     CM_RT_API virtual INT CreateSurface2DUP( UINT width, UINT height, CM_SURFACE_FORMAT format, void* pSysMem, CmSurface2DUP* & pSurface )= 0;
90     CM_RT_API virtual INT DestroySurface2DUP( CmSurface2DUP* & pSurface) = 0;
91 
92     CM_RT_API virtual INT CreateVmeSurfaceG7_5 ( CmSurface2D* pCurSurface, CmSurface2D** pForwardSurface, CmSurface2D** pBackwardSurface, const UINT surfaceCountForward, const UINT surfaceCountBackward, SurfaceIndex* & pVmeIndex )=0;
93     CM_RT_API virtual INT DestroyVmeSurfaceG7_5( SurfaceIndex* & pVmeIndex ) = 0;
94     CM_RT_API virtual INT CreateSampler8x8(const CM_SAMPLER_8X8_DESCR  & smplDescr, CmSampler8x8*& psmplrState)=0;
95     CM_RT_API virtual INT DestroySampler8x8( CmSampler8x8*& pSampler )=0;
96     CM_RT_API virtual INT CreateSampler8x8Surface(CmSurface2D* p2DSurface, SurfaceIndex* & pDIIndex, CM_SAMPLER8x8_SURFACE surf_type = CM_VA_SURFACE, CM_SURFACE_ADDRESS_CONTROL_MODE address_mode = CM_SURFACE_CLAMP )=0;
97     CM_RT_API virtual INT DestroySampler8x8Surface(SurfaceIndex* & pDIIndex)=0;
98 
99     CM_RT_API virtual INT CreateThreadGroupSpace( UINT thrdSpaceWidth, UINT thrdSpaceHeight, UINT grpSpaceWidth, UINT grpSpaceHeight, CmThreadGroupSpace*& pTGS ) = 0;
100     CM_RT_API virtual INT DestroyThreadGroupSpace(CmThreadGroupSpace*& pTGS) = 0;
101     CM_RT_API virtual INT SetL3Config(const L3ConfigRegisterValues *l3_c) = 0;
102     CM_RT_API virtual INT SetSuggestedL3Config( L3_SUGGEST_CONFIG l3_s_c) = 0;
103 
104     CM_RT_API virtual INT SetCaps(CM_DEVICE_CAP_NAME capName, size_t capValueSize, void* pCapValue) = 0;
105 
106     CM_RT_API virtual INT CreateSamplerSurface2D(CmSurface2D* p2DSurface, SurfaceIndex* & pSamplerSurfaceIndex) = 0;
107     CM_RT_API virtual INT CreateSamplerSurface3D(CmSurface3D* p3DSurface, SurfaceIndex* & pSamplerSurfaceIndex) = 0;
108     CM_RT_API virtual INT DestroySamplerSurface(SurfaceIndex* & pSamplerSurfaceIndex) = 0;
109 
110     CM_RT_API virtual INT InitPrintBuffer(size_t printbufsize = 1048576) = 0;
111     CM_RT_API virtual INT FlushPrintBuffer() = 0;
112 
113     CM_RT_API virtual INT CreateVebox( CmVebox* & pVebox ) = 0;
114     CM_RT_API virtual INT DestroyVebox( CmVebox* & pVebox ) = 0;
115 
116     CM_RT_API virtual INT GetVaDpy(VADisplay* & pva_dpy) = 0;
117     CM_RT_API virtual INT CreateVaSurface2D( UINT width, UINT height, CM_SURFACE_FORMAT format, VASurfaceID & iVASurface, CmSurface2D* & pSurface) = 0;
118 
119     CM_RT_API virtual INT CreateBufferSVM(UINT size, void* & pSystMem, uint32_t accessFlag, CmBufferSVM* & pSurface ) = 0;
120     CM_RT_API virtual INT DestroyBufferSVM( CmBufferSVM* & pSurface) = 0;
121     CM_RT_API virtual INT CreateSamplerSurface2DUP(CmSurface2DUP* p2DUPSurface, SurfaceIndex* & pSamplerSurfaceIndex) = 0;
122 
123     CM_RT_API virtual INT CloneKernel( CmKernel * &pKernelDest, CmKernel * pKernelSrc ) = 0;
124 
125     CM_RT_API virtual INT CreateSurface2DAlias(CmSurface2D* p2DSurface, SurfaceIndex* &aliasSurfaceIndex) = 0;
126 
127     CM_RT_API virtual INT CreateHevcVmeSurfaceG10 ( CmSurface2D* pCurSurface, CmSurface2D** pForwardSurface, CmSurface2D** pBackwardSurface, const UINT surfaceCountForward, const UINT surfaceCountBackward, SurfaceIndex* & pVmeIndex )=0;
128     CM_RT_API virtual INT DestroyHevcVmeSurfaceG10( SurfaceIndex* & pVmeIndex )=0;
129     CM_RT_API virtual INT CreateSamplerEx( const CM_SAMPLER_STATE_EX & sampleState, CmSampler* & pSampler ) = 0;
130     CM_RT_API virtual INT FlushPrintBufferIntoFile(const char *filename) = 0;
131     CM_RT_API virtual INT CreateThreadGroupSpaceEx(UINT thrdSpaceWidth, UINT thrdSpaceHeight, UINT thrdSpaceDepth, UINT grpSpaceWidth, UINT grpSpaceHeight, UINT grpSpaceDepth, CmThreadGroupSpace*& pTGS) = 0;
132 
133     CM_RT_API virtual INT CreateSampler8x8SurfaceEx(CmSurface2D* p2DSurface, SurfaceIndex* & pDIIndex, CM_SAMPLER8x8_SURFACE surf_type = CM_VA_SURFACE, CM_SURFACE_ADDRESS_CONTROL_MODE address_mode = CM_SURFACE_CLAMP, CM_FLAG* pFlag = nullptr) = 0;
134     CM_RT_API virtual INT CreateSamplerSurface2DEx(CmSurface2D* p2DSurface, SurfaceIndex* & pSamplerSurfaceIndex, CM_FLAG* pFlag = nullptr) = 0;
135     CM_RT_API virtual INT CreateBufferAlias(CmBuffer *pBuffer, SurfaceIndex* &pAliasIndex) = 0;
136 
137     CM_RT_API virtual INT SetVmeSurfaceStateParam(SurfaceIndex* pVmeIndex, CM_VME_SURFACE_STATE_PARAM *pSSParam) = 0;
138 
139     CM_RT_API virtual int32_t GetVISAVersion(uint32_t& majorVersion, uint32_t& minorVersion) = 0;
140     CM_RT_API virtual int32_t CreateQueueEx(CmQueue *&pQueue, CM_QUEUE_CREATE_OPTION QueueCreateOption = CM_DEFAULT_QUEUE_CREATE_OPTION) = 0;
141 
142     CM_RT_API virtual INT CreateBufferStateless(size_t size,
143                                                 uint32_t option,
144                                                 void *sysMem,
145                                                 CmBufferStateless *&pBufferStateless) = 0;
146     CM_RT_API virtual INT DestroyBufferStateless(CmBufferStateless *&pSurface) = 0;
147 
148     CM_RT_API virtual int32_t DispatchTask() = 0;
149 
150     CM_RT_API virtual INT CreateSurface2DStateless(uint32_t width,
151                                                    uint32_t height,
152                                                    uint32_t &pitch,
153                                                    CmSurface2DStateless *&pSurface) = 0;
154 
155     CM_RT_API virtual int32_t DestroySurface2DStateless(CmSurface2DStateless *&pSurface) = 0;
156 
157     //adding new functions in the bottom is a must
158 protected:
~CmDevice()159     ~CmDevice(){}
160 };
161 
162 #ifndef __SURFACE_SAMPLER_INDEX_DEFINED__
163 #define __SURFACE_SAMPLER_INDEX_DEFINED__
164 
165 class SurfaceIndex
166 {
167 public:
SurfaceIndex()168     CM_NOINLINE SurfaceIndex() { index = 0; };
SurfaceIndex(const SurfaceIndex & _src)169     CM_NOINLINE SurfaceIndex(const SurfaceIndex& _src) { index = _src.index; };
SurfaceIndex(const unsigned int & _n)170     CM_NOINLINE SurfaceIndex(const unsigned int& _n) { index = _n; };
171     CM_NOINLINE SurfaceIndex& operator = (const unsigned int& _n) { this->index = _n; return *this; };
172     CM_NOINLINE SurfaceIndex& operator + (const unsigned int& _n) { this->index += _n; return *this; };
get_data(void)173     virtual unsigned int get_data(void) { return index; };
174 
~SurfaceIndex()175     virtual ~SurfaceIndex(){};
176 private:
177     unsigned int index;
178     unsigned char extra_byte; // an extra byte to align the object size among OSes
179 };
180 
181 class SamplerIndex
182 {
183 public:
SamplerIndex()184     CM_NOINLINE SamplerIndex() { index = 0; };
SamplerIndex(SamplerIndex & _src)185     CM_NOINLINE SamplerIndex(SamplerIndex& _src) { index = _src.get_data(); };
SamplerIndex(const unsigned int & _n)186     CM_NOINLINE SamplerIndex(const unsigned int& _n) { index = _n; };
187     CM_NOINLINE SamplerIndex& operator = (const unsigned int& _n) { this->index = _n; return *this; };
get_data(void)188     virtual unsigned int get_data(void) { return index; };
189 
~SamplerIndex()190     virtual ~SamplerIndex(){};
191 private:
192     unsigned int index;
193     unsigned char extra_byte; // an extra byte to align the object size among OSes
194 };
195 
196 #endif /* __SURFACE_SAMPLER_INDEX_DEFINED__ */
197 typedef enum _AdapterInfoType
198 {
199     Description,                    //    char Description[ 256 ];
200     VendorId,                       //    uint32_t VendorId;
201     DeviceId,                       //    uint32_t DeviceId;
202     SubSysId,                       //    uint32_t SubSysId;
203     Revision,                       //    uint32_t Revision;
204     DedicatedVideoMemory,           //    uint32_t DedicatedVideoMemory;
205     DedicatedSystemMemory,          //    uint32_t DedicatedSystemMemory;
206     SharedSystemMemory,             //    uint32_t SharedSystemMemory;
207     MaxThread,                      //    uint32_t hardware thread count
208     EuNumber,                       //    uint32_t EU count
209     TileNumber,                     //    uint32_t Tile count
210     Reserved                        //    uint32_t
211 } AdapterInfoType;
212 
213 EXTERN_C CM_RT_API int32_t GetCmSupportedAdapters(uint32_t& count);
214 EXTERN_C CM_RT_API int32_t QueryCmAdapterInfo(uint32_t AdapterIndex, AdapterInfoType infoName, void *info, uint32_t infoSize, uint32_t *OutInfoSize);
215 EXTERN_C CM_RT_API int32_t CreateCmDeviceFromAdapter(CmDevice* &pCmDev, uint32_t& version, uint32_t AdapterIndex, uint32_t DevCreateOption = 0);
216 
217 EXTERN_C CM_RT_API INT CreateCmDevice(CmDevice* &device, UINT& version, VADisplay vaDisplay = nullptr);
218 EXTERN_C CM_RT_API INT CreateCmDeviceEx(CmDevice* &device, UINT& version, VADisplay vaDisplay, UINT DevCreateOption = CM_DEVICE_CREATE_OPTION_DEFAULT);
219 
220 #endif //__CM_RT_API_OS_H__
221