Skip to content

rust: Port graphics/bounds.c to obs-graphics - #344

Merged
zackees merged 3 commits into
obs-rust:masterfrom
nathan-v:port/bounds
Oct 12, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
nathan-v:port/bounds

Conversation

@nathan-v

Copy link
Copy Markdown
Contributor

Fixes #343.

Ports libobs/graphics/bounds.c to obs-graphics. Header-inline helpers stay C. ENABLE_RUST_LIBOBS drops graphics/bounds.c. Exports are in libobs/cmake/rust-exports.d/obs-graphics-bounds.txt.

Commits

  1. 3581d4014 characterization: test/cmocka/test_bounds.c. It does not call bounds_plane_test, bounds_under_plane, or a singular bounds_intersects_obb (those read uninitialized memory in C).
  2. 90c2da46a RED. test_bounds_move fails because Bounds::move_by returns a zero box: left (0, 0, 0, 0)-(0, 0, 0, 0), right (11, 1, 3.5, 0)-(14, 4, 6.5, 0). 17 of 18 Tier 1 tests fail. The one that passes is the ray miss, which is also the empty result.
  3. 9f0af2910 GREEN.

What passed here

  • Tier 1: 18 bounds tests.
  • Layout: bounds_layout_matches_c_header (size 32, align 16).
  • Tier 3: bounds_matches_c_oracle, 256 cases, bit-exact (NaN equals NaN). export_list (3 tests). clippy -p obs-graphics --all-targets -- -D warnings.
  • Mutation: returning the ray t from intersection_line without dividing by the segment length made bounds_matches_c_oracle fail on line t. That break was reverted.

Intentional differences

  • bounds_under_plane and bounds_plane_test set the corner w to 0. C leaves it uninitialized and vec3_dot reads it, so those two are not compared to the oracle. The safe plane_test returns BOUNDS_OUTSIDE (1), BOUNDS_INSIDE (2), or BOUNDS_PARTIAL (3). The C function is declared bool, and this compiler stores 1 for every branch (plane_test_abi_byte). The shim returns that byte.
  • bounds_intersects_obb uses a zero matrix when |det| < 0.0005. C leaves that inverse uninitialized. Parity skips those matrices.
  • vec3_min / vec3_max follow SSE: the second lane unless the comparison holds. A ray or line miss does not write *t. bounds_get_point writes a corner for index 8 and writes nothing for i > 8.

Not run

Docker is not installed, so Tier 2 cmocka (./unittest) and the local-gate stamp were not run. This does not claim CI is green. Please add the claimed label on #343. If this branch is behind master at review, rebase onto master and stamp; #338 (plane.c) also edits libobs/CMakeLists.txt and rust/README.md.

@nathan-v
nathan-v requested a review from zackees as a code owner October 12, 2026 08:08
Pins the exports in graphics/bounds.c: w cleared by move and merge, kept by scale, index 8 writing corner 6, a ray or line miss leaving *t unchanged, and min_dist independent of the plane distance.

bounds_plane_test and bounds_under_plane read an uninitialized w, and a rejected matrix4_inv leaves bounds_intersects_obb's inverse uninitialized. Those paths are not called.

Refs obs-rust#343
test_bounds_move fails because Bounds::move_by returns a zero box: left (0, 0, 0, 0)-(0, 0, 0, 0), right (11, 1, 3.5, 0)-(14, 4, 6.5, 0). 17 of 18 Tier 1 tests fail. The one that passes is the ray miss, which is also the empty result.

Refs obs-rust#343
The 18 Tier 1 bounds tests pass. Tier 3 bounds_parity is bit-exact against the C oracle for the defined functions, 256 cases, and the layout matches bounds.h. Dropping the segment-length divide in intersection_line makes bounds_matches_c_oracle fail on line t; that break was reverted.

bounds_under_plane and bounds_plane_test set w to 0. The C bool return of plane_test is 1 for codes 1, 2, and 3. A rejected matrix4_inv uses a zero matrix, and those inputs are excluded from parity.

ENABLE_RUST_LIBOBS drops graphics/bounds.c. Exports are in obs-graphics-bounds.txt. Header-inline helpers stay C.

Fixes obs-rust#343

Local-Gate: v1 tree=88e0239623057a1af286a81ff0e120ec30eaed36 secs=108 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791793482,"gate":"rust/all/fmt","host":"linux-x86_64","key":"71f6d73a34848e54e5b690583d672bcf3e98049eb47b5ae2e3e365ecc4158997","lane":"lint","parents":["46e2bf79799061988dd2a3f0ebcb3a0408e3c78b"],"secs":12,"stamp":"622f947c07732a97009c873761b43846","tree":"88e0239623057a1af286a81ff0e120ec30eaed36","v":1,"via":"run"}
Ci-Attestation: {"at":1791793482,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"71f6d73a34848e54e5b690583d672bcf3e98049eb47b5ae2e3e365ecc4158997","lane":"lint","parents":["46e2bf79799061988dd2a3f0ebcb3a0408e3c78b"],"secs":12,"stamp":"db7291aa602fdf29d8fcca54f5ba39b4","tree":"88e0239623057a1af286a81ff0e120ec30eaed36","v":1,"via":"run"}
Ci-Attestation: {"at":1791793482,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"585392382dbf92222b8d4c4478d8ab87aaef125d12276db681d51809e1ca8b00","lane":"rust-test","parents":["46e2bf79799061988dd2a3f0ebcb3a0408e3c78b"],"secs":44,"stamp":"b41bb8dec20cb61864e88a00ecc07779","tree":"88e0239623057a1af286a81ff0e120ec30eaed36","v":1,"via":"run"}
Ci-Attestation: {"at":1791793482,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"113e7c03da0aefdf5deba3a37244a6c35cfaf5258be5e8ec5d4b972ab47968bd","lane":"tier2-linux","parents":["46e2bf79799061988dd2a3f0ebcb3a0408e3c78b"],"secs":52,"stamp":"0adfb102c3daffd57220690823e017cd","tree":"88e0239623057a1af286a81ff0e120ec30eaed36","v":1,"via":"run"}
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped. The new head is fc16345db.

  • Characterization (3581d4014): Tier 2 passed 109 of 109 with ENABLE_RUST_LIBOBS OFF and 109 of 109 with it ON. test_bounds matches the C.
  • RED (90c2da46a): tests/bounds.rs passed 1 of 18 against the empty stubs.
  • GREEN (9f0af2910): bounds 18 of 18, bounds_parity 2 of 2, bounds_layout 1 of 1 and export_list 3 of 3 passed.

The rebase conflicted with #338 (plane), which also added Vec3 helpers and a README row. I kept both sides: master's cross/norm and your add_xyz/min_xyz/max_xyz/abs_xyz/len. All obs-graphics suites pass and clippy is clean. Local gate: lint, rust-test and tier2-linux all passed (== ported objects checked with ENABLE_RUST_LIBOBS=ON: 38 100% tests passed, 0 tests failed out of 112 100% tests passed, 0 tests failed out of 112 ).

Merging once CI is green.

@zackees
zackees merged commit 6119dbb into obs-rust:master Oct 12, 2026
23 checks passed
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 libobs/graphics/bounds.c to obs-graphics

2 participants