[gegl/gsoc2009-gpu] GeglOperationPointFilter: Implement GPU processing of pixels



commit cbe73b99bf088a0bb8aa3f43e97ae08354b27aa0
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Mon Jul 6 06:52:34 2009 +0800

    GeglOperationPointFilter: Implement GPU processing of pixels
    
    When both GPU acceleration is enabled and at least one GPU processor
    is available for a point filter, GEGL will make use of the GPU processor
    and process GPU textures instead of pixels in main memory.
    
    Refer to the definition of GeglOperationPointFilterGpuProcessor in
    gegl/gegl/operation/gegl-operation-point-filter.h to see how a point filter
    GPU processor should be prototyped.

 gegl/buffer/gegl-buffer-iterator.c           |    1 +
 gegl/operation/gegl-operation-point-filter.c |   53 +++++++++++++++++++++++---
 gegl/operation/gegl-operation-point-filter.h |    7 +++
 3 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index 7e196b2..721de09 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -34,6 +34,7 @@
 
 #include "gegl-gpu-types.h"
 #include "gegl-gpu-texture.h"
+#include "gegl-gpu-init.h"
 
 typedef struct _GeglBufferTileIterator
 {
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index b05f864..07b70ca 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -32,6 +32,9 @@
 #include "gegl-buffer-private.h"
 #include "gegl-tile-storage.h"
 
+#include "gegl-gpu-types.h"
+#include "gegl-gpu-init.h"
+
 static gboolean gegl_operation_point_filter_process
                               (GeglOperation       *operation,
                                GeglBuffer          *input,
@@ -62,7 +65,6 @@ gegl_operation_point_filter_init (GeglOperationPointFilter *self)
 {
 }
 
-
 static gboolean
 gegl_operation_point_filter_process (GeglOperation       *operation,
                                      GeglBuffer          *input,
@@ -71,18 +73,57 @@ gegl_operation_point_filter_process (GeglOperation       *operation,
 {
   const Babl *in_format  = gegl_operation_get_format (operation, "input");
   const Babl *out_format = gegl_operation_get_format (operation, "output");
+
+  GeglOperationClass            *operation_class;
   GeglOperationPointFilterClass *point_filter_class;
 
+  operation_class    = GEGL_OPERATION_GET_CLASS (operation);
   point_filter_class = GEGL_OPERATION_POINT_FILTER_GET_CLASS (operation);
 
-  if ((result->width > 0) && (result->height > 0))
+  if (result->width > 0 && result->height > 0)
     {
-      GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, out_format, GEGL_BUFFER_WRITE);
-      gint read  = gegl_buffer_iterator_add (i, input,  result, in_format, GEGL_BUFFER_READ);
-      while (gegl_buffer_iterator_next (i))
-           point_filter_class->process (operation, i->data[read], i->data[0], i->length, &i->roi[0]);
+      GeglOperationPointFilterGpuProcessor gpu_process
+        = (gpointer) gegl_operation_class_get_gpu_processor (operation_class);
+
+      gboolean use_gpu = (gegl_gpu_is_accelerated () && gpu_process != NULL);
+
+      GeglBufferIterator *i = gegl_buffer_iterator_new (
+                                output,
+                                result,
+                                out_format,
+                                use_gpu
+                                  ? GEGL_BUFFER_GPU_WRITE
+                                  : GEGL_BUFFER_WRITE);
+
+      gint read  = gegl_buffer_iterator_add (i,
+                                             input,
+                                             result,
+                                             in_format,
+                                             use_gpu
+                                               ? GEGL_BUFFER_GPU_READ
+                                               : GEGL_BUFFER_READ);
+
+      if (use_gpu)
+        {
+          while (gegl_buffer_iterator_next (i))
+            gpu_process (operation,
+                         i->gpu_data[read],
+                         i->gpu_data[0],
+                         i->length,
+                         &i->roi[0]);
+        }
+      else
+        {
+          while (gegl_buffer_iterator_next (i))
+            point_filter_class->process (operation,
+                                         i->data[read],
+                                         i->data[0],
+                                         i->length,
+                                         &i->roi[0]);
+        }
 
       gegl_buffer_iterator_free (i);
     }
+
   return TRUE;
 }
diff --git a/gegl/operation/gegl-operation-point-filter.h b/gegl/operation/gegl-operation-point-filter.h
index 29e352c..e251af1 100644
--- a/gegl/operation/gegl-operation-point-filter.h
+++ b/gegl/operation/gegl-operation-point-filter.h
@@ -53,6 +53,13 @@ struct _GeglOperationPointFilterClass
 
 GType gegl_operation_point_filter_get_type (void) G_GNUC_CONST;
 
+typedef gboolean
+(* GeglOperationPointFilterGpuProcessor) (GeglOperation       *self,
+                                          GeglGpuTexture      *in_texture,
+                                          GeglGpuTexture      *out_texture,
+                                          glong                samples,
+                                          const GeglRectangle *roi);
+
 G_END_DECLS
 
 #endif



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