XAudio2: precompute XMA inverse quantizer gains #525

Manually merged
github merged 1 commit from gh-pr/525/head into gh-pr/525/base 2026-11-26 04:24:33 +00:00
Owner

@⁠TG0000 on GitHub · 2026-11-24 01:19 UTC · original
TG0000:perf/xma-quantizer-gains → main · +27 −1 · 1 files · 1 commits · merged 2026-11-25 01:08 UTC

XMA1/XMA2 inverse quantization calculated an exponential for every coded band. This PR initializes a 6.5 KiB gain table once and reuses it across decoder instances. The lookup preserves the original f32 rounding, including underflow and overflow.

What is in it

  • crates/xcl/src/hle/xma2/mod.rs uses the shared table and adds a bit-for-bit comparison with the original formula, including exponents outside the table.

Tested

  • Ryzen 9 5900X, Radeon RX 6800 (driver 32.0.21045.29003), Windows build 26300, Rust 1.100.0 MSVC. Debug workspace build and release xcl build succeeded.
  • cargo +stable-x86_64-pc-windows-msvc test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output recorded 675 passed, 3 failed, and 41 ignored on this head, versus 674 passed, 3 failed, and 41 ignored on main. Both runs hit the same 3D texture subresource mismatch in placed_title_textures_share_vram_and_preserve_pixels and two follow-on failures from poisoned test locks. All eight XMA tests passed on this head.
  • test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state skipped their GPU checks in both runs because the D3D12 debug layer was unavailable.
  • Optimized MSVC benchmark, median of seven alternating runs. Gain calculation over 4,096 synthetic exponents went from 14.929 ns to 0.517 ns per band (28.9×). Complete decode of the existing synthetic cross-packet fixture went from 35.975 µs to 33.128 µs (1.09×), with all 2,860 samples bit-identical.

Regression run

The first head run missed the frame-count gate and recorded zero XMA voices or decodes. The retry used the same head and 45-second command. The blocks are main, the first head run, and the retry in that order.

xcl-smoke v1
commit: 7ebf1b8044bef8f0ef296eb36e85010cceb4633a
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 786 (PresentX 786)
presents per 2 s (last 3): 60 60 32
device removals: 0
crashes: 0
peak commit: 15147 MB
xcl-smoke v1
commit: 6aba0688b59bb2731226fab591ac0600c60a499d
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 443 (PresentX 444)
presents per 2 s (last 3): 8 9 7
device removals: 0
crashes: 0
peak commit: 15550 MB
xcl-smoke v1
commit: 6aba0688b59bb2731226fab591ac0600c60a499d
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 872 (PresentX 873)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15139 MB

Not tested

  • In-title XMA throughput, cold decoder initialization latency, other GPU drivers, macOS, or Linux.

AI use

  • Codex in T3 Code with GPT-6.2 Sol wrote the change and test, ran verification, and drafted this description.
**@⁠TG0000** on GitHub · 2026-11-24 01:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/525) `TG0000:perf/xma-quantizer-gains` → `main` · +27 −1 · 1 files · 1 commits · merged 2026-11-25 01:08 UTC XMA1/XMA2 inverse quantization calculated an exponential for every coded band. This PR initializes a 6.5 KiB gain table once and reuses it across decoder instances. The lookup preserves the original `f32` rounding, including underflow and overflow. **What is in it** - `crates/xcl/src/hle/xma2/mod.rs` uses the shared table and adds a bit-for-bit comparison with the original formula, including exponents outside the table. **Tested** - Ryzen 9 5900X, Radeon RX 6800 (driver 32.0.21045.29003), Windows build 26300, Rust 1.100.0 MSVC. Debug workspace build and release `xcl` build succeeded. - `cargo +stable-x86_64-pc-windows-msvc test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output` recorded 675 passed, 3 failed, and 41 ignored on this head, versus 674 passed, 3 failed, and 41 ignored on `main`. Both runs hit the same 3D texture subresource mismatch in `placed_title_textures_share_vram_and_preserve_pixels` and two follow-on failures from poisoned test locks. All eight XMA tests passed on this head. - `test_title_draws_with_a_root_signature_under_the_debug_layer` and `uploads_start_from_each_subresources_state` skipped their GPU checks in both runs because the D3D12 debug layer was unavailable. - Optimized MSVC benchmark, median of seven alternating runs. Gain calculation over 4,096 synthetic exponents went from 14.929 ns to 0.517 ns per band (28.9×). Complete decode of the existing synthetic cross-packet fixture went from 35.975 µs to 33.128 µs (1.09×), with all 2,860 samples bit-identical. **Regression run** The first head run missed the frame-count gate and recorded zero XMA voices or decodes. The retry used the same head and 45-second command. The blocks are main, the first head run, and the retry in that order. ``` xcl-smoke v1 commit: 7ebf1b8044bef8f0ef296eb36e85010cceb4633a gpu: AMD Radeon RX 6800 title: retail-title-1.0.2.1 seconds: 45 exit: 0x0 frames shown: 786 (PresentX 786) presents per 2 s (last 3): 60 60 32 device removals: 0 crashes: 0 peak commit: 15147 MB ``` ``` xcl-smoke v1 commit: 6aba0688b59bb2731226fab591ac0600c60a499d gpu: AMD Radeon RX 6800 title: retail-title-1.0.2.1 seconds: 45 exit: 0x0 frames shown: 443 (PresentX 444) presents per 2 s (last 3): 8 9 7 device removals: 0 crashes: 0 peak commit: 15550 MB ``` ``` xcl-smoke v1 commit: 6aba0688b59bb2731226fab591ac0600c60a499d gpu: AMD Radeon RX 6800 title: retail-title-1.0.2.1 seconds: 45 exit: 0x0 frames shown: 872 (PresentX 873) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15139 MB ``` **Not tested** - In-title XMA throughput, cold decoder initialization latency, other GPU drivers, macOS, or Linux. **AI use** - Codex in T3 Code with GPT-6.2 Sol wrote the change and test, ran verification, and drafted this description.
Inverse quantization computed the same exponential for each coded band. Cache the finite f32 gain range in the shared decoder tables and clamp exponents outside the range to the matching zero or infinity endpoint.

