Skip to content

Commit 3f292a1

Browse files
committed
pass down the actual root elements
- test that we have the correct number of elements
1 parent 96a959b commit 3f292a1

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
@@ -119,11 +119,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
119119
return CBGV;
120120
}
121121

122-
void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
122+
void addRootSignature(
123+
ArrayRef<llvm::hlsl::root_signature::RootElement> Elements,
124+
llvm::Function *Fn, llvm::Module &M) {
123125
auto &Ctx = M.getContext();
124-
IRBuilder<> B(M.getContext());
125126

126-
MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
127+
SmallVector<Metadata *> GeneratedMetadata;
128+
for (auto Element : Elements) {
129+
MDNode *ExampleRootElement = MDNode::get(Ctx, {});
130+
GeneratedMetadata.push_back(ExampleRootElement);
131+
}
132+
133+
MDNode *ExampleRootSignature = MDNode::get(Ctx, GeneratedMetadata);
127134

128135
MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
129136
ExampleRootSignature});
@@ -471,8 +478,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
471478
// Add and identify root signature to function, if applicable
472479
const AttrVec &Attrs = FD->getAttrs();
473480
for (const Attr *Attr : Attrs) {
474-
if (isa<HLSLRootSignatureAttr>(Attr))
475-
addRootSignature(EntryFn, M);
481+
if (const auto *RSAttr = dyn_cast<HLSLRootSignatureAttr>(Attr))
482+
addRootSignature(RSAttr->getElements(), EntryFn, M);
476483
}
477484
}
478485

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)