formats: read the first BC7 dictionary entry's 32 indices #181

Open
github-bot wants to merge 1 commit from github-bot/gh-181 into main AGit
Owner

@⁠davutsimsekk on GitHub · 2026-11-25 19:35 UTC · original
davutsimsekk:fix/bc7-dictionary-entry → main · +21 −3 · 1 files · 1 commits · open

The BC7 dictionary reader consumed 32 index words for every entry. The first entry does store all 32 right after its width bytes, but every later entry repeats the width bytes first and then stores 31 indices. The old parser kept the entry size at 116 bytes, but put the repeated width in ix[0][0], so every later index moved one slot and the last slot was read from the zero-filled set 1.

This keeps the 32-index form for entry 0 and skips the repeated width for entries 1-254.

Tested

  • cargo test -p victory-formats --lib --locked bc7_dictionary_entries_keep_their_indices: 1 passed.
  • The test reads the shipped bcpack-tables.bin: entry 0 starts 2,1,0; entry 1 starts 1,0,0 after its repeated width.
  • Windows 11, Rust 1.98.1, locked offline build.

Not tested

  • No in-game decode; the shipped table file was parsed directly.

AI use

  • Automated coding agent for analysis, patch preparation and test runs.
**@⁠davutsimsekk** on GitHub · 2026-11-25 19:35 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/181) `davutsimsekk:fix/bc7-dictionary-entry` → `main` · +21 −3 · 1 files · 1 commits · open The BC7 dictionary reader consumed 32 index words for every entry. The first entry does store all 32 right after its width bytes, but every later entry repeats the width bytes first and then stores 31 indices. The old parser kept the entry size at 116 bytes, but put the repeated width in `ix[0][0]`, so every later index moved one slot and the last slot was read from the zero-filled set 1. This keeps the 32-index form for entry 0 and skips the repeated width for entries 1-254. **Tested** - `cargo test -p victory-formats --lib --locked bc7_dictionary_entries_keep_their_indices`: 1 passed. - The test reads the shipped `bcpack-tables.bin`: entry 0 starts `2,1,0`; entry 1 starts `1,0,0` after its repeated width. - Windows 11, Rust 1.98.1, locked offline build. **Not tested** - No in-game decode; the shipped table file was parsed directly. **AI use** - Automated coding agent for analysis, patch preparation and test runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:26 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-25 20:00 UTC · original

Independent verification on PR head 6281cbb (Bazzite Linux 45 x86_64, Rust 1.98.1):

  • Linux cargo test --offline --locked -p victory-formats: 25 passed, 0 failed, 4 ignored (including bc7_dictionary_entries_keep_their_indices).
  • cargo clippy --offline --locked -p victory-formats --all-targets: 0 warnings.
  • Full binary check across all 255 BC7 dictionary entries in the shipped crates/victory-formats/src/bcpack-tables.bin (last 255 * 116 bytes):
    • Entry 0: bits=(4, 0), first u16 after bits is 2 (no repeated width word), followed by 32 index words (words[16..32] all zero).
    • Entries 1..255: 254/254 have first u16 after bits equal to bits[0] | (bits[1] << 8) (0 mismatches), 0/255 have bits[1] != 0, and 0/255 have any non-zero slot in set 1 (words[17..32] for entries 1..255).
    • Total consumed bytes per entry stays 116 (50 + 2 + 64), so stream alignment is preserved.
**@⁠KernelSmoker** on GitHub · 2026-11-25 20:00 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/181#issuecomment-7173064758) Independent verification on PR head `6281cbb` (Bazzite Linux 45 x86_64, Rust 1.98.1): - Linux `cargo test --offline --locked -p victory-formats`: **25 passed, 0 failed, 4 ignored** (including `bc7_dictionary_entries_keep_their_indices`). - `cargo clippy --offline --locked -p victory-formats --all-targets`: **0 warnings**. - Full binary check across all 255 BC7 dictionary entries in the shipped `crates/victory-formats/src/bcpack-tables.bin` (last `255 * 116` bytes): - Entry `0`: `bits=(4, 0)`, first `u16` after `bits` is `2` (no repeated width word), followed by 32 index words (`words[16..32]` all zero). - Entries `1..255`: **254/254** have first `u16` after `bits` equal to `bits[0] | (bits[1] << 8)` (0 mismatches), **0/255** have `bits[1] != 0`, and **0/255** have any non-zero slot in set 1 (`words[17..32]` for entries `1..255`). - Total consumed bytes per entry stays 116 (`50 + 2 + 64`), so stream alignment is preserved.
Author
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:10 UTC · original · approved these changes

Verified on Linux (Rust 1.98.1)

  • cargo test -p victory-formats --lib on 6281cbb: 25 passed, 0 failed, 4 ignored (main: 24 passed).
  • I reverted only the parser change in Tables::parse and kept the new test. bc7_dictionary_entries_keep_their_indices then fails with left: [3, 1, 0], right: [1, 0, 0]. The test does catch the bug.
  • cargo clippy -p victory-formats --target x86_64-pc-windows-msvc: 0 warnings, same as main.
  • git merge --no-commit --no-ff into current main: merges cleanly.
  • I parsed the last 255 * 116 bytes of bcpack-tables.bin myself. For entries 1..254, the first word after bits equals bits[0] | bits[1] << 8 every time. After that come 16 index words and 15 zero words. Each entry still takes 116 bytes, so the stream stays aligned.

