startup: read a uniform compute buffer load past the entry block #2599
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2607"
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 NiiRoZz on 2026-11-25T23:16:08Z.
Depends on #2446, #2454
Refs #1723, #2274
What changes
v_readfirstlane_b32of a VGPR loaded by a compute buffer load past the entry block was refused withv_readfirstlane_b32 requires a proven uniform source. #2446/#2454 prove such a load uniform only in the entry blockwith known
exec, where every lane ran it.Past the entry block, the per-lane model keeps an older VGPR value in lanes the load skipped, so copying the VGPR is
not sound. This change has every lane load the same words again into a function-scope temporary
ul<pc>_<reg>, andthe read copies that temporary:
UNIFORM_LOADS(read-only,never stored through), a uniform offset scalar and a uniform address.
register), or the VGPR itself while
execis still the entry mask (every lane then ran its definition).every lane already computes the same component.
uniform_exprbookkeeping, so the read is accepted only under the existingpast-entry rules: no branch target,
execwrite or overwrite of the loaded register between the load and the read.Soundness
address, so all lanes hold the same words, independent of which lanes
execenabled.s_cbranch_execzand joins: a branch target clears the proof (existing rule), so a load inside a block onelane skips, or a join of two definitions, still refuses.
lane or wave during the dispatch (no aliasing through another descriptor).
Tests
New
tests/startup_gfx2hlsl_readfirstlane_load_recompute_check.py, registered inCMakeLists.txt,AGENTS.mdand theplatform-independent Python job:
under a narrowed
exec(destination equal to the address register); address copy under the entryexec; second wordof a two-dword load; a conversion of the loaded word; a formatted load; the temporary declaration;
between the load and the read; a load inside a block one lane skips;
execnarrowed between the load and the read;a stale address copy under a narrowed
exec; the loaded register overwritten; a two-dword load into three registers;a graphics stage;
UNIFORM_LOADSemptied every accepted form refuses. Against the translator without this changethe check reports 8 failures, each accepted form refused with the readfirstlane message.
Every
tests/startup_gfx2hlsl_*_check.pyplusstartup_buffer_address_check.py,startup_smem_address_check.pyandstartup_stream_fetch_check.py(82 scripts) exit 0.Measured
A local set of 470 refused shader requests (458 compute, 9 graphics and 3 RTV variants), collected with #2446 and #2454 applied and translated offline before and after this change:
v_readfirstlane_b32 requires a proven uniform sourceAll 18 requests that changed were readfirstlane refusals before; no other request changed its first refusal. Where the
18 stop now:
s_load_dwordx8inside a blocks_cbranch_execzskips per lane (scc live at the join)s_buffer_load_dwordx16inside a blocks_cbranch_execzskips per laneds_bpermute_b32buffer_store_format_xyzwsrc_sccins_mov_b32An offline census of the first refused read per request classified 22 refusals as a past-entry buffer load before the
change and none after; 4 of those 22 requests now refuse at a later
v_readfirstlane_b32with another root. Theremaining 95, by the census's root classification (not addressed here):
execv_fmac,v_rndne,v_ceil,v_add,v_sub,v_cvt_f32_i32)image_loadsourcev_cndmask_b32fromvccNot verified
v_readfirstlane_b32reads it. Programs that already translate can therefore gain an unused load and declaration; FXC should remove them,
but the output of already-translating programs was not diffed before and after.
v_readfirstlane_b32refusals need other proofs (waterfall loops, entry-block reads under unknownexec, thread-id chains, exec-masked joins); this change does not address them.vccdefinition live past a per-lanes_cbranch_execzjoin hide later refusals in thoseprograms; what they reach after that is not measured here.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:20:59Z.
Review: COMMENTED
Review of the merge of main into this branch (head
d758f9251). The cascade #2446/#2454/#2455 has landed, so the dependency is met.What I did: the branch conflicted in
tools/startup/gfx2hlsl.pyandtests/startup_gfx2hlsl_readfirstlane_uniform_check.py. I mergedorigin/main(no rebase, no force) and kept both sides: the per-lane temporary (uniform_load_temps,uniform_vaddr,uniform_temps) next to main'sshifted/tid_shiftandheap_indextracking.loadedbecameloaded_regsin theuniform_exprpop, which is the same condition as before.Checked locally:
python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD: clean.uniform_tempsinit): load_recompute check fails.Open point, not a blocker for the logic but for merge: the new lowering emits extra HLSL (
ul<pc>_<reg> = r0.Load(...)), and the only test is a string/refusal check on the emitted text. For a shader lowering, please add a D3D12 WARP readback (synthetic words) that runs a program with a uniform load past a branch and compares against a CPU reference, ideally extending the siblingstartup_gfx2hlsl_*WARP checks. Until then I am not merging this.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T06:11:45Z.
Review: APPROVED
The patched host suite keeps the existing full-entry-EXEC uniform loads and refuses both explicit empty EXEC and a narrowed mask without an active-lane proof. The empty mask reproducer emitted an unguarded reload on the previous head. Readfirstlane uniformity and recomputation, descriptor joins, compute translation and adjacent controls passed.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T06:07:53Z.
I reproduced an empty-EXEC case on
d758f925: lane zero has v7=17, the masked load does not write v7, yet the translated scalar read uses the unguarded reload temporary. The AMD RDNA 2 ISA specifies lane zero for V_READFIRSTLANE_B32 when EXEC is empty. In931af7f8the new load proof requires entry EXEC, and both the explicit empty-mask and potentially empty-mask cases refuse. The prior full-EXEC cases and six adjacent checks pass. A separate path proof can later accept a narrowed mask when the wave is known nonempty.AMD RDNA 2 ISA, V_READFIRSTLANE_B32