feat(libs): implement the AMPR nops and the 04_00 completion writes #580

Merged
CnRJay merged 4 commits from upstream-pr/580 into main 2026-10-05 23:08:22 +00:00
CnRJay commented 2026-10-04 23:28:53 +00:00 (Migrated from github.com)

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


What

Depends on #579, whose commits are included here; only the last commit is new. It reuses the validation added there.

14 libSceAmpr exports threw NotImplemented. Signatures and argument checks follow ampr_emu; only signatures and documented behaviour are taken, no code.

  • sceAmprCommandBufferNop(n) (1..16 dwords) and sceAmprCommandBufferNopWithData(n, data) (0..15 payload dwords) record a Nop with the payload copied. The executor already skips Nop.
    • sceAmprMeasureCommandSizeNop(n) returns the size of Nop(n).
    • sceAmprMeasureCommandSizeNopWithData(n) returns the size of NopWithData(n - 1). ampr_emu reports that retail measures the total record dwords there, while the append takes payload dwords.
    • A null data with a non-zero count throws, since that behaviour is unknown.
  • sceAmprCommandBufferWaitOnAddress_04_00 takes the extended compare set: 4 >= wrapped, 5 > signed, 6 < signed. It needs a non-null aligned address. The executor handles these values since #579.
  • sceAmprCommandBufferWriteAddressFromTimeCounter_04_00, WriteAddressFromCounter_04_00, WriteAddressFromCounterPair_04_00 and WriteKernelEventQueue_04_00 record the same commands as their OnCompletion forms.
    • Their extra at-start (SOP) flag is ignored. The executor runs each command after the previous one completes, so a write at the start of processing and one on completion land at the same point.
  • Their sceAmprMeasureCommandSize*_04_00 forms validate the same arguments and return EINVAL like the marker measures.

Still stubbed: map begin/end, gather/scatter reads, the _04_00 counter waits and writes, and ConstructNop/ConstructMarker. They need executor support or semantics that are not documented.

tools/progress.py: libraries 2529/3190 (79.28%), +14.

Tested

Windows 11, MinGW GCC 15.2.0 r7. guest_ampr_markers gains two tests:

  • Nops: every Nop size against its measure, the NopWithData payload and measure, submission, and the rejected counts.
  • Versioned commands: the _04_00 waits with compares 4/5/6 on values where the signed and unsigned orders differ, run under a 10 s deadline. Also the _04_00 counter, pair and time-counter writes read back after submission, and the rejected arguments and measures.

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: #579
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4738413084 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/580). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-04T23:28:53Z. --- ### What **Depends on #579**, whose commits are included here; only the last commit is new. It reuses the validation added there. 14 libSceAmpr exports threw `NotImplemented`. Signatures and argument checks follow [ampr_emu](https://github.com/drakmor/ampr_emu); only signatures and documented behaviour are taken, no code. - `sceAmprCommandBufferNop(n)` (1..16 dwords) and `sceAmprCommandBufferNopWithData(n, data)` (0..15 payload dwords) record a `Nop` with the payload copied. The executor already skips `Nop`. - `sceAmprMeasureCommandSizeNop(n)` returns the size of `Nop(n)`. - `sceAmprMeasureCommandSizeNopWithData(n)` returns the size of `NopWithData(n - 1)`. ampr_emu reports that retail measures the total record dwords there, while the append takes payload dwords. - A null `data` with a non-zero count throws, since that behaviour is unknown. - `sceAmprCommandBufferWaitOnAddress_04_00` takes the extended compare set: 4 >= wrapped, 5 > signed, 6 < signed. It needs a non-null aligned address. The executor handles these values since #579. - `sceAmprCommandBufferWriteAddressFromTimeCounter_04_00`, `WriteAddressFromCounter_04_00`, `WriteAddressFromCounterPair_04_00` and `WriteKernelEventQueue_04_00` record the same commands as their `OnCompletion` forms. - Their extra at-start (SOP) flag is ignored. The executor runs each command after the previous one completes, so a write at the start of processing and one on completion land at the same point. - Their `sceAmprMeasureCommandSize*_04_00` forms validate the same arguments and return `EINVAL` like the marker measures. Still stubbed: map begin/end, gather/scatter reads, the `_04_00` counter waits and writes, and `ConstructNop`/`ConstructMarker`. They need executor support or semantics that are not documented. `tools/progress.py`: libraries 2529/3190 (79.28%), +14. ### Tested Windows 11, MinGW GCC 15.2.0 r7. `guest_ampr_markers` gains two tests: - **Nops:** every `Nop` size against its measure, the `NopWithData` payload and measure, submission, and the rejected counts. - **Versioned commands:** the `_04_00` waits with compares 4/5/6 on values where the signed and unsigned orders differ, run under a 10 s deadline. Also the `_04_00` counter, pair and time-counter writes read back after submission, and the rejected arguments and measures. 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: #579 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-04 23:44:10 +00:00 (Migrated from github.com)

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


