[PR #1020] [CLOSED] RT-BCPACK-DECODER: DirectStorage BCPack requests decode through the runtime decoder #1057

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

📋 Pull Request Information

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

Base: main ← Head: feat/dstorage-bcpack


📝 Commits (5)

  • 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

📊 Changes

12 files changed (+4398 additions, -47 deletions)

View changed files

📝 docs/directstorage.md (+32 -13)
📝 runtime/CMakeLists.txt (+19 -2)
📝 runtime/shims/dstorage.cpp (+96 -24)
➕ runtime/src/bcpack.cpp (+956 -0)
➕ runtime/src/bcpack.h (+91 -0)
➕ runtime/src/bcpack_tables.h (+1173 -0)
➕ runtime/test/bcpack_test.cpp (+116 -0)
➕ runtime/test/bcpack_vectors.h (+1178 -0)
➕ runtime/test/bcpack_vectors.py (+355 -0)
📝 runtime/test/dstorage_test.cpp (+100 -8)
➕ tests/test_bcpack_header.py (+48 -0)
➕ tools/bcpack_header.py (+234 -0)

📄 Description

Claimed in the coordination issue as: RT-BCPACK-DECODER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7136759575; the request-path wiring, which @DadaCap handed to this claim in comment 7136979744)

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

What and why

