Skip to content

Commit 59e91d4

Browse files
authored
[DXIL][Analysis] Make the DXILResource binding optional. NFC
This makes the binding structure in a DXILResource default to empty and need a separate call to set up, and also moves the unique ID into it since bindings are the only place where those are actually used. This will put us in a better position when dealing with resource handles in libraries. Pull Request: #100623
1 parent ea202f9 commit 59e91d4

File tree

3 files changed

+115
-143
lines changed

3 files changed

+115
-143
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ class MDTuple;
1717

1818
namespace dxil {
1919

20-
struct ResourceBinding {
21-
uint32_t Space;
22-
uint32_t LowerBound;
23-
uint32_t Size;
24-
25-
bool operator==(const ResourceBinding &RHS) const {
26-
return std::tie(Space, LowerBound, Size) ==
27-
std::tie(RHS.Space, RHS.LowerBound, RHS.Size);
28-
}
29-
bool operator!=(const ResourceBinding &RHS) const { return !(*this == RHS); }
30-
};
31-
3220
class ResourceInfo {
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+
3336
struct UAVInfo {
3437
bool GloballyCoherent;
3538
bool HasCounter;
@@ -81,12 +84,11 @@ class ResourceInfo {
8184
Value *Symbol;
8285
StringRef Name;
8386

84-
ResourceBinding Binding;
85-
uint32_t UniqueID;
86-
8787
dxil::ResourceClass RC;
8888
dxil::ResourceKind Kind;
8989

90+
ResourceBinding Binding = {};
91+
9092
// Resource class dependent properties.
9193
// CBuffer, Sampler, and RawBuffer end here.
9294
union {
@@ -114,70 +116,62 @@ class ResourceInfo {
114116
bool isMultiSample() const;
115117

116118
ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
117-
StringRef Name, ResourceBinding Binding, uint32_t UniqueID)
118-
: Symbol(Symbol), Name(Name), Binding(Binding), UniqueID(UniqueID),
119-
RC(RC), Kind(Kind) {}
119+
StringRef Name)
120+
: Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
120121

121122
public:
122123
static ResourceInfo SRV(Value *Symbol, StringRef Name,
123-
ResourceBinding Binding, uint32_t UniqueID,
124124
dxil::ElementType ElementTy, uint32_t ElementCount,
125125
dxil::ResourceKind Kind);
126-
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name,
127-
ResourceBinding Binding, uint32_t UniqueID);
126+
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name);
128127
static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
129-
ResourceBinding Binding,
130-
uint32_t UniqueID, uint32_t Stride,
131-
Align Alignment);
128+
uint32_t Stride, Align Alignment);
132129
static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
133-
ResourceBinding Binding, uint32_t UniqueID,
134130
dxil::ElementType ElementTy,
135131
uint32_t ElementCount, uint32_t SampleCount);
136-
static ResourceInfo
137-
Texture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
138-
uint32_t UniqueID, dxil::ElementType ElementTy,
139-
uint32_t ElementCount, uint32_t SampleCount);
132+
static ResourceInfo Texture2DMSArray(Value *Symbol, StringRef Name,
133+
dxil::ElementType ElementTy,
134+
uint32_t ElementCount,
135+
uint32_t SampleCount);
140136

141137
static ResourceInfo UAV(Value *Symbol, StringRef Name,
142-
ResourceBinding Binding, uint32_t UniqueID,
143138
dxil::ElementType ElementTy, uint32_t ElementCount,
144139
bool GloballyCoherent, bool IsROV,
145140
dxil::ResourceKind Kind);
146141
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
147-
ResourceBinding Binding, uint32_t UniqueID,
148142
bool GloballyCoherent, bool IsROV);
149143
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name,
150-
ResourceBinding Binding,
151-
uint32_t UniqueID, uint32_t Stride,
144+
uint32_t Stride,
152145
Align Alignment, bool GloballyCoherent,
153146
bool IsROV, bool HasCounter);
154147
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
155-
ResourceBinding Binding, uint32_t UniqueID,
156148
dxil::ElementType ElementTy,
157149
uint32_t ElementCount, uint32_t SampleCount,
158150
bool GloballyCoherent);
159-
static ResourceInfo
160-
RWTexture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
161-
uint32_t UniqueID, dxil::ElementType ElementTy,
162-
uint32_t ElementCount, uint32_t SampleCount,
163-
bool GloballyCoherent);
151+
static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name,
152+
dxil::ElementType ElementTy,
153+
uint32_t ElementCount,
154+
uint32_t SampleCount,
155+
bool GloballyCoherent);
164156
static ResourceInfo FeedbackTexture2D(Value *Symbol, StringRef Name,
165-
ResourceBinding Binding,
166-
uint32_t UniqueID,
167157
dxil::SamplerFeedbackType FeedbackTy);
168158
static ResourceInfo
169-
FeedbackTexture2DArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
170-
uint32_t UniqueID,
159+
FeedbackTexture2DArray(Value *Symbol, StringRef Name,
171160
dxil::SamplerFeedbackType FeedbackTy);
172161

