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

Merged
Vonsek merged 4 commits from upstream-pr/106 into main 2026-11-21 17:03:07 +00:00
Vonsek commented 2026-11-21 15:59:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T15:59:47Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6531085780 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/106). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T15:59:47Z. --- ## 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`.
upstream-sync closed this pull request 2026-11-24 06:41:20 +00:00
Sign in to join this conversation.
No reviewers
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!105
No description provided.