fix(libSceAgc): report a non-WRITE_DATA packet in sceAgcWriteDataPatchSetAddressOrOffset #24158

Merged
almarzn merged 1 commit from upstream-pr/24158 into main 2026-11-20 10:15:16 +00:00
almarzn commented 2026-11-20 08:22:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by almarzn on 2026-11-20T08:22:02Z.


What

sceAgcWriteDataPatchSetAddressOrOffset threw not a WRITE_DATA packet when the packet it is given is not a WRITE_DATA packet. It now returns 0x8a6c000c and leaves the packet unchanged, before the address is checked.

Sources, as reading titles and libraries lists them; no console measurement:

  • KytyPS5 AgcWriteDataPatchSetAddressOrOffset patches dwords 2 and 3 only when the opcode is WRITE_DATA and otherwise returns GRAPHICS5_ERROR_INVALID_PACKET (0x8a6c000c, line 810).
  • The same code is what the PS5 12.70 module returns from sceAgcAcquireMemSetEngine for a packet of the wrong type, already followed here (debt entry).

The Async form, sceAgcWriteDataPatchSetDst and sceAgcWriteDataPatchSetCachePolicy still throw for such a packet: KytyPS5 does not implement them and no other source covers them. The debt fragment records that the behaviour is not measured on a console.

