BC5/BC7 entropy stage: two symbol vectors per 16-byte block (structural notes) #5

Closed
opened 2026-11-26 18:55:53 +00:00 by github-bot · 3 comments
Owner

@⁠nineforge0 on GitHub · 2026-11-24 08:49 UTC · original

Sharing structural findings from an independent decoder, in case they help extend decode past BC1. All statistics are from 100 BC5 + 27 BC7 + 1 BC3 real BCPack chunks. No fitted tables or values copied from anywhere — structure and statistics only.

Key correction: two vectors per block

Each lane emits virtual_length / 8 symbols (the same 8-byte unit as BC1), so a 16-byte BCn block takes two symbol vectors, not one.

Symbols per lane BC5 BC7 BC3
virtual_length / 16 (one per block) 0/100 0/27 0/1
virtual_length / 8 100/100 27/27 1/1

With one vector per block the rANS stream stalls after 27-51% of the stored bytes, which is also why individual lane widths look wrong when tested alone. The two vectors of block i are vectors 2i and 2i+1 (confirmed by mutual information: MI(2i,2i+1) >> MI(2i+1,2i+2), e.g. BC7 lane 15: 1.72 vs 0.07 bits).

Confirmed structure

  • Lane widths (as symbol widths, decoder input = width-1): BC5 [4,4,8,8,6,6,6,6,6,6,6,6], BC7 [4,4,8,8,8,8,8,7,7,5,6,8,8,8,8,5]. Changing any one lane by +-1 breaks every chunk.
  • rANS self-consistency: 100%. All 1,644 lanes end in a legal state, every chunk consumed exactly to its zero padding.
  • Fragment headers match the BC1 layout; header+payload accounts for every byte in 1,644/1,644 lanes. All fragments have the flush bit set.

The remaining gap

The entropy layer is exact; what is missing is the fixed transform from each block's two symbol vectors to its 16 BCn bytes. It is not in the stream (only fragment headers + rANS payload), so it must be fitted against reference data (e.g. the plain zlib mips stored next to the BCPack mip-0 slices).

  • BC7: lane 15 is a per-block control symbol (219 of 496 value pairs occur; its value predicts which other lanes are zero). Mapping it to BC7 mode/partition/rotation is the main fit, then per-class field layout.
  • BC5: lanes 2-3 look like endpoint residuals (predictor unknown), lanes 4-11 need a symbol-to-pattern table (natural analogue of BC1's 256-entry quadrant codebook) plus a lane-to-pixel assignment; lane 0 is a 4-bit field of unknown meaning, lane 1 unused.

Full notes (counts and statistics only): https://github.com/nineforge0/forge9/blob/main/docs/bcpack_bc5_bc7_structure.md — reproduce with forge9 bcpack-analyze store.ttpf --codec bc5.

**@⁠nineforge0** on GitHub · 2026-11-24 08:49 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/issues/5) Sharing structural findings from an independent decoder, in case they help extend decode past BC1. All statistics are from 100 BC5 + 27 BC7 + 1 BC3 real BCPack chunks. No fitted tables or values copied from anywhere — structure and statistics only. ## Key correction: two vectors per block Each lane emits `virtual_length / 8` symbols (the same 8-byte unit as BC1), so a 16-byte BCn block takes **two symbol vectors**, not one. | Symbols per lane | BC5 | BC7 | BC3 | |---|---|---|---| | `virtual_length / 16` (one per block) | 0/100 | 0/27 | 0/1 | | `virtual_length / 8` | **100/100** | **27/27** | **1/1** | With one vector per block the rANS stream stalls after 27-51% of the stored bytes, which is also why individual lane widths look wrong when tested alone. The two vectors of block i are vectors 2i and 2i+1 (confirmed by mutual information: MI(2i,2i+1) >> MI(2i+1,2i+2), e.g. BC7 lane 15: 1.72 vs 0.07 bits). ## Confirmed structure - **Lane widths** (as symbol widths, decoder input = width-1): BC5 `[4,4,8,8,6,6,6,6,6,6,6,6]`, BC7 `[4,4,8,8,8,8,8,7,7,5,6,8,8,8,8,5]`. Changing any one lane by +-1 breaks every chunk. - **rANS self-consistency: 100%.** All 1,644 lanes end in a legal state, every chunk consumed exactly to its zero padding. - **Fragment headers** match the BC1 layout; header+payload accounts for every byte in 1,644/1,644 lanes. All fragments have the flush bit set. ## The remaining gap The entropy layer is exact; what is missing is the fixed transform from each block's two symbol vectors to its 16 BCn bytes. It is **not in the stream** (only fragment headers + rANS payload), so it must be fitted against reference data (e.g. the plain zlib mips stored next to the BCPack mip-0 slices). - **BC7:** lane 15 is a per-block control symbol (219 of 496 value pairs occur; its value predicts which other lanes are zero). Mapping it to BC7 mode/partition/rotation is the main fit, then per-class field layout. - **BC5:** lanes 2-3 look like endpoint residuals (predictor unknown), lanes 4-11 need a symbol-to-pattern table (natural analogue of BC1's 256-entry quadrant codebook) plus a lane-to-pixel assignment; lane 0 is a 4-bit field of unknown meaning, lane 1 unused. Full notes (counts and statistics only): https://github.com/nineforge0/forge9/blob/main/docs/bcpack_bc5_bc7_structure.md — reproduce with `forge9 bcpack-analyze store.ttpf --codec bc5`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:55:53 +00:00
Author
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-24 13:35 UTC · original

