Commit ce5cd83c authored by Victor Oliveira's avatar Victor Oliveira

cl: Fixing more bugs and adding cl support to write-buffer

so we can perform color conversion in the GPU for output
parent bd4b9165
......@@ -25,6 +25,7 @@
#include <gio/gio.h>
#include "gegl.h"
#include "gegl/gegl-debug.h"
#include "gegl-types-internal.h"
#include "gegl-buffer-types.h"
#include "gegl-buffer.h"
......
......@@ -342,6 +342,8 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
case GEGL_CL_COLOR_NOT_SUPPORTED:
{
gegl_buffer_cl_cache_flush (i->buffer[no], &i->roi[no][j]);
g_assert (i->tex_op[no][j] == NULL);
i->tex_op[no][j] = gegl_clCreateBuffer (gegl_cl_get_context (),
CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_ONLY,
......
......@@ -219,9 +219,7 @@ gegl_tile_handler_cache_get_tile_command (GeglTileSource *tile_store,
GeglTile *tile = NULL;
if (gegl_cl_is_accelerated ())
{
gegl_buffer_cl_cache_flush2 (cache, NULL);
}
gegl_buffer_cl_cache_flush2 (cache, NULL);
tile = gegl_tile_handler_cache_get_tile (cache, x, y, z);
if (tile)
......@@ -261,6 +259,9 @@ gegl_tile_handler_cache_command (GeglTileSource *tile_store,
{
GList *link;
if (gegl_cl_is_accelerated ())
gegl_buffer_cl_cache_flush2 (GEGL_TILE_HANDLER_CACHE (tile_store), NULL);
for (link = g_queue_peek_head_link (cache_queue); link; link = link->next)
{
CacheItem *item = link->data;
......
......@@ -113,7 +113,7 @@ choose_kernel (const Babl *in_format, const Babl *out_format)
{
if (out_format == babl_format ("RGBA u8")) kernel = CL_RGBAF_TO_RGBAU8;
else if (out_format == babl_format ("RaGaBaA float")) kernel = CL_RGBAF_TO_RAGABAF;
else if (out_format == babl_format ("R'G'B' u8")) kernel = CL_RGBAF_TO_RGB_GAMMA_U8;
else if (out_format == babl_format ("R'G'B' u8")) kernel = CL_RGBAF_TO_RGB_GAMMA_U8;
else if (out_format == babl_format ("R'G'B'A u8")) kernel = CL_RGBAF_TO_RGBA_GAMMA_U8;
else if (out_format == babl_format ("R'G'B'A float")) kernel = CL_RGBAF_TO_RGBA_GAMMA_F;
else if (out_format == babl_format ("Y'CbCrA float")) kernel = CL_RGBAF_TO_YCBCRAF;
......
......@@ -33,6 +33,9 @@ gegl_chant_object (buffer, _("Buffer location"),
#include "gegl-chant.h"
#include "graph/gegl-node.h"
#include "gegl/gegl-debug.h"
#include "opencl/gegl-cl.h"
static gboolean
process (GeglOperation *operation,
GeglBuffer *input,
......@@ -45,7 +48,40 @@ process (GeglOperation *operation,
{
GeglBuffer *output = GEGL_BUFFER (o->buffer);
gegl_buffer_copy (input, result, output, result);
if (gegl_cl_is_accelerated ()
&& gegl_cl_color_supported (input->soft_format, output->soft_format) == GEGL_CL_COLOR_CONVERT)
{
GEGL_NOTE (GEGL_DEBUG_OPENCL, "write-buffer: %p %p %s %s {%d %d %d %d}", input, output, babl_get_name(input->soft_format), babl_get_name(output->soft_format),
result->x, result->y, result->width, result->height);
size_t size;
gboolean err;
cl_int cl_err;
gint j;
gegl_cl_color_babl (output->soft_format, &size);
GeglBufferClIterator *i = gegl_buffer_cl_iterator_new (output, result, output->soft_format, GEGL_CL_BUFFER_WRITE, GEGL_ABYSS_NONE);
gint read = gegl_buffer_cl_iterator_add (i, input, result, output->soft_format, GEGL_CL_BUFFER_READ, GEGL_ABYSS_NONE);
while (gegl_buffer_cl_iterator_next (i, &err))
{
if (err) break;
for (j=0; j < i->n; j++)
{
cl_err = gegl_clEnqueueCopyBuffer (gegl_cl_get_command_queue (),
i->tex[read][j], i->tex[0][j], 0, 0, i->size[0][j] * size,
0, NULL, NULL);
if (cl_err != CL_SUCCESS)
{
GEGL_NOTE (GEGL_DEBUG_OPENCL, "Error in gegl_buffer_copy: %s", gegl_cl_errstring(cl_err));
break;
}
}
}
}
else
gegl_buffer_copy (input, result, output, result);
gegl_buffer_flush (output);
gegl_node_emit_computed (operation->node, result);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment