BCPack: replace bit-packing loops with compile-time LUTs and precomputed masks in victory #2702
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2702
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2702"
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?
@Decodere on GitHub · 2026-11-26 07:14 UTC · original
Decodere:fix-bcpack-victory-lut-and-pack-fastpaths→main· +316 −59 · 1 files · 1 commits · openWhat is in it
Replaces per-block bit-spread/deinterleave loops, dynamic mask shifts, slice anchor scans, and bounds-checked slice indexing in
crates/xcl/src/hle/bcpack/victory.rswith compile-time lookup tables, precomputed masks,u16anchor bitmasks, and fixed-size array packing helpers on the CPU BCPack decompression path.SPREAD4([u8; 16]),SPREAD8([u16; 256]), andNIBBLES([[i16; 2]; 256]) with#[inline(always)]interleave,wide_interleave(used inbc6), andnibblesreplacing the runtime bit-spread and deinterleave folds.Widthsmasks and active loops inplain: Replaces bit-width arrays onWidthswith precomputedep_mask,ep_len,ix_mask, andix_len.plainloops only over active endpoint/index counts (0..w.ep_lenand0..w.ix_len, with a fixed 16-byte SIMD fast path whenw.ix_len == 16for BC1/BC4), removing dynamic shifts from every element.quads(&[u8; 4],&mut [u8; 16]),bc1_color(&[u8; 6],&[u8; 16],&mut [u8; 8], writing a singleu64::to_le_bytes()store), andbc4_alpha(&[u8; 16],&mut [u8; 8]), usesas_chunks_mut::<2>()inpairs, and markszz,quads,pairs,bc1_color,bc4_alpha,add_index, andBits::put#[inline(always)](with a 64-bit mask before widening tou128inBits::put).anchors.contains(...)slice scans inbc7_packand per-pixel anchor branches inbc6with a precomputedu16anchor_mask.lut_helpers_match_scalar_reference_exhaustivelyandall_bc_fixtures_and_packers_match_baseline) exhaustively verifyinginterleave,wide_interleave,nibbles,Widthsmasks/lengths, BC7/BC6Hanchor_mask,Bits::put, all 12 valid shippedtests/data/bcpackfixtures against unmodifiedorigin/mainFNV-1a hashes (plusbc7-700-2error parity),bc1_color/bc4_alpha, and all 14 BC6H modes + all 8 BC7 modes.Part of #1833
Tested
origin/main(b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7): Recorded exact FNV-1a hashes for all 12 valid shippedtests/data/bcpackfixtures (andbc7-700-2error parity) plus baseline end-to-end releasebcpack::decodetimings (bc1-8192-3:701.3 us,bc7-8192-3:1470.5 us,bc1-700-2:185.5 us).bcpack::decodetimings (best of 5, including untouched rANS stage):bc1-8192-3(64 KiB, 8192 blocks):701.3 -> 650.9 us(1.08x)bc7-8192-3(64 KiB, 4096 blocks):1470.5 -> 1147.2 us(1.28x)bc1-700-2(700 blocks):185.5 -> 103.5 us(1.79x)rustc -Oper-primitive micro-benchmarks (100% exhaustive scalar parity verified):interleave:3.89 -> 3.14 ns/op(1.24x)nibbles:5.45 -> 2.78 ns/op(1.96x)wide_interleave:12.34 -> 3.25 ns/op(3.79x)bc7_indices(anchor_mask):84.95 -> 55.70 ns/op(1.53x)bc1_color:18.00 -> 12.16 ns/op(1.48x)bc4_alpha:14.64 -> 11.47 ns/op(1.28x)plainresidual mask loop: BC110.46 -> 4.22 ns/op(2.48x), BC312.49 -> 6.69 ns/op(1.87x)XCL_ADAPTER=warp,XCL_WARP=1):cargo test -p xcl --lib -- hle::bcpack:: --nocapture->8 passed; 0 failed; 0 ignored(0skipped,0.04s).XCL_ADAPTER=warp,XCL_WARP=1):cargo test --release -p xcl --lib -- hle::bcpack:: --nocapture->8 passed; 0 failed; 0 ignored(0skipped,0.01s).cargo clippy --all-targets->0new warnings incrates/xcl/src/hle/bcpack/victory.rs.cargo test --release -p xcl --lib -- hle::bcpack:: --nocapture->8 passed; 0 failed; 0 ignored(0skipped,0.01s).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture->37test binaries,1437 passed; 0 failed; 47 ignored(29pre-existing host-gatedSKIPPEDlines:21wave64-only tests on a 32-lane GPU,3per-lane wave32 tests refused by the driver,3D3D12 debug layer tests withoutd3d12SDKLayers.dll,1no heap windows,1cannot disable the driver cache).Regression run
Baseline (
origin/main):Branch (
HEAD):Not tested
XCL_SAMPLE_BCPACKsample corpus (tests/bcpack_parity.rsskips when the env var is unset).d3d12SDKLayers.dll).AI use
Implemented, unit-tested, benchmarked, and verified with assistance from Google Antigravity (Gemini 4 Neon); every change and test result was reviewed and executed locally.
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.