RT-BCPACK-DECODER: DirectStorage BCPack requests decode through the runtime decoder #1020

Closed
iFeyz wants to merge 5 commits from upstream-pr/1020 into main
iFeyz commented 2026-11-24 17:00:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by iFeyz on 2026-11-24T17:00:16Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5476674190 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1020). Originally posted by [iFeyz](https://github.com/iFeyz) on 2026-11-24T17:00:16Z. --- 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.
aslan2142 commented 2026-11-25 08:40:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T08:40:08Z.


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.
  • main's request path already covers this, and destination pages too.
  • 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7157322543 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1020#issuecomment-7157322543). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T08:40:08Z. --- 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. - `main`'s request path already covers this, and destination pages too. - 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1020
No description provided.