forked from wcandillon/react-native-webgpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPUSharedFence.h
More file actions
53 lines (39 loc) · 1.63 KB
/
Copy pathGPUSharedFence.h
File metadata and controls
53 lines (39 loc) · 1.63 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
#pragma once
#include <memory>
#include <string>
#include "NativeObject.h"
#include "webgpu/webgpu_cpp.h"
namespace rnwgpu {
namespace jsi = facebook::jsi;
// Wraps a wgpu::SharedFence: a native GPU sync primitive (id<MTLSharedEvent> on
// Apple, sync-fd / VkSemaphore on Android).
class GPUSharedFence : public NativeObject<GPUSharedFence> {
public:
static constexpr const char *CLASS_NAME = "GPUSharedFence";
explicit GPUSharedFence(wgpu::SharedFence instance, std::string label)
: NativeObject(CLASS_NAME), _instance(std::move(instance)),
_label(std::move(label)) {}
public:
std::string getBrand() { return CLASS_NAME; }
// export() -> { type, handle }: exposes the native handle (as a BigInt) so
// app code can wait on or signal the fence. The caller owns the returned
// handle (e.g. an exported sync-fd must be close()d).
jsi::Value exportInfo(jsi::Runtime &runtime, const jsi::Value &thisVal,
const jsi::Value *args, size_t count);
std::string getLabel() { return _label; }
void setLabel(const std::string &label) {
_label = label;
_instance.SetLabel(_label.c_str());
}
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
installGetter(runtime, prototype, "__brand", &GPUSharedFence::getBrand);
installMethod(runtime, prototype, "export", &GPUSharedFence::exportInfo);
installGetterSetter(runtime, prototype, "label", &GPUSharedFence::getLabel,
&GPUSharedFence::setLabel);
}
inline wgpu::SharedFence get() { return _instance; }
private:
wgpu::SharedFence _instance;
std::string _label;
};
} // namespace rnwgpu