Skip to content

Commit 5ccbf46

Browse files
committed
add support for associating DescriptorTables with their clauses
1 parent a931947 commit 5ccbf46

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clang/test/CodeGenHLSL/RootSignature.hlsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
void FirstEntry() {}
77

88
// CHECK-DAG: ![[#CBV:]] = !{!"CBV", i32 1, i32 0, i32 0, i32 -1, i32 4}
9-
// CHECK-DAG: ![[#TABLE:]] = !{!"DescriptorTable"}
9+
// CHECK-DAG: ![[#SRV:]] = !{!"SRV", i32 4, i32 42, i32 3, i32 32, i32 0}
10+
// CHECK-DAG: ![[#TABLE:]] = !{!"DescriptorTable", i32 0, ![[#CBV]], ![[#SRV]]}
1011
// CHECK-DAG: ![[#SECOND_RS:]] = !{![[#TABLE]]}
1112

1213
#define SampleDescriptorTable \
1314
"DescriptorTable( " \
14-
" CBV(b0) " \
15+
" CBV(b0), " \
16+
" SRV(t42, space = 3, offset = 32, numDescriptors = 4, flags = 0) " \
1517
")"
1618
[shader("compute"), RootSignature(SampleDescriptorTable)]
1719
[numthreads(1,1,1)]

llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,16 @@ MDNode *MetadataBuilder::BuildRootSignature() {
196196
}
197197

198198
MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
199-
return MDNode::get(Ctx, {MDString::get(Ctx, "DescriptorTable")});
199+
IRBuilder<> B(Ctx);
200+
SmallVector<Metadata *> TableOperands;
201+
TableOperands.push_back(MDString::get(Ctx, "DescriptorTable"));
202+
TableOperands.push_back(ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Table.Visibility))));
203+
204+
assert(Table.NumClauses <= GeneratedMetadata.size() && "Table expected all owned clauses to be generated already");
205+
TableOperands.append(GeneratedMetadata.end() - Table.NumClauses, GeneratedMetadata.end());
206+
GeneratedMetadata.pop_back_n(Table.NumClauses);
207+
208+
return MDNode::get(Ctx, TableOperands);
200209
}
201210

202211
MDNode *MetadataBuilder::BuildDescriptorTableClause(const DescriptorTableClause &Clause) {

0 commit comments

Comments
 (0)