startup: prove exec writes over every path of a compute execz block #2501
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2509"
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-25T19:01:07Z.
Second part of the compute
s_cbranch_execzwork after #2314. Refs #2274.Problem
gfx2hlsl models one lane and emits
s_cbranch_execzas a branch on that lane's exec bit. The wave skips the block only when no lane is active, so for a lane the model skips, the block may still run in the wave.Stage.execz_refusalstherefore refuses a compute block unless it can show the block changes nothing of such a lane.After #2314, an exec write in the block was accepted only in a straight-line block, and only when it narrowed exec or restored it from a copy made in the same block. Compiled programs nest an if/else or a loop in such a block, so nearly every exec write was refused: on a local set of 1,065 compute requests (not shareable), all 1,065 stopped at this check, 969 of them on an exec write.
Change
tools/startup/gfx2hlsl.py: the straight-line rule becomes a forward pass over the block's own control flow.A fact
(word, half)says: for every lane of that wave half (lanes 0-31 or 32-63) whose exec bit was clear at the branch, that lane's bit of the scalar word is clear. At the block's first instruction the facts areexec_lofor the low half andexec_hifor the high half.clear_aftermoves the facts across one instruction:s_movs_ands_or,s_xors_andn2s_*_saveexecs_andn2_wrexecs_andn2with exec; the result goes to exec and Dv_cmpx*Paths meet by intersection and the pass runs to a fixed point, so a fact at an instruction holds on every path to it, loops included. An exec write is accepted when exec still holds both entry facts after it.
Invariant: at every instruction the wave runs inside the block, a lane skipped by the model has its exec bit clear. Such a lane therefore writes no register and has no memory effect in the block, and its exec bit where the block joins is the one the model has. Scalar definitions in the block still have to be dead at the join; that rule is unchanged.
Still refused, each with the existing
exec writereason:s_orn2,s_nand,s_nor,s_xnorand their saveexec forms, and anything else that writes exec);Removed:
is_exec,exec_stays_clear,exec_copies_after, which the pass replaces.Tests
tests/startup_gfx2hlsl_compute_check.py:s_cbranch_execz, the else switch ass_andn2_b32 exec_lo, s0, exec_loand the restore ass_mov_b32 exec_lo, s0. The check compares the exact HLSL tail and every output word for lanes that take the if arm, the else arm, and neither.m-else-unswitched(registered inCMakeLists.txt): the else switch without the complement must fail the comparison.s_andn2_wrexecfrom an in-block copy.s_or_saveexecwith a mask made before the block,s_andn2_wrexecfrom an overwritten copy,s_orn2,exec_hiORed intoexec_lo.clear_after.s_oras union, a single pass instead of the fixed point, no intersection at joins, ignoring an entry from outside.Commands and results (Windows 11 build 26300, Python 3.13 environment from
requirements-dev.txt):python -B tests/startup_gfx2hlsl_compute_check.py: exit 0python -B tests/startup_translator_check.py: exit 0tests/startup_gfx2hlsl_*_check.pywithout arguments: all exit 0git diff --check: cleanm-else-unswitchedis rejected at word 1. Adapter Microsoft Basic Render Driver, driver 10.0.26100.10068, Windows build 26300, debug layer on, DXC from Vulkan SDK 1.4.363.0. Theoffscreen_checkrunner was built from another branch of this repository, not from this commit (this change does not touch its sources); the test script and translator are this commit's.Not run: the
binarymode (no gfx1013llvm-mchere; the new instruction words are hand-assembled and checked only against the repository's decoder), a hardware GPU, the full CMake/ctest build.Measurement
First refusal per request on the same 1,065 compute requests, with a local baseline copy of the translator and the same copy with this change applied (not the branch itself):
The 17 remaining exec writes: 14 in blocks entered from outside, 3
s_or_saveexec_b64of a literal. The 846 live definitions were hidden behind the exec write before; they are a separate rule and are not changed here. The largest forms are a compare intovcc(341; in the ones I read, the join only ANDs it with exec) ands_andn2 R, R, exec(348; in the ones I read, the join moves R into exec).Overlap with #2505
#2505 (open) changes the same function for a different case: a lane mask defined in the block and live at the join. It does not cover exec writes, and this change does not cover that live definition, so the two are complementary in scope. They do not merge together as written: #2505's argument uses
exec_stays_clearand "exec can only narrow inside the block"; this change removes that helper and accepts an else switch and a restore, after which exec no longer only narrows. Whichever lands second needs a rework; I will rebase this one if #2505 merges first.Limits
S0 op EXEC); only the case M forms are checked against a device result.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:18:11Z.
Review: COMMENTED
Review of head
0b7d61dd: code and fixture review only. No issues found in the code. The merge stays with @R0Y00 or MasterDomino.Why we do not merge it: the description measures the change on a local set of compute requests (0 -> 3 translated). We cannot verify that claim without the game. The merge should be done by someone who can.
What I checked in
tools/startup/gfx2hlsl.py:clear_afterfollows the stated table.s_andunions the facts.s_orands_xorintersect them.s_andn2and a move keep the first source.v_cmpxkeeps the exec facts. Any other write, including a compare result, drops the facts of what it may write.exec_hicopied intoexec_lois refused. The pure-Python table covers that case.| entryin the loop does not hide a bad write: every exec write is checked separately againstbefore[i], so one that loses the facts is refused.entered).s_setpc_b64jumps are in the jump list, so a proven one that enters the block also keeps its exec writes refused.Tests:
m-else-unswitched. The control is registered in CMake for each adapter.clear_afterresult.s_andcombined by intersection instead of union: the translation of case M is refused (exec write).s_orcombined by union instead of intersection: a refusal that should happen is accepted.Commands run on Linux:
python3 -B tests/startup_gfx2hlsl_compute_check.py(pass)python3 tests/docs_links_check.py(pass)python3 tests/bidi_controls_check.py(pass)git diff --check origin/main...HEAD(clean)Not run by me: Win2025 WARP (case M dispatch and the control), and any run on the game. The PR is 32 commits behind main.
Related: #2505 also touches the compute execz area (i1-phi lane mask). It looks like a different slice (I did not review it), but whoever merges both should check they do not overlap in
Stage.execz_refusals.AI-assisted; commands listed were executed locally.