textures: check the BC7 4 KiB standard detile order #1452

Manually merged
github merged 1 commit from gh-pr/1452/head into gh-pr/1452/base 2026-11-26 23:08:17 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 11:47 UTC · original
Asimmimx:startup/bc7-4k-s-check → main · +279 −0 · 3 files · 1 commits · merged 2026-11-24 12:29 UTC

Change

Refs #1149. This adds a device-free check for src/startup_stubs/bc7_4k_s.h: supports_bc7_4k_s, the padded sizes of Bc16Surface, block_offset (the GFX10 4 KiB standard non-XOR 16-byte order y0 y1 x0 x1 y2 x2 y3 x3) and detile.

The existing tests reach the header through three paths:

  • startup_xg_bc7_layout compares the copy with an independent bit-order oracle, but only at 81x69 and 64x64. Those are square tile grids (2x2 and 1x1), and the test uses accepted descriptions only.
  • startup_xg_bc7_draw_warp tiles and detiles with the same block_offset, so on its own it cannot see a wrong order.
  • startup_address_bc_view_warp also calls detile.

As a result:

  • A block_offset that multiplies the tile row by tile_rows instead of tile_columns passed every existing CPU and WARP test. That multiplier misplaces blocks on any non-square tile grid.
  • A supports_bc7_4k_s with the MipLevels == 1 or the Alignment == 0 condition dropped also passed.

startup_bc7_4k_s includes only the header. Its expected offsets come from a table of the documented (axis, bit) order and from 16 offsets worked out by hand, not from the header's shifts and masks. It checks:

  • every block offset, unique and in range, on 10 surfaces: 1x1, 4x4, 5x3, 64x64, 65x64, 64x65, 81x69, 200x72 (4x2 tiles), 72x200 (2x4 tiles), and 16384x16384 (sizes only);
  • padded width, height, row bytes and size;
  • detile at tight, +48 and +256 row pitches, with 64-byte guards. The row gaps must stay untouched and the source must not change;
  • Bc16Surface(desc);
  • 3 accepted descriptions and 24 refused ones, each with one field changed, including a Width of 2^32 + 64.

startup_bc7_4k_s_x_first_control runs --mutate x-first, which expects an x-first Morton order, and must fail (WILL_FAIL).

The change is test, CMake and docs/startup-runtime.md only. The header and the device code are unchanged. The CMake block sits after the startup_plane_size_device registration, so it merges cleanly with #1447 and #1450.

Verification

Commit 92bd3362 (main) plus this change, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0.

ctest --preset dev --no-tests=error -R '^(startup_bc7_4k_s|startup_bc7_4k_s_x_first_control|startup_xg_bc7_layout|startup_xg_bc7_draw_warp|startup_address_bc_view_warp)$' -V
startup_bc7_4k_s ...................   Passed   (PASS (16 offsets, 10 surfaces, 3 accepted, 24 refused descriptions))
startup_bc7_4k_s_x_first_control ...   Passed   (the mutated expectations fail, as intended)
startup_xg_bc7_layout ..............   Passed
startup_xg_bc7_draw_warp ...........   Passed
startup_address_bc_view_warp .......   Passed

tests/docs_links_check.py and tests/bidi_controls_check.py passed. addrlib was not configured on this build, but none of these tests need it.

Mutation probe

I applied each mutation to the header alone, rebuilt startup_stub_xg_xs and startup_stream_consumer, ran the tests, then reverted. None of this is committed. "Existing" means startup_xg_bc7_layout, startup_xg_bc7_draw_warp, startup_xg_bc_tiling, startup_xg_bc_chain_warp, startup_xg_bc_array_warp and startup_address_bc_view_warp.

Mutant Existing tests startup_bc7_4k_s
bit swap (y&4)<<2 ↔ (x&4)<<3 killed (layout, address_bc_view; draw_warp passed) fails
tile_rows rounding removed killed fails
padded_row_bytes with block_texels killed (layout only) fails
MipLevels == 1 dropped survived fails
detile ignores row_pitch killed (draw_warp only, needs WARP) fails (CPU only)
tile index * tile_rows instead of * tile_columns survived fails
Alignment == 0 dropped survived fails

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

**@⁠Asimmimx** on GitHub · 2026-11-24 11:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1452) `Asimmimx:startup/bc7-4k-s-check` → `main` · +279 −0 · 3 files · 1 commits · merged 2026-11-24 12:29 UTC ## Change Refs #1149. This adds a device-free check for `src/startup_stubs/bc7_4k_s.h`: `supports_bc7_4k_s`, the padded sizes of `Bc16Surface`, `block_offset` (the GFX10 4 KiB standard non-XOR 16-byte order `y0 y1 x0 x1 y2 x2 y3 x3`) and `detile`. The existing tests reach the header through three paths: - `startup_xg_bc7_layout` compares the copy with an independent bit-order oracle, but only at 81x69 and 64x64. Those are square tile grids (2x2 and 1x1), and the test uses accepted descriptions only. - `startup_xg_bc7_draw_warp` tiles and detiles with the same `block_offset`, so on its own it cannot see a wrong order. - `startup_address_bc_view_warp` also calls `detile`. As a result: - A `block_offset` that multiplies the tile row by `tile_rows` instead of `tile_columns` passed every existing CPU and WARP test. That multiplier misplaces blocks on any non-square tile grid. - A `supports_bc7_4k_s` with the `MipLevels == 1` or the `Alignment == 0` condition dropped also passed. `startup_bc7_4k_s` includes only the header. Its expected offsets come from a table of the documented `(axis, bit)` order and from 16 offsets worked out by hand, not from the header's shifts and masks. It checks: - every block offset, unique and in range, on 10 surfaces: 1x1, 4x4, 5x3, 64x64, 65x64, 64x65, 81x69, 200x72 (4x2 tiles), 72x200 (2x4 tiles), and 16384x16384 (sizes only); - padded width, height, row bytes and size; - `detile` at tight, +48 and +256 row pitches, with 64-byte guards. The row gaps must stay untouched and the source must not change; - `Bc16Surface(desc)`; - 3 accepted descriptions and 24 refused ones, each with one field changed, including a `Width` of 2^32 + 64. `startup_bc7_4k_s_x_first_control` runs `--mutate x-first`, which expects an x-first Morton order, and must fail (`WILL_FAIL`). The change is test, CMake and `docs/startup-runtime.md` only. The header and the device code are unchanged. The CMake block sits after the `startup_plane_size_device` registration, so it merges cleanly with #1447 and #1450. ## Verification Commit `92bd3362` (`main`) plus this change, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0. ```powershell ctest --preset dev --no-tests=error -R '^(startup_bc7_4k_s|startup_bc7_4k_s_x_first_control|startup_xg_bc7_layout|startup_xg_bc7_draw_warp|startup_address_bc_view_warp)$' -V ``` ```text startup_bc7_4k_s ................... Passed (PASS (16 offsets, 10 surfaces, 3 accepted, 24 refused descriptions)) startup_bc7_4k_s_x_first_control ... Passed (the mutated expectations fail, as intended) startup_xg_bc7_layout .............. Passed startup_xg_bc7_draw_warp ........... Passed startup_address_bc_view_warp ....... Passed ``` `tests/docs_links_check.py` and `tests/bidi_controls_check.py` passed. addrlib was not configured on this build, but none of these tests need it. ## Mutation probe I applied each mutation to the header alone, rebuilt `startup_stub_xg_xs` and `startup_stream_consumer`, ran the tests, then reverted. None of this is committed. "Existing" means `startup_xg_bc7_layout`, `startup_xg_bc7_draw_warp`, `startup_xg_bc_tiling`, `startup_xg_bc_chain_warp`, `startup_xg_bc_array_warp` and `startup_address_bc_view_warp`. | Mutant | Existing tests | `startup_bc7_4k_s` | |---|---|---| | bit swap `(y&4)<<2` ↔ `(x&4)<<3` | killed (layout, address_bc_view; draw_warp passed) | fails | | `tile_rows` rounding removed | killed | fails | | `padded_row_bytes` with `block_texels` | killed (layout only) | fails | | `MipLevels == 1` dropped | **survived** | fails | | `detile` ignores `row_pitch` | killed (draw_warp only, needs WARP) | fails (CPU only) | | tile index `* tile_rows` instead of `* tile_columns` | **survived** | fails | | `Alignment == 0` dropped | **survived** | fails | ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
src/startup_stubs/bc7_4k_s.h was reached only through the XG layout check
and the BC7 draw checks. Those run 81x69 and 64x64 surfaces, whose tile
grids are square (2x2 and 1x1), and pass only accepted descriptions. A
block offset that multiplied the tile row by the tile row count instead of
the tile column count, or a supports_bc7_4k_s that dropped the MipLevels
or Alignment condition, passed every existing CPU and WARP test. The draw
check tiles and detiles with the same block offsets, so it cannot see a
wrong bit order on its own.

