toneequal: OpenCL follow-up improvements - #22444
Merged
TurboGit merged 5 commits intoSep 30, 2026
Merged
Conversation
toneeq_process() keeps the full pipe luminance mask in g->full_preview_buf and, while g->ui_preview_hash still matches, skips compute_luminance_mask() and only applies the correction. That is what makes a band slider drag cheap: the mask is the expensive part of the module and the band factors are not in its hash. process_cl() had no such cache. The device to host copy of the full pipe mask was dropped because no GUI code consumes it, and only invalidated g->ui_preview_hash so a later CPU run would recompute. But the consumer would have been the next OpenCL run: without the copy every full pipe run rebuilt the mask, guided filter included, so dragging a band paid the whole extraction on every frame where the CPU path paid the lookup only. Keep the host copy on both darkroom pipes, shared with the CPU path so a fallback stays in sync, and use it in both directions: when the key matches, upload it into the device buffer instead of rebuilding the mask. When it does not, rebuild and copy back. The transfers are blocking, as in lens and overlay: later runs rewrite and reallocate the host copy, and the copy back is only issued when the mask changed, when the device just did the expensive part anyway. The key is invalidated before the copy back and committed after it, so a failed transfer can never pass a half filled buffer off as the mask. The full pipe buffer handling moves into _full_preview_buffer(), used by both paths. It also resets the recorded size when the allocation fails, so the next run retries instead of returning NULL forever, and invalidates the key on a resize.
_fast_surface_blur_cl() and _fast_eigf_surface_blur_cl() start err at CL_MEM_OBJECT_ALLOCATION_FAILURE so the shared cleanup label can be used from the allocation checks, and relied on the first enqueue to overwrite it. The EIGF loop body is the only place that does so there, so with iterations <= 0, which the slider forbids but a preset, style or Lua script can still store, the function returned an allocation failure with every buffer allocated and the pipe silently fell back to the CPU. Set err once the allocations are known good.
With `mask quantization` at zero, quantize() is a plain copy of the downscaled image into the guide buffer, and _fast_surface_blur_cl() launched that copy kernel on every iteration. The guide is then the image itself, so pack the image twice and do not allocate the guide buffer at all, as _fast_eigf_surface_blur_cl() already does.
The OpenCL guided filter and EIGF blend kernels read their per pixel parameters from full size buffers upsampled with dt_interpolate_bilinear_cl(). Sample the downscaled parameters bilinearly in the blend kernels instead. This drops the largest temporaries (0.5 and 1.0 times the input in tiling_callback() terms) and a full size write plus read per blend. Output is unchanged. To keep the arithmetic in one place, it moves from bilinear.cl into a new data/kernels/bilinear.h (dt_bilinear_sample1/2/4), used by both the bilinear kernels and toneequal.cl. The header is installed and added to the kernel cache key includes in src/common/opencl.c, so all cached kernel binaries are rebuilt once. Also drop the unused TONEEQ_PIXEL_CHAN define.
Member
Also the case on current master, a recent change I suppose. Let me know if you have a hint about the possible culprit, there is many OpenCL changes recently. |
Contributor
Author
Yeah, that would be my guess too. I'll try to dig deeper to understand this difference. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Here are some follow-up improvements to the tone equalizer OpenCL code path added earlier in #22051.
Testing
Checklist
src/tests/integration/where the pixelpipe is touched, ordarktable-clias a headless smoke test._(), new preferences are registered indata/darktableconfig.xml.in.RELEASE_NOTES.mdentry was added (only needed if fixing an issue in a release). Do not reference GitHub issues.AI assistance
This PR was co-created with Claude.