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

Closed
github-bot wants to merge 1 commit from gh-pr/976/head into gh-pr/976/base
Owner

@⁠iFeyz on GitHub · 2026-11-24 16:09 UTC · original
iFeyz:feat/bcpack-decoder → main · +2413 −1 · 10 files · 1 commits · closed without merging

Claimed in the coordination issue as: RT-BCPACK-DECODER (#14)

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.
**@⁠iFeyz** on GitHub · 2026-11-24 16:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/976) `iFeyz:feat/bcpack-decoder` → `main` · +2413 −1 · 10 files · 1 commits · closed without merging Claimed in the coordination issue as: RT-BCPACK-DECODER (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### 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.
The DirectStorage worker refuses every BCPack request with E_NOTIMPL, and the
retail title asks for modes 1, 5 and 7 (issue #14, comment 7135719755). This
adds the decoder the request path will call, as a portable library
(gta6rt_bcpack, no windows.h):

- src/bcpack.{h,cpp}: the lane layer, 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 (it stays below 2^32; a negative one is refused
  as model.rs does), and the strict BC1, BC3, BC4 and BC5 rebuilds of
  blocks.rs / _bc1_blocks.._bc5_blocks. Errors are a Status, not a fallback.
  An optional History takes the user's calibrated entries (they win over the
  built-in ones, as _resolve_bc_history merges). Modes 6 and 7 return
  unsupported_codec until they are ported.
- src/bcpack_tables.h: written by tools/bcpack_header.py from
  tools/bcpack_tables.py (confirmed history only, no provisional entry).
- test/bcpack_test.cpp + test/bcpack_vectors.{py,h}: 120 lane cases and 90
  whole-chunk cases from tests/test_bcpack.py's synthetic encoder (valid,
  corrupted, cut short, trailing byte, lane 1 set, history entries confirmed
  or not), each with the pure-Python decoder's answer; the C++ decoder gives
  the same lanes, the same blocks or the same class of refusal for all 210.
- tests/test_bcpack_header.py: both generated headers are current, and no
  provisional entry reaches the table header.
- docs/directstorage.md: the decoder exists; the wiring into
  execute_request waits for destination pages.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:31:29 +00:00
github-bot closed this pull request 2026-11-26 09:31:29 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 16:27 UTC · original · approved these changes

Reviewed exact head a371a739c3. Built the Linux CPU decoder target with GCC 16 in Fedora 45 and ran CTest: bcpack 1/1 passed. The generated-table test passed 3/3, and the no-game-data scan plus diff check passed. This is CPU decoder validation; no game data or GPU behavior is claimed. Hosted label status was queued when checked.

**@⁠KernelSmoker** on GitHub · 2026-11-24 16:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/976#pullrequestreview-6043244397) · **approved these changes** Reviewed exact head a371a739c3aeda38642429d4fed01eb9605689fb. Built the Linux CPU decoder target with GCC 16 in Fedora 45 and ran CTest: bcpack 1/1 passed. The generated-table test passed 3/3, and the no-game-data scan plus diff check passed. This is CPU decoder validation; no game data or GPU behavior is claimed. Hosted label status was queued when checked.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 08:40 UTC · original

Thanks for this stack. main already does what it does: #984 brought in a BCPack decoder and the DirectStorage wiring, so I'm closing this one as carried.

  • runtime/src/bcpack.{h,cpp} on main ports the strict rebuilds of tools/bcpack.py for BC1, BC3, BC4, BC5, BC6H and BC7.
  • dstorage.cpp's decode_stages decodes BCPack requests with zlib, destination and source pages, and swizzle. BC6H/BC7 history comes from a profile built locally (history.bcph). Only BC2 is still E_NOTIMPL.
  • Your 250 synthetic chunk vectors, run through main's decoder: every strict case agrees with tools/bcpack.py (140 identical, 110 refused). 29 of the 98 provisional cases are refused, because main doesn't decode unknown BC6H/BC7 history from zeros; it uses the locally fitted profile instead.
  • The add/add conflict on bcpack.{h,cpp} can't be resolved without picking one decoder, and main's is the one that's wired in and boots.
  • Your claim came first, and #984 had said your decoder would take precedence. The integration kept #984's because it was already wired in and was tested end to end. Sorry for the duplicated work.
  • A pull request porting bcpack_test and its vectors to main's leonida::bcpack::decode would be very welcome. It would be the decoder's first stand-alone test, with refusal cases.

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

**@⁠aslan2142** on GitHub · 2026-11-25 08:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/976#issuecomment-7157325783) Thanks for this stack. `main` already does what it does: #984 brought in a BCPack decoder and the DirectStorage wiring, so I'm closing this one as carried. - `runtime/src/bcpack.{h,cpp}` on `main` ports the strict rebuilds of `tools/bcpack.py` for BC1, BC3, BC4, BC5, BC6H and BC7. - `dstorage.cpp`'s `decode_stages` decodes BCPack requests with zlib, destination and source pages, and swizzle. BC6H/BC7 history comes from a profile built locally (`history.bcph`). Only BC2 is still `E_NOTIMPL`. - Your 250 synthetic chunk vectors, run through `main`'s decoder: every strict case agrees with `tools/bcpack.py` (140 identical, 110 refused). 29 of the 98 provisional cases are refused, because `main` doesn't decode unknown BC6H/BC7 history from zeros; it uses the locally fitted profile instead. - The add/add conflict on `bcpack.{h,cpp}` can't be resolved without picking one decoder, and `main`'s is the one that's wired in and boots. - Your claim came first, and #984 had said your decoder would take precedence. The integration kept #984's because it was already wired in and was tested end to end. Sorry for the duplicated work. - A pull request porting `bcpack_test` and its vectors to `main`'s `leonida::bcpack::decode` would be very welcome. It would be the decoder's first stand-alone test, with refusal cases. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.