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

Merged
mint17 merged 1 commit from upstream-pr/233 into main 2026-11-27 16:49:47 +00:00
mint17 commented 2026-11-27 11:22:40 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by mint17 on 2026-11-27T11:22:40Z.


…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).
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5525783945 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/233). Originally posted by [mint17](https://github.com/mint17) on 2026-11-27T11:22:40Z. --- …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).
TaynanGT commented 2026-11-27 11:42:18 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T11:42:18Z.


@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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7217379355 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/233#issuecomment-7217379355). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T11:42:18Z. --- @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.
hamdanpor-ctrl commented 2026-11-27 16:23:34 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by hamdanpor-ctrl on 2026-11-27T16:23:34Z.


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).

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7223207075 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/233#issuecomment-7223207075). Originally posted by [hamdanpor-ctrl](https://github.com/hamdanpor-ctrl) on 2026-11-27T16:23:34Z. --- 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).
TaynanGT commented 2026-11-27 16:37:49 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T16:37:49Z.


@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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7223484294 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/233#issuecomment-7223484294). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T16:37:49Z. --- @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 commented 2026-11-27 16:42:35 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T16:42:35Z.


Windows CI for 00ad360 is on the repository run.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7223578756 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/233#issuecomment-7223578756). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T16:42:35Z. --- Windows CI for `00ad360` is on the [repository run](https://github.com/TaynanGT/Vice-Tay/actions/runs/45989980403).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
TaynanGT/Vice-Tay!233
No description provided.