feat(shader): decode PS4 (GCN) shaders by re-encoding them to RDNA #9430
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9430"
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 Get-fix on 2026-10-21T21:51:01Z.
What
Part 2 of the PS4 Limbo stack, split out of #6977 for the AGC reviewers (the whole stack is listed in #6978). PS4 shaders do not get a second recompiler: each GCN (Sea Islands) instruction is re-encoded to its RDNA encoding and decoded by the existing RDNA decoder, so control flow, SPIR-V emission and the shader disk cache run PS4 shaders unchanged.
GcnInstructionDecoder.cppwith opcode tables generated from shadPS4'sopcodes.h(GPL-2.0-or-later; opcode numbers, no code); encodings without an RDNA counterpart throw.s_swappc_b64 s[0:1], s[0:1]) return through it.0x7in word 1 bits 15:12). PS4 T#: PS5 layout with the GCN tiling index, POW2_PAD and pitch kept in word 7 for the AGC driver.s_setreg_imm32_b32keeps its literal word, from javierUDP's review of #6977 and savvaniss's decode case (both are co-authors of that commit); the newagc_gcn_decodetest decodes the reported stream.GcnGuestShaders(), which is keyed into the shader disk cache, so PS5 titles take the paths they took before. That includes the user-data pointer check inunchangedUntil(a13d01bcc): a scalar write at thes_loadthat reads the pointer is skipped only for PS4 shaders, and PS5 shaders keepmain's rule.The facts that come from public sources rather than console measurements are in
docs/dev/debt/shader.md.Tested
Windows 11, WinLibs GCC 15.2, NVIDIA GeForce RTX 5060 Ti (driver 610.88), on
main7e2ba73e4:agc_gcn_decode(new): the stream from the review,{0xba80f801, 0x12345678, 0xbf810000}, decodes ass_setreg_imm32_b32in two words with0x12345678insource0, ands_movk_i32stays one word. Without the fix the test fails withliteral operand word is out of the code span bounds.agc_driver_graphics: every GCN DATA_FORMAT/NUM_FORMAT pair maps to at most one unified buffer format, and each unified format comes from exactly one pair.main7e2ba73e4on this machine:agc_driver_sample_orderand its--grid-referenceand--recipe-depth-locationscases.main. The 3 that fail also fail onmain7e2ba73e4on this machine:agc_driver_sample_orderand its--grid-referenceand--recipe-depth-locationscases.ctest -R "^(agc|video_out|shader|recompiler|gcn)" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan SDK 1.4.363), onmain7e2ba73e4and on this branch alone, same machine and GPU. Both builds use-DANYPS5_VIDEO_OUT_TEST_DRIVER=windows, so the 14 VideoOut flip tests get a real display.main: 913 tests; 907 pass, 3 skip and 3 fail (theagc_driver_sample_ordercases).agc_gcn_decode, which passes.VUID-errors in the same 8 existing PS5 tests, with the same IDs and counts test for test (agc_driver_prepared_exports, the threeagc_driver_sample_ordercases and four others). This PR adds none.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-21T22:39:15Z.
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/Translation/include/Translation/InstructionTranslator.hppL38core/shader/recompiler/Translation/include/Translation/InstructionTranslator.hppL38core/shader/recompiler/Translation/include/Translation/InstructionTranslator.hppL38core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL120core/libs/prx/libSceAgcDriver/tests/TextureFormat.cppL270core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaDescriptorFormat.hppL4-5docs/dev/debt/shader.mdL24docs/dev/debt/shader.mdL24docs/dev/debt/shader.mdL24Some 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/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Translation/include/Translation/InstructionTranslator.hppcore/shader/recompiler/Translation/src/InstructionTranslator.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaDescriptorFormat.hppcore/shader/recompiler/RdnaDecoder/src/RdnaDescriptorFormat.cppcore/shader/recompiler/ShaderDiskCache.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T04:18:10Z.
@Get-fix thanks for splitting the stack. I've been through #9430, and nearly everything is behind
GcnGuestShaders()as the commit message says: the decode dispatch, the descriptor rewriting, the buffer masks, the legacy vertex inputs and the fetch-call rules. One change isn't, and it alters how PS5 (RDNA) shaders are analysed:On main, a write at the reader counts as a change. With this, it's skipped. The caller at
:1533asks whether a descriptor pointer stays unchanged up to thes_loadthat reads it. So an RDNA load that overwrites its own address pair (s_load_dwordx2 s[0:1], s[0:1], ...) is now taken as a user-data pointer load where main refused it. That's arguably more correct, since the load reads before it writes, but it's an RDNA behaviour change inside a PS4-decoding PR, and no RDNA test covers it.Could you either put it behind
GcnGuestShaders()like the rest, or move it into its own small PR with an RDNA case in the scalar-call tests? With the first option, #9430 changes nothing for PS5 titles. The rest reads well to me, and the merged files compile against current main.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:50:47Z.
Review: CHANGES_REQUESTED
The PR reports a useful real Limbo shader stream regression test, format-table coverage, a full Limbo run, and paired Vulkan validation on the same GPU. The current branch still needs repository follow-up before merge:
The PR is 534 commits behind current
main; all reported tests and validation comparisons usececb540a6. Please rebase this shader/recompiler change and its dependent stack onto currentmain, then rerun focused shader/AGC tests and the required paired validation-layer run against the new base.The overlap report still lists open PRs touching shared locations, including #7803 (
ResourceMaterializer.cpp), #7622 (ShaderDiskCache.cpp), #8429 (the descriptor-format header), and #8564/#9020/#9335 (docs/dev/debt/shader.md). Some are insertion-point-only overlaps, but the repository rules still require confirming the actual overlap/order with their authors and recording any requiredDepends onorder. Please refresh the overlap report after rebasing and resolve the surviving entries; the current checklist saysDepends on: nonewhile the report names these open changes.The current automated eligibility, conventions, intake, labels, and report checks pass; Linux/Windows and relinker product jobs are skipped. I did not run the Windows/NVIDIA validation locally because no checkout/build matching this PR head is available in the workspace. The PR's paired test logs are author-reported and apply to the older
cecb540a6baseline.Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-22T11:06:50Z.
@oneandonlydean thanks, you were right: that line changed how RDNA shaders are analysed. It is now behind
GcnGuestShaders()in its own commit (a13d01bcc), so for PS5 shadersunchangedUntilbehaves exactly as onmain:With this, #9430 changes nothing for PS5 titles. If the RDNA case (an
s_loadthat overwrites its own address pair) should be accepted too, I'll send it as its own PR with a scalar-call test, as you suggested.@MarcZX10 the stack is rebased onto
main7e2ba73e4, and the tests, the paired validation-layer runs and a Limbo run were redone on that base (see the description). The refreshed overlap report:TranslateOptions(InstructionTranslator.hppL38). #7803 (@thuanquang) adds a function where this PR addsimageCoordinates(ResourceMaterializer.cppL120). #8026 (@NFSS10) calls its new test afterpackedFloatDccClearTests(), where this PR callsgcnBufferFormatTests()(TextureFormat.cppL270). #8429 (@milescoviello) adds an include and declarations where this PR adds the GCN descriptor declarations (RdnaDescriptorFormat.hpp). #8564 (@JAB-dev), #9020 and #9335 (@frankea) add their owndocs/dev/debt/shader.mdentry after the same line.Depends onstaysnone.main.AI-assisted: yes (Claude Code)
🤖 Generated with Claude Code