tests: compare XG-style swizzle selection with AMD addrlib #972

Merged
rasptum merged 2 commits from upstream-pr/979 into main 2026-11-23 20:08:31 +00:00
rasptum commented 2026-11-23 19:36:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T19:36:31Z.


Refs #870. This is the XG slice from the claim and the scope note, which R0Y00 accepted at 18:45Z. It is a source-built comparison of XG-style swizzle selection against AMD addrlib. It does not bind a production xg_xs.dll export. It is separate from the #874 configuration work.

These results are AddrLib observations. A match establishes the chosen PC reference behavior only. The Xbox-specific XG selection and its inputs still need separate evidence.

CI will skip this test (77) unless addrlib is present. addrlib is an optional local dependency and is never vendored. To enable it, run python tools/fetch_addrlib.py and then reconfigure. CMake picks up out/deps/mesa/src/amd/addrlib automatically, or you can set -DXBOX2WINDOWS_ADDRLIB_DIR=.... Without addrlib the rest of the build is unchanged.

Inputs (recorded by the test)

  • Reference. AMD addrlib from Mesa src/amd/addrlib, tag mesa-25.1.0, commit 5c142e46f3f6e752ed745fd48912ebb8fad67145. The license is MIT (SPDX header, copyright AMD). I didn't use the GPUOpen PAL copy, because its addrtypes.h has no 64-bit types for MSVC.
  • Profile. Mesa's PC gfx10.3 "navi21" surface-test configuration (ac_fake_hw_db.h at the same tag). The AddrCreate inputs follow Mesa's ac_addrlib_create: chipEngine 0xD, chipFamily 0x8F (NV), chipRevision 0x28, gbAddrConfig 0x444 (NUM_PIPES 4, NUM_PKRS 4), createFlags 0.
  • Selection inputs. These follow Mesa's gfx9_get_preferred_swizzle_mode: ADDR_RSRC_TEX_2D, ADDR_RSRC_LOC_INVIS, 256 B and variable blocks forbidden, one slice, one sample.
  • XG caller shape. From DirectXTex DirectXTexXboxTile.cpp at a8e5dbf (MIT). The caller asks XG with XGComputeOptimalSwizzleMode and stores the result in XG_TEXTURE2D_DESC::SwizzleMode. DirectXTex does not select a mode itself.
  • Proposed desktop policy. The test-only provider maps XG-style bind flags to addrlib flags: texture, plus color, display, depth or unordered access as the bind flags require. A forced-linear request forbids every non-linear block.

Reference table (all ADDR_OK, identical in dev and release)

Request addrlib flags Mode Base alignment
128x128 8_8_8_8, 8 mips, SRV 0x200 SW_64KB_R_X 65,536
1024x1024 8_8_8_8, 11 mips, SRV 0x200 SW_64KB_R_X 65,536
64x64 8, SRV 0x200 SW_4KB_D_X 4,096
16x16 8_8_8_8, SRV 0x200 SW_4KB_D_X 4,096
4096x1 32, SRV 0x200 SW_LINEAR 256
1920x1080 8_8_8_8, RT 0x201 SW_64KB_R_X 65,536
1920x1080 8_8_8_8, display RT 0x221 SW_64KB_R_X 65,536
1920x1080 32, depth 0x202 SW_64KB_Z_X 65,536
512x512 32_32_32_32, 10 mips, UAV 0x600 SW_64KB_R_X 65,536
2048x2048 16, UAV 0x600 SW_64KB_R_X 65,536

Controls

  • Linear fallback. An always-SW_LINEAR provider disagrees on all 9 tiled rows. A first run with placeholder expectations failed every row, so the table check is not vacuous.
  • Forced linear. The 9 colour requests select SW_LINEAR. The depth target is refused with ADDR_INVALIDPARAMS instead of getting a tiled mode.
  • Tiled request. With the linear block forbidden, no request selects SW_LINEAR, including the 4096x1 row.
  • Explicit pitch. A linear 100x64 surface needs a pitch of 128 elements. A pitch of 128 is accepted. A pitch of 129 (misaligned) and a pitch of 64 (tight) return ADDR_INVALIDPARAMS.
  • Mismatched input. The requests don't all select one mode.

Trimmed

This PR has no explicit layout or texel-address assertions, since R0Y00 reported that those already pass locally. My earlier layout and upload caller (D3D12 footprint provider, readback, tight-pitch and linear-fallback layout controls) stays on a local branch, available if wanted.

Tested

  • Commit 8e8bf20 on 185ffbe. main has since moved to 0bcda16; the merge tree is clean, and I didn't rerun on the newer main.
  • Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64. No GPU or debug layer is involved.
  • dev and release full builds passed.
  • In each preset, ctest --preset <p> --no-tests=error -R '^xg_swizzle_select$|desktop_root_signature|era_heap_allocation|offscreen_warp' passed 4/4.
  • Configured without addrlib (-DXBOX2WINDOWS_ADDRLIB_DIR=), xg_swizzle_select builds and reports Skipped (77). I checked this in dev.
  • tests/docs_links_check.py, tests/bidi_controls_check.py and tests/hardware_reports_check.py passed.
  • pr_overlap_check.py --auto found no overlap.
python tools/fetch_addrlib.py
cmake --preset dev
cmake --build --preset dev --target xg_swizzle_select_check
ctest --preset dev --no-tests=error -R '^xg_swizzle_select$' -V

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6567277584 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/979). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T19:36:31Z. --- Refs #870. This is the XG slice from the [claim](https://github.com/R0Y00/Xbox2Windows/issues/870#issuecomment-7109162352) and the [scope note](https://github.com/R0Y00/Xbox2Windows/issues/870#issuecomment-7110293453), which R0Y00 accepted at 18:45Z. It is a source-built comparison of XG-style swizzle selection against AMD addrlib. It does not bind a production `xg_xs.dll` export. It is separate from the #874 configuration work. **These results are AddrLib observations.** A match establishes the chosen PC reference behavior only. The Xbox-specific XG selection and its inputs still need separate evidence. > **CI will skip this test (77) unless addrlib is present.** addrlib is an optional local dependency and is never vendored. To enable it, run `python tools/fetch_addrlib.py` and then reconfigure. CMake picks up `out/deps/mesa/src/amd/addrlib` automatically, or you can set `-DXBOX2WINDOWS_ADDRLIB_DIR=...`. Without addrlib the rest of the build is unchanged. ### Inputs (recorded by the test) - **Reference.** AMD addrlib from Mesa `src/amd/addrlib`, tag `mesa-25.1.0`, commit [`5c142e46f3f6e752ed745fd48912ebb8fad67145`](https://gitlab.freedesktop.org/mesa/mesa/-/tree/5c142e46f3f6e752ed745fd48912ebb8fad67145/src/amd/addrlib). The license is MIT (SPDX header, copyright AMD). I didn't use the GPUOpen PAL copy, because its `addrtypes.h` has no 64-bit types for MSVC. - **Profile.** Mesa's PC gfx10.3 "navi21" surface-test configuration (`ac_fake_hw_db.h` at the same tag). The `AddrCreate` inputs follow Mesa's `ac_addrlib_create`: `chipEngine` 0xD, `chipFamily` 0x8F (NV), `chipRevision` 0x28, `gbAddrConfig` 0x444 (`NUM_PIPES` 4, `NUM_PKRS` 4), `createFlags` 0. - **Selection inputs.** These follow Mesa's `gfx9_get_preferred_swizzle_mode`: `ADDR_RSRC_TEX_2D`, `ADDR_RSRC_LOC_INVIS`, 256 B and variable blocks forbidden, one slice, one sample. - **XG caller shape.** From [DirectXTex `DirectXTexXboxTile.cpp` at a8e5dbf](https://github.com/microsoft/DirectXTex/blob/a8e5dbf42909aeeb9fcf9c2ae399ae3c06737379/Auxiliary/DirectXTexXboxTile.cpp) (MIT). The caller asks XG with `XGComputeOptimalSwizzleMode` and stores the result in `XG_TEXTURE2D_DESC::SwizzleMode`. DirectXTex does not select a mode itself. - **Proposed desktop policy.** The test-only provider maps XG-style bind flags to addrlib flags: texture, plus color, display, depth or unordered access as the bind flags require. A forced-linear request forbids every non-linear block. ### Reference table (all `ADDR_OK`, identical in dev and release) | Request | addrlib flags | Mode | Base alignment | |---|---|---|---| | 128x128 `8_8_8_8`, 8 mips, SRV | 0x200 | `SW_64KB_R_X` | 65,536 | | 1024x1024 `8_8_8_8`, 11 mips, SRV | 0x200 | `SW_64KB_R_X` | 65,536 | | 64x64 `8`, SRV | 0x200 | `SW_4KB_D_X` | 4,096 | | 16x16 `8_8_8_8`, SRV | 0x200 | `SW_4KB_D_X` | 4,096 | | 4096x1 `32`, SRV | 0x200 | `SW_LINEAR` | 256 | | 1920x1080 `8_8_8_8`, RT | 0x201 | `SW_64KB_R_X` | 65,536 | | 1920x1080 `8_8_8_8`, display RT | 0x221 | `SW_64KB_R_X` | 65,536 | | 1920x1080 `32`, depth | 0x202 | `SW_64KB_Z_X` | 65,536 | | 512x512 `32_32_32_32`, 10 mips, UAV | 0x600 | `SW_64KB_R_X` | 65,536 | | 2048x2048 `16`, UAV | 0x600 | `SW_64KB_R_X` | 65,536 | ### Controls - **Linear fallback.** An always-`SW_LINEAR` provider disagrees on all 9 tiled rows. A first run with placeholder expectations failed every row, so the table check is not vacuous. - **Forced linear.** The 9 colour requests select `SW_LINEAR`. The depth target is refused with `ADDR_INVALIDPARAMS` instead of getting a tiled mode. - **Tiled request.** With the linear block forbidden, no request selects `SW_LINEAR`, including the 4096x1 row. - **Explicit pitch.** A linear 100x64 surface needs a pitch of 128 elements. A pitch of 128 is accepted. A pitch of 129 (misaligned) and a pitch of 64 (tight) return `ADDR_INVALIDPARAMS`. - **Mismatched input.** The requests don't all select one mode. ### Trimmed This PR has no explicit layout or texel-address assertions, since R0Y00 reported that those already pass locally. My earlier layout and upload caller (D3D12 footprint provider, readback, tight-pitch and linear-fallback layout controls) stays on a local branch, available if wanted. ### Tested - Commit `8e8bf20` on `185ffbe`. `main` has since moved to `0bcda16`; the merge tree is clean, and I didn't rerun on the newer `main`. - Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64. No GPU or debug layer is involved. - `dev` and `release` full builds passed. - In each preset, `ctest --preset <p> --no-tests=error -R '^xg_swizzle_select$|desktop_root_signature|era_heap_allocation|offscreen_warp'` passed 4/4. - Configured without addrlib (`-DXBOX2WINDOWS_ADDRLIB_DIR=`), `xg_swizzle_select` builds and reports Skipped (77). I checked this in `dev`. - `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `tests/hardware_reports_check.py` passed. - `pr_overlap_check.py --auto` found no overlap. ```powershell python tools/fetch_addrlib.py cmake --preset dev cmake --build --preset dev --target xg_swizzle_select_check ctest --preset dev --no-tests=error -R '^xg_swizzle_select$' -V ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:41 +00:00
R0Y00 commented 2026-11-24 06:49:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:52:24Z.


