fix(recompiler): read NumWorkgroups in every mesh shader so RADV sizes its user data #3645
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3645"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-11T14:42:03Z.
What
On RADV (Mesa 26.2.4, RX 9070 XT / GFX12), a mesh draw that follows a vertex draw in the same command buffer can hang the GPU. The gfx ring times out, the ring reset fails, and the driver does a MODE1 reset with VRAM lost, which takes the desktop down with it.
Title: Kena: Bridge of Spirits (PPSA01802). Its layered volume draws run our recompiled NGG geometry program as a mesh shader, interleaved with ordinary vertex draws. They become reachable with #1077 (plus #425/#454), and every run hung the GPU 40-55 s in. It also reproduced with the Layer routing switched off, so the cause is the mesh dispatch itself.
Root cause (RADV)
radv_bind_pre_rast_shader(radv_cmd_buffer.c, Mesa 26.2.4) updatesvtx_base_sgpr,vtx_emit_numanduses_drawidonly when the bound shader has theAC_UD_VS_BASE_VERTEX_START_INSTANCEuser SGPR slot. A mesh shader gets that slot only if it readsNumWorkgroups(3 SGPRs) orDrawIndex(1 SGPR). Our mesh shaders read neither, so the state of the previously bound vertex shader stays: 3 SGPRs (base vertex, draw id, start instance), withuses_drawidset.radv_emit_userdata_meshthen:SET_SH_REGwith the stale count of 3;DISPATCH_MESH_DIRECT, which now lands inside the register payload.The CP takes the dispatch header and X as register values and then parses Y/Z/initiator as packet headers.
Evidence, from three hangs:
RADV_DEBUG=hangtrace: the last reached trace point is followed by and the preceding vertex draw wrote GS_3..GS_5 with 3 values.GRBM_STATUSshows only CP_BUSY / GUI_ACTIVE, with SPI, GE, PA, SC, CB and DB all idle, so no shader is stuck;CP_PFP_HEADER_DUMPlists0x00000007and0x00000002as parsed "headers".Fix (workaround)
Every mesh shader the recompiler emits now loads
NumWorkgroups.xand declares zero vertices when it is 0. No dispatch produces that, so behaviour is unchanged, and the read gives the shader the grid-size slot. RADV then updates its state at bind, announces 3 values and writes x, y, z.gl_NumWorkGroupswas already declared for mesh shaders with device-memory LDS; it is now declared for all of them.TechnicalDebt records the workaround and when it can be dropped (once a fixed Mesa is the minimum). I'll report the RADV bug to Mesa separately.
Tested
Linux (Arch), GCC, Release, RX 9070 XT (RADV GFX1201, Mesa 26.2.4), on main
a11c8f7f.agc_driver_mesh_testsnow requires every compiled mesh program to declare and loadBuiltIn NumWorkgroups:the mesh program does not read NumWorkgroups, so RADV can keep a previous vertex pipeline's user SGPR count for its dispatch;ctest: 831/832. The one failure,guest_video_out_output_mode, passes on its own; it flakes under parallel load and is unrelated.tools/check_conventions.pypasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T15:19:45Z.
Independent pre-review on Linux (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON.tools/check_conventions.py --base origin/mainpasses.