Skip to content

libobs: Fix color space query through non-video filters - #1493

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:port/color-space-audio-filter
Oct 20, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:port/color-space-audio-filter

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1492

What and why

HDR Tone Mapping now works whatever the filter order. Before, an audio filter (Gain, Noise Suppression, ...) below it made an HDR source look SDR to it, and it did nothing.

  • obs_source_get_color_space() answered for an enabled audio-only filter itself: it has no video_get_color_space callback, so the result was sRGB. A filter above it that reads its target's colour space (HDR Tone Mapping) got that sRGB instead of the source's space.
  • A filter with no video output now passes the query on to its target, as a disabled filter already did. Six lines in libobs/obs-source.c.h, no API change.
  • Port of upstream PR libobs: Fix color space query through non-video filters obsproject/obs-studio#13761 by saitatter (SaiTatter), approved upstream by derrod and not merged yet. Adapted only for the file name (obs-source.c is obs-source.c.h here). The GREEN commit credits the author.

Headless (private Xvfb, private D-Bus, fresh HOME), test_filter_color_space against each build's libobs:

Build Case Result
v0.1.0-beta.20261018 AppImage libobs audio filter / tone mapping above it / audio filter above tone mapping sRGB, 3 of 5 fail
This branch same 5 cases 5/5 pass

