startup: prove lane-pure v_readfirstlane_b32 sources uniform in straight-line code #1924
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1931"
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 Leyukaka on 2026-11-24T21:39:54Z.
Refs #1723 (row "
v_readfirstlane_b32without a proven uniform source").Change
The startup shaders are compiled with FXC (shader model 5), which has no wave intrinsics, so
tools/startup/gfx2hlsl.pylowersv_readfirstlane_b32 sD, vSassD = vSonly whenvSis proven to hold the same value in every lane. Until now the only proof wasv_cvt_i32_f32of a fixed buffer word.The proof now follows lane-pure VALU results in straight-line code with a known
exec:v_cvt_u32_f32,v_cvt_i32_f32,v_cvt_f32_ubyte0,v_mul_f32,v_fma_f32,v_fmaak_f32,v_rcp_f32andv_mov_b32(e32/e64). It applies when every source is uniform:Scalar writes and SCC are tracked as varying when they depend on
vcc,exec,m0, a varying SGPR, an unproven VGPR or a varyingscc. Lane masks, and descriptor, pointer and sampler symbols, are never uniform sources. Overwrites, SDWA forms and interpolation clear a proof, and so do WQM and restoringexecfrom a saved copy, which can activate helper lanes.The read keeps its preconditions (no modifier, no branch, known
exec, SGPR destination, VGPR source) and now also requires a single register on each side. Branches stay refused.The earlier
v_cvt_i32_f32proof now goes through the same path. AStagebuilt without__init__and without the full tracking state proves nothing.The second and third commits close holes found in review of the first (the fourth only closes a code block in
docs/experiments.mdafter the rebase):atemporary of an aliaseds_buffer_load;exec;execcopies;s_mov_b64;Each has a refusal case. After review, every SCC write either updates the proof or invalidates it: an
m0write judges SCC from its sources, and ops whose SCC result is not modelled (s_add/s_sub/s_min/s_max,s_wqm, symbolic descriptor words) mark it varying; a mixed-lane compare carried throughm0intos_cselectis refused. The check is registered as CTeststartup_gfx2hlsl_readfirstlane_uniformand added to the pure-Python CI list in.github/workflows/windows.ymland its mirror inAGENTS.md.docs/experiments.mdhas a new section.Verification
On
e366d03a(withmainat999875amerged in), Windows 11 build 26300, Python 3.14.10:73 checks,
0 failed. The test translates short instruction sequences through the stage's own dispatch, with no machine code. It covers:clamp,mul:2, and negated and absolute sources;v_interp_p1_f32,v_interp_mov_f32), WQM and otherexecwrites, lane masks, 64-bit high words, branches, operand shapes and constructor-less probes.mul:4,div:2andv_interp_p2_f32are handled by the same code but not exercised.main(b96960b7)AttributeErrorat the constructor-less probe, whichmaindoes not supporte6e3fd25)exec, aliased load first and second word, restoredexeccopy after WQM, descriptor move high word, mask from uniform compare), then the sameAttributeErroredd281c9)4 failed: restoredexeccopy after WQM, overlapping 64-bit move high word, descriptor move high word, mask from uniform compareAn in-process control empties the op list and requires every accepted sequence to be refused again.
Also run on this branch, each
python -B tests/<name>exiting 0:startup_uniform_lane_check.py,startup_gfx2hlsl_op_refusals_check.py,startup_gfx2hlsl_cndmask_neg_check.py,startup_gfx2hlsl_cvt_alu_check.py,startup_gfx2hlsl_operand_count_check.py;startup_gfx2hlsl_bit_alu_check.py,startup_gfx2hlsl_mad_check.py,startup_gfx2hlsl_smem_offset_check.py,startup_gfx2hlsl_scalar_m0_check.py,startup_gfx2hlsl_vopc_sdwa_check.py,startup_translator_check.py,startup_flat_param_check.py;startup_inline_sampler_check.py,startup_buffer_address_check.py,startup_sampler_heap_check.py,startup_stream_fetch_check.py,startup_image_2d_array_check.py,startup_image_load_mip_check.py;docs_links_check.py,bidi_controls_check.py.CTest was not run for this change; the commands above are what the CTest entries run.
Evidence and follow-up
Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:57:35Z.
Review: CHANGES_REQUESTED
Please run the uniformity proof through scalar instructions that write m0 and SCC. The dname == m0 branch still emits the SCC assignment directly, bypassing set_scc(), so a previously uniform SCC stays marked uniform even when s_and_b32 m0, vcc_lo, -1 makes it depend on a varying comparison mask. A following s_cselect_b32 can then mark a varying VGPR uniform and accept v_readfirstlane_b32. Add a mixed-lane compare -> m0 bitwise write -> s_cselect -> VALU -> readfirstlane refusal control with EXEC unchanged. The ordinary numeric uniform path should still pass. Please check that every SCC-writing branch either updates the proof or invalidates it.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T21:52:29Z.
Ran it and broke the proof five ways
Windows 11 build 26300.9974, device-free:
The new check is registered in
CMakeLists.txt,AGENTS.mdand the Linux job, which is the part that is most often forgotten.Mutations to
tools/startup/gfx2hlsl.py, each reverted:UNIFORM_VALUcut down to a single opscalar_expr_uniformalways true (everything is "uniform")if not self.scc_uniform: return Falsedisabledv_rcp_f32removed fromUNIFORM_VALUtracks_uniformity()always false (the proof never runs)The last two are the ones that matter to me. Dropping
v_rcp_f32is a narrower proof, so a fixture that only checks "theaccepted chains translate" would pass while silently refusing more inputs; yours fails. And
tracks_uniformity()returningfalse turns the whole feature into a no-op with the same emitted code for the old paths — the check notices, so the proof is
genuinely exercised rather than merely present.
One thing worth stating in the description
The claim "lane-pure in straight-line code with a known
exec" is the load-bearing condition. The check has a control for thecross-register chain without tracking, which is the right negative case; what I could not find is a case where
execis notknown (after a branch) and the proof must fall back to refusing. If that case exists in the file I missed it, and if it does not,
it is the one a reviewer of a later change to branch handling will want.
What this does not establish
Nothing about real shaders: it says the proof accepts the enumerated chains and refuses the enumerated non-chains. Whether
v_mul_f32on two uniform operands is uniform in every corner (denormal mode,omod/clampon the e64 form) is an ISA argument,not something this fixture measures — and your
v_mul_f32description already limits itself to "uses only local arithmetic",which is the honest framing.
Verdict
Reviewed. The proof is narrow, every off-switch I could find turns the check red, and the registration is complete. No objections.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-24T22:16:40Z.
Confirmed. Addressed in
ed88a09eande366d03a, after mergingmainat999875a(87c120bc, AGENTS.md list conflict only).The
m0branch. The SCC assignment now goes throughset_scc(). Its uniformity is judged from the sources of them0write, because the emitted text readsm0, which the proof never trusts. Sos_and_b32 m0, vcc_lo, -1makes SCC varying, and a write from uniform scalars makes it uniform.Every SCC-writing branch. Each one either updates the proof or invalidates it:
set_scc()callers:s_cmp*/s_cmpk*,scalar()results with an SCC template (SGPR andm0destinations), andexec/vccdestinations (always varying);s_and/s_or/s_andn2_saveexecands_andn2_wrexec: varying;s_add/s_sub/s_min/s_max, i32 and u32),s_wqm_b32/_b64, and scalar ops on symbolic descriptor or pointer words, which emit nothing. Before this, the proof still trusted the previous SCC afters_add_u32 s3, s2, 1, so a followings_cselect_b32result could be proven uniform;m0or a complement, and SCC writers that are not lowered at all, such ass_bitcmp*,s_addc/s_subbands_abs*.Controls, all with
execunchanged:v_cmp_lt_f32 vcc_lo, v0, v1→s_and_b32 m0, vcc_lo, -1→s_cselect_b32→v_mov→v_readfirstlane_b32s_add_u32/s_wqm_b64 exec, exec/s_and_b32on a descriptor word →s_cselect_b32→v_mov→ reads_and_b32 m0, s2, 0xff→s_cselect_b32→v_mov→ read (uniform)73 checks. The 4 new refusal checks fail on
87c120bc. Also passing on this branch:startup_uniform_lane_check.py,startup_gfx2hlsl_op_refusals_check.py,startup_gfx2hlsl_scalar_m0_check.py,startup_gfx2hlsl_sop2_complement_check.pyandstartup_gfx2hlsl_vopc_sdwa_check.py, plusdocs_links_check.pyandbidi_controls_check.py.Since #1755 the float lowering refuses
op_selitself, so the "op_sel overwrite" case now expects that earlier message exactly; "modified move overwrite" still covers proof clearing under a modifier.@ChazY11: thanks for the mutation run. An
execwritten mid-sequence is covered ("compare writes exec" withv_cmpx_lt_f32, "saveexec writes exec" withs_and_saveexec_b32), and so is a branch anywhere in the program ("branch after read"), and "unknown exec refused" runs the plain move and read withexecnot known; each refuses the read.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T23:29:36Z.
Review: APPROVED
The new head tracks m0 writes through SCC. The branchless mixed-lane refusal and ordinary numeric acceptance both pass alongside the expanded uniformity tests.