Skip to content

DirectStorage: BCPack BC1 requests are unpacked, tables from bcpack-rs - #273

Open
Kalmarv wants to merge 2 commits into
ivall:mainfrom
Kalmarv:feat/bcpack-bc1
Open

Kalmarv wants to merge 2 commits into
ivall:mainfrom
Kalmarv:feat/bcpack-bc1

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #208. With this PR, DirectStorage unpacks BCPack BC1 requests, alone or after zlib, instead of refusing them. The BC1 blocks are rebuilt from #208's lanes with two tables of constants that no stream carries; XCL takes the estimates bcpack-rs made of them. BC3–BC7 requests are refused and counted as on main.

This is the second half of #208's earlier form (a7ffb2f), which a tester ran on a retail title (below). One commit, 5f12643, on #208's 34c0ee5; GitHub shows both commits until #208 is merged.

What is in it

  • hle/bcpack/bc1.rs: BC1 blocks from the 12 lanes. A back-reference for the endpoints, six zigzag differences, and four 2×2 selector quadrants through a codebook. It follows the BC1 sections of the format notes of bcpack-decoder and bcpack-rs, both MIT. No code was taken from either. The file's header names both, with URL and licence.
  • hle/bcpack/bc1_fitted.rs: the two tables, which no specification publishes. One is the 255 endpoint sets a stream starts with; the other is the order of the 256 quadrants.
    • bcpack-rs estimated both from retail data. They are constants of the codec, not content of a game.
    • The file is generated, not written: python scripts/gen_bcpack_bc1_tables.py <bcpack-rs>/data/bc1_window.json <bcpack-rs>/data/bc1_quad_table.json (bcpack-rs at c51ec52; the script is in this PR). The file carries bcpack-rs's MIT notice.
  • hle/bcpack/mod.rs: decode(mode, bytes, len) (lanes, then blocks), and the errors lane 1 and unknown history.
  • hle/dstorage.rs: a BC1 request runs the BCPack stage after zlib, or alone.
    • A stream the decoder does not take fails the request with E_DECOMPRESSION and writes nothing, as a refusal does.
    • The log has one line on the first unpacked request of a mode, one warning per mode and kind of failure, then a running count.
    • XCL_DSTORAGE_BCPACK_FILL now applies to the refused modes only.
  • report.rs: report.json gets dstorage.bcpack_unpacked per mode, with requests, destination_bytes (bytes of blocks rebuilt) and failed.
  • tests/data/bcpack/*.bc1: the blocks of DirectStorage: BCPack entropy stage for all modes, not yet called #208's BC1 fixtures, from the same independent encoder.
  • THIRD_PARTY.md:
    • the format-notes row now names the BC1 block rule too;
    • a new row covers bcpack-rs's tables (bc1_fitted.rs, generated by the script above).

Tested

mode without with
BC1 1,492 requests (76.0 MB) 0
BC5 108 (7.1 MB) 108
BC6H 1 (1.0 MB) 1
BC7 155 (19.0 MB) 118
  • More from that run:

    • The log shows BCPack BC1: first request unpacked (39541 to 65536 bytes), and one BC1 stream was not unpacked (BCPack BC1 streams not unpacked so far: 1).
    • There was no crash or device removal in the 170 s; XCL_RUN_SECONDS ended the run.
    • Their cargo test --release -p xcl --lib bcpack: 11 passed.
    • There was no visible difference in the intro: its picture area is still one flat dark colour, so something else is in the way there.
    • So in that run, all BC1 streams but one passed the entropy stage with every lane in a legal end state, each read as one stream per request.
  • What the tests show, all on synthetic data:

    • bc1_fixtures_decode_to_their_blocks: DirectStorage: BCPack entropy stage for all modes, not yet called #208's independent BC1 fixtures decode to their blocks.
    • bc1_block_rebuild: one block by hand, every field.
    • fitted_bc1_tables_are_well_formed: every quadrant appears once, the ranges hold, and one block goes through the shipped tables.
    • bcpack_bc1_requests_are_unpacked_alone_and_after_zlib: seven requests through a memory queue.
      • BC1 alone; zlib + BC1 with and without IntermediateSize.
      • A wrong IntermediateSize, a cut stream and a wrong block count; these three fail and write nothing.
      • The same bytes without the BCPack bit, as a control.
    • main's BCPack refusal tests now use BC3 / BC7 where they used BC1.
  • With the fitted tables, five BC1 streams (8,926 blocks) give byte-identical blocks here and in bcpack-rs's CLI.

  • Mutations of the earlier form, each failing at least one of these tests:

    • BC1 rows mirrored;
    • delta sign;
    • back-reference folding;
    • BCPack stage skipped in execute;
    • IntermediateSize not compared.

    DirectStorage: BCPack entropy stage for all modes, not yet called #208 lists its other six.

Known to be approximate or assumed:

  • The BC1 tables are estimates. Per bcpack-rs:

    • One history entry (slot 4) was never seen and is not known. A block that refers to it fails the request.
    • 17 entries differ by a step or so between fits on two halves of its data.
    • 8 rare quadrants may be swapped with their mirror.

    A wrong history entry gives a slightly wrong colour in the blocks that refer to it and in the ones chained to them. bcpack-rs reports a median 35.4 dB against the next mip level, where 37.9 dB is the ceiling of that measure.

  • BC1 lane 1 is 0 in every stream the notes describe. A stream where it is not is refused (lane 1); bcpack-rs ignores it instead.

  • One request is taken to be one stream that unpacks to DestinationSize bytes.

  • IntermediateSize 0 with zlib + BCPack is accepted; zlib may then yield any size up to the destination's. The GDK documents the field as the size of the stream BCPack reads. What a console does with 0 was not tested.

  • The blocks are written in stream order. Requests with a swizzle mode are still refused.

Overlaps:

Regression run

Run by @ExMoha on a retail title (RX 9070, release, 60 s, no input, back to back; #273 (comment)). The gpu: line names the CPU's integrated GPU (#281 / #285); the runs used the RX 9070. As posted:

main:

xcl-smoke v1
commit: 9ab7d763197c7f420bff10cd9bf1310f07e2a9aa
gpu: AMD Radeon(TM) Graphics
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1505 (PresentX 1505)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14902 MB

PR:

xcl-smoke v1
commit: 5f12643999939d07a234081dbc835c0d8a0497c2
gpu: AMD Radeon(TM) Graphics
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1503 (PresentX 1503)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14883 MB

Not tested

  • The regression run on a title, main and PR (above): none yet. @Cattn's run predates scripts/smoke.ps1, was of a7ffb2f, and is not a substitute for it.
  • Whether BC1 textures look right in a title. That is the only check of the block rule and the fitted tables, and the retail run's intro showed no visible difference.
  • Which BC1 stream failed in that run, and why (the log's warning line was not part of the report).
  • The physical-page destination path with a BCPack request. It shares the write code that physical_page_destinations_and_sources covers.
  • A stream that spans several requests, or several streams in one request, if titles do that.
  • BC3–BC7 block rebuild.

AI use

  • Claude Code (Claude Fable 5.2), the BC1 rebuild, wiring, tests and first description; Codex (GPT-6.2 Astra), the independent fixtures' encoder and a review; Claude Code (Claude Opus 5.5), the split and this description

Kalmarv and others added 2 commits November 23, 2026 17:07
The rANS lanes a BCPack stream is split into, for BC1, BC3, BC4, BC5,
BC6H and BC7: a port of the decoder module of Microsoft's silicon-rans
sample (MIT), with the byte feeder and symbol release after the format
notes of bcpack-decoder and bcpack-rs (MIT, no code taken). The 128
static models are generated by scripts/gen_bcpack_tables.py from the
sample. Nothing calls it yet; DirectStorage still refuses BCPack
requests. Tested against fixtures from an encoder written independently
from the notes (tests/data/bcpack/generate.py) and a round-trip encoder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
BC1 blocks are rebuilt from the 12 lanes of the entropy stage (bc1.rs,
after the BC1 sections of the bcpack-decoder and bcpack-rs format
notes, MIT, no code taken). The rebuild needs two tables of constants
that no stream carries: the 255 endpoint sets a stream starts with and
the order of the 256 selector quadrants. bcpack-rs by Ahmet Dedeler
(https://github.com/Ahmet-Dedeler/bcpack-rs, MIT) estimated both from
retail data; bc1_fitted.rs is generated from its data files by
scripts/gen_bcpack_bc1_tables.py and carries its MIT notice. The
constants belong to the codec, not to a game.

dstorage.rs runs the BCPack stage for BC1, alone or after zlib; every
other mode is refused and counted as before. A stream the decoder does
not take fails the request with E_DECOMPRESSION and writes nothing.
report.json gets dstorage.bcpack_unpacked per mode (requests, bytes
rebuilt, failed).

The output is an approximation where an estimate is off: one history
entry is not known (a block that refers to it fails the request), 17
differ by a step or so between fits on two halves of the data, and 8
rare quadrants may be swapped with their mirror.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@Cattn your run of a7ffb2f (BC1 refusals 1,492 → 0) is in the description; this PR is the same code. For the merge rules it now needs a regression run: if you can run scripts/smoke.ps1 -Game <your title folder> twice, once built from main (9ab7d76) and once from this PR's head (5f12643), please paste both xcl-smoke blocks here. I'll copy them into the description under Regression run, with your name and hardware. We have no title on our machine.

🤖 Claude Opus 5.5

@ExMoha

ExMoha commented Nov 23, 2026

Copy link
Copy Markdown

Test report for #273 at 5f12643. Written by Claude Code (Claude Sonnet 5.5), which ran the commands; the game ran on my machine.

Setup: AMD Radeon RX 9070 (16 GB; XCL's report.json: "AMD Radeon RX 9070 (16191 MiB VRAM)"), Ryzen 7 7800X3D, 31.2 GB RAM, Windows 11 Pro 10.0.26300, DXC 1.8.2502.11, rustc 1.98.1 (48a229cea 2026-09-01), release build for the runs, debug for the tests. Retail title 1.0.2.1, XCL_NETWORK=0.

Regression run (scripts/smoke.ps1, 60 s, same title, back to back, clean checkouts, no input). First main 9ab7d76 (this PR's base), then this PR's head. The gpu: line is the script's first video controller (the CPU's integrated GPU, see #281 / #285); the runs used the RX 9070.

main 9ab7d76:

xcl-smoke v1
commit: 9ab7d763197c7f420bff10cd9bf1310f07e2a9aa
gpu: AMD Radeon(TM) Graphics
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1505 (PresentX 1505)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14902 MB

5f12643:

xcl-smoke v1
commit: 5f12643999939d07a234081dbc835c0d8a0497c2
gpu: AMD Radeon(TM) Graphics
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1503 (PresentX 1503)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14883 MB

Frames 1503 vs 1505 (99.9 %), peak commit 14883 vs 14902 MB, no device removal, no crash. An earlier pair of runs with inputs gave 1194 (main) and 1211 frames, peak commit 16287 and 16276 MB, no crash and no device removal either; the PR's last three windows there were 0 0 60, which the no-input pair does not repeat.

BC1 effect, scripted menus (XCL_PRESS_A_AT=14,17,21 XCL_ACTIVITY=1, one run each, both stopped by an external kill-switch at 90 % system RAM, no crash, no device removal): current main 85bdf21 against the same with 5f12643 merged in locally (merge commit not published):

  • BC1 refusals: 114 (3,383,296 bytes) -> none; the log has BCPack BC1: first request unpacked (39541 to 65536 bytes). BC5 (107) and BC7 (20 to 34) are still refused.
  • failed DirectStorage requests from the first menu window to the stop: 220 -> 26.

Tests on 5f12643 (cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4): 659 passed, 0 failed, 40 ignored; no SKIPPED GPU tests. The 11 bcpack tests passed.

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@ExMoha thank you: the first run where this decoder is actually called. Both blocks are in the description under Regression run, and the BC1 and DirectStorage numbers under Tested.

🤖 Claude Opus 5.5

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@ivall, for the provenance question you raised on #340: the facts on this PR's two BC1 tables, with no argument about whether they are acceptable. Sources: bcpack-rs at c51ec52 and its research branches, bcpack-decoder at d2cb8f3.

1. How bcpack-rs made them

  • Input: the texture files of one retail title, read from the author's own copy: per texture the BCPack BC1 chunk of mip 0 and the plain BC1 mip 1 (sem-indices branch, docs/findings/sem-indices.md:27: 3,276 textures, 20.3 M blocks for the selector fit).

  • data/bc1_window.json (endpoint history): per slot six numbers, searched so that the decoded blocks' colour segment lies closest to the mip-1 texels over every texture using the slot (sem-endpoints branch, docs/findings/sem-endpoints.md:37-41). Its source line: "fitted against mip-1 consistency on retail texture pools (endpoint-window fit); values only".

  • data/bc1_quad_table.json (symbol to 2x2 selector pattern): a permutation of the 256 patterns, the cheapest assignment against the same target (sem-indices.md:115-126).

  • The files hold the constants and, per entry, summary numbers of the fit (textures and blocks behind it, rms, frequency share, whether two half-fits agree). No texels, blocks or names. tools/import_tables.py:16: "Only the fitted values and summary confidence numbers are copied; no per-texture data and no game bytes." bc1_fitted.rs takes only the six numbers per slot and the pattern per symbol.

  • They are estimates computed from game textures, not exact readings: "fitted: constants estimated from retail data; mostly right, some entries uncertain or missing" (docs/BCPACK_SPEC.md:9). Counted from the JSON: 254 of 256 slots set; a slot rests on 2 to 1,500 textures (median 22; 11 slots on fewer than 5); half-fits differ in 17 slots and 8 patterns.

  • On content: "Entries look like a trained codebook of common endpoint pairs [...] An exact search of the store's decompressed plain data for the slot-121/254/82 colour pairs found nothing systematic." (sem-endpoints.md:128-130)

  • bcpack-rs's own notes also say "Nothing derived from game data is committed" (sem-indices.md:3-4), while these fitted tables are committed in its data/; we report both statements as they stand.

2. The same for every stream and title?

  • Every stream of the title measured: yes by both projects' reports. "a fixed 256-entry table of endpoint fields, the same for every chunk. The table is not in the stream." (BCPACK_SPEC.md:122); "a static table of 255 endpoint pairs [...], identical for every chunk" (bcpack-decoder docs/SPEC.md:230).

  • Every title: nobody has shown it. Each project reports one title; neither compares a second. That the tables belong to the codec is an inference: a stream's bytes are all taken by its 12 lanes, and a DirectStorage request names only the mode.

  • From us: nothing. The fixtures of DirectStorage: BCPack entropy stage for all modes, not yet called #208 and of this PR are synthetic, built with made-up tables.

  • Our own wording is firmer than this evidence: bc1_fitted.rs's header and the commit message call the tables "constants of the codec, not game content". The sources support that for one title. If the PR goes ahead in any form, we reword it to say exactly that.

3. Another route to the same constants

  • None found. Microsoft's silicon-rans (MIT) is the rANS lane only. The related patent has "nothing BC-specific" by bcpack-rs's notes (patent branch, docs/findings/patent.md:159; we did not read the patent). The public DirectStorage documentation, as far as we have read it, gives stage order and mode numbers.
  • bcpack-decoder ships no tables: "as a matter of legal caution they are not shipped with this project. The decoder loads them at runtime from a JSON file [...] and learn-tables derives them from your own BCPack data." (README 101-105)
  • An encoder would give both tables exactly from made-up textures. We know of none outside the console SDK, which CONTRIBUTING rules out.

4. What #208 needs

  • Neither table: nothing at 34c0ee5 refers to them. Its only tables are the 16 rANS models, generated from Microsoft's mdu_minirans.v (MIT) by scripts/gen_bcpack_tables.py.
  • It does take two facts, without code, from the two projects' notes: the lane widths per mode and the rule that shares the bytes between lanes. Their authors worked those out on retail streams as well; they are layout, not estimates. DirectStorage: BCPack entropy stage for all modes, not yet called #208's description and THIRD_PARTY.md say so.

What we can do

  • DirectStorage: BCPack entropy stage for all modes, not yet called #208 is its own PR on main, without a table and not called; it merges cleanly onto a6f5f7a (git merge-tree). It can be decided alone.
  • This PR waits as it is, or we re-cut it without bc1_fitted.rs: bc1.rs takes the tables as a parameter and its tests use made-up ones, so the rebuild stays and BC1 requests are refused as on main. Say which.

Not checked: bcpack-rs's fits were not rerun (that needs game files; we have none), so both projects' statements are quoted, not verified. Whether they measured the same title.

🤖 Claude Fable 5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants