perf(formats): BCPack decodes a payload symbol without branching on bucket 0 #566
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!566
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-566"
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?
@IonCojucari on GitHub · 2026-11-27 11:41 UTC · original
IonCojucari:perf/bcpack-branchless-symbol→a-publier· +46 −22 · 1 files · 1 commits · openWhat
Each rANS payload step in
bcpack::Lane::stepread the model's frequencies, starts and reciprocals from three separate tables. It then branched on whether the slot fell in bucket 0 (symbol 0), which is decided by the data and so mispredicts often.Bucket 0 is now one more entry in a per-bucket decode table: start 1, frequency
f[0] - 1, reciprocal 0. Every bucket goes through the same branch-free formula with a single lookup:The
freqandrecipfields ofTablesare gone;startand the window table stay becausebucket_ofuses them. This decoder runs on the DirectStorage workers for every BCPack request, so the speed-up applies to texture streaming and loading.Measurements
cargo test --release -p victory-formats bcpack_throughput -- --ignored --nocapture, synthetic streams (no game data), three alternating old/new runs on one Linux machine:Timed alone, the lane loop is 15–20% faster (BC1 165 → 134 ns/block, BC7 433 → 373). These figures come from synthetic streams. Real title data has different symbol statistics, so the gain on real data may differ.
Verification
cargo test -p victory-formats, debug and release: 41 passed. This includes the exhaustivepayload_step_matches_the_reference_decode(every model, every slot, both table sets). Its reference decode now rebuilds the frequencies from the bucket starts, so it does not depend on the new table.cargo clippy -p victory-formats --all-targets --all-features -- -D warningsis clean, both on Linux and with--target x86_64-pc-windows-msvc. rustfmt is clean on the file.Also tried, not included
texture::Layout::detile/tileone block column at a time: faster for 64 KiB modes but slower for R8 and 4 KiB modes once the offset fix it needed was in, so no clear win.🤖 Generated with Claude Code
@WellyngtonSantos on GitHub · 2026-11-27 13:08 UTC · original
Measured on an older CPU: Intel i7-2600 (Sandy Bridge, no AVX2), Debian 13, Rust 1.98.1, head
9b9cee9againsta-publier4eb6cfd.cargo test --release -p victory-formats: 41 passed, 0 failed, 5 ignored on both.bcpack_throughput(--ignored --nocapture): both test binaries built once, then run alternately 15 times each. The machine had other load, so the minimum is the figure to read:So the branch-free bucket lookup is also faster on a 2011 core, by about 7–9% end to end, which is in line with your Linux numbers. Same caveat as yours: these are synthetic streams.
@gw1337x on GitHub · 2026-11-27 13:10 UTC · original
In-game check on RDNA 3. Memory Integrity was off.
PC: Ryzen 7 9800X3D, RX 7800 XT, 32 GB. Test: 270 s hands-off boat scene, RT off, Belobug launcher settings plus the 5 port switches, warm caches. #566 (
9b9cee9) on4eb6cfdvs4eb6cfd, interleaved with base.No change in load time or fps in this scene. Decode time itself isn't logged, so this doesn't measure the per-block gain. It only shows that the load in this scene doesn't get shorter. Pictures weren't compared.
AI-assisted (Claude Code); numbers from the run logs.
@MamaLeVrai on GitHub · 2026-11-27 15:56 UTC · original
Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At
9b9cee9:victory-formats41 passed, 0 failed, 5 ignored.AI-assisted (Claude Code); no game data.
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.