Skip to content

Add libplacebo GPU module with render and shader filters#1236

Open
ddennedy wants to merge 13 commits intorefactor-image-convertfrom
libplacebo
Open

Add libplacebo GPU module with render and shader filters#1236
ddennedy wants to merge 13 commits intorefactor-image-convertfrom
libplacebo

Conversation

@ddennedy
Copy link
Copy Markdown
Member

@ddennedy ddennedy commented May 6, 2026

supersedes #1201

D-Ogi and others added 10 commits February 1, 2026 22:48
New module 'placebo' providing GPU-accelerated video processing via
libplacebo. Includes two filters:

- placebo.render: GPU scaling, debanding, dithering, and tonemapping
  with quality presets (fast/default/high_quality)
- placebo.shader: Custom mpv-compatible .hook shader support

Backend priority: D3D11 (Windows) -> Vulkan -> OpenGL.
Vulkan loader is dynamically loaded on Windows when libplacebo is
built without vk-proc-addr support.

Features:
- Singleton GPU context with thread-safe access
- Shader cache persistence
- Multiple scaling algorithms (ewa_lanczos, lanczos, mitchell, etc.)
- Tone mapping (auto, clip, mobius, reinhard, hable, bt.2390, spline)
- Graceful fallback to passthrough when no GPU is available

The module is enabled by default but skipped automatically when
libplacebo is not installed.
Use PRIu64/PRId64 from <inttypes.h> instead of %zu/%ld for size
logging in the placebo module. Add libplacebo-dev packages to
Ubuntu, Debian, and Fedora 42 CI workflows, and
mingw-w64-x86_64-libplacebo to the MSYS2 MinGW64 workflow.
Break long mlt_log_info() call into multi-line format to match
the project's clang-format rules (same style as load_cache above).
When multiple placebo filters are stacked on one clip, each filter
previously did a full RAM→GPU upload and GPU→RAM download. The
intermediate uploads are redundant because the next placebo filter
would re-upload the same pixels immediately.

Each filter now attaches its output texture to the mlt_frame via
placebo_frame_put_tex(). The next placebo filter calls
placebo_frame_take_tex() to grab it directly as source, skipping
the upload. The download to RAM still happens every time (MLT
expects the image buffer to be current for non-GPU filters).

Staleness detection: put_tex records the RAM buffer pointer,
take_tex compares it against the current pointer. If a CPU filter
ran in between and requested a writable buffer (triggering a copy
and new allocation), the pointers differ and take_tex returns NULL,
falling back to a fresh upload.

Also cleans up internal ticket-style comments (C1/W2/etc.) with
descriptions of actual logic and pitfalls.
Add apply_shader_params() to override pl_hook DYNAMIC parameters from
MLT animated properties (shader_param.* prefix) on every frame.  Uses
mlt_properties_anim_get_double/int to correctly resolve keyframe strings
("0=200;50=100") at the current frame position.

Add base64 decoding for shader_text values prefixed with "base64:" to
support inline shaders with characters that are problematic in MLT
property strings.
Run clang-format-14 (matching CI) on filter_placebo_shader.c and
gpu_context.c to fix designated initializer spacing, ternary line
breaks, and long argument lists.
- Introduced new `mlt_image_private` format for module internal use.
- Improved placebo texture reuse across filters.
@ddennedy ddennedy changed the title Libplacebo Add libplacebo GPU module with render and shader filters May 6, 2026
@ddennedy ddennedy added this to the v7.40.0 milestone May 6, 2026
@ddennedy ddennedy marked this pull request as ready for review May 6, 2026 17:38
@ddennedy ddennedy requested a review from Copilot May 6, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants