Skip to content

DirectStorage: BCPack BC3, BC4 and BC5 block rebuilds, without their tables, not yet called - #340

Open
NiiRoZz wants to merge 5 commits into
ivall:mainfrom
NiiRoZz:nii/bcpack
Open

NiiRoZz wants to merge 5 commits into
ivall:mainfrom
NiiRoZz:nii/bcpack

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 23, 2026 •

Copy link
Copy Markdown

Stacked on #273 (itself on #208); only the top three commits belong here: 6fd5a60 (BC4), f58df2f (BC5), e02a003 (BC3).

Adds the block rebuild for the three remaining 12-lane BCPack modes, from #208's lanes and in the form of #273's bc1.rs. Each needs constants that no stream carries: the order of the 64 selector pairs (BC3 also the order of the 256 colour quadrants) and a built-in history of 255 endpoint sets that a stream's first blocks refer back to. XCL has no source for them it can take, so they are a Tables parameter: no table is shipped, nothing calls the new code, and DirectStorage refuses BC3 / BC4 / BC5 requests exactly as on main. It is here so that whoever has the tables only has to supply them.

No overlap found: #273 and #233 cover BC1 only.

What is in it

  • hle/bcpack/bc4.rs, bc5.rs, bc3.rs: lanes to blocks, one commit per mode. A block whose history entry is unknown fails with Error::History and nothing is written.
  • hle/bcpack/mod.rs: the modules and their docs.
  • hle/bcpack/tests.rs, tests/data/bcpack/generate.py, tests/data/bcpack/bc{3,4,5}-*: a synthetic fixture per mode, built with made-up tables by the generator's own per-texel assembly, and a hand-built case per mode that covers every field. The fixtures are 2 to 7 KB each.
  • Size: 518 changed lines, 252 of them the three decoders. It is one PR because the three share the fixture generator and the test scaffold, and none is of use before the others' tables exist either.

Tested

  • NVIDIA GeForce RTX 5090 (driver 621.35), AMD Ryzen 7 9800X3D, Windows 11 Pro 26300, Rust 1.100.0.
  • cargo test --release -p xcl --lib bcpack: 17 passed. cargo test --release -p xcl --lib dstorage: 13 passed.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 665 passed, 0 failed, 40 ignored. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • What a retail title's streams say about the missing constants: every BC4 and BC5 chunk of the one checked predicts from the built-in history in its first blocks, so the pair order alone unlocks none of them; 8 of its 35 BC3 chunks never do.

Regression run

scripts/smoke.ps1 -Game <folder> -Seconds 60, release builds, no input (the title stays on its first menu), each run with the machine to itself. The new code is not called by the runtime, so the runs can only show that nothing else moved. The stack sits on #273's base (9ab7d76), so the two builds differ by more than these commits. gpu: is the first video controller Windows lists (#281 / #282 / #285); XCL's log names the RTX 5090 as its backend in both runs.

main:

xcl-smoke v1
commit: 3516080d53daac0f7749b5c02bc9b1e371479557
gpu: AMD Radeon(TM) Graphics
title: retail
seconds: 60
exit: 0x0
frames shown: 1358 (PresentX 1359)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14838 MB

PR:

xcl-smoke v1
commit: e02a0033071233a140dd3dfcb0286a3466e0159d
gpu: AMD Radeon(TM) Graphics
title: retail
seconds: 60
exit: 0x0
frames shown: 1347 (PresentX 1347)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15191 MB

Not tested

  • The tables: XCL has none, so no real stream is rebuilt by this PR.
  • Output against a console's, and any effect on a game: nothing calls the code.
  • Each commit on its own: the suite ran on the head only.

AI use

  • Claude Code with Claude Opus 5.5 wrote the code and the tests, Claude Fable 5.2 this description. The tests and runs above were made on my machine, and I have read the diff.

Kalmarv and others added 5 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>
…called

