[gegl] box-blur: make consistent across more opencl implementations



commit e1a2971c8ccc3aad3f34b71eb63f7a64048fb51c
Author: André Tupinambá <andrelrt gmail com>
Date:   Sun Sep 20 19:16:58 2015 -0300

    box-blur: make consistent across more opencl implementations

 opencl/box-blur.cl   |   19 +++++++++----------
 opencl/box-blur.cl.h |   19 +++++++++----------
 2 files changed, 18 insertions(+), 20 deletions(-)
---
diff --git a/opencl/box-blur.cl b/opencl/box-blur.cl
index bb85bcb..3ae3ac9 100644
--- a/opencl/box-blur.cl
+++ b/opencl/box-blur.cl
@@ -57,7 +57,9 @@ void kernel_box_blur_fast (__global const float4 *in,
   const int twice_radius = 2 * radius;
   const int in_width = twice_radius + width;
   const int in_height = twice_radius + height;
-  const float4 area = (float4)( (twice_radius + 1) * (twice_radius + 1) );
+  const int start = fmax( -radius, -local_id0 );
+  const int stop = fmin( radius, get_local_size(0) - local_id0 );
+  const float4 area = (float4) ( ((stop - start) + 1) * (twice_radius + 1) );
   int column_index_start,column_index_end;
   int y = get_global_id(1) * size;
   const int out_x = get_group_id(0)
@@ -87,17 +89,14 @@ void kernel_box_blur_fast (__global const float4 *in,
     {
       if (out_x < width)
         {
-          if (local_id0 >= radius && local_id0 < get_local_size(0) - radius)
-            {
-                total_sum = (float4)0.0f;
-
-                for (int i = 0; i < twice_radius + 1; ++i)
-                  {
-                    total_sum += column_sum[local_id0 - radius + i];
-                  }
+          total_sum = (float4)0.0f;
 
-                out[y * width + out_x] = total_sum / area;
+          for (int i = start; i < stop; ++i)
+            {
+              total_sum += column_sum[local_id0 + i];
             }
+
+          out[y * width + out_x] = total_sum / area;
         }
 
     if (--tmp_size == 0 || y == height - 1)
diff --git a/opencl/box-blur.cl.h b/opencl/box-blur.cl.h
index 62f98bd..a6d8c94 100644
--- a/opencl/box-blur.cl.h
+++ b/opencl/box-blur.cl.h
@@ -58,7 +58,9 @@ static const char* box_blur_cl_source =
 "  const int twice_radius = 2 * radius;                                        \n"
 "  const int in_width = twice_radius + width;                                  \n"
 "  const int in_height = twice_radius + height;                                \n"
-"  const float4 area = (float4)( (twice_radius + 1) * (twice_radius + 1) );    \n"
+"  const int start = fmax( -radius, -local_id0 );                              \n"
+"  const int stop = fmin( radius, get_local_size(0) - local_id0 );             \n"
+"  const float4 area = (float4) ( ((stop - start) + 1) * (twice_radius + 1) );\n"
 "  int column_index_start,column_index_end;                                    \n"
 "  int y = get_global_id(1) * size;                                            \n"
 "  const int out_x = get_group_id(0)                                           \n"
@@ -88,17 +90,14 @@ static const char* box_blur_cl_source =
 "    {                                                                         \n"
 "      if (out_x < width)                                                      \n"
 "        {                                                                     \n"
-"          if (local_id0 >= radius && local_id0 < get_local_size(0) - radius)  \n"
-"            {                                                                 \n"
-"                total_sum = (float4)0.0f;                                     \n"
-"                                                                              \n"
-"                for (int i = 0; i < twice_radius + 1; ++i)                    \n"
-"                  {                                                           \n"
-"                    total_sum += column_sum[local_id0 - radius + i];          \n"
-"                  }                                                           \n"
+"          total_sum = (float4)0.0f;                                           \n"
 "                                                                              \n"
-"                out[y * width + out_x] = total_sum / area;                    \n"
+"          for (int i = start; i < stop; ++i)                                  \n"
+"            {                                                                 \n"
+"              total_sum += column_sum[local_id0 + i];                         \n"
 "            }                                                                 \n"
+"                                                                              \n"
+"          out[y * width + out_x] = total_sum / area;                          \n"
 "        }                                                                     \n"
 "                                                                              \n"
 "    if (--tmp_size == 0 || y == height - 1)                                   \n"


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