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

Manually merged
github merged 1 commit from github-bot/gh-3671 into main 2026-12-01 03:13:20 +00:00 AGit
Owner

@⁠mumba17 on GitHub · 2026-11-30 23:38 UTC · original
mumba17:shader/mesh-lane-range → main · +171 −7 · 2 files · 1 commits · merged 2026-12-01 03:11 UTC

Part of #2413 (claim: #2413).

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, #3418 layout, main plus #3637/#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

**@⁠mumba17** on GitHub · 2026-11-30 23:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3671) `mumba17:shader/mesh-lane-range` → `main` · +171 −7 · 2 files · 1 commits · merged 2026-12-01 03:11 UTC Part of #2413 (claim: https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/2413). ## 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, #3418 layout, main plus #3637/#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](https://claude.com/claude-code)
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 23:42:52 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 01:19 UTC · original · reviewed

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 #3646 put native_direct_mesh into the pr filter, so only your local run covers them.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 01:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3671#pullrequestreview-6123474831) · **reviewed** 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 #3646 put `native_direct_mesh` into the `pr` filter, so only your local run covers them.
github manually merged commit 00677ed619 into main 2026-12-01 03:13:20 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-01 03:11 UTC · original · approved these changes

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** on GitHub · 2026-12-01 03:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3671#pullrequestreview-6124497078) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.