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

Open
davutsimsekk wants to merge 1 commit from upstream-pr/181 into main
davutsimsekk commented 2026-11-25 19:35:18 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by davutsimsekk on 2026-11-25T19:35:18Z.


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.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6612193597 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/181). Originally posted by [davutsimsekk](https://github.com/davutsimsekk) on 2026-11-25T19:35:18Z. --- 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.
KernelSmoker commented 2026-11-25 20:00:49 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by KernelSmoker on 2026-11-25T20:00:49Z.


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.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7173064758 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/181#issuecomment-7173064758). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-25T20:00:49Z. --- 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.
lcg007xd-c commented 2026-11-25 21:10:58 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by lcg007xd-c on 2026-11-25T21:10:58Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6065036480 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/181#pullrequestreview-6065036480). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T21:10:58Z. **Review:** APPROVED --- ### 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.
adrianmjim commented 2026-11-26 19:41:29 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T19:41:29Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7201860192 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/181#issuecomment-7201860192). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T19:41:29Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/181:upstream-pr/181'
git switch 'upstream-pr/181'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/181'
git switch 'upstream-pr/181'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/181'
git switch 'upstream-pr/181'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/181'
git switch 'main'
git merge --squash 'upstream-pr/181'
git switch 'main'
git merge --ff-only 'upstream-pr/181'
git switch 'main'
git merge 'upstream-pr/181'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Belobug/VIctory-Belobug-AMD!181
No description provided.