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

Closed
zmelumian972 wants to merge 662 commits from upstream-pr/466 into main
zmelumian972 commented 2026-11-30 08:29:09 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by zmelumian972 on 2026-11-30T08:29:09Z.


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

<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5561722753 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/466). Originally posted by [zmelumian972](https://github.com/zmelumian972) on 2026-11-30T08:29:09Z. --- 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)
zmelumian972 commented 2026-11-30 17:04:37 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by zmelumian972 on 2026-11-30T17:04:37Z.


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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285681144 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/466#issuecomment-7285681144). Originally posted by [zmelumian972](https://github.com/zmelumian972) on 2026-11-30T17:04:37Z. --- 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

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
TaynanGT/Vice-Tay!466
No description provided.