1010#include " DXILRootSignature.h"
1111#include " DXILShaderFlags.h"
1212#include " DirectX.h"
13+ #include " llvm/ADT/IntervalMap.h"
1314#include " llvm/ADT/STLForwardCompat.h"
1415#include " llvm/ADT/SmallString.h"
1516#include " llvm/Analysis/DXILMetadataAnalysis.h"
@@ -86,7 +87,9 @@ static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM) {
8687 }
8788 }
8889}
89-
90+ uint64_t combine_uint32_to_uint64 (uint32_t high, uint32_t low) {
91+ return (static_cast <uint64_t >(high) << 32 ) | low;
92+ }
9093static void reportErrors (Module &M, DXILResourceMap &DRM,
9194 DXILResourceBindingInfo &DRBI,
9295 RootSignatureBindingInfo &RSBI,
@@ -101,27 +104,52 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
101104 " DXILResourceImplicitBinding pass" );
102105 // Assuming this is used to validate only the root signature assigned to the
103106 // entry function.
107+ // Start test stuff
108+ if (MMI.EntryPropertyVec .size () == 0 )
109+ return ;
110+
104111 std::optional<mcdxbc::RootSignatureDesc> RootSigDesc =
105112 RSBI.getDescForFunction (MMI.EntryPropertyVec [0 ].Entry );
106113 if (!RootSigDesc)
107114 return ;
108115
109- for (const mcdxbc::RootParameterInfo &Info :
110- RootSigDesc->ParametersContainer ) {
116+ using MapT = llvm::IntervalMap<uint64_t , llvm::dxil::ResourceInfo::ResourceBinding, sizeof (llvm::dxil::ResourceInfo::ResourceBinding), llvm::IntervalMapInfo<uint64_t >>;
117+ MapT::Allocator Allocator;
118+ MapT BindingsMap (Allocator);
119+ auto RSD = *RootSigDesc;
120+ for (size_t I = 0 ; I < RSD.ParametersContainer .size (); I++) {
111121 const auto &[Type, Loc] =
112- RootSigDesc->ParametersContainer .getTypeAndLocForParameter (
113- Info.Location );
122+ RootSigDesc->ParametersContainer .getTypeAndLocForParameter (I);
114123 switch (Type) {
115- case llvm::to_underlying (dxbc::RootParameterType::CBV):
124+ case llvm::to_underlying (dxbc::RootParameterType::CBV):{
116125 dxbc::RTS0::v2::RootDescriptor Desc =
117126 RootSigDesc->ParametersContainer .getRootDescriptor (Loc);
118127
119128 llvm::dxil::ResourceInfo::ResourceBinding Binding;
120129 Binding.LowerBound = Desc.ShaderRegister ;
121130 Binding.Space = Desc.RegisterSpace ;
122131 Binding.Size = 1 ;
132+
133+ BindingsMap.insert (combine_uint32_to_uint64 (Binding.Space , Binding.LowerBound ), combine_uint32_to_uint64 (Binding.Space , Binding.LowerBound + Binding.Size -1 ), Binding);
123134 break ;
124135 }
136+ // case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable):{
137+ // mcdxbc::DescriptorTable Table =
138+ // RootSigDesc->ParametersContainer.getDescriptorTable(Loc);
139+ // for (const dxbc::RTS0::v2::DescriptorRange &Range : Table){
140+ // Range.
141+ // }
142+
143+ // break;
144+ // }
145+ }
146+
147+ }
148+
149+ for (const auto &CBuf : DRM.cbuffers ()) {
150+ auto Binding = CBuf.getBinding ();
151+ if (!BindingsMap.overlaps (combine_uint32_to_uint64 (Binding.Space , Binding.LowerBound ), combine_uint32_to_uint64 (Binding.Space , Binding.LowerBound + Binding.Size -1 )))
152+ auto X = 1 ;
125153 }
126154}
127155} // namespace
@@ -146,7 +174,7 @@ class DXILPostOptimizationValidationLegacy : public ModulePass {
146174 DXILResourceBindingInfo &DRBI =
147175 getAnalysis<DXILResourceBindingWrapperPass>().getBindingInfo ();
148176
149- RootSignatureBindingInfo & RSBI =
177+ RootSignatureBindingInfo& RSBI =
150178 getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo ();
151179 dxil::ModuleMetadataInfo &MMI =
152180 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
0 commit comments