[gegl] GEGL_USE_OPENCL enviroment variable created and OpenCL Init moved to gegl_post_parse_hook so it work



commit 2e3f26a4ce2a8007c4880b3adf5baff9c202d79f
Author: Victor Oliveira <victormatheus gmail com>
Date:   Mon Nov 21 11:19:59 2011 -0200

    GEGL_USE_OPENCL enviroment variable created and OpenCL Init moved to gegl_post_parse_hook so it works in Gimp

 gegl/gegl-config.c            |   21 ++++++++++++++++++++-
 gegl/gegl-config.h            |    1 +
 gegl/gegl-init.c              |   16 +++++++++++++---
 gegl/process/gegl-processor.c |   19 +++++++++++--------
 4 files changed, 45 insertions(+), 12 deletions(-)
---
diff --git a/gegl/gegl-config.c b/gegl/gegl-config.c
index de243a9..9232e93 100644
--- a/gegl/gegl-config.c
+++ b/gegl/gegl-config.c
@@ -38,7 +38,8 @@ enum
   PROP_BABL_TOLERANCE,
   PROP_TILE_WIDTH,
   PROP_TILE_HEIGHT,
-  PROP_THREADS
+  PROP_THREADS,
+  PROP_USE_OPENCL
 };
 
 static void
@@ -83,6 +84,10 @@ gegl_config_get_property (GObject    *gobject,
         g_value_set_int (value, config->threads);
         break;
 
+      case PROP_USE_OPENCL:
+        g_value_set_boolean (value, config->use_opencl);
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
         break;
@@ -147,6 +152,13 @@ gegl_config_set_property (GObject      *gobject,
       case PROP_THREADS:
         config->threads = g_value_get_int (value);
         return;
+      case PROP_USE_OPENCL:
+        config->use_opencl = g_value_get_boolean (value);
+
+        if (config->use_opencl)
+          gegl_cl_init (NULL);
+
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
         break;
@@ -217,6 +229,12 @@ gegl_config_class_init (GeglConfigClass *klass)
                                    g_param_spec_int ("threads", "Number of concurrent evaluation threads", "default tile height for created buffers.",
                                                      0, 16, 1,
                                                      G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_USE_OPENCL,
+                                   g_param_spec_boolean ("use-opencl", "Try to use OpenCL", NULL,
+                                                     TRUE,
+                                                     G_PARAM_READWRITE));
+
 }
 
 static void
@@ -229,4 +247,5 @@ gegl_config_init (GeglConfig *self)
   self->tile_width  = 128;
   self->tile_height = 64;
   self->threads = 1;
+  self->use_opencl = TRUE;
 }
diff --git a/gegl/gegl-config.h b/gegl/gegl-config.h
index 3847aad..bc60cdc 100644
--- a/gegl/gegl-config.h
+++ b/gegl/gegl-config.h
@@ -45,6 +45,7 @@ struct _GeglConfig
   gint     tile_width;
   gint     tile_height;
   gint     threads;
+  gboolean use_opencl;
 };
 
 struct _GeglConfigClass
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index c8d030d..869a9c9 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -198,9 +198,6 @@ gegl_init (gint    *argc,
 
   g_option_context_free (context);
 #endif
-
-  /* Initialize OpenCL if possible */
-  gegl_cl_init (NULL);
 }
 
 static gchar   *cmd_gegl_swap=NULL;
@@ -304,6 +301,12 @@ GeglConfig *gegl_config (void)
               config->threads = GEGL_MAX_THREADS;
             }
         }
+
+      if (g_getenv ("GEGL_USE_OPENCL") == NULL || strcmp(g_getenv ("GEGL_USE_OPENCL"), "yes") == 0)
+        config->use_opencl = TRUE;
+      else
+        config->use_opencl = FALSE;
+
       if (gegl_swap_dir())
         config->swap = g_strdup(gegl_swap_dir ());
     }
@@ -590,6 +593,13 @@ gegl_post_parse_hook (GOptionContext *context,
     }
 
   swap_clean ();
+
+  /* Initialize OpenCL if wanted and possible */
+  if (gegl_config()->use_opencl)
+    gegl_cl_init (NULL);
+
+  g_printf("[OpenCL] Using OpenCL: %d\n", gegl_config()->use_opencl && cl_state.is_accelerated);
+
   return TRUE;
 }
 
diff --git a/gegl/process/gegl-processor.c b/gegl/process/gegl-processor.c
index 155826f..c7c92e5 100644
--- a/gegl/process/gegl-processor.c
+++ b/gegl/process/gegl-processor.c
@@ -35,6 +35,8 @@
 #include "graph/gegl-visitor.h"
 #include "graph/gegl-visitable.h"
 
+#include "opencl/gegl-cl.h"
+
 enum
 {
   PROP_0,
@@ -755,14 +757,15 @@ gegl_processor_work (GeglProcessor *processor,
   gegl_visitor_dfs_traverse (visitor, GEGL_VISITABLE (processor->node));
   visits_list = gegl_visitor_get_visits_list (visitor);
 
-  for (iterator = visits_list; iterator; iterator = iterator->next)
-    {
-      GeglNode *node = (GeglNode*) iterator->data;
-      if (GEGL_OPERATION_GET_CLASS(node->operation)->opencl_support)
-        {
-          processor->chunk_size = INT_MAX;
-        }
-    }
+  if (gegl_config()->use_opencl && cl_state.is_accelerated)
+    for (iterator = visits_list; iterator; iterator = iterator->next)
+      {
+        GeglNode *node = (GeglNode*) iterator->data;
+        if (GEGL_OPERATION_GET_CLASS(node->operation)->opencl_support)
+          {
+            processor->chunk_size = INT_MAX;
+          }
+      }
 
   more_work = gegl_processor_render (processor, &processor->rectangle, progress);
   if (more_work)



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