gpu: check the desktop sampler contract for CreateSamplerX #1114

Merged
Not-Saii merged 1 commit from upstream-pr/1121 into main 2026-11-24 02:17:53 +00:00
Not-Saii commented 2026-11-24 01:21:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-24T01:21:42Z.


Change

Adds startup_sampler_x, a source-built fixture for the CreateSamplerX desktop sampler contract row in #874. Refs #874, #870.

It checks only the desktop side: the D3D12_SAMPLER_DESC fields a translated sampler must reproduce. It doesn't implement CreateSamplerX or map a console descriptor to a desktop one. The public XCL notes list CreateSamplerX as console device slot #61 with a 0x6C-byte descriptor, but give no field layout, so none is assumed here. The shim and its exports are unchanged.

A cs_6_0 shader makes one SampleLevel call per dispatch through a one-sampler descriptor table. It reads an 8×8 R32_FLOAT texture with four mips, where each texel holds the unique value 2 + 64·mip + 8·y + x.

Sampler Filter AddressU AddressV MinLOD MaxLOD
A MIN_MAG_MIP_POINT WRAP MIRROR 1 2
B MIN_MAG_MIP_POINT CLAMP BORDER (opaque white) 0 0
C MIN_MAG_MIP_LINEAR CLAMP CLAMP 0 unlimited
  • A CPU reference computes every expected value. Point rows must match exactly; linear rows allow a tolerance of 0.01.
  • Probe separation. Before dispatching, the fixture checks that each non-default field of A and B would change at least one probe if it were replaced. It also checks that no linear result can be reproduced by a neighbouring point sample.
  • Negative control. startup_sampler_x_swapped_* writes A and B into each other's descriptor slots and must read back exactly the other sampler's rows. FAIL_REGULAR_EXPRESSION catches a swapped run that did not actually swap.
  • Skips. The tests return 77 if the adapter lacks Shader Model 6.0, or if R32_FLOAT does not report shader sampling with mips.

Overlap: #1091 adds a static sampler inside a root signature. This PR uses only descriptor-table samplers and touches none of its files.

Verification

Tested on base 78a6b31e plus this commit (662b77fd); the branch merges cleanly with current main (32f63f9e). Environment: Windows 11 build 26300.9974, MSVC 19.44.35230.

cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^startup_sampler_x_' -V
Preset RTX 4090 (driver 32.0.16.1088), hardware WARP 10.0.26100.9818
dev (Debug) 2/2 pass, 0 of 21 mismatches 2/2 pass, 0 of 21 mismatches
release 2/2 pass, 0 of 21 mismatches 2/2 pass, 0 of 21 mismatches

Both adapters returned the same values:

  • A: 66,68,68,74,74,76,139,139
  • B: 2,9,2,1,1,1,38,38
  • C: 2.5,6,6.5,34,98

The swapped run returned the A and B rows in reverse order, with C unchanged. No capability skips.

Mutations. Each was a one-line local edit to desktop_sampler(), not committed. Each failed on both adapters:

Mutation First mismatch Mismatches
desc.MinLOD = 0.0f table 0, probe 0: expected 66, got 2 6 of 16 (before sampler C was added)
desc.AddressV = s.u table 0, probe 3: expected 74, got 82 6 of 16
desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT table 2, probe 0: expected 2.5, got 3 5 of 21

The neighbouring tests also pass: offscreen_capability_table_self_test, offscreen_invalid_operation_warp, descriptor_heap_paging_* and descriptor_window_*. 14 of 14 tests passed in Debug. tests/docs_links_check.py and tests/bidi_controls_check.py pass.

Not run: the D3D12 debug layer is not available on this machine, so debug-layer validation was not checked. A retest with Graphics Tools or OFFSCREEN_AGILITY_620_DIR would cover it.

Evidence and follow-up

  • Fixture source. The shader, texture contents and sampler descriptors are written in this PR under MIT. No console or third-party data is used.
  • Measured fields: Filter (point and linear), AddressU, AddressV, BorderColor (opaque white only), MinLOD and MaxLOD.
  • Not measured: AddressW, MipLODBias, comparison functions and other border colours. Anisotropic filtering cannot be measured with SampleLevel, because it supplies no derivatives.
  • Open question for the startup boundary. #870 reports a "projected sampler" created and copied during startup. A sanitized summary of its descriptor size and nonzero fields would show which of these desktop fields a translation must fill.
  • Docs: new section "Desktop sampler contract for CreateSamplerX" in docs/experiments.md.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6572438448 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1121). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-24T01:21:42Z. --- ## Change Adds `startup_sampler_x`, a source-built fixture for the **`CreateSamplerX` desktop sampler contract** row in #874. Refs #874, #870. It checks only the desktop side: the `D3D12_SAMPLER_DESC` fields a translated sampler must reproduce. It doesn't implement `CreateSamplerX` or map a console descriptor to a desktop one. The public XCL notes list `CreateSamplerX` as console device slot #61 with a 0x6C-byte descriptor, but give no field layout, so none is assumed here. The shim and its exports are unchanged. A `cs_6_0` shader makes one `SampleLevel` call per dispatch through a one-sampler descriptor table. It reads an 8×8 `R32_FLOAT` texture with four mips, where each texel holds the unique value `2 + 64·mip + 8·y + x`. | Sampler | Filter | AddressU | AddressV | MinLOD | MaxLOD | |---|---|---|---|---|---| | A | MIN_MAG_MIP_POINT | WRAP | MIRROR | 1 | 2 | | B | MIN_MAG_MIP_POINT | CLAMP | BORDER (opaque white) | 0 | 0 | | C | MIN_MAG_MIP_LINEAR | CLAMP | CLAMP | 0 | unlimited | - A CPU reference computes every expected value. Point rows must match exactly; linear rows allow a tolerance of 0.01. - **Probe separation.** Before dispatching, the fixture checks that each non-default field of A and B would change at least one probe if it were replaced. It also checks that no linear result can be reproduced by a neighbouring point sample. - **Negative control.** `startup_sampler_x_swapped_*` writes A and B into each other's descriptor slots and must read back exactly the other sampler's rows. `FAIL_REGULAR_EXPRESSION` catches a swapped run that did not actually swap. - **Skips.** The tests return 77 if the adapter lacks Shader Model 6.0, or if `R32_FLOAT` does not report shader sampling with mips. Overlap: #1091 adds a static sampler inside a root signature. This PR uses only descriptor-table samplers and touches none of its files. ## Verification Tested on base `78a6b31e` plus this commit (`662b77fd`); the branch merges cleanly with current `main` (`32f63f9e`). Environment: Windows 11 build 26300.9974, MSVC 19.44.35230. ```powershell cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R '^startup_sampler_x_' -V ``` | Preset | RTX 4090 (driver 32.0.16.1088), hardware | WARP 10.0.26100.9818 | |---|---|---| | dev (Debug) | 2/2 pass, 0 of 21 mismatches | 2/2 pass, 0 of 21 mismatches | | release | 2/2 pass, 0 of 21 mismatches | 2/2 pass, 0 of 21 mismatches | Both adapters returned the same values: - A: `66,68,68,74,74,76,139,139` - B: `2,9,2,1,1,1,38,38` - C: `2.5,6,6.5,34,98` The swapped run returned the A and B rows in reverse order, with C unchanged. No capability skips. **Mutations.** Each was a one-line local edit to `desktop_sampler()`, not committed. Each failed on both adapters: | Mutation | First mismatch | Mismatches | |---|---|---| | `desc.MinLOD = 0.0f` | table 0, probe 0: expected 66, got 2 | 6 of 16 (before sampler C was added) | | `desc.AddressV = s.u` | table 0, probe 3: expected 74, got 82 | 6 of 16 | | `desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT` | table 2, probe 0: expected 2.5, got 3 | 5 of 21 | The neighbouring tests also pass: `offscreen_capability_table_self_test`, `offscreen_invalid_operation_warp`, `descriptor_heap_paging_*` and `descriptor_window_*`. 14 of 14 tests passed in Debug. `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. **Not run:** the D3D12 debug layer is not available on this machine, so debug-layer validation was not checked. A retest with Graphics Tools or `OFFSCREEN_AGILITY_620_DIR` would cover it. ## Evidence and follow-up - **Fixture source.** The shader, texture contents and sampler descriptors are written in this PR under MIT. No console or third-party data is used. - **Measured fields:** Filter (point and linear), AddressU, AddressV, BorderColor (opaque white only), MinLOD and MaxLOD. - **Not measured:** AddressW, MipLODBias, comparison functions and other border colours. Anisotropic filtering cannot be measured with `SampleLevel`, because it supplies no derivatives. - **Open question for the startup boundary.** #870 reports a "projected sampler" created and copied during startup. A sanitized summary of its descriptor size and nonzero fields would show which of these desktop fields a translation must fill. - Docs: new section "Desktop sampler contract for `CreateSamplerX`" in `docs/experiments.md`. ## 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). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:46:26 +00:00
