Skip to content

Commit 96a959b

Browse files
committed
add basic empty root signature
1 parent 14e7253 commit 96a959b

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

124138
llvm::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

458479
void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | FileCheck %s
2+
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]] = !{}
7+
8+
[shader("compute"), RootSignature("")]
9+
[numthreads(1,1,1)]
10+
void FirstEntry() {}
11+
12+
[shader("compute"), RootSignature("DescriptorTable()")]
13+
[numthreads(1,1,1)]
14+
void SecondEntry() {}
15+
16+
// Sanity test to ensure to root is added for this function
17+
[shader("compute")]
18+
[numthreads(1,1,1)]
19+
void ThirdEntry() {}

0 commit comments

Comments
 (0)