feat(agc): implement packet and range predication and the predication sizes #582

Merged
CnRJay merged 4 commits from upstream-pr/582 into main 2026-10-06 01:12:47 +00:00
CnRJay commented 2026-10-04 23:35:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-04T23:35:49Z.


What

Five libSceAgc exports threw NotImplemented.

  • sceAgcSetPacketPredication(packet, predication) sets (1) or clears (0) the PM4 predicate bit (bit 0) of a type-3 packet header and leaves the payload alone. A null packet, a non-type-3 header or a value above 1 throws.
  • sceAgcSetRangePredication(start, end, predication) does the same for every type-3 packet in [start, end). It skips type-2 filler dwords. A range that ends inside a packet or holds another packet type throws.
  • sceAgcDcbSetZPassPredicationEnableGetSize, sceAgcDcbSetPredicationDisableGetSize and sceAgcDcbSetBoolPredicationEnableGetSize return 16 bytes.
    • Their builders are inline in the SDK and not exported. Z-pass, boolean and disable are all PM4 SET_PREDICATION operations, so the size is that of the packet sceAgcDcbSetPredication writes.
    • This is derived, not observed, so it is recorded under Unknown function info in TechnicalDebt.

The executor still rejects predicated packets ("PM4 header flags ... are not implemented") and SET_PREDICATION itself ("GPU query predication is not implemented"). A title that predicates commands still stops at execution with a clear error, rather than running them unconditionally.

Tested

Windows 11, MinGW GCC 15.2.0 r7. New agc_predication_tests:

  • Sizes: the three size queries against the bytes sceAgcDcbSetPredication writes.
  • Single packet: setting and clearing the bit on a packet, and rejecting bad arguments without modifying anything.
  • Range: a range with a filler dword between packets, where payloads and fillers stay untouched. Also an exclusive end, an empty range, a range ending mid-packet, a reversed range, an invalid value and a non-type-2/3 packet.

Full ctest: 217/218 pass. agc_shader_memory fails without this change too; #574 fixes it.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4738453294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/582). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-04T23:35:49Z. --- ### What Five libSceAgc exports threw `NotImplemented`. - `sceAgcSetPacketPredication(packet, predication)` sets (1) or clears (0) the PM4 predicate bit (bit 0) of a type-3 packet header and leaves the payload alone. A null packet, a non-type-3 header or a value above 1 throws. - `sceAgcSetRangePredication(start, end, predication)` does the same for every type-3 packet in `[start, end)`. It skips type-2 filler dwords. A range that ends inside a packet or holds another packet type throws. - `sceAgcDcbSetZPassPredicationEnableGetSize`, `sceAgcDcbSetPredicationDisableGetSize` and `sceAgcDcbSetBoolPredicationEnableGetSize` return 16 bytes. - Their builders are inline in the SDK and not exported. Z-pass, boolean and disable are all PM4 `SET_PREDICATION` operations, so the size is that of the packet `sceAgcDcbSetPredication` writes. - This is derived, not observed, so it is recorded under Unknown function info in TechnicalDebt. The executor still rejects predicated packets ("PM4 header flags ... are not implemented") and `SET_PREDICATION` itself ("GPU query predication is not implemented"). A title that predicates commands still stops at execution with a clear error, rather than running them unconditionally. ### Tested Windows 11, MinGW GCC 15.2.0 r7. New `agc_predication_tests`: - **Sizes:** the three size queries against the bytes `sceAgcDcbSetPredication` writes. - **Single packet:** setting and clearing the bit on a packet, and rejecting bad arguments without modifying anything. - **Range:** a range with a filler dword between packets, where payloads and fillers stay untouched. Also an exclusive end, an empty range, a range ending mid-packet, a reversed range, an invalid value and a non-type-2/3 packet. Full `ctest`: 217/218 pass. `agc_shader_memory` fails without this change too; #574 fixes it. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-05 01:18:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T01:18:26Z.


Thanks. The five NIDs recompute to these names, the predicate bit and the size from the count field are right for a type-3 header, and it matches BryKytyPS5's AgcSetPacketPredication/AgcSetRangePredication, except that you throw for an invalid value or a reversed range, which is fine. The 16-byte sizes with the TechnicalDebt line look good to me too.