tedin7 commented 2026-11-24 06:46:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T02:02:53Z.

Review: COMMENTED


Reviewed at e672bd10cbdcd63cbbd12b812df76e9470aa6ee1 (diff + tests/startup_sampler_x.cpp, tests/startup_sampler_x.hlsl, tests/offscreen_check.cpp, docs/experiments.md).

  • The check_probe_coverage() self-check cleanly verifies that every non-default AddressU/AddressV/MinLOD/MaxLOD field and linear-vs-point result is separated by the probes, and negative wrapping in address() (WRAP/MIRROR) plus the swapped-slot control (FAIL_REGULAR_EXPRESSION) look solid.
  • docs/experiments.md is updated with the exact commands, measured/unmeasured fields, and stays title-neutral.
  • Linux checks run in a detached worktree: python3 -B tests/docs_links_check.py, python3 -B tests/bidi_controls_check.py, python3 -B tests/gpu_report_format_check.py, python3 -B tests/xgameruntime_table_check.py — all passed.
  • Windows MSVC/D3D12/WARP build and startup_sampler_x_* execution were not run locally on this Linux host and rely on CI (currently pending on this head).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6032525743 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1121#pullrequestreview-6032525743). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T02:02:53Z. **Review:** COMMENTED --- Reviewed at `e672bd10cbdcd63cbbd12b812df76e9470aa6ee1` (diff + `tests/startup_sampler_x.cpp`, `tests/startup_sampler_x.hlsl`, `tests/offscreen_check.cpp`, `docs/experiments.md`). - The `check_probe_coverage()` self-check cleanly verifies that every non-default `AddressU`/`AddressV`/`MinLOD`/`MaxLOD` field and linear-vs-point result is separated by the probes, and negative wrapping in `address()` (`WRAP`/`MIRROR`) plus the swapped-slot control (`FAIL_REGULAR_EXPRESSION`) look solid. - `docs/experiments.md` is updated with the exact commands, measured/unmeasured fields, and stays title-neutral. - Linux checks run in a detached worktree: `python3 -B tests/docs_links_check.py`, `python3 -B tests/bidi_controls_check.py`, `python3 -B tests/gpu_report_format_check.py`, `python3 -B tests/xgameruntime_table_check.py` — all passed. - Windows MSVC/D3D12/WARP build and `startup_sampler_x_*` execution were not run locally on this Linux host and rely on CI (currently pending on this head).
Toons29 commented 2026-11-24 06:50:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Toons29 on 2026-11-24T01:37:46Z.


Tested 662b77fd on an AMD Radeon RX 9070 (RDNA 4, 1002:7550), driver 32.0.32029.2010, Windows 11 build 26300, dev preset, debug layer unavailable: pass, as a third vendor next to WARP and RTX

ctest --preset dev --no-tests=error -R '^startup_sampler_x' -V

All four pass (startup_sampler_x_hardware, _swapped_hardware, _warp, _swapped_warp), with no skips, and each reports mismatches=0 of 21.

Table RX 9070 In-box WARP 10.0.26100.9818
0 (A, point) 66,68,68,74,74,76,139,139 same
1 (B, point) 2,9,2,1,1,1,38,38 same
2 (C, linear) 2.5,6,6.5,34,98 same

In the swapped runs, tables 0 and 1 trade places on both adapters, and table 2 is unchanged. The linear row comes out exactly the same on AMD and WARP, so the 0.01 tolerance isn't used here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119290614 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1121#issuecomment-7119290614). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-24T01:37:46Z. --- Tested 662b77fd on an AMD Radeon RX 9070 (RDNA 4, `1002:7550`), driver `32.0.32029.2010`, Windows 11 build 26300, `dev` preset, debug layer unavailable: pass, as a third vendor next to WARP and RTX ```powershell ctest --preset dev --no-tests=error -R '^startup_sampler_x' -V ``` All four pass (`startup_sampler_x_hardware`, `_swapped_hardware`, `_warp`, `_swapped_warp`), with no skips, and each reports `mismatches=0 of 21`. | Table | RX 9070 | In-box WARP `10.0.26100.9818` | |---|---|---| | 0 (A, point) | `66,68,68,74,74,76,139,139` | same | | 1 (B, point) | `2,9,2,1,1,1,38,38` | same | | 2 (C, linear) | `2.5,6,6.5,34,98` | same | In the swapped runs, tables 0 and 1 trade places on both adapters, and table 2 is unchanged. The linear row comes out exactly the same on AMD and WARP, so the 0.01 tolerance isn't used here.
ChazY11 commented 2026-11-24 06:50:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T01:46:40Z.


Independent verification on three backends, including an Intel Xe2 adapter

Reviewed 662b77fd (your head, based on 78a6b31e; GitHub reports the PR mergeable against current main).
Independent reviewer, not the author — I did not touch the branch, and I report only what I ran.

Environment: Windows 11 build 26300.9974, x64, Core Ultra 9 285H; MSVC 14.44.35207, Windows SDK 10.0.26100,
DXC 1.8.2502.11, CMake+Ninja from the VS component, Python 3.12.10. Debug layer enabled in every run and the fixture
printed zero debug warnings and errors.

cmake --preset dev
cmake --build --preset dev                       # no FAILED target
ctest --preset dev --no-tests=error -R 'sampler_x'
adapter driver startup_sampler_x _swapped _warp _swapped_warp
NVIDIA RTX 5080 Laptop (10de:2c59) 32.0.15.8142 pass pass pass pass
Intel Arc 140T (8086:7d51) 32.0.101.8132 pass pass pass pass
Microsoft Basic Render Driver (WARP) 10.0.26100.9818 pass pass pass pass

Hardware runs used XBOX2WINDOWS_ADAPTER=NVIDIA and =Intel; WARP runs take the in-box adapter. Both swapped
variants passed on every adapter, so the AddressU/AddressV/MinLOD separation controls you built trip as intended
rather than merely not being exercised.

Regression on the same build, because the change touches tests/offscreen_check.cpp and tests/desktop_gpu.h:

ctest --preset dev --no-tests=error -R 'desktop_root_signature|era_heap_allocation|offscreen_warp'   -> 3/3 pass
ctest --preset dev --no-tests=error -R '^desktop_'                                                  -> 3/3 pass

Fixture provenance, as a reviewer has to check: the diff is CMakeLists.txt, docs/experiments.md,
tests/desktop_gpu.h, tests/offscreen_check.cpp, tests/startup_sampler_x.cpp, tests/startup_sampler_x.hlsl —
source only, no game data, dumps or distribution links, and the texture contents are computed in texel_value.

One caveat worth recording, not a defect in this change

startup_sampler_x.cpp says "Point probes use integer LODs, so nearest-mip rounding is not exercised", and the Arc
run confirms it: on this adapter a MinLOD clamp rounds down where the RTX and WARP round to the nearest mip
(1.5625 reads mip 1 on the Arc, mip 2 on the other two; 19-clamp table in
#809). Your probe LODs land on exact values after the clamp, so
both rules agree and the fixture is immune.

If a later case adds a fractional LOD under a MinLOD clamp, the reference's mip = static_cast<UINT>(lod) would then
disagree with this adapter, and the case would fail for a reason that has nothing to do with the sampler contract this
fixture is measuring. Deriving the expected mip from one measured probe, or keeping fractional-LOD cases out of this
fixture, keeps that from looking like a CreateSamplerX regression later.

Verdict

Verified, no objection from me. The desktop-side scope is stated honestly in your description (no console descriptor
layout assumed, no shim change), the fixture is deterministic on all three adapters here, and the negative controls
hold.

Happy to re-run on the same machine after a rebase; the only thing I could not check is the console side, which this
change does not claim to implement.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119436762 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1121#issuecomment-7119436762). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T01:46:40Z. --- ## Independent verification on three backends, including an Intel Xe2 adapter Reviewed `662b77fd` (your head, based on `78a6b31e`; GitHub reports the PR mergeable against current `main`). Independent reviewer, not the author — I did not touch the branch, and I report only what I ran. Environment: Windows 11 build 26300.9974, x64, Core Ultra 9 285H; MSVC 14.44.35207, Windows SDK 10.0.26100, DXC 1.8.2502.11, CMake+Ninja from the VS component, Python 3.12.10. Debug layer enabled in every run and the fixture printed zero debug warnings and errors. ```powershell cmake --preset dev cmake --build --preset dev # no FAILED target ctest --preset dev --no-tests=error -R 'sampler_x' ``` | adapter | driver | `startup_sampler_x` | `_swapped` | `_warp` | `_swapped_warp` | |---|---|---|---|---|---| | NVIDIA RTX 5080 Laptop (10de:2c59) | 32.0.15.8142 | pass | pass | pass | pass | | Intel Arc 140T (8086:7d51) | 32.0.101.8132 | pass | pass | pass | pass | | Microsoft Basic Render Driver (WARP) | 10.0.26100.9818 | pass | pass | pass | pass | Hardware runs used `XBOX2WINDOWS_ADAPTER=NVIDIA` and `=Intel`; WARP runs take the in-box adapter. Both `swapped` variants passed on every adapter, so the AddressU/AddressV/MinLOD separation controls you built trip as intended rather than merely not being exercised. Regression on the same build, because the change touches `tests/offscreen_check.cpp` and `tests/desktop_gpu.h`: ```text ctest --preset dev --no-tests=error -R 'desktop_root_signature|era_heap_allocation|offscreen_warp' -> 3/3 pass ctest --preset dev --no-tests=error -R '^desktop_' -> 3/3 pass ``` Fixture provenance, as a reviewer has to check: the diff is `CMakeLists.txt`, `docs/experiments.md`, `tests/desktop_gpu.h`, `tests/offscreen_check.cpp`, `tests/startup_sampler_x.cpp`, `tests/startup_sampler_x.hlsl` — source only, no game data, dumps or distribution links, and the texture contents are computed in `texel_value`. ### One caveat worth recording, not a defect in this change `startup_sampler_x.cpp` says "Point probes use integer LODs, so nearest-mip rounding is not exercised", and the Arc run confirms it: on this adapter a `MinLOD` clamp rounds **down** where the RTX and WARP round to the nearest mip (`1.5625` reads mip 1 on the Arc, mip 2 on the other two; 19-clamp table in [#809](https://github.com/R0Y00/Xbox2Windows/issues/809)). Your probe LODs land on exact values after the clamp, so both rules agree and the fixture is immune. If a later case adds a fractional LOD under a `MinLOD` clamp, the reference's `mip = static_cast<UINT>(lod)` would then disagree with this adapter, and the case would fail for a reason that has nothing to do with the sampler contract this fixture is measuring. Deriving the expected mip from one measured probe, or keeping fractional-LOD cases out of this fixture, keeps that from looking like a `CreateSamplerX` regression later. ### Verdict Verified, no objection from me. The desktop-side scope is stated honestly in your description (no console descriptor layout assumed, no shim change), the fixture is deterministic on all three adapters here, and the negative controls hold. Happy to re-run on the same machine after a rebase; the only thing I could not check is the console side, which this change does not claim to implement.
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!1114
No description provided.