fix(agc): repeat a periodic pipeline cache save that a pipeline creation skipped #28002

Merged
muhmuhkuh merged 1 commit from upstream-pr/28002 into main 2026-11-30 00:05:03 +00:00
muhmuhkuh commented 2026-11-28 03:09:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by muhmuhkuh on 2026-11-28T03:09:11Z.


What

The periodic pipeline cache save runs every 10 s on the saver thread and takes the cache's snapshot lock with TryLockForSnapshot. Since #6958 it returns without saving while a pipeline creation holds the cache, so that a long creation never waits behind a save and the save never blocks creations. The next attempt then comes only at the next 10 s tick. Pipelines built after the last successful save are lost when the process ends before that tick without a teardown save, for example when the title is stopped by its own watchdog or a crash.

Seen in PPSA38500: one run saved the driver cache (17,558.7 KiB) before a group of large compute pipelines was built; the next periodic save was skipped because one of those creations held the cache, and the process ended a few seconds later. The pipeline journal had recorded the new pipelines, so the next run replayed them at startup against a driver cache that did not contain them: the journal had 11 more compute pipelines than before, five of them took 0.6–7.0 s each (one 6,988 ms), and the replay took 8,317 ms instead of 907 ms. That run then saved 18,958.7 KiB right after the replay.

Change (driver only, Graphics/src/PipelineCache.cpp and .hpp):

  • When a non-blocking save cannot take the snapshot lock (any of its three TryLockForSnapshot points), it sets skippedSave under the saver mutex and wakes the saver thread.
  • While skippedSave is set, the saver thread retries every 100 ms (SkippedSaveRetryMilliseconds) instead of every 10 s. Each retry is still a non-blocking TryLockForSnapshot, so a running creation is never waited for and new creations are never blocked. The first save that gets the lock clears the flag, and the 10 s rhythm resumes.
  • The retry runs only on the saver thread. Pipeline creations take the cache with LockForPipelineUse on their own threads (Execution/src/VulkanDevice.cpp, Graphics/include/Context.hpp, Graphics/src/PipelineLibrary.cpp); nothing new runs there.
  • A save that follows a skipped one logs [pipeline-cache] saved after a skipped save: <KiB> to <path> in <ms> ms.
  • SaveNow and the teardown save still wait for creations (LockForSnapshot) and never set the flag.

Tested

