Commit f92128ed authored by Daniel Sabo's avatar Daniel Sabo

opencl: Add use-opencl to nodes and call gegl_operation_use_opencl

This allows OpenCL to be controlled per node, which
is useful to avoid jumping into OpenCL mode for simple
operations in CPU based graphs.
parent 4c94a565
......@@ -51,7 +51,8 @@ enum
PROP_OP_CLASS,
PROP_OPERATION,
PROP_NAME,
PROP_DONT_CACHE
PROP_DONT_CACHE,
PROP_USE_OPENCL
};
enum
......@@ -153,6 +154,14 @@ gegl_node_class_init (GeglNodeClass *klass)
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_USE_OPENCL,
g_param_spec_boolean ("use-opencl",
"Use OpenCL",
"Use the OpenCL version of this operation if available, this property is inherited by children created from a node.",
TRUE,
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_NAME,
g_param_spec_string ("name",
......@@ -289,6 +298,10 @@ gegl_node_local_set_property (GObject *gobject,
node->dont_cache = g_value_get_boolean (value);
break;
case PROP_USE_OPENCL:
node->use_opencl = g_value_get_boolean (value);
break;
case PROP_OP_CLASS:
{
va_list null; /* dummy to pass along, it's not used anyways since
......@@ -330,6 +343,11 @@ gegl_node_local_get_property (GObject *gobject,
case PROP_DONT_CACHE:
g_value_set_boolean (value, node->dont_cache);
break;
case PROP_USE_OPENCL:
g_value_set_boolean (value, node->use_opencl);
break;
case PROP_NAME:
g_value_set_string (value, gegl_node_get_name (node));
break;
......@@ -1875,6 +1893,7 @@ gegl_node_add_child (GeglNode *self,
child->priv->parent = self;
child->dont_cache = self->dont_cache;
child->use_opencl = self->use_opencl;
return child;
}
......@@ -1984,6 +2003,7 @@ gegl_node_create_child (GeglNode *self,
if (ret && self)
{
ret->dont_cache = self->dont_cache;
ret->use_opencl = self->use_opencl;
}
return ret;
}
......
......@@ -75,6 +75,8 @@ struct _GeglNode
/* Whether result is cached or not, inherited by children */
gboolean dont_cache;
gboolean use_opencl;
GMutex mutex;
/*< private >*/
......
......@@ -249,7 +249,8 @@ gegl_operation_point_composer_process (GeglOperation *operation,
if ((result->width > 0) && (result->height > 0))
{
if (gegl_cl_is_accelerated () && (operation_class->cl_data || point_composer_class->cl_process))
if (gegl_operation_use_opencl (operation) &&
(operation_class->cl_data || point_composer_class->cl_process))
{
if (gegl_operation_point_composer_cl_process (operation, input, aux, output, result, level))
return TRUE;
......
......@@ -174,7 +174,8 @@ gegl_operation_point_filter_process (GeglOperation *operation,
if ((result->width > 0) && (result->height > 0))
{
if (gegl_cl_is_accelerated () && (operation_class->cl_data || point_filter_class->cl_process))
if (gegl_operation_use_opencl (operation) &&
(operation_class->cl_data || point_filter_class->cl_process))
{
if (gegl_operation_point_filter_cl_process (operation, input, output, result, level))
return TRUE;
......
......@@ -744,6 +744,13 @@ gegl_operation_get_key (const gchar *operation_name,
return ret;
}
gboolean
gegl_operation_use_opencl (const GeglOperation *operation)
{
g_return_val_if_fail (operation->node, FALSE);
return operation->node->use_opencl && gegl_cl_is_accelerated ();
}
const Babl *
gegl_operation_get_source_format (GeglOperation *operation,
const gchar *padname)
......
......@@ -247,6 +247,8 @@ void gegl_operation_set_key (const gchar *operation_type,
const gchar * gegl_operation_get_key (const gchar *operation_type,
const gchar *key_name);
gboolean gegl_operation_use_opencl (const GeglOperation *operation);
/* invalidate a specific rectangle, indicating the any computation depending
* on this roi is now invalid.
*
......
......@@ -102,7 +102,8 @@ bilateral_process (GeglOperation *operation,
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
if (gegl_cl_is_accelerated () && bilateral_cl_process (operation, input, output, result, o->s_sigma, o->r_sigma/100))
if (gegl_operation_use_opencl (operation))
if (bilateral_cl_process (operation, input, output, result, o->s_sigma, o->r_sigma/100))
return TRUE;
bilateral_filter (input, result, output, result, o->s_sigma, o->r_sigma/100);
......
......@@ -162,7 +162,7 @@ process (GeglOperation *operation,
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
GeglRectangle compute;
if (o->blur_radius >= 1.0 && gegl_cl_is_accelerated ())
if (o->blur_radius >= 1.0 && gegl_operation_use_opencl (operation))
if (cl_process (operation, input, output, result))
return TRUE;
......
......@@ -320,13 +320,9 @@ process (GeglOperation *operation,
GeglOperationAreaFilter *op_area;
op_area = GEGL_OPERATION_AREA_FILTER (operation);
if (gegl_cl_is_accelerated ())
{
if (cl_process (operation, input, output, result))
return TRUE;
else
gegl_cl_disable();
}
if (gegl_operation_use_opencl (operation))
if (cl_process (operation, input, output, result))
return TRUE;
rect = *result;
tmprect = *result;
......
......@@ -313,7 +313,7 @@ process (GeglOperation *operation,
GeglRectangle compute;
compute = gegl_operation_get_required_for_output (operation, "input",result);
if (o->radius < 500 && gegl_cl_is_accelerated ())
if (o->radius < 500 && gegl_operation_use_opencl (operation))
if(cl_process(operation, input, output, result))
return TRUE;
......
......@@ -75,7 +75,7 @@ process (GeglOperation *operation,
gint i, j;
gfloat *buf1, *buf2, *buf3;
if (gegl_cl_is_accelerated ())
if (gegl_operation_use_opencl (operation))
if (cl_process (operation, input, output, result))
return TRUE;
......
......@@ -195,7 +195,7 @@ process (GeglOperation *operation,
compute = gegl_operation_get_required_for_output (operation, "input", result);
has_alpha = babl_format_has_alpha (gegl_operation_get_format (operation, "output"));
if (gegl_cl_is_accelerated ())
if (gegl_operation_use_opencl (operation))
if (cl_process (operation, input, output, result, has_alpha))
return TRUE;
......
......@@ -649,7 +649,7 @@ process (GeglOperation *operation,
force_iir = (o->filter == GEGL_GAUSSIAN_BLUR_FILTER_IIR);
force_fir = (o->filter == GEGL_GAUSSIAN_BLUR_FILTER_FIR);
if (gegl_cl_is_accelerated () && !force_iir)
if (gegl_operation_use_opencl (operation) && !force_iir)
if (cl_process(operation, input, output, result))
return TRUE;
......
......@@ -220,7 +220,7 @@ process (GeglOperation *operation,
src_rect.width += op_area->left + op_area->right;
src_rect.height += op_area->top + op_area->bottom;
if (gegl_cl_is_accelerated ())
if (gegl_operation_use_opencl (operation))
if (cl_process (operation, input, output, roi, &src_rect))
return TRUE;
......
......@@ -325,7 +325,7 @@ process (GeglOperation *operation,
#endif
GeglRectangle rect;
if (gegl_cl_is_accelerated ())
if (gegl_operation_use_opencl (operation))
if(cl_process(operation, input, output, result))
return TRUE;
......
......@@ -398,7 +398,7 @@ process (GeglOperation *operation,
GeglRectangle src_rect;
gint total_pixels;
if (gegl_cl_is_accelerated ())
if (gegl_operation_use_opencl (operation))
if(cl_process(operation, input, output, result))
return TRUE;
......
......@@ -364,7 +364,7 @@ process (GeglOperation *operation,
whole_region = gegl_operation_source_get_bounding_box (operation, "input");
if (gegl_cl_is_accelerated ())
if (gegl_operation_use_opencl (operation))
if (cl_process (operation, input, output, roi))
return TRUE;
......
......@@ -71,7 +71,7 @@ process (GeglOperation *operation,
GeglBuffer *temp_in;
GeglRectangle compute;
if (gegl_cl_is_accelerated ())
if (gegl_operation_use_opencl (operation))
if (cl_process (operation, input, output, result))
return TRUE;
......
......@@ -48,7 +48,7 @@ process (GeglOperation *operation,
{
GeglBuffer *output = GEGL_BUFFER (o->buffer);
if (gegl_cl_is_accelerated ()
if (gegl_operation_use_opencl (operation)
&& gegl_cl_color_supported (input->soft_format, output->soft_format) == GEGL_CL_COLOR_CONVERT)
{
size_t size;
......
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