xshader: a guarded mesh half result does not read the launch bits no reader takes #268

Merged
NickStallman merged 1 commit from upstream-pr/268 into main 2026-11-26 21:27:17 +00:00
NickStallman commented 2026-11-26 20:23:31 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-26T20:23:31Z.


What was refused: 99 ProjectScarlett mesh programs, with unsupported mesh launch register v7 (59) or v6 (40). That is every request in those two groups.

Cause: each program first writes the register with a VOP1 v_cvt_f16_f32, and some write v8 the same way. On RDNA2 a 16-bit result writes bits 15:0 and keeps 31:16. live_in takes the registers read before they are written in program order, so it counts that write as a read of the launch value in v6, v7 or v8. In fact no result takes those bits. Every later reader is a v_cvt_f32_f16 or a v_pack_b32_f16 without op_sel, which reads bits 15:0 only. In some programs a v_cvt_f32_f16 replaces the whole register before the vertex exports read it.

In all 99 programs the write sits inside the vertex-count guard: s_mov_b64 s[44:45], exec; v_cmpx_gt_u32 s46, v0; s_cbranch_execz to s_mov_b64 exec, s[44:45]. s46 (or s38) is the vertex count mesh_exports already recognises. So lanes past the count, which keep the full launch value, never execute the write or any reader.

Change:

  • kept_half_unread(program, reg, exports) accepts a launch register only when that holds. The proof covers the whole program, export sequence included, and is relative to live_in's program order: EXEC saves and restores pair up in that order, and each branch is checked against it.
    • The 16-bit write is in the block that the vertex-count guard opens and closes. The guard tests exports.vertices against exports.lane_index, and neither register is rewritten after it.
    • The guard is the last EXEC change before the write. Up to the export sequence, EXEC only narrows (v_cmpx_*, s_and_saveexec_b64) or returns to a value saved since the block opened. Inside the block, that value must have been saved after the guard.
    • No branch crosses the guard or the write except the guard's own s_cbranch_execz, which is taken only when no lane is active.
    • After the block, nothing touches the register until the vertex exports, which test the same count against the same lane. MeshExports now records where they start (vertex_start); nothing else in mesh_exports.rs changes.
    • Each reader after the write takes the low half, up to a full 32-bit write that no path leaves early or comes back into. No register range (loads, stores, 64-bit and DPP operands) may hold the register without naming it.
  • Any other shape is still refused, including a write outside the guard. The translation starts the kept bits at zero, as before.

Measured on the recorded ProjectScarlett requests, CPU only, without the game, against main at 68e79b7. The command was tools/triage_scarlett_shaders.py <requests> --xshader <branch> --baseline <main> --aggregate-only. The archive grew during the run, because a game run was recording: 24,848 requests for the triage, 24,866 for the byte comparison.

translated refused failed
main 22,865 1,887 96
this branch 22,964 1,788 96
  • 99 recovered (all mesh_launch: 59 v7, 40 v6), 0 regressed. The 96 failures are the .wave32 requests, which the triage tool cannot snapshot (invalid_input); main fails them too.
  • A separate run of both builds over every request, .wave32 included, gave byte-identical HLSL and profile for all 22,970 requests that main translates, and the same message for all 1,797 that both refuse.
  • The 99 new outputs compile with Linux DXC 1.8.2505.1 (ms_6_6, -E main) and pass DXV.
  • All 99 keep separate counts (s46/s48 or s38/s40). The single-count shape from 68e79b7 is covered by unit tests only.

