Repository navigation
obs-source: Port the source volume multiply kernels (#3080) - #3093
Merged
Merged
Conversation
zackees
approved these changes
Oct 30, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Coordinator review: approved. Each sample is still one IEEE single multiply, bit-exact with the C (no FMA or reassociation, so #3007's SIMD parity holds). The commits show RED (b29adbf) then GREEN (efbb19f). There's Tier 2 cmocka coverage (6 cases) and Tier 3 parity against the new oracle. No C tests or public headers were edited. The target_arch cfg stays in platform/mod.rs, and the tests are in the existing source binary. The Test cost line is present, and it's a behaviour-neutral port, so no ledger line is needed.
zackees
enabled auto-merge
October 30, 2026 18:41
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 30, 2026
Behaviour-neutral extraction before the Rust port (#3080). The two volume multiply loops of obs-source.c move to libobs/obs-source-volume-mul.c.h, as two functions on plain pointers and counts declared in the new libobs/obs-source-volume-mul.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_volume_mul_block(out, count, vol): multiply_output_audio(), one volume over count samples; apply_audio_volume() still passes the mix's first channel buffer and AUDIO_OUTPUT_FRAMES * channels, the mix's channel buffers being consecutive in allocate_audio_output_buffer()'s one allocation; - obs_source_volume_mul_data(out, vol_data, count): multiply_vol_data()'s inner loop, one channel by a volume per frame; the channel loop stays in obs-source.c. The loop bodies are the C's, unchanged. obs-source.c keeps the action queue and its mutex, get_source_volume(), the vol_data fill, the memset and the mix and channel loops. Checked in a scratch harness (not committed): master's two loops against the moved functions on the same buffers, 4,000 ticks of 1 to 8 channels and 71 short counts (0 to 70), samples, volumes and vol_data drawn from NaN, -NaN, infinities, -0.0, 0, 1, random bit patterns and ordinary values; clang -O0 and -O2, with and without ASan/UBSan: 0 differences other than NaN payloads where both operands are NaN. Those differ between builds of the C itself: at -O0 the result carries the sample's payload, vectorized at -O2 the volume's (the multiply is commutative and the compiler orders it), so the payload is not a property of the source. Refs #3080. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Characterization before the Rust port, against the C moved to libobs/obs-source-volume-mul.c: test_source_volume_mul_steps (every platform, the moved file on its own, ASan and UBSan), 6 cases, on buffers laid out as allocate_audio_output_buffer() lays them out (8 consecutive channels of 1024 frames per mix, then the next mix), with a canary after every count: - one volume (0, 1, 0.5, 20, -10 dB) over 1, 2 and 8 channels as one block: those channels multiplied, the rest of the mix and the next mix untouched; - counts 0, 1 to 17 and around a tick: nothing past the count; - special values: 0 times infinity is NaN, -0.0 for negative samples times 0, -0.0 and -1 flip signs, a NaN or infinite volume spreads to every sample (characterized, not endorsed: obs_source_volume_snap() keeps those volumes out of the mix since #2108), a NaN sample keeps its payload; - a vol_data fade across the tick, channel by channel the way multiply_vol_data() calls it, for 1, 2 and 8 channels; - an action's step (0.75, then mute at frame 300), negative samples after it -0.0; - vol_data with special values in every position and counts 0 to 1023. Not covered: a NaN sample times a NaN volume, whose payload depends on how the C is compiled (operand order, scalar or vector). Deliberate breaks of the moved C, 11 mutants (both ends of each loop, the stride, the operator, the vol_data start and step, a rounding nudge, -0.0 lost, the volume's sign): all 11 caught. Refs #3080. Co-Authored-By: Claude Opus 5.5 <[email protected]>
RED for #3080. obs_source::volume_mul has its API and docs, with todo!() bodies: mul_block() (one volume over a slice, multiply_output_audio()) and mul_data() (a volume per sample, multiply_vol_data(); the shorter slice counts). tests/source/volume_mul.rs: - steps_*: test_source_volume_mul_steps.c 1:1 (6 cases, same names, buffers, values and expectations); - edge_*: mul_data() with slices of different lengths, empty slices, and proptests of both kernels against one multiply per sample (special values, any bit pattern, ordinary values) and of any input without a panic. A NaN sample times a NaN volume takes any NaN, as the C does not pin its payload. All 10 fail on the stubs (obs-tests-core, source::volume_mul). Refs #3080. Co-Authored-By: Claude Opus 5.5 <[email protected]>
GREEN for #3080. obs_source::volume_mul implements the two kernels: - mul_block(): `*sample *= vol` for every sample of the slice; - mul_data(): `*sample *= *v` over the slices, so the shorter one counts and the rest of `out` stays. Loops on slices, which cannot overlap, so LLVM vectorizes them without std::arch (#3007); GCC at -O2, as libobs ships, leaves the C loops scalar. The loop form of mul_data() depends on the target, chosen by platform::GROUPED_AUDIO_LOOPS (cfg!(target_arch = "x86_64")), because LLVM unrolls the two forms differently there: - x86_64: 4-sample groups. The plain zip loop was 17 % slower than GCC's vectorized C at -O3 (Ryzen 9 5950X); the grouped loop is 3 %. - aarch64: a plain zip loop. The grouped loop is one vector per iteration and was 49 % slower than clang's C (Apple M1 Max); the zip loop is level with it. Both forms are #[doc(hidden)] pub (mul_data_grouped, mul_data_zipped), and Tier 1 checks on every host that they agree. The module denies clippy::todo now too. No intentional differences: each sample is the C's one IEEE single multiply. A NaN sample times a NaN volume may carry either payload, as in the C, where -O0 and vectorized -O2 builds already differ. C ABI (ffi::source_volume_mul): obs_source_volume_mul_block() and obs_source_volume_mul_data() build slices of exactly `count` samples (nothing for a count of 0, so a null pointer with 0 is fine, as in the C). libobs: obs-source-volume-mul.c.h moves from libobs.core-source to its own group libobs.ported-source-volume-mul (registered in build/ported-source-sets/source-volume-mul.json), whose precompiled header includes only the unit's header. The hybrid libobs leaves the group out and links the shims; the two symbols are listed in rust-exports.map, rust-hidden.txt and rust-unexports-macos.txt and stay hidden. ci/test_ported_sources.py lists the object. Tier 1: 10/10 (obs-tests-core, source::volume_mul). Refs #3080. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 3 for #3080. obs-c-oracle builds the original libobs/obs-source-volume-mul.c.h as oracle_obs_source_volume_mul_* (oracle/source_volume_mul.c). tests/source/volume_mul_parity.rs runs every call on the shim, the C and the core, on copies of two mixes laid out as allocate_audio_output_buffer() lays them out, and compares the whole buffer bit for bit, the samples past the count included: - every count from 0 to 70, the ticks of 1 to 8 channels and both mixes; - 21 special and edge bit patterns (zeros, ones, infinities, NaNs with payloads and signs, denormals, the largest finite, powers of two, -10 dB) as samples against each as a volume, at a whole tick and a count of 37, and as rotating vol_data; - 64 rounds of random bit patterns at random counts; - a proptest over any samples, volumes and count. No intentional differences. A NaN sample times a NaN volume matches any NaN: the C's payload there depends on how it is compiled. 4 tests. Deliberate breaks of the core (14: a skipped first, last or second sample, the volume's sign, add for multiply, -0.0 lost, a clamp, the vol_data offset or start, one volume for all, a short count): all 14 caught here and by Tier 1. port_comparison (audio_mix, one mix of one tick, scaled down and back up), Apple M1 Max, Apple clang (which vectorizes the C too): block stereo Rust 250 ns, C 319 ns (noisy, 256-395); block 8 channels Rust 893 ns, C 892 ns; vol_data stereo Rust 291 ns, C 294 ns. Release assembly on aarch64: both shims multiply 16 samples per iteration (four fmul.4s). Refs #3080. Co-Authored-By: Claude Opus 5.5 <[email protected]>
rust/README.md: the obs-source crate row lists obs-source-volume-mul.c.h, and its own row says what moved, what obs-source.c keeps, why the block call spans the mix's channels, the vectorization (#3007), the NaN-times- NaN payload neither side pins, and what Tier 3 and the bench cover. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. No docs/features.md line: no user-visible change. Refs #3080. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=d44e83ee7c436b1a2a9d8e33d7d94430f1de1944 secs=420 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a Ci-Attestation: {"at":1793383895,"gate":"rust/all/fmt","host":"linux-x86_64","key":"4efe63ebe3acdca441691c6fe67100f8b9b074a7384e83d5dde403b821f4d23a","lane":"lint","parents":["0800a21922050b2ef3e23505bb586f7eabc181c1"],"secs":78,"stamp":"18661d2739b33c2cd30792ce69114fd5","tree":"d44e83ee7c436b1a2a9d8e33d7d94430f1de1944","v":1,"via":"run"} Ci-Attestation: {"at":1793383895,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"4efe63ebe3acdca441691c6fe67100f8b9b074a7384e83d5dde403b821f4d23a","lane":"lint","parents":["0800a21922050b2ef3e23505bb586f7eabc181c1"],"secs":78,"stamp":"430ac319a12b0fc4ac0800ea1c1181be","tree":"d44e83ee7c436b1a2a9d8e33d7d94430f1de1944","v":1,"via":"run"} Ci-Attestation: {"at":1793383895,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"18e7c01990b58fe5c5f66445c47ac04133216aaf0352061309711a3144734a5a","lane":"rust-test","parents":["0800a21922050b2ef3e23505bb586f7eabc181c1"],"secs":202,"stamp":"19711bd13be0639fadef7855fb15027e","tree":"d44e83ee7c436b1a2a9d8e33d7d94430f1de1944","v":1,"via":"run"} Ci-Attestation: {"at":1793383895,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"c28cbafd5ecf8d5dcccae323557643b1e9acb8d80ba4d821cdc9bdd9ef592f2e","lane":"cross","parents":["0800a21922050b2ef3e23505bb586f7eabc181c1"],"secs":140,"stamp":"905dcaa2b70cb39f72c2bcb47537c0e2","tree":"d44e83ee7c436b1a2a9d8e33d7d94430f1de1944","v":1,"via":"run"} Ci-Attestation: {"at":1793383895,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"c28cbafd5ecf8d5dcccae323557643b1e9acb8d80ba4d821cdc9bdd9ef592f2e","lane":"cross","parents":["0800a21922050b2ef3e23505bb586f7eabc181c1"],"secs":140,"stamp":"a2bee8c86fbe7345263c33077d426e4b","tree":"d44e83ee7c436b1a2a9d8e33d7d94430f1de1944","v":1,"via":"run"} Ci-Attestation: {"at":1793383895,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"c28cbafd5ecf8d5dcccae323557643b1e9acb8d80ba4d821cdc9bdd9ef592f2e","lane":"cross","parents":["0800a21922050b2ef3e23505bb586f7eabc181c1"],"secs":140,"stamp":"94a80a286613c93493c122c1566fd3f2","tree":"d44e83ee7c436b1a2a9d8e33d7d94430f1de1944","v":1,"via":"run"} Ci-Attestation: {"at":1793383895,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"c28cbafd5ecf8d5dcccae323557643b1e9acb8d80ba4d821cdc9bdd9ef592f2e","lane":"cross","parents":["0800a21922050b2ef3e23505bb586f7eabc181c1"],"secs":140,"stamp":"80d8472b2f8fdd2d00ce3daf6dc16e09","tree":"d44e83ee7c436b1a2a9d8e33d7d94430f1de1944","v":1,"via":"run"} Ci-Attestation: {"at":1793383895,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"19dd1496d0d1de3fd404eed1e529c68502949eb24f42f7b470062428d7540ad8","lane":"tier2-linux","parents":["0800a21922050b2ef3e23505bb586f7eabc181c1"],"secs":243,"stamp":"7ac1b592455347ef04d2437c5ad9db59","tree":"d44e83ee7c436b1a2a9d8e33d7d94430f1de1944","v":1,"via":"run"}
zackees
force-pushed
the
rust/3080-source-volume-mul
branch
from
October 30, 2026 19:13
1eae853 to
0cd6f5a
Compare
Member
zackees
enabled auto-merge
October 30, 2026 19:14
MCPVOT
pushed a commit
to MCPVOT/obs-studio
that referenced
this pull request
Oct 30, 2026
…#3103) edge_downmix_model ran 4000 full-size cases unscaled and hit nextest's 30 s limit on master b083524 (run 41121995484) and in the merge queue for obs-rust#3075 and obs-rust#3093. Route the block through obs_c_oracle::parity::cases() like the other proptest modules, so PR, queue and master runs take the reduced count (obs-rust#2593); local, nightly and release runs keep 4000.
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 #3080
What
The two volume multiply kernels of
libobs/obs-source.c.hmove tolibobs/obs-source-volume-mul.c.hand are ported torust/obs-source(modulevolume_mul). The hybrid libobs links the Rust shims in place of the C (grouplibobs.ported-source-volume-mul). The kernels are two hidden functions on plain pointers and counts:obs_source_volume_mul_block():multiply_output_audio(), one volume over a whole mix.apply_audio_volume()passes it as one block ofAUDIO_OUTPUT_FRAMES * channelssamples from the mix's first channel; a mix's channels are consecutive inallocate_audio_output_buffer()'s one allocation.obs_source_volume_mul_data():multiply_vol_data()'s inner loop, one channel by a volume per frame, whenapply_audio_actions()applies an action inside the tick.obs-source.c.hkeeps the rest, in its order:get_source_volume();vol_datafill and the memset;Vectorization (#3007): the safe core runs loops on slices, which cannot overlap, so LLVM vectorizes them with no
std::arch. In the release build on aarch64, both shims multiply 16 samples per iteration (fourfmul.4s). GCC 14 at-O2, which builds the Linux release, leaves both C loops scalar.mul_datauses a different loop form on x86_64 and aarch64; see Numbers.NaN payloads: each sample is the C's one IEEE single multiply. The one case neither side pins is a NaN sample times a NaN volume. There the C itself gives the sample's payload at
-O0and the volume's when vectorized at-O2. The tests accept any NaN there.No intentional differences.
Commits
Extraction 8f9d516: behaviour-neutral. A scratch harness (not committed) compared master's two loops with the moved functions:
The only differences were NaN payloads where both operands are NaN, which differ between builds of the C itself.
Characterization 90ed333:
test_source_volume_mul_steps, 6 cases on buffers laid out as libobs lays them out, with a canary after every count. It catches all 11 planted mutants of the C.RED b29adbf: the core with
todo!()bodies and 10 Tier 1 tests:steps_*: the cmocka cases 1:1;edge_*: slices of different lengths, proptests against one multiply per sample, no panic on any input.All 10 fail. GREEN adds an 11th: both loop forms of
mul_dataagree on every host.GREEN efbb19f: the core (with the per-target loop form of
mul_data), two C ABI shims and the ported group. The symbols are inrust-exports.map,rust-hidden.txtandrust-unexports-macos.txtand stay hidden.Tier 3 0800a21: the oracle build of the original C, and 4 parity tests comparing the shim, the C and the core bit for bit, the samples past the count included:
It also adds the
port_comparisonbenchaudio_mix/source_volume_*. All 14 planted mutants of the core are caught by Tier 1 and by Tier 3.Docs 1eae853: the
rust/README.mdrows.naming.mdalready mapsobs-source*.c.h. Nodocs/features.mdline: no user-visible change.Numbers
port_comparison, one mix of one tick. Rust/C below 1: the Rust is faster.Against the C as it ships (libobs
RelWithDebInfo; the Rust staticlib is Cargorelease,opt-level = 3):-O2(scalar)source_volume_block/stereosource_volume_block/8_channelssource_volume_data/stereo-O2(vectorized)source_volume_block/stereosource_volume_block/8_channelssource_volume_data/stereo/O2(vectorized)source_volume_block/stereosource_volume_block/8_channelssource_volume_data/stereoAgainst GCC's vectorized C at
-O3(the oracle's level, not shipped), x86:source_volume_block/stereosource_volume_block/8_channelssource_volume_data/stereox86:
taskset -c 27, functions and loops aligned on both sides, two runs within 1 %. macOS and Windows: not pinned; Windows is the mean of two runs in a VM, which vary by up to 7 %.Why
mul_datahas a different loop on x86_64 and aarch64. LLVM vectorizes both loop forms but unrolls them differently, and the faster form differs per target: on x86_64 the zip loop was 17 % behind GCC's-O3C and 4-sample groups are 3 %; on aarch64 the groups run one vector per iteration and were 49 % behind clang's C (437.9 ns), the zip loop level with it. Somul_datawalks 4-sample groups on x86_64 and is a zip loop on aarch64, chosen by onecfg!(target_arch = "x86_64")constant insrc/platform/mod.rs(GROUPED_AUDIO_LOOPS). Both forms are#[doc(hidden)] pub, and Tier 1 checks on every host that they agree.mul_blockis one stream and a zip loop everywhere. Same finding as #3079.Tests
volume_mulTier 1 and Tier 3, 15/15 in 0.5 s. The cmocka test passes 6/6 with ASan/UBSan at -O0 and -O2.test_source_volume_mul_steps6/6,source::volume_mulTier 1 and Tier 3 15/15 against the MSVC oracle.test_source_volume_mixruns the real libobs mix on the hybrid libobs in Tier 2.Checklist
master🤖 Generated with Claude Code