Stacked on ivall#273 (BC1), which is stacked on ivall#208 (entropy stage). Adds
hle/bcpack/bc4.rs: BC4 blocks from the 12 lane symbols of a BC4 stream, in
the form of ivall#273's bc1.rs. Lane 0 is a back-reference to the block whose
endpoints predict this one's (or to a built-in history before block 0, or
128/128 for none), lane 1 must be 0, lanes 2-3 are zigzag differences of
A0/A1 modulo 256, and lanes 4-11 are the 3-bit selectors two texels at a
time through a 64-entry pair table, row by row, left half first.

The rebuild needs two constants that no stream carries: the order of the
64 pairs and the 255-entry history. XCL has no source for them it can
take, so they are a parameter (bc4::Tables), nothing is shipped and nothing
calls the rebuild: DirectStorage refuses BC4 requests exactly as before.
Every BC4 chunk of the retail title checked here predicts from the history
in its first blocks, so the pair table alone would unlock none of them.

Checked:
- tests/data/bcpack/generate.py builds bc4-300-4 (300 blocks, predictions
  from the history and from the stream) with made-up tables and its own
  per-texel Python assembly; the decoder gives the same blocks, and refuses
  a block whose history entry is unknown.
- A hand-built three-block case covers every field, wrapping differences
  and a non-zero lane 1.

AI-assisted.
…called

Stacked on the BC4 rebuild. Adds hle/bcpack/bc5.rs: BC5 blocks from the
12 lanes, two symbols per lane and block (units 2i and 2i+1). Lane 0 is a
back-reference split over the two units (even bits in the first, odd bits
in the second) and then read as BC4's; lane 1 must be 0 in both; lanes 2
and 3 are the differences of R0/R1 and G0/G1, one per unit; lanes 4-7 and
8-11 are the red and green selectors, a row per lane, the row's left half
in the first unit and its right half in the second, through a pair table
as BC4's. It reuses BC4's back-reference, difference and selector helpers.

As for BC4, the pair order and the 255-entry history of endpoints
(R0, R1, G0, G1) are not in a stream and XCL has no source for them it can
take: they are a parameter, nothing is shipped or wired, and BC5 requests
are refused as before. Every BC5 chunk of the retail title checked here
predicts from the history in its first blocks.

Checked:
- generate.py builds bc5-600-5 (300 blocks) with the made-up tables and its
  own Python assembly; the decoder gives the same blocks, refuses an unknown
  history entry and a size of half a block.
- A hand-built two-block case: the split back-reference (one block back,
  then 255 back), both channels' differences and selector rows, lane 1.

AI-assisted.
…called

Stacked on the BC5 rebuild. Adds hle/bcpack/bc3.rs: BC3 blocks from the 12
lanes, two symbols per lane and block. Lane 0 is BC5's split back-reference
(prediction 128/128 for alpha and 0 for colour when there is none), lane 1
must be 0, lane 2 holds the A0/A1 differences, lanes 3-6 the alpha selector
rows through a pair table as BC4's, lanes 7-9 the red/green/blue
differences of colour 0 (first unit) and colour 1 (second unit) modulo 32,
64 and 32, and lanes 10-11 the colour selectors as BC1's 2x2 quadrants
(top-left/top-right, bottom-left/bottom-right).

Three constants are not in a stream: the alpha pair order, the quadrant
order and the 255-entry history of endpoints (A0, A1, R0, G0, B0, R1, G1,
B1). XCL has no source for them it can take, so they are a parameter and
nothing is shipped or wired; BC3 requests are refused as before. Of the 35
BC3 chunks of the retail title checked here, 8 never predict from the
history, so the two orders alone would unlock those 8.

Checked:
- generate.py builds bc3-600-6 (300 blocks) with made-up tables and its own
  per-texel Python assembly; the decoder gives the same blocks, refuses an
  unknown history entry and half a block.
- A hand-built two-block case: every field, colour differences wrapping in
  5 and 6 bits, a prediction from a rebuilt block's colours, lane 1.

AI-assisted.
@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks - not merged for now: it is stacked on #273 / #208, whose BC1 tables come from bcpack-rs's estimates made from retail data, and that provenance question is still open on the maintainer's side; on its own the new code is not called yet. It stays open until #208 / #273 are decided.

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.

3 participants