diff options
author | Nanley Chery <nanleychery@gmail.com> | 2014-12-08 04:49:14 -0500 |
---|---|---|
committer | Øyvind Kolås <pippin@gimp.org> | 2015-05-23 22:55:56 +0200 |
commit | c9c1181bc28189a09da2c8017e4a8bdd277e376e (patch) | |
tree | 1ef0eb7a5357abec2d0f8ad49a2b0455dd3d3a53 | |
parent | 60ff4cb68895589e7f7297405988d8a68f0644da (diff) |
operations: move checkerboard kernel source to opencl folder
-rw-r--r-- | opencl/checkerboard.cl | 28 | ||||
-rw-r--r-- | opencl/checkerboard.cl.h | 30 | ||||
-rw-r--r-- | operations/common/checkerboard.c | 31 |
3 files changed, 59 insertions, 30 deletions
diff --git a/opencl/checkerboard.cl b/opencl/checkerboard.cl new file mode 100644 index 00000000..06448115 --- /dev/null +++ b/opencl/checkerboard.cl @@ -0,0 +1,28 @@ +inline int tile_index (int coordinate, int stride) +{ + int a = (coordinate < 0); + return ((coordinate + a) / stride) - a; +} + +__kernel void kernel_checkerboard (__global float4 *out, + float4 color1, + float4 color2, + int square_width, + int square_height, + int x_offset, + int y_offset) +{ + size_t roi_width = get_global_size(0); + size_t roi_x = get_global_offset(0); + size_t roi_y = get_global_offset(1); + size_t gidx = get_global_id(0) - roi_x; + size_t gidy = get_global_id(1) - roi_y; + + int x = get_global_id(0) - x_offset; + int y = get_global_id(1) - y_offset; + + int tilex = tile_index (x, square_width); + int tiley = tile_index (y, square_height); + out[gidx + gidy * roi_width] = (tilex + tiley) & 1 ? + color2 : color1; +} diff --git a/opencl/checkerboard.cl.h b/opencl/checkerboard.cl.h new file mode 100644 index 00000000..cda511f8 --- /dev/null +++ b/opencl/checkerboard.cl.h @@ -0,0 +1,30 @@ +static const char* checkerboard_cl_source = +"inline int tile_index (int coordinate, int stride) \n" +"{ \n" +" int a = (coordinate < 0); \n" +" return ((coordinate + a) / stride) - a; \n" +"} \n" +" \n" +"__kernel void kernel_checkerboard (__global float4 *out, \n" +" float4 color1, \n" +" float4 color2, \n" +" int square_width, \n" +" int square_height, \n" +" int x_offset, \n" +" int y_offset) \n" +"{ \n" +" size_t roi_width = get_global_size(0); \n" +" size_t roi_x = get_global_offset(0); \n" +" size_t roi_y = get_global_offset(1); \n" +" size_t gidx = get_global_id(0) - roi_x; \n" +" size_t gidy = get_global_id(1) - roi_y; \n" +" \n" +" int x = get_global_id(0) - x_offset; \n" +" int y = get_global_id(1) - y_offset; \n" +" \n" +" int tilex = tile_index (x, square_width); \n" +" int tiley = tile_index (y, square_height); \n" +" out[gidx + gidy * roi_width] = (tilex + tiley) & 1 ? \n" +" color2 : color1; \n" +"} \n" +; diff --git a/operations/common/checkerboard.c b/operations/common/checkerboard.c index 319025cd..f40eed4d 100644 --- a/operations/common/checkerboard.c +++ b/operations/common/checkerboard.c @@ -87,42 +87,13 @@ get_bounding_box (GeglOperation *operation) return gegl_rectangle_infinite_plane (); } -static const char* checkerboard_cl_source = -"inline int tile_index (int coordinate, int stride) \n" -"{ \n" -" int a = (coordinate < 0); \n" -" return ((coordinate + a) / stride) - a; \n" -"} \n" -" \n" -"__kernel void kernel_checkerboard (__global float4 *out, \n" -" float4 color1, \n" -" float4 color2, \n" -" int square_width, \n" -" int square_height, \n" -" int x_offset, \n" -" int y_offset) \n" -"{ \n" -" size_t roi_width = get_global_size(0); \n" -" size_t roi_x = get_global_offset(0); \n" -" size_t roi_y = get_global_offset(1); \n" -" size_t gidx = get_global_id(0) - roi_x; \n" -" size_t gidy = get_global_id(1) - roi_y; \n" -" \n" -" int x = get_global_id(0) - x_offset; \n" -" int y = get_global_id(1) - y_offset; \n" -" \n" -" int tilex = tile_index (x, square_width); \n" -" int tiley = tile_index (y, square_height); \n" -" out[gidx + gidy * roi_width] = (tilex + tiley) & 1 ? \n" -" color2 : color1; \n" -"} \n"; - #define TILE_INDEX(coordinate,stride) \ (((coordinate) >= 0)?\ (coordinate) / (stride):\ ((((coordinate) + 1) /(stride)) - 1)) +#include "opencl/checkerboard.cl.h" static GeglClRunData *cl_data = NULL; static gboolean |