Skip to content

shader: prove mesh VGPRs written under a lane count stay in range at the count export (Part of #2413) - #3671

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
mumba17:shader/mesh-lane-range
Dec 1, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
mumba17:shader/mesh-lane-range

Conversation

@mumba17

@mumba17 mumba17 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Part of #2413 (claim: #2413 (comment)).

Problem

With the open mesh PRs stacked, graphics register undefined on an incoming path: N is the first refusal for 152 of the 454 cached slot 57 requests. This is the class X2W_MESH57_PARTIAL_ZERO=1 hides by zero-filling. All 152 share one shape:

  1. v_cmpx_gt_u32 sV, v0 + EXECZ: the vertex section writes the position sources for threads below V.
  2. s_mov_b64 exec, -1, then the count exchange, which sends sG = s_cselect_b32 0, sV (taken when min(V, P) == 0).
  3. v_cmpx_gt_i32 sG, v0 + EXECZ, then exp 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, -1 and 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 through check_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:

    • root constants and the group identifier;
    • results of SOP1/SOP2/SOPK/SOPC, SMEM loads, v_mov_b32, v_readfirstlane_b32 and buffer_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_b32 with a zero operand is at most its other operand;
    • s_min_u32 is at most either source;
    • the exchanged count is at most input_v when input_v is group-uniform, because wave zero stored that same value. It is also clamped. The same holds for primitives.
  • check_graphics_read also accepts a lane count that at_most bounds by the defining count. It now also accepts a whole-wave skip on lane_active, not only a per-lane one. The export guard is a whole-wave skip, and in both kinds lanes outside lane_active have no effect. Reads at full EXEC, or under any other guard, still refuse with mesh register read outside its proven lane range.

Census

454 cached slot 57 requests, #3416 layout, main plus #3635/#3645/#3646/#3655/#3668:

  • The 152 requests leave this refusal; none still stops at it.
  • 143 of them now stop at a later offset.
  • 147 now stop at 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.
  • 5 stop at unmapped mesh export target 13.
  • No other request's result changes.

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 sends select(V == 0, 0, V), and exp param0 v10 runs under v_cmpx_gt_i32 s34, v0.

  • Positives: bounded-export, and bounded-export-root-branch (V merged behind an s21 branch).
  • Refusals, each 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).
  • The existing count-*-writer-bound refusals are unchanged.
  • Mutations: each fails native_direct_mesh:
    • no exchange bound;
    • every value treated as group-uniform;
    • any s_cselect treated as a bound;
    • all partials erased (the old behaviour);
    • merge phis marked without checking the branch condition;
    • per-lane skips only.

ctest -R "mesh|compile_dxil": 204/204.

🤖 Generated with Claude Code

…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 lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_partials leaves kept registers in partial_writes. The merge after a VGPR write (src/gfx1013_direct_mesh.inl, the before_partial loop near the end) builds select(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_edges makes phi(T, y) and carries V's tag from the left side. A later read under a guard bounded by V but not inside W passes check_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_b32 with a zero operand, s_min_u32 and clamp(input_v) are true unsigned bounds. Signed v_cmpx_gt_i32 uses 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_cmp ANDs with lane_active, and v_readfirstlane only 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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@R0Y00
R0Y00 merged commit 00677ed into R0Y00:main Dec 1, 2026
5 checks passed
mumba17 added a commit to mumba17/Xbox2Windows that referenced this pull request Dec 1, 2026
…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>
mumba17 added a commit to mumba17/Xbox2Windows that referenced this pull request Dec 1, 2026
…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>
mumba17 added a commit to mumba17/Xbox2Windows that referenced this pull request Dec 2, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants