startup: refuse uniform load proofs across EXEC-changing loops #2760
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2768"
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 RavenCurseBurg on 2026-11-26T06:57:58Z.
Fixes #2757.
The first iteration of a compute loop can reach a read-only buffer load with the entry EXEC mask, and the next iteration can reach the same instruction with EXEC empty. The second readfirstlane must then see lane zero's previous register contents. The former translation reloaded memory using the new offset.
For compute programs with a back edge and a candidate load, the translator now follows CFG successors from blocks that write EXEC. Loads in those successor blocks are ineligible for the past-entry reload proof. This includes an EXEC write reached by a detour beyond the back-edge instruction. A write that occurs only after loop exit leaves the proof intact. The graphics and compute cache seeds both advance from main's revision 21 to revision 22. The compute seed
22csinvalidates earlier translations of this case.Verification
Tested commit
0e29f163on Windows 11. The reported loop and the off-range detour both produced unguarded reloads on the original baseline. Both are refused with the patch. The unchanged-EXEC loop still translates.The host suites passed, including the independently framed compute key
90041d02ef75b4e9. All checked-in fixture words matched LLVM's gfx1013 assembler (LLVM 15.0.7, clang-cc1as -show-encoding). The dispatch suite passed 27 baselines and detected four controls on each of WARP, Intel UHD 770 and RTX 4060 with DXC 1.9.2609.5.The new repo-authored gfx1013 fixture takes both arms of a forward branch in separate workgroups. Eight threads per group store the readfirstlane result at individual addresses. The CPU compares all 320 words, including 304 untouched sentinels. Replacing the read with zero fails on each backend at
word=0 expected=8b02a7f1 actual=00000000. The regression at the loop head is tested as an explicit translator refusal. The broader question about predication of arbitrary VGPR writes is separate.Follow-up
0b861347keeps the graphics and compute cache revisions paired. Runningpython -B tests/<name>.pypassed forstartup_shader_cache_rekey_check,startup_shader_cache_key_check,startup_compute_request_offline_check,startup_gfx2hlsl_buffer_store_check,startup_gfx2hlsl_const_copy_join_check,startup_gfx2hlsl_fract_checkandstartup_packed_position_provenance_check. An independent native C++ run of the runtime hash produced graphics keys93a74e652d95daf6and1ff6b039237188d6(without and with the input layout).After #2723 landed at revision 21,
3341d272mergedf1a8db63and advanced both seeds to 22. All seven cache/translation suites listed above and the compute, readfirstlane-uniform and readfirstlane-load controls passed on this head. The native graphics hash returned30009a5d8295d679anddae7d34c534837e5. The independently framed compute key is5159f6a85d77858e. The joined-load GPU fixture and its zero-read mutant were rerun on all three backends.AI-assisted with Codex (GPT-6.2 Astra, xhigh).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:16:08Z.
Review: COMMENTED
Review of head
0b861347(comment only).What I checked:
gfx2hlsl.py: for compute programs with a back edge and a uniform load, blocks reachable from an EXEC-writing block through the CFG are collected inloads_after_exec_write. Loads there are no longer eligible for the past-entry reload proof. EXEC writes only after loop exit leave the proof intact. This matches the described failure (second readfirstlane after an empty EXEC).Commands run (Linux, exact head):
python3 -B tests/startup_gfx2hlsl_readfirstlane_load_recompute_check.pyrc=0python3 -B tests/startup_gfx2hlsl_compute_check.pyrc=0python3 -B tests/startup_shader_cache_rekey_check.pyrc=0python3 -B tests/startup_shader_cache_key_check.pyrc=0python3 -B tests/startup_compute_readfirstlane_check.pyrc=0python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD: cleanloads_after_exec_writecondition makesstartup_gfx2hlsl_readfirstlane_load_recompute_check.pyfail (rc=1), so the new test guards the behavior.Windows results follow in the receipt.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T07:34:05Z.
Review: APPROVED
Approving
3341d272. Against0b861347, which I reviewed in full, the PR's own translator diff differs only in the revision, nowx2w-startup-shader-22/22cs. It merges cleanly and CI is green.@tedin7, on the Release segfault: it isn't this PR.
startup_resource_retire_titlesegfaults in Release onmaintoo: all 6 variants atf1a8db63, on WARP and an RX 9070 XT. A bisect puts it at #2719: its parent passes 6/6 in Release, and the merge fails 6/6.small_resulttreats a live wrapper in the second register as the (return buffer, object) form. Case 9 nests the slot-9 call inside a slot-20 call, so at/O2rdxstill holds the resource wrapper. The shim then writes the handle over the heap object's vtable and returns the heap's address. The RTV lands in an untracked slot, and the heap's nextReleasejumps into data.Why the guard is complete:
exec_knownis tracked in program order and never comes back after a real EXEC write. So a load placed textually after a writer was already refused; the gap was a writer reaching an earlier load through a back edge, and following CFG successors from every writer block closes it. Through the text harness, each of these now refuses wheremainaccepted:s_or_b32/s_andn2_b32/s_cselect_b32intoexec_lo, ands_and_b64 exec;v_cmpx(e32 and e64),v_cmp_e64 exec_loands_andn2_wrexec_b32;s_cbranch_execnz, and ans_cbranch_execzinside the loop;A writer after loop exit and a loop with no writer still translate.
Non-blocking: a divergent
ifinside a uniform loop (s_and_saveexec…s_or_b32 exec_lo, exec_lo, sNbefore the back edge) is now refused.maintranslated it correctly, because EXEC is the entry mask again at the load on every pass. The refusal is conservative and sound; proving the restore could be a follow-up. The bump is justified: wrong translations are now refused, and some still-translating programs drop a deadulc_Ntemporary.Runs:
0b861347,ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl|^startup_compute_readfirstlane|startup_compute_request_offline|startup_shader_cache|startup_indirect_draw_indexed|startup_resource_retire|startup_packed_position_provenance'gave 321 tests, 319 passed, 0 skipped. The two failures also fail onmainon this adapter (#2746):fma_mix_dispatch_hardwareandf16_alu_draw_hardware.join-loadmatches all 320 words on WARP and hardware, andjoin-load-zerois rejected atword=0 expected=8b02a7f1 actual=00000000.3341d272, these all exit 0: the readfirstlane load/uniform/recompute checks,startup_compute_readfirstlane_check.py,startup_compute_request_offline_check.py,startup_gfx2hlsl_compute_check.py(plusbinarywith llvm-mc 15),startup_shader_cache_rekey_check.pyandstartup_shader_cache_key_check.py.Mutants: four are caught by
startup_gfx2hlsl_readfirstlane_load_recompute: dropping the guard, removing the transitive walk, seeding only forward successors, and counting only saveexec as a writer. The new refusals also fail againstmain's translator.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T07:02:33Z.
@RavenCurseBurg, the Linux Python job fails at
0e29f163ontests/startup_shader_cache_rekey_check.py:The check expects the graphics and compute revisions to share one number. Moving the graphics key to
x2w-startup-shader-21alongside21cs(ingfx2hlsl.py,d3d12_draw.inl, and the tests and docs that spell it) should clear it. A full review follows.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T07:07:26Z.
Pushed
0b861347to keep the runtime, translator, native fixture seeds and key vectors at21/21cs. The original re-key test passes with its shared-revision assertion intact. I reran the six adjacent cache/translation tests and independently checked both graphics keys with the C++ runtime hash. The PR description includes the results.Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T07:18:50Z.
@RavenCurseBurg, thanks for
0b861347. Heads-up: #2723 just merged (f1a8db63) and also tookx2w-startup-shader-21/21cs. This PR now needs22/22csso its refusal re-keys entries cached under21. The semantic review is still running and follows separately.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:20:49Z.
Windows Server 2025 (MSVC + D3D12 WARP) at
0b861347:--preset dev): CTeststartup_indirect_draw_indexed,startup_resource_retire_title8/8 passed. Python checks ok, includingstartup_gfx2hlsl_compute_check.py,startup_gfx2hlsl_readfirstlane_load_recompute_check.py,startup_shader_cache_rekey_check.py.--preset release), run twice with the same result, 4 of 8 (and 4 of 6) CTest entries fail with SEGFAULT:startup_resource_retire_title_warp_debug0startup_resource_retire_title_off_warpstartup_resource_retire_title_hardware_debug0startup_resource_retire_title_off_hardwareThe PR's only change to that test is the
draw_revisionstring (...-20to...-21), so this may already fail on main in release. I could not confirm that here. Not merging until this is explained. @R0Y00 / MasterDomino: do you know whetherstartup_resource_retire_titlecrashes in release on main?Code review and Linux checks are in the earlier review comment.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T07:24:57Z.
Merged
f1a8db63in3341d272and moved both runtime and offline seeds to22/22cs. The documentation also retains #2723's revision-21 history. The ten local checks, the joined-load readback on WARP/Intel/NVIDIA and its pinned zero-read mismatch all passed on this head. The PR description includes the independently calculated keys.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:32:59Z.
Update on the release crash: it is not caused by this PR.
I ran the same four tests on Windows Server 2025 with this PR's changes reverted (main at
f1a8db63, release preset):startup_resource_retire_title_warp_debug0,startup_resource_retire_title_off_warp,startup_resource_retire_title_hardware_debug0andstartup_resource_retire_title_off_hardwarecrash with SEGFAULT there too. Debug passes. The most recent change touching that test is #2719.So the PR's own tests are green in debug and release. The release crash is a separate problem on main.
AI-assisted; commands listed were executed locally.