startup_bc7_4k_s builds against the header alone. It compares every block
offset with a table of the documented y0 y1 x0 x1 y2 x2 y3 x3 bits and
with hand-worked offsets on partial and non-square grids (200x72, 72x200).
It checks the padded sizes from 1x1 to 16384x16384 and detile into
destinations at three row pitches with guard bytes. It also refuses 24
descriptions, each with one field changed. The x-first control expects
the wrong order and must fail.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:08:16 +00:00
github manually merged commit e750486284 into gh-pr/1452/base 2026-11-26 23:08:17 +00:00
Author
Owner

@⁠ChazY11 on GitHub · 2026-11-24 12:01 UTC · original

I reproduced both mutations you describe, and the new check is the only one that catches them

Independent reviewer, not the author. I did not push anything to the branch; the mutations below were made locally,
rebuilt, then reverted, and the working tree is clean.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11, commit e7504862.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^(startup_bc7_4k_s|startup_bc7_4k_s_x_first_control|startup_xg_bc7_layout|startup_xg_bc7_draw_warp|startup_address_bc_view_warp)$'

Unmodified branch — 5 of 5 pass (startup_bc7_4k_s 0.17 s, _x_first_control 0.02 s, startup_xg_bc7_layout 0.47 s,
startup_xg_bc7_draw_warp 4.93 s, startup_address_bc_view_warp 6.05 s).

Mutation 1 — tile row multiplied by tile_rows instead of tile_columns

-const auto tile = std::uint64_t{row / tile_blocks} * tile_columns + column / tile_blocks;
+const auto tile = std::uint64_t{row / tile_blocks} * tile_rows    + column / tile_blocks;
1/5 startup_bc7_4k_s ................... ***Failed   startup_bc7_4k_s: 7 FAILED
2/5 startup_bc7_4k_s_x_first_control ... Passed
3/5 startup_xg_bc7_layout .............. Passed
4/5 startup_xg_bc7_draw_warp ........... Passed
5/5 startup_address_bc_view_warp ....... Passed

Mutation 2 — desc.Alignment == 0 dropped from supports_bc7_4k_s

-desc.SampleDesc.Quality == 0 && desc.Alignment == 0 && desc.Flags
+desc.SampleDesc.Quality == 0 && desc.Flags
1/4 startup_bc7_4k_s ................... ***Failed   startup_bc7_4k_s: 2 FAILED
2/4 startup_xg_bc7_layout .............. Passed
3/4 startup_xg_bc7_draw_warp ........... Passed
4/4 startup_address_bc_view_warp ....... Passed

So the gap you describe is real at this commit: with either mutation the three older checks still pass, and the new
device-free check is the one that reports a first mismatch. That is the property I would want from a new fixture, and it
is worth having in the log for the reason you give — the existing layout test only sees square tile grids (2x2 and 1x1),
and detile is exercised by tests that tile with the same block_offset.

Two small notes, neither blocking

  1. startup_bc7_4k_s_x_first_control stays green under both mutations, which is correct for a control but means a
    reader skimming the ctest list could take it for coverage of the order. One line in the test's own output naming what
    it is a control for would remove that.
  2. If a non-square grid is cheap to add to startup_xg_bc7_layout, the order bug would fail the older check too and the
    new fixture would stop being the sole reporter. Your call — the current split is defensible and the new check is
    device-free, which is what makes it run everywhere.

Verdict

Reviewed e7504862. Builds clean, the new checks pass, both negative controls behave as claimed, and the CMake wiring is
two add_test lines plus the target. No objection from me.

