summaryrefslogtreecommitdiff
path: root/opencl
diff options
context:
space:
mode:
authorNanley 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
commitc9c1181bc28189a09da2c8017e4a8bdd277e376e (patch)
tree1ef0eb7a5357abec2d0f8ad49a2b0455dd3d3a53 /opencl
parent60ff4cb68895589e7f7297405988d8a68f0644da (diff)
operations: move checkerboard kernel source to opencl folder
Diffstat (limited to 'opencl')
-rw-r--r--opencl/checkerboard.cl28
-rw-r--r--opencl/checkerboard.cl.h30
2 files changed, 58 insertions, 0 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"
+;