fix(libs): take the AMPR wait and counter signatures from ampr_emu #579

Merged
CnRJay merged 3 commits from upstream-pr/579 into main 2026-10-05 00:20:59 +00:00
CnRJay commented 2026-10-04 23:25:47 +00:00 (Migrated from github.com)

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


What

@MichonGoddijn231849, this changes functions from 2b5f2d32. Please check against anything you have from a title.

Several AMPR command buffer exports had signatures and argument meanings that differ from ampr_emu. ampr_emu replaces libSceAmpr on the console for retail titles, and TechnicalDebt already cites it for the marker signatures. Signatures and enum values only are taken from it; no code was copied (it is GPL-3.0).

Export Before Now
sceAmprCommandBufferWaitOnAddress (address, reference, mask, compare) (address, reference, compare, flush)
sceAmprCommandBufferWaitOnCounter (counter, reference, compare) (counter, reference, compare, flush)
sceAmprCommandBufferWriteAddressFromCounterPairOnCompletion (address, counter0, counter1) (address, counter)
sceAmprCommandBufferWriteKernelEventQueueOnCompletion (equeue, ident, data, userData) (equeue, int id, data)

The executor read the compare value with the WAIT_REG_MEM meaning (0 always, 1 <, 2 <=, 3 ==, 4 !=, 5 >=, 6 >), which TechnicalDebt marked as assumed. It now uses the SCE values:

  • the current exports accept 0 ==, 1 > unsigned, 2 < unsigned, 3 !=;
  • 4 >= wrapped, 5 > signed and 6 < signed are also handled, for the _04_00 exports.

With the old reading, a game waiting for value > ref (1) waited for value < ref, and one waiting for != (3) waited for ==.

Validation follows ampr_emu: counter index > 127, compare > 3, flush > 1, a misaligned wait address, a null or misaligned write address, an odd counter-pair start, or a null event queue return EINVAL. The flush is accepted and has no effect, since commands run in order. ampr_emu notes that the console accepts only even counter-pair starts, so the pair of counter n is counters n and n + 1. Which one forms the low 32 bits is not stated, so counter n is assumed to be the low half, as before; the TechnicalDebt entry says so.

Tested

Windows 11, MinGW GCC 15.2.0 r7. guest_ampr_markers (core/libs/tests/GuestAmpr.cpp) gains three tests:

  • Waits: each of the four compares on an address whose condition already holds. Submission runs on a thread with a 10 s deadline, so a wrong encoding fails instead of hanging. Restoring the old meaning of compare 1 makes it fail.
  • Counters: writes, a wait, and reads back a single counter and a counter pair.
  • Rejection: the rejected arguments above, including an odd counter pair and null or misaligned write addresses.

Full ctest: 216/217 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:4738398444 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/579). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-04T23:25:47Z. --- ### What @MichonGoddijn231849, this changes functions from 2b5f2d32. Please check against anything you have from a title. Several AMPR command buffer exports had signatures and argument meanings that differ from [ampr_emu](https://github.com/drakmor/ampr_emu). ampr_emu replaces `libSceAmpr` on the console for retail titles, and TechnicalDebt already cites it for the marker signatures. Signatures and enum values only are taken from it; no code was copied (it is GPL-3.0). | Export | Before | Now | |---|---|---| | `sceAmprCommandBufferWaitOnAddress` | `(address, reference, mask, compare)` | `(address, reference, compare, flush)` | | `sceAmprCommandBufferWaitOnCounter` | `(counter, reference, compare)` | `(counter, reference, compare, flush)` | | `sceAmprCommandBufferWriteAddressFromCounterPairOnCompletion` | `(address, counter0, counter1)` | `(address, counter)` | | `sceAmprCommandBufferWriteKernelEventQueueOnCompletion` | `(equeue, ident, data, userData)` | `(equeue, int id, data)` | The executor read the compare value with the WAIT_REG_MEM meaning (0 always, 1 <, 2 <=, 3 ==, 4 !=, 5 >=, 6 >), which TechnicalDebt marked as assumed. It now uses the SCE values: - the current exports accept `0` ==, `1` > unsigned, `2` < unsigned, `3` !=; - `4` >= wrapped, `5` > signed and `6` < signed are also handled, for the `_04_00` exports. With the old reading, a game waiting for `value > ref` (1) waited for `value < ref`, and one waiting for `!=` (3) waited for `==`. Validation follows ampr_emu: counter index > 127, compare > 3, flush > 1, a misaligned wait address, a null or misaligned write address, an odd counter-pair start, or a null event queue return `EINVAL`. The flush is accepted and has no effect, since commands run in order. ampr_emu notes that the console accepts only even counter-pair starts, so the pair of counter `n` is counters `n` and `n + 1`. Which one forms the low 32 bits is not stated, so counter `n` is assumed to be the low half, as before; the TechnicalDebt entry says so. ### Tested Windows 11, MinGW GCC 15.2.0 r7. `guest_ampr_markers` (core/libs/tests/GuestAmpr.cpp) gains three tests: - **Waits:** each of the four compares on an address whose condition already holds. Submission runs on a thread with a 10 s deadline, so a wrong encoding fails instead of hanging. Restoring the old meaning of compare 1 makes it fail. - **Counters:** writes, a wait, and reads back a single counter and a counter pair. - **Rejection:** the rejected arguments above, including an odd counter pair and null or misaligned write addresses. Full `ctest`: 216/217 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-04 23:44:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:44:09Z.