**@⁠ChazY11** on GitHub · 2026-11-24 12:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1452#issuecomment-7130850892) ## I reproduced both mutations you describe, and the new check is the only one that catches them Independent reviewer, not the author. I did not push anything to the branch; the mutations below were made locally, rebuilt, then reverted, and the working tree is clean. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11, commit `e7504862`. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^(startup_bc7_4k_s|startup_bc7_4k_s_x_first_control|startup_xg_bc7_layout|startup_xg_bc7_draw_warp|startup_address_bc_view_warp)$' ``` Unmodified branch — 5 of 5 pass (`startup_bc7_4k_s` 0.17 s, `_x_first_control` 0.02 s, `startup_xg_bc7_layout` 0.47 s, `startup_xg_bc7_draw_warp` 4.93 s, `startup_address_bc_view_warp` 6.05 s). ### Mutation 1 — tile row multiplied by `tile_rows` instead of `tile_columns` ```diff -const auto tile = std::uint64_t{row / tile_blocks} * tile_columns + column / tile_blocks; +const auto tile = std::uint64_t{row / tile_blocks} * tile_rows + column / tile_blocks; ``` ```text 1/5 startup_bc7_4k_s ................... ***Failed startup_bc7_4k_s: 7 FAILED 2/5 startup_bc7_4k_s_x_first_control ... Passed 3/5 startup_xg_bc7_layout .............. Passed 4/5 startup_xg_bc7_draw_warp ........... Passed 5/5 startup_address_bc_view_warp ....... Passed ``` ### Mutation 2 — `desc.Alignment == 0` dropped from `supports_bc7_4k_s` ```diff -desc.SampleDesc.Quality == 0 && desc.Alignment == 0 && desc.Flags +desc.SampleDesc.Quality == 0 && desc.Flags ``` ```text 1/4 startup_bc7_4k_s ................... ***Failed startup_bc7_4k_s: 2 FAILED 2/4 startup_xg_bc7_layout .............. Passed 3/4 startup_xg_bc7_draw_warp ........... Passed 4/4 startup_address_bc_view_warp ....... Passed ``` So the gap you describe is real at this commit: with either mutation the three older checks still pass, and the new device-free check is the one that reports a first mismatch. That is the property I would want from a new fixture, and it is worth having in the log for the reason you give — the existing layout test only sees square tile grids (2x2 and 1x1), and `detile` is exercised by tests that tile with the same `block_offset`. ### Two small notes, neither blocking 1. `startup_bc7_4k_s_x_first_control` stays green under both mutations, which is correct for a control but means a reader skimming the ctest list could take it for coverage of the order. One line in the test's own output naming what it is a control *for* would remove that. 2. If a non-square grid is cheap to add to `startup_xg_bc7_layout`, the order bug would fail the older check too and the new fixture would stop being the sole reporter. Your call — the current split is defensible and the new check is device-free, which is what makes it run everywhere. ### Verdict Reviewed `e7504862`. Builds clean, the new checks pass, both negative controls behave as claimed, and the CMake wiring is two `add_test` lines plus the target. No objection from me.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 12:06 UTC · original · reviewed

Dual-platform peer review at commit e75048628440ab801ffab7ec63d27f63ab4a47b3.

Audit

  • tests/startup_bc7_4k_s_check.cpp, CMakeLists.txt, docs/startup-runtime.md:
    • Independently verifies src/startup_stubs/bc7_4k_s.h (supports_bc7_4k_s, Bc16Surface padded dimensions/sizes, block_offset, and detile) using a table-driven bit-order oracle (y0 y1 x0 x1 y2 x2 y3 x3) and hand-worked offsets without reusing the header's bit shifts.
    • Covers partial/non-square tile grids (200x72, 72x200), 32-bit width truncation (2^32 + 64), 24 single-field refusal cases, pitched detile with 0xa5 guard bands on both ends and row gaps, and a --mutate x-first negative control (startup_bc7_4k_s_x_first_control, WILL_FAIL TRUE).
  • Hygiene & Docs:
    • git diff --check origin/main..HEAD: clean.
    • python3 tests/docs_links_check.py: passed (16 Markdown files, 324 links).
    • python3 tests/bidi_controls_check.py: passed (1186 files).
    • Title-neutrality: clean.

