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

Closed
gohansharma79-svg wants to merge 2 commits from upstream-pr/7686 into main
gohansharma79-svg commented 2026-10-18 23:01:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gohansharma79-svg on 2026-10-18T23:01:39Z.


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 otherwise waits on a writer mutex held by the thread it interrupted. Defer delivery through the full transaction lifetime, release staged state before ending deferral, and preserve nesting when a native thread is adopted by scePthreadSelf.

This is a host deadlock correction, not a measured FPS improvement. The existing one-second sender retry limit remains; exceeding it throws. Other host locks and POSIX signal delivery are outside this change, as recorded in the AGC debt file.

Depends on #7652, included as the first commit with its original authorship retained. That change avoids redirecting running host-module code; this follow-up keeps shader transaction scopes protected even after control returns to executable code, or while a writer is blocked. Its delivery-loop condition retains #7652's running-host-code policy. The original baseline regression also fails before that dependency is applied; validation of this combined branch is listed below.

Tested

Windows 11 x64, GCC 15.2 / MinGW, Release, Ryzen 7 5800X. Fresh current-main dependency build with the existing FFmpeg static artifact reused, ANYPS5_ENABLE_SPIRV_TOOLS=OFF.

  • New synthetic regression fails on baseline: the exception handler starts while the writer owns the transaction.
  • With the fix, owner, writer-waiter and native-thread adoption cases pass; ten additional repeated runs pass.
  • Existing guest exception handler, raise-exception and mutex/raise-exception tests all pass.
  • Native Vulkan prepared-publication and draw-cache reuse tests pass, including cache-off, verification and inline variants (six tests including the new regression).
  • No game files are included, no gameplay FPS result is claimed, and Linux has not been tested.
  • tools/check_conventions.py --base origin/main: passed.
  • Combined branch on main fc623324a: all ten focused tests pass (19.23 s), including #7652's host-code regression. Prepared publication and the new signal regression each pass ten repeats. A control that disables only the new lock-deferral check while retaining #7652 fails the owner assertion; restoring the check passes. An earlier test launched during an in-progress library rebuild was excluded and rerun after the build completed.
  • Overlap scan completed. #7652 is an explicit included dependency. The independent debt-note insertion was moved away from the shared end-of-file append area; older conflicted PRs' shader/exception patches were inspected separately. The scope deferral is not their deferred shader compilation, host-fault delivery or stack allocation work.

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: #7652 (included)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 616.64, Windows 11 x64
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4913585870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7686). Originally posted by [gohansharma79-svg](https://github.com/gohansharma79-svg) on 2026-10-18T23:01:39Z. --- ### 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 otherwise waits on a writer mutex held by the thread it interrupted. Defer delivery through the full transaction lifetime, release staged state before ending deferral, and preserve nesting when a native thread is adopted by `scePthreadSelf`. This is a host deadlock correction, not a measured FPS improvement. The existing one-second sender retry limit remains; exceeding it throws. Other host locks and POSIX signal delivery are outside this change, as recorded in the AGC debt file. Depends on #7652, included as the first commit with its original authorship retained. That change avoids redirecting running host-module code; this follow-up keeps shader transaction scopes protected even after control returns to executable code, or while a writer is blocked. Its delivery-loop condition retains #7652's running-host-code policy. The original baseline regression also fails before that dependency is applied; validation of this combined branch is listed below. ### Tested Windows 11 x64, GCC 15.2 / MinGW, Release, Ryzen 7 5800X. Fresh current-main dependency build with the existing FFmpeg static artifact reused, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. - New synthetic regression fails on baseline: the exception handler starts while the writer owns the transaction. - With the fix, owner, writer-waiter and native-thread adoption cases pass; ten additional repeated runs pass. - Existing guest exception handler, raise-exception and mutex/raise-exception tests all pass. - Native Vulkan prepared-publication and draw-cache reuse tests pass, including cache-off, verification and inline variants (six tests including the new regression). - No game files are included, no gameplay FPS result is claimed, and Linux has not been tested. - `tools/check_conventions.py --base origin/main`: passed. - Combined branch on main `fc623324a`: all ten focused tests pass (19.23 s), including #7652's host-code regression. Prepared publication and the new signal regression each pass ten repeats. A control that disables only the new lock-deferral check while retaining #7652 fails the owner assertion; restoring the check passes. An earlier test launched during an in-progress library rebuild was excluded and rerun after the build completed. - Overlap scan completed. #7652 is an explicit included dependency. The independent debt-note insertion was moved away from the shared end-of-file append area; older conflicted PRs' shader/exception patches were inspected separately. The scope deferral is not their deferred shader compilation, host-fault delivery or stack allocation work. <!-- 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: #7652 (included) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 616.64, Windows 11 x64 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-18 23:01:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T23:01:59Z.


Thank you for your contribution! Authors with no pull requests merged into main can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6256257573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7686#issuecomment-6256257573). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T23:01:59Z. --- Thank you for your contribution! Authors with no pull requests merged into `main` can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

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