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

Merged
mumba17 merged 1 commit from upstream-pr/3710 into main 2026-12-02 20:45:32 +00:00
mumba17 commented 2026-12-01 08:27:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T08:27:44Z.


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 #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 #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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5581917300 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3710). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-01T08:27:44Z. --- 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 #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 #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](https://claude.com/claude-code)
lukaslw-lab commented 2026-12-01 18:51:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T18:51:47Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6137847960 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3710#pullrequestreview-6137847960). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T18:51:47Z. **Review:** APPROVED --- 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.
lukaslw-lab commented 2026-12-02 07:42:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T07:42:10Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6146557096 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3710#pullrequestreview-6146557096). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T07:42:10Z. **Review:** APPROVED --- 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.
lukaslw-lab commented 2026-12-02 09:35:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T09:35:49Z.

Review: APPROVED


Reviewed a2d83177 by git range-diff against 756647ae; not built or run.

Verdict: approve. This is a rebase onto 45c809ab (after #3806). The only change is #3806's inputs → incoming rename in the context of this PR's carried_lane.clear() line, which is kept. No MUST.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6148172485 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3710#pullrequestreview-6148172485). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T09:35:49Z. **Review:** APPROVED --- Reviewed `a2d83177` by `git range-diff` against `756647ae`; not built or run. **Verdict: approve.** This is a rebase onto `45c809ab` (after #3806). The only change is #3806's `inputs` → `incoming` rename in the context of this PR's `carried_lane.clear()` line, which is kept. No MUST.
R0Y00 commented 2026-12-02 20:45:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T20:45:00Z.

Review: APPROVED


Reviewed 43791423. The carried mask can only substitute for the matching parent guard when adjacent CMPX and EXECZ open the nested lane skip, and both skips end at the same PC. The existing export lane-range check remains in place. Independent Windows 11 build 26300, MSVC Debug cmake --build --preset dev --target compile_dxil and ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^native_direct_mesh$' passed. That fixture includes both restore forms, the intervening-write and non-CMPX refusals, and the full-EXEC refusal for the out-of-range export.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6158679404 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3710#pullrequestreview-6158679404). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T20:45:00Z. **Review:** APPROVED --- Reviewed `43791423`. The carried mask can only substitute for the matching parent guard when adjacent CMPX and EXECZ open the nested lane skip, and both skips end at the same PC. The existing export lane-range check remains in place. Independent Windows 11 build 26300, MSVC Debug `cmake --build --preset dev --target compile_dxil` and `ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^native_direct_mesh$'` passed. That fixture includes both restore forms, the intervening-write and non-CMPX refusals, and the full-EXEC refusal for the out-of-range export.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3710
No description provided.