[gegl] opencl: further simplifiy cl abstrcations for opencl point ops



commit 37272011c56cb1f5fe55657c84a878fe121cc141
Author: Ãyvind KolÃs <pippin gimp org>
Date:   Sat Apr 14 20:10:06 2012 +0200

    opencl: further simplifiy cl abstrcations for opencl point ops

 gegl/operation/gegl-operation-point-filter.c |    2 +-
 gegl/operation/gegl-operation.c              |   20 +++++++++++-----
 gegl/process/gegl-processor.c                |    2 +-
 operations/common/brightness-contrast.c      |   32 +++++++++----------------
 4 files changed, 28 insertions(+), 28 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index cc7f48d..edef3a8 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -170,7 +170,7 @@ gegl_operation_point_filter_process (GeglOperation       *operation,
 
   if ((result->width > 0) && (result->height > 0))
     {
-      if (gegl_cl_is_accelerated () && operation_class->opencl_support)
+      if (gegl_cl_is_accelerated () && operation_class->cl_data)
         {
           if (gegl_operation_point_filter_cl_process (operation, input, output, result, level))
             return TRUE;
diff --git a/gegl/operation/gegl-operation.c b/gegl/operation/gegl-operation.c
index d8f4873..12fc7cf 100644
--- a/gegl/operation/gegl-operation.c
+++ b/gegl/operation/gegl-operation.c
@@ -88,7 +88,6 @@ gegl_operation_class_init (GeglOperationClass *klass)
   klass->attach                    = attach;
   klass->prepare                   = NULL;
   klass->no_cache                  = FALSE;
-  klass->opencl_support            = FALSE;
   klass->get_bounding_box          = get_bounding_box;
   klass->get_invalidated_by_change = get_invalidated_by_change;
   klass->get_required_for_output   = get_required_for_output;
@@ -285,14 +284,23 @@ gegl_operation_prepare (GeglOperation *self)
   klass = GEGL_OPERATION_GET_CLASS (self);
 
   /* build OpenCL kernel */
+  if (!klass->cl_data)
   {
     const gchar *cl_source = gegl_operation_class_get_key (klass, "cl-source");
-    const gchar *cl_kernel = gegl_operation_class_get_key (klass, "cl-kernel");
-    if (cl_source && cl_kernel)
+    if (cl_source)
       {
-        const char *kernel_name[] = {cl_kernel, NULL};
-        gegl_cl_run_data *cl_data = gegl_cl_compile_and_build (cl_source, kernel_name);
-        klass->cl_data = cl_data;
+        char *name = strdup (klass->name);
+        const char *kernel_name[] = {name, NULL};
+        char *k;
+        for (k=name; *k; k++)
+          switch (*k)
+            {
+              case ' ': case ':': case '-':
+                *k = '_';
+                break;
+            }
+        klass->cl_data = gegl_cl_compile_and_build (cl_source, kernel_name);
+        free (name);
       }
   }
 
diff --git a/gegl/process/gegl-processor.c b/gegl/process/gegl-processor.c
index 44702aa..05f7985 100644
--- a/gegl/process/gegl-processor.c
+++ b/gegl/process/gegl-processor.c
@@ -762,7 +762,7 @@ gegl_processor_work (GeglProcessor *processor,
       for (iterator = visits_list; iterator; iterator = iterator->next)
         {
           GeglNode *node = (GeglNode*) iterator->data;
-          if (GEGL_OPERATION_GET_CLASS(node->operation)->opencl_support)
+          if (GEGL_OPERATION_GET_CLASS(node->operation)->cl_data)
             {
               processor->chunk_size = GEGL_CL_CHUNK_SIZE;
               break;
diff --git a/operations/common/brightness-contrast.c b/operations/common/brightness-contrast.c
index 0f932eb..8d37a96 100644
--- a/operations/common/brightness-contrast.c
+++ b/operations/common/brightness-contrast.c
@@ -105,21 +105,19 @@ process (GeglOperation       *op,
   return TRUE;
 }
 
-#include "opencl/gegl-cl.h"
-
 static const gchar* kernel_source =
-"__kernel void kernel_bc(__global const float4     *in,         \n"
-"                        __global       float4     *out,        \n"
-"                        float contrast,                        \n"
-"                        float brightness)                      \n"
-"{                                                              \n"
-"  int gid = get_global_id(0);                                  \n"
-"  float4 in_v  = in[gid];                                      \n"
-"  float4 out_v;                                                \n"
-"  out_v.xyz = (in_v.xyz - 0.5f) * contrast + brightness + 0.5f;\n"
-"  out_v.w   =  in_v.w;                                         \n"
-"  out[gid]  =  out_v;                                          \n"
-"}                                                              \n";
+"__kernel void gegl_brightness_contrast(__global const float4     *in,  \n"
+"                                       __global       float4     *out, \n"
+"                                       float contrast,                 \n"
+"                                       float brightness)               \n"
+"{                                                                      \n"
+"  int gid = get_global_id(0);                                          \n"
+"  float4 in_v  = in[gid];                                              \n"
+"  float4 out_v;                                                        \n"
+"  out_v.xyz = (in_v.xyz - 0.5f) * contrast + brightness + 0.5f;        \n"
+"  out_v.w   =  in_v.w;                                                 \n"
+"  out[gid]  =  out_v;                                                  \n"
+"}                                                                      \n";
 
 /*
  * The class init function sets up information needed for this operations class
@@ -141,17 +139,11 @@ gegl_chant_class_init (GeglChantClass *klass)
    */
   point_filter_class->process = process;
 
-  /* specify the name this operation is found under in the GUI/when
-   * programming/in XML
-   */
-  operation_class->opencl_support = TRUE;
-
   gegl_operation_class_set_keys (operation_class,
       "name",       "gegl:brightness-contrast",
       "categories", "color", 
       "description", _("Changes the light level and contrast."),
       "cl-source"  , kernel_source,
-      "cl-kernel"  , "kernel_bc",
       NULL);
 }
 



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