7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " DXILPostOptimizationValidation.h"
10
- #include " DXILRootSignature.h"
11
10
#include " DXILShaderFlags.h"
12
11
#include " DirectX.h"
13
- #include " llvm/ADT/IntervalMap.h"
14
12
#include " llvm/ADT/STLForwardCompat.h"
15
13
#include " llvm/ADT/SmallString.h"
16
14
#include " llvm/Analysis/DXILMetadataAnalysis.h"
21
19
#include " llvm/IR/IntrinsicsDirectX.h"
22
20
#include " llvm/IR/Module.h"
23
21
#include " llvm/InitializePasses.h"
22
+ #include < optional>
24
23
25
24
#define DEBUG_TYPE " dxil-post-optimization-validation"
26
25
@@ -87,9 +86,24 @@ static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM) {
87
86
}
88
87
}
89
88
}
90
- uint64_t combine_uint32_to_uint64 (uint32_t high, uint32_t low) {
91
- return (static_cast <uint64_t >(high) << 32 ) | low;
92
- }
89
+
90
+ static void reportRegNotBound (Module &M,
91
+ ResourceInfo::ResourceBinding Binding) {
92
+ // TODO
93
+ }
94
+
95
+ std::optional<mcdxbc::RootSignatureDesc>
96
+ getRootSignature (RootSignatureBindingInfo &RSBI,
97
+ dxil::ModuleMetadataInfo &MMI) {
98
+ if (MMI.EntryPropertyVec .size () == 0 )
99
+ return std::nullopt;
100
+ std::optional<mcdxbc::RootSignatureDesc> RootSigDesc =
101
+ RSBI.getDescForFunction (MMI.EntryPropertyVec [0 ].Entry );
102
+ if (!RootSigDesc)
103
+ return std::nullopt;
104
+ return RootSigDesc;
105
+ }
106
+
93
107
static void reportErrors (Module &M, DXILResourceMap &DRM,
94
108
DXILResourceBindingInfo &DRBI,
95
109
RootSignatureBindingInfo &RSBI,
@@ -102,54 +116,35 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
102
116
103
117
assert (!DRBI.hasImplicitBinding () && " implicit bindings should be handled in "
104
118
" DXILResourceImplicitBinding pass" );
105
- // Assuming this is used to validate only the root signature assigned to the
106
- // entry function.
107
- // Start test stuff
108
- if (MMI.EntryPropertyVec .size () == 0 )
109
- return ;
110
119
111
- std::optional<mcdxbc::RootSignatureDesc> RootSigDesc =
112
- RSBI.getDescForFunction (MMI.EntryPropertyVec [0 ].Entry );
113
- if (!RootSigDesc)
114
- return ;
120
+ if (auto RSD = getRootSignature (RSBI, MMI)) {
115
121
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++) {
121
- const auto &[Type, Loc] =
122
- RootSigDesc->ParametersContainer .getTypeAndLocForParameter (I);
123
- switch (Type) {
124
- case llvm::to_underlying (dxbc::RootParameterType::CBV):{
125
- dxbc::RTS0::v2::RootDescriptor Desc =
126
- RootSigDesc->ParametersContainer .getRootDescriptor (Loc);
127
-
128
- llvm::dxil::ResourceInfo::ResourceBinding Binding;
129
- Binding.LowerBound = Desc.ShaderRegister ;
130
- Binding.Space = Desc.RegisterSpace ;
131
- 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);
134
- break ;
135
- }
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
- // }
122
+ RootSignatureBindingValidation Validation;
123
+ Validation.addRsBindingInfo (*RSD);
124
+
125
+ for (const auto &CBuf : DRM.cbuffers ()) {
126
+ ResourceInfo::ResourceBinding Binding = CBuf.getBinding ();
127
+ if (!Validation.checkCregBinding (Binding.Space , Binding.LowerBound ,
128
+ Binding.Space ,
129
+ Binding.LowerBound + Binding.Size - 1 ))
130
+ reportRegNotBound (M, Binding);
145
131
}
146
132
147
- }
133
+ for (const auto &CBuf : DRM.srvs ()) {
134
+ ResourceInfo::ResourceBinding Binding = CBuf.getBinding ();
135
+ if (!Validation.checkTRegBinding (Binding.Space , Binding.LowerBound ,
136
+ Binding.Space ,
137
+ Binding.LowerBound + Binding.Size - 1 ))
138
+ reportRegNotBound (M, Binding);
139
+ }
148
140
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 ;
141
+ for (const auto &CBuf : DRM.uavs ()) {
142
+ ResourceInfo::ResourceBinding Binding = CBuf.getBinding ();
143
+ if (!Validation.checkURegBinding (Binding.Space , Binding.LowerBound ,
144
+ Binding.Space ,
145
+ Binding.LowerBound + Binding.Size - 1 ))
146
+ reportRegNotBound (M, Binding);
147
+ }
153
148
}
154
149
}
155
150
} // namespace
@@ -174,7 +169,7 @@ class DXILPostOptimizationValidationLegacy : public ModulePass {
174
169
DXILResourceBindingInfo &DRBI =
175
170
getAnalysis<DXILResourceBindingWrapperPass>().getBindingInfo ();
176
171
177
- RootSignatureBindingInfo& RSBI =
172
+ RootSignatureBindingInfo & RSBI =
178
173
getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo ();
179
174
dxil::ModuleMetadataInfo &MMI =
180
175
getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
0 commit comments