fix(agc): merge the pipeline cache file instead of overwriting it with one device's cache #4915
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4915"
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 fdfawef324 on 2026-10-13T03:55:58Z.
What
A process holds two
Graphics::PipelineCacheobjects for one cache file.Driver::AttachWindowkeeps the replaced headlessVulkanDeviceinreplacedDevicesand creates the windowed one. Each device builds its ownPipelineCachein its constructor, and both resolve to the samevk-pipelines-<vendor>-<device>-<driver>-<uuid>.bin. On main,PipelineCache::savewrote the whole file from its ownVkPipelineCachealone. It ran from the periodicrun()thread every 10 s and once more from the destructor. It wrote whenever the cache size differed fromsavedBytes, which is the size this object last loaded or wrote. Nothing checked what the other object had stored, so the last writer won.Evidence from Demon's Souls (PPSA01342) runs on this machine, from the
[pipeline-cache]log lines:savedBytesand it never wrote again. The process then crashed, so neither teardown save ran.loaded 31289.8 KiBlines at start, then saves of 31651.1 KiB and 32172.1 KiB.The fix keeps one
VkPipelineCacheper device and changes how a save writes the file:vkMergePipelineCacheswith the temporary cache as destination and this object's cache as source. It then writes the merged data with the existing atomic write.dstCacheto be externally synchronised, and worker threads create pipelines with the live cache at any time. So the live cache is only ever a merge source.cannot readinstead of starting empty silently.Behaviour change: a save that has something to write now also reads the file and has the driver parse it. The
saved ... in N msline includes that time and says(merged with the file)when a merge happened. No speed claim is made.Not covered: two AnyPS5 processes sharing one cache directory. The atomic write keeps the file valid, but one process can still drop pipelines the other wrote between its read and its rename.
Related
#4795 (MarcZX100, open) serializes
PipelineCache::save()'svkGetPipelineCacheDatacalls against pipeline creation with a shared/exclusive lock, as a workaround for the Intel crash in #4781. It conflicts with this PR inGraphics/src/PipelineCache.cpp, but the two are complementary: #4795 decides when the live cache may be read, this PR decides what is written to the file. Merge #4795 first. This PR will then be rebased onto its device-cache guard, preserving exclusive access for the initial live-cache size read and the merge that reads the live cache; reads of the temporary merged cache and file I/O stay outside that guard. The file-path mutex still covers the file read/merge/write transaction.Tested
Windows Server 2025, RTX 3060, GCC 15.2,
build-dev(Ninja).New test
agc_pipeline_cache_file(agc_driver_recorder_tests --pipeline-cache-file-only). TwoPipelineCacheobjects on the same path each build a different compute pipeline (SampleLod.comp,SampleArray.comp) and are destroyed in both orders. A third object loads the file, and each pipeline is built into its cache again.vkGetPipelineCacheDatamust report the same size afterwards, which means the pipeline was already in the cache. The test also checks two more cases:It exits with 77 if the driver keeps nothing in a pipeline cache.
VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BITis not used, because the test device does not enablepipelineCreationCacheControl.AGC graphics: the cache file lost the pipeline of the object that saved first. The objects saved 6.2 KiB and 6.4 KiB, and the third object loaded 6.4 KiB.(merged with the file)in both orders. It passed 10 of 10 runs with--repeat until-fail:10.Every ctest registration of the touched executables passed, 26 tests in all:
agc_driver_recorder_tests, includingagc_pipeline_cacheagc_shader_disk_cacheVulkanDevicetestsagc_buffer_pool,agc_compute_pipeline_capture,agc_driver_buffer_load_store,agc_driver_cmask_fast_clear,agc_driver_copied_writer_copy,agc_driver_d16_memory,agc_driver_depth_plane_guest_layersandagc_driver_draw_offset_indicespython -I tools/check_test_registration.py build-dev: 741 test executables, none built and not run.Not run: the other
VulkanDevicetest executables of libSceAgcDriver, lavapipe, Linux, and any title with this change. The floor that refuses a smaller result is not reached by any test, because merges only add entries on the tested driver.Open PR #4795 ("fix(agc): serialize pipeline cache snapshots") implements the separate device-cache synchronization. Its diff was inspected; this PR depends on it and must preserve its guard after rebase.
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 MarcZX10 on 2026-10-13T13:16:36Z.
Review: COMMENTED
I compared this save path with #4795 and issue #4781. The
pathMutexhere serializes file access between devices, but it does not synchronize eithervkGetPipelineCacheDatacall insave()with concurrentvkCreate*Pipelinescalls on the same live cache. #4795 adds that device-cache synchronization for Intel and its test exercises snapshot-vs-pipeline use. Could you clarify whether #4915 should depend on #4795 or include equivalent synchronization? Otherwise the file merge can still hit the exact Intel saver race reported in #4781.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T17:58:59Z.
You are right that
pathMutexonly serializes access to the file between the process's cache objects. It does not serialize reads of a live Vulkan cache against pipeline creation using that cache.I propose #4795 first and have updated the description to
Depends on: #4795. Once its device-cache guard lands, I will rebase this file-merge change onto it and preserve that guard for the initial live-cache size read and the merge that reads the live cache. Reads of the temporary merged cache and the file I/O can stay outside the device-cache guard. The file mutex still covers the read/merge/write transaction so two cache objects cannot overwrite one another's entries.The current RTX 3060 tests cover the file-loss bug. They do not reproduce or validate the Intel saver crash; I will keep that distinction in the description.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T18:27:10Z.
Thanks for confirming the ordering and updating the dependency. I agree #4795 should land first: its device-cache guard needs to cover the live-cache reads and merge, while the file mutex continues to protect the file transaction between cache objects. I also agree the RTX 3060 validation should stay distinct from the unreproduced Intel saver crash. I’ll review the combined result after the rebase.
AI-assisted: yes; reviewed by MarcZX100.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T01:05:47Z.
Update: #4795 has merged, so the device-cache synchronization you listed as a prerequisite is now on
main. This PR currently reports a conflict withmain. Please rebase and retain the guard for the live-cache size/read and merge-source access; the path mutex still covers the file transaction between cache objects.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T02:51:22Z.
Rebased onto main
0df6e295cafter #4795 merged, atf2efd60e1. The live-cache size query, live merge-source access, and the live-source size/data read retainPipelineCacheSynchronization::LockForSnapshot(). The path mutex still covers the file read/merge/write transaction. Reads of the private temporary merged cache and file I/O stay outside the live-cache guard.The combined source was independently checked against the complete expected merge tree, with original authors and commit messages preserved. This update is source-only; the earlier RTX 3060 file-loss tests do not validate or reproduce the Intel saver crash. Thank you for reviewing the guard placement.
AI-assisted: yes.
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T20:56:55Z.
Rebased onto main
4e210a106at8c8cd86cf. It also merges cleanly with the current main7289938ce.Conflicts:
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp. Main still includes<random>, so the PR does not add it again. The revert of #5211 removed<filesystem>from main, so the PR adds<filesystem>and<fstream>back for the new test.core/libs/prx/libSceAgcDriver/CMakeLists.txtmerged without conflicts. Theagc_pipeline_cache_fileregistration and itsSKIP_RETURN_CODE/PATHproperties sit next toagc_pipeline_cache, as before.PipelineCache.hppandPipelineCache.cppapplied unchanged, because main has not touched them since the last rebase.git range-diffagainst the previous head shows only the include change above.Guard:
PipelineCacheSynchronization::LockForSnapshot()is still held for three things:vkMergePipelineCacheswith the live cache as merge sourceThe path mutex still covers the file read, merge and write. Reads of the private temporary merged cache and the file I/O stay outside the guard.
Tests: Windows Server 2025 10.0.26100, NVIDIA GeForce RTX 3060 12 GB with driver 591.86 (from
nvidia-smi), GCC 15.2,build-devRelease (-O3). BuiltlibSceAgcDriverandagc_driver_recorder_tests.agc_pipeline_cache_filepasses. Withagc_pipeline_cache, it passed 5 of 5 runs under--repeat until-fail:5, and the second save logs(merged with the file)in both orders.PipelineCache.hpp/.cppreverted to main,agc_pipeline_cache_filefails withthe cache file lost the pipeline of the object that saved first. The fix was restored afterwards.agc_driver_recorder_testson this base pass, none skipped. They includeagc_pipeline_cache,agc_pipeline_library,agc_pipeline_library_offandagc_pipeline_library_fast_only.tools/check_conventions.py) passes with the current title and body.As before, these tests cover the file-loss bug. They do not reproduce or validate the Intel saver crash from #4781.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T21:08:30Z.
Pushed a one-line fix: the Linux full build rejected the
agc_pipeline_cache_fileskip becausetools/check_skips.pyonly accepts device-limitation wording, so it now saysskipped, the device does not keep pipelines in a pipeline cache. The skip itself was right.