formats/bcpack: strip-streaming, branchless rANS, and fast BC1-BC7 re… #233

Manually merged
github merged 1 commit from github-bot/gh-233 into gh-pr/233/base 2026-11-27 16:53:43 +00:00 AGit
Owner

@⁠mint17 on GitHub · 2026-11-27 11:22 UTC · original
mint17:perf/bcpack-strip-streaming → main · +2702 −693 · 1 files · 1 commits · merged 2026-11-27 16:49 UTC

…construction

Optimize BCPack decoding in crates/victory-formats/src/bcpack.rs with zero unsafe code and bit-exact parity across all 6 BC formats:

  • Stream 256-block strips through an L1-resident 8 KiB stack buffer instead of allocating a full-texture Vec of decoded records (up to 8 MiB per BC7 texture), while heap-allocating large history / table arrays directly via alloc_boxed_array to keep stack frames small.
  • Pack per-model rANS metadata into cache-line-aligned ModelTable with branchless b == 0 folding, a direct slice cursor, and a steady-state burst fast path in const-generic lanes_strip.
  • Speed up block reconstruction with const LUTs (SPREAD4, SPREAD8, NIBBLES), precomputed Ctrl7Meta with 16-bit anchor masks, two-word (lo, hi) bit packing, and SWAR 2-bit/3-bit index packing for BC1/BC3/BC4/BC5.
  • Verified with exhaustive reference-oracle parity tests across all 6 BC formats, all BC7/BC6H modes, strip boundaries, and corrupt inputs; release bcpack_throughput improves 1.82x-1.85x (BC1 47.9->88.5 MB/s, BC4 47.2->86.1 MB/s, BC7 27.4->50.3 MB/s).
**@⁠mint17** on GitHub · 2026-11-27 11:22 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/233) `mint17:perf/bcpack-strip-streaming` → `main` · +2702 −693 · 1 files · 1 commits · merged 2026-11-27 16:49 UTC …construction Optimize BCPack decoding in crates/victory-formats/src/bcpack.rs with zero unsafe code and bit-exact parity across all 6 BC formats: - Stream 256-block strips through an L1-resident 8 KiB stack buffer instead of allocating a full-texture Vec<u8> of decoded records (up to 8 MiB per BC7 texture), while heap-allocating large history / table arrays directly via alloc_boxed_array to keep stack frames small. - Pack per-model rANS metadata into cache-line-aligned ModelTable with branchless b == 0 folding, a direct slice cursor, and a steady-state burst fast path in const-generic lanes_strip. - Speed up block reconstruction with const LUTs (SPREAD4, SPREAD8, NIBBLES), precomputed Ctrl7Meta with 16-bit anchor masks, two-word (lo, hi) bit packing, and SWAR 2-bit/3-bit index packing for BC1/BC3/BC4/BC5. - Verified with exhaustive reference-oracle parity tests across all 6 BC formats, all BC7/BC6H modes, strip boundaries, and corrupt inputs; release bcpack_throughput improves 1.82x-1.85x (BC1 47.9->88.5 MB/s, BC4 47.2->86.1 MB/s, BC7 27.4->50.3 MB/s).
Optimize BCPack decoding in crates/victory-formats/src/bcpack.rs with zero
unsafe code and bit-exact parity across all 6 BC formats:

- Stream 256-block strips through an L1-resident 8 KiB stack buffer instead
  of allocating a full-texture Vec<u8> of decoded records (up to 8 MiB per
  BC7 texture), while heap-allocating large history / table arrays directly
  via alloc_boxed_array to keep stack frames small.
- Pack per-model rANS metadata into cache-line-aligned ModelTable with
  branchless b == 0 folding, a direct slice cursor, and a steady-state burst
  fast path in const-generic lanes_strip.
- Speed up block reconstruction with const LUTs (SPREAD4, SPREAD8, NIBBLES),
  precomputed Ctrl7Meta with 16-bit anchor masks, two-word (lo, hi) bit
  packing, and SWAR 2-bit/3-bit index packing for BC1/BC3/BC4/BC5.
- Verified with exhaustive reference-oracle parity tests across all 6 BC
  formats, all BC7/BC6H modes, strip boundaries, and corrupt inputs; release
  bcpack_throughput improves 1.82x-1.85x (BC1 47.9->88.5 MB/s, BC4
  47.2->86.1 MB/s, BC7 27.4->50.3 MB/s).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 11:25:54 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 11:42 UTC · original

