12
12
#include " llvm/ADT/SmallString.h"
13
13
#include " llvm/Analysis/DXILMetadataAnalysis.h"
14
14
#include " llvm/Analysis/DXILResource.h"
15
+ #include " llvm/IR/DerivedTypes.h"
15
16
#include " llvm/IR/DiagnosticInfo.h"
16
17
#include " llvm/IR/Instructions.h"
17
18
#include " llvm/IR/IntrinsicsDirectX.h"
18
19
#include " llvm/IR/Module.h"
19
20
#include " llvm/InitializePasses.h"
21
+ #include " llvm/Support/Casting.h"
20
22
21
23
#define DEBUG_TYPE " dxil-post-optimization-validation"
22
24
@@ -84,6 +86,17 @@ static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM) {
84
86
}
85
87
}
86
88
89
+ static void
90
+ reportInvalidHandleTyBoundInRs (Module &M, Twine Type,
91
+ ResourceInfo::ResourceBinding Binding) {
92
+ SmallString<128 > Message;
93
+ raw_svector_ostream OS (Message);
94
+ OS << " resource " << Type << " at register (space=" << Binding.Space
95
+ << " , register=" << Binding.LowerBound << " )"
96
+ << " is bound to a texture or typed buffer." ;
97
+ M.getContext ().diagnose (DiagnosticInfoGeneric (Message));
98
+ }
99
+
87
100
static void reportRegNotBound (Module &M, Twine Type,
88
101
ResourceInfo::ResourceBinding Binding) {
89
102
SmallString<128 > Message;
@@ -197,7 +210,7 @@ getRootSignature(RootSignatureBindingInfo &RSBI,
197
210
return RootSigDesc;
198
211
}
199
212
200
- static void reportUnboundRegisters (
213
+ static void reportInvalidRegistersBinding (
201
214
Module &M,
202
215
const std::vector<llvm::dxil::ResourceInfo::ResourceBinding> &Bindings,
203
216
iterator_range<SmallVector<dxil::ResourceInfo>::iterator> &Resources) {
@@ -214,6 +227,13 @@ static void reportUnboundRegisters(
214
227
}
215
228
if (!Bound) {
216
229
reportRegNotBound (M, Res->getName (), Res->getBinding ());
230
+ } else {
231
+ TargetExtType *Handle = Res->getHandleTy ();
232
+ auto *TypedBuffer = dyn_cast_or_null<TypedBufferExtType>(Handle);
233
+ auto *Texture = dyn_cast_or_null<TextureExtType>(Handle);
234
+
235
+ if (TypedBuffer != nullptr || Texture != nullptr )
236
+ reportInvalidHandleTyBoundInRs (M, Res->getName (), Res->getBinding ());
217
237
}
218
238
}
219
239
}
@@ -241,14 +261,14 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
241
261
auto UAVs = DRM.uavs ();
242
262
auto Samplers = DRM.samplers ();
243
263
244
- reportUnboundRegisters (
264
+ reportInvalidRegistersBinding (
245
265
M, Validation.getBindingsOfType (dxbc::DescriptorRangeType::CBV), Cbufs);
246
- reportUnboundRegisters (
266
+ reportInvalidRegistersBinding (
247
267
M, Validation.getBindingsOfType (dxbc::DescriptorRangeType::UAV), UAVs);
248
- reportUnboundRegisters (
268
+ reportInvalidRegistersBinding (
249
269
M, Validation.getBindingsOfType (dxbc::DescriptorRangeType::Sampler),
250
270
Samplers);
251
- reportUnboundRegisters (
271
+ reportInvalidRegistersBinding (
252
272
M, Validation.getBindingsOfType (dxbc::DescriptorRangeType::SRV), SRVs);
253
273
}
254
274
}
0 commit comments