Skip to content

shader: lower two immutable samplers at uniform explicit-LOD joins - #2970

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
chadhyatt:backport/explicit-lod-sampler-join
Nov 27, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
chadhyatt:backport/explicit-lod-sampler-join

Conversation

@chadhyatt

Copy link
Copy Markdown
Contributor

AI-assisted backport patch from x2w-microlift.

Admit a single proven forward SCC diamond that writes all four words of two immutable normalized 2D point wrap/clamp samplers. Preserve point mip filtering and validated LOD limits in static bindings; choose between complete SampleLevel calls using the differing scalar word. Invalidate the join fact on overlapping writes. Implicit-LOD handling from #2699 is unchanged.

Source-built verification on Apple Silicon, head 656c4dd:

  • python3 -B tests/startup_image_sample_l_join_check.py: both forms, both selector outcomes, swapped bindings, six refusals passed.
  • python3 -B tests/startup_image_sample_l_join_check.py binary llvm-mc: all eight exact assembly variants passed (LLVM 23.1.6).
  • Existing explicit-level, LOD-limit, scalar-join, LOD-query controls, docs links and run_checks_parallel checks passed.

The registered Windows draw uses the actual translated shader, two manifest bindings and a runtime selector. DXC/WARP/hardware draw execution not run locally. Test registrations use the upstream CMake and CI check-list fragments.

Admit a single forward SCC diamond with complete literal definitions of two normalized point samplers, preserve their static LOD limits and choose between complete SampleLevel calls.
Exercise both runtime selector outcomes, swapped bindings, six refusals and all eight authored assembly variants. Register the fixture using upstream test-fragment conventions.
@thepatrickworld

Copy link
Copy Markdown
Contributor

Independent Windows / AMD RDNA 4 result on 656c4ddc — measurements only, not a code change

Environment

  • Windows 10.0.26200.9974; MSVC 19.44.35230.0 (BuildTools 14.44.35207); DXC and FXC from SDK 10.0.26100.0
  • WARP: Microsoft Basic Render Driver vendor 1414 device 008c; hardware: AMD Radeon RX 9070 XT vendor 1002 device 7550, driver 32.0.32029.2010
  • D3D12 debug layer not installed (debug_layer=unavailable), so no validation output is part of this report
  • Clean worktree on 656c4ddc9b0e656707fd865b1fb122b1977bfc0a (git status --porcelain --untracked-files=no empty), cmake --preset dev with an external INTAKE_PYTHON, Total Tests: 2447

Commands

cmake --preset dev "-DINTAKE_PYTHON=…/pe-env/Scripts/python.exe"
cmake --build --preset dev --target offscreen_check
set "XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT"
ctest --preset dev --no-tests=error -R startup_image_sample_l_join -V

Observed

1/3 Test #2425: startup_image_sample_l_join_controls ...   Passed    0.66 sec
2/3 Test #2426: startup_image_sample_l_join_warp .......   Passed    1.68 sec
3/3 Test #2427: startup_image_sample_l_join_hardware ...   Passed    2.15 sec
100% tests passed out of 3

Both draw entries executed (no exit 77, no ***Skipped); the hardware entry prints adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550 and driver=32.0.32029.2010 on all six of its renderer invocations. Readback per form, the third draw of each form being the swapped-binding manifest:

  • l selector 0: 3e840000,00000000,00000000,40000000
  • l selector 1 and swapped: 3e880000,3f800000,00000000,40000000
  • lz selector 0: 3d200000,00000000,3f800000,00000000
  • lz selector 1 and swapped: 3d800000,40400000,3f800000,00000000

The same words come back from WARP and from the card. Three repeat runs of each draw entry gave 100% tests passed out of 1 with byte-identical view_rgba lines.

