Repository navigation
Keep only the used resource bindings in cached shader conversions - #2869
Open
martinellimarco wants to merge 1 commit into
Open
martinellimarco wants to merge 1 commit into
martinellimarco wants to merge 1 commit into
Conversation
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>
There was a problem hiding this comment.
🟢 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
vkCreateGraphicsPipelines() with the shaders already converted, same layout,
median of 50 calls:
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