bcpack: read 32 BC7 dictionary indices per entry, as BCPack.dll (fixes wrong BC7 textures) #182

Open
github-bot wants to merge 2 commits from github-bot/gh-182 into main AGit
Owner

@⁠lordra9-svg on GitHub · 2026-12-02 00:53 UTC · original
lordra9-svg:fix/bc7-dictionary → main · +89 −10 · 1 files · 2 commits · open

What

Fixes BC7 texture decoding: read 32 indices for every BC7 dictionary entry, as BCPack.dll does. Ported from lobomfz/VIctory-xmem b73c5c5 (verified there against BCPack.dll: 2,101,646 of 2,866,176 of the title's BC7 blocks differ before, 0 after).

Bug

Our Tables::parse skipped the repeated-widths word after a BC7 entry's two width bytes and read 31 indices. BCPack.dll reads 32: in entries 1-254 the first of them IS the widths word (pixel 0's index). So every index of those entries landed one pixel early, and every block predicted from them, i.e. the decoded texture is wrong for ~73% of BC7 blocks.

Change

  • crates/victory-formats/src/bcpack.rs: Tables::parse -> parse_with(bytes, bc7_dictionary()); n = if k == 0 || all { 32 } else { r.u16(); 31 }.
  • VICTORY_BC7_DICTIONARY (default on; =0 restores the old 31-after-the-repeated-widths read) with owner/reason/removal documented.
  • Table file layout/size unchanged (interpretation only; BC7_ENTRY = 50 + 66 keeps the same byte size).

Verified

  • New test bc7_dictionary_entries_read_as_bcpack_dll_reads_them: entry 0 identical; entries 1.. pixel 0 = widths, old ix[0][..15] -> ix[0][1..], old ix[0][15] -> ix[1][0], endpoints/control/ctrl7 unchanged.
  • cargo test -p victory-formats: 50 passed (baseline 49 + new); VICTORY_BC7_DICTIONARY=0 cargo test ... bc7: 4 passed.
  • cargo test -p victory-core -p xtask and vkback policy: pass; clippy -D warnings clean; tools/build.sh exit 0.

Note: verified against the reference's BCPack.dll comparison and a synthetic-table unit test; a local on-screen A/B is pending (the table-parity reference_chunks test still needs the shipped bcpack-tables.bin + cases).