Tests: unit tests in tests/hlsl/mesh.rs:

  • Accepted: the guarded shape of the 99 programs, including a narrower nested block and a primitive-count block after the guard. It is also accepted ahead of a 128-vertex export sequence with separate counts (s46 for vertices, s48 for primitives, as in the recorded programs), as returned by mesh_exports::recognize, with v7 read by the position export. The same program with the guard on s48 is refused.
  • Accepted ahead of the single-count export sequence from 68e79b7 (guard on the shared count against the lane). Refused there for a guard on another register or lane, a count rewritten before the exports, a read after the block, a ds_swizzle_b32 of the register, and a read in the primitive part.
  • Refused:
    • (A) s_cbranch_scc0 from before the 16-bit write to after the full write.
    • (B) s_and_saveexec_b64 before the write, with EXEC restored after the full write.
    • (C) the same with v_cmpx.
    • (D) EXEC narrowed around the 16-bit write only, then a low-half read.
    • Each of A to D both with and without the guard around it.
    • No guard at all.
    • A guard on the primitive count, or on another lane.
    • The count or the lane rewritten after the guard.
    • The block's restore run early, or s_mov_b64 exec, -1 inside the block.
    • A read after the block.
    • A read in the primitive part of the exports.
    • A branch from after the block back into it.
  • Kept from before: low-half readers, op_sel, accumulating writes, register ranges, and branches or EXEC changes inside the span.

cargo test --locked --target x86_64-unknown-linux-gnu in tools/shader-compiler: 380 + 2 passed. python -m unittest discover -s tests -q: 380 tests, OK (18 skipped).

  • python tuxbox.py check passed on this branch: passed on the earlier base (below); re-running on the rebase.
  • This changes code both vendors run, and the check passed on an AMD and an NVIDIA card:
    • AMD Raphael iGPU (1002:13c0), RADV (Mesa 26.0.8), GE-Proton11-14: full python tuxbox.py check --adapter 1002:13c0 --proton … --prefix … --windows-dxc … passed, 112 gates. That covers Lanes and the fixtures, the D3D12 regression controls and the translator GPU checks.
    • RTX 5090 (10de:2b85), driver 620.70.10, GE-Proton11-14: the same full check passed, 112 gates.
    • Both ran on the branch's earlier base, facfaab. Since then, it has been rebased onto 68e79b7, whose mesh export changes it now builds on. Full checks on the rebased commit are running, and I'll update these lines when they finish.
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below

