fix(libSceAgc): match firmware atomic GDS arguments and unversioned aliases #8314

Closed
hypermoist wants to merge 10 commits from upstream-pr/8314 into main
hypermoist commented 2026-10-20 09:48:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-20T09:48:09Z.


What

Fixes the atomic GDS builders and adds two unversioned aliases, using the decrypted libSceAgc.sprx exports as evidence.

  • DCB argument layout. sceAgcDcbAtomicGds (pH3-dfRpfA0) and sceAgcDcbAtomicGds_0900 (zARR5aCmkoY) take one more argument than upstream declares:

    • esi is shifted left by 30 into the operation dword (shl ebx, 0x1e).
    • control is in edx (and r13d, 0x20; shl r13d, 0xd).
    • mode is in ecx (xor ecx, 1), gdsOp in r8 and src in r9.
    • offset, index, mask, data, compare and extra are on the stack at +0x10..+0x38.

    Upstream's signature started at control, so every argument a title passed was shifted by one. The new leading engine argument is written to ENGINE_SEL (bits 30-31).

  • Seven-bit op mask. The unversioned builders mask the atomic op to seven bits. The DCB variant computes mov r9d, edx; shl r9d, 7; or r9d, edx; and r9d, 0x1007f, which is (control & 0x7f) | ((control & 0x200) << 7); the ACB variant does the same in edi. _0900 computes (control & 0xff) | ((control << 7) & 0x10000) (movzx eax, dl, then shl esi, 7; and esi, 0x10000). So the only difference is control bit 7, which feeds nothing else, and both unversioned exports forward control & ~0x80u to _0900.

  • New sceAgcAcbAtomicGds (cduV1f0dcGQ). Apart from that mask, it is the same as sceAgcAcbAtomicGds_0900, with the same argument registers.

  • New sceAgcGetFusedShaderSize (nQT5kYLv0cg). Its body is the same as _0080, except that it stores the alignment with mov dword ptr [rdi + 8], 4 instead of mov qword ptr [rdi + 8], 4. It does not call _0080: like the firmware body, it checks the halves and writes back->num_sh_registers * 8 and the 32-bit alignment of 4 itself, without the geometry layout _0080 computes. Mismatched halves return 0x8a6c0008 before the output is touched.

Tested

Linux (CachyOS, GCC, Release). All four targets pass:

  • agc_end_of_shader_action_size_tests now passes an engine. It checks operation dword 0x801500e1 for _0900 and 0x80150061 for the unversioned call.
  • agc_atomic_gds_size_tests checks that the ACB unversioned packet clears bit 7 and that the rest of its payload matches _0900.
  • agc_shader_fusion_tests checks that the unversioned size query leaves the upper dword of m_align untouched.
  • agc_command_tests is unchanged.
  • Validation layer (merged with main 0a0ed72167, head ef101701f1): agc_commands, agc_atomic_gds_size, agc_end_of_shader_action_size_tests and agc_shader_fusion ran under ctest -V with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, on main and on this change, on the same machine and GPU (NVIDIA GeForce RTX 3060, driver 615.78.08, CachyOS Linux 7.2.9, vulkan-validation-layers 1.4.363). All four pass on both. Neither log reports the missing-layer warning, the loader inserted the layer in both, and neither has a VUID- error or any other validation message. Only agc_shader_fusion creates a Vulkan device; the other three build command buffers on the CPU, so the layer has nothing to check there.

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 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 3060, driver 615.78.08, CachyOS Linux 7.2.9 (focused tests with the validation layer; command-buffer building only, no title run)
  • AI-assisted: yes (Claude Code), reviewed by the contributor

Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.

