Repository navigation
startup: fold s_mov_b32 copies of a constant SGPR so inline samplers translate (Part of #1723) - #2708
Conversation
…plers translate llc builds a zero sampler as s_mov_b32 s15, 0 then s_mov_b32 s12, s15. The copy kept no symbol, so the sampler operand held None and the shader was refused. The copy now keeps the constant. Extends startup_inline_sampler_check with a copied-constant sampler control. (cherry picked from commit da03456187fe80e5bf53c800f32766df5cb02504)
…ed samplers Do not fold a copy of the tagged unassigned placeholder. Tests: placeholder copy, run-time source and a copy after the source was rewritten must not fold. (cherry picked from commit cbd9717507808d3110e71c3e5e3cd735b23d27e8)
…trol check_draw now also draws 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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
|
@MasterDomino Ready for review on head a52f1d7. Independent gate review of the fold ( Gap found and closed: only translation controls covered the copy form. Verification:
AI-assisted; commands listed were executed locally. |
MasterDomino
left a comment
There was a problem hiding this comment.
Reviewed head a52f1d75 (21 commits behind main, merges cleanly).
The fold itself looks right:
- Only a plain
('const', v)source is copied. The tagged unassigned placeholder,ud, descriptor and unknown sources are not. - The value is copied at that point, so a later write to the source can't reach the copy.
set_sstill assigns the register at run time.- At a join, the copy's constant is dropped exactly as a literal move's would be.
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, 1 lowers to s13 = s12 + 0x00000001u; on main and to s13 = 0x00000005u + 0x00000001u; here. #2319 bumped the revision for the same kind of change (the s_brev_b32 fold).
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);- the tests that pin the revision;
- the revision note in
docs/startup-runtime.md.
Moving the slot-57 mesh key is your call.
Non-blocking:
- Untested run-time write: a one-line mutant that keeps the constant symbol but drops the run-time
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. - Misleading test comment: in
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.- A trial merge with
mainpassed the 114 non-GPU checks. - Mutants caught by
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.
MasterDomino
left a comment
There was a problem hiding this comment.
Approving 2381d5c6; the change request is resolved.
- Revision bump:
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. - New check:
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_check
The 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.
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).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 startup: remove duplicate Pass render target bindings breaking Windows builds #2706.AI-assisted; commands listed were executed locally.