10
10
#include " DXILRootSignature.h"
11
11
#include " DXILShaderFlags.h"
12
12
#include " DirectX.h"
13
+ #include " llvm/ADT/ArrayRef.h"
13
14
#include " llvm/ADT/STLForwardCompat.h"
14
15
#include " llvm/ADT/SmallString.h"
15
16
#include " llvm/ADT/SmallVector.h"
@@ -248,6 +249,44 @@ initRSBindingValidation(const mcdxbc::RootSignatureDesc &RSD,
248
249
return Validation;
249
250
}
250
251
252
+ static SmallVector<ResourceInfo::ResourceBinding>
253
+ getRootDescriptorsBindingInfo (const mcdxbc::RootSignatureDesc &RSD,
254
+ dxbc::ShaderVisibility Visibility) {
255
+
256
+ SmallVector<ResourceInfo::ResourceBinding> RDs;
257
+
258
+ for (size_t I = 0 ; I < RSD.ParametersContainer .size (); I++) {
259
+ const auto &[Type, Loc] =
260
+ RSD.ParametersContainer .getTypeAndLocForParameter (I);
261
+
262
+ const auto &Header = RSD.ParametersContainer .getHeader (I);
263
+ if (Header.ShaderVisibility !=
264
+ llvm::to_underlying (dxbc::ShaderVisibility::All) &&
265
+ Header.ShaderVisibility != llvm::to_underlying (Visibility))
266
+ continue ;
267
+
268
+ switch (Type) {
269
+
270
+ case llvm::to_underlying (dxbc::RootParameterType::SRV):
271
+ case llvm::to_underlying (dxbc::RootParameterType::UAV):
272
+ case llvm::to_underlying (dxbc::RootParameterType::CBV): {
273
+ dxbc::RTS0::v2::RootDescriptor Desc =
274
+ RSD.ParametersContainer .getRootDescriptor (Loc);
275
+
276
+ ResourceInfo::ResourceBinding Binding;
277
+ Binding.LowerBound = Desc.ShaderRegister ;
278
+ Binding.Space = Desc.RegisterSpace ;
279
+ Binding.Size = 1 ;
280
+
281
+ RDs.push_back (Binding);
282
+ break ;
283
+ }
284
+ }
285
+ }
286
+
287
+ return RDs;
288
+ }
289
+
251
290
std::optional<mcdxbc::RootSignatureDesc>
252
291
getRootSignature (RootSignatureBindingInfo &RSBI,
253
292
dxil::ModuleMetadataInfo &MMI) {
@@ -261,10 +300,22 @@ getRootSignature(RootSignatureBindingInfo &RSBI,
261
300
}
262
301
263
302
static void reportInvalidHandleTy (
264
- Module &M,
303
+ Module &M, const llvm::ArrayRef<dxil::ResourceInfo::ResourceBinding> &RDs,
265
304
const iterator_range<SmallVectorImpl<dxil::ResourceInfo>::iterator>
266
305
&Resources) {
267
306
for (auto Res = Resources.begin (), End = Resources.end (); Res != End; Res++) {
307
+ llvm::dxil::ResourceInfo::ResourceBinding Binding = Res->getBinding ();
308
+ bool IsBound = false ;
309
+ for (const auto &RD : RDs) {
310
+ if (Binding.overlapsWith (RD)) {
311
+ IsBound = true ;
312
+ break ;
313
+ }
314
+ }
315
+
316
+ if (!IsBound)
317
+ continue ;
318
+
268
319
TargetExtType *Handle = Res->getHandleTy ();
269
320
auto *TypedBuffer = dyn_cast_or_null<TypedBufferExtType>(Handle);
270
321
auto *Texture = dyn_cast_or_null<TextureExtType>(Handle);
@@ -312,9 +363,9 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
312
363
" DXILResourceImplicitBinding pass" );
313
364
314
365
if (auto RSD = getRootSignature (RSBI, MMI)) {
315
-
366
+ dxbc::ShaderVisibility Visibility = tripleToVisibility (MMI. ShaderProfile );
316
367
llvm::hlsl::rootsig::RootSignatureBindingValidation Validation =
317
- initRSBindingValidation (*RSD, tripleToVisibility (MMI. ShaderProfile ) );
368
+ initRSBindingValidation (*RSD, Visibility );
318
369
319
370
reportUnboundRegisters (M, Validation, ResourceClass::CBuffer,
320
371
DRM.cbuffers ());
@@ -323,10 +374,13 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
323
374
DRM.samplers ());
324
375
reportUnboundRegisters (M, Validation, ResourceClass::SRV, DRM.srvs ());
325
376
326
- reportInvalidHandleTy (M, DRM.cbuffers ());
327
- reportInvalidHandleTy (M, DRM.srvs ());
328
- reportInvalidHandleTy (M, DRM.uavs ());
329
- reportInvalidHandleTy (M, DRM.samplers ());
377
+ SmallVector<ResourceInfo::ResourceBinding> RDs =
378
+ getRootDescriptorsBindingInfo (*RSD, Visibility);
379
+
380
+ reportInvalidHandleTy (M, RDs, DRM.cbuffers ());
381
+ reportInvalidHandleTy (M, RDs, DRM.srvs ());
382
+ reportInvalidHandleTy (M, RDs, DRM.uavs ());
383
+ reportInvalidHandleTy (M, RDs, DRM.samplers ());
330
384
}
331
385
}
332
386
} // namespace
0 commit comments