forked from llvm/offload-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.h
More file actions
219 lines (170 loc) · 6.28 KB
/
Copy pathDevice.h
File metadata and controls
219 lines (170 loc) · 6.28 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
//===- Device.h - Offload API Device API ----------------------------------===//
//
// 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_DEVICE_H
#define OFFLOADTEST_API_DEVICE_H
#include "Config.h"
#include "API/API.h"
#include "API/Buffer.h"
#include "API/Capabilities.h"
#include "API/CommandBuffer.h"
#include "API/Texture.h"
#include "Support/Pipeline.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
namespace llvm {
class raw_ostream;
} // namespace llvm
namespace offloadtest {
struct Pipeline;
struct DeviceConfig {
bool EnableDebugLayer = false;
bool EnableValidationLayer = false;
};
struct InputLayoutDesc {
std::string Name;
Format Fmt;
uint32_t OffsetInBytes;
std::optional<uint32_t> InstanceStepRate;
};
struct ResourceBindingDesc {
ResourceKind Kind;
DirectXBinding DXBinding;
std::optional<VulkanBinding> VKBinding;
uint32_t DescriptorCount;
};
struct DescriptorSetLayoutDesc {
llvm::SmallVector<ResourceBindingDesc> ResourceBindings;
};
struct PushConstantsRange {
uint32_t OffsetInBytes; // Must be multiple of 4
uint32_t SizeInBytes; // Must be multiple of 4
};
struct BindingsDesc {
llvm::SmallVector<DescriptorSetLayoutDesc> DescriptorSetDescs;
llvm::SmallVector<PushConstantsRange> PushConstantRanges;
};
struct ShaderContainer {
std::string EntryPoint;
const llvm::MemoryBuffer *Shader;
llvm::SmallVector<SpecializationConstant> SpecializationConstants;
};
class PipelineState {
public:
GPUAPI API;
virtual ~PipelineState() = default;
PipelineState(const Buffer &) = delete;
PipelineState &operator=(const Buffer &) = delete;
GPUAPI getAPI() const { return API; }
protected:
explicit PipelineState(GPUAPI API) : API(API) {}
};
class Fence {
public:
virtual ~Fence();
Fence(const Fence &) = delete;
Fence &operator=(const Fence &) = delete;
virtual uint64_t getFenceValue() = 0;
virtual llvm::Error waitForCompletion(uint64_t SignalValue) = 0;
protected:
Fence() = default;
};
/// Returned by Queue::submit() so that callers can decide when to block.
struct SubmitResult {
Fence *F;
uint64_t Value;
llvm::Error waitForCompletion() const { return F->waitForCompletion(Value); }
};
class Queue {
public:
virtual ~Queue() = 0;
Queue(const Queue &) = delete;
Queue &operator=(const Queue &) = delete;
Queue(Queue &&) = default;
Queue &operator=(Queue &&) = default;
/// Submit command buffers for GPU execution. Returns a fence + value that
/// the caller can wait on; the call itself does not block.
virtual llvm::Expected<SubmitResult>
submit(llvm::SmallVector<std::unique_ptr<CommandBuffer>> CBs) = 0;
/// Convenience overload for submitting a single command buffer.
llvm::Expected<SubmitResult> submit(std::unique_ptr<CommandBuffer> CB) {
llvm::SmallVector<std::unique_ptr<CommandBuffer>> CBs;
CBs.push_back(std::move(CB));
return submit(std::move(CBs));
}
protected:
Queue() = default;
};
class Device {
protected:
std::string Description;
std::string DriverName;
public:
virtual const Capabilities &getCapabilities() = 0;
virtual llvm::StringRef getAPIName() const = 0;
virtual GPUAPI getAPI() const = 0;
virtual llvm::Error executeProgram(Pipeline &P) = 0;
virtual Queue &getGraphicsQueue() = 0;
virtual llvm::Expected<std::unique_ptr<PipelineState>>
createPipelineCs(llvm::StringRef Name, const BindingsDesc &BindingsDesc,
ShaderContainer CS) = 0;
virtual llvm::Expected<std::unique_ptr<PipelineState>>
createPipelineVsPs(llvm::StringRef Name, const BindingsDesc &BindingsDesc,
llvm::ArrayRef<InputLayoutDesc> InputLayout,
llvm::ArrayRef<Format> RTFormats,
std::optional<Format> DSFormat, ShaderContainer VS,
ShaderContainer PS) = 0;
virtual llvm::Expected<std::unique_ptr<Fence>>
createFence(llvm::StringRef Name) = 0;
virtual llvm::Expected<std::unique_ptr<Buffer>>
createBuffer(std::string Name, const BufferCreateDesc &Desc,
size_t SizeInBytes) = 0;
virtual llvm::Expected<std::unique_ptr<Texture>>
createTexture(std::string Name, const TextureCreateDesc &Desc) = 0;
virtual void printExtra(llvm::raw_ostream &OS) {}
virtual llvm::Expected<std::unique_ptr<CommandBuffer>>
createCommandBuffer() = 0;
virtual ~Device() = 0;
llvm::StringRef getDescription() const { return Description; }
llvm::StringRef getDriverName() const { return DriverName; }
};
llvm::Error
initializeDX12Devices(const DeviceConfig Config,
llvm::SmallVectorImpl<std::unique_ptr<Device>> &Devices);
llvm::Error initializeVulkanDevices(
const DeviceConfig Config,
llvm::SmallVectorImpl<std::unique_ptr<Device>> &Devices);
llvm::Error
initializeMetalDevices(const DeviceConfig Config,
llvm::SmallVectorImpl<std::unique_ptr<Device>> &Devices);
llvm::Expected<llvm::SmallVector<std::unique_ptr<Device>>>
initializeDevices(const DeviceConfig Config);
// Creates a render target texture using the format and dimensions from a
// CPUBuffer. Does not upload the buffer's data — only uses its description to
// configure the texture.
llvm::Expected<std::unique_ptr<Texture>>
createRenderTargetFromCPUBuffer(Device &Dev, const CPUBuffer &Buf);
// Creates a depth/stencil texture matching the dimensions of a render target.
llvm::Expected<std::unique_ptr<Texture>>
createDefaultDepthStencilTarget(Device &Dev, uint32_t Width, uint32_t Height);
llvm::Expected<std::unique_ptr<offloadtest::Buffer>>
createBufferWithData(Device &Dev, std::string Name,
const BufferCreateDesc &Desc, const void *Data,
size_t SizeInBytes, ComputeEncoder *Encoder,
std::unique_ptr<offloadtest::Buffer> *OutUploadBuffer);
} // namespace offloadtest
#endif // OFFLOADTEST_API_DEVICE_H