XAudio2: GetState keeps the title's context for a buffer that just ended #2410
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2410
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2410"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@treybertram06 on GitHub · 2026-11-25 18:05 UTC · original
treybertram06:xaudio2-getstate-ended-context→main· +103 −7 · 1 files · 1 commits · openOn a decoded (XMA / Opus) source voice, XCL submits each buffer with its own token as the context and maps it back to the title's context in
GetState. If the buffer ends between XAudio2'sGetStateand XCL's lookup,OnBufferEndhas already removed the token fromlive_buffers. The title then gets the token, which is the address of a freedDecodedBuffer, aspCurrentBufferContext. Fixes #2386.Each voice now keeps its last 64 ended tokens together with the title's context.
OnBufferEndrecords a token under thelive_bufferslock, so a lookup always finds the token in one of the two. The issue suggests clearing the context to null on a miss. That would also clear the context of a buffer the title queued itself, which XCL never wraps, so a context XCL didn't make still passes through unchanged.What is in it
crates/xcl/src/hle/xaudio2.rs:end_bufferandtitle_context(live tokens, then recently ended ones), used bydecoded_cb_buffer_endandget_state;endedring. It holds each ended buffer's allocation, with its PCM freed, so a later buffer can't get the address of a token that's still kept (the ABA race from review);get_state_context_survives_buffer_end, which fails without the ring because the token comes back, andended_token_is_not_reused_by_a_later_buffer, which fails when the ring keeps only the address.Tested
cargo test -p xcl --lib xaudio2: 11 passed, 0 failed. Each new test fails without the part of the change it covers.cargo test --workspace --no-fail-fast -- --test-threads=4(XCL_DXC_DIRset to DXC 1.9), on the branch rebased ontomaine0d93c84: 1423 passed, 0 failed, 46 ignored.a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrierfailure wasmain's; #2420 fixed it.SKIPPED:no wave64;no heap windows;Regression run
The title used here decodes its audio through XAPU, so these runs do not reach the changed code (see Not tested).
Not tested
GetStateon an XMA / Opus voice while its buffers end, and the title in the regression run uses the XAPU path. The unit test covers the lookup afterOnBufferEnd, not XAudio2's own threads.AI use
@DavidM1911 on GitHub · 2026-11-25 19:28 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1 real failure, deterministic (also fails--test-threads=1, 1219/1):The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge.
— Devin
@ahmetbagci8 on GitHub · 2026-11-25 19:40 UTC · original
Tested
adf3f635be1eec43e0bf30383ffcb496fbdb565032.0.16.1714), Windows 11 Pro (Build 26300), DXCv1.9.2609cargo test -j 2 -p xcl --lib xaudio2 -- --test-threads=4:10 passed; 0 failed; 0 ignored (0.12s)Not tested
scripts/smoke.ps1(no unpacked title locally).AI use
@treybertram06 on GitHub · 2026-11-25 19:47 UTC · original
Thanks for running it. That failure isn't from this PR.
a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barriercame in with254a058onmain, andmain's own CI failed on it until #2420 (c828d8c) changed the test. The PR's CI run is red for the same reason.On
mainat06055a7, which includesc828d8c, with this branch (adf3f63) merged on top, on an RTX 3080:cargo test -p xcl --lib a_bridged_mask_write: 1 passed, 0 failedcargo test -p xcl --lib xaudio2: 10 passed, 0 failedThe diff only touches
hle/xaudio2.rs. If your checkout ofmainpredatesc828d8c, merging the currentmainshould clear it. I'll rebase the branch ontomainso CI runs again.(Checked and written with Claude Code, Claude Opus 5.5.)
@pablogonz12 on GitHub · 2026-11-25 19:56 UTC · original
Test report from Linux + Wine on AMD: this change does not fix #2386 on this lane, and the assertion it targets is reproducible here exactly. Prepared with AI assistance: DeepSeek V4.1 Flash in OpenCode; the commands were run by it and the output is pasted verbatim.
Setup
RADV GFX1201), AMD Radeon RX 9070 XT 16 GB, Ryzen 9 9900X.WINEDLLOVERRIDES="d3d12,d3d12core,dxgi,d3d11,d3d10core=n,b",VKD3D_CONFIG=ignore_shared_fence,WINEDEBUG=-all, DXC 1.9.2609.5.RUSTFLAGS="-C target-feature=+crt-static" cargo xwin test --workspace --release --target x86_64-pc-windows-msvc --no-run; runwine <xcl lib exe> --test-threads=1 xaudio2andwine <e2e exe> --test-threads=1.main2898511with this PR merged on top (clean merge, only this PR differs), head = adf3f63.Result
2898511xaudio2(lib filter)e2e(integration)The new test passes (
get_state_context_survives_buffer_endis the +1). The failure that matters is unchanged, and it is not the ended-buffer race:GetStatereturns a null context at the first call, while both buffers are still queued.Base,
crates/xcl/src/hle/xaudio2.rs:1599:Same assertion on this PR (line 1626 after the added code), same values:
left: 0,right: 12291(0x3003=CTX_VALID).assert_eq!({ st.buffers_queued }, 2)passes just above it, so the context is lost betweenSubmitSourceBufferandGetState, not atOnBufferEnd.The e2e test title shows the same thing, on base and on this PR alike:
(its other
[FAIL]on this lane is the window-cloak check, which Wine cannot satisfy). So the ring for ended tokens does not cover what happens here: on Wine the context is already null before any buffer ends. Two ways that could be Wine-only, worth ruling out before this is read as a Windows bug: no audio device in the prefix (playback may complete immediately), or the decoded path ending the buffer duringSubmit.Not tested
GetStatenull happens there is what would decide if this is a Wine-only difference).AI use
@treybertram06 on GitHub · 2026-11-25 20:08 UTC · original
Thanks, that's useful, but it's a different problem from #2386. The failing test,
xma2_source_voice_decodes_and_manages_lifetime, fails the same way on your base without this PR, and it passes on Windows: 10/10xaudio2tests on an RTX 3080 (here) and on a 3070 (ahmetbagci8 above). As you say, the context is null at the firstGetState, before any buffer ends, so the ended-token ring isn't involved. That looks like Wine's XAudio2 (FAudio) not reportingpCurrentBufferContextfor a voice that hasn't been started; Windows' XAudio2 reports the head buffer's context there. It could be worth its own issue for the Wine lane. This PR only covers the race in #2386: a token read just beforeOnBufferEnd.(Claude Code, Claude Opus 5.5.)
@treybertram06 on GitHub · 2026-11-25 21:49 UTC · original
@bmjask Thanks, that's right. Fixed in
4767b1a, squashed into the commit.endednow holds the endedDecodedBuffers themselves, not(token, context)copies. Their PCM is freed, but the allocation stays in the ring until it is evicted. While a token can still be looked up, no buffer submitted after it can get that address. A stale token from aGetStatethat racedOnBufferEndtherefore resolves to its own buffer's context, never a newer one's. Voice teardown clears the ring along withlive_buffers.ended_token_is_not_reused_by_a_later_buffer: it ends A, submits more buffers as anOnBufferEndcallback would, and checks two things. The ring holds A's own allocation, and no later buffer gets A's address. Whether the heap would hand a freed address straight back is up to the allocator, so the hold is asserted directly. With the ring keeping copies instead of the allocations, the test fails on that assertion.GetStatereading the context and the hook's lookup, but I can make it time-based if you'd rather.Tested on
4767b1a(RTX 3080, driver 621.40, Windows 11 26300):cargo test -p xcl --lib xaudio2: 11 passed, 0 failed.cargo test --workspace --no-fail-fast -- --test-threads=4: 1423 passed, 0 failed, 46 ignored.(Claude Code, Claude Opus 5.5.)
@DavidM1911 on GitHub · 2026-11-26 02:22 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.