fix(agc): read indirect register lists when the command buffer is submitted #1100

Merged
gookie-dev merged 1 commit from upstream-pr/1100 into main 2026-10-08 07:14:03 +00:00
gookie-dev commented 2026-10-07 11:10:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gookie-dev on 2026-10-07T11:10:33Z.


What

SET_SH_REG_INDIRECT, SET_UCONFIG_REG_INDIRECT and SET_CONTEXT_REG_INDIRECT now read their register list when the command buffer is submitted, together with the packets, instead of when the queue worker reaches the packet. The worker writes the registers from that copy. Pm4::Execute still reads the list itself for direct callers.

The driver already copies a submission's packets at submit, so a title that reuses its command memory early does not break the worker. The register lists those packets point to were still read later from live guest memory. If the title rewrites a list in between, the worker throws on what it finds there:

terminate called after throwing an instance of 'std::runtime_error'
  what():  extended register semantics are not implemented (offset dword 0x3a888889)

This is the crash reported in #1034. To answer the question there about what the title waits on: PPSA21402 (Balatro) keeps three frame slots, and before it reuses a slot it busy-waits on that slot's label (Balatro.elf file offset 0x1014b8: while (*slot.label != slot.expected)). At startup it sets every label and every expected value to 0xffffffff (0xff…bf28). The only other writer is each frame's last packet, RELEASE_MEM of the 64-bit value 0xffffffff to 0x280000000 + 0x20 * slot. Hardware watchpoints on the labels show no other CPU write, and no packet writes them. So the wait never blocks, on the console as well. The title's CPU side is held back only by submit blocking. When the queue worker falls behind (first use of the menu's pipelines), the title gets a frame slot ahead and writes per-draw constants over a SET_CONTEXT_REG_INDIRECT list (85 pairs, first 72 bytes overwritten) that the worker has not read yet. The label is therefore not written early by the driver; the title has no effective fence.

On the console the graphics PFP reads the list when it reaches the packet (PAL, gfx9UniversalCmdBuffer.cpp: "The LOAD_CONTEXT_REG_INDEX packet does the load via PFP"). Reading it at submission differs from that for a list written after the submission, by the CPU or by GPU work ahead of the packet behind PFP_SYNC_ME. That case is recorded in TechnicalDebt.md.

This fixes only the abort. Other per-frame data the title rewrites while the worker lags (its uniform constants) can still be read late, which is the flip queue depth question in #1034.

Tested

Pop!_OS 24.04 (kernel 7.1.5), GCC 13.3.0, CMake 3.28.3, Ninja, Release, BUILD_TESTING=ON, SPIRV-Tools validation off, NVIDIA GeForce RTX 4050 Laptop GPU.

  • Default build and libs packaging pass. ctest: 390 of 390 pass.
  • New case in agc_driver_pm4: a DCB waits on a CPU-written label, then runs SET_CONTEXT_REG_INDIRECT and a WRITE_DATA. After submitting, the test rewrites the list's offset to 0x3a888889, then releases the label. With the worker reading the list at execution, the test fails with extended register semantics are not implemented (offset dword 0x3a888889). With this change it passes.
  • PPSA21402 (Balatro 01.015.000) relinked for Linux on main + #1020 (needed to load) + #861 (without it the title segfaults in its libc.prx allocator at startup here). Without this change it aborted with the error above about 8-10 s after start in every run (6 of 6). With it, the error did not occur in any of 10 runs. The next stop was NGS2: waveform block 0 does not fit its data, which #1038 fixes. With #1038 added as well, 3 of 7 runs were still running after 120 s. The other 4 ended in a segfault in libSceNgs2 (in the core dump examined, Ngs2FindVoice called from sceNgs2VoiceGetState reads freed memory), which is unrelated to this change and left for another PR. No audio, input or gameplay claims.
  • Windows not built or tested. Not verified on PS5 hardware.

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

