Skip to content

Commit 6b9fe9e

Browse files
authored
[HLSL] Emit a version in the dx.rootsignatures metadata (llvm#145113)
In llvm#144957 the backend was updated to expect a version in the metadata, but since the frontend wasn't updated this breaks compilation. This is a somewhat temporary fix to that until llvm#144813 lands.
1 parent be7e411 commit 6b9fe9e

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ void addRootSignature(ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
7272

7373
llvm::hlsl::rootsig::MetadataBuilder Builder(Ctx, Elements);
7474
MDNode *RootSignature = Builder.BuildRootSignature();
75-
MDNode *FnPairing =
76-
MDNode::get(Ctx, {ValueAsMetadata::get(Fn), RootSignature});
75+
76+
// TODO: We need to wire the root signature version up through the frontend
77+
// rather than hardcoding it.
78+
ConstantAsMetadata *Version =
79+
ConstantAsMetadata::get(ConstantInt::get(llvm::Type::getInt32Ty(Ctx), 2));
80+
MDNode *MDVals =
81+
MDNode::get(Ctx, {ValueAsMetadata::get(Fn), RootSignature, Version});
7782

7883
StringRef RootSignatureValKey = "dx.rootsignatures";
7984
auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
80-
RootSignatureValMD->addOperand(FnPairing);
85+
RootSignatureValMD->addOperand(MDVals);
8186
}
8287

8388
} // namespace

clang/test/CodeGenHLSL/RootSignature.hlsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// CHECK: !dx.rootsignatures = !{![[#EMPTY_ENTRY:]], ![[#DT_ENTRY:]],
44
// CHECK-SAME: ![[#RF_ENTRY:]], ![[#RC_ENTRY:]], ![[#RD_ENTRY:]], ![[#SS_ENTRY:]]}
55

6-
// CHECK: ![[#EMPTY_ENTRY]] = !{ptr @EmptyEntry, ![[#EMPTY:]]}
6+
// CHECK: ![[#EMPTY_ENTRY]] = !{ptr @EmptyEntry, ![[#EMPTY:]], i32 2}
77
// CHECK: ![[#EMPTY]] = !{}
88

99
[shader("compute"), RootSignature("")]
1010
[numthreads(1,1,1)]
1111
void EmptyEntry() {}
1212

13-
// CHECK: ![[#DT_ENTRY]] = !{ptr @DescriptorTableEntry, ![[#DT_RS:]]}
13+
// CHECK: ![[#DT_ENTRY]] = !{ptr @DescriptorTableEntry, ![[#DT_RS:]], i32 2}
1414
// CHECK: ![[#DT_RS]] = !{![[#TABLE:]]}
1515
// CHECK: ![[#TABLE]] = !{!"DescriptorTable", i32 0, ![[#CBV:]], ![[#SRV:]]}
1616
// CHECK: ![[#CBV]] = !{!"CBV", i32 1, i32 0, i32 0, i32 -1, i32 4}
@@ -25,7 +25,7 @@ void EmptyEntry() {}
2525
[numthreads(1,1,1)]
2626
void DescriptorTableEntry() {}
2727

28-
// CHECK: ![[#RF_ENTRY]] = !{ptr @RootFlagsEntry, ![[#RF_RS:]]}
28+
// CHECK: ![[#RF_ENTRY]] = !{ptr @RootFlagsEntry, ![[#RF_RS:]], i32 2}
2929
// CHECK: ![[#RF_RS]] = !{![[#ROOT_FLAGS:]]}
3030
// CHECK: ![[#ROOT_FLAGS]] = !{!"RootFlags", i32 2114}
3131

@@ -38,7 +38,7 @@ void DescriptorTableEntry() {}
3838
[numthreads(1,1,1)]
3939
void RootFlagsEntry() {}
4040

41-
// CHECK: ![[#RC_ENTRY]] = !{ptr @RootConstantsEntry, ![[#RC_RS:]]}
41+
// CHECK: ![[#RC_ENTRY]] = !{ptr @RootConstantsEntry, ![[#RC_RS:]], i32 2}
4242
// CHECK: ![[#RC_RS]] = !{![[#ROOT_CONSTANTS:]]}
4343
// CHECK: ![[#ROOT_CONSTANTS]] = !{!"RootConstants", i32 5, i32 1, i32 2, i32 1}
4444

@@ -52,7 +52,7 @@ void RootFlagsEntry() {}
5252
[numthreads(1,1,1)]
5353
void RootConstantsEntry() {}
5454

55-
// CHECK: ![[#RD_ENTRY]] = !{ptr @RootDescriptorsEntry, ![[#RD_RS:]]}
55+
// CHECK: ![[#RD_ENTRY]] = !{ptr @RootDescriptorsEntry, ![[#RD_RS:]], i32 2}
5656
// CHECK: ![[#RD_RS]] = !{![[#ROOT_CBV:]], ![[#ROOT_UAV:]], ![[#ROOT_SRV:]]}
5757
// CHECK: ![[#ROOT_CBV]] = !{!"RootCBV", i32 0, i32 0, i32 0, i32 4}
5858
// CHECK: ![[#ROOT_UAV]] = !{!"RootUAV", i32 0, i32 42, i32 3, i32 2}
@@ -66,7 +66,7 @@ void RootConstantsEntry() {}
6666
[numthreads(1,1,1)]
6767
void RootDescriptorsEntry() {}
6868

69-
// CHECK: ![[#SS_ENTRY]] = !{ptr @StaticSamplerEntry, ![[#SS_RS:]]}
69+
// CHECK: ![[#SS_ENTRY]] = !{ptr @StaticSamplerEntry, ![[#SS_RS:]], i32 2}
7070
// CHECK: ![[#SS_RS]] = !{![[#STATIC_SAMPLER:]]}
7171

7272
// checking filter = 0x4

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ analyzeModule(Module &M) {
491491

492492
for (const auto &RSDefNode : RootSignatureNode->operands()) {
493493
if (RSDefNode->getNumOperands() != 3) {
494-
reportError(Ctx, "Invalid format for Root Signature Definition. Pairs "
495-
"of function, root signature expected.");
494+
reportError(Ctx, "Invalid Root Signature metadata - expected function, "
495+
"signature, and version.");
496496
continue;
497497
}
498498

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
target triple = "dxil-unknown-shadermodel6.0-compute"
44

5-
; CHECK: error: Invalid format for Root Signature Definition. Pairs of function, root signature expected.
5+
; CHECK: error: Invalid Root Signature metadata - expected function, signature, and version.
66
; CHECK-NOT: Root Signature Definitions
77

88

0 commit comments

Comments
 (0)