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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2148
Author: @abnalstlll-byte
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/dstorage-fit-slices-packed-mip


📝 Commits (3)

  • fc609e0 build_dstorage_history: include packed depth-1 mips in first 256 blocks (DSTORAGE-FIT-SLICES-PACKED-MIP)
  • 5c343d2 Merge main into fix/dstorage-fit-slices-packed-mip (#2148)
  • 45a7cbc build_dstorage_history: say why every 2D mip is fitted in fit_slices (#2148 review)

📊 Changes

2 files changed (+55 additions, -3 deletions)

View changed files

📝 tests/test_bcpack_history_calib.py (+48 -0)
📝 tools/build_dstorage_history.py (+7 -3)

📄 Description

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).


🔄 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/2148 **Author:** [@abnalstlll-byte](https://github.com/abnalstlll-byte) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/dstorage-fit-slices-packed-mip` --- ### 📝 Commits (3) - [`fc609e0`](https://github.com/ubiquitarianism/leonida/commit/fc609e052849e8108bc63fd8fbbedd76c9938ffd) build_dstorage_history: include packed depth-1 mips in first 256 blocks (DSTORAGE-FIT-SLICES-PACKED-MIP) - [`5c343d2`](https://github.com/ubiquitarianism/leonida/commit/5c343d291c3543e0a927116647d31bf4c0bb7349) Merge main into fix/dstorage-fit-slices-packed-mip (#2148) - [`45a7cbc`](https://github.com/ubiquitarianism/leonida/commit/45a7cbc674ddd13e8c4d5a7e7efa688d870c2d98) build_dstorage_history: say why every 2D mip is fitted in fit_slices (#2148 review) ### 📊 Changes **2 files changed** (+55 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_bcpack_history_calib.py` (+48 -0) 📝 `tools/build_dstorage_history.py` (+7 -3) </details> ### 📄 Description 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). --- <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#2152
No description provided.