xshader: keep first-lane elections out of the per-quad admission #542
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/542"
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 brcly/TuxBox. Originally posted by csj0oe on 2026-11-29T21:08:27Z.
What
A quad exchange behind a guard is now admitted only when the guard is provably uniform within the quad; per-lane guards stay refused.
uniform_control_flowhelper.s_cbranch_scc0/1is admitted only when a scalar compare ors_cmpkwrote SCC earlier in the same straight-line block (the ISA leaves SCC undefined at entry).s_cbranch_execz/execnzis admitted because EXEC is the wave's own mask.s_cbranch_vccz/vccnzis admitted only when the compare that last defined VCC has every operand quad-uniform: constants, SGPRs,v_readfirstlane_b32results and lane-independent arithmetic. Interpolants, LDS/buffer loads,v_mbcnt_*, DPP permutes,v_readlane_b32,v_cndmask_b32, EXEC as vector data and values with no definition are refused.pixel_quad::quad_guardskips a proven forward conditional branch and keeps the existingquad exchange behind <guard>refusal for everything else, including loops and indirect transfers.s_cbranch_scc0with SCC never written before the branch, which is undefined at entry, so the control stays refused — a provenance rule, not a claim about uniformity.Counts
On our 20,295-request record against the merge base: 0 newly translated, 0 lost, 0 previously translated programs with changed HLSL. The four candidates that reach the guard question have per-lane VCC guards (a DPP16 permute mixed with a
v_cndmaskof EXEC-derived masks) and remain refused; the other twelve elect the first active lane and never reach this path.The maintainer's 38,475-request set is not on this machine, so his six recovered programs could not be inspected. If they are SCC-, EXEC- or uniform-VCC-guarded, this rule admits them; that set is the missing evidence.
Verification
guardedwith the named reason;copyandinplacetranslate and passdxc -T ps_6_6 -O3anddxv.python tuxbox.py check --no-gpu: 7/7 in the toolbox.GPU
Pending. On our record no admitted program is left to compare on either card.
Author status (30 Nov)
e5d2e913as six commits; range is ours only;tools/check_straight_pixel_quads.pyuntouched.v_cndmask_b32 v10, 0, -1, vcc, not a constant 0, and proving it needs DPP16 propagation the conservative rule excludes.Still to run:
straight-pixel-quadsand the translator GPU checks on AMD, once the current GPU use finishes. NVIDIA is not available on this machine, so that half cannot be produced here — if the six programs you measured are uniform-guarded the rule admits them; if their guard is the per-lane shape above, it does not.Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T21:11:51Z.
Thanks. This is in our current focus. You noted no GPU checks were run, so we're running the full check on an NVIDIA and an AMD card here, and measuring how many recorded programs' translations change. We'll merge it if that passes.
Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T21:27:52Z.
We merged #510, #531, #537, #538, #541, #543 and #544. This one we held back, because it fails the translator GPU check
straight-pixel-quadson both of our cards (RTX 4070 Ti SUPER and Radeon 610M):The four drawn cases still match, but the check's control, a quad exchange behind a guarded prefix, is supposed to be refused, because the translation can't guarantee complete quads there. With this PR it translates. Without the PR (same batch, same cards) it passes with
guarded_refused True. That's the case your description calls unproven ("the order of lanes that skip the branch").Over our 38,475 recorded ProjectScarlett requests it recovers 6 programs (all small pixel shaders that compile with DXC), changes no other translation, and loses none, so the gain is real. But it needs either a narrower admission that still refuses the guarded control, or a GPU check proving the guarded case correct, with the control in
tools/check_straight_pixel_quads.pyupdated to match.Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:16Z.
Heads-up: main just landed a large cleanup (up to
e5d2e913), so this PR needs a rebase.rustfmt.toml).unwrap(), lossyascasts and undocumentedunsafeoutside tests.cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.The least painful way is to format your branch first, so the rebase only shows real changes:
Then run
python tuxbox.py check --no-gpu, which now includes the format step.If clippy flags something new:
Fromfor widening,TryFromfor narrowing, and a mask for bit fields.unwrap(): use?, orexpectwith the reason it can't fail.unsafeblock: it needs a// SAFETY:comment.CONTRIBUTING's "Code checks" section lists the commands. Thanks!
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T07:14:22Z.
@csj0oe while looking at refused pixel programs we read one of the G-buffer variants and it's what you describe: under
s_wqm, a per-lane VCC from DPP16quad_permmoves of an EXEC-derived helper mask, thens_cbranch_vccnz. An idea, from reading that one program only: both arms of that branch leave the same state. The taken arm sets the result register to 0; the fall-through arm computes quad sums of a register that was just set to 0 in every lane and selects 0 again; the scratch register and VCC are overwritten before their next read. A rule "a branch whose arms provably leave identical live state needs no vote" would admit it without proving the guard uniform. We haven't checked whether the other three match, and aren't building anything on it; it's yours to use or drop.Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-30T08:28:39Z.
Thanks — that's a useful angle, and it avoids the uniformity proof I was attempting.
Which program did you read? If it is one of the four we refuse (
1b24cb42,73ab346a,861d25b4,a6ccffdcin our 20,295-request set), I can test the arm-equivalence rule against those bytes directly: one arm setting the result to 0, the other summing a register that was just zeroed and selecting 0, with scratch and VCC dead before their next read. If it is a different G-buffer variant, the same shape may still apply but I would be guessing from your description.I am not building it yet; first I want to know whether the shape is identical across those four or only this one.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T08:50:17Z.
@csj0oe it was one of your four:
861d25b4. From reading instruction dumps of all four (nothing translated or run):73ab346ahas the same instruction stream as861d25b4.1b24cb42anda6ccffdcare the same as each other, and their guarded region is identical to861d25b4's.1b24cb42the scratch register and VCC are written again after the join before either is read, and the result register, 0 on both arms, is read later. Same in861d25b4."Same live state" is our hand evaluation of both arms, not a proof, so a test against the bytes as you describe would be the right next step. It's yours to build or drop.
Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-30T09:14:30Z.
Tested it against the four bytes rather than by hand. Result: the rule as stated refuses them, and the reason is one register.
1b24cb42/a6ccffdcand73ab346a/861d25b4are identical pairs.v11and VCC are dead after the join at0x190, as you said:v11is rewritten at0x20C, VCC at0x21C, both before a read.v10is not the same on both arms. Taken arm:0x164: v_mov_b32 v10, 0. Fallthrough: last write is0x188: v_cndmask_b32 v10, 0, -1, vcc, which is statically 0 or -1.0x184: v_cmp_lt_f32 vcc, 0, v10is false, which needs the DPP16 permutes at0x170/0x178(quad_perm:[1,0,3,2],[2,3,0,1]) propagated. A conservative "live registers equal, DPP/SDWA refuse" rule cannot do that, so it refuses all four and the counts stay 0/0/0.Our decode of all 147 executable instructions per program matches the reference disassembly exactly — mnemonics, operands, cndmask sources, quad selectors and the branch target — so this is not a decoding artifact.
No code change from this. If you want the four admitted, it needs a DPP-aware proof of that compare, which is a different piece of work than the current rule; I would rather leave them refused than weaken it.
Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T09:20:18Z.
Thanks for the careful write-up, and for testing Nick's arm-equivalence idea against the bytes instead of by hand. That's exactly the right way to settle it.
I ran this PR, squashed onto current main, over our full recorded set: 46,664 ProjectScarlett requests, the 38,475 you mention plus the later recordings. Against main: 0 gained, 0 lost, 0 changed, and no refusal message changes either. The six programs from the older set don't translate with this rule on today's main.
So right now this adds about 200 lines of analysis that admit no program we have, and I'd rather not merge code nothing exercises. Two things would change that:
Leaving it open in case you want to take it there.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T09:20:51Z.
@csj0oe thank you for testing it against the bytes. You're right and my hand evaluation was wrong: I took the fall-through arm's result as 0 because its input had just been zeroed, but
v10is only 0 if the compare's input is shown to stay 0 through the two DPP quad permutes, and I hadn't done that. I agree with leaving the four refused, and I'm not working on them.Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-30T10:10:20Z.
Closing this. Our own record over 46,664 requests is 0 newly translated, 0 lost, 0 changed, which is the same thing you measured, and nothing in the tree exercises the new path. The four candidates need a DPP-aware proof of the compare at
0x184, which is a different change than this rule; if that lands, the admission goes in with it. Branch kept.Pull request closed