Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
gookie-dev:fix/agc-indirect-register-lists-at-submission
Oct 8, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
gookie-dev:fix/agc-indirect-register-lists-at-submission

Conversation

@gookie-dev

Copy link
Copy Markdown
Contributor

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.

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

…mitted

The driver copies a submission's packets when it is submitted, but
SET_SH_REG_INDIRECT, SET_UCONFIG_REG_INDIRECT and SET_CONTEXT_REG_INDIRECT
read their (offset, value) lists from guest memory only when the queue
worker reaches the packet. A title that reuses its per-frame memory once
it expects the GPU to be done with it can rewrite a list in between, and
the worker then throws on the data it finds there ("extended register
semantics are not implemented (offset dword 0x3a888889)").

The lists are now read with the packets, after validation, in Submit and
for a rewind tail, and the worker writes the registers from that copy.
Pm4::Execute keeps reading the list itself for direct callers.

PPSA21402 (Balatro) keeps three frame slots and does not wait for the GPU
before reusing one: its slot labels start at 0xffffffff and the GPU only
ever writes 0xffffffff to them, so the poll before a slot is reused never
blocks. When the worker falls more than two frames behind, the title
writes per-draw constants over a SET_CONTEXT_REG_INDIRECT list the worker
has not read yet.

The console's PFP reads the list when it reaches the packet; the
difference is recorded in TechnicalDebt.md.
@adriadam10
adriadam10 force-pushed the fix/agc-indirect-register-lists-at-submission branch from 0afd04f to de651c6 Compare October 8, 2026 06:45
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
@adriadam10
adriadam10 merged commit 6b57386 into boykopovar:main Oct 8, 2026
4 checks passed
@gookie-dev
gookie-dev deleted the fix/agc-indirect-register-lists-at-submission branch October 11, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants