Skip to content

XAudio2: compute mixed stereo and mono XMA2WAVEFORMATEX stream layouts - #2032

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1488-xma2-stream-layout
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1488-xma2-stream-layout

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

Fixes StreamConfig::from_xma2_wfx in crates/xcl/src/hle/xma2/mod.rs so standard XMA2WAVEFORMATEX headers (cbSize == 34) accept valid mixed stereo + mono multi-stream layouts where ceil(channels / 2) < num_streams < channels (such as 5.1 4-stream [2, 2, 1, 1], 4.0 3-stream [2, 1, 1], 5.0 4-stream [2, 1, 1, 1], and 7.1 5/6-stream). Part of #1488 (XCL-BT-015).

Previously, whenever num_streams != channels, from_xma2_wfx assigned 2 channels to every stream i with (i + 1) * 2 <= channels and 1 otherwise. For valid mixed stereo/mono layouts like (channels = 6, num_streams = 4), that assigned [2, 2, 2, 1] (sum 7 != 6) and rejected the header with XMA2 stream count 4 does not match 6 channels. Because each XMA2 stream holds 1 or 2 channels, any feasible (channels, num_streams) pair with num_streams <= channels <= num_streams * MAX_CHANNELS_PER_STREAM uniquely has stereo = channels - num_streams 2-channel streams and num_streams - stereo 1-channel streams.

What is in it

  • crates/xcl/src/hle/xma2/mod.rs:
    • In StreamConfig::from_xma2_wfx (extradata.len() == 34), validate ch < num_streams || ch > num_streams * MAX_CHANNELS_PER_STREAM and assign stereo = ch - num_streams 2-channel streams followed by 1-channel streams (subsuming the num_streams == channels special case while preserving packed, NumStreams == 0 default, and invalid stream-count behavior).
    • Add stream_config_xma2_wfx_assigns_mixed_stereo_and_mono_streams covering valid mixed stereo/mono layouts, Decoder::new construction, invalid stream counts, and an end-to-end 4-stream 5.1 ([2, 2, 1, 1]) interleaved decode verified against standalone stereo and mono reference decodes.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 4060 (8 GB, 32-lane waves, driver 621.14), Intel Core i5-11400F, 32 GB RAM, Windows 11 Home build 26200, Rust 1.100.0 (0ef1bc386), DXC 1.9.2609.5 (01b62ad4), release build.
  • Pre-fix reproduction: confirmed hle::xma2::tests::stream_config_xma2_wfx_assigns_mixed_stereo_and_mono_streams fails without the fix (channels=4 streams=3: XMA2 stream count 3 does not match 4 channels).
  • Targeted post-fix runs (0 failures, 0 skipped):
    • cargo test --release -p xcl --lib hle::xma2::tests -- --nocapture: 8 passed, 0 failed, 0 ignored.
    • cargo test --release -p xcl --lib hle::xaudio2 -- --nocapture: 9 passed, 0 failed, 0 ignored.
  • cargo build --release --workspace + cargo test --release --workspace -- --test-threads=4: 1063 passed, 0 failed, 45 ignored across 20 test binaries.
  • SKIPPED GPU/runtime tests on this adapter (24 lines):
    • 19 no wave64 subcases across gpu::recomp::lower::tests (4), gpu::recomp::lower_dxil::tests (13), and gpu::recomp::tests (2)
    • 3 intentional per-lane #1426 refusals (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32) in gpu::recomp::lower_dxil::tests
    • shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required)
    • heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows

Regression run
scripts/smoke.ps1 on main (656c0e8ca070bdc9d7cb197d264792ef49304865) and on this PR's head commit (b32eadfea2c6897bc41b2e4a90ae58c30e25ba56):

xcl-smoke v1
commit: 656c0e8ca070bdc9d7cb197d264792ef49304865
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1576 (PresentX 1576)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14703 MB
xcl-smoke v1
commit: b32eadfea2c6897bc41b2e4a90ae58c30e25ba56
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1581)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14733 MB

Not tested

  • Retail title assets specifically using mixed stereo/mono 4-stream 5.1 or 5/6-stream 7.1 XMA2WAVEFORMATEX headers beyond the synthetic 4-stream 5.1 bitstream decode test.
  • Non-standard stream orderings (e.g., mono streams preceding stereo streams), which XMA2WAVEFORMATEX cannot encode because it carries only NumStreams and no per-stream XMA2STREAMFORMAT table.
  • AMD/Intel GPUs, native wave64 hardware, and debug-profile full workspace test run (the full suite ran in --release).

AI use

  • Google Antigravity (Gemini 4 Neon) — analyzed StreamConfig::from_xma2_wfx, implemented the layout calculation fix, unit and 4-stream 5.1 decode regression tests, and PR description; all tests and paired 60s smoke runs were executed and verified locally on RTX 4060 hardware.

