Skip to content

rust: Port graphics/vec4.c to obs-graphics - #73

Merged
zackees merged 5 commits into
obs-rust:masterfrom
b7216309-jpg:port/vec4
Oct 10, 2026
Merged

zackees merged 5 commits into
obs-rust:masterfrom
b7216309-jpg:port/vec4

Conversation

@b7216309-jpg

Copy link
Copy Markdown
Contributor

Description

Ports libobs/graphics/vec4.c (vec4_from_vec3, vec4_transform) to obs-graphics. With ENABLE_RUST_LIBOBS=ON libobs builds without graphics/vec4.c; vec3_transform and the other C callers link the Rust shims. The header-inline helpers in vec4.h stay C.

vec4_dot sums the products through SSE shuffles as (w + y) + (z + x). Vec4::dot adds them in that order, so transforms are bit-identical to C. No intentional differences.

Oracle for the graphics math cluster. vec3, vec4, matrix3, matrix4, quat, plane, bounds, axisang and math-extra call each other (vec4_transform needs matrix4_transpose, which pulls in quat, and so on). The oracle compiles all nine files, renamed to oracle_* by oracle/graphics_math_names.h, so later ports of those files reuse it as is.

SIMDe stand-in (needs your call). util/sse-intrin.h takes SSE from <simde/x86/sse2.h> everywhere except MSVC/MinGW on x86, and the Rust test jobs and ./unittest do not install SIMDe. Instead of adding SIMDe to CI, the oracle gets oracle/sse-shim/simde/x86/sse2.h, on the include path for non-MSVC only:

  • on x86 it includes the native <emmintrin.h>, which is what SIMDe maps to there;
  • elsewhere (the arm64 macOS runner) it defines in plain C just the 15 intrinsics the math headers use, lane by lane as SSE defines them, including the NaN and signed-zero rules of minps/maxps.

If you would rather install SIMDe in the Rust jobs, the shim can go.

Motivation and Context

Issue #45 lists the graphics math ports, and nobody has claimed them yet. This PR does vec4 only, the smallest file, plus the oracle the rest of the list needs.

Refs #45

How Has This Been Tested?

Windows 11, MSVC 14.44, Rust via soldr 0.9.31.

  • Commits follow the policy: test/cmocka/test_vec4.c (C characterization), then RED (todo!() core: Tier 1 and parity fail, layout passes), then GREEN.
  • soldr cargo test -p obs-graphics: Tier 1, Tier 2 layout (vec4, vec3, matrix4 incl. the ptr/m union members), Tier 3 proptest parity on arbitrary bit patterns and on finite values where the summation order decides the last bits, plus in-place dst == v.
  • The test_vec4.c cases also run against the oracle in cmocka_cases_match_c_oracle. I have no cmocka on Windows, so the cmocka test itself first runs in Tier 2 CI.
  • Shim check: a scratch harness compiled the same intrinsic calls through the shim and through native SSE. Zero bit mismatches over 2M random inputs × 18 operations × 4 lanes, with NaNs, infinities, zeros and subnormals mixed in.
  • Scalar path check: a copy of the libobs headers with sse-intrin.h forced onto the shim's scalar branch compiled all nine oracle files with MSVC. oracle_vec4_transform matched Vec4::transform over 1M cases.
  • Mutation check: summing in naive order, setting w to 0, skipping the transpose and a wrong transpose lane are each caught by the parity tests. Swapping the two halves of the final add survives. It changes NaN payloads only, which the tests treat as equal.
  • cargo clippy -p obs-graphics -p libobs-rust --lib -- -D warnings for x86_64/aarch64 Linux and aarch64 macOS; python ci/local_gate.py --lane lint.

Note: since #61 landed, obs-c-oracle no longer builds with MSVC on master: oracle/base.c → threading.h → <pthread.h>, the same failure as on #68. I verified this branch locally with deps/w32-pthreads added to the oracle include path, without committing that. With it, base_parity's default_handler_output_matches_oracle and default_handler_truncates_like_c still fail on Windows (capture worker exits non-zero); everything else passes. So expect Rust Tests (windows) to fail here for that reason until master is fixed.

Types of changes

  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

🤖 Generated with Claude Code

b7216309-jpg and others added 4 commits October 10, 2026 02:54
Pins the exported functions of graphics/vec4.c before the Rust port:
vec4_from_vec3 sets w to 1 whatever the vec3 w lane holds, and
vec4_transform is a row vector times the matrix, including when dst and
v are the same vector.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 1, Tier 2 layout and Tier 3 parity tests for libobs/graphics/vec4.c
against a todo!() core.

The C files of the graphics math cluster (vec3, vec4, matrix3, matrix4,
quat, plane, bounds, axisang, math-extra) call each other, so the oracle
compiles all of them, renamed to oracle_* by graphics_math_names.h. Later
ports of those files reuse it.

libobs/util/sse-intrin.h takes SSE from SIMDe outside MSVC, and the Rust
test jobs do not install SIMDe. The oracle gets a stand-in
<simde/x86/sse2.h>: the native SSE header on x86, and elsewhere scalar
versions of the 15 intrinsics the math headers use, lane by lane as SSE
defines them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vec4_from_vec3 and vec4_transform move to Rust. With ENABLE_RUST_LIBOBS=ON
libobs builds without graphics/vec4.c, and vec3_transform and the other C
callers link the Rust shims.

Vec4::dot adds the four products as (w + y) + (z + x), the order the SSE
shuffles in vec4_dot produce, so transform results are bit-identical to
C. No intentional differences.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	rust/README.md
#	rust/obs-c-oracle/build.rs
# Conflicts:
#	rust/README.md
#	rust/obs-c-oracle/src/lib.rs
@zackees
zackees merged commit 66a8a1d into obs-rust:master Oct 10, 2026
22 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