perf(shader): keep specialized SPIR-V in the shader disk cache #26800
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26800"
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 GabbeHags on 2026-11-24T22:11:00Z.
What
Every run specialized each first-used shader again on the queue worker.
specializeModulememoizes the specialized SPIR-V only in-process, keyed on the per-run variant id, so the shader disk cache and the pipeline journal both hit and the draw or dispatch still waited forspecializeWords. In Mafia: Definitive Edition's city load that is ~560 shaders at ~4.8 ms each, all on queue worker 0, and the queue falls far enough behind that the title's 1 s CPU poll of a GPU label times out.Specialized modules are now ordinary shader disk cache entries (
ShaderDiskCache::LoadSpecialized/StoreSpecialized):wrapEntryheader, which stores the full key, so another key never loads it, and truncated or corrupt files are rejected and counted as load failures.SpirvTargetfields, written field by field. The subdirectory is already per source version.APS5_NO_SPECIALIZED_CACHE=1turns it off.[shader-disk-cache]counts the entries asspecialized modules.agc_shader_disk_cache_testsgainsverifySpecializedStore(round trip, another key, counters, truncated and corrupt entries).docs/user/USAGE.mdanddocs/dev/ENVIRONMENT.mddocument the cache and the switch.tools/pr_overlap.pycould not rule out #25010: it edits other functions inRecompiler.cppandShaderDiskCache.*(indirect-dispatch group folding), not this cache.Tested
Windows 11 (10.0.26200), NVIDIA GeForce RTX 2070 SUPER, driver 617.14, 3840x2160. Mafia: Definitive Edition (PPSA36458, 01.002.000), city load from a save,
APS5_TRACE_SECONDS=35:20and no other trace or profile switch; one cold run first so both builds read warm caches.mainisf6005b11cd, this PR4e9f3ab7ed.mainThe two windows start at slightly different points of the load (present 1739 and 1836), so the p90/p99 differ more than the stall does; the stall frame is inside both. Traces: I will attach
aps5-trace-f6005b11cdbd-8472.json.gzandaps5-trace-4e9f3ab7ed65-6300.json.gz.A warm run counts 567
specialized moduleshits. During development a verify mode recomputed every hit and compared: 0 differences over 573 specializations.Focused tests on
mainand this PR withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer(validation layer 1.4.363):agc_driver_bitfield_mask_testsandagc_driver_cache_control_testspass on both, each log showsInsert instance layer "VK_LAYER_KHRONOS_validation", nowas not foundline, 0VUID-on both.ANYPS5_NO_SHADER_CACHE=1keeps this cache off in those runs, so they show nothing else changed;agc_shader_disk_cache_tests(no Vulkan) covers the cache and passes on both.tools/check_conventions.pypasses.aps5-summary.jsonl lines
main:
this PR:
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-11-25T02:37:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation and tests support merging.
What I ran
Reviewed head
ac8c6e567865e0ddd61f6f878b3ba2a17576085e. No commands or tests were run in this review; the author-reported test results were not independently verified.Read the PR description, commit list, diff, manifest, and all seven changed files listed as reviewed in the manifest:
core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp,core/shader/recompiler/CacheKey.hpp,core/shader/recompiler/Recompiler.cpp,core/shader/recompiler/ShaderDiskCache.cpp,core/shader/recompiler/ShaderDiskCache.hpp,docs/dev/ENVIRONMENT.md, anddocs/user/USAGE.md. No changed files were excluded.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Builds, automated tests, and the reported console performance measurements were not run or independently verified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T19:04:29Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: include every specialization input that can change the cached SPIR-V in its key.
What I ran
Reviewed head
6ed8d29aafa86a182fcae394f246abf8d7a9d253. I used the prepared diff andrepo_read.pyto inspect all seven changed files and targeted specialization and cache code. No commands, builds, or tests were run.Results
Findings
Blocking
core/shader/recompiler/Recompiler.cpp:1140—specializedCacheKeykeys the artifact’s SPIR-V and selected metadata, but omitsartifact.stencilReferences.specializeWordsbranches on whether that vector is empty and uses it to alter specialization handling and push-constant offsets (Recompiler.cpp, lines 1038–1062 and 1079–1082). Therefore artifacts with otherwise matching keyed inputs but different stencil-reference metadata can reuse SPIR-V specialized for the other metadata. Add the stencil-reference state (and any other output-affecting artifact fields) to this key.Non-blocking
None.
Not verified
No build or tests were run. The PR description’s reported test and performance results were not independently verified. All changed files in the manifest were included and inspected; no excluded changed files were listed by the review-folder listing.
To get this to a good state
Add the omitted specialization metadata to the key, then rerun the focused cache tests and validate the changed behavior on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T19:32:52Z.
Review: APPROVED
Reviewed — looks good
The cache key covers the specialization inputs inspected, and the new disk entry path validates its wrapped payload before loading it; no verified blocking defect was found in the reviewed code.
What I ran
Reviewed head
e7cb192d144ee12dc86edea6a974a4f13eb2833f. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior, builds, and tests were not independently verified. The PR description's performance measurements and reported test results were not reproduced.
To get this to a good state
Nothing is required.
Sources
Read all changed files listed in
manifest.json:core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp,core/shader/recompiler/CacheKey.hpp,core/shader/recompiler/Recompiler.cpp,core/shader/recompiler/ShaderDiskCache.cpp,core/shader/recompiler/ShaderDiskCache.hpp,docs/dev/ENVIRONMENT.md, anddocs/user/USAGE.md. No changed files were excluded by the manifest.