Skip to content

Conversation

@gpx1000
Copy link
Collaborator

@gpx1000 gpx1000 commented Oct 16, 2025

Description

Add a sample that shows how to use VK_KHR_shader_relaxed_extended_instruction and tutorial for it.

Fixes #

General Checklist:

Please ensure the following points are checked:

  • My code follows the coding style
  • I have reviewed file licenses
  • I have commented any added functions (in line with Doxygen)
  • I have commented any code that could be hard to understand
  • My changes do not add any new compiler warnings
  • My changes do not add any new validation layer errors or warnings
  • I have used existing framework/helper functions where possible
  • My changes do not add any regressions
  • I have tested every sample to ensure everything runs correctly
  • This PR describes the scope and expected impact of the changes I am making

Note: The Samples CI runs a number of checks including:

  • I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)
  • My changes build on Windows, Linux, macOS and Android. Otherwise I have documented any exceptions

If this PR contains framework changes:

  • I did a full batch run using the batch command line argument to make sure all samples still work properly

Sample Checklist

If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist:

  • I have tested the sample on at least one compliant Vulkan implementation
  • If the sample is vendor-specific, I have tagged it appropriately
  • I have stated on what implementation the sample has been tested so that others can test on different implementations and platforms
  • Any dependent assets have been merged and published in downstream modules
  • For new samples, I have added a paragraph with a summary to the appropriate chapter in the readme of the folder that the sample belongs to e.g. api samples readme
  • For new samples, I have added a tutorial README.md file to guide users through what they need to know to implement code using this feature. For example, see conditional_rendering
  • For new samples, I have added a link to the Antora navigation so that the sample will be listed at the Vulkan documentation site

@gary-sweet
Copy link
Contributor

I'm not really sure what I'm expecting to see with this sample.

What I'm currently seeing is that I seem to have some seemingly random framebuffers begin displayed, and a bunch of these being printed to the console:

[info] vkQueueSubmit(): pSubmits[0] DebugPrintf:
relaxed-ext-inst demo: gid = 0
[info] vkQueueSubmit(): pSubmits[0] DebugPrintf:
relaxed-ext-inst demo: gid = 0

asuessenbach
asuessenbach previously approved these changes Oct 23, 2025
@Keenuts
Copy link

Keenuts commented Oct 31, 2025

Hello!
I looked at the SPIR-V file in this PR (relaxed_demo.comp.spv) and it seams it has no OpExtInstWithForwardRef instructions.

I don't know if GLSL emits those, but you can have a HLSL shader doing the same thing with the following code:

// RUN: %dxc %s -T cs_6_0 -spirv -fspv-target-env=vulkan1.3 -E main -fspv-debug=vulkan-with-source -O3

class A {
  void foo(uint3 gid) {
    printf("relaxed-ext-inst demo: gid = %u", gid.x);
  }
};

[numthreads(1, 1, 1)]
void main(uint3 gid : SV_DispatchThreadID)
{
  A a;
  a.foo(tid);
}

Here, one OpExtInstWithForwardRefs will be emitted as we have debug info with a class method, which brings a circular dependencies in the debug instructions.

@gpx1000
Copy link
Collaborator Author

gpx1000 commented Jan 1, 2026

Great thanks for the validation of HLSL. I went ahead and switched from GLSL to Slang and validated that it does emit the OpExtInstWithForwardRef instruction. This Sample should now be ready (also merged the latest master and fixed merge conflicts.)

@gary-sweet
Copy link
Contributor

I'm still just seeing three random garbage frames cycling on the display. Will need some investigation.

@asuessenbach
Copy link
Contributor

On my platform VK_EXT_layer_settings is not available.
On startup, I get a couple of warnings:

[warning] 2132353751 - VALIDATION-SETTINGS: vkCreateInstance(): Application is using deprecated "enables" (VK_LAYER_ENABLES) layer settings.
Deprecated settings and new settings cannot be mixed, and deprecated ones take precedence. Consider only using the new settings:
  Deprecated: VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT | New: "printf_enable" (VK_LAYER_PRINTF_ENABLE=1)
  
[warning] 2132353751 - VALIDATION-SETTINGS: vkCreateInstance(): DebugPrintf logs to the Information message severity, enabling Information level logging otherwise the message will not be seen.  

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Forcing fragmentStoresAndAtomics to VK_TRUE

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Forcing vertexPipelineStoresAndAtomics to VK_TRUE

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Forcing shaderInt64 to VK_TRUE

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDeviceTimelineSemaphoreFeatures to pNext with timelineSemaphore set to VK_TRUE

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDeviceVulkanMemoryModelFeatures to pNext with vulkanMemoryModel and vulkanMemoryModelDeviceScope set to VK_TRUE

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDeviceBufferDeviceAddressFeatures to pNext with bufferDeviceAddress set to VK_TRUE

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDeviceScalarBlockLayoutFeatures to pNext with scalarBlockLayout set to VK_TRUE

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDevice8BitStorageFeatures to pNext with storageBuffer8BitAccess set to VK_TRUE

And then an endless list of

[info] vkQueueSubmit(): pSubmits[0] DebugPrintf:
relaxed-ext-inst demo: gid = 0

