fix(agc): save the pipeline cache alongside pipeline creation after a bounded wait #28391
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28391"
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 zeezey on 2026-11-30T11:24:33Z.
What
A periodic pipeline cache save does not wait for pipelines: it takes the cache's snapshot lock with a try-lock and, since #28002, tries again every 100 ms after a skip until one attempt gets it. Each pipeline creation holds the shared side of that lock while it builds, so no attempt gets it while creations overlap, and in a cold start they can overlap the whole time. On PPSA38500 (Windows, RTX 4090), a cold start built 394 compute pipelines of over 100,000 SPIR-V words in about 27 minutes, and no save got the lock (#28002 comment). A process that ended in that window without a teardown save would have lost all of them. muhmuhkuh confirmed on #28002 that its retry saves only once creations leave a gap, and suggested keeping a save that runs next to creations as its own change with its own test, including the cache growing between the two
vkGetPipelineCacheDatacalls (comment). This is that change.Vulkan does not require the lock. The cache is created without
VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT, sovkGetPipelineCacheDataandvkCreate*Pipelineson it synchronize inside the driver.vkMergePipelineCachesneeds external synchronization only for its destination, and here that is the cache the save creates from the file, which only the save holds. #4795 added the lock as a workaround: Intel's Windows driver (Iris Xe) faulted insidevkGetPipelineCacheDatawhile a title's threads created pipelines with the same cache (#4781). This change therefore leaves the lock in place on Intel GPUs by default. A pipeline added between the size query and the copy makesvkGetPipelineCacheDatareturnVK_INCOMPLETEwith a shorter cache, which is still valid initial data. Which entries the driver returns in a partial copy is up to the driver, so a partial copy at least as large as the file can still leave out some entries the file had; they stay in the live cache and the next complete save writes them.mainalready acceptsVK_INCOMPLETEfrom the copy and writes what was returned, although under the lock the live cache could not grow between the two calls.Change (driver only,
Graphics/src/PipelineCache.cppand.hpp):APS5_PIPELINE_CACHE_SAVE_BUSY_SECONDS(default 60; default 0 on Intel GPUs, vendor ID 0x8086;0keeps the behaviour ofmain).SaveNowand the teardown save still wait for the lock.saved after a skipped saveline from #28002. That line, and thesavedline at teardown or withAPS5_PROFILE_DRAW, now give the skips before the save and over how long, whether it was taken alongside pipeline creation, and whether the driver returned only part of the cache. The line after a skipped save also says when the save merged the file or went through a mapped file, as the other line already did.VK_INCOMPLETEand is smaller than the file, or than what was loaded at start, is not written (as onmain). Its line now says that the driver returned part of the cache, where it said "the merged cache" before; like a written save, it starts the bound again.APS5_PIPELINE_CACHE_SAVE_FREE_MB) and the mapped save (APS5_PIPELINE_CACHE_MAPPED_SAVE_MB) from #28121 apply to such a save as to any other. This change does not touch that deferral (the separate case raised on #27759, which #28375 now handles onmain): a save taken alongside creation that the reserve puts off is tried again at the next 10 s interval, without the lock while creations still hold it, and counts toward #28375's six saves put off in a row like any other.docs/dev/ENVIRONMENT.md. The debt entry "Periodic pipeline cache saves skip busy intervals" is cut to what stays open (fragmentagc-pipeline-cache-save-alongside.md): a crash while creations overlap still loses the pipelines built since the last save, within the bound and on Intel at any length; whether the Intel fault still happens is not checked; and whether a save without the lock delays creation inside the driver is not measured.Order with #28234 (agreed there): #28234 lands first. Once it is rebased onto
main, this pull request will be stacked on it; until then this head is onmain.#28234 makes a gap for the try-lock: after two busy snapshots and one second of completed compute pipeline creation, new background compute jobs (speculative prebuilds and journal replays) wait at a checkpoint of up to 60 s, so the creations already running can finish and the next retry gets the lock. It does not touch a creation that is already running, foreground creation, or graphics pipelines, and that is deliberate: its own tests check that a foreground creation still takes the lock during the checkpoint, that a long overlapping creation keeps the save waiting, and that pending foreground demand ends the checkpoint.
What this pull request still adds after #28234: a bound on how long saves may skip, whoever holds the lock. While a long compute creation that was admitted before the checkpoint is still running, while foreground creations keep coming (no checkpoint holds background work while one is pending), or while graphics pipelines are being created (which never take part in the checkpoint), #28234 cannot make a gap, and after
APS5_PIPELINE_CACHE_SAVE_BUSY_SECONDSthe save is taken alongside creation. When #28234's checkpoint does make a gap first, the bound never comes into play: that save resets the count of skips. On Intel GPUs the bound defaults to 0, so there only #28234 helps.Stacked, the two will meet in the three snapshot points of the save: a skip there is what arms #28234's checkpoint, and a save taken alongside creation counts as a save that was not busy, so it closes the checkpoint and lets background work go on.
Overlap and prior art:
mainafter this pull request was opened, writes a save of a large cache after six in a row were put off by the free-memory reserve. It changes the reserve check insidesave(), which this change does not touch, so the two do different things: a save taken alongside creation that the reserve puts off counts toward its six like any other. This head is rebased onto it. The rebase conflicted only where both add lines at the same places, and each conflict takes both sides' additions: the declarations and members inPipelineCache.hpp, the functions afterPostponedSaves()inPipelineCache.cpp, theput-offandbusy-boundedtest modes in the mode checks ofPipelineCacheFailures.cpp, both tests' registrations inagc_pipeline_cache_allocation_tests.cmake, and indocs/dev/ENVIRONMENT.mdthis change's new row above #28375's editedAPS5_PIPELINE_CACHE_SAVE_FREE_MBrow. The rest ofsave()merged without a conflict, and the diff of this head againstmainhas the same 292 added and 23 removed lines as before the rebase.git merge-treewith this head conflicts only in the argument check at the top ofmain()inPipelineCacheFailures.cpp, which #28492 changes to take a writer role. With both, a periodic save that finds the file lock held is skipped through the same retry, but that skip does not count toward this change's bound, which counts only skips on the snapshot lock; a save taken alongside creation still needs the file lock before it reads the file.save()to retry aVK_INCOMPLETEcopy up to three times and to skip the save if all three come back incomplete.git merge-treewith this head conflicts inPipelineCache.cppandPipelineCacheFailures.cpp. With both, a save taken alongside creation would be dropped when the cache grows during all three copies.tools/pr_overlap.py --branchon this head: 154 other open pull requests share files with this branch. Of the 97 it could compare, #28492 and #18082 overlap (above). The other 57 conflict withmain, so it could not compare them: #28234 and 56 that share onlydocs/dev/ENVIRONMENT.md, none of which adds or removes a row next to this one. Nine pull request heads could not be fetched (#7642, #9508, #10193, #13928, #13929, #14217, #14218, #24048, #26766); the tool on thismainstops at the first one, so it ran with those nine left out.Tested
This head is one commit on
mainfc294cbbb5, rebased from1b8f79a5b5onto #28375 (see the overlap above); every run below is on this head. Themainside is one unchanged build offc294cbbb5on the same machine, with the same toolchain, options and four variables and the validation layer, shared by our pull requests on that commit.Windows 11 Pro (10.0.26300), NVIDIA GeForce RTX 4090 (driver 621.24), WinLibs GCC 15.2.0, Release,
-DBUILD_TESTING=ON; the files this change touches compile without warnings. Every Windows run below usedANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layerwith the validation layer 1.4.363. Every Vulkan test's log shows the loader inserting the layer: 3 tests in each run of the area tests, and 1,774 tests on each side of the complete run (2,227 insertions; some tests create several instances). The new test and the other tests ofagc_pipeline_cache_allocation_testsuse fake Vulkan functions and create no instance, so their logs have no layer lines. No log haswas not found but was requested by env var VK_INSTANCE_LAYERS, aVUID-line or aSYNC-HAZARDline.New test
agc_pipeline_cache_busy_bounded(every system). It uses the fake Vulkan cache functions ofPipelineCacheFailures.cpp, sets the bound itself (3 s, then0, then the largest value), and keeps pipeline use locked on another thread:VK_INCOMPLETEis saved and loads into a new cache.0, and at the largest value (18446744073709551615), no save goes ahead until pipeline use is released.PipelineCache.cppmakes it fail, 2 of 2 runs each (on Linux, with the same patch on an earliermain,63ee1c120a): the earlier nanosecond comparison of a local revision,now - busySince >= std::chrono::seconds(min(bound, 2^40)), which overflows ("with the largest bound a save went ahead while pipeline use was locked"); the merge never going ahead without the lock ("no save completed while pipeline use stayed locked past the bound"); no restart after a save that found nothing new ("a save that found nothing new did not start the bound again"); and no Intel default. With the branch's code it passes.^agc_pipeline_cacheunder every setting the change reads, 5 runs each, one test at a time: unset;APS5_PIPELINE_CACHE_SAVE_BUSY_SECONDS0and1;APS5_PIPELINE_CACHE_MAPPED_SAVE_MB=0(which maps every save) alone and with the busy setting at0and1; andAPS5_PIPELINE_CACHE_SAVE_FREE_MB=0. The branch (23 tests, with #28375'sagc_pipeline_cache_put_off) passed 5 of 5 runs in all seven settings, 805 test runs.mainfc294cbbb5(the same 22 tests without the new one) passed 5 of 5 in all seven, 770 test runs. They include the Vulkan testsagc_pipeline_cache,agc_pipeline_cache_headerandagc_pipeline_cache_file, which holds #28002's retry case.Complete ctest, Windows (the branch with
ctest -j 6,mainwith-j 8, one after the other):agc_*mainfc294cbbb5agc_pipeline_cache_busy_bounded(passed, 15.3 s), and the same 37 tests were skipped on both sides.guest_video_out_hdr(exit code 0xc0000409; 0 of 5 alone onmain).test_executable_manifests, a timeout in the run. Run alone 5 times on each side, it passed 5 of 5 on the branch and 3 of 5 onmain.tools/vulkan_validation_gate.py(mainfc294cbbb5as the baseline, this head as the candidate,--gpu NVIDIA --repeat 20, on the RTX 4090, the only NVIDIA GPU in this PC): 3 tests, the Vulkan tests both sides have (agc_pipeline_cache,agc_pipeline_cache_fileandagc_pipeline_cache_header);main's new commits touch this change's files (#28375), so the gate ran again on this head. Exit 0, status complete. All 120 test runs (3 tests × 20 iterations × 2 builds) inserted the layer, with no failures, no skips and no new validation diagnostics on either side.Linux (Ubuntu 24.04 in a WSL 2 chroot, GCC 13.3.0, Ninja, Release, lavapipe from Mesa 25.2.8 with LLVM 20.1.2, validation layer 1.4.335, the same four variables). A full build of this head.
^agc_pipeline_cache: 13 tests (12 passed, 1 skipped) in each of 3 runs, and once under each of the six set switch values above.mainran 12 (11 passed, 1 skipped), 3 runs. The skipped test isagc_pipeline_cache_file: lavapipe keeps no pipelines in a pipeline cache. The mapped save is Windows-only, andagc_pipeline_cache_read_retryand theagc_pipeline_cache_mapped*tests are not registered on Linux. NoVUID-line.agc_pipeline_cache_busy_bounded20 times in a row: 20 of 20 passed, 15.02 to 15.04 s each.-j 4): 7389 tests, 7162 passed, 220 skipped, 7 failed; the layer inserted in 1,710 tests (2,160 insertions), as onmain; noVUID-orSYNC-HAZARDline. The shared Linux run ofmainfc294cbbb5(same chroot, toolchain and four variables): 7388 tests, 7160 passed, 220 skipped (the same set), 8 failed.maintoo, where each failed 5 of 5 alone: seven AGC tests that fail in this lavapipe setup (agc_driver_depth_fewer_samples,agc_driver_flat_aperture_lds_bounds,agc_driver_gcn_multisample_color_fill,agc_driver_image_d16_load,agc_driver_image_filter_mode_three,agc_driver_upload_cache_read_only_flush,agc_driver_write_back_guest_newer).mainalso failedagc_driver_msaa_resolve_publication_order(2 of 5 alone there).tools/check_conventions.py(with this title and body),tools/debt_fold.py --checkandtools/check_test_registration.py(the build and--scripts) pass. The pull request steps of the Windows job that build only the changed tests (build_mingw_host_only_tests.py,build_changed_guest_tests.py) were not run on their own: the complete build above built every target and the complete ctest ran every registered test.tools/env_reference.py --checkreports one stale row,APS5_PM4_RING_WORDS, onmainas well; it is not this change's.Title: PPSA38500 on Windows 11, RTX 4090, driver 621.24, from #28002's thread. These were two boots of a local branch that also carries other open pull requests: the first before it had this change, the second with an earlier revision of it. That branch tried a skipped save again every second, where
mainnow does every 100 ms, so a 60 s bound counted about 60 skips there. The code in this pull request ran through the tests above, not through the title again.VK_INCOMPLETE.Not tested:
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
Summary by CodeRabbit
APS5_PIPELINE_CACHE_SAVE_BUSY_SECONDS. It defaults to 60 seconds for most GPUs and 0 seconds for Intel GPUs.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T11:34:07Z.
Review: COMMENTED
Actionable comments posted: 2
Architecture findings (2)
Advisory architecture findings (2)
0dfc4cf3-7c22-4407-8004-cf5e16b7d160Reviewing files that changed from the base of the PR and between
809a271099and7f123d7100.core/libs/prx/libSceAgcDriver/Graphics/include/PipelineCache.hppcore/libs/prx/libSceAgcDriver/Graphics/src/PipelineCache.cppcore/libs/prx/libSceAgcDriver/tests/PipelineCacheFailures.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_pipeline_cache_allocation_tests.cmakedocs/dev/ENVIRONMENT.mddocs/dev/debt/changes/agc-pipeline-cache-save-alongside.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T12:20:36Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and the supplied test results support merging.
What I ran
Reviewed head
7f123d7100d6559703a23e38e2b6f84bcd2d611e. I read the prepared description, commit summary, diff, manifest, and all six changed files listed in the manifest. Repository context was read throughrepo_read.py. No commands or tests were run; test results below are author-reported in the PR description.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently run the test suite or verify the author-reported Windows, Linux, GPU, or driver results. The description reports macOS, AMD and Intel hardware, and real-driver saves alongside pipeline creation as untested.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T20:41:15Z.
Review: COMMENTED
Actionable comments
126ac61a-6871-4f99-ba1b-0a58363bb74fReviewing files that changed from the base of the PR and between
7f123d7100andf1a7f9ae36.core/libs/prx/libSceAgcDriver/Graphics/include/PipelineCache.hppcore/libs/prx/libSceAgcDriver/Graphics/src/PipelineCache.cppcore/libs/prx/libSceAgcDriver/tests/PipelineCacheFailures.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_pipeline_cache_allocation_tests.cmakedocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T20:42:49Z.
Review: APPROVED
Reviewed — looks good
The reviewed change adds a bounded fallback for periodic pipeline cache saves; I found no blocking defect in the changed code.
What I ran
Reviewed head
f1a7f9ae3630f9e21e29ceef6f7eca602372ab2dagainst the prepared diff and head snapshot. No build or tests were run. The test results below are author-reported.Results
Negative control
Not run; no test was executed during this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The reported test results were not independently confirmed. No real-driver test exercised an unlocked save during pipeline creation; the description reports an RTX 4090 run, while other GPUs and platforms were not tested. No files were excluded by the manifest. I inspected the six changed files listed under
reviewed, including targeted ranges of the longer source and test files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T10:56:54Z.
Review: COMMENTED
Ran paired
ctest -Vonmainand the submitted change on the same llvmpipe device with Vulkan required, shader cache disabled, and Khronos validation 1.4.369 enabled. The three allocation-failure cases and the Vulkan scalar-buffer control passed on both. Both logs showed validation insertion with zero missing-layer diagnostics and zeroVUID-messages. The branch's additionalagc_pipeline_cache_busy_boundedfixture passed, including joining another writer's cache contents after the wait bound.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.