[gegl] opencl: Load cl_gl extension functions only if the extension is supported.
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] opencl: Load cl_gl extension functions only if the extension is supported.
- Date: Sat, 23 May 2015 21:06:02 +0000 (UTC)
commit 17c9e8de2fbe783232bfc5590f73eb3e9b07fdc8
Author: Jan Vesely <jan vesely rutgers edu>
Date: Wed Nov 13 11:34:32 2013 -0500
opencl: Load cl_gl extension functions only if the extension is supported.
Load the extensions in a portable way.
Signed-off-by: Jan Vesely <jan vesely rutgers edu>
gegl/opencl/gegl-cl-init.c | 28 +++++++++++++++++++++++++---
gegl/opencl/gegl-cl-init.h | 4 ++++
gegl/opencl/gegl-cl-types.h | 2 ++
3 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 871304a..a5eb95c 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -327,6 +327,16 @@ if (gegl_##func == NULL)
#endif
+#define CL_LOAD_EXTENSION_FUNCTION(func) \
+g_assert(gegl_clGetExtensionFunctionAddress); \
+gegl_##func = gegl_clGetExtensionFunctionAddress(#func); \
+if (gegl_##func == NULL) \
+ { \
+ GEGL_NOTE (GEGL_DEBUG_OPENCL, "symbol gegl_##func is NULL"); \
+ g_set_error (error, GEGL_OPENCL_ERROR, 0, "symbol gegl_##func is NULL"); \
+ return FALSE; \
+ }
+
#if defined(__APPLE__)
typedef struct _CGLContextObject *CGLContextObj;
typedef struct CGLShareGroupRec *CGLShareGroupObj;
@@ -504,9 +514,17 @@ gegl_cl_init_load_functions (GError **error)
CL_LOAD_FUNCTION (clReleaseContext)
CL_LOAD_FUNCTION (clReleaseMemObject)
- CL_LOAD_FUNCTION (clCreateFromGLTexture2D)
- CL_LOAD_FUNCTION (clEnqueueAcquireGLObjects)
- CL_LOAD_FUNCTION (clEnqueueReleaseGLObjects)
+ CL_LOAD_FUNCTION (clGetExtensionFunctionAddress);
+
+ return TRUE;
+}
+
+static gboolean
+gegl_cl_gl_init_load_functions (GError **error)
+{
+ CL_LOAD_EXTENSION_FUNCTION (clCreateFromGLTexture2D)
+ CL_LOAD_EXTENSION_FUNCTION (clEnqueueAcquireGLObjects)
+ CL_LOAD_EXTENSION_FUNCTION (clEnqueueReleaseGLObjects)
return TRUE;
}
@@ -694,6 +712,10 @@ gegl_cl_init_common (cl_device_type requested_device_type,
return FALSE;
}
+ /* Load extension functions */
+ if (!gegl_cl_gl_init_load_functions (error))
+ return FALSE;
+
/* Create context */
ctx = gegl_clCreateContext (gl_contex_props, 1, &cl_state.device, NULL, NULL, &err);
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index 92ddd3b..9d1c983 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -119,6 +119,8 @@ t_clReleaseCommandQueue gegl_clReleaseCommandQueue = NULL;
t_clReleaseContext gegl_clReleaseContext = NULL;
t_clReleaseMemObject gegl_clReleaseMemObject = NULL;
+t_clGetExtensionFunctionAddress gegl_clGetExtensionFunctionAddress = NULL;
+
t_clCreateFromGLTexture2D gegl_clCreateFromGLTexture2D = NULL;
t_clEnqueueAcquireGLObjects gegl_clEnqueueAcquireGLObjects = NULL;
t_clEnqueueReleaseGLObjects gegl_clEnqueueReleaseGLObjects = NULL;
@@ -169,6 +171,8 @@ extern t_clReleaseCommandQueue gegl_clReleaseCommandQueue;
extern t_clReleaseContext gegl_clReleaseContext;
extern t_clReleaseMemObject gegl_clReleaseMemObject;
+extern t_clGetExtensionFunctionAddress gegl_clGetExtensionFunctionAddress;
+
extern t_clCreateFromGLTexture2D gegl_clCreateFromGLTexture2D;
extern t_clEnqueueAcquireGLObjects gegl_clEnqueueAcquireGLObjects;
extern t_clEnqueueReleaseGLObjects gegl_clEnqueueReleaseGLObjects;
diff --git a/gegl/opencl/gegl-cl-types.h b/gegl/opencl/gegl-cl-types.h
index 73c9b3b..eb0ea38 100644
--- a/gegl/opencl/gegl-cl-types.h
+++ b/gegl/opencl/gegl-cl-types.h
@@ -103,4 +103,6 @@ typedef CL_API_ENTRY cl_int (CL_API_CALL *t_clEnqueueReleaseGLObjects
const cl_event *event_wait_list,
cl_event *event);
+typedef CL_API_ENTRY void * (CL_API_CALL *t_clGetExtensionFunctionAddress) (const char *);
+
#endif /* __GEGL_CL_TYPES_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]