Repository navigation
rust: Port media-io/video-matrices.c to obs-media-io - #106
Merged
Merged
Conversation
zackees
force-pushed
the
port/video-matrices
branch
4 times, most recently
from
October 10, 2026 18:24
2233346 to
9f0379e
Compare
Pins video_format_get_parameters and video_format_get_parameters_for_format from media-io/video-matrices.c before the Rust port: the Rec. 601, 709 and 2100 PQ matrices at 8, 10, 12 and 16 bits in partial and full range, the DEFAULT/sRGB -> 709 and HLG -> PQ aliases, the bit depth each format and colorspace selects, NULL range pointers, and an unknown colorspace returning false without writing. Range values other than VIDEO_RANGE_FULL, and format values outside the enum, are characterized as partial range and 8 bits. Matrix entries are compared with a 1e-5 tolerance so a compiler that fuses multiply-adds does not fail the test. Range limits are single divisions and are compared exactly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 1, Tier 2 layout and Tier 3 parity tests for video_format_get_parameters and video_format_get_parameters_for_format against a todo!() core. enum video_colorspace and enum video_range_type cross the C ABI as c_ints, like enum video_format; the safe enums keep the header's values as discriminants, and the layout test checks each enum's size and alignment and every enumerator's value against the oracle. The shims return false without writing for a colorspace outside the enum, as the C does. video-matrices.c only tests the range against VIDEO_RANGE_FULL and lists the formats it gives more than 8 bits, so range and format values outside their enums convert to VIDEO_RANGE_PARTIAL and VIDEO_FORMAT_NONE, which behave the same. The oracle wraps video-matrices.c with graphics_math_names.h, so its vec3_rotate call resolves to the oracle vec3.c rather than the Rust port. obs-media-io now depends on obs-graphics for Vec3 and Matrix3. Parity sweeps every enumerator plus two values on each side of each enum, with every combination of null range pointers, and compares the return value and every written float bit for bit against sentinel-filled buffers. Proptest adds arbitrary c_ints. Co-Authored-By: Claude Opus 5.5 <[email protected]>
video_format_get_parameters and video_format_get_parameters_for_format move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without media-io/video-matrices.c and exports the Rust shims under the same names. No intentional differences. The C fills a table of every matrix on first use behind an unsynchronized static bool, so two threads making the first call race on it. The port has no shared state: each call computes the requested matrix with the C's f32 operations in the same order, and the black-level offsets go through obs-graphics' Vec3::rotate, which sums in the SSE vec3_dot order. Parity against the oracle is bit-exact. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=4d942c109ba49365d605b7094f8bdb2358afec1c secs=112 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791661649,"gate":"rust/all/fmt","host":"linux-x86_64","key":"b86babd2e461fed5dec346f4701b477b6950d2956293ed4b7657c3d7a95b6c97","lane":"lint","parents":["6489bbb0cdb7d8ec39840dcd6b7c23fa10570a0a"],"secs":37,"stamp":"c25ca84e9eebd9052748e0915fe19ba8","tree":"4d942c109ba49365d605b7094f8bdb2358afec1c","v":1,"via":"run"} Ci-Attestation: {"at":1791661649,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"b86babd2e461fed5dec346f4701b477b6950d2956293ed4b7657c3d7a95b6c97","lane":"lint","parents":["6489bbb0cdb7d8ec39840dcd6b7c23fa10570a0a"],"secs":37,"stamp":"ea23036547197f79cb142c88ab78222e","tree":"4d942c109ba49365d605b7094f8bdb2358afec1c","v":1,"via":"run"} Ci-Attestation: {"at":1791661649,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"2afd643f4c2eeac9268a8927c80c2c561c50f1c33ea519cd91b01f657db5161f","lane":"rust-test","parents":["6489bbb0cdb7d8ec39840dcd6b7c23fa10570a0a"],"secs":25,"stamp":"16ad262f58e4bd3359fda105b7d4a4d0","tree":"4d942c109ba49365d605b7094f8bdb2358afec1c","v":1,"via":"run"} Ci-Attestation: {"at":1791661649,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"f9e75b65a773a6c527b93a5b6f1a8e8e4637877e3e37c212f4c0778157af1faf","lane":"tier2-linux","parents":["6489bbb0cdb7d8ec39840dcd6b7c23fa10570a0a"],"secs":50,"stamp":"e4aae9753fd797891df03705efe6ba18","tree":"4d942c109ba49365d605b7094f8bdb2358afec1c","v":1,"via":"run"}
Member
|
Rebased onto master (after #49, #59 and #78), keeping both sides in the oracle build.rs and src/lib.rs. RED→GREEN, checked with soldr's cache disabled: obs-media-io fails 10/12 at the RED commit and all tests pass at head. The C test already avoids fail_msg (no cm_print_error, so Windows links). The local gate passes and is stamped. |
zackees
force-pushed
the
port/video-matrices
branch
from
October 10, 2026 19:47
9f0379e to
3be62fc
Compare
7 tasks done
This was referenced Oct 10, 2026
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.
Description
Ports
libobs/media-io/video-matrices.c(video_format_get_parameters,video_format_get_parameters_for_format) toobs-media-io. WithENABLE_RUST_LIBOBS=ONlibobs builds withoutmedia-io/video-matrices.cand exports the Rust shims under the same names. No intentional differences.No lazy table. The C fills a table of every matrix (3 colorspaces × 9 bit depths × 2 ranges) on first use, behind an unsynchronized
static bool, so two threads making the first call race on it. The port has no shared state. Each call computes only the requested matrix, using the C'sf32operations in the same order. The black-level offsets go throughobs_graphics::vec3::Vec3::rotate, which sums lanes in the SSEvec3_dotorder (#75). Parity against the C oracle is bit-exact, so no ULP tolerance is needed.Enums at the C boundary.
enum video_colorspaceandenum video_range_typecross the C ABI asc_ints, likeenum video_formatin #97. This adds the checked*_from_cconversions that #97 anticipated, plusvideo_format_from_coverVideoFormat::ALL. A colorspace outside its enum returns false and writes nothing, as in C.video-matrices.conly comparesrangewithVIDEO_RANGE_FULL, and gives more than 8 bits only to the formats it lists. So the shims convert out-of-enum range and format values toVIDEO_RANGE_PARTIALandVIDEO_FORMAT_NONE, which behave the same. The parity sweep covers those values.Oracle.
oracle/video_matrices.cincludesgraphics_math_names.h, so the oracle'svec3_rotatecall resolves to the oraclevec3.crather than the Rust port. The original source fills its matrix tables lazily, which-Wextrareports as-Wmissing-field-initializers. The wrapper silences that one warning around the#includewith a GCC/Clang pragma; the source itself is unmodified.obs-media-ionow depends onobs-graphics.Motivation and Context
The second of the two files claimed on #45, after
video-fourcc.c(#97). Unblocked by #75 (vec3).Refs #45
How Has This Been Tested?
Linux x86_64 (WSL2), Rust via soldr.
test/cmocka/test_video_matrices.c(C characterization, passes OFF and ON before any Rust), then RED (todo!()core: Tier 1 fails, parity aborts in the shim, layout andexport_listpass), then GREEN.soldr cargo test -p obs-media-io: Tier 1 (1:1 port of the cmocka cases plus edge cases), Tier 2 layout for both new enums, and Tier 3 parity. Parity sweeps every enumerator of the three enums plus two values on each side of each, with all four combinations of null range pointers. It compares the return value and every written float bit for bit against sentinel-filled buffers, which also checks that nothing is written on failure. The safe core is checked against the oracle directly too, and proptest adds arbitraryc_ints. The sweep covers every cmocka input.Kg = 1 - Kb - Krto1 - Kr - Kb(mathematically equal, differs in the last bit) fails 3 of the 5 parity tests. Dropping R10L from the 10-bit formats fails 2. Both reverted../lintand./unittest: ok. tier2-linux rantest_video_matriceswith ENABLE_RUST_LIBOBS OFF and ON (36/36 each). The libobs exported symbols are identical OFF vs ON (1752). HEAD carries the local-gate stamp.rust-tier2CI jobs cover them.video_format_get_parametersandvideo_format_get_parameters_for_formatare added torust-exports.txt.Types of changes
Checklist:
🤖 Generated with Claude Code