@@ -119,6 +119,20 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
119119 return CBGV;
120120}
121121
122+ void addRootSignature (llvm::Function *Fn, llvm::Module &M) {
123+ auto &Ctx = M.getContext ();
124+ IRBuilder<> B (M.getContext ());
125+
126+ MDNode *ExampleRootSignature = MDNode::get (Ctx, {});
127+
128+ MDNode *ExamplePairing = MDNode::get (Ctx, {ValueAsMetadata::get (Fn),
129+ ExampleRootSignature});
130+
131+ StringRef RootSignatureValKey = " dx.rootsignatures" ;
132+ auto *RootSignatureValMD = M.getOrInsertNamedMetadata (RootSignatureValKey);
133+ RootSignatureValMD->addOperand (ExamplePairing);
134+ }
135+
122136} // namespace
123137
124138llvm::Type *CGHLSLRuntime::convertHLSLSpecificType (const Type *T) {
@@ -453,6 +467,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
453467 // FIXME: Handle codegen for return type semantics.
454468 // See: https://github.com/llvm/llvm-project/issues/57875
455469 B.CreateRetVoid ();
470+
471+ // Add and identify root signature to function, if applicable
472+ const AttrVec &Attrs = FD->getAttrs ();
473+ for (const Attr *Attr : Attrs) {
474+ if (isa<HLSLRootSignatureAttr>(Attr))
475+ addRootSignature (EntryFn, M);
476+ }
456477}
457478
458479void CGHLSLRuntime::setHLSLFunctionAttributes (const FunctionDecl *FD,
0 commit comments