Skip to content

Commit 6b18c2d

Browse files
authored
Add support for resource arrays to the offload test suite (#302)
Introduces support for resource arrays across the offload test suite, including: - Data input and output handling - Comparison of expected results - Integration with both DirectX and Vulkan runtimes (Metal is not supported yet) A new property `ArraySize` has been added to the `Buffer` definition. If `ArraySize` is `1` (the default), the `Data` field of the `Buffer` remains unchanged: ``` Data: [0, 1, 2, 3] ``` If `ArraySize` is greater than `1`, the `Data` field must be specified as a list of arrays: ``` Data: - [0, 1, 2, 3] - [4, 5, 6, 7] - [8, 9, 10, 11] ``` If the resource array includes resources with counters, their values will be output using the `Counters` field: ``` Counters: [1, 2, 3] ``` Closes llvm/wg-hlsl#291
1 parent a5187ec commit 6b18c2d

File tree

16 files changed

+1313
-407
lines changed

16 files changed

+1313
-407
lines changed

include/Image/Image.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ class ImageRef {
9090
B.getSingleElementSize(), B.Channels,
9191
B.Format == DataFormat::Float32 ||
9292
B.Format == DataFormat::Float64,
93-
llvm::StringRef(B.Data.get(), B.size())) {}
93+
llvm::StringRef(B.Data.back().get(), B.size())) {
94+
assert(B.ArraySize == 1 &&
95+
"Buffer must not be an array to be used for ImageRef");
96+
}
9497

9598
uint32_t getHeight() const { return Height; }
9699
uint32_t getWidth() const { return Width; }

include/Support/Pipeline.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@ struct Buffer {
7878
DataFormat Format;
7979
int Channels;
8080
int Stride;
81-
std::unique_ptr<char[]> Data;
81+
uint32_t ArraySize;
82+
// Data can contain one block of data for a singular resource
83+
// or multiple blocks for a resource array.
84+
llvm::SmallVector<std::unique_ptr<char[]>> Data;
8285
size_t Size;
8386
OutputProperties OutputProps;
84-
uint32_t Counter;
87+
// Counters can contain one counter value for a singular resource
88+
// or multiple values for an array of resources with counters.
89+
llvm::SmallVector<uint32_t> Counters;
8590

8691
uint32_t size() const { return Size; }
8792

@@ -267,6 +272,14 @@ struct Pipeline {
267272
return DescriptorCount;
268273
}
269274

275+
uint32_t getDescriptorCountWithFlattenedArrays() const {
276+
uint32_t DescriptorCount = 0;
277+
for (auto &D : Sets)
278+
for (auto &R : D.Resources)
279+
DescriptorCount += R.BufferPtr->ArraySize;
280+
return DescriptorCount;
281+
}
282+
270283
Buffer *getBuffer(llvm::StringRef Name) {
271284
for (auto &B : Buffers)
272285
if (Name == B.Name)
@@ -412,6 +425,32 @@ template <> struct ScalarEnumerationTraits<offloadtest::dx::RootParamKind> {
412425
#undef ENUM_CASE
413426
}
414427
};
428+
429+
template <typename T> struct SequenceTraits<SmallVector<SmallVector<T>>> {
430+
static size_t size(IO &io, SmallVector<SmallVector<T>> &seq) {
431+
return seq.size();
432+
}
433+
434+
static SmallVector<T> &element(IO &io, SmallVector<SmallVector<T>> &seq,
435+
size_t index) {
436+
if (index >= seq.size())
437+
seq.resize(index + 1);
438+
return seq[index];
439+
}
440+
};
441+
442+
template <typename T> struct SequenceTraits<SmallVector<MutableArrayRef<T>>> {
443+
static size_t size(IO &io, SmallVector<MutableArrayRef<T>> &seq) {
444+
return seq.size();
445+
}
446+
447+
static MutableArrayRef<T> &
448+
element(IO &io, SmallVector<MutableArrayRef<T>> &seq, size_t index) {
449+
assert(index < seq.size());
450+
return seq[index];
451+
}
452+
};
453+
415454
} // namespace yaml
416455
} // namespace llvm
417456

0 commit comments

Comments
 (0)