173-
static ResourceInfo CBuffer(Value *Symbol, StringRef Name,
174-
ResourceBinding Binding, uint32_t UniqueID,
175-
uint32_t Size);
162+
static ResourceInfo CBuffer(Value *Symbol, StringRef Name, uint32_t Size);
176163

177164
static ResourceInfo Sampler(Value *Symbol, StringRef Name,
178-
ResourceBinding Binding, uint32_t UniqueID,
179165
dxil::SamplerType SamplerTy);
180166

167+
void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
168+
uint32_t Size) {
169+
Binding.UniqueID = UniqueID;
170+
Binding.Space = Space;
171+
Binding.LowerBound = LowerBound;
172+
Binding.Size = Size;
173+
}
174+
181175
bool operator==(const ResourceInfo &RHS) const;
182176

183177
MDTuple *getAsMetadata(LLVMContext &Ctx) const;

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -64,66 +64,58 @@ bool ResourceInfo::isMultiSample() const {
6464
}
6565

6666
ResourceInfo ResourceInfo::SRV(Value *Symbol, StringRef Name,
67-
ResourceBinding Binding, uint32_t UniqueID,
6867
ElementType ElementTy, uint32_t ElementCount,
6968
ResourceKind Kind) {
70-
ResourceInfo RI(ResourceClass::SRV, Kind, Symbol, Name, Binding, UniqueID);
69+
ResourceInfo RI(ResourceClass::SRV, Kind, Symbol, Name);
7170
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
7271
"Invalid ResourceKind for SRV constructor.");
7372
RI.Typed.ElementTy = ElementTy;
7473
RI.Typed.ElementCount = ElementCount;
7574
return RI;
7675
}
7776

78-
ResourceInfo ResourceInfo::RawBuffer(Value *Symbol, StringRef Name,
79-
ResourceBinding Binding,
80-
uint32_t UniqueID) {
81-
ResourceInfo RI(ResourceClass::SRV, ResourceKind::RawBuffer, Symbol, Name,
82-
Binding, UniqueID);
77+
ResourceInfo ResourceInfo::RawBuffer(Value *Symbol, StringRef Name) {
78+
ResourceInfo RI(ResourceClass::SRV, ResourceKind::RawBuffer, Symbol, Name);
8379
return RI;
8480
}
8581

8682
ResourceInfo ResourceInfo::StructuredBuffer(Value *Symbol, StringRef Name,
87-
ResourceBinding Binding,
88-
uint32_t UniqueID, uint32_t Stride,
89-
Align Alignment) {
83+
uint32_t Stride, Align Alignment) {
9084
ResourceInfo RI(ResourceClass::SRV, ResourceKind::StructuredBuffer, Symbol,
91-
Name, Binding, UniqueID);
85+
Name);
9286
RI.Struct.Stride = Stride;
9387
RI.Struct.Alignment = Alignment;
9488
return RI;
9589
}
9690

9791
ResourceInfo ResourceInfo::Texture2DMS(Value *Symbol, StringRef Name,
98-
ResourceBinding Binding,
99-
uint32_t UniqueID, ElementType ElementTy,
92+
ElementType ElementTy,
10093
uint32_t ElementCount,
10194
uint32_t SampleCount) {
102-
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMS, Symbol, Name,
103-
Binding, UniqueID);
95+
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMS, Symbol, Name);
10496
RI.Typed.ElementTy = ElementTy;
10597
RI.Typed.ElementCount = ElementCount;
10698
RI.MultiSample.Count = SampleCount;
10799
return RI;
108100
}
109101

