[gegl/gsoc2011-opencl: 17/19] GeglOperationPointFilter uses OpenCL



commit fec6e86f31c328a62877fd33bf5eebcd8d13aa22
Author: Victor Oliveira <victormatheus gmail com>
Date:   Thu Aug 18 13:28:50 2011 -0300

    GeglOperationPointFilter uses OpenCL

 gegl/operation/gegl-operation-point-filter.c |   35 +++++++++++++++++--------
 gegl/operation/gegl-operation-point-filter.h |    8 ++++++
 2 files changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index b53c726..2a012a8 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -60,6 +60,9 @@ gegl_operation_point_filter_class_init (GeglOperationPointFilterClass *klass)
   operation_class->process = gegl_operation_point_filter_op_process;
   operation_class->prepare = prepare;
   operation_class->no_cache = TRUE;
+
+  klass->process = NULL;
+  klass->cl_process = NULL;
 }
 
 static void
@@ -82,16 +85,25 @@ gegl_operation_point_filter_process (GeglOperation       *operation,
 
   if ((result->width > 0) && (result->height > 0))
     {
-
-      {
-        GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, out_format, GEGL_BUFFER_WRITE);
-        gint read = /*output == input ? 0 :*/ gegl_buffer_iterator_add (i, input,  result, in_format, GEGL_BUFFER_READ);
-        /* using separate read and write iterators for in-place ideally a single
-         * readwrite indice would be sufficient
-         */
+      /* TODO: OpenCL code only handles RGBA float input & output */
+      if (gegl_cl_is_accelerated () && point_filter_class->cl_process
+          && input->format == babl_format ("RGBA float") && output->format == babl_format ("RGBA float"))
+        {
+          GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, out_format, GEGL_BUFFER_CL_WRITE);
+          gint read = gegl_buffer_iterator_add (i, input,  result, in_format, GEGL_BUFFER_CL_READ);
           while (gegl_buffer_iterator_next (i))
-            point_filter_class->process (operation, i->data[read], i->data[0], i->length, &i->roi[0]);
-      }
+            point_filter_class->cl_process (operation, i->cl_data[read], i->cl_data[0], i->length, &i->roi[0]);
+        }
+      else
+        {
+          GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, out_format, GEGL_BUFFER_WRITE);
+          gint read = /*output == input ? 0 :*/ gegl_buffer_iterator_add (i, input,  result, in_format, GEGL_BUFFER_READ);
+          /* using separate read and write iterators for in-place ideally a single
+           * readwrite indice would be sufficient
+           */
+            while (gegl_buffer_iterator_next (i))
+              point_filter_class->process (operation, i->data[read], i->data[0], i->length, &i->roi[0]);
+        }
     }
   return TRUE;
 }
@@ -129,12 +141,13 @@ static gboolean gegl_operation_point_filter_op_process
 
   input = gegl_operation_context_get_source (context, "input");
 
-  if (gegl_can_do_inplace_processing (operation, input, roi))
+  /* TODO: Currently, buffer locking mechanism doesn't work well with inplace processing  */
+  /*if (gegl_can_do_inplace_processing (operation, input, roi))
     {
       output = g_object_ref (input);
       gegl_operation_context_take_object (context, "output", G_OBJECT (output));
     }
-  else
+  else*/
     {
       output = gegl_operation_context_get_target (context, "output");
     }
diff --git a/gegl/operation/gegl-operation-point-filter.h b/gegl/operation/gegl-operation-point-filter.h
index e4efba2..21eb0ed 100644
--- a/gegl/operation/gegl-operation-point-filter.h
+++ b/gegl/operation/gegl-operation-point-filter.h
@@ -26,6 +26,7 @@
 #ifndef __GEGL_OPERATION_POINT_FILTER_H__
 #define __GEGL_OPERATION_POINT_FILTER_H__
 
+#include "gegl-cl-texture.h"
 #include "gegl-operation-filter.h"
 
 G_BEGIN_DECLS
@@ -56,6 +57,13 @@ struct _GeglOperationPointFilterClass
                                                         in in buffer, see the
                                                         checkerboard op for
                                                         semantics */
+
+  gboolean (* cl_process) (GeglOperation      *self,
+                           GeglClTexture      *in_buf,
+                           GeglClTexture      *out_buf,
+                           glong               samples,
+                           const GeglRectangle *roi);
+
 };
 
 GType gegl_operation_point_filter_get_type (void) G_GNUC_CONST;



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