Skip to content

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

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
CnRJay:fix/ampr-wait-signatures
Oct 5, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
CnRJay:fix/ampr-wait-signatures

Conversation

@CnRJay

@CnRJay CnRJay commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What

@MichonGoddijn231849, this changes functions from 2b5f2d3. 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

CnRJay and others added 2 commits October 4, 2026 18:25
sceAmprCommandBufferWaitOnAddress took (address, reference, mask,
compare) and WaitOnCounter (counter, reference, compare), and both read
the compare value as WAIT_REG_MEM (0 always, 1 <, 2 <=, 3 ==, ...).
ampr_emu, which replaces libSceAmpr for retail titles on the console,
has (address, reference, compare, flush) and (counter, reference,
compare, flush) with the SCE compare values (0 ==, 1 > unsigned,
2 < unsigned, 3 !=), so waits were decoded as other comparisons and
could block forever or pass early.

WriteAddressFromCounterPairOnCompletion takes one counter index, not
two, and WriteKernelEventQueueOnCompletion an int id and no user data.
Counter indices above 127, compare values above 3, flush values above 1
and misaligned wait addresses return EINVAL, as in ampr_emu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As in ampr_emu, a counter pair starts at an even counter, and the write
commands take a non-null, 8-byte aligned address; others return EINVAL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

…tures

# Conflicts:
#	docs/dev/TechnicalDebt.md
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 4, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

@oneandonlydean
oneandonlydean merged commit e440e2c into boykopovar:main Oct 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants