Formats: speed up XMA2 inverse MDCT by 24-29% #2793
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2795"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by brainbudt on 2026-11-25T20:46:34Z.
Every XMA2 subframe runs a half-length inverse MDCT across three fixed sizes (128, 256, 512), but the FFT processed its short stages in separate passes with runtime-sized scratch slices.
What changed
f64cosine-sum accuracy tests and a full mono frame test verifying every PCM sample throughflush.crates/victory-formats/src/xma.rs(does not overlap with VLC changes in #2663).Benchmark (
imdct_throughput, median of 5 release runs per host, ns/transform)f642.178e-74.974e-71.893e-6Verification
cargo test --release -p victory-formatspassed (39 passed, 5 ignored) on both macOS ARM64 and Linux x86-64, including the existing bitwise regression test.cargo clippy -p victory-formats --all-targets -- -D warningspassed; Windows MSVCcargo check -p victory-formats --target x86_64-pc-windows-msvc --testspassed.Reviewed with mistral-loop: 1 round with Mistral Large 4 and DeepSeek V4.1 Flash on high. Verdict: approved.
Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:17:19Z.
Review: COMMENTED
Bit-exactness verified by construction: butterflies at len ≤ 8 are block-local (each chunk only touches its own data), so running stages 2/4/8 per 8-point block instead of per-stage across all blocks is the same f64 operations in the same intra-block order. Stages ≥ 16 go through the unchanged
stagepath, and the fixed-size dispatch preserves thelog2(n) - 7indexing (128→0, 256→1, 512→2). The non-multiple-of-8 fallback keeps the old generic loop. Reference test upgraded to f64 direct-sum — good. LGTM.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:10:44Z.
Reviewed and benchmarked
74529ee9on Windows 11 againstmain(13f91ca).Code review
unsafe, clean stack specialization for the 3 XMA2 subframe sizes (128/256/512), and fusing stages2 -> 4 -> 8inside each 8-element chunk (as_chunks_mut::<8>()) stays strictly self-contained per chunk, producing bit-identical floating-point results to the multi-pass loop.Verification & same-machine
--releasebenchmark (rustc 1.98.1MSVC)cargo test --locked -p victory-formats: 39 passed, 0 failed, 5 ignored (tabled_imdct_gives_the_same_bitsbit-exact acrossn ∈ {0, 2..=2048}× 16 seeds;fast_imdct_matches_the_direct_summax abs error2.18e-7/4.97e-7/1.89e-6).cargo clippy --locked -p victory-formats --all-targets -- -D warnings: 0 warnings;cargo xtask policy: 184 files ok; cleangit merge-treevs13f91ca.imdct_throughput(--release, same machine vs13f91ca):n = 128:337 ns->224 ns(-33.5% / 1.50x)n = 256:688 ns->485 ns(-29.5% / 1.42x)n = 512:1,501 ns->1,063 ns(-29.2% / 1.41x)Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:22:37Z.
Automated triage for the maintainers.
This PR splits
imdct_half(crates/victory-formats/src/xma.rs) intoRotations::transform, using fixed stack buffers for the three XMA2 subframe sizes (128/256/512, the only sizes the decoder produces withSUBFRAME_SAMPLES= 128 andFRAME_SAMPLES= 512). It also fuses the first three butterfly stages within each 8-point block inbutterflies. Those stages never cross an 8-point block, so the arithmetic and its order are unchanged, and the existingtabled_imdct_gives_the_same_bitstest still holds. The accuracy test is tightened, and a full-frame decode test is added. CI passes, and an independent Windows benchmark in the thread shows a similar speedup.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:12:11Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-formats --lib xma::: 21 passed, 0 failed, 3 ignored (includingfast_imdct_matches_the_direct_sumanddecode_single_bin_xma_frame).cargo clippy -p victory-formats --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T13:49:58Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head
74529ee(on its base13f91ca).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 774 passed, 0 failed, 9 ignored.decode_single_bin_xma_frame.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T14:15:36Z.
Review: APPROVED
The math, buffer sizing, and floating-point evaluation order look sound. Stages 2, 4, and 8 only couple elements within aligned 8-point blocks (
xma.rs:440-493), so fusing them per 8-point chunk preserves every butterfly input, twiddle offset, and rounding order before continuing at length16..=m. The cached 128/256/512 stack-buffer paths match the decoder's subframe sizes without heap allocations, andtabled_imdct_gives_the_same_bitsplus the newdecode_single_bin_xma_framefixture cover both bitwise transform equivalence and the decoder boundary.Note: the checked-in
imdct_throughputbenchmark compares againstimdct_half_untabled(4.8x/5.2x/5.2x here), so I also measured--releaseagainstorigin/main's previous tabledimdct_halfdirectly below (also verified clean 3-way merge withorigin/mainand with #2663).Local verification at
74529ee9:xtask policy(184 files ok),cargo clippy -p victory-formats --all-targets(defaultand--all-features, 0 warnings), andcargo test -p victory-formats(debug and--release:39 passed, 0 failed, 5 ignored) all passed. Releaseimdct_throughputon Ryzen 9 9950X improved tabledimdct_halfoverorigin/main(63bcca43) by 24.6% atn=128(329 ns -> 248 ns), 32.8% atn=256(692 ns -> 465 ns), and 34.8% atn=512(1470 ns -> 958 ns). Approving.Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-26T18:02:04Z.
I measured how much of the IMDCT gain reaches PCM output on Apple M1. A 64-frame mono stream at 48 kHz went from 3.845 to 3.229 µs per frame when every frame carried one nonzero coefficient. The all-silent control stayed within 0.003 µs/frame.
I interleaved the PR’s synthetic single-bin frame with coefficient-free frames, kept decoder state across all 64 frames, and flushed once at the end. Timings include overlap and PCM writes into a preallocated buffer. All 33,024 signed 16-bit samples per stream, including the flush tail, matched byte for byte on
13f91caeand74529ee9. Medians from 12 alternating release pairs, Rust 1.98.1 on macOS 14.7.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T23:45:55Z.
I ran the Windows release tests on this branch with the overlap-add change from #3629 applied directly to
74529ee. The original single-bin frame test and the signal reconstruction test both passed. All 39 active victory-formats tests passed, with five ignored, and strict Clippy passed.I also decoded your generated mono frame 16 times and flushed the decoder, using separate release binaries for
74529eeand the combined 4f2dede. The 8,448 PCM samples matched byte for byte, including the 8,430 nonzero samples.The tested commit on top of your head is available if the two changes are reviewed together. The overlap-add step has its own baseline and timings in #3629.
If you reuse the overlap-add change, please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding it into another commit.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T09:30:31Z.
I adapted the output-order change from #3702 to your fixed-size transform at
74529ee. Follow-up738c01eis directly on your head and keeps your butterfly changes.I decoded the single-coefficient mono frame 16 times, then flushed, in separate Windows release binaries with and without the patch. All 8,448 PCM samples matched byte for byte in alternating runs, including the 8,430 nonzero samples. The direct cosine comparison and signal reconstruction passed too. The release suite had 39 passed and 5 ignored. Strict Clippy and the asset policy passed.
The whole-decoder times overlapped across those runs. The isolated transform measurements are in #3702 on current main.
@brainbudt, this is available if you and the maintainer want to review the changes together. Please retain the Git author if you cherry-pick or rebase it, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit.AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T21:26:05Z.
@brainbudt, I measured your fixed-size transforms at
74529eewith the paired FFT storage from #3794. Comparison commit 831fbdc keeps the exact PR heads as parents and retains your 2-, 4- and 8-point stage scheduling.Against #2795 on current main, 262,016 transform samples, 1,053,696 PCM samples and 1,769,472 floating-point output state words matched bit for bit. Two runs of 15 alternating, CPU-pinned benchmark pairs put the median transform times at 0.870x–0.912x for 128 samples, 0.932x–0.953x for 256 and 1.136x–1.137x for 512. The full decoder's median throughput ratios across the 16 cases per size were 1.010x, 1.007x and 0.996x. All 47 active release formats tests, strict formats Clippy and the asset policy passed.
The 512-sample transform regression makes this combined branch useful for A/B comparison. The maintainer can assess the separate changes on their measured workloads. Please retain the Git authors on cherry-pick or rebase, or include Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding the paired-storage change into another commit.
AI-assisted with OpenAI Codex.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.