LLVM 20.0.0git
DXILResource.h
Go to the documentation of this file.
1//===- DXILResource.h - Representations of DXIL resources -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_ANALYSIS_DXILRESOURCE_H
10#define LLVM_ANALYSIS_DXILRESOURCE_H
11
12#include "llvm/IR/Value.h"
14
15namespace llvm {
16class MDTuple;
17
18namespace dxil {
19
21 struct ResourceBinding {
22 uint32_t UniqueID;
23 uint32_t Space;
24 uint32_t LowerBound;
25 uint32_t Size;
26
27 bool operator==(const ResourceBinding &RHS) const {
28 return std::tie(UniqueID, Space, LowerBound, Size) ==
29 std::tie(RHS.UniqueID, RHS.Space, RHS.LowerBound, RHS.Size);
30 }
31 bool operator!=(const ResourceBinding &RHS) const {
32 return !(*this == RHS);
33 }
34 };
35
36 struct UAVInfo {
37 bool GloballyCoherent;
38 bool HasCounter;
39 bool IsROV;
40
41 bool operator==(const UAVInfo &RHS) const {
42 return std::tie(GloballyCoherent, HasCounter, IsROV) ==
43 std::tie(RHS.GloballyCoherent, RHS.HasCounter, RHS.IsROV);
44 }
45 bool operator!=(const UAVInfo &RHS) const { return !(*this == RHS); }
46 };
47
48 struct StructInfo {
49 uint32_t Stride;
50 // Note: we store an integer here rather than using `MaybeAlign` because in
51 // GCC 7 MaybeAlign isn't trivial so having one in this union would delete
52 // our move constructor.
53 // See https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0602r4.html
54 uint32_t AlignLog2;
55
56 bool operator==(const StructInfo &RHS) const {
57 return std::tie(Stride, AlignLog2) == std::tie(RHS.Stride, RHS.AlignLog2);
58 }
59 bool operator!=(const StructInfo &RHS) const { return !(*this == RHS); }
60 };
61
62 struct TypedInfo {
63 dxil::ElementType ElementTy;
65
66 bool operator==(const TypedInfo &RHS) const {
67 return std::tie(ElementTy, ElementCount) ==
68 std::tie(RHS.ElementTy, RHS.ElementCount);
69 }
70 bool operator!=(const TypedInfo &RHS) const { return !(*this == RHS); }
71 };
72
73 struct MSInfo {
74 uint32_t Count;
75
76 bool operator==(const MSInfo &RHS) const { return Count == RHS.Count; }
77 bool operator!=(const MSInfo &RHS) const { return !(*this == RHS); }
78 };
79
80 struct FeedbackInfo {
82
83 bool operator==(const FeedbackInfo &RHS) const { return Type == RHS.Type; }
84 bool operator!=(const FeedbackInfo &RHS) const { return !(*this == RHS); }
85 };
86
87 // Universal properties.
88 Value *Symbol;
89 StringRef Name;
90
93
94 ResourceBinding Binding = {};
95
96 // Resource class dependent properties.
97 // CBuffer, Sampler, and RawBuffer end here.
98 union {
99 UAVInfo UAVFlags; // UAV
102 };
103
104 // Resource kind dependent properties.
105 union {
106 StructInfo Struct; // StructuredBuffer
107 TypedInfo Typed; // All SRV/UAV except Raw/StructuredBuffer
108 FeedbackInfo Feedback; // FeedbackTexture
109 };
110
111 MSInfo MultiSample;
112
113public:
115 StringRef Name)
116 : Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
117
118 // Conditions to check before accessing union members.
119 bool isUAV() const;
120 bool isCBuffer() const;
121 bool isSampler() const;
122 bool isStruct() const;
123 bool isTyped() const;
124 bool isFeedback() const;
125 bool isMultiSample() const;
126
127 void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
128 uint32_t Size) {
129 Binding.UniqueID = UniqueID;
130 Binding.Space = Space;
131 Binding.LowerBound = LowerBound;
132 Binding.Size = Size;
133 }
134 void setUAV(bool GloballyCoherent, bool HasCounter, bool IsROV) {
135 assert(isUAV() && "Not a UAV");
136 UAVFlags.GloballyCoherent = GloballyCoherent;
137 UAVFlags.HasCounter = HasCounter;
138 UAVFlags.IsROV = IsROV;
139 }
141 assert(isCBuffer() && "Not a CBuffer");
143 }
145 void setStruct(uint32_t Stride, MaybeAlign Alignment) {
146 assert(isStruct() && "Not a Struct");
147 Struct.Stride = Stride;
148 Struct.AlignLog2 = Alignment ? Log2(*Alignment) : 0;
149 }
151 assert(isTyped() && "Not Typed");
152 Typed.ElementTy = ElementTy;
153 Typed.ElementCount = ElementCount;
154 }
156 assert(isFeedback() && "Not Feedback");
157 Feedback.Type = Type;
158 }
160 assert(isMultiSample() && "Not MultiSampled");
161 MultiSample.Count = Count;
162 }
163
164 bool operator==(const ResourceInfo &RHS) const;
165
166 static ResourceInfo SRV(Value *Symbol, StringRef Name,
168 dxil::ResourceKind Kind);
169 static ResourceInfo RawBuffer(Value *Symbol, StringRef Name);
170 static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
171 uint32_t Stride, MaybeAlign Alignment);
172 static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
173 dxil::ElementType ElementTy,
174 uint32_t ElementCount, uint32_t SampleCount);
175 static ResourceInfo Texture2DMSArray(Value *Symbol, StringRef Name,
176 dxil::ElementType ElementTy,
178 uint32_t SampleCount);
179
180 static ResourceInfo UAV(Value *Symbol, StringRef Name,
182 bool GloballyCoherent, bool IsROV,
183 dxil::ResourceKind Kind);
184 static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
185 bool GloballyCoherent, bool IsROV);
186 static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name,
187 uint32_t Stride, MaybeAlign Alignment,
188 bool GloballyCoherent, bool IsROV,
189 bool HasCounter);
190 static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
191 dxil::ElementType ElementTy,
192 uint32_t ElementCount, uint32_t SampleCount,
193 bool GloballyCoherent);
194 static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name,
195 dxil::ElementType ElementTy,
197 uint32_t SampleCount,
198 bool GloballyCoherent);
199 static ResourceInfo FeedbackTexture2D(Value *Symbol, StringRef Name,
200 dxil::SamplerFeedbackType FeedbackTy);
201 static ResourceInfo
203 dxil::SamplerFeedbackType FeedbackTy);
204
205 static ResourceInfo CBuffer(Value *Symbol, StringRef Name, uint32_t Size);
206
207 static ResourceInfo Sampler(Value *Symbol, StringRef Name,
209
210 MDTuple *getAsMetadata(LLVMContext &Ctx) const;
211
212 ResourceBinding getBinding() const { return Binding; }
213 std::pair<uint32_t, uint32_t> getAnnotateProps() const;
214};
215
216} // namespace dxil
217} // namespace llvm
218
219#endif // LLVM_ANALYSIS_DXILRESOURCE_H
uint64_t Size
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Tuple of metadata.
Definition: Metadata.h:1472
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound, uint32_t Size)
Definition: DXILResource.h:127
ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol, StringRef Name)
Definition: DXILResource.h:114
void setUAV(bool GloballyCoherent, bool HasCounter, bool IsROV)
Definition: DXILResource.h:134
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
void setCBuffer(uint32_t Size)
Definition: DXILResource.h:140
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name, bool GloballyCoherent, bool IsROV)
dxil::SamplerType SamplerTy
Definition: DXILResource.h:101
void setTyped(dxil::ElementType ElementTy, uint32_t ElementCount)
Definition: DXILResource.h:150
void setMultiSample(uint32_t Count)
Definition: DXILResource.h:159
void setSampler(dxil::SamplerType Ty)
Definition: DXILResource.h:144
void setStruct(uint32_t Stride, MaybeAlign Alignment)
Definition: DXILResource.h:145
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)
Definition: DXILResource.h:155
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name, uint32_t Stride, MaybeAlign Alignment, bool GloballyCoherent, bool IsROV, bool HasCounter)
ResourceBinding getBinding() const
Definition: DXILResource.h:212
ResourceKind
The kind of resource for an SRV or UAV resource.
Definition: DXILABI.h:51
ResourceClass
Definition: DXILABI.h:42
SamplerFeedbackType
Definition: DXILABI.h:111
ElementType
The element type of an SRV or UAV resource.
Definition: DXILABI.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2062
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:208
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117