Repository navigation
obs-scene: Port the scene transform update decisions (#2874) - #2882
Merged
Merged
Conversation
…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
enabled auto-merge
October 29, 2026 07:29
Member
Author
|
Handed off to the coordinator |
zackees
approved these changes
Oct 29, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
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.his the condition that becomesitem_needs_transform_update(): the originalos_atomic_load_bool(&item->update_transform) || source_size_changed(item) || scene_size_changedshort-circuited, soobs_source_get_width()/get_height()ran only when the flag was clear. The new helper hoists the atomic load, reads the size only underif (!update_transform)and passes0 x 0otherwise, andobs_scene_transform_update_item()ignores the size when the flag is set — same result, same number of source size reads, same order relative toupdate_item_transform().test_scene_transform_update_walkpinning theget_width/get_heightcounts 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_sizewrites back underif changed, matching the earlyreturn falsein the C).item_needs_update()keeps the per-dimension compares (source != lastonSizeis width-then-height, same as the C's two!=), andupdate_transformstill 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'sPORTED_ON_EVERY_HOST,rust-exports.map,rust-hidden.txt,rust-unexports-macos.txt, the oracle module,obs-sceneCargo description,rust/README.md(both the crate row and the port table), and both new cmocka targets intest-graph.json. Header stays non-EXPORTand hidden, likeobs-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, nodocs/features.mdline (a port is not user-visible).
Small notes, none blocking
test_scene_transform_update_walkskips whenobs_startup()finds no display. Thexvfb-runprefix intest-graph.jsonis 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
statofac8d0a237("docs: Record the scene transform update port") isrust/README.mdonly. That matches where the port table lives today, so nothing is missing — flagging it because the commit subject reads like it touchesdocs/. - 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.
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.
Port of the transform update decisions of
scene_video_render()andupdate_transforms_and_prune_sources()inlibobs/obs-scene.c.htorust/obs-scene(transform_update), next toitem_transform(#2385),group_transform(#1719) andrender_plan(#2003).Fixes #2874
Commits
libobs: Move the scene transform update decisions into obs-scene-transform-update.c(behaviour-neutral).test: Characterize the scene transform update decisions(test_scene_transform_update_steps,test_scene_transform_update_walk).obs-scene: Add Tier 1 tests for the scene transform update port(RED: 14 tests ontodo!()stubs).obs-scene: Port the scene transform update decisions(GREEN:obs-scene::transform_update, the shims, grouplibobs.ported-scene-transform-update,test_scene_transform_update_steps_rust).obs-scene: Check the scene transform update port against the C(oracle, Tier 3 parity,port_comparison).docs: Record the scene transform update port.Unit
Two functions on plain values, declared in
libobs/obs-scene-transform-update.hwithout 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 theupdate_transformflag, a source size that is not the size of the last transform (each dimension is compared), or a new scene size.obs-scene.ckeeps 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 theget_width/get_heightcallbacks 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
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, theuint32_tlimits, 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 underxvfb-run, astest_canvas_destroy_scene_refs) runs the walk through the real libobs withobs_scene_prune_sources(). It records theitem_transformsignals of the scene and the group's scene in order, and counts theget_width/get_heightcalls. 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 (onlyupdate_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 survivesobs_sceneitem_defer_update_end(), which computes the transform without clearing the flag, so the next walk computes it once more.u32sizes and flags against models written another way).test_scene_transform_update_steps_rust: the same C test source againstlibobs_rust-static.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.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
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 theLocal-GateandCi-Attestationtrailers for its exact tree.test_scene_transform_update_steps,_rust,_walkand 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 underxvfb-run, no skips).windows-ci-x64, MSVC): libobs and the tests build;test_scene_transform_update_steps9/9,test_scene_transform_update_steps_rust9/9,test_scene_item_transform_steps13/13 (against the hybridobs.dll);obs-tests-corescene::transform_updatewith MSVC (the oracle compiled by MSVC): 19/19. The walk test is Linux-only, astest_canvas_destroy_scene_refs.obs-tests-corescene::transform_update19/19.🤖 Generated with Claude Code