Skip to content

obs-scene: Port the group content extent - #1922

Merged
zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/scene-extent
Oct 23, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/scene-extent

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1919

What and why

This PR ports the content extent of a scene or group, the min/max fold in resize_scene_base (libobs/obs-scene.c.h), to a new extent module of rust/obs-scene. Every time a group or scene is resized, the fold takes the four corners of each item's box transform and gives the extent that the group's size and its children's shift come from. The saturating size cast it ends with landed first in #1840.

What stays C: the item loops in resize_scene_base, the child shift (it calls update_item_transform), resize_scene and resize_group. The hybrid libobs drops the C fold and links the Rust shims in its place.

  • Move (libobs: Move the scene content extent out, no behaviour change):

    • The fold and the size step move verbatim into libobs/obs-scene-extent.c.h, behind obs_scene_extent_init(), obs_scene_extent_add() (one item's box_transform) and obs_scene_extent_size(). They are declared in obs-scene-extent.h without EXPORT.
    • obs_scene_size_from_extent(), the static inline from libobs: Clamp loaded scene item crops and saturate the crop and group size casts #1840, moves with them from obs-scene.h into obs-scene-extent.h, and obs-scene.h includes that header, so test_scene_crop_steps and the scene see it as before. Without this move the new file would need obs-scene.h, whose structs use pthread_mutex_t. That compiles on glibc only by accident and not under MSVC, so the C test and the oracle could not build the file on its own.
    • The file gets its own small PCH (math-defs, vec3.h and its header, no core header).
  • Characterization (test_group_extent, 10 cases): one item, several, a rotated item (the extent comes from the corners, not the box), a fractional extent rounded up, the empty fold, NaN, ±inf, items past the start values, out-of-range sizes, and ties.

    • The fold starts at M_INFINITE, which is 3.4e38 and not infinity. So an item at +inf or -inf on its own is UINT32_MAX wide (inf - 3.4e38). An item wholly past 3.4e38 leaves the start value in place. The empty fold is -inf wide, which gives 0. Characterized, not endorsed.
    • A NaN anywhere in an axis's column makes every corner NaN on that axis (the corners have z = 0 and w = 1, and 0 * NaN is NaN). The < and > compares are false for NaN, so the fold skips the item on that axis. An infinitely wide item is UINT32_MAX wide (its corners are NaN and +inf).
    • A tie keeps the value already there, so with -0 and +0 the first one stays.
    • The symbols are not exported, so the test compiles the C into itself, like test_scene_group_transform. It is registered in test/cmocka/build/test-graph.json (core suite). It uses no assert_in_range, and its helpers avoid the names that cmocka 2.x's expect_* macros take.
  • Safe core (src/extent.rs):

    • init() -> Extent, add(&mut Extent, &Matrix4) (one call per item, so no array is built) and size(&Extent) -> Size { scale, cx, cy }, plus size_from_extent(f32) -> u32.
    • The corners go through group_transform::transform_val, which is vec3_transform's sum order and already parity-checked, so this object does not call into obs-graphics.
    • The fold uses the C's strict < and >, not f32::min/f32::max. A NaN corner is skipped, and a ±0 tie keeps the first value. No unsafe.
  • Shim (src/ffi/scene_extent.rs): the three functions, with the C signatures. Each reads its inputs, then writes its outputs. C passes &item->box_transform, so no item field is mirrored.

  • C side:

    • obs-scene-extent.c.h is in its own group, libobs.ported-scene-extent, listed under LIBOBS_PORTED_SOURCES in source-sets.json. Its PCH is libobs-ported-scene-extent.pch.h.
    • ci/test_ported_sources.py checks the group on Linux, Windows and macOS, and checks that obs-scene.c.h stays in production.
  • Symbols: the three shims are listed in rust-hidden.txt, in the local: list of rust-exports.map and in rust-unexports-macos.txt. nm shows them as local (t) in the hybrid libobs. The exported symbol sets are unchanged: 1766 in all three libraries.

  • Oracle (oracle/scene_extent.c): the original file, unmodified, with the three functions renamed to oracle_*. vec3_transform comes from the graphics oracle, as in scene_group_transform.c.

  • Docs:

    • The rust/README.md rows (crate table and port table) and the crate's Cargo description are updated.
    • The docs/rust-port/naming.md row (libobs/obs-scene*.c.h) already covers the file.
    • No docs/features.md line: there is no user-visible change.
  • port_comparison: scene_extent/fold/{1,16}, shim against oracle (start the fold, add 1 or 16 turned boxes, size it). Pinned to one core, the medians are:

    • one item: 10.3 ns (Rust) against 71.7 ns (C);
    • 16 items: 55.5 ns against 1.02 µs.

    The C calls vec3_transform out of line for every corner, with its transpose. The Rust core has the four dots inline. The fold runs once per group or scene resize.

No intentional differences. Since #1840, every input has defined C behaviour, so the parity test excludes nothing.

test_group_child_drift (#9298), test_group_empty_bounds (#388/#4245), test_scene_group_transform and test_scene_dup_group_children link OBS::libobs. In the hybrid libobs they run the Rust fold through real groups.

RED → GREEN

  • RED commit: b5449cfc6 obs-scene: Add the scene content extent tests. The core is todo!(). soldr cargo test -p obs-data --test obs-tests-core scene::extent fails all 15 cases (0 passed, 15 failed, "not yet implemented").
    • Tier 1 (tests/scene/extent.rs) mirrors test_group_extent case for case, under the same names, with the same matrices and expectations.
    • 5 new edge cases:
      • the size step on its own (the values test_scene_crop_steps pins);
      • a NaN in the y column only;
      • an infinite z row, which reaches the corners through 0 * inf;
      • the -0/+0 ties on the min side and on y.
    • The tests are a module of the existing core category binary, obs-tests-core. No new test binary.
  • GREEN: 390b976e5 obs-scene: Port the scene content extent. scene::extent passes 15/15.
  • Tier 3: cfc83bab9 obs-scene: Check the scene content extent port against the C (tests/scene/extent_parity.rs).
    • What is compared. Both sides run init, each add, then size. Min and max must be bit-equal after every add (-0 is not +0, and a start value must stay exactly where the C leaves it). Then the scale must be bit-equal, the default NaN of inf - inf included, and cx and cy equal.

    • Runs:

      • the layout;
      • the cmocka matrices;
      • 4096 random lists of up to 8 matrices, with entries that are finite, huge (up to f32::MAX), ±0, ±1, NaN, ±inf, ±M_INFINITE, 2^32 and its neighbour below, or any bit pattern;
      • the same for box transforms as the scene builds them;
      • 4096 lists of matrices with entries from 0, -0, 1 and -1 only, so -0 and +0 corners tie often;
      • the add and size shims on their own, from any min and max.
    • Excluded: only one thing. With both min and max NaN on an axis, max - min may carry either NaN's payload (the compiler orders the operands), so that one case compares as "both NaN". The fold itself never stores a NaN.

    • Mutation check (done once, not committed): 10 of 11 mutants fail Tier 3, and most fail Tier 1 too:

      • f32::min/f32::max for the compares;
      • <= on the min;
      • >= on the max;
      • an infinite start;
      • three corners;
      • y compared against x;
      • round for ceil;
      • saturating one step below 2^32;
      • a swapped scale;
      • a plain product instead of the C's dot.

      The first run showed that >= on the max passed both tiers and <= on the min passed Tier 3, because random corners almost never tie at ±0. The 0/±1 proptest and a y-tie Tier 1 case were added for them, and both mutants then fail. The one survivor is equivalent: dropping the NaN check in the size, where Rust's NaN as u32 is 0, the same value.

  • Local, on 28a561ade: OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON. Headless: private Xvfb with -noreset, private D-Bus, fresh HOME.
  • Rebased onto c65fffd77 then c9a6cce13 (obs-core: Port util/source-profiler.c #1887), 088d9cff7 (obs-output: port the obs-service lifecycle, references and activation (#1920) #1923) and 739a3c0f2 (obs-media-io: Port media-io/media-remux.c.h #1928, test: fix the source_profiler_parity race (#1930) #1931); the conflicts were only in Cargo.lock, rust/README.md, the oracle's Cargo.toml and benches/port_comparison.rs. After the rebase, ci/test_build_groups.py, ci/test_ported_sources.py, scene::extent (22/22) and the lint lane were re-run and pass.
Lane Library Scene/group ctest (-R 'scene|group') Exported symbols
OBS_LIBOBS_BACKEND=C libobs 26/26 1766
HYBRID, OBS_BUILD_C_REFERENCE=ON hybrid libobs 27/27 1766, identical
HYBRID, OBS_BUILD_C_REFERENCE=ON libobs-c-reference 27/27 1766, identical
  • Nothing was skipped. The hybrid lanes also run test_scene_bounds_place_rust.
  • Among those runs: test_group_extent 10/10, test_group_child_drift, test_group_empty_bounds, test_scene_group_transform, test_scene_dup_group_children and test_scene_crop_steps pass on all three libraries. The move commit on its own also passes them on the C lane.
  • soldr cargo test -p obs-data --test obs-tests-core passes 933/933, 22 of them new (15 Tier 1, 7 Tier 3).
  • soldr cargo bench -p obs-c-oracle --bench port_comparison -- --test scene_extent passes.
  • Also run: uv run ci/local_gate.py --lane lint passed, and --lane cross passed. ci/test_build_groups.py, ci/test_ported_sources.py, ci/test_rust_scope.py, ci/test_ci_scope.py and ci/test_binary_cap.py pass. The export_list tests pass.
  • Real app (UI, protocol output or logging changes): not applicable (no behaviour change for libobs).

Windows/macOS: not built there. The core and the shim have no host conditional. The new file and its test now need no pthread type.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • 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 (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (none)

@rdoupe
rdoupe requested a review from zackees as a code owner October 23, 2026 09:28
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
@rdoupe
rdoupe force-pushed the port/scene-extent branch 2 times, most recently from 2030806 to e4f4be9 Compare October 23, 2026 10:56
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
@rdoupe
rdoupe force-pushed the port/scene-extent branch from e4f4be9 to 1bd329d Compare October 23, 2026 11:58
@zackees
zackees enabled auto-merge October 23, 2026 12:11
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
The min/max fold over the four corners of each item's box transform
and the size step of resize_scene_base now live in
obs-scene-extent.c.h, behind obs_scene_extent_init(),
obs_scene_extent_add() and obs_scene_extent_size(). They are declared
in obs-scene-extent.h without EXPORT. The scene still walks its items,
still shifts the children so the content starts at the origin, and
resize_scene and resize_group are unchanged. Same behavior.

obs_scene_size_from_extent(), the static inline from obs-rust#1840, moves with
them into obs-scene-extent.h, which obs-scene.h now includes, so its
users see it as before. The new file then needs no core header (not
obs-scene.h, whose structs need the pthread types), and a test or the
oracle can compile it on its own on every platform.

Refs obs-rust#1919
The symbols are not exported, so the test compiles
obs-scene-extent.c.h and pins what it does today: one item, several,
a rotated one (the corners, not the box), a fractional extent rounded
up, the empty fold, NaN, the infinities and out-of-range sizes.

The fold starts at M_INFINITE, which is 3.4e38 and not infinity, so an
item at +inf or -inf alone is UINT32_MAX wide, and one wholly past
3.4e38 leaves the start value in place. A NaN corner fails both
compares and is skipped. A tie keeps the value already there, so -0
and +0 keep the first. No display.

Refs obs-rust#1919
Tier 1 mirrors test_group_extent case for case, and adds the size step
on its own, a NaN in the y column, an infinite z row, and the ties of
-0 and +0 on the min side and on y. The core is still todo, so all 15
cases panic: not yet implemented.

Refs obs-rust#1919
The safe core matches obs-scene-extent.c.h: the fold starts at
M_INFINITE, takes the four corners of each box transform through
vec3_transform's sum order, and keeps the C's strict < and >, so a NaN
corner is skipped and a tie keeps the first value. The size is
max - min rounded up and saturated as obs_scene_size_from_extent does.

The three shims stay hidden. The scene still walks its items, still
shifts the children with update_item_transform, and resize_scene and
resize_group stay C. The C file moves to libobs.ported-scene-extent
with its own PCH. obs-scene gains no dependency.

Tier 1 scene::extent is 15/15.

Refs obs-rust#1919
The oracle is obs-scene-extent.c.h, unmodified, with its three
functions renamed and vec3_transform taken from the graphics oracle.
Each run starts the fold, adds every item and sizes it on both sides,
and compares min and max after every add bit for bit, then the scale
bit for bit and cx and cy.

The proptests cover lists of up to 8 matrices with finite, huge, NaN,
infinite, M_INFINITE, 2^32 and any-bit entries, box transforms as the
scene builds them, matrices of only 0, -0, 1 and -1 (so -0 and +0
corners tie), and the add and size shims from any state.

Breaking the core: f32::min/max for the compares, <= on the min, >=
on the max, an infinite start, three corners, y compared against x,
round for ceil, saturating one step early, a swapped scale and a
plain product for the C's dot each fail parity. Dropping the NaN check
in the size survives: Rust's `as u32` gives 0 for NaN, the same value.
Reverted. No intentional differences.

Refs obs-rust#1919
rust/README.md: the obs-scene layout row names
libobs/obs-scene-extent.c.h, and its row of the ported table gives the
swap, what stays in obs-scene.c.h, what C passes in, the compares the
fold keeps, the behavior kept from the characterization and what Tier 3
compares. No intentional differences. The naming.md row
(libobs/obs-scene*.c.h) already covers the file.

port_comparison: scene_extent/fold/{1,16}, shim against oracle, in
benches/port_comparison/scene.rs: start the fold, add 1 or 16 turned
boxes, size it. Pinned to one core, the medians are 10.3 ns (Rust)
against 71.7 ns (C) for one item, and 55.5 ns against 1.02 us for 16.
The C calls vec3_transform out of line for every corner, with its
transpose; the Rust core has the four dots inline. It runs once per
group or scene resize.

Fixes obs-rust#1919
@rdoupe
rdoupe force-pushed the port/scene-extent branch from 1bd329d to 4acaae6 Compare October 23, 2026 12:48
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into obs-rust:master with commit ed71dc3 Oct 23, 2026
33 checks passed
@zackees

zackees commented Oct 23, 2026

Copy link
Copy Markdown
Member

@rdoupe flaky test from this PR, now on master. scene::extent_parity::random_boxes_match_oracle failed on Windows in the merge group for #1929 (run 39984794419, job 120524185410):

panicked at proptest-1.11.0/src/num/float_samplers.rs:466:1:
assertion failed: self.low - result < self.intervals.step

This assertion is inside proptest's float range sampler, so it fires for some float range strategies (for example a range that is tiny or close to the f32/f64 limits), whatever the code under test does. A range strategy with sane bounds would avoid it. It ejected #1929 from the queue.

@rdoupe

rdoupe commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks — fix in #1952 (Fixes #1951): the huge-float arm of entry() now draws from the bit patterns instead of a Range<f32>, so proptest's float sampler assertion can't fire. Same value set.

MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…-rust#1997) (obs-rust#2554)

* test: require the port_comparison units to be discovered, not listed (obs-rust#1997)

RED: the ci test demanded the hand-kept `#[path] mod` lines and the
`modules![...]` call in `port_comparison.rs` stay sorted. It now fails if
either list exists and requires the two generated includes instead.

`uv run -m unittest discover -s ci -p test_sorted_shared_lists.py`:
test_port_comparison_units_are_discovered FAILs, assertNotRegex matched
`#[path = "port_comparison/audio.rs"]`.

* build: Generate the port_comparison unit list from the directory (obs-rust#1997)

GREEN: build.rs enumerates benches/port_comparison/*.rs and writes the
#[path] module lines and the run_units() call list into OUT_DIR, so a port
adds its own file and edits nothing shared. That was the last hand-kept
list every port appended to; two ports on one file collided in the merge
queue (obs-rust#1922 vs obs-rust#1928, obs-rust#1929 vs obs-rust#1922).

The file stem is the module name, so core.rs becomes core_units.rs (a
`mod core` at the crate root would make the units' `use core::ffi` paths
ambiguous). Absolute #[path] rather than `mod x { include!() }` because
the units open with //! inner docs, which include! cannot carry.

Verified: `soldr cargo check -p obs-c-oracle --benches` is clean, and a
throwaway zzz_probe.rs appeared in the generated run_units() and compiled
with no edit to a shared file. ci/test_sorted_shared_lists.py passes.
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.

rust: Port the group content extent in obs-scene.c to obs-scene

2 participants