What these entries pin, and what they do not

  • With the base translator (6ee878d8) and the head tests, all three entries fail with Unsupported: descriptor operand s[24:27] holds None, so the tests do require the new lowering.
  • Both forms differ in word 0 only (arm(0) against arm(CLAMP_XY); word 1 is 0x200000 in both), so k = next(i for i in range(4) if a[i] != b[i]) is forced to 0. A k = 0 mutant emits byte-identical HLSL on both forms (string equality of hlsl_ps() plus the manifest) and all three entries stay green: an equivalent mutant, not a blind spot.
  • A k = 1 mutant is not equivalent — it dies in the controls (AssertionError: ('l', 0)) and in both draws (('l', 0, '3e880000…', '3e840000…')).
  • What stays unpinned is a difference in word 1/2/3 alone: no registered case makes a non-zero k the correct answer. A local, unpushed variant of the l form whose arms differ only in word 1 emits (s25 == 0x00000000u ? … ) and returns mip 1 for selector 0 and mip 0 for selector 1, identically on both adapters, so the choice works today; one such form in the fixture would pin it.
  • Control on the join invalidation: disabling it fails only the controls (AssertionError: overwrite unexpectedly accepted); both draws stay green, which is expected since no draw uses the overwritten form.
  • The join is gated to pixel stages and constant descriptors, so compute and heap samplers never reach it, and none of the six refusal controls covers those two gates.

CI coverage at this head

The three jobs on 656c4ddc are green, and two of the fixture's three modes already run on every pull request: python-linux executes the no-argument controls through tests/checks/python-linux/startup_image_sample_l_join.txt, and the fixture job executes binary llvm-mc-15 through tests/checks/pixel-binary/. What no pull request runs is the draw: none of startup_image_sample_l_join_{controls,warp,hardware} is in the pr test preset (CMakePresets.json, explicit include list), _warp runs only in the post-merge push sweep, and -E '_hardware$' excludes _hardware from every sweep, release included (windows.yml:494 and :614).

Limits

  • One machine, one adapter, no debug layer: nothing here exercises the validation layer.
  • The draw asserts each readback against the fixture's own hardcoded expected texels, and WARP and the AMD driver produced the same bytes that matched them. That is two sampler back-ends agreeing on the same DXC output, not two independent proofs of correctness.
  • Treating MAX_LOD as the field that clamps an explicit LOD is the D3D sampler contract, not something these entries measure: MIN_LOD is zero in every form here, and no fractional or implicit LOD reaches a differing word.
  • No multi-word descriptor difference, no non-zero k, and no compute, heap or packed-2D path is exercised.

AI-assisted.

@chadhyatt

Copy link
Copy Markdown
Contributor Author

Thanks for the exact-head WARP and RX 9070 XT measurements and the explicit limits. The three passing tests and matching readbacks are useful independent evidence. Agreed that a word-1-only descriptor difference should pin nonzero selector-word choice; I will extend that authored fixture without changing the lowering. I will distinguish your physical hardware observations from my local portable verification.

Add the authored explicit-level selector-word-1 variant. Both selectors and swapped manifests exercise distinct mips; all nine gfx1013 sources reassemble exactly with LLVM 15.0.7.
AI-assisted backport patch from x2w-microlift.
@chadhyatt

Copy link
Copy Markdown
Contributor Author

Added the focused test-only follow-up at d908804. Word 0 is identical and word 1 alone differs (MAX_LOD 2 versus 0); selector 0 expects 3e840000000000000000000040000000, selector 1 3d200000000000003f80000000000000, swapped bindings reverse the result. Portable python3 -B tests/startup_image_sample_l_join_check.py passes all three variants, both selectors and six refusals; python3 -B tests/startup_image_sample_l_join_check.py binary <LLVM 15.0.7 llvm-mc> reassembles all nine sources exactly. A throwaway forced-word-0 dispatcher was rejected by the independent pixel oracle. The new registered draw remains unmeasured on my host; prior independent hardware results pertain to 656c4dd, not this new head. No production lowering change.

@Jess-Doit

Copy link
Copy Markdown
Contributor

The join proof, refusal controls, and cache-key pins checked out. I also compiled all three positive cases with FXC at pixel shader model 5.1. Ready to merge from our side