https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4934000270 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8314). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-20T09:48:09Z. --- ### What Fixes the atomic GDS builders and adds two unversioned aliases, using the decrypted `libSceAgc.sprx` exports as evidence. - **DCB argument layout.** `sceAgcDcbAtomicGds` (`pH3-dfRpfA0`) and `sceAgcDcbAtomicGds_0900` (`zARR5aCmkoY`) take one more argument than upstream declares: - `esi` is shifted left by 30 into the operation dword (`shl ebx, 0x1e`). - `control` is in `edx` (`and r13d, 0x20; shl r13d, 0xd`). - mode is in `ecx` (`xor ecx, 1`), gdsOp in `r8` and src in `r9`. - offset, index, mask, data, compare and extra are on the stack at `+0x10..+0x38`. Upstream's signature started at `control`, so every argument a title passed was shifted by one. The new leading `engine` argument is written to ENGINE_SEL (bits 30-31). - **Seven-bit op mask.** The unversioned builders mask the atomic op to seven bits. The DCB variant computes `mov r9d, edx; shl r9d, 7; or r9d, edx; and r9d, 0x1007f`, which is `(control & 0x7f) | ((control & 0x200) << 7)`; the ACB variant does the same in `edi`. `_0900` computes `(control & 0xff) | ((control << 7) & 0x10000)` (`movzx eax, dl`, then `shl esi, 7; and esi, 0x10000`). So the only difference is control bit 7, which feeds nothing else, and both unversioned exports forward `control & ~0x80u` to `_0900`. - **New `sceAgcAcbAtomicGds`** (`cduV1f0dcGQ`). Apart from that mask, it is the same as `sceAgcAcbAtomicGds_0900`, with the same argument registers. - **New `sceAgcGetFusedShaderSize`** (`nQT5kYLv0cg`). Its body is the same as `_0080`, except that it stores the alignment with `mov dword ptr [rdi + 8], 4` instead of `mov qword ptr [rdi + 8], 4`. It does not call `_0080`: like the firmware body, it checks the halves and writes `back->num_sh_registers * 8` and the 32-bit alignment of 4 itself, without the geometry layout `_0080` computes. Mismatched halves return 0x8a6c0008 before the output is touched. ### Tested Linux (CachyOS, GCC, Release). All four targets pass: - `agc_end_of_shader_action_size_tests` now passes an engine. It checks operation dword `0x801500e1` for `_0900` and `0x80150061` for the unversioned call. - `agc_atomic_gds_size_tests` checks that the ACB unversioned packet clears bit 7 and that the rest of its payload matches `_0900`. - `agc_shader_fusion_tests` checks that the unversioned size query leaves the upper dword of `m_align` untouched. - `agc_command_tests` is unchanged. - **Validation layer** (merged with `main` 0a0ed72167, head ef101701f1): `agc_commands`, `agc_atomic_gds_size`, `agc_end_of_shader_action_size_tests` and `agc_shader_fusion` ran under `ctest -V` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, on `main` and on this change, on the same machine and GPU (NVIDIA GeForce RTX 3060, driver 615.78.08, CachyOS Linux 7.2.9, vulkan-validation-layers 1.4.363). All four pass on both. Neither log reports the missing-layer warning, the loader inserted the layer in both, and neither has a `VUID-` error or any other validation message. Only `agc_shader_fusion` creates a Vulkan device; the other three build command buffers on the CPU, so the layer has nothing to check there. ### 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 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3060, driver 615.78.08, CachyOS Linux 7.2.9 (focused tests with the validation layer; command-buffer building only, no title run) - [x] AI-assisted: yes (Claude Code), reviewed by the contributor Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console. https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
MarcZX10 commented 2026-10-23 04:43:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:43:37Z.

Review: CHANGES_REQUESTED


I found a null-output regression in the new sceAgcGetFusedShaderSize wrapper. It calls _0080 with a local result, so _0080’s existing dst == nullptr validation never sees the caller’s pointer. On a successful query the wrapper then unconditionally writes dst->m_size and dst->m_align; a null dst therefore dereferences null instead of taking the established APS5_INVALID_ARG_EX path. The existing _0080 test already expects that path for a null destination, but the new unversioned entry point has no corresponding case. Please validate dst before delegating (or otherwise preserve the same invalid-argument behavior) and add a regression for sceAgcGetFusedShaderSize(nullptr, validFront, validBack).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623981249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8314#pullrequestreview-5623981249). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T04:43:37Z. **Review:** CHANGES_REQUESTED --- I found a null-output regression in the new `sceAgcGetFusedShaderSize` wrapper. It calls `_0080` with a local `result`, so `_0080`’s existing `dst == nullptr` validation never sees the caller’s pointer. On a successful query the wrapper then unconditionally writes `dst->m_size` and `dst->m_align`; a null `dst` therefore dereferences null instead of taking the established `APS5_INVALID_ARG_EX` path. The existing `_0080` test already expects that path for a null destination, but the new unversioned entry point has no corresponding case. Please validate `dst` before delegating (or otherwise preserve the same invalid-argument behavior) and add a regression for `sceAgcGetFusedShaderSize(nullptr, validFront, validBack)`.

Pull request closed

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!8314
No description provided.