parent
d8f31d2e81
commit
1b379e095e
@ -1,7 +1,20 @@
|
|||||||
__kernel void conway_align(__global unsigned char* front_grid, __global unsigned char* rear_grid, __global unsigned char* pixel_out, __global int* num_workers, __global int* grid_width, __global int* grid_height){
|
__kernel void conway_align(__read_only image2d_t front_image, __global char* back_image, __global int* num_workers, __global int* grid_width, __global int *grid_height)
|
||||||
|
{
|
||||||
|
const sampler_t sampler=CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
|
||||||
|
|
||||||
|
// Caclulate the start and end range that this worker will be calculating
|
||||||
|
int data_length = *grid_width * *grid_height;
|
||||||
|
|
||||||
|
int start_range = (data_length / *num_workers) * get_global_id(0);
|
||||||
|
int end_range = (data_length / *num_workers) * (get_global_id(0) + 1);
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = start_range; i < end_range; i++){
|
||||||
|
|
||||||
|
uint4 pixel;
|
||||||
|
pixel = read_imageui(front_image, sampler, (int2)(i,get_global_id(0)));
|
||||||
|
|
||||||
|
back_image[i] = pixel.w / 255;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,21 +1,59 @@
|
|||||||
__kernel void conway_compute(__write_only image2d_t front_grid, __global int* num_workers, __global int* grid_width, __global int *grid_height)
|
__kernel void conway_compute(__write_only image2d_t front_image, __global char* back_image, __global int* num_workers, __global int* grid_width, __global int *grid_height)
|
||||||
{
|
{
|
||||||
|
|
||||||
//int width = *grid_width;
|
float4 black = (float4)(.49, .68, .81, 1);
|
||||||
//int height = grid_height;
|
float4 white = (float4)(.49, .68, .71, .3);
|
||||||
|
|
||||||
for (int i = 0; i < 90000; i ++){
|
// Caclulate the start and end range that this worker will be calculating
|
||||||
int2 pixelcoord = (int2) (i % *grid_width, i / *grid_height);
|
int data_length = *grid_width * *grid_height;
|
||||||
//if (pixelcoord.x < width && pixelcoord.y < height)
|
|
||||||
//{
|
|
||||||
//float4 pixel = read_imagef(image1, sampler, (int2)(pixelcoord.x, pixelcoord.y));
|
|
||||||
int4 black = (int4)(0,0,0,0);
|
|
||||||
|
|
||||||
|
int start_range = (data_length / *num_workers) * get_global_id(0);
|
||||||
|
int end_range = (data_length / *num_workers) * (get_global_id(0) + 1);
|
||||||
|
|
||||||
|
// x, y + 1
|
||||||
|
|
||||||
//write_imagef(front_grid, pixelcoord, black);
|
int neighbors = 0;
|
||||||
|
|
||||||
write_imagei(front_grid, pixelcoord, black);
|
for (int i = start_range; i < end_range; i++){
|
||||||
|
|
||||||
}
|
int2 pixelcoord = (int2) (i % *grid_width, i / *grid_height);
|
||||||
//}
|
|
||||||
|
// add all 8 blocks to neghbors
|
||||||
|
neighbors = 0;
|
||||||
|
// Top
|
||||||
|
neighbors += back_image[i - *grid_width];
|
||||||
|
|
||||||
|
// Top right
|
||||||
|
neighbors += back_image[i - *grid_width + 1];
|
||||||
|
|
||||||
|
// Right
|
||||||
|
neighbors += back_image[i + 1];
|
||||||
|
|
||||||
|
// Bottom Right
|
||||||
|
neighbors += back_image[i + *grid_width + 1];
|
||||||
|
|
||||||
|
// Bottom
|
||||||
|
neighbors += back_image[i + *grid_width];
|
||||||
|
|
||||||
|
// Bottom Left
|
||||||
|
neighbors += back_image[i + *grid_width - 1];
|
||||||
|
|
||||||
|
// Left
|
||||||
|
neighbors += back_image[i - 1];
|
||||||
|
|
||||||
|
// Top left
|
||||||
|
neighbors += back_image[i - *grid_width - 1];
|
||||||
|
|
||||||
|
// push living status to the padded second char
|
||||||
|
|
||||||
|
|
||||||
|
write_imagef(front_image, pixelcoord, black);
|
||||||
|
|
||||||
|
if (neighbors == 3 || (neighbors == 2 && back_image[i])){
|
||||||
|
write_imagef(front_image, pixelcoord, white);
|
||||||
|
}
|
||||||
|
|
||||||
|
//else
|
||||||
|
//write_imagei(front_image, pixelcoord, white);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue