fix(agc): stop pixel invocations on BDA faults when supported #5804
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5804"
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 MarcZX10 on 2026-10-14T11:46:07Z.
What
Carry the pixel-shader BDA fault fix for #2009: stop shader invocations with
OpTerminateInvocationwhen the Vulkan feature is enabled, and retain the existing fallback when it is unavailable. Validate both the extension and opcode against the enabled feature and fragment stage. The carried feature-enable commit preserves abnergtz’s original authorship; subsequent rebase fixes are authored by MarcZX100.Tested
The carried branch reports
agc_driver_pixel_interlockpassing on AMD RDNA 2 devices using driver 32.0.21045, wheremainreproduces an atomic write after the fallback. Added regression coverage for both stop paths, interlock exit ordering, non-pixel stages, SPIR-V specialization, enabled/disabled feature validation, andshaderDrawParametersprofile validation.On this Linux host, no configured build tree for this branch was available. The prior review reported
agc_driver_graphicsfailures on Windows: on the PR head, an earlier unchangedDepthStencilTestsexpectation fails; on main plus the PR, the test shader requiresshaderClipDistance. Those failures remain unresolved and need follow-up.git diff --checkandtools/check_conventions.py --base upstream/mainpass after rebasing on currentmain.Checklist
main; no other open PR implements the same functionsImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T11:59:04Z.
GitHub’s overlap check correctly flags shared
Context,ValidateShaders, and draw-validation interfaces with #4072. The feature checks are separate, but both append to the same APIs, so I updated this PR to depend on #4072 and will rebase it onto that head after #4072 lands.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T14:20:00Z.
Tested on the AMD RDNA 2 iGPU where
mainfails, and the port as it stands does not fix it: it leaves out abnergtz's81f711d8a("enable VK_KHR_shader_terminate_invocation on the device"). Nothing setsContext::shaderTerminateInvocationand nothing addsSPV_KHR_terminate_invocationto the device's SPIR-V extensions, so the recompiler always takes theOpKillfallback.Setup: Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. AMD Radeon(TM) Graphics, Ryzen iGPU gfx1036, driver 32.0.21036.18 (a driver branch not in #2009's list yet). NVIDIA GeForce RTX 5070, driver 617.42.
shaderTerminateInvocationis true on both. The PR merged intomain5a6ad0ed3without conflicts.agc_driver_pixel_interlock, 5 runs each:main5a6ad0ed3pixel interlock wave64 BDA fault: pixel 0 counted 1 of 0 overlapping read-modify-writesmain+ this PRmain+ this PR +81f711d8aThe PR's own tests also don't build or pass on current
main:tests/ShaderDeviceProfile.cpp:ProfileInput::extensionsis astd::array<std::string_view, 2>, soextensions.push_back(...)doesn't compile. With that fixed,agc_shader_device_profilefails because it expects a rejection that only81f711d8aadds toShaderDeviceProfile.cpp.tests/Graphics.cpp:vertexWordsreturnsRecompile(request).spirv.Words(), a span into a destroyed result, and the two spans are then compared with==, which doesn't compile. After that, the vertex recompile throwsclipping a primitive with an all-zero clip position needs shaderClipDistance on the target device, a requirementmainadded after this branch's base. The target needsCapabilityClipDistance.All four fixes are on simonbronk:fix/5804-device-enable (485c18d06), on top of this PR's head 5d9c037a0. abnergtz's commit keeps its authorship there. The technical debt commit
f23c94ca9is also missing from the port; it targets the olddocs/dev/TechnicalDebt.mdlayout and would go todocs/dev/debt/now.With all four on
main5a6ad0ed3:ctest -j 8on the RTX 5070: all pass exceptcheck_main_sync, which fails on a Windows code page and is unrelated;ctest -R "agc|shader|video_out"on the AMD iGPU: all pass exceptagc_driver_lds_mixed_width_atomicsandagc_driver_layered_volume_vertex_no_gpl, the other two from #5271. Onmain,agc_driver_pixel_interlockfails there as well.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:09:50Z.
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.
main)core/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppL144core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppL705core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL619Some 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.
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/ShaderDeviceProfile.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDeviceProfile.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/ShaderDeviceProfile.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:10:59Z.
Review: CHANGES_REQUESTED
Checked the current head (build +
agc_driver*/agc_shader*ctest; the recompiler change and the device enablement look right, and simonbronk's Windows runs cover the AMD behaviour):core/libs/prx/libSceAgcDriver/tests/Graphics.cpp:5827:validateTerminatepasses ninefalsefollowed byenabled, soenabledlands inruntimeDescriptorArray, notshaderTerminateInvocation.agc_driver_graphicsfails on this head withSPV_KHR_terminate_invocation requires enabled shaderTerminateInvocation in a fragment shader. It needs one morefalsebeforeenabled.maininShaderDeviceProfile.cpp,Pipeline.hpp,Draw.cppandShaderValidation.cpp(theValidateShaders/Inspectsignatures changed). Please rebase, and re-runagc_driver_graphics,agc_driver_pixel_interlockandagc_shader_device_profileafterwards.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T14:51:31Z.
Addressed the review: rebased onto current main, restored the Vulkan feature query/enable path and shader-device-profile guard, fixed the
validateTerminateargument soenabledreachesshaderTerminateInvocation, and updated the span comparison for the current API.agc_shader_device_profilepasses locally. Bothagc_driver_graphicsandagc_driver_pixel_interlockabort before test cases on this Xeon E5-1620 v2 because it lacks LZCNT, BMI1/2, MOVBE, AVX2, and FMA; they cannot run on this host. The focused Ninja build, conventions check, andgit diff --checkpass. #4072 remains open and this PR retains the shared feature/interface dependency.Imported from boykopovar/AnyPS5. Originally posted by tezzgod74 on 2026-10-16T02:29:38Z.
Windows run of the three tests from the review, on an RDNA 2 device where
mainfails. Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,-DANYPS5_ENABLE_SPIRV_TOOLS=ON,ANYPS5_GPUset to each device:agc_driver_pixel_interlockiGPUagc_shader_device_profile(both)agc_driver_graphics(both)940eba9a2counted 1 of 0)main5d9dcc42dmain5d9dcc42d+ this PR, local mergeThe fix works on the iGPU.
agc_driver_graphicsfails on both devices with the PR applied, and passes without it on both bases. Each failure reproduced on every run:expected graphics rejection: writable stencil plane(DepthStencilTests,tests/Graphics.cpp:1857/1896).main:ShaderRecompiler::Recompile: SPIR-V module emission failed: clipping a primitive with an all-zero clip position needs shaderClipDistance on the target device.On 9aa8cc7b, swapping the test file:
tests/Graphics.cppagc_driver_graphics940eba9a2940eba9a26 OpKill and 0 OpTerminateInvocation)So the library change passes the existing tests, and failure (1) comes with this PR's test file. I haven't found the mechanism: no hunk touches
DepthStencilTests,main()runs it beforeorderedPixelShaderTestsandvalidationTests, the file adds no namespace-scope statics, and the newContextfield is appended at the end. Commits 2 to 5 of the branch (2080dcc9..37692a21) don't build on their own, so I couldn't bisect inside it.One review point:
ShaderDeviceProfile.cpploses theshaderDrawParametersguard. Both thedrawParameterslookup andcheckFeature(spv::CapabilityDrawParameters, ..., "shaderDrawParameters")exist on the base and onmainbut not at 9aa8cc7b; the terminate check takes their place instead of being added next to them. No test covers that guard, so it isn't caught.The merged build was built for the three test targets only: on current
main,GpuIndirectArgumentsMisalignedWriterAhead.cppdoesn't compile with MinGW (requested alignment '65536' exceeds object file maximum 8192, see #6452).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T05:40:31Z.
Rebased onto current main (
5d9dcc42d) and fixed two issues from review:validateTerminatenow passesshaderTerminateInvocationto the correct argument, and the profile once again validatesCapabilityDrawParametersagainst the enabled Vulkan feature, with enabled/disabled regression coverage. I also removed the stale #4072 dependency; this branch changes independent shader-validation interfaces and does not depend on that FMA PR. Localgit diff --checkand conventions pass. I could not run the suites here because there is no configured build tree for this branch. The previously reported Windowsagc_driver_graphicsfailures (DepthStencil expectation on the PR head;shaderClipDistanceon main plus PR) remain unresolved, so this needs another focused run/review.Imported from boykopovar/AnyPS5. Originally posted by tezzgod74 on 2026-10-16T10:02:12Z.
Focused run of d6cff408 (on
main5d9dcc42d). Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,-DANYPS5_ENABLE_SPIRV_TOOLS=ON, Ryzen 9 7950X iGPU (RDNA 2, 0x164e, 32.0.21045.5002) and RX 9060 XT (RDNA 4, 32.0.31041.1004):agc_driver_pixel_interlockagc_shader_device_profileagc_driver_graphics, 2 runs eachBoth
agc_driver_graphicsfailures are:That comes from the new vertex check in
orderedPixelShaderTests(vertexWords,tests/Graphics.cpp:5728). It recompiles a position-exporting vertex shader (vertexBdaCodeends withexp pos0) againstbdaCapabilities(Shader,Int64,PhysicalStorageBufferAddresses,StorageBuffer8BitAccess). Since9db923e90("clip primitives with an all-zero clip position"), the emitter requiresCapabilityClipDistancefor that. Giving that requestspv::CapabilityClipDistanceas well removes this error on both devices.With that change applied locally, the test gets further but isn't stable. In 8 runs (4 per device): 1 pass, 2 failures on
4 crashes (
unhandled exception 0xc0000005, or the crash report's thread dump), and 1 failure whose message I didn't capture. The same binary passing once and failing in different ways points to something nondeterministic in that check or the code under it; I haven't found what.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T10:05:19Z.
Rerun after the rebase, as asked (
agc_driver_graphics,agc_driver_pixel_interlock,agc_shader_device_profile). Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), WinLibs MinGW-w64 GCC 15.2 r7, Release. PR headd6cff408fon main5d9dcc42d(fast-forward, no conflicts).agc_shader_device_profileandagc_driver_pixel_interlock,--repeat until-fail:3: 3 of 3 each.agc_driver_graphicsfails on this head every time (8 of 8 runs; it passes on main):ShaderRecompiler::Recompile: SPIR-V module emission failed: clipping a primitive with an all-zero clip position needs shaderClipDistance on the target device. It comes from the newvertexWordslambda inorderedPixelShaderTests, which reusesbdaCapabilities(nospv::CapabilityClipDistance). This is the failure tezzgod74 reported on main + PR.vertexWordsreturnsRecompile(request).spirv.Words(), andconst auto terminated(line 5703) keeps the same;Words()is a span into theRecompileResulttemporary, which is destroyed. With a 3-line test change (addspv::CapabilityClipDistanceto a separate capability array for the vertex request, and use.spirv.Copy()in those two places)agc_driver_graphicspasses 8 of 8, and the three tests passuntil-fail:33 of 3 each.SpirvBdaFault.cppreverted to main,agc_driver_graphicsfails 3 of 3 (... 6 OpKill and 0 OpTerminateInvocation, not the valid-mask kill and 5 BDA fault terminations); restored and rebuilt, it passes.agc_driver_pixel_interlockpasses with main's recompiler on this GPU, so only the graphics test shows the change here.agc_driver_bda*,pixel*,vertex_clip*,sample_mask*,alpha_to_coverage*,agc_shader_*,agc_spirv*, serial): 46 of 46 pass. Non-GPU suite (837 tests): 830 pass; the 7 timeouts under load (6conventions_function_bodies*,hardware_oracle_compareat 19 s of its 20 s) pass serially.tools/check_conventions.py --base origin/mainandgit diff origin/main --checkpass. The full build fails only on the known 64 KiBalignastest (#6452/#6478).agc_driver_pixel_interlockon the RDNA 2 iGPU is not re-run here), Intel, Linux, and any title run.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T11:17:12Z.
Review: APPROVED
Re-checked on current main (rebased, build +
agc_driver*/agc_shader*ctest). The recompiler change and the device enablement look right, and tezzgod74's and Lerrylore's Windows runs cover the AMD behaviour.agc_driver_graphicsstill fails on this head (tezzgod74's and screamm's runs: "needs shaderClipDistance"), caused by the PR's own new test code. I pushed two commits to your branch:test(agc): give the vertex terminate test the ClipDistance capability: the vertex recompile inGraphics.cpp(vertexWords) was missingCapabilityClipDistance.test(agc): keep the recompiled words alive in the terminate tests:terminatedandvertexWordsheld a span into the temporaryRecompileResult; they now usespirv.Copy().agc_driver_graphics,agc_driver_pixel_interlockandagc_shader_device_profilepass after that. Merging once CI is green.