@@ -43,6 +43,8 @@ cl_int (CL_API_CALL *web_clGetPlatformIDs)(cl_uint num_entries, cl_platform_id*
43
43
44
44
cl_int (CL_API_CALL *web_clGetPlatformInfo)(cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret);
45
45
46
+ cl_int (CL_API_CALL *web_clUnloadCompiler)(cl_platform_id platform);
47
+
46
48
cl_int (CL_API_CALL *web_clUnloadPlatformCompiler)(cl_platform_id platform);
47
49
48
50
/* Device APIs */
@@ -79,6 +81,8 @@ cl_int (CL_API_CALL *web_clReleaseMemObject)(cl_mem memobj);
79
81
80
82
cl_int (CL_API_CALL *web_clGetImageInfo)(cl_mem image, cl_image_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret);
81
83
84
+ cl_mem (CL_API_CALL *web_clCreateImage2D)(cl_context context, cl_mem_flags flags, const cl_image_format* image_format, size_t image_width, size_t image_height, size_t image_row_pitch, void * host_ptr, cl_int* errcode_ret);
85
+
82
86
cl_mem (CL_API_CALL *web_clCreateImage)(cl_context context, cl_mem_flags flags, const cl_image_format* image_format, const cl_image_desc* image_desc, void * host_ptr, cl_int* errcode_ret);
83
87
84
88
cl_int (CL_API_CALL *web_clGetSupportedImageFormats)(cl_context context, cl_mem_flags flags, cl_mem_object_type image_type, cl_uint num_entries, cl_image_format* image_formats, cl_uint* num_image_formats);
@@ -145,8 +149,12 @@ cl_int (CL_API_CALL *web_clEnqueueWriteImage)(cl_command_queue command_queue, cl
145
149
146
150
cl_int (CL_API_CALL *web_clEnqueueCopyBuffer)(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, size_t src_offset, size_t dst_offset, size_t size, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event);
147
151
152
+ cl_int (CL_API_CALL *web_clEnqueueBarrier)(cl_command_queue command_queue);
153
+
148
154
cl_int (CL_API_CALL *web_clEnqueueBarrierWithWaitList)(cl_command_queue command_queue, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event);
149
155
156
+ cl_int (CL_API_CALL *web_clEnqueueMarker)(cl_command_queue command_queue, cl_event* event);
157
+
150
158
cl_int (CL_API_CALL *web_clEnqueueMarkerWithWaitList)(cl_command_queue command_queue, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event);
151
159
152
160
cl_int (CL_API_CALL *web_clEnqueueTask)(cl_command_queue command_queue, cl_kernel kernel, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event);
@@ -165,6 +173,8 @@ cl_int (CL_API_CALL *web_clEnqueueCopyImageToBuffer)(cl_command_queue command_qu
165
173
166
174
cl_int (CL_API_CALL *web_clEnqueueCopyBufferToImage)(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image, size_t src_offset, const size_t * dst_origin, const size_t * region, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event);
167
175
176
+ cl_int (CL_API_CALL *web_clEnqueueWaitForEvents)(cl_command_queue command_queue, cl_uint num_events, const cl_event* event_list);
177
+
168
178
/* OpenCL Extention */
169
179
cl_int (CL_API_CALL *web_clEnqueueAcquireGLObjects)(cl_command_queue command_queue, cl_uint num_objects, const cl_mem* mem_objects, cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event);
170
180
@@ -174,13 +184,27 @@ cl_mem (CL_API_CALL *web_clCreateFromGLBuffer)(cl_context context, cl_mem_flags
174
184
175
185
cl_mem (CL_API_CALL *web_clCreateFromGLRenderbuffer)(cl_context context, cl_mem_flags flags, GLuint renderbuffer, cl_int* errcode_ret);
176
186
187
+ cl_mem (CL_API_CALL *web_clCreateFromGLTexture2D)(cl_context context, cl_mem_flags flags, GLenum texture_target, GLint miplevel, GLuint texture, cl_int* errcode_ret);
188
+
177
189
cl_mem (CL_API_CALL *web_clCreateFromGLTexture)(cl_context context, cl_mem_flags flags, GLenum texture_target, GLint miplevel, GLuint texture, cl_int* errcode_ret);
178
190
179
191
cl_int (CL_API_CALL *web_clGetGLTextureInfo)(cl_mem, cl_gl_texture_info, size_t , void *, size_t *);
180
192
193
+ // These aliases are missing from WebCLOpenCL.h. Put them here for internal use only.
194
+ #define clReleaseDevice web_clReleaseDevice
195
+ #define clCreateImage web_clCreateImage
196
+ #define clUnloadPlatformCompiler web_clUnloadPlatformCompiler
197
+ #define clEnqueueMarkerWithWaitList web_clEnqueueMarkerWithWaitList
198
+ #define clEnqueueBarrierWithWaitList web_clEnqueueBarrierWithWaitList
199
+ #define clCreateFromGLTexture web_clCreateFromGLTexture
200
+
181
201
#if defined(WTF_OS_LINUX) || OS(ANDROID)
182
202
#define MAP_FUNC (fn ) { *(void **)(&fn) = dlsym (handle, #fn); }
183
203
#define MAP_FUNC_OR_BAIL (fn ) { *(void **)(&fn) = dlsym (handle, #fn); if (!fn) return false ; }
204
+ // In case `fn' is not defined or deprecated in the OpenCL spec tagged by
205
+ // `major' and `minor', map `fn' to a wrapper implemented with APIs defined
206
+ // by this spec.
207
+ #define MAP_FUNC_TO_WRAPPER (fn, major, minor ) { *(void **)(&fn) = (void *)fn##Impl##major##minor; }
184
208
185
209
static const char * DEFAULT_SO[] = LIBS;
186
210
static const int DEFAULT_SO_LEN = SO_LEN;
@@ -198,6 +222,49 @@ static bool getCLHandle(const char** libs, int length)
198
222
}
199
223
#endif // defined(WTF_OS_LINUX) || OS(ANDROID)
200
224
225
+ // In OpenCL 1.1 spec, no release opertion is needed for device.
226
+ static cl_int CL_API_CALL clReleaseDeviceImpl11 (cl_device_id device)
227
+ {
228
+ return CL_SUCCESS;
229
+ }
230
+
231
+ static cl_mem CL_API_CALL clCreateImage2DImpl12 (cl_context context, cl_mem_flags flags, const cl_image_format* format, size_t width, size_t height, size_t rowPitch, void * hostPtr, cl_int* err)
232
+ {
233
+ cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, static_cast <size_t >(width), static_cast <size_t >(height), 0 , 0 , static_cast <size_t >(rowPitch), 0 , 0 , 0 , 0 };
234
+ ASSERT (clCreateImage);
235
+ return clCreateImage (context, flags, format, &desc, hostPtr, err);
236
+ }
237
+
238
+ static cl_int CL_API_CALL clUnloadCompilerImpl12 (cl_platform_id platform)
239
+ {
240
+ ASSERT (clUnloadPlatformCompiler);
241
+ return clUnloadPlatformCompiler (platform);
242
+ }
243
+
244
+ static cl_int CL_API_CALL clEnqueueMarkerImpl12 (cl_command_queue queue, cl_event* event)
245
+ {
246
+ ASSERT (clEnqueueMarkerWithWaitList);
247
+ return clEnqueueMarkerWithWaitList (queue, 0 , nullptr , event);
248
+ }
249
+
250
+ static cl_int CL_API_CALL clEnqueueBarrierImpl12 (cl_command_queue queue)
251
+ {
252
+ ASSERT (clEnqueueBarrierWithWaitList);
253
+ return clEnqueueBarrierWithWaitList (queue, 0 , nullptr , nullptr );
254
+ }
255
+
256
+ static cl_int CL_API_CALL clEnqueueWaitForEventsImpl12 (cl_command_queue queue, cl_uint numEvents, const cl_event* eventList)
257
+ {
258
+ ASSERT (clEnqueueBarrierWithWaitList);
259
+ return clEnqueueBarrierWithWaitList (queue, numEvents, eventList, nullptr );
260
+ }
261
+
262
+ static cl_mem CL_API_CALL clCreateFromGLTexture2DImpl12 (cl_context context, cl_mem_flags flags, GLenum textureTarget, GLint miplevel, GLuint texture, cl_int* err)
263
+ {
264
+ ASSERT (clCreateFromGLTexture);
265
+ return clCreateFromGLTexture (context, flags, textureTarget, miplevel, texture, err);
266
+ }
267
+
201
268
bool init (const char ** libs, int length)
202
269
{
203
270
const char ** mLibs = (libs == 0 ? DEFAULT_SO : libs);
@@ -211,7 +278,6 @@ bool init(const char** libs, int length)
211
278
MAP_FUNC_OR_BAIL (clCreateCommandQueue);
212
279
MAP_FUNC_OR_BAIL (clCreateContext);
213
280
MAP_FUNC_OR_BAIL (clCreateContextFromType);
214
- MAP_FUNC_OR_BAIL (clCreateImage);
215
281
MAP_FUNC_OR_BAIL (clCreateKernel);
216
282
MAP_FUNC_OR_BAIL (clCreateKernelsInProgram);
217
283
MAP_FUNC_OR_BAIL (clCreateProgramWithSource);
@@ -230,8 +296,6 @@ bool init(const char** libs, int length)
230
296
MAP_FUNC_OR_BAIL (clEnqueueCopyImageToBuffer);
231
297
MAP_FUNC_OR_BAIL (clEnqueueReadBufferRect);
232
298
MAP_FUNC_OR_BAIL (clEnqueueWriteBufferRect);
233
- MAP_FUNC_OR_BAIL (clEnqueueBarrierWithWaitList);
234
- MAP_FUNC_OR_BAIL (clEnqueueMarkerWithWaitList);
235
299
MAP_FUNC_OR_BAIL (clEnqueueNDRangeKernel);
236
300
MAP_FUNC_OR_BAIL (clEnqueueTask);
237
301
@@ -258,7 +322,6 @@ bool init(const char** libs, int length)
258
322
259
323
MAP_FUNC_OR_BAIL (clReleaseCommandQueue);
260
324
MAP_FUNC_OR_BAIL (clReleaseContext);
261
- MAP_FUNC_OR_BAIL (clReleaseDevice);
262
325
MAP_FUNC_OR_BAIL (clReleaseEvent);
263
326
MAP_FUNC_OR_BAIL (clReleaseKernel);
264
327
MAP_FUNC_OR_BAIL (clReleaseMemObject);
@@ -269,7 +332,6 @@ bool init(const char** libs, int length)
269
332
MAP_FUNC_OR_BAIL (clSetKernelArg);
270
333
MAP_FUNC_OR_BAIL (clSetUserEventStatus);
271
334
272
- MAP_FUNC_OR_BAIL (clUnloadPlatformCompiler);
273
335
MAP_FUNC_OR_BAIL (clWaitForEvents);
274
336
275
337
// They depends on whether OpenCL library support gl_sharing extension.
@@ -278,9 +340,49 @@ bool init(const char** libs, int length)
278
340
MAP_FUNC (clEnqueueReleaseGLObjects);
279
341
MAP_FUNC (clCreateFromGLBuffer);
280
342
MAP_FUNC (clCreateFromGLRenderbuffer);
281
- MAP_FUNC (clCreateFromGLTexture);
282
343
MAP_FUNC (clGetGLTextureInfo);
283
344
345
+ // The following APIs are not available in all versions of the OpenCL
346
+ // spec, so wrappers may be needed if they are not exported by the OpenCL
347
+ // runtime library.
348
+ MAP_FUNC (clReleaseDevice)
349
+ if (!clReleaseDevice)
350
+ MAP_FUNC_TO_WRAPPER (clReleaseDevice, 1 , 1 )
351
+
352
+ MAP_FUNC (clCreateImage)
353
+ if (clCreateImage)
354
+ MAP_FUNC_TO_WRAPPER (clCreateImage2D, 1 , 2 )
355
+ else
356
+ MAP_FUNC_OR_BAIL (clCreateImage2D)
357
+
358
+ MAP_FUNC (clUnloadPlatformCompiler)
359
+ if (clUnloadPlatformCompiler)
360
+ MAP_FUNC_TO_WRAPPER (clUnloadCompiler, 1 , 2 )
361
+ else
362
+ MAP_FUNC_OR_BAIL (clUnloadCompiler)
363
+
364
+ MAP_FUNC (clEnqueueMarkerWithWaitList)
365
+ if (clEnqueueMarkerWithWaitList)
366
+ MAP_FUNC_TO_WRAPPER (clEnqueueMarker, 1 , 2 )
367
+ else
368
+ MAP_FUNC_OR_BAIL (clEnqueueMarker)
369
+
370
+ MAP_FUNC (clEnqueueBarrierWithWaitList)
371
+ if (clEnqueueBarrierWithWaitList)
372
+ MAP_FUNC_TO_WRAPPER (clEnqueueBarrier, 1 , 2 )
373
+ else
374
+ MAP_FUNC_OR_BAIL (clEnqueueBarrier)
375
+
376
+ MAP_FUNC (clEnqueueWaitForEvents)
377
+ if (!clEnqueueWaitForEvents)
378
+ MAP_FUNC_TO_WRAPPER (clEnqueueWaitForEvents, 1 , 2 )
379
+
380
+ MAP_FUNC (clCreateFromGLTexture)
381
+ if (clCreateFromGLTexture)
382
+ MAP_FUNC_TO_WRAPPER (clCreateFromGLTexture2D, 1 , 2 )
383
+ else
384
+ MAP_FUNC (clCreateFromGLTexture2D)
385
+
284
386
return true ;
285
387
}
286
388
0 commit comments