Skip to content

XAudio2: under Wine GetState names the oldest queued buffer of a voice XCL does not decode - #1698

Draft
shortside wants to merge 2 commits into
xcl-dev:mainfrom
shortside:xaudio2/getstate-undecoded-voices
Draft

shortside wants to merge 2 commits into
xcl-dev:mainfrom
shortside:xaudio2/getstate-undecoded-voices

Conversation

@shortside

@shortside shortside commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #890; only the top commit (e2ee5c0) belongs here.

#890 makes GetState name the oldest queued buffer of a decoded voice when the host names none. @pablogonz12's run of it (#890 (comment)) showed the same gap one check further in the test title: Opus GetState: ctx=0x0, queued=1 under Wine without libopus, where the voice plays silence and is not a decoded one. It is wider than that: under Wine any source voice XCL does not decode reads so before it starts, a plain PCM voice too (two buffers queued: 2 queued, context 0, on CrossOver 26.3).

Under Wine only, XCL now keeps the contexts submitted to such a voice (at most the 64 a voice can hold) and answers a null current context with buffers queued from them. On Windows nothing is kept and nothing is asked: the host answers.

What is in it (crates/xcl/src/hle/xaudio2.rs, +193 / -3 with the tests)

  • QUEUED: voice → the contexts submitted, oldest first; note_submitted, oldest_queued (the host's queued buffers are the last ones submitted, so with N queued it is the N-th from the end), note_flushed (a flush keeps the playing buffer, the oldest of those queued).
  • submit_source_buffer: on the path that is not decoded (PCM passed through, or silence), a submit the host took is noted. flush_source_buffers: asks the host its queue before and after. destroy_voice: drops the record. All three only with util::under_wine().
  • get_state: after the decoded voices' branch (unchanged in what it does; it now returns), a null context with buffers queued is answered from QUEUED.
  • Tests: queued_contexts_follow_submits_and_flushes (the record alone, any host) and get_state_names_the_oldest_buffer_of_a_voice_that_is_not_decoded (a PCM voice on the real engine: two queued and not started names the first; after they have played, a third names itself).

Tested

  • MacBook Pro M5 Pro, macOS 27.2.1, Rosetta 2; CrossOver 26.3 (Wine 11.0), Windows 10 bottle; Rust 1.100.0, cross-built for x86_64-pc-windows-msvc with clang-cl / lld-link 23.1.6 and an xwin SDK 10.0.26100, debug. The lib test binary run under Wine. Base main c160d86 + XAudio2: GetState names the oldest queued buffer when the host gives none #890's commit.
  • hle::xaudio2:: --test-threads=1, 3 runs at the head: 11 passed, 0 failed every run.
  • The engine test with the QUEUED answer in get_state switched off (a local edit, reverted), 2 runs: failed, left: (2, 0), right: (2, 20481) ("two queued, not started"; 20481 is the context 0x5001). With it on: passed. So the test fails without the change on this host.

Regression run

main:

xcl-smoke v1
commit: 85e38262ff94aecd75d6f83fa8156a8b7697bd13
gpu: NVIDIA GeForce RTX 4080 SUPER
title: t1
seconds: 60
exit: 0x0
frames shown: 1333 (PresentX 1333)
presents per 2 s (last 3): 11 21 49
device removals: 0
crashes: 0
peak commit: 25722 MB

this PR:

xcl-smoke v1
commit: e2ee5c0fc24ffa9d5cf9d27bfcfe7f5408460d3a
gpu: NVIDIA GeForce RTX 4080 SUPER
title: t1
seconds: 60
exit: 0x0
frames shown: 1235 (PresentX 1235)
presents per 2 s (last 3): 44 47 60
device removals: 0
crashes: 0
peak commit: 27346 MB

Not tested

  • The test title's Opus GetState check itself: main does not get that far on this host (D3DMetal). The silent voice goes through the same branch of submit_source_buffer as the PCM voice tested here; a Wine host without libopus that runs the title can confirm it.
  • Windows: no run. The engine test should pass there without the new path (the host names the buffer); nobody has run it yet.
  • The whole suite, GPU tests, any title.
  • A flush the host carries out later than the call: covered in the record's test (the last N submitted are still the right ones), not on a real engine.

AI use

  • Claude Code with Claude Fable 5.2: found the wider case, wrote the change, the tests and this description, and ran the tests above on my machine.

🤖 Generated with Claude Code

shortside and others added 2 commits November 24, 2026 20:20
…none

Under Wine (CrossOver 26.3), GetState on a decoded (XMA / Opus) source
voice that has buffers queued but has not started returns
BuffersQueued = 2 and pCurrentBufferContext = NULL. Windows names the
first queued buffer there, and xma2_source_voice_decodes_and_manages_lifetime
checks for it (left 0, right 0x3003).

XCL submits its decoded buffers with a non-null token as the context, so
a null current context with buffers queued means the host did not say.
Each decoded buffer now carries its submission number, and GetState
names the oldest one that has not ended. When the host returns a context,
the mapping is unchanged, so Windows is not affected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e XCL does not decode

Wine's XAudio2 counts the buffers of a source voice that has not started
but names no current one, where Windows names the first queued buffer.
The change before this one answers that for decoded (XMA / Opus) voices
from their own record. A voice XCL does not decode has none: plain PCM,
and the silence that stands in for XMA / Opus without a decoder (the test
title's "Opus GetState: ctx=0x0, queued=1" under Wine without libopus). A
PCM voice with two buffers queued reads (2 queued, context 0) under
CrossOver 26.3.

Under Wine only, the contexts submitted to such a voice are kept, oldest
first and at most the 64 a voice can hold; the host's queued buffers are
the last ones submitted, so a null current context with N queued is the
N-th from the end. FlushSourceBuffers keeps what the host kept, and
DestroyVoice drops the record. On Windows nothing is kept and nothing is
asked: the host answers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@papasmurph0

Copy link
Copy Markdown

Regression run for this PR on Windows / NVIDIA, since it has no xcl-smoke pair yet.

Tested

main:

xcl-smoke v1
commit: 85e38262ff94aecd75d6f83fa8156a8b7697bd13
gpu: NVIDIA GeForce RTX 4080 SUPER
title: t1
seconds: 60
exit: 0x0
frames shown: 1333 (PresentX 1333)
presents per 2 s (last 3): 11 21 49
device removals: 0
crashes: 0
peak commit: 25722 MB

this PR:

xcl-smoke v1
commit: e2ee5c0fc24ffa9d5cf9d27bfcfe7f5408460d3a
gpu: NVIDIA GeForce RTX 4080 SUPER
title: t1
seconds: 60
exit: 0x0
frames shown: 1235 (PresentX 1235)
presents per 2 s (last 3): 44 47 60
device removals: 0
crashes: 0
peak commit: 27346 MB

Both runs started from the same state (the title's settings already saved, so no first-run screens). The PR's run is within the limits: 93 % of main's frames, 106 % of its peak commit, no crash, no device removal. A first run of this PR right after the title had saved its settings, paired with a main run that still showed the first-run screens, is left out: the two did not start from the same state.

Not tested: Wine; on native Windows the host's XAudio2 names its buffers, so the PR's branch is not reached and this is a regression check only.

AI use: Claude Code (Claude Opus 5.5) built the trees, made the runs on my PC and wrote this report; I asked for it to be posted.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.

Thanks!

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.

3 participants