Skip to content

Commit 6a1af28

Browse files
committed
[SPIR-V] Fix void on extented inst sets
Inline SPIR-V on normal instructions had a condition to avoid emitting a result type on instruction with a void return type. This is because instructions like `OpStore` have a void return type, but in SPIR-V have no result id. OpExtInst when defining void instruction (like debugBreak()) always have a result id, even with a void result type. This commits fixes the condition to reflect this. Fixes #8012
1 parent 60a1c85 commit 6a1af28

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

tools/clang/lib/SPIRV/SpirvBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ SpirvInstruction *SpirvBuilder::createSpirvIntrInstExt(
13461346
SpirvExtInstImport *set =
13471347
(instSet.size() == 0) ? nullptr : getExtInstSet(instSet);
13481348

1349-
if (retType != QualType() && retType->isVoidType()) {
1349+
if (!set && retType != QualType() && retType->isVoidType()) {
13501350
retType = QualType();
13511351
}
13521352

tools/clang/test/CodeGenSPIRV/inline-spirv/spv.intrinsicInstruction.hlsl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// RUN: %dxc -T vs_6_0 -E main -fspv-target-env=vulkan1.1 -fcgl %s -spirv | FileCheck %s
22

33
// CHECK: OpCapability ShaderClockKHR
4-
// CHECK: {{%[0-9]+}} = OpExtInstImport "GLSL.std.450"
5-
// CHECK: {{%[0-9]+}} = OpExtInstImport "SPV_AMD_shader_trinary_minmax"
4+
5+
// CHECK: OpExtension "SPV_KHR_non_semantic_info"
6+
7+
// CHECK-DAG: [[glsl_set:%[0-9]+]] = OpExtInstImport "GLSL.std.450"
8+
// CHECK-DAG: [[debug_set:%[0-9]+]] = OpExtInstImport "NonSemantic.DebugBreak"
9+
// CHECK-DAG: [[minmax_set:%[0-9]+]] = OpExtInstImport "SPV_AMD_shader_trinary_minmax"
610

711
struct SInstanceData {
812
float4x3 VisualToWorld;
@@ -25,15 +29,22 @@ float4 spv_sin(float4 v);
2529
[[vk::ext_instruction(/* FMin3AMD */ 1, "SPV_AMD_shader_trinary_minmax")]]
2630
float FMin3AMD(float x, float y, float z);
2731

32+
[[vk::ext_extension("SPV_KHR_non_semantic_info")]]
33+
[[vk::ext_instruction(1, "NonSemantic.DebugBreak")]]
34+
void debugBreak();
35+
2836
float4 main(const VS_INPUT v) : SV_Position {
2937
SInstanceData I = v.InstanceData;
3038
uint64_t clock;
31-
// CHECK: {{%[0-9]+}} = OpExtInst %v4float {{%[0-9]+}} Sin {{%[0-9]+}}
39+
// CHECK: {{%[0-9]+}} = OpExtInst %v4float [[glsl_set]] Sin {{%[0-9]+}}
3240
I.Output = spv_sin(v.InstanceData.Output);
3341
// CHECK: {{%[0-9]+}} = OpReadClockKHR %ulong %uint_1
3442
clock = ReadClock(vk::DeviceScope);
35-
// CHECK: {{%[0-9]+}} = OpExtInst %float {{%[0-9]+}} FMin3AMD {{%[0-9]+}} {{%[0-9]+}} {{%[0-9]+}}
43+
// CHECK: {{%[0-9]+}} = OpExtInst %float [[minmax_set]] FMin3AMD {{%[0-9]+}} {{%[0-9]+}} {{%[0-9]+}}
3644
I.Output.w = FMin3AMD(I.Output.z, I.Output.y, I.Output.z);
3745

46+
debugBreak();
47+
// CHECK: {{.*}} = OpExtInst %void [[debug_set]] 1
48+
3849
return I.Output;
3950
}

0 commit comments

Comments
 (0)