dstorage: rebuild a BC6H/BC7 request with a few lost blocks instead of failing it (BCPACK-LOST-BLOCK-LIMIT) #1715

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

@⁠kawaii-shakal on GitHub · 2026-11-25 09:20 UTC · original
kawaii-shakal:bcpack-bc7-partial → main · +81 −6 · 5 files · 2 commits · open

Claim: BCPACK-LOST-BLOCK-LIMIT, #1608

What and why

In fitted mode, bcpack::decode rebuilds a BC6H/BC7 block from the local profile's history entry. Some blocks have a predictor chain that starts at an entry the profile does not know. They are rebuilt from the bits the profile has, and are counted as lost. Past max(2, blocks / 1024) lost blocks the whole request fails with E_DSTORAGE_DECOMPRESSION_ERROR (missing-endpoint / missing-index). The destination is then never written, so the texture region stays blank.

On the 1.0.2.1 package, two BC7 requests in data/ttdb/props/octa_imposters.ttpf fail this way at every boot (DadaCap counted 6 of 6 runs in #1537; I see the same two in every boot of mine). With a profile rebuilt by tools/build_dstorage_history.py on main, each request has exactly one unknown endpoint entry:

request (file offset) blocks lost unknown entry
76014336 1,536 5 endpoint 223
455285504 768 15 endpoint 176

A few approximate 4×4 blocks are far cheaper than a blank request. So:

  • runtime/src/bcpack.{h,cpp}:
    • lost blocks get their own limit, max(2, blocks / lost_divisor), through a new lost_divisor parameter;
    • the default stays 1024, so existing callers are unchanged;
    • an optional Report returns the block and lost counts;
    • inconsistent blocks (anchor-or-pbit) keep the 1-in-1,024 limit;
    • strict mode still refuses any lost block.
  • runtime/shims/dstorage.cpp:
    • passes a divisor of 32 by default; LEONIDA_DSTORAGE_LOST_DIVISOR=N overrides it, and 1024 is the old behaviour. A value that is not a positive number is logged once and 32 is used;
    • logs each approximated request ([rt] dstorage: BC7 request approximated N of M blocks ...), the first eight and then at powers of two.
  • docs/directstorage.md: the rule, the switch, and these two requests.

Test

  • runtime/test/dstorage_test.cpp, for both BC6H and BC7, using the test profile with its slot 255 made unknown:

    • at the reference limit the request fails as missing-endpoint;
    • with lost_divisor = 1 it decodes as fitted, and the report has every block and more than 2 lost;
    • strict mode still fails.
  • dstorage_test: 481 checks, 0 failures (Windows 11 Pro 26300, MSVC 19.50). gta6rt builds.

  • The two real requests above were decoded with tools/bcpack.py and the locally fitted JSON profile:

    • with the reference limit, both are refused, 5/1,536 and 15/768 blocks;
    • with 1/32, both decode to their full 24,576 and 12,288 bytes.

    I did not boot the retail title with this branch, so the runtime log line on those two requests is not yet seen. scripts/check_no_game_data.py is clean.

Why 32: it covers these requests (15 of 768 is 1 in 51), and it still refuses a request that has lost a real share of its blocks. It is a judgement, not a measurement. The switch is there to compare against.

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

🤖 Generated with Claude Code

**@⁠kawaii-shakal** on GitHub · 2026-11-25 09:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1715) `kawaii-shakal:bcpack-bc7-partial` → `main` · +81 −6 · 5 files · 2 commits · open Claim: BCPACK-LOST-BLOCK-LIMIT, https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### What and why In fitted mode, `bcpack::decode` rebuilds a BC6H/BC7 block from the local profile's history entry. Some blocks have a predictor chain that starts at an entry the profile does not know. They are rebuilt from the bits the profile has, and are counted as lost. Past `max(2, blocks / 1024)` lost blocks the whole request fails with `E_DSTORAGE_DECOMPRESSION_ERROR` (`missing-endpoint` / `missing-index`). The destination is then never written, so the texture region stays blank. On the 1.0.2.1 package, two BC7 requests in `data/ttdb/props/octa_imposters.ttpf` fail this way at every boot (DadaCap counted 6 of 6 runs in #1537; I see the same two in every boot of mine). With a profile rebuilt by `tools/build_dstorage_history.py` on main, each request has exactly one unknown endpoint entry: | request (file offset) | blocks | lost | unknown entry | |---|---|---|---| | 76014336 | 1,536 | 5 | endpoint 223 | | 455285504 | 768 | 15 | endpoint 176 | A few approximate 4×4 blocks are far cheaper than a blank request. So: - `runtime/src/bcpack.{h,cpp}`: - lost blocks get their own limit, `max(2, blocks / lost_divisor)`, through a new `lost_divisor` parameter; - the default stays 1024, so existing callers are unchanged; - an optional `Report` returns the block and lost counts; - inconsistent blocks (`anchor-or-pbit`) keep the 1-in-1,024 limit; - strict mode still refuses any lost block. - `runtime/shims/dstorage.cpp`: - passes a divisor of 32 by default; `LEONIDA_DSTORAGE_LOST_DIVISOR=N` overrides it, and `1024` is the old behaviour. A value that is not a positive number is logged once and 32 is used; - logs each approximated request (`[rt] dstorage: BC7 request approximated N of M blocks ...`), the first eight and then at powers of two. - `docs/directstorage.md`: the rule, the switch, and these two requests. ### Test - `runtime/test/dstorage_test.cpp`, for both BC6H and BC7, using the test profile with its slot 255 made unknown: - at the reference limit the request fails as `missing-endpoint`; - with `lost_divisor = 1` it decodes as `fitted`, and the report has every block and more than 2 lost; - strict mode still fails. - `dstorage_test`: 481 checks, 0 failures (Windows 11 Pro 26300, MSVC 19.50). `gta6rt` builds. - The two real requests above were decoded with `tools/bcpack.py` and the locally fitted JSON profile: - with the reference limit, both are refused, 5/1,536 and 15/768 blocks; - with 1/32, both decode to their full 24,576 and 12,288 bytes. I did not boot the retail title with this branch, so the runtime log line on those two requests is not yet seen. `scripts/check_no_game_data.py` is clean. Why 32: it covers these requests (15 of 768 is 1 in 51), and it still refuses a request that has lost a real share of its blocks. It is a judgement, not a measurement. The switch is there to compare against. AI-assisted: yes (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A fitted BPTC request whose predictor chains reach a history entry the
local profile does not know was refused once more than max(2, blocks/1024)
blocks were affected, leaving the whole destination untouched. On the
1.0.2.1 package two BC7 requests fail this way at every boot, with one
unknown endpoint entry each (5 of 1,536 and 15 of 768 blocks).

