feat(recompiler): load prebuilt shader packs before the writable cache #5792
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5792"
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 SaloQT on 2026-10-14T11:13:14Z.
What
Load shader variants from read-only prebuilt storage before the writable disk cache.
ShaderDiskCache::Loadnow checks, in order:.agcscpacks and loose entry files undershader_cache/prebuiltnext to the writable cache, then the writable cache as before. With no prebuilt directory, behaviour and on-disk layout are unchanged.[shader-disk-cache]totals keep measuring only the writable cache; prebuilt activity reports under[shader-prebuilt].Tested
Windows 11:
agc_shader_disk_cacheandshader_cache_file_readpass, including pack validation and corruption cases, loose entries, counter separation, and the cross-process load path. Linux (NVIDIA, RADV, lavapipe) test evidence is in the review thread. No game performance claim: with no pack installed the path is inert.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)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:33:54Z.
Review: CHANGES_REQUESTED
Thanks for the PR. Points to address:
mainincore/shader/recompiler/ShaderDiskCache.cppandShaderDiskCache.hpp; please rebase and re-runshader_cache_file_read.--no-prebuilt-shaders, but nothing in the diff parses that flag (only theANYPS5_NO_PREBUILT_SHADERSenv var). Add it or fix the description.PackHeader/PackRecord, index checksum, sorted-hash lookup, rejection of truncated/invalid records, fall-through to the writable cache) can't be exercised on Linux CI as it stands, and the pack writer is not in this PR. Please add a ctest that builds a pack fromEncodeEntryoutput and checks hit, miss, key mismatch, corrupt index/record and wrong source version (it must fail without the change).EntryKeyandIsCurrentEntryHeaderare declared/defined but unused in this PR; either use them or move them to the PR that needs them.CompileShaderUncachedlikewise has no caller or test here.ReadFileoverlapped,ANYPS5_PREBUILT_MAPPED_READ) is untested; say which CI job covers it or drop it from this PR.docs/dev/ARCHITECTURE.mdshould describe the new prebuilt-pack lookup before the writable cache.Imported from boykopovar/AnyPS5. Originally posted by SaloQT on 2026-10-14T15:44:49Z.
Thanks for the review — all six points are addressed in the force-pushed update:
main. The prebuilt lookup now sits in front of the sharedload()helper (variant loads only; plan loads are untouched), so the resource-plan changes are preserved. It merges cleanly now.--no-prebuilt-shaders— that was my description being wrong, copied from our local fork where host flags exist. Upstream is env-only, so the description now says justANYPS5_NO_PREBUILT_SHADERS; no flag parsing added.agc_shader_disk_cachegrew pack cases built fromEncodeEntryoutput: hit with an identical decoded variant, absent key, an entry stored under another key, a truncated entry (Rejected), a damaged index checksum, an out-of-range record and a wrong compiler source version. A child process (--load-prebuilt, same pattern as--load) covers discovery undershader_cache/prebuilt, theANYPS5_NO_PREBUILT_SHADERS=1opt out and fall-through to the writable cache. The new cases referenceCachePack/PackKeyHash, so they cannot build without this change.CompileShaderUncached,EntryKeyandIsCurrentEntryHeaderare removed from this pull request; they move to the tool follow-up, their only caller. This pull request is now the loader plus its tests.ANYPS5_PREBUILT_MAPPED_READswitch is gone with it. If a future benchmark justifies the positioned-read path it can come back with numbers.ShaderDiskCachebullet in ARCHITECTURE.md now describes the prebuilt lookup: where packs are discovered, that entries are ordinary encoded cache entries behind a sorted key-hash index, how they are validated, and that a miss or rejected entry falls through.Verified locally after the rebase:
agc_shader_disk_cacheandshader_cache_file_readpass (child log:first exact-key hit, then writable fall-through), and the conventions check passes againstmain. The tool pull request (#5793, currently closed by the one-open-PR limit) will be restructured onto this head and reopened once this lands.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-14T16:13:30Z.
On
maine34c47921with this PR (8e619d016),agc_shader_disk_cachepasses on Linux with NVIDIA, RADV and lavapipe. A few things from reading the diff:CachePack::Loadnever setsPackLoadTimings::readNanoseconds, so for packs thefile readfigure in the[shader-prebuilt]line is always 0 ms.A prebuilt hit also adds to the writable cache's
hits(DiskStore::Load), and a rejected loose entry adds to itsloadFailuresand prints[shader-disk-cache] rejected .... The existing[shader-disk-cache]line then no longer counts the writable cache alone, which makes the two lines hard to compare.The loose-folder path (32-character
.binnames,prebuilt/<source version>/) has no test; only packs are covered.ANYPS5_PREBUILT_SHADER_CACHEandANYPS5_NO_PREBUILT_SHADERSare new environment switches. The intake rules ask for none, andshader_cache/prebuiltalready works without them, so dropping both would keep the PR to the default path.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T16:30:56Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/ARCHITECTURE.mdL97docs/dev/ARCHITECTURE.mdL97docs/dev/ARCHITECTURE.mdL97Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:30:47Z.
Review: CHANGES_REQUESTED
Thanks for the update; the six earlier points are addressed (
agc_shader_disk_cachepasses here, and its new cases don't even build without the change). Remaining:ANYPS5_PREBUILT_SHADER_CACHEandANYPS5_NO_PREBUILT_SHADERS, and the reply says the child process covers the opt-out. The code no longer reads either variable and the test never sets one. Update the description to the real behaviour (shader_cache/prebuiltonly).core/shader/recompiler/ShaderCachePack.cpp:107:HashBytes(data)on every pack hit exists only to time "file read", andDecodeEntryalready checksums the payload, so each hit hashes the entry twice. Drop it (andreadNanosecondsfor packs) or measure something that is not extra work.core/shader/recompiler/ShaderDiskCache.cpp:1446and:1489: on a prebuilt missloadPrebuiltadds its duration toloadNanosecondsandload()then adds the whole lookup again, so the "total load" in the interval line double counts misses. Only add it when the prebuilt lookup is what returned.Imported from boykopovar/AnyPS5. Originally posted by SaloQT on 2026-10-14T18:45:36Z.
Thanks for the careful review — all four points are addressed in the new head, squashed into the commit that owns each change:
ANYPS5_PREBUILT_SHADER_CACHEandANYPS5_NO_PREBUILT_SHADERS. Prebuilt storage is onlyshader_cache/prebuiltnext to the writable cache; with no directory there, nothing changes.[shader-disk-cache]line measures only the writable cache. Loose-entry rejections log under[shader-prebuilt].Also addressed in the same push, from the latest re-review: the per-hit pack hash that existed only to time "file read" is gone (decode already checksums, so each hit hashed twice), the pack timings struct no longer carries a read time, prebuilt load time is only counted when the prebuilt lookup is the one that returned (no double count on misses), and the PR description now matches the real behaviour (
shader_cache/prebuiltonly, no environment variables).Build and the
agc_shader_disk_cache/shader_cache_file_readtests pass locally; the Linux evidence from your run still applies since the load path itself did not change.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:52:26Z.
Review: APPROVED
Checked the three remaining points against the new head: the description matches the code (
shader_cache/prebuiltonly), the extra payload hash on pack hits is gone, and prebuilt load time/bytes no longer leak into the writable totals.agc_shader_disk_cachepasses (including the new corrupt-entry and counter-separation cases, which don't build without the change); merging.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-14T19:40:08Z.
Thanks, nice work on the format and the Oodle decoder. Things we noticed, testing against Wolverine and GTA V:
.toc/dag archives; GTA V: RAGE) can produce a pack yet. Worth saying in the description which games or engines it covers.[shader-prebuilt]hits/misses line from a game run with a static pack would show the real value.pipeline-cache.bin, but nothing loads it. Also, pipeline-library compiles done offline may not match the full pipelines built at runtime. Have you measured whether it removes runtime compiles?.agcscpacks, but discovery only picks up*.pack(and loose 32-character.bin) files. And the fingerprint bump invalidates everyone's existing shader cache once, which is worth a line in the description.Imported from boykopovar/AnyPS5. Originally posted by SaloQT on 2026-10-14T19:45:45Z.
Thanks, and thanks for testing against those titles. Point by point:
[shader-prebuilt]line from a real run is the right evidence and I do not have it yet.pipeline-cache.binis written but nothing loads it, and whether offline pipeline compiles match runtime full-pipeline compiles is unmeasured. The description says so and claims no driver-compile saving.*.packfiles and loose 32-character.binentries, and the fingerprint bump does invalidate existing shader caches once — both now stated where users will see them.The tool PR has been rebased onto merged #5792 and reopened as #6032 with these corrections in its description (#5793 could not be reopened after the force-push).