Skip to content

rdna2spirv: lift known-%pc guards in mesh shaders, so a join's barrier is not in a selection (AMD 24.10.24 crash in ms_wave_info_s3) - #8502

Open
SpaghettiMaster545 wants to merge 1 commit into
ItsNotRexed:mainfrom
SpaghettiMaster545:ms-barrier-known-pc
Open

SpaghettiMaster545 wants to merge 1 commit into
ItsNotRexed:mainfrom
SpaghettiMaster545:ms-barrier-known-pc

Conversation

@SpaghettiMaster545

Copy link
Copy Markdown

Claim: #8047, from my finding in #7913.

What and why

On AMD's Windows driver 24.10.24 (Vulkan driver 2.0.302), ms_wave_info_s3 crashes the driver's shader compiler inside vkCreateGraphicsPipelines with 0xC0000005 (VK_LAYER_LUNARG_api_dump ends there). Hand-edited modules, all spirv-val clean for vulkan1.2 and 1.3, isolate the trigger: a mesh shader with any barrier inside a selection construct. That includes OpControlBarrier, and also OpMemoryBarrier on its own. It crashes even when the condition is a push constant or LocalInvocationIndex < 128. ms_tri with one barrier added behind if (pushconst == 0) crashes too. The same barrier outside the selection compiles and draws.

variant (AMD, VKH_MESH=1, LEONIDA_PC_TAIL_UBO=1) result
translated ms_wave_info_s3 on main crash
the ms_counts store ungated, via OpAtomicStore, or gated as in #5741 / #5855 / #7136 crash
barrier semantics changed, OpMemoryBarrier only, or Subgroup scope crash
barrier moved out of the %pc == 2 selection, or that guard removed 4096/4096
ms_tri + if (pushconst == 0) { barrier }, or if (local_index < 128) { barrier } crash
ms_tri + the same selection with no barrier 4096/4096

In ms_wave_info_s3, the barrier sits in the join of the skipped s_sendmsg GS_ALLOC_REQ, a block that every path reaches. But cfg_structure leaves that join behind if (%pc == 2), and the driver can't fold the test.

assemble() now runs the existing wave64_emulate_opt._unwrap_known_pc_guards on the native structured tree of mesh shaders; until now only the emulated wave64 tree did. It interprets what each block can leave in %pc: its successors, plus "past the end" for a conditional branch with no block after it, which Gen.pc_may_end now records because succ doesn't list it. A guard that every path reaches with %pc already equal to its block is always taken, so its items are emitted without it. The shader runs the same blocks in the same order. needs_barrier_rounds still decides from the tree before this step, which is conservative.

Scope: mesh shaders only. Applied to every stage, the step changes 13 of the 247 test modules (structured cs, ms and ps). All of those stay spirv-val valid and get the same GPU verdicts. It can't be measured over the corpus here, though, so this PR limits it to the stage that crashes.

docs/design.md says the barrier stays "inside a selection or loop construct in every ms … shader of the corpus" on the native wave64 path. If those are known-%pc guards like this one, the same crash would hit most game mesh shaders on that driver. That is a hypothesis; I couldn't check it without the corpus. A barrier that is really inside a loop or a branch would still crash there.

The NVIDIA failure of ms_wave_info_s3 (SHADER-766: the counts are never written) is separate. All three open fixes for it (#5741, #7136, #5855) still crash on this AMD driver, because the barrier stays behind if (%pc == 2). Combined with this change, #7136 passes ms_wave_info_s3 4096/4096 on both GPUs.

Changes

  • tools/rdna2spirv.py: the step in assemble(), and Gen.pc_may_end.
  • tests/test_cfg_structure.py: checks the step on 18,228 random structured graphs. Each graph runs once as is and once with random blocks that may also end the program, compared against the graph and the original tree (18,423 guards dropped over 36,430 runs). tests/test_runner_calls_all_tests.py lists the new function, following the existing pattern.
  • tests/semantic/test_ms_barrier_top_level.py: a hand-written mesh listing. It checks that the join and its barrier sit outside any construct, while the send stays guarded. It fails with main's translator and passes with this PR.
  • docs/design.md: a new contract row, "Known-%pc guards (native structured form)", and one sentence in "Workgroup barriers".

Tested

Windows 11 IoT Enterprise LTSC 2024 (26100), Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, Python 3.14. Test programs built with MSVC 14.50 (VS 2026). Both GPUs are in one machine. Synthetic fixtures only, no game files.

scripts/run_gpu_tests.py, every test main dfe4e4a this PR
AMD Radeon Graphics (Ryzen 7 9800X3D iGPU, RDNA2 gfx1036), AMD 24.10.24, LEONIDA_PC_TAIL_UBO=1 219/241 (20 skipped); ms_wave_info_s3 crash 220/241; ms_wave_info_s3 4096/4096 pixels exact. No other verdict changes. The only failure left is ms_clip, fixed by #8097.
NVIDIA GeForce RTX 5070 Ti, 621.24 192/241 (48 skipped) 192/241; every verdict identical

Overlap: this PR touches tools/rdna2spirv.py, as #8097 does, but in different places. This PR adds the step after capped_tree, the Gen field and one line in translate(); #8097 changes the mesh output declarations and the epilogue. They don't conflict textually.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…r is not in a selection (AMD 24.10.24 crash)

AMD's Windows driver 24.10.24 (Vulkan driver 2.0.302, a gfx1036 iGPU) crashes inside
vkCreateGraphicsPipelines on a mesh shader with any barrier inside a selection construct. That
includes OpControlBarrier and also OpMemoryBarrier on its own, even when the condition is a push
constant. In ms_wave_info_s3 the barrier sits in the join after a skipped s_sendmsg, a block every
path reaches, but cfg_structure leaves it behind if (%pc == 2).

assemble() now runs wave64_emulate_opt._unwrap_known_pc_guards on the native structured tree of mesh
shaders. It interprets %pc over each block's successors, plus past-the-end for a conditional branch
with no block after it (Gen.pc_may_end). A guard that every path reaches with %pc already naming its
block is always taken, so its items go in unguarded, and the same blocks run in the same order. Other
stages are left as they were until the step is measured over the corpus.

Tested on Windows 11 (VS 2026, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6):
- run_gpu_tests on the AMD iGPU: 219 -> 220 of 241, with ms_wave_info_s3 going from crash to
  4096/4096; no other verdict changes.
- run_gpu_tests on an RTX 5070 Ti (621.24): identical verdicts.
- Translated modules: only ms_wave_info_s3 of 261 changes.
- test_cfg_structure checks the step on 18,228 random graphs. The new
  semantic/test_ms_barrier_top_level fails on main and passes here.

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

Copy link
Copy Markdown
Contributor

Tested 49c3667f on Windows Server 2022, CPython 3.13.12: pass

  • python -I -m unittest discover -s tests/semantic -p "test_ms_barrier_top_level.py" -> OK (skipped=1)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@itzzflamee

Copy link
Copy Markdown

I'll independently test this PR on an NVIDIA RTX 4070. Windows. I'll report the exact commit, driver, test command and results. Synthetic tests only, no game files.

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