One gap in the range walk: the one-dword pad 0xffff1000 (a type-3 NOP with count 0x3fff, which the CP treats as a single dword; main's Commands.cpp test calls it the empty payload marker). Here it's read as a 16385-dword packet. In a short range that throws, but in a range longer than that it silently skips the next 16384 dwords, and those packets keep their old predicate bit. BryKytyPS5 treats (header & 0x3fffff00) == 0x3fff1000 as one dword. Could you do the same (or throw on it), with a test row next to the type-2 filler?

agc_predication_tests passes here and fails on main's code ("sceAgcDcbSetZPassPredicationEnableGetSize not implemented"). It conflicts with #338, #407, #545 and #550 in TechnicalDebt.md (neighbouring lines), so whichever lands later needs a one-line rebase. PPSA21564 doesn't import any of these functions. The CI run still needs workflow approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986481937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/582#issuecomment-5986481937). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T01:18:26Z. --- Thanks. The five NIDs recompute to these names, the predicate bit and the size from the count field are right for a type-3 header, and it matches BryKytyPS5's `AgcSetPacketPredication`/`AgcSetRangePredication`, except that you throw for an invalid value or a reversed range, which is fine. The 16-byte sizes with the TechnicalDebt line look good to me too. One gap in the range walk: the one-dword pad `0xffff1000` (a type-3 NOP with count 0x3fff, which the CP treats as a single dword; main's `Commands.cpp` test calls it the empty payload marker). Here it's read as a 16385-dword packet. In a short range that throws, but in a range longer than that it silently skips the next 16384 dwords, and those packets keep their old predicate bit. BryKytyPS5 treats `(header & 0x3fffff00) == 0x3fff1000` as one dword. Could you do the same (or throw on it), with a test row next to the type-2 filler? `agc_predication_tests` passes here and fails on main's code ("sceAgcDcbSetZPassPredicationEnableGetSize not implemented"). It conflicts with #338, #407, #545 and #550 in TechnicalDebt.md (neighbouring lines), so whichever lands later needs a one-line rebase. PPSA21564 doesn't import any of these functions. The CI run still needs workflow approval.
github-actions[bot] commented 2026-10-05 01:19:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T01:19:44Z.


Progress report (7de111f → 73a751a)

📈 System libraries: 80.85% (+0.15%, +5 implemented functions)

✅ 5 implemented
Library Name
libSceAgc sceAgcDcbSetBoolPredicationEnableGetSize
libSceAgc sceAgcDcbSetPredicationDisableGetSize
libSceAgc sceAgcDcbSetZPassPredicationEnableGetSize
libSceAgc sceAgcSetPacketPredication
libSceAgc sceAgcSetRangePredication
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986492419 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/582#issuecomment-5986492419). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T01:19:44Z. --- <!-- progress-report --> ### Progress report (7de111f → 73a751a) 📈 **System libraries**: 80.85% (+0.15%, +5 implemented functions) <details> <summary>✅ 5 implemented</summary> | Library | Name | | - | - | | libSceAgc | `sceAgcDcbSetBoolPredicationEnableGetSize` | | libSceAgc | `sceAgcDcbSetPredicationDisableGetSize` | | libSceAgc | `sceAgcDcbSetZPassPredicationEnableGetSize` | | libSceAgc | `sceAgcSetPacketPredication` | | libSceAgc | `sceAgcSetRangePredication` | </details>
oneandonlydean commented 2026-10-05 07:26:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T07:26:37Z.


One more thing for when you push the pad change: #338 and #613 have landed since, and both add lines at the end of "Unknown function info" in docs/dev/TechnicalDebt.md, where this PR adds its predication sizes line. Could you rebase onto main at the same time, keeping main's lines and adding yours after them?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5990013047 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/582#issuecomment-5990013047). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T07:26:37Z. --- One more thing for when you push the pad change: #338 and #613 have landed since, and both add lines at the end of "Unknown function info" in `docs/dev/TechnicalDebt.md`, where this PR adds its predication sizes line. Could you rebase onto main at the same time, keeping main's lines and adding yours after them?
github-actions[bot] commented 2026-10-05 23:50:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T23:50:11Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#778 docs/dev/TechnicalDebt.md L122
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6005781507 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/582#issuecomment-6005781507). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T23:50:11Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #778 | `docs/dev/TechnicalDebt.md` [L122](https://github.com/boykopovar/AnyPS5/blob/8afcf7203ffc47671b11769769240407cdf418c4/docs/dev/TechnicalDebt.md#L122) | | |
oneandonlydean commented 2026-10-06 01:12:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T01:12:48Z.


Thanks for the pad change and the rebase. d4f7dda steps over 0xffff10xx as one dword, like a type-2 filler, and leaves it unpredicated. The test now puts the pad between two packets and checks that both still get the bit and that the pad is unchanged, which throws on the previous head. That matches the one-dword size #772 uses for sceAgcGetPacketSize.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6007249930 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/582#issuecomment-6007249930). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T01:12:48Z. --- Thanks for the pad change and the rebase. `d4f7dda` steps over `0xffff10xx` as one dword, like a type-2 filler, and leaves it unpredicated. The test now puts the pad between two packets and checks that both still get the bit and that the pad is unchanged, which throws on the previous head. That matches the one-dword size #772 uses for `sceAgcGetPacketSize`.
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!582
No description provided.