fix(shader): key the device's capabilities and extensions by a digest #10438

Merged
milescoviello merged 1 commit from upstream-pr/10438 into main 2026-10-24 06:08:52 +00:00
milescoviello commented 2026-10-24 00:23:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-24T00:23:13Z.


What

RecompileCacheKey puts the whole SpirvTarget into every recompile cache key. Two of its fields are lists: the device's SPIR-V capabilities, and the SPIR-V extension names, which go in one byte per 64-bit word. On a device that enables a dozen extensions, that is about 350 words of the same device description in every key. The key is built and compared on every dispatch and draw, kept in memory by every prepared handle and cache entry, and written into every disk cache entry.

  • In Forspoken's (PPSA03984) disk cache on an RTX 4070 Ti, the 24,774 entries' keys have a median of 833 words. About 350 of them are the 12 extension names (SPV_EXT_demote_to_helper_invocation ... SPV_KHR_terminate_invocation), their lengths and the capability list.
  • In a jemalloc heap profile of Ghost of Tsushima (PPSA02225) at about 900 s, RecompileCacheKey::append holds about 380 MiB of live memory. That title is killed by its 20 GB memory cap in its opening, so this is memory it needs back.

How

append(key, SpirvTarget) now adds the two lists as one 128-bit digest instead of word by word. The digest mixes the capability count and values, then each extension's length and its bytes eight at a time, through two independent 64-bit multiply-xor chains. Every other SpirvTarget field is appended as before. The disk cache source version changes with the recompiler sources, so old entries aren't misread.

Tested

Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, NVIDIA 615.71.09. The commit was tested as 6fbdaa9d69 on main f3456a4152 and is unchanged (git range-diff) on the current head d7d9747e7d, rebased onto main 3b23d18360.

  • New verifyTargetFeatureKey in agc_shader_memory. Equal lists in other storage give the same key. A different last byte of an extension name, a byte moved between two names, or an added capability each give a different key. A key built with 40 extension names is no longer than one built with 2. With only the test on main, agc_shader_memory fails 3 of 3 with target feature key: the key grows with the device's extension names; with the change it passes 3 of 3.
  • The 38 tests matching ^agc_shader_memory$|^agc_spirv_module$|^agc_shader_|shader_disk_cache|^agc_driver_graphics$|pipeline_journal pass 3 of 3 on main 9d4fb4fb70 and on 6fbdaa9d69.
  • 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_memory$|^agc_spirv_module$|^agc_shader_disk_cache$|^agc_driver_graphics$|^agc_driver_pipeline_journal$. main 9d4fb4fb70: 5 of 5 pass; 6fbdaa9d69: 5 of 5 pass. Neither log reports the layer missing, and neither has a VUID.
  • Windows 11 VM (GeForce GT 1030, driver 582.66, WinLibs GCC 15.2.0 r7, Release): the same 5 tests pass 3 of 3 on main at the merge base (f3456a4152) and on 6fbdaa9d69.

Not checked by me: AMD, Intel, macOS, and a title run measuring the saving (Ghost of Tsushima needs more free host memory than this machine has right now).

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 its opening)
  • 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:4990940693 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10438). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-24T00:23:13Z. --- ### What `RecompileCacheKey` puts the whole `SpirvTarget` into every recompile cache key. Two of its fields are lists: the device's SPIR-V capabilities, and the SPIR-V extension names, which go in one byte per 64-bit word. On a device that enables a dozen extensions, that is about 350 words of the same device description in every key. The key is built and compared on every dispatch and draw, kept in memory by every prepared handle and cache entry, and written into every disk cache entry. - In Forspoken's (PPSA03984) disk cache on an RTX 4070 Ti, the 24,774 entries' keys have a median of 833 words. About 350 of them are the 12 extension names (`SPV_EXT_demote_to_helper_invocation` ... `SPV_KHR_terminate_invocation`), their lengths and the capability list. - In a jemalloc heap profile of Ghost of Tsushima (PPSA02225) at about 900 s, `RecompileCacheKey::append` holds about 380 MiB of live memory. That title is killed by its 20 GB memory cap in its opening, so this is memory it needs back. ### How `append(key, SpirvTarget)` now adds the two lists as one 128-bit digest instead of word by word. The digest mixes the capability count and values, then each extension's length and its bytes eight at a time, through two independent 64-bit multiply-xor chains. Every other `SpirvTarget` field is appended as before. The disk cache source version changes with the recompiler sources, so old entries aren't misread. ### Tested Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, NVIDIA 615.71.09. The commit was tested as `6fbdaa9d69` on `main` f3456a4152 and is unchanged (`git range-diff`) on the current head `d7d9747e7d`, rebased onto `main` 3b23d18360. - New `verifyTargetFeatureKey` in `agc_shader_memory`. Equal lists in other storage give the same key. A different last byte of an extension name, a byte moved between two names, or an added capability each give a different key. A key built with 40 extension names is no longer than one built with 2. With only the test on `main`, `agc_shader_memory` fails 3 of 3 with `target feature key: the key grows with the device's extension names`; with the change it passes 3 of 3. - The 38 tests matching `^agc_shader_memory$|^agc_spirv_module$|^agc_shader_|shader_disk_cache|^agc_driver_graphics$|pipeline_journal` pass 3 of 3 on `main` 9d4fb4fb70 and on `6fbdaa9d69`. - 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_memory$|^agc_spirv_module$|^agc_shader_disk_cache$|^agc_driver_graphics$|^agc_driver_pipeline_journal$`. `main` 9d4fb4fb70: 5 of 5 pass; `6fbdaa9d69`: 5 of 5 pass. Neither log reports the layer missing, and neither has a VUID. - Windows 11 VM (GeForce GT 1030, driver 582.66, WinLibs GCC 15.2.0 r7, Release): the same 5 tests pass 3 of 3 on `main` at the merge base (f3456a4152) and on `6fbdaa9d69`. Not checked by me: AMD, Intel, macOS, and a title run measuring the saving (Ghost of Tsushima needs more free host memory than this machine has right now). ### 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 its opening) - [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)
MarcZX10 commented 2026-10-24 21:59:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:59:42Z.

Review: APPROVED


Reviewed exact head d7d9747e7d9aae3375846c52f4814c3b80d2cb39.

The cache key now replaces the variable-length capability/extension payload with two fixed 64-bit digest words while including list counts, capability values, extension lengths, and extension bytes. Other target fields retain their existing key representation. The test checks storage-independent equality, changed extension bytes, byte movement between names, added capabilities, and bounded key size for 40 extensions.

Local current-main merge-tree is clean; conventions and diff-check pass. Hosted eligibility, intake, labels, report, and conventions pass; hosted build/product jobs are skipped. The author reports focused Vulkan/validation-layer and Windows VM runs; I did not reproduce GPU/title measurements locally. No blocking findings on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640191064 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10438#pullrequestreview-5640191064). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T21:59:42Z. **Review:** APPROVED --- Reviewed exact head `d7d9747e7d9aae3375846c52f4814c3b80d2cb39`. The cache key now replaces the variable-length capability/extension payload with two fixed 64-bit digest words while including list counts, capability values, extension lengths, and extension bytes. Other target fields retain their existing key representation. The test checks storage-independent equality, changed extension bytes, byte movement between names, added capabilities, and bounded key size for 40 extensions. Local current-main merge-tree is clean; conventions and diff-check pass. Hosted eligibility, intake, labels, report, and conventions pass; hosted build/product jobs are skipped. The author reports focused Vulkan/validation-layer and Windows VM runs; I did not reproduce GPU/title measurements locally. No blocking findings on this head.
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!10438
No description provided.