xcrdapi: decode BCPack BC1, BC3, BC4, BC5 and BC7 in DirectStorage requests #345

Merged
NickStallman merged 4 commits from upstream-pr/345 into main 2026-11-28 01:22:56 +00:00
NickStallman commented 2026-11-28 00:21:40 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T00:21:40Z.


What

This PR decodes BCPack, the console's DirectStorage texture codec, in runtime/xcrdapi.

Before it, a request with BcpackMode set (options bits 1–4) failed with E_NOTIMPL and nothing was logged. The texture's memory kept whatever it held before.

The title uses BCPack for a lot of its texture data. Reading only the chunk tables of its 46 texture pools (data/ttdb/**.ttpf) gives:

Codec Chunks Stored
zlib 908,603 45.3 GiB
BCPack BC1 100,020 10.1 GiB
BCPack BC7 5,120 1.07 GiB
BCPack BC6H 268 0.07 GiB
BCPack BC5 325 0.06 GiB
BCPack BC3 35 0.01 GiB
BCPack BC4 77 < 0.01 GiB

I have not yet measured how many of these chunks reach DirectStorage as BCPack requests in a game run. The first commit's log is there to show it.

Commits, for separate review:

  1. Diagnostic.
    • The first refused request of each distinct option word is always logged.
    • TUXBOX_XCRD_LOG=1 counts requests per option word, with their bytes and failures. The fields are decoded as documented in DSTORAGE_REQUEST_OPTIONS.
  2. tuxbox-xcrdapi-codec. A platform-independent crate, tested in the code checks on Linux. It models one lane of Microsoft's rANS reference decoder.
  3. BC1.
    • Adds the 12-lane stream (feeder and lockstep output), the silicon-rans models and the BC1 rebuild.
    • Uses only bcpack-rs material from 22 Nov, which bcpack-rs derived from retail data.
    • zlib-then-BCPack goes through IntermediateSize, in the documented stage order.
  4. BC3, BC4, BC5 and BC7, plus the format's exact BC1 tables. See the maintainer question below.

Not covered:

  • BC6H: 268 chunks stay refused. The entropy layer converges on all 268 sampled chunks, but no source TuxBox can use describes the block rebuild.
  • BC2: has no data in the title.
  • Swizzle (bits 5–20): still refused. Its modes are named in the GDK docs but not described.
  • Physical-page sources (bit 23): still refused.

Provenance

Part Source Licence How used
rANS lane model, 144 probability models microsoft/silicon-rans mdu_minirans.v @2f6827d MIT Models generated by gen_models.py; notice in docs/licenses/silicon-rans/
Request option layout, stage order, IntermediateSize docs.xbox.com DirectStorage Documentation Facts
Feeder, lockstep output, BC1 rebuild bcpack-rs @5bf5cc5 (22 Nov) MIT OR Apache-2.0 Ported, header kept
BC3/4/5/7 rebuilds, BC1 index reference bcpack-rs @2d6333b MIT OR Apache-2.0 Ported, header kept
BC1 codebook, 180 BC1 window slots, BC3/4/5 pair ranks, 205 BC7 control codes bcpack-rs data/, fitted on retail data MIT OR Apache-2.0 Values
Dictionaries of BC3/4/5/7, BC3 colour ranks, 80 BC7 control codes, 75 BC1 window slots, 2 swapped BC1 codebook pairs VIctory's bcpack-tables.bin, through bcpack-rs c55c5fa and b1c3099 (the pairs observed from VIctory's decoder output) Outside VIctory's GPL (see below) Values only, commit 4

No VIctory or XCL code is used.

For the maintainer to decide: the commit 4 tables

What VIctory says. VIctory's docs/asset-policy.md (commit 2849477, 23 Nov) describes bcpack-tables.bin as follows:

the constant tables of the BCPack format (entropy models, index rank tables, control codes, per-format dictionaries). A BCPack stream cannot be decoded without exactly these tables and they cannot be derived, so they ship with VIctory by the project owner's decision (2026-11-23) … They are part of the format, not our work, and the repository's licence does not cover them.

  • VIctory names no origin. VIctory #2753 asks for one and is unanswered.
  • XCL's port says the same: "the format's constant tables, not derived here".
  • bcpack-rs's data/bc4.json says: "reference decoder tables (GPL project; values are constants of the format…)".

What the public record shows.

  • Patent US11234023B2 (Microsoft) covers the rANS layer and its static model tables. That layer is the part silicon-rans publishes. Its text does not mention BCPack's block tables.
  • I found none of the table fragments in plaintext in the title's executable, gameos.xvd or its DLLs. The executable may be encrypted, so this does not rule out that the tables were extracted from Microsoft software. If they were, that would be a different question from the GPL.

The case for using them. The values are fixed constants of a hardware format: what the decoder hardware does to every stream. They are not expression in VIctory's code, and VIctory itself disclaims them. bcpack-rs measured several independently from retail data and got the same values:

  • all 192 pair ranks;
  • 205 of 285 BC7 control codes;
  • 180 of 255 BC1 window slots.

Without them: commits 1–3 stand alone. BC1 is then approximate, and the other formats stay refused.

Accuracy

There is no hardware ground truth here. The checks below are self-consistency and agreement between independent decoders.

Unit tests round-trip random blocks of every format through our own encoder. Retail chunks were sampled from the title's pools, decoded locally, and none of their bytes are committed:

Format Chunks Decode OK Same bytes as bcpack-rs 2d6333b Same bytes as VIctory's decoder
BC1 400 (6.87 M blocks) 400 48 (99.61% of blocks; the rest differ only in the two swapped codebook pairs) 400
BC3 35 35 35 35
BC4 77 77 77 77
BC5 325 325 325 325
BC7 400 (5.56 M blocks) 400 400 0 (15.1% of blocks)
  • No reserved modes: none of the decoded BC7 blocks is in the reserved mode.
  • BC7 against VIctory: the modes agree but the index bits differ. Measured as the mean adjacent-pixel difference inside each 4×4 block, our decode is smoother than VIctory's (this fork, 6726920) in 39 of 40 chunks: 6.91 against 8.61 on average. That suggests our BC7 is the more correct of the two, but it doesn't prove it.
  • BC1 with commit 3 alone, which uses fitted tables only:
    • identical to VIctory on 92.93% of blocks;
    • mean absolute RGB error 0.11 (0–255 per channel);
    • all differences are in the 75 window slots and the two codebook pairs.
  • Speed, single thread, megabytes of blocks out per second (median per chunk): BC1 39, BC3 39, BC4 34, BC5 34, BC7 20. The existing pool runs up to 8 requests at once.

Checks

  • python tuxbox.py check --no-gpu: all 7 passed: shader compiler build, Python, shader compiler, DXBC, XG layout, storage codec, and the D3D12 Windows typecheck. Run on the branch rebased onto e63a5bf8.
  • Codec unit tests: cargo test -p tuxbox-xcrdapi-codec, 18 passed. Clippy is clean.
  • Storage guest (xcrdapi-read.exe under GE-Proton 11-14, CPU only): raw=16 zlib=16 guards=2 errors=2 cancellation=1 bc1=4 bc7=2 autosubmit=64 PASS.
    • With the commit 2 provider it fails: BCPack BC1: 0x80004001.
    • With the commit 3 provider it fails: BCPack BC7: 0x80004001.
  • python tuxbox.py verify --only xcrdapi passed on an AMD Raphael iGPU (1002:13c0, RADV) and an RTX 5090 (10de:2b85, 620.70.10), GE-Proton11-14. xcrdapi is a CPU-only provider, so no other suite is touched.
  • Not run yet: a game run with TUXBOX_XCRD_LOG=1, to confirm the title sends BCPack requests and in which formats.
  • No Lanes scenario. Lanes doesn't use DirectStorage, and the provider's guest already covers the request path end to end. The decode happens on the CPU, before any GPU work.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5534868244 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/345). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T00:21:40Z. --- ## What This PR decodes BCPack, the console's DirectStorage texture codec, in `runtime/xcrdapi`. Before it, a request with BcpackMode set (options bits 1–4) failed with `E_NOTIMPL` and nothing was logged. The texture's memory kept whatever it held before. The title uses BCPack for a lot of its texture data. Reading only the chunk tables of its 46 texture pools (`data/ttdb/**.ttpf`) gives: | Codec | Chunks | Stored | | --- | --- | --- | | zlib | 908,603 | 45.3 GiB | | BCPack BC1 | 100,020 | 10.1 GiB | | BCPack BC7 | 5,120 | 1.07 GiB | | BCPack BC6H | 268 | 0.07 GiB | | BCPack BC5 | 325 | 0.06 GiB | | BCPack BC3 | 35 | 0.01 GiB | | BCPack BC4 | 77 | < 0.01 GiB | I have not yet measured how many of these chunks reach DirectStorage as BCPack requests in a game run. The first commit's log is there to show it. **Commits, for separate review:** 1. **Diagnostic.** - The first refused request of each distinct option word is always logged. - `TUXBOX_XCRD_LOG=1` counts requests per option word, with their bytes and failures. The fields are decoded as documented in `DSTORAGE_REQUEST_OPTIONS`. 2. **`tuxbox-xcrdapi-codec`.** A platform-independent crate, tested in the code checks on Linux. It models one lane of Microsoft's rANS reference decoder. 3. **BC1.** - Adds the 12-lane stream (feeder and lockstep output), the silicon-rans models and the BC1 rebuild. - Uses only bcpack-rs material from 22 Nov, which bcpack-rs derived from retail data. - zlib-then-BCPack goes through `IntermediateSize`, in the documented stage order. 4. **BC3, BC4, BC5 and BC7**, plus the format's exact BC1 tables. See the maintainer question below. **Not covered:** - **BC6H:** 268 chunks stay refused. The entropy layer converges on all 268 sampled chunks, but no source TuxBox can use describes the block rebuild. - **BC2:** has no data in the title. - **Swizzle (bits 5–20):** still refused. Its modes are named in the GDK docs but not described. - **Physical-page sources (bit 23):** still refused. ## Provenance | Part | Source | Licence | How used | | --- | --- | --- | --- | | rANS lane model, 144 probability models | [microsoft/silicon-rans](https://github.com/microsoft/silicon-rans) `mdu_minirans.v` @2f6827d | MIT | Models generated by `gen_models.py`; notice in `docs/licenses/silicon-rans/` | | Request option layout, stage order, `IntermediateSize` | [docs.xbox.com DirectStorage](https://docs.xbox.com/reference/system/dstorage/structs/dstorage_request_options.md) | Documentation | Facts | | Feeder, lockstep output, BC1 rebuild | [bcpack-rs](https://github.com/Ahmet-Dedeler/bcpack-rs) @5bf5cc5 (22 Nov) | MIT OR Apache-2.0 | Ported, header kept | | BC3/4/5/7 rebuilds, BC1 index reference | bcpack-rs @2d6333b | MIT OR Apache-2.0 | Ported, header kept | | BC1 codebook, 180 BC1 window slots, BC3/4/5 pair ranks, 205 BC7 control codes | bcpack-rs `data/`, fitted on retail data | MIT OR Apache-2.0 | Values | | Dictionaries of BC3/4/5/7, BC3 colour ranks, 80 BC7 control codes, 75 BC1 window slots, 2 swapped BC1 codebook pairs | VIctory's `bcpack-tables.bin`, through bcpack-rs c55c5fa and b1c3099 (the pairs observed from VIctory's decoder output) | Outside VIctory's GPL (see below) | Values only, commit 4 | No VIctory or XCL code is used. ### For the maintainer to decide: the commit 4 tables **What VIctory says.** VIctory's `docs/asset-policy.md` (commit 2849477, 23 Nov) describes `bcpack-tables.bin` as follows: > the constant tables of the BCPack format (entropy models, index rank tables, control codes, per-format dictionaries). A BCPack stream cannot be decoded without exactly these tables and they cannot be derived, so they ship with VIctory by the project owner's decision (2026-11-23) … They are part of the format, not our work, and the repository's licence does not cover them. - VIctory names no origin. [VIctory #2753](https://github.com/Marvisak/VIctory/issues/2753) asks for one and is unanswered. - XCL's port says the same: "the format's constant tables, not derived here". - bcpack-rs's `data/bc4.json` says: "reference decoder tables (GPL project; values are constants of the format…)". **What the public record shows.** - Patent US11234023B2 (Microsoft) covers the rANS layer and its static model tables. That layer is the part silicon-rans publishes. Its text does not mention BCPack's block tables. - I found none of the table fragments in plaintext in the title's executable, `gameos.xvd` or its DLLs. The executable may be encrypted, so this does not rule out that the tables were extracted from Microsoft software. If they were, that would be a different question from the GPL. **The case for using them.** The values are fixed constants of a hardware format: what the decoder hardware does to every stream. They are not expression in VIctory's code, and VIctory itself disclaims them. bcpack-rs measured several independently from retail data and got the same values: - all 192 pair ranks; - 205 of 285 BC7 control codes; - 180 of 255 BC1 window slots. **Without them:** commits 1–3 stand alone. BC1 is then approximate, and the other formats stay refused. ## Accuracy There is no hardware ground truth here. The checks below are self-consistency and agreement between independent decoders. Unit tests round-trip random blocks of every format through our own encoder. Retail chunks were sampled from the title's pools, decoded locally, and none of their bytes are committed: | Format | Chunks | Decode OK | Same bytes as bcpack-rs 2d6333b | Same bytes as VIctory's decoder | | --- | --- | --- | --- | --- | | BC1 | 400 (6.87 M blocks) | 400 | 48 (99.61% of blocks; the rest differ only in the two swapped codebook pairs) | 400 | | BC3 | 35 | 35 | 35 | 35 | | BC4 | 77 | 77 | 77 | 77 | | BC5 | 325 | 325 | 325 | 325 | | BC7 | 400 (5.56 M blocks) | 400 | 400 | 0 (15.1% of blocks) | - **No reserved modes:** none of the decoded BC7 blocks is in the reserved mode. - **BC7 against VIctory:** the modes agree but the index bits differ. Measured as the mean adjacent-pixel difference inside each 4×4 block, our decode is smoother than VIctory's (this fork, 6726920) in 39 of 40 chunks: 6.91 against 8.61 on average. That suggests our BC7 is the more correct of the two, but it doesn't prove it. - **BC1 with commit 3 alone**, which uses fitted tables only: - identical to VIctory on 92.93% of blocks; - mean absolute RGB error 0.11 (0–255 per channel); - all differences are in the 75 window slots and the two codebook pairs. - **Speed**, single thread, megabytes of blocks out per second (median per chunk): BC1 39, BC3 39, BC4 34, BC5 34, BC7 20. The existing pool runs up to 8 requests at once. ## Checks - **`python tuxbox.py check --no-gpu`:** all 7 passed: shader compiler build, Python, shader compiler, DXBC, XG layout, storage codec, and the D3D12 Windows typecheck. Run on the branch rebased onto e63a5bf8. - **Codec unit tests:** `cargo test -p tuxbox-xcrdapi-codec`, 18 passed. Clippy is clean. - **Storage guest** (`xcrdapi-read.exe` under GE-Proton 11-14, CPU only): `raw=16 zlib=16 guards=2 errors=2 cancellation=1 bc1=4 bc7=2 autosubmit=64 PASS`. - With the commit 2 provider it fails: `BCPack BC1: 0x80004001`. - With the commit 3 provider it fails: `BCPack BC7: 0x80004001`. - `python tuxbox.py verify --only xcrdapi` passed on an AMD Raphael iGPU (1002:13c0, RADV) and an RTX 5090 (10de:2b85, 620.70.10), GE-Proton11-14. xcrdapi is a CPU-only provider, so no other suite is touched. - **Not run yet:** a game run with `TUXBOX_XCRD_LOG=1`, to confirm the title sends BCPack requests and in which formats. - **No Lanes scenario.** Lanes doesn't use DirectStorage, and the provider's guest already covers the request path end to end. The decode happens on the CPU, before any GPU work. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!345
No description provided.