bcpack::decode gets a separate limit for these lost blocks (lost_divisor,
1024 by default, as before) and an optional Report with the block and
lost counts. DirectStorage passes 32 (LEONIDA_DSTORAGE_LOST_DIVISOR) and
logs each approximated request. Inconsistent blocks keep the 1-in-1,024
limit; strict mode refuses any lost block.

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

@⁠Tyrannys on GitHub · 2026-11-25 15:31 UTC · original · edited 2026-11-25 15:53 UTC

Independent verification of head 7b251064ade817ade05a1bfe40d160558ac62604, merged onto current main (71a769d7d) without conflicts.

Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo.

  • dstorage (ctest, which holds the new BC6H/BC7 lost-block checks): pass, "506 checks, 0 failures".
  • The new checks call bcpack::decode with the two new parameters, so they do not compile against main; there is no red run to compare with.

Diff read: the shim's default divisor is 32 (the header's default stays the reference 1024), as docs/directstorage.md says; inconsistent blocks keep the 1-in-1,024 limit; strict mode still refuses. No problem found.

No game files used. AI-assisted (Claude Code).

**@⁠Tyrannys** on GitHub · 2026-11-25 15:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1715#issuecomment-7166966922) · edited 2026-11-25 15:53 UTC **Independent verification** of head `7b251064ade817ade05a1bfe40d160558ac62604`, merged onto current `main` (71a769d7d) without conflicts. Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo. - `dstorage` (ctest, which holds the new BC6H/BC7 lost-block checks): **pass**, "506 checks, 0 failures". - The new checks call `bcpack::decode` with the two new parameters, so they do not compile against `main`; there is no red run to compare with. Diff read: the shim's default divisor is 32 (the header's default stays the reference 1024), as `docs/directstorage.md` says; inconsistent blocks keep the 1-in-1,024 limit; strict mode still refuses. No problem found. No game files used. AI-assisted (Claude Code).
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 17:56 UTC · original

Reviewed 7b25106: dstorage_test itself is MSVC/Windows-only and was not built here. Instead I compiled runtime/src/bcpack.cpp standalone on both this branch and main with the generated tables and vectors, replicated every check the PR adds to test_extended (all pass; the same checks on main behave as this PR's default does), ran tests/test_bcpack.py (20 ok), and probed the policy with a crafted 1536-block BC7 stream whose first five blocks chain to an unknown history entry: main and the default divisor 1024 refuse it as missing-endpoint (the Python reference refuses the same stream with "5/1536 blocks from unknown built-in history entries"), while the DirectStorage divisor 32 rebuilds it fitted and reports 5 lost. The boundary is exactly lost <= max(2, blocks/divisor) (307 admits 5, 308 refuses), strict mode still refuses, and inconsistent blocks keep the old limit. No findings; the package-level counts (5 of 1,536 / 15 of 768) are unverified here without game data.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 17:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1715#issuecomment-7170209721) Reviewed 7b25106: dstorage_test itself is MSVC/Windows-only and was not built here. Instead I compiled runtime/src/bcpack.cpp standalone on both this branch and main with the generated tables and vectors, replicated every check the PR adds to test_extended (all pass; the same checks on main behave as this PR's default does), ran tests/test_bcpack.py (20 ok), and probed the policy with a crafted 1536-block BC7 stream whose first five blocks chain to an unknown history entry: main and the default divisor 1024 refuse it as missing-endpoint (the Python reference refuses the same stream with "5/1536 blocks from unknown built-in history entries"), while the DirectStorage divisor 32 rebuilds it fitted and reports 5 lost. The boundary is exactly lost <= max(2, blocks/divisor) (307 admits 5, 308 refuses), strict mode still refuses, and inconsistent blocks keep the old limit. No findings; the package-level counts (5 of 1,536 / 15 of 768) are unverified here without game data. AI-assisted review. **Recommendation:** Merge
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/1715/head:github-bot/gh-1715'
git switch 'github-bot/gh-1715'

Merge

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