aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGHLSLRuntime.cpp
diff options
context:
space:
mode:
authorFinn Plummer <canadienfinn@gmail.com>2025-05-15 14:54:00 -0700
committerGitHub <noreply@github.com>2025-05-15 14:54:00 -0700
commita4eb0db062b646907a2c19d54f8240fe4bdd98ce (patch)
tree4e87794da0f1db654cd68a00cd68e12c72cf4e21 /clang/lib/CodeGen/CGHLSLRuntime.cpp
parent2e6433b8293ac64923c737078e87dc39fc4bced6 (diff)
downloadllvm-a4eb0db062b646907a2c19d54f8240fe4bdd98ce.zip
llvm-a4eb0db062b646907a2c19d54f8240fe4bdd98ce.tar.gz
llvm-a4eb0db062b646907a2c19d54f8240fe4bdd98ce.tar.bz2
[HLSL][RootSignature] Add metadata generation for descriptor tables (#139633)
- prereq: Modify `RootSignatureAttr` to hold a reference to the owned declaration - Define and implement `MetadataBuilder` in `HLSLRootSignature` - Integrate and invoke the builder in `CGHLSLRuntime.cpp` to generate the Root Signature for any associated entry functions - Add tests to demonstrate functionality in `RootSignature.hlsl` Resolves https://github.com/llvm/llvm-project/issues/126584 Note: this is essentially just https://github.com/llvm/llvm-project/pull/125131 rebased onto the new approach of constructing a root signature decl, instead of holding the elements in `AdditionalMembers`.
Diffstat (limited to 'clang/lib/CodeGen/CGHLSLRuntime.cpp')
-rw-r--r--clang/lib/CodeGen/CGHLSLRuntime.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 0eb4bb0..5bc71a9 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -68,6 +68,20 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) {
DXILValMD->addOperand(Val);
}
+void addRootSignature(ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
+ llvm::Function *Fn, llvm::Module &M) {
+ auto &Ctx = M.getContext();
+
+ llvm::hlsl::rootsig::MetadataBuilder Builder(Ctx, Elements);
+ MDNode *RootSignature = Builder.BuildRootSignature();
+ MDNode *FnPairing =
+ MDNode::get(Ctx, {ValueAsMetadata::get(Fn), RootSignature});
+
+ StringRef RootSignatureValKey = "dx.rootsignatures";
+ auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
+ RootSignatureValMD->addOperand(FnPairing);
+}
+
} // namespace
llvm::Type *
@@ -423,6 +437,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
// FIXME: Handle codegen for return type semantics.
// See: https://github.com/llvm/llvm-project/issues/57875
B.CreateRetVoid();
+
+ // Add and identify root signature to function, if applicable
+ for (const Attr *Attr : FD->getAttrs()) {
+ if (const auto *RSAttr = dyn_cast<RootSignatureAttr>(Attr))
+ addRootSignature(RSAttr->getSignatureDecl()->getRootElements(), EntryFn,
+ M);
+ }
}
void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,