fix(agc): replace with a stencil operation value the pixel shader exports #6762
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6762"
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 simonbronk on 2026-10-16T10:35:55Z.
What
DB_SHADER_CONTROL.STENCIL_OP_VAL_EXPORT_ENABLE(bit 2) lets the pixel shader supply the value thatREPLACE_OPand the add and subtract operations use in place ofDB_STENCILREFMASK.STENCILOPVAL(AMD_stencil_operation_extended, AMD_shader_stencil_value_export). The bit was refused as a whole:depth export, shader coverage or ordered fragment execution is unsupported (register 0x203 = 0x00000045).REPLACE_OP(StencilOperationValueReplaces) becomesVK_STENCIL_OP_REPLACEwith the exported value asFragStencilRefEXT. Devices withoutVK_EXT_shader_stencil_exportuse the existing bounded replay.NEVER,ALWAYSor compare mask 0) and use noONESorREPLACE_TEST, since those would need the register reference. Otherwise it throws.REPLACE_OPtogether with a test value export.emit_ps_mrtz_export), and I found no public source for the operation value. The evidence is the title's pixel shader below: right beforeexp mrtz, it shifts the value left by 8. The debt entry says this is the only evidence.ShaderPixelStageInfo::stencilOperationValueExportflag carries this to the recompiler. It enters the recompile cache key, the draw lookup and register keys, and request serialization version 33 (#5884 took 31,7a6cc7178took 32). Replayed reference values use the same byte.The title's case. Onimusha: Way of the Sword draws with:
DB_SHADER_CONTROL0x45 andDB_STENCIL_CONTROL0x40040 (REPLACE_OPon depth pass, both faces);DB_STENCILREFMASK0x00ff0000 (write mask 0xff, test and operation values 0) and compareALWAYS;The pixel shader at 0x2112442100 ends with:
(words
d7710000 0401fe00 000000ff,34000088,f8001883 00000003).Tested
APS5_NO_HOST_IMPORT=1(#6374). The build wasmain5d9dcc42d+ #5907 + #5884 + #5915 + #6557 + #6727 + this change.sample-preserving guest publication of native multisample depth is not implemented, #6570).agc_driver_graphics(stencilRefExportTests) covers 15 stencil-control cases, each underDB_SHADER_CONTROL0x54, 0x56 and 0x45 with Z formats 2 and 9:REPLACEmapping andStencilReferenceUnused;0x2a05export:request_serializerandagc_shader_memoryexpect version 33. A version 32 pixel request reads no flag.ctest -j 8on both GPUs:agc_driver_preparation_scope_settle, which also fails about one run in three on its own on other branches. It has no stencil code.agc_driver_gpu_indirect_arguments_misaligned_writer_ahead(frommain) does not build with WinLibs GCC (#6452).python tools/check_conventions.py --base upstream/main: passed.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T10:51:48Z.
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/shader/recompiler/tests/RequestSerializerTests.cppL210, L249, L274, L397-400, L411, L431, L433core/shader/recompiler/tests/RequestSerializerTests.cppL210, L249, L274, L397-400, L411, L431, L433core/shader/recompiler/tests/RequestSerializerTests.cppL210, L249, L274, L398, L411, L431, L433core/shader/recompiler/StencilReplay.hppL9core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppL414-415core/shader/recompiler/StencilReplay.cppL604-606core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL4742, L4860, L5029-5032core/shader/recompiler/ControlFlow/src/RequestSerializer.cppL797, L836core/shader/recompiler/tests/RequestSerializerTests.cppL210, L249, L274, L398, L411, L431, L433Some 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/State.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.cppdocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/Recompiler.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/ControlFlow/src/RequestSerializer.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/ControlFlow/src/RequestSerializer.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/tests/RequestSerializerTests.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/ControlFlow/src/RequestSerializer.cppcore/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cppcore/shader/recompiler/tests/RequestSerializerTests.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/ControlFlow/src/RequestSerializer.cppcore/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cppcore/shader/recompiler/tests/RequestSerializerTests.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/shader/recompiler/Recompiler.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/State.hppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderInputState.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/Recompiler.hppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-16T12:22:10Z.
Rebased onto
maineb901bcf4. #5884 was merged with request serialization version 31, and this PR also used 31. Git merged the two bumps without a conflict, but a version 31 request frommainwould then be read with a stencil flag it doesn't contain. The flag now comes with version 32.request_serializerandagc_shader_memoryexpect 32, and a version 31 pixel request reads no flag. Head c51ee6b82.ctest -R "agc|shader|video_out" -j 8on Windows 11 26200, RTX 5070 (617.42), with this PR merged intomaineb901bcf4alongside #5907, #5915, #6557, #6727 and #6763: everything passes exceptagc_driver_gpu_indirect_arguments_misaligned_writer_ahead, which doesn't build with MinGW onmaineither (64 KiBalignas).Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-16T13:56:29Z.
AMD run with this head (c51ee6b82) merged onto
main82ddae75b: AMD Radeon RX 7600 (RDNA 3, RADV NAVI33, Mesa 25.2.8), Ubuntu 24.04, GCC 13.3, Release, fullctest -j4.main: 1286 / 1287. With this PR: 1286 / 1287, the same single failure.agc_driver_graphics. It fails the same way onmain(#6792, "VOP2 opcode is not implemented") and stops before the cases this PR adds toGraphics.cpp. With #6789 merged as well it passes, with this PR and without, so the new cases run and pass here.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-17T07:44:49Z.
Rebased onto
main17cfb1f4c, head aa0857a8d. Two changes:mainnow uses request serialization version 32 forspannedWaves(7a6cc7178), so the stencil flag moves to version 33. As last time, Git merged the two version bumps without a conflict.request_serializerandagc_shader_memoryexpect 33, and a version 32 pixel request reads no flag.State.cpp:decodeDepthkeepsmain's narrowerDB_RENDER_CONTROLmask (0x101c, from4cdd2f483).ShaderMemory.cpp: the older-version cases keepmain'spop_back()for the trailingspannedWavesbyte and also drop this PR's byte.ctest -R "agc|shader|video_out|request_serializer" -j 8, Windows 11 26200, with this PR merged ontomain17cfb1f4ctogether with #5915, #6557, #6727 and #6911:agc_driver_lds_mixed_width_atomicsfails, as in #5271.agc_driver_layered_volume_vertex_no_gplfails too: it's the driverVkCachethat mixes GPL modes, the case #6436 covers. Neither test touches this change.@johnmaia thanks for the RADV run.
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-17T08:55:50Z.
A title result with this head, recorded here so nobody reads more into the earlier run than it showed.
On the RTX 5070, which doesn't expose
VK_EXT_shader_stencil_export(vulkaninfolists it only for the AMD iGPU), the title's 0x45 draw now stops in #5466's replay path:The request decodes to
stencilRefExportEnable 1,stencilOperationValueExport 1. The pixel shader takes the value either from a user-data byte (s4 & 0xff) or from a buffer read, then shifts it left by 8 beforeexp mrtz. So the set of values can't be proven at compile time. The run on 2026-10-16 passed this draw only because the head at the time read bits 0-7, which that shift always leaves at 0.So the throw is correct, and this PR doesn't change it. On devices with the extension the draw goes through
FragStencilRef. Replaying an 8-bit operation value needs at most 256 values, but that is a change to #5466's emulation and not part of this PR.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T13:45:35Z.
Rebased onto current
main: it changedShaderInputState.cpp, the request serializer and its tests again. The stencil operation value flag stays in request serialization version 37 (after the pixel sample locations), the old-version cases skip its byte, andGraphics.cppaccepts either the shifted literal or the constant0x2athat the SPIR-V optimizer folds it to.The PR logic is unchanged from the version checked: the flag is in the recompile cache key, the draw lookup/register keys and the serializer; add/subtract,
REPLACE_OPwith a test value export and early tests still throw;stencilRefExportTestspins accepted and refused cases. The bits 8-15 layout rests on the one pixel shader quoted in the PR, as the debt entry says. Build and ctest passed on the rebased head; merged.