Skip to content

shader: keep a mesh lane limit across a nested CMPX skip that closes at the same restore (Part of #3703) - #3710

Open
mumba17 wants to merge 1 commit into
R0Y00:mainfrom
mumba17:shader/mesh-nested-skip-lane-limit
Open

mumba17 wants to merge 1 commit into
R0Y00:mainfrom
mumba17:shader/mesh-nested-skip-lane-limit

Conversation

@mumba17

@mumba17 mumba17 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Part of #3703 (item 6). Refs #3641, #3671.

Problem

Many slot 86 mesh programs compute their position in a vertex skip with a nested CMPX skip inside it, and both skips exit to the same EXEC restore:

s_mov_b64 s[36:37], exec
v_cmpx_gt_u32 s40, v0          ; vertex lanes: v0 < V
s_cbranch_execz R
  … v1..v4 = defaults
  v_cmpx_eq_u32 0, v8          ; nested
  s_cbranch_execz R            ; the same exit
    … v1..v4 = position
R: s_mov_b64 exec, s[36:37]
…
v_cmp_gt_u32 vcc, s40, v0      ; the same V
s_and_b64 s[0:1], vcc, s[4:5]
s_and_saveexec_b64 s[0:1], s[0:1]
s_cbranch_execz …
exp pos0 v1, v2, v3, v4        ; refused: graphics register undefined on an incoming path

#3671 lets an export read VGPRs written under a vertex skip when the read is under the same lane count. When the skip closes, it tags the VGPRs with the skip's lane limit (close_skip, retain). That requires the closing skip's guard to be the current lane mask. Here the nested skip closes first at R and leaves its narrowed mask current. So the outer skip was never tagged, and the restore erased v1–v4.

Change

src/gfx1013_direct_mesh.inl:

  • Recording the narrowing. When a nested per-lane skip opens directly after a single CMPX, and that CMPX narrowed the parent skip's guard (mask_parent), the skip records the parent guard (Skip::narrowed_from).
    • Nothing ran under the narrowed mask outside the nested skip.
    • A per-lane skip branches per thread, so after its merge every VGPR is exact for each of the parent's lanes.
  • Carrying it to the parent. When such a skip closes and its parent ends at the same instruction, the parent's guard is carried to the parent's close. There it satisfies retain in place of guard == lane_active. The tag, the restore and check_graphics_read are unchanged from shader: prove mesh VGPRs written under a lane count stay in range at the count export (Part of #2413) #3671, so every later read must still be under a proven bound of the same count.
  • Not carried. Nothing is carried for:
    • a whole-wave nested skip;
    • a narrowing that isn't a CMPX directly before the EXECZ;
    • any write between the CMPX and the EXECZ;
    • another forward path arriving at the restore.

Census

Capture. A native Mesh86 run on main 1c634037, with X2W_REFUSE_FIXED_MESH=1 and X2W_NATIVE_MESH86=1: 1,569 distinct .m86 requests. Each went through compile_dxil … gfx1013-container-ms-texture-heap. Counts only; request bytes stay local.

Translate fully undefined on an incoming path first
main (+ #3706, which changes none of these counts) 267 37
+ this PR 299 5
main + #3706 + #3708 + #3709 389 79
+ this PR 454 14

No program that translated before is refused now. Program by program, 32 go from refused to translated, and none go the other way.

Tests

tests/native_direct_mesh_check.py, built like #3671's bounded-export:

  • Positives. V comes from root constant s21. The vertex skip sets v10 = 1.0, a nested v_cmpx_eq_u32 0, v0 skip sets v10 = 2.0, both exit to the same restore, and the export runs under the count guard.
    • nested-skip-export: restore with exec = -1.
    • nested-skip-saved-exec: restore with s_mov_b64 exec, s[36:37] saved before the skip, as in the title.
    • Both reach storeVertexOutput with both constants.
  • Refusals.
    • nested-skip-write-before-execz (a v_mov between the nested CMPX and its EXECZ) and nested-skip-and-exec (narrowing by v_cmp + s_and_b64 exec): both still stop at graphics register undefined on an incoming path: 266.
    • nested-skip-full-exec (export without the count guard): mesh register read outside its proven lane range: 266.
  • Mutation. With the source change reverted, the check fails at nested-skip-export with undefined on an incoming path: 266.
  • Regression. ctest -R "native_|mesh|gfx1013" -E "hardware|_warp": 786/788 pass. The same two local-only failures as in shader: lower s_not_b32, s_brev_b32 and s_bfe_i32 in the mesh frontend #3708: the SDK validator here supports DXIL 1.7, and those tests emit 1.8.

Environment: Windows 11 build 26300, RTX 3090, MSVC 14.44, DXC from SDK 10.0.26100.

AI-assisted.

🤖 Generated with Claude Code

@mumba17
mumba17 force-pushed the shader/mesh-nested-skip-lane-limit branch from 8280898 to e0fbad9 Compare December 1, 2026 11:38
mumba17 added a commit to mumba17/Xbox2Windows that referenced this pull request Dec 1, 2026
…estore

A chain of per-lane skips, each opened straight after a CMPX that narrows
the skip around it, merges every register per lane when it closes. R0Y00#3710
carried that fact from one nested skip to its parent only, and only when
the parent closed at the same instruction. Skinned mesh programs nest
three such skips inside the vertex skip and close all of them at a restore
of the vertex mask, after which the vertex skip goes on. The restore then
treated every register written since the mask was saved as stale and
cleared it, so the next read refused with "graphics register undefined on
an incoming path".

The carried lane set now passes through any depth of skips closing at one
pc, and an EXEC restore at that pc keeps the register file when the
restored mask is the carried guard of the enclosing skip. The set is tied
to its pc so it never describes a later instruction. A write between the
innermost CMPX and its EXECZ, or a narrowing that is not a CMPX, still
breaks the chain.

Part of R0Y00#3703.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mumba17
mumba17 force-pushed the shader/mesh-nested-skip-lane-limit branch from e0fbad9 to a7d9804 Compare December 1, 2026 17:22

@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 a7d98042 by reading the diff; not built or run.

Verdict: approve. The carried guard is set only for a per-lane skip opened right after a CMPX that narrowed the parent's guard (mask_parent). It is used only when both skips close at the same pc, and only through the existing retain conditions. So every read after the restore still needs #3671's lane-range proof. No MUST.

  • NIT The carried_lane.clear() in the forward-arrival block (gfx1013_direct_mesh.inl:763) never runs while carried_lane is set. Arrivals at pc are merged, and forward.at(pc) erased, before the first close_skip(). return true then re-enters the loop with nothing left to arrive, and merge_edges adds no forward edges. The EXEC-definition refusal and retain's forward.empty() are what actually guard this, so the line could go.
  • NIT The description lists a whole-wave nested skip (wave_active set) as not carried, but no case pins it. Adding one beside nested-skip-and-exec would cover the wave_active.empty() test at :1378.
  • Checked, no finding:
    • Nested skips that end at the same restore. The middle skip cannot retain (skip_parents not empty). Its own narrowed_from is passed on only if its guard is still lane_active after the merge, so the outer skip is otherwise not tagged and the read is refused.
    • last_end == pc. This requires the CMPX to fall through directly into the EXECZ. Instructions that leave the loop through continue don't update last_name, which fails closed.
    • Fixture encodings. 0x7da40080 is v_cmpx_eq_u32 0, v0, and 0x7da80017 is v_cmpx_gt_u32 s23, v0. 0x7d840080, 0x87fe6a7e is v_cmp_eq_u32 then s_and_b64 exec, exec, vcc. 0xf2/0xf4/0xf6 are 1.0/2.0/4.0, and the EXECZ offsets land on the restore.

Tests: the two positives reach storeVertexOutput with both constants, through exec = -1 and through the saved-EXEC restore. The two refusal cases pin the write-before-EXECZ and non-CMPX narrowing exclusions. nested-skip-full-exec keeps the count guard required. native_direct_mesh is in the pr preset filter, and CI ran it green at this head.

…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
mumba17 force-pushed the shader/mesh-nested-skip-lane-limit branch from a7d9804 to 756647a Compare December 2, 2026 07:26
mumba17 added a commit to mumba17/Xbox2Windows that referenced this pull request Dec 2, 2026
…estore

A chain of per-lane skips, each opened straight after a CMPX that narrows
the skip around it, merges every register per lane when it closes. R0Y00#3710
carried that fact from one nested skip to its parent only, and only when
the parent closed at the same instruction. Skinned mesh programs nest
three such skips inside the vertex skip and close all of them at a restore
of the vertex mask, after which the vertex skip goes on. The restore then
treated every register written since the mask was saved as stale and
cleared it, so the next read refused with "graphics register undefined on
an incoming path".

The carried lane set now passes through any depth of skips closing at one
pc, and an EXEC restore at that pc keeps the register file when the
restored mask is the carried guard of the enclosing skip. The set is tied
to its pc so it never describes a later instruction. A write between the
innermost CMPX and its EXECZ, or a narrowing that is not a CMPX, still
breaks the chain.

Part of R0Y00#3703.

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 756647ae by reading the diff; not built or run.

Verdict: approve. This is a rebase onto f365f125. The PR's own change is identical to a7d98042, which I approved. No MUST.

  • I compared a7d98042 with 756647ae using git range-diff. Only context lines from main changed (saveexec_vcc_tests branch, the skip-narrow-inner-save test line); the source and test hunks of the PR itself did not.
  • The earlier NITs still apply and do not block: the dead carried_lane.clear(), and no whole-wave nested-skip control.

Tests: native_direct_mesh (in the pr filter) is green on this head.

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.

2 participants