Add a source-built BC7 block reference and field fixture #106

Manually merged
github merged 4 commits from gh-pr/106/head into gh-pr/106/base 2026-11-26 21:27:18 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 15:59 UTC · original
Vonsek:bcpack-reference → main · +430 −1 · 5 files · 4 commits · merged 2026-11-21 17:03 UTC

Change

Adds tools/bc7_blocks.py, a pure-Python BC7 reference for the block reference that #15 asks for. layout(mode, partition) lists the name, first bit and width of every field. unpack and pack convert between a 16-byte block and named field values, and decode returns RGBA8 texels for all eight modes. fixture() generates 512 blocks with known field values covering every mode, partition, rotation and index selection value, and the CLI writes them in the existing BC7C case layout with an optional JSON field dump. The new bc7_block_reference test is registered beside bcpack_prefix_and_mip_tail.

The module contains no BCPack logic and makes no claim about the packed format. It gives a candidate lane-to-field mapping the complete block rows and field values to compare against.

Refs #15

Verification

Linux, Python 3.13:

python -B tests/bc7_blocks_check.py   -> Ran 7 tests, OK (skipped=1)
python -B tests/bcpack_check.py       -> OK

With the optional texture2ddecoder 1.0.6 installed, all 7 tests pass, including a comparison of 16,897 decoded blocks. Separately, 65,536 random blocks per mode and 65,536 uniformly random blocks decoded identically with texture2ddecoder. The fixture and per-mode random blocks also decoded identically with Pillow 13.0.0; Pillow differs only on reserved-mode blocks. The test also runs in the Windows CI job through ctest. On Windows, ctest --preset dev --no-tests=error -R '^(bc7_block_reference|bcpack_prefix_and_mip_tail)$' -V at bb67738 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): both passed (bc7_block_reference: Ran 7 tests, OK, skipped=1).

Evidence and follow-up

All fixtures are generated: field values come from SHA-256 of the mode, case number and field name, and the block rows and texels are pinned by digest. The mode, partition, anchor and weight tables are facts of the public BC7 format. The test checks them against field offsets transcribed from the published mode layouts, three blocks whose texels are derived by hand in comments, anchor/subset consistency, and the independently written mode-6 blocks in tests/bc7_draw_check.py. Changing one partition bit, anchor, weight, field width or the bit-replication shift fails the test. No game or SDK material is used.

Follow-up for #15:

  • Drawing the generated BC7C case through offscreen_check --check-bc7 has not been run; it would add a GPU decoder as a further reference.
  • Variable-symbol distributions, refill order beyond the documented rounds, and the lane-to-field mapping remain open. This change supplies only the known blocks to match against.

README: the "Texture recovery" row of the experiment table now lists bc7_block_reference. Details are in docs/experiments.md under "Drawing BC7 textures with a recompiled pixel shader".

Reproduction: ctest --preset dev --no-tests=error -R '^bc7_block_reference$' -V or python -B tests/bc7_blocks_check.py.

**@⁠Vonsek** on GitHub · 2026-11-21 15:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/106) `Vonsek:bcpack-reference` → `main` · +430 −1 · 5 files · 4 commits · merged 2026-11-21 17:03 UTC ## Change Adds `tools/bc7_blocks.py`, a pure-Python BC7 reference for the block reference that #15 asks for. `layout(mode, partition)` lists the name, first bit and width of every field. `unpack` and `pack` convert between a 16-byte block and named field values, and `decode` returns RGBA8 texels for all eight modes. `fixture()` generates 512 blocks with known field values covering every mode, partition, rotation and index selection value, and the CLI writes them in the existing `BC7C` case layout with an optional JSON field dump. The new `bc7_block_reference` test is registered beside `bcpack_prefix_and_mip_tail`. The module contains no BCPack logic and makes no claim about the packed format. It gives a candidate lane-to-field mapping the complete block rows and field values to compare against. Refs #15 ## Verification Linux, Python 3.13: ``` python -B tests/bc7_blocks_check.py -> Ran 7 tests, OK (skipped=1) python -B tests/bcpack_check.py -> OK ``` With the optional `texture2ddecoder` 1.0.6 installed, all 7 tests pass, including a comparison of 16,897 decoded blocks. Separately, 65,536 random blocks per mode and 65,536 uniformly random blocks decoded identically with `texture2ddecoder`. The fixture and per-mode random blocks also decoded identically with Pillow 13.0.0; Pillow differs only on reserved-mode blocks. The test also runs in the Windows CI job through ctest. On Windows, `ctest --preset dev --no-tests=error -R '^(bc7_block_reference|bcpack_prefix_and_mip_tail)$' -V` at bb67738 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): both passed (`bc7_block_reference`: Ran 7 tests, OK, skipped=1). ## Evidence and follow-up All fixtures are generated: field values come from SHA-256 of the mode, case number and field name, and the block rows and texels are pinned by digest. The mode, partition, anchor and weight tables are facts of the public BC7 format. The test checks them against field offsets transcribed from the published mode layouts, three blocks whose texels are derived by hand in comments, anchor/subset consistency, and the independently written mode-6 blocks in `tests/bc7_draw_check.py`. Changing one partition bit, anchor, weight, field width or the bit-replication shift fails the test. No game or SDK material is used. Follow-up for #15: - Drawing the generated `BC7C` case through `offscreen_check --check-bc7` has not been run; it would add a GPU decoder as a further reference. - Variable-symbol distributions, refill order beyond the documented rounds, and the lane-to-field mapping remain open. This change supplies only the known blocks to match against. README: the "Texture recovery" row of the experiment table now lists `bc7_block_reference`. Details are in `docs/experiments.md` under "Drawing BC7 textures with a recompiled pixel shader". Reproduction: `ctest --preset dev --no-tests=error -R '^bc7_block_reference$' -V` or `python -B tests/bc7_blocks_check.py`.
Pack, unpack and decode all eight BC7 modes in pure Python and
generate blocks with known field values for every mode and partition.
Pin the layout to hand-derived vectors, the mode-6 draw fixture and
fixed digests, and register the check as bc7_block_reference.

Refs #15
# Conflicts:
#	docs/experiments.md
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:27:17 +00:00
github manually merged commit da357bdd73 into gh-pr/106/base 2026-11-26 21:27:18 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.