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

Merged
mumba17 merged 1 commit from upstream-pr/3671 into main 2026-12-01 03:11:51 +00:00
mumba17 commented 2026-11-30 23:38:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-30T23:38:46Z.


Part of #2413 (claim: https://github.com/R0Y00/Xbox2Windows/issues/2413#issuecomment-7294482863).

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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5575794757 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3671). Originally posted by [mumba17](https://github.com/mumba17) on 2026-11-30T23:38:46Z. --- Part of #2413 (claim: https://github.com/R0Y00/Xbox2Windows/issues/2413#issuecomment-7294482863). ## 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](https://claude.com/claude-code)
lukaslw-lab commented 2026-12-01 01:19:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T01:19:14Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6123474831 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3671#pullrequestreview-6123474831). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T01:19:14Z. **Review:** COMMENTED --- 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 commented 2026-12-01 03:11:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-01T03:11:03Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6124497078 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3671#pullrequestreview-6124497078). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-01T03:11:03Z. **Review:** APPROVED --- 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.
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!3671
No description provided.