feat(shader): implement s_swappc_b64 null, long branches and dword jump tables #754

Merged
Celegans12 merged 1 commit from upstream-pr/754 into main 2026-10-05 23:11:57 +00:00
Celegans12 commented 2026-10-05 20:40:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-05T20:40:34Z.


What

The decoder threw unsupported SOP1 opcode 33 on s_swappc_b64 null, s[N:N+1] (0xbefd21NN), and GraphBuilder could not resolve the jumps built around it.

  • SOP1 opcode 33 with SDST null decodes as s_setpc_b64: S_SWAPPC_B64 is D.u64 = PC + 4; PC = S0.u64 (RDNA2 ISA) and null drops the write, as in KytyPS5 DecodeSop1. A real destination (a call) still throws.
  • Long branch: s_getpc_b64, then s_add_u32/s_addc_u32 or s_sub_u32/s_subb_u32 immediates on the same pair (also vcc); the target is the exact 64-bit result, and a jump into the sequence throws.
  • Dword jump table: target = base - s_load_dword entry, with the base from s_getpc_b64/s_add_u32/s_addc_u32 0 and the index bounded by s_min_u32 (at most 255) and scaled by s_lshl_b32 2. The resolver follows the last write of each register through straight-line code, so other code may sit between the steps; anything else is refused. Lowered like the 64-bit tables of #141; the code table load now also takes one-dword entries.
  • PPSA26344 v1.008 all_shaders.xpps: 6 long branches and 25 tables in 11 programs, e.g. 32ac8b907b12797b 0x144 beea1f00 806aff6a 0002ee98 826b806b befd216a, 2bb3e36a02c36373 0x208 (15 entries, v_cmp writes between load and jump), 22cccef7ba602287 0x67ec (index in vcc_lo, load offset 0x50).
  • This also unblocks tessellation M3: the 7 LS front programs end with s_swappc_b64 null, s[6:7] (0xbefd2106), where DecodeRdnaFrontProgram now stops.
  • #387 edits resolveJumpTable (waitcnt variants); this PR does not touch that function and merges cleanly with it.
  • #234 adds s_bfe_i64 to the same decoder file; the two merge cleanly.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 681f83e5: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 317/317 tests pass (ctest --output-on-failure)
  • Extended agc_shader_control_flow (decode, front program, table values and targets, both long branches, structurize and recompile, 8 refusals) and new agc_driver_scalar_swappc (all four shapes on the GPU, wave32 and wave64). Both fail on main with unsupported SOP1 opcode 33.
  • PPSA26344 v1.008 offline sweep: all 11 programs, which failed at decode, now decode and build their graphs, then stop at runtime-indexed descriptors or at state the harness lacks; 3ba7ffa5ac5a098a passes spirv-val with null descriptors. cd88a1ad0e8964d4 (6 tables of 98 entries) spends 25 minutes in Structurizer::Structurize, and 32ac8b907b12797b (10 tables) does not finish it in 90 minutes.
  • Not tested: PPSA21564 (gate not run; expect it), Dreaming Sarah, Linux (CI), console behaviour.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4750520349 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/754). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-05T20:40:34Z. --- ### What The decoder threw `unsupported SOP1 opcode 33` on `s_swappc_b64 null, s[N:N+1]` (`0xbefd21NN`), and `GraphBuilder` could not resolve the jumps built around it. - SOP1 opcode 33 with SDST null decodes as `s_setpc_b64`: S_SWAPPC_B64 is `D.u64 = PC + 4; PC = S0.u64` (RDNA2 ISA) and null drops the write, as in [KytyPS5 `DecodeSop1`](https://github.com/KytyPS5/KytyPS5/blob/77d772217310dc734ce53289110c9be0885a0577/src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp#L144-L147). A real destination (a call) still throws. - Long branch: `s_getpc_b64`, then `s_add_u32`/`s_addc_u32` or `s_sub_u32`/`s_subb_u32` immediates on the same pair (also `vcc`); the target is the exact 64-bit result, and a jump into the sequence throws. - Dword jump table: target = base - `s_load_dword` entry, with the base from `s_getpc_b64`/`s_add_u32`/`s_addc_u32 0` and the index bounded by `s_min_u32` (at most 255) and scaled by `s_lshl_b32 2`. The resolver follows the last write of each register through straight-line code, so other code may sit between the steps; anything else is refused. Lowered like the 64-bit tables of #141; the code table load now also takes one-dword entries. - PPSA26344 v1.008 `all_shaders.xpps`: 6 long branches and 25 tables in 11 programs, e.g. `32ac8b907b12797b` 0x144 `beea1f00 806aff6a 0002ee98 826b806b befd216a`, `2bb3e36a02c36373` 0x208 (15 entries, `v_cmp` writes between load and jump), `22cccef7ba602287` 0x67ec (index in `vcc_lo`, load offset 0x50). - This also unblocks tessellation M3: the 7 LS front programs end with `s_swappc_b64 null, s[6:7]` (`0xbefd2106`), where `DecodeRdnaFrontProgram` now stops. - #387 edits `resolveJumpTable` (waitcnt variants); this PR does not touch that function and merges cleanly with it. - #234 adds `s_bfe_i64` to the same decoder file; the two merge cleanly. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 681f83e5: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 317/317 tests pass (`ctest --output-on-failure`) - Extended `agc_shader_control_flow` (decode, front program, table values and targets, both long branches, structurize and recompile, 8 refusals) and new `agc_driver_scalar_swappc` (all four shapes on the GPU, wave32 and wave64). Both fail on `main` with `unsupported SOP1 opcode 33`. - PPSA26344 v1.008 offline sweep: all 11 programs, which failed at decode, now decode and build their graphs, then stop at runtime-indexed descriptors or at state the harness lacks; `3ba7ffa5ac5a098a` passes `spirv-val` with null descriptors. `cd88a1ad0e8964d4` (6 tables of 98 entries) spends 25 minutes in `Structurizer::Structurize`, and `32ac8b907b12797b` (10 tables) does not finish it in 90 minutes. - Not tested: PPSA21564 (gate not run; expect it), Dreaming Sarah, Linux (CI), console behaviour. ### Checklist - [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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 - [x] AI-assisted: yes
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!754
No description provided.