[pr-fix][audio] audio: split XMA voice and ring locks with round-robin block pumping #714

Open
ggwp wants to merge 1 commit from ggwp/Darner:fix/audio-xma-locks into post-merge
Contributor

Contributor role (optional)

  • Fluxer ID: FomalhautCusimanse#7381

What it changes

Port of the XMA locking/pumping update from newer upstream CNF (larp-hle/src/modules/audio.rs):

  • The problem on post-merge: Each XMA context guarded both its decoding state and its output ring behind a single Mutex<Option<Voice>>. The title sends ACP commands from its time-critical mixer thread, while the XMA decoder runs at ordinary thread priority — if the decoder thread is preempted while holding the voice lock, the time-critical mixer thread blocks waiting for decoding (priority inversion), causing audio stalls/dropouts and frame-pacing hiccups.

  • Fix:

    • Splits each context into a Slot with two narrow locks: ring: Mutex<Taken> (held only over the shared ring read/write pointers, taken briefly once per decoded block so read commands never wait on decoding) and voice: Mutex<Option<Voice>> (held for at most one decoded block at a time).
    • Pumps voices round-robin one block at a time (Xma::pump), so when many rings empty simultaneously (e.g. after a load), every active voice receives its first block before any receives its second.

How it was tested

  • Tested revision: e6f1156 (based on post-merge 28a9b42; also run in-game in a combined build on AMD Radeon 8060S and RX 9070 XT)
  • Commands and results:
    • cargo test --offline -p darner-hle --lib audio — passed
    • cargo clippy --offline -p darner-hle --tests — passed
    • cargo build --offline --release -p darner — succeeded (combined build)
  • Changes a default: yes (internal XMA lock granularity and round-robin scheduling; no user-facing switch).
  • A/B result: Tested in-game on AMD Radeon 8060S and AMD Radeon RX 9070 XT inside a combined test build — clean audio playback with no lockups or regressions.
  • Checks run on e6f1156: cargo test, cargo clippy (passed).
  • Gameplay: AMD Radeon 8060S (64 GB) and AMD Radeon RX 9070 XT (16 GB), Series X, combined build.
  • Hardware dependence: general (CPU/audio thread scheduling across all GPUs).
  • Coverage gaps: No dedicated stress benchmark for XMA mixer overrun counts.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on post-merge.
  • The diff contains no game files, code or assets.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #702 (touches dsp.rs only; this PR touches audio.rs only, no overlap).
  • Replaces or overlaps: none found.
## Contributor role (optional) - Fluxer ID: FomalhautCusimanse#7381 ## What it changes Port of the XMA locking/pumping update from newer upstream CNF (`larp-hle/src/modules/audio.rs`): - **The problem on `post-merge`:** Each XMA context guarded both its decoding state and its output ring behind a single `Mutex<Option<Voice>>`. The title sends ACP commands from its time-critical mixer thread, while the XMA decoder runs at ordinary thread priority — if the decoder thread is preempted while holding the voice lock, the time-critical mixer thread blocks waiting for decoding (priority inversion), causing audio stalls/dropouts and frame-pacing hiccups. - **Fix:** - Splits each context into a `Slot` with two narrow locks: `ring: Mutex<Taken>` (held only over the shared ring read/write pointers, taken briefly once per decoded block so read commands never wait on decoding) and `voice: Mutex<Option<Voice>>` (held for at most one decoded block at a time). - Pumps voices round-robin one block at a time (`Xma::pump`), so when many rings empty simultaneously (e.g. after a load), every active voice receives its first block before any receives its second. ## How it was tested - Tested revision: `e6f1156` (based on `post-merge` `28a9b42`; also run in-game in a combined build on AMD Radeon 8060S and RX 9070 XT) - Commands and results: - `cargo test --offline -p darner-hle --lib audio` — passed - `cargo clippy --offline -p darner-hle --tests` — passed - `cargo build --offline --release -p darner` — succeeded (combined build) - Changes a default: yes (internal XMA lock granularity and round-robin scheduling; no user-facing switch). - A/B result: Tested in-game on AMD Radeon 8060S and AMD Radeon RX 9070 XT inside a combined test build — clean audio playback with no lockups or regressions. - Checks run on `e6f1156`: `cargo test`, `cargo clippy` (passed). - Gameplay: AMD Radeon 8060S (64 GB) and AMD Radeon RX 9070 XT (16 GB), Series X, combined build. - Hardware dependence: general (CPU/audio thread scheduling across all GPUs). - Coverage gaps: No dedicated stress benchmark for XMA mixer overrun counts. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `post-merge`. - [x] The diff contains no game files, code or assets. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #702 (touches `dsp.rs` only; this PR touches `audio.rs` only, no overlap). - Replaces or overlaps: none found.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/audio-xma-locks:ggwp-fix/audio-xma-locks'
git switch 'ggwp-fix/audio-xma-locks'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'post-merge'
git merge --no-ff 'ggwp-fix/audio-xma-locks'
git switch 'ggwp-fix/audio-xma-locks'
git rebase 'post-merge'
git switch 'post-merge'
git merge --ff-only 'ggwp-fix/audio-xma-locks'
git switch 'ggwp-fix/audio-xma-locks'
git rebase 'post-merge'
git switch 'post-merge'
git merge --no-ff 'ggwp-fix/audio-xma-locks'
git switch 'post-merge'
git merge --squash 'ggwp-fix/audio-xma-locks'
git switch 'post-merge'
git merge --ff-only 'ggwp-fix/audio-xma-locks'
git switch 'post-merge'
git merge 'ggwp-fix/audio-xma-locks'
git push origin 'post-merge'
Sign in to join this conversation.
No reviewers
No milestone
No project
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
TrustNo1/Darner!714
No description provided.