shader: refuse mesh VGPRs written under a narrowed EXEC and read after the count exchange #3422

Merged
Leyukaka merged 1 commit from upstream-pr/3422 into main 2026-11-29 08:38:31 +00:00
Leyukaka commented 2026-11-29 00:31:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T00:31:26Z.


Change

The count-exchange matcher in lower_mesh accepts a narrowed incoming EXEC and then sets full_exec=true, but it left partial_writes as it was. A VGPR first written under the narrowed EXEC therefore kept its narrowed definition after the exchange, and a vertex export after the exchange read it for every vertex up to the exchanged count.

This change adds, after full_exec=true; ... in the matcher (src/gfx1013_direct_mesh.inl:446-447):

for (auto r : partial_writes) alu.write(r,{});
partial_writes.clear();

This is the same pair the explicit s_mov_b64 exec, -1 (0xbefe04c1) reset runs at :900-901. The exchange consumes its own trailing befe04c1 inside the matcher, so that reset never ran there. partial_writes only holds registers with no prior full value (:1106-1111 merges a partial write over an existing value with a lane select and removes it from the set), so only VGPRs first defined under a narrowed EXEC are invalidated. A later read of one raises the existing diagnostic graphics register undefined on an incoming path: <r> (src/gfx1013_direct_compute.inl:113).

Trade-off: the rule ignores the vertex count. When the count equals the writer bound, every exported lane executed the write and the translated value would be correct, but that case is now refused too. This is conservative and fails closed. A later change could prove the min(count, bound) relation and accept that case.

Tests (tests/native_direct_mesh_check.py): two probes write v10 with v_cndmask_b32 under v_cmpx_gt_u32 s23, v0 (threads 0..2), run the unchanged count exchange, then export v10 as PARAM0. count-exceeds-writer-bound uses vertex count 4, count-equals-writer-bound uses 3. Both assert a nonzero exit, a stderr ending in graphics register undefined on an incoming path: 266 (256 + 10 = v10) and no DXIL file. run() is split into compile_mesh() and run() with the same behavior.

Refs #2413, #3416 (last claimed item; the control showed the count-4 case translating, so this adds the refusal as well).

Verification

Base main 51472392, release build.

  • Before the fix, with the probes recording the outcome: ctest --test-dir out\build\release --no-tests=error --output-on-failure -V -R "^native_direct_mesh$" passed and printed count-exceeds-writer-bound: translated and count-equals-writer-bound: translated.
  • dxc -dumpbin of the count-4 probe's DXIL: v10 is select i1 %t48, i32 1065353216, i32 0 computed for every thread, the cmpx guard (icmp ult i32 %t0, %t27) is never used to merge it, and the PARAM0 export is guarded only by icmp ult i32 %t0, %t53 where %t53 is the exchanged count (4). Vertex 3 exports 0.0. In the guest, lane 3 skipped the v_cndmask_b32, so its v10 holds a value the guest never wrote.
  • After the fix, both probes:
    count-exceeds-writer-bound: refused: native compute +0xe8: graphics register undefined on an incoming path: 266
    count-equals-writer-bound: refused: native compute +0xe8: graphics register undefined on an incoming path: 266
    
  • Mutation: with the two added lines removed (main's .inl), the count-4 probe compiles (exit 0, 4177 bytes) and native_direct_mesh fails with AssertionError: ('count-exceeds-writer-bound', ...). Main's .inl with main's test file passes.
  • Selection -R "native_direct_mesh|native_compile_dxil_refusals|native_fixed_mesh57.*" (22 tests): same results with the fix and with main's .inl, except native_direct_mesh (passes with the fix, fails on main's .inl as above). native_fixed_mesh57_waterfall_fine_hardware fails in both with native slot57 mesh efb95ca628778f2c refused: profile input bytes differ.
  • ctest --test-dir out/build/release --no-tests=error -R mesh with the fix (170 tests): 167 pass, 1 fails, 2 skipped. native_fixed_mesh57_waterfall_fine_hardware fails with profile input bytes differ (pre-existing, also fails on main); mesh_two_exits_hardware and mesh_two_exits_warp skip (requires LLVM 15 with AMDGPU). No existing accepted fixture reads such a register across the exchange.

Evidence and follow-up

