XAudio2: refuse invalid decoded buffers before they reach the decoder #1210
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1219"
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?
Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T13:19:12Z.
For a decoded source voice (XMA or Opus, played through a Windows PCM16 voice),
submit_decoded_bufferdecoded the title's buffer first and only then passed the PCM to Windows'SubmitSourceBuffer. When Windows refused it, only XCL's copy of the PCM was dropped, and the decoder kept its new state: XMA packets consumed, the overlap tail held, the initial skip used up, and onEND_OF_STREAMa flush. The title gets the error back and submits the buffer again, which is then decoded against a stream that has already eaten it. XMA packets are fed twice, and an Opus end of stream is flushed twice.Microsoft's documentation of
SubmitSourceBuffergives two refusals that can be seen before decoding: more thanXAUDIO2_MAX_QUEUED_BUFFERS(64) buffers queued, and aLoopCountthat is neither 1–XAUDIO2_MAX_LOOP_COUNT(254) norXAUDIO2_LOOP_INFINITE(255). Windows' xaudio2_9 returnsXAUDIO2_E_INVALID_CALLfor both; the new test checks that on the unchanged path. These two are now refused before the decoder sees the buffer. The queue count comes from the voice's ownGetState(XAUDIO2_VOICE_NOSAMPLESPLAYED), since XCL's buffer list shrinks only inOnBufferEnd.What is in it
crates/xcl/src/hle/xaudio2.rs:submit_decoded_buffer;refused_decoded_submit_leaves_the_decoder_untouched, which skips without an audio device. It covers aLoopCount300 buffer, and a 65th buffer while 64 are queued. After each refusal, the next accepted buffer must decode to the same PCM as a decoder that never saw the refused one;xma2_source_voice_decodes_and_manages_lifetime, which counts the global XMA statistics.Tested
cargo test --workspace -- --test-threads=4on4a01d21: 742 passed, 0 failed, 41 ignored; no SKIPPED GPU tests (the audio test ran; an audio device is present)cargo test -p xcl --lib xaudio2passes, 10 passedRegression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:47:04Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Note: the full
d3d12xlib filter currently aborts with 0xc0000005 on unmodifiedmaintoo (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:05:30Z.
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
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:42:38Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:11:30Z.
merge-check claim
head:
4a01d21172Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:19:48Z.
merge-check
base:
86e86fcb33head:
4a01d21172merge: clean
build: cargo build --workspace -> ok; the lib test target does not compile (below)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> did not run:
cargo teststops aterror[E0308]: mismatched typesincrates/xcl/src/hle/xaudio2.rs:1752of the merge result, in the new testrefused_decoded_submit_leaves_the_decoder_untouched: the closurepcm_ofis declared-> Vec<u8>and returnsb._pcm.to_vec(), which isVec<i16>on current main. 0 tests ran. The base alone, same run: 2889 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache).review: blocking: the merge is textually clean but the PR's own test no longer compiles against
main, so the suite cannot run on the merge result (the PR's green CI is from an older base). The comparison two lines below (pcm_of(0x11) == wantwithwantbuilt as bytes) needs the same adjustment. The runtime part was read and looks right for what it says:submit_decoded_bufferreturnsXAUDIO2_E_INVALID_CALLfor aLoopCountabove 254 that is not 255, and when the voice already has 64 queued buffers, before the decoder sees the data; it asks the real voice withGetState(XAUDIO2_VOICE_NOSAMPLESPLAYED), one extra call per decoded submit. Not tested here for the reason above.performance: one extra
GetStatecall per submit to a decoded (XMA / Opus) voice; not measured.verdict: not yet: the new test does not compile after merging into current main (xaudio2.rs:1752,
Vec<i16>whereVec<u8>is declared); needs a rebase and a rerunhardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:09:30Z.
Triage (#1607) – head
4a01d21No open or merged PR makes the same change: main's
submit_decoded_buffer(hle/xaudio2.rs) still decodes before XAudio2 can refuse the buffer, and #1698 only uses the 64-buffer limit for its GetState context queue. The 38 added lines that also appear on main are test boilerplate (engine/voice setup), not the fix.Minor: the queue-depth check reads
GetStateand then submits, so two threads submitting to the same voice concurrently could still both pass at 63 queued; harmless for single-threaded submitters.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.