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

Merged
milescoviello merged 1 commit from upstream-pr/10496 into main 2026-10-24 09:54:08 +00:00
milescoviello commented 2026-10-24 04:24:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-24T04:24:34Z.


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 379b1dca32 and is unchanged (git range-diff) on the current head 38ac888dbb, rebased onto main 6c52b649e7.

  • 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 379b1dca32 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 379b1dca32 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 #10473 and #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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4992445958 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10496). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-24T04:24:34Z. --- ### 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` 379b1dca32 and is unchanged (`git range-diff`) on the current head `38ac888dbb`, rebased onto `main` 6c52b649e7. - 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` 379b1dca32 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` 379b1dca32 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 #10473 and #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 - [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) - [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: none (it lowers the memory Ghost of Tsushima, PPSA02225, needs in a warm run) - [x] 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 - [x] AI-assisted: yes (Claude Code) 🤖 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!10496
No description provided.