-
Notifications
You must be signed in to change notification settings - Fork 792
Add VK_KHR_pipeline_binary sample #1418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gpx1000
wants to merge
21
commits into
KhronosGroup:main
Choose a base branch
from
gpx1000:VK_KHR_pipeline_binaries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d59eb7a
Add VK_KHR_pipeline_binary sample and related resources
gpx1000 11f4384
update the clang format and copyright.
gpx1000 35286a4
update nav.adoc
gpx1000 1f92e28
- Enhance README with Antora site-gen support and improved references.
gpx1000 ff0952d
Adjust code formatting in pipeline_binary.cpp for improved readability
gpx1000 fe2db8b
Merge branch 'main' into VK_KHR_pipeline_binaries
gpx1000 8d0497b
Update pipeline binary sample with interactive demo and performance m…
gpx1000 b60c1a7
Refactor logging to use std::format and eliminate snprintf
gpx1000 e9d53b7
Add missing std::format include to pipeline_binary sample
gpx1000 9612175
Remove duplicate logging statement in pipeline_binary sample
gpx1000 19fa02c
Revert updating volk.
gpx1000 ed10cd5
Add `-extra-arg=-std=c++20` to clang-tidy and fix include order
gpx1000 d7a4654
Fix clang-tidy by installing GCC 13 toolchain and configuring gcc-too…
gpx1000 8aae311
Remove clang-tidy container and use system-installed run-clang-tidy
gpx1000 96c4369
Disable X11 in GLFW build for clang-tidy check
gpx1000 145428d
Install XCB headers for CMake configure and re-enable X11 in GLFW build
gpx1000 92767a5
Disable X11 in GLFW build for clang-tidy check
gpx1000 0cb3404
Replace std::format with fmt::format in pipeline_binary sample
gpx1000 992ba12
clang format fix.
gpx1000 e85706f
Replace std::format with fmt::format in pipeline_binary sample
gpx1000 376f98d
Merge branch 'main' into VK_KHR_pipeline_binaries
gpx1000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright (c) 2025-2026, Holochip Inc | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 the "License"; | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) | ||
| get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH) | ||
| get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME) | ||
|
|
||
| add_sample_with_tags( | ||
| ID ${FOLDER_NAME} | ||
| CATEGORY ${CATEGORY_NAME} | ||
| AUTHOR "Holochip" | ||
| NAME "Pipeline binary" | ||
| DESCRIPTION "Demonstrates VK_KHR_pipeline_binary: querying keys and capturing pipeline binaries." | ||
| SHADER_FILES_GLSL | ||
| "pipeline_binary/glsl/binary_demo.comp") |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| //// | ||
| - Copyright (c) 2026, Holochip Inc. | ||
| - | ||
| - SPDX-License-Identifier: Apache-2.0 | ||
| - | ||
| - Licensed under the Apache License, Version 2.0 the "License"; | ||
| - you may not use this file except in compliance with the License. | ||
| - You may obtain a copy of the License at | ||
| - | ||
| - http://www.apache.org/licenses/LICENSE-2.0 | ||
| - | ||
| - Unless required by applicable law or agreed to in writing, software | ||
| - distributed under the License is distributed on an "AS IS" BASIS, | ||
| - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| - See the License for the specific language governing permissions and | ||
| - limitations under the License. | ||
| - | ||
| //// | ||
| ifdef::site-gen-antora[] | ||
| TIP: The source for this sample can be found in the https://github.com/KhronosGroup/Vulkan-Samples/tree/main/samples/extensions/pipeline_binary[Khronos Vulkan samples github repository]. | ||
| endif::[] | ||
|
|
||
| = Pipeline binary (VK_KHR_pipeline_binary) | ||
| :description: Interactive demonstration of pipeline binary capture, persistence, and performance benefits. | ||
|
|
||
| == Overview | ||
| VK_KHR_pipeline_binary lets you explicitly capture and reuse driver-produced pipeline binaries. Instead of relying only on opaque pipeline caches, you can: | ||
|
|
||
| - Compute a portable pipeline key up front for a given set of creation parameters. | ||
| - Ask the driver to give you an implementation-specific binary for that key. | ||
| - Persist that binary and reuse it on the same driver/device to avoid runtime compilation hitches. | ||
|
|
||
| This sample provides an interactive demonstration of the complete pipeline binary workflow. It creates a compute pipeline, captures its binary, and allows you to: | ||
|
|
||
| - Recreate pipelines from scratch or from cached binaries with performance timing | ||
| - Save binaries to disk and load them back | ||
| - Compare creation times to see the performance benefits | ||
| - Observe the speedup gained from using pre-compiled binaries | ||
|
|
||
| == Why and when to use it | ||
| Pipeline caches are useful, but they are intentionally opaque and not keyed by a structure you can compute deterministically. Pipeline binaries add: | ||
|
|
||
| - Deterministic cache management (you can compute the key before creating a pipeline). | ||
| - Cross-process or install-time pre-warming strategies. | ||
| - A clear, explicit handle (VkPipelineBinaryKHR) you can store and manage. | ||
|
|
||
| They complement other techniques: | ||
|
|
||
| - VK_EXT_graphics_pipeline_library reduces link-time work, but doesn’t hand you the final binary for persistence. | ||
| - VK_EXT_shader_object changes the binding model, not binary persistence. | ||
|
|
||
| == How it works (TL;DR) | ||
gpx1000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| . Prepare the same creation info you’d pass to vkCreate*Pipelines (compute or graphics). | ||
| . Wrap it in VkPipelineCreateInfoKHR. | ||
| . vkGetPipelineKeyKHR(device, &VkPipelineCreateInfoKHR, &VkPipelineBinaryKeyKHR) → portable key. | ||
| . vkCreatePipelineBinariesKHR(device, &VkPipelineBinaryCreateInfoKHR, …) → VkPipelineBinaryKHR handle. | ||
| . vkGetPipelineBinaryDataKHR(device, &VkPipelineBinaryDataInfoKHR, …) → query size, then fetch bytes. | ||
| . Store bytes together with device/vendor/driver identifiers and the key. | ||
|
|
||
| == Required Vulkan extensions and features | ||
| To use feature chaining like the other samples, this sample enables the following and requests the needed feature explicitly: | ||
|
|
||
| - Instance: `VK_KHR_get_physical_device_properties2` — required by the framework to chain extension feature structs during device creation. | ||
| - Device: `VK_KHR_pipeline_binary` — the extension demonstrated here. | ||
| - Device: `VK_KHR_maintenance5` — defines the `VkPipelineCreateFlags2` flag space that includes CAPTURE_DATA (not required for this sample’s path, but commonly expected by validation). | ||
| - Device: `VK_KHR_dynamic_rendering`, `VK_KHR_depth_stencil_resolve`, `VK_KHR_create_renderpass2` — commonly used by the framework/WSI paths; enabled to avoid spurious present-time validation issues. | ||
|
|
||
| Note: This sample uses the `pPipelineCreateInfo` path when creating pipeline binaries, so it does not require creating a live pipeline with `CAPTURE_DATA` set. | ||
|
|
||
| == Interactive UI Features | ||
| The sample provides an interactive GUI with three main sections: | ||
|
|
||
| === Pipeline Binary Info | ||
| Displays initial information about pipeline binary support, properties, and the captured binary details including key size and binary signature. | ||
|
|
||
| === Interactive Demo | ||
| Provides buttons to interact with the pipeline binary system: | ||
|
|
||
| - **Recreate Pipeline (from scratch)**: Destroys and recreates the pipeline using normal creation, measuring the time taken. | ||
| - **Recreate Pipeline (from binary)**: Recreates the pipeline using the cached binary data, demonstrating faster creation. | ||
| - **Save Binary to File**: Persists the binary and its key to disk (`pipeline_binary.bin`). | ||
| - **Load Binary from File**: Loads a previously saved binary from disk, enabling cross-session reuse. | ||
|
|
||
| === Performance Statistics | ||
| Shows timing measurements and performance comparisons: | ||
|
|
||
| - Creation time from scratch (in milliseconds) | ||
| - Creation time from binary (in milliseconds) | ||
| - Speedup factor (how much faster binary creation is) | ||
| - Total recreation counts for each method | ||
| - Binary size and key size information | ||
|
|
||
| == Walkthrough of the code | ||
| - log_pipeline_binary_support() uses vkGetPhysicalDeviceFeatures2/properties2 to show what the driver supports and prefers regarding internal caches and compression. | ||
| - demo_pipeline_key_and_binary(): | ||
| * Reuses the cached compute pipeline creation info and wraps it in VkPipelineCreateInfoKHR. | ||
| * Calls vkGetPipelineKeyKHR to compute the key. | ||
| * Calls vkCreatePipelineBinariesKHR with pPipelineCreateInfo set (and pipeline/pKeysAndDataInfo null) to get a VkPipelineBinaryKHR. | ||
| * Calls vkGetPipelineBinaryDataKHR twice to first query size, then fetch bytes (requires a valid VkPipelineBinaryKeyKHR pointer on both calls). | ||
| * Stores the binary data and key in member variables for later reuse. | ||
| - recreate_pipeline_from_scratch(): Destroys and recreates the pipeline normally, measuring creation time with high-resolution timing. | ||
| - recreate_pipeline_from_binary(): Creates a pipeline from the cached binary data using VkPipelineBinaryKeysAndDataKHR, demonstrating the reuse path and measuring performance. | ||
| - save_binary_to_file() / load_binary_from_file(): Demonstrate persistence by writing/reading the key and binary data to/from disk. | ||
| - on_update_ui_overlay(): Provides the interactive GUI with buttons and real-time statistics display. | ||
|
|
||
| == Best practices and caveats | ||
| - Treat captured binaries as opaque and device/driver-specific; don’t assume portability across vendors or driver revisions. | ||
| - Record identity metadata (vendor ID, device ID, driver version, pipeline key) so you can invalidate stale entries. | ||
| - Some drivers may prefer or enforce internal caches; honor properties like pipelineBinaryPrefersInternalCache. | ||
| - Not all implementations will return data; some may return zero bytes. Handle that gracefully. | ||
| - Any change in creation parameters changes the key and the resulting binary. | ||
|
|
||
| == References | ||
gpx1000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - VK_KHR_pipeline_binary specification: xref:https://docs.vulkan.org/spec/latest/chapters/pipelines.html#pipelines-binaries[pipeline binaries] | ||
| - Related samples: xref:../graphics_pipeline_library/README.adoc[graphics_pipeline_library], xref:../pipeline_cache/README.adoc[pipeline_cache] | ||
| - Khronos Blog: xref:https://www.khronos.org/blog/bringing-explicit-pipeline-caching-control-to-vulkan[Bringing explicit pipeline caching control] <- this blog includes graphs and explanation which could help with understanding how this works. | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.