From d16f10804a9cf2fd73691c4823bad517f68c37f3 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 08:54:01 -0800 Subject: [PATCH 1/2] test(obs-scene): require transform deferral against Rust stubs (Refs #5260) --- rust/obs-scene/src/item_defer_update.rs | 18 +++ rust/obs-scene/src/lib.rs | 1 + .../tests/scene/item_defer_update.rs | 131 ++++++++++++++++++ rust/obs-scene/tests/scene/main.rs | 1 + 4 files changed, 151 insertions(+) create mode 100644 rust/obs-scene/src/item_defer_update.rs create mode 100644 rust/obs-scene/tests/scene/item_defer_update.rs diff --git a/rust/obs-scene/src/item_defer_update.rs b/rust/obs-scene/src/item_defer_update.rs new file mode 100644 index 0000000000..b672c6f66e --- /dev/null +++ b/rust/obs-scene/src/item_defer_update.rs @@ -0,0 +1,18 @@ +//! Transform deferral over a C-owned atomic counter. The transform adapter +//! retains ordinary, group-child and parentless dispatch behavior. + +/// Native operations on a live item, without borrowing its private layout. +pub trait TransformDeferral { + fn increment(&self); + /// Return this atomic decrement's result, never a later load. + fn decrement(&self) -> isize; + fn update_transform(&self); +} + +pub fn begin(_item: &impl TransformDeferral) { + todo!("port obs_sceneitem_defer_update_begin"); +} + +pub fn end(_item: &impl TransformDeferral) { + todo!("port obs_sceneitem_defer_update_end"); +} diff --git a/rust/obs-scene/src/lib.rs b/rust/obs-scene/src/lib.rs index 7e7ec6ebbf..0219a34085 100644 --- a/rust/obs-scene/src/lib.rs +++ b/rust/obs-scene/src/lib.rs @@ -58,6 +58,7 @@ pub mod group_queries; pub mod group_resize_defer; pub mod group_transform; pub mod item_audio_actions; +pub mod item_defer_update; pub mod item_id; pub mod item_names; pub mod item_order; diff --git a/rust/obs-scene/tests/scene/item_defer_update.rs b/rust/obs-scene/tests/scene/item_defer_update.rs new file mode 100644 index 0000000000..e749add05c --- /dev/null +++ b/rust/obs-scene/tests/scene/item_defer_update.rs @@ -0,0 +1,131 @@ +//! Tier 1 mirrors test_scene_item_defer_update.c. The downstream transform +//! adapter is modeled as in item_bounds_setters; actual dispatch stays Tier 2. +use obs_scene::item_defer_update::{self as defer, TransformDeferral}; +use std::cell::{Cell, RefCell}; + +#[derive(Clone, Copy, Default)] +enum Parent { + #[default] + Scene, + Group, + None, +} + +#[derive(Default)] +struct Item { + count: Cell, + parent: Parent, + pending: Cell, + transforms: Cell, + calls: RefCell>, +} + +impl TransformDeferral for Item { + fn increment(&self) { + self.calls.borrow_mut().push("increment"); + self.count.set(self.count.get() + 1); + } + fn decrement(&self) -> isize { + self.calls.borrow_mut().push("decrement"); + let count = self.count.get() - 1; + self.count.set(count); + count + } + fn update_transform(&self) { + self.calls.borrow_mut().push("update"); + assert_eq!(self.count.get(), 0, "decrement must finish before dispatch"); + match self.parent { + Parent::Scene => self.transforms.set(self.transforms.get() + 1), + Parent::Group | Parent::None => self.pending.set(true), + } + } +} + +#[test] +fn plain_pair_computes_on_end() { + let item = Item::default(); + for expected in 1..=3 { + defer::begin(&item); + assert_eq!(item.count.get(), 1); + assert_eq!(item.transforms.get(), expected - 1); + defer::end(&item); + assert_eq!(item.count.get(), 0); + assert_eq!(item.transforms.get(), expected); + } + assert_eq!(*item.calls.borrow(), ["increment", "decrement", "update"].repeat(3)); +} + +#[test] +fn nested_pairs_compute_on_outer_end() { + let item = Item::default(); + for _ in 0..3 { + defer::begin(&item); + } + for expected in [2, 1] { + defer::end(&item); + assert_eq!(item.count.get(), expected); + assert_eq!(item.transforms.get(), 0); + } + defer::end(&item); + assert_eq!(item.transforms.get(), 1); +} + +#[test] +fn unmatched_end_goes_negative_and_begin_reaching_zero_is_quiet() { + let item = Item::default(); + for expected in [-1, -2] { + defer::end(&item); + assert_eq!(item.count.get(), expected); + assert_eq!(item.transforms.get(), 0); + } + for expected in [-1, 0] { + defer::begin(&item); + assert_eq!(item.count.get(), expected); + assert_eq!(item.transforms.get(), 0); + } + defer::begin(&item); + defer::end(&item); + assert_eq!(item.transforms.get(), 1); +} + +#[test] +fn group_child_end_sets_flag_and_parentless_end_reads_nothing() { + for parent in [Parent::Group, Parent::None] { + let item = Item { parent, ..Item::default() }; + defer::begin(&item); + defer::begin(&item); + defer::end(&item); + assert!(!item.pending.get()); + defer::end(&item); + assert!(item.pending.get()); + assert_eq!(item.transforms.get(), 0); + assert_eq!(*item.calls.borrow(), ["increment", "increment", "decrement", "decrement", "update"]); + } +} + +#[test] +fn group_item_end_computes_like_an_ordinary_item() { + let item = Item::default(); + defer::begin(&item); + assert_eq!(item.transforms.get(), 0); + defer::end(&item); + assert_eq!(item.transforms.get(), 1); +} + +#[test] +fn dispatch_uses_the_decrement_result_without_reloading() { + struct RacingItem(Cell, Cell); + impl TransformDeferral for RacingItem { + fn increment(&self) { self.0.set(self.0.get() + 1); } + fn decrement(&self) -> isize { + let result = self.0.get() - 1; + self.0.set(77); // another caller can increment after this RMW + result + } + fn update_transform(&self) { self.1.set(true); } + } + let item = RacingItem(Cell::new(1), Cell::new(false)); + defer::end(&item); + assert!(item.1.get()); + assert_eq!(item.0.get(), 77); +} diff --git a/rust/obs-scene/tests/scene/main.rs b/rust/obs-scene/tests/scene/main.rs index 12e4ed3f6b..e8fb6a2a6c 100644 --- a/rust/obs-scene/tests/scene/main.rs +++ b/rust/obs-scene/tests/scene/main.rs @@ -23,6 +23,7 @@ mod group_enum; mod group_enum_parity; mod item_audio_actions; mod item_audio_actions_parity; +mod item_defer_update; mod item_id; mod item_id_parity; mod item_names; From 65de4f86f22019f499b5c4b8106eb1e6281ba555 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 09:03:34 -0800 Subject: [PATCH 2/2] obs-scene: swap scene-item transform deferral to Rust (Refs #5260) Ci-Attestation: {"at":1795113605,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":212,"stamp":"2b433e7dd4cc34ed9439905c046264b6","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113605,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":212,"stamp":"d19346949e26d69dda9a4e8c6fe6227b","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113605,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":212,"stamp":"1b2b6a23a32a6004d53db7b104399612","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113605,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":212,"stamp":"51fbb07318bcb9f8e62b5f7b52b1d01e","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113390,"gate":"general/all/client-lint","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"4a2eeab247f1fb29e6eae8f231f866ee","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113605,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":212,"stamp":"d198ba89a50a2d7fe1a03e16647443d9","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"f952a22e2cc316e54ad93e923b87926a","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"8743b364f0d9d2e8b77bad9a195e0ebe","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"c75c1f9d8313d35245f22ec2573ac2e9","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"c485291fea5be4b827dbf4b6670c3296","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"59894b874d3afc7c56a23262b877031a","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"4f57fcbf3e4cecb370c5803879ec2c2d","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"4a15b553f5207f31c17fe488b8173631","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"9bc330ad53ee47901bfc769831bfb3f6","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"0049058e5a8d28401177afeb6cce1e9e","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"c5d2be19ead294e1e51a0fc13fb78155","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"47458ec9ad2238dce4061450f3a091b2","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795113391,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"b57b745606f7cea1edd2c0e1ea439c98543934456b7b3a73ec9562eeb3ab90b7","lane":"client-lint","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":425,"stamp":"73aa60217b0b3e259c60694034336a76","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Ci-Attestation: {"at":1795114813,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"ed78f7e05ab3f0bdcebc2ec111c1016cdf34fb989d62574cb87ba4c0c0875868","lane":"client-test-x86_64-unknown-linux-gnu","parents":["d16f10804a9cf2fd73691c4823bad517f68c37f3"],"secs":1206,"stamp":"420fcaeaf222f6a78272cd6a3901afd9","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9","v":1,"via":"run"} Client-Checks: {"checks":{"base":"fa4ceee9dcbee20ca561ab7d083199953113eeea","coverage":"all-tracked-applicable-files","diff":["ci/test_bench_libobs_stand_ins.py","ci/test_tier2_runtime_delta.py","docs/ci-tooling.md","libobs/build/libobs.core-output+.h.c","libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-encoder-get-name+.h.c","libobs/build/libobs.ported-sceneitem-defer-update+.h.c","libobs/build/ported-source-sets/encoder-get-name.json","libobs/build/ported-source-sets/sceneitem-defer-update.json","libobs/cmake/rust-exports.d/obs-encoder-get_name.txt","libobs/cmake/rust-exports.d/obs-scene-item_defer_update.txt","libobs/obs-encoder-get-name-fields.c.h","libobs/obs-output-interleave-name-fields.c.h","libobs/obs-sceneitem-defer-update-fields.c.h","rust/README.md","rust/obs-build/tests/native/registration/canonical_video_info_query_is_registered.rs","rust/obs-c-oracle/benches/port_comparison.rs","rust/obs-c-oracle/oracle.d/encoder-get-name.list","rust/obs-c-oracle/oracle.d/sceneitem-defer-update.list","rust/obs-c-oracle/oracle/encoder_get_name.c","rust/obs-c-oracle/oracle/output_interleave.c","rust/obs-c-oracle/oracle/scene_item_bounds_setters.c","rust/obs-c-oracle/oracle/scene_transform_states_links.c","rust/obs-c-oracle/oracle/sceneitem_defer_update.c","rust/obs-encoder/src/ffi/get_name.rs","rust/obs-encoder/src/ffi/mod.rs","rust/obs-encoder/src/get_name.rs","rust/obs-encoder/src/lib.rs","rust/obs-encoder/tests/encoder/get_name.rs","rust/obs-encoder/tests/encoder/get_name_parity.rs","rust/obs-encoder/tests/encoder/main.rs","rust/obs-output/src/ffi/output_interleave.rs","rust/obs-output/tests/output/interleave_parity.rs","rust/obs-scene/src/ffi/item_defer_update.rs","rust/obs-scene/src/ffi/mod.rs","rust/obs-scene/src/item_defer_update.rs","rust/obs-scene/src/lib.rs","rust/obs-scene/tests/scene/item_defer_update.rs","rust/obs-scene/tests/scene/item_defer_update_parity.rs","rust/obs-scene/tests/scene/main.rs","rust/tools/linux-validate/ci-runtime.py","test/cmocka/encoder-get-name-link-support.c","test/cmocka/output-interleave-name-link-support.c","test/cmocka/sceneitem-defer-update-link-support.c","test/cmocka/tests.d/video_info_query_link_support.cmake"],"head":"9c9de72fb187b579158a779538e910411a950116","tools":{"orchestrator-python":"3.14.7 (main, Aug 14 2026, 15:35:28) [Clang 22.1.3 ]","schema-dependencies":"3.14.7 (main, Aug 14 2026, 15:35:28) [Clang 22.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ISO8859X Regexps Automata RelaxNG Schemas Modules Debug"},"tracked-digest":"3e11debca84b2a631cde016942c1a07fd70577865211ac13335a2e4b6daaffc0","tree":"bc670f680f5cad35a8ef4f965c3cf1e7357c84e9"}} --- libobs/build/libobs.core-source+.h.c | 2 +- .../libobs.ported-sceneitem-defer-update+.h.c | 5 ++ .../sceneitem-defer-update.json | 5 ++ .../obs-scene-item_defer_update.txt | 2 + libobs/obs-sceneitem-defer-update-fields.c.h | 16 ++++ rust/README.md | 1 + .../oracle.d/sceneitem-defer-update.list | 1 + .../oracle/scene_item_bounds_setters.c | 49 +++++++++++ .../oracle/scene_transform_states_links.c | 13 +-- .../oracle/sceneitem_defer_update.c | 66 +++++++++++++++ rust/obs-scene/src/ffi/item_defer_update.rs | 62 ++++++++++++++ rust/obs-scene/src/ffi/mod.rs | 1 + rust/obs-scene/src/item_defer_update.rs | 10 ++- .../tests/scene/item_defer_update.rs | 23 +++-- .../tests/scene/item_defer_update_parity.rs | 83 +++++++++++++++++++ rust/obs-scene/tests/scene/main.rs | 1 + .../sceneitem-defer-update-link-support.c | 2 + .../video_info_query_link_support.cmake | 1 + 18 files changed, 321 insertions(+), 22 deletions(-) create mode 100644 libobs/build/libobs.ported-sceneitem-defer-update+.h.c create mode 100644 libobs/build/ported-source-sets/sceneitem-defer-update.json create mode 100644 libobs/cmake/rust-exports.d/obs-scene-item_defer_update.txt create mode 100644 libobs/obs-sceneitem-defer-update-fields.c.h create mode 100644 rust/obs-c-oracle/oracle.d/sceneitem-defer-update.list create mode 100644 rust/obs-c-oracle/oracle/sceneitem_defer_update.c create mode 100644 rust/obs-scene/src/ffi/item_defer_update.rs create mode 100644 rust/obs-scene/tests/scene/item_defer_update_parity.rs create mode 100644 test/cmocka/sceneitem-defer-update-link-support.c diff --git a/libobs/build/libobs.core-source+.h.c b/libobs/build/libobs.core-source+.h.c index 8e0f07a5e9..f6ef16ea81 100644 --- a/libobs/build/libobs.core-source+.h.c +++ b/libobs/build/libobs.core-source+.h.c @@ -44,7 +44,7 @@ #include "libobs/obs-scene-ref-fields.c.h" #include "libobs/obs-scene-source-fields.c.h" #include "libobs/obs-scene.c.h" -#include "libobs/obs-sceneitem-defer-update.c.h" +#include "libobs/obs-sceneitem-defer-update-fields.c.h" #include "libobs/obs-shader-param-introspection-fields.c.h" #include "libobs/obs-source-async-compensation-fields.c.h" #include "libobs/obs-source-async-decoupled-fields.c.h" diff --git a/libobs/build/libobs.ported-sceneitem-defer-update+.h.c b/libobs/build/libobs.ported-sceneitem-defer-update+.h.c new file mode 100644 index 0000000000..585de676ce --- /dev/null +++ b/libobs/build/libobs.ported-sceneitem-defer-update+.h.c @@ -0,0 +1,5 @@ +/* Unity group (BUILD.md): C reference for scene-item transform deferral. */ + +#include "libobs/build/libobs.pch.h" + +#include "libobs/obs-sceneitem-defer-update.c.h" diff --git a/libobs/build/ported-source-sets/sceneitem-defer-update.json b/libobs/build/ported-source-sets/sceneitem-defer-update.json new file mode 100644 index 0000000000..92ee4e9497 --- /dev/null +++ b/libobs/build/ported-source-sets/sceneitem-defer-update.json @@ -0,0 +1,5 @@ +{ + "LIBOBS_PORTED_SOURCES": [ + "build/libobs.ported-sceneitem-defer-update+.h.c" + ] +} diff --git a/libobs/cmake/rust-exports.d/obs-scene-item_defer_update.txt b/libobs/cmake/rust-exports.d/obs-scene-item_defer_update.txt new file mode 100644 index 0000000000..c20000ae0e --- /dev/null +++ b/libobs/cmake/rust-exports.d/obs-scene-item_defer_update.txt @@ -0,0 +1,2 @@ +obs_sceneitem_defer_update_begin +obs_sceneitem_defer_update_end diff --git a/libobs/obs-sceneitem-defer-update-fields.c.h b/libobs/obs-sceneitem-defer-update-fields.c.h new file mode 100644 index 0000000000..664af13a4c --- /dev/null +++ b/libobs/obs-sceneitem-defer-update-fields.c.h @@ -0,0 +1,16 @@ +#include "libobs/build/libobs.pch.h" + +/* C owns the counter layout and the platform's atomic long implementation. + * Return the RMW result: a separate load could observe another caller. */ +long obs_sceneitem_defer_update_increment(obs_sceneitem_t *item); +long obs_sceneitem_defer_update_decrement(obs_sceneitem_t *item); + +long obs_sceneitem_defer_update_increment(obs_sceneitem_t *item) +{ + return os_atomic_inc_long(&item->defer_update); +} + +long obs_sceneitem_defer_update_decrement(obs_sceneitem_t *item) +{ + return os_atomic_dec_long(&item->defer_update); +} diff --git a/rust/README.md b/rust/README.md index 5467e67628..68a551627e 100644 --- a/rust/README.md +++ b/rust/README.md @@ -388,6 +388,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions | `libobs/obs-scene-item-crop-fields.c.h` | `obs-scene::item_crop_getter` | The crop getter preserves item-before-output debug diagnostics, all four signed integers and the captured parent video mutex. Complete output/state byte parity, real-header layout, integer extremes, recursive ownership and concurrent publication are covered. No intentional differences. | | `libobs/obs-scene-item-crop-setter.c.h` | `obs-scene::item_crop_setter` | Swapped in hybrid `libobs` (group `libobs.ported-scene-item-crop-setter`). Public `obs_sceneitem_set_crop` reuses the crop getter's layout-checked item prefix and the existing item fields lock, so it needs no new C adapter. It clamps the input before the lock, compares the raw input (not the clamped crop) with the stored one under the lock, stores the clamped crop and sets `update_transform` after the unlock; a negative input therefore stores and marks every time (characterized, not endorsed). Null item and crop keep their debug diagnostics, item first. The unchanged C characterization runs against hybrid and C reference; Tier 3 compares whole-item bytes, the lock release and lock waiting against the verbatim C with the original clamp. No intentional differences. | | `libobs/obs-scene-item-group-resize-defer.c.h` | `obs-scene::group_resize_defer` | Atomic begin/end preserve nesting and unmatched-end underflow. Only an end whose decrement returns zero schedules a resize; neither entry point takes the scene mutex, emits signals or runs transforms. The existing update walk consumes the flag later. Native C field operations retain platform long widths and atomic ordering; no item layout is mirrored. NULL diagnostics and bounded operation sequences compare every real-header item byte against the unchanged C reference. | +| `libobs/obs-sceneitem-defer-update.c.h` | `obs-scene::item_defer_update` | Atomic begin/end retain the C-owned long counter and native ordering. Only an end whose decrement returns zero calls the existing bounds-transform adapter; begin reaching zero and negative counts remain quiet. Exact NULL diagnostics are preserved. Unchanged actual-library Tier 2 and per-operation C differential traces cover the swap. No intentional differences. | | `libobs/obs-scene-item-id.c.h` | `obs-scene::item_id` | Scene item ID getter: exact signed 64-bit C parity, including zero and the original debug diagnostic for null. Leaves every item byte unchanged, with no intended behavior differences. Real-header prefix layout, differential ID/state and unchanged actual-library characterization coverage. | | `libobs/obs-scene-item-scale-fields.c.h` | `obs-scene::item_scale_getter` | Synchronized vec2 scale getter preserves NULL output storage and exact stored float bits. Relative coordinates retain the existing C canvas conversion under the captured parent video mutex, with no Rust lock. Actual-library C characterization, real-header layout, callback-only differential/mutation and concurrent publication tests cover the seam. No intended differences. | | `libobs/obs-scene-item-scale-filter-setter.c.h` | `obs-scene::item_scale_filter` | Swapped in hybrid `libobs`. Preserves NULL pointer diagnostics, every stored enum bit and sequentially consistent atomic transform invalidation, including repeated filters. Reuses the render-prefix real-header layout test; complete-item differential parity covers enum edges, random values and NULL. Existing `test_scene_rotated_scale_filter` remains unchanged. No intended differences. | diff --git a/rust/obs-c-oracle/oracle.d/sceneitem-defer-update.list b/rust/obs-c-oracle/oracle.d/sceneitem-defer-update.list new file mode 100644 index 0000000000..2df4c4da2f --- /dev/null +++ b/rust/obs-c-oracle/oracle.d/sceneitem-defer-update.list @@ -0,0 +1 @@ +sceneitem-defer-update.inc|libobs/obs-sceneitem-defer-update.c.h|auto diff --git a/rust/obs-c-oracle/oracle/scene_item_bounds_setters.c b/rust/obs-c-oracle/oracle/scene_item_bounds_setters.c index 720a0d06a2..ffe29d554f 100644 --- a/rust/obs-c-oracle/oracle/scene_item_bounds_setters.c +++ b/rust/obs-c-oracle/oracle/scene_item_bounds_setters.c @@ -418,3 +418,52 @@ unsigned oracle_scene_bounds_alignment_probe(alignment_setter original, alignmen abort(); return result; } + +/* Deferral calls the same transform adapter. Reuse its recorder so the + * amalgamated category has one definition and one native fixture layout. + * Every operation compares the whole item and callback trace, while the + * caller owns a nonrecursive mutex (begin/end must not acquire it). */ +typedef void (*defer_operation)(obs_sceneitem_t *); +unsigned oracle_scene_bounds_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count, + defer_operation c_begin, defer_operation c_end, defer_operation begin, + defer_operation end); + +unsigned oracle_scene_bounds_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count, + defer_operation c_begin, defer_operation c_end, defer_operation begin, + defer_operation end) +{ + struct obs_scene scene = {0}; + if (pthread_mutex_init(&scene.video_mutex, NULL)) + abort(); + scene.is_group = (flags & 2) != 0; + struct obs_scene *parent = (flags & 1) ? &scene : NULL; + struct bounds_item expected, actual; + bounds_item_init(&expected, parent, 0); + expected.item.align = 37; + os_atomic_store_long(&expected.item.defer_update, initial); + os_atomic_store_bool(&expected.item.update_transform, (flags & 4) != 0); + memcpy(&actual, &expected, sizeof(actual)); + pthread_mutex_lock(&scene.video_mutex); + unsigned result = 0; + for (size_t i = 0; i < count; i++) { + expected.count = actual.count = 0; + memset(expected.events, 0, sizeof(expected.events)); + memset(actual.events, 0, sizeof(actual.events)); + if (ops[i]) { + c_begin(&expected.item); + begin(&actual.item); + } else { + c_end(&expected.item); + end(&actual.item); + } + if (memcmp(&expected.item, &actual.item, sizeof(expected.item)) || expected.count != actual.count || + memcmp(expected.events, actual.events, sizeof(expected.events))) { + result = (unsigned)i + 1; + break; + } + } + pthread_mutex_unlock(&scene.video_mutex); + if (pthread_mutex_destroy(&scene.video_mutex)) + abort(); + return result; +} diff --git a/rust/obs-c-oracle/oracle/scene_transform_states_links.c b/rust/obs-c-oracle/oracle/scene_transform_states_links.c index df82c5b39a..247f0c8d13 100644 --- a/rust/obs-c-oracle/oracle/scene_transform_states_links.c +++ b/rust/obs-c-oracle/oracle/scene_transform_states_links.c @@ -1,6 +1,5 @@ /* Test-only link stand-ins: obs_get_source_by_uuid(), - * obs_sceneitem_set_info2(), - * obs_sceneitem_defer_update_begin() and obs_sceneitem_defer_update_end() + * obs_sceneitem_set_info2() * under libobs's own names, for the test * binaries that link the obs-scene shims without libobs. * obs_sceneitem_get_info2() is the obs-scene shim itself now @@ -30,13 +29,3 @@ void obs_sceneitem_set_info2(obs_sceneitem_t *item, const struct obs_transform_i UNUSED_PARAMETER(item); UNUSED_PARAMETER(info); } - -void obs_sceneitem_defer_update_begin(obs_sceneitem_t *item) -{ - UNUSED_PARAMETER(item); -} - -void obs_sceneitem_defer_update_end(obs_sceneitem_t *item) -{ - UNUSED_PARAMETER(item); -} diff --git a/rust/obs-c-oracle/oracle/sceneitem_defer_update.c b/rust/obs-c-oracle/oracle/sceneitem_defer_update.c new file mode 100644 index 0000000000..1a5c2eef52 --- /dev/null +++ b/rust/obs-c-oracle/oracle/sceneitem_defer_update.c @@ -0,0 +1,66 @@ +/* Original extracted C and the real production atomic adapters. The bounds + * oracle owns the shared transform recorder and its complete native items. */ +#define obs_sceneitem_defer_update_begin oracle_obs_sceneitem_defer_update_begin +#define obs_sceneitem_defer_update_end oracle_obs_sceneitem_defer_update_end +#include "libobs/build/libobs.pch.h" +#include "sceneitem-defer-update.inc" +#undef obs_sceneitem_defer_update_begin +#undef obs_sceneitem_defer_update_end +#include "sceneitem_defer_update_fields.inc" + +typedef void (*defer_operation)(obs_sceneitem_t *); +unsigned oracle_scene_bounds_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count, + defer_operation c_begin, defer_operation c_end, defer_operation begin, + defer_operation end); +unsigned oracle_sceneitem_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count, + defer_operation begin, defer_operation end); +unsigned oracle_sceneitem_defer_null(defer_operation begin, defer_operation end); + +unsigned oracle_sceneitem_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count, + defer_operation begin, defer_operation end) +{ + return oracle_scene_bounds_defer_probe(initial, flags, ops, count, oracle_obs_sceneitem_defer_update_begin, + oracle_obs_sceneitem_defer_update_end, begin, end); +} + +struct defer_log { + unsigned count; + int level; + char text[128]; +}; +#if defined(__GNUC__) || defined(__clang__) +static void defer_capture(int level, const char *format, va_list args, void *param) + __attribute__((format(printf, 2, 0))); +#endif +static void defer_capture(int level, const char *format, va_list args, void *param) +{ + struct defer_log *log = param; + log->count++; + log->level = level; + vsnprintf(log->text, sizeof(log->text), format, args); +} + +unsigned oracle_sceneitem_defer_null(defer_operation begin, defer_operation end) +{ + log_handler_t previous; + void *param; + base_get_log_handler(&previous, ¶m); + defer_operation c[] = {oracle_obs_sceneitem_defer_update_begin, oracle_obs_sceneitem_defer_update_end}; + defer_operation rust[] = {begin, end}; + const char *messages[] = {"obs_sceneitem_defer_update_begin: Null 'item' parameter", + "obs_sceneitem_defer_update_end: Null 'item' parameter"}; + unsigned result = 0; + for (unsigned i = 0; i < 2; i++) { + struct defer_log expected = {0}, actual = {0}; + base_set_log_handler(defer_capture, &expected); + c[i](NULL); + base_set_log_handler(defer_capture, &actual); + rust[i](NULL); + if (expected.count != 1 || expected.level != LOG_DEBUG || strcmp(expected.text, messages[i]) || + actual.count != expected.count || actual.level != expected.level || + strcmp(actual.text, expected.text)) + result |= 1u << i; + } + base_set_log_handler(previous, param); + return result; +} diff --git a/rust/obs-scene/src/ffi/item_defer_update.rs b/rust/obs-scene/src/ffi/item_defer_update.rs new file mode 100644 index 0000000000..5742805c15 --- /dev/null +++ b/rust/obs-scene/src/ffi/item_defer_update.rs @@ -0,0 +1,62 @@ +//! Opaque scene items: C retains the layout, atomic width and ordering. +use super::item_bounds_getters::SceneItemPrefix; +use crate::item_defer_update::{self, TransformDeferral}; +use core::ffi::{CStr, c_char, c_int, c_long, c_void}; +use core::ptr::NonNull; + +unsafe extern "C" { + fn obs_sceneitem_defer_update_increment(item: *mut c_void) -> c_long; + fn obs_sceneitem_defer_update_decrement(item: *mut c_void) -> c_long; + fn obs_sceneitem_bounds_update_transform(item: *mut SceneItemPrefix); + fn blog(level: c_int, format: *const c_char, ...); +} + +struct Item(NonNull); +impl TransformDeferral for Item { + fn increment(&self) { + // SAFETY: validated live item; C performs the original atomic RMW. + unsafe { obs_sceneitem_defer_update_increment(self.0.as_ptr()) }; + } + fn decrement(&self) -> isize { + // SAFETY: same live item. C long fits isize on all supported targets. + unsafe { obs_sceneitem_defer_update_decrement(self.0.as_ptr()) as isize } + } + fn update_transform(&self) { + // SAFETY: same live item; reuse the existing scene dispatch adapter. + unsafe { obs_sceneitem_bounds_update_transform(self.0.as_ptr().cast()) }; + } +} + +fn validated(item: *mut c_void, function: &CStr) -> Option { + let item = NonNull::new(item); + if item.is_none() { + // SAFETY: static NUL-terminated format and string arguments. + unsafe { + blog( + 400, + c"%s: Null '%s' parameter".as_ptr(), + function.as_ptr(), + c"item".as_ptr(), + ); + } + } + item.map(Item) +} + +/// # Safety +/// A non-null item must remain live for the call, as in the original C API. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_sceneitem_defer_update_begin(item: *mut c_void) { + if let Some(item) = validated(item, c"obs_sceneitem_defer_update_begin") { + item_defer_update::begin(&item); + } +} + +/// # Safety +/// A non-null item must remain live for the call, as in the original C API. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_sceneitem_defer_update_end(item: *mut c_void) { + if let Some(item) = validated(item, c"obs_sceneitem_defer_update_end") { + item_defer_update::end(&item); + } +} diff --git a/rust/obs-scene/src/ffi/mod.rs b/rust/obs-scene/src/ffi/mod.rs index 904195f223..048abdb33c 100644 --- a/rust/obs-scene/src/ffi/mod.rs +++ b/rust/obs-scene/src/ffi/mod.rs @@ -6,6 +6,7 @@ pub mod group_enum; pub mod group_queries; pub mod group_resize_defer; pub mod item_audio_actions; +pub mod item_defer_update; pub mod item_id; pub mod item_parent_getter; pub mod item_private_settings; diff --git a/rust/obs-scene/src/item_defer_update.rs b/rust/obs-scene/src/item_defer_update.rs index b672c6f66e..b65641cf83 100644 --- a/rust/obs-scene/src/item_defer_update.rs +++ b/rust/obs-scene/src/item_defer_update.rs @@ -9,10 +9,12 @@ pub trait TransformDeferral { fn update_transform(&self); } -pub fn begin(_item: &impl TransformDeferral) { - todo!("port obs_sceneitem_defer_update_begin"); +pub fn begin(item: &impl TransformDeferral) { + item.increment(); } -pub fn end(_item: &impl TransformDeferral) { - todo!("port obs_sceneitem_defer_update_end"); +pub fn end(item: &impl TransformDeferral) { + if item.decrement() == 0 { + item.update_transform(); + } } diff --git a/rust/obs-scene/tests/scene/item_defer_update.rs b/rust/obs-scene/tests/scene/item_defer_update.rs index e749add05c..a3fee34a05 100644 --- a/rust/obs-scene/tests/scene/item_defer_update.rs +++ b/rust/obs-scene/tests/scene/item_defer_update.rs @@ -52,7 +52,10 @@ fn plain_pair_computes_on_end() { assert_eq!(item.count.get(), 0); assert_eq!(item.transforms.get(), expected); } - assert_eq!(*item.calls.borrow(), ["increment", "decrement", "update"].repeat(3)); + assert_eq!( + *item.calls.borrow(), + ["increment", "decrement", "update"].repeat(3) + ); } #[test] @@ -91,7 +94,10 @@ fn unmatched_end_goes_negative_and_begin_reaching_zero_is_quiet() { #[test] fn group_child_end_sets_flag_and_parentless_end_reads_nothing() { for parent in [Parent::Group, Parent::None] { - let item = Item { parent, ..Item::default() }; + let item = Item { + parent, + ..Item::default() + }; defer::begin(&item); defer::begin(&item); defer::end(&item); @@ -99,7 +105,10 @@ fn group_child_end_sets_flag_and_parentless_end_reads_nothing() { defer::end(&item); assert!(item.pending.get()); assert_eq!(item.transforms.get(), 0); - assert_eq!(*item.calls.borrow(), ["increment", "increment", "decrement", "decrement", "update"]); + assert_eq!( + *item.calls.borrow(), + ["increment", "increment", "decrement", "decrement", "update"] + ); } } @@ -116,13 +125,17 @@ fn group_item_end_computes_like_an_ordinary_item() { fn dispatch_uses_the_decrement_result_without_reloading() { struct RacingItem(Cell, Cell); impl TransformDeferral for RacingItem { - fn increment(&self) { self.0.set(self.0.get() + 1); } + fn increment(&self) { + self.0.set(self.0.get() + 1); + } fn decrement(&self) -> isize { let result = self.0.get() - 1; self.0.set(77); // another caller can increment after this RMW result } - fn update_transform(&self) { self.1.set(true); } + fn update_transform(&self) { + self.1.set(true); + } } let item = RacingItem(Cell::new(1), Cell::new(false)); defer::end(&item); diff --git a/rust/obs-scene/tests/scene/item_defer_update_parity.rs b/rust/obs-scene/tests/scene/item_defer_update_parity.rs new file mode 100644 index 0000000000..1a7b4d92c6 --- /dev/null +++ b/rust/obs-scene/tests/scene/item_defer_update_parity.rs @@ -0,0 +1,83 @@ +//! Tier 3: real-header C items, original C operations, production atomics, and +//! the existing bounds-transform recorder. No intentional differences. Inputs +//! leave space for 64 operations on the host's actual C long width. +use core::ffi::{c_long, c_void}; +use obs_scene::ffi::item_defer_update::{ + obs_sceneitem_defer_update_begin as begin, obs_sceneitem_defer_update_end as end, +}; +use proptest::prelude::*; + +type Operation = unsafe extern "C" fn(*mut c_void); +const INITIAL_MIN: c_long = -10000; +const INITIAL_MAX: c_long = 10000; +unsafe extern "C" { + fn oracle_sceneitem_defer_probe( + initial: c_long, + flags: u32, + ops: *const u8, + count: usize, + begin: Operation, + end: Operation, + ) -> u32; + fn oracle_sceneitem_defer_null(begin: Operation, end: Operation) -> u32; +} + +fn check(initial: c_long, flags: u32, ops: &[u8]) { + // SAFETY: C owns complete native items and keeps them live for both callbacks. + assert_eq!( + unsafe { + oracle_sceneitem_defer_probe(initial, flags, ops.as_ptr(), ops.len(), begin, end) + }, + 0, + "initial={initial}, flags={flags}, ops={ops:?}" + ); +} + +#[test] +fn nested_negative_zero_crossings_and_native_long_edges() { + for initial in [-3, -1, 0, 1, 2, 3, c_long::MIN + 64, c_long::MAX - 64] { + for flags in 0..8 { + for ops in [ + &[1, 1, 1, 0, 0, 0][..], + &[0, 0, 1, 1, 1, 0], + &[1], + &[0], + &[], + ] { + check(initial, flags, ops); + } + } + } +} + +#[test] +fn null_item_logs_exactly_and_touches_nothing() { + // Logging callbacks are process-wide: isolate this case in the same binary. + const CHILD: &str = "OBS_SCENEITEM_DEFER_NULL_CHILD"; + if std::env::var_os(CHILD).is_none() { + let module = module_path!().split_once("::").unwrap().1; + let selector = format!("{module}::null_item_logs_exactly_and_touches_nothing"); + let status = std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact", &selector, "--nocapture"]) + .env(CHILD, "1") + .status() + .unwrap(); + assert!(status.success()); + return; + } + // SAFETY: C passes only NULL and restores the process-wide logging callback. + assert_eq!(unsafe { oracle_sceneitem_defer_null(begin, end) }, 0); + check(0, 1, &[1, 0]); +} + +proptest! { + #![proptest_config(ProptestConfig { + cases: obs_c_oracle::parity::cases(128), failure_persistence: None, + ..ProptestConfig::default() + })] + #[test] + fn operation_traces_match_c(initial in INITIAL_MIN..INITIAL_MAX, + flags in 0u32..8, ops in prop::collection::vec(0u8..2, 0..=64)) { + check(initial, flags, &ops); + } +} diff --git a/rust/obs-scene/tests/scene/main.rs b/rust/obs-scene/tests/scene/main.rs index e8fb6a2a6c..dcf0fc9723 100644 --- a/rust/obs-scene/tests/scene/main.rs +++ b/rust/obs-scene/tests/scene/main.rs @@ -24,6 +24,7 @@ mod group_enum_parity; mod item_audio_actions; mod item_audio_actions_parity; mod item_defer_update; +mod item_defer_update_parity; mod item_id; mod item_id_parity; mod item_names; diff --git a/test/cmocka/sceneitem-defer-update-link-support.c b/test/cmocka/sceneitem-defer-update-link-support.c new file mode 100644 index 0000000000..025f88c7e3 --- /dev/null +++ b/test/cmocka/sceneitem-defer-update-link-support.c @@ -0,0 +1,2 @@ +/* A separate lazy archive member, using the real production atomics. */ +#include "libobs/obs-sceneitem-defer-update-fields.c.h" diff --git a/test/cmocka/tests.d/video_info_query_link_support.cmake b/test/cmocka/tests.d/video_info_query_link_support.cmake index 8bd1579776..43a58b4635 100644 --- a/test/cmocka/tests.d/video_info_query_link_support.cmake +++ b/test/cmocka/tests.d/video_info_query_link_support.cmake @@ -9,6 +9,7 @@ function(_video_info_query_link_support) "${CMAKE_CURRENT_SOURCE_DIR}/core-state-link-support.c" "${CMAKE_CURRENT_SOURCE_DIR}/encoder-video-tex-active-fields-link-support.c" "${CMAKE_CURRENT_SOURCE_DIR}/encoder-video-tex-active-mix-link-support.c" + "${CMAKE_CURRENT_SOURCE_DIR}/sceneitem-defer-update-link-support.c" ) target_include_directories( video_info_query_link_support