Why a title passes such a packet, from PPSA24913 (Ace Combat 8, UE5) on main:

  • At 0x6384db–0x6385e6 it builds sceAgcCbNop, sceAgcDcbWriteData, sceAgcCbReleaseMem and sceAgcDcbWaitRegMem into a 0x400-byte command buffer on the stack, copies it into another command buffer and rebases the returned pointers. At 0x6386b1–0x6386dd it calls sceAgcGetDataPacketPayloadAddress, then sceAgcWriteDataPatchSetAddressOrOffset, sceAgcWaitRegMemPatchAddress and sceAgcQueueEndOfPipeActionPatchAddress on the rebased pointers.

  • The copy lands in a 0x90-byte static scratch region (0x0d212e90 in that run) that two of its threads also fill through sceAgcDcbContextStateOp, rewinding the cursor to its start each time. A failing call received cmd=0x0d212eb8, inside the NOP(8) that sceAgcDcbContextStateOp writes:

    cmd-8 ... 00000000 00000000 00000000 c0061000 00000000 00000000 00000000 00000000
    cmd   ... 00000000 00000000 00000000 c0071000 00000000 ...
    

    The title ignores the result. With this change it no longer stops at the logos or the world load on this call.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, on main at e825fa1492.

  • agc_write_data_patch_tests: passes. A NOP packet, a packet body and a NOP with a misaligned address each return 0x8a6c000c and stay unchanged for the graphics form; the Async form still throws. Negative control: with WaitRegMem.cpp from main the same test fails with sceAgcWriteDataPatchSetAddressOrOffset: not a WRITE_DATA packet.
  • python3 tools/check_conventions.py --base origin/main: passes. python3 tools/debt_fold.py --check: passes.
  • PPSA24913 (relinked with --to-intel, Intel i5-12600KF, NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.2124): on main it stopped in this call in most runs, from 22 s to 2.5 min. With this change it did not stop in this call in any of three runs; one of them stopped in sceAgcQueueEndOfPipeActionPatchAddress: unexpected packet type, size or flags, the third call of the same sequence, which #22184 changes.

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: PPSA24913 #21185
  • GPUs tested: n/a (libSceAgc packet patching; its test does not use the GPU)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5410158255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24158). Originally posted by [almarzn](https://github.com/almarzn) on 2026-11-20T08:22:02Z. --- ### What `sceAgcWriteDataPatchSetAddressOrOffset` threw `not a WRITE_DATA packet` when the packet it is given is not a WRITE_DATA packet. It now returns `0x8a6c000c` and leaves the packet unchanged, before the address is checked. Sources, as [reading titles and libraries](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/REVERSE_ENGINEERING.md) lists them; no console measurement: - [KytyPS5 `AgcWriteDataPatchSetAddressOrOffset`](https://github.com/KytyPS5/KytyPS5/blob/87f59df17ae75b6303cfdf7a5d85b3d3ed664666/src/libs/agc.cpp#L1470-L1481) patches dwords 2 and 3 only when the opcode is WRITE_DATA and otherwise returns `GRAPHICS5_ERROR_INVALID_PACKET` (`0x8a6c000c`, [line 810](https://github.com/KytyPS5/KytyPS5/blob/87f59df17ae75b6303cfdf7a5d85b3d3ed664666/src/libs/agc.cpp#L810)). - The same code is what the PS5 12.70 module returns from `sceAgcAcquireMemSetEngine` for a packet of the wrong type, already followed here ([debt entry](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/debt/libSceAgc.md)). The Async form, `sceAgcWriteDataPatchSetDst` and `sceAgcWriteDataPatchSetCachePolicy` still throw for such a packet: KytyPS5 does not implement them and no other source covers them. The debt fragment records that the behaviour is not measured on a console. Why a title passes such a packet, from PPSA24913 (Ace Combat 8, UE5) on `main`: - At `0x6384db`–`0x6385e6` it builds `sceAgcCbNop`, `sceAgcDcbWriteData`, `sceAgcCbReleaseMem` and `sceAgcDcbWaitRegMem` into a 0x400-byte command buffer on the stack, copies it into another command buffer and rebases the returned pointers. At `0x6386b1`–`0x6386dd` it calls `sceAgcGetDataPacketPayloadAddress`, then `sceAgcWriteDataPatchSetAddressOrOffset`, `sceAgcWaitRegMemPatchAddress` and `sceAgcQueueEndOfPipeActionPatchAddress` on the rebased pointers. - The copy lands in a 0x90-byte static scratch region (`0x0d212e90` in that run) that two of its threads also fill through `sceAgcDcbContextStateOp`, rewinding the cursor to its start each time. A failing call received `cmd=0x0d212eb8`, inside the NOP(8) that `sceAgcDcbContextStateOp` writes: ``` cmd-8 ... 00000000 00000000 00000000 c0061000 00000000 00000000 00000000 00000000 cmd ... 00000000 00000000 00000000 c0071000 00000000 ... ``` The title ignores the result. With this change it no longer stops at the logos or the world load on this call. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, on `main` at e825fa1492. - `agc_write_data_patch_tests`: passes. A NOP packet, a packet body and a NOP with a misaligned address each return `0x8a6c000c` and stay unchanged for the graphics form; the Async form still throws. Negative control: with `WaitRegMem.cpp` from `main` the same test fails with `sceAgcWriteDataPatchSetAddressOrOffset: not a WRITE_DATA packet`. - `python3 tools/check_conventions.py --base origin/main`: passes. `python3 tools/debt_fold.py --check`: passes. - PPSA24913 (relinked with `--to-intel`, Intel i5-12600KF, NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.2124): on `main` it stopped in this call in most runs, from 22 s to 2.5 min. With this change it did not stop in this call in any of three runs; one of them stopped in `sceAgcQueueEndOfPipeActionPatchAddress: unexpected packet type, size or flags`, the third call of the same sequence, which #22184 changes. ### 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 - [x] Fixes: none - [x] Unblocks: PPSA24913 #21185 - [x] GPUs tested: n/a (libSceAgc packet patching; its test does not use the GPU) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-20 09:06:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T09:06:29Z.

Review: APPROVED


Reviewed — looks good

Nothing in the changed code blocks merging; the graphics address patch reports the invalid packet before address validation and the tests cover the new behavior.

What I ran

Reviewed head 8fcf2009a913265ed5db282c424ae12b57b6a8e3. I read the prepared description, commits, manifest, diff, and all three changed files. No commands or tests were run; reported test results below are author-supplied.

Results

Check Result Note
Code review passed All changed files read
Tests and checks not run Results reported by author

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run independently. The PR description reports the focused test, convention check, and debt check passed, and describes three title runs; these results were not independently verified. No files were excluded from review.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5990078750 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24158#pullrequestreview-5990078750). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T09:06:29Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the changed code blocks merging; the graphics address patch reports the invalid packet before address validation and the tests cover the new behavior. ## What I ran Reviewed head `8fcf2009a913265ed5db282c424ae12b57b6a8e3`. I read the prepared description, commits, manifest, diff, and all three changed files. No commands or tests were run; reported test results below are author-supplied. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | All changed files read | | Tests and checks | not run | Results reported by author | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run independently. The PR description reports the focused test, convention check, and debt check passed, and describes three title runs; these results were not independently verified. No files were excluded from review. ## 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!24158
No description provided.