Skip to content

rust: port graphics/matrix4.c to obs-graphics - #227

Merged
zackees merged 4 commits into
obs-rust:masterfrom
nathan-v:port/matrix4
Oct 11, 2026
Merged

zackees merged 4 commits into
obs-rust:masterfrom
nathan-v:port/matrix4

Conversation

@nathan-v

Copy link
Copy Markdown
Contributor

Summary

Ports libobs/graphics/matrix4.c to obs-graphics::matrix4 and swaps it under ENABLE_RUST_LIBOBS. Header-inline helpers stay in matrix4.h. matrix4_mul_4x3_only is not exported (hidden in the C build); rotate_i, rotate_aa_i, and scale_i cover it.

Refs #150, #45.

Commits

  1. 159522cb7 characterization cmocka test test_matrix4.
  2. RED 5cd84f211 — Tier 1 tests against zero stubs. soldr cargo test -p obs-graphics --test matrix4: 11 failed, 1 passed. test_matrix4_transpose passed because the vec4 port already implemented the scalar transpose. The other 11 fail assert_eq (left == right): stubs return an all-zero matrix, determinant returns 0.0, and try_inv returns Some of that zero matrix.
  3. b9230fa90 corrects the translation-inverse expectation. The inverse of a translation by (4, -2, 8) is (-4, 2, -8), so assert_identity (which requires a zero translation) was wrong.
  4. GREEN f631dd8fa — safe core, C shims, layout test, bit-exact Tier 3 parity, ENABLE_RUST_LIBOBS guard, rust-exports.d/obs-graphics-matrix4.txt.

Tests

  • Tier 1: 12/12 matrix4 tests pass. The rest of obs-graphics passes.
  • Tier 3: matrix4_matches_c_oracle, 256 proptest cases, bit equality (NaN == NaN). No ULP slack. The C transpose is SSE unpacks and matrix4_mul uses SSE vec4_dot; both only permute or sum lanes, and Vec4::dot uses the SSE sum order, so the results match bit for bit. Determinant and inverse are scalar in C. |det| < 0.0005 leaves dst unchanged.
  • Mutation check: flipping the determinant sign from +1 to -1 made matrix4_matches_c_oracle fail (det shim != C). Reverted.
  • export_list passes, including the new fragment.
  • Clippy -D warnings is clean for obs-graphics and obs-c-oracle.

Tier 2 (./unittest, OFF and ON) was not run here: Docker is not installed. CI should run it.

No intentional differences from C.

The claimed label on #150 needs a maintainer. The claim comment is on the issue.

@nathan-v
nathan-v requested a review from zackees as a code owner October 11, 2026 10:23
Local-Gate: v1 tree=313f273c26cb89c597191b5a887e5feec361d964 secs=121 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791715564,"gate":"rust/all/fmt","host":"linux-x86_64","key":"c8de349e80cfb5c337466788ae832195a14761a90f136bd9b01ab089b40e1542","lane":"lint","parents":["b9230fa9043e9ba0f1fc1b32a33f63e441cb71ec"],"secs":47,"stamp":"00bd55e424e505ee67220b85e3e35c7d","tree":"313f273c26cb89c597191b5a887e5feec361d964","v":1,"via":"run"}
Ci-Attestation: {"at":1791715564,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"c8de349e80cfb5c337466788ae832195a14761a90f136bd9b01ab089b40e1542","lane":"lint","parents":["b9230fa9043e9ba0f1fc1b32a33f63e441cb71ec"],"secs":47,"stamp":"aad4ec3b5fe62e8abf4cca6987eacf18","tree":"313f273c26cb89c597191b5a887e5feec361d964","v":1,"via":"run"}
Ci-Attestation: {"at":1791715564,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"cdc2aa43905eee6aa339504d38f93eacf39381488e7fa461d4d658640fec2063","lane":"rust-test","parents":["b9230fa9043e9ba0f1fc1b32a33f63e441cb71ec"],"secs":30,"stamp":"35a47fc16075527aca16e931c819d8d7","tree":"313f273c26cb89c597191b5a887e5feec361d964","v":1,"via":"run"}
Ci-Attestation: {"at":1791715564,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"fe9e5c59dc7ce8bbe415ddf2e7cc84716c2565b880bd7a5955634bfa5c51f00e","lane":"tier2-linux","parents":["b9230fa9043e9ba0f1fc1b32a33f63e441cb71ec"],"secs":44,"stamp":"39bfb796ae216a8e8f5b685422b864af","tree":"313f273c26cb89c597191b5a887e5feec361d964","v":1,"via":"run"}
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped.

  • Characterization: 159522cb7 failed test_matrix4_inv_scale_translation_and_singular against the C. b9230fa90 corrected the expectation to the C's actual output, so the characterization is right from there on.
  • RED (5cd84f211): tests/matrix4.rs failed against the zero stubs (determinant, from_quat_*, inv_*, mul_*, and others).
  • GREEN (f631dd8fa): matrix4 12 of 12, matrix4_layout 1 of 1 and matrix4_parity 1 of 1 passed. Tier 2 passed 73 of 73 with ENABLE_RUST_LIBOBS OFF (C) and 73 of 73 with it ON (Rust). Local gate: lint, rust-test and tier2-linux all passed.

Non-blocking: ideally the characterization commit passes against the C on its own, so a fixup into 159522cb7 would make the history cleaner. Merging once CI is green.

@zackees
zackees merged commit a3d4268 into obs-rust:master Oct 11, 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.

2 participants