shader: recompute uniform compute loads under a proven nonempty EXEC #3692
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3692"
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 Not-Saii on 2026-12-01T02:18:40Z.
Change
Refs #2644.
v_readfirstlane_b32of a uniform compute buffer load past the entry block is lowered by reloading the words into a temporary in every lane (the recompute path). Until now that path required the entry EXEC mask at the load. On RDNA 2, READFIRSTLANE with an empty EXEC returns the old lane-zero VGPR, and an unguarded reload cannot reproduce that. The existing comment already allowed this "until the path proves a nonempty wave". This change adds that proof.Stage.nonempty_exec_loads()is a forward must-dataflow over the block graph (spill_cfg). It applies to compute stages only.s_cbranch_execz;s_cbranch_execnz.writes_execaccepts, includingv_cmpx, saveexec, wrexec ands_movreld.A uniform load at a proven offset is recomputed even when
exec_knownis false. Under a narrowed EXEC, a lane that skipped the address definition holds an older copy. So a VGPR address must still have its recomputable uniform expression; the copy is used only under the entry mask, as before.Everything else in the read is unchanged. A branch target, an EXEC write, or an overwrite between the load and the read still refuses. Image loads keep their current gate.
Not covered
s_mov_b64 exec, 1uses the VGPR-copy path, not the recompute path, and stays refused.Verification
Base: main
1a9ccbc4. Python 3.14.8, no GPU.tests/startup_gfx2hlsl_readfirstlane_load_recompute_check.pyadds these cases:s_cbranch_execzfallthrough;idxenload on the same fallthrough;s_cbranch_execnztaken edge;s_and_saveexec.nonempty_exec_loadsreturning nothing, every accepted case refuses again.Mutation checks:
stale address copy on the s_cbranch_execz fallthroughfails.Local census (counts only, inputs not attached): 512 compute requests stopped first at
v_readfirstlane_b32 requires a proven uniform sourceon main.cs_6_0compiles: 4 of them.ds_bpermute_b32(1), and a scalar live out of an execz block (1).Regression replay: I retranslated the 223 compute requests of the same set that already translated, on main and on this branch.
Not measured: GPU readback (WARP or hardware) of the new path.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T02:32:37Z.
Review: APPROVED
Reviewed
273a534dby reading the diff; not built or run.Verdict: approve.
nonempty_exec_loadsis a sound must-analysis, and the new recompute gate keeps the address guard that a narrowed EXEC needs. No MUST.tools/startup/gfx2hlsl.py:4557,return set()). Ans_setpc_b64without a calculated target in front of ans_cbranch_execzfallthrough load, expected to refuse, would pin it.new and has,:4579), so the fixpoint is the greatest one. Theexeczfallthrough andexecnztaken edges assert nonempty, and the opposite edges assert empty. Anexeczthat branches to its own fallthrough gets both edges, so the AND drops the fact.vaddr[1] in exprs,:4922) relies onforget_writesclearing everyuniform_expron any EXEC write (:5129-5131). An address that still has an expression was therefore written after the last EXEC write, by the same lanes that are active at the load. That is why recomputing it matches the first active lane. Thestale address copycase covers the scalar-rewrite side.cs(:4062), and the entry-mask path is unchanged.nonempty_exec_loadstoset()makes every accepted case refuse again, so the accepted cases depend on the new proof. The back-edge, narrowed-join and taken-edge-join refusals exercise the dataflow itself.Tests:
startup_gfx2hlsl_readfirstlane_load_recompute_check.pyadds 5 accepted cases, 8 refused cases and the control. They reach the new edges, the joins and the address guard. CI ran the test at this head (the Windows Python checks step,windows.yml:322).