@thepatrickworld

Copy link
Copy Markdown
Contributor

Portable-suite audit of d908804a — controls and mutants only, no draw

Environment

  • Linux host, python3 3.11.16, no GPU and no Windows machine this cycle (my tunnel to the PC was down), so no draw entry ran: no adapter, no driver, no dxc.
  • Fresh blobless clone (git clone --filter=blob:none --no-checkout), then git fetch origin refs/pull/2970/head:pr2970 and git checkout -f pr2970. git rev-parse HEAD = d908804a32f4e01344b5bbfa122011b0d8376475; git status --porcelain --untracked-files=no empty.
  • sha256 with line endings normalised to LF: tests/startup_image_sample_l_join_check.py afc2df447bb78cfa5cc7429d12e6a95b3e58623800425015926e7d25b8df5548, tools/startup/gfx2hlsl.py dbf82d5a80eb768bddd1f800b89da4954166a5dd31ce988c6b53e261eab6947d, .github/workflows/windows.yml d3be662a1ec7c98be71d0bc4bc0a9cd1b1ebe14bb9b72cedd10b21f0d8f1a377.

Commands

python3 -B tests/startup_image_sample_l_join_check.py
# per mutant: edit tools/startup/gfx2hlsl.py, rerun the line above, then
git checkout -- tools/startup/gfx2hlsl.py

After each mutant the translator's sha256 was back to the value above, git status --porcelain --untracked-files=no was empty, and the clean tree re-ran to 0.

Observed

uniform sampler diamond: 3 forms, both selector outcomes, swapped bindings and 6 refusal controls passed

Your forced-word-0 rejection reproduces. Seven mutants of joined_sampler_call (gfx2hlsl.py:2893-2908, line numbers at this head):

Mutant Result
:2903 k = next(i for i in range(4) …) → k = 0 fails in the controls, AssertionError: ('l_word1', 0)
:2903 first differing word → last differing word green
:2905-2906 lod_limits=True → False on both arms fails in sampler_manifest, assert len(lines) == 2 with []
:2904 delete self.used_s.add(base + k) green
:2907 == → != in the emitted call fails as unmodelled dispatcher statement: t = (s24 != 0x00000012u ? …)
:2908 literal taken from the other arm (b[k]) fails at ('l', 0)
:2898 drop or w1 & ~0xffffff green

The runner stops at the first failing form, so the k = 0 mutant only ever reports ('l_word1', 0); selector 1 is not reached.

Three of the seven stay green, and they are not the same kind of result:

  • used_s.add(base + k) is redundant by construction: a pair only exists when both arms define all four words as constants (:3703-3708), and the join then marks every one of those registers used (:3731). Deleting the line cannot change anything, on any input this path admits.
  • k = last differing word instead of first is behaviourally equivalent for the same reason: the descriptor at the join is exactly one of the two arms, so any word in which they differ discriminates correctly. It is not textually equivalent in general — a pair differing in two words would emit a different selector register and literal — but every form in this file differs in one word, so the emitted HLSL and manifest are byte-identical to the base on all three forms.
  • w1 & ~0xffffff survives because no fixture carries a word 1 above 0x200000. This one is a real coverage note, not an equivalent mutant: it is the only check on word 1's upper bits in this path (lod_sampler_words, :7541-7547, validates word 2's low fields, the mip filter and MIN_LOD ≤ MAX_LOD; Pipeline.sampler, :10381-10387, validates nothing), so dropping it silently accepts descriptors those bits reach. No other test builds such a diamond (s_branch BB2 appears in this file only).

