@@ -40,19 +40,21 @@ static bool reportError(LLVMContext *Ctx, Twine Message,
40
40
return true ;
41
41
}
42
42
43
- static bool reportValueError (LLVMContext *Ctx, Twine ParamName,
44
- uint32_t Value ) {
43
+ static bool reportValueError (LLVMContext *Ctx, Twine ParamName, uint32_t Value,
44
+ DiagnosticSeverity Severity = DS_Error ) {
45
45
Ctx->diagnose (DiagnosticInfoGeneric (
46
- " Invalid value for " + ParamName + " : " + Twine (Value), DS_Error ));
46
+ " Invalid value for " + ParamName + " : " + Twine (Value), Severity ));
47
47
return true ;
48
48
}
49
49
50
- static std::optional<uint32_t > extractMdIntValue (MDNode *Node,
51
- unsigned int OpId) {
52
- if (auto *CI =
53
- mdconst::dyn_extract<ConstantInt>(Node->getOperand (OpId).get ()))
54
- return CI->getZExtValue ();
55
- return std::nullopt;
50
+ static bool extractMdIntValue (uint32_t &Value, MDNode *Node,
51
+ unsigned int OpId) {
52
+ auto *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand (OpId).get ());
53
+ if (CI == nullptr )
54
+ return true ;
55
+
56
+ Value = CI->getZExtValue ();
57
+ return false ;
56
58
}
57
59
58
60
static bool parseRootFlags (LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
@@ -61,9 +63,7 @@ static bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
61
63
if (RootFlagNode->getNumOperands () != 2 )
62
64
return reportError (Ctx, " Invalid format for RootFlag Element" );
63
65
64
- if (std::optional<uint32_t > Val = extractMdIntValue (RootFlagNode, 1 ))
65
- RSD.Flags = *Val;
66
- else
66
+ if (extractMdIntValue (RSD.Flags , RootFlagNode, 1 ))
67
67
return reportError (Ctx, " Invalid value for RootFlag" );
68
68
69
69
return false ;
@@ -79,24 +79,22 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
79
79
NewParameter.Header .ParameterType =
80
80
llvm::to_underlying (dxbc::RootParameterType::Constants32Bit);
81
81
82
- if (std::optional<uint32_t > Val = extractMdIntValue (RootConstantNode, 1 ))
83
- NewParameter.Header .ShaderVisibility = *Val;
84
- else
82
+ uint32_t SV;
83
+ if (extractMdIntValue (SV, RootConstantNode, 1 ))
85
84
return reportError (Ctx, " Invalid value for ShaderVisibility" );
86
85
87
- if (std::optional<uint32_t > Val = extractMdIntValue (RootConstantNode, 2 ))
88
- NewParameter.Constants .ShaderRegister = *Val;
89
- else
86
+ NewParameter.Header .ShaderVisibility = SV;
87
+
88
+ if (extractMdIntValue (NewParameter.Constants .ShaderRegister , RootConstantNode,
89
+ 2 ))
90
90
return reportError (Ctx, " Invalid value for ShaderRegister" );
91
91
92
- if (std::optional<uint32_t > Val = extractMdIntValue (RootConstantNode, 3 ))
93
- NewParameter.Constants .RegisterSpace = *Val;
94
- else
92
+ if (extractMdIntValue (NewParameter.Constants .RegisterSpace , RootConstantNode,
93
+ 3 ))
95
94
return reportError (Ctx, " Invalid value for RegisterSpace" );
96
95
97
- if (std::optional<uint32_t > Val = extractMdIntValue (RootConstantNode, 4 ))
98
- NewParameter.Constants .Num32BitValues = *Val;
99
- else
96
+ if (extractMdIntValue (NewParameter.Constants .Num32BitValues , RootConstantNode,
97
+ 4 ))
100
98
return reportError (Ctx, " Invalid value for Num32BitValues" );
101
99
102
100
RSD.Parameters .push_back (NewParameter);
@@ -150,6 +148,32 @@ static bool parse(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
150
148
151
149
static bool verifyRootFlag (uint32_t Flags) { return (Flags & ~0xfff ) == 0 ; }
152
150
151
+ static bool verifyShaderVisibility (uint32_t Flags) {
152
+ switch (Flags) {
153
+
154
+ case llvm::to_underlying (dxbc::ShaderVisibility::All):
155
+ case llvm::to_underlying (dxbc::ShaderVisibility::Vertex):
156
+ case llvm::to_underlying (dxbc::ShaderVisibility::Hull):
157
+ case llvm::to_underlying (dxbc::ShaderVisibility::Domain):
158
+ case llvm::to_underlying (dxbc::ShaderVisibility::Geometry):
159
+ case llvm::to_underlying (dxbc::ShaderVisibility::Pixel):
160
+ case llvm::to_underlying (dxbc::ShaderVisibility::Amplification):
161
+ case llvm::to_underlying (dxbc::ShaderVisibility::Mesh):
162
+ return true ;
163
+ }
164
+
165
+ return false ;
166
+ }
167
+
168
+ static bool verifyParameterType (uint32_t Type) {
169
+ switch (Type) {
170
+ case llvm::to_underlying (dxbc::RootParameterType::Constants32Bit):
171
+ return true ;
172
+ }
173
+
174
+ return false ;
175
+ }
176
+
153
177
static bool verifyVersion (uint32_t Version) {
154
178
return (Version == 1 || Version == 2 );
155
179
}
@@ -164,12 +188,12 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
164
188
return reportValueError (Ctx, " RootFlags" , RSD.Flags );
165
189
}
166
190
167
- for (const mcdxbc::RootParameter &P : RSD.Parameters ) {
168
- if (!dxbc::isValidShaderVisibility (P.Header .ShaderVisibility ))
191
+ for (const auto &P : RSD.Parameters ) {
192
+ if (!verifyShaderVisibility (P.Header .ShaderVisibility ))
169
193
return reportValueError (Ctx, " ShaderVisibility" ,
170
- P.Header .ShaderVisibility );
194
+ ( uint32_t ) P.Header .ShaderVisibility );
171
195
172
- assert (dxbc::isValidParameterType (P.Header .ParameterType ) &&
196
+ assert (verifyParameterType (P.Header .ParameterType ) &&
173
197
" Invalid value for ParameterType" );
174
198
}
175
199
@@ -241,10 +265,6 @@ analyzeModule(Module &M) {
241
265
}
242
266
243
267
mcdxbc::RootSignatureDesc RSD;
244
- // Clang emits the root signature data in dxcontainer following a specific
245
- // sequence. First the header, then the root parameters. So the header
246
- // offset will always equal to the header size.
247
- RSD.RootParameterOffset = sizeof (dxbc::RootSignatureHeader);
248
268
249
269
if (parse (Ctx, RSD, RootElementListNode) || validate (Ctx, RSD)) {
250
270
return RSDMap;
@@ -271,6 +291,7 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
271
291
SmallDenseMap<const Function *, mcdxbc::RootSignatureDesc> &RSDMap =
272
292
AM.getResult <RootSignatureAnalysis>(M);
273
293
294
+ const size_t RSHSize = sizeof (dxbc::RootSignatureHeader);
274
295
OS << " Root Signature Definitions"
275
296
<< " \n " ;
276
297
uint8_t Space = 0 ;
@@ -285,30 +306,32 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
285
306
Space++;
286
307
OS << indent (Space) << " Flags: " << format_hex (RS.Flags , 8 ) << " \n " ;
287
308
OS << indent (Space) << " Version: " << RS.Version << " \n " ;
288
- OS << indent (Space) << " RootParametersOffset: " << RS.RootParameterOffset
289
- << " \n " ;
290
309
OS << indent (Space) << " NumParameters: " << RS.Parameters .size () << " \n " ;
310
+ OS << indent (Space) << " RootParametersOffset: " << RSHSize << " \n " ;
311
+ OS << indent (Space) << " NumStaticSamplers: " << 0 << " \n " ;
312
+ OS << indent (Space)
313
+ << " StaticSamplersOffset: " << RSHSize + RS.Parameters .size_in_bytes ()
314
+ << " \n " ;
315
+
291
316
Space++;
292
317
for (auto const &P : RS.Parameters ) {
293
- OS << indent (Space) << " - Parameter Type: " << P.Header .ParameterType
318
+ OS << indent (Space)
319
+ << " Parameter Type: " << (uint32_t )P.Header .ParameterType << " \n " ;
320
+ OS << indent (Space)
321
+ << " Shader Visibility: " << (uint32_t )P.Header .ShaderVisibility
294
322
<< " \n " ;
295
- OS << indent (Space + 2 )
296
- << " Shader Visibility: " << P.Header .ShaderVisibility << " \n " ;
297
323
switch (P.Header .ParameterType ) {
298
324
case llvm::to_underlying (dxbc::RootParameterType::Constants32Bit):
299
- OS << indent (Space + 2 )
300
- << " Register Space: " << P. Constants . RegisterSpace << " \n " ;
301
- OS << indent (Space + 2 )
302
- << " Shader Register: " << P. Constants . ShaderRegister << " \n " ;
303
- OS << indent (Space + 2 )
325
+ OS << indent (Space) << " Register Space: " << P. Constants . RegisterSpace
326
+ << " \n " ;
327
+ OS << indent (Space) << " Shader Register: " << P. Constants . ShaderRegister
328
+ << " \n " ;
329
+ OS << indent (Space)
304
330
<< " Num 32 Bit Values: " << P.Constants .Num32BitValues << " \n " ;
305
331
break ;
306
332
}
307
333
}
308
334
Space--;
309
- OS << indent (Space) << " NumStaticSamplers: " << 0 << " \n " ;
310
- OS << indent (Space) << " StaticSamplersOffset: " << RS.StaticSamplersOffset
311
- << " \n " ;
312
335
313
336
Space--;
314
337
// end root signature header
0 commit comments