Thanks, this is a useful fix. I checked every changed signature against ampr_emu (src/sceampr_exports.cpp at cfa85df3) and they match, including the uint8_t counter indexes and the int32_t event id. The compare values match include/ampr.h (0 ==, 1 > unsigned, 2 < unsigned, 3 !=, then 4 to 6 for the versioned forms), and the wrapped and signed evaluations give the same results as ampr_emu's reactor. The argument checks follow its validators too: compare below 4, flush below 2, a 7-bit counter, (index & 0x81) == 0 for a pair, an aligned wait address, and a non-null aligned write address.

It also fixes a real misread on main: with the old signature the compare landed in mask and the flush in compare, so a wait with flush 0 never waited. The event id is sign extended the same way sceKernelAddUserEvent stores it, so the triggered event still matches.

PPSA21564 doesn't import any of the non-versioned exports changed here, and the versioned waits it does import still throw on main, so this doesn't change anything in my runs. guest_ampr_markers covers the new rows: it passes here (with #580 on top), and with main's code it waits until its 10 s deadline and aborts, which is the misread above.

The CI run still needs approval. Once it's green, this is ready to merge from my side. TechnicalDebt.md conflicts with #516, #518 and #553 (same lines), so whichever lands later needs a one-line rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985703532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/579#issuecomment-5985703532). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T23:44:09Z. --- Thanks, this is a useful fix. I checked every changed signature against ampr_emu (src/sceampr_exports.cpp at cfa85df3) and they match, including the `uint8_t` counter indexes and the `int32_t` event id. The compare values match `include/ampr.h` (0 ==, 1 > unsigned, 2 < unsigned, 3 !=, then 4 to 6 for the versioned forms), and the wrapped and signed evaluations give the same results as ampr_emu's reactor. The argument checks follow its validators too: compare below 4, flush below 2, a 7-bit counter, `(index & 0x81) == 0` for a pair, an aligned wait address, and a non-null aligned write address. It also fixes a real misread on main: with the old signature the compare landed in `mask` and the flush in `compare`, so a wait with flush 0 never waited. The event id is sign extended the same way `sceKernelAddUserEvent` stores it, so the triggered event still matches. PPSA21564 doesn't import any of the non-versioned exports changed here, and the versioned waits it does import still throw on main, so this doesn't change anything in my runs. `guest_ampr_markers` covers the new rows: it passes here (with #580 on top), and with main's code it waits until its 10 s deadline and aborts, which is the misread above. The CI run still needs approval. Once it's green, this is ready to merge from my side. TechnicalDebt.md conflicts with #516, #518 and #553 (same lines), so whichever lands later needs a one-line rebase.
oneandonlydean commented 2026-10-05 00:15:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T00:15:43Z.


Thanks for merging main in. The code is the same as the head I reviewed, and the TechnicalDebt.md resolution is right: it keeps main's sceRtcParseDateTime line and replaces the old WAIT_REG_MEM line with yours. guest_ampr_markers passes here on this head on its own (without #580).

The new push needs workflow approval again before CI runs. Ready to merge from my side once it's green. #518 and #553 still touch the same TechnicalDebt.md lines, so whichever of those lands after this one needs a one-line rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985948537 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/579#issuecomment-5985948537). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T00:15:43Z. --- Thanks for merging main in. The code is the same as the head I reviewed, and the TechnicalDebt.md resolution is right: it keeps main's `sceRtcParseDateTime` line and replaces the old WAIT_REG_MEM line with yours. `guest_ampr_markers` passes here on this head on its own (without #580). The new push needs workflow approval again before CI runs. Ready to merge from my side once it's green. #518 and #553 still touch the same TechnicalDebt.md lines, so whichever of those lands after this one needs a one-line rebase.
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!579
No description provided.