RT-BCPACK-DECODER: the user's calibrated BC6H/BC7 history in the runtime decoder and the request path #1044

Closed
iFeyz wants to merge 6 commits from upstream-pr/1044 into main
iFeyz commented 2026-11-24 17:10:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by iFeyz on 2026-11-24T17:10:57Z.


Claimed in the coordination issue as: RT-BCPACK-DECODER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7136759575)

Depends on: #976, #982, #991, #1020 (this branch is built on them; its last commit is this pull request)

What and why

The repository carries no built-in BC6H or BC7 BCPack history (tools/bcpack_tables_bptc.py knows none of it), so the
runtime decoder refuses (strict) or zeroes (lenient) every block that reads it, and the retail title's BC7 textures
come out with wrong blocks wherever they do. A user who has calibrated that history from their own copy
(tools/bcpack_history_calib.py, the --history JSON of tools/bcpack.py) can now hand it to the runtime.

  • tools/bcpack_history_sidecar.py: the history JSON (a file, a folder with bc6h.json / bc7.json, or a dict),
    read by load_bc6h / load_bc7 themselves, so the same merging and mid-range fill as tools/bcpack.py, written as
    a 60,936-byte BCPHIST1 sidecar. The layout is the profile of @Moriz82's integration branch in #984
    (tools/gen_bcpack_runtime_tables.py --profile), field for field as far as reading that code shows (I did not run
    it), so one file can serve both.
  • runtime/src/bcpack.{h,cpp}: History gains the BC6H and BC7 tables and read_history_sidecar.
    • BC7: each direct read of a built-in entry is checked as _bc7_check checks it, every bit the block's mode reads
      known, then confirmed. Per read instead of the per-entry maximum Python takes, which refuses exactly the same
      chunks: a slot short for one reader is short for the maximum. The rebuild starts from the calibrated endpoints and
      indices.
    • BC6H: the entry's values; strict needs class 3 with every bit the mode reads confirmed, as _bc6h_blocks does.
    • Lenient counts a block as guessed only when what it reads is still unknown (BC7: missing bits; BC6H: class 0),
      as Python's provisional mode counts them.
  • runtime/shims/dstorage.cpp: the request path reads the sidecar once, from LEONIDA_BCPACK_HISTORY or else
    bcpack_history.bin next to the executable, and decodes with it. A file that is not a sidecar is ignored with a
    log line. The sidecar comes from the user's own data and stays on their machine.
  • Docs: docs/directstorage.md.

Not in this PR: calibrated BC1/BC3/BC4/BC5 history in the request path (History::values takes it, the sidecar does
not carry it).

