-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathGPUBuffer.h
More file actions
82 lines (64 loc) · 2.3 KB
/
Copy pathGPUBuffer.h
File metadata and controls
82 lines (64 loc) · 2.3 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
#pragma once
#include <future>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "Unions.h"
#include "RNFHybridObject.h"
#include "AsyncRunner.h"
#include "webgpu/webgpu_cpp.h"
#include "ArrayBuffer.h"
namespace rnwgpu {
namespace m = margelo;
class GPUBuffer : public m::HybridObject {
public:
explicit GPUBuffer(wgpu::Buffer instance, std::shared_ptr<AsyncRunner> async,
std::string label)
: HybridObject("GPUBuffer"), _instance(instance), _async(async),
_label(label) {}
public:
std::string getBrand() { return _name; }
std::future<void> mapAsync(uint64_t modeIn, std::optional<uint64_t> offset,
std::optional<uint64_t> size);
std::shared_ptr<ArrayBuffer> getMappedRange(std::optional<size_t> offset,
std::optional<size_t> size);
void unmap();
void destroy();
uint64_t getSize();
double getUsage();
wgpu::BufferMapState getMapState();
std::string getLabel() { return _label; }
void setLabel(const std::string &label) {
_label = label;
_instance.SetLabel(_label.c_str());
}
void loadHybridMethods() override {
registerHybridGetter("__brand", &GPUBuffer::getBrand, this);
registerHybridMethod("mapAsync", &GPUBuffer::mapAsync, this);
registerHybridMethod("getMappedRange", &GPUBuffer::getMappedRange, this);
registerHybridMethod("unmap", &GPUBuffer::unmap, this);
registerHybridMethod("destroy", &GPUBuffer::destroy, this);
registerHybridGetter("size", &GPUBuffer::getSize, this);
registerHybridGetter("usage", &GPUBuffer::getUsage, this);
registerHybridGetter("mapState", &GPUBuffer::getMapState, this);
registerHybridGetter("label", &GPUBuffer::getLabel, this);
registerHybridSetter("label", &GPUBuffer::setLabel, this);
}
inline const wgpu::Buffer get() { return _instance; }
size_t getMemoryPressure() override { return static_cast<size_t>(getSize()); }
private:
wgpu::Buffer _instance;
std::shared_ptr<AsyncRunner> _async;
std::string _label;
struct Mapping {
uint64_t start;
uint64_t end;
inline bool Intersects(uint64_t s, uint64_t e) const {
return s < end && e > start;
}
std::shared_ptr<ArrayBuffer> buffer;
};
std::vector<Mapping> mappings;
};
} // namespace rnwgpu