Repository navigation
rust: Port media-io/format-conversion.c to obs-media-io - #184
Merged
Merged
Conversation
Pins the current behaviour of the six functions media-io/format-conversion.c exports. Nothing in the tree calls them, so this is their only C coverage and the Tier 2 check for the port (obs-rust#183). Every buffer starts filled with a canary byte and each test compares the whole buffer, so writes outside the expected area fail too. Inputs follow the functions' contracts: 16-byte-aligned UYVX rows with in_linesize a multiple of 16 and widths a multiple of 4, and uint16_t/uint32_t-aligned linesizes for decompress_*. Characterized, not endorsed: - compress_uyvx_to_i420 addresses the V plane with out_linesize[1]; convert_uyvx_to_i444 addresses all three planes with out_linesize[0]. - decompress_420 and decompress_nv12 round start_y and end_y down to row pairs, so start_y 1, end_y 3 writes rows 0 and 1. - decompress_420 takes its width from in_linesize[0] alone. - decompress_422 reads min(in_linesize, out_linesize) / 2 dwords per row, twice the row, and writes twice as many dwords, so each row spills into the next. Refs obs-rust#183 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 1 and Tier 3 parity tests for the six functions media-io/format-conversion.c exports, against a todo!() core. The safe core takes its planes as Source/Sink traits addressed by byte offset. Byte slices implement both and panic where the C would read or write out of bounds; the shims implement them over the caller's raw pointers, so they convert nothing and the core sees the C's offsets. Each shim reads only the output/input and linesize entries the C reads. The oracle builds format-conversion.c twice. oracle_* uses native SSE2 on x86. oracle_scalar_* defines OBS_ORACLE_SCALAR_SSE, so even on x86 it uses the plain-C __m128i intrinsics this commit adds to the oracle's sse-shim (_mm_load_si128, _mm_set1_epi32/epi16, _mm_and_si128, _mm_srli_si128, _mm_packs_epi32, _mm_packus_epi16, _mm_add_epi64, _mm_shuffle_epi32, _mm_shufflelo_epi16, _mm_srai_epi16), which non-x86 builds use for both. Parity compares all four implementations byte for byte, so the x86 jobs check the stand-ins before the arm64 job relies on them. Parity buffers are 16-byte aligned, sized to exactly the bytes a call touches plus canary slack, and compared whole. The test file lists the excluded inputs: misaligned loads and stores, loops that wrap past u32::MAX, and overlapping planes. RED: soldr cargo test -p obs-media-io --test format_conversion fails 22 of 22, --test format_conversion_parity fails 8 of 8 (not yet implemented). Refs obs-rust#183 Co-Authored-By: Claude Opus 5.5 <[email protected]>
compress_uyvx_to_i420, compress_uyvx_to_nv12, convert_uyvx_to_i444, decompress_420, decompress_nv12 and decompress_422 move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without media-io/format-conversion.c and exports the Rust shims under the same names. No intentional differences. The C's SSE2 is integer only, and every lane reduces to byte extraction or a (a + b + c + d) >> 2 chroma average, so the core is scalar with no core::arch and parity is byte-exact. Offsets use the C's u32 arithmetic, wrapping included, and each loop keeps the C's order of reads and writes, which decides the result where output rows overlap. uint16_t/uint32_t values are stored native-endian as in the C, including the I420 chroma the C packs into one uint32_t and splits into two uint16_t stores. Mutation checks: halving the chroma divisor, swapping decompress_420's row write order, changing decompress_422's luma duplication and the I420 chroma packing each fail parity. Breaking _mm_packus_epi16, _mm_shuffle_epi32, _mm_srai_epi16 or _mm_shufflelo_epi16 in the oracle's plain-C sse-shim fails parity as "CScalar differs from C" on x86. Local gate: rust-test and tier2-linux pass (test_format_conversion passes OFF and ON; exported symbols identical, 1752). obs-media-io tests also pass for x86_64-pc-windows-msvc via cargo-xwin. Fixes obs-rust#183 Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=e2a36762c7a5157c323e2754690ab6ba7213dcfa secs=150 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791686476,"gate":"rust/all/fmt","host":"linux-x86_64","key":"05801aa46783e55e6e04153c3347c6417abd35835e74561121b5cb9604ea5039","lane":"lint","parents":["07e455b799ee5447efaa23ccab9600dc6da880bf"],"secs":31,"stamp":"44a6d04f5eeaa235b4dd078dbaf7578c","tree":"e2a36762c7a5157c323e2754690ab6ba7213dcfa","v":1,"via":"run"} Ci-Attestation: {"at":1791686476,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"05801aa46783e55e6e04153c3347c6417abd35835e74561121b5cb9604ea5039","lane":"lint","parents":["07e455b799ee5447efaa23ccab9600dc6da880bf"],"secs":31,"stamp":"771bc902bc2e221cfb589516aa23773f","tree":"e2a36762c7a5157c323e2754690ab6ba7213dcfa","v":1,"via":"run"} Ci-Attestation: {"at":1791686476,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"d3822cf976ffc59edf870d9b5a02c2b1d2bc85be9b739e0035b8b38881bde94f","lane":"rust-test","parents":["07e455b799ee5447efaa23ccab9600dc6da880bf"],"secs":38,"stamp":"17639da348f0ad7ca81887a113cfa0c4","tree":"e2a36762c7a5157c323e2754690ab6ba7213dcfa","v":1,"via":"run"} Ci-Attestation: {"at":1791686476,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"33a162da37eb409489461f876489e604e62c9e2da8e8281e6d484002c7c5e56a","lane":"tier2-linux","parents":["07e455b799ee5447efaa23ccab9600dc6da880bf"],"secs":81,"stamp":"cbc3595ea12a68316fc9465a0037c43a","tree":"e2a36762c7a5157c323e2754690ab6ba7213dcfa","v":1,"via":"run"}
Member
|
Verified locally, rebased onto master and stamped. The new head is
The RED run leaves a |
zackees
force-pushed
the
port/format-conversion
branch
from
October 11, 2026 02:41
9e51716 to
5ad7973
Compare
10 of 22 tasks
This was referenced Oct 11, 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.
Fixes #183
What and why
Ports the six functions
libobs/media-io/format-conversion.cexports (compress_uyvx_to_i420,compress_uyvx_to_nv12,convert_uyvx_to_i444,decompress_420,decompress_nv12,decompress_422) toobs-media-io(obs_media_io::format_conversion). This is item 6 of the media-io part 2 order on #45 (#45 (comment)), claimed on #183. No intentional differences.With
ENABLE_RUST_LIBOBS=ON, libobs builds withoutformat-conversion.cand exports the Rust shims under the same names, listed inrust-exports.d/obs-media-io-format_conversion.txt.Scalar, byte-exact. The C's SSE2 is integer only, and every lane reduces to plain integer math: byte extraction, and
(a + b + c + d) >> 2for 2x2 chroma. So the core is scalar with nocore::arch, and parity is exact byte equality with no ULP allowance. Offsets use the C'su32arithmetic, wrapping included. Each loop keeps the C's order of reads and writes, which decides the result where output rows overlap.uint16_t/uint32_tvalues are stored native-endian, as in the C. That includes the I420 chroma, which the C packs into oneuint32_tand splits into twouint16_tstores.Planes as traits. The safe core takes its planes as
Source/Sinktraits, addressed by byte offset. Byte slices implement both and panic where the C would read or write out of bounds. The shims implement them over the caller's raw pointers, so the shims convert nothing and the core sees the C's offsets. Each shim reads only theoutput/inputand linesize entries the C reads.Oracle
__m128istand-ins. As noted on #45, the oracle'ssse-shim/simde/x86/sse2.hhad only the float ops for non-x86. This PR adds the integer opsformat-conversion.cuses, lane by lane:_mm_load_si128,_mm_set1_epi32/epi16,_mm_and_si128,_mm_srli_si128,_mm_packs_epi32,_mm_packus_epi16,_mm_add_epi64,_mm_shuffle_epi32,_mm_shufflelo_epi16and_mm_srai_epi16.__m128istores its bytes asuint32_t, because the C reads lanes with*(uint32_t *)&val.The oracle builds
format-conversion.ctwice:oracle_*uses native SSE2 on x86.oracle_scalar_*(oracle/format_conversion_scalar.c) definesOBS_ORACLE_SCALAR_SSE, so it uses the stand-ins on x86 too.Parity compares four implementations: C, C with the stand-ins, the Rust shim and the safe core. That way the x86 jobs check the stand-ins before the arm64 job relies on them.
Characterized, not endorsed (pinned in the cmocka test and kept by the port):
compress_uyvx_to_i420addresses the V plane without_linesize[1].convert_uyvx_to_i444addresses all three planes without_linesize[0].decompress_420anddecompress_nv12roundstart_yandend_ydown to row pairs.decompress_420takes its width fromin_linesize[0]alone.decompress_422readsmin(in_linesize, out_linesize) / 2dwords per row, which is twice the row, and writes twice as many. Each row spills into the next, and the next row overwrites the spill.RED → GREEN
61bfc212daddstest/cmocka/test_format_conversion.c(tests.d/test_format_conversion.cmake). Every buffer is canary-filled and compared whole. It passes OFF and ON before any Rust.dc583bee0. Against thetodo!()core,format_conversionfails 22/22 andformat_conversion_parityfails 8/8.9e5171627.format_conversionpasses 22/22 andformat_conversion_parity8/8. Tier 2 Linux: 53/53 withENABLE_RUST_LIBOBSOFF and ON,test_format_conversionincluded, and libobs exports are identical (1752 symbols).How has this been tested?
tests/format_conversion.rs: portstest_format_conversion.ccase for case. Edge cases:u32row-offset wrap (row 2 of a 2^31 linesize starts at 0)tests/format_conversion_parity.rs: proptest, 512 cases per function, over linesizes, row ranges (including empty and odd) and random contents, plus the cmocka inputs and theu32wrap.u32::MAX; and overlapping planes.decompress_420's row write order, changingdecompress_422's luma duplication, and changing the I420 chroma packing. Breaking_mm_packus_epi16,_mm_shuffle_epi32,_mm_srai_epi16or_mm_shufflelo_epi16in the stand-ins fails parity asCScalar differs from Con x86. On arm64, the_mm_shuffle_epi32break fails asSafe differs from C.obs-c-oraclerlib when only oracle C changes. UseSOLDR_RUSTC_WRAPPER=none, or also touch an oracle.rsfile../lint,./unittest, and the stamped head.format_conversion22/22 andformat_conversion_parity8/8. The oracle there is native SSE2 for both builds, and cmocka Tier 2 wasn't run locally.rust/tools/tier2-validate/validate.shpasses OFF and ON (48/48 each,test_format_conversionincluded) with identical exports (1863 symbols).Checklist
master🤖 Generated with Claude Code