Skip to content

fix(shader): write a mesh shader's layer through a per-primitive block - #7674

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/mesh-layer-block
Oct 19, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/mesh-layer-block

Conversation

@thuanquang

Copy link
Copy Markdown
Contributor

What

On AMD's Windows driver, a draw through a geometry program that writes a layer crashes the process on main. The mesh shader the recompiler builds for it declares the per-primitive layer as a standalone Output array of uint, decorated BuiltIn Layer and PerPrimitiveEXT. Creating the pipeline crashes inside the driver:

FATAL: unhandled exception 0xc0000005 on thread 30504 ''
  rip 0x00007ffc7b523221 amdvlk64.dll+0x21f3221
  read of 0x0000000000000004

The layer is now written through an array of a one-member Block struct whose member is decorated BuiltIn Layer and PerPrimitiveEXT, stored with an access chain to member 0. That is how glslang declares gl_Layer, as a member of gl_MeshPerPrimitiveEXT. AMD's driver creates that pipeline and draws with it, also when the pixel shader reads the layer. ShaderValidation now reads PerPrimitiveEXT member decorations, so the block's array is checked against maxPrimitives like the other per-primitive outputs. The debt entry records why the block form is used.

#6379 (@Feuris) works around the same crash by removing the mesh layer output and the fragment layer input when pipelines are created, so layered mesh draws land in slice 0 on every vendor. This keeps the layer instead. I offered the block form for #6379 there first (comment); this is the separate PR that comment mentions. #7377 notes that Demon's Souls (PPSA01342) needed #6379 for this crash on AMD. #6959 (@JJenkx) renders layered mesh targets in windows and needs the layer output that #6379 removes; on this driver its new agc_driver_layered_volume_mesh crashes the same way, at amdvlk64.dll+0x21f3221.

The test is the one @oneandonlydean asked for on #7374: the layer each triangle lands on in first and last provoking vertex mode. On main it never reaches the comparison on this GPU, because the first draw crashes the driver.

Tested

Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, ANYPS5_REQUIRE_VULKAN=1, main 05171bc66:

  • New agc_driver_mesh_provoking_layer. It draws one quad through the geometry program agc_driver_layered_volume_draw compiles, which exports each vertex's layer, into a 2-slice target. Each triangle's vertices carry layers 0, 0 and 1.
    • First mode must fill slice 0 and leave slice 1 untouched.
    • Last mode must fill slice 1 and leave slice 0 untouched (fix(agc): draw geometry programs with the last provoking vertex #7374's provoking vertex for the per-primitive layer).
    • Both modes run twice: with a white pixel shader, and with one that writes the layer it reads from its ancillary input (0 and 128).
    • Built with main's emitter and ShaderValidation, the test crashes at the first draw, 3 of 3, with the amdvlk64.dll+0x21f3221 crash above. With this change it passes 3 of 3.
    • It skips without VK_EXT_mesh_shader, VK_EXT_shader_viewport_index_layer or a last provoking vertex mode, and on llvmpipe like the other mesh execution tests, so CI does not run it.
  • ctest -R "mesh|layer|provoking" (18 tests): all pass except agc_driver_layered_volume_vertex_no_gpl, which fails on main here too (AMD Windows: GPL-mode cache failures (alpha/wave32 pass after local driver update) #4768).
  • Full ctest --parallel 4 --timeout 120 on main 023106ae4 with this change, before the rebase onto 05171bc66: 1509 tests. The failures are the three that main has on this machine (agc_driver_lds_mixed_width_atomics fix(shader): release the LDS lock with an exchange and drop fences inside it #6976, agc_driver_lds_lock_budget, agc_driver_layered_volume_vertex_no_gpl AMD Windows: GPL-mode cache failures (alpha/wave32 pass after local driver update) #4768), plus log_macros and log_macros_timestamps, which fail in this build only because ccache rewrites __FILE__.
  • python tools/check_conventions.py --base origin/main with this title and body passes.
  • Not tested:

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, Windows 11 26200
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

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

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6959 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp L1003-1004

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4072 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
PR 5021 docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5500 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
docs/dev/debt/shader.md
PR 5941 docs/dev/debt/shader.md
PR 6009 docs/dev/debt/shader.md
PR 6235 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
docs/dev/debt/shader.md
PR 6612 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
docs/dev/debt/shader.md
PR 6639 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6679 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
docs/dev/debt/shader.md
PR 6683 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6762 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6767 docs/dev/debt/shader.md
PR 6801 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6924 docs/dev/debt/shader.md
PR 6941 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6947 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6977 docs/dev/debt/shader.md
PR 7085 docs/dev/debt/shader.md
PR 7201 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 7223 docs/dev/debt/shader.md
PR 7332 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
docs/dev/debt/shader.md
PR 7388 docs/dev/debt/shader.md
PR 7390 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 7392 docs/dev/debt/shader.md
PR 7395 docs/dev/debt/shader.md
PR 7410 docs/dev/debt/shader.md
PR 7429 docs/dev/debt/shader.md
PR 7484 docs/dev/debt/shader.md
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp

@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Oct 18, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, this looks good on our side: review passes and all the mesh and layered tests pass on NVIDIA, including the new one. We don't have an AMD GPU, so before merging we'd like one independent AMD run: the crash on current main, and no crash with this PR. Could anyone with an RDNA2 card (or another AMD GPU) on a recent Windows driver post that?

@wachi35676

Copy link
Copy Markdown
Contributor

Independent AMD run, as requested. Windows 11, AMD Radeon(TM) Graphics iGPU (Granite Ridge, RDNA2, deviceID 0x13c0), driver 32.0.21042.62, WinLibs GCC 15.2.0, Release, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_GPU=AMD. Base is main a373e85e5; head is that plus a9cd39045.

  • On main: the new test, built against main's emitter and ShaderValidation, crashes at the first draw with 0xc0000005 ... amdvlk64.dll+0x21f31a1, read of 0x0000000000000004. That is the same crash as the reported offset 0x21f3221, shifted by the driver build.
  • With this PR: it passes 3/3 on the AMD iGPU, and 3/3 on an RTX 5070 Ti (driver 617.42).
  • NVIDIA: on the RTX 5070 Ti the test also passes against main, so only an AMD run catches this regression.
  • Regressions: the related subset (agc|shader|spirv|recomp|video|pad|record|mesh|layer, 793 tests) has no new failures on either GPU. The AMD failures lds_lock_budget, lds_mixed_width_atomics and layered_volume_vertex_no_gpl also fail on main.

AI-assisted: yes (Claude Code); results above were run on this machine.

@Feuris

Feuris commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with AMD Radeon RX 6700 XT and AMD Ryzen 9 7900X:

  • \�gc_driver_mesh_provoking_layer: passes cleanly (0.22 s).
  • Mesh & layer regression test suite: 17/18 pass (the known \layered_volume_vertex_no_gpl\ issue is pre-existing on AMD \main).
  • Super Meat Boy 3D (PPSA31162):
    • The previous \�mdvlk64.dll\ crash is completely gone.
    • Unlike fix(agc): drop layer I/O when linking mesh pipelines in driver to prevent AMD crash #6379 where dropping the layer caused the 3D background scene to render pitch black, declaring the block struct allows the 3D scene geometry, sky, and diorama on \L_MainMenu\ to actually reach their layers and render, with noticeable FPS improvements.
    • (Note: The 3D scene still has separate visual artifacts such as checkerboard tile dropouts from virtual texturing/PRT and color contour banding, but the mesh shader layer crash and routing targeted by this PR are fully resolved).

Fully support closing #6379 in favor of this cleaner solution. Thanks @thuanquang and @oneandonlydean!

@oneandonlydean
oneandonlydean merged commit 819ced2 into boykopovar:main Oct 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants