shader: merge mesh writes under one CMPX inside a lane skip and restore the guard (Part of #3703) #3765
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3765"
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 mumba17 on 2026-12-01T17:16:35Z.
Part of #3703. Fixes the wall
mesh EXEC write inside a lane-skip block(209 programs in my census on the current stack).Shape
All 209 programs share one shape inside the vertex skip:
v_cmpx_ne_u32that narrows EXEC, with nos_cbranch_execzafter it;s_mov_b64 exec, s[N:N+1]back to the saved vertex mask.The restore was refused because an open lane skip may not write EXEC.
Change
When that CMPX runs, every register is exact for the skip's guard lanes. So:
select(narrowed, new, old). The result is exact for the guard, and stays partial against full EXEC.These stay refused:
Tests
Source-built in
tests/native_direct_mesh_check.py:skip-narrow-merge:v10 += 1.0underv0 != 0, restore, thenv10is read and written under the vertex mask. Exactly one moreselectthan the same program with an empty region (skip-narrow-empty).skip-narrow-new-register:v11first written under the narrowed mask and read after the restore. Refusesgraphics register undefined on an incoming path: 267.skip-narrow-twiceandskip-narrow-inner-save: the two refusals above.I broke each part in turn, and a test failed each time:
skip-narrow-merge;skip-narrow-merge(undefined ... 266);skip-narrow-new-register.Validation (Windows 11, MSVC, Windows SDK 10.0.26100)
ctest --test-dir out/build/dev -R "native_direct_mesh|mesh": 210/210 on this branch. The twomesh_two_exitshardware tests skip as usual.main+ #3708 + #3709 + #3710 + #3729 + #3760 + this: 837 of 1,569 translate, up from 749. 88 gained, none lost. The rest of the 209 now stop at walls already listed on #3703, chieflyv_cmpx_lt_f32(69, in #3666). Counts only; request bytes stay local.This touches the same EXEC restore as #3760, so whichever lands second has a small conflict there. Because a nested EXECZ skip ends this region, the two never apply to the same restore. I checked the combination, and both test sets pass together.
AI-assisted.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T18:59:40Z.
Review: CHANGES_REQUESTED
Reviewed
5625b205by reading the diff; not built or run.Verdict: changes requested.
mergedis a set of values, not of registers, so a copy of a merged value into another register passes the restore as exact.skip_narrowing->merged(gfx1013_direct_mesh.inl,narrowed_restoreloop). The merge branch accepts an old value on the same test (merged.count(before_vec[j])).v_mov_b32lowers toz = a(gfx1013_direct_compute.inl:5502), sov_mov_b32 v11, v10under the narrowed mask, afterv10was merged toM, givesv11 = Mby name.v11had no value before, so the merge branch never ran for it. Yet at the restoremerged.count(M)keeps it, and later reads under the vertex mask takeMfor every guard lane. On the GPU, lanes outside the narrowed mask never wrotev11. A later write tov11would also merge againstMas if it were exact. Recording merges per register (std::map<unsigned,string>, kept only whilegraphics_registers[r]still equals that entry) closes both. A fixture would pin it:narrowed([0x061414f2, 0x7e16030a], after=(0x0614150b,))(v_mov_b32 v11, v10after the merge, then readv11) should refuse withundefined on an incoming path: 267, the same asskip-narrow-new-register.v_cmpthere ANDs its predicate withlane_active(:1579), so VCC stays exact for every lane after the restore. VGPR writes that were not merged are cleared.lane_activedifferent fromskip_narrowing->lane. A mask saved inside the region has the narrowed lane, not the skip guard. Both still reach "EXEC write inside a lane-skip block".value_limits-tagged register unchanged since the CMPX stays inpartial_writes, where the old path dropped it. That refuses more, not less.Tests:
skip-narrow-mergeproves one addedselectand the restore.skip-narrow-new-register,-twiceand-inner-savepin the three refusals. None copies a merged value.native_direct_meshis in theprpreset filter, and CI ran it green at this head.Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T19:47:56Z.
@lukaslw-lab Thanks, you're right.
mergedwas keyed by value, so a copy of a merged value passed the restore as exact.Fixed in
de321a36:skip_narrowing->mergedis nowstd::map<unsigned,string>: register → the value merged into it.M.Tests:
skip-narrow-merged-copyis your fixture (v_mov_b32 v11, v10after the merge, then readv11). It refuses withgraphics register undefined on an incoming path: 267. On5625b205the same fixture compiles, so it pins the bug.skip-narrow-merge-twicemerges intov10twice and expects exactly two addedselects, so a register's own entry still carries through a second merge.ctest -R "native_direct_mesh|mesh": 210/210 (the twomesh_two_exitshardware tests skip as usual).Census on the combined stack with this fix: still 845 of 1,569, none lost.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T20:06:16Z.
Review: APPROVED
Reviewed
de321a36by reading the diff; not built or run. Re-review after our change request at5625b205.Verdict: approve. Merges are now recorded per register, which closes the copy case from our MUST. No MUST.
de321a36keepsskip_narrowing->mergedas register → merged value.narrowed_restore, thepartial_writesloop): a register is kept only if it is unchanged since the CMPX, or if its current value is still its own merged entry.v_mov_b32 v11, v10after the merge leavesv11 = Mwith no entry, sov11is dropped.M.v_mov_b32 v10, v11under the narrowed mask) leavesv10 = Mby name. That is correct: the lanes outside the narrowed mask still hold the old part ofM, and the guard lanes inside hold the copy. The register keeps its own entry.Tests:
skip-narrow-merged-copyis the copy case. It refuses withundefined on an incoming path: 267; per the author, the same fixture compiles at5625b205, so it pins the fix.skip-narrow-merge-twiceexpects exactly two addedselects for two merges intov10, so it covers the entry update.native_direct_meshis in theprpreset filter, and CI is green at this head. The branch merges cleanly withmain158ef794.