191 gboolean *
const cache_output,
197 void *cl_mem_input = NULL;
198 void *cl_mem_output = NULL;
199 void *cl_mem_process_input = NULL;
200 void *cl_mem_blend_input = NULL;
201 void *cl_mem_blend_output = NULL;
202 void *cl_mem_process_input_temp = NULL;
203 void *cl_mem_blend_input_temp = NULL;
204 void *cl_mem_blend_output_temp = NULL;
207 gboolean borrowed_cl_mem_input =
FALSE;
219 actual_input_dsc.
bpp);
220 borrowed_cl_mem_input = (!
IS_NULL_PTR(cl_mem_input));
236 &borrowed_cl_mem_input, piece, previous_piece,
tiling,
237 pixelpipe_flow, cache_output,
238 input_entry, output_entry);
246 const float required_factor_cl
253 size_t fit_needed = 0, fit_limit = 0;
257 required_factor_cl,
tiling->overhead, &fit_needed, &fit_limit);
262 "[dev_pixelpipe] %s pre-check didn't fit on device, flushing cached pinned buffers and retrying\n",
267 required_factor_cl,
tiling->overhead, &fit_needed, &fit_limit);
272 && (
module->flags() & IOP_FLAGS_PREVIEW_NON_OPENCL))
273 && (fits_on_device || piece->process_tiling_ready);
275 if(!possible_cl || !fits_on_device) *cache_output =
TRUE;
282 if(possible_cl && !fits_on_device)
287 * ceilf(required_factor_cl));
290 const float border =
tiling->overlap + 1;
291 const gboolean possible = (cl_px > dx * border) || (cl_px > dy * border) || (cl_px > border * border);
295 "[dt_dev_pixelpipe_process_rec] CL: tiling impossible in module `%s'. avail=%.1fM, requ=%.1fM (%ix%i). overlap=%i\n",
296 module->name(), cl_px / 1e6f, dx * dy / 1e6f, (
int)dx, (
int)dy, (
int)
tiling->overlap);
303 input_entry, output_entry))
307 if(!possible_cl)
goto error;
315 &locked_input_entry, NULL))
318 cl_mem_process_input = cl_mem_input;
322 "output", output_entry,
326 const int cst_before_cl = process_input_dsc.
cst;
331 module,
"module input colorspace temp",
339 &process_input_dsc.
cst, work_profile))
341 cl_mem_process_input = cl_mem_process_input_temp;
347 const int cst_after_cl = process_input_dsc.
cst;
352 cst_before_cl, cst_after_cl);
354 if(!module->process_cl(module, pipe, piece, cl_mem_process_input, cl_mem_output))
363 = (
module->dev->gui_attached && (module == module->dev->gui_module) && (pipe == module->dev->pipe))
364 ? module->request_mask_display
365 : DT_DEV_PIXELPIPE_DISPLAY_NONE;
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);
434 size_t origin[] = { 0, 0, 0 };
437 region) != CL_SUCCESS)
465 const float *module_input = input;
466 const float *blend_input = input;
467 float *module_input_temp = NULL;
468 float *blend_input_temp = NULL;
469 gboolean input_locked =
FALSE;
471 if(borrowed_cl_mem_input)
475 borrowed_cl_mem_input =
FALSE;
493 &process_input_dsc.
cst, work_profile);
495 input_locked =
FALSE;
496 module_input = module_input_temp;
510 int fail = !
module->process_tiling_cl(module, pipe, piece, module_input, output, piece->dsc_in.bpp);
524 blend_input = module_input;
525 blend_input_dsc = process_input_dsc;
526 void *blend_output = output;
527 blend_output_dsc = piece->
dsc_out;
530 = (
module->dev->gui_attached && (module == module->dev->gui_module) && (pipe == module->dev->pipe))
531 ? module->request_mask_display
532 : DT_DEV_PIXELPIPE_DISPLAY_NONE;
553 &blend_input_dsc.
cst, work_profile);
554 blend_input = blend_input_temp;
558 input_locked =
FALSE;
564 float *blend_output_temp
577 &blend_output_dsc.
cst, work_profile);
578 blend_output = blend_output_temp;
590 memcpy(output, blend_output,
597 &blend_output_dsc.
cst, work_profile);
603 if(blend_output != output)
617 if(locked_input_entry)
623 if(borrowed_cl_mem_input)
627 borrowed_cl_mem_input =
FALSE;
654 if(locked_input_entry)
673 dt_control_log(_(
"OpenCL failed for module `%s`: image buffer needs %" G_GSIZE_FORMAT
674 " MiB but the largest allocation the device allows is %" G_GSIZE_FORMAT
675 " MiB; falling back to CPU"),
676 module->name(), (
size_t)(fit_needed / (1024 * 1024)),
677 (
size_t)(fit_limit / (1024 * 1024)));
680 dt_control_log(_(
"OpenCL failed for module `%s`: image buffer needs %" G_GSIZE_FORMAT
681 " MiB but only %" G_GSIZE_FORMAT
" MiB are free on the device; falling back to CPU"),
682 module->name(), (
size_t)(fit_needed / (1024 * 1024)),
683 (
size_t)(fit_limit / (1024 * 1024)));
686 dt_control_log(_(
"OpenCL failed for module `%s`: image dimensions %" G_GSIZE_FORMAT
"x%" G_GSIZE_FORMAT
687 " exceed the device limits; falling back to CPU"),
688 module->name(), precheck_width, precheck_height);
691 dt_control_log(_(
"OpenCL failed for module `%s`; falling back to CPU"), module->name());
695 cache_output, cpu_input_entry, output_entry);
701 "[dev_pixelpipe] %s GPU error fallback will reuse host input\n",
707 cpu_input_entry, output_entry))
709 if(borrowed_cl_mem_input)
713 borrowed_cl_mem_input =
FALSE;
724 "[dev_pixelpipe] %s CPU fallback has no input buffer (cache allocation failed?)\n",
729 if(borrowed_cl_mem_input)
739 cache_output, cpu_input_entry, output_entry);