Formats/BCPack: restrict BC7 channel rotation to modes 4 and 5 #3111
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!3111
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3111"
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?
@RVZO6 on GitHub · 2026-11-26 08:26 UTC · original
RVZO6:rvzo/bcpack-bc7-rotation→main· +107 −2 · 1 files · 1 commits · openWhat
Splits out item (1) requested in the
#315triage note: restrict BC7 channel rotation incrates/victory-formats/src/bcpack.rsto BC7 modes 4 and 5.Root cause
Only BC7 modes 4 and 5 define a 2-bit channel rotation field. Previously, both
bc7_precisionandbc7_packunconditionally extractedctrl >> 3 & 3for all modes:pbits(mode) == true, alpha width0) withrot == 1,bc7_precisionswapped0intop[0]and skippedelse if pbits(mode) { p[0] += 1; }, leavingprec[0] == 0.bc7_packthen evaluatedep.rows[...][...] >> (16 - prec[0]), panicking withattempt to shift right with overflow.rot == 2 | 3,bc7_precisionswapped alpha's0width into G or B, dropping a color channel.rot != 0,bc7_precisionskipped red's p-bit increment andbc7_packreordered endpoint channels and misaligned the packed block.Fix
fn rotation(ctrl: u16) -> usize, returningusize::from(ctrl >> 3 & 3)only whenmatches!(ctrl & 7, 4 | 5)and0otherwise.rotation(ctrl)in bothbc7_precisionandbc7_pack.bc7_rotation_applies_only_to_modes_4_and_5covering:rot = 1..=3matchingrot = 0bit-for-bit through publicdecode(7, ...)(verified panicking atbcpack.rs:866before the fix).rot = 1..=3continuing to rotate alpha with channelrot - 1(positive control).Verification
cargo test -p victory-formats --locked(Linux): 47 passed, 0 failed.cargo clippy -p victory-formats --all-targets --locked -- -D warnings(default +--all-features): clean.windows-latestMSVC + WARP SM 6.6 CI (xtask policy, clippy default +--all-features, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45782627843.Not run: the title; any hardware GPU.
AI-assisted: T3 Code (Antigravity, gemini-4-neon).
@Marvisak on GitHub · 2026-11-26 08:32 UTC · original
Automated triage for the maintainers.
Verdict: merge candidate. CI
checkpasses.This PR adds
rotation(ctrl)incrates/victory-formats/src/bcpack.rs. It uses it inbc7_precisionandbc7_pack, so the 2-bit rotation field is honoured only for BC7 modes 4 and 5, which matches the public BC7 format. I checked it against main. Withrot == 1on modes 0, 1 and 3,bc7_precisionzeroes red's precision (alpha width 0), andbc7_pack's>> (16 - p)then overflows. On other modes, rotation reorders the endpoints. So a malformed or unexpected control word from the stream tables could panic or produce a corrupt block. The change is minimal, and the new testbc7_rotation_applies_only_to_modes_4_and_5checks that non-rotating modes decode the same for everyrot. It also checks the rotated packing for modes 4 and 5.Generated by Claude Code
@AurumCarlos on GitHub · 2026-11-26 08:43 UTC · original · reviewed
Reviewed head
796c55e(onmain63bcca4). The change looks correct to me; nothing blocking, three small notes.Checked
rotation()honours bits 4:3 only for modes 4 and 5, as in BC7, andbc7_precisionandbc7_packnow share it, so precision and endpoint order cannot disagree.usize::from(ctrl >> 3 & 3)it fails withattempt to shift right with overflowat the>> (16 - p)inbc7_pack; with the PR, the 11bcpacktests pass andcargo clippy -p victory-formats --lib --tests -- -D warningsis clean (Linux).Notes
t.ctrl7, not from the stream, and the runtime only usesTables::builtin()(dstorage.rs,load_bcpack_tables). Scanning its 285 used codes: bits 4:3 are non-zero only on modes 4 (2/2/2/2 per rotation) and 5 (1/1/1/1); modes 0-3, 6 and 7 all have rotation 0. So this is hardening for tables given toTables::parse(tests,VICTORY_BCPACK_TABLES), and in-game decoding is byte-for-byte the same. It may be worth saying so in the description, since the triage note reads as if a title stream could trigger the panic.Tables::parsecould refuse such ctrl7 entries instead, asbc7already refusesctrl == 0("unused BC7 control code"), so a wrong table file fails loudly. The built-in tables pass that check.rot - 1thatbc7_packuses, so it pins the current behaviour but would not notice a wrong rotation convention. The half for the other modes is an independent check. Optional: compare one rotated mode-4 block with an independent BC7 decode, or note in the comment that this part is a regression pin.AI-assisted review (Claude Code).
@oni-swr on GitHub · 2026-11-26 08:44 UTC · original
Independent CPU test report for PR #3111 (claim: #1633). This is a test report, not a source review.
Tested: head
796c55ec776da567d9c1566867ac3dc13e5d78f2, exact parent63bcca43c6a00a758510398fa43096ce7e4f7df0.Environment: Windows 11, rustc/cargo 1.98.1, CPU only (no GPU, no D3D12).
cargo test --locked -j 4 -p victory-formats, with a privateCARGO_TARGET_DIR.Results
48 passed; 0 failed; 5 ignored(the 5 are benchmarks or tests that need files outside the repository, which were not used). This includes the PR's ownbc7_rotation_applies_only_to_modes_4_and_5.46 passed; 0 failed; 5 ignored(the PR's test is absent there, as expected). With the scratch oracle added:47 passed; 0 failed; 5 ignored.Independent oracle (scratch only, not part of the PR). I wrote a separate test that builds valid single-subset synthetic stream records for BC7 modes 4 and 5. It decodes each record, then parses the output block bit by bit. It checks the mode bit, the 2-bit rotation field and, for mode 4, the index-selection bit. For every rotation 0..3 it then checks that each wire channel slot holds the expected logical channel: slot
jholds the logical channel that rotation swaps into it, with R/G/B/A swapped as in the public BC7 rule, and the alpha-width slot is the 4th. Mode 4 uses 5/5/5/6 bits and mode 5 uses 7/7/7/8. Endpoint values are distinct per channel and endpoint, and a second value set puts wide values in the alpha-width slot. Everything after the endpoints must be zero, since the indices are zero.Not covered: modes 0-3/6/7 with nonzero rotation bits, which are the PR's other behavior change, are exercised only by the PR's own test and not by my oracle. No multi-subset or non-zero index data was checked. All data is synthetic.
Cleanup: the scratch test was removed (working tree clean), and the unique target directory was deleted by literal path and confirmed gone.
AI use: Claude Code (Claude Sonnet 5.5) ran this verification; coordinated with Codex (gpt-6.2-sol) per the claim.
@Dukestar69 on GitHub · 2026-11-26 08:56 UTC · original · approved these changes
Verified against
origin/main(63bcca4):cargo test -p victory-formats -- --test-threads=1: 47/47 passed (5 ignored benches/external; includingbc7_rotation_applies_only_to_modes_4_and_5).cargo clippy -p victory-formats --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly restricts BC7 channel rotation to modes 4 and 5 per spec.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.