Skip to content

Keep only the used resource bindings in cached shader conversions - #2869

Open
martinellimarco wants to merge 1 commit into
KhronosGroup:mainfrom
martinellimarco:prune-cached-shader-config
Open

martinellimarco wants to merge 1 commit into
KhronosGroup:mainfrom
martinellimarco:prune-cached-shader-config

Conversation

@martinellimarco

Copy link
Copy Markdown

MVKShaderLibraryCache keeps a copy of the conversion configuration of every
converted shader. That copy holds one resource binding per pipeline layout
binding and per shader stage, and nearly all of them belong to other stages
or are not used by the shader. The cache reads it only through matches() and
alignWith(), and both ignore those bindings: matches() skips them, and
alignWith() clears every usage flag before copying the matching ones.

Keep only the bindings used by the converted stage. Lookups give the same
results, the cache needs much less memory, pipeline cache data shrinks by the
same amount, and alignWith() gets faster because it scans a short list.

200 graphics pipelines with distinct shaders and one descriptor set of N
sampled images visible to the vertex and fragment stages, median of 5 runs
on an Apple M3 Max:

          process footprint     vkGetPipelineCacheData()
            per pipeline           per pipeline
     N     before    after         before    after
    16      63 KB    40 KB        22.1 KB   1.2 KB
    64     107 KB    41 KB        84.9 KB   1.2 KB
   256     393 KB    49 KB       336.2 KB   1.2 KB

vkCreateGraphicsPipelines() with the shaders already converted, same layout,
median of 50 calls:

     N     before    after
    16      40 us    33 us
    32      69 us    32 us
    64     167 us    35 us
   128     489 us    41 us
   256    3071 us    53 us

Benchmarks: https://gist.github.com/martinellimarco/22b85ea628e1ded7182783a0e18548e7
Tested on a MacBook Pro with Apple M3 Max (16-core CPU, 40-core GPU, 48 GB), macOS 15.6.1, and reviewed manually by the author.
The Vulkan CTS 1.4.7.0 (vk-default) was run with this change, with no regressions measured.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

MVKShaderLibraryCache keeps a copy of the conversion configuration of every
converted shader. That copy holds one resource binding per pipeline layout
binding and per shader stage, and nearly all of them belong to other stages
or are not used by the shader. The cache reads it only through matches() and
alignWith(), and both ignore those bindings: matches() skips them, and
alignWith() clears every usage flag before copying the matching ones.

Keep only the bindings used by the converted stage. Lookups give the same
results, the cache needs much less memory, pipeline cache data shrinks by the
same amount, and alignWith() gets faster because it scans a short list.

200 graphics pipelines with distinct shaders and one descriptor set of N
sampled images visible to the vertex and fragment stages, median of 5 runs
on an Apple M3 Max:

          process footprint     vkGetPipelineCacheData()
            per pipeline           per pipeline
     N     before    after         before    after
    16      63 KB    40 KB        22.1 KB   1.2 KB
    64     107 KB    41 KB        84.9 KB   1.2 KB
   256     393 KB    49 KB       336.2 KB   1.2 KB

vkCreateGraphicsPipelines() with the shaders already converted, same layout,
median of 50 calls:

     N     before    after
    16      40 us    33 us
    32      69 us    32 us
    64     167 us    35 us
   128     489 us    41 us
   256    3071 us    53 us

Benchmarks: https://gist.github.com/martinellimarco/22b85ea628e1ded7182783a0e18548e7
Tested on a MacBook Pro with Apple M3 Max (16-core CPU, 40-core GPU, 48 GB), macOS 15.6.1, and reviewed manually by the author.
The Vulkan CTS 1.4.7.0 (vk-default) was run with this change, with no regressions measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 11, 2026 14:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused optimization preserves matching and alignment behavior while reducing cache memory and serialized data size.

0 open findings

What changed in this PR

Reduces shader-conversion cache size by retaining only resource bindings used by the converted shader stage.

Changes:

  • Filters cached conversion configurations to used, stage-specific bindings.
  • Documents the resulting cache memory reduction.
File Description
MoltenVK/​MoltenVK/​GPUObjects/​MVKShaderModule.mm Filters bindings before caching shader configurations.
Docs/​Whats_New.md Adds the cache-memory optimization to release notes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants