fix(agc): print a GPU queue worker failure when it is first stored #5177

Merged
13hourstilliland merged 2 commits from upstream-pr/5177 into main 2026-10-14 20:53:17 +00:00
13hourstilliland commented 2026-10-13 13:57:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-13T13:57:41Z.


What

Driver::ReportFailure stores a queue worker's exception without printing it. The failure only surfaces when a guest thread next enters the driver (CheckFailure on Submit, WaitIdle and the like). A guest whose own driver waits on a fence word in guest memory never enters the driver again, so it sees a GPU that stopped and never the reason.

The first stored failure is now printed once, as [gpu] driver failure: <what()>, while ReportFailure still holds the driver mutex, so a WaitIdle that wakes on the stored failure returns only after the line is out. Control flow is unchanged: it is still rethrown on the next driver call and at shutdown.

This does not fix the vkQuake (PPSA99010) radv/ps5: the GPU has not reached submission ... stall. @orishamir measured on Windows that it is the host pipeline compile time (#4977), with no stored failure, on main and on this PR alike.

Tested

Linux (Debian, GCC 14), lavapipe (Mesa 25.0.7), on main 4c1de0c0c:

  • agc_driver_worker_failure_log: a flip that fails on the worker is printed exactly once and is still rethrown by the next driver call. With the PrintFailure call removed it fails with the worker failure was not printed; restored, it passes. 20 of 20 repeated runs pass.
  • agc_driver_flip, agc_driver_present_mode, agc_driver_flip_compute pass (4/4 with the new test).
  • tools/check_conventions.py --base origin/main passes.

The capture is opened with "wb", so Windows no longer writes \r\n into it, and the print now happens before WaitIdle can return. Both failures @orishamir found were Windows-only and don't reproduce on Linux, so the 20 of 20 above doesn't show the race is gone. His local run with the same two changes passed 20 of 20 on Windows.

No title run: this box has no 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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4844355706 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5177). Originally posted by [13hourstilliland](https://github.com/13hourstilliland) on 2026-10-13T13:57:41Z. --- ### What `Driver::ReportFailure` stores a queue worker's exception without printing it. The failure only surfaces when a guest thread next enters the driver (`CheckFailure` on Submit, WaitIdle and the like). A guest whose own driver waits on a fence word in guest memory never enters the driver again, so it sees a GPU that stopped and never the reason. The first stored failure is now printed once, as `[gpu] driver failure: <what()>`, while `ReportFailure` still holds the driver mutex, so a `WaitIdle` that wakes on the stored failure returns only after the line is out. Control flow is unchanged: it is still rethrown on the next driver call and at shutdown. This does not fix the vkQuake (PPSA99010) `radv/ps5: the GPU has not reached submission ...` stall. @orishamir measured on Windows that it is the host pipeline compile time (#4977), with no stored failure, on `main` and on this PR alike. ### Tested Linux (Debian, GCC 14), lavapipe (Mesa 25.0.7), on `main` 4c1de0c0c: - `agc_driver_worker_failure_log`: a flip that fails on the worker is printed exactly once and is still rethrown by the next driver call. With the `PrintFailure` call removed it fails with `the worker failure was not printed`; restored, it passes. 20 of 20 repeated runs pass. - `agc_driver_flip`, `agc_driver_present_mode`, `agc_driver_flip_compute` pass (4/4 with the new test). - `tools/check_conventions.py --base origin/main` passes. The capture is opened with `"wb"`, so Windows no longer writes `\r\n` into it, and the print now happens before `WaitIdle` can return. Both failures @orishamir found were Windows-only and don't reproduce on Linux, so the 20 of 20 above doesn't show the race is gone. His local run with the same two changes passed 20 of 20 on Windows. No title run: this box has no GPU. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Unblocks: none - [x] AI-assisted: yes
orishamir commented 2026-10-14 17:27:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-14T17:27:09Z.


Windows run, since the description says Windows wasn't tested. Windows 11, RTX 4080, WinLibs GCC 15.2.0 r7, Release, this head (ac03f3ed1) merged onto main e34c47921. Every other test in the full ctest passes (1198 of 1199).

agc_driver_worker_failure_log fails on Windows in 20 of 20 runs with the worker failure was not printed. I found two causes and checked each with local edits (not pushed anywhere):

  1. freopen(..., "w", stderr) (Flip.cpp:347) opens the capture file in text mode. With the file kept instead of removed, it holds [gpu] driver failure: intentional flip failure\r\n: the line is printed once, but the check at Flip.cpp:372 looks for ...failure\n.
  2. With that check made newline-insensitive, the test passes only 5 of 10 runs (3 of 10 in a second set). In the failing runs the line shows up in the test's own output with its first bytes missing (gpu] driver failure: intentional flip failure). ReportFailure prints at Lifecycle.cpp:198, after it releases mutex, so WaitIdle (its predicate is failure != nullptr, line 166) can return and the test can restore stderr before the print lands. With the print also moved inside the locked block, the test passes 20 of 20. With main's Lifecycle.cpp and the newline-insensitive check, it fails 3 of 3, so the check still pins the change.

vkQuake (PPSA99010), with LibreQuake data in app0/id1, 90 s per run:

  • On main it stalls in 3 of 3 runs: radv/ps5: the GPU has not reached submission 19 (at 18) in 10 s, then QUAKE ERROR: vkWaitForFences failed with code -4 and exit status 1. The same happens in 3 of 3 runs with this PR, and no [gpu] driver failure line appears in the title's app0/trace.txt. That file also receives this library's own [dispatch] creating a pipeline ... lines, so a print there would have shown up.
  • A gdb snapshot 30 s in, during the stall: the queue worker 0x0 thread is in AgcDriver::VulkanDevice::dispatch -> nvoglv64 -> nvgpucomp64, so it is still compiling. With APS5_PROFILE_DRAW=1, the last pipelines started before the stall are 420,923, 208,392, 208,366, 105,396 and 349,278 SPIR-V words. On this machine the stall is the pipeline compile time from #4977, not a stored failure, so this PR doesn't print anything for it.
  • The 349,278-word program is 0x20bf92000, the one that threw the #981 s_round_mode 8 at pc 316 error on main 968d32686 earlier today. With this PR on e34c47921 it gets a pipeline (the PR doesn't touch the recompiler), and none of these 8 runs (3 on main, 5 with this PR) aborted on #981.

AI-assisted: yes (Claude Code Opus 5.5)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174268437 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5177#issuecomment-6174268437). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-14T17:27:09Z. --- Windows run, since the description says Windows wasn't tested. Windows 11, RTX 4080, WinLibs GCC 15.2.0 r7, Release, this head (ac03f3ed1) merged onto `main` e34c47921. Every other test in the full `ctest` passes (1198 of 1199). **`agc_driver_worker_failure_log` fails on Windows in 20 of 20 runs** with `the worker failure was not printed`. I found two causes and checked each with local edits (not pushed anywhere): 1. `freopen(..., "w", stderr)` (`Flip.cpp:347`) opens the capture file in text mode. With the file kept instead of removed, it holds `[gpu] driver failure: intentional flip failure\r\n`: the line is printed once, but the check at `Flip.cpp:372` looks for `...failure\n`. 2. With that check made newline-insensitive, the test passes only 5 of 10 runs (3 of 10 in a second set). In the failing runs the line shows up in the test's own output with its first bytes missing (`gpu] driver failure: intentional flip failure`). `ReportFailure` prints at `Lifecycle.cpp:198`, after it releases `mutex`, so `WaitIdle` (its predicate is `failure != nullptr`, line 166) can return and the test can restore stderr before the print lands. With the print also moved inside the locked block, the test passes 20 of 20. With `main`'s `Lifecycle.cpp` and the newline-insensitive check, it fails 3 of 3, so the check still pins the change. **vkQuake (PPSA99010)**, with LibreQuake data in `app0/id1`, 90 s per run: - On `main` it stalls in 3 of 3 runs: `radv/ps5: the GPU has not reached submission 19 (at 18) in 10 s`, then `QUAKE ERROR: vkWaitForFences failed with code -4` and exit status 1. The same happens in 3 of 3 runs with this PR, and no `[gpu] driver failure` line appears in the title's `app0/trace.txt`. That file also receives this library's own `[dispatch] creating a pipeline ...` lines, so a print there would have shown up. - A gdb snapshot 30 s in, during the stall: the `queue worker 0x0` thread is in `AgcDriver::VulkanDevice::dispatch` -> `nvoglv64` -> `nvgpucomp64`, so it is still compiling. With `APS5_PROFILE_DRAW=1`, the last pipelines started before the stall are 420,923, 208,392, 208,366, 105,396 and 349,278 SPIR-V words. On this machine the stall is the pipeline compile time from #4977, not a stored failure, so this PR doesn't print anything for it. - The 349,278-word program is 0x20bf92000, the one that threw the #981 `s_round_mode 8 at pc 316` error on `main` 968d32686 earlier today. With this PR on e34c47921 it gets a pipeline (the PR doesn't touch the recompiler), and none of these 8 runs (3 on `main`, 5 with this PR) aborted on #981. AI-assisted: yes (Claude Code Opus 5.5)
adriadam10 commented 2026-10-14 17:59:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:59:36Z.

Review: CHANGES_REQUESTED


Thanks for the fix and for the negative check. Two problems make the new test fail on Windows (confirmed by @orishamir above: 20 of 20 runs, the worker failure was not printed):

  • tests/Flip.cpp:347: freopen(..., "w", stderr) opens the file in text mode, so on Windows the capture holds ...failure\r\n and the search at Flip.cpp:372 for ...failure\n never matches. Open it in binary mode ("wb") or make the check newline-insensitive.
  • Execution/src/Driver/Lifecycle.cpp:199: PrintFailure runs after mutex is released, while WaitIdle already returns once failure != nullptr (line 166). The test can restore stderr before the print lands (first bytes missing in the capture; 5 of 10 runs passed even with the newline fixed). Printing inside the locked block made it 20 of 20 in @orishamir's run. Please do that, or make the test wait for the print another way.

Also, the description says the vkQuake stall hides the #981 throw. @orishamir measured on Windows that the stall is the pipeline compile time (#4977): the same radv/ps5: the GPU has not reached submission ... appears 3 of 3 on main and 3 of 3 with this PR, with no stored failure. Please reword "What" so it doesn't present this as the fix for that symptom; the print is still useful for failures that do get stored.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5522329933 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5177#pullrequestreview-5522329933). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T17:59:36Z. **Review:** CHANGES_REQUESTED --- Thanks for the fix and for the negative check. Two problems make the new test fail on Windows (confirmed by @orishamir above: 20 of 20 runs, `the worker failure was not printed`): - `tests/Flip.cpp:347`: `freopen(..., "w", stderr)` opens the file in text mode, so on Windows the capture holds `...failure\r\n` and the search at `Flip.cpp:372` for `...failure\n` never matches. Open it in binary mode (`"wb"`) or make the check newline-insensitive. - `Execution/src/Driver/Lifecycle.cpp:199`: `PrintFailure` runs after `mutex` is released, while `WaitIdle` already returns once `failure != nullptr` (line 166). The test can restore stderr before the print lands (first bytes missing in the capture; 5 of 10 runs passed even with the newline fixed). Printing inside the locked block made it 20 of 20 in @orishamir's run. Please do that, or make the test wait for the print another way. Also, the description says the vkQuake stall hides the #981 throw. @orishamir measured on Windows that the stall is the pipeline compile time (#4977): the same `radv/ps5: the GPU has not reached submission ...` appears 3 of 3 on `main` and 3 of 3 with this PR, with no stored failure. Please reword "What" so it doesn't present this as the fix for that symptom; the print is still useful for failures that do get stored.
13hourstilliland commented 2026-10-14 19:43:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-14T19:43:01Z.


@adriadam10 @orishamir thanks for the Windows runs and for pinning down both causes.

Pushed 6e3152f0e, rebased on 4c1de0c0c:

  • tests/Flip.cpp: stderr is captured with freopen(..., "wb", ...), so the line ends in \n on Windows too.
  • Lifecycle.cpp: PrintFailure runs inside the locked block in ReportFailure, so a WaitIdle that wakes on failure != nullptr returns only after the line is out.
  • "What" no longer ties this to the vkQuake stall. It says the stall is the pipeline compile time from #4977, per orishamir's measurement.

Linux, lavapipe: 4/4 flip tests pass, and the new test passes 20 of 20 repeated runs. It still fails with the worker failure was not printed with the print removed. I can't reproduce either Windows failure here, so orishamir's 20 of 20 on Windows with the same two changes is the evidence for those.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176843424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5177#issuecomment-6176843424). Originally posted by [13hourstilliland](https://github.com/13hourstilliland) on 2026-10-14T19:43:01Z. --- @adriadam10 @orishamir thanks for the Windows runs and for pinning down both causes. Pushed 6e3152f0e, rebased on 4c1de0c0c: - `tests/Flip.cpp`: stderr is captured with `freopen(..., "wb", ...)`, so the line ends in `\n` on Windows too. - `Lifecycle.cpp`: `PrintFailure` runs inside the locked block in `ReportFailure`, so a `WaitIdle` that wakes on `failure != nullptr` returns only after the line is out. - "What" no longer ties this to the vkQuake stall. It says the stall is the pipeline compile time from #4977, per orishamir's measurement. Linux, lavapipe: 4/4 flip tests pass, and the new test passes 20 of 20 repeated runs. It still fails with `the worker failure was not printed` with the print removed. I can't reproduce either Windows failure here, so orishamir's 20 of 20 on Windows with the same two changes is the evidence for those. AI-assisted: yes
adriadam10 commented 2026-10-14 19:50:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T19:50:42Z.

Review: APPROVED


Checked the interdiff against the earlier points: the capture is opened with "wb" (Flip.cpp:347), PrintFailure now runs inside the locked block (Lifecycle.cpp:198), and "What" no longer presents this as the vkQuake stall fix. agc_driver_worker_failure_log and the flip tests pass here, and the test fails with the PrintFailure call removed. Merging once the Windows build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5523764348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5177#pullrequestreview-5523764348). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T19:50:42Z. **Review:** APPROVED --- Checked the interdiff against the earlier points: the capture is opened with `"wb"` (`Flip.cpp:347`), `PrintFailure` now runs inside the locked block (`Lifecycle.cpp:198`), and "What" no longer presents this as the vkQuake stall fix. `agc_driver_worker_failure_log` and the flip tests pass here, and the test fails with the `PrintFailure` call removed. Merging once the Windows build is green.
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!5177
No description provided.