[PR #976] [CLOSED] RT-BCPACK-DECODER: a runtime BCPack decoder, BC1/BC3/BC4/BC5, checked against tools/bcpack.py #1013

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/976
Author: @iFeyz
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: feat/bcpack-decoder


📝 Commits (1)

  • a371a73 RT-BCPACK-DECODER: a runtime BCPack decoder, BC1/BC3/BC4/BC5, checked against tools/bcpack.py

📊 Changes

10 files changed (+2413 additions, -1 deletions)

View changed files

📝 docs/directstorage.md (+7 -1)
📝 runtime/CMakeLists.txt (+15 -0)
➕ runtime/src/bcpack.cpp (+556 -0)
➕ runtime/src/bcpack.h (+64 -0)
➕ runtime/src/bcpack_tables.h (+594 -0)
➕ runtime/test/bcpack_test.cpp (+98 -0)
➕ runtime/test/bcpack_vectors.h (+667 -0)
➕ runtime/test/bcpack_vectors.py (+224 -0)
➕ tests/test_bcpack_header.py (+48 -0)
➕ tools/bcpack_header.py (+140 -0)

📄 Description

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

What and why

The DirectStorage shim refuses every BCPack request with E_NOTIMPL (execute_request, runtime/shims/dstorage.cpp),
and the retail title asks for BCPack modes 1, 5 and 7 (@DesertGamer's count of refused requests, #14 comment
7135719755). This adds the decoder that path will call, as a portable library (gta6rt_bcpack, no windows.h), so
it builds and tests on every OS. It does not touch execute_request: every BCPack request measured also carries the
destination-pages bit, so the wiring waits for destination pages (@DadaCap), and @DesertGamer offered to do it.

  • runtime/src/bcpack.{h,cpp}: the lane layer is a statement-by-statement port of
    tools/bcpack_calibration/src/model.rs (itself a port of _decode_lanes_raw), with a 64-bit coder state instead
    of model.rs's i128: a state below RANS_L is shifted a byte at a time until it reaches RANS_L, so it stays below
    2^32, and a negative one (only a corrupt stream makes one) is refused before any shift, as model.rs does. The
    BC1, BC3, BC4 and BC5 rebuilds follow blocks.rs / _bc1_blocks .. _bc5_blocks, strict like bcpack.decode:
    a block that needs an unconfirmed built-in history entry is refused (Status::unconfirmed_history), never
    guessed. Where the Rust port hands a stream back to Python, this returns a Status. An optional History takes
    the user's calibrated entries, which win over the built-in ones (_resolve_bc_history's merge).
  • runtime/src/bcpack_tables.h: written by tools/bcpack_header.py from tools/bcpack_tables.py (rANS models,
    symbol-rank tables, confirmed history only). tests/test_bcpack_header.py fails if it goes stale or if a
    provisional entry gets in.
  • runtime/test/bcpack_test.cpp with runtime/test/bcpack_vectors.{py,h}: 120 lane cases over all six modes
    and 90 whole-chunk cases over modes 1, 3, 4 and 5, from tests/test_bcpack.py's synthetic encoder (valid,
    corrupted, cut short, a trailing byte, lane 1 set, history distances to no block, an earlier block or a built-in
    entry), each with the pure-Python decoder's answer (LEONIDA_BCPACK_NATIVE=0). No Python is needed at test time.
  • docs/directstorage.md: the decoder exists; what is left is the wiring.

Not in this PR: BC7 (mode 7, which the title uses) and BC6H; both return unsupported_codec for now and come next
under the same claim. Swizzle (no request measured uses it) and physical pages are not touched.

