fix(agc): defer Windows exceptions during shader preparation #8592

Closed
gohansharma79-svg wants to merge 2 commits from upstream-pr/8592 into main
gohansharma79-svg commented 2026-10-20 17:41:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gohansharma79-svg on 2026-10-20T17:41:55Z.


What

Prevent redirected Windows guest exceptions from entering a handler while the target is acquiring or holding a shader preparation transaction. A handler that prepares shaders can otherwise wait on a writer mutex held by the thread it interrupted. Defer delivery through acquisition and the full transaction lifetime, release staged state before ending deferral, and preserve nesting when a native thread is adopted by scePthreadSelf.

Resubmits #7686, which was closed automatically by the open-PR limit before #7680 merged. The original prerequisite #7652 has also merged. This branch contains only the follow-up fix on current main, preserving main's newer running-code classification and deferred image classification outside the suspended-thread interval.

This is a host deadlock correction. No gameplay FPS improvement is claimed. The existing one-second retry limit remains and throws if a target remains in a protected scope; other host locks and POSIX delivery are outside this change, recorded in the AGC debt file.

Overlap scan: #8512 has merged. This branch incorporates its 50 ms host-code deadline while retaining the one-second limit for protected shader scopes. #8539 also changes the delivery condition, without adding shader-transaction deferral; if merged subsequently it must preserve the guard. #8224 edits the adjacent strided-buffer debt note, unrelated to this fix. Older already-conflicted PRs also share files, as reported by the overlap tool; this is not a claim that those PRs merge cleanly together.

Tested