Tested

  • bcpack_test: a synthetic history (BC7 entries known and confirmed, known only, partly known or absent; BC6H
    entries confirmed with every bit, short of bits, fitted, last resort or unknown), its sidecar written by the tool,
    and 120 BC6H/BC7 chunks that read it often, each with tools/bcpack.py's strict and provisional answers for that
    same history. All agree: 28 strict decodes (8 of them decode only with the history) and 66 provisional ones. A
    sidecar with the wrong magic or size is refused. The earlier 370 cases without history are unchanged. MSVC /W4,
    no warning.
  • dstorage_test: 354 checks, 0 failures; a chunk decodes to Python's blocks through the queue with the sidecar named
    by LEONIDA_BCPACK_HISTORY, and would not without it.
  • tests/test_bcpack_history_sidecar.py: known values at their offsets, the empty history (all zero), the command
    line (writes, refuses its own input, a missing file is an error and not a traceback).
  • Runtime (Windows 11, MSVC 2022 Build Tools, RelWithDebInfo, full build): ctest 302 of 306 pass, dstorage and
    bcpack included. The 4 failures are the same as on main here (d3d12_clear,
    d3d12_execute_indirect_validation, d3d12_texture_tiles, d3d12_pipeline_library_host, all already reported in
    #14).
  • tests/test_bcpack_header.py, tests/test_docs_links.py, tests/test_tool_startup.py,
    tests/test_text_write_line_endings.py, scripts/check_no_game_data.py on every changed file.
    tests/test_tool_stdout_encoding.py lists only tools/native_pso_hashes.py, red on main too.

GPUs tested: n/a (CPU only)

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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5476841783 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1044). Originally posted by [iFeyz](https://github.com/iFeyz) on 2026-11-24T17:10:57Z. --- Claimed in the coordination issue as: RT-BCPACK-DECODER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7136759575) Depends on: #976, #982, #991, #1020 (this branch is built on them; its last commit is this pull request) ### What and why The repository carries no built-in BC6H or BC7 BCPack history (`tools/bcpack_tables_bptc.py` knows none of it), so the runtime decoder refuses (strict) or zeroes (lenient) every block that reads it, and the retail title's BC7 textures come out with wrong blocks wherever they do. A user who has calibrated that history from their own copy (`tools/bcpack_history_calib.py`, the `--history` JSON of `tools/bcpack.py`) can now hand it to the runtime. - **`tools/bcpack_history_sidecar.py`**: the history JSON (a file, a folder with `bc6h.json` / `bc7.json`, or a dict), read by `load_bc6h` / `load_bc7` themselves, so the same merging and mid-range fill as `tools/bcpack.py`, written as a 60,936-byte `BCPHIST1` sidecar. The layout is the profile of @Moriz82's integration branch in #984 (`tools/gen_bcpack_runtime_tables.py --profile`), field for field as far as reading that code shows (I did not run it), so one file can serve both. - **`runtime/src/bcpack.{h,cpp}`**: `History` gains the BC6H and BC7 tables and `read_history_sidecar`. - BC7: each direct read of a built-in entry is checked as `_bc7_check` checks it, every bit the block's mode reads known, then confirmed. Per read instead of the per-entry maximum Python takes, which refuses exactly the same chunks: a slot short for one reader is short for the maximum. The rebuild starts from the calibrated endpoints and indices. - BC6H: the entry's values; strict needs class 3 with every bit the mode reads confirmed, as `_bc6h_blocks` does. - Lenient counts a block as guessed only when what it reads is still unknown (BC7: missing bits; BC6H: class 0), as Python's provisional mode counts them. - **`runtime/shims/dstorage.cpp`**: the request path reads the sidecar once, from `LEONIDA_BCPACK_HISTORY` or else `bcpack_history.bin` next to the executable, and decodes with it. A file that is not a sidecar is ignored with a log line. The sidecar comes from the user's own data and stays on their machine. - **Docs**: `docs/directstorage.md`. Not in this PR: calibrated BC1/BC3/BC4/BC5 history in the request path (`History::values` takes it, the sidecar does not carry it). ### Tested - `bcpack_test`: a synthetic history (BC7 entries known and confirmed, known only, partly known or absent; BC6H entries confirmed with every bit, short of bits, fitted, last resort or unknown), its sidecar written by the tool, and 120 BC6H/BC7 chunks that read it often, each with `tools/bcpack.py`'s strict and provisional answers for that same history. All agree: 28 strict decodes (8 of them decode only with the history) and 66 provisional ones. A sidecar with the wrong magic or size is refused. The earlier 370 cases without history are unchanged. MSVC `/W4`, no warning. - `dstorage_test`: 354 checks, 0 failures; a chunk decodes to Python's blocks through the queue with the sidecar named by `LEONIDA_BCPACK_HISTORY`, and would not without it. - `tests/test_bcpack_history_sidecar.py`: known values at their offsets, the empty history (all zero), the command line (writes, refuses its own input, a missing file is an error and not a traceback). - Runtime (Windows 11, MSVC 2022 Build Tools, RelWithDebInfo, full build): `ctest` 302 of 306 pass, `dstorage` and `bcpack` included. The 4 failures are the same as on `main` here (`d3d12_clear`, `d3d12_execute_indirect_validation`, `d3d12_texture_tiles`, `d3d12_pipeline_library_host`, all already reported in #14). - `tests/test_bcpack_header.py`, `tests/test_docs_links.py`, `tests/test_tool_startup.py`, `tests/test_text_write_line_endings.py`, `scripts/check_no_game_data.py` on every changed file. `tests/test_tool_stdout_encoding.py` lists only `tools/native_pso_hashes.py`, red on `main` too. GPUs tested: n/a (CPU only) 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
morodirule commented 2026-11-24 17:12:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by morodirule on 2026-11-24T17:12:23Z.


Independent Linux check (native g++, no game/GPU/Wine): the portable library builds clean and bcpack_test passes, exit 0 — 28 strict decodes against tools/bcpack.py (8 history-only), 79 lane cases accepted / 41 refused, 140 block cases decoded of 250 checked, plus the lenient path. The Python side also passes: test_bcpack_history_sidecar 4/4, test_bcpack_header 3/3 on head f7a18eecd. This independently confirms the bit-exactness claim on a second OS/compiler. Not claiming; review evidence.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7138845460 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1044#issuecomment-7138845460). Originally posted by [morodirule](https://github.com/morodirule) on 2026-11-24T17:12:23Z. --- Independent Linux check (native g++, no game/GPU/Wine): the portable library builds clean and bcpack_test passes, exit 0 — 28 strict decodes against tools/bcpack.py (8 history-only), 79 lane cases accepted / 41 refused, 140 block cases decoded of 250 checked, plus the lenient path. The Python side also passes: test_bcpack_history_sidecar 4/4, test_bcpack_header 3/3 on head f7a18eecd. This independently confirms the bit-exactness claim on a second OS/compiler. Not claiming; review evidence.
MoonEyes commented 2026-11-27 23:36:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:36:31Z.


Hi @iFeyz, thanks for this series. A heads-up on the stack: its first four pull requests (#976, #982, #991, #1020) were closed on 25 November because main already has a BCPack decoder and the DirectStorage wiring (see the maintainer's note on #1020). #1044 and #1103 are built on top of them, so their diffs (+5,320 and +5,788 lines) still contain that code and conflict with main.

Could you rebase #1044 onto main so that it only keeps what main does not have yet (the calibrated-history sidecar tool and its use on the request path), and say whether main's locally fitted history profile already covers it? #1103 can follow once #1044 is reduced. If #1044 is no longer needed, tell us and we will close both.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230270906 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1044#issuecomment-7230270906). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:36:31Z. --- Hi @iFeyz, thanks for this series. A heads-up on the stack: its first four pull requests (#976, #982, #991, #1020) were closed on 25 November because `main` already has a BCPack decoder and the DirectStorage wiring (see the maintainer's note on #1020). #1044 and #1103 are built on top of them, so their diffs (+5,320 and +5,788 lines) still contain that code and conflict with `main`. Could you rebase #1044 onto `main` so that it only keeps what `main` does not have yet (the calibrated-history sidecar tool and its use on the request path), and say whether `main`'s locally fitted history profile already covers it? #1103 can follow once #1044 is reduced. If #1044 is no longer needed, tell us and we will close both. AI-assisted (Claude Code, Claude Opus 5.5)
DadaCap commented 2026-11-28 10:33:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:33:54Z.


Thanks for the contribution! This PR was reviewed by the maintainers and is being closed as part of a large batch of closures.

Reason: stale and conflicting.

If this looks like a mistake, mention @DadaCap here at any time and it will be looked at again.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237978498 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1044#issuecomment-7237978498). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T10:33:54Z. --- Thanks for the contribution! This PR was reviewed by the maintainers and is being closed as part of a large batch of closures. Reason: stale and conflicting. If this looks like a mistake, mention @DadaCap here at any time and it will be looked at again. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Pull request closed

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!1044
No description provided.