Repository navigation
BCPack: read BC7 dictionary indices where each entry has them - #2163
0xkn0wh3r3 wants to merge 2 commits into
Conversation
Each BC7 dictionary entry has two more bytes after the two index widths. They repeat the widths in all entries but the first. The parser read them as pixel 0 of set 0, so every index was off by one: pixel 0 was 4 in 253 of 255 entries, and set 0's last pixel landed in set 1, which no entry uses. Any BC7 block whose index reference points into the dictionary was built on the wrong indices. Skip the two bytes and read 16 indices for set 0 and 15 for set 1. The table size does not change. The new test checks the shipped table: a set with 0 bits holds no indices, and pixel 0 is a valid anchor.
The previous commit (from Marvisak#658) skips two bytes after each BC7 dictionary entry's index widths, the widths repeated. The table file repeats them in entries 1 to 254 only: in entry 0 the bytes after the widths are its first index already. Checked on the built-in table: the u16 after the widths equals the width bytes in 254 entries; in entry 0 (control 0, widths [4, 0]) it is 2, its indices 2, 1, 0, ... Skipping there dropped the 2 and shifted the rest. XCL's notes report the same layout (their tables were made from this file). Entry 0 now reads its 32 indices at once; the others skip the repeated widths and read 31. The test also checks entry 0: control 0, widths [4, 0], indices beginning 2, 1, 0.
|
I checked the effect on the final 16-byte BC7 block using synthetic data through
The synthetic table intentionally repeats the widths for entry 1 only. This verifies why both changes matter for the two stated layouts; it does not independently establish which layout an external encoder uses. No game assets. AI-assisted. |
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-formats --lib bcpack::— 10 passed, 0 failed (2 ignored), includingbc7_dictionary_indices_line_upcargo clippy -p victory-formats --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean fix reading BC7 dictionary indices at each entry's actual location with targeted regression test. Looks good.
AI-assisted (Gemini 4 Neon).
|
Automated triage for the maintainers. Merge candidate. The evidence comes from the table file itself, which is the right source here. CI: not run on this head. It merges cleanly with For the maintainers: the first commit is #658 (coderanonymus), which was closed unmerged on 2026-11-24 with no stated reason. If that close was deliberate, this PR needs the same decision. Generated by Claude Code |
… them) into demo
cd4402f to
77d7c9f
Compare
|
Automated triage for the maintainers, second look (a review against current Closing because If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution. |
Problem
Tables::parsereads 32 indices straight after each BC7 dictionary entry's two index-width bytes. The built-in table file (bcpack-tables.bin) has another layout: entries 1 to 254 repeat their two width bytes before 31 indices. So every one of those entries' indices is read two bytes early, and BCPack BC7 blocks that come from the dictionary decode with the wrong indices.Entry 0 is the exception: its 32 indices start right after its widths. Checked on the built-in file: the u16 after the widths equals the width bytes in 254 entries. In entry 0 (control 0, widths [4, 0]) it is 2, the first of its indices 2, 1, 0, ...
Fix
Two commits:
5f0936dis BCPack: read BC7 dictionary indices from the right offset #658 by coderanonymus, unchanged (cherry-picked onto currentmain): skip the repeated widths and read 31 indices (set 1's 16th slot is unused; no entry gives set 1 index bits). BCPack: read BC7 dictionary indices from the right offset #658 was closed on 2026-11-24 without being merged and without a stated reason; it had an independent Windows check. If it was closed for a reason this misses, please say.cd4402fadds the exception: entry 0 reads its 32 indices directly. With BCPack: read BC7 dictionary indices from the right offset #658 alone, entry 0 lost its leading 2 and its other indices shifted. XCL's notes report the same layout (their tables were generated from this file; their GPU: a pipeline library save the host has no memory for waits, not aborts (1.7 GB library on NVIDIA) #2007).Testing
bc7_dictionary_indices_line_up(from BCPack: read BC7 dictionary indices from the right offset #658) checks every entry: pixel 0 is an anchor (top bit clear), and a set with 0 index bits holds no indices. It now also checks entry 0: control 0, widths [4, 0], indices beginning 2, 1, 0.main's parser it fails at entry 1 (its first index is the repeated width bytes); with BCPack: read BC7 dictionary indices from the right offset #658 alone it fails on entry 0 ([1, 0, 0]where[2, 1, 0]is wanted); with both commits it passes.cargo test -p victory-formats: 39 passed;cargo test -p victory-hle(DirectStorage's BCPack path): all pass.cargo clippy --workspace --all-targets, with and without--features diagnostics: clean.