Skip to content

XAudio2: write decoded XMA samples directly into interleaved PCM - #526

Draft
wileyGray wants to merge 1 commit into
xcl-dev:mainfrom
wileyGray:codex/xma-pcm-output
Draft

wileyGray wants to merge 1 commit into
xcl-dev:mainfrom
wileyGray:codex/xma-pcm-output

Conversation

@wileyGray

@wileyGray wileyGray commented Nov 24, 2026 •

Copy link
Copy Markdown

XAudio2 requests PCM16 from the XMA decoder. The decoder previously popped each sample from a channel queue into a float buffer, then allocated a second buffer and converted the entire result. Related to #459.

What is in it

  • Write each channel into its interleaved output positions, convert to the requested format as samples are written, and drain the channel queue once. The 5.1 test compares packet-by-packet PCM16 with a full float decode.

Tested

  • Windows 11 build 26300, i9-14900K, RTX 4080 SUPER (32.0.16.2114), Rust 1.93.0 MSVC. Debug cargo build --locked --workspace --offline passed. cargo test --workspace -- --test-threads=4 on cc09012 reported 680 passed, 0 failed, 41 ignored, including the end-to-end test title. Two GPU tests reported SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • All seven project XMA fixtures produced byte-identical float and PCM16 output on 508a0c7 and cc09012.
  • Median time in microseconds for a complete decode_buffer_i16(packet_data, true) call. Built both module versions with rustc --edition=2021 -O --test, pinned to the same logical CPU, warmed the decoder, then alternated baseline and patch order over 15 runs of 350 decodes per fixture. Inputs and outputs used std::hint::black_box.
Project fixture Main µs PR µs Time saved
XMA2 mono 50.59 40.89 19.2%
XMA2 stereo 61.28 51.40 16.1%
Variable subframes 45.83 40.47 11.7%
All coefficient paths 25.02 21.34 14.7%
XMA1 stereo 59.00 51.63 12.5%
Cross-packet 24.32 21.06 13.4%
5.1 surround 96.84 77.76 19.7%

Regression run

Retail regression evidence needed. A tester with any unpacked Xbox Series title can supply this pair; the title need not use XMA. In clean checkouts of upstream 508a0c74d7c0 and PR head cc09012b7e0b, run the following in each checkout, using the same game folder, machine and duration:

cargo build --release -p xcl
.\scripts\smoke.ps1 -Game 'D:\Games\YourTitle' -Seconds 60

Please attach the two generated xcl-smoke blocks to this PR, labeled main and PR, with the title version. Only the text output is needed. I can then update this section with the credited results.

For comparison, the repository's synthetic title passed all 50 checks on both commits with xcl run <game> -- --hello (exit 0). Unmodified scripts/smoke.ps1 launched the same fixture without its required --hello argument and recorded exit 1, one crash and zero device removals on both commits.

Not tested

  • Retail-title throughput, frame rate, and paired retail smoke runs. Optional game samples were unset. The D3D12 debug layer was unavailable.

AI use

  • Codex (gpt-6.2-astra) wrote and reviewed the patch, extended the test, ran the benchmarks and workspace suite, and drafted this description.

Drain synchronized channels in batches and convert each sample as it lands in the output buffer. This avoids a separate float buffer and a queue pop per sample. Compare streamed PCM16 against the full 5.1 float fixture.

Assisted-by: Codex (gpt-6.2-astra)
@DTsordas

Copy link
Copy Markdown

Test report for #526 at cc09012: AMD RDNA4 (native wave64), Windows

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 5 5600X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug; DXC 1.9.2602.17 (SDK 10.0.26100.0).
  • cargo build --workspace and cargo test --workspace -- --test-threads=4 at cc09012: 680 passed, 0 failed, 41 ignored, 0 SKIPPED. The two tests skipped on the RTX 4080 for lack of wave64 (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware) ran and passed here.
  • All 7 hle::xma2 tests pass, including the extended surround_5_1_interleaves_three_streams_and_isolates_channels and decodes_xma2_and_xma1_bitstreams_matching_ffmpeg.
  • cc09012 merged into current main 077ce40 (no conflicts): cargo test -p xcl --lib hle::xma2:: 7 passed, 0 failed.

Not tested

  • The regression run: there's no unpacked title on this machine yet, so no xcl-smoke blocks; the PR check still needs them.
  • Release build, and the whole suite on the merge with main (only the XMA tests there).

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of cc09012b on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: cc09012b7e0b598d62cfad39d53402634188d44b
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1459 (PresentX 1459)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14733 MB

Against the limits in CONTRIBUTING.md: 90 % of main's frames, 99 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@github-actions

Copy link
Copy Markdown

Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

@github-actions github-actions Bot added the stale No activity for 3 days; closed 4 days later unless something happens label Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head cc09012

No open or merged PR changes Decoder::drain_synchronized or decode_buffer_i16; #2683 avoids copies in xaudio2.rs, not in the XMA decoder. Read drain_synchronized against main's: it skips the same encoder-delay frames, interleaves in the same stream/channel order and drains min(emit_total + trim_tail, len) per FIFO as before, so output should be unchanged. The new 5.1 check compares packet-by-packet PCM16 with the float decode. No problems found in the diff (the failing check is the description check, which asks for the regression run).
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@github-actions github-actions Bot removed the stale No activity for 3 days; closed 4 days later unless something happens label Dec 2, 2026
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.

5 participants