Formats: speed up XMA2 inverse MDCT by 24-29% #2795
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2795
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@brainbudt on GitHub · 2026-11-25 20:46 UTC · original
brainbudt:perf/xma-imdct→main· +112 −58 · 1 files · 1 commits · openEvery 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).
@fuzeofficlal on GitHub · 2026-11-25 21:10 UTC · original
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)@Marvisak on GitHub · 2026-11-25 23:22 UTC · original
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
@kotekompotek on GitHub · 2026-11-25 21:17 UTC · original · reviewed
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.@Dukestar69 on GitHub · 2026-11-26 03:12 UTC · original · approved these changes
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).
@futurepro62 on GitHub · 2026-11-26 13:49 UTC · original
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
@fuzeofficlal on GitHub · 2026-11-26 14:15 UTC · original · approved these changes
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.@rezioliver-collab on GitHub · 2026-11-26 18:02 UTC · original
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.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.