Skip to content

fix(shader): share resource plans loaded from the same disk cache payload - #10496

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/share-identical-resource-plans
Oct 24, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/share-identical-resource-plans

Conversation

@milescoviello

Copy link
Copy Markdown
Contributor

What

A shader source whose resource plan comes from the disk cache decodes its own copy of it (getSource → ShaderDiskCache::LoadPlan), including when another source has already decoded the same plan. The same code registered under another plan key (another host subgroup size or interface) stores byte-identical plan entries, so a warm run holds the same decoded plan, its compact form and its compiled SRT tape several times.

  • In Ghost of Tsushima's (PPSA02225) disk cache, written by one run on an RTX 4070 Ti, the 14,043 plan entries hold 8,170 distinct payloads: 291 MiB of payloads, 182 MiB of them distinct. No payload appears more than three times. The payload carries the shader address, so these copies are the same shader's.
  • In a jemalloc heap profile of that title at about 900 s, DecodePlan and buildCompactPlan hold about 720 MiB of live memory. The title is killed by its 20 GB memory cap in its opening.

How

LoadSharedPlan(key, shaderHash) replaces the load in getSource. A loaded payload is looked up in a table of weak references, keyed by two HashBytes of the payload (two seeds), its size and the shader address the plan is given. An equal entry that a source still uses is returned as is. Otherwise the payload is decoded, given the address and published. The table only refers to plans and never keeps one alive; expired slots are dropped every 1,024 inserts. IrResourcePlan is const once loaded (source->plan), and its SRT tape is compiled from its content, so sources sharing a plan share the tape too.

Tested

Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, NVIDIA 615.71.09. The commit was tested as a428c3ab4f on main 379b1dc and is unchanged (git range-diff) on the current head 38ac888dbb, rebased onto main 6c52b64.

  • New verifySharedPlans in agc_shader_disk_cache. It writes one plan's entry under two keys, then checks that loading both for one shader address gives the same plan, equal to a fresh decode of the payload with that address. Another address gets its own plan. Once both references are dropped, the plan is released, and a later load decodes it again.
  • With the table changed to decode every load (test/planshare-mut), it fails 3 of 3: two plan entries with the same payload for one shader decoded into separate plans.
  • The 34 tests matching ^agc_shader_disk_cache|^agc_shader_memory$|^agc_shader_|resource_plan|^agc_driver_graphics$ pass 3 of 3 on main 379b1dc and on a428c3ab4f.
  • Windows 11 VM (GeForce GT 1030, driver 582.66, WinLibs GCC 15.2.0 r7, Release): the 6 tests matching ^agc_shader_disk_cache|^agc_shader_memory$|^request_serializer$ pass 3 of 3 on main at the merge base and on a428c3ab4f.
  • Khronos validation layer (LunarG SDK 1.4.363), VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 on the 5 tests matching ^agc_shader_disk_cache$|^agc_shader_memory$|^agc_driver_graphics$|^agc_driver_pipeline_journal$|^request_serializer$: 5 of 5 on main 379b1dc and on a428c3ab4f. Neither log reports the layer missing, and neither has a VUID.
  • Ghost of Tsushima, warm against warm (each build on its own filled cache version), on the stack the title needs plus fix(shader): release specialized modules that no result uses #10473 and fix(shader): key the device's capabilities and extensions by a digest #10438, 19 GB cap. The run with this change was killed by the cap at 828 s against 715 s without it. It loaded plans from disk 69,982 times against 69,891: plans of undrawn registrations are released and loaded again, so the same payloads come back many times. RssAnon at 2 / 4 / 6 / 8 / 10 / 12 min was 3,756 / 4,497 / 5,720 / 6,929 / 7,067 / 6,821 MB against 3,964 / 4,413 / 5,351 / 6,351 / 6,843 / 7,464 MB. That is within this title's run-to-run spread, which other runs show at over 1 GB in its opening, so this title doesn't resolve the saving. The disk cache duplication above is the direct measure.

Not checked by me: AMD, Intel, macOS.

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
  • 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: none (it lowers the memory Ghost of Tsushima, PPSA02225, needs in a warm run)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 615.71.09, Ubuntu 26.04.1; NVIDIA GeForce GT 1030, driver 582.66, Windows 11 VM
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

…load

A shader source loading its resource plan from the disk cache decoded
its own copy, also when another source had already loaded the same
plan: the same code registered under another plan key (another host
subgroup size or interface) stores byte-identical plan entries. In Ghost
of Tsushima's cache, 14,043 plan entries hold 8,170 distinct payloads.
Loaded plans now go through a table of weak references keyed by two
hashes of the payload, its size and the shader address the plan carries,
so equal payloads for one shader decode once and share the plan, its
compact form and its compiled SRT tape while any source uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4072 core/shader/recompiler/Recompiler.cpp
PR 5021 core/shader/recompiler/Recompiler.cpp
PR 5609 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 5925 core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6280 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 6539 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 6858 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 6924 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 7201 core/shader/recompiler/Recompiler.cpp
PR 7223 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 7410 core/shader/recompiler/Recompiler.cpp
PR 7484 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
PR 7642 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 7689 core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 8004 core/shader/recompiler/Recompiler.cpp
PR 8077 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 9193 core/shader/recompiler/Recompiler.cpp
PR 9356 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 9387 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 9508 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 9889 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 9897 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 9957 core/shader/recompiler/ShaderDiskCache.hpp
PR 9969 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp
PR 10193 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.hpp

@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 24, 2026
@adriadam10 adriadam10 self-assigned this Oct 24, 2026
@adriadam10
adriadam10 merged commit 893f1a0 into boykopovar:main Oct 24, 2026
11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked LoadSharedPlan against DecodePlanEntry (same unwrap and validation, same hit/miss/reject counters), the weak table (no plan kept alive, the decode race resolved under the lock, key is two payload hashes + size + shader address) and verifySharedPlans (pointer equality, other address, release and reload; fails with per-load decode). Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants