AGC: since #5875, a registration library prebuild racing the window attach segfaults in LinkPipelineFromLibraries (Stray PPSA02100, warm shader cache) #6805

Closed
opened 2026-10-16 12:43:12 +00:00 by teepean · 3 comments
teepean commented 2026-10-16 12:43:12 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-16T12:43:12Z.


What happens

On main 65d56a297 (built with #6784 so that it compiles on Linux), Stray (PPSA02100) segfaults about 10 s after start, when the presenter attaches the window, on every run with a warm shader cache: 5 of 5 runs. The one run with a cold cache (first run after the shader cache version changed) survived. Builds on main 332b0b1b7, before #5875, ran 13 warm runs of the same scene today without this crash. The code involved is unchanged on 82ddae75b, the newest main when filing (the line numbers below refer to it).

Crashing thread (registration prepare pool), from the core dump:

#0 std::_Rb_tree<std::vector<std::byte>, std::pair<const std::vector<std::byte>, VkPipeline_T*>, ...>::find   (libSceAgcDriver.prx)
#1 AgcDriver::Graphics::LinkPipelineFromLibraries(...)
#2 AgcDriver::Graphics::Pipeline::Pipeline(...)
#3 AgcDriver::Graphics::Pipeline::Prebuild(...)
#4 AgcDriver::VulkanDevice::PrebuildGraphicsLibraries(...)
#5 std::_Function_handler<..., PrebuildStageLibrary(...)::{lambda}>
#6 AgcDriver::DriverDetail::(anonymous namespace)::RegistrationPreparePool::Main(void*)
Signal 11 (SEGV), si_code SI_KERNEL

At the same moment the VideoOut present loop is inside the attach:

#8  AgcDriver::VulkanDevice::VulkanDevice(PresentationWindow const*, bool)
#9  AgcDriver::DriverDetail::Driver::AttachWindow(PresentationWindow const&)
#10 VideoOutDriver::presentLoop(...)

The log's last lines are always the window device's constructor (VulkanDevice constructor window=0x..., Presentation window context=... extent=1920x1080).

Cause (from the code; consistent with the runs below)

  • Driver::AttachWindow (Execution/src/Driver/Presentation.cpp:44) calls device->PrepareForReplacement() on the windowless device (line 51) and keeps it in replacedDevices.
  • #5875 added Graphics::ClearCachedPipelines(state->device) to VulkanDevice::PrepareForReplacement (Execution/src/VulkanDevice.cpp:2021, the call at 2036). Before #5875 the device's cached pipelines were cleared only at teardown. ClearCachedPipelines calls ClearPipelineLibraries (Graphics/src/PipelineLibrary.cpp:312), which destroys the device's library parts and erases its entry from store.devices (line 324).
  • PrepareForReplacement cancels and waits for the journal replay first, but not for registration library prebuilds: PrebuildStageLibrary (Execution/src/Driver/Shaders/ShaderRegistry.cpp:879) queues jobs that hold the old VulkanDevice and build its parts through LinkPipelineFromLibraries.
  • LinkPipelineFromLibraries takes auto& device = store.devices[context.device] (PipelineLibrary.cpp:112) and the device.parts[part] map under store.mutex, then releases the mutex around vkCreateGraphicsPipelines (line 208). When ClearPipelineLibraries erases the entry meanwhile, the job relocks and searches a destroyed map (cache.find, line 219): the crash in frame #0. Its part would also be built on a device whose libraries were just destroyed.
  • With a warm shader cache the prebuild jobs are already running when the window attaches; with a cold one they are still waiting on recompiles, which is why only warm runs crash.

A fix would make PrepareForReplacement wait for (or cancel) the registration prebuild jobs of that device before ClearCachedPipelines, as it does for the journal replay, or have ClearPipelineLibraries wait until no build for the device is in flight.

Runs (same machine, same scene, stock game config)

Libraries Shader cache Runs Crash at window attach
main 332b0b1b7 (before #5875), plus in 9 of them local DrawPipeline-only changes warm 13 0
main 65d56a297 + #6784 cold (new source version) 1 0
main 65d56a297 + #6784 warm 1 1
main 65d56a297 + #6784 + #6782 + #6771 warm 3 3
same, APS5_NO_PIPELINE_JOURNAL=1 warm 1 1
same, APS5_NO_LIBRARY_PREBUILD=1 warm 1 0

So the journal replay itself is not needed for the crash, and turning the library prebuild off avoids it. With the prebuild off, the replay loaded and built all 438 journaled pipelines (366 graphics, 72 compute) in 340 ms on 16 threads.

Every run also carries one local test switch (APS5_NO_IDLE_STORE=1, which turns off the idle store; without it Stray hits an unrelated startup crash). APS5_PROFILE_DRAW=1 was set in the runs on 65d56a297, not in the 13 runs on 332b0b1b7.

Workaround: APS5_NO_LIBRARY_PREBUILD=1.

Tested on

  • Linux (CachyOS, kernel 7.2.9), AMD Ryzen 9 9950X, NVIDIA GeForce RTX 3090, driver 615.78.08
  • Release build, GCC
  • Stray (PPSA02100), DeadCity start from a save, loaded through scripted pad input

Core dumps and logs are available on request.

AI-assisted: yes (analysis and text written with Claude Code; the runs and core dumps are from my machine).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5884355470 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6805). Originally posted by [teepean](https://github.com/teepean) on 2026-10-16T12:43:12Z. --- ### What happens On `main` 65d56a297 (built with #6784 so that it compiles on Linux), Stray (PPSA02100) segfaults about 10 s after start, when the presenter attaches the window, on every run with a warm shader cache: 5 of 5 runs. The one run with a cold cache (first run after the shader cache version changed) survived. Builds on main 332b0b1b7, before #5875, ran 13 warm runs of the same scene today without this crash. The code involved is unchanged on 82ddae75b, the newest `main` when filing (the line numbers below refer to it). Crashing thread (registration prepare pool), from the core dump: ``` #0 std::_Rb_tree<std::vector<std::byte>, std::pair<const std::vector<std::byte>, VkPipeline_T*>, ...>::find (libSceAgcDriver.prx) #1 AgcDriver::Graphics::LinkPipelineFromLibraries(...) #2 AgcDriver::Graphics::Pipeline::Pipeline(...) #3 AgcDriver::Graphics::Pipeline::Prebuild(...) #4 AgcDriver::VulkanDevice::PrebuildGraphicsLibraries(...) #5 std::_Function_handler<..., PrebuildStageLibrary(...)::{lambda}> #6 AgcDriver::DriverDetail::(anonymous namespace)::RegistrationPreparePool::Main(void*) Signal 11 (SEGV), si_code SI_KERNEL ``` At the same moment the VideoOut present loop is inside the attach: ``` #8 AgcDriver::VulkanDevice::VulkanDevice(PresentationWindow const*, bool) #9 AgcDriver::DriverDetail::Driver::AttachWindow(PresentationWindow const&) #10 VideoOutDriver::presentLoop(...) ``` The log's last lines are always the window device's constructor (`VulkanDevice constructor window=0x...`, `Presentation window context=... extent=1920x1080`). ### Cause (from the code; consistent with the runs below) - `Driver::AttachWindow` (Execution/src/Driver/Presentation.cpp:44) calls `device->PrepareForReplacement()` on the windowless device (line 51) and keeps it in `replacedDevices`. - #5875 added `Graphics::ClearCachedPipelines(state->device)` to `VulkanDevice::PrepareForReplacement` (Execution/src/VulkanDevice.cpp:2021, the call at 2036). Before #5875 the device's cached pipelines were cleared only at teardown. `ClearCachedPipelines` calls `ClearPipelineLibraries` (Graphics/src/PipelineLibrary.cpp:312), which destroys the device's library parts and erases its entry from `store.devices` (line 324). - `PrepareForReplacement` cancels and waits for the journal replay first, but not for registration library prebuilds: `PrebuildStageLibrary` (Execution/src/Driver/Shaders/ShaderRegistry.cpp:879) queues jobs that hold the old `VulkanDevice` and build its parts through `LinkPipelineFromLibraries`. - `LinkPipelineFromLibraries` takes `auto& device = store.devices[context.device]` (PipelineLibrary.cpp:112) and the `device.parts[part]` map under `store.mutex`, then releases the mutex around `vkCreateGraphicsPipelines` (line 208). When `ClearPipelineLibraries` erases the entry meanwhile, the job relocks and searches a destroyed map (`cache.find`, line 219): the crash in frame #0. Its part would also be built on a device whose libraries were just destroyed. - With a warm shader cache the prebuild jobs are already running when the window attaches; with a cold one they are still waiting on recompiles, which is why only warm runs crash. A fix would make `PrepareForReplacement` wait for (or cancel) the registration prebuild jobs of that device before `ClearCachedPipelines`, as it does for the journal replay, or have `ClearPipelineLibraries` wait until no build for the device is in flight. ### Runs (same machine, same scene, stock game config) | Libraries | Shader cache | Runs | Crash at window attach | |---|---|---|---| | main 332b0b1b7 (before #5875), plus in 9 of them local DrawPipeline-only changes | warm | 13 | 0 | | main 65d56a297 + #6784 | cold (new source version) | 1 | 0 | | main 65d56a297 + #6784 | warm | 1 | 1 | | main 65d56a297 + #6784 + #6782 + #6771 | warm | 3 | 3 | | same, `APS5_NO_PIPELINE_JOURNAL=1` | warm | 1 | 1 | | same, `APS5_NO_LIBRARY_PREBUILD=1` | warm | 1 | 0 | So the journal replay itself is not needed for the crash, and turning the library prebuild off avoids it. With the prebuild off, the replay loaded and built all 438 journaled pipelines (366 graphics, 72 compute) in 340 ms on 16 threads. Every run also carries one local test switch (`APS5_NO_IDLE_STORE=1`, which turns off the idle store; without it Stray hits an unrelated startup crash). `APS5_PROFILE_DRAW=1` was set in the runs on 65d56a297, not in the 13 runs on 332b0b1b7. Workaround: `APS5_NO_LIBRARY_PREBUILD=1`. ### Tested on - Linux (CachyOS, kernel 7.2.9), AMD Ryzen 9 9950X, NVIDIA GeForce RTX 3090, driver 615.78.08 - Release build, GCC - Stray (PPSA02100), DeadCity start from a save, loaded through scripted pad input Core dumps and logs are available on request. AI-assisted: yes (analysis and text written with Claude Code; the runs and core dumps are from my machine).
MarcZX10 commented 2026-10-17 04:01:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T04:01:33Z.


Yes, please post the 43-line diff. The measurements show a useful attach-time improvement, but I would want to inspect the late-submission window before replacing the global drain: a RegisteredPreparation can still hold the retiring device and submit a prebuild after the device-scoped queue cancellation returns. A focused regression should coordinate an in-flight registration preparation with replacement and prove the old device cannot receive a prebuild after its teardown boundary.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6229386463 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6805#issuecomment-6229386463). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T04:01:33Z. --- Yes, please post the 43-line diff. The measurements show a useful attach-time improvement, but I would want to inspect the late-submission window before replacing the global drain: a `RegisteredPreparation` can still hold the retiring device and submit a prebuild after the device-scoped queue cancellation returns. A focused regression should coordinate an in-flight registration preparation with replacement and prove the old device cannot receive a prebuild after its teardown boundary.
Tamalero commented 2026-10-17 04:30:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-17T04:30:03Z.


A second title with the same crash: High on Life (PPSA15388), Linux, RTX 4090, GCC 16.2.1, Release.

Same top frame (std::_Rb_tree<std::vector<std::byte>, … VkPipeline_T*>::find in libSceAgcDriver.prx), same moment: the last log lines are VulkanDevice constructor window=… and Presentation window context=… extent=1920x1080, then SIGSEGV about 25 s after start.

Build Shader cache Runs Result
main 5d9dcc42d (before #5875) + PlayGo setting warm several on 2026-10-15 no crash
main f26eb67c8 + PlayGo setting (now #6236) warm, written by 5d9dcc42d 1 SIGSEGV, find
same empty 1 starts, plays normally
same warm, written by the run above 1 SIGSEGV, find
main 07e741481 warm, written by 5d9dcc42d 2 SIGSEGV, find

So it matches what you found on Stray: any warm cache, not a cache from an older build, and a cold start survives. Pointing ANYPS5_SHADER_CACHE_DIR at an empty folder is a workaround until the fix lands. I can run the fix on this title as soon as there's a branch.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6229650127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6805#issuecomment-6229650127). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-17T04:30:03Z. --- A second title with the same crash: High on Life (PPSA15388), Linux, RTX 4090, GCC 16.2.1, Release. Same top frame (`std::_Rb_tree<std::vector<std::byte>, … VkPipeline_T*>::find` in `libSceAgcDriver.prx`), same moment: the last log lines are `VulkanDevice constructor window=…` and `Presentation window context=… extent=1920x1080`, then SIGSEGV about 25 s after start. | Build | Shader cache | Runs | Result | |---|---|---|---| | `main` `5d9dcc42d` (before #5875) + PlayGo setting | warm | several on 2026-10-15 | no crash | | `main` `f26eb67c8` + PlayGo setting (now #6236) | warm, written by `5d9dcc42d` | 1 | SIGSEGV, `find` | | same | empty | 1 | starts, plays normally | | same | warm, written by the run above | 1 | SIGSEGV, `find` | | `main` `07e741481` | warm, written by `5d9dcc42d` | 2 | SIGSEGV, `find` | So it matches what you found on Stray: any warm cache, not a cache from an older build, and a cold start survives. Pointing `ANYPS5_SHADER_CACHE_DIR` at an empty folder is a workaround until the fix lands. I can run the fix on this title as soon as there's a branch. *Tested and written by Claude (AI assistant) on a contributor's machine.*
Tamalero commented 2026-10-17 04:38:17 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-17T04:38:17Z.


A third title: Guardians of the Galaxy (PPSA01748), Linux, RTX 4090, GCC 16.2.1, Release.

Same top frame (std::_Rb_tree<std::vector<std::byte>, … VkPipeline_T*>::find in libSceAgcDriver.prx), same moment: right after VulkanDevice constructor window=… and Presentation window context=… extent=1920x1080.

Build Shader cache Runs Result
main f26eb67c8 warm 4 3 × SIGSEGV, find; 1 reached the menu
same empty 1 starts, reaches the menu

So it's timing-dependent, as expected for a race. This title seems to hit it a little less often than High on Life (4 of 4), possibly because fewer of its shaders are prepared at registration.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6229719988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6805#issuecomment-6229719988). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-17T04:38:17Z. --- A third title: Guardians of the Galaxy (PPSA01748), Linux, RTX 4090, GCC 16.2.1, Release. Same top frame (`std::_Rb_tree<std::vector<std::byte>, … VkPipeline_T*>::find` in `libSceAgcDriver.prx`), same moment: right after `VulkanDevice constructor window=…` and `Presentation window context=… extent=1920x1080`. | Build | Shader cache | Runs | Result | |---|---|---|---| | `main` `f26eb67c8` | warm | 4 | 3 × SIGSEGV, `find`; 1 reached the menu | | same | empty | 1 | starts, reaches the menu | So it's timing-dependent, as expected for a race. This title seems to hit it a little less often than High on Life (4 of 4), possibly because fewer of its shaders are prepared at registration. *Tested and written by Claude (AI assistant) on a contributor's machine.*
Sign in to join this conversation.
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#6805
No description provided.