test: check the bc64 chain offsets and address interleave #1683

Merged
ChazY11 merged 1 commit from upstream-pr/1690 into main 2026-11-24 17:24:42 +00:00
ChazY11 commented 2026-11-24 17:09:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T17:09:43Z.


What

tests/startup_bc64_supports_check.cpp referenced x2w_startup::bc64::supports only. The Chain arithmetic in
src/startup_stubs/bc64_chain.h — start(), slice_bytes() and the in-tile bit interleave in address() — had no
assertion in this fixture, and the only other user (xg_swizzle_select_check --bc64-tiling) is gated on the addrlib
source: on this checkout it reports ***Skipped, so in a build without addrlib none of that code is checked at all.

This adds device-free assertions for that arithmetic. No source change and no new target.

How I found it

Removing any of the following from bc64_chain.h left startup_bc64_supports green, with startup_bc64_supports_check.exe
rebuilt each time:

tail{0x8000, ...}            ->  tail{0x4000, ...}          (mip 3 offset)
within |= ((y >> bit) ...)   ->  the same line with x       (axes swapped in the interleave)
for (bit = 2; ...)           ->  for (bit = 3; ...)         (bit-2 term dropped)
slice_bytes(): start(0) +    ->  without start(0)

After the additions all four fail; with the source untouched the fixture passes.

Assertions added

  • the six tail offsets start(3..8) = 0x8000, 0x4000, 0x2000, 0x1000, 0x800, 0x600 for the nine-mip shape;
  • start(mip) == start(mip+1) + tiles_wide(mip+1) * tiles_high(mip+1) * tile_bytes for the whole-tile mips;
  • address(0,1,0,0) - start(0) == 64 and address(0,0,1,0) - start(0) == 16 (the low two bits of each coordinate);
  • address(0,4,0,0) - start(0) == 512 and address(0,0,4,0) - start(0) == 256 (the bit-2 term, which the one-texel
    cases do not reach — this is what catches the two interleave mutants);
  • slice_bytes() == start(0) + tiles_wide(0) * tiles_high(0) * tile_bytes;
  • address(0,0,0,1) == slice_bytes() + start(0).

Tested

cmake --preset dev
cmake --build --preset dev --target startup_bc64_supports_check
ctest --preset dev --no-tests=error -R '^(startup_bc64|xg_bc64)' -V
xg_bc64_tiling_reference ....... ***Skipped   (addrlib not configured here)
startup_bc64_supports .......... Passed
startup_bc64_supports_layout_control ... Passed

bc64 supports: 10 of 26 descriptions accepted, the rest rejected is unchanged, and the --mutate layout control still
reports its expected single failure.

Notes

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587275458 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1690). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T17:09:43Z. --- ## What `tests/startup_bc64_supports_check.cpp` referenced `x2w_startup::bc64::supports` only. The `Chain` arithmetic in `src/startup_stubs/bc64_chain.h` — `start()`, `slice_bytes()` and the in-tile bit interleave in `address()` — had no assertion in this fixture, and the only other user (`xg_swizzle_select_check --bc64-tiling`) is gated on the addrlib source: on this checkout it reports `***Skipped`, so in a build without addrlib none of that code is checked at all. This adds device-free assertions for that arithmetic. No source change and no new target. ## How I found it Removing any of the following from `bc64_chain.h` left `startup_bc64_supports` green, with `startup_bc64_supports_check.exe` rebuilt each time: ```text tail{0x8000, ...} -> tail{0x4000, ...} (mip 3 offset) within |= ((y >> bit) ...) -> the same line with x (axes swapped in the interleave) for (bit = 2; ...) -> for (bit = 3; ...) (bit-2 term dropped) slice_bytes(): start(0) + -> without start(0) ``` After the additions all four fail; with the source untouched the fixture passes. ## Assertions added - the six tail offsets `start(3..8)` = `0x8000, 0x4000, 0x2000, 0x1000, 0x800, 0x600` for the nine-mip shape; - `start(mip) == start(mip+1) + tiles_wide(mip+1) * tiles_high(mip+1) * tile_bytes` for the whole-tile mips; - `address(0,1,0,0) - start(0) == 64` and `address(0,0,1,0) - start(0) == 16` (the low two bits of each coordinate); - `address(0,4,0,0) - start(0) == 512` and `address(0,0,4,0) - start(0) == 256` (the bit-2 term, which the one-texel cases do not reach — this is what catches the two interleave mutants); - `slice_bytes() == start(0) + tiles_wide(0) * tiles_high(0) * tile_bytes`; - `address(0,0,0,1) == slice_bytes() + start(0)`. ## Tested ```powershell cmake --preset dev cmake --build --preset dev --target startup_bc64_supports_check ctest --preset dev --no-tests=error -R '^(startup_bc64|xg_bc64)' -V ``` ```text xg_bc64_tiling_reference ....... ***Skipped (addrlib not configured here) startup_bc64_supports .......... Passed startup_bc64_supports_layout_control ... Passed ``` `bc64 supports: 10 of 26 descriptions accepted, the rest rejected` is unchanged, and the `--mutate layout` control still reports its expected single failure. ## Notes - AI-assisted.
upstream-sync closed this pull request 2026-11-24 18:02:33 +00:00
tedin7 commented 2026-11-24 18:02:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:15:16Z.

Review: COMMENTED


