[gegl/gsoc2011-opencl: 76/78] some opencl texture auxiliar functions



commit e7d21ef5b01c67305c0359be37a83216296afc9c
Author: Victor Oliveira <victormatheus gmail com>
Date:   Tue Jun 21 17:20:53 2011 -0300

    some opencl texture auxiliar functions

 gegl/opencl/gegl-cl-texture.c |   59 +++++++++++++++++++++++++++++++++++++++-
 gegl/opencl/gegl-cl-texture.h |    7 +++++
 2 files changed, 64 insertions(+), 2 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-texture.c b/gegl/opencl/gegl-cl-texture.c
index 2fe6e4b..b17d323 100644
--- a/gegl/opencl/gegl-cl-texture.c
+++ b/gegl/opencl/gegl-cl-texture.c
@@ -33,7 +33,7 @@ gegl_cl_texture_get (const GeglClTexture *texture,
                      gpointer             dst,
                      const gint           size)
 {
-  gegl_clEnqueueReadBuffer(gegl_cl_get_command_queue(), 
+  gegl_clEnqueueReadBuffer(gegl_cl_get_command_queue(),
                            texture->data, CL_TRUE, 0, size, dst,
                            0, NULL, NULL);
   gegl_clFinish(gegl_cl_get_command_queue());
@@ -44,7 +44,7 @@ gegl_cl_texture_set (GeglClTexture  *texture,
                      const gpointer  src,
                      const gint      size)
 {
-  gegl_clEnqueueWriteBuffer(gegl_cl_get_command_queue(), 
+  gegl_clEnqueueWriteBuffer(gegl_cl_get_command_queue(),
                             texture->data, CL_TRUE, 0, size, src,
                             0, NULL, NULL);
   gegl_clFinish(gegl_cl_get_command_queue());
@@ -63,3 +63,58 @@ gegl_cl_texture_dup (const GeglClTexture *texture,
 
   return new_texture;
 }
+
+void
+gegl_cl_texture_copy (const GeglClTexture *src,
+                      GeglClTexture *dst,
+                      const gint           size)
+{
+  gegl_clEnqueueCopyBuffer (gegl_cl_get_command_queue(),
+                            src->data, dst->data,
+                            0, 0, size, 0, NULL, NULL);
+  gegl_clFinish(gegl_cl_get_command_queue());
+}
+
+void
+gegl_cl_texture_clear (const GeglClTexture *texture,
+                       const gint           size)
+{
+  cl_int errcode;
+  char buffer[16384];
+
+  const char* kernel_source[] =
+  {
+  "__kernel void kernel_clear (__global float* dst) \n",
+  "{                                                \n",
+  "  dst[get_global_id(0)] = 0.0f;                  \n",
+  "}                                                \n",
+  };
+
+  cl_program program;
+  cl_kernel kernel;
+
+  CL_SAFE_CALL( program = gegl_clCreateProgramWithSource(gegl_cl_get_context(), 4, (const char **)&kernel_source, NULL, &errcode) );
+  errcode = gegl_clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
+  if (errcode != CL_SUCCESS)
+    {
+      CL_SAFE_CALL( errcode = gegl_clGetProgramBuildInfo(program, gegl_cl_get_device(), CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, NULL) );
+      g_warning("OpenCL Build Error in Line %u in file %s\nError:%s\n%s",
+                __LINE__, __FILE__, gegl_cl_errstring(errcode), buffer);
+      return FALSE;
+    }
+
+  CL_SAFE_CALL( kernel = gegl_clCreateKernel(program, "kernel_clear", &errcode) );
+  CL_SAFE_CALL( errcode = gegl_clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&texture->data) );
+
+  size_t local_worksize;
+  size_t global_worksize;
+
+  // THIS ASSUMES TEXTURE TYPE IS FLOAT !!
+  global_worksize = (size/4);
+
+  CL_SAFE_CALL( errcode = gegl_clEnqueueNDRangeKernel(gegl_cl_get_command_queue(), kernel, 1, NULL, &global_worksize, NULL, 0, NULL, NULL) );
+  gegl_clFinish( errcode = gegl_cl_get_command_queue() );
+
+  CL_SAFE_CALL( errcode = gegl_clReleaseProgram(program) );
+  CL_SAFE_CALL( errcode = gegl_clReleaseKernel(kernel) );
+}
diff --git a/gegl/opencl/gegl-cl-texture.h b/gegl/opencl/gegl-cl-texture.h
index e9bcabb..761f115 100644
--- a/gegl/opencl/gegl-cl-texture.h
+++ b/gegl/opencl/gegl-cl-texture.h
@@ -31,6 +31,13 @@ void            gegl_cl_texture_set      (GeglClTexture       *texture,
 GeglClTexture  *gegl_cl_texture_dup      (const GeglClTexture *texture,
                                           const gint           size);
 
+void            gegl_cl_texture_copy     (const GeglClTexture *src,
+                                          GeglClTexture *dst,
+                                          const gint           size);
+
+void            gegl_cl_texture_clear    (const GeglClTexture *texture,
+                                          const gint           size);
+
 #define GEGL_TYPE_CL_TEXTURE   (gegl_cl_texture_get_type())
 
 #define gegl_cl_texture_get_data(texture) (texture->data)



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