Thanks for writing this up. It matches what I have on the bc5-bc7 branch, which got to the same structure independently: two symbols per lane for 16-byte blocks and the same lane widths. Good to have a second measurement of both.

That branch goes one step further than the entropy layer. The block rebuild rules for BC3, BC4, BC5 and BC7 are in src/bcn.rs and src/bc7.rs, and with the format's tables they are byte-identical to a reference decoder on every chunk I have (BC5 4.9 M blocks, BC7 80 M, 0 differing). The writeup is in docs/findings/bc345-bc7.md. Short version of the parts you list as open:

  • References: the index reference is lane 1, the endpoint reference is lane 1 + unzigzag(lane 0). References past the chunk start read a 255-entry dictionary per format, same idea as BC1's preset window.
  • BC5 lane 1: it is the index reference. It is always 0 in retail data for BC1, BC3, BC4 and BC5, which is why it looks unused. BC7 uses it.
  • BC7 lane 15: yes, it is the control symbol (mode, partition, rotation, index selection). 205 of the 285 codes could be solved from data alone; modes 0 and 2 could not.
  • The fixed transform: the pair ranks came out of the data as a substitution cipher against the plain mips. The dictionaries did not, statistics get close but never exact.

It is not on master yet because there is no encoder, CLI or Python mirror for those modes. If you try the branch and something disagrees with your 128 chunks, I'd like to hear it.

**@⁠Ahmet-Dedeler** on GitHub · 2026-11-24 13:35 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/issues/5#issuecomment-7133047281) Thanks for writing this up. It matches what I have on the `bc5-bc7` branch, which got to the same structure independently: two symbols per lane for 16-byte blocks and the same lane widths. Good to have a second measurement of both. That branch goes one step further than the entropy layer. The block rebuild rules for BC3, BC4, BC5 and BC7 are in `src/bcn.rs` and `src/bc7.rs`, and with the format's tables they are byte-identical to a reference decoder on every chunk I have (BC5 4.9 M blocks, BC7 80 M, 0 differing). The writeup is in `docs/findings/bc345-bc7.md`. Short version of the parts you list as open: - **References:** the index reference is lane 1, the endpoint reference is lane 1 + unzigzag(lane 0). References past the chunk start read a 255-entry dictionary per format, same idea as BC1's preset window. - **BC5 lane 1:** it is the index reference. It is always 0 in retail data for BC1, BC3, BC4 and BC5, which is why it looks unused. BC7 uses it. - **BC7 lane 15:** yes, it is the control symbol (mode, partition, rotation, index selection). 205 of the 285 codes could be solved from data alone; modes 0 and 2 could not. - **The fixed transform:** the pair ranks came out of the data as a substitution cipher against the plain mips. The dictionaries did not, statistics get close but never exact. It is not on master yet because there is no encoder, CLI or Python mirror for those modes. If you try the branch and something disagrees with your 128 chunks, I'd like to hear it.
Author
Owner

@⁠nineforge0 on GitHub · 2026-11-24 14:37 UTC · original

Validated the bc5-bc7 branch (head c55c5fa) against our 129 real chunks (1 BC3, 100 BC5, 28 BC7; 651,264 blocks). Clean, no disagreements.

  • Decode: 129/129 decode with no error or panic, deterministic across runs. BC7: 0 blocks rejected by unpack, pack(unpack(b)) == b on every block, unknown_controls = 0 everywhere. Modes 0 and 2 are 64,083 of 239,616 BC7 blocks (26.7%); some chunks are ~84% mode 0/2 and still decode cleanly, so your latest control-code fill holds.
  • Pixel check (decode each mip, box-downsample level L, mean abs error vs level L+1, 0-255, vs the plain-only baseline of the same stores):