Not covered:

  • The min(count, bound) relation that would let the count == bound case translate.
  • The explicit reset (:897-903) also calls export_limit.clear() (:899); the matcher still does not. Not examined.
  • The effect on the 543 captured slot 57 requests is not measured.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (no capability or build change)
  • No application files, dumps, distribution links or secrets included.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5546053622 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3422). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T00:31:26Z. --- ## Change The count-exchange matcher in `lower_mesh` accepts a narrowed incoming EXEC and then sets `full_exec=true`, but it left `partial_writes` as it was. A VGPR first written under the narrowed EXEC therefore kept its narrowed definition after the exchange, and a vertex export after the exchange read it for every vertex up to the exchanged count. This change adds, after `full_exec=true; ...` in the matcher (`src/gfx1013_direct_mesh.inl:446-447`): ```cpp for (auto r : partial_writes) alu.write(r,{}); partial_writes.clear(); ``` This is the same pair the explicit `s_mov_b64 exec, -1` (`0xbefe04c1`) reset runs at `:900-901`. The exchange consumes its own trailing `befe04c1` inside the matcher, so that reset never ran there. `partial_writes` only holds registers with no prior full value (`:1106-1111` merges a partial write over an existing value with a lane select and removes it from the set), so only VGPRs first defined under a narrowed EXEC are invalidated. A later read of one raises the existing diagnostic `graphics register undefined on an incoming path: <r>` (`src/gfx1013_direct_compute.inl:113`). Trade-off: the rule ignores the vertex count. When the count equals the writer bound, every exported lane executed the write and the translated value would be correct, but that case is now refused too. This is conservative and fails closed. A later change could prove the `min(count, bound)` relation and accept that case. Tests (`tests/native_direct_mesh_check.py`): two probes write v10 with `v_cndmask_b32` under `v_cmpx_gt_u32 s23, v0` (threads 0..2), run the unchanged count exchange, then export v10 as PARAM0. `count-exceeds-writer-bound` uses vertex count 4, `count-equals-writer-bound` uses 3. Both assert a nonzero exit, a stderr ending in `graphics register undefined on an incoming path: 266` (256 + 10 = v10) and no DXIL file. `run()` is split into `compile_mesh()` and `run()` with the same behavior. Refs #2413, #3416 (last claimed item; the control showed the count-4 case translating, so this adds the refusal as well). ## Verification Base `main` `51472392`, release build. - Before the fix, with the probes recording the outcome: `ctest --test-dir out\build\release --no-tests=error --output-on-failure -V -R "^native_direct_mesh$"` passed and printed `count-exceeds-writer-bound: translated` and `count-equals-writer-bound: translated`. - `dxc -dumpbin` of the count-4 probe's DXIL: v10 is `select i1 %t48, i32 1065353216, i32 0` computed for every thread, the cmpx guard (`icmp ult i32 %t0, %t27`) is never used to merge it, and the PARAM0 export is guarded only by `icmp ult i32 %t0, %t53` where `%t53` is the exchanged count (4). Vertex 3 exports 0.0. In the guest, lane 3 skipped the `v_cndmask_b32`, so its v10 holds a value the guest never wrote. - After the fix, both probes: ``` count-exceeds-writer-bound: refused: native compute +0xe8: graphics register undefined on an incoming path: 266 count-equals-writer-bound: refused: native compute +0xe8: graphics register undefined on an incoming path: 266 ``` - Mutation: with the two added lines removed (main's `.inl`), the count-4 probe compiles (exit 0, 4177 bytes) and `native_direct_mesh` fails with `AssertionError: ('count-exceeds-writer-bound', ...)`. Main's `.inl` with main's test file passes. - Selection `-R "native_direct_mesh|native_compile_dxil_refusals|native_fixed_mesh57.*"` (22 tests): same results with the fix and with main's `.inl`, except `native_direct_mesh` (passes with the fix, fails on main's `.inl` as above). `native_fixed_mesh57_waterfall_fine_hardware` fails in both with `native slot57 mesh efb95ca628778f2c refused: profile input bytes differ`. - `ctest --test-dir out/build/release --no-tests=error -R mesh` with the fix (170 tests): 167 pass, 1 fails, 2 skipped. `native_fixed_mesh57_waterfall_fine_hardware` fails with `profile input bytes differ` (pre-existing, also fails on main); `mesh_two_exits_hardware` and `mesh_two_exits_warp` skip (`requires LLVM 15 with AMDGPU`). No existing accepted fixture reads such a register across the exchange. ## Evidence and follow-up Not covered: - The `min(count, bound)` relation that would let the count == bound case translate. - The explicit reset (`:897-903`) also calls `export_limit.clear()` (`:899`); the matcher still does not. Not examined. - The effect on the 543 captured slot 57 requests is not measured. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [ ] I updated README/docs when a capability or build requirement changed. (no capability or build change) - [x] No application files, dumps, distribution links or secrets included.
tedin7 commented 2026-11-29 08:38:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-29T08:38:28Z.

Review: COMMENTED


Reviewed 0ceb1bcdd71393c48e9d090288165c23a2014334:

  • src/gfx1013_direct_mesh.inl: clears all partial_writes registers in alu and empties partial_writes when restoring full_exec = true on mesh allocation/exchange, preventing VGPRs written under a narrowed EXEC from remaining valid after EXEC is restored.
  • tests/native_direct_mesh_check.py: adds count-exceeds-writer-bound and count-equals-writer-bound negative controls verifying both refuse with graphics register undefined on an incoming path: 266.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 0ceb1bcdd71393c48e9d090288165c23a2014334:

  • ctest --preset dev -R '^native_direct_mesh$' --parallel 2 --no-tests=error --output-on-failure: 1/1 passed (1.14s)
  • ctest --preset release -R '^native_direct_mesh$' --parallel 2 --no-tests=error --output-on-failure: 1/1 passed (1.18s)

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6102114220 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3422#pullrequestreview-6102114220). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-29T08:38:28Z. **Review:** COMMENTED --- Reviewed `0ceb1bcdd71393c48e9d090288165c23a2014334`: - `src/gfx1013_direct_mesh.inl`: clears all `partial_writes` registers in `alu` and empties `partial_writes` when restoring `full_exec = true` on mesh allocation/exchange, preventing VGPRs written under a narrowed EXEC from remaining valid after EXEC is restored. - `tests/native_direct_mesh_check.py`: adds `count-exceeds-writer-bound` and `count-equals-writer-bound` negative controls verifying both refuse with `graphics register undefined on an incoming path: 266`. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `0ceb1bcdd71393c48e9d090288165c23a2014334`: - `ctest --preset dev -R '^native_direct_mesh$' --parallel 2 --no-tests=error --output-on-failure`: **1/1 passed** (`1.14s`) - `ctest --preset release -R '^native_direct_mesh$' --parallel 2 --no-tests=error --output-on-failure`: **1/1 passed** (`1.18s`) AI-assisted; commands listed were executed locally.
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!3422
No description provided.