Skip to content

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

Open
DavidM1911 wants to merge 2 commits into
xcl-dev:mainfrom
DavidM1911:xaudio2-voice-aba
Open

DavidM1911 wants to merge 2 commits into
xcl-dev:mainfrom
DavidM1911:xaudio2-voice-aba

Conversation

@DavidM1911

@DavidM1911 DavidM1911 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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:
  • 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 xcl-dev#328.

Assisted-by: Devin (SWE-2 Flash Medium)

@shdann shdann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

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.

@DavidM1911

Copy link
Copy Markdown
Contributor Author

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.

@alpz1000

Copy link
Copy Markdown

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.

@ryosen0

ryosen0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@woreksami

Copy link
Copy Markdown

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

Tested

Not tested

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XAudio2: stale voice-pointer reuse (ABA) when an IXAudio2 engine is released with live voices

6 participants