18#include "llvm/IR/IntrinsicsDirectX.h"
23#define DEBUG_TYPE "dxil-post-optimization-validation"
31 case RootParameterType::Constants32Bit:
33 case RootParameterType::SRV:
35 case RootParameterType::UAV:
37 case RootParameterType::CBV:
39 case dxbc::RootParameterType::DescriptorTable:
46 for (
const auto &
UAV : DRM.
uavs()) {
52 if (*DRM.
find(MaybeHandle) ==
UAV) {
53 ResourceHandle = MaybeHandle;
58 StringRef Message =
"RWStructuredBuffers may increment or decrement their "
59 "counters, but not both.";
60 for (
const auto &U : ResourceHandle->
users()) {
62 if (!CI && CI->
getIntrinsicID() != Intrinsic::dx_resource_updatecounter)
75 OS <<
"resource " << R1.
getName() <<
" at register "
77 <<
" at register " <<
R2.getBinding().LowerBound <<
" in space "
78 <<
R2.getBinding().Space;
83 [[maybe_unused]]
bool ErrorFound =
false;
84 for (
const auto &ResList :
89 for (
auto *
I = ResList.begin() + 1;
I != ResList.end(); ++
I) {
92 while (RI != ResList.end() &&
101 assert(ErrorFound &&
"this function should be called only when if "
102 "DXILResourceBindingInfo::hasOverlapingBinding() is "
103 "true, yet no overlapping binding was found");
111 OS << RCName <<
" at register " <<
Binding.LowerBound <<
" and space "
112 <<
Binding.Space <<
" is bound to a texture or typed buffer. " << RCName
113 <<
" root descriptors can only be Raw or Structured buffers.";
125 <<
" (space=" <<
R2.Space <<
", registers=[" <<
R2.LowerBound <<
", "
126 <<
R2.UpperBound <<
"])";
136 <<
" in space " << Unbound.
Space
137 <<
" does not have a binding in the Root Signature";
145 return dxbc::ShaderVisibility::Pixel;
147 return dxbc::ShaderVisibility::Vertex;
149 return dxbc::ShaderVisibility::Geometry;
151 return dxbc::ShaderVisibility::Hull;
153 return dxbc::ShaderVisibility::Domain;
155 return dxbc::ShaderVisibility::Mesh;
157 return dxbc::ShaderVisibility::All;
175 if (ParamVisibility != dxbc::ShaderVisibility::All &&
176 ParamVisibility != Visibility)
180 case dxbc::RootParameterType::Constants32Bit: {
184 Const.ShaderRegister, Const.ShaderRegister,
189 case dxbc::RootParameterType::SRV:
190 case dxbc::RootParameterType::UAV:
191 case dxbc::RootParameterType::CBV: {
195 Desc.ShaderRegister,
Desc.ShaderRegister,
200 case dxbc::RootParameterType::DescriptorTable: {
206 Range.NumDescriptors == ~0U
207 ?
Range.BaseShaderRegister
208 :
Range.BaseShaderRegister +
Range.NumDescriptors - 1;
209 Builder.trackBinding(
Range.RangeType,
Range.RegisterSpace,
210 Range.BaseShaderRegister, UpperBound, &ParamInfo);
221 Builder.calculateBindingInfo(
225 Builder.findOverlapping(ReportedBinding);
239 if (
Reg !=
nullptr) {
240 const auto *ParamInfo =
246 if (ParamInfo->
Type == dxbc::RootParameterType::DescriptorTable)
277 "DXILResourceImplicitBinding pass");
296class DXILPostOptimizationValidationLegacy :
public ModulePass {
298 bool runOnModule(
Module &M)
override {
300 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
302 getAnalysis<DXILResourceBindingWrapperPass>().getBindingInfo();
304 getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
306 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
308 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
314 return "DXIL Post Optimization Validation";
316 DXILPostOptimizationValidationLegacy() : ModulePass(
ID) {}
319 void getAnalysisUsage(llvm::AnalysisUsage &AU)
const override {
332char DXILPostOptimizationValidationLegacy::ID = 0;
336 "DXIL Post Optimization Validation",
false,
false)
347 return new DXILPostOptimizationValidationLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static dxbc::ShaderVisibility tripleToVisibility(llvm::Triple::EnvironmentType ET)
static void reportRegNotBound(Module &M, ResourceClass Class, const llvm::dxil::ResourceInfo::ResourceBinding &Unbound)
static ResourceClass toResourceClass(dxbc::RootParameterType Type)
static void reportOverlappingError(Module &M, ResourceInfo R1, ResourceInfo R2)
static void reportErrors(Module &M, DXILResourceMap &DRM, DXILResourceBindingInfo &DRBI, RootSignatureBindingInfo &RSBI, dxil::ModuleMetadataInfo &MMI, DXILResourceTypeMap &DRTM)
static void validateRootSignature(Module &M, const mcdxbc::RootSignatureDesc &RSD, dxil::ModuleMetadataInfo &MMI, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM)
static void reportInvalidHandleTyError(Module &M, ResourceClass RC, ResourceInfo::ResourceBinding Binding)
static mcdxbc::RootSignatureDesc * getRootSignature(RootSignatureBindingInfo &RSBI, dxil::ModuleMetadataInfo &MMI)
static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM)
static void reportInvalidDirection(Module &M, DXILResourceMap &DRM)
static void reportOverlappingRegisters(Module &M, const llvm::hlsl::Binding &R1, const llvm::hlsl::Binding &R2)
DXIL Resource Implicit Binding
Module.h This file contains the declarations for the Module class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallString class.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
This class represents a function call, abstracting a target machine's calling convention.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
bool hasOverlappingBinding() const
bool hasImplicitBinding() const
iterator find(const CallInst *Key)
bool hasInvalidCounterDirection() const
iterator_range< iterator > samplers()
iterator_range< iterator > srvs()
iterator_range< iterator > cbuffers()
iterator_range< iterator > uavs()
iterator_range< call_iterator > calls()
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
iterator_range< user_iterator > users()
StringRef getName() const
const ResourceBinding & getBinding() const
dxil::ResourceClass getResourceClass() const
dxil::ResourceKind getResourceKind() const
Wrapper pass for the legacy pass manager.
mcdxbc::RootSignatureDesc * getDescForFunction(const Function *F)
Builder class for creating a /c BindingInfo.
const Binding * findBoundReg(dxil::ResourceClass RC, uint32_t Space, uint32_t LowerBound, uint32_t UpperBound) const
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
LLVM_ABI StringRef getResourceClassName(ResourceClass RC)
ResourceKind
The kind of resource for an SRV or UAV resource.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
ModulePass * createDXILPostOptimizationValidationLegacyPass()
Pass to lowering LLVM intrinsic call to DXIL op function call.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
bool overlapsWith(const ResourceBinding &RHS) const
SmallVector< DescriptorRange > Ranges
dxbc::ShaderVisibility Visibility
dxbc::RootParameterType Type
const RootDescriptor & getRootDescriptor(size_t Index) const
const DescriptorTable & getDescriptorTable(size_t Index) const
const RootConstants & getConstant(size_t Index) const
SmallVector< StaticSampler > StaticSamplers
mcdxbc::RootParametersContainer ParametersContainer