Lanes / translator GPU check: none, for three reasons.

  • Nothing runs a translated console mesh program on the GPU today.
    • tools/check_translator_gpu.py runs compute programs only.
    • The Lanes fixtures (shader_fixture.py, raster_fixture.py) are compute, vertex and pixel programs.
    • check_frosty_mesh.py and the d3d12-mesh suite dispatch desktop DXIL mesh shaders.
    • check_frosty_nanite_mesh.py needs Frosty's retail archive.
  • A synthetic case would need a new 128-vertex mesh fixture that passes mesh_exports::recognize and mesh_bindings::read: the full GS_ALLOC_REQ and export sequence, PSV mesh info, PSG1, a position signature and a MeshLayout binding table. It would also need a mesh pipeline with pixel readback in Lanes.
  • On main such a scenario would fail only because xshader refuses the program, and the unit tests already show that. The emitted code is unchanged, and its kept bits start at zero as before. A GPU readback could not tell zero from launch bits that, by the proof, never reach an output.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5516670274 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/268). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-26T20:23:31Z. --- **What was refused:** 99 ProjectScarlett mesh programs, with `unsupported mesh launch register v7` (59) or `v6` (40). That is every request in those two groups. **Cause:** each program first writes the register with a VOP1 `v_cvt_f16_f32`, and some write v8 the same way. On RDNA2 a 16-bit result writes bits 15:0 and keeps 31:16. `live_in` takes the registers read before they are written in program order, so it counts that write as a read of the launch value in v6, v7 or v8. In fact no result takes those bits. Every later reader is a `v_cvt_f32_f16` or a `v_pack_b32_f16` without op_sel, which reads bits 15:0 only. In some programs a `v_cvt_f32_f16` replaces the whole register before the vertex exports read it. In all 99 programs the write sits inside the vertex-count guard: `s_mov_b64 s[44:45], exec; v_cmpx_gt_u32 s46, v0; s_cbranch_execz` to `s_mov_b64 exec, s[44:45]`. `s46` (or `s38`) is the vertex count `mesh_exports` already recognises. So lanes past the count, which keep the full launch value, never execute the write or any reader. **Change:** - `kept_half_unread(program, reg, exports)` accepts a launch register only when that holds. The proof covers the whole program, export sequence included, and is relative to `live_in`'s program order: EXEC saves and restores pair up in that order, and each branch is checked against it. - The 16-bit write is in the block that the vertex-count guard opens and closes. The guard tests `exports.vertices` against `exports.lane_index`, and neither register is rewritten after it. - The guard is the last EXEC change before the write. Up to the export sequence, EXEC only narrows (`v_cmpx_*`, `s_and_saveexec_b64`) or returns to a value saved since the block opened. Inside the block, that value must have been saved after the guard. - No branch crosses the guard or the write except the guard's own `s_cbranch_execz`, which is taken only when no lane is active. - After the block, nothing touches the register until the vertex exports, which test the same count against the same lane. `MeshExports` now records where they start (`vertex_start`); nothing else in `mesh_exports.rs` changes. - Each reader after the write takes the low half, up to a full 32-bit write that no path leaves early or comes back into. No register range (loads, stores, 64-bit and DPP operands) may hold the register without naming it. - Any other shape is still refused, including a write outside the guard. The translation starts the kept bits at zero, as before. **Measured** on the recorded ProjectScarlett requests, CPU only, without the game, against `main` at 68e79b7. The command was `tools/triage_scarlett_shaders.py <requests> --xshader <branch> --baseline <main> --aggregate-only`. The archive grew during the run, because a game run was recording: 24,848 requests for the triage, 24,866 for the byte comparison. | | translated | refused | failed | | --- | ---: | ---: | ---: | | `main` | 22,865 | 1,887 | 96 | | this branch | 22,964 | 1,788 | 96 | - 99 recovered (all `mesh_launch`: 59 v7, 40 v6), 0 regressed. The 96 failures are the `.wave32` requests, which the triage tool cannot snapshot (`invalid_input`); `main` fails them too. - A separate run of both builds over every request, `.wave32` included, gave byte-identical HLSL and profile for all 22,970 requests that `main` translates, and the same message for all 1,797 that both refuse. - The 99 new outputs compile with Linux DXC 1.8.2505.1 (`ms_6_6`, `-E main`) and pass DXV. - All 99 keep separate counts (s46/s48 or s38/s40). The single-count shape from 68e79b7 is covered by unit tests only. **Tests:** unit tests in `tests/hlsl/mesh.rs`: - Accepted: the guarded shape of the 99 programs, including a narrower nested block and a primitive-count block after the guard. It is also accepted ahead of a 128-vertex export sequence with separate counts (s46 for vertices, s48 for primitives, as in the recorded programs), as returned by `mesh_exports::recognize`, with v7 read by the position export. The same program with the guard on s48 is refused. - Accepted ahead of the single-count export sequence from 68e79b7 (guard on the shared count against the lane). Refused there for a guard on another register or lane, a count rewritten before the exports, a read after the block, a `ds_swizzle_b32` of the register, and a read in the primitive part. - Refused: - (A) `s_cbranch_scc0` from before the 16-bit write to after the full write. - (B) `s_and_saveexec_b64` before the write, with EXEC restored after the full write. - (C) the same with `v_cmpx`. - (D) EXEC narrowed around the 16-bit write only, then a low-half read. - Each of A to D both with and without the guard around it. - No guard at all. - A guard on the primitive count, or on another lane. - The count or the lane rewritten after the guard. - The block's restore run early, or `s_mov_b64 exec, -1` inside the block. - A read after the block. - A read in the primitive part of the exports. - A branch from after the block back into it. - Kept from before: low-half readers, op_sel, accumulating writes, register ranges, and branches or EXEC changes inside the span. `cargo test --locked --target x86_64-unknown-linux-gnu` in `tools/shader-compiler`: 380 + 2 passed. `python -m unittest discover -s tests -q`: 380 tests, OK (18 skipped). - [ ] `python tuxbox.py check` passed on this branch: passed on the earlier base (below); re-running on the rebase. - [x] This changes code both vendors run, and the check passed on an AMD and an NVIDIA card: - AMD Raphael iGPU (1002:13c0), RADV (Mesa 26.0.8), GE-Proton11-14: full `python tuxbox.py check --adapter 1002:13c0 --proton … --prefix … --windows-dxc …` passed, 112 gates. That covers Lanes and the fixtures, the D3D12 regression controls and the translator GPU checks. - RTX 5090 (10de:2b85), driver 620.70.10, GE-Proton11-14: the same full check passed, 112 gates. - Both ran on the branch's earlier base, `facfaab`. Since then, it has been rebased onto 68e79b7, whose mesh export changes it now builds on. Full checks on the rebased commit are running, and I'll update these lines when they finish. - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below **Lanes / translator GPU check:** none, for three reasons. - Nothing runs a translated console mesh program on the GPU today. - `tools/check_translator_gpu.py` runs compute programs only. - The Lanes fixtures (`shader_fixture.py`, `raster_fixture.py`) are compute, vertex and pixel programs. - `check_frosty_mesh.py` and the `d3d12-mesh` suite dispatch desktop DXIL mesh shaders. - `check_frosty_nanite_mesh.py` needs Frosty's retail archive. - A synthetic case would need a new 128-vertex mesh fixture that passes `mesh_exports::recognize` and `mesh_bindings::read`: the full GS_ALLOC_REQ and export sequence, PSV mesh info, PSG1, a position signature and a MeshLayout binding table. It would also need a mesh pipeline with pixel readback in Lanes. - On `main` such a scenario would fail only because `xshader` refuses the program, and the unit tests already show that. The emitted code is unchanged, and its kept bits start at zero as before. A GPU readback could not tell zero from launch bits that, by the proof, never reach an output. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Valdi320 commented 2026-11-26 21:06:07 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Valdi320 on 2026-11-26T21:06:07Z.