The actual sample windows stays black.

Is that to be expected?

…/DXC with UI-driven dispatch and message capture

Replaces Slang shader with HLSL variant using DXC that reliably emits OpExtInstWithForwardRef patterns. Adds interactive UI with value slider and manual dispatch button, captures debugPrintf messages via debug utils callback, and eliminates per-frame dispatch to avoid console spam. Updates to Vulkan 1.3 target and pre-records UI render pass commands.
@gpx1000
Copy link
Collaborator Author

gpx1000 commented Jan 8, 2026

I implemented a GUI and allow user to send a number that will be printed out from the shader and routed back to the GUI. I also am displaying in the GUI if the sample is supporting the extension being used. As our framework already enables vkdebugprintf in shaders, you will see the print outs even if you don't have the extension supported. However, in the case that the user were to implement this on a system that supports it, then they can use the relaxed extended instruction to not need to do extra work and see their shader print out.
In this design, there's nothing really interesting to display as I'm demonstrating using this extension to enable debug without enabling it, so I tried to give a GUI.. so it at least looks more interesting than a black screen. If anyone has thoughts for what else I can do; lemme know. But I've intentionally kept this sample simple.

Copy link
Contributor

@gary-sweet gary-sweet left a comment

Choose a reason for hiding this comment

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

I am seeing the debug messages appear in the UI, but only if I build in debug mode, is that expected? In release mode, no messages ever appear.

{
if (drawer.header("VK_KHR_shader_relaxed_extended_instruction"))
{
const bool has_ext = get_instance().is_enabled(VK_KHR_SHADER_RELAXED_EXTENDED_INSTRUCTION_EXTENSION_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

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

get_instance().is_enabled doesn't appear to report device extensions. I see OFF for both extensions when they are both actually supported.

@gpx1000
Copy link
Collaborator Author

gpx1000 commented Jan 9, 2026

The messages in the UI will appear in the case that Validation Layers and debugprintf are enabled, that happens in the framework when we do a debug build. So, artifact of that.
The fact that get_instance().is_enabled isn't working is a surprise. I'll track that down in the morning.

@gary-sweet
Copy link
Contributor

The messages in the UI will appear in the case that Validation Layers and debugprintf are enabled, that happens in the framework when we do a debug build. So, artifact of that. The fact that get_instance().is_enabled isn't working is a surprise. I'll track that down in the morning.

Should we make it obvious somewhere that this only works fully in debug mode? I can just see people (like me) thinking that it just doesn't work.

@gpx1000
Copy link
Collaborator Author

gpx1000 commented Jan 9, 2026

This one, technically is more technical. See, the point of the extension is if you don't enable debugprintf for the shader in your code, you can still use it as it's a relaxed extended instruction. Thus, the real bug is on your system that does support the extension you're getting it behaving like the extension doesn't exist. In Release and Debug with the extension you'll get it behaving properly. Without the extension's help, you'll get it behaving "properly" due to us making that a convenient call.

@gpx1000
Copy link
Collaborator Author

gpx1000 commented Jan 9, 2026

actually found the bug... I'm an idiot. device extension not instance extension.

…tensions

The VK_KHR_shader_relaxed_extended_instruction and VK_KHR_shader_non_semantic_info are device extensions, not instance extensions. Update the check to use `get_device().is_extension_enabled()` instead of `get_instance().is_enabled()`.
Copy link

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

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

Shader in the latest revision LGTM (demonstrated opcodes are present) Thanks!

@SaschaWillems
Copy link
Collaborator

Does compile and run for me (Win 11, RTX 4070), but I do get several warnings.

First these:

[warning] 2132353751 - VALIDATION-SETTINGS: vkCreateInstance(): Application is using deprecated "enables" (VK_LAYER_ENABLES) layer settings.
Deprecated settings and new settings cannot be mixed, and deprecated ones take precedence. Consider only using the new settings:
  Deprecated: VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT | New: "printf_enable" (VK_LAYER_PRINTF_ENABLE=1)

[warning] 2132353751 - VALIDATION-SETTINGS: vkCreateInstance(): DebugPrintf logs to the Information message severity, enabling Information level logging otherwise the message will not be seen.
[info] Found GPU: NVIDIA GeForce RTX 4070

And at a later point these:

[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Forcing fragmentStoresAndAtomics to VK_TRUE
[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Forcing vertexPipelineStoresAndAtomics to VK_TRUE
[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Forcing shaderInt64 to VK_TRUE
[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDeviceTimelineSemaphoreFeatures to pNext with timelineSemaphore set to VK_TRUE
[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDeviceVulkanMemoryModelFeatures to pNext with vulkanMemoryModel and vulkanMemoryModelDeviceScope set to VK_TRUE
[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDeviceBufferDeviceAddressFeatures to pNext with bufferDeviceAddress set to VK_TRUE
[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDeviceScalarBlockLayoutFeatures to pNext with scalarBlockLayout set to VK_TRUE
[warning] -2030147807 - WARNING-Setting-Limit-Adjusted: vkCreateDevice(): Internal Warning: Adding a VkPhysicalDevice8BitStorageFeatures to pNext with storageBuffer8BitAccess set to VK_TRUE

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.

5 participants