[gegl] Changes in OpenCL library load in Windows



commit 3e99802d7be7e4608dc76122c7df5647afebaca8
Author: Victor Oliveira <victormatheus gmail com>
Date:   Sun Dec 4 16:51:21 2011 -0200

    Changes in OpenCL library load in Windows

 gegl/opencl/gegl-cl-init.c  |   29 +++++++++++++-
 gegl/opencl/gegl-cl-types.h |   88 +++++++++++++++++++++++-------------------
 2 files changed, 74 insertions(+), 43 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 4828671..e3f7ce5 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -89,6 +89,20 @@ gegl_cl_get_command_queue (void)
   return cl_state.cq;
 }
 
+#ifdef G_OS_WIN32
+
+#include <windows.h>
+
+#define CL_LOAD_FUNCTION(func)                                                    \
+if ((gegl_##func = (t_##func) GetProcAddress(module, #func)) == NULL)             \
+  {                                                                               \
+    g_set_error (error, 0, 0, "symbol gegl_##func is NULL");                      \
+    FreeLibrary(module);                                                          \
+    return FALSE;                                                                 \
+  }
+
+#else
+
 #define CL_LOAD_FUNCTION(func)                                                    \
 if (!g_module_symbol (module, #func, (gpointer *)& gegl_##func))                  \
   {                                                                               \
@@ -106,19 +120,26 @@ if (gegl_##func == NULL)
     return FALSE;                                                                 \
   }
 
+#endif
+
 gboolean
 gegl_cl_init (GError **error)
 {
-  GModule *module;
   cl_int err;
 
   if (!cl_state.is_accelerated)
     {
-      module = g_module_open ("libOpenCL.so", G_MODULE_BIND_LAZY);
+      #ifdef G_OS_WIN32
+        HINSTANCE module;
+        module = LoadLibrary ("OpenCL.dll");
+      #else
+        GModule *module;
+        module = g_module_open ("libOpenCL.so", G_MODULE_BIND_LAZY);
+      #endif
 
       if (!module)
         {
-          g_set_error (error, 0, 0, "%s", g_module_error ());
+          g_warning ("Unable to load OpenCL library");
           return FALSE;
         }
 
@@ -216,6 +237,8 @@ gegl_cl_init (GError **error)
   /* XXX: this dict is being leaked */
   cl_program_hash = g_hash_table_new (g_str_hash, g_str_equal);
 
+  g_printf("[OpenCL] OK\n");
+
   return TRUE;
 }
 
diff --git a/gegl/opencl/gegl-cl-types.h b/gegl/opencl/gegl-cl-types.h
index 372d12f..b1028bc 100644
--- a/gegl/opencl/gegl-cl-types.h
+++ b/gegl/opencl/gegl-cl-types.h
@@ -8,45 +8,53 @@
 #include "cl_gl_ext.h"
 #include "cl_ext.h"
 
-typedef cl_int (*t_clGetPlatformIDs)  (cl_uint, cl_platform_id *, cl_uint *);
-typedef cl_int (*t_clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *);
-typedef cl_int (*t_clGetDeviceIDs)    (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *);
-typedef cl_int (*t_clGetDeviceInfo)   (cl_device_id, cl_device_info, size_t, void *, size_t *);
-
-typedef cl_context        (*t_clCreateContext          ) (const cl_context_properties *, cl_uint, const cl_device_id *, void (CL_CALLBACK *) (const char *, const void *, size_t, void *), void *, cl_int *);
-typedef cl_context        (*t_clCreateContextFromType  ) (cl_context_properties *, cl_device_type, void  (*pfn_notify) (const char *, const void *, size_t, void *), void *, cl_int  *);
-typedef cl_command_queue  (*t_clCreateCommandQueue     ) (cl_context context, cl_device_id device, cl_command_queue_properties, cl_int *);
-typedef cl_program        (*t_clCreateProgramWithSource) (cl_context, cl_uint, const char **, const size_t *, cl_int *);
-typedef cl_int            (*t_clBuildProgram           ) (cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK *)(cl_program, void *), void *);
-typedef cl_int            (*t_clGetProgramBuildInfo    ) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *);
-typedef cl_kernel         (*t_clCreateKernel           ) (cl_program, const char *, cl_int *);
-typedef cl_int            (*t_clSetKernelArg           ) (cl_kernel, cl_uint, size_t, const void *);
-typedef cl_int            (*t_clGetKernelWorkGroupInfo ) (cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void *, size_t *);
-typedef cl_mem            (*t_clCreateBuffer           ) (cl_context, cl_mem_flags, size_t, void *, cl_int *);
-typedef cl_int            (*t_clEnqueueWriteBuffer     ) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *);
-typedef cl_int            (*t_clEnqueueReadBuffer      ) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *);
-typedef cl_int            (*t_clEnqueueCopyBuffer      ) (cl_command_queue, cl_mem, cl_mem,  size_t, size_t, size_t, cl_uint, const cl_event *, cl_event *);
-
-typedef cl_mem            (*t_clCreateImage2D          ) (cl_context, cl_mem_flags, const cl_image_format *, size_t, size_t, size_t, void *, cl_int *);
-typedef cl_int            (*t_clEnqueueReadImage       ) (cl_command_queue, cl_mem, cl_bool, const size_t [3], const size_t [3], size_t, size_t, void *, cl_uint, const cl_event *, cl_event *);
-typedef cl_int            (*t_clEnqueueWriteImage      ) (cl_command_queue, cl_mem, cl_bool, const size_t [3], const size_t [3], size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *);
-typedef cl_int            (*t_clEnqueueCopyImage       ) (cl_command_queue, cl_mem, cl_mem, const size_t [3], const size_t [3], const size_t [3], cl_uint, const cl_event *, cl_event *);
-typedef cl_int            (*t_clEnqueueCopyImageToBuffer) (cl_command_queue, cl_mem, cl_mem, const size_t [3], const size_t [3], size_t, cl_uint, const cl_event *, cl_event *);
-typedef cl_int            (*t_clEnqueueCopyBufferToImage) (cl_command_queue, cl_mem, cl_mem, size_t, const size_t [3], const size_t [3], cl_uint, const cl_event *, cl_event *);
-
-typedef void *            (*t_clEnqueueMapBuffer       ) (cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, const cl_event *, cl_event *, cl_int *);
-typedef void *            (*t_clEnqueueMapImage        ) (cl_command_queue, cl_mem, cl_bool, cl_map_flags, const size_t [3], const size_t [3], size_t *, size_t *, cl_uint, const cl_event *, cl_event *, cl_int *);
-typedef cl_int            (*t_clEnqueueUnmapMemObject  ) (cl_command_queue, cl_mem, void *, cl_uint, const cl_event *, cl_event *);
-
-
-typedef cl_int            (*t_clEnqueueNDRangeKernel   ) (cl_command_queue, cl_kernel, cl_uint, const size_t *, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *);
-typedef cl_int            (*t_clEnqueueBarrier         ) (cl_command_queue);
-typedef cl_int            (*t_clFinish                 ) (cl_command_queue);
-
-typedef cl_int (*t_clReleaseKernel      ) (cl_kernel);
-typedef cl_int (*t_clReleaseProgram     ) (cl_program);
-typedef cl_int (*t_clReleaseCommandQueue) (cl_command_queue);
-typedef cl_int (*t_clReleaseContext     ) (cl_context);
-typedef cl_int (*t_clReleaseMemObject   ) (cl_mem);
+#if defined(_WIN32)
+#define CL_API_ENTRY
+#define CL_API_CALL __stdcall
+#else
+#define CL_API_ENTRY
+#define CL_API_CALL
+#endif
+
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clGetPlatformIDs         ) (cl_uint, cl_platform_id *, cl_uint *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clGetPlatformInfo        ) (cl_platform_id, cl_platform_info, size_t, void *, size_t *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clGetDeviceIDs           ) (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clGetDeviceInfo          ) (cl_device_id, cl_device_info, size_t, void *, size_t *);
+
+typedef CL_API_ENTRY cl_context        (CL_API_CALL *t_clCreateContext          ) (const cl_context_properties *, cl_uint, const cl_device_id *, void (CL_CALLBACK *) (const char *, const void *, size_t, void *), void *, cl_int *);
+typedef CL_API_ENTRY cl_context        (CL_API_CALL *t_clCreateContextFromType  ) (cl_context_properties *, cl_device_type, void  (*pfn_notify) (const char *, const void *, size_t, void *), void *, cl_int  *);
+typedef CL_API_ENTRY cl_command_queue  (CL_API_CALL *t_clCreateCommandQueue     ) (cl_context context, cl_device_id device, cl_command_queue_properties, cl_int *);
+typedef CL_API_ENTRY cl_program        (CL_API_CALL *t_clCreateProgramWithSource) (cl_context, cl_uint, const char **, const size_t *, cl_int *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clBuildProgram           ) (cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK *)(cl_program, void *), void *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clGetProgramBuildInfo    ) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *);
+typedef CL_API_ENTRY cl_kernel         (CL_API_CALL *t_clCreateKernel           ) (cl_program, const char *, cl_int *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clSetKernelArg           ) (cl_kernel, cl_uint, size_t, const void *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clGetKernelWorkGroupInfo ) (cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void *, size_t *);
+typedef CL_API_ENTRY cl_mem            (CL_API_CALL *t_clCreateBuffer           ) (cl_context, cl_mem_flags, size_t, void *, cl_int *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueWriteBuffer     ) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueReadBuffer      ) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueCopyBuffer      ) (cl_command_queue, cl_mem, cl_mem,  size_t, size_t, size_t, cl_uint, const cl_event *, cl_event *);
+
+typedef CL_API_ENTRY cl_mem            (CL_API_CALL *t_clCreateImage2D          ) (cl_context, cl_mem_flags, const cl_image_format *, size_t, size_t, size_t, void *, cl_int *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueReadImage       ) (cl_command_queue, cl_mem, cl_bool, const size_t [3], const size_t [3], size_t, size_t, void *, cl_uint, const cl_event *, cl_event *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueWriteImage      ) (cl_command_queue, cl_mem, cl_bool, const size_t [3], const size_t [3], size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueCopyImage       ) (cl_command_queue, cl_mem, cl_mem, const size_t [3], const size_t [3], const size_t [3], cl_uint, const cl_event *, cl_event *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueCopyImageToBuffer) (cl_command_queue, cl_mem, cl_mem, const size_t [3], const size_t [3], size_t, cl_uint, const cl_event *, cl_event *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueCopyBufferToImage) (cl_command_queue, cl_mem, cl_mem, size_t, const size_t [3], const size_t [3], cl_uint, const cl_event *, cl_event *);
+
+typedef CL_API_ENTRY void *            (CL_API_CALL *t_clEnqueueMapBuffer       ) (cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, const cl_event *, cl_event *, cl_int *);
+typedef CL_API_ENTRY void *            (CL_API_CALL *t_clEnqueueMapImage        ) (cl_command_queue, cl_mem, cl_bool, cl_map_flags, const size_t [3], const size_t [3], size_t *, size_t *, cl_uint, const cl_event *, cl_event *, cl_int *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueUnmapMemObject  ) (cl_command_queue, cl_mem, void *, cl_uint, const cl_event *, cl_event *);
+
+
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueNDRangeKernel   ) (cl_command_queue, cl_kernel, cl_uint, const size_t *, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clEnqueueBarrier         ) (cl_command_queue);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clFinish                 ) (cl_command_queue);
+
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clReleaseKernel          ) (cl_kernel);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clReleaseProgram         ) (cl_program);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clReleaseCommandQueue    ) (cl_command_queue);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clReleaseContext         ) (cl_context);
+typedef CL_API_ENTRY cl_int            (CL_API_CALL *t_clReleaseMemObject       ) (cl_mem);
 
 #endif /* __GEGL_CL_TYPES_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]