fix(agc): reapply pipeline cache persistence with guarded key queries #15169

Merged
liskeee merged 5 commits from upstream-pr/15169 into main 2026-11-09 19:16:50 +00:00
liskeee commented 2026-11-02 19:46:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by liskeee on 2026-11-02T19:46:08Z.


What

I reapply #13931, reverted in #14839: driver pipeline caches survive source updates, and eligible compute pipelines are captured and restored with VK_KHR_pipeline_binary, with ordinary driver-cache fallback. Against merged main 6773f91a7e I keep main's recorder error handling, debt entries, APS5_HEADLESS_PIPELINE_CACHE loading condition and portability-subset test features, and link the store test against libSceAgcDriver because DeviceProcLookups moved out of the header. The binary layout key also tells main's scratch-pool layouts apart (0, 1 or 2 additional descriptor sets); layouts without a scratch pool keep the same contribution to the key.

New in this PR: global and per-pipeline key queries write into separate, 64-byte-aligned heap scratch followed by a 64-byte guard filled with 0xa5, and a key is accepted only after VK_SUCCESS, an intact guard, the expected sType, a null pNext and a size from 1 to VK_MAX_PIPELINE_BINARY_KEY_SIZE_KHR.

 PipelineBinaryStore(...)
   resolve vkGetPipelineKeyKHR ...
-  getKey(device, nullptr, &globalKey)
-  enable if VK_SUCCESS and 1 <= keySize <= 32
+  getKey(device, nullptr, &guardedScratch.key)
+  enable only if VK_SUCCESS, guard intact, sType unchanged, pNext null, 1 <= keySize <= 32
+  copy the validated key into globalKey
+  else: stay disabled, log once, use the driver pipeline cache

A rejected per-pipeline key falls back to an ordinary build for that pipeline. I have not found the cause of the NVIDIA Linux startup crash in the code: the call uses the Khronos function-pointer type from the device resolver, the output structure is initialised, and the feature is enabled before the call. These checks detect malformed keys and writes that reach the guard; they cannot contain arbitrary driver corruption or clobbered registers, and they cannot stop a crash inside the call. APS5_NO_PIPELINE_BINARIES still turns the store off before the call.

Tested

