Skip to content

Commit 999ed27

Browse files
committed
Convert shader_relaxed_extended_instruction sample from GLSL to Slang and update copyrights to 2026
1 parent 2a65770 commit 999ed27

File tree

7 files changed

+53
-17
lines changed

7 files changed

+53
-17
lines changed

bldsys/cmake/sample_helper.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[[
2-
Copyright (c) 2019-2025, Arm Limited and Contributors
3-
Copyright (c) 2024-2025, Mobica Limited
4-
Copyright (c) 2024-2025, Sascha Willems
2+
Copyright (c) 2019-2026, Arm Limited and Contributors
3+
Copyright (c) 2024-2026, Mobica Limited
4+
Copyright (c) 2024-2026, Sascha Willems
55
66
SPDX-License-Identifier: Apache-2.0
77
@@ -281,7 +281,7 @@ endif()
281281
set(SLANG_ENTRY_POINT "main")
282282
add_custom_command(
283283
OUTPUT ${OUTPUT_FILE}
284-
COMMAND ${Vulkan_slang_EXECUTABLE} ${SHADER_FILE_SLANG} -profile ${SLANG_PROFILE} -matrix-layout-column-major -target spirv -o ${OUTPUT_FILE} -entry ${SLANG_ENTRY_POINT}
284+
COMMAND ${Vulkan_slang_EXECUTABLE} ${SHADER_FILE_SLANG} -profile ${SLANG_PROFILE} -matrix-layout-column-major -target spirv -o ${OUTPUT_FILE} -entry ${SLANG_ENTRY_POINT} ${TARGET_SLANGC_ADDITIONAL_ARGUMENTS}
285285
COMMAND ${CMAKE_COMMAND} -E copy ${OUTPUT_FILE} ${directory}
286286
MAIN_DEPENDENCY ${SHADER_FILE_SLANG}
287287
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}

samples/extensions/shader_relaxed_extended_instruction/README.adoc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
////
2-
- Copyright (c) 2025, Holochip Inc.
2+
- Copyright (c) 2026, Holochip Inc.
33
-
44
- SPDX-License-Identifier: Apache-2.0
55
-
@@ -80,6 +80,29 @@ void main() {
8080
}
8181
----
8282

83+
== Slang shader variant and OpExtInstWithForwardRef
84+
85+
This sample also includes a Slang shader variant that demonstrates the pattern intended to trigger `OpExtInstWithForwardRef` emission. The Slang shader uses a struct with a method that calls `printf`, which creates the structure that should produce circular dependencies in debug instructions when compiled with rich debug info (e.g., `NonSemantic.Shader.DebugInfo.100`).
86+
87+
[source,slang]
88+
----
89+
struct A {
90+
void foo(uint3 gid) {
91+
printf("relaxed-ext-inst demo: gid = %u", gid.x);
92+
}
93+
};
94+
95+
[shader("compute")]
96+
[numthreads(1, 1, 1)]
97+
void main(uint3 gid : SV_DispatchThreadID)
98+
{
99+
A a;
100+
a.foo(gid);
101+
}
102+
----
103+
104+
NOTE: As of Slang in Vulkan SDK 1.4.328, the compiler does not yet emit the rich debug info needed to trigger `OpExtInstWithForwardRef` emission. The shader is structured correctly and will emit `OpExtInstWithForwardRef` once Slang's debug info support is enhanced. The `OpExtInstWithForwardRef` instruction is specifically designed to handle forward references in extended instruction sets, which can occur when debug info creates circular dependencies (e.g., a class method referencing debug info that references the class).
105+
83106
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.
84107

85108
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.

samples/extensions/shader_relaxed_extended_instruction/shader_relaxed_extended_instruction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2025, Holochip Inc.
1+
/* Copyright (c) 2026, Holochip Inc.
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -220,7 +220,7 @@ bool ShaderRelaxedExtendedInstruction::prepare(const vkb::ApplicationOptions &op
220220
VkPipelineLayoutCreateInfo layout_info{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
221221
VK_CHECK(vkCreatePipelineLayout(get_device().get_handle(), &layout_info, nullptr, &pipeline_layout));
222222

223-
VkPipelineShaderStageCreateInfo stage = load_shader("shader_relaxed_extended_instruction/glsl/relaxed_demo.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT);
223+
VkPipelineShaderStageCreateInfo stage = load_shader("shader_relaxed_extended_instruction/slang/relaxed_demo.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT);
224224

225225
VkComputePipelineCreateInfo compute_ci{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO};
226226
compute_ci.stage = stage;

samples/extensions/shader_relaxed_extended_instruction/shader_relaxed_extended_instruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2025, Holochip Inc.
1+
/* Copyright (c) 2026, Holochip Inc.
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
Binary file not shown.

shaders/shader_relaxed_extended_instruction/glsl/relaxed_demo.comp renamed to shaders/shader_relaxed_extended_instruction/slang/relaxed_demo.comp.slang

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#version 450
2-
/* Copyright (c) 2025, Holochip Inc.
1+
/* Copyright (c) 2026, Holochip Inc.
32
*
43
* SPDX-License-Identifier: Apache-2.0
54
*
@@ -17,18 +16,32 @@
1716
*/
1817

1918
// This shader demonstrates a non-semantic extended instruction via
20-
// GL_EXT_debug_printf. On SPIR-V this lowers to an OpExtInst in the
19+
// printf. On SPIR-V this lowers to an OpExtInst in the
2120
// NonSemantic.DebugPrintf instruction set, which interacts with
2221
// SPV_KHR_non_semantic_info. VK_KHR_shader_relaxed_extended_instruction
2322
// makes certain forward-reference cases in such extended instruction sets
2423
// legal in SPIR-V.
24+
//
25+
// By using a struct with a method that calls printf, we create the pattern
26+
// that should trigger circular dependencies in debug instructions, which
27+
// would emit OpExtInstWithForwardRef instructions when compiled with rich
28+
// debug info (e.g., NonSemantic.Shader.DebugInfo.100).
29+
//
30+
// Note: As of Slang in Vulkan SDK 1.4.328, the compiler does not yet emit
31+
// the rich debug info needed to trigger OpExtInstWithForwardRef. This shader
32+
// is structured correctly and will emit OpExtInstWithForwardRef once Slang's
33+
// debug info support is enhanced.
2534

26-
#extension GL_EXT_debug_printf : enable
35+
struct A {
36+
void foo(uint3 gid) {
37+
printf("relaxed-ext-inst demo: gid = %u", gid.x);
38+
}
39+
};
2740

28-
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
29-
30-
void main()
41+
[shader("compute")]
42+
[numthreads(1, 1, 1)]
43+
void main(uint3 gid : SV_DispatchThreadID)
3144
{
32-
// If validation is configured to route debugPrintfEXT, this will be printed.
33-
debugPrintfEXT("relaxed-ext-inst demo: gid = %u", gl_GlobalInvocationID.x);
45+
A a;
46+
a.foo(gid);
3447
}
Binary file not shown.

0 commit comments

Comments
 (0)