Formats: fix BC7 dictionary layout and mode 4/5 rotation guards #3386
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3386
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3386"
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?
@legayclightning22 on GitHub · 2026-11-26 21:19 UTC · original
legayclightning22:fix/bc7-dictionary-and-rotation-guards→main· +149 −8 · 1 files · 1 commits · openSummary
Fixes BC7 dictionary layout parsing and restricts channel rotation to BC7 modes 4 and 5 in
crates/victory-formats/src/bcpack.rs(817313d,+125/-5).Changes
Tables::parse,rotation,bc7_precision, andbc7_packso BC7 dictionary indices align and channel rotation is applied only to modes 4 and 5.bc7_rotation_applies_only_to_modes_4_and_5andbc7_dictionary_indices_line_up.Verification
cargo test -p victory-formats --lib bcpack::cargo clippy --locked -p victory-formats --all-targets -- -D warningscargo xtask policy@Dukestar69 on GitHub · 2026-11-26 21:28 UTC · original · approved these changes
LGTM — verified on Windows against
origin/main(63bcca4).cargo test -p victory-formats --lib bcpack:: -- --test-threads=1: 12 passed, 0 failed (2 ignored; includingbc7_dictionary_indices_line_upandbc7_rotation_applies_only_to_modes_4_and_5).cargo clippy -p victory-formats --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 21:30 UTC · original · requested changes
Requesting a fix on the BC7 dictionary parser (
817313dvs63bcca43) — the Mode 4/5 rotation handling matches Microsoft's BC7 layout, but entry 0 of the BC7 dictionary is misread:Blocking issue
crates/victory-formats/src/bcpack.rs:225notes// Unused: the widths again in all entries but the first., yetTables::parsecallsr.u16()unconditionally for all0..DICTIONARY(255) entries.crates/victory-formats/src/bcpack-tables.binat the start of the BC7 dictionary (0xBD12):+50..+63):04 00(bits = [4, 0]), followed immediately at+52by02 00 01 00 00 00 ...([2, 1, 0, ...]).+50..+63):03 00(bits = [3, 0]), repeated03 00at+52, then indices01 00 00 00 ...at+54.u16shifts entry 0'six.ix[0]to[1, 0, 0, ...](which still happens to satisfybc7_dictionary_indices_line_up's< 1 << (bits[0] - 1)check). Reading 32u16s from+52for entry 0 and skipping the repeatedu16(reading 31) only for entries1..255fixes entry 0 while keeping the 116-byte stride intact.Additional notes
bcpack.rs:748-754,859-882): Restrictingrotation(ctrl)to BC7 modes 4 and 5 cleanly fixes the channel-precision / non-rotating-mode shift overflow and matches the BC7 Mode 4 (rotation+idxMode) and Mode 5 (rotation) bit layout (0..=3).t.bc7[0].1.ix[0](and optionally a nonzero-index Mode 4idxMode = 1case) would pin entry 0 directly.cargo test --locked -p victory-formats -- --test-threads=1: 48 passed, 0 failed, 5 ignored.cargo clippy -p victory-formats --all-targets --locked -- -D warnings(default and--all-features): clean.cargo xtask policy: 191 files ok;rustfmt --edition 2024: clean.@legayclightning22 on GitHub · 2026-11-26 21:53 UTC · original
Good catch—pushed
7520d2ffixingTables::parseso entry0reads 32u16s directly without discarding its first index, while entries1..255skip the repeated widthu16and read 31u16s to preserve the 116-byte stride. Also added an exact check ont.bc7[0].1.ix[0]and a Mode 4idxMode = 1test; re-verifiedvictory-formatstests,clippy --all-features -- -D warnings,rustfmt, andcargo xtask policy.@fuzeofficlal on GitHub · 2026-11-26 22:08 UTC · original · approved these changes
Re-verified on
7520d2f8:rustfmt --edition 2024 --check crates/victory-formats/src/bcpack.rs: clean.cargo xtask policy:191 files ok.cargo clippy --locked -p victory-formats --all-targets -- -D warnings(default and--all-features): clean.cargo test --locked -p victory-formats: 48 passed, 0 failed, 5 ignored (the_shipped_tables_parse,bc7_dictionary_indices_line_up, andbc7_rotation_applies_only_to_modes_4_and_5all pass).Verified directly against
crates/victory-formats/src/bcpack-tables.bin(77,982bytes): entry 0 at0xBD12readsbits = [4, 0],ix[0] = [2, 1, 0, ...], andix[1] = [0; 16](116 bytes total), and entries1..254(0xBD86..0x1309E) all havebits[1] == 0, matching duplicate width words, valid pixel-0 anchors, and exact 116-byte stride alignment to EOF. The mode 4/5 rotation guard inrotation(ctrl)is also consistent acrossbc7_precisionandbc7_pack. Previous feedback is resolved — LGTM.@passerbyyhx on GitHub · 2026-11-26 22:33 UTC · original
I verified
7520d2f87548fc05c79a354632159e7c8f0accd7with synthetic rANS BCPack streams throughbcpack::decode. Pillow 11.2.1 independently decoded the emitted BC7, and all 480 RGBA texels across 30 blocks matched the expected pixels. The matrix covers modes 4 and 5 at all four rotations, both mode-4 index selectors, and two distinct endpoint and spatial index patterns.The same fixture on parent
63bcca43c6a00a758510398fa43096ce7e4f7df0disagreed on 63 texels across four blocks. The three mode-6 reserved-rotation-bit cases differed at all 16 texels each, and the second synthetic dictionary entry differed at 15. The zero-bit mode-6 control and first dictionary entry matched. Swapping the two mode-4 index streams in the revision caused 248 texel mismatches across all 16 mode-4 cases. Thevictory-formatssuite passed 49 tests, with five ignored.Synthetic fixture and Pillow comparison script
AI-assisted with Codex.
@upipibi on GitHub · 2026-11-27 23:15 UTC · original
Overlap with #3111 (read from both diffs, not run): the rotation half of this PR is the same change. Both add
fn rotation(ctrl)afterpbitsand use it inbc7_precisionandbc7_pack, and both add a test namedbc7_rotation_applies_only_to_modes_4_and_5. #3111 is older (26 Nov 08:26), triage marked it a merge candidate, and gabrielvbraga reproduced its panic case with thebcpack_tablesfuzz target.So whichever lands second conflicts on those hunks. Rebased onto #3111, this PR would come down to the
Tables::parsedictionary-layout fix andbc7_dictionary_indices_line_up, the part #3111 doesn't have.On the rotation half's effect: with the shipped tables, no BC7 control word sets bits 3-4 outside modes 4 and 5 (0 of 512 control words and 0 of 255 dictionary entries in xcl's copy of the same tables, counted for xcl#3081), so it changes no decoded block there.
AI-assisted (Claude Code, Claude Opus 5.5 read both diffs).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.