I fetched the pinned Mesa 5c142e46 and ran the optional test with the real library on Windows. CTest reported 1/1 passed, 0 skips: exact modes and alignments for all ten entries, nine mismatches for the always-linear control, depth refusal when forced linear, and pitch controls. An existing CMake cache kept the optional path empty after the fetch, so 783bb9b documents setting the path explicitly; I reconfigured the old cache with that command and verified it runs. The results describe the PC AddrLib reference.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112228188 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/979#issuecomment-7112228188). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T19:52:24Z. --- I fetched the pinned Mesa 5c142e46 and ran the optional test with the real library on Windows. CTest reported 1/1 passed, 0 skips: exact modes and alignments for all ten entries, nine mismatches for the always-linear control, depth refusal when forced linear, and pitch controls. An existing CMake cache kept the optional path empty after the fetch, so 783bb9b documents setting the path explicitly; I reconfigured the old cache with that command and verified it runs. The results describe the PC AddrLib reference.
Leyukaka commented 2026-11-24 06:49:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-23T20:05:14Z.


Two small points from reading the diff (not built or run here):

  • The linear-fallback control compares a constant (ADDR_SW_LINEAR) with the table's constant modes and never calls addrlib, so it cannot fail unless the table is edited.
  • tools/fetch_addrlib.py pins the commit and checks rev-parse HEAD, but checkout has no --force, so local edits under out/deps/mesa survive a re-run and rev-parse does not see them.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112536209 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/979#issuecomment-7112536209). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-23T20:05:14Z. --- Two small points from reading the diff (not built or run here): - The linear-fallback control compares a constant (`ADDR_SW_LINEAR`) with the table's constant modes and never calls addrlib, so it cannot fail unless the table is edited. - `tools/fetch_addrlib.py` pins the commit and checks `rev-parse HEAD`, but `checkout` has no `--force`, so local edits under `out/deps/mesa` survive a re-run and `rev-parse` does not see them.
rasptum commented 2026-11-24 06:49:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T20:27:54Z.


Thanks @Leyukaka, both points were right. The follow-up is #996:

  • The linear-fallback control now asks addrlib with only the linear block allowed, and it runs through the same table comparison as the provider under test.
  • A new WILL_FAIL CTest, xg_swizzle_select_mutation, swaps that provider in for the provider under test, and the run fails.
  • tools/fetch_addrlib.py now force-checks-out the pin, cleans the dependency checkout, and fails if git status still reports anything.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7113099675 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/979#issuecomment-7113099675). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T20:27:54Z. --- Thanks @Leyukaka, both points were right. The follow-up is #996: - The linear-fallback control now asks addrlib with only the linear block allowed, and it runs through the same table comparison as the provider under test. - A new `WILL_FAIL` CTest, `xg_swizzle_select_mutation`, swaps that provider in for the provider under test, and the run fails. - `tools/fetch_addrlib.py` now force-checks-out the pin, cleans the dependency checkout, and fails if `git status` still reports anything. AI-assisted (Claude Code).
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!972
No description provided.