195 gboolean *
const cache_output,
201 void *cl_mem_input = NULL;
202 void *cl_mem_output = NULL;
203 void *cl_mem_process_input = NULL;
204 void *cl_mem_blend_input = NULL;
205 void *cl_mem_blend_output = NULL;
206 void *cl_mem_process_input_temp = NULL;
207 void *cl_mem_blend_input_temp = NULL;
208 void *cl_mem_blend_output_temp = NULL;
211 gboolean borrowed_cl_mem_input =
FALSE;
223 actual_input_dsc.
bpp);
224 borrowed_cl_mem_input = (!
IS_NULL_PTR(cl_mem_input));
240 &borrowed_cl_mem_input, piece, previous_piece,
tiling,
241 pixelpipe_flow, cache_output,
242 input_entry, output_entry);
250 const float required_factor_cl
257 size_t fit_needed = 0, fit_limit = 0;
261 required_factor_cl,
tiling->overhead, &fit_needed, &fit_limit);
266 "[dev_pixelpipe] %s pre-check didn't fit on device, flushing cached pinned buffers and retrying\n",
271 required_factor_cl,
tiling->overhead, &fit_needed, &fit_limit);
276 && (
module->flags() & IOP_FLAGS_PREVIEW_NON_OPENCL))
277 && (fits_on_device || piece->process_tiling_ready);
279 if(!possible_cl || !fits_on_device) *cache_output =
TRUE;
286 if(possible_cl && !fits_on_device)
291 * ceilf(required_factor_cl));
294 const float border =
tiling->overlap + 1;
295 const gboolean possible = (cl_px > dx * border) || (cl_px > dy * border) || (cl_px > border * border);
299 "[dt_dev_pixelpipe_process_rec] CL: tiling impossible in module `%s'. avail=%.1fM, requ=%.1fM (%ix%i). overlap=%i\n",
300 module->name(), cl_px / 1e6f, dx * dy / 1e6f, (
int)dx, (
int)dy, (
int)
tiling->overlap);
307 input_entry, output_entry))
311 if(!possible_cl)
goto error;
319 &locked_input_entry, NULL))
322 cl_mem_process_input = cl_mem_input;
326 "output", output_entry,
330 const int cst_before_cl = process_input_dsc.
cst;
335 module,
"module input colorspace temp",
343 &process_input_dsc.
cst, work_profile))
345 cl_mem_process_input = cl_mem_process_input_temp;
351 const int cst_after_cl = process_input_dsc.
cst;
356 cst_before_cl, cst_after_cl);
358 if(!module->process_cl(module, pipe, piece, cl_mem_process_input, cl_mem_output))
368 cl_mem_blend_input = cl_mem_process_input;
369 cl_mem_blend_output = cl_mem_output;
370 blend_input_dsc = process_input_dsc;
371 blend_output_dsc = piece->
dsc_out;
376 const int blend_in_before = blend_input_dsc.
cst;
380 module,
"blend input colorspace temp",
381 cl_mem_process_input);
386 cl_mem_process_input, cl_mem_blend_input_temp,
388 blend_input_dsc.
cst, blend_cst,
389 &blend_input_dsc.
cst, work_profile);
390 cl_mem_blend_input = cl_mem_blend_input_temp;
392 const int blend_in_after = blend_input_dsc.
cst;
394 &process_input_dsc, &blend_input_dsc,
396 process_input_dsc.
bpp, blend_input_dsc.
bpp,
397 blend_in_before, blend_in_after);
398 const int blend_out_before = blend_output_dsc.
cst;
403 "blend output colorspace temp", cl_mem_output);
410 &blend_output_dsc.
cst, work_profile);
411 cl_mem_blend_output = cl_mem_blend_output_temp;
413 const int blend_out_after = blend_output_dsc.
cst;
415 &piece->
dsc_out, &blend_output_dsc,
418 blend_out_before, blend_out_after);
457 const float *module_input = input;
458 const float *blend_input = input;
459 float *module_input_temp = NULL;
460 float *blend_input_temp = NULL;
461 gboolean input_locked =
FALSE;
463 if(borrowed_cl_mem_input)
467 borrowed_cl_mem_input =
FALSE;
485 &process_input_dsc.
cst, work_profile);
487 input_locked =
FALSE;
488 module_input = module_input_temp;
502 int fail = !
module->process_tiling_cl(module, pipe, piece, module_input, output, piece->dsc_in.bpp);
516 blend_input = module_input;
517 blend_input_dsc = process_input_dsc;
518 void *blend_output = output;
519 blend_output_dsc = piece->
dsc_out;
541 &blend_input_dsc.
cst, work_profile);
542 blend_input = blend_input_temp;
546 input_locked =
FALSE;
552 float *blend_output_temp
565 &blend_output_dsc.
cst, work_profile);
566 blend_output = blend_output_temp;
580 &blend_output_dsc.
cst, work_profile);
585 if(blend_output != output)
599 if(locked_input_entry)
605 if(borrowed_cl_mem_input)
609 borrowed_cl_mem_input =
FALSE;
636 if(locked_input_entry)
656 " MiB but the largest allocation the device allows is %" G_GSIZE_FORMAT
657 " MiB; falling back to CPU"),
658 module->name(), (
size_t)(fit_needed / (1024 * 1024)),
659 (
size_t)(fit_limit / (1024 * 1024)));
663 " MiB but only %" G_GSIZE_FORMAT
" MiB are free on the device; falling back to CPU"),
664 module->name(), (
size_t)(fit_needed / (1024 * 1024)),
665 (
size_t)(fit_limit / (1024 * 1024)));
668 dt_pipeline_message(_(
"OpenCL failed for module `%s`: image dimensions %" G_GSIZE_FORMAT
"x%" G_GSIZE_FORMAT
669 " exceed the device limits; falling back to CPU"),
670 module->name(), precheck_width, precheck_height);
673 dt_pipeline_message(_(
"OpenCL failed for module `%s`; falling back to CPU"), module->name());
677 cache_output, cpu_input_entry, output_entry);
683 "[dev_pixelpipe] %s GPU error fallback will reuse host input\n",
689 cpu_input_entry, output_entry))
691 if(borrowed_cl_mem_input)
695 borrowed_cl_mem_input =
FALSE;
706 "[dev_pixelpipe] %s CPU fallback has no input buffer (cache allocation failed?)\n",
711 if(borrowed_cl_mem_input)
721 cache_output, cpu_input_entry, output_entry);