Skip to content

Commit 76e3b5e

Browse files
committed
pass down the actual root elements
- test that we have the correct number of elements
1 parent e1693cc commit 76e3b5e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,18 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) {
6868
DXILValMD->addOperand(Val);
6969
}
7070

71-
void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
71+
void addRootSignature(
72+
ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
73+
llvm::Function *Fn, llvm::Module &M) {
7274
auto &Ctx = M.getContext();
73-
IRBuilder<> B(M.getContext());
7475

75-
MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
76+
SmallVector<Metadata *> GeneratedMetadata;
77+
for (auto Element : Elements) {
78+
MDNode *ExampleRootElement = MDNode::get(Ctx, {});
79+
GeneratedMetadata.push_back(ExampleRootElement);
80+
}
81+
82+
MDNode *ExampleRootSignature = MDNode::get(Ctx, GeneratedMetadata);
7683

7784
MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
7885
ExampleRootSignature});
@@ -441,8 +448,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
441448
// Add and identify root signature to function, if applicable
442449
const AttrVec &Attrs = FD->getAttrs();
443450
for (const Attr *Attr : Attrs) {
444-
if (isa<RootSignatureAttr>(Attr))
445-
addRootSignature(EntryFn, M);
451+
if (const auto *RSAttr = dyn_cast<RootSignatureAttr>(Attr))
452+
addRootSignature(RSAttr->getSignatureDecl()->getRootElements(), EntryFn, M);
446453
}
447454
}
448455

clang/test/CodeGenHLSL/RootSignature.hlsl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | FileCheck %s
22

3-
// CHECK: !dx.rootsignatures = !{![[#FIRST_ENTRY:]], ![[#SECOND_ENTRY:]]}
4-
// CHECK-DAG: ![[#FIRST_ENTRY]] = !{ptr @FirstEntry, ![[#RS:]]}
5-
// CHECK-DAG: ![[#SECOND_ENTRY]] = !{ptr @SecondEntry, ![[#RS:]]}
6-
// CHECK-DAG: ![[#RS]] = !{}
3+
// CHECK-DAG: ![[#EMPTY:]] = !{}
4+
// CHECK-DAG: ![[#SECOND_RS:]] = !{![[#EMPTY]]}
5+
// CHECK-DAG: ![[#SECOND_ENTRY:]] = !{ptr @SecondEntry, ![[#SECOND_RS]]}
6+
// CHECK-DAG: ![[#FIRST_ENTRY:]] = !{ptr @FirstEntry, ![[#EMPTY]]}
7+
// CHECK-DAG: !dx.rootsignatures = !{![[#FIRST_ENTRY]], ![[#SECOND_ENTRY]]}
78

89
[shader("compute"), RootSignature("")]
910
[numthreads(1,1,1)]

0 commit comments

Comments
 (0)