-
Notifications
You must be signed in to change notification settings - Fork 790
Add sample demonstrating VK_KHR_shader_relaxed_extended_instruction #1420
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
13
commits into
KhronosGroup:main
Choose a base branch
from
gpx1000:VK_KHR_shader_relaxed_extended_instruction
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 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0e4168f
Add sample demonstrating VK_KHR_shader_relaxed_extended_instruction u…
gpx1000 160e617
fix copyright and clang-format
gpx1000 0597b14
- Update README with GitHub repository link for sample
gpx1000 2a65770
Merge branch 'main' into VK_KHR_shader_relaxed_extended_instruction
gpx1000 999ed27
Convert shader_relaxed_extended_instruction sample from GLSL to Slang…
gpx1000 9a0723d
Convert shader_relaxed_extended_instruction sample from GLSL to Slang…
gpx1000 91611c5
Update copyrights to 2026
gpx1000 d38d9b1
Convert shader_relaxed_extended_instruction sample from Slang to HLSL…
gpx1000 959ce72
Fix extension check to query device extensions instead of instance ex…
gpx1000 93dd405
remove frustration comment :)
gpx1000 6d62664
Improve debug printf setup and handle missing validation layer gracef…
gpx1000 aeb0e6d
Fix indentation from spaces to tabs in shader_relaxed_extended_instru…
gpx1000 25ddb92
Merge branch 'main' into VK_KHR_shader_relaxed_extended_instruction
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
31 changes: 31 additions & 0 deletions
31
samples/extensions/shader_relaxed_extended_instruction/CMakeLists.txt
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,31 @@ | ||
| # 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. | ||
| # | ||
|
|
||
| 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 "Shader relaxed extended instruction" | ||
| DESCRIPTION "Demonstrates enabling VK_KHR_shader_relaxed_extended_instruction and requesting its feature" | ||
| SHADER_FILES_HLSL | ||
| "shader_relaxed_extended_instruction/hlsl/relaxed_demo.comp.hlsl" | ||
| DXC_ADDITIONAL_ARGUMENTS "-fspv-target-env=vulkan1.3 -fspv-debug=vulkan-with-source -O3" | ||
| ) |
108 changes: 108 additions & 0 deletions
108
samples/extensions/shader_relaxed_extended_instruction/README.adoc
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,108 @@ | ||
| //// | ||
| - 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/shader_relaxed_extended[Khronos Vulkan samples github repository]. | ||
| endif::[] | ||
|
|
||
| = VK_KHR_shader_relaxed_extended_instruction — Enable SPIR-V relaxed extended instruction for non-semantic sets | ||
|
|
||
| This sample demonstrates the device feature VK_KHR_shader_relaxed_extended_instruction and how it relates to SPV_KHR_relaxed_extended_instruction in SPIR-V. The SPIR-V extension introduces a new instruction that allows certain forward references in extended instruction sets used by non-semantic information (for example, the NonSemantic.DebugPrintf instruction set used by GL_EXT_debug_printf). In Vulkan, those non-semantic instruction sets are allowed via VK_KHR_shader_non_semantic_info. | ||
|
|
||
| == What is it? | ||
| - SPV_KHR_relaxed_extended_instruction adds a SPIR-V mechanism to relax forward‑reference rules for extended instruction sets, specifically for non‑semantic information. | ||
| - VK_KHR_shader_relaxed_extended_instruction is the Vulkan device extension/feature that allows modules using that SPIR‑V extension to be consumed by the driver. | ||
| - This interacts with SPV_KHR_non_semantic_info and VK_KHR_shader_non_semantic_info: the relaxed forward‑reference rule applies to non‑semantic extended instruction sets like `NonSemantic.DebugPrintf`. | ||
|
|
||
| The feature is exposed via `VkPhysicalDeviceShaderRelaxedExtendedInstructionFeaturesKHR` with a single boolean field `shaderRelaxedExtendedInstruction`. | ||
|
|
||
| == Why/when to use it | ||
| - When compiling shaders that embed non‑semantic extended instruction sets (e.g., debug info or debugPrintf) that may use forward references that were previously disallowed. | ||
| - When you want tool and debugging SPIR‑V to be accepted by implementations that support this relaxation, without affecting the program’s semantics (non‑semantic content does not change the observable results). | ||
| - Shaders should continue to function when the feature is off; the relaxation only affects acceptance of certain SPIR‑V forms, not execution semantics. | ||
|
|
||
| == What this sample does | ||
| - Enables device extensions: `VK_KHR_shader_relaxed_extended_instruction` and `VK_KHR_shader_non_semantic_info`. | ||
| - Requests the feature via the framework’s feature‑chaining helper. | ||
| - Builds a tiny compute pipeline whose shader calls `debugPrintfEXT` (a non‑semantic extended instruction) using a class method to demonstrate the relaxed forward‑reference pattern. | ||
| - Renders a visible UI and background and only dispatches the compute shader on demand (or when a UI value changes). This avoids per‑frame logging spam while still demonstrating consumption of a module that contains non‑semantic extended instructions. | ||
|
|
||
| == How to use it | ||
| - The sample shows a small UI panel with: | ||
| * A `Value` slider (integer). Changing it triggers a one‑shot compute dispatch that prints the new value from the shader. | ||
| * A `Dispatch once` button to manually run a one‑shot dispatch. | ||
| * “Last messages” — the last 5 lines captured from `debugPrintf` via `VK_EXT_debug_utils`. | ||
| - The shader prints only from thread `(0,0,0)` and only when you request a dispatch, so there is no per‑frame console spam. | ||
|
|
||
| == Required Vulkan extensions and features | ||
| - Device extensions (required by this sample): | ||
| * `VK_KHR_shader_relaxed_extended_instruction` | ||
| * `VK_KHR_shader_non_semantic_info` | ||
| - Instance extension for feature chaining: `VK_KHR_get_physical_device_properties2` (the framework enables this; the sample requests it explicitly). | ||
| - Device feature (required): `VkPhysicalDeviceShaderRelaxedExtendedInstructionFeaturesKHR::shaderRelaxedExtendedInstruction = VK_TRUE` | ||
|
|
||
| Code excerpt: | ||
| [source,cpp] | ||
| ---- | ||
| ShaderRelaxedExtendedInstruction::ShaderRelaxedExtendedInstruction() | ||
| { | ||
| title = "Shader relaxed extended instruction (VK_KHR_shader_relaxed_extended_instruction)"; | ||
| add_instance_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); | ||
| add_device_extension(VK_KHR_SHADER_RELAXED_EXTENDED_INSTRUCTION_EXTENSION_NAME); | ||
| add_device_extension(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME); | ||
| } | ||
|
|
||
| void ShaderRelaxedExtendedInstruction::request_gpu_features(vkb::core::PhysicalDeviceC &gpu) | ||
| { | ||
| REQUEST_REQUIRED_FEATURE(gpu, | ||
| VkPhysicalDeviceShaderRelaxedExtendedInstructionFeaturesKHR, | ||
| shaderRelaxedExtendedInstruction); | ||
| } | ||
| ---- | ||
|
|
||
| Shader (HLSL, compiled with DXC) used by this sample: | ||
| [source,hlsl] | ||
| ---- | ||
| // RUN: %dxc %s -T cs_6_0 -spirv -fspv-target-env=vulkan1.3 -E main -fspv-debug=vulkan-with-source -O3 | ||
|
|
||
| struct PushConstants { uint value; }; | ||
| [[vk::push_constant]] PushConstants pc; | ||
|
|
||
| class A { | ||
| void foo(uint v) { | ||
| printf("relaxed-ext-inst demo: value = %u", v); | ||
| } | ||
| }; | ||
|
|
||
| [numthreads(1, 1, 1)] | ||
| void main(uint3 gid : SV_DispatchThreadID) | ||
| { | ||
| A a; | ||
| if (all(gid == uint3(0,0,0))) { a.foo(pc.value); } | ||
| } | ||
| ---- | ||
|
|
||
| == Why HLSL (DXC) instead of Slang or GLSL? | ||
|
|
||
| At the time of writing, Slang and glslc in the Vulkan SDK does not emit the necessary debug information patterns that lead to `OpExtInstWithForwardRef` in SPIR-V for this demonstration. The HLSL/DXC path above does emit the required SPIR-V relaxed extended instruction sequence, so this sample uses HLSL for reliability. | ||
|
|
||
| TIP: To actually see the `debugPrintfEXT` output, run with validation configured to capture debug printf (see the `shader_debugprintf` sample or use VK_EXT_layer_settings to enable `VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT`). This sample registers an INFO‑severity `VkDebugUtilsMessengerEXT` so messages are visible when validation is active. | ||
|
|
||
| NOTE: If `VK_EXT_layer_settings` is not available from the validation layer at runtime, the sample automatically falls back to `VK_EXT_validation_features` and enables `VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT` during instance creation. In that case you do not need any environment configuration to see output. | ||
|
|
||
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.