RSS/Atom feed Twitter
Site is read-only, email is disabled

[PATCH 1/2] opencl: Load cl_gl extension functions only if the extension is supported.

This discussion is connected to the gegl-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

Jan Vesely
2014-07-28 15:32:23 UTC (over 10 years ago)

[PATCH 1/2] opencl: Load cl_gl extension functions only if the extension is supported.

These are not available on mesa.

Signed-off-by: Jan Vesely ---
gegl/opencl/gegl-cl-init.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)

diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c index 8a52ff5..da5f97d 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -501,6 +501,25 @@ gegl_cl_init_load_functions (GError **error) CL_LOAD_FUNCTION (clReleaseContext) CL_LOAD_FUNCTION (clReleaseMemObject)
+ return TRUE;
+}
+
+static gboolean
+gegl_cl_gl_init_load_functions (GError **error) +{
+#ifdef G_OS_WIN32
+ HINSTANCE module = LoadLibrary ("OpenCL.dll"); +#else
+ GModule *module = g_module_open (CL_LIBRARY_NAME, G_MODULE_BIND_LAZY); +#endif
+
+ if (!module)
+ {
+ GEGL_NOTE (GEGL_DEBUG_OPENCL, "Unable to load OpenCL library"); + g_set_error (error, GEGL_OPENCL_ERROR, 0, "Unable to load OpenCL library"); + return FALSE;
+ }
+
CL_LOAD_FUNCTION (clCreateFromGLTexture2D) CL_LOAD_FUNCTION (clEnqueueAcquireGLObjects) CL_LOAD_FUNCTION (clEnqueueReleaseGLObjects) @@ -691,6 +710,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);

1.9.3
Jan Vesely
2014-07-28 15:32:24 UTC (over 10 years ago)

[PATCH 2/2] opencl: Load extension function in a portable way.

Signed-off-by: Jan Vesely
---
gegl/opencl/gegl-cl-init.c | 31 +++++++++++++++---------------- gegl/opencl/gegl-cl-init.h | 4 ++++ gegl/opencl/gegl-cl-types.h | 2 ++ 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c index da5f97d..f4ba3ce 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -324,6 +324,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; @@ -501,28 +511,17 @@ gegl_cl_init_load_functions (GError **error) CL_LOAD_FUNCTION (clReleaseContext) CL_LOAD_FUNCTION (clReleaseMemObject)
+ CL_LOAD_FUNCTION (clGetExtensionFunctionAddress); +
return TRUE;
}

static gboolean
gegl_cl_gl_init_load_functions (GError **error) {
-#ifdef G_OS_WIN32
- HINSTANCE module = LoadLibrary ("OpenCL.dll"); -#else
- GModule *module = g_module_open (CL_LIBRARY_NAME, G_MODULE_BIND_LAZY); -#endif
-
- if (!module)
- {
- GEGL_NOTE (GEGL_DEBUG_OPENCL, "Unable to load OpenCL library"); - g_set_error (error, GEGL_OPENCL_ERROR, 0, "Unable to load OpenCL library"); - return FALSE;
- }
-
- CL_LOAD_FUNCTION (clCreateFromGLTexture2D) - CL_LOAD_FUNCTION (clEnqueueAcquireGLObjects) - CL_LOAD_FUNCTION (clEnqueueReleaseGLObjects) + CL_LOAD_EXTENSION_FUNCTION (clCreateFromGLTexture2D) + CL_LOAD_EXTENSION_FUNCTION (clEnqueueAcquireGLObjects) + CL_LOAD_EXTENSION_FUNCTION (clEnqueueReleaseGLObjects)
return TRUE;
}
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__ */

1.9.3
Jan Vesely
2014-08-13 15:08:42 UTC (over 10 years ago)

[PATCH 2/2] opencl: Load extension function in a portable way.

ping, any takers?

Jan

