fix(agc): skip a periodic pipeline cache save while a pipeline creation holds the cache #6958
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6958"
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?
Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-16T21:15:30Z.
What
PipelineCache's saver thread wakes every 10 s and snapshots the Vulkan pipeline cache withLockForSnapshot(), an exclusive lock on theshared_mutexthat every pipeline creation holds shared (LockPipelineCacheForUse). If a creation is running, the save blocks until it ends, and because the lock prefers a waiting writer, every later creation on every queue blocks behind the save as well.With a compute pipeline that takes minutes in the NVIDIA compiler, this stops all graphics work for the whole compile, though the compile runs on a compute queue. Ghost of Yōtei (PPSA26344) froze its loading at frame 797–799 for 8+ minutes this way on every warm run.
With this change, the periodic save takes the snapshot with
TryLockForSnapshot()at each of its three snapshot points (live size, merge, data). When a creation holds the cache, it returns and tries again at the next interval.SaveNow()and the teardown save still wait for the lock.SaveUnlessBusy()exposes the periodic path for the test.Thread dumps of the freeze (run193, five dumps between 382 and ~800 s, identical)
Symbolized against the build that ran; line numbers from
addr2line:Draw→CachedPipeline→Pipeline::Pipeline(Pipeline.cpp:543) →LinkPipelineFromLibraries→LockPipelineCacheForUse(PipelineLibrary.cpp:214),lock_sharedPipelineCache::run→save(false)LockForSnapshot(PipelineCache.cpp:172),lockPipelineCache::run→save(false)pathMutex(PipelineCache.cpp:168)nvgpucomp64.dllThe driver's periodic stats stopped about when the frame count did (
[gpu] worker ... draw 64.7 sthen silence), while the title's CPU side kept running (2.35 cores, audio streaming).Tests
pipelineCacheFileTests(agc_pipeline_cache_file) gains a case: one thread holdsLockForPipelineUse()like a long creation.SaveUnlessBusy()must return within 5 s, and a secondLockForPipelineUse()must then be granted within 5 s. If the save blocks, the test releases the holder after the timeout and fails, so it doesn't hang.SaveUnlessBusy()routed to the blocking save, the case fails with "a periodic pipeline cache save waited for a pipeline creation to finish".Tested
Windows 11 Pro 26200, RTX 4090, driver 617.42.
main4986aca62. 1336 of 1340 pass.guest_shader_linkandagc_shader_helperstimed out under--parallel 8, andagc_driver_pixel_ldsfailed once; all three pass when run alone, as doagc_pipeline_cacheandagc_pipeline_cache_file.select_testsfails on this machine because Windows refuses its test's symlink without the symlink privilege (WinError 1314).misaligned_writer_aheadis not built: main'sGpuIndirectArgumentsMisalignedWriterAhead.cppneeds 65536-byte alignment, which MinGW's object format does not allow.APS5_LAZY_SHADER_PREPARE=1, 900 s per run. The tree ismain82ddae75bplus #6227 (needed to get past start-up), #6867, #6537 and three local diagnostics. ItsPipelineCache.cpp,PipelineCache.hpp,PipelineLibrary.cppandPipelineCacheSynchronizationare identical to this branch's base (Context.hppdiffers only by a newstorageImageMultisamplefield), and the change applied there has the same patch-id as this branch's commit.In run194 two periodic saves wrote the file, and a thread dump at 442 s shows no save waiting and the graphics worker idle in its run loop rather than on the lock. The title then stops at frame 813 while a compute queue worker is inside the NVIDIA compiler again; that one is not a lock wait and is still being looked into.
Technical debt
New entry in
docs/dev/debt/libSceAgcDriver.md, "Periodic pipeline cache saves skip busy intervals":Related
PipelineCache.cpp(where the file lives); the two touch different code.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T21:27:30Z.
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.
main)docs/dev/debt/libSceAgcDriver.mdL193docs/dev/debt/libSceAgcDriver.mdL193docs/dev/debt/libSceAgcDriver.mdL193docs/dev/debt/libSceAgcDriver.mdL193Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/PipelineCache.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T21:58:38Z.
Review: COMMENTED
Right fix for the right problem: a blocking exclusive
LockForSnapshoton a writer-preferringshared_mutexstalls every later creation on every queue, andTryLockForSnapshotremoves that without touchingSaveNowor the teardown save. The thread dumps in the description make the cause clear,mergedis destroyed byDestroyMergedon the three early returns, and the debt entry states the cost (no periodic save while creations overlap without a gap).Minor:
readHeader()/readFile()and the merge-cache creation, and nothing is settled, so the next interval repeats all of it. During a long compile that is a read of the whole cache file every 10 s for no result. Check for a creation in flight before reading the file, or settleliveBytesso the next interval returns early.owns_lock()returns.Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T10:16:28Z.
AMD / Windows run of this PR at eb477738b: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.
Every ctest entry built from the test targets this PR changes passes (42):
agc_pipeline_cache,agc_pipeline_cache_file,agc_pipeline_library,agc_pipeline_library_off,agc_pipeline_library_fast_only,agc_import_watch,agc_import_watch_other_family,agc_unchanged_cpu_stamps,agc_storage_kept_unit_settle,agc_storage_baseline_settled,agc_storage_integer_clear,agc_storage_upload_lifetime,agc_storage_upload_failure,agc_storage_written_buffer_order,agc_storage_split_writeback,agc_copied_direct_ordering,agc_recorder_read_list,agc_space_pending_writes,agc_host_import_unmap,agc_parked_import_unmap,agc_host_import_retirement,agc_sparse_run_import,agc_sparse_run_import_copied,agc_unit_shadow,agc_storage_cpu_snapshot,agc_descriptor_pool_recycling,agc_draw_snapshot_cap,agc_draw_snapshot_epoch,agc_multisample_guest_access,agc_draw_inputs_in_place,agc_pending_write_snapshot,agc_resident_present,agc_queued_write_groups,agc_tiled_resolve,agc_slice_dirty,agc_metadata_pass,agc_host_import_second_mapping,agc_pending_key_stores,agc_shadowed_key_stores,agc_sample_dumps,agc_driver_vertex_target_range_copied,agc_driver_vertex_target_range_importedAI-assisted: yes (runs made on the device above).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T14:49:12Z.
Checked the change against
PipelineCache::save: all three snapshot points (live size, merge, data) useTryLockForSnapshot()on the periodic path and return on a lost try,mergedis released on those early returns, andSaveNow()and the teardown save still wait. The newRecorder.cppcase pins the behaviour (the save must return while a creation holds the cache, and a second creation must then be granted the lock), and the debt entry states the cost (no periodic save while creations overlap without a gap). Thread dumps, the Yōtei runs and the AMD/Windows run by @keravyn-ops cover the freeze and the touched tests.The only conflict with
mainwas the neighbouring line indocs/dev/debt/libSceAgcDriver.md; I rebased and resolved it, nothing else changed; merged.