Add a byte-exact BC7 mode-6 BCPack fixture for the decoder in #15 #436

Closed
opened 2026-11-22 03:33:43 +00:00 by wish131400 · 2 comments
wish131400 commented 2026-11-22 03:33:43 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by wish131400 on 2026-11-22T03:33:43Z.


Following up on #15, could this one-block fixture be added to the BC7 regression suite? It gives another implementation a fixed compressed input and the expected 16 output bytes. I generated it from a chosen standard BC7 mode-6 block with Leonida’s synthetic encoder and checked the result with the packaged Python decoder in strict mode. The fixture requires no game files or preset history. Its scope is a synthetic round trip; I have no Xbox hardware reference for it.

Reproduce

With tools/ from the linked revision on the Python import path, this passes as written. To exercise another implementation, replace the call to decode_with_info and compare all 16 bytes. Decoder · Synthetic encoder

import bcpack

packed = bytes.fromhex("""
101010101010101004040303030304040101010101010140
000000000000024002027546281800000101df5f4b7c0341
020202411010101004040403101010104004100103030304
4001080001010104000000080000000041020994e4db27a4
410511fe6b020005
""")
expected = bytes.fromhex("40 31 72 04 a5 68 19 be 02 34 56 78 9a bc de f0")
actual, provisional = bcpack.decode_with_info(packed, 7, 16)
assert actual == expected
assert not provisional

From the stream to the BC7 block

  1. Use 16 rANS lanes with symbol widths 4,4,8,8,8,8,8,7,7,5,6,8,8,8,8,5. Each lane emits two symbols per 16-byte output block. The feeder grants at most eight requested bytes per clock in lane order. The two lane-15 symbols select the mode, partition, rotation and index-selection configuration.
  2. Let inter(a,b) put the four bits of a in positions 0,2,4,6 and those of b in 1,3,5,7. For each block in stored order, compute di = inter(lane1[2*i], lane1[2*i+1]) and de = (di + unzig(inter(lane0[2*i], lane0[2*i+1]))) & 255, where unzig(v) = (v >> 1) ^ -(v & 1). These are the index and endpoint distances respectively. Distance zero uses the BC7 zero predictor. A positive distance reads block i-d, or initial history slot 256+i-d when d > i. This fixture sets both distances to zero.
  3. In mode 6, lanes 2–5 carry R, G, B and A endpoint residuals. The two symbols address endpoints 0 and 1. The red field includes each endpoint’s p-bit. Add the signed residual modulo the field width, then store the reconstructed history value left-aligned for the next block. Lanes 11–14 carry the four selector rows. Within each pixel pair use odd/even interleaved bits for rows 0–2, and even/odd for row 3. Mode 6 stores a 3-bit anchor selector and fifteen 4-bit selectors.