Refs #1034

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4771767056 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1100). Originally posted by [gookie-dev](https://github.com/gookie-dev) on 2026-10-07T11:10:33Z. --- ### What `SET_SH_REG_INDIRECT`, `SET_UCONFIG_REG_INDIRECT` and `SET_CONTEXT_REG_INDIRECT` now read their register list when the command buffer is submitted, together with the packets, instead of when the queue worker reaches the packet. The worker writes the registers from that copy. `Pm4::Execute` still reads the list itself for direct callers. The driver already copies a submission's packets at submit, so a title that reuses its command memory early does not break the worker. The register lists those packets point to were still read later from live guest memory. If the title rewrites a list in between, the worker throws on what it finds there: ``` terminate called after throwing an instance of 'std::runtime_error' what(): extended register semantics are not implemented (offset dword 0x3a888889) ``` This is the crash reported in #1034. To answer the question there about what the title waits on: PPSA21402 (Balatro) keeps three frame slots, and before it reuses a slot it busy-waits on that slot's label (`Balatro.elf` file offset `0x1014b8`: `while (*slot.label != slot.expected)`). At startup it sets every label and every expected value to `0xffffffff` (`0xff…bf28`). The only other writer is each frame's last packet, `RELEASE_MEM` of the 64-bit value `0xffffffff` to `0x280000000 + 0x20 * slot`. Hardware watchpoints on the labels show no other CPU write, and no packet writes them. So the wait never blocks, on the console as well. The title's CPU side is held back only by submit blocking. When the queue worker falls behind (first use of the menu's pipelines), the title gets a frame slot ahead and writes per-draw constants over a `SET_CONTEXT_REG_INDIRECT` list (85 pairs, first 72 bytes overwritten) that the worker has not read yet. The label is therefore not written early by the driver; the title has no effective fence. On the console the graphics PFP reads the list when it reaches the packet (PAL, `gfx9UniversalCmdBuffer.cpp`: "The LOAD_CONTEXT_REG_INDEX packet does the load via PFP"). Reading it at submission differs from that for a list written after the submission, by the CPU or by GPU work ahead of the packet behind `PFP_SYNC_ME`. That case is recorded in TechnicalDebt.md. This fixes only the abort. Other per-frame data the title rewrites while the worker lags (its uniform constants) can still be read late, which is the flip queue depth question in #1034. ### Tested Pop!_OS 24.04 (kernel 7.1.5), GCC 13.3.0, CMake 3.28.3, Ninja, Release, `BUILD_TESTING=ON`, SPIRV-Tools validation off, NVIDIA GeForce RTX 4050 Laptop GPU. - Default build and `libs` packaging pass. `ctest`: 390 of 390 pass. - New case in `agc_driver_pm4`: a DCB waits on a CPU-written label, then runs `SET_CONTEXT_REG_INDIRECT` and a `WRITE_DATA`. After submitting, the test rewrites the list's offset to `0x3a888889`, then releases the label. With the worker reading the list at execution, the test fails with `extended register semantics are not implemented (offset dword 0x3a888889)`. With this change it passes. - PPSA21402 (Balatro 01.015.000) relinked for Linux on `main` + #1020 (needed to load) + #861 (without it the title segfaults in its `libc.prx` allocator at startup here). Without this change it aborted with the error above about 8-10 s after start in every run (6 of 6). With it, the error did not occur in any of 10 runs. The next stop was `NGS2: waveform block 0 does not fit its data`, which #1038 fixes. With #1038 added as well, 3 of 7 runs were still running after 120 s. The other 4 ended in a segfault in `libSceNgs2` (in the core dump examined, `Ngs2FindVoice` called from `sceNgs2VoiceGetState` reads freed memory), which is unrelated to this change and left for another PR. No audio, input or gameplay claims. - Windows not built or tested. Not verified on PS5 hardware. ### 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 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 Refs #1034
adriadam10 commented 2026-10-08 06:45:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T06:45:07Z.


Checked on Linux (RADV): build, libs and full ctest green, and agc_driver_pm4 fails when the non-test changes are reverted. The packet-offset keying of registerLists matches Driver::execute, and the rewind tail reads its lists too. Rebased onto current main (only conflict: the TechnicalDebt.md line next to the COND_INDIRECT_BUFFER one, both kept); rebuilt and ctest green (419/419). Merging once CI is green on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054138183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1100#issuecomment-6054138183). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T06:45:07Z. --- Checked on Linux (RADV): build, `libs` and full ctest green, and `agc_driver_pm4` fails when the non-test changes are reverted. The packet-offset keying of `registerLists` matches `Driver::execute`, and the rewind tail reads its lists too. Rebased onto current `main` (only conflict: the `TechnicalDebt.md` line next to the COND_INDIRECT_BUFFER one, both kept); rebuilt and ctest green (419/419). Merging once CI is green on the rebased head.
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!1100
No description provided.