Commit 883ffd9
Add libplacebo GPU module with render and shader filters (#1236)
* Add libplacebo GPU module with render and shader filters
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.
* Fix MinGW build: portable format specifiers, add libplacebo to CI
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.
* Fix clang-format violation in save_cache log line
Break long mlt_log_info() call into multi-line format to match
the project's clang-format rules (same style as load_cache above).
* Reuse GPU textures between chained placebo filters
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.
* Support DYNAMIC shader parameters and base64-encoded shader_text
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.
* Fix clang-format-14 violations in placebo module
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.
* Refactor image conversion
- Refactored image conversion handling across various modules to use new framework functions for better clarity and maintainability.
- Now, there can be multiple possible image converters per frame stopping after the first success. But also, one converter can part of the work (e.g. dowload from GPU) while a later one converts it to the actual requested format.
- Replaced direct calls to `convert_image` with `mlt_frame_convert_image` and added checks for the existence of conversion functions.
- Improved documentation in YAML files to clarify the purpose of image conversion callbacks.
- Added tests to verify the correct propagation of image conversion functions through frames and producers.
* Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* fix early returns not releasing lock
* change a log to debug level
* add MLT_PLACEBO_CACHE_PATH and replace atext()
* Add placebo.convert filter
- Introduced new `mlt_image_private` format for module internal use.
- Improved placebo texture reuse across filters.
* fix cppcheck and redundant workflow runs
* fix ctest on msvc
* docs for placebo private image handling
* Enhance image conversion logic to handle private format cases
* Fix double-free of src_tex and out-of-bounds in imageconvert
- Remove incorrect pl_tex_destroy(src_tex) in error paths of the render
and shader filters: src_tex is owned by the frame and freed automatically
when placebo_frame_set_tex() replaces the "image" property, so manual
destruction caused a double-free on frame close.
- Add *image = NULL after failed placebo_frame_set_tex() in render and
shader filters (consistent with filter_placebo_convert.c).
- Guard filter_imageconvert's conversion_matrix access: mlt_image_private
(and mlt_image_invalid) are out of range for the matrix indexed by
[format - 1]; early-return 1 for any format outside [mlt_image_rgb,
mlt_image_rgba64] to avoid an out-of-bounds read.
Agent-Logs-Url: https://github.com/mltframework/mlt/sessions/f71fd929-5b62-4e71-864a-13291a3ec28e
Co-authored-by: ddennedy <1146683+ddennedy@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* fix lazy allocation not thread-safe
* fix races in placebo.shader
* Add permanent failure flag for GPU initialization and fix leak
* Add permanent failure and shutdown flags for GPU management
* use "mlt_image_private"
and mlt_properties_clear()
* add `mlt_frame_prepend_convert_image()`
* add `mlt_frame_prepend_convert_image()`
* fix cppcheck and redundant workflow runs
* fix ctest on msvc
* remove placebo.convert filter
prepend the callback on the frame as-needed
* fix cppcheck
* mlt_frame_append_convert_image()
* update CMakeLists.txt to require libplacebo version 5.229
and simplify cppcheck suppression for placebo module
* improve placebo.render meta & cleanup
* Change minimum Fedora build test version to 40
---------
Co-authored-by: D-Ogi <D-Ogi@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ddennedy <1146683+ddennedy@users.noreply.github.com>1 parent 5780111 commit 883ffd9
29 files changed
Lines changed: 1890 additions & 35 deletions
File tree
- .github/workflows
- src
- framework
- modules
- avformat
- core
- placebo
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
113 | | - | |
114 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
319 | 320 | | |
320 | 321 | | |
321 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
322 | 332 | | |
323 | 333 | | |
324 | 334 | | |
| |||
598 | 608 | | |
599 | 609 | | |
600 | 610 | | |
| 611 | + | |
601 | 612 | | |
602 | 613 | | |
603 | 614 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| 451 | + | |
451 | 452 | | |
452 | 453 | | |
453 | 454 | | |
| |||
1157 | 1158 | | |
1158 | 1159 | | |
1159 | 1160 | | |
1160 | | - | |
| 1161 | + | |
| 1162 | + | |
1161 | 1163 | | |
1162 | 1164 | | |
1163 | 1165 | | |
1164 | 1166 | | |
1165 | | - | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
| 1167 | + | |
1169 | 1168 | | |
1170 | 1169 | | |
1171 | 1170 | | |
| |||
1299 | 1298 | | |
1300 | 1299 | | |
1301 | 1300 | | |
1302 | | - | |
| 1301 | + | |
| 1302 | + | |
1303 | 1303 | | |
1304 | 1304 | | |
1305 | 1305 | | |
1306 | 1306 | | |
1307 | | - | |
1308 | | - | |
1309 | | - | |
1310 | | - | |
| 1307 | + | |
1311 | 1308 | | |
1312 | 1309 | | |
1313 | 1310 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
| 192 | + | |
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| |||
228 | 229 | | |
229 | 230 | | |
230 | 231 | | |
| 232 | + | |
| 233 | + | |
231 | 234 | | |
232 | 235 | | |
233 | 236 | | |
| |||
489 | 492 | | |
490 | 493 | | |
491 | 494 | | |
| 495 | + | |
492 | 496 | | |
493 | 497 | | |
494 | 498 | | |
| |||
605 | 609 | | |
606 | 610 | | |
607 | 611 | | |
| 612 | + | |
608 | 613 | | |
609 | 614 | | |
610 | 615 | | |
| |||
693 | 698 | | |
694 | 699 | | |
695 | 700 | | |
| 701 | + | |
696 | 702 | | |
697 | 703 | | |
698 | 704 | | |
| |||
798 | 804 | | |
799 | 805 | | |
800 | 806 | | |
| 807 | + | |
801 | 808 | | |
802 | 809 | | |
803 | 810 | | |
| |||
952 | 959 | | |
953 | 960 | | |
954 | 961 | | |
| 962 | + | |
955 | 963 | | |
956 | 964 | | |
957 | | - | |
| 965 | + | |
958 | 966 | | |
959 | 967 | | |
960 | 968 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| |||
0 commit comments