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

Merged
kawaii-shakal merged 3 commits from upstream-pr/1715 into main 2026-11-28 17:57:34 +00:00
kawaii-shakal commented 2026-11-25 09:20:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-25T09:20:52Z.


Claim: BCPACK-LOST-BLOCK-LIMIT, https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7158195672

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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5488533066 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1715). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-25T09:20:52Z. --- Claim: BCPACK-LOST-BLOCK-LIMIT, https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7158195672 ### 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)
Tyrannys commented 2026-11-25 15:31:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-25T15:31:07Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7166966922 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1715#issuecomment-7166966922). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-25T15:31:07Z. --- **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).
PierreEbele commented 2026-11-25 17:56:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T17:56:18Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7170209721 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1715#issuecomment-7170209721). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T17:56:18Z. --- 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
MoonEyes commented 2026-11-28 17:57:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:57:31Z.


Red/green: On main dstorage_test does not compile because bcpack::Report and the new decode parameters are missing, and main refuses a BC6H/BC7 request with a few lost blocks, and with the PR ctest -R "^dstorage$" passes, including the lost-block rebuild checks.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243418688 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1715#issuecomment-7243418688). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T17:57:31Z. --- Red/green: On main dstorage_test does not compile because bcpack::Report and the new decode parameters are missing, and main refuses a BC6H/BC7 request with a few lost blocks, and with the PR ctest -R "^dstorage$" passes, including the lost-block rebuild checks. Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:53:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:53:14Z.


Verified by OreoFR

  • Base: main c1ecf04ed + PR head 0f71e7670; green run in a merge package of 15 PRs, no new ctest failure vs main
  • Test: ctest -R ^dstorage$
  • Red on main: the test does not compile on main (bcpack::Report missing, C2039)
  • Green with the PR: OK
  • Verdict: READY (merged during the test, at the tested head)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246344864 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1715#issuecomment-7246344864). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:53:14Z. --- **Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `0f71e7670`; green run in a merge package of 15 PRs, no new ctest failure vs main - Test: `ctest -R ^dstorage$` - Red on main: the test does not compile on main (bcpack::Report missing, C2039) - Green with the PR: OK - Verdict: READY (merged during the test, at the tested head) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1715
No description provided.