On a local corpus, all 5,167 BC7 chunks consumed their declared payload and reached legal rANS end states. End-state convergence checks the entropy layer. Exact reconstruction of chunks that reference fitted initial history still needs independent block comparisons. Earlier feeder work and bcpack-rs results

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6537972736 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/442). Originally posted by [wish131400](https://github.com/wish131400) on 2026-11-22T03:33:43Z. --- Following up on #15, could this one-block fixture be added to the BC7 regression suite? It gives another implementation a fixed compressed input and the expected 16 output bytes. I generated it from a chosen standard BC7 mode-6 block with Leonida’s synthetic encoder and checked the result with the packaged Python decoder in strict mode. The fixture requires no game files or preset history. Its scope is a synthetic round trip; I have no Xbox hardware reference for it. ### Reproduce With `tools/` from the linked revision on the Python import path, this passes as written. To exercise another implementation, replace the call to `decode_with_info` and compare all 16 bytes. [Decoder](https://github.com/timelery/Leonida/blob/03d1e118a676d73aba66b1793cf033f6ad23b2b2/tools/bcpack.py) · [Synthetic encoder](https://github.com/timelery/Leonida/blob/03d1e118a676d73aba66b1793cf033f6ad23b2b2/tests/test_bcpack.py) ```python import bcpack packed = bytes.fromhex(""" 101010101010101004040303030304040101010101010140 000000000000024002027546281800000101df5f4b7c0341 020202411010101004040403101010104004100103030304 4001080001010104000000080000000041020994e4db27a4 410511fe6b020005 """) expected = bytes.fromhex("40 31 72 04 a5 68 19 be 02 34 56 78 9a bc de f0") actual, provisional = bcpack.decode_with_info(packed, 7, 16) assert actual == expected assert not provisional ``` ### From the stream to the BC7 block 1. Use 16 rANS lanes with symbol widths `4,4,8,8,8,8,8,7,7,5,6,8,8,8,8,5`. Each lane emits two symbols per 16-byte output block. The feeder grants at most eight requested bytes per clock in lane order. The two lane-15 symbols select the mode, partition, rotation and index-selection configuration. 2. Let `inter(a,b)` put the four bits of `a` in positions 0,2,4,6 and those of `b` in 1,3,5,7. For each block in stored order, compute `di = inter(lane1[2*i], lane1[2*i+1])` and `de = (di + unzig(inter(lane0[2*i], lane0[2*i+1]))) & 255`, where `unzig(v) = (v >> 1) ^ -(v & 1)`. These are the index and endpoint distances respectively. Distance zero uses the BC7 zero predictor. A positive distance reads block `i-d`, or initial history slot `256+i-d` when `d > i`. This fixture sets both distances to zero. 3. In mode 6, lanes 2–5 carry R, G, B and A endpoint residuals. The two symbols address endpoints 0 and 1. The red field includes each endpoint’s p-bit. Add the signed residual modulo the field width, then store the reconstructed history value left-aligned for the next block. Lanes 11–14 carry the four selector rows. Within each pixel pair use odd/even interleaved bits for rows 0–2, and even/odd for row 3. Mode 6 stores a 3-bit anchor selector and fifteen 4-bit selectors. On a local corpus, all 5,167 BC7 chunks consumed their declared payload and reached legal rANS end states. End-state convergence checks the entropy layer. Exact reconstruction of chunks that reference fitted initial history still needs independent block comparisons. [Earlier feeder work and bcpack-rs results](https://github.com/R0Y00/Xbox2Windows/issues/15#issuecomment-7070407414)
wish131400 commented 2026-11-24 06:48:24 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by wish131400 on 2026-11-22T04:38:29Z.


While testing archive extraction, oVolkra caught a mistake in my companion issue. In an RDS5 chunk-table entry, the low 26 bits give the physical offset in units of 256 bytes. Bits 26 through 29 give the codec ID.

offset_bytes = (v & 0x03ffffff) << 8
codec_id = (v >> 26) & 0x0f

For example, the synthetic entry value 0x1d000000 selects codec 7 at byte offset 4 GiB. A 24-bit mask would instead read from byte zero. The BC7 fixture above already supplies the extracted bytes, so its expected 16-byte output is still valid.

Leonida PR #882

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7074292486 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/442#issuecomment-7074292486). Originally posted by [wish131400](https://github.com/wish131400) on 2026-11-22T04:38:29Z. --- While testing archive extraction, oVolkra caught a mistake in my companion issue. In an RDS5 chunk-table entry, the low 26 bits give the physical offset in units of 256 bytes. Bits 26 through 29 give the codec ID. ```python offset_bytes = (v & 0x03ffffff) << 8 codec_id = (v >> 26) & 0x0f ``` For example, the synthetic entry value `0x1d000000` selects codec 7 at byte offset 4 GiB. A 24-bit mask would instead read from byte zero. The BC7 fixture above already supplies the extracted bytes, so its expected 16-byte output is still valid. [Leonida PR #882](https://github.com/ItsNotRexed/Leonida/pull/882)
R0Y00 commented 2026-11-24 06:48:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T01:59:33Z.


#613 merged in f77b829. The bounded rANS decoder reproduces all 32 expected symbols from this issue’s synthetic packet and consumes all 104 bytes. The pinned Rust-generated controls cover another 9,168 symbols. Both Windows configurations and the Linux checks passed on the merged candidate.

This issue stays open for an independent symbol-to-field reconstruction of the expected 16-byte BC7 block using the repository’s decoder.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7089572633 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/442#issuecomment-7089572633). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T01:59:33Z. --- #613 merged in f77b829. The bounded rANS decoder reproduces all 32 expected symbols from this issue’s synthetic packet and consumes all 104 bytes. The pinned Rust-generated controls cover another 9,168 symbols. Both Windows configurations and the Linux checks passed on the merged candidate. This issue stays open for an independent symbol-to-field reconstruction of the expected 16-byte BC7 block using the repository’s decoder.
Sign in to join this conversation.
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
R0Y00/Xbox2Windows#436
No description provided.