fix(shader): refuse GCN DPP instructions by name #23237
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23237"
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 adam25136 on 2026-11-18T20:45:00Z.
What
A VOP1, VOP2 or VOPC instruction whose first source is
0xFAuses DPP: a second word holds the real first source and a lane-crossing control. On GCN, DPP exists only in gfx8 and gfx9 (LLVM; gfx6 and gfx7 define only the 32- and 64-bit forms, L1486-L1506), and shadPS4 also reads operand 250 as DPP (opcodes.h, decode.cpp).The GCN path rewrites each GCN instruction into RDNA words before decoding it, and for most opcodes it rewrote a DPP instruction into one word. Nearly every such instruction already failed, but in a way that hides what it is, and two decoded wrongly:
std::out_of_range.ReadRawShader, which reads an unregistered shader from guest memory, takes that error as "read more code". It kept reading until the end of mapped memory or its 1 MiB limit, and stopped with "raw shader program has no reachable end within mapped code or the size limit", which names no instruction.v_add_i32) failed in the VOP3 decoder instead, with "unsupported scalar source operand code 250".v_madmk_f32andv_madak_f32read the DPP word as their constant and failed with "DPP modifier is not supported for opcode".v_nopandv_clrexcpdecoded as one word, and their DPP word was then decoded as the next instruction.The change:
GcnInstructionDecoder.cpp:encodeGcnrefuses such an instruction before the rewrite, as an unsupportedVOP1_DPP,VOP2_DPPorVOPC_DPPinstruction with its opcode and program counter. That error is not astd::out_of_range, soReadRawShaderpasses it on at once. At registration,PlanRegistereddefers a shader to its first use on an unsupported-instruction error but not on other errors such asstd::out_of_range, so a registered shader with DPP now takes that deferred path, like one with any other unsupported instruction.tests/GcnDecode.cpp(agc_gcn_decode) checks, with hand-built encodings:v_mov_b32,v_nop,v_add_f32,v_add_i32,v_cmp_lt_f32andv_cmp_lt_i32(opcode 0x81) are refused with their family and opcode;v_madmk_f32, whose constant would otherwise be read first;v_mov_b32from VGPR v250 (first-source field0x1FA) still decodes.docs/dev/debt/changes/fix-gcn-dpp-refusal.md: records that GCN DPP throws.Why all of DPP is refused rather than passed through to the RDNA decoder: no title is known to use it, its layout isn't measured on a PS4 Pro, and some GCN DPP controls (
wave_shl,wave_rol,wave_shr,wave_ror,row_bcast) exist only on gfx8 and gfx9, not on RDNA (LLVM). The one PS4 Pro shader checked for it, inFAMOUS Second Son's compute shader at0x2f2fb2100, uses SDWA 67 times and DPP not at all.This came out of the code review of #23128 (GCN SDWA), which changes the same file. The check sits in
encodeGcn, not in the three encoders #23128 changes, and the two branches merge without conflicts in either order.Tested
Windows 10 Pro 19045, NVIDIA GeForce RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 r7, Release. This branch (
7b53e2ef0b) is onmain3858655d2a. The runs below were onmainf15df3256c: the full round on 5b973bc0f6, and the last checks on ab7e786ad9, which has the same changed lines as this branch. Themaincommits since then change none of this PR's files.agc_gcn_decodepasses (ab7e786ad9).GcnInstructionDecoder.cppchange reversed and the tests kept, 8 of its checks fail, among them "DPP v_mov_b32 was not refused as VOP1_DPP" and "DPP v_nop was not refused as VOP1_DPP".v_nopcase was added):v_mov_b32from v250 is refused ("GCN VOP1_DPP opcode 1 at program counter 0 is not implemented").8e869690fc(a local trial merge;git merge-treegives the same tree in both orders),agc_gcn_decodepasses with both PRs' tests.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer VK_LOADER_LAYERS_DISABLE=~implicit~),ctest -R 'gcn|Gcn' -V: 13 of 13 pass on the branch and onmain. The layer is inserted 10 times in each log, with no "not found" line and noVUID-line.tools/select_tests.py selectpicks for the two changed source files (3,223), run withselect_tests.py ctest build --parallel 4 --timeout 120andANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1on the branch and onmain:agc_driver_bda_device,agc_driver_msaa_dcc_unwatch,agc_driver_stencil_plane_memory,agc_driver_store_over_untracked, andagc_driver_upload_cache_read_only_flush, whose test executable doesn't build here on either side (setenvis not declared).agc_driverreached the 120 s timeout on the branch only. Run alone, it passes 3 of 3 on the branch, in 20 s, 38 s and 113 s.ANYPS5_ENABLE_SPIRV_TOOLS=ON(5b973bc0f6): everything builds exceptagc_driver_upload_cache_read_only_flush_tests, with the samesetenverror as in the normal build ofmain.tools/check_conventions.pywith this title and description passes, andtools/debt_fold.py --checkpasses; the new entry lands after the otherGcnInstructionDecoder.cppentries indocs/dev/debt/shader.md.tools/pr_overlap.py --branch fix/gcn-dpp-refusal(5b973bc0f6): no overlap with the 1,930 open pull requests (5 touch the same files; none conflicts).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)AI-assisted: Claude Code found the gap while reviewing #23128, wrote the change and its tests, ran the tests, and drafted this description; separate review agents checked it.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T06:17:23Z.
Review: APPROVED
Reviewed — looks good
The changed code explicitly rejects GCN DPP encodings before rewriting them, and the inspected tests cover each affected instruction family, truncation, and the v250 source edge case at head
7b53e2ef0bc598406ce65d57f5181c6eeff07158.What I ran
No commands or tests were run. I read the prepared description, commits, manifest, diff, and all three changed files at the pinned head.
Results
Findings
Blocking
None.
Non-blocking
None.
Sources
core/shader/recompiler/RdnaDecoder/src/GcnInstructionDecoder.cppconfirms DPP detection and family-specific refusal before encoding.core/libs/prx/libSceAgcDriver/tests/GcnDecode.cppcovers VOP1, VOP2 and VOPC refusals, truncated encodings, and valid use of source register v250.docs/dev/debt/changes/fix-gcn-dpp-refusal.mdrecords the unsupported behavior.Not verified
No tests or build checks were run in this review; the test and validation results in the PR description were not independently verified. The prepared manifest lists three changed files, all included and read. No files were excluded by the manifest.
To get this to a good state
Nothing is required.