XAudio2: precompute XMA inverse quantizer gains #520

Merged
TG0000 merged 1 commit from upstream-pr/525 into main 2026-11-25 01:08:00 +00:00
TG0000 commented 2026-11-24 01:19:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by TG0000 on 2026-11-24T01:19:14Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6572410363 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/525). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-24T01:19:14Z. --- 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.
thehollowedone commented 2026-11-24 07:05:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-24T01:28:29Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7119134508 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/525#issuecomment-7119134508). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-24T01:28:29Z. --- **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.
MesshM commented 2026-11-24 07:06:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T04:14:44Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7121840853 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/525#issuecomment-7121840853). Originally posted by [MesshM](https://github.com/MesshM) on 2026-11-24T04:14:44Z. --- 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.
upstream-sync closed this pull request 2026-11-25 01:08:37 +00:00
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!520
No description provided.