Formats/XMA: add 10-bit VLC lookup table, u64 bit-peek, and quant-factor LUT #2663
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!2663
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2663"
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?
@RVZO6 on GitHub · 2026-11-25 17:44 UTC · original
RVZO6:rvzo/xma-hot-luts→main· +212 −2 · 1 files · 1 commits · openClaimed in #1633: #1633
Summary
Speeds up hot XMA2 frame decoding paths in
crates/victory-formats/src/xma.rs(+212/-2) with bit-for-bit identical decoded output:Bits::peek32: reads a single unalignedu64::from_be_bytesword on the hot path (>= 8bytes remaining) with a 5-byte tail fallback.Vlc10-bit primary table: precomputes aBox<[(i32, u8); 1024]>table inVlc::newresolving >99% of Huffman symbols in O(1), falling back to prefix-bounded binary search for codes > 10 bits.quant_factorLUT: caches10.0_f32.powf(exp as f32 / 16.0)in a bit-exactOnceLock<[f32; 384]>table forexp in -128..256(verified via.to_bits()equality across the full range).Measured (
--release xma::tests::vlc_and_quant_throughput)main)coef028.09 ns/sym6.30 ns/symcoef123.47 ns/sym5.86 ns/symvec423.76 ns/sym5.58 ns/symquant_factor10.69 ns/op1.18 ns/opNot a duplicate of
crates/victory-formats/src/xma.rs.Verification
windows-latestMSVC + WARP SM 6.6 CI (both clippy-D warningsprofiles,xtaskpolicy 6/6,victory-formats41/41 including exhaustive bit-exact equivalence tests forpeek32,Vlc, andquant_factor): https://github.com/RVZO6/VIctory/actions/runs/45666985023AI-assisted: T3 Code (Antigravity, gemini-4-neon)
@kotekompotek on GitHub · 2026-11-25 17:57 UTC · original
Reviewed: the 10-bit direct lookup is the standard ff_vlc optimization — prefix span fill for len ≤ FAST_BITS, else first-encountered fallback index;
peek32's u64 big-endian read covers bit offsets 0–7 for a full 32-bit window, tail path preserved for the last 8 bytes. CI green.@oni-swr on GitHub · 2026-11-25 18:22 UTC · original
Independent verification of #2663 (XMA: 10-bit VLC lookup, u64 bit-peek, quant-factor LUT)
PR head
485fb82b4dcf0c8075677b9d5006a3bb3b4c8f12, merges cleanly ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca.Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1, CPU only (
VICTORY_WARP=1/VICTORY_D3D12_WARP=1still set; this crate touches no GPU),cargo ... -j 4 --locked.Tests/clippy vs baseline.
origin/main:cargo test -p victory-formats --lib --locked= 38 passed, 0 failed, 5 ignored. With #2663: 41 passed, 0 failed, 6 ignored (+3 tests, +1 ignored benchmark).cargo clippy -p victory-formats --all-targets --locked: 0 warnings on both.Equivalence. Full diff read.
peek32: the 8-byte path reads bitspos..pos+32from oneu64(at most 7+32 bits) and falls back to the old zero-padding loop whenever fewer than 8 bytes remain, so reads past the buffer still see zeros as before. VLC: codes are contiguous, so the first code with a given 10-bit prefix starts that prefix's region; prefixes with no code (the unused tail of an incomplete table) fall back to a search from index 0, which reproduces the old "last code <= v".quant_factoris the samepowfevaluated once at startup, so it is bit-exact within a build, with apowffallback outside [-128, 256). Tests added:peek32vs the byte loop at every position for lengths 0-24; all 7 Huffman tables vs binary search at each code's first and last value plus a 4 KiB random stream;quant_factorbits vspowffor -200..300.Perf (release, in-PR benchmark). VLC read 21.5-24.6 -> 4.1-4.3 ns/symbol (5.3-5.7x) on the coef0/coef1/vec4 tables; quant factor 8.63 -> 0.74 ns (11.6x). Synthetic random bitstreams.
Findings: no bugs. Observation: each
Vlcnow owns an 8 KiB lookup table (7 tables), negligible.Limits: no game files, so no real XMA streams were decoded; coverage is synthetic (exhaustive at code boundaries plus random streams).
AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
@Marvisak on GitHub · 2026-11-25 22:22 UTC · original
Automated triage for the maintainers.
Merge candidate (performance, same output). In
crates/victory-formats/src/xma.rs:Bits::peek32reads one big-endian u64 when 8 bytes remain and otherwise falls back to the old loop.Vlcgains a 10-bit direct lookup table, with the old binary search kept for longer codes.quant_factorcaches10^(exp/20)for exponents in [-128, 256), computed once with the samepowf.I checked that codes are handed out contiguously, so a 10-bit region holds either one short code or long codes starting at the region's start. The slow-path search from that index therefore cannot underflow, and the empty tail falls back to a full search, as before. The tests compare against the old paths at every code boundary, at every bit position and for exponents -200..300. The "title" (XMA) data path is unchanged in semantics; the LUT memory is about 8 KiB per table. It merges cleanly; CI
check: passing.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 00:50 UTC · original
Code review and Windows 11 release benchmark verification at head
485fb82b4dcfmerged cleanly ontomain(63bcca43c6a0):crates/victory-formats/src/xma.rs):Bits::peek32(xma.rs:203-210): takes theu64::from_be_bytesfast path only whenself.data.get(byte..byte + 8)isSome, falling back safely topeek32_tail()near stream end; bit shifts match across all bit offsets (fast_peek32_matches_byte_loopcheckslen in 0..=24,pos in 0..=(len*8 + 16)).xma.rs:258-306): fills1 << (10 - len)prefix slots forlen <= 10, stores the first sorted-table index(idx, 0)forlen > 10falling back to#[cold] read_slow(partition_point(|c| c.0 <= v) - 1; sincecodes[0].0 == 0 <= v,partition_point >= 1never underflows). Verified across all 7 XMA2 Huffman tables.xma.rs:320-338, line 1169):OnceLock384-entry table forexp in [-128, 256)with single unsigned range check viawrapping_sub, falling back to10f32.powf(...)out of range;quant_table_matches_powf_bitsverifies exact bit equality across-200..=300.cargo xtask policy:191 files ok;cargo clippy -p victory-formats --all-targets -- -D warnings: 0 warningscargo test --locked -p victory-formats --all-targets: 49/49 passed (6 ignored)--releasexma::tests::vlc_and_quant_throughput:vlc coef0:21.13 -> 3.45 ns/sym(6.12x)vlc coef1:18.60 -> 3.15 ns/sym(5.90x)vlc vec4:16.66 -> 3.00 ns/sym(5.55x)quant:4.84 -> 0.42 ns/op(11.56x)Clean, bit-exact, and a huge speedup; LGTM.
@Dukestar69 on GitHub · 2026-11-26 04:31 UTC · original · approved these changes
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-formats --lib xma::: 23 passed, 0 failed, 4 ignored (including newfast_peek32_matches_byte_loop,quant_table_matches_powf_bits, andtabled_vlc_matches_binary_search).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 11:40 UTC · original
NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head
485fb82(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: 776 passed, 0 failed, 10 ignored.fast_peek32_matches_byte_loop,tabled_vlc_matches_binary_search,quant_table_matches_powf_bits.--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 12:10 UTC · original · approved these changes
Reviewed and verified
485fb82bagainstorigin/main(63bcca43; cleangit merge-tree):Bits::peek32(crates/victory-formats/src/xma.rs:203-218) extracts identical bits to the 5-byte tail path across all bit alignments, short buffers, and past physical EOF withoutbyte + 8overflow.prefix << 22 <= vand empty buckets fall back to index0, sopartition_point(|c| c.0 <= v) - 1inVlc::read_slow(xma.rs:300-306) cannot underflow; documenting or asserting that invariant inVlc::newwould make the safety contract explicit.quant_factor(xma.rs:323-338, 1169) matches baseline'sexp / 20.0across[-128, 255]and falls back cleanly outside that range.Minor non-blocking notes: the PR description says
/ 16.0whereas both the baseline and LUT use/ 20.0, andcargo fmtflags line wrapping in the new test lines (xma.rs:1460..1554).Local verification on Windows 11 (Ryzen 9 9950X):
xtask policy(184 files ok) andcargo clippy -p victory-formats --all-targets -- -D warnings(default and--all-features): clean.cargo test -p victory-formats --locked(both debug and--release):41 passed; 0 failed; 6 ignored.--release vlc_and_quant_throughput:coef05.85x (19.89 -> 3.40 ns/sym),coef15.83x (18.04 -> 3.10 ns/sym),vec45.58x (16.15 -> 2.90 ns/sym),quant12.48x (4.64 -> 0.37 ns/op).@rezioliver-collab on GitHub · 2026-11-26 18:00 UTC · original
The speedup from the 10-bit lookup on Apple M1 depended on how many symbols reached the fallback. I compared
485fb82bwith its base13f91caeusing identical synthetic bitstreams.coef0speedupcoef1speedupvec4speedupWith all-long codes,
vec4went from 33.40 to 36.35 ns/symbol. A fresh build reproduced that result (33.94 to 36.90 ns/symbol). The long-code fractions were chosen explicitly to measure fallback cost.Each cell used 5,000 deterministic symbols encoded with the corresponding table. I checked every decoded symbol and its ending bit position against the encoder’s record. All 45,000 matched on both revisions. The factors are median base/PR ratios from 12 paired release runs with alternating order, macOS 14.7, Rust 1.98.1.
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.