Recompiler: compute s_swappc_b64 calls through a user-data pointer can't be built (free repro: Unity catalog title, 68 of 250 shaders) #3271

Closed
opened 2026-10-11 04:47:18 +00:00 by kr4y4 · 1 comment
kr4y4 commented 2026-10-11 04:47:18 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-11T04:47:18Z.


What

Compute shaders that call through a user-data pointer pair with s_swappc_b64 still can't be built. Since #1836 they are deferred at registration, but a dispatch of one still throws:

computed/data-dependent s_swappc_b64 call target at program counter 0x... is not statically resolvable

So far this has been reported only from retail titles: Ghost of Yōtei and Astro Bot (#1817), Disney Epic Mickey: Rebrushed (johnmaia on #1817, 380 deferred shaders), PPSA15186 (#2207), and Stray, where 371 shaders never prepare and the title stays on its loading screen (#2749).

The same shaders are in a free homebrew title from ps5-homebrew-catalog, so anyone can reproduce this without a retail dump.

Free reproduction

Middle Ages Ping Pong (PPSA28319 01.000.000, Unity, MIT, STL1te/MedievalTennis). The catalog artifact PPSA28319.zip has sha256 6426468091b42f6512a456004e47a0807ae83fc2af82a4408bef8a51103fbd48; its eboot.bin unwrapped from fSELF has sha256 2042d0a4d721c42dbdab0a05c44fe56ee1ed33dbe20422b2576351a149a1112.

The eboot embeds 300 AGC shader headers (1234, version 0x18). 252 of them are paired with their code by the RELATIVE relocations of the table that points at them, which leaves 250 unique compute shaders.

I fed each one through the recompiler offline, without running the title:

  • the request is built from its header registers (COMPUTE_NUM_THREAD_*, COMPUTE_PGM_RSRC1/RSRC2);
  • user data is zeroed and no guest memory is given;
  • the target is VulkanDevice::ComputeTarget on an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU;
  • wave32 and wave64 both run.

Results on main 961b25fe, for both wave sizes:

result RTX 4070 Intel iGPU
PrepareResourceProgram and Recompile succeed 160–161 158–159
Recompile needs guest memory for an SRT read (expected offline) 21–22 21–22
Recompile needs shaderBufferInt64Atomics, which the iGPU lacks – 2
PrepareResourceProgram throws the s_swappc_b64 error above 68 68

The 68 failing shaders share one shape, the one johnmaia described for Epic Mickey:

  • Every call is s_swappc_b64 s[14:15], s[14:15], after s_mov_b32 s14, sN / s_mov_b32 s15, sN+1 from a user-data pair: s[0:1], s[2:3], s[4:5], s[6:7], s[8:9] or s[12:13].
  • 8 shaders make one call. The other 60 make 4 to 13 calls to one or two targets, all through s[14:15].
  • At least 12 make their calls inside a loop (s_branch back over the call).
  • The first call is at 23 different program counters, from 0x3c to 0xdc.

The start of one of them (the caller passes values in VGPRs and reads s[0:3]/s[86:87] from its SRT before calling):

0x2c  s_mov_b32 s14, s0
0x30  s_mov_b32 s15, s1
0x34  s_load_dwordx4 s[0:3], s[8:9], 0x0
0x3c  s_load_dwordx2 s[86:87], s[8:9], 0x10
0x44  s_swappc_b64 s[14:15], s[14:15]

What the current model rejects

GraphBuilder::analyzeSwappcCalls needs four things that these shaders don't give it:

  • a target resolvable from the code (this one is a user-data pointer);
  • one call per link pair (here up to 13 calls share s[14:15]);
  • no other write to the link pair (here s_mov_b32 s14, sN before every call);
  • one s_setpc_b64 return per link pair.

Proposed approach

I'd like to implement this, and would like to know first whether this shape is acceptable:

  1. Driver, at dispatch, deferred shaders only (InvocationFor).
    • For each s_swappc_b64 whose source pair was copied from an unmodified user-data pair in the same block, read the callee from guest memory at the user-data address, up to its s_setpc_b64 on the link pair.
    • Refuse, with a message that names the shader, any callee that has an s_getpc_b64, a branch out of its own code, another s_setpc_b64, or more than a fixed size.
  2. Driver, building the program.
    • Append one copy of the callee per call site after the caller's code.
    • Rewrite that call site as s_call_b64 s[14:15] to its copy. s_call_b64 saves the same link (pc + 4), and TechnicalDebt already notes that forward callees after s_endpgm are decoded.
    • The prepared key then follows the callee code, so different callees give different prepared entries.
  3. GraphBuilder.
    • Pair each call with the return inside its own region, so several calls can share a link pair.
    • Allow writes to the link pair outside every call region, since the call overwrites them.
    • Inside a region, the current rules stay.

Tests would be:

  • a control-flow test of the linked shape: four calls, two targets, inside a loop;
  • an execution test that dispatches a compute shader calling a user-data callee from a loop, on NVIDIA and Intel.

Two questions:

  • Is linking at dispatch acceptable here, or would you rather have the recompiler take the callee code in the request?
  • @EdouardSence offered to work on this on #1817. Are you already on it? If you are, I'll leave it and test your branch instead.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5798060981 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3271). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-11T04:47:18Z. --- ### What Compute shaders that call through a user-data pointer pair with `s_swappc_b64` still can't be built. Since #1836 they are deferred at registration, but a dispatch of one still throws: ``` computed/data-dependent s_swappc_b64 call target at program counter 0x... is not statically resolvable ``` So far this has been reported only from retail titles: Ghost of Yōtei and Astro Bot (#1817), Disney Epic Mickey: Rebrushed (johnmaia on #1817, 380 deferred shaders), PPSA15186 (#2207), and Stray, where 371 shaders never prepare and the title stays on its loading screen (#2749). The same shaders are in a free homebrew title from [ps5-homebrew-catalog](https://github.com/blackbearreloaded/ps5-homebrew-catalog), so anyone can reproduce this without a retail dump. ### Free reproduction Middle Ages Ping Pong (PPSA28319 01.000.000, Unity, MIT, [STL1te/MedievalTennis](https://github.com/STL1te/MedievalTennis)). The catalog artifact `PPSA28319.zip` has sha256 `6426468091b42f6512a456004e47a0807ae83fc2af82a4408bef8a51103fbd48`; its `eboot.bin` unwrapped from fSELF has sha256 `2042d0a4d721c42dbdab0a05c44fe56ee1ed33dbe20422b2576351a149a1112`. The eboot embeds 300 AGC shader headers (`1234`, version `0x18`). 252 of them are paired with their code by the RELATIVE relocations of the table that points at them, which leaves 250 unique compute shaders. I fed each one through the recompiler offline, without running the title: - the request is built from its header registers (`COMPUTE_NUM_THREAD_*`, `COMPUTE_PGM_RSRC1`/`RSRC2`); - user data is zeroed and no guest memory is given; - the target is `VulkanDevice::ComputeTarget` on an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU; - wave32 and wave64 both run. Results on `main` 961b25fe, for both wave sizes: | result | RTX 4070 | Intel iGPU | |---|---|---| | `PrepareResourceProgram` and `Recompile` succeed | 160–161 | 158–159 | | `Recompile` needs guest memory for an SRT read (expected offline) | 21–22 | 21–22 | | `Recompile` needs `shaderBufferInt64Atomics`, which the iGPU lacks | – | 2 | | `PrepareResourceProgram` throws the `s_swappc_b64` error above | **68** | **68** | The 68 failing shaders share one shape, the one johnmaia described for Epic Mickey: - Every call is `s_swappc_b64 s[14:15], s[14:15]`, after `s_mov_b32 s14, sN` / `s_mov_b32 s15, sN+1` from a user-data pair: `s[0:1]`, `s[2:3]`, `s[4:5]`, `s[6:7]`, `s[8:9]` or `s[12:13]`. - 8 shaders make one call. The other 60 make 4 to 13 calls to one or two targets, all through `s[14:15]`. - At least 12 make their calls inside a loop (`s_branch` back over the call). - The first call is at 23 different program counters, from `0x3c` to `0xdc`. The start of one of them (the caller passes values in VGPRs and reads `s[0:3]`/`s[86:87]` from its SRT before calling): ``` 0x2c s_mov_b32 s14, s0 0x30 s_mov_b32 s15, s1 0x34 s_load_dwordx4 s[0:3], s[8:9], 0x0 0x3c s_load_dwordx2 s[86:87], s[8:9], 0x10 0x44 s_swappc_b64 s[14:15], s[14:15] ``` ### What the current model rejects `GraphBuilder::analyzeSwappcCalls` needs four things that these shaders don't give it: - a target resolvable from the code (this one is a user-data pointer); - one call per link pair (here up to 13 calls share `s[14:15]`); - no other write to the link pair (here `s_mov_b32 s14, sN` before every call); - one `s_setpc_b64` return per link pair. ### Proposed approach I'd like to implement this, and would like to know first whether this shape is acceptable: 1. **Driver, at dispatch, deferred shaders only (`InvocationFor`).** - For each `s_swappc_b64` whose source pair was copied from an unmodified user-data pair in the same block, read the callee from guest memory at the user-data address, up to its `s_setpc_b64` on the link pair. - Refuse, with a message that names the shader, any callee that has an `s_getpc_b64`, a branch out of its own code, another `s_setpc_b64`, or more than a fixed size. 2. **Driver, building the program.** - Append one copy of the callee per call site after the caller's code. - Rewrite that call site as `s_call_b64 s[14:15]` to its copy. `s_call_b64` saves the same link (`pc + 4`), and TechnicalDebt already notes that forward callees after `s_endpgm` are decoded. - The prepared key then follows the callee code, so different callees give different prepared entries. 3. **`GraphBuilder`.** - Pair each call with the return inside its own region, so several calls can share a link pair. - Allow writes to the link pair outside every call region, since the call overwrites them. - Inside a region, the current rules stay. Tests would be: - a control-flow test of the linked shape: four calls, two targets, inside a loop; - an execution test that dispatches a compute shader calling a user-data callee from a loop, on NVIDIA and Intel. Two questions: - Is linking at dispatch acceptable here, or would you rather have the recompiler take the callee code in the request? - @EdouardSence offered to work on this on #1817. Are you already on it? If you are, I'll leave it and test your branch instead. Written with AI assistance.
kr4y4 commented 2026-10-11 05:57:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-11T05:57:07Z.


#3294 implements the approach above. Two changes from the proposal:

  • The call sites share s[14:15], so GraphBuilder pairs each call with the return inside its own copy.
  • The caller is cut after its last instruction. The words after it, which are sl00 metadata in these shaders, aren't kept.

@johnmaia, you offered on #1817 to test an implementation on Epic Mickey, and @EdouardSence has Ghost of Yōtei and Astro Bot. A run of #3294 on either would show whether a title actually dispatches these shaders, and what it hits next. I can't run titles here.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106027179 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3271#issuecomment-6106027179). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-11T05:57:07Z. --- #3294 implements the approach above. Two changes from the proposal: - The call sites share `s[14:15]`, so GraphBuilder pairs each call with the return inside its own copy. - The caller is cut after its last instruction. The words after it, which are `sl00` metadata in these shaders, aren't kept. @johnmaia, you offered on #1817 to test an implementation on Epic Mickey, and @EdouardSence has Ghost of Yōtei and Astro Bot. A run of #3294 on either would show whether a title actually dispatches these shaders, and what it hits next. I can't run titles here. Written with AI assistance.
Sign in to join this conversation.
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#3271
No description provided.