[PR #2236] build_dstorage_history: fit missing BPTC history slots across multi-level sibling mips (DSTORAGE-MULTILEVEL-MIP-FIT) #2240

Open
opened 2026-11-26 21:20:31 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2236
Author: @zmasi
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/dstorage-multilevel-bcpack-fit


📝 Commits (1)

  • 16a9550 tools/dstorage: fit missing BPTC history slots across multi-level sibling mips

📊 Changes

3 files changed (+351 additions, -4 deletions)

View changed files

📝 docs/directstorage.md (+6 -4)
➕ tests/test_dstorage_multilevel_fit.py (+154 -0)
📝 tools/build_dstorage_history.py (+191 -0)

📄 Description

Claimed in the coordination issue as: DSTORAGE-MULTILEVEL-MIP-FIT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7188273837)

What and why

calibrate_from_pools and fit_slices in tools/build_dstorage_history.py only pair BC6H and BC7 chunks with immediate level ± 1 raw or zlib neighbor mips. When a mixed-codec texture stores lossless raw/zlib at mip[0] (<= 1 MiB) and BCPack across mips[1..N], packed tail and mid-chain BC7/BC6H mips at |level - ref_level| >= 2 are never visited, leaving initial-history slots (eslot = 256 + i - de, islot = 256 + i - di) at 0 bits and causing runtime/src/bcpack.cpp (missing-endpoint at :387) to reject the stream with 0x89240030 (E_DSTORAGE_DECOMPRESSION_ERROR) when transitive descendants exceed max(2, blocks / 1024).

fit_distant_mips runs after calibrate_from_pools and fit_slices (preserving full precedence of existing adjacent-mip, array, and cubemap fits via extend_missing) and scans only BC6H/BC7 chunks whose 256-block prefix still references an unfitted slot (77 / 5,167 BC7 chunks across the 57 retail pools), pairing those mips with the closest raw or zlib mip on the same layer across multi-level mip distances (child upsample for delta_level < 0, parent box average for delta_level > 0) ahead of the native bcpack_history_train full-stream constraint pass.

Across all 57 v1.0.2.1 pools (5,435 BPTC streams evaluated at strict divisor = 1024, counts only):

  • BC7 predictor fields: 4,228 / 6,144 -> 4,336 / 6,144 (+108); index fields 8,160 / 8,192.
  • BC6H predictor slots: endpoints 210 / 256 -> 226 / 256 (+16); indices 249 / 256 -> 251 / 256 (+2).
  • BC6H missing-slot refusals: 0 / 268 (100% pass).
  • BC7 missing-slot refusals: 60 / 5,167 -> 18 / 5,167 (-70%), resolving 25 / 25 mixed-codec BC7 streams (including both world-load 0x89240030 missing-endpoint requests, each decoding with 0 unknown blocks and 0 consistency violations at divisor = 1024). The remaining 18 streams belong to pure-BCPack textures with no raw or zlib mips.

Tested

  • python -m compileall -q make_game.py tools tests (exit 0)
  • python -I tests/test_dstorage_multilevel_fit.py -v (3/3 synthetic multi-level BC7 downsample, BC7 upsample, and BC6H + slot-precedence tests pass; fails without fit_distant_mips)
  • python -I -m unittest discover -s tests -p "test_dstorage_*.py" -v (7/7 pass, including bcpack_history_train integration)
  • python -I tests/test_bcpack_history_calib.py -v (19/19 pass)
  • python -I tests/test_text_write_line_endings.py & python -I -m unittest discover -s tests -p "test_docs_*.py" (55/55 pass)
  • python -I scripts/check_no_game_data.py tools/build_dstorage_history.py docs/directstorage.md tests/test_dstorage_multilevel_fit.py (exit 0)
  • Full 57-pool sidecar rebuild + bcpack_history_train refinement on Windows 11 (fit_distant_mips pass: ~88 s)

