-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathGPUQueue.h
More file actions
86 lines (68 loc) · 2.78 KB
/
GPUQueue.h
File metadata and controls
86 lines (68 loc) · 2.78 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
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "Unions.h"
#include "RNFHybridObject.h"
#include "rnwgpu/async/AsyncRunner.h"
#include "rnwgpu/async/AsyncTaskHandle.h"
#include "webgpu/webgpu_cpp.h"
#include "ArrayBuffer.h"
#include "GPUBuffer.h"
#include "GPUCommandBuffer.h"
#include "GPUImageCopyExternalImage.h"
#include "GPUImageCopyTextureTagged.h"
namespace rnwgpu {
namespace m = margelo;
class GPUQueue : public m::HybridObject {
public:
explicit GPUQueue(wgpu::Queue instance,
std::shared_ptr<async::AsyncRunner> async,
std::string label)
: HybridObject("GPUQueue"), _instance(instance), _async(async),
_label(label) {}
public:
std::string getBrand() { return _name; }
void submit(std::vector<std::shared_ptr<GPUCommandBuffer>> commandBuffers);
async::AsyncTaskHandle onSubmittedWorkDone();
void writeBuffer(std::shared_ptr<GPUBuffer> buffer, uint64_t bufferOffset,
std::shared_ptr<ArrayBuffer> data,
std::optional<uint64_t> dataOffsetElements,
std::optional<size_t> sizeElements);
void writeTexture(std::shared_ptr<GPUImageCopyTexture> destination,
std::shared_ptr<ArrayBuffer> data,
std::shared_ptr<GPUImageDataLayout> dataLayout,
std::shared_ptr<GPUExtent3D> size);
void copyExternalImageToTexture(
std::shared_ptr<GPUImageCopyExternalImage> source,
std::shared_ptr<GPUImageCopyTextureTagged> destination,
std::shared_ptr<GPUExtent3D> copySize);
std::string getLabel() { return _label; }
void setLabel(const std::string &label) {
_label = label;
_instance.SetLabel(_label.c_str());
}
void loadHybridMethods() override {
registerHybridGetter("__brand", &GPUQueue::getBrand, this);
registerHybridMethod("submit", &GPUQueue::submit, this);
registerHybridMethod("onSubmittedWorkDone", &GPUQueue::onSubmittedWorkDone,
this);
registerHybridMethod("writeBuffer", &GPUQueue::writeBuffer, this);
registerHybridMethod("writeTexture", &GPUQueue::writeTexture, this);
registerHybridMethod("copyExternalImageToTexture",
&GPUQueue::copyExternalImageToTexture, this);
registerHybridGetter("label", &GPUQueue::getLabel, this);
registerHybridSetter("label", &GPUQueue::setLabel, this);
}
inline const wgpu::Queue get() { return _instance; }
size_t getMemoryPressure() override {
// Queues retain submitted command buffers and backend scheduling state.
constexpr size_t kQueueFloor = 1 * 1024 * 1024; // 1MB baseline
return kQueueFloor + _label.capacity();
}
private:
wgpu::Queue _instance;
std::shared_ptr<async::AsyncRunner> _async;
std::string _label;
};
} // namespace rnwgpu