In `StreamConfig::from_xma2_wfx`, standard `XMA2WAVEFORMATEX` headers
(`cbSize == 34`) previously assigned 2 channels to every stream `i` with
`(i + 1) * 2 <= channels` whenever `num_streams != channels`. For valid
multi-stream layouts mixing stereo and mono streams where
`ceil(channels / 2) < num_streams < channels` (such as 5.1 4-stream
`[2, 2, 1, 1]`, 4.0 3-stream `[2, 1, 1]`, 5.0 4-stream `[2, 1, 1, 1]`,
or 7.1 5/6-stream), that assigned too many 2-channel streams and
rejected the header with a channel-count mismatch (`XCL-BT-015`).

Validate `num_streams <= channels <= num_streams * MAX_CHANNELS_PER_STREAM`
and assign `stereo = channels - num_streams` 2-channel streams followed
by 1-channel streams, subsuming the all-mono special case while keeping
packed and invalid stream counts unchanged. Add unit and end-to-end
4-stream 5.1 decode regression tests.

Part of xcl-dev#1488

Assisted-by: Google Antigravity (Gemini 4 Neon)
@raylitebull

Copy link
Copy Markdown
Member

Code review on b32eadf:

  • StreamConfig::from_xma2_wfx in crates/xcl/src/hle/xma2/mod.rs cleanly validates ch < num_streams || ch > num_streams * MAX_CHANNELS_PER_STREAM and partitions stereo = ch - num_streams (2 channels) followed by mono streams (1 channel), supporting mixed stereo + mono XMA2WAVEFORMATEX layouts (cbSize == 34) such as [2, 2, 1, 1].
  • stream_config_xma2_wfx_assigns_mixed_stereo_and_mono_streams thoroughly covers valid packed, mixed, all-mono, and invalid channel/stream combinations plus an end-to-end 5.1 4-stream decode against stereo/mono reference packets.
  • PR description is green and Build and test (Windows, no GPU) is currently running.

Remaining before merge: Build and test finishing green plus dual-vendor (AMD + NVIDIA) / independent test verification on b32eadf.

@JJAutoCompare

Copy link
Copy Markdown

PR #2032 verification on STOR-WINLAB

Verified the live PR head b32eadf from refs/pull/2032/head, with a clean worktree. Fetched main was cbc296a. git merge-tree --write-tree origin/main HEAD exited 0 and produced tree 24580937c02cc9b28262b7f89fcada21c50ccbab.

What is in it

  • crates/xcl/src/hle/xma2/mod.rs computes stereo and mono stream counts from XMA2WAVEFORMATEX and tests layout parsing and synthetic four-stream 5.1 decoding.

Tested

  • AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, DoublePrecisionFloatShaderOps=0, wave range 8–32), Windows 11 Enterprise Evaluation build 26200.9974, rustc 1.100.0 (0ef1bc386 2026-11-09), DXC and DXIL 1.9.2609.5. Unoptimized dev/test profiles with debug info and incremental compilation disabled.
  • cargo build --workspace and cargo test --workspace --no-run both exited 0 outside the GPU lock.
  • cargo test -p xcl --lib hle::xma2::tests -- --show-output had 8 passed, 0 failed, 0 ignored, 0 skips. The new mixed stereo/mono test passed.
  • cargo test -p xcl --lib hle::xaudio2::tests -- --show-output had 9 harness passes, 0 failed, 0 ignored. Three returned early for lack of an audio device, so six completed their checks.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output ran once under the shared Arc GPU lock. Across 20 test targets the harness reported 1037 passed, 26 failed, 45 ignored, with 26 explicit SKIPPED lines across 16 tests. Exit code 101. Harness pass totals can include skips, including partial cases and additional early returns. Skipped checks provide no coverage.
  • The library target failed 25 GPU tests. 21 reported CreateComputePipelineState (0x80070057). Four failed assertions involving FMA contraction, mip sampling, f16 high-half preservation, and wave64 pixel reductions. In the e2e target, test_title_runs_and_game_folder_is_untouched failed the dynamic depth-bias pixel check (blue instead of green).
  • Full output is in L:\XclTooling\neon-slot-2\tmp\pr2032-suite.log. The explicit skip lines follow.
SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu: const_mask, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
SKIPPED shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D)
SKIPPED placed_title_textures_share_vram_and_preserve_pixels: tiled tier < 2
SKIPPED test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll
SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
SKIPPED uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))

