Repository navigation
fix(shader): end a pixel shader's failed BDA reads through one exit - #7377
oneandonlydean merged 1 commit into
Conversation
Every guest-memory read of a pixel shader that can fault ended the invocation with its own OpTerminateInvocation, or OpKill without the extension. A main-menu pixel shader of NHL 27 (PPSA34063) has 216 such exits and Demon's Souls (PPSA01342) up to 112, and AMD's Windows driver crashes in vkCreateGraphicsPipelines on those modules (amdvlk64.dll+0x9e251f). The guest code is now emitted as its own function: a failed read sets a private flag and returns, and the entry point calls it and terminates once when the flag is set. A pixel shader without a fault site keeps a plain entry point, with no exit and no SPV_KHR_terminate_invocation. Primitive-ordered pixel shaders keep the old form, as their interlock instructions must stay in the entry point. Based on poonasor's design in poonasor/AnyPS5@eb2e2309, ported to current main. Co-authored-by: poonasor <12569806+poonasor@users.noreply.github.com>
|
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.
|
|
AMD on Windows: the tests this PR names pass on an RDNA 3.5 GPU. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release.
AI-assisted |
|
@LeandroLP23 thanks for running them on the Radeon 860M. Your run is now in the Tested section, with your note that the three |
|
A reproduction of the crash on a discrete RDNA 2 card, red on The test,
On With this PR, the three tests the description names and this one pass 3 of 3 runs each under ctest on this GPU: The test is on my fork as one commit on top of this PR's head: |
|
AMD hardware result, which the PR lists as not tested. Tested at
I didn't reproduce the amdvlk crash itself; that needs the titles' large shaders. AI-assisted: yes (Claude Code); results above were run on this machine. |
* fix(shader): pass the minimum LOD sampler bank into non-entry-point functions CompilerMSL::to_name qualifies an argument-buffer member only while it emits the default entry point. The minimum LOD bank is referenced by name, so a pixel body emitted in its own function saw minimumLodSamplers out of scope and the shader failed to compile. A real access chain on the bank in every function that samples through it makes extract_global_variables_from_function pass the bank as an argument, exactly like the original sampler array. * fix(shader): end a pixel shader's failed BDA reads through one exit Integrates upstream boykopovar#7377. A pixel body with BDA reads is emitted as a second function and the entry point terminates once, after it returns, when a fault was recorded; the fault sites return instead of terminating from wherever they are. The bridge change below makes the minimum LOD sampler bank visible in that second function. * fix(shader): type a wrapped body's store pointers before its purity check SPIRV-Cross clears expression types at the start of every compile pass, and function_is_pure then reads the type of each OpStore pointer, including blocks that are never emitted. A pixel body wrapped in its own function by the one-exit BDA change hit an unregistered access chain there and the shader failed with "Cannot resolve expression type". Register the type of a callee's store pointers just before its OpFunctionCall is emitted.
jotitadev
left a comment
There was a problem hiding this comment.
Apple GPU / MoltenVK run. One regression on Metal: agc_driver_stencil_ref_export_unused fails with this PR and passes without it.
Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Head e8b3198, PR diff applied cleanly on top of the tree below. Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main + SPIRV-Cross #2704.
Tested: the tree is main a373e85 + mugurc's macOS series (ci/macos-series-2, includes ImportWatched) + the PRs needed to build on macOS (#6667, #6668, #7524, #6969, and two files of #7332), not plain main (it doesn't build on macOS yet). Base on that tree: 40 ^agc failures with MoltenVK 1.4.2, the same known failures in every run below unless noted.
agc_driver_graphics,agc_driver_gpu_buffer_format,agc_driver_layered_volume_drawpass (the mesh case skips: noVK_EXT_mesh_shader).- thuanquang's
PixelBdaStops.cpp(d95a790) passes:160 chained reads, 2 invocation exits. Without the PR (exit-count check disabled) Metal also compiles the 161-exit module and both draws are correct, so Apple doesn't have the amdvlk crash. - Full
^agcsuite: 40 of 728 fail, as on the base, but one of them is new:agc_driver_stencil_ref_export_unusedfails 5 of 5 runs with the PR on MoltenVK 1.4.2 and also on MoltenVK main + #2704, and passes on the base tree. (The count matches only becauseagc_driver_cross_workgroup_flag, intermittent on Apple, passed in this run.)
MoltenVK rejects the fragment shader:
program_source:56:5: error: no matching function for call to '_22'
_22(gl_HelperInvocation, gl_FragStencilRefARB, out.out_mrt_0, vsharp);
program_source:25:6: note: candidate function not viable: no known conversion from 'int' to 'uint &' (aka 'unsigned int &') for 2nd argument
[gpu] driver failure: AGC graphics: vkCreateGraphicsPipelines: Vulkan result -3
The guest code is now its own function (%22), and gl_FragStencilRefARB (BuiltIn FragStencilRefEXT, OpVariable %_ptr_Output_int) is stored there. In this test the pipeline doesn't export stencil, so SPIRV-Cross makes the builtin a local int gl_FragStencilRefARB; in main0. It still declares the helper's parameter with the builtin's MSL type, thread uint&, so the call doesn't compile. Before this PR the store stayed in the entry point and no parameter was needed. agc_driver_stencil_ref_export, where the stencil output is live, passes.
That's a SPIRV-Cross issue, but this PR is what exposes it. Possible ways around it: declare the stencil reference output as a 32-bit uint (FragStencilRefEXT takes a scalar 32-bit integer), or keep the per-site form for pixel shaders that write FragStencilRefEXT, as for primitive-ordered ones. I haven't tried either. The MSL and SPIR-V dumps are available if useful.
GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704 for the stencil failure)
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
What
On AMD's Windows driver, two titles crash the shader compiler inside
vkCreateGraphicsPipelines:main143f130 with fix(agc): drop layer I/O when linking mesh pipelines in driver to prevent AMD crash #6379, feat(recompiler): run waterfall loops over per-lane T#s through image tables #6488, fix(shader): plan image tables through invariant descriptor phis #6417 and feat(libSceImeDialog): take the dialog's text from the host keyboard #6504. The crash happens at boot: an access violation atamdvlk64.dll+0x9e251fon a driver thread, on pixel shaders with up to 112 BDA-fault exits. Cleverdee got past it with poonasor's commit below. Demon's Souls also needed fix(agc): drop layer I/O when linking mesh pipelines in driver to prevent AMD crash #6379 for a separate meshgl_Layerlink crash on AMD.amdvlk64.dll+0x9e251finvkCreateGraphicsPipelines, after START. One main-menu fragment shader is 662,679 SPIR-V words with 216OpTerminateInvocation/OpKillexits. poonasor reproduced the crash offline with a stand-alone pipeline-creation tool, and the module passes the validation layer.StopBdaInvocationIf(SpirvBdaFault.cpp) ends a pixel invocation at every guest-memory read that faults. That's anOpTerminateInvocationwhenSPV_KHR_terminate_invocationis supported (#5804), and anOpKillotherwise. A large shader therefore carries one exit per read.This is poonasor's fix from poonasor/AnyPS5@eb2e2309, ported to current
mainwith them as co-author:Two changes from eb2e230:
SPV_KHR_terminate_invocation. Otherwise every unordered pixel shader would declare the extension.agc_driver_layered_volume_drawvalidates its mesh pipeline withoutshaderTerminateInvocationenabled, and rejects such a shader with "SPV_KHR_terminate_invocation requires enabled shaderTerminateInvocation in a fragment shader".Tests:
orderedPixelShaderTests(agc_driver_graphics) now expects these exits:SPV_KHR_terminate_invocationOpTerminateInvocationin the module, in the entry pointOpKillin the entry point, plus the shader's ownValidateShaderswithoutshaderTerminateInvocation#6416 also edits
StopBdaInvocationIf. Its write masking applies to every stage except pixel shaders, and this PR changes only pixel shaders, so the two compose. They merge without conflicts.Tested
main's code:agc_driver_graphicsfails with "AGC graphics: a pixel shader with BDA reads and SPV_KHR_terminate_invocation did not end its BDA faults through one OpTerminateInvocation in its entry point (5 in the module)".agc_driver_graphics,agc_driver_layered_volume_drawandagc_driver_gpu_buffer_formatamong them, pass 10 of 10 runs on both runners. Two of them skip on the Windows runner, which has no Vulkan device.precise_waittiming test failed in this run. It also failed there onmain's code in an earlier run of the same tree, and it passes in the Linux mirror below.check_skipspasses.ANYPS5_ENABLE_SPIRV_TOOLS=ON, run as an unprivileged user):maintoo, and no test changes status againstmain195d0d0.guest_sce_net, whichmainshows too.main6efb726 with 13 other open PRs, built once as one tree (comment):agc_driver_gpu_buffer_format,agc_driver_graphicsandagc_driver_layered_volume_drawpass 3 of 3 runs;agc_*tests, 713 of 716 pass. LeandroLP23 reports that the 3 that fail (agc_driver_host_import_lifetime,agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gpl) fail the same way on unchangedmainthere.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)