build_dstorage_history: include packed depth-1 mips in first 256 blocks (DSTORAGE-FIT-SLICES-PACKED-MIP) #2148

Open
github-bot wants to merge 3 commits from github-bot/gh-2148 into main AGit
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 23:34 UTC · original
abnalstlll-byte:fix/dstorage-fit-slices-packed-mip → main · +55 −3 · 2 files · 3 commits · open

Include packed depth-1 mips whose first block lies in the chunk's first 256 blocks in fit_slices() (DSTORAGE-FIT-SLICES-PACKED-MIP).

Problem

In tools/build_dstorage_history.py::fit_slices(), packed depth-1 mips were skipped if their first block fell within the chunk's first 256 blocks:

if d["depth"] == 1:
    first = start + calib.tiled_offset(layout, mip, 0, 0) - virt
    if not 256 * 16 <= first < blocks * 16:
        continue

This was based on the premise that "the usual 2D fit visits only the first 256 physical blocks". However, in packed tails, calibrate_from_pools() does not necessarily visit or fit all packed mips with sibling context (especially where sibling mips share packed tail layouts). Skipping these mips caused the affected BC7 predictor rows to be recorded with ep_bits=0, which runtime/src/bcpack.cpp treats as an unknown predictor entry and counts against the lost-block budget.

Solution

  1. In tools/build_dstorage_history.py::fit_slices(), change the check to if not 0 <= first < blocks * 16: continue. This ensures any packed depth-1 mip whose blocks lie within the chunk is visited and fitted against its sibling.
  2. In tests/test_bcpack_history_calib.py, add test_fit_slices_includes_packed_depth1_mip_in_first_256_blocks verifying that a packed depth-1 mip in the first 256 blocks is properly visited and recovers the expected predictor endpoint bits (depth 8 on entry 91).

Finding by @⁠Undefined3301 in issue #1608.

Verification

  • python -I scripts/check_no_game_data.py tools/build_dstorage_history.py tests/test_bcpack_history_calib.py -> 0 violations.
  • python -I tests/test_text_write_line_endings.py -> 3/3 PASS.
  • python -m compileall -q make_game.py tools tests -> Clean.
  • python -I tests/test_bcpack_history_calib.py -> 20/20 PASS.

AI-assisted (Claude Code).

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 23:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2148) `abnalstlll-byte:fix/dstorage-fit-slices-packed-mip` → `main` · +55 −3 · 2 files · 3 commits · open Include packed depth-1 mips whose first block lies in the chunk's first 256 blocks in `fit_slices()` (DSTORAGE-FIT-SLICES-PACKED-MIP). ### Problem In `tools/build_dstorage_history.py::fit_slices()`, packed depth-1 mips were skipped if their first block fell within the chunk's first 256 blocks: ```python if d["depth"] == 1: first = start + calib.tiled_offset(layout, mip, 0, 0) - virt if not 256 * 16 <= first < blocks * 16: continue ``` This was based on the premise that "the usual 2D fit visits only the first 256 physical blocks". However, in packed tails, `calibrate_from_pools()` does not necessarily visit or fit all packed mips with sibling context (especially where sibling mips share packed tail layouts). Skipping these mips caused the affected BC7 predictor rows to be recorded with `ep_bits=0`, which `runtime/src/bcpack.cpp` treats as an unknown predictor entry and counts against the lost-block budget. ### Solution 1. In `tools/build_dstorage_history.py::fit_slices()`, change the check to `if not 0 <= first < blocks * 16: continue`. This ensures any packed depth-1 mip whose blocks lie within the chunk is visited and fitted against its sibling. 2. In `tests/test_bcpack_history_calib.py`, add `test_fit_slices_includes_packed_depth1_mip_in_first_256_blocks` verifying that a packed depth-1 mip in the first 256 blocks is properly visited and recovers the expected predictor endpoint bits (depth 8 on entry 91). Finding by @⁠Undefined3301 in issue #1608. ### Verification - `python -I scripts/check_no_game_data.py tools/build_dstorage_history.py tests/test_bcpack_history_calib.py` -> 0 violations. - `python -I tests/test_text_write_line_endings.py` -> 3/3 PASS. - `python -m compileall -q make_game.py tools tests` -> Clean. - `python -I tests/test_bcpack_history_calib.py` -> 20/20 PASS. AI-assisted (Claude Code).
In 	ools/build_dstorage_history.py::fit_slices(), packed depth-1 mips
were previously skipped if their first block fell within the first 256
blocks (
ot 256 * 16 <= first < blocks * 16), under the assumption
that the usual 2D fit already visited them. When those mips were skipped,
their BC7 predictor rows were recorded with ep_bits=0, counting against
the lost-block budget in 
untime/src/bcpack.cpp.

