fix(shader): drop masked selects proven unobserved through whole quad mode #3391
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3391"
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 tibzejoker on 2026-10-11T09:40:30Z.
What
GTA V (PPSA04264) stops on current
main(2220effbe) at its first pixel shaders. Replaying the captured requests withagc_shader_replay:The
SelectU32writes a copy of the ancillary VGPR under a whole quad mode exec mask,WQM(X), whereXis a ballot of the live lanes taken in the entry block. Its value is read only by lanes insideX, and by implicit-LOD samples. The masked-lane walk could not prove either case, so the select kept the whole ancillary word alive.It also fixes Dead Cells (PPSA15552) pixel shader
0x21a23e700, on devices withoutVK_KHR_fragment_shader_barycentric, as reported by @hansjm10 below. It stopped withthe emulated barycentric inputs exceed 32 locations, because a select under thes_wqmexec kept the I barycentric alive. With the change it takes the host-interpolation path.MaskedSelectEliminatornow proves both:Xis contained inWQM(X). Containment is proven throughBitwiseAndand through ballots evaluated in the uniform entry blocks, where every invocation is active.WQMmask the masked lanes form whole quads. An implicit-LOD pixel sample only reads its own quad, so it does not observe them.With the change, both shaders recompile (4456 and 1840 SPIR-V words).
Tested
Windows 11, MinGW GCC 15.2.
agc_masked_select_tests:main, on the new cases ("an implicit-LOD pixel sample under whole quad mode reads no masked quad and drops the select", "a write under whole quad mode read only by the lanes it was widened from drops the select");agc_shader_replayon the two GTA V requests above: they fail onmainand recompile with the change.python tools/check_conventions.py --base upstream/mainpasses.ctest -R "agc_driver|agc_masked"(298 tests, RTX 4090): 297 pass;agc_driver_emulated_color_comparefails the same way onmain.agc_driver_gated_dispatch_capturepasses 13 of 13 atdb1f3c38e, and the fullagc_driver|agc_maskedrun has the same 10 failures with and without the change.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
https://claude.ai/code/session_01V1W4jdNSKTV7xwuS6xQPJV
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:53:28Z.
Review: CHANGES_REQUESTED
Thanks for the analysis, the reasoning in
MaskedSelectEliminatorlooks sound andagc_masked_selectpasses here (and fails without the change). One blocker:agc_driver_gated_dispatch_capturefails with this PR merged onto currentmain(3 of 3 runs, RADV):radv/amdgpu: The CS has been cancelled because the context is lost. This context is guilty of a hard recovery, thenthe gated submissions did not finish. WithMaskedSelectEliminator.cppreverted tomainthe same test passes (2.7 s). So a select that is observed is being dropped in that shader, or the generated code hangs. The PR text says the whole suite wasn't run; please runctest -R agc_driverand fix.withinQuadsOfis used inImplications::Impliesfor every stage, while only the sample exemption (quadMasked) is limited toPixel. Check whether the gated-dispatch compute shader reaches the new path, and add a test for that case.Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-11T12:16:09Z.
Thanks for the review. Rebased onto current
main(2220effbe) and checked:agc_driver_gated_dispatch_capturenever reaches the new path. WithAPS5_DUMP_IR=all, neither of its two compute shaders (the spin loop and the reader) has a select left whenMaskedSelectEliminatorruns. The onlySelectU32(the reader's, with conditiontrue) is folded away before the pass. The IR aftersrtandresourcesis byte-identical with and without this PR. So the pass cannot change the code this test runs. I can't reproduce the RADV hang here (no AMD GPU, only RTX 4090 / Vulkan). The test passes in about 1 s with and without the PR, both variants (_short_timeouttoo).ctest -R "agc_driver|agc_masked"(298 tests) with the PR: 297 pass. The one failure,agc_driver_emulated_color_compare, fails the same way onmainwithout the PR, so it is unrelated (NVIDIA).Stage question:
withinQuadsOfis stage-independent on purpose.WQM(X) ⊇ Xholds fors_wqmin any stage, so a select written underWQM(X)and read only underXis unobserved everywhere. Only the sample exemption depends on quads having implicit derivatives, and that staysPixel-only. Added tests:Computeas inPixel;Computeread by a lane outside the widened mask keeps it.The new and existing WQM cases fail on
mainand pass with the change.If the hang still shows up on your RADV box with this rebase, the shader logs from
APS5_DUMP_IR=allor the replay requests would help me find which shader changes. From what I can see here, none of them do.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T13:07:02Z.
Thanks for the updated IR trace and the compute regression cases. That addresses the specific hypothesis that
agc_driver_gated_dispatch_capturereaches the newMaskedSelectEliminatorproof on this shader. The reported 3/3 RADV failure versus 2/2 onmainis still an unresolved validation result, though: can someone with RADV rerun the rebased commit and confirm whether the failure persists? If it does, the shader dump / IR-stage comparison for that run would help isolate it; if it no longer reproduces, recording the commit and test result here would close the outstanding concern.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T13:27:17Z.
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/tests/MaskedSelect.cppL699core/shader/recompiler/Optimization/src/MaskedSelectEliminator.cppL477, L481-482, L523-524Imported from boykopovar/AnyPS5. Originally posted by hansjm10 on 2026-10-11T18:16:20Z.
RADV results for @MarcZX100's question. Setup: Debian 12, GCC 14.4, Release,
ANYPS5_ENABLE_SPIRV_TOOLS=ON, AMD Radeon iGPU through RADV GFX1036 (gfx1036), Mesa 22.3.6, selected withANYPS5_GPU=RADV(checked in theSelected GPUline).agc_driver_gated_dispatch_captureat this PR's headdb1f3c38e(onmaina11c8f7f7): 13 of 13 runs pass, and_short_timeoutpasses 3 of 3, at about 0.9 s each with no context loss. Both also pass inside the full parallel run below. Onmaina11c8f7f7both pass 3 of 3.ctest -R "agc_driver|agc_masked" -j4on RADV: 289 of 299 pass with this PR and 289 of 299 onmain. The same 10 tests fail on both:alpha_to_coverage,bindless_images,depth_compare_copy,ds_append_consume,gds_append_consume,image_sint8,pixel_helper_lanes,read_first_lane,read_lane,shader_clock.agc_masked_selectpasses.So I can't reproduce the hard recovery on this RADV. If it came from a newer Mesa or another GPU, the Mesa version from that run would tell.
A second title this fixes: Dead Cells (PPSA15552), on a device without
VK_KHR_fragment_shader_barycentric(RADV with Mesa 22.3.6 here; lavapipe in CI). Its pixel shader0x21a23e700stops withBarycentric geometry SPIR-V: the emulated barycentric inputs exceed 32 locations. The shader reads its 11 parameters only throughv_interp_p1/p2pairs. After the last interpolation it writesv0/v1again under thes_wqmexec, then restores the original exec before the export.HostInterpolationCheckertherefore finds the I barycentric still alive through that masked select, and the shader takes the emulated path, which needs 11 × 3 + 1 locations. With this PR the dumped request replays to 15958 SPIR-V words on the host-interpolation path: 11 plain inputs, noPerVertexKHRorBaryCoord. Caveat: onmainthe title stops earlier, on NGS2 rack0x4001(#3793) and then on the Geom family; this shader is reached with those applied.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-11T18:21:26Z.
Thanks a lot @hansjm10, both for the RADV runs and for the Dead Cells shader (
0x21a23e700). I added it to the description.@adriadam10: with these results (13/13 on RADV gfx1036, and the same 10 failures with and without the PR across the full suite), could you rerun on your box at
db1f3c38e? If it still hangs there, the Mesa version and GPU would help narrow it down.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:23:54Z.
Review: APPROVED
Checked on RADV: the PR merged onto current
main, scoped build and ctest of libSceAgc/libSceAgcDriver 406/406, including bothagc_driver_gated_dispatch_capturevariants. The earlier context loss no longer reproduces here, and @hansjm10's 13/13 agrees.agc_masked_selectfails without the change and passes with it. The WQM-superset and quad-local-sample proofs fall back to "observed" on any shape they don't recognise, so the elimination is conservative. Merging.