1
- // ===- HLSLRootSignature.cpp - HLSL Root Signature helper objects ----------===//
1
+ // ===- HLSLRootSignature.cpp - HLSL Root Signature helper objects
2
+ // ----------===//
2
3
//
3
4
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
5
// See https://llvm.org/LICENSE.txt for license information.
17
18
18
19
namespace llvm {
19
20
namespace hlsl {
20
- namespace root_signature {
21
+ namespace rootsig {
22
+
23
+ // Static helper functions
21
24
22
25
static MDString *ClauseTypeToName (LLVMContext &Ctx, ClauseType Type) {
23
26
StringRef Name;
@@ -47,16 +50,15 @@ template <class... Ts> OverloadBuilds(Ts...) -> OverloadBuilds<Ts...>;
47
50
MDNode *MetadataBuilder::BuildRootSignature () {
48
51
for (const RootElement &Element : Elements) {
49
52
MDNode *ElementMD =
50
- std::visit (
51
- OverloadBuilds{
52
- [&](DescriptorTable Table) -> MDNode * {
53
- return BuildDescriptorTable (Table);
54
- },
55
- [&](DescriptorTableClause Clause) -> MDNode * {
56
- return BuildDescriptorTableClause (Clause);
57
- },
58
- },
59
- Element);
53
+ std::visit (OverloadBuilds{
54
+ [&](DescriptorTable Table) -> MDNode * {
55
+ return BuildDescriptorTable (Table);
56
+ },
57
+ [&](DescriptorTableClause Clause) -> MDNode * {
58
+ return BuildDescriptorTableClause (Clause);
59
+ },
60
+ },
61
+ Element);
60
62
GeneratedMetadata.push_back (ElementMD);
61
63
}
62
64
@@ -66,29 +68,41 @@ MDNode *MetadataBuilder::BuildRootSignature() {
66
68
MDNode *MetadataBuilder::BuildDescriptorTable (const DescriptorTable &Table) {
67
69
IRBuilder<> B (Ctx);
68
70
SmallVector<Metadata *> TableOperands;
71
+ // Set the mandatory arguments
69
72
TableOperands.push_back (MDString::get (Ctx, " DescriptorTable" ));
70
- TableOperands.push_back (ConstantAsMetadata::get (B.getInt32 (llvm::to_underlying (Table.Visibility ))));
73
+ TableOperands.push_back (ConstantAsMetadata::get (
74
+ B.getInt32 (llvm::to_underlying (Table.Visibility ))));
71
75
72
- assert (Table.NumClauses <= GeneratedMetadata.size () && " Table expected all owned clauses to be generated already" );
73
- TableOperands.append (GeneratedMetadata.end () - Table.NumClauses , GeneratedMetadata.end ());
76
+ // Remaining operands are references to the table's clauses. The in-memory
77
+ // representation of the Root Elements created from parsing will ensure that
78
+ // the previous N elements are the clauses for this table.
79
+ assert (Table.NumClauses <= GeneratedMetadata.size () &&
80
+ " Table expected all owned clauses to be generated already" );
81
+ // So, add a refence to each clause to our operands
82
+ TableOperands.append (GeneratedMetadata.end () - Table.NumClauses ,
83
+ GeneratedMetadata.end ());
84
+ // Then, remove those clauses from the general list of Root Elements
74
85
GeneratedMetadata.pop_back_n (Table.NumClauses );
75
86
76
87
return MDNode::get (Ctx, TableOperands);
77
88
}
78
89
79
- MDNode *MetadataBuilder::BuildDescriptorTableClause (const DescriptorTableClause &Clause) {
90
+ MDNode *MetadataBuilder::BuildDescriptorTableClause (
91
+ const DescriptorTableClause &Clause) {
80
92
IRBuilder<> B (Ctx);
81
- return MDNode::get (Ctx, {
82
- ClauseTypeToName (Ctx, Clause.Type ),
83
- ConstantAsMetadata::get (B.getInt32 (Clause.NumDescriptors )),
84
- ConstantAsMetadata::get (B.getInt32 (Clause.Register .Number )),
85
- ConstantAsMetadata::get (B.getInt32 (Clause.Space )),
86
- ConstantAsMetadata::get (B.getInt32 (llvm::to_underlying (Clause.Offset ))),
87
- ConstantAsMetadata::get (B.getInt32 (llvm::to_underlying (Clause.Flags ))),
88
- });
93
+ return MDNode::get (
94
+ Ctx, {
95
+ ClauseTypeToName (Ctx, Clause.Type ),
96
+ ConstantAsMetadata::get (B.getInt32 (Clause.NumDescriptors )),
97
+ ConstantAsMetadata::get (B.getInt32 (Clause.Register .Number )),
98
+ ConstantAsMetadata::get (B.getInt32 (Clause.Space )),
99
+ ConstantAsMetadata::get (
100
+ B.getInt32 (llvm::to_underlying (Clause.Offset ))),
101
+ ConstantAsMetadata::get (
102
+ B.getInt32 (llvm::to_underlying (Clause.Flags ))),
103
+ });
89
104
}
90
105
91
- } // namespace root_signature
106
+ } // namespace rootsig
92
107
} // namespace hlsl
93
108
} // namespace llvm
94
-
0 commit comments