Thanks. The signatures, ranges and checks of the nops, the versioned wait and the versioned writes match ampr_emu (src/sceampr_exports.cpp and src/ampr_emu_command_buffer.cpp at cfa85df3). That includes the NopWithData measure counting the record dwords while the append takes payload dwords. Ignoring the at-start flag gives the same result here, since the executor runs each command only after the previous one has finished. The signed _04_00 row (reference 1, compare 6) is a good one: it would fail with an unsigned compare.

Before it goes in:

  1. Nop size. On the console a Nop(n) record is n dwords including its header (ampr_emu's packing gives n * 4 bytes for a nop, and (n + 1) * 4 for a nop with data). Here the emulator's 8-byte command header comes on top, so Nop(n) takes 8 + 4n bytes. The measure functions agree with that, so a title that sizes with them works. But a title that pads to an exact offset or the end of the buffer with Nop(remaining / 4) gets BUFFER_FULL or a shifted offset. Could you add a line to docs/dev/TechnicalDebt.md for that? The ignored at-start flag could go on the same line.
  2. Two measure checks are stricter than ampr_emu. sceAmprMeasureCommandSizeWriteAddressFromCounter_04_00 rejects counters of 128 and up, and the pair measure rejects index & 0x80, but ampr_emu's measures only check the address, plus index & 1 for the pair. Unless you have another source, I'd match it and adjust the (&single, 128) test row.

For context, PPSA21564 imports Nop, NopWithData and most of the _04_00 forms here. They all throw on main and aren't reached in my runs yet, so this makes them usable without changing the current path.

The CI run still needs approval. This needs #579 first; the commits it carries are identical to #579's head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985703683 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/580#issuecomment-5985703683). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T23:44:10Z. --- Thanks. The signatures, ranges and checks of the nops, the versioned wait and the versioned writes match ampr_emu (src/sceampr_exports.cpp and src/ampr_emu_command_buffer.cpp at cfa85df3). That includes the NopWithData measure counting the record dwords while the append takes payload dwords. Ignoring the at-start flag gives the same result here, since the executor runs each command only after the previous one has finished. The signed `_04_00` row (reference 1, compare 6) is a good one: it would fail with an unsigned compare. Before it goes in: 1. Nop size. On the console a `Nop(n)` record is n dwords including its header (ampr_emu's packing gives n * 4 bytes for a nop, and (n + 1) * 4 for a nop with data). Here the emulator's 8-byte command header comes on top, so `Nop(n)` takes 8 + 4n bytes. The measure functions agree with that, so a title that sizes with them works. But a title that pads to an exact offset or the end of the buffer with `Nop(remaining / 4)` gets `BUFFER_FULL` or a shifted offset. Could you add a line to docs/dev/TechnicalDebt.md for that? The ignored at-start flag could go on the same line. 2. Two measure checks are stricter than ampr_emu. `sceAmprMeasureCommandSizeWriteAddressFromCounter_04_00` rejects counters of 128 and up, and the pair measure rejects `index & 0x80`, but ampr_emu's measures only check the address, plus `index & 1` for the pair. Unless you have another source, I'd match it and adjust the `(&single, 128)` test row. For context, PPSA21564 imports Nop, NopWithData and most of the `_04_00` forms here. They all throw on main and aren't reached in my runs yet, so this makes them usable without changing the current path. The CI run still needs approval. This needs #579 first; the commits it carries are identical to #579's head.
github-actions[bot] commented 2026-10-04 23:44:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T23:44:46Z.


Progress report (681f83e → c3ab220)

📈 System libraries: 79.91% (+0.43%, +14 implemented functions)

✅ 14 implemented
Library Name
libSceAmpr sceAmprCommandBufferNop
libSceAmpr sceAmprCommandBufferNopWithData
libSceAmpr sceAmprCommandBufferWaitOnAddress_04_00
libSceAmpr sceAmprCommandBufferWriteAddressFromCounterPair_04_00
libSceAmpr sceAmprCommandBufferWriteAddressFromCounter_04_00
libSceAmpr sceAmprCommandBufferWriteAddressFromTimeCounter_04_00
libSceAmpr sceAmprCommandBufferWriteKernelEventQueue_04_00
libSceAmpr sceAmprMeasureCommandSizeNop
libSceAmpr sceAmprMeasureCommandSizeNopWithData
libSceAmpr sceAmprMeasureCommandSizeWaitOnAddress_04_00
libSceAmpr sceAmprMeasureCommandSizeWriteAddressFromCounterPair_04_00
libSceAmpr sceAmprMeasureCommandSizeWriteAddressFromCounter_04_00
libSceAmpr sceAmprMeasureCommandSizeWriteAddressFromTimeCounter_04_00
libSceAmpr sceAmprMeasureCommandSizeWriteKernelEventQueue_04_00
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985707938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/580#issuecomment-5985707938). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T23:44:46Z. --- <!-- progress-report --> ### Progress report (681f83e → c3ab220) 📈 **System libraries**: 79.91% (+0.43%, +14 implemented functions) <details> <summary>✅ 14 implemented</summary> | Library | Name | | - | - | | libSceAmpr | `sceAmprCommandBufferNop` | | libSceAmpr | `sceAmprCommandBufferNopWithData` | | libSceAmpr | `sceAmprCommandBufferWaitOnAddress_04_00` | | libSceAmpr | `sceAmprCommandBufferWriteAddressFromCounterPair_04_00` | | libSceAmpr | `sceAmprCommandBufferWriteAddressFromCounter_04_00` | | libSceAmpr | `sceAmprCommandBufferWriteAddressFromTimeCounter_04_00` | | libSceAmpr | `sceAmprCommandBufferWriteKernelEventQueue_04_00` | | libSceAmpr | `sceAmprMeasureCommandSizeNop` | | libSceAmpr | `sceAmprMeasureCommandSizeNopWithData` | | libSceAmpr | `sceAmprMeasureCommandSizeWaitOnAddress_04_00` | | libSceAmpr | `sceAmprMeasureCommandSizeWriteAddressFromCounterPair_04_00` | | libSceAmpr | `sceAmprMeasureCommandSizeWriteAddressFromCounter_04_00` | | libSceAmpr | `sceAmprMeasureCommandSizeWriteAddressFromTimeCounter_04_00` | | libSceAmpr | `sceAmprMeasureCommandSizeWriteKernelEventQueue_04_00` | </details>
oneandonlydean commented 2026-10-05 01:18:24 +00:00 (Migrated from github.com)

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


Thanks, 6f5cb736 covers both: the TechnicalDebt line records the Nop and NopWithData sizes against the console records and the ignored at-start flag, and the two measures now check only what ampr_emu checks (the address, plus an even start for the pair), with the 128 rows flipped to expect a size.

#579 is on main now, and merging this branch into it gives a conflict in docs/dev/TechnicalDebt.md, a leftover of the two separate merges of main. The resolution is to keep your "AMPR command sizes" line under main's pair line; the code merges cleanly, and with that resolution guest_ampr_markers passes here. After that update it's ready to merge from my side (CI is green on 7030c57).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986481705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/580#issuecomment-5986481705). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T01:18:24Z. --- Thanks, 6f5cb736 covers both: the TechnicalDebt line records the Nop and NopWithData sizes against the console records and the ignored at-start flag, and the two measures now check only what ampr_emu checks (the address, plus an even start for the pair), with the 128 rows flipped to expect a size. #579 is on main now, and merging this branch into it gives a conflict in docs/dev/TechnicalDebt.md, a leftover of the two separate merges of main. The resolution is to keep your "AMPR command sizes" line under main's pair line; the code merges cleanly, and with that resolution `guest_ampr_markers` passes here. After that update it's ready to merge from my side (CI is green on 7030c57).
alfalfa-star commented 2026-10-05 18:05:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-05T18:05:45Z.


Tested 7030c573 with LEGO Horizon Adventures (PPSA14632, Unreal Engine), Arch Linux, GCC 16.2, Release, on top of main 0518f0e0 together with #672, #722, #723 and local throwing stubs for the title's other missing imports.

Without this PR the title stops right after Unreal starts its first worker thread:

terminate called after throwing an instance of 'std::runtime_error'
  what():  sceAmprMeasureCommandSizeWriteKernelEventQueue_04_00 not implemented

With it the title continues through its config, key-value store, crash report client and localization setup and starts more threads, until sceVoiceQoSInit, which is not implemented and unrelated to AMPR. The AMPR tests pass on this combination.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6000234196 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/580#issuecomment-6000234196). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-05T18:05:45Z. --- Tested `7030c573` with LEGO Horizon Adventures (PPSA14632, Unreal Engine), Arch Linux, GCC 16.2, Release, on top of main `0518f0e0` together with #672, #722, #723 and local throwing stubs for the title's other missing imports. Without this PR the title stops right after Unreal starts its first worker thread: ``` terminate called after throwing an instance of 'std::runtime_error' what(): sceAmprMeasureCommandSizeWriteKernelEventQueue_04_00 not implemented ``` With it the title continues through its config, key-value store, crash report client and localization setup and starts more threads, until `sceVoiceQoSInit`, which is not implemented and unrelated to AMPR. The AMPR tests pass on this combination.
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!580
No description provided.