Skip to content

obs-scene: Port the scene transform update decisions (#2874) - #2882

Merged
vpacher merged 6 commits into
masterfrom
port/scene-transform-update
Oct 29, 2026
Merged

vpacher merged 6 commits into
masterfrom
port/scene-transform-update

Conversation

@vpacher

@vpacher vpacher commented Oct 29, 2026

Copy link
Copy Markdown
Member

Port of the transform update decisions of scene_video_render() and update_transforms_and_prune_sources() in libobs/obs-scene.c.h to rust/obs-scene (transform_update), next to item_transform (#2385), group_transform (#1719) and render_plan (#2003).

Fixes #2874

Commits

  1. libobs: Move the scene transform update decisions into obs-scene-transform-update.c (behaviour-neutral).
  2. test: Characterize the scene transform update decisions (test_scene_transform_update_steps, test_scene_transform_update_walk).
  3. obs-scene: Add Tier 1 tests for the scene transform update port (RED: 14 tests on todo!() stubs).
  4. obs-scene: Port the scene transform update decisions (GREEN: obs-scene::transform_update, the shims, group libobs.ported-scene-transform-update, test_scene_transform_update_steps_rust).
  5. obs-scene: Check the scene transform update port against the C (oracle, Tier 3 parity, port_comparison).
  6. docs: Record the scene transform update port.

Unit

Two functions on plain values, declared in libobs/obs-scene-transform-update.h without EXPORT (hidden):

  • obs_scene_transform_update_scene_size(&last_width, &last_height, width, height): scene_size_changed(). It returns whether the scene has a new size since its last render. It stores the size only on a change.
  • obs_scene_transform_update_item(update_transform, last_width, last_height, width, height, scene_size_changed): whether an item's transform is computed again on this walk. The reasons are the update_transform flag, a source size that is not the size of the last transform (each dimension is compared), or a new scene size.

obs-scene.c keeps the video locks, the item list walk, the recursion into a group's scene, the removed-source check and the removal, the group rebuild flag, update_item_transform(), resize_group() and every size read. It reads the source size only when the flag is clear, because the original || stopped at the flag. Thus the get_width/get_height callbacks of a source run as often as before. The walk test counts these calls.

Scope change from the issue: the group rebuild flag stays in C. It is three boolean assignments around C calls (the removal, update_item_transform(), resize_group()), with no decision of its own to move. The walk test pins it through the real libobs, and the Tier 3 walk model runs it with the shims and with the C.

No intentional differences.

Tests

  • Characterization:
    • test_scene_transform_update_steps (9 cases, ASan and UBSan; every platform) compiles the moved file into itself. It covers the scene size step (the same size, new width, height or both, swapped, back to 0 x 0, the uint32_t limits, a run of renders) and the item decision (each input alone, all 8 patterns, a set flag with the 0 x 0 the caller passes, 0 x 0 sizes, each dimension on its own).
    • test_scene_transform_update_walk (12 cases; Linux under xvfb-run, as test_canvas_destroy_scene_refs) runs the walk through the real libobs with obs_scene_prune_sources(). It records the item_transform signals of the scene and the group's scene in order, and counts the get_width/get_height calls. Cases: a new item (obs_scene_add() leaves its last size at 0 x 0, so the first walk computes it), idle, a set flag (only update_item_transform() reads the size), a new source size, a deferred item (asks on every walk), a removed item, and in a group: idle, a child update (child, then the resize: child again and group twice), the group's resize flag alone, a removed child, a deferred child (keeps the group resizing) and a removed group (its walk is skipped). Characterized, not endorsed: a flag set while an item is deferred survives obs_sceneitem_defer_update_end(), which computes the transform without clearing the flag, so the next walk computes it once more.
    • The walk test passes 12/12 on libobs and libobs-c-reference of this branch and on a libobs built from master before the move.
  • Tier 1: the 9 cases 1:1, and 5 edge cases (a 500-render run against a model that remembers the size before; proptests over any u32 sizes and flags against models written another way).
  • test_scene_transform_update_steps_rust: the same C test source against libobs_rust-static.
  • Tier 3: shim, C and core on every call. Exhaustive over both flags and every pair of 81 edge sizes; a walk model of update_transforms_and_prune_sources() (up to 16 items and 12 renders: removed and deferred items, flags, size changes, with and without a group) with the shims on one side and the C on the other; full-range proptests.
  • Deliberate-break check (by hand, 9 mutants): all 8 real mutants fail Tier 3 (2 or 3 tests each), the 6 core mutants also fail Tier 1 (3 to 5 tests each); the survivor is equivalent (the shim writes back an unchanged size). Table in commit 5.
  • port_comparison (scene_transform_update/frame/60x16: 60 frames of a 16-item scene, a new scene size at frame 30): macOS arm64 Rust 1.71 us, C 1.59 us. That is about 2 ns more per frame for 16 items: the C compiles both functions inline into one unit, the hybrid crosses the FFI for each call.

Verification

  • Local gate, stamped (build-rust, Debian 13, the pinned ci-lint local-gate run): lint 70 s, rust-test 221 s, cross 152 s, tier2-linux 276 s (both ctest modes against libobs and libobs-c-reference, IDENTICAL (1766 symbols); reused in the stamped run, same inputs); 7 min 24 s. The head carries the Local-Gate and Ci-Attestation trailers for its exact tree.
  • Linux x86_64 (Debian 13, GCC, hybrid + C reference build): libobs exports 1766 symbols in both, the two new functions are local in both; only libobs-c-reference builds the group object. test_scene_transform_update_steps, _rust, _walk and these real-libobs tests pass on both libraries: test_scene_item_transform_steps, test_scene_group_transform, test_group_child_drift, test_group_extent, test_group_recursion, test_group_teardown_uaf, test_scene_enum_items_removal, test_scene_list_remove, test_canvas_destroy_scene_refs (the display-needing ones checked under xvfb-run, no skips).
  • Windows 11 LTSC (VM, CI preset windows-ci-x64, MSVC): libobs and the tests build; test_scene_transform_update_steps 9/9, test_scene_transform_update_steps_rust 9/9, test_scene_item_transform_steps 13/13 (against the hybrid obs.dll); obs-tests-core scene::transform_update with MSVC (the oracle compiled by MSVC): 19/19. The walk test is Linux-only, as test_canvas_destroy_scene_refs.
  • macOS 26.7.1 arm64: obs-tests-core scene::transform_update 19/19.
  • Memory and time of the new Rust tests (macOS arm64, debug, 25 runs, one thread): peak RSS 18 MB, longest run 0.72 s. No generated value drives an allocation. The walk test takes 0.2 to 0.3 s.

🤖 Generated with Claude Code

vpacher and others added 6 commits October 29, 2026 08:05
…sform-update.c

Behaviour-neutral extraction before the Rust port (#2874). Two decisions
of scene_video_render() and update_transforms_and_prune_sources() in
obs-scene.c.h move to libobs/obs-scene-transform-update.c.h, as two
functions on plain values declared in the new
libobs/obs-scene-transform-update.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- obs_scene_transform_update_scene_size(last_width, last_height, width,
  height): scene_size_changed(), whether the scene has a new size since
  its last render, and the stored size, which changes only on a change;
- obs_scene_transform_update_item(update_transform, last_width,
  last_height, width, height, scene_size_changed): whether an item's
  transform is computed again on this walk, with source_size_changed()'s
  comparison.

obs-scene.c keeps the video locks, the item list walk, the recursion into
a group's scene, the removed-source check and the removal, the group
rebuild flag, update_item_transform(), resize_group() and every size
read. It reads the source size only when the update_transform flag is
clear, as the original || stopped at the flag, so a source's get_width
and get_height callbacks run as often as before.

Refs #2874

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two tests before the Rust port (#2874):

- test_scene_transform_update_steps builds the moved
  libobs/obs-scene-transform-update.c.h into itself and calls its two
  hidden functions: the scene size step (the same size, a new width, a
  new height, both, swapped, back to 0 x 0, the limits, and a run of
  renders: the size is stored only on a change) and the item decision
  (each input alone, all eight patterns, a set flag with the 0 x 0 the
  caller passes, 0 x 0 sizes, each dimension compared on its own).
- test_scene_transform_update_walk runs the walk through the real libobs
  with obs_scene_prune_sources(), which runs it without a render. It
  records the item_transform signals of the scene and of the group's
  scene in order, and counts the get_width and get_height calls of the
  sources: a new item's first walk (obs_scene_add() leaves its last size
  at 0 x 0), an idle item (the size read once), a set flag (the size
  read only by update_item_transform()), a new source size (read twice),
  a deferred item (asks on every walk, its size never stored), a flag
  set while deferred (it survives defer_update_end(), so the next walk
  computes the transform once more: characterized, not endorsed), a
  removed item, and in a group: idle, a child update (the child, then
  the resize: the child again and the group twice), the group's resize
  flag alone, a removed child, a deferred child (keeps the group
  resizing on every walk) and a removed group (its walk is skipped).

The walk test passes 12/12 on libobs and libobs-c-reference of this
branch and on a libobs built from master before the move, so the move
is behaviour-neutral for the walk. It needs obs_startup(), so it runs on
Linux under xvfb-run like test_canvas_destroy_scene_refs and skips
without a display.

Refs #2874

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RED for #2874. obs_scene::transform_update is declared with todo!()
stubs: Size, scene_size() (scene_size_changed(): whether the scene has a
new size since its last render, and the stored size) and
item_needs_update() (whether an item's transform is computed again on
this walk).

The steps_* cases port test_scene_transform_update_steps.c 1:1 (9
cases, same names, order, inputs and expectations). The edge_* cases
add a 500-render run against a model that remembers the size before,
and proptests over any u32 sizes and flags: the stored size is always
the new one, a second step is never a change, the item decision against
"nothing asks", and a set flag decides alone.

`soldr cargo test -p obs-data --test obs-tests-core
scene::transform_update`: 14 failed, each at the todo!() of its stub.

Refs #2874

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GREEN for #2874. Ports libobs/obs-scene-transform-update.c.h, the
transform update decisions of scene_video_render() and
update_transforms_and_prune_sources(), to the transform_update module
of rust/obs-scene. The hybrid libobs drops the C file and links the
Rust shims in its place.

Safe core (src/transform_update.rs):
- scene_size(): false when the size is the stored one; otherwise
  stores it and returns true;
- item_needs_update(): update_transform, or a source size that is not
  the last one (each dimension), or a new scene size.
It keeps no state, takes no lock, allocates nothing and denies clippy's
arithmetic, indexing, as-conversion, unwrap, expect, panic and
unreachable lints.

Shim (src/ffi/scene_transform_update.rs): the two functions with the C
signatures. The scene's stored size crosses as two uint32_t pointers
and is written only on a change, as the C does; everything else crosses
by value. No struct is mirrored and nothing calls into libobs.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-scene-transform-update, whose PCH has only the file's own
header; libobs.pch.h keeps the header for obs-scene.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.
ci/test_ported_sources.py checks the group on every host.

test_scene_transform_update_steps still compiles the C file into
itself, unchanged. The new test_scene_transform_update_steps_rust builds
the same test source against libobs_rust-static. The real-libobs walk
test sees the swap through the hybrid.

Tier 1 scene::transform_update passes 14/14.

Refs #2874

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Oracle (oracle/scene_transform_update.c): the original
obs-scene-transform-update.c.h, unmodified, with its two functions
renamed to oracle_*. Everything crosses as uint32_t and bool, so there
is no layout to check.

Tier 3 (tests/scene/transform_update_parity.rs, 5 tests); every call
runs the shim, the C and the safe core and compares the result and the
stored size:
- exhaustive: the scene size step over every pair of 81 sizes (0, 1, 2,
  common sizes and the u32 ends in each dimension), and the item
  decision over both flags and every pair of those sizes (26,244 calls);
- a walk model: update_transforms_and_prune_sources()'s per-item steps
  over up to 16 items and 12 renders (removed and deferred items, flags,
  new source sizes between renders, with and without a group and its
  resize flag), the shims on one side and the C on the other with the
  same glue (the removed check first, the size read only when the flag
  is clear, the size stored and the flag cleared unless deferred); the
  scene size answers, the per-item steps and the group rebuild match on
  every render (500 cases);
- proptests over the full u32 ranges (4,000 cases each).

port_comparison gets benches/port_comparison/scene_transform_update.rs:
60 frames of a 16-item scene (a new scene size at frame 30, one item in
five with its flag set, one in seven with a new source size), folded
into a checksum both sides must match (checked before timing). It
allocates nothing.

Tier 1 and Tier 3 pass (14/14 and 5/5) in 0.42 s; over 25 runs the
peak RSS of the test process is 18 MB and the longest run 0.72 s.

Mutation check (done once, not committed); failures per mutant:

| Mutant | Tier 1 | Tier 3 |
|---|---|---|
| scene_size: width compared only | 4 | 2 |
| scene_size: never stores | 5 | 3 |
| scene_size: always a change | 5 | 3 |
| item: scene size change ignored | 3 | 3 |
| item: flag ignored | 5 | 3 |
| item: height compared only | 5 | 2 |
| shim: item width and height swapped | 0 | 3 |
| shim: stored width and height swapped | 0 | 3 |
| equivalent: shim writes back an unchanged size | 0 | 0 |

All eight are killed; the shim mutants only by Tier 3, which is the
tier that reaches the shims (as test_scene_transform_update_steps_rust
does). The survivor is equivalent: an unchanged size written back is
the same size. The proptest regression files keep the seeds the mutants
failed on.

Refs #2874

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rust/README.md crate table now lists
libobs/obs-scene-transform-update.c.h among the rust/obs-scene units,
and its port table has a row for it, after the item transform: the two
decisions, what stays C (the locks, the walk, the removal, the group
rebuild flag, update_item_transform(), resize_group() and every size
read, the source size read only when the flag is clear), how values
cross, the one characterized-not-endorsed case (a flag set while
deferred survives defer_update_end()), the steps test and its _rust
variant, the real-libobs walk test and the group tests that see the
swap, 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-scene*.c.h to rust/obs-scene. No docs/features.md line: no
user-visible change.

Fixes #2874

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7 secs=444 lanes=lint:run,rust-test:run,cross:run,tier2-linux:reused@f8c5f00527db,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793258720,"gate":"rust/all/fmt","host":"linux-x86_64","key":"cd650bca923d465bb2939c41a0439ce216680ab7ab10ff498c072ec4a5c5c2fd","lane":"lint","parents":["ecde555c55fc746c87e8cf0cdf047cdea6eb9237"],"secs":70,"stamp":"296d2d5379cacc0c210c250199849b2b","tree":"2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7","v":1,"via":"run"}
Ci-Attestation: {"at":1793258720,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"cd650bca923d465bb2939c41a0439ce216680ab7ab10ff498c072ec4a5c5c2fd","lane":"lint","parents":["ecde555c55fc746c87e8cf0cdf047cdea6eb9237"],"secs":70,"stamp":"ab5fd90456dc6ddb1e4a4767128362cd","tree":"2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7","v":1,"via":"run"}
Ci-Attestation: {"at":1793258720,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"0c50a30d4ebf524410f5d79fef04f8bc9002c8e8d4436475fa42c0d585fc2263","lane":"rust-test","parents":["ecde555c55fc746c87e8cf0cdf047cdea6eb9237"],"secs":221,"stamp":"14137798701ed11d922548bca6fc6098","tree":"2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7","v":1,"via":"run"}
Ci-Attestation: {"at":1793258720,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"ee35241ff8b4605c87a2338288b18e91465c972a505d7d4cfe8edf60955622a7","lane":"cross","parents":["ecde555c55fc746c87e8cf0cdf047cdea6eb9237"],"secs":152,"stamp":"e1429534b8a7c0e462c8c20032b995ed","tree":"2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7","v":1,"via":"run"}
Ci-Attestation: {"at":1793258720,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"ee35241ff8b4605c87a2338288b18e91465c972a505d7d4cfe8edf60955622a7","lane":"cross","parents":["ecde555c55fc746c87e8cf0cdf047cdea6eb9237"],"secs":152,"stamp":"10e36c4b1828bfdca86b66aa56c00934","tree":"2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7","v":1,"via":"run"}
Ci-Attestation: {"at":1793258720,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"ee35241ff8b4605c87a2338288b18e91465c972a505d7d4cfe8edf60955622a7","lane":"cross","parents":["ecde555c55fc746c87e8cf0cdf047cdea6eb9237"],"secs":152,"stamp":"daa7ecdcdb58052cbfd26292aeb282c0","tree":"2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7","v":1,"via":"run"}
Ci-Attestation: {"at":1793258720,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"ee35241ff8b4605c87a2338288b18e91465c972a505d7d4cfe8edf60955622a7","lane":"cross","parents":["ecde555c55fc746c87e8cf0cdf047cdea6eb9237"],"secs":152,"stamp":"9d4897dc74af46ff6ce7ac6d45ddb30f","tree":"2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7","v":1,"via":"run"}
Ci-Attestation: {"at":1793258183,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"f8c5f00527db66d55ca9adcd0708f09b124aad7bd4b3f12487013f64bcc50d4a","lane":"tier2-linux","parents":["ecde555c55fc746c87e8cf0cdf047cdea6eb9237"],"secs":null,"stamp":"bd40102ae2e92e626ef6da9b5ef1787e","tree":"2e21f5a4655a8e0ce14d1bfa2021fe233d3734b7","v":1,"via":"reused"}
@vpacher
vpacher requested a review from zackees as a code owner October 29, 2026 07:28
@vpacher
vpacher enabled auto-merge October 29, 2026 07:29
@vpacher

vpacher commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Handed off to the coordinator

@vpacher
vpacher added this pull request to the merge queue Oct 29, 2026
Merged via the queue into master with commit 7a1c513 Oct 29, 2026
34 checks passed
@vpacher
vpacher deleted the port/scene-transform-update branch October 29, 2026 07:53

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review.

Verdict: correct and faithful; the port is 69 lines of Rust and the rest is the coverage that proves it, which is the right shape. Approving on the code; the merge queue still decides on green checks (no workflow run had started at review time).

What I verified

  • The "behaviour-neutral" move really is neutral. The only behaviour-sensitive line in obs-scene.c.h is the condition that becomes item_needs_transform_update(): the original os_atomic_load_bool(&item->update_transform) || source_size_changed(item) || scene_size_changed short-circuited, so obs_source_get_width()/get_height() ran only when the flag was clear. The new helper hoists the atomic load, reads the size only under if (!update_transform) and passes 0 x 0 otherwise, and obs_scene_transform_update_item() ignores the size when the flag is set — same result, same number of source size reads, same order relative to update_item_transform(). test_scene_transform_update_walk pinning the get_width/get_height counts through the real libobs is exactly the check that would catch a regression here, and the steps test would not have.
  • scene_size_changed() is carried over exactly, including that the stored size is written only on a change (obs_scene_transform_update_scene_size writes back under if changed, matching the early return false in the C).
  • item_needs_update() keeps the per-dimension compares (source != last on Size is width-then-height, same as the C's two !=), and update_transform still decides alone.
  • Registration is complete and consistent with the other scene ports: source-sets.json (header + libobs.ported-scene-transform-update+.h.c), the pch, ci/test_ported_sources.py's PORTED_ON_EVERY_HOST, rust-exports.map, rust-hidden.txt, rust-unexports-macos.txt, the oracle module, obs-scene Cargo description, rust/README.md (both the crate row and the port table), and both new cmocka targets in test-graph.json. Header stays non-EXPORT and hidden, like obs-scene-item-transform.h.
  • Commit shape is right: move → characterize → Tier 1 RED on todo!() stubs → GREEN → Tier 3 parity/oracle → docs. No public header, no edit to an existing C test, no docs/features.md line (a port is not user-visible).

Small notes, none blocking

  • test_scene_transform_update_walk skips when obs_startup() finds no display. The xvfb-run prefix in test-graph.json is the same pattern 38 other tests use, so this is fine — just worth knowing that on a runner without xvfb the walk test reports skip, not pass, and the steps/parity tests are what is actually being enforced there.
  • The stat of ac8d0a237 ("docs: Record the scene transform update port") is rust/README.md only. That matches where the port table lives today, so nothing is missing — flagging it because the commit subject reads like it touches docs/.
  • Tier 3's walk model deliberately re-implements the caller's glue (removed check, rebuild flag, size read under the flag); that glue is what the cmocka walk test covers on the real libobs. Two implementations of the same glue is fine, but a comment on the parity side saying the C walk test is the authority for the glue would save the next reader the review you and I just did.

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 scene transform update decisions in obs-scene.c to obs-scene

2 participants