Allow
No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The comment now gives the reason: the usual 2D fit stops at each chunk's
first 256 blocks, while a later block still reaches a built-in history
entry through a chain of references, and these results only fill entries
the usual fit left empty.

The test's mip is the top mip at block 0 of its own chunk, not a packed
tail mip; it is named after what it checks, with a docstring. It fails
without the fit_slices change (entry 91 keeps 0 endpoint bits).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:20:07 +00:00
Author
Owner

@⁠JordanWebDev on GitHub · 2026-11-25 23:40 UTC · original · approved these changes

**@⁠JordanWebDev** on GitHub · 2026-11-25 23:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2148#pullrequestreview-6066533794) · **approved these changes**
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 00:42 UTC · original

Thanks! We merged main into the branch and pushed one review commit (45a7cbc67):

  • Comment: it now says why every 2D mip is fitted here. The usual 2D fit stops at each chunk's first 256 blocks, later blocks still reach built-in history entries through chains, and these results only fill entries the usual fit left empty.
  • Test: named after what it checks. Its mip is the top mip at block 0 of its own chunk, not a packed-tail mip. It fails without the change.

Measured on a full v1.0.2.1 copy (57 pools), running build_dstorage_history.py before and after:

  • The predictor profile is byte-identical: BC6H endpoints 210/256, indices 249/256; BC7 endpoint fields 4228/6144, index fields 8160/8192, both ways.
  • The build takes 410 s instead of 127 s.

So on this copy the wider pass costs about 4.7 minutes per build and fills no entry. We're keeping this open:

  • @⁠Undefined3301, could you run build_dstorage_history.py on the pools where you saw the missing-endpoint failures, with and without this branch, and post the Available predictors line from both runs (counts only)? If your copy fills more entries with it, that shows where it helps.
  • The finding's second half (a packed sibling decoded without the local history) doesn't apply to fit_slices as it is: it only takes raw or zlib siblings, and the third read_range argument is a decode cache. If you saw it somewhere else, please say where.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-26 00:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2148#issuecomment-7179037488) Thanks! We merged `main` into the branch and pushed one review commit (`45a7cbc67`): - **Comment:** it now says why every 2D mip is fitted here. The usual 2D fit stops at each chunk's first 256 blocks, later blocks still reach built-in history entries through chains, and these results only fill entries the usual fit left empty. - **Test:** named after what it checks. Its mip is the top mip at block 0 of its own chunk, not a packed-tail mip. It fails without the change. **Measured on a full v1.0.2.1 copy (57 pools), running `build_dstorage_history.py` before and after:** - The predictor profile is byte-identical: BC6H endpoints 210/256, indices 249/256; BC7 endpoint fields 4228/6144, index fields 8160/8192, both ways. - The build takes 410 s instead of 127 s. So on this copy the wider pass costs about 4.7 minutes per build and fills no entry. We're keeping this open: - @⁠Undefined3301, could you run `build_dstorage_history.py` on the pools where you saw the missing-endpoint failures, with and without this branch, and post the `Available predictors` line from both runs (counts only)? If your copy fills more entries with it, that shows where it helps. - **The finding's second half** (a packed sibling decoded without the local history) doesn't apply to `fit_slices` as it is: it only takes raw or zlib siblings, and the third `read_range` argument is a decode cache. If you saw it somewhere else, please say where. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 12:23 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_bcpack_history_calib.py: 20 tests OK. The PR's test file against main's tool: 1 failure, so the new test fails on main and passes with the change. compileall clean.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 12:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2148#issuecomment-7191947318) 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_bcpack_history_calib.py: 20 tests OK. The PR's test file against main's tool: 1 failure, so the new test fails on main and passes with the change. compileall clean. AI-assisted: yes (Claude Code)
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/2148/head:github-bot/gh-2148'
git switch 'github-bot/gh-2148'

Merge

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