RED → GREEN

  • RED commit: 3646eda test: Audio filters pass colour space queries down the filter chain. test_filter_color_space registers an HDR source with audio, an audio-only filter, a video filter without a colour space callback and a tone-mapping filter that asks its target, as hdr-tonemap-filter does. On master 3 of 5 cases fail (test_audio_filter_passes_query_on, test_tonemap_above_audio_filter, test_audio_filter_above_tonemap: sRGB instead of the source's space). Two controls pass on both sides: a disabled audio filter already passed the query on, and a video filter without a callback still answers sRGB.
  • GREEN: 2020a64. test_filter_color_space 5/5. The change is in libobs core (C only: obs-source has no Rust port), so I ran the full ctest -j4 of the C lane: 325/325, none skipped.
  • Real app: not run; colour spaces are not visible over obs-websocket, and the test drives the same libobs calls the filters make.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • User-visible change: its line in docs/features.md is added (Fixed upstream bugs, Sources and filters)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite

rdoupe and others added 2 commits October 20, 2026 00:27
An audio-only filter (Gain, Noise Suppression, ...) in a source's
filter chain answers obs_source_get_color_space() with sRGB instead of
passing the query on to the filter or source below it. HDR Tone Mapping
above such a filter then takes an HDR source for SDR, so whether it
works depends on the order the filters were added in (upstream
obsproject/obs-studio PR #13761).

The test registers an HDR source with audio, an audio-only filter, a
video filter without a colour space callback and a tone-mapping filter
that asks its target, as hdr-tonemap-filter does. On master 3 of 5
cases fail: the audio filter answers sRGB itself, and the tone-mapping
filter above it sees sRGB. Two controls pass: a disabled audio filter
already passed the query on, and a video filter without a callback
still answers sRGB.

Refs obs-rust#1492
An audio-only filter answered obs_source_get_color_space() itself, with
sRGB, when it was enabled. A filter above it that reads its target's
colour space, HDR Tone Mapping for one, then took an HDR source for SDR
and did nothing, so it worked or not depending on the order the filters
were added in.

A filter with no video output now passes the query on to its target,
as a disabled filter already did.

Port of upstream obsproject/obs-studio PR #13761 (approved upstream,
not merged yet). Adapted only for the file name: obs-source.c is
obs-source.c.h here.

Fixes obs-rust#1492

Co-Authored-By: SaiTatter <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 04:27
@zackees
zackees added this pull request to the merge queue Oct 20, 2026
Merged via the queue into obs-rust:master with commit b0e3be0 Oct 20, 2026
23 checks passed
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 23, 2026
* libobs: Move the source colour space routing into obs-source-color-space.c

Behaviour-neutral extraction before the Rust port. The decisions of
obs_source_get_color_space() in obs-source.c.h move to
libobs/obs-source-color-space.c.h as two pure functions, declared in the
new libobs/obs-source-color-space.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- obs_source_color_space_route(): which source answers. A non-filter
  source with no video asks its filter parent; a filter with no video asks
  its target (obs-rust#1493); a source with no data, or a disabled one, asks its
  target; an async source picks; any other asks its callback. The checks
  run in the same order as before.
- obs_source_color_space_pick(): the async pick, the same loop: the first
  preferred space equal to the frame's space, else the last preferred
  space, else (none) the frame's space.

obs_source_get_color_space() keeps data_valid(), reads info.type,
info.output_flags, context.data != NULL, enabled, filter_parent != NULL
and filter_target != NULL into struct obs_source_color_space_node, and
follows the route: the recursion into the parent or the target,
convert_video_space() of async_format and async_trc (passed to the pick),
and video_get_color_space or GS_CS_SRGB, with the assert, as before.

The colour spaces cross as int, so the header needs no graphics header.
obs-source.c.h checks at compile time that enum gs_color_space and enum
obs_source_type are int-sized, and that the header's filter type and VIDEO
and ASYNC flags are OBS_SOURCE_TYPE_FILTER, OBS_SOURCE_VIDEO and
OBS_SOURCE_ASYNC. The obs-rust#1493 comment moves with its check.

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#1979

* test: Characterize the source colour space routing

test_source_color_space_steps compiles libobs/obs-source-color-space.c.h
(ASan and UBSan, no libobs core) and calls only its two hidden functions,
so it runs on every platform. 12 cases:

- obs_source_color_space_route(), every combination of the inputs: a
  filter or not, the VIDEO and ASYNC flags (output_flags carries both, so
  the six fields are seven inputs and 128 rows), data, enabled, a filter
  parent and a filter target. Each row's route is written out.
- Only OBS_SOURCE_TYPE_FILTER is a filter: transitions, scenes and values
  outside the enum route as inputs, over all 64 input rows. Only the VIDEO
  and ASYNC bits count: every other flag set, or OBS_SOURCE_AUDIO, changes
  no route.
- The chains of test_filter_color_space and obs-rust#1493: the HDR async source
  picks; an audio filter above it asks its target, enabled or not; a
  video filter asks its callback, and its target when disabled or without
  data; a detached audio filter asks its callback; an audio-only input
  asks its filter parent before its target.
- obs_source_color_space_pick(): no preferred spaces (NULL, or a count of
  0) gives the frame's space; a match first, last or in the middle stops
  there, a later match included; no match gives the last preferred space,
  with the HDR Tone Mapping filter's list among them.

Characterized, not endorsed:
- a filter flagged async picks from its own async frame's space, unless
  obs-rust#1493's rule (no VIDEO) or the disabled rule sends it to its target;
  filters have no async frames, so in libobs that is GS_CS_SRGB;
- with no data and nowhere to go the route is the callback or the pick
  (obs_source_get_color_space() checks data_valid() first, so libobs
  never gets there);
- a value outside enum gs_color_space in the list is compared and
  returned as it is.

It is in the native test graph, in the core suite. The real-libobs
test_filter_color_space is unchanged.

Refs obs-rust#1979

* obs-source: Add Tier 1 tests for the source colour space routing port

RED for the port of libobs/obs-source-color-space.c.h to the color_space
module of rust/obs-source, next to audio_timing and deinterlace_pacing.
The safe core is a stub (todo!()): route() over a Node (the source's
type, output flags, and whether it has data, is enabled and has a filter
parent and a filter target) giving a Route (AskParent, AskTarget,
AsyncPick, Callback), and pick() of the frame's space from a slice of
preferred spaces, one per hidden C function, with TYPE_FILTER, VIDEO and
ASYNC.

tests/source/color_space.rs ports test_source_color_space_steps 1:1: its
12 cases under the same names (steps_*), in the same order, with the same
inputs and expectations, the 128-row route table and the
characterized-not-endorsed cases included.

Edge cases (edge_*): the route's invariants over every row and four
types (a filter never asks its parent, nothing asks a parent or target it
does not have, an enabled video source with data asks no one, only ASYNC
picks); obs-rust#1493's rule with any other flags; and three proptests (4000
cases each): any type but OBS_SOURCE_TYPE_FILTER routes as an input and
only the VIDEO and ASYNC bits count, over any i32 type and any u32 flags;
the pick against a model written another way (the frame's space when the
list is empty or holds it, the last entry otherwise) over lists of 0 to 8
values; and a list holding the frame's space anywhere gives it back.

The tests are a module of obs-tests-core (rust/obs-data/tests/core.rs),
as audio_timing's are.

soldr cargo test -p obs-data --test obs-tests-core source::color_space
fails 17 of 17 with "not yet implemented".

Refs obs-rust#1979

* obs-source: Port the source colour space routing

Ports libobs/obs-source-color-space.c.h, the colour space query routing
of obs_source_get_color_space(), to the color_space module of
rust/obs-source. obs_source_get_color_space() stays C in obs-source.c.h:
data_valid(), the field reads into the node, the recursion into the
filter parent or target, convert_video_space() of the async frame's
format and transfer, and the video_get_color_space callback (GS_CS_SRGB
without one). The hybrid libobs drops the C file and links the Rust shims
in its place.

Safe core (src/color_space.rs): route() tries the C's rules in the C's
order: a non-filter without VIDEO and with a filter parent asks the
parent; a filter without VIDEO and with a target asks the target
(obs-rust#1493's rule, kept exactly); a source without data, or disabled, with a
target asks the target; an ASYNC source picks; anything else asks its
callback. Only OBS_SOURCE_TYPE_FILTER is a filter and only the VIDEO and
ASYNC bits count. pick() is the C's loop: each preferred space in turn,
stopping at one equal to the frame's space, so no match leaves the last
one and an empty list the frame's space. Values outside enum
gs_color_space are compared and returned as they are. The module denies
clippy's arithmetic, indexing, as, unwrap, expect, panic, unimplemented
and unreachable lints, keeps no state and takes no lock.

Shim (src/ffi/source_color_space.rs): obs_source_color_space_route()
takes struct obs_source_color_space_node by value (mirrored, #[repr(C)])
and returns the C's enum values; obs_source_color_space_pick() takes the
count and pointer. No source pointer crosses. Intentional difference: a
null list with a count above 0 is read as empty (the C reads through the
null pointer); libobs passes NULL only with a count of 0.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-color-space (LIBOBS_PORTED_SOURCES), whose PCH is
only obs-source-color-space.h; libobs.pch.h keeps the header for
obs-source.c. The two 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 two 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_color_space_steps still compiles the C file into itself,
unchanged. The new test_source_color_space_steps_rust builds the same
test source against libobs_rust-static instead, as
test_source_audio_timing_steps_rust does: the test calls the two hidden
functions directly, so this variant runs the shims, the node passed by
value from C included. It passes 12 of 12 on the hybrid tree.
test_filter_color_space sees the swap through the hybrid.

Tier 1 source::color_space passes 17/17.

Refs obs-rust#1979

* obs-source: Check the source colour space routing port against the C

Oracle (oracle/source_color_space.c): the original
obs-source-color-space.c.h, unmodified, with its two functions renamed
to oracle_*, plus the node's layout (size, alignment, the six offsets),
the size and values of the route enum and the filter type and VIDEO and
ASYNC constants. The node is mirrored on the Rust side and passed by
value, as obs-source.c.h passes it.

Tier 3 (tests/source/color_space_parity.rs, 7 tests), comparing the
route's value and the picked space:
- the layout and constants against the C header, and the shim's mirror
  against the oracle's;
- the route over every combination of the VIDEO and ASYNC flags, data,
  enabled, a filter parent and a filter target (64), with eight types
  (the four enum obs_source_type values, -1, 4 and the ends of i32: so
  all 128 rows of the characterization, the filter type and seven
  others) and sixteen sets of other flags (OBS_SOURCE_AUDIO, bits 3, 10
  and 31, every other bit): 8,192 nodes, each route reached more than
  100 times; and a proptest over any i32 type, any u32 flags and the four
  bools (20,000 cases);
- the pick over every list of 0 to 5 values from -1..=4 (the four
  gs_color_space values and one past each end) against each of those
  frame spaces: 9,331 lists, 55,986 picks; and a proptest over lists of
  0 to 8 arbitrary i32 values, the frame's space drawn from the list half
  the time so matches land first, last and in the middle (20,000 cases);
  both sides read the list through a pointer;
- a count of 0 reads nothing on either side, with a null pointer or not;
- the intentional difference, on the shim only: a null list with a count
  above 0 gives the frame's space.

The parity module passed 20 runs in a row with fresh random seeds; no
regression file came up.

Mutation check (done once, not committed), with the two test modules in
obs-tests-core: 33 mutants. The 27 core mutants all fail Tier 1 (2 to 7
of 17) and Tier 3 (2 or 4 of 7): each rule removed, each rule widened
(filters asking their parent, sources with video asking it, any source
without video asking its target, filters with video asking it, a parent
or target asked without one), the disabled rule on data only, enabled
only or both, the rules reordered, the async rule on the VIDEO bit or
skipped for filters, any non-input type a filter, any flag counted as
video, the fallback picking, and the pick without its break, giving the
frame's space or the first entry with no match, GS_CS_SRGB for an empty
list, skipping the last entry or stopping one late. obs-rust#1493's rule
reverted fails 5 of 17 and 2 of 7. Of the 6 shim mutants, 5 fail Tier 3
(the parent and target routes swapped, the parent and target flags
swapped, the type read as 0, the count less one, and the null check
dropped, which aborts in from_raw_parts); Tier 1 does not reach the
shims. One survives and is equivalent: has_data and enabled swapped in
the shim, which the route only reads as !has_data || !enabled.

Refs obs-rust#1979

* docs: Record the source colour space routing port

The rust/README.md crate table now lists libobs/obs-source-color-space.c.h
among the rust/obs-source units, and its port table has a row for it: the
two functions and their rules in order (obs-rust#1493's included), what stays C
(data_valid(), the field reads, the recursion, convert_video_space() and
the callback), the node passed by value, the int-sized colour spaces and
the compile-time checks, what the characterization pins and the port
keeps, the intentional difference (a null list with a count above 0 is
empty), the _rust variant of the steps test, test_filter_color_space 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.

port_comparison gets its own bench file,
benches/port_comparison/source_color_space.rs: 1024 routes over every
combination of the inputs, with and without OBS_SOURCE_AUDIO, and 1024
async picks of the four frame spaces from lists of 0 to 4 preferred
spaces, matched first, last, in the middle or not at all, each folded
into a checksum both sides must match. On x86_64 Linux (GCC, not pinned;
median per 1024 calls): route 2.05 us Rust and 2.26 us C (0.91x),
async_pick 2.21 us Rust and 2.69 us C (0.82x), about 2 ns a call either
way.

Fixes obs-rust#1979
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
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
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: an audio filter below HDR Tone Mapping makes an HDR source look SDR (upstream PR #13761)

2 participants