[gegl/gsoc2011-opencl-2] GEGL_USE_OPENCL enviroment variable created



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

    GEGL_USE_OPENCL enviroment variable created

 gegl/gegl-config.c            |   17 ++++++++++++++++-
 gegl/gegl-config.h            |    1 +
 gegl/gegl-init.c              |   11 +++++++++--
 gegl/process/gegl-processor.c |   19 +++++++++++--------
 4 files changed, 37 insertions(+), 11 deletions(-)
---
diff --git a/gegl/gegl-config.c b/gegl/gegl-config.c
index de243a9..353470e 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,9 @@ 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);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
         break;
@@ -217,6 +225,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_int ("use_opencl", "Try to use OpenCL", NULL,
+                                                     FALSE, TRUE, TRUE,
+                                                     G_PARAM_READWRITE));
+
 }
 
 static void
@@ -229,4 +243,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 199d2d3..177841e 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -199,8 +199,9 @@ gegl_init (gint    *argc,
   g_option_context_free (context);
 #endif
 
-  /* Initialize OpenCL if possible */
-  gegl_cl_init (NULL);
+  /* Initialize OpenCL if wanted and possible */
+  if (gegl_config()->use_opencl)
+    gegl_cl_init (NULL);
 }
 
 static gchar   *cmd_gegl_swap=NULL;
@@ -304,6 +305,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 ());
     }
diff --git a/gegl/process/gegl-processor.c b/gegl/process/gegl-processor.c
index e36e8cd..7cfea4a 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,
@@ -747,14 +749,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]