**@⁠lordra9-svg** on GitHub · 2026-12-02 00:53 UTC · [original](https://github.com/vktory6/VKtory/pull/182) `lordra9-svg:fix/bc7-dictionary` → `main` · +89 −10 · 1 files · 2 commits · open ## What Fixes BC7 texture decoding: read **32 indices for every BC7 dictionary entry**, as BCPack.dll does. Ported from lobomfz/VIctory-xmem b73c5c5 (verified there against BCPack.dll: 2,101,646 of 2,866,176 of the title's BC7 blocks differ before, **0 after**). ## Bug Our `Tables::parse` skipped the repeated-widths word after a BC7 entry's two width bytes and read 31 indices. BCPack.dll reads 32: in entries 1-254 the first of them IS the widths word (pixel 0's index). So every index of those entries landed **one pixel early**, and every block predicted from them, i.e. the decoded texture is wrong for ~73% of BC7 blocks. ## Change - `crates/victory-formats/src/bcpack.rs`: `Tables::parse` -> `parse_with(bytes, bc7_dictionary())`; `n = if k == 0 || all { 32 } else { r.u16(); 31 }`. - `VICTORY_BC7_DICTIONARY` (default on; `=0` restores the old 31-after-the-repeated-widths read) with owner/reason/removal documented. - Table file layout/size unchanged (interpretation only; `BC7_ENTRY = 50 + 66` keeps the same byte size). ## Verified - New test `bc7_dictionary_entries_read_as_bcpack_dll_reads_them`: entry 0 identical; entries 1.. pixel 0 = widths, old `ix[0][..15]` -> `ix[0][1..]`, old `ix[0][15]` -> `ix[1][0]`, endpoints/control/ctrl7 unchanged. - `cargo test -p victory-formats`: 50 passed (baseline 49 + new); `VICTORY_BC7_DICTIONARY=0 cargo test ... bc7`: 4 passed. - `cargo test -p victory-core -p xtask` and vkback policy: pass; `clippy -D warnings` clean; `tools/build.sh` exit 0. Note: verified against the reference's BCPack.dll comparison and a synthetic-table unit test; a local on-screen A/B is pending (the table-parity `reference_chunks` test still needs the shipped `bcpack-tables.bin` + cases).
Each BC7 entry of the table file has two width bytes, then 32 words.
BCPack.dll takes all 32 as the entry's indices, pixel 0 first. In entries
1-254 that first word holds the widths again, and parse() took it for a
repeat: it skipped the word and read 31, so every index of those entries
landed one pixel early, and so did every block predicted from them, directly
or through the history. Entry 0, whose first word is not the widths, was
already read with all 32.

Check: 2,101,646 of the title's 2,866,176 BC7 blocks differed before, none
after (trustno1-coder/VIctory-NVIDIA f9de61c5, ubiquitarianism/leonida
b589e0fe, checked against BCPack.dll).

parse() now reads 32 words for every entry. On by default;
VICTORY_BC7_DICTIONARY=0 restores the old reading (read once). The table file
bytes and TABLES_SIZE are unchanged: this is interpretation only.

New bc7_dictionary_entries_read_as_bcpack_dll_reads_them parses a known
table both ways: entry 0 unchanged; in every other entry pixel 0 holds the
widths word, the old indices sit one pixel later, the last of them in set 1's
slot 0; endpoints and control words unchanged.
bc7_dictionary_indices_line_up now asserts what that slot means: no entry
gives set 1 bits, so add_index drops it, and the rest of set 1 stays empty.

Ported from lobomfz/VIctory-xmem b73c5c5.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 00:58:31 +00:00
Author
Owner

@⁠TheRifai on GitHub · 2026-12-02 12:11 UTC · original

Tried the on-screen A/B you noted is pending, but the result is not usable as evidence, so I'm not claiming a visual win from it.

Setup: your branch at 8e1f12d, VICTORY_BC7_DICTIONARY=1 vs =0, RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, VKB_LIVE_SHOT=<base> with <base>.req=3 at 45-50 s, city70 and house save rt3. Three frames each.

  • City scene: mean absolute pixel difference ~30/255, 57% of pixels differ >16 — but viewing the frames shows the scene/camera and the vehicles have drifted; the difference is not attributable to BC7 decoding.
  • House scene: ~8-9/255 mean, 13-15% of pixels differ >16. Localising the difference shows nearly all of it is the Bink video playing on the TV, which is on a different frame in the two runs; outside that rectangle the mean is ~3/255 and no BC7-decoded surface shows a stable difference.

So this is a timing confound, not a refutation of the fix — the unit test and the BCPack.dll comparison remain the evidence. I'd rather record the negative result than attach misleading screenshots. Evidence kept at /home/shlong/Documents/VKtory-capture/bc7-{shot,static}-{on,off}/.

**@⁠TheRifai** on GitHub · 2026-12-02 12:11 UTC · [original](https://github.com/vktory6/VKtory/pull/182#issuecomment-7344967604) Tried the on-screen A/B you noted is pending, but the result is not usable as evidence, so I'm not claiming a visual win from it. Setup: your branch at `8e1f12d`, `VICTORY_BC7_DICTIONARY=1` vs `=0`, RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, `VKB_LIVE_SHOT=<base>` with `<base>.req=3` at 45-50 s, city70 and house save `rt3`. Three frames each. - City scene: mean absolute pixel difference ~30/255, 57% of pixels differ >16 — but viewing the frames shows the scene/camera and the vehicles have drifted; the difference is not attributable to BC7 decoding. - House scene: ~8-9/255 mean, 13-15% of pixels differ >16. Localising the difference shows nearly all of it is the **Bink video playing on the TV**, which is on a different frame in the two runs; outside that rectangle the mean is ~3/255 and no BC7-decoded surface shows a stable difference. So this is a timing confound, not a refutation of the fix — the unit test and the BCPack.dll comparison remain the evidence. I'd rather record the negative result than attach misleading screenshots. Evidence kept at `/home/shlong/Documents/VKtory-capture/bc7-{shot,static}-{on,off}/`.
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 15:28 UTC · original

Thanks, this looks like a real fix: 2.1M of 2.87M BC7 blocks differ before it and none after. Three things before it can merge:

  • Drop VICTORY_BC7_DICTIONARY. =0 restores a read we know is wrong, so the switch has only one working setting (rules 2 and 33).
  • State what BCPack.dll does in the comment. Right now it cites forks, and the PR text and the comment name different ones (rules 3 and 15).
  • Show it. Please post a run of bc7_dictionary_indices_line_up with VICTORY_BCPACK_TABLES set (the PR changes that test's assertion), plus before/after screenshots of a BC7 texture that uses the tables, no game content beyond a plain description. We don't have the tables on this machine, so we can't produce that evidence ourselves.
**@⁠vktory6** on GitHub · 2026-12-02 15:28 UTC · [original](https://github.com/vktory6/VKtory/pull/182#issuecomment-7350387094) Thanks, this looks like a real fix: 2.1M of 2.87M BC7 blocks differ before it and none after. Three things before it can merge: - **Drop `VICTORY_BC7_DICTIONARY`.** `=0` restores a read we know is wrong, so the switch has only one working setting (rules 2 and 33). - **State what BCPack.dll does in the comment.** Right now it cites forks, and the PR text and the comment name different ones (rules 3 and 15). - **Show it.** Please post a run of `bc7_dictionary_indices_line_up` with `VICTORY_BCPACK_TABLES` set (the PR changes that test's assertion), plus before/after screenshots of a BC7 texture that uses the tables, no game content beyond a plain description. We don't have the tables on this machine, so we can't produce that evidence ourselves.
Author
Owner

@⁠firefloc on GitHub · 2026-12-02 17:29 UTC · original

I ran bc7_dictionary_indices_line_up against PR head 8e1f12de with local BCPack tables: 1 passed, 0 failed, 0 ignored. To rule out the test's silent early return when table loading fails, I changed only that return to Tables::load().expect(...) in an isolated source copy. A nonexistent table path made the test fail, and the same test passed with the local tables and VICTORY_BC7_DICTIONARY unset. The test ran offline without Proton or the GPU.

This confirms the dictionary-index assertions for these tables. The requested visual before/after check remains open. When removing the toggle and the legacy branch, please also update the Tables::parse layout description, which still says 31 indices even though the revised path reads 32 words for every entry.

**@⁠firefloc** on GitHub · 2026-12-02 17:29 UTC · [original](https://github.com/vktory6/VKtory/pull/182#issuecomment-7353356554) I ran `bc7_dictionary_indices_line_up` against PR head `8e1f12de` with local BCPack tables: **1 passed, 0 failed, 0 ignored**. To rule out the test's silent early return when table loading fails, I changed only that return to `Tables::load().expect(...)` in an isolated source copy. A nonexistent table path made the test fail, and the same test passed with the local tables and `VICTORY_BC7_DICTIONARY` unset. The test ran offline without Proton or the GPU. This confirms the dictionary-index assertions for these tables. The requested visual before/after check remains open. When removing the toggle and the legacy branch, please also update the `Tables::parse` layout description, which still says 31 indices even though the revised path reads 32 words for every entry.
Author
Owner

@⁠firefloc on GitHub · 2026-12-02 18:50 UTC · original

Rechecked the unconditional 32-word parser on 55369b31. bc7_dictionary_indices_line_up passed with local tables (1 passed, 0 failed, 0 ignored). In an isolated test copy, requiring table load explicitly made the same test fail with a missing table path. The current head also removes the toggle and updates the format description.

As a separate synthetic test, the same tables and 64 synthetic records produced different BC7 output blocks in all 64 cases when comparing the current parser with a simulation of the old index interpretation. This establishes that the index change affects decoded blocks in that fixture. The BCPack.dll comparison and the requested matched visual evidence are separate checks.

**@⁠firefloc** on GitHub · 2026-12-02 18:50 UTC · [original](https://github.com/vktory6/VKtory/pull/182#issuecomment-7355243963) Rechecked the unconditional 32-word parser on `55369b31`. `bc7_dictionary_indices_line_up` passed with local tables (1 passed, 0 failed, 0 ignored). In an isolated test copy, requiring table load explicitly made the same test fail with a missing table path. The current head also removes the toggle and updates the format description. As a separate synthetic test, the same tables and 64 synthetic records produced different BC7 output blocks in all 64 cases when comparing the current parser with a simulation of the old index interpretation. This establishes that the index change affects decoded blocks in that fixture. The BCPack.dll comparison and the requested matched visual evidence are separate checks.
Drop VICTORY_BC7_DICTIONARY: the 31-index read it restored is wrong, so
the switch had only one working setting. Tables::parse now reads the 32
words after the two width bytes for every entry, and the legacy path is
gone.

The comment states what BCPack.dll's decoder does with those words,
citing BCPack.dll's block differential, instead of naming forks, and the
Tables::parse layout description says 32 u16 indices per BC7 entry.

The dictionary test asserts the single parse result against the known
blob words; bc7_dictionary_indices_line_up runs on the same unconditional
path.
Author
Owner

@⁠lordra9-svg on GitHub · 2026-12-02 19:14 UTC · original

Ran the dictionary tests with the real tables on the current head (55369b3, after dropping the switch):

$ ls -l ~/.vktory-data/bcpack-tables.bin
-rw-r--r-- 1 ... 77982 ... bcpack-tables.bin
$ VICTORY_BCPACK_TABLES=~/.vktory-data/bcpack-tables.bin cargo test -p victory-formats bc7_dictionary -- --nocapture
running 2 tests
test bcpack::tests::bc7_dictionary_indices_line_up ... ok
test bcpack::tests::bc7_dictionary_entries_read_as_bcpack_dll_reads_them ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 53 filtered out

The three review items are in that head: VICTORY_BC7_DICTIONARY is gone (32 readings unconditional), the parse-site comment states what BCPack.dll's decoder does (32 words, pixel 0 first) with the 31-vs-32 block differential, and Tables::parse's layout says 32 index words.

On the visual pair: I can't produce an honest one from this machine. My F9 capture path is not writing frames here, and the save I have is an animated cutscene — TheRifai's A/B already showed that timing confound. Rather than post a misleading pair, I can render a synthetic BC7 texture (a known block encoded with the title's tables, decoded by the old 31-word and the new 32-word path, side by side) so the difference is real and there is no game content; or use a static save if you have one in mind. Which would you prefer?

**@⁠lordra9-svg** on GitHub · 2026-12-02 19:14 UTC · [original](https://github.com/vktory6/VKtory/pull/182#issuecomment-7355840015) Ran the dictionary tests with the real tables on the current head (`55369b3`, after dropping the switch): ``` $ ls -l ~/.vktory-data/bcpack-tables.bin -rw-r--r-- 1 ... 77982 ... bcpack-tables.bin $ VICTORY_BCPACK_TABLES=~/.vktory-data/bcpack-tables.bin cargo test -p victory-formats bc7_dictionary -- --nocapture running 2 tests test bcpack::tests::bc7_dictionary_indices_line_up ... ok test bcpack::tests::bc7_dictionary_entries_read_as_bcpack_dll_reads_them ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 53 filtered out ``` The three review items are in that head: `VICTORY_BC7_DICTIONARY` is gone (32 readings unconditional), the parse-site comment states what BCPack.dll's decoder does (32 words, pixel 0 first) with the 31-vs-32 block differential, and `Tables::parse`'s layout says 32 index words. On the visual pair: I can't produce an honest one from this machine. My F9 capture path is not writing frames here, and the save I have is an animated cutscene — TheRifai's A/B already showed that timing confound. Rather than post a misleading pair, I can render a **synthetic** BC7 texture (a known block encoded with the title's tables, decoded by the old 31-word and the new 32-word path, side by side) so the difference is real and there is no game content; or use a static save if you have one in mind. Which would you prefer?
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/182/head:github-bot/gh-182'
git switch 'github-bot/gh-182'

Merge

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