Formats: speed up BC7 BCPack decoding by 27% (and BC1/BC4 by 14-15%) #2735
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!2735
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2735"
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 19:22 UTC · original
brainbudt:perf/bcpack-bc7→main· +304 −151 · 1 files · 1 commits · openBC7 decodes 32 symbols per block (vs. 12 for BC1/BC4) and previously ran ~3x slower per block (
70.2 MB/s,228.1 ns/block), packing each pixel index through a separate 128-bit writer operation.What changed
Benchmark (
bcpack_throughput, median of 7 release runs on Apple M4, 16,384 blocks × 40)Verification
cargo test --release -p victory-formatspassed,cargo clippy -p victory-formats --all-targets -- -D warningspassed, andcargo checkforx86_64-pc-windows-msvcpassed.Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
@kotekompotek on GitHub · 2026-11-25 20:08 UTC · original
Read the Model/MixedWindow construction: the transition-bitmask + rank approach replaces the per-symbol window scan, and the empty-bucket / does-not-tile-65536 validation happens up front before any symbols are emitted - good. What I can't verify by reading is bit-exactness vs the old decoder across all BC7 modes; is there a differential test or corpus run backing the 27% figure? If the existing bcpack tests decode the same fixtures through both paths, that would cover it.
@rezioliver-collab on GitHub · 2026-11-25 20:08 UTC · original
On an Apple M1, this PR reduced median warm BC7 decode time at all four sizes. Including
Tables::builtin()in the first request, the PR was faster only at 16,384 blocks among the sizes tested. At that size, first-request time fell from 12.17 ms to 10.22 ms, and the PR was faster in all 40 pairs.Medians in microseconds (µs). Each cell shows
main(13f91ca) → this PR (62911d14).We built both revisions in release mode with Rust 1.98.1 on macOS 14.7. For each size, both builds used the same pre-generated synthetic BC7 input. We ran 40 pairs, alternating which build ran first. Each process built the shipped tables once and timed its first decode, then ran three warm-ups before timing repeated decodes with those tables. The combined column is the median of each process’s total. Every timed output matched the
mainreference byte for byte, with comparisons outside the timed region.@fuzeofficlal on GitHub · 2026-11-25 20:09 UTC · original
Reviewed and benchmarked
62911d14on Windows 11 againstmain(13f91ca).Code review
unsafe, clean bit-exact equivalence across all fast paths:ModelrANS 256×256-slot windows (Window::Single/Window::Mixed(u8)+[u64; 4]transition bitmap): at most 256 symbols means at most 255 transitions, somixed.len() as u8andvalue: u8cannot overflow;63 - (slot & 63)stays in0..=63, andwrapping_add/subpreserves the exact 32-bit modular behavior even onslot == 0malformed inputs.Lane::step:(x >> 16) * u32::from(sym.freq)stays belowu32::MAX, matching the prior modular step.nibbles256-entryPAIRStable,bc7shifted endpoint accumulation, andbc7_pack'spack_indices::<BITS>+ descending-order anchorshorten(max(a,b) -> min(a,b) -> 0) preserve exact bit layout.Verification & same-machine
--releasebenchmark (rustc 1.98.1MSVC)cargo test -p victory-formats --locked: 39 passed, 0 failed, 5 ignored (includingfragmented_streams_match_original_decoderFNV-1a golden hash + truncation safety andinvalid_modes_stop_after_the_last_valid_block).cargo clippy -p victory-formats --all-targets --locked -- -D warnings: 0 warnings;cargo xtask policy: 184 files ok; cleangit merge-treeagainst13f91caand#2736.bcpack_throughput(--release, same machine vs13f91ca):110.5->136.0 MB out/s(72.4->58.8 ns/block, +23.1% / 1.23x)114.6->133.2 MB out/s(69.8->60.0 ns/block, +16.2% / 1.16x)67.4->88.0 MB out/s(237.6->181.9 ns/block, +30.6% / 1.31x)@Marvisak on GitHub · 2026-11-25 23:22 UTC · original
Automated triage for the maintainers.
This replaces the bucket scan plus reciprocal division in the BCPack rANS step (
Lane::step,crates/victory-formats/src/bcpack.rs) with a per-modelModeltable (precomputed symbol for single-symbol 256-slot windows, transition bitmask + popcount for mixed ones), and speeds up BC7 endpoint rebuilding and index packing inbc7/bc7_pack. By reading I checked that the new symbol ranges give the same next state as the old(sym, f, rem)computation (including symbol 0's slot-0 wrap), that(base >> shift) + residual) << shiftequals the old masked add, and thatpack_indices+shortendrops exactly the anchor high bits the old per-indexputdropped (Writer::put is LSB-first and masks);payload_step_matches_the_reference_decodestill checks every slot of every model against the reference decode, now including narrow tables that force mixed windows. Table construction becomes slower (one-time, about 0.36 ms per a commenter's measurement). CI (check) passes.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 04:19 UTC · original · approved these changes
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-formats --lib bcpack::tests: 11 passed, 0 failed, 2 ignored (includingfragmented_streams_match_original_decoder,payload_step_matches_the_reference_decode, andnoise_never_panics).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 12:35 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
62911d1(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.fragmented_streams_match_original_decoder,invalid_modes_stop_after_the_last_valid_block.--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:58 UTC · original · approved these changes
Reviewed and verified
62911d14bbeaagainstorigin/main(63bcca43; cleangit merge-tree):u8indices cannot overflow), the transition rank includes the current slot across 64-slot word and 256-slot page boundaries, and the updated rANS step (crates/victory-formats/src/bcpack.rs:416-422) preserves original modular wrapping atslot == 0andf[0] == 1.bcpack.rs:749-786, 934-980) matches the original per-index writer (verified all 64 three-subset partitions keep distinct non-zero anchors). Independent differential checks across 3,080,192 slot lookups, 12,320,721 rANS updates, 261,120 endpoints, and 19,200 index packs matched bit-for-bit.Local verification on Windows 11 (Ryzen 9 9950X):
rustfmt --edition 2024 --check crates/victory-formats/src/bcpack.rs,xtask policy(184 files ok),cargo clippy -p victory-formats --all-targets(default &--all-features), andcargo test -p victory-formatsin both Debug and Release (39 passed, 0 failed, 5 ignored) all pass.--release bcpack_throughput(16,384 blocks vs63bcca43):108.0 -> 134.1 MB out/s(74.1 -> 59.7 ns/block, +24.2%)113.4 -> 138.7 MB out/s(70.5 -> 57.7 ns/block, +22.3%)66.1 -> 88.9 MB out/s(241.9 -> 180.1 ns/block, +34.5%)LGTM.
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.