@@ -66,14 +66,22 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) {
66
66
DXILValMD->addOperand (Val);
67
67
}
68
68
69
- void addRootSignature (ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
69
+ void addRootSignature (llvm::dxil::RootSignatureVersion RootSigVer,
70
+ ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
70
71
llvm::Function *Fn, llvm::Module &M) {
71
72
auto &Ctx = M.getContext ();
73
+ IRBuilder<> Builder (Ctx);
72
74
73
- llvm::hlsl::rootsig::MetadataBuilder Builder (Ctx, Elements);
74
- MDNode *RootSignature = Builder.BuildRootSignature ();
75
- MDNode *FnPairing =
76
- MDNode::get (Ctx, {ValueAsMetadata::get (Fn), RootSignature});
75
+ llvm::hlsl::rootsig::MetadataBuilder RSBuilder (Ctx, Elements);
76
+ MDNode *RootSignature = RSBuilder.BuildRootSignature ();
77
+
78
+ Metadata *Operands[] = {
79
+ ValueAsMetadata::get (Fn),
80
+ RootSignature,
81
+ ConstantAsMetadata::get (
82
+ Builder.getInt32 (llvm::to_underlying (RootSigVer))),
83
+ };
84
+ MDNode *FnPairing = MDNode::get (Ctx, Operands);
77
85
78
86
StringRef RootSignatureValKey = " dx.rootsignatures" ;
79
87
auto *RootSignatureValMD = M.getOrInsertNamedMetadata (RootSignatureValKey);
@@ -465,9 +473,11 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
465
473
466
474
// Add and identify root signature to function, if applicable
467
475
for (const Attr *Attr : FD->getAttrs ()) {
468
- if (const auto *RSAttr = dyn_cast<RootSignatureAttr>(Attr))
469
- addRootSignature (RSAttr->getSignatureDecl ()->getRootElements (), EntryFn,
476
+ if (const auto *RSAttr = dyn_cast<RootSignatureAttr>(Attr)) {
477
+ auto *RSDecl = RSAttr->getSignatureDecl ();
478
+ addRootSignature (RSDecl->getVersion (), RSDecl->getRootElements (), EntryFn,
470
479
M);
480
+ }
471
481
}
472
482
}
473
483
0 commit comments