@@ -55,6 +55,14 @@ static std::optional<uint32_t> extractMdIntValue(MDNode *Node,
55
55
return std::nullopt;
56
56
}
57
57
58
+ static std::optional<StringRef> extractMdStringValue (MDNode *Node,
59
+ unsigned int OpId) {
60
+ MDString *NodeText = cast<MDString>(Node->getOperand (OpId));
61
+ if (NodeText == nullptr )
62
+ return std::nullopt;
63
+ return NodeText->getString ();
64
+ }
65
+
58
66
static bool parseRootFlags (LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
59
67
MDNode *RootFlagNode) {
60
68
@@ -105,6 +113,56 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
105
113
return false ;
106
114
}
107
115
116
+ static bool parseRootDescriptors (LLVMContext *Ctx,
117
+ mcdxbc::RootSignatureDesc &RSD,
118
+ MDNode *RootDescriptorNode) {
119
+
120
+ if (RootDescriptorNode->getNumOperands () != 5 )
121
+ return reportError (Ctx, " Invalid format for RootConstants Element" );
122
+
123
+ std::optional<StringRef> ElementText =
124
+ extractMdStringValue (RootDescriptorNode, 0 );
125
+ assert (!ElementText->empty ());
126
+
127
+ dxbc::RootParameterHeader Header;
128
+ Header.ParameterType =
129
+ StringSwitch<uint32_t >(*ElementText)
130
+ .Case (" RootCBV" , llvm::to_underlying (dxbc::RootParameterType::CBV))
131
+ .Case (" RootSRV" , llvm::to_underlying (dxbc::RootParameterType::SRV))
132
+ .Case (" RootUAV" , llvm::to_underlying (dxbc::RootParameterType::UAV));
133
+
134
+ if (std::optional<uint32_t > Val = extractMdIntValue (RootDescriptorNode, 1 ))
135
+ Header.ShaderVisibility = *Val;
136
+ else
137
+ return reportError (Ctx, " Invalid value for ShaderVisibility" );
138
+
139
+ dxbc::RTS0::v1::RootDescriptor Descriptor;
140
+ if (std::optional<uint32_t > Val = extractMdIntValue (RootDescriptorNode, 2 ))
141
+ Descriptor.ShaderRegister = *Val;
142
+ else
143
+ return reportError (Ctx, " Invalid value for ShaderRegister" );
144
+
145
+ if (std::optional<uint32_t > Val = extractMdIntValue (RootDescriptorNode, 3 ))
146
+ Descriptor.RegisterSpace = *Val;
147
+ else
148
+ return reportError (Ctx, " Invalid value for RegisterSpace" );
149
+
150
+ if (RSD.Version == 1 ) {
151
+ RSD.ParametersContainer .addParameter (Header, Descriptor);
152
+ return false ;
153
+ }
154
+ assert (RSD.Version > 1 );
155
+ dxbc::RTS0::v2::RootDescriptor DescriptorV2 (Descriptor);
156
+
157
+ if (std::optional<uint32_t > Val = extractMdIntValue (RootDescriptorNode, 4 ))
158
+ DescriptorV2.Flags = *Val;
159
+ else
160
+ return reportError (Ctx, " Invalid value for Root Descriptor Flags" );
161
+
162
+ RSD.ParametersContainer .addParameter (Header, DescriptorV2);
163
+ return false ;
164
+ }
165
+
108
166
static bool parseRootSignatureElement (LLVMContext *Ctx,
109
167
mcdxbc::RootSignatureDesc &RSD,
110
168
MDNode *Element) {
@@ -116,6 +174,9 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
116
174
StringSwitch<RootSignatureElementKind>(ElementText->getString ())
117
175
.Case (" RootFlags" , RootSignatureElementKind::RootFlags)
118
176
.Case (" RootConstants" , RootSignatureElementKind::RootConstants)
177
+ .Case (" RootCBV" , RootSignatureElementKind::RootDescriptors)
178
+ .Case (" RootSRV" , RootSignatureElementKind::RootDescriptors)
179
+ .Case (" RootUAV" , RootSignatureElementKind::RootDescriptors)
119
180
.Default (RootSignatureElementKind::Error);
120
181
121
182
switch (ElementKind) {
@@ -124,7 +185,8 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
124
185
return parseRootFlags (Ctx, RSD, Element);
125
186
case RootSignatureElementKind::RootConstants:
126
187
return parseRootConstants (Ctx, RSD, Element);
127
- break ;
188
+ case RootSignatureElementKind::RootDescriptors:
189
+ return parseRootDescriptors (Ctx, RSD, Element);
128
190
case RootSignatureElementKind::Error:
129
191
return reportError (Ctx, " Invalid Root Signature Element: " +
130
192
ElementText->getString ());
0 commit comments