perf(hle/audio): offload APU Opus decoding and DSP convolution to worker threads (Wave 8B) #424

Manually merged
github merged 0 commits from github-bot/gh-424 into gh-pr/424/base 2026-12-04 07:35:43 +00:00 AGit
Owner

@⁠Androtim on GitHub · 2026-12-04 05:30 UTC · original
Androtim:perf/audio-offload-apu-dsp → main · +1460 −92 · 2 files · 2 commits · merged 2026-12-04 07:30 UTC

Summary

Ports Wave 8B (\ReTerryDavis/ReVIctory\ PR #37, \

**@⁠Androtim** on GitHub · 2026-12-04 05:30 UTC · [original](https://github.com/Androtim/MiniVI/pull/424) `Androtim:perf/audio-offload-apu-dsp` → `main` · +1460 −92 · 2 files · 2 commits · merged 2026-12-04 07:30 UTC ## Summary Ports **Wave 8B** (\ReTerryDavis/ReVIctory\ PR \#37\, \
Ported ReTerryDavis/ReVIctory PR #37 (073fc17, GPL-3.0) audio offload architecture to MiniVI while preserving MiniVI's sample-rate converter and mono DSP convolution fixes:

- APU (crates/victory-hle/src/modules/apu.rs):
  - Offload Opus decode and sample-rate conversion commands to a bounded worker thread pool (VICTORY_APU_ASYNC, on unless 0; VICTORY_APU_THREADS, default 4, 1..=16) with deterministic per-stream sharding (stream % threads) and THREAD_PRIORITY_HIGHEST.
  - Preserve command-order result dequeueing via AtomicBool Acquire/Release completion slots, panic isolation (catch_unwind), inline fallback on closed/failed send, and in-flight drain with 5s leak-safe timeout on XApuDisconnect.
- DSP (crates/victory-hle/src/modules/dsp.rs):
  - Offload computed mono 1024-frame convolution blocks to a bounded worker pool (VICTORY_DSP_ASYNC, on unless 0; VICTORY_DSP_THREADS, default 2, 1..=8), preserving VICTORY_DSP_CONVOLVE and VICTORY_DSP_GAIN.
  - Copy input blocks into bounded per-stream spare buffers for safe in-place convolution, isolate panics, publish status.completed after a Release fence, track late/overrun submissions, and drain in-flight blocks on XDspDeactivate.
- Global opt-out: VICTORY_AUDIO_OFFLOAD=0 disables both APU and DSP async offload.
- Process-wide pools live in OnceLock so ExitProcess never deadlocks on DllMain/atexit joins; owned WorkerPool instances cleanly close channels and join threads on shutdown/drop.
- Added unit tests for async command ordering, bit-for-bit async vs sync convolution with Acquire/Release fences, env opt-out parsing, and clean worker pool shutdown.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 05:34:29 +00:00
Addresses all 4 [P1] and 1 [P2] findings from Gate 2 audit on PR #424:

- APU [P1] #1 (premature SetEvent / lost wakeup): track FIFO (slot, signal)
  entries in Shared::pending_signals when RESULT_EVENT is enabled and fire
  SetEvent only once the contiguous completed FIFO prefix covers a SIGNAL
  command.
- APU [P1] #3 (cross-thread enqueue reordering): keep Connection::state
  locked across worker shard submission (and inline fallback) so shard
  execution order matches state.results FIFO order.
- DSP [P1] #2 (non-atomic Status data race & invalid fence pairing): switch
  Status fields to AtomicU32/AtomicI32 (preserving 16-byte #[repr(C)] ABI)
  with Relaxed result + Release completed stores and Acquire loads.
- DSP [P1] #4 (late in-place overrun buffer aliasing): track in-flight
  output byte ranges per stream and wait on the overrun path (in_flight > 0)
  when command.input overlaps an active worker output buffer while keeping
  disjoint double-buffered pipelining non-blocking.
- DSP [P2] #5 (test aliasing UB): mutate (*stream).asynchronous before
  creating shared &Stream borrow in worker_pool_clean_shutdown_drains_and_rejects_after_close.

Adds targeted unit tests covering each fixed race/edge case.
github-bot force-pushed github-bot/gh-424 from 1e14358884 to abd7b7cf1b 2026-12-04 05:55:43 +00:00 Compare
Author
Owner

@⁠Androtim on GitHub · 2026-12-04 06:01 UTC · original

Triage (abd7b7cf, CI IN_PROGRESS, MERGEABLE):

  • Clean, 100% title-neutral Wave 8B port (ReTerryDavis/ReVIctory #37, GPL-3.0, +1,460/-92 across apu.rs + dsp.rs, zero opt-in toggles — VICTORY_AUDIO_OFFLOAD, VICTORY_APU_ASYNC, and VICTORY_DSP_ASYNC are all default-on with =0 kill-switches): offloads Opus decoding (4 workers) and DSP reverb convolution (2 workers) onto dedicated threads.
  • Gate 2 Pure-Reasoning Re-Audit (#282): VERIFIED CLEAN (0 P0, 0 P1).
  • Marked triage: needs gpu test — awaiting CI check PASS + Gate 3 plain---release GPU verification (confirming zero audio regressions/deadlocks and CPU headroom win) before merging.
**@⁠Androtim** on GitHub · 2026-12-04 06:01 UTC · [original](https://github.com/Androtim/MiniVI/pull/424#issuecomment-7402998462) Triage (`abd7b7cf`, CI `IN_PROGRESS`, `MERGEABLE`): - Clean, 100% title-neutral Wave 8B port (`ReTerryDavis/ReVIctory` `#37`, GPL-3.0, `+1,460/-92` across `apu.rs` + `dsp.rs`, **zero opt-in toggles** — `VICTORY_AUDIO_OFFLOAD`, `VICTORY_APU_ASYNC`, and `VICTORY_DSP_ASYNC` are all default-on with `=0` kill-switches): offloads Opus decoding (`4` workers) and DSP reverb convolution (`2` workers) onto dedicated threads. - **Gate 2 Pure-Reasoning Re-Audit (`#282`):** `VERIFIED CLEAN (0 P0, 0 P1)`. - Marked `triage: needs gpu test` — awaiting CI `check` PASS + Gate 3 plain-`--release` GPU verification (confirming zero audio regressions/deadlocks and CPU headroom win) before merging.
github-bot changed target branch from main to gh-pr/424/base 2026-12-04 07:35:39 +00:00
github manually merged commit abd7b7cf1b into gh-pr/424/base 2026-12-04 07:35:42 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Androtim--MiniVI!424
No description provided.