Notes

  1. Entry 0 is a special case based on one data point (bcpack.rs:225). Entry 0 has bits = (4, 0) and words 2, 1, 0, 0, .... The PR reads that as "no repeated width". It could also be a leading field that equals the width in 254 entries but not here. In that reading, entry 0's indices would be [1, 0, 0, ...] instead of [2, 1, 0, ...]. The new test checks that entry 0 is parsed the way main already parsed it, so it doesn't decide between the two. If you have BC7 reference chunks, running the ignored reference_chunks test (VICTORY_BCPACK_TABLES / VICTORY_BCPACK_CASES) on a block that uses dictionary entry 0 would settle it. I'm approving because entries 1..254 are clearly fixed and entry 0 behaves as before.
  2. A small wording point in the description: main did not read into the next entry. It read 116 bytes per entry as well, but put the repeated width in ix[0][0], so every index moved one slot and the 16th index landed in ix[1][0].

Not verified

  • No in-game BC7 decode and no reference-chunk comparison. That data is not in the repository.

Reviewed with Claude Code.

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:10 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/181#pullrequestreview-6065036480) · **approved these changes** ### Verified on Linux (Rust 1.98.1) - `cargo test -p victory-formats --lib` on 6281cbb: 25 passed, 0 failed, 4 ignored (main: 24 passed). - I reverted only the parser change in `Tables::parse` and kept the new test. `bc7_dictionary_entries_keep_their_indices` then fails with `left: [3, 1, 0]`, `right: [1, 0, 0]`. The test does catch the bug. - `cargo clippy -p victory-formats --target x86_64-pc-windows-msvc`: 0 warnings, same as main. - `git merge --no-commit --no-ff` into current main: merges cleanly. - I parsed the last `255 * 116` bytes of `bcpack-tables.bin` myself. For entries 1..254, the first word after `bits` equals `bits[0] | bits[1] << 8` every time. After that come 16 index words and 15 zero words. Each entry still takes 116 bytes, so the stream stays aligned. ### Notes 1. **Entry 0 is a special case based on one data point** (`bcpack.rs:225`). Entry 0 has `bits = (4, 0)` and words `2, 1, 0, 0, ...`. The PR reads that as "no repeated width". It could also be a leading field that equals the width in 254 entries but not here. In that reading, entry 0's indices would be `[1, 0, 0, ...]` instead of `[2, 1, 0, ...]`. The new test checks that entry 0 is parsed the way main already parsed it, so it doesn't decide between the two. If you have BC7 reference chunks, running the ignored `reference_chunks` test (`VICTORY_BCPACK_TABLES` / `VICTORY_BCPACK_CASES`) on a block that uses dictionary entry 0 would settle it. I'm approving because entries 1..254 are clearly fixed and entry 0 behaves as before. 2. A small wording point in the description: main did not read into the next entry. It read 116 bytes per entry as well, but put the repeated width in `ix[0][0]`, so every index moved one slot and the 16th index landed in `ix[1][0]`. ### Not verified - No in-game BC7 decode and no reference-chunk comparison. That data is not in the repository. Reviewed with Claude Code.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:41 UTC · original

Tested natively on Windows 11 (Rust 1.98.1) at 6281cbb, and also with the PR merged onto current main 4f62c2a. The author ran only the new test, so this is the full lib test run on Windows. The tests are CPU-only.

  • cargo test -p victory-formats --lib --locked: 25 passed, 0 failed, 4 ignored on the PR head and on the merge. 4f62c2a alone: 24 passed. Main has no other changes in victory-formats since 000ffdd.

One small thing not mentioned yet:

  • The doc comment on Tables::parse (bcpack.rs:132) still gives the BC7 entry layout as u16 control, 24 u16, 2 u8, 32 i16. With this change, that only matches entry 0. Entries 1-254 are now read as u16 control, 24 u16, 2 u8, u16 (repeated width), 31 i16. It may be worth updating so the layout note matches the parser.

Not tested: no in-game texture decode and no reference-chunk comparison. The entry 0 question from the review is still open.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:41 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/181#issuecomment-7201860192) Tested natively on Windows 11 (Rust 1.98.1) at 6281cbb, and also with the PR merged onto current main 4f62c2a. The author ran only the new test, so this is the full lib test run on Windows. The tests are CPU-only. - `cargo test -p victory-formats --lib --locked`: 25 passed, 0 failed, 4 ignored on the PR head and on the merge. 4f62c2a alone: 24 passed. Main has no other changes in victory-formats since 000ffdd. One small thing not mentioned yet: - The doc comment on `Tables::parse` (bcpack.rs:132) still gives the BC7 entry layout as `u16 control, 24 u16, 2 u8, 32 i16`. With this change, that only matches entry 0. Entries 1-254 are now read as `u16 control, 24 u16, 2 u8, u16 (repeated width), 31 i16`. It may be worth updating so the layout note matches the parser. Not tested: no in-game texture decode and no reference-chunk comparison. The entry 0 question from the review is still open.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/181/head:github-bot/gh-181'
git switch 'github-bot/gh-181'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-181'
git switch 'github-bot/gh-181'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-181'
git switch 'github-bot/gh-181'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-181'
git switch 'main'
git merge --squash 'github-bot/gh-181'
git switch 'main'
git merge --ff-only 'github-bot/gh-181'
git switch 'main'
git merge 'github-bot/gh-181'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.