XAudio2: a voice at a reused address drops the stale decoder's state #456

Open
github-bot wants to merge 2 commits from github-bot/gh-456 into main AGit
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 00:31 UTC · original
DavidM1911:xaudio2-voice-aba → main · +65 −10 · 1 files · 2 commits · open

Fixes #328.

An IXAudio2 engine released without DestroyVoice on its voices leaves their entries in XMA / DECODED_VOICES (and DECODED_LIVE_COUNT incremented, the DecodedCallback leaked). When Windows hands the same address to a later CreateSourceVoice, the new voice inherited them: a plain PCM voice's SubmitSourceBuffer calls were fed to the stale Opus/XMA decoder. evict_voice() now forgets both tables on every successful create, on the decoded path (create_decoded_voice) and the plain/silent path, before the new entry is inserted. destroy_voice shares the same take/release helpers, so teardown is unchanged.

What is in it

  • crates/xcl/src/hle/xaudio2.rs: take_decoded_voice / release_decoded_handle / evict_voice helpers; evict_voice called after *pp on both create paths; destroy_voice refactored onto the helpers; one unit test that plants stale XMA + DECODED_VOICES entries at a fake voice address and checks both maps and the live count after eviction.

Tested

  • Windows 11, Ryzen 9 7900X (Radeon iGPU gfx1036 + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 x86_64-pc-windows-msvc, debug build:
    • cargo test -p xcl --lib xaudio2: 10 passed, 0 failed (includes the new test; the real-engine XAudio2 tests also pass)
    • cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored
    • SKIPPED on the RTX 3060 Ti run: the 2 no wave64 recompiler GPU tests (ran on the iGPU in the #42 report)
  • Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, scripts/smoke.ps1 -Seconds 60, cargo build --release -p xcl:

main a6f5f7a:

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1473 (PresentX 1473)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14459 MB

this PR's head 00f0fd5 (rerun after a first cold-cache pass showed 685 frames; warm-cache numbers below):

xcl-smoke v1
commit: 00f0fd5e08420abac8e000988ea7f919634d466f
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1487 (PresentX 1487)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14443 MB

Not tested

  • AMD adapter smoke run (suite ran on both adapters, smoke only on the RTX 3060 Ti)
  • An actual engine-teardown-then-reuse sequence on a real title (the hazard is timing-dependent; the unit test covers the eviction itself)

AI use

  • Devin (SWE-2 Flash Medium): implemented the fix and test, ran the suites and smoke runs.
**@⁠DavidM1911** on GitHub · 2026-11-24 00:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/456) `DavidM1911:xaudio2-voice-aba` → `main` · +65 −10 · 1 files · 2 commits · open Fixes #328. An `IXAudio2` engine released without `DestroyVoice` on its voices leaves their entries in `XMA` / `DECODED_VOICES` (and `DECODED_LIVE_COUNT` incremented, the `DecodedCallback` leaked). When Windows hands the same address to a later `CreateSourceVoice`, the new voice inherited them: a plain PCM voice's `SubmitSourceBuffer` calls were fed to the stale Opus/XMA decoder. `evict_voice()` now forgets both tables on every successful create, on the decoded path (`create_decoded_voice`) and the plain/silent path, before the new entry is inserted. `destroy_voice` shares the same take/release helpers, so teardown is unchanged. **What is in it** - `crates/xcl/src/hle/xaudio2.rs`: `take_decoded_voice` / `release_decoded_handle` / `evict_voice` helpers; `evict_voice` called after `*pp` on both create paths; `destroy_voice` refactored onto the helpers; one unit test that plants stale `XMA` + `DECODED_VOICES` entries at a fake voice address and checks both maps and the live count after eviction. **Tested** - Windows 11, Ryzen 9 7900X (Radeon iGPU gfx1036 + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 `x86_64-pc-windows-msvc`, debug build: - `cargo test -p xcl --lib xaudio2`: 10 passed, 0 failed (includes the new test; the real-engine XAudio2 tests also pass) - `cargo test --workspace -- --test-threads=4`: 677 passed, 0 failed, 41 ignored - SKIPPED on the RTX 3060 Ti run: the 2 `no wave64` recompiler GPU tests (ran on the iGPU in the #42 report) - Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, `scripts/smoke.ps1 -Seconds 60`, `cargo build --release -p xcl`: main `a6f5f7a`: ``` xcl-smoke v1 commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212 gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1473 (PresentX 1473) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14459 MB ``` this PR's head `00f0fd5` (rerun after a first cold-cache pass showed 685 frames; warm-cache numbers below): ``` xcl-smoke v1 commit: 00f0fd5e08420abac8e000988ea7f919634d466f gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1487 (PresentX 1487) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14443 MB ``` **Not tested** - AMD adapter smoke run (suite ran on both adapters, smoke only on the RTX 3060 Ti) - An actual engine-teardown-then-reuse sequence on a real title (the hazard is timing-dependent; the unit test covers the eviction itself) **AI use** - Devin (SWE-2 Flash Medium): implemented the fix and test, ran the suites and smoke runs.
An IXAudio2 engine released without DestroyVoice on its voices leaves
their entries in XMA / DECODED_VOICES (and DECODED_LIVE_COUNT
incremented, the DecodedCallback leaked). When Windows hands the same
address to a later CreateSourceVoice, the new voice inherited them: a
plain PCM voice's SubmitSourceBuffer calls were fed to the stale Opus /
XMA decoder. evict_voice() forgets both tables on every successful
create, on the decoded and the plain paths; destroy_voice shares the
same take/release helpers. Fixes part of #328.

Assisted-by: Devin (SWE-2 Flash Medium)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:22:24 +00:00
Author
Owner

@⁠mastrr9 on GitHub · 2026-11-24 01:02 UTC · original

Code audit + NVIDIA RTX 5080 test run on 00f0fd5e08420abac8e000988ea7f919634d466f (fixes #328):

Review

Looks clean — evict_voice is called on both create_decoded_voice and create_source_voice before inserting new entries, and sharing take_decoded_voice / release_decoded_handle with destroy_voice keeps the teardown logic in one place.

  • (Tiny non-blocking nit: in evict_voice_drops_stale_entries_at_a_reused_address, asserting DECODED_LIVE_COUNT == 0 could flake if another test in xaudio2::tests ever holds a live decoded voice concurrently under --test-threads=4; comparing against a pre-test snapshot or delta would avoid that.)

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), rustc 1.100.0 (MSVC), debug build.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored.
  • New test hle::xaudio2::tests::evict_voice_drops_stale_entries_at_a_reused_address: passed.
  • SKIPPED GPU tests (2, wave32-only adapter): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.

Not tested

  • Retail title / scripts/smoke.ps1 run (test suite only).
  • AMD / Intel GPUs.

AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.

**@⁠mastrr9** on GitHub · 2026-11-24 01:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/456#issuecomment-7118687052) Code audit + NVIDIA RTX 5080 test run on `00f0fd5e08420abac8e000988ea7f919634d466f` (fixes #328): ### Review Looks clean — `evict_voice` is called on both `create_decoded_voice` and `create_source_voice` before inserting new entries, and sharing `take_decoded_voice` / `release_decoded_handle` with `destroy_voice` keeps the teardown logic in one place. - *(Tiny non-blocking nit: in `evict_voice_drops_stale_entries_at_a_reused_address`, asserting `DECODED_LIVE_COUNT == 0` could flake if another test in `xaudio2::tests` ever holds a live decoded voice concurrently under `--test-threads=4`; comparing against a pre-test snapshot or delta would avoid that.)* ### Tested - Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), `rustc 1.100.0` (MSVC), debug build. - `cargo build --workspace && cargo test --workspace -- --test-threads=4`: **677 passed, 0 failed, 41 ignored**. - New test `hle::xaudio2::tests::evict_voice_drops_stale_entries_at_a_reused_address`: **passed**. - `SKIPPED` GPU tests (2, wave32-only adapter): `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64`. ### Not tested - Retail title / `scripts/smoke.ps1` run (test suite only). - AMD / Intel GPUs. *AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.*
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 01:06 UTC · original

Re-ran the regression smoke on the new head 017515c (test-only change per review — dropped the global DECODED_LIVE_COUNT assert that raced parallel Opus/XMA2 tests; the per-address assertions stay). RTX 3060 Ti, GTA VI 1.0.2.1, 60 s:

xcl-smoke v1
commit: 017515ca0b8f92354c4d06db550e93dcc1aa0288
gpu: NVIDIA GeForce RTX 3060 Ti
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1497 (PresentX 1497)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14449 MB

cargo test -p xcl --lib xaudio2: 10 passed, 0 failed.

**@⁠DavidM1911** on GitHub · 2026-11-24 01:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/456#issuecomment-7118768402) Re-ran the regression smoke on the new head `017515c` (test-only change per review — dropped the global `DECODED_LIVE_COUNT` assert that raced parallel Opus/XMA2 tests; the per-address assertions stay). RTX 3060 Ti, GTA VI 1.0.2.1, 60 s: ``` xcl-smoke v1 commit: 017515ca0b8f92354c4d06db550e93dcc1aa0288 gpu: NVIDIA GeForce RTX 3060 Ti title: GTA6.Xbox.v1.0.2.1-CYBERLEEK seconds: 60 exit: 0x0 frames shown: 1497 (PresentX 1497) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14449 MB ``` `cargo test -p xcl --lib xaudio2`: 10 passed, 0 failed.
Author
Owner

@⁠alpz1000 on GitHub · 2026-11-24 01:40 UTC · original

Independent parallel XAudio2 test check at PR head 017515ca0b8f92354c4d06db550e93dcc1aa0288, including the follow-up that removes the global live-count assertion.

Tested on Windows 11 Home 26200.9974, Intel Core i5-8400, Rust 1.100.0 x86_64-pc-windows-msvc, debug. cargo test --locked -p xcl --lib xaudio2 -- --test-threads=4 --nocapture passed all 10 tests, including the reused-address eviction regression and the tests using system XAudio2. Then I ran that same lib test executable with xaudio2 --test-threads=4 in 20 fresh processes. All 20 runs passed all 10 tests with no skips.

Not tested: the prior revision's failure rate, full workspace, retail gameplay, or an actual engine-teardown/address-reuse sequence. The stale-address regression uses synthetic state.

AI use: OpenAI Codex (GPT-6) ran the local tests and drafted the report.

**@⁠alpz1000** on GitHub · 2026-11-24 01:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/456#issuecomment-7119330295) Independent parallel XAudio2 test check at PR head `017515ca0b8f92354c4d06db550e93dcc1aa0288`, including the follow-up that removes the global live-count assertion. **Tested** on Windows 11 Home 26200.9974, Intel Core i5-8400, Rust 1.100.0 x86_64-pc-windows-msvc, debug. `cargo test --locked -p xcl --lib xaudio2 -- --test-threads=4 --nocapture` passed all 10 tests, including the reused-address eviction regression and the tests using system XAudio2. Then I ran that same lib test executable with `xaudio2 --test-threads=4` in 20 fresh processes. All 20 runs passed all 10 tests with no skips. **Not tested**: the prior revision's failure rate, full workspace, retail gameplay, or an actual engine-teardown/address-reuse sequence. The stale-address regression uses synthetic state. **AI use**: OpenAI Codex (GPT-6) ran the local tests and drafted the report.
Author
Owner

@⁠ryosen0 on GitHub · 2026-11-24 01:57 UTC · original

Serial-test confirmation on NVIDIA: head 017515c merged onto main 508a0c7 (clean), with #468 and #508 also applied. RTX 3060 Ti 8 GB, Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11.

  • cargo test -p xcl --lib -- --test-threads=1 title_textures xaudio2 acphal: 27 passed, 0 failed - the stale-decoder eviction test passes with the global live-count assert removed (the removal is right: the count is process-global, parallel tests legitimately move it).
  • With --test-threads=1 the xaudio2 set is stable here; the race the removed assert caught was test-only, as the review said.

Not tested: a retail voice-reuse scenario end-to-end (no audible check).

AI use: GPT-6.2 Astra (API model selector) in DSH ran the tests and wrote this comment; the human contributor reviewed it.

**@⁠ryosen0** on GitHub · 2026-11-24 01:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/456#issuecomment-7119614431) Serial-test confirmation on NVIDIA: head `017515c` merged onto `main` `508a0c7` (clean), with #468 and #508 also applied. RTX 3060 Ti 8 GB, Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11. - `cargo test -p xcl --lib -- --test-threads=1 title_textures xaudio2 acphal`: **27 passed, 0 failed** - the stale-decoder eviction test passes with the global live-count assert removed (the removal is right: the count is process-global, parallel tests legitimately move it). - With `--test-threads=1` the xaudio2 set is stable here; the race the removed assert caught was test-only, as the review said. Not tested: a retail voice-reuse scenario end-to-end (no audible check). AI use: GPT-6.2 Astra (API model selector) in DSH ran the tests and wrote this comment; the human contributor reviewed it.
Author
Owner

@⁠woreksami on GitHub · 2026-11-24 02:16 UTC · original

Test report: on this machine this PR is what made the title's sound continuous (the choppy sound from #260).

Tested

  • NVIDIA GeForce RTX 3060 8 GB, driver 610.88 · Intel i9-14900K · 32 GB · Windows 11 (26200) · release build · XCL_NETWORK=0, XCL_PSO_WAIT_MS=150, XCL_DXC_THREADS unset
  • The newer retail title from the README, 1.0.2.1.
  • Before, main 508a0c7 + #214, #267, #300, #503, #468: narration and loading-screen music cut out after 1–2 s, in every run.
  • After, main 9ce2070 + #214 (960162e), #267 (043d1f7), #300 (9507d05), #503 (78f5510), #468 (0d407cf), #572 (14d638a) + this PR (017515c): three runs, the sound was continuous through the menus and the loading screen ("pretty much all of it", by ear). This PR is the only audio change between the two trees.
  • xapu still logs a single 1 Opus packets decoded line per run in both trees, so the continuous sound does not come through that path here.
  • cargo test --release -p xcl --lib on the merged tree: 658 passed, 0 failed, 21 ignored.

Not tested

  • This PR alone on top of main (the before/after trees also differ by #451 and #572); AMD; a meter on the audio output (heard by ear only); the workspace suite and scripts/smoke.ps1.

AI use

  • Claude Code with Claude Opus 5.5: built the branches, ran the title, read the logs and wrote this report from those runs; the listening was done by me.
**@⁠woreksami** on GitHub · 2026-11-24 02:16 UTC · [original](https://github.com/xcl-dev/xcl/pull/456#issuecomment-7119946326) Test report: on this machine this PR is what made the title's sound continuous (the choppy sound from #260). **Tested** - NVIDIA GeForce RTX 3060 8 GB, driver 610.88 · Intel i9-14900K · 32 GB · Windows 11 (26200) · release build · `XCL_NETWORK=0`, `XCL_PSO_WAIT_MS=150`, `XCL_DXC_THREADS` unset - The newer retail title from the README, 1.0.2.1. - Before, `main` 508a0c7 + #214, #267, #300, #503, #468: narration and loading-screen music cut out after 1–2 s, in every run. - After, `main` 9ce2070 + #214 (960162e), #267 (043d1f7), #300 (9507d05), #503 (78f5510), #468 (0d407cf), #572 (14d638a) + this PR (017515c): three runs, the sound was continuous through the menus and the loading screen ("pretty much all of it", by ear). This PR is the only audio change between the two trees. - `xapu` still logs a single `1 Opus packets decoded` line per run in both trees, so the continuous sound does not come through that path here. - `cargo test --release -p xcl --lib` on the merged tree: 658 passed, 0 failed, 21 ignored. **Not tested** - This PR alone on top of `main` (the before/after trees also differ by #451 and #572); AMD; a meter on the audio output (heard by ear only); the workspace suite and `scripts/smoke.ps1`. **AI use** - Claude Code with Claude Opus 5.5: built the branches, ran the title, read the logs and wrote this report from those runs; the listening was done by me.
Author
Owner

@⁠shdann on GitHub · 2026-11-24 00:47 UTC · original · reviewed

crates/xcl/src/hle/xaudio2.rs:1843 asserts that the process has zero decoded voices after the test removes its own voice. The Opus and XMA2 lifetime tests in the same binary can each hold a decoded voice at that point. With parallel tests, eviction can succeed and the count can still be one. The preceding two assertions already check removal of this voice by address. Please keep those assertions and check the global count in an isolated test process if counter coverage is needed. Static review of 00f0fd5 with OpenAI Codex (GPT-6).

**@⁠shdann** on GitHub · 2026-11-24 00:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/456#pullrequestreview-6031899473) · **reviewed** `crates/xcl/src/hle/xaudio2.rs:1843` asserts that the process has zero decoded voices after the test removes its own voice. The Opus and XMA2 lifetime tests in the same binary can each hold a decoded voice at that point. With parallel tests, eviction can succeed and the count can still be one. The preceding two assertions already check removal of this voice by address. Please keep those assertions and check the global count in an isolated test process if counter coverage is needed. Static review of `00f0fd5` with OpenAI Codex (GPT-6).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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 origin '+refs/pull/456/head:github-bot/gh-456'
git switch 'github-bot/gh-456'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-456'
git switch 'github-bot/gh-456'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-456'
git switch 'github-bot/gh-456'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-456'
git switch 'main'
git merge --squash 'github-bot/gh-456'
git switch 'main'
git merge --ff-only 'github-bot/gh-456'
git switch 'main'
git merge 'github-bot/gh-456'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.