Tackling PSO Explosion in Vulkan: From Pipeline Caches to Shader Objects
Reading time ~7 minutes
A renderer may use only a modest number of shaders and still end up managing thousands of graphics pipelines. Different combinations of shader stages, vertex formats, attachment formats, and fixed-function state can quickly multiply into a large collection of pipeline state objects.
Vulkan provides several ways to manage this cost. Pipeline caches reuse previous compilation work, dynamic state reduces the number of required variants, graphics pipeline libraries share work across pipelines, and shader objects let applications bind shader stages independently.
Each approach addresses a different part of the problem.
Why PSO Counts Grow So Quickly
In this article, a PSO refers to a graphics VkPipeline. For a typical vertex-and-fragment rendering path, it combines shader stages with vertex input, rasterization, depth/stencil, multisampling, and blending state.
A simplified model is:
Graphics pipeline =
shader stages
+ fixed-function state
+ resource interface
+ rendering compatibility information
Suppose a renderer needs 30 vertex shader variants, 40 fragment shader variants, and 25 fixed-function state combinations. If every combination is used, it needs:
30 × 40 × 25 = 30,000 graphics pipelines
This is an illustrative upper bound: real renderers usually use only a subset of all possible combinations. Nevertheless, the multiplicative growth is the central problem.
Creating these pipelines through vkCreateGraphicsPipelines() can involve translating SPIR-V into GPU machine code and optimizing it for the pipeline configuration. If that work happens on the rendering thread when a new combination first appears, it can cause a visible hitch. Compilation cost varies with the shader, driver, hardware, and available caches.
MJP’s The Shader Permutation Problem provides a useful explanation of how rendering features and material systems generate these combinations.
Pipeline Precaching and Pipeline Caches
A common response is to move compilation out of gameplay.
During development and testing, the application records the pipeline configurations it encounters. On the player’s machine, it creates those pipelines during startup or loading screens. This approach, usually called PSO precaching, trades additional loading time for fewer compilation stalls during rendering.
Vulkan’s VkPipelineCache complements this process. It allows the driver to reuse implementation-specific data across pipeline creation calls. Applications can retrieve that data with vkGetPipelineCacheData(), save it to disk, and provide compatible data on a later run.
These mechanisms serve different purposes:
| Mechanism | What it provides |
|---|---|
| PSO precaching | Knowledge of which pipelines to create ahead of time |
VkPipelineCache | Reusable driver data that may make creation cheaper |
A pipeline cache does not restore live VkPipeline handles, and it does not eliminate the need to create the requested pipelines. Its data is also implementation-specific, so a saved cache should not be treated as a universally portable compiled asset. See the Vulkan pipeline cache guide.
Dynamic State: Reducing the Number of Variants
Before making pipeline creation faster, it is worth reducing how many pipelines need to exist.
Extended dynamic state allows more state to be specified while recording commands instead of being fixed at pipeline creation. For example, when cull mode is dynamic, changing from back-face culling to no culling does not require a separate pipeline solely for that difference:
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
vkCmdSetCullMode(cmd, VK_CULL_MODE_BACK_BIT);
vkCmdDraw(cmd, ...);
vkCmdSetCullMode(cmd, VK_CULL_MODE_NONE);
vkCmdDraw(cmd, ...);
The pipeline must declare the relevant state as dynamic, and the required features must be supported and enabled. Extensions such as VK_EXT_extended_dynamic_state, VK_EXT_extended_dynamic_state2, and VK_EXT_extended_dynamic_state3 expand the set of available controls. Vulkan dynamic state guide
Dynamic rendering is a separate feature. VK_KHR_dynamic_rendering removes the need to create traditional render pass and framebuffer objects for that rendering path. It does not, by itself, make rasterization, depth, or blending state dynamic.
Dynamic state reduces combinations caused by fixed-function settings. Shader permutations still need their own solution.
Graphics Pipeline Libraries: Reusing Compilation Work
VK_EXT_graphics_pipeline_library, commonly abbreviated as GPL, divides a graphics pipeline into four reusable subsets:
| Library | Main contents |
|---|---|
| Vertex Input Interface | Vertex input and input assembly |
| Pre-Rasterization Shaders | Pre-rasterization shader stages and associated state |
| Fragment Shader | Fragment shader and associated state |
| Fragment Output Interface | Color blending, output compatibility, and associated multisample state |
This is a conceptual overview; the exact state ownership follows the extension’s rules. GPL libraries contain more than shader bytecode, so their cache keys must capture all relevant state. GPL proposal
The application creates or retrieves the required libraries, then links them into an executable pipeline:
// Simplified application-level flow.
VkPipeline libraries[] = {
getVertexInputLibrary(vertexInputKey),
getPreRasterLibrary(preRasterKey),
getFragmentShaderLibrary(fragmentKey),
getFragmentOutputLibrary(fragmentOutputKey),
};
VkPipeline pipeline = linkLibraries(libraries, enableLTO);
For the earlier example, assume that:
- Vertex input is shared by every pipeline.
- The 30 vertex variants require 30 pre-rasterization libraries.
- The 40 fragment variants require 40 fragment shader libraries.
- All 25 state combinations belong to the fragment output subset.
The application can then reuse:
1 + 30 + 40 + 25 = 96 libraries
It may still need 30,000 executable pipeline combinations, but those pipelines share their constituent libraries.
That distinction explains GPL’s value: it separates reusable compilation work from the final combination step. It does not automatically reduce the number of executable pipelines the application requests.
Fast Linking and Link-Time Optimization
GPL supports a tradeoff between link cost and optimization opportunity.
Setting VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT requests link-time optimization, or LTO. Libraries intended for this path must have been created with VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT.
The device property graphicsPipelineLibraryFastLinking describes the non-LTO path. When it is true, creating a pipeline entirely from libraries without LTO has a cost comparable to recording a command. It does not promise that LTO linking is equally cheap. Fast-linking property
One strategy is to create a non-LTO pipeline when needed, then build an optimized replacement on a background thread. Khronos describes this approach in its GPL integration article.
This also explains why enabling GPL may produce a smaller improvement than expected: repeatedly rebuilding libraries, using overly broad cache keys, or performing LTO for every final combination can preserve much of the original cost.
Shader Objects: Binding Stages Independently
VK_EXT_shader_object changes the application-facing model more directly.
Instead of creating an executable graphics pipeline for each combination, the application creates VkShaderEXT objects and binds the required shader stages. Fixed-function state is supplied through command-buffer commands. Graphics shader objects are used with dynamic rendering. Khronos shader object sample
In the LVK sample, the draw setup becomes:
buf.cmdBindShaderEXT(VK_SHADER_STAGE_VERTEX_BIT, vertex.get());
buf.cmdBindShaderEXT(VK_SHADER_STAGE_FRAGMENT_BIT, fragment.get());
// Application helper that establishes baseline dynamic state.
buf.cmdSetShaderObjectDefaults();
buf.cmdSetVertexInput(vertexInput_);
buf.cmdSetCullMode(lvk::CullMode_Back);
buf.cmdBindDepthState({
.compareOp = lvk::CompareOp_Less,
.isDepthWriteEnabled = true,
});
buf.cmdSetDepthBiasEnable(false);
Here, cmdSetShaderObjectDefaults() is an application helper, not a Vulkan API. It initializes the required baseline state and explicitly unbinds unused shader stages.
The remaining setup—resource binding, push constants, vertex/index buffers, and drawing—still has to be recorded.
This model allows a vertex shader to be reused with multiple compatible fragment shaders without creating a graphics pipeline for every pairing. Shader compilation still exists, and stage interfaces and resource layouts must remain compatible. Shader objects can also be linked at creation time when the application wants a linked group rather than freely interchangeable stages. Shader object specification
Native Support and the Compatibility Layer
Khronos also provides a shader object implementation in Vulkan-ExtensionLayer.
The layer translates shader object operations into pipeline operations, using dynamic state and GPL where available. It can therefore simplify the application’s rendering interface even when the underlying implementation still manages pipelines.
Native support and layer-based support should be measured separately. Using the same API does not mean both paths have identical compilation or runtime costs. The base VK_EXT_shader_object extension also does not replace ray tracing pipelines. Khronos shader object overview
Comparing the Approaches
| Approach | Primary benefit | Work that remains |
|---|---|---|
| PSO precaching | Moves pipeline creation into loading periods | Discovering and creating required combinations |
| Pipeline cache | Reuses previous driver compilation data | Pipeline creation and cache misses |
| Dynamic state | Removes variants caused by selected state changes | Shader permutations and remaining static state |
| GPL | Shares libraries across executable pipelines | Library creation and final linking |
| Shader objects | Removes the application’s need for graphics PSO combinations | Shader creation, interface compatibility, and dynamic state management |
For a useful benchmark, measure library creation and final linking separately, distinguish LTO from non-LTO, and report whether application and driver caches are warm. Passing VK_NULL_HANDLE as the VkPipelineCache only removes the explicit application-provided cache; it does not establish that the driver has no reusable internal data.
The practical target is predictable frame time. A renderer benefits most when expensive compilation happens early, reusable work stays reusable, and encountering a new draw configuration does not block the frame.