Review of head d81928db9ac7764dd58da93a00a330d8046cb2fc. Only tests/startup_bc64_supports_check.cpp changes (+70/-0); no production code.

Linux limits. Linux x86_64. The test was built with x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextra -static -Isrc and run with wine, not on Windows, not through CTest, not with the project's MSVC or CMake configuration. Native g++ -fsyntax-only cannot be used (no d3d12.h).

What I ran

  • git diff --check origin/main...HEAD: clean. The diff has no non-ASCII bytes and no bidi controls; tests/bidi_controls_check.py and tests/docs_links_check.py pass (no docs touched).
  • MinGW build: no warnings, exit 0. Run under wine: bc64 supports: 10 of 26 descriptions accepted, the rest rejected, exit 0.
  • Every added line checked against src/startup_stubs/bc64_chain.h by hand: tail offsets 0x8000..0x600 match the table; texel (x=1) is +64 and (y=1) is +16 from (y&3)<<4 | (x&3)<<6; coordinate 4 is +512 (x, bit 5+2*2) and +256 (y, bit 4+2*2); slice 1 is slice_bytes() further. No assertion is weakened (additions only, the existing loop and the early if (failures) return 1; are untouched).
  • Mutations on the header, each rebuilt and run, then git checkout -- .:
    • last tail offset 0x600 -> 0x700: FAIL (start(8)).
    • x low shift 6 -> 5: FAIL (x should be +64).
    • x high-bit shift 5+bit*2 -> 6+bit*2: FAIL (+512).
    • slice stride +1: FAIL (slice 1).
    • mip base UINT tiles = 1 -> 2: PASSED (not caught).
    • tile index tiles_wide -> tiles_high in address: PASSED (not caught).

Findings

  • Not caught: the absolute start of mips 0..2. The loop check only compares start(mip) with start(mip+1) plus a step, so a uniform shift of all three stays consistent. A literal expectation for start(2) (one tile, 0x10000) would pin it.
  • Not caught: tile selection. Every probed coordinate is below 64, so address never leaves tile 0; a coordinate such as (64, 0) and (0, 64) on mip 0 would cover tile * tile_bytes.
  • The slice check (slice_bytes() == start(0) + tiles_wide(0)*tiles_high(0)*tile_bytes) and the step loop restate the production formula, so they cannot fail independently of it; the literal tail table, the +64/+16/+512/+256 values and the slice-1 offset are the independent parts.
  • Comments say "texel" but address takes 4x4 block coordinates.

Verdict: sound, test-only, passes everywhere I could run it; the two gaps above are cheap to close. Not approving.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043983116 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1690#pullrequestreview-6043983116). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:15:16Z. **Review:** COMMENTED --- Review of head `d81928db9ac7764dd58da93a00a330d8046cb2fc`. Only `tests/startup_bc64_supports_check.cpp` changes (+70/-0); no production code. **Linux limits.** Linux x86_64. The test was built with `x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextra -static -Isrc` and run with `wine`, not on Windows, not through CTest, not with the project's MSVC or CMake configuration. Native `g++ -fsyntax-only` cannot be used (no `d3d12.h`). **What I ran** - `git diff --check origin/main...HEAD`: clean. The diff has no non-ASCII bytes and no bidi controls; `tests/bidi_controls_check.py` and `tests/docs_links_check.py` pass (no docs touched). - MinGW build: no warnings, exit 0. Run under wine: `bc64 supports: 10 of 26 descriptions accepted, the rest rejected`, exit 0. - Every added line checked against `src/startup_stubs/bc64_chain.h` by hand: tail offsets 0x8000..0x600 match the table; texel (x=1) is +64 and (y=1) is +16 from `(y&3)<<4 | (x&3)<<6`; coordinate 4 is +512 (x, bit `5+2*2`) and +256 (y, bit `4+2*2`); slice 1 is `slice_bytes()` further. No assertion is weakened (additions only, the existing loop and the early `if (failures) return 1;` are untouched). - Mutations on the header, each rebuilt and run, then `git checkout -- .`: - last tail offset 0x600 -> 0x700: FAIL (`start(8)`). - x low shift 6 -> 5: FAIL (x should be +64). - x high-bit shift `5+bit*2` -> `6+bit*2`: FAIL (+512). - slice stride +1: FAIL (slice 1). - mip base `UINT tiles = 1` -> `2`: PASSED (not caught). - tile index `tiles_wide` -> `tiles_high` in `address`: PASSED (not caught). **Findings** - Not caught: the absolute start of mips 0..2. The loop check only compares `start(mip)` with `start(mip+1)` plus a step, so a uniform shift of all three stays consistent. A literal expectation for `start(2)` (one tile, 0x10000) would pin it. - Not caught: tile selection. Every probed coordinate is below 64, so `address` never leaves tile 0; a coordinate such as (64, 0) and (0, 64) on mip 0 would cover `tile * tile_bytes`. - The slice check (`slice_bytes() == start(0) + tiles_wide(0)*tiles_high(0)*tile_bytes`) and the step loop restate the production formula, so they cannot fail independently of it; the literal tail table, the +64/+16/+512/+256 values and the slice-1 offset are the independent parts. - Comments say "texel" but `address` takes 4x4 block coordinates. Verdict: sound, test-only, passes everywhere I could run it; the two gaps above are cheap to close. Not approving. AI-assisted; commands listed were executed locally.
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!1683
No description provided.