[gegl/threaded-base-classes: 21/22] use temporary buffers and fishes inside conversions
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/threaded-base-classes: 21/22] use temporary buffers and fishes inside conversions
- Date: Mon, 30 Jun 2014 02:16:39 +0000 (UTC)
commit d29ba9fea8d2c231c71ab75a4528e3a94e964de6
Author: Øyvind Kolås <pippin gimp org>
Date: Mon Jun 30 02:03:28 2014 +0200
use temporary buffers and fishes inside conversions
gegl/buffer/gegl-buffer-iterator.c | 2 +-
gegl/operation/gegl-operation-point-composer3.c | 180 +++++++++++++++++++----
2 files changed, 155 insertions(+), 27 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index 585829a..0f00938 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -130,7 +130,7 @@ gegl_buffer_iterator_add (GeglBufferIterator *iter,
sub = &priv->sub_iter[index];
if (!format)
- format = gegl_buffer_get_format (buf);
+ format = gegl_buffer_get_format (buf); // XXX: inline
if (!roi)
roi = &buf->extent;
diff --git a/gegl/operation/gegl-operation-point-composer3.c b/gegl/operation/gegl-operation-point-composer3.c
index f9cd039..ba24b39 100644
--- a/gegl/operation/gegl-operation-point-composer3.c
+++ b/gegl/operation/gegl-operation-point-composer3.c
@@ -29,8 +29,6 @@
#include <unistd.h>
#include <string.h>
-pthread_t main_thread = 0;
-
typedef struct ThreadData
{
GeglOperationPointComposer3Class *klass;
@@ -44,6 +42,15 @@ typedef struct ThreadData
gint level;
gboolean success;
GeglRectangle roi;
+
+ guchar *in_tmp;
+ guchar *aux_tmp;
+ guchar *aux2_tmp;
+ guchar *output_tmp;
+ const Babl *input_fish;
+ const Babl *aux_fish;
+ const Babl *aux2_fish;
+ const Babl *output_fish;
} ThreadData;
static GMutex pool_mutex = {0,};
@@ -52,12 +59,40 @@ static GCond pool_cond = {0,};
static void thread_process (gpointer thread_data, gpointer unused)
{
ThreadData *data = thread_data;
+
+ guchar *input = data->input;
+ guchar *aux = data->aux;
+ guchar *aux2 = data->aux2;
+ guchar *output = data->output;
+ glong samples = data->roi.width * data->roi.height;
+
+ if (data->input_fish && input)
+ {
+ babl_process (data->input_fish, data->input, data->in_tmp, samples);
+ input = data->in_tmp;
+ }
+ if (data->aux_fish && aux)
+ {
+ babl_process (data->aux_fish, data->aux, data->aux_tmp, samples);
+ aux = data->aux_tmp;
+ }
+ if (data->aux2_fish && aux2)
+ {
+ babl_process (data->aux2_fish, data->aux2, data->aux2_tmp, samples);
+ aux2 = data->aux2_tmp;
+ }
+ if (data->output_fish)
+ output = data->output_tmp;
+
if (!data->klass->process (data->operation,
- data->input, data->aux, data->aux2,
- data->output, data->roi.width * data->roi.height,
+ input, aux, aux2,
+ output, samples,
&data->roi, data->level))
data->success = FALSE;
+ if (data->output_fish)
+ babl_process (data->output_fish, data->output_tmp, data->output, samples);
+
g_atomic_int_add (data->pending, -1);
if (*data->pending == 0)
{
@@ -188,6 +223,14 @@ gegl_operation_point_composer3_init (GeglOperationPointComposer3 *self)
}
+static guchar *qalloc (int tid, int i)
+{
+ static guchar *alloc[GEGL_MAX_THREADS][4]={{NULL,}};
+ if (!alloc[tid][i])
+ alloc[tid][i] = gegl_malloc (256 * 256 * 16);
+ return alloc[tid][i];
+}
+
#include <math.h>
static gboolean
@@ -205,36 +248,116 @@ gegl_operation_point_composer3_process (GeglOperation *operation,
const Babl *aux2_format = gegl_operation_get_format (operation, "aux2");
const Babl *out_format = gegl_operation_get_format (operation, "output");
+
if ((result->width > 0) && (result->height > 0))
{
+ const Babl *in_buf_format = input?gegl_buffer_get_format(input):NULL;
+ const Babl *aux_buf_format = aux?gegl_buffer_get_format(aux):NULL;
+ const Babl *aux2_buf_format = aux2?gegl_buffer_get_format(aux2):NULL;
+ const Babl *output_buf_format = output?gegl_buffer_get_format(output):NULL;
+
if (gegl_operation_use_threading (operation, result) && result->height > 1)
{
gint threads = gegl_config ()->threads;
GThreadPool *pool = thread_pool ();
- GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, out_format,
GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
+ ThreadData thread_data[GEGL_MAX_THREADS];
+ GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, output_buf_format,
GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
gint foo = 0, bar = 0, read = 0;
- gint in_bpp = babl_format_get_bytes_per_pixel (in_format);
- gint aux_bpp = babl_format_get_bytes_per_pixel (aux_format);
- gint aux2_bpp = babl_format_get_bytes_per_pixel (aux2_format);
- gint out_bpp = babl_format_get_bytes_per_pixel (out_format);
-
- main_thread = pthread_self();
+ gint in_bpp = input?babl_format_get_bytes_per_pixel (in_buf_format):0;
+ gint aux_bpp = aux?babl_format_get_bytes_per_pixel (aux_buf_format):0;
+ gint aux2_bpp = aux2?babl_format_get_bytes_per_pixel (aux2_buf_format):0;
+ gint out_bpp = babl_format_get_bytes_per_pixel (output_buf_format);
if (input)
- read = gegl_buffer_iterator_add (i, input, result, level, in_format, GEGL_BUFFER_READ,
GEGL_ABYSS_NONE);
+ {
+ read = gegl_buffer_iterator_add (i, input, result, level, in_buf_format, GEGL_BUFFER_READ,
GEGL_ABYSS_NONE);
+ for (gint j = 0; j < threads; j ++)
+ {
+ if (in_buf_format != in_format)
+ {
+ thread_data[j].input_fish = babl_fish (in_buf_format, in_format);
+ thread_data[j].in_tmp = qalloc (j, 0);
+ }
+ else
+ {
+ thread_data[j].input_fish = NULL;
+ }
+ }
+ }
+ else
+ for (gint j = 0; j < threads; j ++)
+ thread_data[j].input_fish = NULL;
if (aux)
- foo = gegl_buffer_iterator_add (i, aux, result, level, aux_format, GEGL_BUFFER_READ,
GEGL_ABYSS_NONE);
+ {
+ foo = gegl_buffer_iterator_add (i, aux, result, level, aux_buf_format, GEGL_BUFFER_READ,
GEGL_ABYSS_NONE);
+ for (gint j = 0; j < threads; j ++)
+ {
+ if (aux_buf_format != aux_format)
+ {
+ thread_data[j].aux_fish = babl_fish (aux_buf_format, aux_format);
+ thread_data[j].aux_tmp = qalloc (j, 1);
+ }
+ else
+ {
+ thread_data[j].aux_fish = NULL;
+ }
+ }
+ }
+ else
+ {
+ for (gint j = 0; j < threads; j ++)
+ thread_data[j].aux_fish = NULL;
+ }
if (aux2)
- bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_format, GEGL_BUFFER_READ,
GEGL_ABYSS_NONE);
+ {
+ bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_buf_format, GEGL_BUFFER_READ,
GEGL_ABYSS_NONE);
+ for (gint j = 0; j < threads; j ++)
+ {
+ if (aux2_buf_format != aux2_format)
+ {
+ thread_data[j].aux2_fish = babl_fish (aux2_buf_format, aux2_format);
+ thread_data[j].aux2_tmp = qalloc (j, 2);
+ }
+ else
+ {
+ thread_data[j].aux2_fish = NULL;
+ }
+ }
+ }
+ else
+ {
+ for (gint j = 0; j < threads; j ++)
+ thread_data[j].aux2_fish = NULL;
+ }
+
+ for (gint j = 0; j < threads; j ++)
+ {
+ if (output_buf_format != gegl_buffer_get_format (output))
+ {
+ thread_data[j].output_fish = babl_fish (out_format, output_buf_format);
+ thread_data[j].output_tmp = qalloc (j, 3);
+ }
+ else
+ {
+ thread_data[j].output_fish = NULL;
+ }
+ }
while (gegl_buffer_iterator_next (i))
{
- if (i->roi[0].height >= threads)
+ gint threads = gegl_config()->threads;
+ gint pending;
+ gint bit;
+
+ if (i->roi[0].height < threads)
{
- ThreadData thread_data[GEGL_MAX_THREADS];
- gint pending = threads;
- gint bit = i->roi[0].height / threads;
+ threads = i->roi[0].height;
+ }
+
+ bit = i->roi[0].height / threads;
+ pending = threads;
+
for (gint j = 0; j < threads; j++)
{
thread_data[j].roi.x = (i->roi[0]).x;
@@ -268,16 +391,21 @@ gegl_operation_point_composer3_process (GeglOperation *operation,
g_mutex_unlock (&pool_mutex);
- }
- else
- {
- point_composer3_class->process (operation, input?i->data[read]:NULL,
- aux?i->data[foo]:NULL,
- aux2?i->data[bar]:NULL,
- i->data[0], i->length, &(i->roi[0]), level);
- }
}
+ if(0)for (gint j = 0; j < threads; j ++)
+ {
+ if (thread_data[j].input_fish)
+ gegl_free (thread_data[j].in_tmp);
+ if (thread_data[j].aux_fish)
+ gegl_free (thread_data[j].aux_tmp);
+ if (thread_data[j].aux2_fish)
+ gegl_free (thread_data[j].aux2_tmp);
+ if (thread_data[j].output_fish)
+ gegl_free (thread_data[j].output_tmp);
+ }
+
+
return TRUE;
}
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]