fix(agc): don't let a queue worker record on a device the presenter is replacing #110

Merged
oneandonlydean merged 1 commit from upstream-pr/110 into main 2026-09-29 10:06:31 +00:00
oneandonlydean commented 2026-09-28 23:56:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-28T23:56:17Z.


What

The presenter replaces the driver's device when the window first appears (the headless device has no surface). Queue workers don't hold GpuMutex for all of a packet: a dispatch's prologue loads the device atomically and records later. A worker could therefore capture the old device, lose the race with the presenter, and record onto a device that PrepareForReplacement was already tearing down. On Linux with NVIDIA, the next submission hung the GPU.

DeviceUseGate is a small writer-preferring gate:

  • a worker holds it shared for each packet it executes;
  • the presenter takes it exclusively only while it replaces the device (no device yet, or one without a window);
  • ordinary presents don't touch it.

Packets that wait on something the presenter may produce don't take the gate, so a waiting worker can't block the replacement it's waiting for. Those are WAIT_REG_MEM (0x3c), WAIT_REG_MEM64 (0x93), the rendering-wait packet and the flip.

Tested

  • Linux (CachyOS, RTX 4090, NVIDIA 615): Astro Bot (PPSA21564) boots through the window's device replacement while compute queues are running. Without the gate it hangs there intermittently.
  • ctest: 57/57 pass.

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4670715294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/110). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-28T23:56:17Z. --- ### What The presenter replaces the driver's device when the window first appears (the headless device has no surface). Queue workers don't hold `GpuMutex` for all of a packet: a dispatch's prologue loads the device atomically and records later. A worker could therefore capture the old device, lose the race with the presenter, and record onto a device that `PrepareForReplacement` was already tearing down. On Linux with NVIDIA, the next submission hung the GPU. `DeviceUseGate` is a small writer-preferring gate: - a worker holds it shared for each packet it executes; - the presenter takes it exclusively only while it replaces the device (no device yet, or one without a window); - ordinary presents don't touch it. Packets that wait on something the presenter may produce don't take the gate, so a waiting worker can't block the replacement it's waiting for. Those are WAIT_REG_MEM (0x3c), WAIT_REG_MEM64 (0x93), the rendering-wait packet and the flip. ### Tested - Linux (CachyOS, RTX 4090, NVIDIA 615): Astro Bot (PPSA21564) boots through the window's device replacement while compute queues are running. Without the gate it hangs there intermittently. - `ctest`: 57/57 pass. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!110
No description provided.