GPUs tested: n/a (CPU calibration tool and unit tests; verified on Windows 11 x64, Ryzen 9 5950X / RTX 3090 host)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2236 **Author:** [@zmasi](https://github.com/zmasi) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/dstorage-multilevel-bcpack-fit` --- ### 📝 Commits (1) - [`16a9550`](https://github.com/ubiquitarianism/leonida/commit/16a95502a2ff4eae321718d3aebf4f0c40452cbb) tools/dstorage: fit missing BPTC history slots across multi-level sibling mips ### 📊 Changes **3 files changed** (+351 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/directstorage.md` (+6 -4) ➕ `tests/test_dstorage_multilevel_fit.py` (+154 -0) 📝 `tools/build_dstorage_history.py` (+191 -0) </details> ### 📄 Description Claimed in the coordination issue as: `DSTORAGE-MULTILEVEL-MIP-FIT` (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7188273837) ### What and why `calibrate_from_pools` and `fit_slices` in `tools/build_dstorage_history.py` only pair BC6H and BC7 chunks with immediate `level ± 1` raw or zlib neighbor mips. When a mixed-codec texture stores lossless raw/zlib at `mip[0]` (`<= 1 MiB`) and BCPack across `mips[1..N]`, packed tail and mid-chain BC7/BC6H mips at `|level - ref_level| >= 2` are never visited, leaving initial-history slots (`eslot = 256 + i - de`, `islot = 256 + i - di`) at `0` bits and causing `runtime/src/bcpack.cpp` (`missing-endpoint` at `:387`) to reject the stream with `0x89240030` (`E_DSTORAGE_DECOMPRESSION_ERROR`) when transitive descendants exceed `max(2, blocks / 1024)`. `fit_distant_mips` runs after `calibrate_from_pools` and `fit_slices` (preserving full precedence of existing adjacent-mip, array, and cubemap fits via `extend_missing`) and scans only BC6H/BC7 chunks whose 256-block prefix still references an unfitted slot (`77 / 5,167` BC7 chunks across the 57 retail pools), pairing those mips with the closest raw or zlib mip on the same layer across multi-level mip distances (child upsample for `delta_level < 0`, parent box average for `delta_level > 0`) ahead of the native `bcpack_history_train` full-stream constraint pass. Across all 57 v1.0.2.1 pools (`5,435` BPTC streams evaluated at strict `divisor = 1024`, counts only): - **BC7 predictor fields:** `4,228 / 6,144` -> **`4,336 / 6,144` (`+108`)**; index fields `8,160 / 8,192`. - **BC6H predictor slots:** endpoints `210 / 256` -> **`226 / 256` (`+16`)**; indices `249 / 256` -> **`251 / 256` (`+2`)**. - **BC6H missing-slot refusals:** **`0 / 268` (`100%` pass)**. - **BC7 missing-slot refusals:** `60 / 5,167` -> **`18 / 5,167` (`-70%`)**, resolving `25 / 25` mixed-codec BC7 streams (including both world-load `0x89240030` `missing-endpoint` requests, each decoding with `0` unknown blocks and `0` consistency violations at `divisor = 1024`). The remaining 18 streams belong to pure-BCPack textures with no raw or zlib mips. ### Tested - `python -m compileall -q make_game.py tools tests` (exit 0) - `python -I tests/test_dstorage_multilevel_fit.py -v` (`3/3` synthetic multi-level BC7 downsample, BC7 upsample, and BC6H + slot-precedence tests pass; fails without `fit_distant_mips`) - `python -I -m unittest discover -s tests -p "test_dstorage_*.py" -v` (`7/7` pass, including `bcpack_history_train` integration) - `python -I tests/test_bcpack_history_calib.py -v` (`19/19` pass) - `python -I tests/test_text_write_line_endings.py` & `python -I -m unittest discover -s tests -p "test_docs_*.py"` (`55/55` pass) - `python -I scripts/check_no_game_data.py tools/build_dstorage_history.py docs/directstorage.md tests/test_dstorage_multilevel_fit.py` (exit 0) - Full 57-pool sidecar rebuild + `bcpack_history_train` refinement on Windows 11 (`fit_distant_mips` pass: ~88 s) GPUs tested: n/a (CPU calibration tool and unit tests; verified on Windows 11 x64, Ryzen 9 5950X / RTX 3090 host) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2240
No description provided.