Skip to content

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

Merged
boykopovar merged 1 commit into
boykopovar:mainfrom
oneandonlydean:fix/device-replacement-race
Sep 29, 2026
Merged

boykopovar merged 1 commit into
boykopovar:mainfrom
oneandonlydean:fix/device-replacement-race

Conversation

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

…s replacing

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ButHENCbXXt8h4EZuWUabJ
@github-actions github-actions Bot added the agc libSceAgc* label Sep 29, 2026
@boykopovar
boykopovar merged commit 9edb1f9 into boykopovar:main Sep 29, 2026
3 checks passed
@oneandonlydean
oneandonlydean deleted the fix/device-replacement-race branch October 1, 2026 21:26
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.

2 participants