[PR #1103] RT-BCPACK-DECODER: the user's calibrated BC1/BC3/BC4/BC5 history in the sidecar and the request path #1139

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

📋 Pull Request Information

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

Base: main ← Head: feat/bcpack-history-bc15


📝 Commits (7)

  • 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
  • 0265612 RT-BCPACK-DECODER: the user's calibrated BC1/BC3/BC4/BC5 history in the sidecar and the request path

📊 Changes

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

View changed files

📝 docs/directstorage.md (+50 -13)
📝 runtime/CMakeLists.txt (+19 -2)
📝 runtime/shims/dstorage.cpp (+139 -24)
➕ runtime/src/bcpack.cpp (+1113 -0)
➕ runtime/src/bcpack.h (+114 -0)
➕ runtime/src/bcpack_tables.h (+1173 -0)
➕ runtime/test/bcpack_test.cpp (+183 -0)
➕ runtime/test/bcpack_vectors.h (+1885 -0)
➕ runtime/test/bcpack_vectors.py (+443 -0)
📝 runtime/test/dstorage_test.cpp (+148 -8)
➕ tests/test_bcpack_header.py (+48 -0)
➕ tests/test_bcpack_history_sidecar.py (+128 -0)
➕ tools/bcpack_header.py (+234 -0)
➕ tools/bcpack_history_sidecar.py (+111 -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, #1044 (this branch is built on them; its last commit is this pull request)

What and why

#1044 brought the user's calibrated BC6H/BC7 history to the runtime decoder and left BC1/BC3/BC4/BC5 out. Those
matter as much: the repository's tables confirm 252 BC1 entries but none for BC3, 2 for BC4 and 5 for BC5, so
without a calibration nearly every BC3/BC4/BC5 block that predicts from the built-in history is decoded from zeros
on the request path (and the retail title asks for mode 5, issue #14 comment 7135719755).

  • tools/bcpack_history_sidecar.py: when the history JSON has a bc1 / bc3 / bc4 / bc5 section (read by
    load_bc_history, as tools/bcpack.py --history reads it), a BC15HIS1 section follows the BC6H/BC7 tables: per
    mode a given byte, the section's replace byte and its 256 confirmed entries (int16, -1 where not confirmed).
    71,192 bytes in all. A history without those sections still gives the 60,936-byte file of #984's profile, byte
    for byte
    ; only a file with BC1-5 history is longer, which #984's profile reader may not take.
  • runtime/src/bcpack.{h,cpp}: History::replace, and read_history_sidecar reads the optional section. The
    merge is _resolve_bc_history's: an entry given there wins over the built-in one, and with replace the built-in
    table is not read. Provisional entries are not written, as for the built-in tables (strict decoding takes confirmed
    history only).
  • runtime/shims/dstorage.cpp: the request path reads files up to 128 KiB (it stopped at 70,000 bytes, which
    would have cut the longer sidecar and ignored it), and its log line says whether BC1-5 history came with it.
  • Docs: docs/directstorage.md; the "not done yet" entry for this is gone.

Tested

  • bcpack_test: the synthetic history now has BC1-5 sections (BC1 replacing its table, the one with many confirmed
    entries; BC4 and BC5 merged, with confirmed and provisional entries; BC3 not given), and 100 BC1-5 chunks that read
    the built-in history often, each with tools/bcpack.py's strict answer for that same history. All agree; 10 decode
    only with the history, and BC1's replace decides the result of 9 (checked by decoding them with the flag off).
    The sidecar without its BC1-5 section (#984's size) still reads. The earlier cases are unchanged: the BC1-5 part
    has a random generator of its own, so the regenerated header only adds.
  • dstorage_test: 355 checks, 0 failures. Its BC1 chunk is now one whose blocks are the same with the calibrated
    history, since that history replaces BC1's built-in table for the whole process; a failing check now names its case.
  • tests/test_bcpack_history_sidecar.py (6): the BC15HIS1 offsets, flags and a provisional entry left out, and the
    unchanged size without BC1-5 sections.
  • 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, runtime/test/bcpack_vectors.py --check, 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.

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/1103 **Author:** [@iFeyz](https://github.com/iFeyz) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/bcpack-history-bc15` --- ### 📝 Commits (7) - [`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 - [`0265612`](https://github.com/ubiquitarianism/leonida/commit/0265612f1084ed065cd4429bcf70fd1c30584cc7) RT-BCPACK-DECODER: the user's calibrated BC1/BC3/BC4/BC5 history in the sidecar and the request path ### 📊 Changes **14 files changed** (+5788 additions, -47 deletions) <details> <summary>View changed files</summary> 📝 `docs/directstorage.md` (+50 -13) 📝 `runtime/CMakeLists.txt` (+19 -2) 📝 `runtime/shims/dstorage.cpp` (+139 -24) ➕ `runtime/src/bcpack.cpp` (+1113 -0) ➕ `runtime/src/bcpack.h` (+114 -0) ➕ `runtime/src/bcpack_tables.h` (+1173 -0) ➕ `runtime/test/bcpack_test.cpp` (+183 -0) ➕ `runtime/test/bcpack_vectors.h` (+1885 -0) ➕ `runtime/test/bcpack_vectors.py` (+443 -0) 📝 `runtime/test/dstorage_test.cpp` (+148 -8) ➕ `tests/test_bcpack_header.py` (+48 -0) ➕ `tests/test_bcpack_history_sidecar.py` (+128 -0) ➕ `tools/bcpack_header.py` (+234 -0) ➕ `tools/bcpack_history_sidecar.py` (+111 -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, #1044 (this branch is built on them; its last commit is this pull request) ### What and why #1044 brought the user's calibrated BC6H/BC7 history to the runtime decoder and left BC1/BC3/BC4/BC5 out. Those matter as much: the repository's tables confirm 252 BC1 entries but **none for BC3, 2 for BC4 and 5 for BC5**, so without a calibration nearly every BC3/BC4/BC5 block that predicts from the built-in history is decoded from zeros on the request path (and the retail title asks for mode 5, issue #14 comment 7135719755). - **`tools/bcpack_history_sidecar.py`**: when the history JSON has a `bc1` / `bc3` / `bc4` / `bc5` section (read by `load_bc_history`, as `tools/bcpack.py --history` reads it), a `BC15HIS1` section follows the BC6H/BC7 tables: per mode a given byte, the section's `replace` byte and its 256 confirmed entries (int16, -1 where not confirmed). 71,192 bytes in all. **A history without those sections still gives the 60,936-byte file of #984's profile, byte for byte**; only a file with BC1-5 history is longer, which #984's profile reader may not take. - **`runtime/src/bcpack.{h,cpp}`**: `History::replace`, and `read_history_sidecar` reads the optional section. The merge is `_resolve_bc_history`'s: an entry given there wins over the built-in one, and with `replace` the built-in table is not read. Provisional entries are not written, as for the built-in tables (strict decoding takes confirmed history only). - **`runtime/shims/dstorage.cpp`**: the request path reads files up to 128 KiB (it stopped at 70,000 bytes, which would have cut the longer sidecar and ignored it), and its log line says whether BC1-5 history came with it. - **Docs**: `docs/directstorage.md`; the "not done yet" entry for this is gone. ### Tested - `bcpack_test`: the synthetic history now has BC1-5 sections (BC1 replacing its table, the one with many confirmed entries; BC4 and BC5 merged, with confirmed and provisional entries; BC3 not given), and 100 BC1-5 chunks that read the built-in history often, each with `tools/bcpack.py`'s strict answer for that same history. All agree; 10 decode only with the history, and BC1's `replace` decides the result of 9 (checked by decoding them with the flag off). The sidecar without its BC1-5 section (#984's size) still reads. The earlier cases are unchanged: the BC1-5 part has a random generator of its own, so the regenerated header only adds. - `dstorage_test`: 355 checks, 0 failures. Its BC1 chunk is now one whose blocks are the same with the calibrated history, since that history replaces BC1's built-in table for the whole process; a failing check now names its case. - `tests/test_bcpack_history_sidecar.py` (6): the BC15HIS1 offsets, flags and a provisional entry left out, and the unchanged size without BC1-5 sections. - 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`, `runtime/test/bcpack_vectors.py --check`, `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. 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#1139
No description provided.