Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
XairRrR:fix/agc-empty-register-list
Oct 17, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
XairRrR:fix/agc-empty-register-list

Conversation

@XairRrR

@XairRrR XairRrR commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

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

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 Uncharted: Legacy of Thieves Collection (PPSA05684) on Linux / NVIDIA #4001 (main menu termination)
  • GPUs tested: n/a (command buffer encoding only)
  • AI-assisted: yes

sceAgcCbSetShRegistersDirect and the other register list writers threw on
a count of 0 although the matching size functions report 0 words for it.
PPSA05684 calls the writer with an empty list at its main menu and
terminated. An empty list now writes no packet and returns the cursor,
as its size says; a null buffer still throws.

AI-assisted: yes
@github-actions github-actions Bot added the agc libSceAgc* label Oct 14, 2026
@Dextroid17

Copy link
Copy Markdown
Contributor

Measured on this branch (cf914b5, 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

XairRrR commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for measuring it. The null-buffer case is now covered: f991052 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

Copy link
Copy Markdown
Contributor

Thanks, that closes the gap I noted. Re-run at f991052 as-is (merge base 2b7e3ce, 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 adriadam10 self-assigned this Oct 16, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit f1dded2 into boykopovar:main Oct 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants