fix(libSceAgc): accept s_swappc_b64 null, s[6:7] as a front half's terminator #1124

Merged
TideOPL merged 1 commit from upstream-pr/1124 into main 2026-10-08 07:55:07 +00:00
TideOPL commented 2026-10-07 13:14:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-07T13:14:00Z.


What

sceAgcUnknownGetFusedShaderSize / sceAgcUnknownFuseShaderHalves require a front half to end with s_setpc_b64 s[6:7] (0xbe802006) before its s_code_end padding. PPSA16064 (Minecraft Dungeons II, Unreal Engine) has front halves ending with 0xbefd2106 instead, so the size query threw front half does not end with s_setpc_b64 s[6:7] on a worker thread, and rendering stopped about 6 s in.

0xbefd2106 is SOP1 S_SWAPPC_B64 (opcode 0x21) with SSRC0 s[6:7] and SDST 125 = NULL (RDNA2 ISA, SOP1 opcodes and the scalar operand table). It jumps to s[6:7] and discards the return address, the same transfer as s_setpc_b64 s[6:7]. Fusion drops this instruction and pads to the back half with s_nop either way, so both forms are accepted. Any other last instruction still throws.

Tested

  • Windows 11, NVIDIA GeForce RTX 5070, MinGW-w64 GCC 15.2.0 (WinLibs UCRT r7). Full ctest: 393/393.
  • agc_shader_fusion: runs the full fusion check on a front half ending with the s_swappc_b64 form, including that the terminator is replaced by s_nop padding. Fails on main with the title's error.
  • PPSA16064: the title's fused shaders build.

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:4773172166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1124). Originally posted by [TideOPL](https://github.com/TideOPL) on 2026-10-07T13:14:00Z. --- ### What `sceAgcUnknownGetFusedShaderSize` / `sceAgcUnknownFuseShaderHalves` require a front half to end with `s_setpc_b64 s[6:7]` (`0xbe802006`) before its `s_code_end` padding. PPSA16064 (Minecraft Dungeons II, Unreal Engine) has front halves ending with `0xbefd2106` instead, so the size query threw `front half does not end with s_setpc_b64 s[6:7]` on a worker thread, and rendering stopped about 6 s in. `0xbefd2106` is SOP1 `S_SWAPPC_B64` (opcode `0x21`) with SSRC0 `s[6:7]` and SDST 125 = `NULL` (RDNA2 ISA, SOP1 opcodes and the scalar operand table). It jumps to `s[6:7]` and discards the return address, the same transfer as `s_setpc_b64 s[6:7]`. Fusion drops this instruction and pads to the back half with `s_nop` either way, so both forms are accepted. Any other last instruction still throws. ### Tested - Windows 11, NVIDIA GeForce RTX 5070, MinGW-w64 GCC 15.2.0 (WinLibs UCRT r7). Full `ctest`: 393/393. - `agc_shader_fusion`: runs the full fusion check on a front half ending with the `s_swappc_b64` form, including that the terminator is replaced by `s_nop` padding. Fails on `main` with the title's error. - PPSA16064: the title's fused shaders build. ### 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
adriadam10 commented 2026-10-08 07:55:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T07:55:04Z.


Checked: 0xbefd2106 encodes s_swappc_b64 null, s[6:7] (llvm-mc gfx1030); agc_shader_fusion passes on the merge with main and fails without the ShaderFusion.cpp change; the test also checks the terminator is replaced by s_nop padding; Linux and Windows CI green. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6055393826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1124#issuecomment-6055393826). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T07:55:04Z. --- Checked: `0xbefd2106` encodes `s_swappc_b64 null, s[6:7]` (llvm-mc gfx1030); `agc_shader_fusion` passes on the merge with main and fails without the `ShaderFusion.cpp` change; the test also checks the terminator is replaced by `s_nop` padding; Linux and Windows CI green. Merging.
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!1124
No description provided.