hle(dsp): replace O(N*TAPS) scalar convolution with partitioned overlap-save FFT (#17) #340

Merged
brainbudt merged 1 commit from upstream-pr/340 into main 2026-11-27 16:14:20 +00:00
brainbudt commented 2026-11-27 12:56:51 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by brainbudt on 2026-11-27T12:56:51Z.


Refs #17

VICTORY_GUESS_DSP=1 in crates/victory-hle/src/modules/dsp.rs previously ran a direct O(frames * TAPS) scalar convolution loop (4800 taps × 1024 frames × 2 channels ≈ 9.8M multiply-adds per block on the audio thread).

What this changes

  • Replaces the scalar convolution loop with a zero-dependency, uniformly partitioned overlap-save radix-2 FFT convolver (FftPlan + PartitionedConvolver) in crates/victory-hle/src/modules/dsp.rs.
  • Precomputes bit-reversal indices, twiddle factors, and IR partition spectra once at XDspActivate, and reuses all FDL/FFT scratch buffers across XDspSubmitCommand calls (zero heap allocations on the audio path, including when command.input == command.output via process_in_place).
  • Default behaviour (VICTORY_GUESS_DSP unset: silence) and VICTORY_DUMP_DSP / VICTORY_TRACE_DSP diagnostics are unchanged.

Tests

  • cargo test -p victory-hle --locked: 98 passed, 0 failed, including:
    • partitioned_fft_matches_scalar_reference_across_blocks_and_channels (exact comparison against the convolve_merged scalar reference across mono/stereo, multiple block sizes, and 12 consecutive blocks of 512 × 2 with TAPS = 4800, max error < 1e-3).
    • partitioned_fft_unit_impulse_reproduces_ir_across_partitions (unit impulse across multiple partition boundaries and per-channel gains).
    • partitioned_fft_in_place_matches_out_of_place (command.input == command.output aliasing).
  • cargo clippy --no-deps -p victory-hle --all-targets --locked: 0 warnings in dsp.rs.
  • cargo xtask policy: 376 files ok.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5527009595 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/340). Originally posted by [brainbudt](https://github.com/brainbudt) on 2026-11-27T12:56:51Z. --- Refs #17 `VICTORY_GUESS_DSP=1` in `crates/victory-hle/src/modules/dsp.rs` previously ran a direct `O(frames * TAPS)` scalar convolution loop (`4800` taps × `1024` frames × `2` channels ≈ 9.8M multiply-adds per block on the audio thread). ### What this changes - Replaces the scalar convolution loop with a zero-dependency, uniformly partitioned overlap-save radix-2 FFT convolver (`FftPlan` + `PartitionedConvolver`) in `crates/victory-hle/src/modules/dsp.rs`. - Precomputes bit-reversal indices, twiddle factors, and IR partition spectra once at `XDspActivate`, and reuses all FDL/FFT scratch buffers across `XDspSubmitCommand` calls (zero heap allocations on the audio path, including when `command.input == command.output` via `process_in_place`). - Default behaviour (`VICTORY_GUESS_DSP` unset: silence) and `VICTORY_DUMP_DSP` / `VICTORY_TRACE_DSP` diagnostics are unchanged. ### Tests - `cargo test -p victory-hle --locked`: 98 passed, 0 failed, including: - `partitioned_fft_matches_scalar_reference_across_blocks_and_channels` (exact comparison against the `convolve_merged` scalar reference across mono/stereo, multiple block sizes, and 12 consecutive blocks of `512 × 2` with `TAPS = 4800`, max error `< 1e-3`). - `partitioned_fft_unit_impulse_reproduces_ir_across_partitions` (unit impulse across multiple partition boundaries and per-channel gains). - `partitioned_fft_in_place_matches_out_of_place` (`command.input == command.output` aliasing). - `cargo clippy --no-deps -p victory-hle --all-targets --locked`: 0 warnings in `dsp.rs`. - `cargo xtask policy`: 376 files ok.
Olima34 commented 2026-11-27 13:28:50 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:28:50Z.


Check report: befb6a09 checked together with #337 and #340 merged onto main 60baf130 (M5 Pro 48 GB, arm64, with the converter):

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask: all pass (victory-hle 144 passed, main 141 with the new tests of both PRs; victory-gpu 347 passed).
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings: clean. cargo xtask policy: ok.
  • HLE only, so no sweep; not run in game.

Result: passes, and no review question is open. It can't be merged from my side (the branch rule requires an approving review), so it's ready for the maintainer. @brainbudt, one useful addition if you have time: a number for the speed-up (time per DSP block before/after for a typical IR length), since the tests show equivalence but not the gain.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219528279 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/340#issuecomment-7219528279). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T13:28:50Z. --- Check report: `befb6a09` checked together with #337 and #340 merged onto main `60baf130` (M5 Pro 48 GB, arm64, with the converter): - `cargo test -p victory-hle -p victory -p victory-gpu -p xtask`: all pass (victory-hle 144 passed, main 141 with the new tests of both PRs; victory-gpu 347 passed). - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings`: clean. `cargo xtask policy`: ok. - HLE only, so no sweep; not run in game. Result: passes, and no review question is open. It can't be merged from my side (the branch rule requires an approving review), so it's ready for the maintainer. @brainbudt, one useful addition if you have time: a number for the speed-up (time per DSP block before/after for a typical IR length), since the tests show equivalence but not the gain.
brainbudt commented 2026-11-27 13:53:27 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by brainbudt on 2026-11-27T13:53:27Z.


Note

🤖 Gemini 4 Neon responding on behalf of brainbudt

Measured --release time per DSP block (50 blocks after warmup, TAPS = 4800 / 100 ms at 48 kHz, Intel Core i7-1165G7, Linux x86_64) comparing convolve_merged (before) vs PartitionedConvolver::process (after):

Block (frames × ch) Scalar convolve_merged Partitioned FFT Speed-up
512 × 2 (10.7 ms audio) 4,854.3 µs 60.3 µs 80.5×
1024 × 2 (21.3 ms audio) 9,714.0 µs 115.9 µs 83.8×
1024 × 1 (21.3 ms audio) 4,835.6 µs 58.1 µs 83.3×

At 1024 × 2, per-block cost drops from ~46% of a 21.3 ms audio quantum to ~0.5% per stream, with zero heap allocations on the audio path.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7220070538 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/340#issuecomment-7220070538). Originally posted by [brainbudt](https://github.com/brainbudt) on 2026-11-27T13:53:27Z. --- > [!NOTE] > 🤖 **Gemini 4 Neon responding on behalf of brainbudt** Measured `--release` time per DSP block (`50` blocks after warmup, `TAPS = 4800` / 100 ms at 48 kHz, Intel Core i7-1165G7, Linux x86_64) comparing `convolve_merged` (before) vs `PartitionedConvolver::process` (after): | Block (`frames × ch`) | Scalar `convolve_merged` | Partitioned FFT | Speed-up | | --- | ---: | ---: | ---: | | `512 × 2` (10.7 ms audio) | `4,854.3 µs` | `60.3 µs` | **80.5×** | | `1024 × 2` (21.3 ms audio) | `9,714.0 µs` | `115.9 µs` | **83.8×** | | `1024 × 1` (21.3 ms audio) | `4,835.6 µs` | `58.1 µs` | **83.3×** | At `1024 × 2`, per-block cost drops from ~46% of a 21.3 ms audio quantum to ~0.5% per stream, with zero heap allocations on the audio path.
LakshanSivakumar commented 2026-11-27 16:15:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:15:14Z.


Merged in 4cf84c83. Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. I did not listen for the reverb itself. Thanks.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223040251 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/340#issuecomment-7223040251). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:15:14Z. --- Merged in 4cf84c83. Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. I did not listen for the reverb itself. Thanks.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!340
No description provided.