Skip to content

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

Merged
brcly merged 1 commit into
brcly:mainfrom
NickStallman:fix/xshader-mesh-launch-2
Nov 26, 2026
Merged

brcly merged 1 commit into
brcly:mainfrom
NickStallman:fix/xshader-mesh-launch-2

Conversation

@NickStallman

@NickStallman NickStallman commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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

…reader takes

99 ProjectScarlett mesh programs were refused with "unsupported mesh
launch register v7" (59) or "v6" (40). Each first writes the register
with a VOP1 v_cvt_f16_f32, and some write v8 the same way. On RDNA2 that
writes bits 15:0 and keeps 31:16, so `live_in`, which takes registers
read before they are written in program order, counts the write as a
read of the launch value. 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 then replaces the whole register before the
vertex exports read it.

`kept_half_unread` proves that for each such register, over the whole
program including the export sequence, in `live_in`'s program order.
The 16-bit write must sit in the block the vertex-count guard opens:
s_mov_b64 s[n:n+1], exec; v_cmpx_gt_u32 count, lane; s_cbranch_execz
to s_mov_b64 exec, s[n:n+1]. `count` and `lane` are the registers the
export sequence tests, and neither changes after the guard. The guard
is the last EXEC change before the write. Up to the export sequence
EXEC only narrows or returns to a value saved since the block opened,
and inside the block to one saved after the guard. No branch crosses
the guard or the write except the guard's own, taken when no lane is
active. So every lane that reads the register has executed the write.
After the block nothing touches the register before the vertex exports,
which test the same count against the same lane; the export recognizer
now records where they begin. Each later reader takes the low half,
until a full write that no path leaves early or comes back into, and no
register range may hold the register without naming it. Any other
shape is still refused. The translation starts the kept bits at zero,
as before.

When one register holds both counts, as the recognizer now also accepts,
the vertex exports still test that register against the lane, so a guard
on it keeps the same lanes. The check never reads the primitive count. A
read in the primitive part is still refused, though its lanes are then
the guard's.

Over the recorded ProjectScarlett requests (24,848, and 24,866 for the
byte comparison, as a game run was adding to them), against 68e79b7: the
99 translate, compile with Linux DXC 1.8.2505.1 and pass DXV. All 22,970
requests main translates give byte-identical output, and every other
refusal is unchanged. No GPU run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Valdi320

Copy link
Copy Markdown
Contributor

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
NickStallman force-pushed the fix/xshader-mesh-launch-2 branch from e3262e0 to e56f9ee Compare November 26, 2026 21:14
@NickStallman

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

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.

@brcly
brcly merged commit e76ff6a into brcly:main Nov 26, 2026
2 checks passed
brcly added a commit that referenced this pull request Nov 26, 2026
# Conflicts:
#	tools/shader-compiler/src/tests/hlsl/mesh.rs
@Valdi320

Copy link
Copy Markdown
Contributor

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants