fix(agc): write nothing for an empty register list #6004

Merged
XairRrR merged 2 commits from upstream-pr/6004 into main 2026-10-17 01:10:52 +00:00
XairRrR commented 2026-10-14 18:52:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-14T18:52:33Z.


What

Agc::Command::WriteRegisters, behind sceAgcCbSetShRegistersDirect, sceAgcCbSetUcRegistersDirect and the sceAgcDcbSet{Cx,Sh,Uc}RegisterDirect writers, threw empty register list on a count of 0, although the matching ...GetSize functions already report 0 bytes for it (agc_register_command_tests checks that). PPSA05684 (Uncharted: Legacy of Thieves Collection) calls sceAgcCbSetShRegistersDirect with an empty list at its main menu and terminated with what(): sceAgcCbSetShRegistersDirect: empty register list.

An empty list now writes no packet, leaves the buffer untouched and returns its cursor, as its size says; a null buffer still throws. No packet is the behaviour the size function implies; the console's own return value for an empty list is not measured.

Tested

  • Linux 7.2.9-zen, GCC, Ninja, Release, main 2b7e3ce69: full ctest 1182 of 1182, tools/check_conventions.py --base origin/main passes.
  • agc_register_command_tests now writes an empty list through each writer into a sentinel-filled buffer and requires the returned pointer to be the cursor, the cursor unchanged and the sentinel intact. With Packet.cpp from main it fails with sceAgcCbSetShRegistersDirect: empty register list.
  • PPSA05684 on a local stack (main plus #757/#758): the main menu no longer terminates on this call.

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
  • Unblocks: PPSA05684 #4001 (main menu termination)
  • GPUs tested: n/a (command buffer encoding only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4862881445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6004). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-14T18:52:33Z. --- ### What `Agc::Command::WriteRegisters`, behind `sceAgcCbSetShRegistersDirect`, `sceAgcCbSetUcRegistersDirect` and the `sceAgcDcbSet{Cx,Sh,Uc}RegisterDirect` writers, threw `empty register list` on a count of 0, although the matching `...GetSize` functions already report 0 bytes for it (`agc_register_command_tests` checks that). PPSA05684 (Uncharted: Legacy of Thieves Collection) calls `sceAgcCbSetShRegistersDirect` with an empty list at its main menu and terminated with `what(): sceAgcCbSetShRegistersDirect: empty register list`. An empty list now writes no packet, leaves the buffer untouched and returns its cursor, as its size says; a null buffer still throws. No packet is the behaviour the size function implies; the console's own return value for an empty list is not measured. ### Tested - Linux 7.2.9-zen, GCC, Ninja, Release, `main` 2b7e3ce69: full ctest 1182 of 1182, `tools/check_conventions.py --base origin/main` passes. - `agc_register_command_tests` now writes an empty list through each writer into a sentinel-filled buffer and requires the returned pointer to be the cursor, the cursor unchanged and the sentinel intact. With `Packet.cpp` from `main` it fails with `sceAgcCbSetShRegistersDirect: empty register list`. - PPSA05684 on a local stack (`main` plus #757/#758): the main menu no longer terminates on this call. ### 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] Unblocks: PPSA05684 #4001 (main menu termination) - [x] GPUs tested: n/a (command buffer encoding only) - [x] AI-assisted: yes
Dextroid17 commented 2026-10-14 22:18:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-14T22:18:51Z.


Measured on this branch (cf914b510, 238 commits behind main), default CMake build (CMAKE_BUILD_TYPE empty, so unoptimized), lavapipe not involved (command-buffer encoding only), CachyOS Linux 7.2.9, agc_register_command_tests, rebuilt:

  • 3 of 3 runs pass.
  • With Packet.cpp taken from main and the new test kept: the added call throws main's sceAgcCbSetShRegistersDirect: empty register list and the test exits 1. That matches the PR body.

I read the change: a count of 0 now returns buffer->cursor_up without writing, and a null buffer still throws (by reading; no test covers a null buffer with count 0). That agrees with ...GetSize(0) == 0, which the existing test already requires.

Not checked: what the console returns for an empty list (the PR body says the same), the title run on PPSA05684, and other targets.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6179753389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6004#issuecomment-6179753389). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-14T22:18:51Z. --- Measured on this branch (cf914b510, 238 commits behind main), default CMake build (CMAKE_BUILD_TYPE empty, so unoptimized), lavapipe not involved (command-buffer encoding only), CachyOS Linux 7.2.9, `agc_register_command_tests`, rebuilt: - 3 of 3 runs pass. - With `Packet.cpp` taken from main and the new test kept: the added call throws main's `sceAgcCbSetShRegistersDirect: empty register list` and the test exits 1. That matches the PR body. I read the change: a count of 0 now returns `buffer->cursor_up` without writing, and a null buffer still throws (by reading; no test covers a null buffer with count 0). That agrees with `...GetSize(0) == 0`, which the existing test already requires. Not checked: what the console returns for an empty list (the PR body says the same), the title run on PPSA05684, and other targets. AI-assisted: yes
XairRrR commented 2026-10-15 00:54:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-15T00:54:53Z.


Thanks for measuring it. The null-buffer case is now covered: f991052cf adds expectFailure([&] { writers[i](nullptr, nullptr, 0); }) next to the empty-list check, for all three writers. With the Require(buffer != nullptr, ...) line removed from WriteRegisters the test crashes (segfault on buffer->cursor_up); with it, it passes.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181863303 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6004#issuecomment-6181863303). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-15T00:54:53Z. --- Thanks for measuring it. The null-buffer case is now covered: f991052cf adds `expectFailure([&] { writers[i](nullptr, nullptr, 0); })` next to the empty-list check, for all three writers. With the `Require(buffer != nullptr, ...)` line removed from `WriteRegisters` the test crashes (segfault on `buffer->cursor_up`); with it, it passes. AI-assisted: yes
Dextroid17 commented 2026-10-16 11:41:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-16T11:41:45Z.


Thanks, that closes the gap I noted. Re-run at f991052cf as-is (merge base 2b7e3ce69, not rebased onto current main), Release build, Linux (CachyOS, kernel 7.2.9), agc_register_command_tests:

  • 3 of 3 pass.
  • With the Require(buffer != nullptr, ...) line in the count == 0 branch of WriteRegisters removed, the test segfaults (exit 139), 3 of 3, as you describe.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6214708991 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6004#issuecomment-6214708991). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-16T11:41:45Z. --- Thanks, that closes the gap I noted. Re-run at f991052cf as-is (merge base 2b7e3ce69, not rebased onto current `main`), Release build, Linux (CachyOS, kernel 7.2.9), `agc_register_command_tests`: - 3 of 3 pass. - With the `Require(buffer != nullptr, ...)` line in the `count == 0` branch of `WriteRegisters` removed, the test segfaults (exit 139), 3 of 3, as you describe. AI-assisted: yes
adriadam10 commented 2026-10-16 20:51:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T20:51:00Z.


Checked on the PR merged onto current main: agc_register_command_tests passes, and with Packet.cpp reverted the new empty-list check fails. Empty list returns the cursor without writing, null buffer still throws, which matches what the ...GetSize functions report; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224452160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6004#issuecomment-6224452160). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T20:51:00Z. --- Checked on the PR merged onto current `main`: `agc_register_command_tests` passes, and with `Packet.cpp` reverted the new empty-list check fails. Empty list returns the cursor without writing, null buffer still throws, which matches what the `...GetSize` functions report; merging.
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!6004
No description provided.