@@ -122,9 +122,8 @@ static void reportInvalidHandleTyError(Module &M, Twine Type,
122122 ResourceInfo::ResourceBinding Binding) {
123123 SmallString<128 > Message;
124124 raw_svector_ostream OS (Message);
125- OS << " resource " << Type << " at register (space=" << Binding.Space
126- << " , register=" << Binding.LowerBound << " )"
127- << " is bound to a texture or typed buffer." ;
125+ OS << Type << " at register " << Binding.LowerBound << " and space "
126+ << Binding.Space << " is bound to a texture or typed buffer." ;
128127 M.getContext ().diagnose (DiagnosticInfoGeneric (Message));
129128}
130129
@@ -145,31 +144,24 @@ reportOverlappingRegisters(Module &M,
145144
146145static void
147146reportRegNotBound (Module &M, ResourceClass Class,
148- llvm::dxil::ResourceInfo::ResourceBinding Unbound) {
147+ const llvm::dxil::ResourceInfo::ResourceBinding & Unbound) {
149148 SmallString<128 > Message;
150149 raw_svector_ostream OS (Message);
151- OS << " register " << getResourceClassName (Class)
152- << " (space=" << Unbound.Space << " , register=" << Unbound.LowerBound
153- << " )"
150+ OS << getResourceClassName (Class) << " register " << Unbound.LowerBound
151+ << " in space " << Unbound.Space
154152 << " does not have a binding in the Root Signature" ;
155153 M.getContext ().diagnose (DiagnosticInfoGeneric (Message));
156154}
157155
158156static void checkInvalidHandleTy (
159157 Module &M, const llvm::ArrayRef<dxil::ResourceInfo::ResourceBinding> &RDs,
160- const iterator_range<SmallVectorImpl<dxil::ResourceInfo>::iterator>
161- &Resources) {
162- for (auto Res = Resources.begin (), End = Resources.end (); Res != End; Res++) {
163- llvm::dxil::ResourceInfo::ResourceBinding Binding = Res->getBinding ();
164- for (const auto &RD : RDs) {
165- if (Binding.overlapsWith (RD)) {
166- TargetExtType *Handle = Res->getHandleTy ();
167- auto *TypedBuffer = dyn_cast_or_null<TypedBufferExtType>(Handle);
168- auto *Texture = dyn_cast_or_null<TextureExtType>(Handle);
169-
170- if (TypedBuffer != nullptr || Texture != nullptr )
171- reportInvalidHandleTyError (M, Res->getName (), Res->getBinding ());
172- }
158+ const llvm::dxil::ResourceInfo::ResourceBinding &Binding,
159+ const ResourceKind &Kind, const dxil::ResourceClass &RC) {
160+ for (const auto &RD : RDs) {
161+ if (Binding.overlapsWith (RD)) {
162+
163+ if (Kind != ResourceKind::RawBuffer)
164+ reportInvalidHandleTyError (M, getResourceClassName (RC), Binding);
173165 }
174166 }
175167}
@@ -239,7 +231,8 @@ getRootDescriptorsBindingInfo(const mcdxbc::RootSignatureDesc &RSD,
239231static void validateRootSignature (Module &M,
240232 const mcdxbc::RootSignatureDesc &RSD,
241233 dxil::ModuleMetadataInfo &MMI,
242- DXILResourceMap &DRM) {
234+ DXILResourceMap &DRM,
235+ DXILResourceTypeMap &DRTM) {
243236
244237 hlsl::BindingInfoBuilder Builder;
245238 dxbc::ShaderVisibility Visibility = tripleToVisibility (MMI.ShaderProfile );
@@ -305,22 +298,20 @@ static void validateRootSignature(Module &M,
305298 Builder.findOverlapping (ReportedBinding);
306299 reportOverlappingRegisters (M, ReportedBinding, Overlaping);
307300 });
301+
308302 SmallVector<ResourceInfo::ResourceBinding> RDs =
309303 getRootDescriptorsBindingInfo (RSD, Visibility);
310- for (const auto &ResList :
311- {std::make_pair (ResourceClass::SRV, DRM.srvs ()),
312- std::make_pair (ResourceClass::UAV, DRM.uavs ()),
313- std::make_pair (ResourceClass::CBuffer, DRM.cbuffers ()),
314- std::make_pair (ResourceClass::Sampler, DRM.samplers ())}) {
315- for (auto Res : ResList.second ) {
316- llvm::dxil::ResourceInfo::ResourceBinding ResBinding = Res.getBinding ();
317- llvm::hlsl::BindingInfo::BindingRange ResRange (
318- ResBinding.LowerBound , ResBinding.LowerBound + ResBinding.Size );
319-
320- if (!Info.isBound (ResList.first , ResBinding.Space , ResRange))
321- reportRegNotBound (M, ResList.first , ResBinding);
322- }
323- checkInvalidHandleTy (M, RDs, ResList.second );
304+
305+ for (const ResourceInfo &RI : DRM) {
306+ const ResourceInfo::ResourceBinding &Binding = RI.getBinding ();
307+ dxil::ResourceTypeInfo RTI = DRTM[RI.getHandleTy ()];
308+ dxil::ResourceClass RC = RTI.getResourceClass ();
309+
310+ if (!Info.isBound (RC, Binding.Space ,
311+ {Binding.LowerBound , Binding.LowerBound + Binding.Size }))
312+ reportRegNotBound (M, RC, Binding);
313+
314+ checkInvalidHandleTy (M, RDs, Binding, RTI.getResourceKind (), RC);
324315 }
325316}
326317
@@ -335,7 +326,8 @@ getRootSignature(RootSignatureBindingInfo &RSBI,
335326static void reportErrors (Module &M, DXILResourceMap &DRM,
336327 DXILResourceBindingInfo &DRBI,
337328 RootSignatureBindingInfo &RSBI,
338- dxil::ModuleMetadataInfo &MMI) {
329+ dxil::ModuleMetadataInfo &MMI,
330+ DXILResourceTypeMap &DRTM) {
339331 if (DRM.hasInvalidCounterDirection ())
340332 reportInvalidDirection (M, DRM);
341333
@@ -346,7 +338,7 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
346338 " DXILResourceImplicitBinding pass" );
347339
348340 if (mcdxbc::RootSignatureDesc *RSD = getRootSignature (RSBI, MMI))
349- validateRootSignature (M, *RSD, MMI, DRM);
341+ validateRootSignature (M, *RSD, MMI, DRM, DRTM );
350342}
351343
352344PreservedAnalyses
@@ -355,8 +347,9 @@ DXILPostOptimizationValidation::run(Module &M, ModuleAnalysisManager &MAM) {
355347 DXILResourceBindingInfo &DRBI = MAM.getResult <DXILResourceBindingAnalysis>(M);
356348 RootSignatureBindingInfo &RSBI = MAM.getResult <RootSignatureAnalysis>(M);
357349 ModuleMetadataInfo &MMI = MAM.getResult <DXILMetadataAnalysis>(M);
350+ DXILResourceTypeMap &DRTM = MAM.getResult <DXILResourceTypeAnalysis>(M);
358351
359- reportErrors (M, DRM, DRBI, RSBI, MMI);
352+ reportErrors (M, DRM, DRBI, RSBI, MMI, DRTM );
360353 return PreservedAnalyses::all ();
361354}
362355
@@ -372,8 +365,10 @@ class DXILPostOptimizationValidationLegacy : public ModulePass {
372365 getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo ();
373366 dxil::ModuleMetadataInfo &MMI =
374367 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
368+ DXILResourceTypeMap &DRTM =
369+ getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap ();
375370
376- reportErrors (M, DRM, DRBI, RSBI, MMI);
371+ reportErrors (M, DRM, DRBI, RSBI, MMI, DRTM );
377372 return false ;
378373 }
379374 StringRef getPassName () const override {
@@ -383,15 +378,18 @@ class DXILPostOptimizationValidationLegacy : public ModulePass {
383378
384379 static char ID; // Pass identification.
385380 void getAnalysisUsage (llvm::AnalysisUsage &AU) const override {
381+
386382 AU.addRequired <DXILResourceWrapperPass>();
387383 AU.addRequired <DXILResourceBindingWrapperPass>();
388384 AU.addRequired <DXILMetadataAnalysisWrapperPass>();
389385 AU.addRequired <RootSignatureAnalysisWrapper>();
386+ AU.addRequired <DXILResourceTypeWrapperPass>();
390387 AU.addPreserved <DXILResourceWrapperPass>();
391388 AU.addPreserved <DXILResourceBindingWrapperPass>();
392389 AU.addPreserved <DXILMetadataAnalysisWrapperPass>();
393390 AU.addPreserved <ShaderFlagsAnalysisWrapper>();
394391 AU.addPreserved <RootSignatureAnalysisWrapper>();
392+ AU.addPreserved <DXILResourceTypeWrapperPass>();
395393 }
396394};
397395char DXILPostOptimizationValidationLegacy::ID = 0 ;
@@ -404,6 +402,7 @@ INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass)
404402INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapperPass)
405403INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass)
406404INITIALIZE_PASS_DEPENDENCY(RootSignatureAnalysisWrapper)
405+ INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass)
407406INITIALIZE_PASS_END(DXILPostOptimizationValidationLegacy, DEBUG_TYPE,
408407 " DXIL Post Optimization Validation" , false , false )
409408
0 commit comments