cmd: Output error messages to stderr where appropriate.
[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     FIXME("(%p, 0x%lx, %d, %p): deprecated\n", command_queue, (long unsigned int)properties, enable, old_properties);
280     return CL_INVALID_QUEUE_PROPERTIES;
281 }
282
283
284 /*---------------------------------------------------------------*/
285 /* Memory Object APIs  */
286
287 cl_mem WINAPI wine_clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void * host_ptr, cl_int * errcode_ret)
288 {
289     cl_mem ret;
290     TRACE("\n");
291     ret = clCreateBuffer(context, flags, size, host_ptr, errcode_ret);
292     return ret;
293 }
294
295 cl_mem WINAPI wine_clCreateImage2D(cl_context context, cl_mem_flags flags, cl_image_format * image_format,
296                                    size_t image_width, size_t image_height, size_t image_row_pitch, void * host_ptr, cl_int * errcode_ret)
297 {
298     cl_mem ret;
299     TRACE("\n");
300     ret = clCreateImage2D(context, flags, image_format, image_width, image_height, image_row_pitch, host_ptr, errcode_ret);
301     return ret;
302 }
303
304 cl_mem WINAPI wine_clCreateImage3D(cl_context context, cl_mem_flags flags, cl_image_format * image_format,
305                                    size_t image_width, size_t image_height, size_t image_depth, size_t image_row_pitch, size_t image_slice_pitch,
306                                    void * host_ptr, cl_int * errcode_ret)
307 {
308     cl_mem ret;
309     TRACE("\n");
310     ret = clCreateImage3D(context, flags, image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, errcode_ret);
311     return ret;
312 }
313
314 cl_int WINAPI wine_clRetainMemObject(cl_mem memobj)
315 {
316     cl_int ret;
317     TRACE("(%p)\n", memobj);
318     ret = clRetainMemObject(memobj);
319     TRACE("(%p)=%d\n", memobj, ret);
320     return ret;
321 }
322
323 cl_int WINAPI wine_clReleaseMemObject(cl_mem memobj)
324 {
325     cl_int ret;
326     TRACE("(%p)\n", memobj);
327     ret = clReleaseMemObject(memobj);
328     TRACE("(%p)=%d\n", memobj, ret);
329     return ret;
330 }
331
332 cl_int WINAPI wine_clGetSupportedImageFormats(cl_context context, cl_mem_flags flags, cl_mem_object_type image_type, cl_uint num_entries,
333                                               cl_image_format * image_formats, cl_uint * num_image_formats)
334 {
335     cl_int ret;
336     TRACE("\n");
337     ret = clGetSupportedImageFormats(context, flags, image_type, num_entries, image_formats, num_image_formats);
338     return ret;
339 }
340
341 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)
342 {
343     cl_int ret;
344     TRACE("\n");
345     ret = clGetMemObjectInfo(memobj, param_name, param_value_size, param_value, param_value_size_ret);
346     return ret;
347 }
348
349 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)
350 {
351     cl_int ret;
352     TRACE("\n");
353     ret = clGetImageInfo(image, param_name, param_value_size, param_value, param_value_size_ret);
354     return ret;
355 }
356
357
358 /*---------------------------------------------------------------*/
359 /* Sampler APIs  */
360
361 cl_sampler WINAPI wine_clCreateSampler(cl_context context, cl_bool normalized_coords, cl_addressing_mode addressing_mode,
362                                        cl_filter_mode filter_mode, cl_int * errcode_ret)
363 {
364     cl_sampler ret;
365     TRACE("\n");
366     ret = clCreateSampler(context, normalized_coords, addressing_mode, filter_mode, errcode_ret);
367     return ret;
368 }
369
370 cl_int WINAPI wine_clRetainSampler(cl_sampler sampler)
371 {
372     cl_int ret;
373     TRACE("\n");
374     ret = clRetainSampler(sampler);
375     return ret;
376 }
377
378 cl_int WINAPI wine_clReleaseSampler(cl_sampler sampler)
379 {
380     cl_int ret;
381     TRACE("\n");
382     ret = clReleaseSampler(sampler);
383     return ret;
384 }
385
386 cl_int WINAPI wine_clGetSamplerInfo(cl_sampler sampler, cl_sampler_info param_name, size_t param_value_size,
387                                     void * param_value, size_t * param_value_size_ret)
388 {
389     cl_int ret;
390     TRACE("\n");
391     ret = clGetSamplerInfo(sampler, param_name, param_value_size, param_value, param_value_size_ret);
392     return ret;
393 }
394
395
396 /*---------------------------------------------------------------*/
397 /* Program Object APIs  */
398
399 cl_program WINAPI wine_clCreateProgramWithSource(cl_context context, cl_uint count, const char ** strings,
400                                                  const size_t * lengths, cl_int * errcode_ret)
401 {
402     cl_program ret;
403     TRACE("\n");
404     ret = clCreateProgramWithSource(context, count, strings, lengths, errcode_ret);
405     return ret;
406 }
407
408 cl_program WINAPI wine_clCreateProgramWithBinary(cl_context context, cl_uint num_devices, const cl_device_id * device_list,
409                                                  const size_t * lengths, const unsigned char ** binaries, cl_int * binary_status,
410                                                  cl_int * errcode_ret)
411 {
412     cl_program ret;
413     TRACE("\n");
414     ret = clCreateProgramWithBinary(context, num_devices, device_list, lengths, binaries, binary_status, errcode_ret);
415     return ret;
416 }
417
418 cl_int WINAPI wine_clRetainProgram(cl_program program)
419 {
420     cl_int ret;
421     TRACE("\n");
422     ret = clRetainProgram(program);
423     return ret;
424 }
425
426 cl_int WINAPI wine_clReleaseProgram(cl_program program)
427 {
428     cl_int ret;
429     TRACE("\n");
430     ret = clReleaseProgram(program);
431     return ret;
432 }
433
434 typedef struct
435 {
436     void WINAPI (*pfn_notify)(cl_program program, void * user_data);
437     void *user_data;
438 } PROGRAM_CALLBACK;
439
440 static void program_fn_notify(cl_program program, void * user_data)
441 {
442     PROGRAM_CALLBACK *pcb;
443     TRACE("(%p, %p)\n", program, user_data);
444     pcb = (PROGRAM_CALLBACK *) user_data;
445     pcb->pfn_notify(program, pcb->user_data);
446     HeapFree(GetProcessHeap(), 0, pcb);
447     TRACE("Callback COMPLETED\n");
448 }
449
450 cl_int WINAPI wine_clBuildProgram(cl_program program, cl_uint num_devices, const cl_device_id * device_list, const char * options,
451                                   void WINAPI (*pfn_notify)(cl_program program, void * user_data),
452                                   void * user_data)
453 {
454     cl_int ret;
455     TRACE("\n");
456     if(pfn_notify)
457     {
458         /* When pfn_notify is provided, clBuildProgram is asynchronous */
459         PROGRAM_CALLBACK *pcb;
460         pcb = HeapAlloc(GetProcessHeap(), 0, sizeof(PROGRAM_CALLBACK));
461         pcb->pfn_notify = pfn_notify;
462         pcb->user_data = user_data;
463         ret = clBuildProgram(program, num_devices, device_list, options, program_fn_notify, pcb);
464     }
465     else
466     {
467         /* When pfn_notify is NULL, clBuildProgram is synchronous */
468         ret = clBuildProgram(program, num_devices, device_list, options, NULL, user_data);
469     }
470     return ret;
471 }
472
473 cl_int WINAPI wine_clUnloadCompiler(void)
474 {
475     cl_int ret;
476     TRACE("()\n");
477     ret = clUnloadCompiler();
478     TRACE("()=%d\n", ret);
479     return ret;
480 }
481
482 cl_int WINAPI wine_clGetProgramInfo(cl_program program, cl_program_info param_name,
483                                     size_t param_value_size, void * param_value, size_t * param_value_size_ret)
484 {
485     cl_int ret;
486     TRACE("\n");
487     ret = clGetProgramInfo(program, param_name, param_value_size, param_value, param_value_size_ret);
488     return ret;
489 }
490
491 cl_int WINAPI wine_clGetProgramBuildInfo(cl_program program, cl_device_id device,
492                                          cl_program_build_info param_name, size_t param_value_size, void * param_value,
493                                          size_t * param_value_size_ret)
494 {
495     cl_int ret;
496     TRACE("\n");
497     ret = clGetProgramBuildInfo(program, device, param_name, param_value_size, param_value, param_value_size_ret);
498     return ret;
499 }
500
501
502 /*---------------------------------------------------------------*/
503 /* Kernel Object APIs */
504
505 cl_kernel WINAPI wine_clCreateKernel(cl_program program, char * kernel_name, cl_int * errcode_ret)
506 {
507     cl_kernel ret;
508     TRACE("\n");
509     ret = clCreateKernel(program, kernel_name, errcode_ret);
510     return ret;
511 }
512
513 cl_int WINAPI wine_clCreateKernelsInProgram(cl_program program, cl_uint num_kernels,
514                                             cl_kernel * kernels, cl_uint * num_kernels_ret)
515 {
516     cl_int ret;
517     TRACE("\n");
518     ret = clCreateKernelsInProgram(program, num_kernels, kernels, num_kernels_ret);
519     return ret;
520 }
521
522 cl_int WINAPI wine_clRetainKernel(cl_kernel kernel)
523 {
524     cl_int ret;
525     TRACE("\n");
526     ret = clRetainKernel(kernel);
527     return ret;
528 }
529
530 cl_int WINAPI wine_clReleaseKernel(cl_kernel kernel)
531 {
532     cl_int ret;
533     TRACE("\n");
534     ret = clReleaseKernel(kernel);
535     return ret;
536 }
537
538 cl_int WINAPI wine_clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, void * arg_value)
539 {
540     cl_int ret;
541     TRACE("\n");
542     ret = clSetKernelArg(kernel, arg_index, arg_size, arg_value);
543     return ret;
544 }
545
546 cl_int WINAPI wine_clGetKernelInfo(cl_kernel kernel, cl_kernel_info param_name,
547                                    size_t param_value_size, void * param_value, size_t * param_value_size_ret)
548 {
549     cl_int ret;
550     TRACE("\n");
551     ret = clGetKernelInfo(kernel, param_name, param_value_size, param_value, param_value_size_ret);
552     return ret;
553 }
554
555 cl_int WINAPI wine_clGetKernelWorkGroupInfo(cl_kernel kernel, cl_device_id device,
556                                             cl_kernel_work_group_info param_name, size_t param_value_size,
557                                             void * param_value, size_t * param_value_size_ret)
558 {
559     cl_int ret;
560     TRACE("\n");
561     ret = clGetKernelWorkGroupInfo(kernel, device, param_name, param_value_size, param_value, param_value_size_ret);
562     return ret;
563 }
564
565
566 /*---------------------------------------------------------------*/
567 /* Event Object APIs  */
568
569 cl_int WINAPI wine_clWaitForEvents(cl_uint num_events, cl_event * event_list)
570 {
571     cl_int ret;
572     TRACE("\n");
573     ret = clWaitForEvents(num_events, event_list);
574     return ret;
575 }
576
577 cl_int WINAPI wine_clGetEventInfo(cl_event event, cl_event_info param_name, size_t param_value_size,
578                                   void * param_value, size_t * param_value_size_ret)
579 {
580     cl_int ret;
581     TRACE("\n");
582     ret = clGetEventInfo(event, param_name, param_value_size, param_value, param_value_size_ret);
583     return ret;
584 }
585
586 cl_int WINAPI wine_clRetainEvent(cl_event event)
587 {
588     cl_int ret;
589     TRACE("\n");
590     ret = clRetainEvent(event);
591     return ret;
592 }
593
594 cl_int WINAPI wine_clReleaseEvent(cl_event event)
595 {
596     cl_int ret;
597     TRACE("\n");
598     ret = clReleaseEvent(event);
599     return ret;
600 }
601
602
603 /*---------------------------------------------------------------*/
604 /* Profiling APIs  */
605
606 cl_int WINAPI wine_clGetEventProfilingInfo(cl_event event, cl_profiling_info param_name, size_t param_value_size,
607                                            void * param_value, size_t * param_value_size_ret)
608 {
609     cl_int ret;
610     TRACE("\n");
611     ret = clGetEventProfilingInfo(event, param_name, param_value_size, param_value, param_value_size_ret);
612     return ret;
613 }
614
615
616 /*---------------------------------------------------------------*/
617 /* Flush and Finish APIs */
618
619 cl_int WINAPI wine_clFlush(cl_command_queue command_queue)
620 {
621     cl_int ret;
622     TRACE("(%p)\n", command_queue);
623     ret = clFlush(command_queue);
624     TRACE("(%p)=%d\n", command_queue, ret);
625     return ret;
626 }
627
628 cl_int WINAPI wine_clFinish(cl_command_queue command_queue)
629 {
630     cl_int ret;
631     TRACE("(%p)\n", command_queue);
632     ret = clFinish(command_queue);
633     TRACE("(%p)=%d\n", command_queue, ret);
634     return ret;
635 }
636
637
638 /*---------------------------------------------------------------*/
639 /* Enqueued Commands APIs */
640
641 cl_int WINAPI wine_clEnqueueReadBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read,
642                                        size_t offset, size_t cb, void * ptr,
643                                        cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
644 {
645     cl_int ret;
646     TRACE("\n");
647     ret = clEnqueueReadBuffer(command_queue, buffer, blocking_read, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
648     return ret;
649 }
650
651 cl_int WINAPI wine_clEnqueueWriteBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write,
652                                         size_t offset, size_t cb, const void * ptr,
653                                         cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
654 {
655     cl_int ret;
656     TRACE("\n");
657     ret = clEnqueueWriteBuffer(command_queue, buffer, blocking_write, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event);
658     return ret;
659 }
660
661 cl_int WINAPI wine_clEnqueueCopyBuffer(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer,
662                                        size_t src_offset, size_t dst_offset, size_t cb,
663                                        cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
664 {
665     cl_int ret;
666     TRACE("\n");
667     ret = clEnqueueCopyBuffer(command_queue, src_buffer, dst_buffer, src_offset, dst_offset, cb, num_events_in_wait_list, event_wait_list, event);
668     return ret;
669 }
670
671 cl_int WINAPI wine_clEnqueueReadImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_read,
672                                       const size_t * origin, const size_t * region,
673                                       SIZE_T row_pitch, SIZE_T slice_pitch, void * ptr,
674                                       cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
675 {
676     cl_int ret;
677     TRACE("(%p, %p, %d, %p, %p, %ld, %ld, %p, %d, %p, %p)\n", command_queue, image, blocking_read,
678           origin, region, row_pitch, slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event);
679     ret = clEnqueueReadImage(command_queue, image, blocking_read, origin, region, row_pitch, slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event);
680     TRACE("(%p, %p, %d, %p, %p, %ld, %ld, %p, %d, %p, %p)=%d\n", command_queue, image, blocking_read,
681           origin, region, row_pitch, slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event, ret);
682     return ret;
683 }
684
685 cl_int WINAPI wine_clEnqueueWriteImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_write,
686                                        const size_t * origin, const size_t * region,
687                                        size_t input_row_pitch, size_t input_slice_pitch, const void * ptr,
688                                        cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
689 {
690     cl_int ret;
691     TRACE("\n");
692     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);
693     return ret;
694 }
695
696 cl_int WINAPI wine_clEnqueueCopyImage(cl_command_queue command_queue, cl_mem src_image, cl_mem dst_image,
697                                       size_t * src_origin, size_t * dst_origin, size_t * region,
698                                       cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
699 {
700     cl_int ret;
701     TRACE("\n");
702     ret = clEnqueueCopyImage(command_queue, src_image, dst_image, src_origin, dst_origin, region, num_events_in_wait_list, event_wait_list, event);
703     return ret;
704 }
705
706 cl_int WINAPI wine_clEnqueueCopyImageToBuffer(cl_command_queue command_queue, cl_mem src_image, cl_mem dst_buffer,
707                                               size_t * src_origin, size_t * region, size_t dst_offset,
708                                               cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
709 {
710     cl_int ret;
711     TRACE("\n");
712     ret = clEnqueueCopyImageToBuffer(command_queue, src_image, dst_buffer, src_origin, region, dst_offset, num_events_in_wait_list, event_wait_list, event);
713     return ret;
714 }
715
716 cl_int WINAPI wine_clEnqueueCopyBufferToImage(cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_image,
717                                               size_t src_offset, size_t * dst_origin, size_t * region,
718                                               cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
719 {
720     cl_int ret;
721     TRACE("\n");
722     ret = clEnqueueCopyBufferToImage(command_queue, src_buffer, dst_image, src_offset, dst_origin, region, num_events_in_wait_list, event_wait_list, event);
723     return ret;
724 }
725
726 void * WINAPI wine_clEnqueueMapBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map,
727                                       cl_map_flags map_flags, size_t offset, size_t cb,
728                                       cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event, cl_int * errcode_ret)
729 {
730     void * ret;
731     TRACE("\n");
732     ret = clEnqueueMapBuffer(command_queue, buffer, blocking_map, map_flags, offset, cb, num_events_in_wait_list, event_wait_list, event, errcode_ret);
733     return ret;
734 }
735
736 void * WINAPI wine_clEnqueueMapImage(cl_command_queue command_queue, cl_mem image, cl_bool blocking_map,
737                                      cl_map_flags map_flags, size_t * origin, size_t * region,
738                                      size_t * image_row_pitch, size_t * image_slice_pitch,
739                                      cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event, cl_int * errcode_ret)
740 {
741     void * ret;
742     TRACE("\n");
743     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);
744     return ret;
745 }
746
747 cl_int WINAPI wine_clEnqueueUnmapMemObject(cl_command_queue command_queue, cl_mem memobj, void * mapped_ptr,
748                                            cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
749 {
750     cl_int ret;
751     TRACE("\n");
752     ret = clEnqueueUnmapMemObject(command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event);
753     return ret;
754 }
755
756 cl_int WINAPI wine_clEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim,
757                                           size_t * global_work_offset, size_t * global_work_size, size_t * local_work_size,
758                                           cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
759 {
760     cl_int ret;
761     TRACE("\n");
762     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);
763     return ret;
764 }
765
766 cl_int WINAPI wine_clEnqueueTask(cl_command_queue command_queue, cl_kernel kernel,
767                                  cl_uint num_events_in_wait_list, cl_event * event_wait_list, cl_event * event)
768 {
769     cl_int ret;
770     TRACE("\n");
771     ret = clEnqueueTask(command_queue, kernel, num_events_in_wait_list, event_wait_list, event);
772     return ret;
773 }
774
775 cl_int WINAPI wine_clEnqueueNativeKernel(cl_command_queue command_queue,
776                                          void WINAPI (*user_func)(void *args),
777                                          void * args, size_t cb_args,
778                                          cl_uint num_mem_objects, const cl_mem * mem_list, const void ** args_mem_loc,
779                                          cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
780 {
781     cl_int ret = CL_INVALID_OPERATION;
782     /* FIXME: There appears to be no obvious method for translating the ABI for user_func.
783      * There is no opaque user_data structure passed, that could encapsulate the return address.
784      * The OpenCL specification seems to indicate that args has an implementation specific
785      * structure that cannot be used to stash away a return address for the WINAPI user_func.
786      */
787 #if 0
788     ret = clEnqueueNativeKernel(command_queue, user_func, args, cb_args, num_mem_objects, mem_list, args_mem_loc,
789                                  num_events_in_wait_list, event_wait_list, event);
790 #else
791     FIXME("not supported due to user_func ABI mismatch\n");
792 #endif
793     return ret;
794 }
795
796 cl_int WINAPI wine_clEnqueueMarker(cl_command_queue command_queue, cl_event * event)
797 {
798     cl_int ret;
799     TRACE("\n");
800     ret = clEnqueueMarker(command_queue, event);
801     return ret;
802 }
803
804 cl_int WINAPI wine_clEnqueueWaitForEvents(cl_command_queue command_queue, cl_uint num_events, cl_event * event_list)
805 {
806     cl_int ret;
807     TRACE("\n");
808     ret = clEnqueueWaitForEvents(command_queue, num_events, event_list);
809     return ret;
810 }
811
812 cl_int WINAPI wine_clEnqueueBarrier(cl_command_queue command_queue)
813 {
814     cl_int ret;
815     TRACE("\n");
816     ret = clEnqueueBarrier(command_queue);
817     return ret;
818 }
819
820
821 /*---------------------------------------------------------------*/
822 /* Extension function access */
823
824 void * WINAPI wine_clGetExtensionFunctionAddress(const char * func_name)
825 {
826     void * ret = 0;
827     TRACE("(%s)\n",func_name);
828 #if 0
829     ret = clGetExtensionFunctionAddress(func_name);
830 #else
831     FIXME("extensions not implemented\n");
832 #endif
833     TRACE("(%s)=%p\n",func_name, ret);
834     return ret;
835 }
836
837
838 #if OPENCL_WITH_GL
839 /*---------------------------------------------------------------*/
840 /* Khronos-approved (KHR) OpenCL extensions which have OpenGL dependencies. */
841
842 cl_mem WINAPI wine_clCreateFromGLBuffer(cl_context context, cl_mem_flags flags, cl_GLuint bufobj, int * errcode_ret)
843 {
844 }
845
846 cl_mem WINAPI wine_clCreateFromGLTexture2D(cl_context context, cl_mem_flags flags, cl_GLenum target,
847                                            cl_GLint miplevel, cl_GLuint texture, cl_int * errcode_ret)
848 {
849 }
850
851 cl_mem WINAPI wine_clCreateFromGLTexture3D(cl_context context, cl_mem_flags flags, cl_GLenum target,
852                                            cl_GLint miplevel, cl_GLuint texture, cl_int * errcode_ret)
853 {
854 }
855
856 cl_mem WINAPI wine_clCreateFromGLRenderbuffer(cl_context context, cl_mem_flags flags, cl_GLuint renderbuffer, cl_int * errcode_ret)
857 {
858 }
859
860 cl_int WINAPI wine_clGetGLObjectInfo(cl_mem memobj, cl_gl_object_type * gl_object_type, cl_GLuint * gl_object_name)
861 {
862 }
863
864 cl_int WINAPI wine_clGetGLTextureInfo(cl_mem memobj, cl_gl_texture_info param_name, size_t param_value_size,
865                                       void * param_value, size_t * param_value_size_ret)
866 {
867 }
868
869 cl_int WINAPI wine_clEnqueueAcquireGLObjects(cl_command_queue command_queue, cl_uint num_objects, const cl_mem * mem_objects,
870                                              cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
871 {
872 }
873
874 cl_int WINAPI wine_clEnqueueReleaseGLObjects(cl_command_queue command_queue, cl_uint num_objects, const cl_mem * mem_objects,
875                                              cl_uint num_events_in_wait_list, const cl_event * event_wait_list, cl_event * event)
876 {
877 }
878
879
880 /*---------------------------------------------------------------*/
881 /* cl_khr_gl_sharing extension  */
882
883 cl_int WINAPI wine_clGetGLContextInfoKHR(const cl_context_properties * properties, cl_gl_context_info param_name,
884                                          size_t param_value_size, void * param_value, size_t * param_value_size_ret)
885 {
886 }
887
888 #endif
889
890
891 #if 0
892 /*---------------------------------------------------------------*/
893 /* cl_khr_icd extension */
894
895 cl_int WINAPI wine_clIcdGetPlatformIDsKHR(cl_uint num_entries, cl_platform_id * platforms, cl_uint * num_platforms)
896 {
897 }
898 #endif