On Mon, 2014-07-28 at 11:32 -0400, Jan Vesely wrote:

Signed-off-by: Jan Vesely
---
gegl/opencl/gegl-cl-init.c | 31 +++++++++++++++---------------- gegl/opencl/gegl-cl-init.h | 4 ++++ gegl/opencl/gegl-cl-types.h | 2 ++ 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c index da5f97d..f4ba3ce 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -324,6 +324,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; @@ -501,28 +511,17 @@ gegl_cl_init_load_functions (GError **error) CL_LOAD_FUNCTION (clReleaseContext) CL_LOAD_FUNCTION (clReleaseMemObject)
+ CL_LOAD_FUNCTION (clGetExtensionFunctionAddress); +
return TRUE;
}

static gboolean
gegl_cl_gl_init_load_functions (GError **error) {
-#ifdef G_OS_WIN32
- HINSTANCE module = LoadLibrary ("OpenCL.dll"); -#else
- GModule *module = g_module_open (CL_LIBRARY_NAME, G_MODULE_BIND_LAZY); -#endif
-
- if (!module)
- {
- GEGL_NOTE (GEGL_DEBUG_OPENCL, "Unable to load OpenCL library"); - g_set_error (error, GEGL_OPENCL_ERROR, 0, "Unable to load OpenCL library"); - return FALSE;
- }
-
- CL_LOAD_FUNCTION (clCreateFromGLTexture2D) - CL_LOAD_FUNCTION (clEnqueueAcquireGLObjects) - CL_LOAD_FUNCTION (clEnqueueReleaseGLObjects) + CL_LOAD_EXTENSION_FUNCTION (clCreateFromGLTexture2D) + CL_LOAD_EXTENSION_FUNCTION (clEnqueueAcquireGLObjects) + CL_LOAD_EXTENSION_FUNCTION (clEnqueueReleaseGLObjects)
return TRUE;
}
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__ */

Jan Vesely 
scl
2014-08-16 06:07:24 UTC (over 10 years ago)

[PATCH 2/2] opencl: Load extension function in a portable way.

Hi Jan,

I see you are eagerly taking care for the OpenCL topic and think that's a good idea that doesn't deserve bitrotting on a mailing list.
To increase the chances that your contributions get the attention they deserve I think it would be a good idea to: - come to irc.gimp.org, channel #gegl and poke the GEGL developers there. IMHO daniel_s, massimo, victorm and pippin are the right people to talk to. - contribute your patches as described here: https://wiki.gnome.org/Git/Developers#Contributing_patches This means to either contribute patches by Bugzilla (https://bugzilla.gnome.org) where they can get reviewed, or to get a GNOME Git account, push your patches to a GEGL branch, discuss and merge/cherry-pick them to GEGL master.

Thank you for your efforts and good luck!

Sven

Jan Vesely
2014-08-20 09:23:00 UTC (over 10 years ago)

[PATCH 2/2] opencl: Load extension function in a portable way.

Hi Sven,

thanks for the hints and advice. I should have read the developer info before sending out the patches. There's now a bug report with the patches attached.

thanks
Jan

On Sat, 2014-08-16 at 08:07 +0200, scl wrote:

Hi Jan,

I see you are eagerly taking care for the OpenCL topic and think that's a good idea that doesn't deserve bitrotting on a mailing list.
To increase the chances that your contributions get the attention they deserve I think it would be a good idea to: - come to irc.gimp.org, channel #gegl and poke the GEGL developers there. IMHO daniel_s, massimo, victorm and pippin are the right people to talk to. - contribute your patches as described here: https://wiki.gnome.org/Git/Developers#Contributing_patches This means to either contribute patches by Bugzilla (https://bugzilla.gnome.org) where they can get reviewed, or to get a GNOME Git account, push your patches to a GEGL branch, discuss and merge/cherry-pick them to GEGL master.

Thank you for your efforts and good luck!

Sven

Jan Vesely