feat(agc): implement the Sh and Uc RegistersDirect size queries #575

Merged
DotDebian merged 1 commit from upstream-pr/575 into main 2026-10-04 23:49:13 +00:00
DotDebian commented 2026-10-04 23:08:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-04T23:08:02Z.


What

sceAgcCbSetShRegistersDirectGetSize and sceAgcCbSetUcRegistersDirectGetSize threw not implemented. Their writers go through Agc::Command::WriteRegisters, which emits one SET_SH_REG (0x76) or SET_UCONFIG_REG (0x79) range packet per run of adjacent offsets: a run of k registers takes k + 2 dwords. The query only receives the register count, so it returns the size of the longest output for that count, when no two registers are adjacent: 3 dwords, 12 bytes, per register. A count whose byte size does not fit 32 bits throws.

The size is derived from the existing writer, not from the console library: it is an upper bound whenever the writer merges adjacent registers.

agc_register_command_tests (core/libs/prx/libSceAgc/tests/RegisterCommands.cpp) gains a case for both commands:

  • 1 to 4 non-adjacent registers fill a buffer of exactly the queried size with one packet each, and are rejected with a dword less;
  • 4 adjacent registers, and two adjacent pairs, are written as one and two range packets inside the queried size;
  • a count of 0 gives 0, the largest representable count gives 0xfffffffc, larger counts throw.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, ctest: 213/213 pass. agc_register_command_tests fails on main with the new case (sceAgcCbSetShRegistersDirectGetSize not implemented) and passes with the change. No title run.

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:4738312152 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/575). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-04T23:08:02Z. --- ### What `sceAgcCbSetShRegistersDirectGetSize` and `sceAgcCbSetUcRegistersDirectGetSize` threw `not implemented`. Their writers go through `Agc::Command::WriteRegisters`, which emits one SET_SH_REG (`0x76`) or SET_UCONFIG_REG (`0x79`) range packet per run of adjacent offsets: a run of `k` registers takes `k + 2` dwords. The query only receives the register count, so it returns the size of the longest output for that count, when no two registers are adjacent: 3 dwords, 12 bytes, per register. A count whose byte size does not fit 32 bits throws. The size is derived from the existing writer, not from the console library: it is an upper bound whenever the writer merges adjacent registers. `agc_register_command_tests` (`core/libs/prx/libSceAgc/tests/RegisterCommands.cpp`) gains a case for both commands: - 1 to 4 non-adjacent registers fill a buffer of exactly the queried size with one packet each, and are rejected with a dword less; - 4 adjacent registers, and two adjacent pairs, are written as one and two range packets inside the queried size; - a count of 0 gives 0, the largest representable count gives `0xfffffffc`, larger counts throw. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, `ctest`: 213/213 pass. `agc_register_command_tests` fails on `main` with the new case (`sceAgcCbSetShRegistersDirectGetSize not implemented`) and passes with the change. No title run. ### 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)
github-actions[bot] commented 2026-10-04 23:08:24 +00:00 (Migrated from github.com)

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


Progress report (28e7799 → dd9a62f)

📈 System libraries: 78.78% (+0.07%, +2 implemented functions)

✅ 2 implemented
Library Name
libSceAgc sceAgcCbSetShRegistersDirectGetSize
libSceAgc sceAgcCbSetUcRegistersDirectGetSize
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985443912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/575#issuecomment-5985443912). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T23:08:24Z. --- <!-- progress-report --> ### Progress report (28e7799 → dd9a62f) 📈 **System libraries**: 78.78% (+0.07%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libSceAgc | `sceAgcCbSetShRegistersDirectGetSize` | | libSceAgc | `sceAgcCbSetUcRegistersDirectGetSize` | </details>
oneandonlydean commented 2026-10-04 23:44:04 +00:00 (Migrated from github.com)

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


Thanks. Both names recompute to their NIDs (yUBESvCCJ4I and TGEZzUWLbrc). Since the query only gets the register count, a fixed 12 bytes per register is the only value it can return that is always large enough: a register that isn't adjacent to the previous one needs its own SET_SH_REG (0x76) or SET_UCONFIG_REG (0x79) packet of 3 dwords (header, offset, value; opcodes as in Mesa's sid.h), and the writer's merged runs of k registers take k + 2 dwords, never more than 3k. So the value is right whether the console's writer merges adjacent registers or not. The overflow bound is right too: 0x15555555 * 12 = 0xfffffffc.

The test checks the exact fit with a dword less rejected, the merged and split runs, and the overflow throws. It fails on main ("sceAgcCbSetShRegistersDirectGetSize not implemented") and passes here. Ready to merge from my side.

PPSA21564 calls sceAgcCbSetShRegistersDirect but not the size queries, so this doesn't change anything in my runs.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985703023 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/575#issuecomment-5985703023). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T23:44:04Z. --- Thanks. Both names recompute to their NIDs (yUBESvCCJ4I and TGEZzUWLbrc). Since the query only gets the register count, a fixed 12 bytes per register is the only value it can return that is always large enough: a register that isn't adjacent to the previous one needs its own SET_SH_REG (0x76) or SET_UCONFIG_REG (0x79) packet of 3 dwords (header, offset, value; opcodes as in Mesa's `sid.h`), and the writer's merged runs of k registers take k + 2 dwords, never more than 3k. So the value is right whether the console's writer merges adjacent registers or not. The overflow bound is right too: 0x15555555 * 12 = 0xfffffffc. The test checks the exact fit with a dword less rejected, the merged and split runs, and the overflow throws. It fails on main ("sceAgcCbSetShRegistersDirectGetSize not implemented") and passes here. Ready to merge from my side. PPSA21564 calls `sceAgcCbSetShRegistersDirect` but not the size queries, so this doesn't change anything in my runs.
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!575
No description provided.