Independent synthetic GPU check of #268 integrated with #266 and #272: github.com/Valdi320/TuxBox@b9d796e8ee. Added 3 guarded FP16->FP32 position-export fixtures (3/67/128 vertices). The previous compiler at 86cd032 refuses each with 'unsupported mesh launch register v7'; the combined compiler translates all three. RTX 4080 / GE-Proton11-14: 28/28 draws, 1792/1792 exact readback words (including 6 new half-register draws, full and clipped scissor). All six non-GPU groups passed before adding the small Python fixture unit test, which also passes. Scope is actual translated geometry on desktop D3D12, not Xbox root replacement or retail shader equivalence.

<!-- greyfinch-sync:brcly/TuxBox:comment:7203390526 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/268#issuecomment-7203390526). Originally posted by [Valdi320](https://github.com/Valdi320) on 2026-11-26T21:06:07Z. --- Independent synthetic GPU check of #268 integrated with #266 and #272: https://github.com/Valdi320/TuxBox/tree/b9d796e8ee8147ee4a36c4353f979f17d11ee238. Added 3 guarded FP16->FP32 position-export fixtures (3/67/128 vertices). The previous compiler at 86cd032 refuses each with 'unsupported mesh launch register v7'; the combined compiler translates all three. RTX 4080 / GE-Proton11-14: 28/28 draws, 1792/1792 exact readback words (including 6 new half-register draws, full and clipped scissor). All six non-GPU groups passed before adding the small Python fixture unit test, which also passes. Scope is actual translated geometry on desktop D3D12, not Xbox root replacement or retail shader equivalence.
NickStallman commented 2026-11-26 21:14:49 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-26T21:14:49Z.


Rebased onto 68e79b7. The only conflict was in tests/hlsl/mesh.rs, where both changes appended tests. Both are kept, and the single-count fixture is now a const so another test can reuse it.

kept_half_unread is unchanged:

  • It never reads the primitive count.
  • With one count, the vertex exports still test that register against the lane, so a guard on it covers the same lanes.
  • The allocation's s_cmpk_gt_u32 on the count isn't taken as a write. Removing that exclusion makes the new test fail.

New test: the guarded shape ahead of the single-count sequence is accepted. It's refused for:

  • a guard on another register or lane;
  • a count rewritten before the exports;
  • a read after the block;
  • a ds_swizzle_b32 of the register;
  • a read in the primitive part. That one would be safe with one count, but the proof stops at the vertex exports.

Re-measured against 68e79b7: 99 recovered, 0 regressed, and every other output byte-identical. The numbers are in the description. None of the 99 uses the single-count shape. The full GPU checks in the description ran on the old base. They're running again on the rebase on AMD and NVIDIA, and I'll update the description when they finish.