Windows 11, NVIDIA GeForce RTX 3080 Ti, driver 610.88; built and run on main 4814cae8551 and on this branch on the same machine.

  • New case in the pipeline cache file test (tests/Recorder.cpp, next to the #6958 case): a cache saves pipeline 0; a thread takes LockForPipelineUse, builds pipeline 1 and holds the lock; SaveUnlessBusy is skipped and the file is unchanged; the thread releases the lock; within 3 s (shorter than the 10 s interval) the file grows, and a cache reloaded from it holds pipeline 1.
  • Without the fix (main plus the new test): agc_pipeline_cache_file fails with "a periodic pipeline cache save skipped for a pipeline creation was not repeated after the creation finished".
  • With the fix: agc_pipeline_cache_file passes.
  • The #6958 case (a save does not wait for a creation, a creation does not wait behind a save) is unchanged and runs in the same test.
  • AGC focused tests with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest --test-dir build -R '^agc_pipeline_(cache|link_optimization|queue_failure|library$|library_off$|library_fast_only$|library_wide$|library_lto_info)' -V: main 19/19 passed, this branch 19/19 passed; the validation layer was loaded, neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS; VUID- lines: 0 on main, 0 on this branch.
  • PPSA38500, on a local test branch with other patches: in one run a periodic save was skipped while a 327,948-word compute pipeline was building (5.4 s), and the retry logged saved after a skipped save: 21148.3 KiB right as the build finished. An earlier run with the change skipped no save.
  • tools/check_conventions.py --base origin/main: All conventions checks passed.

tools/pr_overlap.py --branch fix/agc-pipeline-cache-save-after-skip: #27932 (open, seeds a new cache folder from an older one) conflicts with this branch in Graphics/src/PipelineCache.cpp around lines 297–298 of main; it is a different change, and whichever merges second rebases. The tool cannot compare 33 open pull requests that conflict with main themselves; checked by hand with git diff against their merge bases: none adds a retry of a skipped save; #18082 changes other parts of PipelineCache::save.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA38500 #27523 (startup replay after a run that ended before its next cache save)
  • GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 610.88, Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Pipeline cache saves skipped while pipelines are being created are now retried automatically. Newly created pipelines are more likely to be retained in the cache, including when a save overlaps with pipeline creation.
    • Routine saves continue on their usual schedule, while skipped saves are retried sooner. This helps preserve newly created pipelines without changing the normal cache-saving cadence.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5536093249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28002). Originally posted by [muhmuhkuh](https://github.com/muhmuhkuh) on 2026-11-28T03:09:11Z. --- ### What The periodic pipeline cache save runs every 10 s on the saver thread and takes the cache's snapshot lock with `TryLockForSnapshot`. Since #6958 it returns without saving while a pipeline creation holds the cache, so that a long creation never waits behind a save and the save never blocks creations. The next attempt then comes only at the next 10 s tick. Pipelines built after the last successful save are lost when the process ends before that tick without a teardown save, for example when the title is stopped by its own watchdog or a crash. Seen in PPSA38500: one run saved the driver cache (17,558.7 KiB) before a group of large compute pipelines was built; the next periodic save was skipped because one of those creations held the cache, and the process ended a few seconds later. The pipeline journal had recorded the new pipelines, so the next run replayed them at startup against a driver cache that did not contain them: the journal had 11 more compute pipelines than before, five of them took 0.6–7.0 s each (one 6,988 ms), and the replay took 8,317 ms instead of 907 ms. That run then saved 18,958.7 KiB right after the replay. Change (driver only, `Graphics/src/PipelineCache.cpp` and `.hpp`): - When a non-blocking save cannot take the snapshot lock (any of its three `TryLockForSnapshot` points), it sets `skippedSave` under the saver mutex and wakes the saver thread. - While `skippedSave` is set, the saver thread retries every 100 ms (`SkippedSaveRetryMilliseconds`) instead of every 10 s. Each retry is still a non-blocking `TryLockForSnapshot`, so a running creation is never waited for and new creations are never blocked. The first save that gets the lock clears the flag, and the 10 s rhythm resumes. - The retry runs only on the saver thread. Pipeline creations take the cache with `LockForPipelineUse` on their own threads (`Execution/src/VulkanDevice.cpp`, `Graphics/include/Context.hpp`, `Graphics/src/PipelineLibrary.cpp`); nothing new runs there. - A save that follows a skipped one logs `[pipeline-cache] saved after a skipped save: <KiB> to <path> in <ms> ms`. - `SaveNow` and the teardown save still wait for creations (`LockForSnapshot`) and never set the flag. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, NVIDIA GeForce RTX 3080 Ti, driver 610.88; built and run on `main` `4814cae8551` and on this branch on the same machine. - New case in the pipeline cache file test (`tests/Recorder.cpp`, next to the #6958 case): a cache saves pipeline 0; a thread takes `LockForPipelineUse`, builds pipeline 1 and holds the lock; `SaveUnlessBusy` is skipped and the file is unchanged; the thread releases the lock; within 3 s (shorter than the 10 s interval) the file grows, and a cache reloaded from it holds pipeline 1. - Without the fix (`main` plus the new test): `agc_pipeline_cache_file` fails with "a periodic pipeline cache save skipped for a pipeline creation was not repeated after the creation finished". - With the fix: `agc_pipeline_cache_file` passes. - The #6958 case (a save does not wait for a creation, a creation does not wait behind a save) is unchanged and runs in the same test. - AGC focused tests with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest --test-dir build -R '^agc_pipeline_(cache|link_optimization|queue_failure|library$|library_off$|library_fast_only$|library_wide$|library_lto_info)' -V`: `main` 19/19 passed, this branch 19/19 passed; the validation layer was loaded, neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`; `VUID-` lines: 0 on `main`, 0 on this branch. - PPSA38500, on a local test branch with other patches: in one run a periodic save was skipped while a 327,948-word compute pipeline was building (5.4 s), and the retry logged `saved after a skipped save: 21148.3 KiB` right as the build finished. An earlier run with the change skipped no save. - `tools/check_conventions.py --base origin/main`: `All conventions checks passed.` `tools/pr_overlap.py --branch fix/agc-pipeline-cache-save-after-skip`: #27932 (open, seeds a new cache folder from an older one) conflicts with this branch in `Graphics/src/PipelineCache.cpp` around lines 297–298 of `main`; it is a different change, and whichever merges second rebases. The tool cannot compare 33 open pull requests that conflict with `main` themselves; checked by hand with `git diff` against their merge bases: none adds a retry of a skipped save; #18082 changes other parts of `PipelineCache::save`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA38500 #27523 (startup replay after a run that ended before its next cache save) - [x] GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 610.88, Windows 11 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Pipeline cache saves skipped while pipelines are being created are now retried automatically. Newly created pipelines are more likely to be retained in the cache, including when a save overlaps with pipeline creation. * Routine saves continue on their usual schedule, while skipped saves are retried sooner. This helps preserve newly created pipelines without changing the normal cache-saving cadence. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Plyxen commented 2026-11-28 07:01:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T07:01:33Z.

Review: APPROVED


Checked head c11d52b473. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main 4c7578e0a4 together with #28006, #27985, #28001, #27991, #27987, #28007, #27994. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. In the full CPU suite (5,135 tests) the only failure is windows_read_trap_unknown, which fails on main too (fixed in #28028). The full GPU suite (2,249 tests) on both GPUs, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer and the 1.4.363 layer inserted, matches main on the same machine. The GPUs were an NVIDIA RTX 5080 (621.24) and an AMD Radeon gfx1036 iGPU (26.11.2). Only agc_driver_linear_target_import_creation fails, as on main (fixed in #28029), and neither log has a VUID- or SYNC-HAZARD line.

agc_driver_recorder and the agc_pipeline_cache_allocation* tests pass on both GPUs. I checked that skipped() cannot deadlock against run(): run() releases mutex before it calls save(), so the lambda never takes a lock its caller holds.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6096379097 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28002#pullrequestreview-6096379097). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T07:01:33Z. **Review:** APPROVED --- Checked head `c11d52b473`. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to `main` `4c7578e0a4` together with #28006, #27985, #28001, #27991, #27987, #28007, #27994. `tools/check_conventions.py --head` and `tools/debt_fold.py --check` passed and the full build succeeded. In the full CPU suite (5,135 tests) the only failure is `windows_read_trap_unknown`, which fails on `main` too (fixed in #28028). The full GPU suite (2,249 tests) on both GPUs, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer` and the 1.4.363 layer inserted, matches `main` on the same machine. The GPUs were an NVIDIA RTX 5080 (621.24) and an AMD Radeon gfx1036 iGPU (26.11.2). Only `agc_driver_linear_target_import_creation` fails, as on `main` (fixed in #28029), and neither log has a `VUID-` or `SYNC-HAZARD` line. `agc_driver_recorder` and the `agc_pipeline_cache_allocation*` tests pass on both GPUs. I checked that `skipped()` cannot deadlock against `run()`: `run()` releases `mutex` before it calls `save()`, so the lambda never takes a lock its caller holds. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-28 07:43:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T07:43:58Z.

Review: COMMENTED


Reviewed — no blocking findings

The change looks consistent with the stated retry behavior, but I could not run its tests, so a formal approval is not justified.

What I ran

Reviewed head c11d52b4739c582cd573db0cce6c2db2427f47a using repo_read.py; no commands or tests were run in this environment.

Results

Check Result Note
Diff and targeted code review passed Three changed files inspected
Tests not run Test results in the description are author-reported

Negative control

Not run here. The description reports that the new test fails on main without the fix.

Findings

Blocking

None.

Non-blocking

None.

Sources

Reviewed description.md, commits.md, manifest.json, and diff.patch; inspected PipelineCache.hpp and PipelineCache.cpp, plus the changed test block in Recorder.cpp at the pinned head.

Not verified

The reported test runs and convention check were not independently verified. Recorder.cpp is too large to be included in the review bundle; only the changed test region was read. Other parts of that file and unmodified repository code were not reviewed.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6096604474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28002#pullrequestreview-6096604474). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T07:43:58Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The change looks consistent with the stated retry behavior, but I could not run its tests, so a formal approval is not justified. ## What I ran Reviewed head `c11d52b4739c582cd573db0cce6c2db2427f47a` using `repo_read.py`; no commands or tests were run in this environment. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Three changed files inspected | | Tests | not run | Test results in the description are author-reported | ## Negative control Not run here. The description reports that the new test fails on `main` without the fix. ## Findings ### Blocking None. ### Non-blocking None. ## Sources Reviewed `description.md`, `commits.md`, `manifest.json`, and `diff.patch`; inspected `PipelineCache.hpp` and `PipelineCache.cpp`, plus the changed test block in `Recorder.cpp` at the pinned head. ## Not verified The reported test runs and convention check were not independently verified. `Recorder.cpp` is too large to be included in the review bundle; only the changed test region was read. Other parts of that file and unmodified repository code were not reviewed. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-29 17:55:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T17:55:33Z.

Review: APPROVED


Reviewed — looks good

The retry logic and regression case appear sound at the reviewed head; no checks were run in this review session.

What I ran

  • Read the prepared description, commit summary, manifest, and diff for head 33cc1120f7ae018841eea5a5dae3209efa7a5323.
  • Read both included changed files and targeted constructor, destructor, caller, and test context using repo_read.py.
  • No build or tests were run in this review session.

Results

Check Result Note
Diff and logic review passed Retry state and wake loop inspected
Automated checks not run Author reports Windows tests; not rerun here

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • tests/Recorder.cpp is excluded from the prepared review files because it is too large; its changed test hunk and relevant surrounding test code were read through repo_read.py.
  • The author-reported Windows build, Vulkan tests, and convention checks were not independently run.
  • Files read: description.md, commits.md, manifest.json, diff.patch, PipelineCache.hpp, PipelineCache.cpp (targeted ranges), and Recorder.cpp (targeted ranges). files.json was unavailable in the review folder; the manifest identifies the excluded test file. No other changed repository files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6104075851 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28002#pullrequestreview-6104075851). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-29T17:55:33Z. **Review:** APPROVED --- # Reviewed — looks good The retry logic and regression case appear sound at the reviewed head; no checks were run in this review session. ## What I ran - Read the prepared description, commit summary, manifest, and diff for head `33cc1120f7ae018841eea5a5dae3209efa7a5323`. - Read both included changed files and targeted constructor, destructor, caller, and test context using `repo_read.py`. - No build or tests were run in this review session. ## Results | Check | Result | Note | |---|---|---| | Diff and logic review | passed | Retry state and wake loop inspected | | Automated checks | not run | Author reports Windows tests; not rerun here | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - `tests/Recorder.cpp` is excluded from the prepared review files because it is too large; its changed test hunk and relevant surrounding test code were read through `repo_read.py`. - The author-reported Windows build, Vulkan tests, and convention checks were not independently run. - Files read: `description.md`, `commits.md`, `manifest.json`, `diff.patch`, `PipelineCache.hpp`, `PipelineCache.cpp` (targeted ranges), and `Recorder.cpp` (targeted ranges). `files.json` was unavailable in the review folder; the manifest identifies the excluded test file. No other changed repository files were excluded. ## To get this to a good state Nothing is required.
Plyxen commented 2026-11-29 18:02:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-29T18:02:08Z.

Review: APPROVED


Re-checked the rebased head 33cc1120f7 on main 6f6f6c8e6b. Against the head I approved, c11d52b473, the change is the same apart from the save line, which keeps #28121's "(written through a mapped file)" field in the line that a non-retried save prints.

Windows 11, WinLibs GCC 15.2, Release, RTX 5080, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_LAYER_KHRONOS_validation (inserted in every run, no VUID-):

  • agc_pipeline_cache, agc_pipeline_cache_file and agc_pipeline_cache_header pass on main and pass 3/3 at this head.
  • With main's PipelineCache.cpp and PipelineCache.hpp and this head's test, agc_pipeline_cache_file fails with "a periodic pipeline cache save skipped for a pipeline creation was not repeated after the creation finished".

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6104099436 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28002#pullrequestreview-6104099436). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-29T18:02:08Z. **Review:** APPROVED --- Re-checked the rebased head `33cc1120f7` on `main` `6f6f6c8e6b`. Against the head I approved, `c11d52b473`, the change is the same apart from the save line, which keeps #28121's "(written through a mapped file)" field in the line that a non-retried save prints. Windows 11, WinLibs GCC 15.2, Release, RTX 5080, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_LAYER_KHRONOS_validation` (inserted in every run, no `VUID-`): - `agc_pipeline_cache`, `agc_pipeline_cache_file` and `agc_pipeline_cache_header` pass on `main` and pass 3/3 at this head. - With `main`'s `PipelineCache.cpp` and `PipelineCache.hpp` and this head's test, `agc_pipeline_cache_file` fails with "a periodic pipeline cache save skipped for a pipeline creation was not repeated after the creation finished". AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
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!28002
No description provided.