110-
ResourceInfo ResourceInfo::Texture2DMSArray(
111-
Value *Symbol, StringRef Name, ResourceBinding Binding, uint32_t UniqueID,
112-
ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount) {
102+
ResourceInfo ResourceInfo::Texture2DMSArray(Value *Symbol, StringRef Name,
103+
ElementType ElementTy,
104+
uint32_t ElementCount,
105+
uint32_t SampleCount) {
113106
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMSArray, Symbol,
114-
Name, Binding, UniqueID);
107+
Name);
115108
RI.Typed.ElementTy = ElementTy;
116109
RI.Typed.ElementCount = ElementCount;
117110
RI.MultiSample.Count = SampleCount;
118111
return RI;
119112
}
120113

121114
ResourceInfo ResourceInfo::UAV(Value *Symbol, StringRef Name,
122-
ResourceBinding Binding, uint32_t UniqueID,
123115
ElementType ElementTy, uint32_t ElementCount,
124116
bool GloballyCoherent, bool IsROV,
125117
ResourceKind Kind) {
126-
ResourceInfo RI(ResourceClass::UAV, Kind, Symbol, Name, Binding, UniqueID);
118+
ResourceInfo RI(ResourceClass::UAV, Kind, Symbol, Name);
127119
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
128120
"Invalid ResourceKind for UAV constructor.");
129121
RI.Typed.ElementTy = ElementTy;
@@ -135,25 +127,20 @@ ResourceInfo ResourceInfo::UAV(Value *Symbol, StringRef Name,
135127
}
136128

137129
ResourceInfo ResourceInfo::RWRawBuffer(Value *Symbol, StringRef Name,
138-
ResourceBinding Binding,
139-
uint32_t UniqueID, bool GloballyCoherent,
140-
bool IsROV) {
141-
ResourceInfo RI(ResourceClass::UAV, ResourceKind::RawBuffer, Symbol, Name,
142-
Binding, UniqueID);
130+
bool GloballyCoherent, bool IsROV) {
131+
ResourceInfo RI(ResourceClass::UAV, ResourceKind::RawBuffer, Symbol, Name);
143132
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
144133
RI.UAVFlags.IsROV = IsROV;
145134
RI.UAVFlags.HasCounter = false;
146135
return RI;
147136
}
148137

149138
ResourceInfo ResourceInfo::RWStructuredBuffer(Value *Symbol, StringRef Name,
150-
ResourceBinding Binding,
151-
uint32_t UniqueID,
152139
uint32_t Stride, Align Alignment,
153140
bool GloballyCoherent, bool IsROV,
154141
bool HasCounter) {
155142
ResourceInfo RI(ResourceClass::UAV, ResourceKind::StructuredBuffer, Symbol,
156-
Name, Binding, UniqueID);
143+
Name);
157144
RI.Struct.Stride = Stride;
158145
RI.Struct.Alignment = Alignment;
159146
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
@@ -162,13 +149,12 @@ ResourceInfo ResourceInfo::RWStructuredBuffer(Value *Symbol, StringRef Name,
162149
return RI;
163150
}
164151

165-
ResourceInfo
166-
ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
167-
ResourceBinding Binding, uint32_t UniqueID,
168-
ElementType ElementTy, uint32_t ElementCount,
169-
uint32_t SampleCount, bool GloballyCoherent) {
170-
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMS, Symbol, Name,
171-
Binding, UniqueID);
152+
ResourceInfo ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
153+
ElementType ElementTy,
154+
uint32_t ElementCount,
155+
uint32_t SampleCount,
156+
bool GloballyCoherent) {
157+
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMS, Symbol, Name);
172158
RI.Typed.ElementTy = ElementTy;
173159
RI.Typed.ElementCount = ElementCount;
174160
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
@@ -178,13 +164,13 @@ ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
178164
return RI;
179165
}
180166

