shader: split shared comparison samplers in the SPIR-V bridge #675

Merged
rwZephyr merged 4 commits from upstream-pr/681 into main 2026-11-22 21:56:10 +00:00
rwZephyr commented 2026-11-22 19:51:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T19:51:14Z.


Advances #670 (lowering and binding change), following the interface agreed in https://github.com/R0Y00/Xbox2Windows/issues/670#issuecomment-7084324877 (host-reserved ordinary binding, proposed in https://github.com/R0Y00/Xbox2Windows/issues/670#issuecomment-7084271313). Refs #670, #656, #218.

Relation to #676

#676 handles the bridge's indexed %samplers table. It keeps ordinary accesses at set 0, binding 1, and moves depth-reference uses to a comparison view at set 3, binding 1. This PR handles a standalone UniformConstant sampler. That is the shape of the #670 reproducer, and #676's pass returns it unchanged. The two passes accept disjoint inputs. Here the comparison sampler stays at its binding and the ordinary uses move to a host-supplied binding, as agreed on #670. If you'd rather standalone samplers follow #676's direction and move the comparison side instead, I can rework it that way.

What changes

When one SPIR-V sampler variable feeds both OpImageSampleDrefExplicitLod and OpImageSampleExplicitLod, pinned SPIRV-Cross declares a SamplerComparisonState and passes it to SampleLevel. DXC then fails with no matching member function for call to 'SampleLevel' (reproducer: https://github.com/R0Y00/Xbox2Windows/issues/670#issuecomment-7084034682).

  • tools/spirv_sampler_split.py is an opt-in pass. The caller supplies a free ordinary-sampler binding (--ordinary-binding N) in the comparison sampler's descriptor set. The comparison sampler keeps its original binding. Only the ordinary uses move to a new UniformConstant sampler at the supplied binding. The pass prints descriptor_set, comparison_binding and ordinary_binding for the host. Modules with no mixed sampler are returned unchanged, so they stay on the existing path.
  • Scope: one GLCompute entry point, with direct, non-array float32 Texture2D sampling at a constant LOD of 0, from a standalone UniformConstant sampler in the entry-point interface. The pass rejects the following with a specific diagnostic: other image forms, any other LOD, an occupied binding, more than one mixed sampler, and a single sampled image used for both kinds.
  • tests/spirv_window/shared_sampler.spvasm is the source-built shared-sampler fixture from the reproducer, with its HLSL source and derivation in the header.
  • offscreen_check --spirv-compare-sampler <dxil> <ordinary register> <reference> binds 2×2 R32_FLOAT SRVs at t0/t1, a point-clamp LESS_EQUAL comparison sampler at s2, a point-clamp ordinary sampler at the given register, and a raw UAV at u4. It compares all 16 output words against the reference.
  • spirv_compare_sampler_{hardware,warp} are registered next to the address-window and ballot bridge tests (skip code 77). The compile-only stage and controls also run in the Linux job.

What the test checks

  1. The unsplit module still produces the original DXC diagnostic.
  2. Controls: an occupied binding is rejected for 2, 3 and 4, both through the API and through the CLI (exit 1, no output written). A nonzero comparison LOD is rejected. An already-separated module is returned unchanged.
  3. The split module (ordinary binding 5) passes spirv-val --target-env vulkan1.2. SPIRV-Cross emits both SampleCmpLevelZero calls on the s2 sampler and SampleLevel on the s5 sampler. DXC compiles it as cs_6_6.
  4. GPU readback: the expected words are 3f800000,00000000,3ec00000 (0.25 ≤ 0.5 passes, 0.75 ≤ 0.5 fails, ordinary sample 0.375), and the other 13 words must stay at the c5c5c5c5 guard value. The ordinary sample serves as the ordinary-sampling control.
  5. Wrong-reference control: a reference that claims the second comparison passed must fail with exactly one mismatch, word=1 expected=3f800000 actual=00000000.

Results

Tested at 26b501dc8ebca80b73e3a736d8b9a0062a7a61f2, rebased onto 5748b02 (#676), with a clean tree.

Test RX 9070 XT WARP
spirv_compare_sampler_* Passed: outputs 3f800000,00000000,3ec00000, 16/16 words; wrong reference 1 mismatch at word 1 Passed: same outputs, 16/16 words; wrong reference 1 mismatch at word 1
spirv_sampler_views_* (#676) Passed Passed
spirv_address_window_* Passed Passed
spirv_ballot_extract_* Passed Passed

8 passed, 0 failed, 0 skipped. The pure-Python checks tests/spirv_window/check.py, plus sampler.py, ballot.py and compare_sampler.py in compile-only mode, tests/docs_links_check.py and tests/bidi_controls_check.py also pass.

Environment:

  • Windows 11 25H2 x64, build 26200.9974
  • AMD Radeon RX 9070 XT (1002:7550), driver 32.0.32029.2010, selected with XBOX2WINDOWS_ADAPTER='RX 9070 XT'
  • WARP: Microsoft Basic Render Driver (1414:008c) 10.0.26100.9818
  • D3D12 debug layer unavailable on both
  • MSVC 19.44.35230, Windows SDK 10.0.26100, CMake 3.31.12, Python 3.12.10
  • SPIRV-Tools v2025.5, SPIRV-Cross 57e4efcc84112abcd426dc5ec248b5339bee04f2, DXC 1.8.2502.8
cmake --preset dev
cmake --build --preset dev --target offscreen_check
$env:XBOX2WINDOWS_ADAPTER = 'RX 9070 XT'
ctest --preset dev --no-tests=error -R '^spirv_' -V

SPIRV-Tools and SPIRV-Cross must be found at configure time, as for the existing bridge tests.

Not covered

  • This covers the public source-built fixture only. I have not measured the effect on the 807-record compute cohort from https://github.com/R0Y00/Xbox2Windows/pull/656#issuecomment-7084115192. The maintainer can rerun that cohort with this pass, using a free ordinary binding chosen per record.
  • The separate CS package WARP readback discrepancy in that comment is unrelated and remains open.
  • Arrays, other formats, nonzero or dynamic LOD, graphics stages and samplers passed through function parameters are rejected, not lowered.
  • This does not touch #671 or #560.

docs/experiments.md has a new section, "Standalone comparison-sampler split in the SPIR-V bridge", placed after the #676 section, with the reproduction command.

AI-assisted. Prepared with an AI coding assistant; all commands were run locally on the hardware above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6546965359 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681). Originally posted by [rwZephyr](https://github.com/rwZephyr) on 2026-11-22T19:51:14Z. --- Advances #670 (lowering and binding change), following the interface agreed in https://github.com/R0Y00/Xbox2Windows/issues/670#issuecomment-7084324877 (host-reserved ordinary binding, proposed in https://github.com/R0Y00/Xbox2Windows/issues/670#issuecomment-7084271313). Refs #670, #656, #218. ## Relation to #676 #676 handles the bridge's indexed `%samplers` table. It keeps ordinary accesses at set 0, binding 1, and moves depth-reference uses to a comparison view at set 3, binding 1. This PR handles a standalone `UniformConstant` sampler. That is the shape of the #670 reproducer, and #676's pass returns it unchanged. The two passes accept disjoint inputs. Here the comparison sampler stays at its binding and the ordinary uses move to a host-supplied binding, as agreed on #670. If you'd rather standalone samplers follow #676's direction and move the comparison side instead, I can rework it that way. ## What changes When one SPIR-V sampler variable feeds both `OpImageSampleDrefExplicitLod` and `OpImageSampleExplicitLod`, pinned SPIRV-Cross declares a `SamplerComparisonState` and passes it to `SampleLevel`. DXC then fails with `no matching member function for call to 'SampleLevel'` (reproducer: https://github.com/R0Y00/Xbox2Windows/issues/670#issuecomment-7084034682). - `tools/spirv_sampler_split.py` is an opt-in pass. The caller supplies a free ordinary-sampler binding (`--ordinary-binding N`) in the comparison sampler's descriptor set. The comparison sampler keeps its original binding. Only the ordinary uses move to a new `UniformConstant` sampler at the supplied binding. The pass prints `descriptor_set`, `comparison_binding` and `ordinary_binding` for the host. Modules with no mixed sampler are returned unchanged, so they stay on the existing path. - Scope: one GLCompute entry point, with direct, non-array float32 `Texture2D` sampling at a constant LOD of 0, from a standalone `UniformConstant` sampler in the entry-point interface. The pass rejects the following with a specific diagnostic: other image forms, any other LOD, an occupied binding, more than one mixed sampler, and a single sampled image used for both kinds. - `tests/spirv_window/shared_sampler.spvasm` is the source-built shared-sampler fixture from the reproducer, with its HLSL source and derivation in the header. - `offscreen_check --spirv-compare-sampler <dxil> <ordinary register> <reference>` binds 2×2 R32_FLOAT SRVs at t0/t1, a point-clamp `LESS_EQUAL` comparison sampler at s2, a point-clamp ordinary sampler at the given register, and a raw UAV at u4. It compares all 16 output words against the reference. - `spirv_compare_sampler_{hardware,warp}` are registered next to the address-window and ballot bridge tests (skip code 77). The compile-only stage and controls also run in the Linux job. ## What the test checks 1. The unsplit module still produces the original DXC diagnostic. 2. Controls: an occupied binding is rejected for 2, 3 and 4, both through the API and through the CLI (exit 1, no output written). A nonzero comparison LOD is rejected. An already-separated module is returned unchanged. 3. The split module (ordinary binding 5) passes `spirv-val --target-env vulkan1.2`. SPIRV-Cross emits both `SampleCmpLevelZero` calls on the s2 sampler and `SampleLevel` on the s5 sampler. DXC compiles it as `cs_6_6`. 4. GPU readback: the expected words are `3f800000,00000000,3ec00000` (0.25 ≤ 0.5 passes, 0.75 ≤ 0.5 fails, ordinary sample 0.375), and the other 13 words must stay at the `c5c5c5c5` guard value. The ordinary sample serves as the ordinary-sampling control. 5. Wrong-reference control: a reference that claims the second comparison passed must fail with exactly one mismatch, `word=1 expected=3f800000 actual=00000000`. ## Results Tested at `26b501dc8ebca80b73e3a736d8b9a0062a7a61f2`, rebased onto `5748b02` (#676), with a clean tree. | Test | RX 9070 XT | WARP | |---|---|---| | `spirv_compare_sampler_*` | Passed: outputs `3f800000,00000000,3ec00000`, 16/16 words; wrong reference 1 mismatch at word 1 | Passed: same outputs, 16/16 words; wrong reference 1 mismatch at word 1 | | `spirv_sampler_views_*` (#676) | Passed | Passed | | `spirv_address_window_*` | Passed | Passed | | `spirv_ballot_extract_*` | Passed | Passed | 8 passed, 0 failed, 0 skipped. The pure-Python checks `tests/spirv_window/check.py`, plus `sampler.py`, `ballot.py` and `compare_sampler.py` in compile-only mode, `tests/docs_links_check.py` and `tests/bidi_controls_check.py` also pass. **Environment:** - Windows 11 25H2 x64, build 26200.9974 - AMD Radeon RX 9070 XT (1002:7550), driver 32.0.32029.2010, selected with `XBOX2WINDOWS_ADAPTER='RX 9070 XT'` - WARP: Microsoft Basic Render Driver (1414:008c) 10.0.26100.9818 - D3D12 debug layer unavailable on both - MSVC 19.44.35230, Windows SDK 10.0.26100, CMake 3.31.12, Python 3.12.10 - SPIRV-Tools v2025.5, SPIRV-Cross 57e4efcc84112abcd426dc5ec248b5339bee04f2, DXC 1.8.2502.8 ```powershell cmake --preset dev cmake --build --preset dev --target offscreen_check $env:XBOX2WINDOWS_ADAPTER = 'RX 9070 XT' ctest --preset dev --no-tests=error -R '^spirv_' -V ``` SPIRV-Tools and SPIRV-Cross must be found at configure time, as for the existing bridge tests. ## Not covered - This covers the public source-built fixture only. I have not measured the effect on the 807-record compute cohort from https://github.com/R0Y00/Xbox2Windows/pull/656#issuecomment-7084115192. The maintainer can rerun that cohort with this pass, using a free ordinary binding chosen per record. - The separate CS package WARP readback discrepancy in that comment is unrelated and remains open. - Arrays, other formats, nonzero or dynamic LOD, graphics stages and samplers passed through function parameters are rejected, not lowered. - This does not touch #671 or #560. `docs/experiments.md` has a new section, "Standalone comparison-sampler split in the SPIR-V bridge", placed after the #676 section, with the reproduction command. _AI-assisted. Prepared with an AI coding assistant; all commands were run locally on the hardware above._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:17 +00:00
R0Y00 commented 2026-11-24 06:44:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:04:19Z.

Review: CHANGES_REQUESTED


The host-reserved binding and keeping the original comparison binding still match #670. One passthrough case needs fixing first. split_comparison_sampler validates every OpSampledImage and requires a direct OpLoad from a standalone sampler before it checks whether a mixed standalone sampler exists. A module with only an indexed sampler-table load (the #676 profile), or with an unrelated ordinary nonzero-LOD sample, raises before reaching if not mixed. Please identify the mixed standalone candidate first, then apply the narrow validation to its uses. Add a byte-for-byte unchanged control for a no-mixed module outside the standalone profile, alongside the existing already-separated test. Keep rejecting unsupported uses of the sampler you actually split.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6014525312 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#pullrequestreview-6014525312). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T21:04:19Z. **Review:** CHANGES_REQUESTED --- The host-reserved binding and keeping the original comparison binding still match #670. One passthrough case needs fixing first. `split_comparison_sampler` validates every `OpSampledImage` and requires a direct `OpLoad` from a standalone sampler before it checks whether a mixed standalone sampler exists. A module with only an indexed sampler-table load (the #676 profile), or with an unrelated ordinary nonzero-LOD sample, raises before reaching `if not mixed`. Please identify the mixed standalone candidate first, then apply the narrow validation to its uses. Add a byte-for-byte unchanged control for a no-mixed module outside the standalone profile, alongside the existing already-separated test. Keep rejecting unsupported uses of the sampler you actually split.
rwZephyr commented 2026-11-24 06:48:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T21:08:36Z.


Thanks, fixed in 33524e3 (new commit on top of 26b501d; history not rewritten).

split_comparison_sampler now works in two steps:

  1. Find the candidate first. A candidate is a sampled image whose sampler is a direct OpLoad of a standalone UniformConstant OpTypeSampler variable, with both comparison and ordinary image uses. Nothing else is judged here. Without a candidate the module is returned byte-for-byte, before the entry-point, decoration or texture checks.
  2. Apply the narrow profile only to the sampler being split. Its only allowed uses are direct loads feeding OpSampledImage. Each of those images must be non-array float32 Texture2D, used by explicit-LOD ordinary or depth-comparison sampling at constant LOD 0, with one kind per sampled image. There must be a single GLCompute entry point, and the sampler must be in the interface. The host-supplied binding must be free.

New controls in tests/spirv_window/compare_sampler.py:

  • Byte-for-byte unchanged: the #676 sampler.spvasm indexed table, both before and after split_sampler_views; a separated module with an unrelated ordinary sample at LOD 0.25; and the existing already-separated module.
  • Still splits: the shared fixture plus an unrelated LOD 0.25 ordinary sample on %plainSampler. That sample is left untouched.
  • Still rejected for the split sampler: occupied bindings 2, 3 and 4; nonzero LOD on the comparison use; nonzero LOD on the ordinary use (new); and a non-load use of the sampler variable (new, an OpCopyObject).

Against the previous code, the indexed-table control raised sampler must be a standalone UniformConstant variable, and the unrelated nonzero-LOD control raised requires a constant LOD of zero. Both pass through now.

ctest --preset dev --no-tests=error -R '^spirv_' -V at 33524e3: 8 passed, 0 failed, 0 skipped. This covers spirv_compare_sampler, spirv_sampler_views, spirv_address_window and spirv_ballot_extract on RX 9070 XT (driver 32.0.32029.2010) and WARP (10.0.26100.9818), Windows 11 build 26200.9974, debug layer unavailable. Readback is unchanged: 3f800000,00000000,3ec00000, all 13 guards intact, and the wrong reference fails only at word 1. The docs-link and bidi checks pass. The branch still merges cleanly with current main (a3cf689).

AI-assisted; run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7085819896 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7085819896). Originally posted by [rwZephyr](https://github.com/rwZephyr) on 2026-11-22T21:08:36Z. --- Thanks, fixed in 33524e3 (new commit on top of 26b501d; history not rewritten). `split_comparison_sampler` now works in two steps: 1. Find the candidate first. A candidate is a sampled image whose sampler is a direct `OpLoad` of a standalone `UniformConstant` `OpTypeSampler` variable, with both comparison and ordinary image uses. Nothing else is judged here. Without a candidate the module is returned byte-for-byte, before the entry-point, decoration or texture checks. 2. Apply the narrow profile only to the sampler being split. Its only allowed uses are direct loads feeding `OpSampledImage`. Each of those images must be non-array float32 `Texture2D`, used by explicit-LOD ordinary or depth-comparison sampling at constant LOD 0, with one kind per sampled image. There must be a single GLCompute entry point, and the sampler must be in the interface. The host-supplied binding must be free. New controls in `tests/spirv_window/compare_sampler.py`: - Byte-for-byte unchanged: the #676 `sampler.spvasm` indexed table, both before and after `split_sampler_views`; a separated module with an unrelated ordinary sample at LOD 0.25; and the existing already-separated module. - Still splits: the shared fixture plus an unrelated LOD 0.25 ordinary sample on `%plainSampler`. That sample is left untouched. - Still rejected for the split sampler: occupied bindings 2, 3 and 4; nonzero LOD on the comparison use; nonzero LOD on the ordinary use (new); and a non-load use of the sampler variable (new, an `OpCopyObject`). Against the previous code, the indexed-table control raised `sampler must be a standalone UniformConstant variable`, and the unrelated nonzero-LOD control raised `requires a constant LOD of zero`. Both pass through now. `ctest --preset dev --no-tests=error -R '^spirv_' -V` at 33524e3: 8 passed, 0 failed, 0 skipped. This covers `spirv_compare_sampler`, `spirv_sampler_views`, `spirv_address_window` and `spirv_ballot_extract` on RX 9070 XT (driver 32.0.32029.2010) and WARP (10.0.26100.9818), Windows 11 build 26200.9974, debug layer unavailable. Readback is unchanged: `3f800000,00000000,3ec00000`, all 13 guards intact, and the wrong reference fails only at word 1. The docs-link and bidi checks pass. The branch still merges cleanly with current main (a3cf689). _AI-assisted; run locally._
rwZephyr commented 2026-11-24 06:48:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T21:12:48Z.


Sorry for the noise: the close/reopen above was an accidental click on "Close with comment" while posting the reply. The PR is still active and ready for re-review at 33524e3.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7085875498 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7085875498). Originally posted by [rwZephyr](https://github.com/rwZephyr) on 2026-11-22T21:12:48Z. --- Sorry for the noise: the close/reopen above was an accidental click on "Close with comment" while posting the reply. The PR is still active and ready for re-review at 33524e3.
R0Y00 commented 2026-11-24 06:48:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:26:23Z.


The new 33524e3 revision addresses my earlier scoping concern. The no-op controls and unrelated nonzero-LOD sample now exercise the intended distinction, and the Linux SPIR-V job runs the new test. The two Windows jobs are green, but their run 45070777810 logs compile compare_sampler.cpp without showing spirv_compare_sampler_warp in CTest. Before merging, please provide the exact-head WARP readback (including the swapped-descriptor control) with the full CTest command and commit, or arrange for that test to run in Windows CI. CI

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086050791 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7086050791). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T21:26:23Z. --- The new `33524e3` revision addresses my earlier scoping concern. The no-op controls and unrelated nonzero-LOD sample now exercise the intended distinction, and the Linux SPIR-V job runs the new test. The two Windows jobs are green, but their run `45070777810` logs compile `compare_sampler.cpp` without showing `spirv_compare_sampler_warp` in CTest. Before merging, please provide the exact-head WARP readback (including the swapped-descriptor control) with the full CTest command and commit, or arrange for that test to run in Windows CI. [CI](https://github.com/R0Y00/Xbox2Windows/actions/runs/45070777810)
rwZephyr commented 2026-11-24 06:48:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T21:30:47Z.


Thanks. Both points are addressed at head 4b10089 (two commits on top of 26b501d; nothing rewritten).

Why Windows CI doesn't run it. The Windows jobs never install SPIRV-Tools or SPIRV-Cross, so the if(SPIRV_WINDOW_AS AND SPIRV_WINDOW_VAL AND SPIRV_WINDOW_CROSS) block in CMakeLists.txt is false there. That's why compare_sampler.cpp compiles but no spirv_* test is registered. This applies equally to the existing spirv_address_window_*, spirv_ballot_extract_* and spirv_sampler_views_* (#676) tests. Getting them into Windows CI means adding a toolchain install to the workflow, which I'd keep out of this PR. I can open a separate one if you want it. Below is the exact-head local readback instead.

Descriptor controls (new in 4b10089). This PR didn't have a swapped-descriptor control before. I've added two, modelled on #676's, each changing one static sampler:

  • comparison-greater: s2 uses GREATER instead of LESS_EQUAL. Only words 0 and 1 may change, and they exchange.
  • ordinary-min-lod1: the ordinary sampler (s5) clamps MinLOD to 1. The value texture now has a 1×1 second mip of 0.625, so only word 2 may change.

Each runs against the baseline reference, where it must report exactly those mismatches, and against its own reference, where all 16 words must match.

Exact-head run. Commit 4b10089fd10512649dc3e134520b2f4170e80044, clean tree. Windows 11 25H2 build 26200.9974, debug layer unavailable. SPIRV-Tools v2025.5, SPIRV-Cross 57e4efcc84112abcd426dc5ec248b5339bee04f2, DXC 1.8.2502.8.

cmake --preset dev
cmake --build --preset dev --target offscreen_check
$env:XBOX2WINDOWS_ADAPTER = 'RX 9070 XT'
ctest --preset dev --no-tests=error -R '^spirv_' -V

Result: 8 passed, 0 failed, 0 skipped (spirv_{address_window,sampler_views,ballot_extract,compare_sampler}_{hardware,warp}). spirv_compare_sampler_warp output, with the test command line left out:

shared and lowered SPIR-V validated; comparison s2, ordinary s5; controls passed
shared-sampler HLSL: DXC rejected SampleLevel as expected
[baseline] backend=warp debug_layer=unavailable
adapter=Microsoft Basic Render Driver vendor=1414 device=008c
driver=10.0.26100.9818
descriptors=baseline outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=0
[wrong reference] backend=warp debug_layer=unavailable
descriptors=baseline outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=1
word=1 expected=3f800000 actual=00000000
[comparison descriptor vs baseline] backend=warp debug_layer=unavailable
descriptors=comparison-greater outputs=00000000,3f800000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=2
word=0 expected=3f800000 actual=00000000
word=1 expected=00000000 actual=3f800000
[comparison descriptor] backend=warp debug_layer=unavailable
descriptors=comparison-greater outputs=00000000,3f800000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=0
[ordinary descriptor vs baseline] backend=warp debug_layer=unavailable
descriptors=ordinary-min-lod1 outputs=3f800000,00000000,3f200000 sampler_registers=s2,s5 compared_words=16 mismatches=1
word=2 expected=3ec00000 actual=3f200000
[ordinary descriptor] backend=warp debug_layer=unavailable
descriptors=ordinary-min-lod1 outputs=3f800000,00000000,3f200000 sampler_registers=s2,s5 compared_words=16 mismatches=0
wrong reference fails only at word 1; s2 changes only words 0-1; s5 changes only word 2

(The adapter and driver lines repeat for each draw; I kept only the first.) spirv_compare_sampler_hardware gave the same six results on AMD Radeon RX 9070 XT (1002:7550), driver 32.0.32029.2010. The docs-link, bidi and tests/spirv_window/*.py compile-only checks pass. The branch merges cleanly with current main (ba329ec).

AI-assisted; run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086105777 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7086105777). Originally posted by [rwZephyr](https://github.com/rwZephyr) on 2026-11-22T21:30:47Z. --- Thanks. Both points are addressed at head `4b10089` (two commits on top of 26b501d; nothing rewritten). **Why Windows CI doesn't run it.** The Windows jobs never install SPIRV-Tools or SPIRV-Cross, so the `if(SPIRV_WINDOW_AS AND SPIRV_WINDOW_VAL AND SPIRV_WINDOW_CROSS)` block in CMakeLists.txt is false there. That's why `compare_sampler.cpp` compiles but no `spirv_*` test is registered. This applies equally to the existing `spirv_address_window_*`, `spirv_ballot_extract_*` and `spirv_sampler_views_*` (#676) tests. Getting them into Windows CI means adding a toolchain install to the workflow, which I'd keep out of this PR. I can open a separate one if you want it. Below is the exact-head local readback instead. **Descriptor controls (new in 4b10089).** This PR didn't have a swapped-descriptor control before. I've added two, modelled on #676's, each changing one static sampler: - `comparison-greater`: s2 uses `GREATER` instead of `LESS_EQUAL`. Only words 0 and 1 may change, and they exchange. - `ordinary-min-lod1`: the ordinary sampler (s5) clamps `MinLOD` to 1. The value texture now has a 1×1 second mip of 0.625, so only word 2 may change. Each runs against the baseline reference, where it must report exactly those mismatches, and against its own reference, where all 16 words must match. **Exact-head run.** Commit `4b10089fd10512649dc3e134520b2f4170e80044`, clean tree. Windows 11 25H2 build 26200.9974, debug layer unavailable. SPIRV-Tools v2025.5, SPIRV-Cross 57e4efcc84112abcd426dc5ec248b5339bee04f2, DXC 1.8.2502.8. ```powershell cmake --preset dev cmake --build --preset dev --target offscreen_check $env:XBOX2WINDOWS_ADAPTER = 'RX 9070 XT' ctest --preset dev --no-tests=error -R '^spirv_' -V ``` Result: 8 passed, 0 failed, 0 skipped (`spirv_{address_window,sampler_views,ballot_extract,compare_sampler}_{hardware,warp}`). `spirv_compare_sampler_warp` output, with the test command line left out: ```text shared and lowered SPIR-V validated; comparison s2, ordinary s5; controls passed shared-sampler HLSL: DXC rejected SampleLevel as expected [baseline] backend=warp debug_layer=unavailable adapter=Microsoft Basic Render Driver vendor=1414 device=008c driver=10.0.26100.9818 descriptors=baseline outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=0 [wrong reference] backend=warp debug_layer=unavailable descriptors=baseline outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=1 word=1 expected=3f800000 actual=00000000 [comparison descriptor vs baseline] backend=warp debug_layer=unavailable descriptors=comparison-greater outputs=00000000,3f800000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=2 word=0 expected=3f800000 actual=00000000 word=1 expected=00000000 actual=3f800000 [comparison descriptor] backend=warp debug_layer=unavailable descriptors=comparison-greater outputs=00000000,3f800000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=0 [ordinary descriptor vs baseline] backend=warp debug_layer=unavailable descriptors=ordinary-min-lod1 outputs=3f800000,00000000,3f200000 sampler_registers=s2,s5 compared_words=16 mismatches=1 word=2 expected=3ec00000 actual=3f200000 [ordinary descriptor] backend=warp debug_layer=unavailable descriptors=ordinary-min-lod1 outputs=3f800000,00000000,3f200000 sampler_registers=s2,s5 compared_words=16 mismatches=0 wrong reference fails only at word 1; s2 changes only words 0-1; s5 changes only word 2 ``` (The adapter and driver lines repeat for each draw; I kept only the first.) `spirv_compare_sampler_hardware` gave the same six results on AMD Radeon RX 9070 XT (1002:7550), driver 32.0.32029.2010. The docs-link, bidi and `tests/spirv_window/*.py` compile-only checks pass. The branch merges cleanly with current main (ba329ec). _AI-assisted; run locally._
rwZephyr commented 2026-11-24 06:48:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T21:36:52Z.


@thepatrickworld thanks for the independent run and the careful reserve. Your run was at 33524e3. The head has since moved to 4b10089 (descriptor controls, see my comment above) and now 6f620f7, which takes up two of your points.

Changed in 6f620f7

  • (a) Implicit descriptor set. Confirmed: with OpDecorate %plainSampler DescriptorSet 0 removed, --ordinary-binding 3 was accepted and produced two samplers at binding 3. The input is already invalid Vulkan SPIR-V (spirv-val reports VUID-StandaloneSpirv-UniformConstant-06677, missing DescriptorSet), but the pass should refuse it rather than add to it. The occupancy loop now uses descriptor_sets.get(variable, 0), and compare_sampler.py has that exact rejection case.
  • Shared sampled image. Pointing the ordinary sample at the comparison's OpSampledImage (%34) was already rejected with "one sampled image is used for both sampling kinds", but nothing tested it. It's now a permanent control.

Left as is, with reasons

  • (b) Binding ≤ 15. The 15 is a limit of the test host (offscreen_check), which uses static samplers s0–s15 for this fixture. It isn't a limit of the pass. D3D12 sampler registers go much higher, and the pass shouldn't encode one harness's range. Out-of-range values are still rejected by the host with an explicit error.
  • (c) Unresolved IDs. A module with an undefined ID is invalid SPIR-V, and spirv-as rejects it before anything is emitted. I'd rather not turn the pass into a validator. In the test and the bridge path, its output is always assembled and validated.
  • Retarget mutation as a permanent case. This is already caught without a GPU. The compile-only stage asserts that the lowered HLSL contains exactly one SampleLevel( call on the sampler declared at register(s5…), and two SampleCmpLevelZero( calls on the one at s2. With your mutation, SampleLevel uses the s2 sampler again, so that assertion fails before DXC runs. The test also checks that the unsplit module is still rejected by DXC.
  • Tests vanish when the tools are missing. Agreed that this is a real gap. As you note, it's the existing pattern for all four spirv_* tests, and Windows CI has no SPIRV-Tools/Cross at all. I've offered R0Y00 a separate PR that installs the tools in Windows CI and registers the tests unconditionally with exit code 77, rather than changing one test here.

Exact-head run at 6f620f7 (clean tree, merges cleanly with main ba329ec). ctest --preset dev --no-tests=error -R '^spirv_' -V: 8 passed, 0 failed, 0 skipped on AMD Radeon RX 9070 XT (driver 32.0.32029.2010) and WARP (10.0.26100.9818), Windows 11 build 26200.9974. The readback, wrong-reference and descriptor-control outputs match those in my previous comment. The docs-link, bidi and compile-only checks pass.

AI-assisted; run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086183357 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7086183357). Originally posted by [rwZephyr](https://github.com/rwZephyr) on 2026-11-22T21:36:52Z. --- @thepatrickworld thanks for the independent run and the careful reserve. Your run was at 33524e3. The head has since moved to `4b10089` (descriptor controls, see my comment above) and now `6f620f7`, which takes up two of your points. **Changed in 6f620f7** - **(a) Implicit descriptor set.** Confirmed: with `OpDecorate %plainSampler DescriptorSet 0` removed, `--ordinary-binding 3` was accepted and produced two samplers at binding 3. The input is already invalid Vulkan SPIR-V (`spirv-val` reports VUID-StandaloneSpirv-UniformConstant-06677, missing DescriptorSet), but the pass should refuse it rather than add to it. The occupancy loop now uses `descriptor_sets.get(variable, 0)`, and `compare_sampler.py` has that exact rejection case. - **Shared sampled image.** Pointing the ordinary sample at the comparison's `OpSampledImage` (`%34`) was already rejected with "one sampled image is used for both sampling kinds", but nothing tested it. It's now a permanent control. **Left as is, with reasons** - **(b) Binding ≤ 15.** The 15 is a limit of the test host (`offscreen_check`), which uses static samplers s0–s15 for this fixture. It isn't a limit of the pass. D3D12 sampler registers go much higher, and the pass shouldn't encode one harness's range. Out-of-range values are still rejected by the host with an explicit error. - **(c) Unresolved IDs.** A module with an undefined ID is invalid SPIR-V, and `spirv-as` rejects it before anything is emitted. I'd rather not turn the pass into a validator. In the test and the bridge path, its output is always assembled and validated. - **Retarget mutation as a permanent case.** This is already caught without a GPU. The compile-only stage asserts that the lowered HLSL contains exactly one `SampleLevel(` call on the sampler declared at `register(s5…)`, and two `SampleCmpLevelZero(` calls on the one at s2. With your mutation, `SampleLevel` uses the s2 sampler again, so that assertion fails before DXC runs. The test also checks that the unsplit module is still rejected by DXC. - **Tests vanish when the tools are missing.** Agreed that this is a real gap. As you note, it's the existing pattern for all four `spirv_*` tests, and Windows CI has no SPIRV-Tools/Cross at all. I've offered R0Y00 a separate PR that installs the tools in Windows CI and registers the tests unconditionally with exit code 77, rather than changing one test here. **Exact-head run at 6f620f7** (clean tree, merges cleanly with main ba329ec). `ctest --preset dev --no-tests=error -R '^spirv_' -V`: 8 passed, 0 failed, 0 skipped on AMD Radeon RX 9070 XT (driver 32.0.32029.2010) and WARP (10.0.26100.9818), Windows 11 build 26200.9974. The readback, wrong-reference and descriptor-control outputs match those in my previous comment. The docs-link, bidi and compile-only checks pass. _AI-assisted; run locally._
thepatrickworld commented 2026-11-24 06:48:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T21:31:44Z.


Verification: #681 shader: split shared comparison samplers in the SPIR-V bridge

Head 33524e3a (two commits: 26b501dc plus the review fix 33524e3a), merged with main.
Eleven files, +653/−1: a new tools/spirv_sampler_split.py, a tests/spirv_window/compare_sampler.py
driver, a compare_sampler.cpp readback, a fixture module and the CI wiring.

What it changes

The #670 fixture binds one sampler used both as SamplerComparisonState and as a plain
SamplerState. DXC refuses the module — SampleLevel has no member on a comparison sampler. The PR
adds a tool that rewrites the module: it keeps the comparison sampler on its binding, clones it onto
an ordinary binding, retargets the non-comparison OpLoad, and leaves every other word alone.

Environment

Windows 11 25H2 (build 26200.9711), MSVC 19.44.35230, DXC 1.9.2602.17, AMD RX 9070 XT
(vendor 1002, device 7550), driver 32.0.32029.2010. Python 3.15.2 in the worktree venv.
Vulkan SDK 1.4.363.1, giving SPIRV-Tools v2026.4 (spirv-as, spirv-val) and spirv-cross.

The SDK was installed for this run. Without it CMake registers zero tests for this PR — see the
reserve. I first measured 26b501dc; the numbers below are from the fixed head 33524e3a, and I also
re-ran the Python probes on both to show what the fix changed.

Commands and output

cmake --preset dev -DINTAKE_PYTHON=<venv>      # PATH includes C:\VulkanSDK\1.4.363.1\Bin
cmake --build --preset dev --parallel 12
set XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT
ctest --preset dev --no-tests=error -R "spirv"
1/8 Test #91: spirv_address_window_hardware ....   Passed    0.69 sec
2/8 Test #92: spirv_sampler_views_hardware .....   Passed    0.47 sec
3/8 Test #93: spirv_ballot_extract_hardware ....   Passed    0.47 sec
4/8 Test #94: spirv_compare_sampler_hardware ...   Passed    0.67 sec
5/8 Test #95: spirv_address_window_warp ........   Passed    0.31 sec
6/8 Test #96: spirv_sampler_views_warp .........   Passed    0.30 sec
7/8 Test #97: spirv_ballot_extract_warp ........   Passed    0.27 sec
8/8 Test #98: spirv_compare_sampler_warp .......   Passed    0.47 sec

100% tests passed out of 8

Verbose run of the new test, hardware backend:

shared and lowered SPIR-V validated; comparison s2, ordinary s5; controls passed
shared-sampler HLSL: DXC rejected SampleLevel as expected
backend=hardware debug_layer=unavailable
outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=0
outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=1
wrong-reference control: exactly one mismatch at word 1

Verbose run of the same test on WARP — this is the exact-head readback R0Y00 asks for before
merging, with the command:

ctest --preset dev -V -R "spirv_compare_sampler_warp"
98: shared and lowered SPIR-V validated; comparison s2, ordinary s5; controls passed
98: shared-sampler HLSL: DXC rejected SampleLevel as expected
98: backend=warp debug_layer=unavailable
98: outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=0
98: outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=1
98: wrong-reference control: exactly one mismatch at word 1
1/1 Test #98: spirv_compare_sampler_warp .......   Passed    0.50 sec

The ordinary sampler is read from s5, the host-supplied binding, not from the comparison one at
s2 — that is what sampler_registers=s2,s5 reports — and the swapped-reference control moves exactly
one word.

So the three claims of the PR hold on this machine: the rewritten module assembles and validates, the
unsplit module is still rejected by DXC for the reason stated, and the GPU readback matches the
reference, with the wrong-reference control producing exactly one mismatch at word 1.

Negative control: I made the split leave the ordinary OpLoad pointing at the comparison sampler
(f"{load} = OpLoad {sampler_type} {PREFIX}" → {sampler}), which is precisely the failure the PR
exists to prevent. Re-run on both heads:

0% tests passed, 1 tests failed out of 1
94 - spirv_compare_sampler_hardware (Failed)

The test does catch a split that does not retarget the load, before and after the review fix.

Before the SDK was installed I also ran the Python half alone (compare_sampler.controls()), which
touches no external binary: mapping correct, an already-separated module returned unchanged with
mapping=None, and all four rejection controls firing.

R0Y00's review, and the fix that answers it

Review 6014525312, CHANGES_REQUESTED at 2026-11-22T21:04Z on 26b501dc: the pass validated every
OpSampledImage — demanding a direct OpLoad from a standalone sampler and a zero LOD — before
checking whether a mixed standalone sampler existed, so a module with nothing to split raised instead
of passing through. I reproduced it on the old head:

separated (no mixed sampler)        -> None
same + an ordinary non-zero LOD     -> raises "%37: OpImageSampleDrefExplicitLod requires a constant LOD of zero"
same + an indexed sampler table     -> raises "%42: sampler must be a standalone UniformConstant variable"

33524e3a rewrites the pass to find the candidate first, then apply the narrow profile to that
sampler's uses only. Re-measured on the new head:

separated (baseline)                  UNCHANGED
+ ordinary non-zero LOD               UNCHANGED
+ indexed sampler table               UNCHANGED
shared (mixed standalone)             SPLIT   {descriptor_set: 0, comparison_binding: 2, ordinary_binding: 5}
shared, binding 3 (occupied)          RAISE   Ordinary sampler binding 3 is occupied in set 0 by %plainSampler

The review is addressed: the three out-of-profile modules now come back byte-for-byte unchanged, the
real case still splits, and the occupancy rejection still fires. 33524e3a also adds the passthrough
controls he asked for in compare_sampler.py, including one where an unrelated non-zero-LOD sample on
another sampler must not block the split. ctest -R spirv is 8/8 on this head.

The reserve: three holes in the split's input validation

These are textual and need no Khronos binary to see. All three were re-measured on 33524e3a: the
review fix does not touch them.

(a) The occupancy check ignores the implicit descriptor set. The loop compares
descriptor_sets.get(variable) == descriptor_set. A variable declared with only OpDecorate %v Binding N — no DescriptorSet, which means set 0 — gives None != 0, so it is invisible. Measured on
the fixture by removing one line (OpDecorate %plainSampler DescriptorSet 0) and passing
--ordinary-binding 3: the tool accepts, and the output contains both

OpDecorate %x2w_plain_sampler Binding 3
OpDecorate %plainSampler       Binding 3

Two samplers on the same (set 0, binding 3). Nothing downstream catches it: a duplicate binding is
not a spirv-val error (it is a Vulkan layout constraint on the host side), so the module still
validates and the mapping handed to the host is wrong. One-line fix: descriptor_sets.get(variable, 0).

(b) No bound on --ordinary-binding. The pass accepts 100 (mapping ordinary_binding=100), while
its only consumer, compare_sampler.cpp:43, refuses anything above 15. The pass's contract is
silent exactly where its single client is strict.

(c) Unresolved ids become "no mixed sampler". Replacing the sampled image of the ordinary use with a
nonexistent %99 yields UNCHANGED — the use is no longer seen, so the sampler no longer looks mixed,
and the fixed pass returns the module as out-of-profile. In one respect the fix makes this harder to
spot: "returned unchanged" is now a legitimate answer, so the outcome alone cannot tell a typo from a
real nothing-to-do. There is no unknown-id control; the only net is spirv-as downstream, which a
default build does not run.

The test disappears instead of skipping. add_test sits inside if(SPIRV_WINDOW_AS AND VAL AND CROSS), so on a machine without the tools the test is not registered at all and ctest reports
success by omission — with them missing, ctest -N -R spirv printed Total Tests: 0. SKIP_RETURN_CODE 77 is unreachable on that path. To be fair, this is a pre-existing pattern: spirv_address_window,
spirv_sampler_views and spirv_ballot_extract are guarded the same way, so this PR adds a fourth
instance rather than the first. The right fix is a shared helper or an unconditional add_test with
the script exiting 77.

Correction to my own first pass: I wrote that only spirv-val could catch a bad rewrite. That is too
pessimistic — (a) and (b) are visible in the text with no binary at all. What genuinely needs the
validator is only that the rewrite is structurally sound (ids defined, section order monotone, one
OpLoad per ordinary OpSampledImage, no duplicated (set, binding) once decorations are explicit).
On this fixture that holds.

What I would add

  • descriptor_sets.get(variable, 0) in the occupancy loop, plus a rejection case built with the
    OpDecorate %plainSampler DescriptorSet 0 line removed.
  • A bound on --ordinary-binding (≤ 15), aligned with compare_sampler.cpp:43.
  • A rejection case for the central safety property, which no test exercises today: point the ordinary
    sample at the comparison OpSampledImage and expect "one sampled image is used for both sampling
    kinds".
  • Register the test unconditionally, exiting 77 when the tools are missing, so the omission shows up
    in ctest -N and in the pass count.
  • Keep my retarget mutation as a permanent case: drop the retarget and the suite should fail on its
    own, without anyone trying it by hand.

What this does not prove

  • Nothing about comparison-sampler filtering beyond the two threshold comparisons at 0.25 and 0.75
    against 0.5.
  • Nothing about wave32 execution: the _warp tests registered by CMake run in the same wave64 backend
    as their _hardware twins, so they mostly prove the suite is adapter-parametrised.
  • Nothing about a module where the comparison sampler is reached from more than one OpLoad, or where
    the ordinary binding lives in a different descriptor set.

AI-assisted; runs executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086118159 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7086118159). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-22T21:31:44Z. --- **Verification: #681 `shader: split shared comparison samplers in the SPIR-V bridge`** Head **`33524e3a`** (two commits: `26b501dc` plus the review fix `33524e3a`), merged with `main`. Eleven files, +653/−1: a new `tools/spirv_sampler_split.py`, a `tests/spirv_window/compare_sampler.py` driver, a `compare_sampler.cpp` readback, a fixture module and the CI wiring. ### What it changes The #670 fixture binds one sampler used both as `SamplerComparisonState` and as a plain `SamplerState`. DXC refuses the module — `SampleLevel` has no member on a comparison sampler. The PR adds a tool that rewrites the module: it keeps the comparison sampler on its binding, clones it onto an ordinary binding, retargets the non-comparison `OpLoad`, and leaves every other word alone. ### Environment Windows 11 25H2 (build 26200.9711), MSVC 19.44.35230, DXC 1.9.2602.17, AMD RX 9070 XT (vendor `1002`, device `7550`), driver 32.0.32029.2010. Python 3.15.2 in the worktree venv. Vulkan SDK **1.4.363.1**, giving SPIRV-Tools **v2026.4** (`spirv-as`, `spirv-val`) and `spirv-cross`. The SDK was installed for this run. Without it CMake registers **zero** tests for this PR — see the reserve. I first measured `26b501dc`; the numbers below are from the fixed head `33524e3a`, and I also re-ran the Python probes on both to show what the fix changed. ### Commands and output ``` cmake --preset dev -DINTAKE_PYTHON=<venv> # PATH includes C:\VulkanSDK\1.4.363.1\Bin cmake --build --preset dev --parallel 12 set XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT ctest --preset dev --no-tests=error -R "spirv" ``` ``` 1/8 Test #91: spirv_address_window_hardware .... Passed 0.69 sec 2/8 Test #92: spirv_sampler_views_hardware ..... Passed 0.47 sec 3/8 Test #93: spirv_ballot_extract_hardware .... Passed 0.47 sec 4/8 Test #94: spirv_compare_sampler_hardware ... Passed 0.67 sec 5/8 Test #95: spirv_address_window_warp ........ Passed 0.31 sec 6/8 Test #96: spirv_sampler_views_warp ......... Passed 0.30 sec 7/8 Test #97: spirv_ballot_extract_warp ........ Passed 0.27 sec 8/8 Test #98: spirv_compare_sampler_warp ....... Passed 0.47 sec 100% tests passed out of 8 ``` Verbose run of the new test, hardware backend: ``` shared and lowered SPIR-V validated; comparison s2, ordinary s5; controls passed shared-sampler HLSL: DXC rejected SampleLevel as expected backend=hardware debug_layer=unavailable outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=0 outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=1 wrong-reference control: exactly one mismatch at word 1 ``` Verbose run of the same test on **WARP** — this is the exact-head readback R0Y00 asks for before merging, with the command: ``` ctest --preset dev -V -R "spirv_compare_sampler_warp" ``` ``` 98: shared and lowered SPIR-V validated; comparison s2, ordinary s5; controls passed 98: shared-sampler HLSL: DXC rejected SampleLevel as expected 98: backend=warp debug_layer=unavailable 98: outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=0 98: outputs=3f800000,00000000,3ec00000 sampler_registers=s2,s5 compared_words=16 mismatches=1 98: wrong-reference control: exactly one mismatch at word 1 1/1 Test #98: spirv_compare_sampler_warp ....... Passed 0.50 sec ``` The ordinary sampler is read from `s5`, the host-supplied binding, not from the comparison one at `s2` — that is what `sampler_registers=s2,s5` reports — and the swapped-reference control moves exactly one word. So the three claims of the PR hold on this machine: the rewritten module assembles and validates, the unsplit module is still rejected by DXC for the reason stated, and the GPU readback matches the reference, with the wrong-reference control producing exactly one mismatch at word 1. Negative control: I made the split leave the ordinary `OpLoad` pointing at the comparison sampler (`f"{load} = OpLoad {sampler_type} {PREFIX}"` → `{sampler}`), which is precisely the failure the PR exists to prevent. Re-run on **both** heads: ``` 0% tests passed, 1 tests failed out of 1 94 - spirv_compare_sampler_hardware (Failed) ``` The test does catch a split that does not retarget the load, before and after the review fix. Before the SDK was installed I also ran the Python half alone (`compare_sampler.controls()`), which touches no external binary: mapping correct, an already-separated module returned unchanged with `mapping=None`, and all four rejection controls firing. ### R0Y00's review, and the fix that answers it Review `6014525312`, `CHANGES_REQUESTED` at 2026-11-22T21:04Z on `26b501dc`: the pass validated every `OpSampledImage` — demanding a direct `OpLoad` from a standalone sampler and a zero LOD — **before** checking whether a mixed standalone sampler existed, so a module with nothing to split raised instead of passing through. I reproduced it on the old head: ``` separated (no mixed sampler) -> None same + an ordinary non-zero LOD -> raises "%37: OpImageSampleDrefExplicitLod requires a constant LOD of zero" same + an indexed sampler table -> raises "%42: sampler must be a standalone UniformConstant variable" ``` `33524e3a` rewrites the pass to find the candidate first, then apply the narrow profile to that sampler's uses only. Re-measured on the new head: ``` separated (baseline) UNCHANGED + ordinary non-zero LOD UNCHANGED + indexed sampler table UNCHANGED shared (mixed standalone) SPLIT {descriptor_set: 0, comparison_binding: 2, ordinary_binding: 5} shared, binding 3 (occupied) RAISE Ordinary sampler binding 3 is occupied in set 0 by %plainSampler ``` The review is addressed: the three out-of-profile modules now come back byte-for-byte unchanged, the real case still splits, and the occupancy rejection still fires. `33524e3a` also adds the passthrough controls he asked for in `compare_sampler.py`, including one where an unrelated non-zero-LOD sample on *another* sampler must not block the split. `ctest -R spirv` is **8/8** on this head. ### The reserve: three holes in the split's input validation These are textual and need no Khronos binary to see. All three were re-measured on `33524e3a`: the review fix does not touch them. `(a) The occupancy check ignores the implicit descriptor set.` The loop compares `descriptor_sets.get(variable) == descriptor_set`. A variable declared with only `OpDecorate %v Binding N` — no `DescriptorSet`, which means set 0 — gives `None != 0`, so it is invisible. Measured on the fixture by removing one line (`OpDecorate %plainSampler DescriptorSet 0`) and passing `--ordinary-binding 3`: the tool **accepts**, and the output contains both ``` OpDecorate %x2w_plain_sampler Binding 3 OpDecorate %plainSampler Binding 3 ``` Two samplers on the same `(set 0, binding 3)`. Nothing downstream catches it: a duplicate binding is not a `spirv-val` error (it is a Vulkan layout constraint on the host side), so the module still validates and the mapping handed to the host is wrong. One-line fix: `descriptor_sets.get(variable, 0)`. `(b) No bound on --ordinary-binding.` The pass accepts `100` (`mapping ordinary_binding=100`), while its only consumer, `compare_sampler.cpp:43`, refuses anything above 15. The pass's contract is silent exactly where its single client is strict. `(c) Unresolved ids become "no mixed sampler".` Replacing the sampled image of the ordinary use with a nonexistent `%99` yields UNCHANGED — the use is no longer seen, so the sampler no longer looks mixed, and the fixed pass returns the module as out-of-profile. In one respect the fix makes this harder to spot: "returned unchanged" is now a legitimate answer, so the outcome alone cannot tell a typo from a real nothing-to-do. There is no unknown-id control; the only net is `spirv-as` downstream, which a default build does not run. `The test disappears instead of skipping.` `add_test` sits inside `if(SPIRV_WINDOW_AS AND VAL AND CROSS)`, so on a machine without the tools the test is not registered at all and `ctest` reports success by omission — with them missing, `ctest -N -R spirv` printed `Total Tests: 0`. `SKIP_RETURN_CODE 77` is unreachable on that path. To be fair, this is a pre-existing pattern: `spirv_address_window`, `spirv_sampler_views` and `spirv_ballot_extract` are guarded the same way, so this PR adds a fourth instance rather than the first. The right fix is a shared helper or an unconditional `add_test` with the script exiting 77. Correction to my own first pass: I wrote that only `spirv-val` could catch a bad rewrite. That is too pessimistic — (a) and (b) are visible in the text with no binary at all. What genuinely needs the validator is only that the rewrite is structurally sound (ids defined, section order monotone, one `OpLoad` per ordinary `OpSampledImage`, no duplicated `(set, binding)` once decorations are explicit). On this fixture that holds. ### What I would add - `descriptor_sets.get(variable, 0)` in the occupancy loop, plus a rejection case built with the `OpDecorate %plainSampler DescriptorSet 0` line removed. - A bound on `--ordinary-binding` (≤ 15), aligned with `compare_sampler.cpp:43`. - A rejection case for the central safety property, which no test exercises today: point the ordinary sample at the comparison `OpSampledImage` and expect "one sampled image is used for both sampling kinds". - Register the test unconditionally, exiting 77 when the tools are missing, so the omission shows up in `ctest -N` and in the pass count. - Keep my retarget mutation as a permanent case: drop the retarget and the suite should fail on its own, without anyone trying it by hand. ### What this does not prove - Nothing about comparison-sampler filtering beyond the two threshold comparisons at 0.25 and 0.75 against 0.5. - Nothing about wave32 execution: the `_warp` tests registered by CMake run in the same wave64 backend as their `_hardware` twins, so they mostly prove the suite is adapter-parametrised. - Nothing about a module where the comparison sampler is reached from more than one `OpLoad`, or where the ordinary binding lives in a different descriptor set. _AI-assisted; runs executed locally._
R0Y00 commented 2026-11-24 06:48:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:55:12Z.


Reviewed 6f620f7372c642b6a50bf38ea8fd52649b86b8b8. The exact-head report satisfies my outstanding Windows check: ctest --preset dev --no-tests=error -R '^spirv_' -V returned 8 passed, 0 failed, 0 skipped across WARP and RX 9070 XT on Windows build 26200.9974. The report confirms the wrong-reference and swapped-descriptor controls still detect a mismatch. The new descriptor-collision and shared-sampled-image rejection controls and no-op scoping tests are in the current patch. The two Windows build jobs and both Linux jobs also passed at this SHA. My requested changes are satisfied. Running the SPIR-V draw tests automatically in Windows CI remains a separate follow-up.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086413027 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7086413027). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T21:55:12Z. --- Reviewed `6f620f7372c642b6a50bf38ea8fd52649b86b8b8`. The [exact-head report](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7086183357) satisfies my outstanding Windows check: `ctest --preset dev --no-tests=error -R '^spirv_' -V` returned 8 passed, 0 failed, 0 skipped across WARP and RX 9070 XT on Windows build 26200.9974. The report confirms the wrong-reference and swapped-descriptor controls still detect a mismatch. The new descriptor-collision and shared-sampled-image rejection controls and no-op scoping tests are in the current patch. The two Windows build jobs and both Linux jobs also passed at this SHA. My requested changes are satisfied. Running the SPIR-V draw tests automatically in Windows CI remains a separate follow-up.
thepatrickworld commented 2026-11-24 06:48:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T21:55:44Z.


Follow-up on 6f620f7 — two corrections on my side, two on the stated reasons

ctest --preset dev -R "spirv" gives 8/8 here too (RX 9070 XT, RDNA4, driver 32.0.32029.2010). The three points below are what remains after re-measuring your answers.

Accepted

  • (a) implicit set 0 — fixed and verified on my side. Dropping OpDecorate %plainSampler DescriptorSet 0 and passing --ordinary-binding 3 now raises Ordinary sampler binding 3 is occupied in set 0 by %plainSampler. Moving the other sampler to set 1 at binding 3 is still accepted, which is correct. OpMemberDecorate is a non-issue as you say.
  • (d) my mutation — you are right, it is caught without a GPU. With the OpLoad left on the comparison sampler the test fails in 0.39 s on assert source.count(f"SampleLevel({ordinary[1]},") == 1, printing SampleLevel(cmpSampler, …). Nothing to add.

(b) I accept the refusal, but not the reason given

compare_sampler.cpp does not use an s0-s15 range. The root signature builds exactly two static samplers:

D3D12_STATIC_SAMPLER_DESC samplers[2]{};
    s.ShaderRegister = comparison ? comparison_register : static_cast<UINT>(ordinary);

The number 15 comes from compare_sampler.cpp:43, which is in this PR — ordinary > 15 → Ordinary sampler register must be 0-15 and differ from s2. That is a circular oracle, inherited from the D3D11 per-stage sampler limit; it is not a D3D12 constraint. So I accept the refusal on the real principle — the pass must not encode its client's policy — but the 15 is your host's own arbitrary cap, untested, and the PR should not present it as a hardware bound.

(c) the premise does not match what the tools do

Measured on this machine:

spirv-as  --target-env vulkan1.2  undef.spvasm  -> RC=0
spirv-val --target-env vulkan1.2  undef.spv     -> RC=1
  error: line 9: ID '5[%5]' has not been defined

spirv-as accepts the undefined id; the safety net is one tool further out. That does not change your conclusion — compare_sampler.py:103-104 runs both with check=True — but the validator is not what you described, and "in the bridge path its output is always assembled and validated" is a promise about code that does not exist yet: the pass has one caller today.

More importantly, the real hole is not id validation. On a module that passes spirv-as and spirv-val:

%c1  = OpCopyObject %ptr %cmpSampler
%41  = OpLoad %type_sampler %c1

the pass prints unchanged: no sampler with mixed uses, spirv-cross emits valueTexture.SampleLevel(cmpSampler, 0.25f.xx, 0.0f), and DXC rejects it with no matching member function for call to 'SampleLevel'. Same with %41 = OpLoad %type_sampler %cmpSampler Aligned 4, because _standalone_sampler requires len(load) == 3.

The one that matters: spirv_sampler_split.py:182

else:
    print("unchanged: no sampler with mixed uses")

The pass cannot know that. It only knows it found no candidate. Those are different statements, and on the modules above the first one is false while the second one is true. This is the line a future bridge caller will read as a green.

Also: spirv_sampler_split.py:25 omits three annotations

ANNOTATIONS = {"OpName", "OpMemberName", "OpDecorate", "OpMemberDecorate", "OpEntryPoint", "OpExecutionMode"}

OpDecorateString, OpMemberDecorateString and OpDecorateId are missing, so they are classified as uses. A module that passes spirv-as and spirv-val with OpDecorateString %cmpSampler UserSemantic "S" fails with %cmpSampler: OpDecorateString uses the sampler; only direct loads are supported — a false rejection that names the wrong cause. DXC emits HlslSemanticGOOGLE on resources in some paths.

(e)

Agreed on a separate PR, and your premise checks out: the windows-2025 runner image has no Vulkan SDK and CMakeLists.txt:453-456 guards registration, so the test does not exist on CI. But a deferral with no owner leaves four spirv_* tests invisible indefinitely.

Four one-line asks before merge

  1. spirv_sampler_split.py:182 — say what the pass knows (no candidate sampler found), not what it cannot know.
  2. spirv_sampler_split.py:25 — add OpDecorateString, OpMemberDecorateString, OpDecorateId, plus a non-regression control.
  3. compare_sampler.py:109-110 — anchor space0 in both regexes. A set-1 module yields register(s5, space1) and matches today, then dies at CreateComputePipelineState because the root signature's static samplers are in space 0. Not reachable with the current fixture (compare_sampler.py:41 asserts descriptor_set == 0), but the assert does not prove what it appears to prove.
  4. A linked issue for (e), referenced here.

None of these widens the pass's profile or asks it to be a validator.

AI-assisted; runs executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086419879 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/681#issuecomment-7086419879). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-22T21:55:44Z. --- **Follow-up on `6f620f7` — two corrections on my side, two on the stated reasons** `ctest --preset dev -R "spirv"` gives **8/8** here too (RX 9070 XT, RDNA4, driver 32.0.32029.2010). The three points below are what remains after re-measuring your answers. ### Accepted - **(a) implicit set 0** — fixed and verified on my side. Dropping `OpDecorate %plainSampler DescriptorSet 0` and passing `--ordinary-binding 3` now raises `Ordinary sampler binding 3 is occupied in set 0 by %plainSampler`. Moving the other sampler to set 1 at binding 3 is still accepted, which is correct. `OpMemberDecorate` is a non-issue as you say. - **(d) my mutation** — you are right, it is caught without a GPU. With the `OpLoad` left on the comparison sampler the test fails in 0.39 s on `assert source.count(f"SampleLevel({ordinary[1]},") == 1`, printing `SampleLevel(cmpSampler, …)`. Nothing to add. ### (b) I accept the refusal, but not the reason given `compare_sampler.cpp` does not use an s0-s15 range. The root signature builds exactly two static samplers: ```cpp D3D12_STATIC_SAMPLER_DESC samplers[2]{}; s.ShaderRegister = comparison ? comparison_register : static_cast<UINT>(ordinary); ``` The number 15 comes from `compare_sampler.cpp:43`, which is in this PR — `ordinary > 15` → `Ordinary sampler register must be 0-15 and differ from s2`. That is a circular oracle, inherited from the D3D11 per-stage sampler limit; it is not a D3D12 constraint. So I accept the refusal on the real principle — the pass must not encode its client's policy — but the 15 is your host's own arbitrary cap, untested, and the PR should not present it as a hardware bound. ### (c) the premise does not match what the tools do Measured on this machine: ``` spirv-as --target-env vulkan1.2 undef.spvasm -> RC=0 spirv-val --target-env vulkan1.2 undef.spv -> RC=1 error: line 9: ID '5[%5]' has not been defined ``` `spirv-as` accepts the undefined id; the safety net is one tool further out. That does not change your conclusion — `compare_sampler.py:103-104` runs both with `check=True` — but the validator is not what you described, and "in the bridge path its output is always assembled and validated" is a promise about code that does not exist yet: the pass has one caller today. More importantly, the real hole is not id validation. On a module that **passes** `spirv-as` and `spirv-val`: ``` %c1 = OpCopyObject %ptr %cmpSampler %41 = OpLoad %type_sampler %c1 ``` the pass prints `unchanged: no sampler with mixed uses`, `spirv-cross` emits `valueTexture.SampleLevel(cmpSampler, 0.25f.xx, 0.0f)`, and DXC rejects it with `no matching member function for call to 'SampleLevel'`. Same with `%41 = OpLoad %type_sampler %cmpSampler Aligned 4`, because `_standalone_sampler` requires `len(load) == 3`. ### The one that matters: `spirv_sampler_split.py:182` ```python else: print("unchanged: no sampler with mixed uses") ``` The pass cannot know that. It only knows it found no candidate. Those are different statements, and on the modules above the first one is false while the second one is true. This is the line a future bridge caller will read as a green. ### Also: `spirv_sampler_split.py:25` omits three annotations ```python ANNOTATIONS = {"OpName", "OpMemberName", "OpDecorate", "OpMemberDecorate", "OpEntryPoint", "OpExecutionMode"} ``` `OpDecorateString`, `OpMemberDecorateString` and `OpDecorateId` are missing, so they are classified as uses. A module that passes `spirv-as` and `spirv-val` with `OpDecorateString %cmpSampler UserSemantic "S"` fails with `%cmpSampler: OpDecorateString uses the sampler; only direct loads are supported` — a false rejection that names the wrong cause. DXC emits `HlslSemanticGOOGLE` on resources in some paths. ### (e) Agreed on a separate PR, and your premise checks out: the `windows-2025` runner image has no Vulkan SDK and `CMakeLists.txt:453-456` guards registration, so the test does not exist on CI. But a deferral with no owner leaves four `spirv_*` tests invisible indefinitely. ### Four one-line asks before merge 1. `spirv_sampler_split.py:182` — say what the pass knows (`no candidate sampler found`), not what it cannot know. 2. `spirv_sampler_split.py:25` — add `OpDecorateString`, `OpMemberDecorateString`, `OpDecorateId`, plus a non-regression control. 3. `compare_sampler.py:109-110` — anchor `space0` in both regexes. A set-1 module yields `register(s5, space1)` and matches today, then dies at `CreateComputePipelineState` because the root signature's static samplers are in space 0. Not reachable with the current fixture (`compare_sampler.py:41` asserts `descriptor_set == 0`), but the assert does not prove what it appears to prove. 4. A linked issue for (e), referenced here. None of these widens the pass's profile or asks it to be a validator. _AI-assisted; runs 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!675
No description provided.