Skip to content

Commit c8b18bc

Browse files
[SPIRV] Fix pcf with rich debug info enabled (#7663)
Compilation crashes when generating the patch constant function when rich debug info is enabled. This PR corrects the issue, which was reported in #7311
1 parent 34f8fb0 commit c8b18bc

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,8 +1591,15 @@ void SpirvEmitter::doFunctionDecl(const FunctionDecl *decl) {
15911591
if (spirvOptions.debugInfoRich) {
15921592
if (srcDebugFunction) {
15931593
spvContext.pushDebugLexicalScope(info, srcDebugFunction);
1594-
} else {
1594+
} else if (debugFunction) {
15951595
spvContext.pushDebugLexicalScope(info, debugFunction);
1596+
} else {
1597+
// A function which is not called directly in HLSL, and therefore does not
1598+
// reside in the workQueue
1599+
if (decl->hasBody()) {
1600+
debugFunction = emitDebugFunction(decl, func, &info, funcName);
1601+
spvContext.pushDebugLexicalScope(info, debugFunction);
1602+
}
15961603
}
15971604
}
15981605

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %dxc -T hs_6_0 -E HS -fspv-debug=vulkan-with-source -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK: [[set:%[0-9]+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4+
// CHECK: [[hsConstantName:%[0-9]+]] = OpString "hsConstant"
5+
// CHECK: [[dbgFunction:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[hsConstantName]]
6+
// CHECK: [[lexicalBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} %uint_23 %uint_1 [[dbgFunction]]
7+
// CHECK: %hsConstant = OpFunction %HS_OUTPUT None {{%[0-9]+}}
8+
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugFunctionDefinition [[dbgFunction]] %hsConstant
9+
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[lexicalBlock]]
10+
11+
struct HS_OUTPUT
12+
{
13+
float edges[4] : SV_TessFactor;
14+
float inside[2]: SV_InsideTessFactor;
15+
};
16+
17+
struct VS_OUTPUT
18+
{
19+
float4 pos : POSITION;
20+
};
21+
22+
HS_OUTPUT hsConstant( InputPatch<VS_OUTPUT, 4> ip, uint pid : SV_PrimitiveID )
23+
{
24+
return (HS_OUTPUT)0;
25+
}
26+
27+
[domain("quad")]
28+
[partitioning("integer")]
29+
[outputcontrolpoints(4)]
30+
[outputtopology("triangle_cw")]
31+
[patchconstantfunc("hsConstant")]
32+
VS_OUTPUT HS( InputPatch<VS_OUTPUT, 4> ip, uint cpid : SV_OutputControlPointID)
33+
{
34+
return (VS_OUTPUT)0;
35+
}

0 commit comments

Comments
 (0)