@⁠mint17 The bit-exact oracle and strip boundary coverage give us a good decoder check. I’ll keep the reported 1.82×–1.85× scoped to decode throughput. For the streaming path, the follow-up is the same input and output hash with peak temporary bytes and decode time measured together.

**@⁠TaynanGT** on GitHub · 2026-11-27 11:42 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/233#issuecomment-7217379355) @⁠mint17 The bit-exact oracle and strip boundary coverage give us a good decoder check. I’ll keep the reported 1.82×–1.85× scoped to decode throughput. For the streaming path, the follow-up is the same input and output hash with peak temporary bytes and decode time measured together.
Author
Owner

@⁠hamdanpor-ctrl on GitHub · 2026-11-27 16:23 UTC · original

Test report, NVIDIA laptop on Windows: tests pass, BC packing faster here too.

  • PC: i7-12700H (6 P-cores + 8 E-cores), RTX 3050 Laptop GPU 4 GB, 16 GB, Windows 11 Pro, plugged in
  • Build: Rust 1.98.1, VS 2022 Build Tools
  • Compared: main at 6b3a266, and the same commit with 00ad360 merged (git merge --no-ff, clean)
  • Tests: cargo test -p victory-formats --locked passes; clippy with and without --all-features is clean on the merge.
  • Speed: cargo test --release -p victory-formats --locked -- --ignored --nocapture throughput, one run each
bcpack_throughput main main + this PR
BC1, 16,384 blocks 196.0 ns/block 119.0 ns/block 1.65x
BC4, 16,384 blocks 200.3 ns/block 105.6 ns/block 1.90x
BC7, 16,384 blocks 677.9 ns/block 432.2 ns/block 1.57x

imdct_throughput and bench_detile_throughput moved within what a single run on a laptop varies (the detile rows went both ways by up to about 25 %), so I don't read anything into them.

Single run each. AI-assisted (Claude Code).

**@⁠hamdanpor-ctrl** on GitHub · 2026-11-27 16:23 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/233#issuecomment-7223207075) Test report, NVIDIA laptop on Windows: tests pass, BC packing faster here too. - PC: i7-12700H (6 P-cores + 8 E-cores), RTX 3050 Laptop GPU 4 GB, 16 GB, Windows 11 Pro, plugged in - Build: Rust 1.98.1, VS 2022 Build Tools - Compared: `main` at `6b3a266`, and the same commit with `00ad360` merged (`git merge --no-ff`, clean) - Tests: `cargo test -p victory-formats --locked` passes; clippy with and without `--all-features` is clean on the merge. - Speed: `cargo test --release -p victory-formats --locked -- --ignored --nocapture throughput`, one run each | `bcpack_throughput` | main | main + this PR | | |---|---:|---:|---:| | BC1, 16,384 blocks | 196.0 ns/block | 119.0 ns/block | 1.65x | | BC4, 16,384 blocks | 200.3 ns/block | 105.6 ns/block | 1.90x | | BC7, 16,384 blocks | 677.9 ns/block | 432.2 ns/block | 1.57x | `imdct_throughput` and `bench_detile_throughput` moved within what a single run on a laptop varies (the detile rows went both ways by up to about 25 %), so I don't read anything into them. Single run each. AI-assisted (Claude Code).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 16:37 UTC · original

@⁠hamdanpor-ctrl Thanks for the laptop pass. The BC1, BC4 and BC7 packing numbers move in the same direction, and the formats suite passed on your merge. That confirms the benefit in the packing benchmark. A repeated run on the current head would give us the spread before we use those numbers in the docs.

**@⁠TaynanGT** on GitHub · 2026-11-27 16:37 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/233#issuecomment-7223484294) @⁠hamdanpor-ctrl Thanks for the laptop pass. The BC1, BC4 and BC7 packing numbers move in the same direction, and the formats suite passed on your merge. That confirms the benefit in the packing benchmark. A repeated run on the current head would give us the spread before we use those numbers in the docs.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 16:42 UTC · original · edited 2026-11-27 16:45 UTC

Windows CI for 00ad360 is on the repository run.

**@⁠TaynanGT** on GitHub · 2026-11-27 16:42 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/233#issuecomment-7223578756) · edited 2026-11-27 16:45 UTC Windows CI for `00ad360` is on the [repository run](https://github.com/TaynanGT/Vice-Tay/actions/runs/45989980403).
github-bot changed target branch from main to gh-pr/233/base 2026-11-27 16:53:38 +00:00
github manually merged commit 00ad360668 into gh-pr/233/base 2026-11-27 16:53:43 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.