Add a source-built BC7 block reference and field fixture #105
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/106"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.unpackandpackconvert between a 16-byte block and named field values, anddecodereturns 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 existingBC7Ccase layout with an optional JSON field dump. The newbc7_block_referencetest is registered besidebcpack_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:
With the optional
texture2ddecoder1.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 withtexture2ddecoder. 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)$' -Vatbb67738on 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:
BC7Ccase throughoffscreen_check --check-bc7has not been run; it would add a GPU decoder as a further reference.README: the "Texture recovery" row of the experiment table now lists
bc7_block_reference. Details are indocs/experiments.mdunder "Drawing BC7 textures with a recompiled pixel shader".Reproduction:
ctest --preset dev --no-tests=error -R '^bc7_block_reference$' -Vorpython -B tests/bc7_blocks_check.py.