On MSVC, the synthetic gain benchmark went from 14.929 ns to 0.517 ns per band and the cross-packet decode went from 35.975 to 33.128 us, with bit-identical samples.

Co-Authored-By: GPT 6.2 Sol <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:24:32 +00:00
github manually merged commit 6aba0688b5 into gh-pr/525/base 2026-11-26 04:24:33 +00:00
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-24 01:28 UTC · original

Tested

RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug. On each revision I ran cargo build --offline --locked --workspace then cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4, with all XCL_SAMPLE_* variables unset and separate build outputs for the reported runs.

Revision Cargo passed Failed Ignored Runtime skips counted by Cargo as passes
Exact PR parent 7ebf1b8 677 0 41 2
PR head 6aba068 678 0 41 2

The new bit-for-bit quantization gain test passed. The reported 3D texture mismatch and follow-on failures did not occur on either revision here. Both runs skipped gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware because the adapter lacks wave64. The parent is the commit from the author's smoke baseline. Current main includes the later FPS-counter merge. Main checked at 508a0c7

Not tested

Retail titles, optimized decode performance, or integration with current main.

AI use

Codex with GPT-6.2 Sol ran the tests and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-24 01:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/525#issuecomment-7119134508) **Tested** RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug. On each revision I ran `cargo build --offline --locked --workspace` then `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4`, with all `XCL_SAMPLE_*` variables unset and separate build outputs for the reported runs. | Revision | Cargo passed | Failed | Ignored | Runtime skips counted by Cargo as passes | | --- | ---: | ---: | ---: | ---: | | [Exact PR parent 7ebf1b8](https://github.com/ivall/xcl/commit/7ebf1b8044bef8f0ef296eb36e85010cceb4633a) | 677 | 0 | 41 | 2 | | [PR head 6aba068](https://github.com/ivall/xcl/commit/6aba0688b59bb2731226fab591ac0600c60a499d) | 678 | 0 | 41 | 2 | The new bit-for-bit quantization gain test passed. The reported 3D texture mismatch and follow-on failures did not occur on either revision here. Both runs skipped `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` because the adapter lacks wave64. The parent is the commit from the author's smoke baseline. Current main includes the later FPS-counter merge. [Main checked at 508a0c7](https://github.com/ivall/xcl/commit/508a0c74d7c0625d6d2de8d24494e69dc2e1926f) **Not tested** Retail titles, optimized decode performance, or integration with current main. **AI use** Codex with GPT-6.2 Sol ran the tests and drafted this report.
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 04:14 UTC · original

Test run of 6aba0688b59bb2731226fab591ac0600c60a499d on AMD RDNA4. I merged it onto current main f4ce27c locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 702 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 661 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the xma2 tests pass, including the bit-for-bit comparison with the original formula.

Review: The table covers −904..771 and clamps outside it. At the ends the original formula already saturates: 10^(−904/20) ≈ 6·10⁻⁴⁶ rounds to 0 in f32 and 10^(771/20) ≈ 3.5·10³⁸ overflows to inf, so clamping gives the same bits as computing. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

**@⁠MesshM** on GitHub · 2026-11-24 04:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/525#issuecomment-7121840853) Test run of `6aba0688b59bb2731226fab591ac0600c60a499d` on AMD RDNA4. I merged it onto current `main` `f4ce27c` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **702 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 661 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; the `xma2` tests pass, including the bit-for-bit comparison with the original formula. **Review:** The table covers −904..771 and clamps outside it. At the ends the original formula already saturates: 10^(−904/20) ≈ 6·10⁻⁴⁶ rounds to 0 in f32 and 10^(771/20) ≈ 3.5·10³⁸ overflows to inf, so clamping gives the same bits as computing. I found nothing to change. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`. Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
This discussion has been locked. Commenting is limited to contributors.
No description provided.