Skip to content

Commit 22b71b0

Browse files
kpyzhovKonstantin
andauthored
Corrected setting IRBuilder debug location in HLSignatureLower::GenerateDxilComputeAndNodeCommonInputs() (#8022)
As a result of #7799, the HLSL entry function can now contain `dbg.value` calls with !dbg location metadata with scopes corresponding to functions which have been inlined. The `HLSignatureLower::GenerateDxilComputeAndNodeCommonInputs()` creates `@dx.op.threadId` intrinsic calls, using the default dbg loc when creating an `IRBuilder`. When the first instruction in the entry block is one of the `dbg,value` calls, its dbg location is copied to the `@dx.op.threadId` calls. That makes the DXIL unreadable by the modern LLVM IR reader since it fails the IR module verification because of !dbg pointing to a different subprogram scope. This change sets the dbg location for IRBuilder to be the !dbg node of the first non-PHI and non-debug instruction in the block. --------- Co-authored-by: Konstantin <konstantin.pyzhov@amd.com>
1 parent bdaeae0 commit 22b71b0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/HLSL/HLSignatureLower.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,8 @@ void HLSignatureLower::GenerateDxilComputeAndNodeCommonInputs() {
12531253
DXASSERT(funcAnnotation, "must find annotation for entry function");
12541254
auto &funcProps = HLM.GetDxilFunctionProps(Entry);
12551255
IRBuilder<> Builder(Entry->getEntryBlock().getFirstInsertionPt());
1256+
Builder.SetCurrentDebugLocation(
1257+
Entry->getEntryBlock().getFirstNonPHIOrDbg()->getDebugLoc());
12561258

12571259
for (Argument &arg : Entry->args()) {
12581260
DxilParameterAnnotation &paramAnnotation =
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %dxc -T cs_6_5 -E CSMain -O0 -Zi -enable-16bit-types %s | FileCheck %s
2+
3+
// CHECK-LABEL: @CSMain()
4+
// CHECK: %{{[0-9]+}} = call i32 @dx.op.threadId.i32(i32 {{[0-9]+}}, i32 {{[0-9]+}}), !dbg [[DBG_MD:![0-9]+]]
5+
// CHECK-DAG: [[SUBPGM:![0-9]+]] = !DISubprogram(name: "CSMain"
6+
// CHECK-DAG: [[DBG_MD]] = !DILocation(line: 21, column: 15, scope: [[SUBPGM]])
7+
8+
RWBuffer<float> u0 : register(u0);
9+
RWBuffer<float> u1 : register(u1);
10+
11+
static float my_var;
12+
static float my_var2;
13+
14+
void foo() {
15+
my_var2 = my_var * 2;
16+
}
17+
18+
[RootSignature("DescriptorTable(UAV(u0,numDescriptors=2))")]
19+
[numthreads(64,1,1)]
20+
void CSMain(uint3 dtid : SV_DispatchThreadID) {
21+
my_var = u0[dtid.x];
22+
foo();
23+
u1[dtid.x] = my_var2;
24+
}

0 commit comments

Comments
 (0)