fix: save pipeline cache on emulator crash #1312
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1312
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1312"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@gavvahar on GitHub · 2026-10-09 15:37 UTC · original
gavvahar:main→main· +63 −5 · 4 files · 5 commits · openProblem
Emulator crashes during gameplay (especially heavy loads like cinematics in Astro's Playroom) cause complete loss of the Vulkan pipeline cache. On next launch all shaders must recompile, perpetuating the stutter.
Root cause:
PipelineCache::Save()was only called on graceful shutdown (destructor + the explicitWindowRunpath). Crashes go throughDbgExit()->std::_Exit(), which skips all C++ destructors, so the cache never reaches disk.Solution
Add an
EmergencyShutdown()callback to the Graphics subsystem Lifecycle, mirroring the existing pattern used byLibs::ControllerandLibs::LibKernel::FileSystem. It dumps the in-memory Vulkan pipeline cache to disk during emergency teardown, usingTryLock()so a crash on a thread already holding the render mutex skips the save rather than hanging the crash handler.Graphics is registered last in
emulator.cpp, so its emergency callback runs first in the reverse-order teardown, while the FileSystem subsystem is still alive to service the write.Changes
src/libs/agc.cpp: addEmergencyShutdown()src/libs/agc.h: declare it and wire it intoLifecycle::emergency_shutdownVerification
Full build of the
launchertarget passes: 1084 objects, 0 errors, 191 warnings (all pre-existing, e.g. deprecatedwstring_convertinstringUtils.h).Scope
This makes the existing cache survive crashes. Predictive/async shader pre-compilation (the broader ask in #1300) is a much larger renderer change and is not attempted here. First-playthrough stutter on genuinely new pipelines remains.
Refs #1300
The pipeline cache (VkPipelineCache serialized to _PipelineCache/{title_id}.bin) survives crashes only if the graphics subsystem has an emergency_shutdown callback to flush it to disk before process exit. Currently, the graphics lifecycle registers only a shutdown callback (runs on clean exit) but no emergency_shutdown (runs on assertion/EXIT() crashes). This causes crash scenarios to lose all compiled pipelines: if a game crashes during initial load (reported in issue #1300), the cache is never persisted, and the next launch has no warm cache, forcing full recompilation and perpetuating the stutter the user experienced before the crash. Add EmergencyShutdown() to Libs::Graphics following the exact pattern of Libs::Controller and Libs::LibKernel::FileSystem. The function: - Checks g_renderer != nullptr - Uses TryLock to avoid deadlock if called from a thread already holding the render context mutex (safe no-op if lock fails) - Calls Save() to persist the pipeline cache to disk Fixes #1300@coderabbitai[bot] on GitHub · 2026-10-09 15:40 UTC · original · edited 2026-10-10 02:51 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
45e07a51-3d20-49df-8372-a16215459b60📥 Commits
Reviewing files that changed from the base of the PR and between
86a1c609c9and769f97289a.📒 Files selected for processing (1)
src/common/threads.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
The graphics library adds
EmergencyShutdown()and exposes it throughLifecycle::emergency_shutdown.Common::Mutextracks lock ownership and exposesIsHeldByCurrentThread(). The shutdown function returns if the renderer is absent or the current thread holds the renderer mutex. Otherwise, it saves the pipeline cache only if it acquires the mutex withTryLock(), then unlocks it.Suggested reviewers:
nmzikPriority: ⬇️ Low
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
769f9No actionable merge-blocking risk remains in the reviewed changes.
Pre-merge checks |
4 |
1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-09 15:40 UTC · original · edited 2026-10-09 17:21 UTC
On
src/libs/agc.cppline 84 (outdated):🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19708
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8133
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29326
Do not use
TryLock()as the emergency ownership check.On Windows,
Mutex::TryLock()uses recursiveTryEnterCriticalSection. If the fatal path runs on the thread that owns the renderer mutex, it can enterPipelineCache::Save()instead of skipping the save.Save()performs Vulkan cache retrieval and synchronous filesystem operations, includingFlushFileBuffersand file renaming. These operations can delay emergency termination.Use a separate non-recursive, ownership-independent guard for the emergency save. Do not rely on recursively acquiring the renderer mutex to detect whether the save is safe.
✅ Addressed in commit
4df15ef@coderabbitai[bot] on GitHub · 2026-10-09 15:40 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
7d6f80ee-e414-439b-bb04-b587810128ba📥 Commits
Reviewing files that changed from the base of the PR and between
4c8fc53a85and3264936f0f.📒 Files selected for processing (2)
src/libs/agc.cppsrc/libs/agc.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -59,2 +59,4 @@bool TryLock();// Returns true if the current thread holds this mutex.bool IsHeldByCurrentThread() const;@coderabbitai[bot] on GitHub · 2026-10-09 20:26 UTC · original
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4709
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5050
Maintain ownership tracking across condition-variable waits.
CondVar::Wait()andCondVar::WaitFor()release and reacquire the underlying mutex without callingMutex::Releasing()orMutex::Acquired().m_ownercan therefore remain stale or identify another thread after reacquisition.EmergencyShutdown()usesIsHeldByCurrentThread()beforeTryLock(). A stalefalseresult can let the recursiveTryLock()succeed while the current thread already holds the mutex, causingSave()to run on partially updated state. A staletrueresult can also skip a save when the mutex is not held.Update ownership tracking around every direct release and reacquisition, including the polling callback.
@coderabbitai[bot] on GitHub · 2026-10-09 20:27 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
3c284ef5-3dae-44e3-bae0-8d6c773720e9📥 Commits
Reviewing files that changed from the base of the PR and between
4df15ef266and86a1c609c9.📒 Files selected for processing (2)
src/common/threads.hsrc/libs/agc.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.