formats(bcpack): add strip-streaming, branchless rANS, and fast BC1-BC7 decode #90

Manually merged
github merged 1 commit from gh-pr/90/head into gh-pr/90/base 2026-12-01 20:08:17 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-29 08:36 UTC · original
Androtim:feat/iter91-bcpack-strip-streaming-fast-decode → main · +2697 −694 · 1 files · 1 commits · merged 2026-11-29 13:06 UTC

Summary

Adapted from upstream VIctory-NVIDIA (b075af8 / c777d87, GPL-3.0), rebased cleanly onto origin/main (5d40f8b) with zero overlap against open PRs and zero unsafe code:

  • 256-block strip-streaming (crates/victory-formats/src/bcpack.rs): Decodes 256 blocks per strip so intermediate symbol buffers stay in L1 cache instead of allocating multi-megabyte per-stream vectors.
  • Branchless rANS & fast BC1–BC7 reconstruction: Uses a 64-byte cache-line-aligned ModelTable with heap-allocated large tables and fast SWAR/LUT BC1–BC7 block reconstruction, preserving origin/main BC7 dictionary index parsing (skip unused widths word via r.u16(); and read &mut ix.ix.as_flattened_mut()[..31]), bc7_dictionary_indices_line_up, and mode 4/5 rotation fixes (6726920).
  • Bit-exact test oracle alignment: Keeps mod ref_oracle::RefTables::parse() matching origin/main's BC7 dictionary index parsing (r.u16(); + [..31]) so all parity tests validate strictly against origin/main semantics.

Verification

  • cargo xtask policy: asset policy: 303 files ok
  • cargo test -p victory-formats --lib --locked -- bcpack::: 15 passed; 0 failed; 3 ignored (including all 4 oracle_parity_* tests, bc7_dictionary_indices_line_up, and bc7_rotation_applies_only_to_modes_4_and_5)
  • cargo test -p victory-formats --lib --release --locked -- bcpack_throughput --ignored --nocapture:
    • Synthetic: BC1: 174.0 MB out/s (46.0 ns/block), BC4: 169.1 MB out/s (47.3 ns/block), BC7: 100.8 MB out/s (158.7 ns/block)
    • Builtin tables: BC1 41.7, BC3 42.1, BC4 40.2, BC5 41.5, BC6 27.5, BC7 28.6 MB out/s
  • cargo clippy --workspace --all-targets -- -D warnings & --features diagnostics: 0 warnings
  • Plain --release + objdump -p: standard Windows system DLLs only
  • Live 75s Series S GPU verification (pr91-bcpack-fast-decode): 10/11 gates PASS (0 crashes, 0 host texture errors)
    • Median FPS: 11.9 fps (83.9 ms, vs 8.9 fps baseline, +3.00 fps)
    • Max VRAM: 5767 MB / 6962 MB budget (over=0 MB, -97 MB vs baseline)
    • Waiting textures: 3414 (vs 7121 baseline) | mapped() stall rate: 7.27 ms/s
    • Shader translation: untranslated=1
    • Visually inspected 24 captured frames (frame-8614.png, frame-8638.png, median luma 103.91, edge energy 7.05, 0.0% near-black/magenta): crisp streamed textures with zero corruption.
    • Pipeline-drops note (275 vs 261.0 baseline): bcpack.rs does not touch shaders/pipelines; steady-state windows showed 0 being made / 0 repeat-waits skipped, and 100% of drops were intentionally skipped passes (ray-tracing structure builder, which is off: 260.2–300.5/frame + VICTORY_LEAVE_OUT: 2.0/frame).
