Repository navigation
libobs: Draw nothing when a filter with no parent skips its video - #2177
Merged
Merged
Conversation
obs_source_skip_video_filter() reads the parent's output flags without checking the parent. obs_source_filter_remove() clears the filter's parent and target, and the graphics thread renders the filter chain from a reference it took before the removal, so a filter that is removed while it renders and then skips (as filters do when they have nothing to draw) crashes on a NULL parent. test_filter_skip_removed registers a filter that removes itself from its parent inside its own video_render and then calls obs_source_skip_video_filter(), with the parent on output channel 0, so the graphics thread sees the cleared parent deterministically. It also calls the skip on a filter that was never attached, and checks that an attached filter that skips still draws its parent, on the pixels and the parent's render count, for a parent that draws itself, one drawn with the default effect, and a chain of two filters. Refs obs-rust#2160
obs_source_skip_video_filter() read the parent's output flags without checking the parent. obs_source_filter_remove() clears the filter's parent and target, and the graphics thread renders the filter chain from a reference it took before the removal, so a filter removed while it renders (from the Filters dialog, a script or obs-websocket) that then skips, as filters do when they are disabled or have nothing to draw, crashed on a NULL parent. A filter that was never attached crashed the same way. The function now returns when the parent or the target is NULL, as obs_source_process_filter_begin() and obs_source_process_filter_tech_end() do, so the removed filter draws nothing for that frame. An attached filter skips as before. docs/features.md gets a line under fixed upstream bugs. Fixes obs-rust#2160
This was referenced Oct 24, 2026
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
…der-route.c Behaviour-neutral extraction before the Rust port. The decisions of source_render_video(), obs_source_main_render(), can_bypass(), obs_source_process_filter_begin_with_color_space(), obs_source_process_filter_tech_end() and obs_source_skip_video_filter() in obs-source.c.h move to libobs/obs-source-render-route.c.h as 23 functions on plain values, declared in the new libobs/obs-source-render-route.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_render_route_filter(): the target and parent check of the three filter functions, no target first, then no parent (obs-rust#2177's guard in obs_source_skip_video_filter()); - source_render_video(): _video_reads_flags() and _video_none() (neither video nor a filter), _async_reads_flags(), _async_reads_rendering_filter() and _async_update() (the async texture update), _reads_enabled() and _inactive() (no data or disabled); - the draw, as a route over enum obs_source_render_route_draw: _draw() starts source_render_video()'s, _skip() a skipped filter's and _filter_render() the draw into a filter's texrender; _draw_next() takes the value a READ_ step asks for and returns the next step or the draw (default render, filters, main render, filter target, deinterlace or async video); - obs_source_main_render(): _main_custom_draw(), _main_srgb_aware(), _main_reads_filters() and _main_default_effect(); - can_bypass(): _bypass_reads_space() and _bypass(); then _size_skip() (zero width or height) and _texrender_stale() (the format check); - obs_source_process_filter_tech_end(): _tech_end_linear_srgb(), _tech_name() ("Draw" for NULL, else the pointer given) and _tech_end() (bypass or texture). obs-source.c.h keeps every gs_* call and texrender, the refs, the render calls, get_base_width() and get_base_height(), the debug markers and every field read, in their order and under their conditions. That is why the decisions are many small calls and not one plan per function: each old short circuit read a field or called gs_get_color_space() or deinterlacing_enabled() only on one side, so a _reads_ function says whether to read the next value, and the draw chains read one value per READ_ step, in the old order (the plan's single route struct would have hoisted those reads). Two adjustments to the plan's sketch: the texrender reuse is one decision on the format gs_texrender_get_format() returns (C still checks the pointer before calling it, and again after the destroy); and the update_deinterlace flag stays the C call deinterlacing_enabled(), as there is nothing else to decide. Types, the direct render choice, colour spaces and formats cross as int; obs-source.c.h checks that the four enums are int-sized. A value outside an enum takes the path it took before. Checked against the unchanged functions of origin/master (outside the tree, not committed): both versions extracted from obs-source.c.h, every source->field, filter->field, target->field and parent->field access rewritten into a logged access, and compiled against stubs that log every call with its arguments (obs_filter_get_target/_parent, get_base_width/_height, obs_source_video_render and the other renders, the async and deinterlace updates, gs_get_linear_srgb/gs_set_linear_srgb, gs_get_effect, gs_get_color_space, every gs_texrender_* call, the blend, clear and ortho calls, render_filter_bypass/_tex with the technique name, blog, the debug markers). 6,496,768 cases: source_render_video() for every type (and -1, 4) x 32 flag patterns x every data, enabled, rendering_filter, video_render, filter target, filter parent (and which), deinterlace and linear sRGB combination x 0-2 filters (with the skip into obs_source_skip_video_filter() and obs_source_main_render()); obs_source_main_render() alone; the filter begin for 6 wirings (no filter, no target, no parent, neither, the target is the parent, another filter) x 4 filter flags x 14 parent flags x 4 direct render choices x 6 x 6 requested and current spaces x 4 x 4 sizes (0, 1, 1920, UINT32_MAX) x texrender present, matching and begin result; the tech end for every wiring, 32 flags, bypass, texture, linear sRGB and a NULL, "Draw" or custom technique; the skip for every wiring, 32 parent flags, video_render and deinterlace of each target. The traces are identical byte for byte under GCC -O2 and clang -O0. Planted changes to the SRGB match of the bypass, the deinterlace step, the inactive rule and the enabled read are each caught. The new file joins libobs.core-source with libobs.pch.h, which includes the new header. The exported symbol sets are unchanged (1766). Refs obs-rust#2189
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
test_source_render_route_steps compiles libobs/obs-source-render-route.c.h (ASan and UBSan) and calls only its 23 hidden functions. 18 cases: - enum_values: the filter check, draw and tech end numbers the C acts on (and the port will return), that each enum is int-sized, and that the four libobs enums obs-source.c passes as int are int-sized; - filter_target_and_parent: ready, no target, no parent, and no target first when both are missing (obs-rust#2177's guard); - video_none_every_type_and_flags, video_none_filter_and_audio: for each of nine types (the enum, -1, 4, 99 and the ends of int) and every combination of VIDEO, ASYNC, CUSTOM_DRAW, SRGB, AUDIO and CAP_DISABLED (and UINT32_MAX), whether the flags are read and whether the source is skipped; a filter draws whatever its flags; - async_update_every_type_flags_and_filter, async_update_cases: the reads and the update for every type, flag pattern and rendering_filter; - inactive_every_input: no data or disabled, enabled read only with data; - draw_every_source: source_render_video()'s draw for all 32 combinations of filters, rendering_filter, video_render, filter target and deinterlacing, against the old if/else chain, with the READ_ steps in order (so a value the old chain did not read is never asked for); - draw_next_every_step: both values of each READ_ step; draws and values outside the enum (-1, 12, 99, the ends of int) come back unchanged; - skip_every_target_and_flags, skip_cases: obs_source_skip_video_filter()'s draw for the target being the parent or not, every parent flag pattern, video_render and deinterlacing, against the old chain; - main_render_every_input: the custom draw, sRGB-aware and default-effect rules, filters.num read only for a source that is not a filter; - bypass_every_input, bypass_cases: can_bypass() for both wirings, six direct render choices, every pair of filter and parent flag patterns and every pair of eight spaces (the enum, -1, 4, the ends of int): when gs_get_color_space() is read and when the filter bypasses; the SRGB and space rules of obs-rust#1493's filter colour space class; - size_skip_every_size, texrender_stale_every_format, filter_render_every_input: the zero size skip, the format check for every pair of formats around the enum, and the default or target render into the texrender; - tech_end_every_input: the linear sRGB flag, bypass or texture, "Draw" for a NULL name and the given pointer otherwise. Characterized, not endorsed: - ASYNC without VIDEO is no video, yet an input with it would update its async textures if it got that far (it does not: the "no video" check returns first); - a direct render choice outside the enum is not direct; spaces outside the enum bypass when they are equal; - cx and cy are get_base_width()'s and get_base_height()'s uint32_t in an int, so a size of 2^31 or more is negative there and does not skip; - an empty technique name is passed on as it is. The test is in the native test graph in name order, with libm except on MSVC, in the core suite. On the C backend, the hybrid and libobs-c-reference it passes 18 of 18 (it compiles the C file into itself on each). test_filter_color_space, test_filter_skip_removed, test_scroll_filter_wide_source, test_color_correction_16f, test_darken_transparent, test_scene_rotated_scale_filter, test_slideshow_size, test_texture_render and the other 28 tests that touch filters pass on all three, unchanged. Refs obs-rust#2189
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
Ports libobs/obs-source-render-route.c.h, the source and filter render routing of obs-source.c, to the render_route module of rust/obs-source. obs-source.c.h stays C: every gs_* call and texrender, the refs, the render functions, get_base_width() and get_base_height(), the debug markers and every field read, in their order and under their conditions. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/render_route.rs): - filter_check(): no target first, then no parent (obs-rust#2177); - video_reads_flags() and video_none(): a type that is not a filter reads its flags and draws nothing without VIDEO; - async_reads_flags(), async_reads_rendering_filter() and async_update(): an input reads its flags, an async input rendering_filter, and an async input not drawn by its own chain updates its textures; - reads_enabled() and inactive(): enabled read only with data; - draw(), draw_next() and skip(): the draws as a Draw route with the C's numbers; each Read* step names the one value C reads next, in the old order, and draw_next() moves to the next step or the draw; on the C's value (draw_next_value()) a value outside the enum comes back unchanged; - main_custom_draw(), main_srgb_aware(), main_reads_filters() and main_default_effect(); - bypass_reads_space() and bypass() (can_bypass(): the target is the parent, direct rendering allowed, the parent neither custom draw nor async, the SRGB flags agree, and then the spaces match), size_skip(), texrender_stale() and filter_render(); - tech_end_linear_srgb(), tech_name() (Given or Draw) and tech_end(). The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock. Shim (src/ffi/source_render_route.rs): the 23 functions keep the C signatures, plain values in and out; the enums come back as their C values. One pointer crosses: obs_source_render_route_tech_name() returns the name it is given, or a static c"Draw" for NULL, and never reads through it (gs_effect_get_technique() compares the name by its bytes, so the address differing from the C literal's does not matter). No other intentional differences. C side: the file leaves libobs.core-source for its own group, libobs.ported-source-render-route (LIBOBS_PORTED_SOURCES), whose PCH is obs.h (the enums and flags) and obs-source-render-route.h. libobs.pch.h keeps the header for obs-source.c. The functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. libobs-rust already links the crate's ffi. The exported symbol sets are unchanged and equal: 1766 on the C backend, the hybrid and libobs-c-reference; the 23 are local in all three, and the hybrid's come from the Rust archive. ci/test_ported_sources.py checks the group on every host. test_source_render_route_steps still compiles the C file into itself, unchanged. The new test_source_render_route_steps_rust builds the same test source against libobs_rust-static (and libm except on MSVC): the test calls only the 23 functions and includes their header and obs.h, so it takes libobs's include directories (SIMDe, obsconfig.h) and links the archive alone. It passes 18 of 18 against the shims. The filter tests (test_filter_color_space, test_filter_skip_removed, test_scroll_filter_wide_source, test_color_correction_16f, test_darken_transparent, test_scene_rotated_scale_filter, test_slideshow_size, test_texture_render and 28 more) see the swap through the hybrid and pass on all three builds. Tier 1 source::render_route passes 28/28. clippy -D warnings is clean for the host and x86_64-pc-windows-msvc. Refs obs-rust#2189
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
…der-route.c Behaviour-neutral extraction before the Rust port. The decisions of source_render_video(), obs_source_main_render(), can_bypass(), obs_source_process_filter_begin_with_color_space(), obs_source_process_filter_tech_end() and obs_source_skip_video_filter() in obs-source.c.h move to libobs/obs-source-render-route.c.h as 23 functions on plain values, declared in the new libobs/obs-source-render-route.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_render_route_filter(): the target and parent check of the three filter functions, no target first, then no parent (obs-rust#2177's guard in obs_source_skip_video_filter()); - source_render_video(): _video_reads_flags() and _video_none() (neither video nor a filter), _async_reads_flags(), _async_reads_rendering_filter() and _async_update() (the async texture update), _reads_enabled() and _inactive() (no data or disabled); - the draw, as a route over enum obs_source_render_route_draw: _draw() starts source_render_video()'s, _skip() a skipped filter's and _filter_render() the draw into a filter's texrender; _draw_next() takes the value a READ_ step asks for and returns the next step or the draw (default render, filters, main render, filter target, deinterlace or async video); - obs_source_main_render(): _main_custom_draw(), _main_srgb_aware(), _main_reads_filters() and _main_default_effect(); - can_bypass(): _bypass_reads_space() and _bypass(); then _size_skip() (zero width or height) and _texrender_stale() (the format check); - obs_source_process_filter_tech_end(): _tech_end_linear_srgb(), _tech_name() ("Draw" for NULL, else the pointer given) and _tech_end() (bypass or texture). obs-source.c.h keeps every gs_* call and texrender, the refs, the render calls, get_base_width() and get_base_height(), the debug markers and every field read, in their order and under their conditions. That is why the decisions are many small calls and not one plan per function: each old short circuit read a field or called gs_get_color_space() or deinterlacing_enabled() only on one side, so a _reads_ function says whether to read the next value, and the draw chains read one value per READ_ step, in the old order (the plan's single route struct would have hoisted those reads). Two adjustments to the plan's sketch: the texrender reuse is one decision on the format gs_texrender_get_format() returns (C still checks the pointer before calling it, and again after the destroy); and the update_deinterlace flag stays the C call deinterlacing_enabled(), as there is nothing else to decide. Types, the direct render choice, colour spaces and formats cross as int; obs-source.c.h checks that the four enums are int-sized. A value outside an enum takes the path it took before. Checked against the unchanged functions of origin/master (outside the tree, not committed): both versions extracted from obs-source.c.h, every source->field, filter->field, target->field and parent->field access rewritten into a logged access, and compiled against stubs that log every call with its arguments (obs_filter_get_target/_parent, get_base_width/_height, obs_source_video_render and the other renders, the async and deinterlace updates, gs_get_linear_srgb/gs_set_linear_srgb, gs_get_effect, gs_get_color_space, every gs_texrender_* call, the blend, clear and ortho calls, render_filter_bypass/_tex with the technique name, blog, the debug markers). 6,496,768 cases: source_render_video() for every type (and -1, 4) x 32 flag patterns x every data, enabled, rendering_filter, video_render, filter target, filter parent (and which), deinterlace and linear sRGB combination x 0-2 filters (with the skip into obs_source_skip_video_filter() and obs_source_main_render()); obs_source_main_render() alone; the filter begin for 6 wirings (no filter, no target, no parent, neither, the target is the parent, another filter) x 4 filter flags x 14 parent flags x 4 direct render choices x 6 x 6 requested and current spaces x 4 x 4 sizes (0, 1, 1920, UINT32_MAX) x texrender present, matching and begin result; the tech end for every wiring, 32 flags, bypass, texture, linear sRGB and a NULL, "Draw" or custom technique; the skip for every wiring, 32 parent flags, video_render and deinterlace of each target. The traces are identical byte for byte under GCC -O2 and clang -O0. Planted changes to the SRGB match of the bypass, the deinterlace step, the inactive rule and the enabled read are each caught. The new file joins libobs.core-source with libobs.pch.h, which includes the new header. The exported symbol sets are unchanged (1766). Refs obs-rust#2189
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
test_source_render_route_steps compiles libobs/obs-source-render-route.c.h (ASan and UBSan) and calls only its 23 hidden functions. 18 cases: - enum_values: the filter check, draw and tech end numbers the C acts on (and the port will return), that each enum is int-sized, and that the four libobs enums obs-source.c passes as int are int-sized; - filter_target_and_parent: ready, no target, no parent, and no target first when both are missing (obs-rust#2177's guard); - video_none_every_type_and_flags, video_none_filter_and_audio: for each of nine types (the enum, -1, 4, 99 and the ends of int) and every combination of VIDEO, ASYNC, CUSTOM_DRAW, SRGB, AUDIO and CAP_DISABLED (and UINT32_MAX), whether the flags are read and whether the source is skipped; a filter draws whatever its flags; - async_update_every_type_flags_and_filter, async_update_cases: the reads and the update for every type, flag pattern and rendering_filter; - inactive_every_input: no data or disabled, enabled read only with data; - draw_every_source: source_render_video()'s draw for all 32 combinations of filters, rendering_filter, video_render, filter target and deinterlacing, against the old if/else chain, with the READ_ steps in order (so a value the old chain did not read is never asked for); - draw_next_every_step: both values of each READ_ step; draws and values outside the enum (-1, 12, 99, the ends of int) come back unchanged; - skip_every_target_and_flags, skip_cases: obs_source_skip_video_filter()'s draw for the target being the parent or not, every parent flag pattern, video_render and deinterlacing, against the old chain; - main_render_every_input: the custom draw, sRGB-aware and default-effect rules, filters.num read only for a source that is not a filter; - bypass_every_input, bypass_cases: can_bypass() for both wirings, six direct render choices, every pair of filter and parent flag patterns and every pair of eight spaces (the enum, -1, 4, the ends of int): when gs_get_color_space() is read and when the filter bypasses; the SRGB and space rules of obs-rust#1493's filter colour space class; - size_skip_every_size, texrender_stale_every_format, filter_render_every_input: the zero size skip, the format check for every pair of formats around the enum, and the default or target render into the texrender; - tech_end_every_input: the linear sRGB flag, bypass or texture, "Draw" for a NULL name and the given pointer otherwise. Characterized, not endorsed: - ASYNC without VIDEO is no video, yet an input with it would update its async textures if it got that far (it does not: the "no video" check returns first); - a direct render choice outside the enum is not direct; spaces outside the enum bypass when they are equal; - cx and cy are get_base_width()'s and get_base_height()'s uint32_t in an int, so a size of 2^31 or more is negative there and does not skip; - an empty technique name is passed on as it is. The test is in the native test graph in name order, with libm except on MSVC, in the core suite. On the C backend, the hybrid and libobs-c-reference it passes 18 of 18 (it compiles the C file into itself on each). test_filter_color_space, test_filter_skip_removed, test_scroll_filter_wide_source, test_color_correction_16f, test_darken_transparent, test_scene_rotated_scale_filter, test_slideshow_size, test_texture_render and the other 28 tests that touch filters pass on all three, unchanged. Refs obs-rust#2189
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
Ports libobs/obs-source-render-route.c.h, the source and filter render routing of obs-source.c, to the render_route module of rust/obs-source. obs-source.c.h stays C: every gs_* call and texrender, the refs, the render functions, get_base_width() and get_base_height(), the debug markers and every field read, in their order and under their conditions. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/render_route.rs): - filter_check(): no target first, then no parent (obs-rust#2177); - video_reads_flags() and video_none(): a type that is not a filter reads its flags and draws nothing without VIDEO; - async_reads_flags(), async_reads_rendering_filter() and async_update(): an input reads its flags, an async input rendering_filter, and an async input not drawn by its own chain updates its textures; - reads_enabled() and inactive(): enabled read only with data; - draw(), draw_next() and skip(): the draws as a Draw route with the C's numbers; each Read* step names the one value C reads next, in the old order, and draw_next() moves to the next step or the draw; on the C's value (draw_next_value()) a value outside the enum comes back unchanged; - main_custom_draw(), main_srgb_aware(), main_reads_filters() and main_default_effect(); - bypass_reads_space() and bypass() (can_bypass(): the target is the parent, direct rendering allowed, the parent neither custom draw nor async, the SRGB flags agree, and then the spaces match), size_skip(), texrender_stale() and filter_render(); - tech_end_linear_srgb(), tech_name() (Given or Draw) and tech_end(). The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock. Shim (src/ffi/source_render_route.rs): the 23 functions keep the C signatures, plain values in and out; the enums come back as their C values. One pointer crosses: obs_source_render_route_tech_name() returns the name it is given, or a static c"Draw" for NULL, and never reads through it (gs_effect_get_technique() compares the name by its bytes, so the address differing from the C literal's does not matter). No other intentional differences. C side: the file leaves libobs.core-source for its own group, libobs.ported-source-render-route (LIBOBS_PORTED_SOURCES), whose PCH is obs.h (the enums and flags) and obs-source-render-route.h. libobs.pch.h keeps the header for obs-source.c. The functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. libobs-rust already links the crate's ffi. The exported symbol sets are unchanged and equal: 1766 on the C backend, the hybrid and libobs-c-reference; the 23 are local in all three, and the hybrid's come from the Rust archive. ci/test_ported_sources.py checks the group on every host. test_source_render_route_steps still compiles the C file into itself, unchanged. The new test_source_render_route_steps_rust builds the same test source against libobs_rust-static (and libm except on MSVC): the test calls only the 23 functions and includes their header and obs.h, so it takes libobs's include directories (SIMDe, obsconfig.h) and links the archive alone. It passes 18 of 18 against the shims. The filter tests (test_filter_color_space, test_filter_skip_removed, test_scroll_filter_wide_source, test_color_correction_16f, test_darken_transparent, test_scene_rotated_scale_filter, test_slideshow_size, test_texture_render and 28 more) see the swap through the hybrid and pass on all three builds. Tier 1 source::render_route passes 28/28. clippy -D warnings is clean for the host and x86_64-pc-windows-msvc. Refs obs-rust#2189
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
* libobs: Move the source and filter render routing into obs-source-render-route.c Behaviour-neutral extraction before the Rust port. The decisions of source_render_video(), obs_source_main_render(), can_bypass(), obs_source_process_filter_begin_with_color_space(), obs_source_process_filter_tech_end() and obs_source_skip_video_filter() in obs-source.c.h move to libobs/obs-source-render-route.c.h as 23 functions on plain values, declared in the new libobs/obs-source-render-route.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_render_route_filter(): the target and parent check of the three filter functions, no target first, then no parent (obs-rust#2177's guard in obs_source_skip_video_filter()); - source_render_video(): _video_reads_flags() and _video_none() (neither video nor a filter), _async_reads_flags(), _async_reads_rendering_filter() and _async_update() (the async texture update), _reads_enabled() and _inactive() (no data or disabled); - the draw, as a route over enum obs_source_render_route_draw: _draw() starts source_render_video()'s, _skip() a skipped filter's and _filter_render() the draw into a filter's texrender; _draw_next() takes the value a READ_ step asks for and returns the next step or the draw (default render, filters, main render, filter target, deinterlace or async video); - obs_source_main_render(): _main_custom_draw(), _main_srgb_aware(), _main_reads_filters() and _main_default_effect(); - can_bypass(): _bypass_reads_space() and _bypass(); then _size_skip() (zero width or height) and _texrender_stale() (the format check); - obs_source_process_filter_tech_end(): _tech_end_linear_srgb(), _tech_name() ("Draw" for NULL, else the pointer given) and _tech_end() (bypass or texture). obs-source.c.h keeps every gs_* call and texrender, the refs, the render calls, get_base_width() and get_base_height(), the debug markers and every field read, in their order and under their conditions. That is why the decisions are many small calls and not one plan per function: each old short circuit read a field or called gs_get_color_space() or deinterlacing_enabled() only on one side, so a _reads_ function says whether to read the next value, and the draw chains read one value per READ_ step, in the old order (the plan's single route struct would have hoisted those reads). Two adjustments to the plan's sketch: the texrender reuse is one decision on the format gs_texrender_get_format() returns (C still checks the pointer before calling it, and again after the destroy); and the update_deinterlace flag stays the C call deinterlacing_enabled(), as there is nothing else to decide. Types, the direct render choice, colour spaces and formats cross as int; obs-source.c.h checks that the four enums are int-sized. A value outside an enum takes the path it took before. Checked against the unchanged functions of origin/master (outside the tree, not committed): both versions extracted from obs-source.c.h, every source->field, filter->field, target->field and parent->field access rewritten into a logged access, and compiled against stubs that log every call with its arguments (obs_filter_get_target/_parent, get_base_width/_height, obs_source_video_render and the other renders, the async and deinterlace updates, gs_get_linear_srgb/gs_set_linear_srgb, gs_get_effect, gs_get_color_space, every gs_texrender_* call, the blend, clear and ortho calls, render_filter_bypass/_tex with the technique name, blog, the debug markers). 6,496,768 cases: source_render_video() for every type (and -1, 4) x 32 flag patterns x every data, enabled, rendering_filter, video_render, filter target, filter parent (and which), deinterlace and linear sRGB combination x 0-2 filters (with the skip into obs_source_skip_video_filter() and obs_source_main_render()); obs_source_main_render() alone; the filter begin for 6 wirings (no filter, no target, no parent, neither, the target is the parent, another filter) x 4 filter flags x 14 parent flags x 4 direct render choices x 6 x 6 requested and current spaces x 4 x 4 sizes (0, 1, 1920, UINT32_MAX) x texrender present, matching and begin result; the tech end for every wiring, 32 flags, bypass, texture, linear sRGB and a NULL, "Draw" or custom technique; the skip for every wiring, 32 parent flags, video_render and deinterlace of each target. The traces are identical byte for byte under GCC -O2 and clang -O0. Planted changes to the SRGB match of the bypass, the deinterlace step, the inactive rule and the enabled read are each caught. The new file joins libobs.core-source with libobs.pch.h, which includes the new header. The exported symbol sets are unchanged (1766). Refs obs-rust#2189 * test: Characterize the source and filter render routing test_source_render_route_steps compiles libobs/obs-source-render-route.c.h (ASan and UBSan) and calls only its 23 hidden functions. 18 cases: - enum_values: the filter check, draw and tech end numbers the C acts on (and the port will return), that each enum is int-sized, and that the four libobs enums obs-source.c passes as int are int-sized; - filter_target_and_parent: ready, no target, no parent, and no target first when both are missing (obs-rust#2177's guard); - video_none_every_type_and_flags, video_none_filter_and_audio: for each of nine types (the enum, -1, 4, 99 and the ends of int) and every combination of VIDEO, ASYNC, CUSTOM_DRAW, SRGB, AUDIO and CAP_DISABLED (and UINT32_MAX), whether the flags are read and whether the source is skipped; a filter draws whatever its flags; - async_update_every_type_flags_and_filter, async_update_cases: the reads and the update for every type, flag pattern and rendering_filter; - inactive_every_input: no data or disabled, enabled read only with data; - draw_every_source: source_render_video()'s draw for all 32 combinations of filters, rendering_filter, video_render, filter target and deinterlacing, against the old if/else chain, with the READ_ steps in order (so a value the old chain did not read is never asked for); - draw_next_every_step: both values of each READ_ step; draws and values outside the enum (-1, 12, 99, the ends of int) come back unchanged; - skip_every_target_and_flags, skip_cases: obs_source_skip_video_filter()'s draw for the target being the parent or not, every parent flag pattern, video_render and deinterlacing, against the old chain; - main_render_every_input: the custom draw, sRGB-aware and default-effect rules, filters.num read only for a source that is not a filter; - bypass_every_input, bypass_cases: can_bypass() for both wirings, six direct render choices, every pair of filter and parent flag patterns and every pair of eight spaces (the enum, -1, 4, the ends of int): when gs_get_color_space() is read and when the filter bypasses; the SRGB and space rules of obs-rust#1493's filter colour space class; - size_skip_every_size, texrender_stale_every_format, filter_render_every_input: the zero size skip, the format check for every pair of formats around the enum, and the default or target render into the texrender; - tech_end_every_input: the linear sRGB flag, bypass or texture, "Draw" for a NULL name and the given pointer otherwise. Characterized, not endorsed: - ASYNC without VIDEO is no video, yet an input with it would update its async textures if it got that far (it does not: the "no video" check returns first); - a direct render choice outside the enum is not direct; spaces outside the enum bypass when they are equal; - cx and cy are get_base_width()'s and get_base_height()'s uint32_t in an int, so a size of 2^31 or more is negative there and does not skip; - an empty technique name is passed on as it is. The test is in the native test graph in name order, with libm except on MSVC, in the core suite. On the C backend, the hybrid and libobs-c-reference it passes 18 of 18 (it compiles the C file into itself on each). test_filter_color_space, test_filter_skip_removed, test_scroll_filter_wide_source, test_color_correction_16f, test_darken_transparent, test_scene_rotated_scale_filter, test_slideshow_size, test_texture_render and the other 28 tests that touch filters pass on all three, unchanged. Refs obs-rust#2189 * obs-source: Add Tier 1 tests for the source and filter render routing port Tests for the port of libobs/obs-source-render-route.c.h to the render_route module of rust/obs-source. The safe core is a stub (todo!()): - filter_check() (a FilterCheck), video_reads_flags(), video_none(), async_reads_flags(), async_reads_rendering_filter(), async_update(), reads_enabled(), inactive(), draw(), draw_next() and draw_next_value() (a Draw, or the C's value, which comes back unchanged outside the enum), main_custom_draw(), main_srgb_aware(), main_reads_filters(), main_default_effect(), bypass_reads_space(), bypass(), size_skip(), texrender_stale(), filter_render(), tech_end_linear_srgb(), tech_name() (a TechName), tech_end() (a TechEnd) and skip(), on plain values: types, the direct render choice, spaces and formats as the C's int, output flags as u32; - the enum obs_source_type, OBS_SOURCE_* flag, obs_allow_direct_render and gs_color_space values, and FilterCheck, Draw and TechEnd with the C's numbers. tests/source/render_route.rs ports test_source_render_route_steps 1:1: its 18 cases under the same names (steps_*), in the same order, with the same inputs and expectations; the draw cases walk the READ_ steps against the old if/else chains written out, with the values each one reads. Edge cases (edge_*): every rule over all 65,536 low output flag patterns, each also with the high 16 bits set; types, direct render choices and spaces from -300 to 300 and near the ends of i32; sizes and formats over the same range; every C value a draw step can come back as (0 to 40 and the ends of u32) and every step reaching a draw in at most four reads. Proptests (4000 cases each): the checks, the draw and skip walks, the bypass, the main render rules, sizes and formats over full-range values. soldr cargo test -p obs-data --test obs-tests-core source::render_route fails 28 of 28 with "not yet implemented". The regression file proptest wrote for the stub is not kept. Refs obs-rust#2189 * obs-source: Port the source and filter render routing Ports libobs/obs-source-render-route.c.h, the source and filter render routing of obs-source.c, to the render_route module of rust/obs-source. obs-source.c.h stays C: every gs_* call and texrender, the refs, the render functions, get_base_width() and get_base_height(), the debug markers and every field read, in their order and under their conditions. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/render_route.rs): - filter_check(): no target first, then no parent (obs-rust#2177); - video_reads_flags() and video_none(): a type that is not a filter reads its flags and draws nothing without VIDEO; - async_reads_flags(), async_reads_rendering_filter() and async_update(): an input reads its flags, an async input rendering_filter, and an async input not drawn by its own chain updates its textures; - reads_enabled() and inactive(): enabled read only with data; - draw(), draw_next() and skip(): the draws as a Draw route with the C's numbers; each Read* step names the one value C reads next, in the old order, and draw_next() moves to the next step or the draw; on the C's value (draw_next_value()) a value outside the enum comes back unchanged; - main_custom_draw(), main_srgb_aware(), main_reads_filters() and main_default_effect(); - bypass_reads_space() and bypass() (can_bypass(): the target is the parent, direct rendering allowed, the parent neither custom draw nor async, the SRGB flags agree, and then the spaces match), size_skip(), texrender_stale() and filter_render(); - tech_end_linear_srgb(), tech_name() (Given or Draw) and tech_end(). The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock. Shim (src/ffi/source_render_route.rs): the 23 functions keep the C signatures, plain values in and out; the enums come back as their C values. One pointer crosses: obs_source_render_route_tech_name() returns the name it is given, or a static c"Draw" for NULL, and never reads through it (gs_effect_get_technique() compares the name by its bytes, so the address differing from the C literal's does not matter). No other intentional differences. C side: the file leaves libobs.core-source for its own group, libobs.ported-source-render-route (LIBOBS_PORTED_SOURCES), whose PCH is obs.h (the enums and flags) and obs-source-render-route.h. libobs.pch.h keeps the header for obs-source.c. The functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. libobs-rust already links the crate's ffi. The exported symbol sets are unchanged and equal: 1766 on the C backend, the hybrid and libobs-c-reference; the 23 are local in all three, and the hybrid's come from the Rust archive. ci/test_ported_sources.py checks the group on every host. test_source_render_route_steps still compiles the C file into itself, unchanged. The new test_source_render_route_steps_rust builds the same test source against libobs_rust-static (and libm except on MSVC): the test calls only the 23 functions and includes their header and obs.h, so it takes libobs's include directories (SIMDe, obsconfig.h) and links the archive alone. It passes 18 of 18 against the shims. The filter tests (test_filter_color_space, test_filter_skip_removed, test_scroll_filter_wide_source, test_color_correction_16f, test_darken_transparent, test_scene_rotated_scale_filter, test_slideshow_size, test_texture_render and 28 more) see the swap through the hybrid and pass on all three builds. Tier 1 source::render_route passes 28/28. clippy -D warnings is clean for the host and x86_64-pc-windows-msvc. Refs obs-rust#2189 * obs-source: Check the source and filter render routing port against the C Oracle (oracle/source_render_route.c): the original obs-source-render-route.c.h, unmodified, with its 23 functions renamed to oracle_*, plus every value the port uses (the four source types, the six OBS_SOURCE_* flags it names, the direct render choices, the four colour spaces, GS_RG16, and the filter check, draw and tech end values) and the sizes of the four libobs enums, the three route enums, int, bool and uint32_t. The rename macros also rename the three enum tags that share their function's name, so the size table names the renamed tags. The bool results are declared as u8 on the Rust side, the byte the C returns. Tier 3 (tests/source/render_route_parity.rs, 15 tests). Every function takes and returns plain values, so each run compares the bytes of the two results; obs_source_render_route_tech_name() must hand back the pointer it is given on both sides, and "Draw" for NULL on both. - the values and sizes against the C headers; - every boolean input of the single-call functions; - types, direct render choices, spaces, formats and sizes over every value from -70000 to 70000, every 65521st i32 over the whole range and the ends (205,569 values); - all 65,536 low 16-bit output flag patterns, with the high bits clear and set, for every rule that reads flags, for ten types; - can_bypass(): both wirings, 14 direct render choices, every pair of 65 flag patterns and every pair of 12 spaces (17,035,200 inputs), then every parent flag pattern for four filter flags and the sweeps above for the direct render choice and both spaces; - every draw step value from 0 to 70000 and near the ends of u32, both ways; - source_render_video()'s decisions in its order (the reads, the skips, the async update, the draw walk and obs_source_main_render()'s rules), one copy on each side: 166,400 sources; the begin, tech end and skip decisions of a filter in their order: 19,906,560 filters; - proptests (20,000 cases each) over full-range values. None of these functions divides or does arithmetic, so no input reaches a path that traps under MSVC x64 (_udiv128, INT_MIN / -1): no input is skipped on any target. Tier 1 and the parity module passed 6 runs in a row with fresh seeds (43/43 each). No regression file came up on the port; the ones the todo!() stub and the mutants below wrote are not kept. Mutation check: each mutant of src/render_route.rs against Tier 1, Tier 3 and test_source_render_route_steps_rust (the C characterization linked to the Rust archive). Failing tests per tier: | Mutant | Change | Tier 1 | Tier 3 | cmocka | |---|---|---|---|---| | M1 | video_none ignores the filter type | 3 | 4 | 2 | | M2 | async_update ignores rendering_filter | 3 | 4 | 2 | | M3 | enabled read without data | 2 | 3 | 1 | | M4 | filter target step draws main | 3 | 3 | 2 | | M5 | skipped filter's chain reads its own filter target | 3 | 3 | 2 | | M6 | bypass ignores the SRGB match | 3 | 4 | 2 | | M7 | bypass ignores the space | 3 | 5 | 2 | | M8 | zero size needs both sizes 0 | 2 | 3 | 1 | | M9 | texrender stale only for a smaller format | 3 | 4 | 1 | | M10 | filter render ignores ASYNC | 2 | 4 | 1 | | M11 | tech end linear sRGB inverted | 2 | 4 | 1 | | M12 | skip of another filter draws default | 4 | 4 | 2 | | M13 | a step outside the enum becomes DEFAULT | 2 | 2 | 1 | | M14 | no parent checked before no target | 1 | 3 | 1 | | M15 | default effect ignores custom draw | 3 | 4 | 1 | | M16 | direct render accepts any non-zero choice | 4 | 5 | 2 | All 16 are killed by every tier. Refs obs-rust#2189 * docs: Record the source and filter render routing port The rust/README.md crate table now lists libobs/obs-source-render-route.c.h among the rust/obs-source units, and its port table has a row for it: the 23 functions and what they decide, what stays C (every gs_* call and texrender, the refs, the render calls, get_base_width() and get_base_height(), the debug markers and every field read, in their order and under their conditions), why the decisions are many small calls with _reads_ functions and READ_ steps rather than one plan, the types, choices, spaces and formats as int, what is kept and characterized, the one pointer that crosses (the technique name), the _rust variant of the characterization, the real-libobs tests and what Tier 3 compares. The crate's description and lib.rs say what it holds. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source, so it needs no row. port_comparison gets its own bench file, benches/port_comparison/source_render_route.rs, in the sorted modules! list: 1024 source_render_video() decision runs (the checks, the draw walk and obs_source_main_render()'s rules), 1024 filter begin and tech end runs and 1024 skip runs, folded into checksums both sides must match. The fixtures are plain Rust arrays, nothing allocated with bmalloc, so the per-module allocation check passes. On x86_64 Linux (GCC, not pinned, load average 13 to 24; median per 1024 calls, two runs): render_video 47.0 and 31.4 us Rust, 79.6 and 33.6 us C; filter 8.3 and 7.2 us Rust, 9.3 and 12.3 us C; skip 4.3 and 13.9 us Rust, 4.2 and 8.9 us C. All within the noise of that machine: a few ns per source or filter either way. Fixes obs-rust#2189
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.
Fixes #2160
What and why
obs_source_skip_video_filter()(libobs/obs-source.c.h) readparent->info.output_flagswithout checking the parent.obs_source_filter_remove()clears the filter's parent and target, and the graphics thread renders the filter chain from a reference it took before the removal (obs_source_render_filters()dropsfilter_mutexbefore it renders the first filter). So a filter removed while it renders (from the Filters dialog, a script or obs-websocketRemoveSourceFilter) that then skips, as filters do when they are disabled or have nothing to draw, crashed on a NULL parent. A filter that was never attached crashed the same way.The function now returns when the parent or the target is NULL, as
obs_source_process_filter_begin_with_color_space()andobs_source_process_filter_tech_end()already do. The removed filter draws nothing for that frame. An attached filter skips as before. Spec-following, no change while a filter is attached. Upstream has the same code.git log -Lon the function shows only upstream history (added in 2015, last changed by the deinterlacing API); the fork never changed it.Two commits:
RED:
test_filter_skip_removed, a new real-libobs test in the graphics suite (OS_LINUX+HAVE_OBS_OPENGL, sorted intotest-graph.json). It is new rather than an extension: the existing filter tests cover plugin filters (test_scroll_filter_wide_source,test_color_correction_16f) or colour space routing with no video (test_filter_color_space), and none registers its own video filter or renders through the filter helpers. It registers two parents (one that draws itself, one drawn with the default effect) and a filter that skips on every render. Five cases:video_render, then skips, with the parent on output channel 0, so the graphics thread renders it as in OBS.obs_source_filter_remove()clears the parent and target at once (it takes the parent'sfilter_mutex, which the render no longer holds), so the skip sees them NULL deterministically, with no second thread racing. It checks the filter rendered once, the skip returned, and the filter has no parent, no target and is no longer in the list;video_render; nothing is drawn;obs_source_main_render()); target is the parent, drawn with the default effect; a chain of two filters, where the top filter's target is the filter below it.The removal case runs last: without the fix it crashes on the graphics thread.
GREEN: the early return, and a
docs/features.mdline under fixed upstream bugs (Stability).Other filter helpers (read only):
obs_source_process_filter_begin_with_color_space(): checks the target and the parent and returns. Fine.obs_source_process_filter_tech_end()(andobs_source_process_filter_end(), which calls it): checks the target and the parent and returns. Fine.source_render_video()calls the skip onlyif (source->filter_parent), and readsfilter_targetbefore passing it toobs_source_video_render(), which checks NULL. Fine.obs_source_get_color_space()passes the parent or target to itself, which checks NULL. Fine.obs_filter_get_parent()/_target()user inplugins/checks the result or passes it to a public function that checks NULL (obs_source_get_base_width(),obs_source_get_color_space(),obs_source_get_name(),obs_source_release_frame()). Fine.No other same-class NULL dereference in
obs-source.c.h, so nothing else is changed.Not fixed here (races, recorded for a separate change):
filter_parentandfilter_targetare still read with no lock on the graphics thread while another thread clears them. That data race stays; the fix only stops the crash. Making the two fields atomic is a separate change.get_base_width()/get_base_height()readfilter_parentand thenfilter_targetseparately, and recurse into the target with no NULL check.obs_source_restore_filters()sets a reused filter's parent before its target (the target is set one iteration later), outsidefilter_mutex, while the graphics thread can still be rendering that filter from an earlier reference. A disabled filter sized in that window would read a NULL target. Timing only; these lines are in the size routing being moved in obs-source: Port the source size query routing #2171, so they are left alone here.Overlap: #2171 (size routing) and #2175 (volume snap and apply) touch
obs-source.c.h, at lines 2219-2565 and 4716-4847. This change is at 3975 only.RED → GREEN
fc522b463(runs onc74bf1c2b, the same commit before the rebase onto master).test_filter_skip_removedfails on the C backend, against the hybrid libobs and againstlibobs-c-reference: the three attached cases pass,unattached_filter_skipsfails with a segmentation fault in the skip, andfilter_removed_during_render_skipslogs the removal and then crashes the process with a segmentation fault. Every other filter test passes (35/36 C, 40/41 hybrid and c-ref).0a2dc0b6f.test_filter_skip_removed5/5, with the removal case seeing one render and the skip returning, plus every existing test that mentions filters (36 ctest entries with the new test on the C backend, 41 with the_rustvariants against the hybrid libobs andlibobs-c-reference): all pass, no skips. Run onbe5520346(GREEN before the rebase) and again on the head. On the head one C-backend run oftest_properties_dialog_refresh(a Qt colour dialog test, no filters involved) failed once at a host load of about 40 and passed 3/3 alone.be5520346(private Xvfb, fresh HOME, TMPDIR unset,ulimit -c 0): 451/451 on the C backend and 465/465 against the hybrid libobs, 0 skipped. The known flakes (test_deinterlace_2x_field_order is timing-sensitive (yadif 2x 60i into 60): startup underrun and load-induced hold #456, Flaky: real-time audio cmocka tests lose audio under machine load (test_vlc_playlist_gap, test_group_hide_transition_audio) #838) did not fail.libobs-c-reference, identical sets, onbe5520346and on the head.ci/local_gate.py --test-diff origin/master: 3412 Rust tests pass (4 skipped, all#[ignore]), onbe5520346and on the head.--lane lintand--lane crosspass onbe5520346; the rebase changed only where thedocs/features.mdline sits.be5520346: sorted shared lists, test graph sorted, cmocka includes, cmocka Windows diagnostics, cmocka sanitize, mbedtls graph, rust-static guard and naming. Sorted shared lists, test graph sorted, cmocka includes and naming pass again on the head.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC