shader: split shared comparison samplers in the SPIR-V bridge #675
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/681"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
%samplerstable. 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 standaloneUniformConstantsampler. 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
OpImageSampleDrefExplicitLodandOpImageSampleExplicitLod, pinned SPIRV-Cross declares aSamplerComparisonStateand passes it toSampleLevel. DXC then fails withno matching member function for call to 'SampleLevel'(reproducer: https://github.com/R0Y00/Xbox2Windows/issues/670#issuecomment-7084034682).tools/spirv_sampler_split.pyis 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 newUniformConstantsampler at the supplied binding. The pass printsdescriptor_set,comparison_bindingandordinary_bindingfor the host. Modules with no mixed sampler are returned unchanged, so they stay on the existing path.Texture2Dsampling at a constant LOD of 0, from a standaloneUniformConstantsampler 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.spvasmis 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-clampLESS_EQUALcomparison 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
spirv-val --target-env vulkan1.2. SPIRV-Cross emits bothSampleCmpLevelZerocalls on the s2 sampler andSampleLevelon the s5 sampler. DXC compiles it ascs_6_6.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 thec5c5c5c5guard value. The ordinary sample serves as the ordinary-sampling control.word=1 expected=3f800000 actual=00000000.Results
Tested at
26b501dc8ebca80b73e3a736d8b9a0062a7a61f2, rebased onto5748b02(#676), with a clean tree.spirv_compare_sampler_*3f800000,00000000,3ec00000, 16/16 words; wrong reference 1 mismatch at word 1spirv_sampler_views_*(#676)spirv_address_window_*spirv_ballot_extract_*8 passed, 0 failed, 0 skipped. The pure-Python checks
tests/spirv_window/check.py, plussampler.py,ballot.pyandcompare_sampler.pyin compile-only mode,tests/docs_links_check.pyandtests/bidi_controls_check.pyalso pass.Environment:
XBOX2WINDOWS_ADAPTER='RX 9070 XT'SPIRV-Tools and SPIRV-Cross must be found at configure time, as for the existing bridge tests.
Not covered
docs/experiments.mdhas 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
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_samplervalidates everyOpSampledImageand requires a directOpLoadfrom 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 reachingif 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.Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T21:08:36Z.
Thanks, fixed in
33524e3(new commit on top of26b501d; history not rewritten).split_comparison_samplernow works in two steps:OpLoadof a standaloneUniformConstantOpTypeSamplervariable, 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.OpSampledImage. Each of those images must be non-array float32Texture2D, 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:sampler.spvasmindexed table, both before and aftersplit_sampler_views; a separated module with an unrelated ordinary sample at LOD 0.25; and the existing already-separated module.%plainSampler. That sample is left untouched.OpCopyObject).Against the previous code, the indexed-table control raised
sampler must be a standalone UniformConstant variable, and the unrelated nonzero-LOD control raisedrequires a constant LOD of zero. Both pass through now.ctest --preset dev --no-tests=error -R '^spirv_' -Vat33524e3: 8 passed, 0 failed, 0 skipped. This coversspirv_compare_sampler,spirv_sampler_views,spirv_address_windowandspirv_ballot_extracton 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.
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.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:26:23Z.
The new
33524e3revision 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 run45070777810logs compilecompare_sampler.cppwithout showingspirv_compare_sampler_warpin 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. CIImported 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 of26b501d; 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 whycompare_sampler.cppcompiles but nospirv_*test is registered. This applies equally to the existingspirv_address_window_*,spirv_ballot_extract_*andspirv_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 usesGREATERinstead ofLESS_EQUAL. Only words 0 and 1 may change, and they exchange.ordinary-min-lod1: the ordinary sampler (s5) clampsMinLODto 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.Result: 8 passed, 0 failed, 0 skipped (
spirv_{address_window,sampler_views,ballot_extract,compare_sampler}_{hardware,warp}).spirv_compare_sampler_warpoutput, with the test command line left out:(The adapter and driver lines repeat for each draw; I kept only the first.)
spirv_compare_sampler_hardwaregave the same six results on AMD Radeon RX 9070 XT (1002:7550), driver 32.0.32029.2010. The docs-link, bidi andtests/spirv_window/*.pycompile-only checks pass. The branch merges cleanly with current main (ba329ec).AI-assisted; run locally.
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 to4b10089(descriptor controls, see my comment above) and now6f620f7, which takes up two of your points.Changed in
6f620f7OpDecorate %plainSampler DescriptorSet 0removed,--ordinary-binding 3was accepted and produced two samplers at binding 3. The input is already invalid Vulkan SPIR-V (spirv-valreports VUID-StandaloneSpirv-UniformConstant-06677, missing DescriptorSet), but the pass should refuse it rather than add to it. The occupancy loop now usesdescriptor_sets.get(variable, 0), andcompare_sampler.pyhas that exact rejection case.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
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.spirv-asrejects 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.SampleLevel(call on the sampler declared atregister(s5…), and twoSampleCmpLevelZero(calls on the one at s2. With your mutation,SampleLeveluses the s2 sampler again, so that assertion fails before DXC runs. The test also checks that the unsplit module is still rejected by DXC.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 mainba329ec).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.
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 bridgeHead
33524e3a(two commits:26b501dcplus the review fix33524e3a), merged withmain.Eleven files, +653/−1: a new
tools/spirv_sampler_split.py, atests/spirv_window/compare_sampler.pydriver, a
compare_sampler.cppreadback, a fixture module and the CI wiring.What it changes
The #670 fixture binds one sampler used both as
SamplerComparisonStateand as a plainSamplerState. DXC refuses the module —SampleLevelhas no member on a comparison sampler. The PRadds 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, device7550), 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) andspirv-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 head33524e3a, and I alsore-ran the Python probes on both to show what the fix changed.
Commands and output
Verbose run of the new test, hardware backend:
Verbose run of the same test on WARP — this is the exact-head readback R0Y00 asks for before
merging, with the command:
The ordinary sampler is read from
s5, the host-supplied binding, not from the comparison one ats2— that is whatsampler_registers=s2,s5reports — and the swapped-reference control moves exactlyone 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
OpLoadpointing at the comparison sampler(
f"{load} = OpLoad {sampler_type} {PREFIX}"→{sampler}), which is precisely the failure the PRexists to prevent. Re-run on both heads:
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()), whichtouches 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_REQUESTEDat 2026-11-22T21:04Z on26b501dc: the pass validated everyOpSampledImage— demanding a directOpLoadfrom a standalone sampler and a zero LOD — beforechecking 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:
33524e3arewrites the pass to find the candidate first, then apply the narrow profile to thatsampler's uses only. Re-measured on the new head:
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.
33524e3aalso adds the passthroughcontrols he asked for in
compare_sampler.py, including one where an unrelated non-zero-LOD sample onanother sampler must not block the split.
ctest -R spirvis 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: thereview fix does not touch them.
(a) The occupancy check ignores the implicit descriptor set.The loop comparesdescriptor_sets.get(variable) == descriptor_set. A variable declared with onlyOpDecorate %v Binding N— noDescriptorSet, which means set 0 — givesNone != 0, so it is invisible. Measured onthe fixture by removing one line (
OpDecorate %plainSampler DescriptorSet 0) and passing--ordinary-binding 3: the tool accepts, and the output contains bothTwo samplers on the same
(set 0, binding 3). Nothing downstream catches it: a duplicate binding isnot a
spirv-valerror (it is a Vulkan layout constraint on the host side), so the module stillvalidates 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 accepts100(mapping ordinary_binding=100), whileits only consumer,
compare_sampler.cpp:43, refuses anything above 15. The pass's contract issilent exactly where its single client is strict.
(c) Unresolved ids become "no mixed sampler".Replacing the sampled image of the ordinary use with anonexistent
%99yields 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-asdownstream, which adefault build does not run.
The test disappears instead of skipping.add_testsits insideif(SPIRV_WINDOW_AS AND VAL AND CROSS), so on a machine without the tools the test is not registered at all andctestreportssuccess by omission — with them missing,
ctest -N -R spirvprintedTotal Tests: 0.SKIP_RETURN_CODE 77is unreachable on that path. To be fair, this is a pre-existing pattern:spirv_address_window,spirv_sampler_viewsandspirv_ballot_extractare guarded the same way, so this PR adds a fourthinstance rather than the first. The right fix is a shared helper or an unconditional
add_testwiththe script exiting 77.
Correction to my own first pass: I wrote that only
spirv-valcould catch a bad rewrite. That is toopessimistic — (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
OpLoadper ordinaryOpSampledImage, 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 theOpDecorate %plainSampler DescriptorSet 0line removed.--ordinary-binding(≤ 15), aligned withcompare_sampler.cpp:43.sample at the comparison
OpSampledImageand expect "one sampled image is used for both samplingkinds".
in
ctest -Nand in the pass count.own, without anyone trying it by hand.
What this does not prove
against 0.5.
_warptests registered by CMake run in the same wave64 backendas their
_hardwaretwins, so they mostly prove the suite is adapter-parametrised.OpLoad, or wherethe ordinary binding lives in a different descriptor set.
AI-assisted; runs executed locally.
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_' -Vreturned 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.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 reasonsctest --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
OpDecorate %plainSampler DescriptorSet 0and passing--ordinary-binding 3now raisesOrdinary 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.OpMemberDecorateis a non-issue as you say.OpLoadleft on the comparison sampler the test fails in 0.39 s onassert source.count(f"SampleLevel({ordinary[1]},") == 1, printingSampleLevel(cmpSampler, …). Nothing to add.(b) I accept the refusal, but not the reason given
compare_sampler.cppdoes not use an s0-s15 range. The root signature builds exactly two static samplers: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-asaccepts the undefined id; the safety net is one tool further out. That does not change your conclusion —compare_sampler.py:103-104runs both withcheck=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-asandspirv-val:the pass prints
unchanged: no sampler with mixed uses,spirv-crossemitsvalueTexture.SampleLevel(cmpSampler, 0.25f.xx, 0.0f), and DXC rejects it withno matching member function for call to 'SampleLevel'. Same with%41 = OpLoad %type_sampler %cmpSampler Aligned 4, because_standalone_samplerrequireslen(load) == 3.The one that matters:
spirv_sampler_split.py:182The 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:25omits three annotationsOpDecorateString,OpMemberDecorateStringandOpDecorateIdare missing, so they are classified as uses. A module that passesspirv-asandspirv-valwithOpDecorateString %cmpSampler UserSemantic "S"fails with%cmpSampler: OpDecorateString uses the sampler; only direct loads are supported— a false rejection that names the wrong cause. DXC emitsHlslSemanticGOOGLEon resources in some paths.(e)
Agreed on a separate PR, and your premise checks out: the
windows-2025runner image has no Vulkan SDK andCMakeLists.txt:453-456guards registration, so the test does not exist on CI. But a deferral with no owner leaves fourspirv_*tests invisible indefinitely.Four one-line asks before merge
spirv_sampler_split.py:182— say what the pass knows (no candidate sampler found), not what it cannot know.spirv_sampler_split.py:25— addOpDecorateString,OpMemberDecorateString,OpDecorateId, plus a non-regression control.compare_sampler.py:109-110— anchorspace0in both regexes. A set-1 module yieldsregister(s5, space1)and matches today, then dies atCreateComputePipelineStatebecause the root signature's static samplers are in space 0. Not reachable with the current fixture (compare_sampler.py:41assertsdescriptor_set == 0), but the assert does not prove what it appears to prove.None of these widens the pass's profile or asks it to be a validator.
AI-assisted; runs executed locally.