-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathDevice.h
More file actions
189 lines (146 loc) · 5.04 KB
/
Device.h
File metadata and controls
189 lines (146 loc) · 5.04 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
//===- 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 DXBinding {
uint32_t Register;
uint32_t Space;
};
struct InputLayoutDesc {
std::string Name;
Format Format;
uint32_t OffsetInBytes;
std::optional<uint32_t> InstanceStepRate;
};
struct ResourceBindingDesc {
ResourceKind Kind;
DXBinding 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:
virtual ~PipelineState() = default;
PipelineState(const Buffer &) = delete;
PipelineState &operator=(const Buffer &) = delete;
protected:
PipelineState() = default;
};
class Fence {
public:
virtual ~Fence() = default;
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;
};
class Queue {
public:
virtual ~Queue() = 0;
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, ShaderContainer VS,
ShaderContainer PS) = 0;
virtual llvm::Expected<std::unique_ptr<Fence>>
createFence(llvm::StringRef Name) = 0;
virtual llvm::Expected<std::shared_ptr<Buffer>>
createBuffer(std::string Name, BufferCreateDesc &Desc,
size_t SizeInBytes) = 0;
virtual llvm::Expected<std::shared_ptr<Texture>>
createTexture(std::string Name, 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::shared_ptr<Texture>>
createRenderTargetFromCPUBuffer(Device &Dev, const CPUBuffer &Buf);
// Creates a depth/stencil texture matching the dimensions of a render target.
llvm::Expected<std::shared_ptr<Texture>>
createDefaultDepthStencilTarget(Device &Dev, uint32_t Width, uint32_t Height);
} // namespace offloadtest
#endif // OFFLOADTEST_API_DEVICE_H