Skip to content

Commit 016f380

Browse files
committed
add support for associating DescriptorTables with their clauses
1 parent afbf120 commit 016f380

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
@@ -64,7 +64,16 @@ MDNode *MetadataBuilder::BuildRootSignature() {
6464
}
6565

6666
MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
67-
return MDNode::get(Ctx, {MDString::get(Ctx, "DescriptorTable")});
67+
IRBuilder<> B(Ctx);
68+
SmallVector<Metadata *> TableOperands;
69+
TableOperands.push_back(MDString::get(Ctx, "DescriptorTable"));
70+
TableOperands.push_back(ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Table.Visibility))));
71+
72+
assert(Table.NumClauses <= GeneratedMetadata.size() && "Table expected all owned clauses to be generated already");
73+
TableOperands.append(GeneratedMetadata.end() - Table.NumClauses, GeneratedMetadata.end());
74+
GeneratedMetadata.pop_back_n(Table.NumClauses);
75+
76+
return MDNode::get(Ctx, TableOperands);
6877
}
6978

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

0 commit comments

Comments
 (0)