Skip to content

Commit e1693cc

Browse files
committed
add basic empty root signature
1 parent 135e6c9 commit e1693cc

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
@@ -68,6 +68,20 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) {
6868
DXILValMD->addOperand(Val);
6969
}
7070

71+
void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
72+
auto &Ctx = M.getContext();
73+
IRBuilder<> B(M.getContext());
74+
75+
MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
76+
77+
MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
78+
ExampleRootSignature});
79+
80+
StringRef RootSignatureValKey = "dx.rootsignatures";
81+
auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
82+
RootSignatureValMD->addOperand(ExamplePairing);
83+
}
84+
7185
} // namespace
7286

7387
llvm::Type *
@@ -423,6 +437,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
423437
// FIXME: Handle codegen for return type semantics.
424438
// See: https://github.com/llvm/llvm-project/issues/57875
425439
B.CreateRetVoid();
440+
441+
// Add and identify root signature to function, if applicable
442+
const AttrVec &Attrs = FD->getAttrs();
443+
for (const Attr *Attr : Attrs) {
444+
if (isa<RootSignatureAttr>(Attr))
445+
addRootSignature(EntryFn, M);
446+
}
426447
}
427448

428449
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)