181-
ResourceInfo
182-
ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
183-
ResourceBinding Binding, uint32_t UniqueID,
184-
ElementType ElementTy, uint32_t ElementCount,
185-
uint32_t SampleCount, bool GloballyCoherent) {
167+
ResourceInfo ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
168+
ElementType ElementTy,
169+
uint32_t ElementCount,
170+
uint32_t SampleCount,
171+
bool GloballyCoherent) {
186172
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMSArray, Symbol,
187-
Name, Binding, UniqueID);
173+
Name);
188174
RI.Typed.ElementTy = ElementTy;
189175
RI.Typed.ElementCount = ElementCount;
190176
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
@@ -195,11 +181,9 @@ ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
195181
}
196182

197183
ResourceInfo ResourceInfo::FeedbackTexture2D(Value *Symbol, StringRef Name,
198-
ResourceBinding Binding,
199-
uint32_t UniqueID,
200184
SamplerFeedbackType FeedbackTy) {
201185
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2D, Symbol,
202-
Name, Binding, UniqueID);
186+
Name);
203187
RI.UAVFlags.GloballyCoherent = false;
204188
RI.UAVFlags.IsROV = false;
205189
RI.UAVFlags.HasCounter = false;
@@ -209,10 +193,9 @@ ResourceInfo ResourceInfo::FeedbackTexture2D(Value *Symbol, StringRef Name,
209193

210194
ResourceInfo
211195
ResourceInfo::FeedbackTexture2DArray(Value *Symbol, StringRef Name,
212-
ResourceBinding Binding, uint32_t UniqueID,
213196
SamplerFeedbackType FeedbackTy) {
214197
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2DArray,
215-
Symbol, Name, Binding, UniqueID);
198+
Symbol, Name);
216199
RI.UAVFlags.GloballyCoherent = false;
217200
RI.UAVFlags.IsROV = false;
218201
RI.UAVFlags.HasCounter = false;
@@ -221,27 +204,22 @@ ResourceInfo::FeedbackTexture2DArray(Value *Symbol, StringRef Name,
221204
}
222205

223206
ResourceInfo ResourceInfo::CBuffer(Value *Symbol, StringRef Name,
224-
ResourceBinding Binding, uint32_t UniqueID,
225207
uint32_t Size) {
226-
ResourceInfo RI(ResourceClass::CBuffer, ResourceKind::CBuffer, Symbol, Name,
227-
Binding, UniqueID);
208+
ResourceInfo RI(ResourceClass::CBuffer, ResourceKind::CBuffer, Symbol, Name);
228209
RI.CBufferSize = Size;
229210
return RI;
230211
}
231212

232213
ResourceInfo ResourceInfo::Sampler(Value *Symbol, StringRef Name,
233-
ResourceBinding Binding, uint32_t UniqueID,
234214
SamplerType SamplerTy) {
235-
ResourceInfo RI(ResourceClass::Sampler, ResourceKind::Sampler, Symbol, Name,
236-
Binding, UniqueID);
215+
ResourceInfo RI(ResourceClass::Sampler, ResourceKind::Sampler, Symbol, Name);
237216
RI.SamplerTy = SamplerTy;
238217
return RI;
239218
}
240219

241220
bool ResourceInfo::operator==(const ResourceInfo &RHS) const {
242-
if (std::tie(Symbol, Name, Binding, UniqueID, RC, Kind) !=
243-
std::tie(RHS.Symbol, RHS.Name, RHS.Binding, RHS.UniqueID, RHS.RC,
244-
RHS.Kind))
221+
if (std::tie(Symbol, Name, Binding, RC, Kind) !=
222+
std::tie(RHS.Symbol, RHS.Name, RHS.Binding, RHS.RC, RHS.Kind))
245223
return false;
246224
if (isCBuffer())
247225
return CBufferSize == RHS.CBufferSize;
@@ -278,7 +256,7 @@ MDTuple *ResourceInfo::getAsMetadata(LLVMContext &Ctx) const {
278256
Constant::getIntegerValue(I1Ty, APInt(1, V)));
279257
};
280258

281-
MDVals.push_back(getIntMD(UniqueID));
259+
MDVals.push_back(getIntMD(Binding.UniqueID));
282260
MDVals.push_back(ValueAsMetadata::get(Symbol));
283261
MDVals.push_back(MDString::get(Ctx, Name));
284262
MDVals.push_back(getIntMD(Binding.Space));

0 commit comments

Comments
 (0)