feat(libSceAgcDriver): write the user data packets as firmware 13.42 does #13474

Merged
BunnyFl merged 2 commits from upstream-pr/13474 into main 2026-11-02 17:31:29 +00:00
BunnyFl commented 2026-10-30 16:30:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-10-30T16:30:43Z.


What

sceAgcDriverUserDataWritePacket, sceAgcDriverUserDataWritePushMarker, sceAgcDriverUserDataWriteSetMarker and sceAgcDriverUserDataWritePopMarker were parameterless stubs in core/libs/prx/libSceAgcDriver/Export.cpp that throw. In firmware 13.42's libSceAgcDriver.sprx (read from disassembly, not measured on a console), each one writes thread-trace user data packets into the caller's command buffer and returns how many dwords it wrote:

  • Register packet: a SET_UCONFIG_REG of register 0x342 carrying a 32-bit value.
    • For WritePacket the value is the caller's.
    • For the markers it is a kind (0xC0000000 set, 0xC1000000 push, 0xC2000000 pop) plus the name length in dwords and a packed colour.
    • With data, the same packet also sets 0x343 to the first four bytes.
  • Data packet: a WRITE_DATA (control 0x06010000) of any remaining bytes to register 0xC343, with the last dword zero-padded.
  • Packet sizes:
    • no data: 3 dwords;
    • up to four bytes of data: 4 dwords;
    • more: the payload dword count plus 7, the same sizes sceAgcDriverUserDataGetPacketSize already returns.
  • Second argument: firmware libSceAgc passes 1 from its sceAgcAcb* marker calls and 0 from sceAgcDcbPopMarker, so it is named asyncCompute. When it is 0, header bit 2 is set in both packets.

The four functions now live next to sceAgcDriverUserDataGetPacketSize in Submit/src/Dcb.cpp. Like the other writers there, they check the command buffer and the data range before writing. Their stubs are removed from Export.cpp, and the four names leave the debt entry that lists throwing stubs there.

The PM4 validator accepted header bit 2 (reset filter CAM) only on register-write opcodes. The draw-queue packets put it on a WRITE_DATA whose destination is a register, so validation stopped them. Such a WRITE_DATA now counts as a register write for that check. A WRITE_DATA to memory with bit 2 is still rejected.

A libSceAgcDriver debt entry records the source of the layout and the names that are not known.

Tested