Where the new pin lives

  • The l_word1 form is what kills the mutant that was equivalent at 656c4ddc: forcing k = 0 compares word 0, which the new form holds identical in both arms, so one arm could never be taken.
  • Those controls run on every pull request, so this pin is enforced before merge: windows.yml:181 is the python-linux job (ubuntu-24.04, Python 3.12, no job-level if:, and the workflow's pull_request trigger has no paths: filter); it calls tools/run_checks_parallel.py --from-dir tests/checks/python-linux (:199), and tests/checks/python-linux/startup_image_sample_l_join.txt lists the fixture with no arguments, i.e. the no-argument mode.
  • The draw still runs nowhere before merge: the pr test preset is a single allow-list regex of 21 alternatives, none of which matches startup_image_sample_l_join_*, and ctest --preset pr (windows.yml:489) adds no -E. _hardware is excluded only in the push sweeps, dev at :494 and release at :614.

What these forms do not pin

  • Nothing here measures a sampler back end. selected_texel (fixture lines 114-156) re-executes the emitted dispatcher, then models wrap/clamp addressing and the MIN/MAX LOD clamp from the emitted smpl words — the translator's manifest, not the guest descriptor — against hard-coded expected texels. So what the three forms pin is which arm the dispatcher selects and the texel the fixture's own model derives for it; the clamp itself is the fixture's model, not a D3D measurement, and the draw that would measure it did not run.
  • MIN_LOD is 0 in every arm of every form, so only the upper clamp is exercised; a form whose arms differ only in MIN_LOD would cover the lower side the same way.
  • The invalid mode refusal exercises the word-0 clause of unsupported joined sampler words (CLAMP_XY | 0x8000), not the word-1 clause; one refusal control with a bit set above 23 in word 1 would pin that clause.
  • These mutants are mine; the fixture documents its own set (six refusals, both selector outcomes, swapped bindings).

Limits

  • One interpreter (3.11.16) against the 3.12 the CI job uses, no compiler and no renderer part of this run.
  • The equivalent-mutant statements hold for the three forms in this fixture; they are argued from the emitted text and from the join's own preconditions, not from a proof over all admitted inputs.

AI-assisted.

@chadhyatt

Copy link
Copy Markdown
Contributor Author

Thanks for the independent exact-head audit. The upper-word1-bit refusal is the actionable missing control; I am adding a decoded negative diamond for that guard. The equivalent selector mutations do not warrant extra implementation changes. I will report the amended portable and assembler evidence, with prior draw evidence kept separate.

Exercise a decoded sampler diamond whose only invalid field is bit 24 of word 1.
AI-assisted backport patch from x2w-microlift.
@chadhyatt

Copy link
Copy Markdown
Contributor Author

Updated 8697fe9: decoded negative diamond sets only word1 bit 24, so the exact high-bit refusal is now covered. python3 -B tests/startup_image_sample_l_join_check.py passed three forms, both outcomes, swapped bindings and seven refusals; binary mode reassembled all ten variants exactly with LLVM 15.0.7 and 23.1.6. Independently omitting only the word1 guard now fails with high word1 unexpectedly accepted. Fixture/documentation-only amendment; prior draw evidence remains on its original head.

@Jess-Doit

Copy link
Copy Markdown
Contributor

The added upper sampler-word refusal closes the coverage gap. The current head passed three positive forms, seven refusal controls, ten LLVM 15 reassemblies, and the cache-key checks. Removing just the upper-word guard made the new control fail, and restoring it passed. Ready to merge from our side

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 8697fe94dd30ad99e5f6df7192dc3408ccb7918c. The sampler proof requires two literal incoming definitions with uniform SCC control and unchanged EXEC. An overlapping scalar write invalidates the proof. I independently built cmake --build --preset release --target offscreen_check and ran ctest --preset release --no-tests=error -V -R '^startup_image_sample_l_join': 3 passed, zero skips. WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656) on Windows 11 build 26200.9974 both matched all three draw forms, both root-selector values and swapped bindings, with zero D3D12 debug-layer errors or warnings. The portable fixture passed all seven refusals, including the upper sampler-word bit. Required Windows CI passed.

@R0Y00
R0Y00 merged commit fb955a5 into R0Y00:main Nov 27, 2026
5 checks passed
@chadhyatt
chadhyatt deleted the backport/explicit-lod-sampler-join branch November 27, 2026 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants