Repository navigation
shader: prove mesh VGPRs written under a lane count stay in range at the count export (Part of #2413) - #3671
Conversation
…the count export A vertex skip writes the position sources for threads below V. Full EXEC then returns, and the count exchange shares select(V == 0, 0, V). The export reads those sources under the exchanged count. Until now the full-EXEC reset and the exchange erased every partial VGPR, so these reads refused as "graphics register undefined on an incoming path". - Keep a partial VGPR across both erase points when its value carries the lane count that defined it (the existing skip-close tag). Every later read still goes through check_graphics_read. - Track group-uniform values: root constants, the group identifier, and scalar, SMEM, copy, readfirstlane and typed-load results of them. A merge phi is group-uniform only while every scalar branch so far had a group-uniform condition. Stores end the SMEM rule. - Record unsigned bounds: s_cselect_b32 with a zero operand and s_min_u32 are at most their sources. The exchanged count is at most a group-uniform input, because wave zero stored the same value. - check_graphics_read accepts a read whose lane count is bounded by the defining count, in a per-lane or whole-wave skip on lane_active. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed ce6285f2 by reading the diff; not built or run.
Verdict: comment. The bound rules and the group-uniform tagging look sound to me. But keeping partials past full EXEC opens one path that, as I read it, gives a wrong value instead of a refusal. No MUST, because compiler output should rarely hit it. I'd approve once it is closed or shown unreachable.
- SHOULD
keep_bounded_partialsleaves kept registers inpartial_writes. The merge after a VGPR write (src/gfx1013_direct_mesh.inl, thebefore_partialloop near the end) buildsselect(lane_active, new, old)only when the register was not already partial and the old value is untagged. Before this PR, both were cleared at full EXEC. Now, after the exchange, a kept v10 (tagged V) rewritten inside a whole-wave skip on W gets no select, so the threads outside W in that wave also take the new value. At the skip close,merge_edgesmakesphi(T, y)and carries V's tag from the left side. A later read under a guard bounded by V but not inside W passescheck_graphics_read, while hardware keeps T in those lanes. Refusing a partial write over a kept register would close it. A control:bounded-export, plus a v10 write under the export guard, read again under the vertex guard. - Checked, no finding:
at_most:s_cselect_b32with a zero operand,s_min_u32andclamp(input_v)are true unsigned bounds. Signedv_cmpx_gt_i32uses the capped unsigned limit (thread < min(limit, threads)), so a bounded limit gives a subset.- The group-uniform bound is used only at the exchange, which sits between two barriers, so same-group stores after the loads cannot change
input_v. Phis count only in the forward-branch funnel (uniform_join), not at skip or diamond joins. - The whole-wave skip read is safe for the other reads:
v_cmpANDs withlane_active, andv_readfirstlaneonly takes proven-uniform values.
Tests: five fixtures plus six mutations cover the bound, uniformity and guard rules. None rewrites a kept register. CI at this head (23:38 UTC) ran before #3644 put native_direct_mesh into the pr filter, so only your local run covers them.
R0Y00
left a comment
There was a problem hiding this comment.
Reviewed the lane-count bound and group-uniform provenance. Reads of retained partial VGPRs still require a compatible lane guard after full EXEC is restored. ctest --test-dir <build> --no-tests=error -j1 -R '^native_direct_mesh$' --output-on-failure passed in the integration, including the bounded export and the insufficient-bound controls.
…at the same restore The R0Y00#3671 lane-limit proof tags partial VGPRs with the vertex skip's lane count when the skip closes, so an export under the same count may read them after full EXEC returns. It required the closing skip's guard to be the current lane mask. When a nested CMPX skip inside the vertex skip exits to the same EXEC restore, the nested mask is still current at the outer close, so the proof was skipped and the restore erased the position VGPRs ("graphics register undefined on an incoming path"). A nested per-lane skip now records the parent guard when it opens directly after a single CMPX that narrowed it. Nothing ran under the narrowed mask outside that skip, and the skip branches per thread, so after it closes every register is exact for each of the parent's lanes. If the parent then closes at the same instruction, its lane limit applies as before. Any other narrowing, a write between the CMPX and the EXECZ, or another path arriving at the restore keeps the previous behavior. Part of R0Y00#3703 (item 6). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at the same restore The R0Y00#3671 lane-limit proof tags partial VGPRs with the vertex skip's lane count when the skip closes, so an export under the same count may read them after full EXEC returns. It required the closing skip's guard to be the current lane mask. When a nested CMPX skip inside the vertex skip exits to the same EXEC restore, the nested mask is still current at the outer close, so the proof was skipped and the restore erased the position VGPRs ("graphics register undefined on an incoming path"). A nested per-lane skip now records the parent guard when it opens directly after a single CMPX that narrowed it. Nothing ran under the narrowed mask outside that skip, and the skip branches per thread, so after it closes every register is exact for each of the parent's lanes. If the parent then closes at the same instruction, its lane limit applies as before. Any other narrowing, a write between the CMPX and the EXECZ, or another path arriving at the restore keeps the previous behavior. Part of R0Y00#3703 (item 6). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at the same restore The R0Y00#3671 lane-limit proof tags partial VGPRs with the vertex skip's lane count when the skip closes, so an export under the same count may read them after full EXEC returns. It required the closing skip's guard to be the current lane mask. When a nested CMPX skip inside the vertex skip exits to the same EXEC restore, the nested mask is still current at the outer close, so the proof was skipped and the restore erased the position VGPRs ("graphics register undefined on an incoming path"). A nested per-lane skip now records the parent guard when it opens directly after a single CMPX that narrowed it. Nothing ran under the narrowed mask outside that skip, and the skip branches per thread, so after it closes every register is exact for each of the parent's lanes. If the parent then closes at the same instruction, its lane limit applies as before. Any other narrowing, a write between the CMPX and the EXECZ, or another path arriving at the restore keeps the previous behavior. Part of R0Y00#3703 (item 6). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Part of #2413 (claim: #2413 (comment)).
Problem
With the open mesh PRs stacked,
graphics register undefined on an incoming path: Nis the first refusal for 152 of the 454 cached slot 57 requests. This is the classX2W_MESH57_PARTIAL_ZERO=1hides by zero-filling. All 152 share one shape:v_cmpx_gt_u32 sV, v0+ EXECZ: the vertex section writes the position sources for threads below V.s_mov_b64 exec, -1, then the count exchange, which sendssG = s_cselect_b32 0, sV(taken whenmin(V, P) == 0).v_cmpx_gt_i32 sG, v0+ EXECZ, thenexp pos0.The full-EXEC reset and the exchange erased every partial VGPR. The export therefore refused, although its lanes are a subset of the writing lanes.
Change (
src/gfx1013_direct_mesh.inl)Keep bounded partials. At
s_mov_b64 exec, -1and at the end of the count exchange, a partial VGPR survives if its value carries the existing skip-close lane-count tag (value_limits). Untagged partials are still erased. Every later read still goes throughcheck_graphics_read. This is the same rule the saved-mask EXEC restore already applies.Group-uniform values. These are values equal in every thread of the group:
v_mov_b32,v_readfirstlane_b32andbuffer_load_format(index form), when all their inputs are group-uniform, including SCC and descriptor symbols. Descriptors from such an SMEM load count too.A merge phi counts only while every scalar branch so far had a group-uniform condition; a VCC branch or a non-uniform SCC clears that for good. EXEC, getreg/setreg, PC and movrel forms are excluded. After any buffer or image store, SMEM and typed loads stop counting.
Unsigned bounds (
at_most):s_cselect_b32with a zero operand is at most its other operand;s_min_u32is at most either source;input_vwheninput_vis group-uniform, because wave zero stored that same value. It is also clamped. The same holds for primitives.check_graphics_readalso accepts a lane count thatat_mostbounds by the defining count. It now also accepts a whole-wave skip onlane_active, not only a per-lane one. The export guard is a whole-wave skip, and in both kinds lanes outsidelane_activehave no effect. Reads at full EXEC, or under any other guard, still refuse withmesh register read outside its proven lane range.Census
454 cached slot 57 requests, #3416 layout, main plus #3635/#3645/#3646/#3655/#3668:
mesh register read outside its proven lane range. Mostly the primitive export reads a VGPR written in the vertex section (thread < V) under the primitive count. Nothing proves that count is at most V, so the refusal is correct.unmapped mesh export target 13.Tests (
tests/native_direct_mesh_check.py)Fixture
bounded-export: V comes from the root constant in s21, a vertex skip writes v10 for threads below V, full EXEC returns, the count exchange sendsselect(V == 0, 0, V), andexp param0 v10runs underv_cmpx_gt_i32 s34, v0.bounded-export, andbounded-export-root-branch(V merged behind an s21 branch).outside its proven lane range: 266:-wave-v(V from the wave index);-select-4(s_cselect 4, V);-full-exec(no count guard);-wave-branch(V merged behind a wave-index branch).count-*-writer-boundrefusals are unchanged.native_direct_mesh:s_cselecttreated as a bound;ctest -R "mesh|compile_dxil": 204/204.🤖 Generated with Claude Code