fix(shader): refuse GCN DPP instructions by name #23237

Merged
adam25136 merged 1 commit from upstream-pr/23237 into main 2026-11-27 00:53:22 +00:00
adam25136 commented 2026-11-18 20:45:00 +00:00 (Migrated from github.com)

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 0xFA uses 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:

  • The RDNA decoder found the DPP word missing ("truncated VOP1 DPP instruction", and the same for VOP2 and VOPC), a 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.
  • The DPP form of a VOP2 opcode that AnyPS5 promotes to VOP3 (such as v_add_i32) failed in the VOP3 decoder instead, with "unsupported scalar source operand code 250".
  • v_madmk_f32 and v_madak_f32 read the DPP word as their constant and failed with "DPP modifier is not supported for opcode".
  • v_nop and v_clrexcp decoded as one word, and their DPP word was then decoded as the next instruction.

The change:

  • GcnInstructionDecoder.cpp: encodeGcn refuses such an instruction before the rewrite, as an unsupported VOP1_DPP, VOP2_DPP or VOPC_DPP instruction with its opcode and program counter. That error is not a std::out_of_range, so ReadRawShader passes it on at once. At registration, PlanRegistered defers a shader to its first use on an unsupported-instruction error but not on other errors such as std::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:
    • DPP v_mov_b32, v_nop, v_add_f32, v_add_i32, v_cmp_lt_f32 and v_cmp_lt_i32 (opcode 0x81) are refused with their family and opcode;
    • a DPP instruction is refused even when the code ends after its first word, including v_madmk_f32, whose constant would otherwise be read first;
    • v_mov_b32 from VGPR v250 (first-source field 0x1FA) 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 at 0x2f2fb2100, 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 on main 3858655d2a. The runs below were on main f15df3256c: the full round on 5b973bc0f6, and the last checks on ab7e786ad9, which has the same changed lines as this branch. The main commits since then change none of this PR's files.

  • agc_gcn_decode passes (ab7e786ad9).
    • With the GcnInstructionDecoder.cpp change 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".
    • Each deliberate break fails it, and the restored code passes (5b973bc0f6, before the v_nop case was added):
      • the whole check removed: "DPP v_mov_b32 was not refused as VOP1_DPP";
      • the VOPC arm dropped: "DPP v_cmp_lt_f32 was not refused as VOPC_DPP";
      • the VOP1 arm dropped, or its opcode read from the VOPC field: "DPP v_mov_b32 was not refused as VOP1_DPP";
      • the VOPC opcode cut to 7 bits: "DPP v_cmp_lt_i32 was not refused as VOPC_DPP with its opcode";
      • the VOP2 refusal dropped: "DPP v_add_f32 was not refused as VOP2_DPP";
      • the first source compared on 8 bits: v_mov_b32 from v250 is refused ("GCN VOP1_DPP opcode 1 at program counter 0 is not implemented").
    • The whole check removed again on ab7e786ad9: the test fails.
    • Merged with #23128's head 8e869690fc (a local trial merge; git merge-tree gives the same tree in both orders), agc_gcn_decode passes with both PRs' tests.
  • Validation layer (Khronos 1.4.367 from a local folder, 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 on main. The layer is inserted 10 times in each log, with no "not found" line and no VUID- line.
  • The tests tools/select_tests.py select picks for the two changed source files (3,223), run with select_tests.py ctest build --parallel 4 --timeout 120 and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 on the branch and on main:
    • The same 5 fail on both: agc_driver_bda_device, agc_driver_msaa_dcc_unwatch, agc_driver_stencil_plane_memory, agc_driver_store_over_untracked, and agc_driver_upload_cache_read_only_flush, whose test executable doesn't build here on either side (setenv is not declared).
    • agc_driver reached 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.
    • Both skip the same 19 tests.
  • Build with ANYPS5_ENABLE_SPIRV_TOOLS=ON (5b973bc0f6): everything builds except agc_driver_upload_cache_read_only_flush_tests, with the same setenv error as in the normal build of main.
  • No title was run: none is known to use GCN DPP.
  • tools/check_conventions.py with this title and description passes, and tools/debt_fold.py --check passes; the new entry lands after the other GcnInstructionDecoder.cpp entries in docs/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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 621.14, Windows 10 Pro 19045
  • AI-assisted: yes

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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5383788701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23237). Originally posted by [adam25136](https://github.com/adam25136) on 2026-11-18T20:45:00Z. --- ### What A VOP1, VOP2 or VOPC instruction whose first source is `0xFA` uses DPP: a second word holds the real first source and a lane-crossing control. On GCN, DPP exists only in gfx8 and gfx9 ([LLVM](https://github.com/llvm/llvm-project/blob/48d0dc8f61a7680190a144ef89bd80543c0ec4f9/llvm/lib/Target/AMDGPU/VOP1Instructions.td#L1599-L1608); gfx6 and gfx7 define only the 32- and 64-bit forms, [L1486-L1506](https://github.com/llvm/llvm-project/blob/48d0dc8f61a7680190a144ef89bd80543c0ec4f9/llvm/lib/Target/AMDGPU/VOP1Instructions.td#L1486-L1506)), and shadPS4 also reads operand 250 as DPP ([opcodes.h](https://github.com/shadps4-emu/shadPS4/blob/7c0b846d0579c7c13b4c2d76032227b68615d068/src/shader_recompiler/frontend/opcodes.h#L2572-L2583), [decode.cpp](https://github.com/shadps4-emu/shadPS4/blob/7c0b846d0579c7c13b4c2d76032227b68615d068/src/shader_recompiler/frontend/decode.cpp#L511-L520)). 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: - The RDNA decoder found the DPP word missing ("truncated VOP1 DPP instruction", and the same for VOP2 and VOPC), a `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. - The DPP form of a VOP2 opcode that AnyPS5 promotes to VOP3 (such as `v_add_i32`) failed in the VOP3 decoder instead, with "unsupported scalar source operand code 250". - `v_madmk_f32` and `v_madak_f32` read the DPP word as their constant and failed with "DPP modifier is not supported for opcode". - `v_nop` and `v_clrexcp` decoded as one word, and their DPP word was then decoded as the next instruction. The change: - `GcnInstructionDecoder.cpp`: `encodeGcn` refuses such an instruction before the rewrite, as an unsupported `VOP1_DPP`, `VOP2_DPP` or `VOPC_DPP` instruction with its opcode and program counter. That error is not a `std::out_of_range`, so `ReadRawShader` passes it on at once. At registration, `PlanRegistered` defers a shader to its first use on an unsupported-instruction error but not on other errors such as `std::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: - DPP `v_mov_b32`, `v_nop`, `v_add_f32`, `v_add_i32`, `v_cmp_lt_f32` and `v_cmp_lt_i32` (opcode 0x81) are refused with their family and opcode; - a DPP instruction is refused even when the code ends after its first word, including `v_madmk_f32`, whose constant would otherwise be read first; - `v_mov_b32` from VGPR v250 (first-source field `0x1FA`) 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](https://github.com/llvm/llvm-project/blob/48d0dc8f61a7680190a144ef89bd80543c0ec4f9/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp#L10305-L10320)). The one PS4 Pro shader checked for it, inFAMOUS Second Son's compute shader at `0x2f2fb2100`, 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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 10 Pro 19045, NVIDIA GeForce RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 r7, Release. This branch (7b53e2ef0b) is on `main` 3858655d2a. The runs below were on `main` f15df3256c: the full round on 5b973bc0f6, and the last checks on ab7e786ad9, which has the same changed lines as this branch. The `main` commits since then change none of this PR's files. - **`agc_gcn_decode` passes** (ab7e786ad9). - With the `GcnInstructionDecoder.cpp` change 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". - Each deliberate break fails it, and the restored code passes (5b973bc0f6, before the `v_nop` case was added): - the whole check removed: "DPP v_mov_b32 was not refused as VOP1_DPP"; - the VOPC arm dropped: "DPP v_cmp_lt_f32 was not refused as VOPC_DPP"; - the VOP1 arm dropped, or its opcode read from the VOPC field: "DPP v_mov_b32 was not refused as VOP1_DPP"; - the VOPC opcode cut to 7 bits: "DPP v_cmp_lt_i32 was not refused as VOPC_DPP with its opcode"; - the VOP2 refusal dropped: "DPP v_add_f32 was not refused as VOP2_DPP"; - the first source compared on 8 bits: `v_mov_b32` from v250 is refused ("GCN VOP1_DPP opcode 1 at program counter 0 is not implemented"). - The whole check removed again on ab7e786ad9: the test fails. - Merged with #23128's head 8e869690fc (a local trial merge; `git merge-tree` gives the same tree in both orders), `agc_gcn_decode` passes with both PRs' tests. - **Validation layer** (Khronos 1.4.367 from a local folder, `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 on `main`. The layer is inserted 10 times in each log, with no "not found" line and no `VUID-` line. - **The tests `tools/select_tests.py select` picks for the two changed source files** (3,223), run with `select_tests.py ctest build --parallel 4 --timeout 120` and `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` on the branch and on `main`: - The same 5 fail on both: `agc_driver_bda_device`, `agc_driver_msaa_dcc_unwatch`, `agc_driver_stencil_plane_memory`, `agc_driver_store_over_untracked`, and `agc_driver_upload_cache_read_only_flush`, whose test executable doesn't build here on either side (`setenv` is not declared). - `agc_driver` reached 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. - Both skip the same 19 tests. - **Build with `ANYPS5_ENABLE_SPIRV_TOOLS=ON`** (5b973bc0f6): everything builds except `agc_driver_upload_cache_read_only_flush_tests`, with the same `setenv` error as in the normal build of `main`. - No title was run: none is known to use GCN DPP. - `tools/check_conventions.py` with this title and description passes, and `tools/debt_fold.py --check` passes; the new entry lands after the other `GcnInstructionDecoder.cpp` entries in `docs/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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 621.14, Windows 10 Pro 19045 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> 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](https://claude.com/claude-code)
MarcZX10 commented 2026-11-23 06:17:23 +00:00 (Migrated from github.com)

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

Check Result Note
Change and targeted source review passed All three changed files read
Tests not run Results in the description are author reported

Findings

Blocking

None.

Non-blocking

None.

Sources

  • core/shader/recompiler/RdnaDecoder/src/GcnInstructionDecoder.cpp confirms DPP detection and family-specific refusal before encoding.
  • core/libs/prx/libSceAgcDriver/tests/GcnDecode.cpp covers VOP1, VOP2 and VOPC refusals, truncated encodings, and valid use of source register v250.
  • docs/dev/debt/changes/fix-gcn-dpp-refusal.md records 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017304148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23237#pullrequestreview-6017304148). Originally posted by [MarcZX10](https://github.com/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 | Check | Result | Note | |---|---|---| | Change and targeted source review | passed | All three changed files read | | Tests | not run | Results in the description are author reported | ## Findings ### Blocking None. ### Non-blocking None. ## Sources - `core/shader/recompiler/RdnaDecoder/src/GcnInstructionDecoder.cpp` confirms DPP detection and family-specific refusal before encoding. - `core/libs/prx/libSceAgcDriver/tests/GcnDecode.cpp` covers VOP1, VOP2 and VOPC refusals, truncated encodings, and valid use of source register v250. - `docs/dev/debt/changes/fix-gcn-dpp-refusal.md` records 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!23237
No description provided.