Windows 11 x64, Ryzen 7 5800X, GCC 15.2 / MinGW, Release, ANYPS5_ENABLE_SPIRV_TOOLS=OFF.

  • Historical validation of the original fix from #7686: the baseline owner assertion fails; owner, writer-waiter and native-thread-adoption cases pass with the fix, including ten repeated runs. Ten focused exception, shader publication and draw-cache tests passed. A control retaining #7652 while disabling only the new deferral check fails; restoring the check passes.
  • Resubmission is refreshed through main b85d972f42; candidate head 16dab33e38. Conventions and whitespace checks pass. Fresh runtime validation after resolving the #8512 merge conflict: main b85d972f42 passes 5/5 focused Vulkan tests; candidate 16dab33e38 passes all 10 focused shader-deferral, exception, prepared-publication and draw-cache tests. Both used the same machine and validation-layer settings; no new VUID- diagnostics and no missing-layer messages were found. The earlier resubmission head also passed 10/10 on recheck (16.03 s).
  • Matched GPU tests used the same RTX 4070 SUPER with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and the official Khronos Windows x64 validation artifact from main commit aea761f4d54b86682be4099c428dba27b6609940. Neither log reports a missing requested layer. Both logs have zero VUID- diagnostics; existing unused-fragment-output warnings occur on both.
  • One initial candidate agc_driver_draw_cache_reuse launch exited before application logging with Windows status 0xc0e90002; the other four GPU tests passed. A subsequent complete ten-test run passed, including that test. The first failure is retained in the validation record and its cause is not established. Draft status is retained pending investigation of that startup failure.
  • No Linux runtime validation or isolated gameplay FPS comparison has been performed.

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 (#7652 is merged)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 616.64, Windows 11 x64 (original and rebased-head focused validation)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4939896472 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8592). Originally posted by [gohansharma79-svg](https://github.com/gohansharma79-svg) on 2026-10-20T17:41:55Z. --- ### What Prevent redirected Windows guest exceptions from entering a handler while the target is acquiring or holding a shader preparation transaction. A handler that prepares shaders can otherwise wait on a writer mutex held by the thread it interrupted. Defer delivery through acquisition and the full transaction lifetime, release staged state before ending deferral, and preserve nesting when a native thread is adopted by `scePthreadSelf`. Resubmits #7686, which was closed automatically by the open-PR limit before #7680 merged. The original prerequisite #7652 has also merged. This branch contains only the follow-up fix on current main, preserving main's newer running-code classification and deferred image classification outside the suspended-thread interval. This is a host deadlock correction. No gameplay FPS improvement is claimed. The existing one-second retry limit remains and throws if a target remains in a protected scope; other host locks and POSIX delivery are outside this change, recorded in the AGC debt file. Overlap scan: #8512 has merged. This branch incorporates its 50 ms host-code deadline while retaining the one-second limit for protected shader scopes. #8539 also changes the delivery condition, without adding shader-transaction deferral; if merged subsequently it must preserve the guard. #8224 edits the adjacent strided-buffer debt note, unrelated to this fix. Older already-conflicted PRs also share files, as reported by the overlap tool; this is not a claim that those PRs merge cleanly together. ### Tested Windows 11 x64, Ryzen 7 5800X, GCC 15.2 / MinGW, Release, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. - Historical validation of the original fix from #7686: the baseline owner assertion fails; owner, writer-waiter and native-thread-adoption cases pass with the fix, including ten repeated runs. Ten focused exception, shader publication and draw-cache tests passed. A control retaining #7652 while disabling only the new deferral check fails; restoring the check passes. - Resubmission is refreshed through main `b85d972f42`; candidate head `16dab33e38`. Conventions and whitespace checks pass. Fresh runtime validation after resolving the #8512 merge conflict: main `b85d972f42` passes 5/5 focused Vulkan tests; candidate `16dab33e38` passes all 10 focused shader-deferral, exception, prepared-publication and draw-cache tests. Both used the same machine and validation-layer settings; no new `VUID-` diagnostics and no missing-layer messages were found. The earlier resubmission head also passed 10/10 on recheck (16.03 s). - Matched GPU tests used the same RTX 4070 SUPER with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and the official Khronos Windows x64 validation artifact from main commit `aea761f4d54b86682be4099c428dba27b6609940`. Neither log reports a missing requested layer. Both logs have zero `VUID-` diagnostics; existing unused-fragment-output warnings occur on both. - One initial candidate `agc_driver_draw_cache_reuse` launch exited before application logging with Windows status `0xc0e90002`; the other four GPU tests passed. A subsequent complete ten-test run passed, including that test. The first failure is retained in the validation record and its cause is not established. Draft status is retained pending investigation of that startup failure. - No Linux runtime validation or isolated gameplay FPS comparison has been performed. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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 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 (#7652 is merged) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 616.64, Windows 11 x64 (original and rebased-head focused validation) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-23 02:34:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:34:30Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed changes have no verified blocking defects; the author reports passing focused tests, but a startup failure remains unexplained and I could not run the checks independently.

What I ran

Reviewed head 16dab33e389a5d398d0184421ab67788085da4c9 using the prepared diff and repo_read.py. No tests or build commands were run.

Results

Check Result Note
Source review passed All 10 changed files read
Focused runtime tests not run Passing results are author-reported
Startup failure investigation not run Cause remains unknown

Findings

Blocking

None.

Non-blocking

  • The description reports one candidate GPU test startup exit (0xc0e90002) before application logging, with cause undetermined. The later full run reportedly passed, but investigating the initial failure would strengthen confidence in the validation record. See core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp:318 for the changed deferral lifecycle.

Not verified

I did not independently run builds or tests, verify the reported Windows environment, or test Linux runtime behavior or console behavior. The full text of all 10 changed files was included and read: core/libs/prx/libSceAgcDriver/CMakeLists.txt, core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp, core/libs/prx/libSceAgcDriver/tests/ShaderSignalDeferral.cpp, core/libs/prx/libkernel/Pthread/include/Pthread.hpp, core/libs/prx/libkernel/Pthread/src/Thread.cpp, core/libs/prx/libkernel/System/src/Exception.cpp, core/libs/prx/libkernel/Time/TimedWait.cpp, core/libs/prx/libkernel/Time/include/HostSignalDeferral.hpp, core/libs/prx/libkernel/Time/include/TimedWait.hpp, and docs/dev/debt/libSceAgcDriver.md.

To get this to a good state

Nothing is required. Optionally investigate and document the cause of the reported startup failure.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015951323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8592#pullrequestreview-6015951323). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:34:30Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed changes have no verified blocking defects; the author reports passing focused tests, but a startup failure remains unexplained and I could not run the checks independently. ## What I ran Reviewed head `16dab33e389a5d398d0184421ab67788085da4c9` using the prepared diff and `repo_read.py`. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | All 10 changed files read | | Focused runtime tests | not run | Passing results are author-reported | | Startup failure investigation | not run | Cause remains unknown | ## Findings ### Blocking None. ### Non-blocking - The description reports one candidate GPU test startup exit (`0xc0e90002`) before application logging, with cause undetermined. The later full run reportedly passed, but investigating the initial failure would strengthen confidence in the validation record. See `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp:318` for the changed deferral lifecycle. ## Not verified I did not independently run builds or tests, verify the reported Windows environment, or test Linux runtime behavior or console behavior. The full text of all 10 changed files was included and read: `core/libs/prx/libSceAgcDriver/CMakeLists.txt`, `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp`, `core/libs/prx/libSceAgcDriver/tests/ShaderSignalDeferral.cpp`, `core/libs/prx/libkernel/Pthread/include/Pthread.hpp`, `core/libs/prx/libkernel/Pthread/src/Thread.cpp`, `core/libs/prx/libkernel/System/src/Exception.cpp`, `core/libs/prx/libkernel/Time/TimedWait.cpp`, `core/libs/prx/libkernel/Time/include/HostSignalDeferral.hpp`, `core/libs/prx/libkernel/Time/include/TimedWait.hpp`, and `docs/dev/debt/libSceAgcDriver.md`. ## To get this to a good state Nothing is required. Optionally investigate and document the cause of the reported startup failure.

Pull request closed

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!8592
No description provided.