codec involves BCPack (MAE) plain/plain baseline
BC5 0.98 (102 pairs) 0.61 (354)
BC7 1.54 (31 pairs) 3.27 (400)
BC3 2.92 (1 pair) 3.75 (40)
  • Negative control: zeroing the dictionaries pushes the error to 10.4 (BC5) and 53.3 (BC7), so the check does catch a wrong decode.
  • Limit: this is agreement with the stored mips, not byte-for-byte against a reference decoder (we dont have one).

Two small things from the run:

  1. data/bc7.json has "subsets": null on all 255 entries, which trips an "unfitted" flag downstream even though those blocks decode correctly — looks like a leftover now that modes are filled in.
  2. docs/findings/bc345-bc7.md still says the dictionaries / BC3 quadrant ranks / mode 0/2 codes ship as null; c55c5fa fills them, so that section is stale.

Thanks for the invite to test it — nice work. We pinned forge9's texture decode to this branch.

**@⁠nineforge0** on GitHub · 2026-11-24 14:37 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/issues/5#issuecomment-7134682770) Validated the `bc5-bc7` branch (head `c55c5fa`) against our 129 real chunks (1 BC3, 100 BC5, 28 BC7; 651,264 blocks). **Clean, no disagreements.** - **Decode:** 129/129 decode with no error or panic, deterministic across runs. BC7: 0 blocks rejected by `unpack`, `pack(unpack(b)) == b` on every block, `unknown_controls = 0` everywhere. Modes 0 and 2 are 64,083 of 239,616 BC7 blocks (26.7%); some chunks are ~84% mode 0/2 and still decode cleanly, so your latest control-code fill holds. - **Pixel check** (decode each mip, box-downsample level L, mean abs error vs level L+1, 0-255, vs the plain-only baseline of the same stores): | codec | involves BCPack (MAE) | plain/plain baseline | |---|---|---| | BC5 | 0.98 (102 pairs) | 0.61 (354) | | BC7 | 1.54 (31 pairs) | 3.27 (400) | | BC3 | 2.92 (1 pair) | 3.75 (40) | - **Negative control:** zeroing the dictionaries pushes the error to 10.4 (BC5) and 53.3 (BC7), so the check does catch a wrong decode. - **Limit:** this is agreement with the stored mips, not byte-for-byte against a reference decoder (we dont have one). Two small things from the run: 1. `data/bc7.json` has `"subsets": null` on all 255 entries, which trips an "unfitted" flag downstream even though those blocks decode correctly — looks like a leftover now that modes are filled in. 2. `docs/findings/bc345-bc7.md` still says the dictionaries / BC3 quadrant ranks / mode 0/2 codes ship as null; `c55c5fa` fills them, so that section is stale. Thanks for the invite to test it — nice work. We pinned forge9's texture decode to this branch.
Author
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-25 14:16 UTC · original

Thanks for testing it on your 129 chunks and catching those two things.

bc5-bc7 is now merged into master (7b2dfb7), along with both fixes in f5145dd:

  1. Set "subsets": 1 on all 255 entries in data/bc7.json (each dictionary entry is a single-subset state, so from already fell back to subset 0 for every row and null was just tripping unfitted_blocks on multi-subset blocks). Added a test in tests/modes.rs to verify multi-subset blocks referencing the dictionary come back with unfitted_blocks == 0.
  2. Updated docs/findings/bc345-bc7.md (plus README.md and the crate docs) to reflect the filled tables from c55c5fa and the current library vs CLI status.

You can point forge9 back to master now. Open a new issue if anything else turns up.

**@⁠Ahmet-Dedeler** on GitHub · 2026-11-25 14:16 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/issues/5#issuecomment-7165013944) Thanks for testing it on your 129 chunks and catching those two things. `bc5-bc7` is now merged into `master` (`7b2dfb7`), along with both fixes in `f5145dd`: 1. Set `"subsets": 1` on all 255 entries in `data/bc7.json` (each dictionary entry is a single-subset state, so `from` already fell back to subset 0 for every row and `null` was just tripping `unfitted_blocks` on multi-subset blocks). Added a test in `tests/modes.rs` to verify multi-subset blocks referencing the dictionary come back with `unfitted_blocks == 0`. 2. Updated `docs/findings/bc345-bc7.md` (plus `README.md` and the crate docs) to reflect the filled tables from `c55c5fa` and the current library vs CLI status. You can point forge9 back to `master` now. Open a new issue if anything else turns up.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Ahmet-Dedeler--bcpack-rs#5
No description provided.