XAudio2: write decoded XMA samples directly into interleaved PCM #521

Open
wileyGray wants to merge 1 commit from upstream-pr/526 into main
wileyGray commented 2026-11-24 01:20:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by wileyGray on 2026-11-24T01:20:00Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5464253684 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/526). Originally posted by [wileyGray](https://github.com/wileyGray) on 2026-11-24T01:20:00Z. --- 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: ```powershell 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.
DTsordas commented 2026-11-24 10:04:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DTsordas on 2026-11-24T09:44:17Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7127820018 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/526#issuecomment-7127820018). Originally posted by [DTsordas](https://github.com/DTsordas) on 2026-11-24T09:44:17Z. --- **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 commented 2026-11-25 03:05:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T02:57:14Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7151410561 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/526#issuecomment-7151410561). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T02:57:14Z. --- 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 commented 2026-11-25 14:10:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T13:43:22Z.


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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7164193475 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/526#issuecomment-7164193475). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T13:43:22Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
github-actions[bot] commented 2026-11-29 07:43:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:43:41Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7252652631 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/526#issuecomment-7252652631). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T07:43:41Z. --- 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.
Foniass commented 2026-12-01 03:39:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:39:46Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7299936299 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/526#issuecomment-7299936299). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:39:46Z. --- **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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/526:upstream-pr/526'
git switch 'upstream-pr/526'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/526'
git switch 'upstream-pr/526'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/526'
git switch 'upstream-pr/526'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/526'
git switch 'main'
git merge --squash 'upstream-pr/526'
git switch 'main'
git merge --ff-only 'upstream-pr/526'
git switch 'main'
git merge 'upstream-pr/526'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!521
No description provided.