Tested

  • bcpack_test: all 210 cases agree with tools/bcpack.py (79 lane streams accepted and 41 refused exactly as
    Python does, with the same symbols; 71 chunks decoded to the same bytes, 19 refused with the same class of error),
    plus a chunk refused for its history decoding with a complete external table. Built with MSVC /W4, no warning.
  • tests/test_bcpack_header.py, tests/test_bcpack.py, tests/test_bcpack_tables.py, tests/test_tool_startup.py,
    tests/test_docs_links.py, tests/test_text_write_line_endings.py, scripts/check_no_game_data.py on every new
    file. tests/test_tool_stdout_encoding.py lists only tools/native_pso_hashes.py, which fails on main too.
  • Runtime (Windows 11, MSVC 2022 Build Tools, RelWithDebInfo, full build): ctest 302 of 306 pass, 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).

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/976 **Author:** [@iFeyz](https://github.com/iFeyz) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/bcpack-decoder` --- ### 📝 Commits (1) - [`a371a73`](https://github.com/ubiquitarianism/leonida/commit/a371a739c3aeda38642429d4fed01eb9605689fb) RT-BCPACK-DECODER: a runtime BCPack decoder, BC1/BC3/BC4/BC5, checked against tools/bcpack.py ### 📊 Changes **10 files changed** (+2413 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/directstorage.md` (+7 -1) 📝 `runtime/CMakeLists.txt` (+15 -0) ➕ `runtime/src/bcpack.cpp` (+556 -0) ➕ `runtime/src/bcpack.h` (+64 -0) ➕ `runtime/src/bcpack_tables.h` (+594 -0) ➕ `runtime/test/bcpack_test.cpp` (+98 -0) ➕ `runtime/test/bcpack_vectors.h` (+667 -0) ➕ `runtime/test/bcpack_vectors.py` (+224 -0) ➕ `tests/test_bcpack_header.py` (+48 -0) ➕ `tools/bcpack_header.py` (+140 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-BCPACK-DECODER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7136759575) ### What and why The DirectStorage shim refuses every BCPack request with `E_NOTIMPL` (`execute_request`, `runtime/shims/dstorage.cpp`), and the retail title asks for BCPack modes 1, 5 and 7 (@DesertGamer's count of refused requests, #14 comment 7135719755). This adds the decoder that path will call, as a portable library (`gta6rt_bcpack`, no `windows.h`), so it builds and tests on every OS. It does not touch `execute_request`: every BCPack request measured also carries the destination-pages bit, so the wiring waits for destination pages (@DadaCap), and @DesertGamer offered to do it. - **`runtime/src/bcpack.{h,cpp}`**: the lane layer is a statement-by-statement port of `tools/bcpack_calibration/src/model.rs` (itself a port of `_decode_lanes_raw`), with a 64-bit coder state instead of model.rs's i128: a state below `RANS_L` is shifted a byte at a time until it reaches `RANS_L`, so it stays below 2^32, and a negative one (only a corrupt stream makes one) is refused before any shift, as model.rs does. The BC1, BC3, BC4 and BC5 rebuilds follow `blocks.rs` / `_bc1_blocks` .. `_bc5_blocks`, strict like `bcpack.decode`: a block that needs an unconfirmed built-in history entry is refused (`Status::unconfirmed_history`), never guessed. Where the Rust port hands a stream back to Python, this returns a `Status`. An optional `History` takes the user's calibrated entries, which win over the built-in ones (`_resolve_bc_history`'s merge). - **`runtime/src/bcpack_tables.h`**: written by `tools/bcpack_header.py` from `tools/bcpack_tables.py` (rANS models, symbol-rank tables, confirmed history only). `tests/test_bcpack_header.py` fails if it goes stale or if a provisional entry gets in. - **`runtime/test/bcpack_test.cpp`** with **`runtime/test/bcpack_vectors.{py,h}`**: 120 lane cases over all six modes and 90 whole-chunk cases over modes 1, 3, 4 and 5, from `tests/test_bcpack.py`'s synthetic encoder (valid, corrupted, cut short, a trailing byte, lane 1 set, history distances to no block, an earlier block or a built-in entry), each with the pure-Python decoder's answer (`LEONIDA_BCPACK_NATIVE=0`). No Python is needed at test time. - **`docs/directstorage.md`**: the decoder exists; what is left is the wiring. Not in this PR: BC7 (mode 7, which the title uses) and BC6H; both return `unsupported_codec` for now and come next under the same claim. Swizzle (no request measured uses it) and physical pages are not touched. ### Tested - `bcpack_test`: all 210 cases agree with `tools/bcpack.py` (79 lane streams accepted and 41 refused exactly as Python does, with the same symbols; 71 chunks decoded to the same bytes, 19 refused with the same class of error), plus a chunk refused for its history decoding with a complete external table. Built with MSVC `/W4`, no warning. - `tests/test_bcpack_header.py`, `tests/test_bcpack.py`, `tests/test_bcpack_tables.py`, `tests/test_tool_startup.py`, `tests/test_docs_links.py`, `tests/test_text_write_line_endings.py`, `scripts/check_no_game_data.py` on every new file. `tests/test_tool_stdout_encoding.py` lists only `tools/native_pso_hashes.py`, which fails on `main` too. - Runtime (Windows 11, MSVC 2022 Build Tools, RelWithDebInfo, full build): `ctest` 302 of 306 pass, `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). 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>
4ld0 2026-11-26 20:19:48 +01:00
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#1013
No description provided.