rpcrt4: Don't try to bind to a null handle.
[wine] / dlls / opencl / opencl.c
1 /*
2  * OpenCL.dll proxy for native OpenCL implementation.
3  *
4  * Copyright 2010 Peter Urbanec
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27
28 #include "wine/debug.h"
29 #include "wine/library.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(opencl);
32
33 #if defined(HAVE_CL_CL_H)
34 #include <CL/cl.h>
35 #elif defined(HAVE_OPENCL_OPENCL_H)
36 #include <OpenCL/opencl.h>
37 #endif
38
39 /* TODO: Figure out how to provide GL context sharing before enabling OpenGL */
40 #define OPENCL_WITH_GL 0
41
42
43 /*---------------------------------------------------------------*/
44 /* Platform API */
45
46 cl_int WINAPI wine_clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms)
47 {
48     cl_int ret;
49     TRACE("(%d, %p, %p)\n", num_entries, platforms, num_platforms);
50     ret = clGetPlatformIDs(num_entries, platforms, num_platforms);
51     TRACE("(%d, %p, %p)=%d\n", num_entries, platforms, num_platforms, ret);
52     return ret;
53 }
54
55 cl_int WINAPI wine_clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name,
56                                      SIZE_T param_value_size, void * param_value, size_t * param_value_size_ret)
57 {
58     cl_int ret;
59     TRACE("(%p, 0x%x, %ld, %p, %p)\n", platform, param_name, param_value_size, param_value, param_value_size_ret);
60
61     /* Hide all extensions.
62      * TODO: Add individual extension support as needed.
63      */
64     if (param_name == CL_PLATFORM_EXTENSIONS)
65     {
66         ret = CL_INVALID_VALUE;
67
68         if (param_value && param_value_size > 0)
69         {
70             char *exts = (char *) param_value;
71             exts[0] = '\0';
72             ret = CL_SUCCESS;
73         }
74
75         if (param_value_size_ret)
76         {
77             *param_value_size_ret = 1;
78             ret = CL_SUCCESS;
79         }
80     }
81     else
82     {
83         ret = clGetPlatformInfo(platform, param_name, param_value_size, param_value, param_value_size_ret);
84     }
85
86     TRACE("(%p, 0x%x, %ld, %p, %p)=%d\n", platform, param_name, param_value_size, param_value, param_value_size_ret, ret);
87     return ret;
88 }
89
90
91 /*---------------------------------------------------------------*/
92 /* Device APIs */
93
94 cl_int WINAPI wine_clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type,
95                                   cl_uint num_entries, cl_device_id * devices, cl_uint * num_devices)
96 {
97     cl_int ret;
98     TRACE("(%p, 0x%lx, %d, %p, %p)\n", platform, (long unsigned int)device_type, num_entries, devices, num_devices);
99     ret = clGetDeviceIDs(platform, device_type, num_entries, devices, num_devices);
100     TRACE("(%p, 0x%lx, %d, %p, %p)=%d\n", platform, (long unsigned int)device_type, num_entries, devices, num_devices, ret);
101     return ret;
102 }
103
104 cl_int WINAPI wine_clGetDeviceInfo(cl_device_id device, cl_device_info param_name,
105                                    SIZE_T param_value_size, void * param_value, size_t * param_value_size_ret)
106 {
107     cl_int ret;
108     TRACE("(%p, 0x%x, %ld, %p, %p)\n",device, param_name, param_value_size, param_value, param_value_size_ret);
109
110     /* Hide all extensions.
111      * TODO: Add individual extension support as needed.
112      */
113     if (param_name == CL_DEVICE_EXTENSIONS)
114     {
115         ret = CL_INVALID_VALUE;
116
117         if (param_value && param_value_size > 0)
118         {
119             char *exts = (char *) param_value;
120             exts[0] = '\0';
121             ret = CL_SUCCESS;
122         }
123
124         if (param_value_size_ret)
125         {
126             *param_value_size_ret = 1;
127             ret = CL_SUCCESS;
128         }
129     }
130     else
131     {
132         ret = clGetDeviceInfo(device, param_name, param_value_size, param_value, param_value_size_ret);
133     }
134
135     /* Filter out the CL_EXEC_NATIVE_KERNEL flag */
136     if (param_name == CL_DEVICE_EXECUTION_CAPABILITIES)
137     {
138         cl_device_exec_capabilities *caps = (cl_device_exec_capabilities *) param_value;
139         *caps &= ~CL_EXEC_NATIVE_KERNEL;
140     }
141
142     TRACE("(%p, 0x%x, %ld, %p, %p)=%d\n",device, param_name, param_value_size, param_value, param_value_size_ret, ret);
143     return ret;
144 }
145
146
147 /*---------------------------------------------------------------*/
148 /* Context APIs  */
149
150 typedef struct
151 {
152     void WINAPI (*pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data);
153     void *user_data;
154 } CONTEXT_CALLBACK;
155
156 static void context_fn_notify(const char *errinfo, const void *private_info, size_t cb, void *user_data)
157 {
158     CONTEXT_CALLBACK *ccb;
159     TRACE("(%s, %p, %ld, %p)\n", errinfo, private_info, (SIZE_T)cb, user_data);
160     ccb = (CONTEXT_CALLBACK *) user_data;
161     if(ccb->pfn_notify) ccb->pfn_notify(errinfo, private_info, cb, ccb->user_data);
162     TRACE("Callback COMPLETED\n");
163 }
164
165 cl_context WINAPI wine_clCreateContext(const cl_context_properties * properties, cl_uint num_devices, const cl_device_id * devices,
166                                        void WINAPI (*pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
167                                        void * user_data, cl_int * errcode_ret)
168 {
169     cl_context ret;
170     CONTEXT_CALLBACK *ccb;
171     TRACE("(%p, %d, %p, %p, %p, %p)\n", properties, num_devices, devices, pfn_notify, user_data, errcode_ret);
172     /* FIXME: The CONTEXT_CALLBACK structure is currently leaked.
173      * Pointers to callback redirectors should be remembered and free()d when the context is destroyed.
174      * The problem is determining when a context is being destroyed. clReleaseContext only decrements
175      * the use count for a context, it's destruction can come much later and therefore there is a risk
176      * that the callback could be invoked after the user_data memory has been free()d.
177      */
178     ccb = HeapAlloc(GetProcessHeap(), 0, sizeof(CONTEXT_CALLBACK));
179     ccb->pfn_notify = pfn_notify;
180     ccb->user_data = user_data;
181     ret = clCreateContext(properties, num_devices, devices, context_fn_notify, ccb, errcode_ret);
182     TRACE("(%p, %d, %p, %p, %p, %p (%d)))=%p\n", properties, num_devices, devices, &pfn_notify, user_data, errcode_ret, errcode_ret ? *errcode_ret : 0, ret);
183     return ret;
184 }
185
186 cl_context WINAPI wine_clCreateContextFromType(const cl_context_properties * properties, cl_device_type device_type,
187                                                void WINAPI (*pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
188                                                void * user_data, cl_int * errcode_ret)
189 {
190     cl_context ret;
191     CONTEXT_CALLBACK *ccb;
192     TRACE("(%p, 0x%lx, %p, %p, %p)\n", properties, (long unsigned int)device_type, pfn_notify, user_data, errcode_ret);
193     /* FIXME: The CONTEXT_CALLBACK structure is currently leaked.
194      * Pointers to callback redirectors should be remembered and free()d when the context is destroyed.
195      * The problem is determining when a context is being destroyed. clReleaseContext only decrements
196      * the use count for a context, it's destruction can come much later and therefore there is a risk
197      * that the callback could be invoked after the user_data memory has been free()d.
198      */
199     ccb = HeapAlloc(GetProcessHeap(), 0, sizeof(CONTEXT_CALLBACK));
200     ccb->pfn_notify = pfn_notify;
201     ccb->user_data = user_data;
202     ret = clCreateContextFromType(properties, device_type, context_fn_notify, ccb, errcode_ret);
203     TRACE("(%p, 0x%lx, %p, %p, %p (%d)))=%p\n", properties, (long unsigned int)device_type, pfn_notify, user_data, errcode_ret, errcode_ret ? *errcode_ret : 0, ret);
204     return ret;
205 }
206
207 cl_int WINAPI wine_clRetainContext(cl_context context)
208 {
209     cl_int ret;
210     TRACE("(%p)\n", context);
211     ret = clRetainContext(context);
212     TRACE("(%p)=%d\n", context, ret);
213     return ret;
214 }
215
216 cl_int WINAPI wine_clReleaseContext(cl_context context)
217 {
218     cl_int ret;
219     TRACE("(%p)\n", context);
220     ret = clReleaseContext(context);
221     TRACE("(%p)=%d\n", context, ret);
222     return ret;
223 }
224
225 cl_int WINAPI wine_clGetContextInfo(cl_context context, cl_context_info param_name,
226                                     SIZE_T param_value_size, void * param_value, size_t * param_value_size_ret)
227 {
228     cl_int ret;
229     TRACE("(%p, 0x%x, %ld, %p, %p)\n", context, param_name, param_value_size, param_value, param_value_size_ret);
230     ret = clGetContextInfo(context, param_name, param_value_size, param_value, param_value_size_ret);
231     TRACE("(%p, 0x%x, %ld, %p, %p)=%d\n", context, param_name, param_value_size, param_value, param_value_size_ret, ret);
232     return ret;
233 }
234
235
236 /*---------------------------------------------------------------*/
237 /* Command Queue APIs */
238
239 cl_command_queue WINAPI wine_clCreateCommandQueue(cl_context context, cl_device_id device,
240                                                   cl_command_queue_properties properties, cl_int * errcode_ret)
241 {
242     cl_command_queue ret;
243     TRACE("(%p, %p, 0x%lx, %p)\n", context, device, (long unsigned int)properties, errcode_ret);
244     ret = clCreateCommandQueue(context, device, properties, errcode_ret);
245     TRACE("(%p, %p, 0x%lx, %p)=%p\n", context, device, (long unsigned int)properties, errcode_ret, ret);
246     return ret;
247 }
248
249 cl_int WINAPI wine_clRetainCommandQueue(cl_command_queue command_queue)
250 {
251     cl_int ret;
252     TRACE("(%p)\n", command_queue);
253     ret = clRetainCommandQueue(command_queue);
254     TRACE("(%p)=%d\n", command_queue, ret);
255     return ret;
256 }
257
258 cl_int WINAPI wine_clReleaseCommandQueue(cl_command_queue command_queue)
259 {
260     cl_int ret;
261     TRACE("(%p)\n", command_queue);
262     ret = clReleaseCommandQueue(command_queue);
263     TRACE("(%p)=%d\n", command_queue, ret);
264     return ret;
265 }
266
267 cl_int WINAPI wine_clGetCommandQueueInfo(cl_command_queue command_queue, cl_command_queue_info param_name,
268                                          SIZE_T param_value_size, void * param_value, size_t * param_value_size_ret)
269 {
270     cl_int ret;
271     TRACE("%p, %d, %ld, %p, %p\n", command_queue, param_name, param_value_size, param_value, param_value_size_ret);
272     ret = clGetCommandQueueInfo(command_queue, param_name, param_value_size, param_value, param_value_size_ret);
273     return ret;
274 }
275
276 cl_int WINAPI wine_clSetCommandQueueProperty(cl_command_queue command_queue, cl_command_queue_properties properties, cl_bool enable,
277                                              cl_command_queue_properties * old_properties)
278 {
279     cl_int ret;
280     TRACE("%p, 0x%lx, %d, %p\n", command_queue, (long unsigned int)properties, enable, old_properties);
281     ret = clSetCommandQueueProperty(command_queue, properties, enable, old_properties);
282     return ret;
283 }
284
285
286 /*---------------------------------------------------------------*/
287 /* Memory Object APIs  */
288
289 cl_mem WINAPI wine_clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void * host_ptr, cl_int * errcode_ret)
290 {
291     cl_mem ret;
292     TRACE("\n");
293     ret = clCreateBuffer(context, flags, size, host_ptr, errcode_ret);
294     return ret;
295 }
296
297 cl_mem WINAPI wine_clCreateImage2D(cl_context context, cl_mem_flags flags, cl_image_format * image_format,
298                                    size_t image_width, size_t image_height, size_t image_row_pitch, void * host_ptr, cl_int * errcode_ret)
299 {
300     cl_mem ret;
301     TRACE("\n");
302     ret = clCreateImage2D(context, flags, image_format, image_width, image_height, image_row_pitch, host_ptr, errcode_ret);
303     return ret;
304 }
305
306 cl_mem WINAPI wine_clCreateImage3D(cl_context context, cl_mem_flags flags, cl_image_format * image_format,
307                                    size_t image_width, size_t image_height, size_t image_depth, size_t image_row_pitch, size_t image_slice_pitch,
308                                    void * host_ptr, cl_int * errcode_ret)
309 {
310     cl_mem ret;
311     TRACE("\n");
312     ret = clCreateImage3D(context, flags, image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, errcode_ret);
313     return ret;
314 }
315
316 cl_int WINAPI wine_clRetainMemObject(cl_mem memobj)
317 {
318     cl_int ret;
319     TRACE("(%p)\n", memobj);
320     ret = clRetainMemObject(memobj);
321     TRACE("(%p)=%d\n", memobj, ret);
322     return ret;
323 }
324
325 cl_int WINAPI wine_clReleaseMemObject(cl_mem memobj)
326 {
327     cl_int ret;
328     TRACE("(%p)\n", memobj);
329     ret = clReleaseMemObject(memobj);
330     TRACE("(%p)=%d\n", memobj, ret);
331     return ret;
332 }
333
334 cl_int WINAPI wine_clGetSupportedImageFormats(cl_context context, cl_mem_flags flags, cl_mem_object_type image_type, cl_uint num_entries,
335                                               cl_image_format * image_formats, cl_uint * num_image_formats)
336 {
337     cl_int ret;
338     TRACE("\n");
339     ret = clGetSupportedImageFormats(context, flags, image_type, num_entries, image_formats, num_image_formats);
340     return ret;
341 }
342
343 cl_int WINAPI wine_clGetMemObjectInfo(cl_mem memobj, cl_mem_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret)
344 {
345     cl_int ret;
346     TRACE("\n");
347     ret = clGetMemObjectInfo(memobj, param_name, param_value_size, param_value, param_value_size_ret);
348     return ret;
349 }
350
351 cl_int WINAPI wine_clGetImageInfo(cl_mem image, cl_image_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret)
352 {
353     cl_int ret;
354     TRACE("\n");
355     ret = clGetImageInfo(image, param_name, param_value_size, param_value, param_value_size_ret);
356     return ret;
357 }
358
359
360 /*---------------------------------------------------------------*/
361 /* Sampler APIs  */
362
363 cl_sampler WINAPI wine_clCreateSampler(cl_context context, cl_bool normalized_coords, cl_addressing_mode addressing_mode,
364                                        cl_filter_mode filter_mode, cl_int * errcode_ret)
365 {
366     cl_sampler ret;
367     TRACE("\n");
368     ret = clCreateSampler(context, normalized_coords, addressing_mode, filter_mode, errcode_ret);
369     return ret;
370 }
371
372 cl_int WINAPI wine_clRetainSampler(cl_sampler sampler)
373 {
374     cl_int ret;
375     TRACE("\n");
376     ret = clRetainSampler(sampler);
377     return ret;
378 }
379
380 cl_int WINAPI wine_clReleaseSampler(cl_sampler sampler)
381 {
382     cl_int ret;
383     TRACE("\n");
384     ret = clReleaseSampler(sampler);
385     return ret;
386 }
387
388 cl_int WINAPI wine_clGetSamplerInfo(cl_sampler sampler, cl_sampler_info param_name, size_t param_value_size,
389                                     void * param_value, size_t * param_value_size_ret)
390 {
391     cl_int ret;
392     TRACE("\n");
393     ret = clGetSamplerInfo(sampler, param_name, param_value_size, param_value, param_value_size_ret);
394     return ret;
395 }
396
397
398 /*---------------------------------------------------------------*/
399 /* Program Object APIs  */
400
401 cl_program WINAPI wine_clCreateProgramWithSource(cl_context context, cl_uint count, const char ** strings,
402                                                  const size_t * lengths, cl_int * errcode_ret)
403 {
404     cl_program ret;
405     TRACE("\n");
406     ret = clCreateProgramWithSource(context, count, strings, lengths, errcode_ret);
407     return ret;
408 }
409
410 cl_program WINAPI wine_clCreateProgramWithBinary(cl_context context, cl_uint num_devices, const cl_device_id * device_list,
411                                                  const size_t * lengths, const unsigned char ** binaries, cl_int * binary_status,
412                                                  cl_int * errcode_ret)
413 {
414     cl_program ret;
415     TRACE("\n");
416     ret = clCreateProgramWithBinary(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
417     return ret;
418 }
419
420 cl_int WINAPI wine_clRetainProgram(cl_program program)
421 {
422     cl_int ret;
423     TRACE("\n");
424     ret = clRetainProgram(program);
425     return ret;
426 }
427
428 cl_int WINAPI wine_clReleaseProgram(cl_program program)
429 {
430     cl_int ret;
431     TRACE("\n");
432     ret = clReleaseProgram(program);
433     return ret;
434 }
435
436 typedef struct
437 {
438     void WINAPI (*pfn_notify)(cl_program program, void * user_data);
439     void *user_data;
440 } PROGRAM_CALLBACK;
441
442 static void program_fn_notify(cl_program program, void * user_data)
443 {
444     PROGRAM_CALLBACK *pcb;
445     TRACE("(%p, %p)\n", program, user_data);
446     pcb = (PROGRAM_CALLBACK *) user_data;
447     pcb->pfn_notify(program, pcb->user_data);
448     HeapFree(GetProcessHeap(), 0, pcb);
449     TRACE("Callback COMPLETED\n");
450 }
451
452 cl_int WINAPI wine_clBuildProgram(cl_program program, cl_uint num_devices, const cl_device_id * device_list, const char * options,
453                                   void WINAPI (*pfn_notify)(cl_program program, void * user_data),
454                                   void * user_data)
455 {
456     cl_int ret;
457     TRACE("\n");
458     if(pfn_notify)
459     {
460         /* When pfn_notify is provided, clBuildProgram is asynchronous */
461         PROGRAM_CALLBACK *pcb;
462         pcb = HeapAlloc(GetProcessHeap(), 0, sizeof(PROGRAM_CALLBACK));
463         pcb->pfn_notify = pfn_notify;
464         pcb->user_data = user_data;
465         ret = clBuildProgram(program, num_devices, device_list, options, program_fn_notify, pcb);
466     }
467     else
468     {
469         /* When pfn_notify is NULL, clBuildProgram is synchronous */
470         ret = clBuildProgram(program, num_devices, device_list, options, NULL, user_data);
471     }
472     return ret;
473 }
474
475 cl_int WINAPI wine_clUnloadCompiler(void)
476 {
477     cl_int ret;
478     TRACE("()\n");
479     ret = clUnloadCompiler();
480     TRACE("()=%d\n", ret);
481     return ret;
482 }
483
484 cl_int WINAPI wine_clGetProgramInfo(cl_program program, cl_program_info param_name,
485                                     size_t param_value_size, void * param_value, size_t * param_value_size_ret)
486 {
487     cl_int ret;
488     TRACE("\n");
489     ret = clGetProgramInfo(program, param_name, param_value_size, param_value, param_value_size_ret);
490     return ret;
491 }
492
493 cl_int WINAPI wine_clGetProgramBuildInfo(cl_program program, cl_device_id device,
494                                          cl_program_build_info param_name, size_t param_value_size, void * param_value,
495                                          size_t * param_value_size_ret)
496 {
497     cl_int ret;
498     TRACE("\n");
499     ret = clGetProgramBuildInfo(program, device, param_name, param_value_size, param_value, param_value_size_ret);
500     return ret;
501 }
502
503
504 /*---------------------------------------------------------------*/
505 /* Kernel Object APIs */
506
507 cl_kernel WINAPI wine_clCreateKernel(cl_program program, char * kernel_name, cl_int * errcode_ret)
508 {
509     cl_kernel ret;
510     TRACE("\n");
511     ret = clCreateKernel(program, kernel_name, errcode_ret);
512     return ret;
513 }
514
515 cl_int WINAPI wine_clCreateKernelsInProgram(cl_program program, cl_uint num_kernels,
516                                             cl_kernel * kernels, cl_uint * num_kernels_ret)
517 {
518     cl_int ret;
519     TRACE("\n");
520     ret = clCreateKernelsInProgram(program, num_kernels, kernels, num_kernels_ret);
521     return ret;
522 }
523
524 cl_int WINAPI wine_clRetainKernel(cl_kernel kernel)
525 {
526     cl_int ret;
527     TRACE("\n");
528     ret = clRetainKernel(kernel);
529     return ret;
530 }
531
532 cl_int WINAPI wine_clReleaseKernel(cl_kernel kernel)
533 {
534     cl_int ret;
535     TRACE("\n");
536     ret = clReleaseKernel(kernel);
537     return ret;
538 }
539
540 cl_int WINAPI wine_clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, void * arg_value)
541 {
542     cl_int ret;
543     TRACE("\n");
544     ret = clSetKernelArg(kernel, arg_index, arg_size, arg_value);
545     return ret;
546 }
547
548 cl_int WINAPI wine_clGetKernelInfo(cl_kernel kernel, cl_kernel_info param_name,
549                                    size_t param_value_size, void * param_value, size_t * param_value_size_ret)
550 {
551     cl_int ret;
552     TRACE("\n");
553     ret = clGetKernelInfo(kernel, param_name, param_value_size, param_value, param_value_size_ret);
554     return ret;
555 }
556
557 cl_int WINAPI wine_clGetKernelWorkGroupInfo(cl_kernel kernel, cl_device_id device,
558                                             cl_kernel_work_group_info param_name, size_t param_value_size,
559                                             void * param_value, size_t * param_value_size_ret)
560 {
561     cl_int ret;
562     TRACE("\n");
563     ret = clGetKernelWorkGroupInfo(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
564     return ret;
565 }
566
567
568 /*---------------------------------------------------------------*/
569 /* Event Object APIs  */
570
571 cl_int WINAPI wine_clWaitForEvents(cl_uint num_events, cl_event * event_list)
572 {
573     cl_int ret;
574     TRACE("\n");
575     ret = clWaitForEvents(num_events, event_list);
576     return ret;
577 }
578
579 cl_int WINAPI wine_clGetEventInfo(cl_event event, cl_event_info param_name, size_t param_value_size,
580                                   void * param_value, size_t * param_value_size_ret)
581 {
582     cl_int ret;
583     TRACE("\n");
584     ret = clGetEventInfo(event, param_name, param_value_size, param_value, param_value_size_ret);
585     return ret;
586 }
587
588 cl_int WINAPI wine_clRetainEvent(cl_event event)
589 {
590     cl_int ret;
591     TRACE("\n");
592     ret = clRetainEvent(event);
593     return ret;
594 }
595
596 cl_int WINAPI wine_clReleaseEvent(cl_event event)
597 {
598     cl_int ret;
599     TRACE("\n");
600     ret = clReleaseEvent(event);
601     return ret;
602 }
603
604
605 /*---------------------------------------------------------------*/
606 /* Profiling APIs  */
607
608 cl_int WINAPI wine_clGetEventProfilingInfo(cl_event event, cl_profiling_info param_name, size_t param_value_size,
609                                            void * param_value, size_t * param_value_size_ret)
610 {
611     cl_int ret;
612     TRACE("\n");
613     ret = clGetEventProfilingInfo(event, param_name, param_value_size, param_value, param_value_size_ret);
614     return ret;
615 }
616
617
618 /*---------------------------------------------------------------*/
619 /* Flush and Finish APIs */
620
621 cl_int WINAPI wine_clFlush(cl_command_queue command_queue)
622 {
623     cl_int ret;
624     TRACE("(%p)\n", command_queue);
625     ret = clFlush(command_queue);
626     TRACE("(%p)=%d\n", command_queue, ret);
627     return ret;
628 }
629
630 cl_int WINAPI wine_clFinish(cl_command_queue command_queue)
631 {
632     cl_int ret;
633     TRACE("(%p)\n", command_queue);
634     ret = clFinish(command_queue);
635     TRACE("(%p)=%d\n", command_queue, ret);
636     return ret;
637 }
638
639
640 /*---------------------------------------------------------------*/
641 /* Enqueued Commands APIs */
642
643 cl_int WINAPI wine_clEnqueueReadBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read,
644                                        size_t offset, size_t cb, void * ptr,
645                                        cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
646 {
647     cl_int ret;
648     TRACE("\n");
649     ret = clEnqueueReadBuffer(command_queue, buffer, blocking_read, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
650     return ret;
651 }
652
653 cl_int WINAPI wine_clEnqueueWriteBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write,
654                                         size_t offset, size_t cb, const void * ptr,
655                                         cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
656 {
657     cl_int ret;
658     TRACE("\n");
659     ret = clEnqueueWriteBuffer(command_queue, buffer, blocking_write, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
660     return ret;
661 }
662
663 cl_int WINAPI wine_clEnqueueCopyBuffer(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer,
664                                        size_t src_offset, size_t dst_offset, size_t cb,
665                                        cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
666 {
667     cl_int ret;
668     TRACE("\n");
669     ret = clEnqueueCopyBuffer(command_queue, src_buffer, dst_buffer, src_offset, dst_offset, cb, num_events_in_wait_list, event_wait_list, event);
670     return ret;
671 }
672
673 cl_int WINAPI wine_clEnqueueReadImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_read,
674                                       const size_t * origin, const size_t * region,
675                                       SIZE_T row_pitch, SIZE_T slice_pitch, void * ptr,
676                                       cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
677 {
678     cl_int ret;
679     TRACE("(%p, %p, %d, %p, %p, %ld, %ld, %p, %d, %p, %p)\n", command_queue, image, blocking_read,
680           origin, region, row_pitch, slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event);
681     ret = clEnqueueReadImage(command_queue, image, blocking_read, origin, region, row_pitch, slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event);
682     TRACE("(%p, %p, %d, %p, %p, %ld, %ld, %p, %d, %p, %p)=%d\n", command_queue, image, blocking_read,
683           origin, region, row_pitch, slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event, ret);
684     return ret;
685 }
686
687 cl_int WINAPI wine_clEnqueueWriteImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_write,
688                                        const size_t * origin, const size_t * region,
689                                        size_t input_row_pitch, size_t input_slice_pitch, const void * ptr,
690                                        cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
691 {
692     cl_int ret;
693     TRACE("\n");
694     ret = clEnqueueWriteImage(command_queue, image, blocking_write, origin, region, input_row_pitch, input_slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event);
695     return ret;
696 }
697
698 cl_int WINAPI wine_clEnqueueCopyImage(cl_command_queue command_queue, cl_mem src_image, cl_mem dst_image,
699                                       size_t * src_origin, size_t * dst_origin, size_t * region,
700                                       cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
701 {
702     cl_int ret;
703     TRACE("\n");
704     ret = clEnqueueCopyImage(command_queue, src_image, dst_image, src_origin, dst_origin, region, num_events_in_wait_list, event_wait_list, event);
705     return ret;
706 }
707
708 cl_int WINAPI wine_clEnqueueCopyImageToBuffer(cl_command_queue command_queue, cl_mem src_image, cl_mem dst_buffer,
709                                               size_t * src_origin, size_t * region, size_t dst_offset,
710                                               cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
711 {
712     cl_int ret;
713     TRACE("\n");
714     ret = clEnqueueCopyImageToBuffer(command_queue, src_image, dst_buffer, src_origin, region, dst_offset, num_events_in_wait_list, event_wait_list, event);
715     return ret;
716 }
717
718 cl_int WINAPI wine_clEnqueueCopyBufferToImage(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image,
719                                               size_t src_offset, size_t * dst_origin, size_t * region,
720                                               cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
721 {
722     cl_int ret;
723     TRACE("\n");
724     ret = clEnqueueCopyBufferToImage(command_queue, src_buffer, dst_image, src_offset, dst_origin, region, num_events_in_wait_list, event_wait_list, event);
725     return ret;
726 }
727
728 void * WINAPI wine_clEnqueueMapBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map,
729                                       cl_map_flags map_flags, size_t offset, size_t cb,
730                                       cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event, cl_int * errcode_ret)
731 {
732     void * ret;
733     TRACE("\n");
734     ret = clEnqueueMapBuffer(command_queue, buffer, blocking_map, map_flags, offset, cb, num_events_in_wait_list, event_wait_list, event, errcode_ret);
735     return ret;
736 }
737
738 void * WINAPI wine_clEnqueueMapImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_map,
739                                      cl_map_flags map_flags, size_t * origin, size_t * region,
740                                      size_t * image_row_pitch, size_t * image_slice_pitch,
741                                      cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event, cl_int * errcode_ret)
742 {
743     void * ret;
744     TRACE("\n");
745     ret = clEnqueueMapImage(command_queue, image, blocking_map, map_flags, origin, region, image_row_pitch, image_slice_pitch, num_events_in_wait_list, event_wait_list, event, errcode_ret);
746     return ret;
747 }
748
749 cl_int WINAPI wine_clEnqueueUnmapMemObject(cl_command_queue command_queue, cl_mem memobj, void * mapped_ptr,
750                                            cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
751 {
752     cl_int ret;
753     TRACE("\n");
754     ret = clEnqueueUnmapMemObject(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
755     return ret;
756 }
757
758 cl_int WINAPI wine_clEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim,
759                                           size_t * global_work_offset, size_t * global_work_size, size_t * local_work_size,
760                                           cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
761 {
762     cl_int ret;
763     TRACE("\n");
764     ret = clEnqueueNDRangeKernel(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event);
765     return ret;
766 }
767
768 cl_int WINAPI wine_clEnqueueTask(cl_command_queue command_queue, cl_kernel kernel,
769                                  cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
770 {
771     cl_int ret;
772     TRACE("\n");
773     ret = clEnqueueTask(command_queue, kernel, num_events_in_wait_list, event_wait_list, event);
774     return ret;
775 }
776
777 cl_int WINAPI wine_clEnqueueNativeKernel(cl_command_queue command_queue,
778                                          void WINAPI (*user_func)(void *args),
779                                          void * args, size_t cb_args,
780                                          cl_uint num_mem_objects, const cl_mem * mem_list, const void ** args_mem_loc,
781                                          cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
782 {
783     cl_int ret = CL_INVALID_OPERATION;
784     /* FIXME: There appears to be no obvious method for translating the ABI for user_func.
785      * There is no opaque user_data structure passed, that could encapsulate the return address.
786      * The OpenCL specification seems to indicate that args has an implementation specific
787      * structure that cannot be used to stash away a return address for the WINAPI user_func.
788      */
789 #if 0
790     ret = clEnqueueNativeKernel(command_queue, user_func, args, cb_args, num_mem_objects, mem_list, args_mem_loc,
791                                  num_events_in_wait_list, event_wait_list, event);
792 #else
793     FIXME("not supported due to user_func ABI mismatch\n");
794 #endif
795     return ret;
796 }
797
798 cl_int WINAPI wine_clEnqueueMarker(cl_command_queue command_queue, cl_event * event)
799 {
800     cl_int ret;
801     TRACE("\n");
802     ret = clEnqueueMarker(command_queue, event);
803     return ret;
804 }
805
806 cl_int WINAPI wine_clEnqueueWaitForEvents(cl_command_queue command_queue, cl_uint num_events, cl_event * event_list)
807 {
808     cl_int ret;
809     TRACE("\n");
810     ret = clEnqueueWaitForEvents(command_queue, num_events, event_list);
811     return ret;
812 }
813
814 cl_int WINAPI wine_clEnqueueBarrier(cl_command_queue command_queue)
815 {
816     cl_int ret;
817     TRACE("\n");
818     ret = clEnqueueBarrier(command_queue);
819     return ret;
820 }
821
822
823 /*---------------------------------------------------------------*/
824 /* Extension function access */
825
826 void * WINAPI wine_clGetExtensionFunctionAddress(const char * func_name)
827 {
828     void * ret = 0;
829     TRACE("(%s)\n",func_name);
830 #if 0
831     ret = clGetExtensionFunctionAddress(func_name);
832 #else
833     FIXME("extensions not implemented\n");
834 #endif
835     TRACE("(%s)=%p\n",func_name, ret);
836     return ret;
837 }
838
839
840 #if OPENCL_WITH_GL
841 /*---------------------------------------------------------------*/
842 /* Khronos-approved (KHR) OpenCL extensions which have OpenGL dependencies. */
843
844 cl_mem WINAPI wine_clCreateFromGLBuffer(cl_context context, cl_mem_flags flags, cl_GLuint bufobj, int * errcode_ret)
845 {
846 }
847
848 cl_mem WINAPI wine_clCreateFromGLTexture2D(cl_context context, cl_mem_flags flags, cl_GLenum target,
849                                            cl_GLint miplevel, cl_GLuint texture, cl_int * errcode_ret)
850 {
851 }
852
853 cl_mem WINAPI wine_clCreateFromGLTexture3D(cl_context context, cl_mem_flags flags, cl_GLenum target,
854                                            cl_GLint miplevel, cl_GLuint texture, cl_int * errcode_ret)
855 {
856 }
857
858 cl_mem WINAPI wine_clCreateFromGLRenderbuffer(cl_context context, cl_mem_flags flags, cl_GLuint renderbuffer, cl_int * errcode_ret)
859 {
860 }
861
862 cl_int WINAPI wine_clGetGLObjectInfo(cl_mem memobj, cl_gl_object_type * gl_object_type, cl_GLuint * gl_object_name)
863 {
864 }
865
866 cl_int WINAPI wine_clGetGLTextureInfo(cl_mem memobj, cl_gl_texture_info param_name, size_t param_value_size,
867                                       void * param_value, size_t * param_value_size_ret)
868 {
869 }
870
871 cl_int WINAPI wine_clEnqueueAcquireGLObjects(cl_command_queue command_queue, cl_uint num_objects, const cl_mem * mem_objects,
872                                              cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
873 {
874 }
875
876 cl_int WINAPI wine_clEnqueueReleaseGLObjects(cl_command_queue command_queue, cl_uint num_objects, const cl_mem * mem_objects,
877                                              cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
878 {
879 }
880
881
882 /*---------------------------------------------------------------*/
883 /* cl_khr_gl_sharing extension  */
884
885 cl_int WINAPI wine_clGetGLContextInfoKHR(const cl_context_properties * properties, cl_gl_context_info param_name,
886                                          size_t param_value_size, void * param_value, size_t * param_value_size_ret)
887 {
888 }
889
890 #endif
891
892
893 #if 0
894 /*---------------------------------------------------------------*/
895 /* cl_khr_icd extension */
896
897 cl_int WINAPI wine_clIcdGetPlatformIDsKHR(cl_uint num_entries, cl_platform_id * platforms, cl_uint * num_platforms)
898 {
899 }
900 #endif