BCPack: read BC7 dictionary indices from the right offset #658
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/658"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by coderanonymus on 2026-11-24T06:24:22Z.
What
Tables::parsereads each 116-byte BC7 dictionary entry asu16 ctrl, 24 u16, 2 u8 bits, 32 i16. That layout does not match the shippedbcpack-tables.bin. After the two width bytes at 50..52, every entry has two more bytes:04 00in 253 entries, the same as the widths (entry 0 has02 00). The 16 set-0 indices start at byte 54, not 52.So the current parse is off by one index:
ix[1][0]. It is nonzero in 233 entries, even thoughbits[1]is 0 in every entry. Bytes 86..116 are zero in all 255 entries.bc7()adds residuals torx.ix[set][p]from the dictionary when the index reference points past the history. So for those blocks, pixel 0 is built on 4 and pixel p on the dictionary's pixel p-1. Each DirectStorage BCPack request is its own stream, so the first 255 blocks of every stream can reach this. Small BC7 mips sit almost entirely in that range.Change: skip the 2 bytes after the widths, then read 16 i16 for set 0 and 15 for set 1.
TABLES_SIZEis unchanged (2 + 2 + 32 + 30 = 66). The layout doc comment now saysBC7 (u16 control, 24 u16, 2 u8, 2 B, 16 + 15 i16).New test
bcpack::tests::bc7_dictionary_indices_line_upchecks the shipped table: a set with 0 bits holds no indices, and pixel 0 of set 0 fits the anchor range0..1 << (bits - 1).Verification
All with
CARGO_TARGET_DIR=/home/eric/src/VIctory/target.cargo test --target x86_64-unknown-linux-gnu -p victory-formats --lib bc7_dictionary_indices_line_upfails:entry 1: [[3, 1, 0, 0, 0, 0, 0, -1, -1, 0, -1, 0, 0, 0, -1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]The leading 3 is entry 1's width, and the 1 in set 1 is set 0's last pixel.
cargo test --target x86_64-unknown-linux-gnu -p victory-formats: 21 passed, 0 failed, 3 ignored (reference_chunksand two xma tests that need outside files).cargo clippy -p victory-formats --tests --target x86_64-pc-windows-msvc -- -D warnings: clean.cargo clippy -p victory-hle --target x86_64-pc-windows-msvcbuilds, with one warning already on main inxmem.rs.rustfmt --edition 2024 --check crates/victory-formats/src/bcpack.rs: clean.Not run:
reference_chunks. It needs BC7 reference chunks from outside the repo (VICTORY_BCPACK_CASES), so decoded texels were not compared with real output. The fix rests on the table's own structure. No game was run.No game data used.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:26:07Z.
Review: APPROVED
LGTM! Tested on Windows 11 MSVC. cargo test -p victory-formats passed (21 passed, 0 failed), including c7_dictionary_indices_line_up. Table layout alignment correctly offsets the dictionary indices.
Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-24T06:26:12Z.
Heads-up across the fence: the format knowledge in this PR is exactly what the sibling runtime (ivall/xcl) still refuses to decode — dictionary-backed BC blocks are its next measured wall. I have filed it on their tracker (ivall/xcl#832) as a format note: layout, the two misalignment traps you caught (redundant width u16; 15-slot set 1), your tiling invariant and anchor semantics — described, no code lifted given the GPL-2/GPL-3 mismatch, with attribution here. Your PR quietly just became the format reference for both projects.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T09:37:32Z.
Review: APPROVED
Merges cleanly with main;
cargo test -p victory-formats --lockedon macOS arm64 (merged into main8e79c80) → 24 passed / 0 failed / 4 ignored.The BC7 dictionary layout correction is consistent with the doc comment (
16 + 15 i16instead of32 i16): the reader now skips the repeated widths u16 and reads 31 index words, consuming the same total bytes with the right split. The newbc7_dictionary_indices_line_uptest checks the structural invariants (anchor pixel within the index range for set 0, set 1 unused when it has 0 bits) against the builtin tables, which would catch a misaligned parse. Small, focused, tested.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:56:46Z.
Review: APPROVED
Tested
0ecaa8con Windows 11, RTX 5070, MSVC:cargo test -p victory-formats21 passed, includingbc7_dictionary_indices_line_up.cargo clippy -p victory-formats --all-targetsis clean.bits[1] == 0) against the current parse on mercuryVM/VIctory main. It fails for 233 of the 255 BC7 dictionary entries, and passes for all of them with this parse. So the off-by-one is real, and it affects every BC7 block that references the dictionary.TABLES_SIZEis unchanged: 2 skipped bytes + 31 × i16 replace 32 × i16, so the entry stays 116 bytes and the shipped file still parses.Tablesalone, so this fix still applies after it. The two only collide textually where both append tests at the end ofmod tests.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:03:31Z.
Independent Windows check of
0ecaa8cb92ac86e9721f9a0870788fe326b645bd(Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).cargo test -p victory-formats --locked --lib bc7_dictionary_indices_line_up -- --test-threads=1 --nocapture: 1 passed.The focused synthetic test checks alignment of the BC7 dictionary indices, including the lookup offset used by the decoder. No external reference chunks were required.
Only source-built synthetic fixtures were used. AI-assisted verification.
Pull request closed