gfx2hlsl: read a joined mask ANDed with exec at an execz branch target #2458
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2466"
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-25T17:26:17Z.
What
tools/startup/gfx2hlsl.pyrefuses every read of a scalar register that holds, on some path into a branchtarget, a symbol with no run-time value (
numeric use of sN holding joined at a branch target). One read isnow accepted in vertex and pixel stages:
s_and_b64 D, S, exec(either operand order) ors_orn2_b64 D, S, exec, as the instruction at the target, whens_cbranch_execz(no other branch kind, no backward branch, nocalculated jump), and
Why
A common shape in compiled pixel programs:
In a set of 153 vertex/pixel requests measured on a local merge of open translator PRs, this was the first
refusal of 35: 34 with
s_and_b64(stale descriptor word, in 14 of them carried through an earlier join),1 with
s_orn2_b64(stale table pointer). All 35 are pixel stages and all 35 meet the conditions above.Argument
The translator models one lane; a lane mask is its bit 0, and
s_cbranch_execzis emitted as a branch on(exec & 1) == 0. The emitted statements areD = (S & exec) & 1andD = (S | ~exec) & 1.the result is 0 (AND) or 1 (OR with the complement) whatever the variable of S holds. On hardware the
lane's bit of
S & execis likewise 0 when the lane's exec bit is 0, whatever S holds.Not proven here: that a lane whose exec bit is 0 may be treated as taking the branch while other lanes of
the wave fall through. That is the translator's standing one-lane model for every
s_cbranch_execzin vertexand pixel stages; this change adds no new assumption to it. SCC after the instruction is the lane's bit, as
for every other mask operation.
Change
Stage.translate: the set of targets entered only by forwards_cbranch_execzbranches (empty forcompute stages), and per target the joined registers whose fall-through value is a plain run-time number.
Stage.exec_absorbed_source+ one line inStage.scalar: the qualifying source is read as its variable;symbols are not changed, so a later read of the same register is still refused.
docs/experiments.md: three sentences under the join paragraph.Still refused: any other read of a joined register;
s_or_b64,s_andn2_b64,s_orn2_b64with execfirst,
s_and_b32; another branch kind or a second edge of another kind into the target; the sameinstruction one instruction after the target; a constant (or any symbol) on the fall-through; compute stages.
Tests
tests/startup_gfx2hlsl_join_symbols_check.py(no arguments) gainscheck_exec_join():execas the destination, and the emitted right-hand sides evaluated with exec bit 0 over six words;Mutating each of the five conditions in the translator (branch kind, position, fall-through symbol,
operation, exec operand) makes the check fail.
Not run:
binary(no llvm-mc here; the new words are built from the SOP2/SOPP/VOP3 field layouts and are notin the assembled SOURCES table),
dispatch/control(no GPU run of the new fixture), ctest.Measured
First refusal per request, 153 requests, same merged translator:
The 35 then stop at later refusals (34 at an operand form another open PR covers, 1 elsewhere); none
translates end to end from this change alone.
Limits
s_and_b32/exec_loform, no loop headers.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T17:41:34Z.
Five mutations: two caught, three survive, and one of them is the compute exclusion the comment calls out
Baseline on this branch:
startup_gfx2hlsl_join_symbols_check.pyexit 0 with both summary lines, and all 62tests/startup_gfx2hlsl_*_check.pypass.exec_joinkind == 'cs'exclusion removed (set() if False else …)all(...)→any(...)for "every other path iss_cbranch_execz"arriving[0][0][reg] is None→True(a folded value also qualifies)falls(fall-through wrote it) requirement droppedself.sym.get(reg) == ('joined at a branch target',)→TrueThe first survivor is the documented exclusion
The comment says "Compute stages have their own execz handling and are left out", and the mutation that removes that exclusion is invisible to the fixture. I grepped rather than assumed: the fixture's own
execzcases (lines 298–343) are the pixel-stage shape, and the two compute programs it mentions (CS_RELOAD,CS_UNPLACED, lines 23–27) are about descriptor reloads, not about this join. So nothing pins "compute is excluded", and a compute program that reaches this path would take the new code with no test noticing either way.That is the one I would close, and cheaply:
run(..., kind='cs')on the same program the pixel case uses, asserting the mask is not read there (the old refusal). One case, and it turns the exclusion into something the fixture states.The other two survivors
falls— "the fall-through of a forwards_cbranch_execz" is what makes the stale value a plain run-time number; dropping the requirement widens the set to registers not written on the fall-through. I could not construct a program where that changes the output, and the fixture'sat_target=Falsecase may already be covering the shape; I am reporting it as unexercised rather than as a gap.'joined at a branch target'marker — replacing it withTruepasses, which means the other conjuncts already restrictregto joined registers in these fixtures, or the marker is redundant. If it is redundant it can go; if it is not, it wants a case.What the two caught rows show
all→anyis the classic weakening: a target with oneexeczedge and onescc1edge would have its join read as if every path were execz. That is caught. Andarriving[0][0][reg] is None→Truemeans a constant-folded value now qualifies as the "stale run-time number" the transformation is allowed to absorb — also caught. Those are the two that decide whether the emitted mask is right, so the fixture is pinning the important half.The twelve refusal controls and the "old behaviour still holds" line are the right shape for a change that relaxes a proof, which is what this is.
AI-assisted; the five mutations were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T18:29:59Z.
Review: COMMENTED
Review of head
baafda83. I checked it at that commit and merged with currentmain(6706077b, clean).The argument holds. On every taken
s_cbranch_execzedge into the target, the lane's exec bit is 0 and nothing runs between the branch and the target. So bit 0 ofS & execis 0, and bit 0 ofS | ~execis 1, whatever the variable of S holds.s_orn2_b64is correctly limited to S assrc0. No cache revision bump is needed, because the change only accepts requests that were refused before.startup_gfx2hlsl_join_symbols_check.pyand the neighbouring handler arity, operand count, saveexec, mask overwrite, readfirstlane and loop constants checks pass, at the head and merged withmain.One request before merge. Two of the conditions the description states are not pinned by the fixture. With these mutants of
tools/startup/gfx2hlsl.py, applied one at a time and then reverted:join_symbols_checkall(pc < t and …)becomesall(names[pc] == 's_cbranch_execz' …))s_cbranch_execzinto the targetanybranch kind (pc < tonly)s_orn2_b64with exec assrc0What would resolve it: two refusal cases in
tests/startup_gfx2hlsl_join_symbols_check.py, each asserting the oldnumeric use of sN holding joined at a branch targetrefusal:s_cbranch_execzintoLplaced afterL(a backward edge);kind='cs'), as @ChazY11 suggests.Both conditions are stated in the description, so with these cases a later change can't drop either one silently. Once they're in and CI is green, I'll merge.
AI-assisted; commands listed were executed locally (Windows 11 build 26300, Python 3.13).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:24:20Z.
Review: COMMENTED
Review of head
d5658cdd(current head, checked against origin/main).Findings:
tools/startup/gfx2hlsl.py(newexecz_targets, thekind == 'cs'exclusion): removing the exclusion (set() if False else {...}) leavestests/startup_gfx2hlsl_join_symbols_check.pygreen. The compute exclusion the comment documents has no test, which matches the earlier mutation report in this thread. Add a case with acsstage and the same execz shape that must still be refused.falls and off in execz_targetscondition: droppingfallsalso survives. No test has a target entered only by taken execz edges with no fall-through write. Add that refusal control.self.sym.get(reg) == ('joined at a branch target',)check in the newexec_zero_joinset can be replaced byTruewithout any test failing. Either add a case where the register is not in the joined state, or drop the check if it is redundant with the other conditions.s_orn2_b64removed from the accepted forms, and theexecoperand check removed.(exec & s16) & 1and(s16 | ~exec) & 1. The reasoning in the docstring is sound for a one-lane model (a taken execz edge means exec bit 0 is 0). The change is an operand-reading rule, not new arithmetic, so I did not ask for a new WARP readback, but the test does compare the generated HLSL, not GPU output. Please say whether a readback is wanted here.Not a blocker on its own, but I would fix 1 and 2 before merge: these are the guards that keep compute stages and fall-through-less targets refused.
Commands run locally:
python3 tests/startup_gfx2hlsl_join_symbols_check.py: exit 0, both summary linesgit diff --check origin/main...HEAD: cleangfx2hlsl.py(cs exclusion,falls, sym check, orn2, exec operand): 3 survived (items 1-3), 2 caught; tree restored withgit checkout -- .No Win2025 run and no game run were done by this review.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T19:59:31Z.
Review: APPROVED
Approved at head
8c9d7a96. That isd7ce3abc, with the controls that closed my review, plus a merge ofmain.Conflict resolution
Stage.scalar,main's short-operand-list guard (neededfrom the template placeholders) now runs beforeexec_absorbed_source.srcs, and every list that passes has the two sourcesexec_absorbed_sourcerequires.Commands executed at
8c9d7a96(Windows 11 build 26300, Python 3.13)All exit 0. The head merges cleanly with current
main.Negative control (re-run after the merge)
Each mutation is applied to
tools/startup/gfx2hlsl.pyalone, then reverted:join_symbols_checkall(names[pc] == 's_cbranch_execz' …))baafda83)set() if False else …)baafda83)s_orn2_b64with exec assrc0acceptedThe
fallscontrol and the plain-on-every-path control @NiiRoZz added cover @tedin7's and @ChazY11's survivors too. Removing the redundant joined-marker check is fine, since that control pins the output.Merge checks: required CI passed at this head. The
/O2and coverage skips come from explicit workflow conditions. There are no unresolved review threads. I read the whole thread, including @tedin7's review and the author's responses.The change is text-level under the translator's one-lane model, as the docs say. @tedin7 asked whether a readback is wanted; it isn't needed for this operand-reading rule.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T19:51:45Z.
Thanks for the mutation runs. I reproduced each one at
d5658cdd(apply the mutation, runtests/startup_gfx2hlsl_join_symbols_check.py, revert) and pushed the result asd7ce3abcon top.Mutations are on
execz_targetsandexec_zero_joinintools/startup/gfx2hlsl.py. "exit 0" means the check passed, so the mutation survived. "exit 1" means it was caught.Mutation table
d5658cdd)d7ce3abc)set() if False else ...)all(names[pc] == 's_cbranch_execz' ...))fallsrequirement droppedsym == joined markerreplaced byTrueall(...)toany(...)all(pc < t ...))arriving[0][0][reg] is NonetoTrues_orn2_b64removed from the accepted formsexecoperand check removedChazY11
execz_refusals) refuses that first, with "definition of sN, live where the block joins", before the join code runs. The refusal lists with and without the exclusion were identical.s_and_b64 s12, s12, execat the target).numeric use of s12 holding joined at a branch target, the old refusal.fallsrequirement. Verdict: test gap. I could not see a changed result at first because the case I tried was accepted either way.s_cbranch_execz, a descriptor load follows, a second skippings_cbranch_execzfollows, thens_endpgm, then the target. No fall-through enters.fallsrequirement the first edge is treated as the fall-through and the read is accepted. The new control asserts the old refusal. It decodes the program to check that the instruction before the target iss_endpgm.s16 = (s16 & exec) & 1;.MasterDomino
L: s_and_b64 s16, s16, execfollowed bys_cbranch_execz L(backward), reached by a forward skipping edge too. It asserts the old refusal and decodes the program to check that the lasts_cbranch_execztargets an earlier label.numeric userefusal through the real pipeline, because the pre-pass refuses it first. The stubbed-pre-pass control gives exactly that refusal, so the condition is stated in the fixture.tedin7
falls. As above.Commands and results (head
d7ce3abc, Windows, Python 3.13,python -B)tests/startup_gfx2hlsl_join_symbols_check.py: exit 0, both summary lines (the join line now reports 17 refusal controls, counted by the check).tests/startup_translator_check.py: 0 failed.tests/docs_links_check.py: 19 Markdown files, 469 links.tests/startup_gfx2hlsl_*_check.pyrun with no arguments: 66 files, all exit 0.git diff --check origin/main...HEAD: clean.Not run
dispatch,controlandbinarymodes of the join check were not run.main.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T19:54:22Z.
Re-checked at
d7ce3abc. Thanks, @NiiRoZz.tests/startup_gfx2hlsl_join_symbols_check.pypasses.baafda83are now caught. Dropping "forward only" (all(pc < t and names[pc] == …)changed toall(names[pc] == …)) fails the check with exit 1, and so does removing the compute exclusion (set() if False else …). Both reverted.One thing left: the branch now conflicts with
mainintools/startup/gfx2hlsl.py(git merge-tree). Once it's rebased and CI is green, I'll recheck the head and merge.AI-assisted; commands executed locally (Windows 11 build 26300, Python 3.13).
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T19:54:30Z.
Current
mainis merged in at8c9d7a96. One conflict, intools/startup/gfx2hlsl.py: main's short-operand-list guard now runs first, then this PR's exec-absorbed read. Re-run at that head:startup_gfx2hlsl_join_symbols_check.py,startup_translator_check.pyand every no-argumentstartup_gfx2hlsl_*_check.py, all exit 0. The reviewer mutations were not re-run after the merge.