forked from llvm/offload-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResources.h
More file actions
266 lines (251 loc) · 6.49 KB
/
Resources.h
File metadata and controls
266 lines (251 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//===- Resources.h - Offload API shared resource types --------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
#ifndef OFFLOADTEST_API_RESOURCES_H
#define OFFLOADTEST_API_RESOURCES_H
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include <cstdint>
namespace offloadtest {
enum class MemoryLocation {
GpuOnly,
CpuToGpu,
GpuToCpu,
};
// TODO: Add Unorm types (e.g. R8Unorm, RGBA8Unorm) which can be sampled as
// floats.
// TODO: Add SRGB types (e.g. RGBA8Srgb) once needed.
enum class Format {
R16Sint,
R16Uint,
RG16Sint,
RG16Uint,
RGBA16Sint,
RGBA16Uint,
R32Sint,
R32Uint,
R32Float,
RG32Sint,
RG32Uint,
RG32Float,
RGB32Float,
RGBA32Sint,
RGBA32Uint,
RGBA32Float,
D32Float,
D32FloatS8Uint,
};
inline llvm::StringRef getFormatName(Format Format) {
switch (Format) {
case Format::R16Sint:
return "R16Sint";
case Format::R16Uint:
return "R16Uint";
case Format::RG16Sint:
return "RG16Sint";
case Format::RG16Uint:
return "RG16Uint";
case Format::RGBA16Sint:
return "RGBA16Sint";
case Format::RGBA16Uint:
return "RGBA16Uint";
case Format::R32Sint:
return "R32Sint";
case Format::R32Uint:
return "R32Uint";
case Format::R32Float:
return "R32Float";
case Format::RG32Sint:
return "RG32Sint";
case Format::RG32Uint:
return "RG32Uint";
case Format::RG32Float:
return "RG32Float";
case Format::RGB32Float:
return "RGB32Float";
case Format::RGBA32Sint:
return "RGBA32Sint";
case Format::RGBA32Uint:
return "RGBA32Uint";
case Format::RGBA32Float:
return "RGBA32Float";
case Format::D32Float:
return "D32Float";
case Format::D32FloatS8Uint:
return "D32FloatS8Uint";
}
llvm_unreachable("All Format cases handled");
}
// Returns the size in bytes of a single texel/element for the given format.
inline uint32_t getFormatSizeInBytes(Format Format) {
switch (Format) {
case Format::R16Sint:
case Format::R16Uint:
return 2;
case Format::RG16Sint:
case Format::RG16Uint:
case Format::R32Sint:
case Format::R32Uint:
case Format::R32Float:
case Format::D32Float:
return 4;
case Format::RGBA16Sint:
case Format::RGBA16Uint:
case Format::RG32Sint:
case Format::RG32Uint:
case Format::RG32Float:
case Format::D32FloatS8Uint:
return 8;
case Format::RGB32Float:
return 12;
case Format::RGBA32Sint:
case Format::RGBA32Uint:
case Format::RGBA32Float:
return 16;
}
llvm_unreachable("All Format cases handled");
}
// Returns the number of components per element for the given format.
inline uint32_t getComponentCount(Format Format) {
switch (Format) {
case Format::R16Sint:
case Format::R16Uint:
case Format::R32Sint:
case Format::R32Uint:
case Format::R32Float:
case Format::D32Float:
return 1;
case Format::RG16Sint:
case Format::RG16Uint:
case Format::RG32Sint:
case Format::RG32Uint:
case Format::RG32Float:
case Format::D32FloatS8Uint:
return 2;
case Format::RGB32Float:
return 3;
case Format::RGBA16Sint:
case Format::RGBA16Uint:
case Format::RGBA32Sint:
case Format::RGBA32Uint:
case Format::RGBA32Float:
return 4;
}
llvm_unreachable("All Format cases handled");
}
inline bool isDepthFormat(Format Format) {
switch (Format) {
case Format::R16Sint:
case Format::R16Uint:
case Format::RG16Sint:
case Format::RG16Uint:
case Format::R32Sint:
case Format::R32Uint:
case Format::R32Float:
case Format::RGBA16Sint:
case Format::RGBA16Uint:
case Format::RG32Sint:
case Format::RG32Uint:
case Format::RG32Float:
case Format::RGB32Float:
case Format::RGBA32Sint:
case Format::RGBA32Uint:
case Format::RGBA32Float:
return false;
case Format::D32Float:
case Format::D32FloatS8Uint:
return true;
}
llvm_unreachable("All Format cases handled");
}
// Returns true if the format can be used as a texture pixel format across all
// backends. Formats like RGB32Float are valid for vertex attributes but have no
// pixel format equivalent on some APIs (e.g. Metal).
inline bool isTextureCompatible(Format Format) {
switch (Format) {
case Format::RGB32Float:
return false;
case Format::R16Sint:
case Format::R16Uint:
case Format::RG16Sint:
case Format::RG16Uint:
case Format::RGBA16Sint:
case Format::RGBA16Uint:
case Format::R32Sint:
case Format::R32Uint:
case Format::R32Float:
case Format::RG32Sint:
case Format::RG32Uint:
case Format::RG32Float:
case Format::RGBA32Sint:
case Format::RGBA32Uint:
case Format::RGBA32Float:
case Format::D32Float:
case Format::D32FloatS8Uint:
return true;
}
llvm_unreachable("All Format cases handled");
}
// Returns true if the format can be used as a vertex attribute.
inline bool isVertexCompatible(Format Format) {
switch (Format) {
case Format::R16Sint:
case Format::R16Uint:
case Format::RG16Sint:
case Format::RG16Uint:
case Format::RGBA16Sint:
case Format::RGBA16Uint:
case Format::R32Sint:
case Format::R32Uint:
case Format::R32Float:
case Format::RG32Sint:
case Format::RG32Uint:
case Format::RG32Float:
case Format::RGB32Float:
case Format::RGBA32Sint:
case Format::RGBA32Uint:
case Format::RGBA32Float:
return true;
case Format::D32Float:
case Format::D32FloatS8Uint:
return false;
}
llvm_unreachable("All Format cases handled");
}
// Returns true if the format can be used as a BLAS position attribute for
// raytracing acceleration structure builds. Only a small subset of floating
// point formats are supported across DX12, Vulkan, and Metal.
inline bool isPositionCompatible(Format Format) {
switch (Format) {
case Format::RG32Float:
case Format::RGB32Float:
case Format::RGBA32Float:
return true;
case Format::R16Sint:
case Format::R16Uint:
case Format::RG16Sint:
case Format::RG16Uint:
case Format::RGBA16Sint:
case Format::RGBA16Uint:
case Format::R32Sint:
case Format::R32Uint:
case Format::R32Float:
case Format::RG32Sint:
case Format::RG32Uint:
case Format::RGBA32Sint:
case Format::RGBA32Uint:
case Format::D32Float:
case Format::D32FloatS8Uint:
return false;
}
llvm_unreachable("All Format cases handled");
}
} // namespace offloadtest
#endif // OFFLOADTEST_API_RESOURCES_H