[gegl] Make GEGL_USE_OPENCL=no a hard disable



commit 3ca8183e0cb9496638d3e50b2f0949eaacfb0c6a
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Thu Oct 17 15:32:04 2013 -0700

    Make GEGL_USE_OPENCL=no a hard disable
    
    Setting GEGL_USE_OPENCL=no or --gegl-disable-opencl will
    prevent OpenCL from ever being activated. The value yes
    is now ignored but OpenCL will still start by default if
    the application hasn't changed gegl_config() before init
    is called.

 gegl/gegl-init.c           |   33 ++++++++++++++++-----------------
 gegl/opencl/gegl-cl-init.c |   15 +++++++++++++++
 gegl/opencl/gegl-cl-init.h |    2 ++
 3 files changed, 33 insertions(+), 17 deletions(-)
---
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 341aee4..9ee57b7 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -229,15 +229,15 @@ gegl_init (gint    *argc,
   g_option_context_free (context);
 }
 
-static gchar    *cmd_gegl_swap       = NULL;
-static gchar    *cmd_gegl_cache_size = NULL;
-static gchar    *cmd_gegl_chunk_size = NULL;
-static gchar    *cmd_gegl_quality    = NULL;
-static gchar    *cmd_gegl_tile_size  = NULL;
-static gchar    *cmd_babl_tolerance  = NULL;
-static gchar    *cmd_gegl_threads    = NULL;
-static gboolean *cmd_gegl_opencl     = NULL;
-static gchar    *cmd_gegl_queue_size = NULL;
+static gchar    *cmd_gegl_swap           = NULL;
+static gchar    *cmd_gegl_cache_size     = NULL;
+static gchar    *cmd_gegl_chunk_size     = NULL;
+static gchar    *cmd_gegl_quality        = NULL;
+static gchar    *cmd_gegl_tile_size      = NULL;
+static gchar    *cmd_babl_tolerance      = NULL;
+static gchar    *cmd_gegl_threads        = NULL;
+static gboolean *cmd_gegl_disable_opencl = NULL;
+static gchar    *cmd_gegl_queue_size     = NULL;
 
 static const GOptionEntry cmd_entries[]=
 {
@@ -277,9 +277,9 @@ static const GOptionEntry cmd_entries[]=
      N_("The number of concurrent processing threads to use"), "<threads>"
     },
     {
-      "gegl-use-opencl", 0, 0,
-      G_OPTION_ARG_NONE, &cmd_gegl_opencl,
-      N_("Use OpenCL"), NULL
+      "gegl-disable-opencl", 0, 0,
+      G_OPTION_ARG_NONE, &cmd_gegl_disable_opencl,
+      N_("Disable OpenCL"), NULL
     },
     {
       "gegl-queue-size", 0, 0,
@@ -362,9 +362,9 @@ static void gegl_config_parse_env (GeglConfig *config)
       const char *opencl_env = g_getenv ("GEGL_USE_OPENCL");
 
       if (g_ascii_strcasecmp (opencl_env, "yes") == 0)
-        g_object_set (config, "use-opencl", TRUE, NULL);
+        ;
       else if (g_ascii_strcasecmp (opencl_env, "no") == 0)
-        g_object_set (config, "use-opencl", FALSE, NULL);
+        gegl_cl_hard_disable ();
       else
         g_warning ("Unknown value for GEGL_USE_OPENCL: %s", opencl_env);
     }
@@ -596,9 +596,8 @@ gegl_post_parse_hook (GOptionContext *context,
   /* FIXME: This comes after babl init and is useless */
   if (cmd_babl_tolerance)
     g_object_set (config, "babl-tolerance", atof(cmd_babl_tolerance), NULL);
-  /* don't override the environment variable */
-  if (cmd_gegl_opencl)
-    g_object_set (config, "use-opencl", cmd_gegl_opencl, NULL);
+  if (cmd_gegl_disable_opencl)
+    gegl_cl_hard_disable ();
   if (cmd_gegl_queue_size)
     config->queue_size = atoi (cmd_gegl_queue_size) * 1024 * 1024;
 
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 7e3c24e..a3950dd 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -129,6 +129,7 @@ typedef struct
 {
   gboolean         is_accelerated;
   gboolean         is_loaded;
+  gboolean         hard_disable;
   cl_context       ctx;
   cl_platform_id   platform;
   cl_device_id     device;
@@ -161,6 +162,13 @@ gegl_cl_disable (void)
   cl_state.is_accelerated = FALSE;
 }
 
+void
+gegl_cl_hard_disable (void)
+{
+  cl_state.hard_disable = TRUE;
+  cl_state.is_accelerated = FALSE;
+}
+
 cl_platform_id
 gegl_cl_get_platform (void)
 {
@@ -248,6 +256,13 @@ gegl_cl_init (GError **error)
 {
   cl_int err;
 
+  if (cl_state.hard_disable)
+    {
+      GEGL_NOTE (GEGL_DEBUG_OPENCL, "OpenCL is disabled");
+      g_set_error (error, GEGL_OPENCL_ERROR, 0, "OpenCL is disabled");
+      return FALSE;
+    }
+
   if (!cl_state.is_loaded)
     {
       #ifdef G_OS_WIN32
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index c6fb360..ac527be 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -29,6 +29,8 @@ gboolean          gegl_cl_is_accelerated (void);
 
 void              gegl_cl_disable (void);
 
+void              gegl_cl_hard_disable (void);
+
 cl_platform_id    gegl_cl_get_platform (void);
 
 cl_device_id      gegl_cl_get_device (void);


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