Repository navigation
shader: merge mesh writes under one CMPX inside a lane skip and restore the guard (Part of #3703) - #3765
Conversation
…re the guard Inside the vertex skip, skinned mesh programs save EXEC, narrow it with one v_cmpx_ne_u32 and no EXECZ, run straight-line VALU work and restore the saved vertex mask. The restore was refused as "mesh EXEC write inside a lane-skip block". When the CMPX runs, every register is exact for the skip's guard lanes. A write under the narrowed mask whose old value is still that exact value (unchanged since the CMPX, or itself merged) is now merged per lane with it, so it stays exact for the guard. A restore of the guard's saved mask keeps every register that is unchanged since the CMPX or merged, and clears the rest, such as a register first written under the narrowed mask. A second narrowing, or a restore of a mask saved under the narrowed EXEC, stays refused. Part of R0Y00#3703. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed 5625b205 by reading the diff; not built or run.
Verdict: changes requested. merged is a set of values, not of registers, so a copy of a merged value into another register passes the restore as exact.
- MUST The restore keeps a register when its current value is in
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. - Checked, no finding:
- VCC under the narrowed mask. A
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. - The two refusals. A second CMPX leaves
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". - A
value_limits-tagged register unchanged since the CMPX stays inpartial_writes, where the old path dropped it. That refuses more, not less.
- VCC under the narrowed mask. A
Tests: skip-narrow-merge proves one added select and the restore. skip-narrow-new-register, -twice and -inner-save pin the three refusals. None copies a merged value. native_direct_mesh is in the pr preset filter, and CI ran it green at this head.
A merged value is exact for the guard's lanes only in the register it was merged into. Keying the merges by value let a copy of a merged value into another register pass the restore as exact. Record the merged value per register instead, and add the copy fixture from review plus a second merge into the same register. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@lukaslw-lab Thanks, you're right. Fixed in
Tests:
AI-assisted. |
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed de321a36 by reading the diff; not built or run. Re-review after our change request at 5625b205.
Verdict: approve. Merges are now recorded per register, which closes the copy case from our MUST. No MUST.
de321a36keepsskip_narrowing->mergedas register → merged value.- Restore (
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. - Merge branch: it accepts an old value on the same per-register test, so a later write to the copy does not merge against
M.
- Restore (
- Checked, no finding:
- A merged register that is later overwritten without a merge no longer matches its entry, so it is dropped at the restore.
- Writing the copy back (
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. - A second merge into the same register replaces its entry, so the register still carries through to the restore.
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_mesh is in the pr preset filter, and CI is green at this head. The branch merges cleanly with main 158ef794.
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.s_bitset1_b32, then stop at a scalar loop #3703) onmain+ shader: lower s_not_b32, s_brev_b32 and s_bfe_i32 in the mesh frontend #3708 + shader: lower v_rcp_iflag_f32 and v_ashrrev_i32 in the mesh frontend #3709 + shader: keep a mesh lane limit across a nested CMPX skip that closes at the same restore (Part of #3703) #3710 + shader: lower v_cmpx_lg_f32, v_cmpx_gt_f32 and per-lane v_cmpx_gt_u32 in the mesh frontend (Part of #3703) #3729 + shader: carry exact mesh lanes through nested CMPX skips to an EXEC restore (Part of #3703) #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 shader: slot 86 mesh programs set the root SRV stride withs_bitset1_b32, then stop at a scalar loop #3703, chieflyv_cmpx_lt_f32(69, in shader: lower half conversions and three CMPX compares in the mesh frontend (Part of #2413) #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