formats/bcpack: strip-streaming, branchless rANS, and fast BC1-BC7 reconstruction #674

Merged
mint17 merged 1 commit from upstream-pr/674 into main 2026-11-29 08:16:59 +00:00
mint17 commented 2026-11-28 03:22:15 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mint17 on 2026-11-28T03:22:15Z.


Optimizes BCPack texture decoding in crates/victory-formats/src/bcpack.rs with zero unsafe code and bit-exact parity across all 6 BC formats (clean standalone port of our merged TaynanGT/Vice-Tay#233, preserving VIctory-NVIDIA's baseline BC7 dictionary parsing verbatim).

Changes

  • Strip-streaming (STRIP = 256): Decodes 256 blocks per strip so intermediate symbol streams stay resident in L1 cache instead of allocating multi-megabyte full-texture scratch vectors.
  • Branchless rANS & cache-line-aligned ModelTable: Replaces branching symbol lookup / renormalization with branchless rANS over 64-byte-aligned tables, heap-allocating large decode arrays via alloc_boxed_array to avoid stack-frame bloat.
  • Fast BC1–BC7 reconstruction: Uses SWAR/LUT bit-packing across all BC formats with zero unsafe.
  • Preserves baseline semantics: Keeps VIctory-NVIDIA's exact baseline BC7 dictionary parsing and pure LF line endings.

Release Throughput Benchmark (cargo test --release --locked -p victory-formats bcpack_throughput -- --ignored --nocapture, 16,384 blocks × 40 runs)

Format Throughput Time / Block Speedup vs. Baseline
BC1 89.1 MB out/s 89.8 ns/block ~1.86×
BC4 86.1 MB out/s 92.9 ns/block ~1.82×
BC7 50.9 MB out/s 314.4 ns/block ~1.86×

Verification

  • cargo test --locked -p victory-formats (50 passed, 0 failed — includes bit-exact reference-oracle parity across BC1–BC7 and strip-boundary tests).
  • cargo clippy -p victory-formats --all-targets --locked -- -D warnings (default + --all-features), rustfmt --check --edition 2024, and cargo test --locked -p xtask (6 passed, 0 failed, including asset policy).
  • Verified with synthetic tests, reference-oracle checks, and benchmarks only (no game files).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5536188006 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/674). Originally posted by [mint17](https://github.com/mint17) on 2026-11-28T03:22:15Z. --- Optimizes BCPack texture decoding in `crates/victory-formats/src/bcpack.rs` with **zero `unsafe` code** and bit-exact parity across all 6 BC formats (clean standalone port of our merged `TaynanGT/Vice-Tay#233`, preserving `VIctory-NVIDIA`'s baseline BC7 dictionary parsing verbatim). ### Changes - **Strip-streaming (`STRIP = 256`):** Decodes 256 blocks per strip so intermediate symbol streams stay resident in L1 cache instead of allocating multi-megabyte full-texture scratch vectors. - **Branchless rANS & cache-line-aligned `ModelTable`:** Replaces branching symbol lookup / renormalization with branchless rANS over 64-byte-aligned tables, heap-allocating large decode arrays via `alloc_boxed_array` to avoid stack-frame bloat. - **Fast BC1–BC7 reconstruction:** Uses SWAR/LUT bit-packing across all BC formats with zero `unsafe`. - **Preserves baseline semantics:** Keeps `VIctory-NVIDIA`'s exact baseline BC7 dictionary parsing and pure LF line endings. ### Release Throughput Benchmark (`cargo test --release --locked -p victory-formats bcpack_throughput -- --ignored --nocapture`, 16,384 blocks × 40 runs) | Format | Throughput | Time / Block | Speedup vs. Baseline | | --- | ---: | ---: | ---: | | **BC1** | **89.1 MB out/s** | 89.8 ns/block | **~1.86×** | | **BC4** | **86.1 MB out/s** | 92.9 ns/block | **~1.82×** | | **BC7** | **50.9 MB out/s** | 314.4 ns/block | **~1.86×** | ### Verification - `cargo test --locked -p victory-formats` (50 passed, 0 failed — includes bit-exact reference-oracle parity across BC1–BC7 and strip-boundary tests). - `cargo clippy -p victory-formats --all-targets --locked -- -D warnings` (default + `--all-features`), `rustfmt --check --edition 2024`, and `cargo test --locked -p xtask` (6 passed, 0 failed, including asset policy). - Verified with synthetic tests, reference-oracle checks, and benchmarks only (no game files).
Dukestar69 commented 2026-11-28 05:34:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T05:34:35Z.

Review: APPROVED


LGTM — verified on Windows:

  • cargo test -p victory-formats --lib bcpack:: passed (15/15, including all 4 new oracle_parity_* tests across BC1–BC7 modes, rotations, subsets, strip boundaries, and malformed inputs)
  • cargo clippy -p victory-formats --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (294 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6096062862 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/674#pullrequestreview-6096062862). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T05:34:35Z. **Review:** APPROVED --- LGTM — verified on Windows: - `cargo test -p victory-formats --lib bcpack::` passed (15/15, including all 4 new `oracle_parity_*` tests across BC1–BC7 modes, rotations, subsets, strip boundaries, and malformed inputs) - `cargo clippy -p victory-formats --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`294 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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
trustno1-coder/VIctory-NVIDIA!674
No description provided.