Skip to content

Commit a307907

Browse files
committed
update metadata generation to output the retained version
1 parent 9408f86 commit a307907

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,22 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) {
6666
DXILValMD->addOperand(Val);
6767
}
6868

69-
void addRootSignature(ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
69+
void addRootSignature(llvm::dxil::RootSignatureVersion RootSigVer,
70+
ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
7071
llvm::Function *Fn, llvm::Module &M) {
7172
auto &Ctx = M.getContext();
73+
IRBuilder<> Builder(Ctx);
7274

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);
7785

7886
StringRef RootSignatureValKey = "dx.rootsignatures";
7987
auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
@@ -465,9 +473,11 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
465473

466474
// Add and identify root signature to function, if applicable
467475
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,
470479
M);
480+
}
471481
}
472482
}
473483

0 commit comments

Comments
 (0)