Windows, NVIDIA GeForce RTX 4080, driver 610.88, and the affected Linux RTX 4090 (run by @oneandonlydean). No title or performance claim.

  • RTX 4090, the machine from #14839 (Linux, NVIDIA 610.57.04, result): @oneandonlydean ran the command from the previous description at c8244e0269 merged with the main of that day and reports 28/28 passing with VK_LAYER_KHRONOS_validation and 28/28 without it, no VUID- line and no crash, with the startup test reporting store ready on that device. I treat this as startup and store coverage, not a full game boot.
  • main vs this PR, RTX 4080, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -j 1 -V, the 139 existing tests registered in the files this PR touches (pipeline cache, recorder and Vulkan test-device tests): main 6773f91a7e 139/139, this PR 1202ace37c 139/139 (the later be14e4c25e changes only the debt entry's coverage sentence). The validation layer loaded in both logs, neither reports a missing requested layer, and neither has a VUID- or SYNC-HAZARD- line.
  • Store tests: 12/12 pass. The new cases cover the query arguments, zero, oversized and maximum key sizes, a changed sType or non-null pNext for global and per-pipeline keys, a corrupted guard and the fallback after a rejected global key. The new tests require the added scratch type and IsReady. With the startup test, agc_pipeline_binary_vulkan and three agc_pipeline_cache_allocation modes, all 17 tests this PR adds pass under the settings above.
  • agc_driver_pipeline_binary_startup (new): creates the production device with the shader cache enabled in a temporary directory and requires the store to be ready when the device has VK_KHR_pipeline_binary (exit 77 with skipped, the device lacks VK_KHR_pipeline_binary otherwise). On the RTX 4080 it prints pipeline binary startup: global-key query completed successfully; store ready; device=NVIDIA GeForce RTX 4080; driver=NVIDIA 610.88.
  • Cache enabled (neither ANYPS5_NO_SHADER_CACHE nor APS5_NO_PIPELINE_BINARIES set, validation layer loaded), RTX 4080: 103/103 pass: the startup test, the binary-store and pipeline-cache tests, agc_driver_small_copy_sync, both agc_driver_address_passes tests, the other agc_driver tests that do not disable the cache, and the automatically added agc_driver_pm4_replay fixture (which disables the shader cache itself). No VUID- line. agc_pipeline_binary_vulkan saves binary records for two pipelines and restores both in the next process. On main 6773f91a7e, the 85 of these tests that exist there, plus the fixture, pass 86/86. The binary round-trip test uses trivial shaders and an empty layout, so it does not test scratch-pool layouts.

Checklist

  • Based on current main; no other open PR implements the same functions
    Merged with main 6773f91a7e, without a force-push. tools/pr_overlap.py --branch on 11-09: of the 295 open PRs that share files or exports with this branch, none of those it could compare has conflicting lines; 94 conflict with main themselves, so it could not compare them and failed closed (mostly VulkanDevice.cpp, Recorder.cpp, CMakeLists.txt, ENVIRONMENT.md and the debt file). A GitHub search found no open PR implementing driver pipeline caches or pipeline binaries.
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
    No unimplemented exports or silent stubs are added.
  • 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
    No third-party code is added.
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4080, driver 610.88, Windows; NVIDIA GeForce RTX 4090, driver 610.57.04, Linux (startup and store tests, by @oneandonlydean)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5126393570 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15169). Originally posted by [liskeee](https://github.com/liskeee) on 2026-11-02T19:46:08Z. --- ### What I reapply [#13931](https://github.com/boykopovar/AnyPS5/pull/13931), reverted in [#14839](https://github.com/boykopovar/AnyPS5/pull/14839): driver pipeline caches survive source updates, and eligible compute pipelines are captured and restored with `VK_KHR_pipeline_binary`, with ordinary driver-cache fallback. Against merged `main` `6773f91a7e` I keep main's recorder error handling, debt entries, `APS5_HEADLESS_PIPELINE_CACHE` loading condition and portability-subset test features, and link the store test against `libSceAgcDriver` because `DeviceProcLookups` moved out of the header. The binary layout key also tells main's scratch-pool layouts apart (0, 1 or 2 additional descriptor sets); layouts without a scratch pool keep the same contribution to the key. New in this PR: global and per-pipeline key queries write into separate, 64-byte-aligned heap scratch followed by a 64-byte guard filled with `0xa5`, and a key is accepted only after `VK_SUCCESS`, an intact guard, the expected `sType`, a null `pNext` and a size from 1 to `VK_MAX_PIPELINE_BINARY_KEY_SIZE_KHR`. ```diff PipelineBinaryStore(...) resolve vkGetPipelineKeyKHR ... - getKey(device, nullptr, &globalKey) - enable if VK_SUCCESS and 1 <= keySize <= 32 + getKey(device, nullptr, &guardedScratch.key) + enable only if VK_SUCCESS, guard intact, sType unchanged, pNext null, 1 <= keySize <= 32 + copy the validated key into globalKey + else: stay disabled, log once, use the driver pipeline cache ``` A rejected per-pipeline key falls back to an ordinary build for that pipeline. I have not found the cause of the NVIDIA Linux startup crash in the code: the call uses the Khronos function-pointer type from the device resolver, the output structure is initialised, and the feature is enabled before the call. These checks detect malformed keys and writes that reach the guard; they cannot contain arbitrary driver corruption or clobbered registers, and they cannot stop a crash inside the call. `APS5_NO_PIPELINE_BINARIES` still turns the store off before the call. ### 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, NVIDIA GeForce RTX 4080, driver 610.88, and the affected Linux RTX 4090 (run by @oneandonlydean). No title or performance claim. - **RTX 4090, the machine from #14839** (Linux, NVIDIA 610.57.04, [result](https://github.com/boykopovar/AnyPS5/pull/15169#issuecomment-6701543076)): @oneandonlydean ran the command from the previous description at `c8244e0269` merged with the `main` of that day and reports 28/28 passing with `VK_LAYER_KHRONOS_validation` and 28/28 without it, no `VUID-` line and no crash, with the startup test reporting `store ready` on that device. I treat this as startup and store coverage, not a full game boot. - **main vs this PR**, RTX 4080, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest -j 1 -V`, the 139 existing tests registered in the files this PR touches (pipeline cache, recorder and Vulkan test-device tests): `main` `6773f91a7e` 139/139, this PR `1202ace37c` 139/139 (the later `be14e4c25e` changes only the debt entry's coverage sentence). The validation layer loaded in both logs, neither reports a missing requested layer, and neither has a `VUID-` or `SYNC-HAZARD-` line. - **Store tests:** 12/12 pass. The new cases cover the query arguments, zero, oversized and maximum key sizes, a changed `sType` or non-null `pNext` for global and per-pipeline keys, a corrupted guard and the fallback after a rejected global key. The new tests require the added scratch type and `IsReady`. With the startup test, `agc_pipeline_binary_vulkan` and three `agc_pipeline_cache_allocation` modes, all 17 tests this PR adds pass under the settings above. - **`agc_driver_pipeline_binary_startup` (new):** creates the production device with the shader cache enabled in a temporary directory and requires the store to be ready when the device has `VK_KHR_pipeline_binary` (exit 77 with `skipped, the device lacks VK_KHR_pipeline_binary` otherwise). On the RTX 4080 it prints `pipeline binary startup: global-key query completed successfully; store ready; device=NVIDIA GeForce RTX 4080; driver=NVIDIA 610.88`. - **Cache enabled** (neither `ANYPS5_NO_SHADER_CACHE` nor `APS5_NO_PIPELINE_BINARIES` set, validation layer loaded), RTX 4080: 103/103 pass: the startup test, the binary-store and pipeline-cache tests, `agc_driver_small_copy_sync`, both `agc_driver_address_passes` tests, the other `agc_driver` tests that do not disable the cache, and the automatically added `agc_driver_pm4_replay` fixture (which disables the shader cache itself). No `VUID-` line. `agc_pipeline_binary_vulkan` saves binary records for two pipelines and restores both in the next process. On `main` `6773f91a7e`, the 85 of these tests that exist there, plus the fixture, pass 86/86. The binary round-trip test uses trivial shaders and an empty layout, so it does not test scratch-pool layouts. ### 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 Merged with `main` `6773f91a7e`, without a force-push. `tools/pr_overlap.py --branch` on 11-09: of the 295 open PRs that share files or exports with this branch, none of those it could compare has conflicting lines; 94 conflict with `main` themselves, so it could not compare them and failed closed (mostly `VulkanDevice.cpp`, `Recorder.cpp`, `CMakeLists.txt`, `ENVIRONMENT.md` and the debt file). A GitHub search found no open PR implementing driver pipeline caches or pipeline binaries. - [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) - [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 No unimplemented exports or silent stubs are added. - [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 No third-party code is added. - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: NVIDIA GeForce RTX 4080, driver 610.88, Windows; NVIDIA GeForce RTX 4090, driver 610.57.04, Linux (startup and store tests, by @oneandonlydean) <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> 🤖 Generated with [Claude Code](https://claude.com/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!15169
No description provided.