startup: fold s_mov_b32 copies of a constant SGPR so inline samplers translate (Part of #1723) #2700
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2708"
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 tedin7 on 2026-11-26T02:59:47Z.
Part of #1723
What this unblocks: an inline sampler whose words are built by copying a zero register (the way LLVM builds
<0, N, M, 0>) now translates to a static sampler instead of being refused as a descriptor held in an unknown register.Small follow-up to #2319, which folds
s_brev_b32of a known constant; the copy form was still missing.What changed
s_mov_b32 sD, sSwheresSholds a plain known constant now makessDthat constant (same word, same symbolic value), soconst_words()can read the four sampler words. Example:s_mov_b32 s15, 0thens_mov_b32 s12, s15for sampler word 0.The second commit narrows the fold to a plain constant. A register with an unassigned placeholder, a run-time value or a descriptor symbol is not copied as a constant, so a sampler built from run-time words stays refused.
What stays refused
A sampler with any word from a run-time register, a table or the sampler heap; vector or 64-bit moves; copies of non-constant registers.
Tests
tests/startup_inline_sampler_check.py(already registered inCMakeLists.txt):check_copied_constant_sampler(a copied-zero sampler folds to the expectedsmpline),check_copy_only_folds_plain_constants(copies of non-constant symbols are not folded), andcheck_copied_sampler_after_overwrite(a run-time source is refused, a new constant wins). Onorigin/mainthe check fails (descriptor operand s[24:27] holds ('const', 0)); with the change it passes.Verification
python3 -B tests/startup_inline_sampler_check.py: PASS (fails onorigin/main)python3 -B tests/startup_inline_sampler_check.py binary llvm-mc-19: PASS (fixture words assemble to the recorded words)tests/startup_gfx2hlsl_*_check.pyrun with no arguments on this branch and onorigin/main: identical result per script (108 scripts,export_null_drawandmul24_align_drawneed a compiler and renderer and exit 1 on both).a52f1d75e):x2w_pipe.py win2025 2708 --regex startup_inline_sampler: 3/3 passed (controls, warp, hardware). The draw now includes a shader whose sampler word 0 is built in s29 and copied into s24 (it must read the clamped texel with its own sampler and mismatch with the wrap sampler), so a GPU readback depends on the copy fold.cmake --build --preset dev --target offscreen_checkthenctest --preset dev --no-tests=error -R '^startup_inline_sampler' -V.main(no rebase) so it builds on Windows after #2706.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:40:46Z.
@MasterDomino Ready for review on head
a52f1d75e.Independent gate review of the fold (
s_mov_b32copy of a plain constant SGPR): tried a branch-arm sampler word, copies of a run-time/placeholder/descriptor source, a 64-bit pair,vccandm0sources, and two one-line mutations of the fix (drop the plain-constant guard; copy a wrong value). The first set stays refused or unfolded, both mutations failstartup_inline_sampler_check.py.Gap found and closed: only translation controls covered the copy form.
check_drawnow also draws a shader whose sampler word 0 is built ins29and copied intos24; it must read the clamped texel with its own sampler and mismatch with the wrap sampler (wrong-value control). The branch was also merged with currentmain(no rebase, no force) so it builds on Windows after #2706.Verification:
python3 -B tests/startup_inline_sampler_check.pyand... binary llvm-mc-19pass; onorigin/main's translator the check fails.x2w_pipe.py win2025 2708 --patch <diff> --targets offscreen_check --regex startup_inline_sampler: 3/3 passed (controls, warp, hardware).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:40:44Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
a52f1d7ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T05:34:59Z.
Review: CHANGES_REQUESTED
Reviewed head
a52f1d75(21 commits behindmain, merges cleanly).The fold itself looks right:
('const', v)source is copied. The tagged unassigned placeholder,ud, descriptor and unknown sources are not.set_sstill assigns the register at run time.Blocking: this needs a shader-cache revision bump. A register copied from a constant now folds at every later read, so programs that already translated emit different HLSL. For example,
s_mov_b32 s15, 5; s_mov_b32 s12, s15; s_add_u32 s13, s12, 1lowers tos13 = s12 + 0x00000001u;onmainand tos13 = 0x00000005u + 0x00000001u;here. #2319 bumped the revision for the same kind of change (thes_brev_b32fold).Please move to
x2w-startup-shader-19/19cs(main is at 18 / 18cs) in:gfx2hlsl.py(pipeline_key,compute_key);src/startup_stubs/d3d12_draw.inl(revision,compute_revision);docs/startup-runtime.md.Moving the slot-57 mesh key is your call.
Non-blocking:
sD = …write passes every inline-sampler and join check. A case where a join drops the copy's constant and the copy is read afterwards would pin it.check_copy_only_folds_plain_constants, the case commented "A copy after the source was overwritten takes the new value" doesn't overwrite anything.Environment: Windows 11 build 26300; AMD Radeon RX 9070 XT (driver 32.0.32029.2010); WARP 10.0.26100.9818; debug layer on, 0 errors; dev preset.
Runs and mutants:
ctest --preset dev --no-tests=error -R '^startup_inline_sampler|^startup_gfx2hlsl|^startup_image_3d': 256 passed, 0 skipped, 1 failed. The failure isstartup_gfx2hlsl_fma_mix_dispatch_hardware, which fails the same way onmainon this adapter (#2746), so it's unrelated.mainpassed the 114 non-GPU checks.startup_inline_sampler_controls,_warpand_hardware: dropping the plain-constant guard, copying a wrong value, and disabling the fold.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T06:04:16Z.
Review: APPROVED
Approving
2381d5c6; the change request is resolved.x2w-startup-shader-19/19csnow appear ingfx2hlsl.py(pipeline_key,compute_key), ind3d12_draw.inl(revision,compute_revision), in the tests that pin the key, and in the revision note indocs/startup-runtime.md.startup_gfx2hlsl_const_copy_join_checkpins the run-time write. I replayed the mutant that survived my earlier review, keeping the copy's constant symbol but dropping its run-timesD = …write: it now fails with "FAIL: straight line: the copy is still assigned at run time" (exit 1), and passes again once restored.Pure-Python checks at this head, all passing (Windows 11 build 26300):
startup_gfx2hlsl_const_copy_join_checkstartup_inline_sampler_checkstartup_compute_request_offline_checkstartup_gfx2hlsl_fract_checkstartup_gfx2hlsl_buffer_store_checkstartup_shader_cache_key_checkThe GPU results from my earlier review (inline sampler WARP and RX 9070 XT) were at
a52f1d75; the fold itself is unchanged since then. CI is green at this head.AI-assisted; commands listed were executed locally.