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

Merged
Asimmimx merged 1 commit from upstream-pr/1452 into main 2026-11-24 12:29:04 +00:00
Asimmimx commented 2026-11-24 11:47:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T11:47:21Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6581054979 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1452). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T11:47:21Z. --- ## 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).
ChazY11 commented 2026-11-24 12:03:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T12:01:15Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130850892 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1452#issuecomment-7130850892). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T12:01:15Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 13:00:31 +00:00
tedin7 commented 2026-11-24 13:00:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:06:49Z.

Review: COMMENTED


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)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038892885 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1452#pullrequestreview-6038892885). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:06:49Z. **Review:** COMMENTED --- 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`)
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!1445
No description provided.