**@⁠Androtim** on GitHub · 2026-11-29 08:36 UTC · [original](https://github.com/Androtim/MiniVI/pull/90) `Androtim:feat/iter91-bcpack-strip-streaming-fast-decode` → `main` · +2697 −694 · 1 files · 1 commits · merged 2026-11-29 13:06 UTC ## Summary Adapted from upstream `VIctory-NVIDIA` (`b075af8` / `c777d87`, GPL-3.0), rebased cleanly onto `origin/main` (`5d40f8b`) with zero overlap against open PRs and zero `unsafe` code: - **256-block strip-streaming (`crates/victory-formats/src/bcpack.rs`):** Decodes 256 blocks per strip so intermediate symbol buffers stay in L1 cache instead of allocating multi-megabyte per-stream vectors. - **Branchless rANS & fast BC1–BC7 reconstruction:** Uses a 64-byte cache-line-aligned `ModelTable` with heap-allocated large tables and fast SWAR/LUT BC1–BC7 block reconstruction, preserving `origin/main` BC7 dictionary index parsing (skip unused widths word via `r.u16();` and read `&mut ix.ix.as_flattened_mut()[..31]`), `bc7_dictionary_indices_line_up`, and mode 4/5 rotation fixes (`6726920`). - **Bit-exact test oracle alignment:** Keeps `mod ref_oracle::RefTables::parse()` matching `origin/main`'s BC7 dictionary index parsing (`r.u16();` + `[..31]`) so all parity tests validate strictly against `origin/main` semantics. ## Verification - `cargo xtask policy`: `asset policy: 303 files ok` - `cargo test -p victory-formats --lib --locked -- bcpack::`: **15 passed; 0 failed; 3 ignored** (including all 4 `oracle_parity_*` tests, `bc7_dictionary_indices_line_up`, and `bc7_rotation_applies_only_to_modes_4_and_5`) - `cargo test -p victory-formats --lib --release --locked -- bcpack_throughput --ignored --nocapture`: - Synthetic: `BC1: 174.0 MB out/s` (`46.0 ns/block`), `BC4: 169.1 MB out/s` (`47.3 ns/block`), `BC7: 100.8 MB out/s` (`158.7 ns/block`) - Builtin tables: `BC1 41.7`, `BC3 42.1`, `BC4 40.2`, `BC5 41.5`, `BC6 27.5`, `BC7 28.6` `MB out/s` - `cargo clippy --workspace --all-targets -- -D warnings` & `--features diagnostics`: **0 warnings** - Plain `--release` + `objdump -p`: standard Windows system DLLs only - Live 75s Series S GPU verification (`pr91-bcpack-fast-decode`): **10/11 gates PASS** (`0` crashes, `0` host texture errors) - Median FPS: `11.9 fps` (`83.9 ms`, vs `8.9 fps` baseline, `+3.00 fps`) - Max VRAM: `5767 MB` / `6962 MB` budget (`over=0 MB`, `-97 MB` vs baseline) - Waiting textures: `3414` (vs `7121` baseline) | `mapped()` stall rate: `7.27 ms/s` - Shader translation: `untranslated=1` - Visually inspected 24 captured frames (`frame-8614.png`, `frame-8638.png`, median luma `103.91`, edge energy `7.05`, `0.0%` near-black/magenta): crisp streamed textures with zero corruption. - Pipeline-drops note (`275` vs `261.0` baseline): `bcpack.rs` does not touch shaders/pipelines; steady-state windows showed `0 being made` / `0 repeat-waits skipped`, and 100% of drops were intentionally skipped passes (`ray-tracing structure builder, which is off`: `260.2`–`300.5`/frame + `VICTORY_LEAVE_OUT`: `2.0`/frame).
Adapt VIctory-NVIDIA b075af8 / c777d87 (GPL-3.0) with zero unsafe code:
- Strip-stream 256 blocks at a time so symbol buffers stay in L1 cache.
- Use branchless rANS with 64-byte aligned ModelTable and fast SWAR/LUT BC1-BC7
  block reconstruction while preserving origin/main BC7 dictionary parsing
  (skip unused widths word via r.u16() and fill indices[..31]) and mode 4/5
  rotation fixes (6726920).
- Align mod ref_oracle::RefTables::parse and bc7_dictionary_indices_line_up
  with origin/main BC7 dictionary index semantics.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:08:15 +00:00
github manually merged commit 07aa2fa345 into gh-pr/90/base 2026-12-01 20:08:17 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 09:05 UTC · original · edited 2026-11-29 11:05 UTC

Automated triage for the maintainers (not an approval).

Verdict: merge-candidate · CI (check): passing

Review Summary

Reviewed crates/victory-formats/src/bcpack.rs against origin/main. The change is a clean, zero-unsafe optimization of the BCPack decoder (256-block strip streaming, cache-line-aligned branchless rANS tables, and specialized SWAR/LUT BC1–BC7 decoders) with a verbatim ref_oracle test module for bit-exact parity.

Verified Details

  • Branchless rANS (ModelTable, BucketEntry, Lane::decode_symbol): Folding bucket 0 (eff_start = 1, eff_freq = f[0] - 1, recip = 0) and rewriting (x >> 16) * f + (offset - q * f) as ((x >> 16) - q) * f + offset (mod 2^{32}) is algebraically identical to origin/main, including the slot == 0 case. last_slot terminates at u16::MAX for the last used bucket and sentinel tail.
  • Strip-streaming fast burst (lanes_strip): Guarding the fast loop on all_payload && min_left > 1 for min_left - 1 rounds guarantees lane.left >= 1 throughout, so fragment-end transitions cannot occur mid-burst, and stalled / taken / src_pos transitions match the slow path.
  • SWAR & block reconstruction: swar_add2, swar_bc1_code, swar_add3, swar_bc4_code, pack_quad_table/quads_packed, pack_pair_table/pairs_packed, Bits::put_unmasked, decode_index_set, and bc7_pack_indices (including the w.at + 15 * bits < 128 shift bound) match origin/main semantics.
  • Preserved origin/main fixes & stack safety: Keeps rotation(ctrl) restricted to BC7 modes 4/5 and preserves BC7 dictionary index parsing (r.u16(); + [..31]) in both Tables::parse and ref_oracle::RefTables::parse. Large tables (models, ctrl7_meta) and BC6/BC7 history rings are heap-allocated via alloc_boxed_array.
  • CI & Scope: CI is passing, scope is isolated to crates/victory-formats/src/bcpack.rs, and there is no overlap with other open PRs.

Verdict

merge-candidate — pure CPU format decoder optimization with passing CI and no GPU/shader/host changes requiring a separate real-GPU gate.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-29 09:05 UTC · [original](https://github.com/Androtim/MiniVI/pull/90#issuecomment-7253527985) · edited 2026-11-29 11:05 UTC <!-- minivi-triage v1 head=07aa2fa3453602e12dec5591694f457d650172f6 verdict=merge-candidate ci=passing at=2026-11-29T11:06:15Z --> Automated triage for the maintainers (not an approval). **Verdict:** `merge-candidate` · **CI (`check`):** `passing` ### Review Summary Reviewed `crates/victory-formats/src/bcpack.rs` against `origin/main`. The change is a clean, zero-`unsafe` optimization of the BCPack decoder (256-block strip streaming, cache-line-aligned branchless rANS tables, and specialized SWAR/LUT BC1–BC7 decoders) with a verbatim `ref_oracle` test module for bit-exact parity. ### Verified Details - **Branchless rANS (`ModelTable`, `BucketEntry`, `Lane::decode_symbol`):** Folding bucket 0 (`eff_start = 1`, `eff_freq = f[0] - 1`, `recip = 0`) and rewriting `(x >> 16) * f + (offset - q * f)` as `((x >> 16) - q) * f + offset` (mod $2^{32}$) is algebraically identical to `origin/main`, including the `slot == 0` case. `last_slot` terminates at `u16::MAX` for the last used bucket and sentinel tail. - **Strip-streaming fast burst (`lanes_strip`):** Guarding the fast loop on `all_payload && min_left > 1` for `min_left - 1` rounds guarantees `lane.left >= 1` throughout, so fragment-end transitions cannot occur mid-burst, and `stalled` / `taken` / `src_pos` transitions match the slow path. - **SWAR & block reconstruction:** `swar_add2`, `swar_bc1_code`, `swar_add3`, `swar_bc4_code`, `pack_quad_table`/`quads_packed`, `pack_pair_table`/`pairs_packed`, `Bits::put_unmasked`, `decode_index_set`, and `bc7_pack_indices` (including the `w.at + 15 * bits < 128` shift bound) match `origin/main` semantics. - **Preserved `origin/main` fixes & stack safety:** Keeps `rotation(ctrl)` restricted to BC7 modes 4/5 and preserves BC7 dictionary index parsing (`r.u16();` + `[..31]`) in both `Tables::parse` and `ref_oracle::RefTables::parse`. Large tables (`models`, `ctrl7_meta`) and BC6/BC7 history rings are heap-allocated via `alloc_boxed_array`. - **CI & Scope:** CI is passing, scope is isolated to `crates/victory-formats/src/bcpack.rs`, and there is no overlap with other open PRs. ### Verdict `merge-candidate` — pure CPU format decoder optimization with passing CI and no GPU/shader/host changes requiring a separate real-GPU gate. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 09:27 UTC · original

Addressed the minivi-triage feedback at 07aa2fa (rebased onto origin/main 5d40f8b):

  • Restored origin/main's BC7 dictionary index parsing (r.u16(); followed by &mut ix.ix.as_flattened_mut()[..31]) in both Tables::parse() and ref_oracle::RefTables::parse().
  • Restored origin/main's bc7_dictionary_indices_line_up test and doc comment, keeping PR #90 strictly bit-exact with origin/main.
  • Updated the PR description to accurately describe preserving origin/main semantics rather than stale upstream SHAs.

Re-verified locally & on CI:

  • cargo xtask policy: asset policy: 303 files ok
  • cargo test -p victory-formats --lib --locked -- bcpack::: 15 passed; 0 failed; 3 ignored (including bc7_dictionary_indices_line_up and all 4 oracle_parity_* tests)
  • cargo clippy --workspace --all-targets --locked -- -D warnings & --features diagnostics: 0 warnings
  • Plain --release + objdump -p: standard Windows system DLLs only
  • GitHub Actions check: SUCCESS (https://github.com/Androtim/MiniVI/actions/runs/46246507434 — initial failure was an unrelated victory-gpu land::tests access violation flake; failed job rerun passed cleanly)
**@⁠Androtim** on GitHub · 2026-11-29 09:27 UTC · [original](https://github.com/Androtim/MiniVI/pull/90#issuecomment-7253772323) Addressed the `minivi-triage` feedback at [`07aa2fa`](https://github.com/Androtim/MiniVI/commit/07aa2fa3453602e12dec5591694f457d650172f6) (rebased onto `origin/main` `5d40f8b`): - Restored `origin/main`'s BC7 dictionary index parsing (`r.u16();` followed by `&mut ix.ix.as_flattened_mut()[..31]`) in both `Tables::parse()` and `ref_oracle::RefTables::parse()`. - Restored `origin/main`'s `bc7_dictionary_indices_line_up` test and doc comment, keeping PR #90 strictly bit-exact with `origin/main`. - Updated the PR description to accurately describe preserving `origin/main` semantics rather than stale upstream SHAs. Re-verified locally & on CI: - `cargo xtask policy`: `asset policy: 303 files ok` - `cargo test -p victory-formats --lib --locked -- bcpack::`: **15 passed; 0 failed; 3 ignored** (including `bc7_dictionary_indices_line_up` and all 4 `oracle_parity_*` tests) - `cargo clippy --workspace --all-targets --locked -- -D warnings` & `--features diagnostics`: **0 warnings** - Plain `--release` + `objdump -p`: standard Windows system DLLs only - GitHub Actions `check`: **SUCCESS** (https://github.com/Androtim/MiniVI/actions/runs/46246507434 — initial failure was an unrelated `victory-gpu` `land::tests` access violation flake; failed job rerun passed cleanly)
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Androtim--MiniVI!90
No description provided.