You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: libobs: vectorize scene audio mixing and source volume multiply when ported #3007
Two per-tick audio loops that still run in C, because the Rust port moved only the decisions around them:
Scene audio mixing: libobs/obs-scene.c.h:1330,1341 (multiply-add into the output, every scene item every tick).
Source volume multiply: libobs/obs-source.c.h:4829,4838 (per source per tick).
Running today: the C (scalar).
Expected gain: low to medium.
Parity: the C is scalar, so the port must be bit-exact. A separate multiply and add (no FMA contraction) stays exact.
Acceptance criteria
When these loops are ported to Rust, the port ships with a vectorized element-wise kernel (checked in the assembly or written with std::arch in src/platform/) and a scalar fallback.
A bit-exact Tier 3 parity test.
A benchmark entry under audiomix (sub-issue 1).
Dependencies
Blocked on porting these loops. This issue tracks only the SIMD requirement for that port.
Failing-test sketch
RED: a Tier 3 parity test that calls the Rust kernel against the C oracle for random gains and buffers, failing against a stub.
Rules for this work (#756): portable stable Rust only (no std::simd/nightly), a scalar fallback with runtime CPU detection, ISA-specific code only in the crate's src/platform/ (Dylint ban_platform_cfg_outside_boundary). Tier 3 parity is bit-exact unless the C reference itself uses SIMD (docs/rust-port/testing-policy.md:296). RED then GREEN. Every kernel needs a benchmark in rust/tools/benchmarks/record.py first (sub-issue 1 of the meta issue).
Triage: not Ready. It applies when scene audio mixing and the source volume multiply (C obs-scene.c.h, obs-source.c.h) are ported to Rust, and it also needs #3003's baseline. It stays open as part of #3009 until then.
Vectorized kernel: LLVM vectorizes the safe cores' slice loops without std::arch, checked in the assembly: SSE on x86_64, NEON (fmul.4s, fadd.4s) on aarch64. Both baselines always have these, so there is no runtime detection and no separate scalar path. The loop form of the two-stream kernels (mix_add, mul_data) differs per target through one cfg!(target_arch = "x86_64") constant in each crate's src/platform/, because LLVM unrolls the two forms differently:
x86_64: a zip loop was 17–18 % behind GCC's vectorized C; 4-sample groups are within 2–3 %;
aarch64: 4-sample groups were 46–49 % behind clang's C; a zip loop is level.
Tier 1 checks on every host that both forms give the same bits.
Bit-exact Tier 3: yes, against the oracle without contraction, shim, C and core compared bit for bit. Where two NaNs meet, any NaN matches any NaN: IEEE 754 leaves the payload open, and x86 returns the first operand's.
Benchmark:audio_mix/scene_mix_* and audio_mix/source_volume_* in port_comparison.
Numbers against the C as it ships:
Linux, GCC 14 -O2: the C loops stay scalar, and the Rust is 3–4 times faster (scene_mix_add, whole tick: 65.9 ns against 237.2 ns).
macOS, clang: level.
Windows, MSVC /O2: 4 % faster to 14 % slower, measured in a VM.
The one gap left is mix_with_buf, 11–14 % behind vectorized C on x86 (GCC -O3, MSVC). No safe-Rust loop form I tried closed it. The PR texts have the details.
Vectorized kernel. Both are slice loops with no std::arch and no runtime detection, because SSE2 (x86_64) and NEON (aarch64) are baseline for every target this repo builds; LLVM vectorizes them, checked in the assembly by the port PRs (fmul.4s / fadd.4s on aarch64). The only per-target difference is the loop shape (platform::GROUPED_AUDIO_LOOPS), because LLVM unrolls the two-stream loops differently per target; Tier 1 checks that both forms give the same bits on every host. The separate scalar fallback the issue asks for is not needed where the ISA is a baseline, which is the same reasoning recorded on perf: guard: Rust replacements for swresample and swscale must ship with SIMD #3008.
Bit-exact Tier 3.rust/obs-scene/tests/scene/audio_mix_parity.rs and rust/obs-source/tests/source/volume_mul_parity.rs compare against the oracle built with -ffp-contract=off, so the multiply and add stay separate. NaNs match NaN regardless of payload (IEEE 754 leaves it open).
Measured now, soldr cargo bench -p obs-c-oracle --bench port_comparison -- audio_mix, this host (Ryzen 7 3700X, load average 25-38 from the other worker slots, so treat the absolute numbers as loaded and the Rust/C ratio as the signal; the C column moves with the Rust column):
Bench
Rust (median)
C (median)
Rust/C
audio_mix/mix_whole_tick
1.4253 µs
4.5481 µs
0.31
audio_mix/mix_from_frame_300
972.33 ns
3.3667 µs
0.29
audio_mix/time_to_frames
1.9222 ns
1.9840 ns
0.97
audio_mix/buffering_add_one_tick
51.383 ns
42.264 ns
1.22
audio_mix/output_tick/stereo_6_mixes
5.2984 µs
19.264 µs
0.28
audio_mix/scene_mix_with_buf/whole_tick
139.49 ns
462.36 ns
0.30
audio_mix/scene_mix_with_buf/from_frame_300
96.410 ns
330.28 ns
0.29
audio_mix/scene_mix_add/whole_tick
101.63 ns
365.24 ns
0.28
audio_mix/scene_mix_add/from_frame_300
66.404 ns
242.97 ns
0.27
audio_mix/source_volume_block/stereo
334.07 ns
330.49 ns
1.01
audio_mix/source_volume_block/8_channels
1.1833 µs
1.3746 µs
0.86
audio_mix/source_volume_data/stereo
409.41 ns
2.0968 µs
0.20
The scene mix and the source volume multiply are the two loops this issue tracks, and both are inside the 1.10x bound on this host (0.27-0.31 and 0.20-1.01). The one row over the bound is buffering_add_one_tick, which is not one of this issue's loops; it reproduced 1.22 / 1.19 / 1.30 over three runs and is filed separately as #3138 rather than kept here. Verifiable: gh issue view 3138.
Known remaining gap, already recorded on #3092 and #3093: mix_with_buf is 11-14 % behind vectorized C (-O3 GCC, MSVC) on x86; against the C as it ships (-O2), it is 0.29-0.30 of the C's time here. That is a performance follow-up, not this issue's acceptance criterion.
Activity
zackees commentedon Oct 30, 2026
Triage: not Ready. It applies when scene audio mixing and the source volume multiply (C
obs-scene.c.h,obs-source.c.h) are ported to Rust, and it also needs #3003's baseline. It stays open as part of #3009 until then.vpacher commentedon Oct 30, 2026
Both loops of this issue are ported, in two PRs (open, not merged yet):
mix_audio_with_buf()andscene_mix_audio()ofobs-scene.c.h, nowobs-scene::audio_mix;multiply_output_audio()andmultiply_vol_data()ofobs-source.c.h, nowobs-source::volume_mul.Against the acceptance criteria:
Vectorized kernel: LLVM vectorizes the safe cores' slice loops without
std::arch, checked in the assembly: SSE on x86_64, NEON (fmul.4s,fadd.4s) on aarch64. Both baselines always have these, so there is no runtime detection and no separate scalar path. The loop form of the two-stream kernels (mix_add,mul_data) differs per target through onecfg!(target_arch = "x86_64")constant in each crate'ssrc/platform/, because LLVM unrolls the two forms differently:Tier 1 checks on every host that both forms give the same bits.
Bit-exact Tier 3: yes, against the oracle without contraction, shim, C and core compared bit for bit. Where two NaNs meet, any NaN matches any NaN: IEEE 754 leaves the payload open, and x86 returns the first operand's.
Benchmark:
audio_mix/scene_mix_*andaudio_mix/source_volume_*inport_comparison.Numbers against the C as it ships:
-O2: the C loops stay scalar, and the Rust is 3–4 times faster (scene_mix_add, whole tick: 65.9 ns against 237.2 ns)./O2: 4 % faster to 14 % slower, measured in a VM.The one gap left is
mix_with_buf, 11–14 % behind vectorized C on x86 (GCC-O3, MSVC). No safe-Rust loop form I tried closed it. The PR texts have the details.This issue can close when both PRs merge.
obs-source: Port the source volume multiply kernels
docs: Record the source volume multiply port
obs-source: Port the source volume multiply kernels (obs-rust#3080) (o…
zackees commentedon Oct 31, 2026
Closing: both ports are on master and every acceptance criterion is met, verified on
origin/master3e17f5d0d(2026-10-31).rust/obs-scene/src/audio_mix.rs(mix_with_buf,mix_add) landed in obs-scene: Port the scene audio mix kernels (#3079) #3092 (d3ce1c892), andrust/obs-source/src/volume_mul.rs(mul_data,mul_block) in obs-source: Port the source volume multiply kernels (#3080) #3093 (f2e76ff3e).std::archand no runtime detection, because SSE2 (x86_64) and NEON (aarch64) are baseline for every target this repo builds; LLVM vectorizes them, checked in the assembly by the port PRs (fmul.4s/fadd.4son aarch64). The only per-target difference is the loop shape (platform::GROUPED_AUDIO_LOOPS), because LLVM unrolls the two-stream loops differently per target; Tier 1 checks that both forms give the same bits on every host. The separate scalar fallback the issue asks for is not needed where the ISA is a baseline, which is the same reasoning recorded on perf: guard: Rust replacements for swresample and swscale must ship with SIMD #3008.rust/obs-scene/tests/scene/audio_mix_parity.rsandrust/obs-source/tests/source/volume_mul_parity.rscompare against the oracle built with-ffp-contract=off, so the multiply and add stay separate. NaNs match NaN regardless of payload (IEEE 754 leaves it open).audio_mix/*inport_comparison(scene_audio_mix.rs,source_volume_mul.rs,audio.rs), measured byrecord.py --category audio_mix(chore: perf: benchmark the SIMD candidates in record.py (format conversion, volume meter, audio mix) #3003's baseline).Measured now,
soldr cargo bench -p obs-c-oracle --bench port_comparison -- audio_mix, this host (Ryzen 7 3700X, load average 25-38 from the other worker slots, so treat the absolute numbers as loaded and the Rust/C ratio as the signal; the C column moves with the Rust column):audio_mix/mix_whole_tickaudio_mix/mix_from_frame_300audio_mix/time_to_framesaudio_mix/buffering_add_one_tickaudio_mix/output_tick/stereo_6_mixesaudio_mix/scene_mix_with_buf/whole_tickaudio_mix/scene_mix_with_buf/from_frame_300audio_mix/scene_mix_add/whole_tickaudio_mix/scene_mix_add/from_frame_300audio_mix/source_volume_block/stereoaudio_mix/source_volume_block/8_channelsaudio_mix/source_volume_data/stereoThe scene mix and the source volume multiply are the two loops this issue tracks, and both are inside the 1.10x bound on this host (0.27-0.31 and 0.20-1.01). The one row over the bound is
buffering_add_one_tick, which is not one of this issue's loops; it reproduced 1.22 / 1.19 / 1.30 over three runs and is filed separately as #3138 rather than kept here. Verifiable:gh issue view 3138.Known remaining gap, already recorded on #3092 and #3093:
mix_with_bufis 11-14 % behind vectorized C (-O3GCC, MSVC) on x86; against the C as it ships (-O2), it is 0.29-0.30 of the C's time here. That is a performance follow-up, not this issue's acceptance criterion.