Verification on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_bc7_4k_s_check -- -j 6): 4.14s
    • Test (ctest --preset dev -R '^(startup_bc7_4k_s|startup_bc7_4k_s_x_first_control|startup_xg_bc7_layout|startup_xg_bc7_draw_warp|startup_address_bc_view_warp)$' --parallel 4 --no-tests=error --output-on-failure): 5/5 passed (startup_bc7_4k_s 0.02s, startup_bc7_4k_s_x_first_control 0.02s, startup_xg_bc7_layout 0.16s, startup_xg_bc7_draw_warp 3.13s, startup_address_bc_view_warp 4.05s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_bc7_4k_s_check -- -j 6): 1.56s
    • Test (ctest --preset release -R '^(startup_bc7_4k_s|startup_bc7_4k_s_x_first_control|startup_xg_bc7_layout|startup_xg_bc7_draw_warp|startup_address_bc_view_warp)$' --parallel 4 --no-tests=error --output-on-failure): 5/5 passed (startup_bc7_4k_s 0.02s, startup_bc7_4k_s_x_first_control 0.01s, startup_xg_bc7_layout 0.14s, startup_xg_bc7_draw_warp 3.21s, startup_address_bc_view_warp 4.16s)
**@⁠tedin7** on GitHub · 2026-11-24 12:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1452#pullrequestreview-6038892885) · **reviewed** Dual-platform peer review at commit `e75048628440ab801ffab7ec63d27f63ab4a47b3`. ### Audit - **`tests/startup_bc7_4k_s_check.cpp`, `CMakeLists.txt`, `docs/startup-runtime.md`**: - Independently verifies `src/startup_stubs/bc7_4k_s.h` (`supports_bc7_4k_s`, `Bc16Surface` padded dimensions/sizes, `block_offset`, and `detile`) using a table-driven bit-order oracle (`y0 y1 x0 x1 y2 x2 y3 x3`) and hand-worked offsets without reusing the header's bit shifts. - Covers partial/non-square tile grids (`200x72`, `72x200`), 32-bit width truncation (`2^32 + 64`), 24 single-field refusal cases, pitched `detile` with `0xa5` guard bands on both ends and row gaps, and a `--mutate x-first` negative control (`startup_bc7_4k_s_x_first_control`, `WILL_FAIL TRUE`). - **Hygiene & Docs**: - `git diff --check origin/main..HEAD`: clean. - `python3 tests/docs_links_check.py`: passed (16 Markdown files, 324 links). - `python3 tests/bidi_controls_check.py`: passed (1186 files). - Title-neutrality: clean. ### Verification on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target startup_bc7_4k_s_check -- -j 6`): `4.14s` - Test (`ctest --preset dev -R '^(startup_bc7_4k_s|startup_bc7_4k_s_x_first_control|startup_xg_bc7_layout|startup_xg_bc7_draw_warp|startup_address_bc_view_warp)$' --parallel 4 --no-tests=error --output-on-failure`): **5/5 passed** (`startup_bc7_4k_s` `0.02s`, `startup_bc7_4k_s_x_first_control` `0.02s`, `startup_xg_bc7_layout` `0.16s`, `startup_xg_bc7_draw_warp` `3.13s`, `startup_address_bc_view_warp` `4.05s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target startup_bc7_4k_s_check -- -j 6`): `1.56s` - Test (`ctest --preset release -R '^(startup_bc7_4k_s|startup_bc7_4k_s_x_first_control|startup_xg_bc7_layout|startup_xg_bc7_draw_warp|startup_address_bc_view_warp)$' --parallel 4 --no-tests=error --output-on-failure`): **5/5 passed** (`startup_bc7_4k_s` `0.02s`, `startup_bc7_4k_s_x_first_control` `0.01s`, `startup_xg_bc7_layout` `0.14s`, `startup_xg_bc7_draw_warp` `3.21s`, `startup_address_bc_view_warp` `4.16s`)
This discussion has been locked. Commenting is limited to contributors.
No description provided.