Windows 11, WinLibs GCC 15.2, Release. No title was run.

  • agc_driver_pm4 gains testUserDataWriters: the exact dwords of the pop marker on both queue kinds, of WritePacket on the compute queue (asyncCompute 1) without data, with a null data pointer, with two bytes and with a 9-byte payload, of a push marker on the draw queue (0) and of a set marker on the compute queue (1); the word after the packet is left untouched. Each packet then goes through Validate and Execute; main executes a SET_UCONFIG_REG of 0x342 as a tag marker that writes no register state, so the test checks the 0x343 value only where a separate WRITE_DATA sets it. A WRITE_DATA to memory with header bit 2 is still rejected.
  • On this branch (base main 9304896d89), the 16 agc_driver_pm4* tests pass 3/3. With the four writers made to throw as main's stubs do, agc_driver_pm4 fails 3/3. No other code or test in the repository calls them.
  • Validation layers, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1 and ctest -V, on main and on this branch, same machine and GPU: the 16 agc_driver_pm4* tests pass on both, neither log reports the layer missing, and neither has a VUID- error. These tests create no Vulkan device, so the layer had nothing to check.
  • Locally I ran the firmware's four functions under a CPU emulator and compared them with this branch's built library on 40,000 random calls (asyncCompute 0, 1, 2, 0x80000000 and random values, data sizes from 0 to 200 bytes, a null data pointer in about one call in ten, random values, names and colours): 0 mismatches in the returned count and every written dword. Nothing from the firmware is attached or added.
  • check_conventions.py --base upstream/main passes. pr_overlap.py: my #13471 changes the same debt lines (the list of throwing Export.cpp stubs), so whichever merges second needs a rebase; neither implements the other's functions. The 54 PRs it could not compare (they conflict with main) share files, but none of their diffs names these four. progress.py --compare: +4 implemented functions in libSceAgcDriver, none flagged empty.

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: Windows 11, AMD Radeon RX 9070 XT, driver 32.0.32015.7029. The focused tests ran with the validation-layer variables on main and this branch, but they create no Vulkan device, so they exercise no GPU work (agc_driver_pm4*)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5087652406 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13474). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-10-30T16:30:43Z. --- ### What `sceAgcDriverUserDataWritePacket`, `sceAgcDriverUserDataWritePushMarker`, `sceAgcDriverUserDataWriteSetMarker` and `sceAgcDriverUserDataWritePopMarker` were parameterless stubs in `core/libs/prx/libSceAgcDriver/Export.cpp` that throw. In firmware 13.42's libSceAgcDriver.sprx (read from disassembly, not measured on a console), each one writes thread-trace user data packets into the caller's command buffer and returns how many dwords it wrote: - **Register packet:** a SET_UCONFIG_REG of register 0x342 carrying a 32-bit value. - For `WritePacket` the value is the caller's. - For the markers it is a kind (0xC0000000 set, 0xC1000000 push, 0xC2000000 pop) plus the name length in dwords and a packed colour. - With data, the same packet also sets 0x343 to the first four bytes. - **Data packet:** a WRITE_DATA (control 0x06010000) of any remaining bytes to register 0xC343, with the last dword zero-padded. - **Packet sizes:** - no data: 3 dwords; - up to four bytes of data: 4 dwords; - more: the payload dword count plus 7, the same sizes `sceAgcDriverUserDataGetPacketSize` already returns. - **Second argument:** firmware libSceAgc passes 1 from its `sceAgcAcb*` marker calls and 0 from `sceAgcDcbPopMarker`, so it is named `asyncCompute`. When it is 0, header bit 2 is set in both packets. The four functions now live next to `sceAgcDriverUserDataGetPacketSize` in `Submit/src/Dcb.cpp`. Like the other writers there, they check the command buffer and the data range before writing. Their stubs are removed from `Export.cpp`, and the four names leave the debt entry that lists throwing stubs there. The PM4 validator accepted header bit 2 (reset filter CAM) only on register-write opcodes. The draw-queue packets put it on a WRITE_DATA whose destination is a register, so validation stopped them. Such a WRITE_DATA now counts as a register write for that check. A WRITE_DATA to memory with bit 2 is still rejected. A libSceAgcDriver debt entry records the source of the layout and the names that are not known. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, WinLibs GCC 15.2, Release. No title was run. - `agc_driver_pm4` gains `testUserDataWriters`: the exact dwords of the pop marker on both queue kinds, of `WritePacket` on the compute queue (`asyncCompute` 1) without data, with a null data pointer, with two bytes and with a 9-byte payload, of a push marker on the draw queue (0) and of a set marker on the compute queue (1); the word after the packet is left untouched. Each packet then goes through `Validate` and `Execute`; `main` executes a SET_UCONFIG_REG of 0x342 as a tag marker that writes no register state, so the test checks the 0x343 value only where a separate WRITE_DATA sets it. A WRITE_DATA to memory with header bit 2 is still rejected. - On this branch (base `main` `9304896d89`), the 16 `agc_driver_pm4*` tests pass 3/3. With the four writers made to throw as `main`'s stubs do, `agc_driver_pm4` fails 3/3. No other code or test in the repository calls them. - Validation layers, with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1` and `ctest -V`, on `main` and on this branch, same machine and GPU: the 16 `agc_driver_pm4*` tests pass on both, neither log reports the layer missing, and neither has a `VUID-` error. These tests create no Vulkan device, so the layer had nothing to check. - Locally I ran the firmware's four functions under a CPU emulator and compared them with this branch's built library on 40,000 random calls (`asyncCompute` 0, 1, 2, 0x80000000 and random values, data sizes from 0 to 200 bytes, a null data pointer in about one call in ten, random values, names and colours): 0 mismatches in the returned count and every written dword. Nothing from the firmware is attached or added. - `check_conventions.py --base upstream/main` passes. `pr_overlap.py`: my #13471 changes the same debt lines (the list of throwing `Export.cpp` stubs), so whichever merges second needs a rebase; neither implements the other's functions. The 54 PRs it could not compare (they conflict with `main`) share files, but none of their diffs names these four. `progress.py --compare`: +4 implemented functions in libSceAgcDriver, none flagged empty. ### 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) - [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: Windows 11, AMD Radeon RX 9070 XT, driver 32.0.32015.7029. The focused tests ran with the validation-layer variables on `main` and this branch, but they create no Vulkan device, so they exercise no GPU work (`agc_driver_pm4*`) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!13474
No description provided.