The DirectStorage shim refuses every BCPack request with E_NOTIMPL, and the retail title asks for BCPack modes 1,
5 and 7 (@DesertGamer's counts, #14 comment 7135719755). This serves them through the runtime decoder of #976/#982/#991.

  • execute_request: swizzle stays E_NOTIMPL (no retail request measured asks for it), and so does BCPack mode 2
    (BC2 has no BCPack form). IntermediateSize must be set exactly on a zlib + BCPack request and is held to the
    32 MiB limit of a staging buffer; a BCPack DestinationSize only has to be non-zero (a chunk's size against its
    blocks depends on the texture).
  • unpack_request: the source goes into a staging buffer, is inflated to exactly IntermediateSize bytes first
    when the request is zlib too (the zlib failure codes are now shared with inflate_request through inflate_exact),
    then decoded by leonida::bcpack::decode, lenient: a block on built-in history nobody has measured decodes from
    the zero state and is logged once, so a texture has a few wrong blocks instead of missing (the choice of DadaCap's
    prototype). A chunk the decoder refuses is E_DSTORAGE_DECOMPRESSION_ERROR and leaves the destination as it was.
    BCPack requests count in the decompression statistics as zlib ones do.
  • gta6rt and dstorage_test link gta6rt_bcpack. docs/directstorage.md describes the path.

With destination pages: every BCPack request measured on the retail title also has the destination-pages bit, so
it reaches this path once RT-DSTORAGE-DEST-PAGES (#969) is in: its paged_request runs the plain request into a
staging buffer, which is this code, then writes the pages. The two pull requests touch different parts of
execute_request; whichever lands second takes a small rebase.

Tested

  • dstorage_test: 351 checks, 0 failures. New: BC1 and BC7 chunks from bcpack_vectors.h decode through the queue to
    the Python decoder's blocks, a BC7 chunk on unknown history to Python's provisional blocks, a BC1 chunk inside a
    stored zlib stream to the same blocks; a corrupt chunk, a destination that is not whole blocks, a zlib + BCPack
    request without IntermediateSize, one whose stream is longer than it and one with no destination size each get
    their code, and a failed request leaves its destination untouched. The old "BCPack is not implemented yet" cases
    now expect mode 2's refusal and the zlib + BCPack size error, and the statistics counts follow.
  • 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).
  • scripts/check_no_game_data.py on every changed file, tests/test_docs_links.py.
  • On the retail title: not run here (no game files on this machine). A branch with this wiring on @DadaCap's
    boot-prototype, test/ab-prototype on https://github.com/iFeyz/leonida, can decode every request with both decoders
    and count where they agree (LEONIDA_BCPACK_CROSSCHECK=1), for anyone who can run it.

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/1020 **Author:** [@iFeyz](https://github.com/iFeyz) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/dstorage-bcpack` --- ### 📝 Commits (5) - [`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 ### 📊 Changes **12 files changed** (+4398 additions, -47 deletions) <details> <summary>View changed files</summary> 📝 `docs/directstorage.md` (+32 -13) 📝 `runtime/CMakeLists.txt` (+19 -2) 📝 `runtime/shims/dstorage.cpp` (+96 -24) ➕ `runtime/src/bcpack.cpp` (+956 -0) ➕ `runtime/src/bcpack.h` (+91 -0) ➕ `runtime/src/bcpack_tables.h` (+1173 -0) ➕ `runtime/test/bcpack_test.cpp` (+116 -0) ➕ `runtime/test/bcpack_vectors.h` (+1178 -0) ➕ `runtime/test/bcpack_vectors.py` (+355 -0) 📝 `runtime/test/dstorage_test.cpp` (+100 -8) ➕ `tests/test_bcpack_header.py` (+48 -0) ➕ `tools/bcpack_header.py` (+234 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-BCPACK-DECODER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7136759575; the request-path wiring, which @DadaCap handed to this claim in comment 7136979744) Depends on: #976, #982, #991 (the decoder; this branch is built on them, its last commit is this pull request) ### What and why The DirectStorage shim refuses every BCPack request with `E_NOTIMPL`, and the retail title asks for BCPack modes 1, 5 and 7 (@DesertGamer's counts, #14 comment 7135719755). This serves them through the runtime decoder of #976/#982/#991. - **`execute_request`**: swizzle stays `E_NOTIMPL` (no retail request measured asks for it), and so does BCPack mode 2 (BC2 has no BCPack form). `IntermediateSize` must be set exactly on a zlib + BCPack request and is held to the 32 MiB limit of a staging buffer; a BCPack `DestinationSize` only has to be non-zero (a chunk's size against its blocks depends on the texture). - **`unpack_request`**: the source goes into a staging buffer, is inflated to exactly `IntermediateSize` bytes first when the request is zlib too (the zlib failure codes are now shared with `inflate_request` through `inflate_exact`), then decoded by `leonida::bcpack::decode`, **lenient**: a block on built-in history nobody has measured decodes from the zero state and is logged once, so a texture has a few wrong blocks instead of missing (the choice of DadaCap's prototype). A chunk the decoder refuses is `E_DSTORAGE_DECOMPRESSION_ERROR` and leaves the destination as it was. BCPack requests count in the decompression statistics as zlib ones do. - `gta6rt` and `dstorage_test` link `gta6rt_bcpack`. `docs/directstorage.md` describes the path. **With destination pages**: every BCPack request measured on the retail title also has the destination-pages bit, so it reaches this path once RT-DSTORAGE-DEST-PAGES (#969) is in: its `paged_request` runs the plain request into a staging buffer, which is this code, then writes the pages. The two pull requests touch different parts of `execute_request`; whichever lands second takes a small rebase. ### Tested - `dstorage_test`: 351 checks, 0 failures. New: BC1 and BC7 chunks from `bcpack_vectors.h` decode through the queue to the Python decoder's blocks, a BC7 chunk on unknown history to Python's provisional blocks, a BC1 chunk inside a stored zlib stream to the same blocks; a corrupt chunk, a destination that is not whole blocks, a zlib + BCPack request without `IntermediateSize`, one whose stream is longer than it and one with no destination size each get their code, and a failed request leaves its destination untouched. The old "BCPack is not implemented yet" cases now expect mode 2's refusal and the zlib + BCPack size error, and the statistics counts follow. - 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). - `scripts/check_no_game_data.py` on every changed file, `tests/test_docs_links.py`. - On the retail title: not run here (no game files on this machine). A branch with this wiring on @DadaCap's boot-prototype, `test/ab-prototype` on https://github.com/iFeyz/leonida, can decode every request with both decoders and count where they agree (`LEONIDA_BCPACK_CROSSCHECK=1`), for anyone who can run it. 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:56 +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#1057
No description provided.