1010#include " DXILRootSignature.h"
1111#include " DXILShaderFlags.h"
1212#include " DirectX.h"
13+ #include " llvm/ADT/ArrayRef.h"
1314#include " llvm/ADT/STLForwardCompat.h"
1415#include " llvm/ADT/SmallString.h"
1516#include " llvm/ADT/SmallVector.h"
@@ -248,6 +249,44 @@ initRSBindingValidation(const mcdxbc::RootSignatureDesc &RSD,
248249 return Validation;
249250}
250251
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+
251290std::optional<mcdxbc::RootSignatureDesc>
252291getRootSignature (RootSignatureBindingInfo &RSBI,
253292 dxil::ModuleMetadataInfo &MMI) {
@@ -261,10 +300,22 @@ getRootSignature(RootSignatureBindingInfo &RSBI,
261300}
262301
263302static void reportInvalidHandleTy (
264- Module &M,
303+ Module &M, const llvm::ArrayRef<dxil::ResourceInfo::ResourceBinding> &RDs,
265304 const iterator_range<SmallVectorImpl<dxil::ResourceInfo>::iterator>
266305 &Resources) {
267306 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+
268319 TargetExtType *Handle = Res->getHandleTy ();
269320 auto *TypedBuffer = dyn_cast_or_null<TypedBufferExtType>(Handle);
270321 auto *Texture = dyn_cast_or_null<TextureExtType>(Handle);
@@ -312,9 +363,9 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
312363 " DXILResourceImplicitBinding pass" );
313364
314365 if (auto RSD = getRootSignature (RSBI, MMI)) {
315-
366+ dxbc::ShaderVisibility Visibility = tripleToVisibility (MMI. ShaderProfile );
316367 llvm::hlsl::rootsig::RootSignatureBindingValidation Validation =
317- initRSBindingValidation (*RSD, tripleToVisibility (MMI. ShaderProfile ) );
368+ initRSBindingValidation (*RSD, Visibility );
318369
319370 reportUnboundRegisters (M, Validation, ResourceClass::CBuffer,
320371 DRM.cbuffers ());
@@ -323,10 +374,13 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
323374 DRM.samplers ());
324375 reportUnboundRegisters (M, Validation, ResourceClass::SRV, DRM.srvs ());
325376
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 ());
330384 }
331385}
332386} // namespace
0 commit comments