fix(agc): keep shader preparation temporaries off guest stacks #2456

Closed
Mouhand-Kaddo wants to merge 1 commit from upstream-pr/2456 into main
Mouhand-Kaddo commented 2026-10-09 21:50:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-09T21:50:43Z.


Summary

What

Shader registration and ABI preparation run on caller-owned guest fibers. QueueState embeds 48 KiB of constant RAM; local instances and copies made RegisterShader reserve about 99 KiB and PrepareRegistered about 51 KiB, even on paths that never used those locals. A 64 KiB guest fiber could therefore overwrite its neighbor.

Keep the five shader-preparation temporaries on the heap, retaining their initialization and copy behavior:

- QueueState state{}; / auto stageState = state;
+ auto storage = std::make_unique<QueueState>(...);
+ auto& state = *storage;

This changes storage duration/location only. No shader semantics, guest fiber sizes, title checks, or fallback behavior change.

Evidence

Tested

  • Before: agc_shader_preparation_stack fails on Windows and Arch with preparation wrote below its fiber context. The valid-registration case separately reproduces the remaining PrepareRegistered overflow after moving only the other four locals.
    After: both tests pass on both platforms. They use 32 KiB fiber contexts with a sentinel region below them, exercise existing input validation and successful synthetic compute registration/ABI preparation, and check that the sentinel survives. Each completes well under one second locally; the valid-registration test skips without Vulkan.
  • Built the full project and patched libs on main 19a0daa7 plus this commit. Windows 11, WinLibs GCC 15.2, RX 6900 XT: 527 tests, 523 passed, 1 skipped, 3 failed (36.82 s). Arch WSL2, GCC 16.2, lavapipe: 532 tests, 504 passed, 27 skipped, 1 timeout (41.82 s). Windows failures are agc_driver_pixel_interlock, agc_driver_sdwa_float_selectors, and agc_driver_sdwa_ldexp_f16; Arch times out in agc_driver_flat_store. All four were also reproduced after rebuilding the affected targets on unchanged main da122c90.
  • Conventions and test-registration checks pass.
  • A local guest startup probe confirmed the overflowing registration frame inside a 64 KiB fiber. The updated driver continues beyond that point; additional startup issues remain outside this PR. The probe uses a separate integration runtime with other startup changes, none of which are included here.

Overlap check reports a textual conflict with #1902, which moves null-pixel registration to another helper. It does not fix stack storage; if it lands first, retain this heap allocation in its new helper. No dependency on its behavior.

Merge Danger

Door: two-way

Blast Radius: preparation

Shader-preparation calls incur heap allocation and can propagate allocation failure. Existing registration publication, validation and transaction behavior remain intact.

Checklist

  • Based on main 19a0daa7; open PRs checked for the same stack fix (textual overlap with #1902 described above)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths retain their exceptions; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4806244807 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2456). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-09T21:50:43Z. --- ## Summary ### What Shader registration and ABI preparation run on caller-owned guest fibers. `QueueState` embeds 48 KiB of constant RAM; local instances and copies made `RegisterShader` reserve about 99 KiB and `PrepareRegistered` about 51 KiB, even on paths that never used those locals. A 64 KiB guest fiber could therefore overwrite its neighbor. Keep the five shader-preparation temporaries on the heap, retaining their initialization and copy behavior: ```diff - QueueState state{}; / auto stageState = state; + auto storage = std::make_unique<QueueState>(...); + auto& state = *storage; ``` This changes storage duration/location only. No shader semantics, guest fiber sizes, title checks, or fallback behavior change. ## Evidence ### Tested - **Before:** `agc_shader_preparation_stack` fails on Windows and Arch with `preparation wrote below its fiber context`. The valid-registration case separately reproduces the remaining `PrepareRegistered` overflow after moving only the other four locals. **After:** both tests pass on both platforms. They use 32 KiB fiber contexts with a sentinel region below them, exercise existing input validation and successful synthetic compute registration/ABI preparation, and check that the sentinel survives. Each completes well under one second locally; the valid-registration test skips without Vulkan. - Built the full project and patched `libs` on main `19a0daa7` plus this commit. Windows 11, WinLibs GCC 15.2, RX 6900 XT: 527 tests, 523 passed, 1 skipped, 3 failed (36.82 s). Arch WSL2, GCC 16.2, lavapipe: 532 tests, 504 passed, 27 skipped, 1 timeout (41.82 s). Windows failures are `agc_driver_pixel_interlock`, `agc_driver_sdwa_float_selectors`, and `agc_driver_sdwa_ldexp_f16`; Arch times out in `agc_driver_flat_store`. All four were also reproduced after rebuilding the affected targets on unchanged main `da122c90`. - Conventions and test-registration checks pass. - A local guest startup probe confirmed the overflowing registration frame inside a 64 KiB fiber. The updated driver continues beyond that point; additional startup issues remain outside this PR. The probe uses a separate integration runtime with other startup changes, none of which are included here. Overlap check reports a textual conflict with #1902, which moves null-pixel registration to another helper. It does not fix stack storage; if it lands first, retain this heap allocation in its new helper. No dependency on its behavior. ## Merge Danger **Door:** two-way **Blast Radius:** preparation Shader-preparation calls incur heap allocation and can propagate allocation failure. Existing registration publication, validation and transaction behavior remain intact. ### Checklist - [x] Based on main `19a0daa7`; open PRs checked for the same stack fix (textual overlap with #1902 described above) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths retain their exceptions; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-09 22:02:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:02:15Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089991651 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2456#issuecomment-6089991651). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:02:15Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
github-actions[bot] commented 2026-10-09 22:09:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:09:28Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1902 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp L733-749
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090081340 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2456#issuecomment-6090081340). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:09:28Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1902 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` [L733-749](https://github.com/boykopovar/AnyPS5/blob/c2ac5dd93f0b6275634fe57415681f27af95ae7d/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L733-L749) | | |

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