Fit BC1's BCPack tables from the game's own texture stores #466

Closed
github-bot wants to merge 662 commits from github-bot/gh-466 into main AGit
Owner

@⁠zmelumian972 on GitHub · 2026-11-30 08:29 UTC · original
zmelumian972:bcpack-bc1-fit → main · +61117 −5449 · 210 files · 662 commits · closed without merging

Builds on #465 (its commit is included here; review that one first).

Without VICTORY_BCPACK_TABLES, every BCPack texture comes out as block noise (#385). victory bcpack-fit now fits what BC1 needs from the player's own .ttpf stores and writes it to cache_dir/bcpack/. Runs decode BC1 requests with it when the format tables aren't set. BC3–BC7 still need the tables; in GTA VI's stores that's about 1,400 of the roughly 32,400 textures that use BCPack. The fitted file is derived data and never enters the repository.

The fit learns from mips stored as one BC1 BCPack chunk whose next smaller mip is stored plain. The entropy layer uses Microsoft's published models, and with them every packed BC1 chunk in the title decodes. Blocks whose back-reference chain starts with no reference have exact endpoints. On those, each quadrant index symbol gets its 2x2 pattern from the next mip and from the edges it makes with neighbouring pixels. The patterns form a one-to-one table, solved as an assignment and refitted until it stops changing. Once the indices are known, each dictionary entry is searched per colour channel over the blocks whose chains start at it, then refined through the real BC1 palette, which switches to three colours when endpoint 0 is not above endpoint 1. Each entry samples at most 100 blocks per mip and 2,000 per store, so no single texture decides it.

Held out, fitted on half the stores and scored on the other half: decoded mips, shrunk to half size, against the game's stored next mip had a median of 36.5 dB (p10 30.3). Plain textures, the best this measure can score, reach 37.7 dB (p10 30.1). With an empty dictionary the median is 6.7 dB. Within the same packed textures, blocks whose chains start at a dictionary entry score MSE 23.0 against the next mip, and blocks with exact endpoints 17.9. Even the best value per texture for each entry only reaches about 19, so most of the remaining gap is in the blocks, not the tables. Fits on the two halves agree on 254 of 256 index-table entries. The full fit takes about 1 minute 40 seconds under Wine, two runs give byte-identical tables,, and play.sh and play.ps1 run it once with --if-needed.

Testing: the fitter's tests pass, as do the BCPack tests in victory-formats and the dstorage BCPack tests under Wine. The asset policy check passes, and the Windows build compiles without warnings. Decoded textures matched their next mip visually. I couldn't check textures in game: on my RTX 5090 under Wine, scripted 150-second runs with and without the fitted tables both ended with exit code 5 (#221) before any textured scene. No screen recorder worked on that session, so there is no video.

🤖 Generated with Claude Code

**@⁠zmelumian972** on GitHub · 2026-11-30 08:29 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/466) `zmelumian972:bcpack-bc1-fit` → `main` · +61117 −5449 · 210 files · 662 commits · closed without merging Builds on #465 (its commit is included here; review that one first). Without `VICTORY_BCPACK_TABLES`, every BCPack texture comes out as block noise (#385). `victory bcpack-fit` now fits what BC1 needs from the player's own `.ttpf` stores and writes it to `cache_dir/bcpack/`. Runs decode BC1 requests with it when the format tables aren't set. BC3–BC7 still need the tables; in GTA VI's stores that's about 1,400 of the roughly 32,400 textures that use BCPack. The fitted file is derived data and never enters the repository. The fit learns from mips stored as one BC1 BCPack chunk whose next smaller mip is stored plain. The entropy layer uses Microsoft's published models, and with them every packed BC1 chunk in the title decodes. Blocks whose back-reference chain starts with no reference have exact endpoints. On those, each quadrant index symbol gets its 2x2 pattern from the next mip and from the edges it makes with neighbouring pixels. The patterns form a one-to-one table, solved as an assignment and refitted until it stops changing. Once the indices are known, each dictionary entry is searched per colour channel over the blocks whose chains start at it, then refined through the real BC1 palette, which switches to three colours when endpoint 0 is not above endpoint 1. Each entry samples at most 100 blocks per mip and 2,000 per store, so no single texture decides it. Held out, fitted on half the stores and scored on the other half: decoded mips, shrunk to half size, against the game's stored next mip had a median of 36.5 dB (p10 30.3). Plain textures, the best this measure can score, reach 37.7 dB (p10 30.1). With an empty dictionary the median is 6.7 dB. Within the same packed textures, blocks whose chains start at a dictionary entry score MSE 23.0 against the next mip, and blocks with exact endpoints 17.9. Even the best value per texture for each entry only reaches about 19, so most of the remaining gap is in the blocks, not the tables. Fits on the two halves agree on 254 of 256 index-table entries. The full fit takes about 1 minute 40 seconds under Wine, two runs give byte-identical tables,, and `play.sh` and `play.ps1` run it once with `--if-needed`. Testing: the fitter's tests pass, as do the BCPack tests in `victory-formats` and the `dstorage` BCPack tests under Wine. The asset policy check passes, and the Windows build compiles without warnings. Decoded textures matched their next mip visually. I couldn't check textures in game: on my RTX 5090 under Wine, scripted 150-second runs with and without the fitted tables both ended with exit code 5 (#221) before any textured scene. No screen recorder worked on that session, so there is no video. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Microsoft published the 128 static rANS models of the BCPack decoder in
silicon-rans (mdu_minirans.v, MIT). They equal the first 2,304 bytes of the
format tables, so they can ship with VIctory under that licence.

- bcpack_models.rs: MODEL_FREQS, generated from freq_table, with the MIT notice.
- dstorage: refuse a VICTORY_BCPACK_TABLES file whose models differ, so a
  wrong or corrupt file is reported instead of decoding to block noise (#385).
- Synthetic test tables use the real models instead of uniform ones.

The rank tables, BC7 control words and dictionaries still come only from the
user's local file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Without VICTORY_BCPACK_TABLES every BCPack texture came out as block noise
(#385). `victory bcpack-fit` now fits what BC1 needs from the player's own
.ttpf stores, writes it to cache_dir/bcpack/, and runs decode BC1 requests
with it. Other BCPack formats still need the format tables.

- Training pairs: a mip stored as one BC1 BCPack chunk whose next mip is
  plain. Entropy layer from Microsoft's published models (every packed BC1
  chunk in the title decodes).
- Quadrant index table: symbols 0-3 are the uniform patterns; the rest a
  bijection (Hungarian) on next-mip and full-resolution edge costs over
  blocks with exact endpoints, refitted until stable. Fits on disjoint
  halves of the stores agree on 254 of 256 entries.
- Dictionary endpoints: with the indices known a quadrant's mean is linear
  in its endpoints, so each entry is searched per colour channel.
- Held out (fitted on even stores, scored on odd): decoded mips against
  their plain next mip, median 36.5 dB (p10 30.1); plain textures, the
  ceiling, 37.7 dB (p10 30.1); zero dictionary 6.7 dB.
- The fit takes about two minutes; play.sh and play.ps1 run it once.
- bcpack::bc1_symbols and Tables::models_only expose the entropy layer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 08:30:52 +00:00
Two changes to the endpoint fit, from measuring where its error is:

- Each entry is refined by coordinate descent through the real BC1
  palette after the per-channel search. The search assumes four-colour
  blocks; BC1 switches to three colours when endpoint 0 is not above
  endpoint 1, which only a joint fit sees.
- Samples are spread: at most 100 blocks per entry from one mip and 2,000
  from one store, instead of the first 20,000 to arrive. One or two
  textures could decide an entry before; 11 held-out textures agreed that
  entry 62 had the wrong value.

Held out (fitted on even stores, scored on odd), error of blocks whose
chain starts at a dictionary entry: MSE 29.5 before, 23.0 after; blocks
with exact endpoints score 17.9. The per-texture median stays 36.5 dB
(p10 30.1 -> 30.3): the rest of the gap to plain textures is in the
blocks, not the tables (the best value per texture only reaches ~19).
The fit takes 1:41 under Wine and two runs give byte-identical tables.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot closed this pull request 2026-11-30 17:08:21 +00:00
Author
Owner

@⁠zmelumian972 on GitHub · 2026-11-30 17:04 UTC · original

Superseded by the new main, which ships the full BCPack tables built in (Tables::builtin). There are no tables left to fit from the game's texture stores.

**@⁠zmelumian972** on GitHub · 2026-11-30 17:04 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/466#issuecomment-7285681144) Superseded by the new main, which ships the full BCPack tables built in (`Tables::builtin`). There are no tables left to fit from the game's texture stores.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.