16#include "llvm/IR/IntrinsicsDirectX.h"
21#define DEBUG_TYPE "dxil-resource"
28 case ResourceClass::SRV:
30 case ResourceClass::UAV:
32 case ResourceClass::CBuffer:
34 case ResourceClass::Sampler:
42 case ResourceKind::Texture1D:
44 case ResourceKind::Texture2D:
46 case ResourceKind::Texture2DMS:
48 case ResourceKind::Texture3D:
50 case ResourceKind::TextureCube:
52 case ResourceKind::Texture1DArray:
53 return "Texture1DArray";
54 case ResourceKind::Texture2DArray:
55 return "Texture2DArray";
56 case ResourceKind::Texture2DMSArray:
57 return "Texture2DMSArray";
58 case ResourceKind::TextureCubeArray:
59 return "TextureCubeArray";
60 case ResourceKind::TypedBuffer:
62 case ResourceKind::RawBuffer:
64 case ResourceKind::StructuredBuffer:
65 return "StructuredBuffer";
66 case ResourceKind::CBuffer:
68 case ResourceKind::Sampler:
70 case ResourceKind::TBuffer:
72 case ResourceKind::RTAccelerationStructure:
73 return "RTAccelerationStructure";
74 case ResourceKind::FeedbackTexture2D:
75 return "FeedbackTexture2D";
76 case ResourceKind::FeedbackTexture2DArray:
77 return "FeedbackTexture2DArray";
78 case ResourceKind::NumEntries:
79 case ResourceKind::Invalid:
89 case ElementType::I16:
91 case ElementType::U16:
93 case ElementType::I32:
95 case ElementType::U32:
97 case ElementType::I64:
99 case ElementType::U64:
101 case ElementType::F16:
103 case ElementType::F32:
105 case ElementType::F64:
107 case ElementType::SNormF16:
109 case ElementType::UNormF16:
111 case ElementType::SNormF32:
113 case ElementType::UNormF32:
115 case ElementType::SNormF64:
117 case ElementType::UNormF64:
119 case ElementType::PackedS8x32:
121 case ElementType::PackedU8x32:
123 case ElementType::Invalid:
131 case SamplerType::Default:
133 case SamplerType::Comparison:
135 case SamplerType::Mono:
143 case SamplerFeedbackType::MinMip:
145 case SamplerFeedbackType::MipRegionUsed:
146 return "MipRegionUsed";
205 "Invalid ResourceKind for SRV constructor.");
247 bool GloballyCoherent,
bool IsROV,
251 "Invalid ResourceKind for UAV constructor.");
253 RI.
setUAV(GloballyCoherent,
false, IsROV);
258 bool GloballyCoherent,
bool IsROV) {
260 RI.
setUAV(GloballyCoherent,
false, IsROV);
267 bool GloballyCoherent,
bool IsROV,
272 RI.
setUAV(GloballyCoherent, HasCounter, IsROV);
280 bool GloballyCoherent) {
283 RI.
setUAV(GloballyCoherent,
false,
false);
292 bool GloballyCoherent) {
296 RI.
setUAV(GloballyCoherent,
false,
false);
305 RI.
setUAV(
false,
false,
false);
315 RI.
setUAV(
false,
false,
false);
335 if (std::tie(Symbol, Name, Binding, RC, Kind) !=
353 return MultiSample ==
RHS.MultiSample;
364 auto getIntMD = [&I32Ty](
uint32_t V) {
368 auto getBoolMD = [&I1Ty](
uint32_t V) {
373 MDVals.
push_back(getIntMD(Binding.RecordID));
376 MDVals.
push_back(getIntMD(Binding.Space));
377 MDVals.
push_back(getIntMD(Binding.LowerBound));
378 MDVals.
push_back(getIntMD(Binding.Size));
424 bool IsUAV =
isUAV();
425 bool IsROV = IsUAV &&
UAVFlags.IsROV;
426 bool IsGloballyCoherent = IsUAV &&
UAVFlags.GloballyCoherent;
427 uint8_t SamplerCmpOrHasCounter = 0;
429 SamplerCmpOrHasCounter =
UAVFlags.HasCounter;
437 Word0 |= (AlignLog2 & 0xF) << 8;
438 Word0 |= (IsUAV & 1) << 12;
439 Word0 |= (IsROV & 1) << 13;
440 Word0 |= (IsGloballyCoherent & 1) << 14;
441 Word0 |= (SamplerCmpOrHasCounter & 1) << 15;
455 Word1 |= (CompType & 0xFF) << 0;
456 Word1 |= (CompCount & 0xFF) << 8;
457 Word1 |= (SampleCount & 0xFF) << 16;
460 return {Word0, Word1};
468 OS <<
" Name: \"" << Name <<
"\"\n"
470 <<
" Record ID: " << Binding.RecordID <<
"\n"
471 <<
" Space: " << Binding.Space <<
"\n"
472 <<
" Lower Bound: " << Binding.LowerBound <<
"\n"
473 <<
" Size: " << Binding.Size <<
"\n"
483 OS <<
" Globally Coherent: " <<
UAVFlags.GloballyCoherent <<
"\n"
484 <<
" HasCounter: " <<
UAVFlags.HasCounter <<
"\n"
485 <<
" IsROV: " <<
UAVFlags.IsROV <<
"\n";
488 OS <<
" Sample Count: " << MultiSample.Count <<
"\n";
491 OS <<
" Buffer Stride: " <<
Struct.Stride <<
"\n";
492 OS <<
" Alignment: " <<
Struct.AlignLog2 <<
"\n";
495 <<
" Element Count: " <<
Typed.ElementCount <<
"\n";
534class ResourceMapper {
564 diagnoseHandle(CI,
Twine(
"Invalid buffer target type"));
573 ResourceClass RC = IsWriteable ? ResourceClass::UAV : ResourceClass::SRV;
576 Kind = ResourceKind::TypedBuffer;
578 Kind = ResourceKind::RawBuffer;
580 Kind = ResourceKind::StructuredBuffer;
598 RI->
setUAV(
false,
false, IsROV);
603 if (
auto *VTy = dyn_cast<FixedVectorType>(ElTy))
604 Count = VTy->getNumElements();
613 if (
auto *STy = dyn_cast<StructType>(ElTy))
624 auto *HandleTy = dyn_cast<TargetExtType>(
RetTy);
626 diagnoseHandle(CI,
"dx.handle.fromBinding requires target type");
631 if (TypeName ==
"dx.TypedBuffer") {
632 return mapBufferType(CI, HandleTy,
true);
633 }
else if (TypeName ==
"dx.RawBuffer") {
634 return mapBufferType(CI, HandleTy,
false);
635 }
else if (TypeName ==
"dx.CBuffer") {
637 diagnoseHandle(CI,
"dx.CBuffer handles are not implemented yet");
639 }
else if (TypeName ==
"dx.Sampler") {
641 diagnoseHandle(CI,
"dx.Sampler handles are not implemented yet");
643 }
else if (TypeName ==
"dx.Texture") {
645 diagnoseHandle(CI,
"dx.Texture handles are not implemented yet");
649 diagnoseHandle(CI,
"Invalid target(dx) type");
655 "Must be dx.handle.fromBinding intrinsic");
666 else if (RI->
isUAV())
676 RI->
bind(NextID, Space, LowerBound,
Size);
681 void mapResources() {
683 if (!
F.isDeclaration())
691 case Intrinsic::dx_handle_fromBinding:
692 for (
User *U :
F.users()) {
694 if (
CallInst *CI = dyn_cast<CallInst>(U))
695 mapHandleFromBinding(CI);
714 ResourceMapper(M,
Data).mapResources();
723 for (
const auto &[Handle,
Info] :
Data) {
724 OS <<
"Binding for ";
749 ResourceMapper(M, *ResourceMap).mapResources();
757 OS <<
"No resource map has been built!\n";
760 for (
const auto &[Handle,
Info] : *ResourceMap) {
761 OS <<
"Binding for ";
769#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned)
static StringRef getResourceClassName(ResourceClass RC)
static StringRef getElementTypeName(ElementType ET)
static StringRef getResourceKindName(ResourceKind RK)
static StringRef getSamplerTypeName(SamplerType ST)
static StringRef getSamplerFeedbackTypeName(SamplerFeedbackType SFT)
Analysis containing CSE Info
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Class for arbitrary precision integers.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
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.
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
DXILResourceMap run(Module &M, ModuleAnalysisManager &AM)
Gather resource info for the module M.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
DXILResourceWrapperPass()
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
~DXILResourceWrapperPass() override
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
A parsed version of the target data layout string in and methods for querying it.
Diagnostic information for unsupported feature in backend.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
const Function * getFunction() const
Return the function this instruction belongs to.
This is an important class for using LLVM in a threaded context.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDString * get(LLVMContext &Context, StringRef Str)
Align getAlignment() const
Return alignment of the basic block.
This class implements a map that also provides access to all stored values in a deterministic order.
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.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
unsigned getNumIntParameters() const
Type * getTypeParameter(unsigned i) const
unsigned getNumTypeParameters() const
unsigned getIntParameter(unsigned i) const
StringRef getName() const
Return the name for this target extension type.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getIntegerBitWidth() const
static IntegerType * getInt1Ty(LLVMContext &C)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static IntegerType * getInt32Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVM Value Representation.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
static ResourceInfo Texture2DMSArray(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount)
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name)
void setUAV(bool GloballyCoherent, bool HasCounter, bool IsROV)
static ResourceInfo FeedbackTexture2D(Value *Symbol, StringRef Name, dxil::SamplerFeedbackType FeedbackTy)
static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount)
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount, bool GloballyCoherent)
std::pair< uint32_t, uint32_t > getAnnotateProps() const
static ResourceInfo Sampler(Value *Symbol, StringRef Name, dxil::SamplerType SamplerTy)
bool isMultiSample() const
void setCBuffer(uint32_t Size)
static ResourceInfo UAV(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, bool GloballyCoherent, bool IsROV, dxil::ResourceKind Kind)
void print(raw_ostream &OS) const
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name, bool GloballyCoherent, bool IsROV)
dxil::SamplerType SamplerTy
static ResourceInfo SRV(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, dxil::ResourceKind Kind)
void setTyped(dxil::ElementType ElementTy, uint32_t ElementCount)
bool operator==(const ResourceInfo &RHS) const
void setMultiSample(uint32_t Count)
void setSampler(dxil::SamplerType Ty)
void setStruct(uint32_t Stride, MaybeAlign Alignment)
static ResourceInfo FeedbackTexture2DArray(Value *Symbol, StringRef Name, dxil::SamplerFeedbackType FeedbackTy)
static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount, bool GloballyCoherent)
MDTuple * getAsMetadata(LLVMContext &Ctx) const
void setFeedback(dxil::SamplerFeedbackType Type)
void bind(uint32_t RecordID, uint32_t Space, uint32_t LowerBound, uint32_t Size)
static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name, uint32_t Stride, MaybeAlign Alignment)
static ResourceInfo CBuffer(Value *Symbol, StringRef Name, uint32_t Size)
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name, uint32_t Stride, MaybeAlign Alignment, bool GloballyCoherent, bool IsROV, bool HasCounter)
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
ResourceKind
The kind of resource for an SRV or UAV resource.
@ RTAccelerationStructure
ElementType
The element type of an SRV or UAV resource.
This is an optimization pass for GlobalISel generic memory operations.
void initializeDXILResourceWrapperPassPass(PassRegistry &)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
ModulePass * createDXILResourceWrapperPassPass()
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
MapVector< CallInst *, dxil::ResourceInfo > DXILResourceMap
A special type used by analysis passes to provide an address that identifies that particular analysis...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.