<!-- greyfinch-sync:brcly/TuxBox:comment:7203535504 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/268#issuecomment-7203535504). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-26T21:14:49Z. --- Rebased onto 68e79b7. The only conflict was in `tests/hlsl/mesh.rs`, where both changes appended tests. Both are kept, and the single-count fixture is now a `const` so another test can reuse it. `kept_half_unread` is unchanged: - It never reads the primitive count. - With one count, the vertex exports still test that register against the lane, so a guard on it covers the same lanes. - The allocation's `s_cmpk_gt_u32` on the count isn't taken as a write. Removing that exclusion makes the new test fail. New test: the guarded shape ahead of the single-count sequence is accepted. It's refused for: - a guard on another register or lane; - a count rewritten before the exports; - a read after the block; - a `ds_swizzle_b32` of the register; - a read in the primitive part. That one would be safe with one count, but the proof stops at the vertex exports. Re-measured against 68e79b7: 99 recovered, 0 regressed, and every other output byte-identical. The numbers are in the description. None of the 99 uses the single-count shape. The full GPU checks in the description ran on the old base. They're running again on the rebase on AMD and NVIDIA, and I'll update the description when they finish.
NickStallman commented 2026-11-26 21:20:32 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-26T21:20:32Z.


Thanks @Valdi320, that covers what I couldn't: a translated mesh program drawing on the GPU. The three guarded fixtures are a good shape for a Lanes scenario if mesh pipelines get one.

<!-- greyfinch-sync:brcly/TuxBox:comment:7203631884 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/268#issuecomment-7203631884). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-26T21:20:32Z. --- Thanks @Valdi320, that covers what I couldn't: a translated mesh program drawing on the GPU. The three guarded fixtures are a good shape for a Lanes scenario if mesh pipelines get one.
Valdi320 commented 2026-11-26 21:27:48 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Valdi320 on 2026-11-26T21:27:48Z.


Following your suggestion, I replaced the records-only desktop mesh fixture in the combined #266/#268/#272 verification branch with synthetic RDNA2 NGG (67 vertices, guarded half-to-float position exports). The worker must now compile BOTH mesh and pixel stages against the reflected root; the gate checks that every loaded stage digest matches a worker receipt and rejects rootless/stand-in paths. github.com/Valdi320/TuxBox@c0a663e1af

Same rebuilt provider and Lanes executable, RTX 4080 / GE-Proton11-14, isolated prefixes, null pipelines disabled: A/B with compiler 86cd032 (before #268) vs combined compiler: raster-tables and raster-samplers pass both; mesh-samplers and mesh-sampler-single fail with missing mesh shader before, pass after. All six no-GPU groups passed, including updated negative tests. The final C++ change is comments only. This is a combined test branch, not a standalone PR or a title replay. Native AMD verification and rebase against your newest head remain outstanding. Thanks for the suggestion.

<!-- greyfinch-sync:brcly/TuxBox:comment:7203750606 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/268#issuecomment-7203750606). Originally posted by [Valdi320](https://github.com/Valdi320) on 2026-11-26T21:27:48Z. --- Following your suggestion, I replaced the records-only desktop mesh fixture in the combined #266/#268/#272 verification branch with synthetic RDNA2 NGG (67 vertices, guarded half-to-float position exports). The worker must now compile BOTH mesh and pixel stages against the reflected root; the gate checks that every loaded stage digest matches a worker receipt and rejects rootless/stand-in paths. https://github.com/Valdi320/TuxBox/tree/c0a663e1af986335f52370dc1f49b5859fc3ac9b Same rebuilt provider and Lanes executable, RTX 4080 / GE-Proton11-14, isolated prefixes, null pipelines disabled: A/B with compiler 86cd032 (before #268) vs combined compiler: raster-tables and raster-samplers pass both; mesh-samplers and mesh-sampler-single fail with missing mesh shader before, pass after. All six no-GPU groups passed, including updated negative tests. The final C++ change is comments only. This is a combined test branch, not a standalone PR or a title replay. Native AMD verification and rebase against your newest head remain outstanding. Thanks for the suggestion.
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
brcly/TuxBox!268
No description provided.