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

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

@⁠zmasi on GitHub · 2026-11-26 09:53 UTC · original
zmasi:fix/dstorage-multilevel-bcpack-fit → main · +391 −10 · 3 files · 2 commits · open

Claimed in the coordination issue as: DSTORAGE-MULTILEVEL-MIP-FIT (#1608)

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.
**@⁠zmasi** on GitHub · 2026-11-26 09:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2236) `zmasi:fix/dstorage-multilevel-bcpack-fit` → `main` · +391 −10 · 3 files · 2 commits · open Claimed in the coordination issue as: `DSTORAGE-MULTILEVEL-MIP-FIT` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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.
When a BC6H or BC7 stream still references an unfitted built-in predictor slot after adjacent-mip fitting, pair its mips with the closest raw or zlib mip on the same layer across multi-level mip distances before running the full-stream constraint pass. Existing adjacent-mip, array, and cubemap fits keep precedence.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:24:06 +00:00
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 10:12 UTC · original

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU, no game data). Merges cleanly. With this PR, python -I tests/test_dstorage_multilevel_fit.py: 3 tests OK. The PR's test file against main's tools: 3 errors, so the new tests fail on main and pass with the change. compileall clean.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 10:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2236#issuecomment-7189060639) Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU, no game data). Merges cleanly. With this PR, python -I tests/test_dstorage_multilevel_fit.py: 3 tests OK. The PR's test file against main's tools: 3 errors, so the new tests fail on main and pass with the change. compileall clean. AI-assisted: yes (Claude Code)
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 10:55 UTC · original · reviewed

Tested this head locally with synthetic fixtures. In Ubuntu on WSL, all 7 DirectStorage tests passed, including a native bcpack_history_train build and build/resume/repair, the BC7 parent and child cases, and BC6H slot precedence. On Windows, the 6 Python checks passed and the native fitter integration skipped without a C++ compiler on PATH. No findings from these checks. The retail pool coverage numbers were outside this run.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 10:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2236#pullrequestreview-6072873344) · **reviewed** Tested this head locally with synthetic fixtures. In Ubuntu on WSL, all 7 DirectStorage tests passed, including a native `bcpack_history_train` build and build/resume/repair, the BC7 parent and child cases, and BC6H slot precedence. On Windows, the 6 Python checks passed and the native fitter integration skipped without a C++ compiler on PATH. No findings from these checks. The retail pool coverage numbers were outside this run. AI-assisted.
Run fit_distant_mips ahead of fit_decoded_neighbors so mixed-codec BC6H and BC7 streams fit directly against lossless raw/zlib mips across multi-level distances before iterative BCPack sibling decoding, eliminating all 10 remaining BC6H stream refusals on 1.0.2.1 (210 -> 226/256 endpoints, 249 -> 251/256 indices) and cutting fit_decoded_neighbors runtime by 46%.
Author
Owner

@⁠zmasi on GitHub · 2026-11-27 00:20 UTC · original

Thanks @⁠real-rusher and @⁠lixonik for verifying the synthetic and native fitter checks!

Merged main (d1dff7949, including 2a491668a and #2124) cleanly in 801f8e7b7 and re-measured the 57-pool corpus directly against d1dff7949 alone vs d1dff7949 + fit_distant_mips:

Metric (57 pools, 5,435 BPTC streams) main (d1dff7949) main + #2236 (801f8e7b7) Delta
BC6H endpoint rows 210 / 256 226 / 256 +16
BC6H index rows 249 / 256 251 / 256 +2
BC6H refused streams 10 / 268 0 / 268 -10 (100% pass)
BC7 endpoint fields 4,406 / 6,144 4,406 / 6,144 (4,336 lossless-anchored, low2Fits = 7 vs 6) Lossless-anchored + +1 low2Fit
BC7 index fields 8,160 / 8,192 8,160 / 8,192 0
BC7 refused streams 8 / 5,167 8 / 5,167 0
Supplemental fit runtime (fit_distant + fit_decoded) 1,185.56 s 767.73 s (136.06 s + 631.56 s) -417.83 s (-35.2%)
  • Why fit_distant_mips complements fit_decoded_neighbors (2a491668a): fit_decoded_neighbors skips refused BC6H siblings (10 / 268 left refused on main), whereas running fit_distant_mips immediately ahead of fit_decoded_neighbors pairs mixed-codec BPTC mips directly against lossless raw/zlib mips across multi-level distances — eliminating all 10 / 268 remaining BC6H refusals, anchoring 4,336 BC7 endpoint fields directly from lossless mips, and cutting fit_decoded_neighbors runtime by 46.7% (-35.2% overall).
  • Added regression test: test_refused_bc6h_intermediate_sibling_falls_back_to_multilevel_zlib_mip in tests/test_dstorage_multilevel_fit.py (10 / 10 DirectStorage tests passing).

No game files. AI-assisted.

**@⁠zmasi** on GitHub · 2026-11-27 00:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2236#issuecomment-7206377111) Thanks @⁠real-rusher and @⁠lixonik for verifying the synthetic and native fitter checks! Merged `main` (`d1dff7949`, including `2a491668a` and `#2124`) cleanly in `801f8e7b7` and re-measured the 57-pool corpus directly against `d1dff7949` alone vs `d1dff7949 + fit_distant_mips`: | Metric (57 pools, 5,435 BPTC streams) | `main` (`d1dff7949`) | `main` + `#2236` (`801f8e7b7`) | Delta | |---|---:|---:|---:| | **BC6H endpoint rows** | `210 / 256` | **`226 / 256`** | **`+16`** | | **BC6H index rows** | `249 / 256` | **`251 / 256`** | **`+2`** | | **BC6H refused streams** | `10 / 268` | **`0 / 268`** | **`-10` (`100%` pass)** | | **BC7 endpoint fields** | `4,406 / 6,144` | **`4,406 / 6,144`** (`4,336` lossless-anchored, `low2Fits = 7` vs `6`) | Lossless-anchored + `+1` `low2Fit` | | **BC7 index fields** | `8,160 / 8,192` | **`8,160 / 8,192`** | `0` | | **BC7 refused streams** | `8 / 5,167` | **`8 / 5,167`** | `0` | | **Supplemental fit runtime (`fit_distant` + `fit_decoded`)** | `1,185.56 s` | **`767.73 s`** (`136.06 s` + `631.56 s`) | **`-417.83 s` (`-35.2%`)** | - **Why `fit_distant_mips` complements `fit_decoded_neighbors` (`2a491668a`):** `fit_decoded_neighbors` skips refused BC6H siblings (`10 / 268` left refused on `main`), whereas running `fit_distant_mips` immediately ahead of `fit_decoded_neighbors` pairs mixed-codec BPTC mips directly against lossless raw/zlib mips across multi-level distances — eliminating all `10 / 268` remaining BC6H refusals, anchoring `4,336` BC7 endpoint fields directly from lossless mips, and cutting `fit_decoded_neighbors` runtime by `46.7%` (`-35.2%` overall). - **Added regression test:** `test_refused_bc6h_intermediate_sibling_falls_back_to_multilevel_zlib_mip` in `tests/test_dstorage_multilevel_fit.py` (`10 / 10` DirectStorage tests passing). No game files. AI-assisted.
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/2236/head:github-bot/gh-2236'
git switch 'github-bot/gh-2236'

Merge

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