[gegl] Add gegl_cl_has_extension()



commit 8a9933e44daa32d7a48f60c8e69b063ac1aaecd2
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Fri Nov 1 16:01:40 2013 -0700

    Add gegl_cl_has_extension()
    
    Takes an extension name and returns TRUE if it is available on the
    current device. Must be called after OpenCL is initialized.

 gegl/opencl/gegl-cl-init.c |   37 +++++++++++++++++++++++++++++++++++++
 gegl/opencl/gegl-cl-init.h |    2 ++
 2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index c6e85d4..0fc257c 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -221,6 +221,43 @@ gegl_cl_set_profiling (gboolean enable)
   cl_state.enable_profiling = enable;
 }
 
+gboolean
+gegl_cl_has_extension (const char *extension_name)
+{
+  size_t     string_len;
+  gchar     *device_ext_string = NULL;
+  gchar    **extensions;
+  gboolean   found = FALSE;
+
+  if (!gegl_cl_is_accelerated () || !extension_name)
+    return FALSE;
+
+  gegl_clGetDeviceInfo (cl_state.device, CL_DEVICE_EXTENSIONS,
+                        0, NULL, &string_len);
+
+  if (!string_len)
+    return FALSE;
+
+  device_ext_string = g_malloc (string_len);
+
+
+  gegl_clGetDeviceInfo (cl_state.device, CL_DEVICE_EXTENSIONS,
+                        string_len, device_ext_string, NULL);
+
+  extensions = g_strsplit (device_ext_string, " ", 0);
+
+  for (gint i = 0; extensions[i] && !found; ++i)
+    {
+      if (!strcmp (extensions[i], extension_name))
+        found = TRUE;
+    }
+
+  g_free (device_ext_string);
+  g_strfreev (extensions);
+
+  return found;
+}
+
 #ifdef G_OS_WIN32
 
 #include <windows.h>
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index 4e241f1..4d7ff0e 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -47,6 +47,8 @@ size_t            gegl_cl_get_iter_height (void);
 
 void              gegl_cl_set_profiling (gboolean enable);
 
+gboolean          gegl_cl_has_extension (const char *extension_name);
+
 typedef struct
 {
   cl_program  program;


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