Not tested

  • Windows source-voice playback and lifecycle with an audio device. XAudio2 tests clamped_and_silenced_buffers_accepted_by_windows_xaudio2, opus_source_voice_decodes_and_manages_lifetime, and xma2_source_voice_decodes_and_manages_lifetime returned early because CreateMasteringVoice failed with 0x80070490. The workspace log also records early returns for an unavailable audio endpoint, system xgameruntime.dll, and optional XCL_SAMPLE_RPF, XCL_SAMPLE_TTPF, and XCL_SAMPLE_AWC inputs.
  • Retail-title smoke runs, the workspace suite on main, AMD or NVIDIA GPUs, and wave64-capable hardware. The run establishes failures on the PR head. A baseline would be needed to determine whether they also occur on main.

AI use

Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified the counts against pr2032-suite.log and published this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@upipibi

upipibi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Tested head b32eadfea2c6897bc41b2e4a90ae58c30e25ba56 (merge-base with main 656c0e8) on Windows 11 Pro 26100, rustc 1.100.0 MSVC, debug, CPU only (no GPU opened).

cargo test -p xcl --lib hle::xma2 -- --test-threads=1: head 8 passed, 0 failed, 0 ignored; merge-base 7 passed, 0 failed. New on head: stream_config_xma2_wfx_assigns_mixed_stereo_and_mono_streams. Applied to the merge-base 656c0e8ca070bdc9d7cb197d264792ef49304865 code (test hunk only, no fix), hle::xma2::tests::stream_config_xma2_wfx_assigns_mixed_stereo_and_mono_streams fails: channels=4 streams=3: XMA2 stream count 3 does not match 4 channels, 0 passed, 1 failed.

Not tested: full suite, GPU, retail title. AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: b32eadf

@github-actions github-actions Bot added area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 29, 2026
@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: b10cc4c
head: b32eadf
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2608 passed, 0 failed, 49 ignored on the merge result with main b10cc4c (27 SKIPPED lines).
review: the arithmetic is safe (channel and stream counts are already bounded, the subtraction runs after the range check) and every header main accepts today gives the same layout as before. The change is that headers main refuses, with more streams than a fully packed layout needs, are now accepted with a guessed order: stereo streams first, then mono ones. The header format does not say which streams are stereo, and nothing in the PR or the thread cites a real stream or an encoder's rule for it. If the guess is wrong, the result is scrambled audio where today the header is refused. main's newer audio work did not touch this file.
performance: none.
verdict: not yet: evidence for the stereo-first order (a real stream that decodes right, or a documented encoder rule).
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@github-actions github-actions Bot removed the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Nov 29, 2026
@jsalzy

jsalzy commented Nov 30, 2026

Copy link
Copy Markdown

merge-check claim
head: b32eadf

@jsalzy

jsalzy commented Nov 30, 2026

Copy link
Copy Markdown

merge-check
base: 2bfb6d1
head: b32eadf
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2813 passed, 2 failed, 51 ignored; SKIPPED: 28 (22 no wave64 on this GPU; 3 per-lane form refused (#1426 semantics); 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: (1) hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline (standin.rs:459, left (0, 1, 1), right (0, 0, 1)), fails on base too; (2) two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (gpu_two_pass_cache_e2e.rs:472, in a child run; its child's own result line is printed inside the failure, so cargo's total reads 3), passes on base this time, but it is a D3D12 driver-cache test with no audio in it and it is unstable here: it failed in 3 of 10 suite runs on this machine tonight, twice on main alone (9335bc0). Main alone at 2bfb6d1: 2813 passed, 1 failed (the standin test), 51 ignored. The PR's new test stream_config_xma2_wfx_assigns_mixed_stereo_and_mono_streams passes.
review: the arithmetic is safe (the count check runs before ch - num_streams), and every header main accepts today gives the same stream layout as before (fully packed 2+2+...+1, all mono, NumStreams 0). What changes is that headers with ceil(ch/2) < NumStreams < ch, which main refuses, are now accepted with stereo streams first and mono streams last. XMA2WAVEFORMATEX does not say which streams are stereo, and the new end-to-end test builds its 5.1 / 4-stream input in that same order, so it shows the decoder follows the assumed layout, not that encoders write it. The first check's point is still open: if real streams order them differently, the result is scrambled channels where today the header is refused. Related but different: #1446 and #1886 (open) reject 0- or >2-channel streams in Decoder::new; #1287 changes the PCM channel clamp. Not duplicates.
performance: none (format parsing at voice creation).
verdict: not yet: evidence for the stereo-first order (a real title's stream that decodes right with it, or a documented encoder rule); with that, the code itself has no finding.
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head b32eadf

No open or merged PR changes the XMA2WAVEFORMATEX stream layout in StreamConfig::from_xma2_wfx.
No problems found in the diff: for every layout main accepted (all mono, or ceil(ch/2) streams) the new ch - num_streams stereo-first rule gives the same layout, and it adds the mixed counts main refused (e.g. 6 channels in 4 streams -> 2,2,1,1), with a decode test.
Recommendation: keep open.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants