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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1044
Author: @iFeyz
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: feat/bcpack-history


📝 Commits (6)

  • a371a73 RT-BCPACK-DECODER: a runtime BCPack decoder, BC1/BC3/BC4/BC5, checked against tools/bcpack.py
  • eba0442 RT-BCPACK-DECODER: BC7, and a lenient policy for the request path
  • 182b8c1 RT-BCPACK-DECODER: BC6H, so the runtime decoder covers all six BCPack modes
  • 3a5f520 RT-BCPACK-DECODER: review of #991 - say that lenient decoding never applies Python's loose limit, and reuse bytes in decode()
  • e006370 RT-BCPACK-DECODER: DirectStorage BCPack requests decode through the runtime decoder
  • f7a18ee RT-BCPACK-DECODER: the user's calibrated BC6H/BC7 history in the runtime decoder and the request path

📊 Changes

14 files changed (+5320 additions, -47 deletions)

View changed files

📝 docs/directstorage.md (+43 -13)
📝 runtime/CMakeLists.txt (+19 -2)
📝 runtime/shims/dstorage.cpp (+135 -24)
➕ runtime/src/bcpack.cpp (+1082 -0)
➕ runtime/src/bcpack.h (+111 -0)
➕ runtime/src/bcpack_tables.h (+1173 -0)
➕ runtime/test/bcpack_test.cpp (+157 -0)
➕ runtime/test/bcpack_vectors.h (+1584 -0)
➕ runtime/test/bcpack_vectors.py (+417 -0)
📝 runtime/test/dstorage_test.cpp (+137 -8)
➕ tests/test_bcpack_header.py (+48 -0)
➕ tests/test_bcpack_history_sidecar.py (+97 -0)
➕ tools/bcpack_header.py (+234 -0)
➕ tools/bcpack_history_sidecar.py (+83 -0)

📄 Description

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.

🔄 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/1044 **Author:** [@iFeyz](https://github.com/iFeyz) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/bcpack-history` --- ### 📝 Commits (6) - [`a371a73`](https://github.com/ubiquitarianism/leonida/commit/a371a739c3aeda38642429d4fed01eb9605689fb) RT-BCPACK-DECODER: a runtime BCPack decoder, BC1/BC3/BC4/BC5, checked against tools/bcpack.py - [`eba0442`](https://github.com/ubiquitarianism/leonida/commit/eba0442ae36307e93e738f47841dad804ceeae9b) RT-BCPACK-DECODER: BC7, and a lenient policy for the request path - [`182b8c1`](https://github.com/ubiquitarianism/leonida/commit/182b8c1f0c12a47523141aa8b138ccd2f66ef1d7) RT-BCPACK-DECODER: BC6H, so the runtime decoder covers all six BCPack modes - [`3a5f520`](https://github.com/ubiquitarianism/leonida/commit/3a5f5207ae69b1554f9590158175de26d0dd4f78) RT-BCPACK-DECODER: review of #991 - say that lenient decoding never applies Python's loose limit, and reuse bytes in decode() - [`e006370`](https://github.com/ubiquitarianism/leonida/commit/e006370e4bed4d45bc9bf67c935b2c7effe63f8d) RT-BCPACK-DECODER: DirectStorage BCPack requests decode through the runtime decoder - [`f7a18ee`](https://github.com/ubiquitarianism/leonida/commit/f7a18eecddb6db8a050d61fb21c89ca376f775fe) RT-BCPACK-DECODER: the user's calibrated BC6H/BC7 history in the runtime decoder and the request path ### 📊 Changes **14 files changed** (+5320 additions, -47 deletions) <details> <summary>View changed files</summary> 📝 `docs/directstorage.md` (+43 -13) 📝 `runtime/CMakeLists.txt` (+19 -2) 📝 `runtime/shims/dstorage.cpp` (+135 -24) ➕ `runtime/src/bcpack.cpp` (+1082 -0) ➕ `runtime/src/bcpack.h` (+111 -0) ➕ `runtime/src/bcpack_tables.h` (+1173 -0) ➕ `runtime/test/bcpack_test.cpp` (+157 -0) ➕ `runtime/test/bcpack_vectors.h` (+1584 -0) ➕ `runtime/test/bcpack_vectors.py` (+417 -0) 📝 `runtime/test/dstorage_test.cpp` (+137 -8) ➕ `tests/test_bcpack_header.py` (+48 -0) ➕ `tests/test_bcpack_history_sidecar.py` (+97 -0) ➕ `tools/bcpack_header.py` (+234 -0) ➕ `tools/bcpack_history_sidecar.py` (+83 -0) </details> ### 📄 Description 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. --- <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#1082
No description provided.