Skip to content

fix(agc): stop pixel invocations on BDA faults when supported - #5804

Merged
adriadam10 merged 9 commits into
boykopovar:mainfrom
MarcZX10:codex/pixel-interlock-terminate-2009
Oct 16, 2026
Merged

adriadam10 merged 9 commits into
boykopovar:mainfrom
MarcZX10:codex/pixel-interlock-terminate-2009

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What

Carry the pixel-shader BDA fault fix for #2009: stop shader invocations with OpTerminateInvocation when 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_interlock passing on AMD RDNA 2 devices using driver 32.0.21045, where main reproduces 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, and shaderDrawParameters profile validation.

On this Linux host, no configured build tree for this branch was available. The prior review reported agc_driver_graphics failures on Windows: on the PR head, an earlier unchanged DepthStencilTests expectation fails; on main plus the PR, the test shader requires shaderClipDistance. Those failures remain unresolved and need follow-up. git diff --check and tools/check_conventions.py --base upstream/main pass after rebasing on current main.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR
  • No comments in code
  • Generic behavior
  • Depends on: none
  • Unblocks: none
  • GPUs tested: AMD RDNA 2 devices on Windows, driver 32.0.21045; local Linux host has no configured build for this branch
  • AI-assisted: yes

@MarcZX10

Copy link
Copy Markdown
Contributor Author

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.

@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 14, 2026
@simonbronk

Copy link
Copy Markdown
Contributor

Tested on the AMD RDNA 2 iGPU where main fails, and the port as it stands does not fix it: it leaves out abnergtz's 81f711d8a ("enable VK_KHR_shader_terminate_invocation on the device"). Nothing sets Context::shaderTerminateInvocation and nothing adds SPV_KHR_terminate_invocation to the device's SPIR-V extensions, so the recompiler always takes the OpKill fallback.

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. shaderTerminateInvocation is true on both. The PR merged into main 5a6ad0e without conflicts.

agc_driver_pixel_interlock, 5 runs each:

Build AMD iGPU RTX 5070
main 5a6ad0e fails 5/5: pixel interlock wave64 BDA fault: pixel 0 counted 1 of 0 overlapping read-modify-writes passes 5/5
main + this PR fails 5/5, same message passes 5/5
main + this PR + 81f711d8a passes 5/5 passes 5/5

The PR's own tests also don't build or pass on current main:

  • tests/ShaderDeviceProfile.cpp: ProfileInput::extensions is a std::array<std::string_view, 2>, so extensions.push_back(...) doesn't compile. With that fixed, agc_shader_device_profile fails because it expects a rejection that only 81f711d8a adds to ShaderDeviceProfile.cpp.
  • tests/Graphics.cpp: vertexWords returns Recompile(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 throws clipping a primitive with an all-zero clip position needs shaderClipDistance on the target device, a requirement main added after this branch's base. The target needs CapabilityClipDistance.

All four fixes are on simonbronk:fix/5804-device-enable (485c18d), on top of this PR's head 5d9c037. abnergtz's commit keeps its authorship there. The technical debt commit f23c94ca9 is also missing from the port; it targets the old docs/dev/TechnicalDebt.md layout and would go to docs/dev/debt/ now.

With all four on main 5a6ad0e:

AI-assisted (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 14, 2026
@MarcZX10
MarcZX10 force-pushed the codex/pixel-interlock-terminate-2009 branch from 5d9c037 to 5b5cdc6 Compare October 14, 2026 17:09
@github-actions github-actions Bot added docs needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 14, 2026
@screamm

screamm commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

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 head d6cff408f on main 5d9dcc42d (fast-forward, no conflicts).

  • agc_shader_device_profile and agc_driver_pixel_interlock, --repeat until-fail:3: 3 of 3 each.
  • agc_driver_graphics fails 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 new vertexWords lambda in orderedPixelShaderTests, which reuses bdaCapabilities (no spv::CapabilityClipDistance). This is the failure tezzgod74 reported on main + PR.
  • Fixing that is not enough: the test is then flaky (2 of 6 runs pass), which matches @tezzgod74's 1 pass, 2 failures and 4 crashes above; a crash or a changed fault exit is what a dangling span gives. vertexWords returns Recompile(request).spirv.Words(), and const auto terminated (line 5703) keeps the same; Words() is a span into the RecompileResult temporary, which is destroyed. With a 3-line test change (add spv::CapabilityClipDistance to a separate capability array for the vertex request, and use .spirv.Copy() in those two places) agc_driver_graphics passes 8 of 8, and the three tests pass until-fail:3 3 of 3 each.
  • Negative control (with that test change): SpirvBdaFault.cpp reverted to main, agc_driver_graphics fails 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_interlock passes with main's recompiler on this GPU, so only the graphics test shows the change here.
  • 46 related GPU tests (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 (6 conventions_function_bodies*, hardware_oracle_compare at 19 s of its 20 s) pass serially. tools/check_conventions.py --base origin/main and git diff origin/main --check pass. The full build fails only on the known 64 KiB alignas test (test(agc): align the indirect arguments block at run time #6452/fix(agc): allocate indirect arguments test block dynamically on Windows #6478).
  • Not checked: AMD (the PR's target, so agc_driver_pixel_interlock on 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).

abnergtz and others added 9 commits October 16, 2026 13:10
Pixel invocations stopped by a BDA fault now end with OpTerminateInvocation when the target offers SPV_KHR_terminate_invocation, and keep OpKill otherwise. OpKill is not enough on AMD driver branch 21045, where a guest atomic after the kill still lands once per faulting pixel.

Based on the approach in poonasor/AnyPS5@73969879.

Refs boykopovar#2009
…tion

Shader validation accepts the extension only in fragment shaders and only when the device enabled shaderTerminateInvocation. The flag is part of the validation memo key.

Refs boykopovar#2009
The validator only checked SPV_KHR_terminate_invocation when it saw the
OpExtension, so a module using OpTerminateInvocation without declaring
the extension, or in a non-fragment stage, was accepted. Require the
fragment stage, the enabled shaderTerminateInvocation feature and the
declared extension at the instruction itself.

Refs boykopovar#2009
The device queries and enables shaderTerminateInvocation when available, advertises SPV_KHR_terminate_invocation to the recompiler and validation, and the shader device profile rejects a target that advertises the extension without the enabled feature.

Based on the approach in poonasor/AnyPS5@73969879.

Refs boykopovar#2009

(cherry picked from commit 1866a3f)
Restore the shaderDrawParameters feature guard while adding shaderTerminateInvocation support. Cover enabled and disabled DrawParameters profiles, and pass the termination feature to the correct shader validation argument.
@adriadam10
adriadam10 force-pushed the codex/pixel-interlock-terminate-2009 branch from d6cff40 to b85146d Compare October 16, 2026 11:17

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_graphics still 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 in Graphics.cpp (vertexWords) was missing CapabilityClipDistance.
  • test(agc): keep the recompiled words alive in the terminate tests: terminated and vertexWords held a span into the temporary RecompileResult; they now use spirv.Copy().

agc_driver_graphics, agc_driver_pixel_interlock and agc_shader_device_profile pass after that. Merging once CI is green.

@adriadam10
adriadam10 merged commit 65d56a2 into boykopovar:main Oct 16, 2026
8 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.

6 participants