react-native-webgpu 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +9 -1
  2. package/android/CMakeLists.txt +2 -0
  3. package/cpp/rnwgpu/ArrayBuffer.h +47 -2
  4. package/cpp/rnwgpu/DawnEventPump.cpp +227 -0
  5. package/cpp/rnwgpu/DawnEventPump.h +173 -0
  6. package/cpp/rnwgpu/WebGPURuntime.cpp +6 -8
  7. package/cpp/rnwgpu/api/GPU.cpp +1 -1
  8. package/cpp/rnwgpu/api/GPUAdapter.cpp +1 -1
  9. package/cpp/rnwgpu/api/GPUBuffer.cpp +100 -27
  10. package/cpp/rnwgpu/api/GPUBuffer.h +55 -6
  11. package/cpp/rnwgpu/api/GPUDevice.cpp +57 -55
  12. package/cpp/rnwgpu/api/GPUDevice.h +6 -0
  13. package/cpp/rnwgpu/api/GPUQueue.cpp +7 -2
  14. package/cpp/rnwgpu/api/GPUQueue.h +8 -2
  15. package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -1
  16. package/cpp/rnwgpu/api/RNWebGPU.h +26 -5
  17. package/cpp/rnwgpu/api/descriptors/CreateNativeBufferFromPointerOptions.h +46 -0
  18. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +21 -15
  19. package/cpp/rnwgpu/async/AsyncTaskHandle.h +3 -2
  20. package/cpp/rnwgpu/async/DeviceTicker.cpp +105 -0
  21. package/cpp/rnwgpu/async/DeviceTicker.h +71 -0
  22. package/cpp/rnwgpu/async/RuntimeContext.cpp +56 -70
  23. package/cpp/rnwgpu/async/RuntimeContext.h +37 -18
  24. package/lib/commonjs/NativeBufferView.js.map +1 -1
  25. package/lib/commonjs/NativeBufferViewNativeComponent.web.js +114 -0
  26. package/lib/commonjs/NativeBufferViewNativeComponent.web.js.map +1 -0
  27. package/lib/commonjs/WebPolyfillGPUModule.js +79 -0
  28. package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -1
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/commonjs/main/index.web.js +11 -0
  31. package/lib/commonjs/main/index.web.js.map +1 -1
  32. package/lib/commonjs/utils.js +29 -0
  33. package/lib/commonjs/utils.js.map +1 -1
  34. package/lib/commonjs/video.js +1 -1
  35. package/lib/commonjs/video.js.map +1 -1
  36. package/lib/module/NativeBufferView.js.map +1 -1
  37. package/lib/module/NativeBufferViewNativeComponent.web.js +107 -0
  38. package/lib/module/NativeBufferViewNativeComponent.web.js.map +1 -0
  39. package/lib/module/WebPolyfillGPUModule.js +80 -1
  40. package/lib/module/WebPolyfillGPUModule.js.map +1 -1
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/main/index.web.js +1 -0
  43. package/lib/module/main/index.web.js.map +1 -1
  44. package/lib/module/utils.js +27 -0
  45. package/lib/module/utils.js.map +1 -1
  46. package/lib/module/video.js +1 -1
  47. package/lib/module/video.js.map +1 -1
  48. package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.web.d.ts +4 -0
  49. package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
  50. package/lib/typescript/lib/commonjs/utils.d.ts +2 -0
  51. package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -1
  52. package/lib/typescript/lib/commonjs/video.d.ts +1 -1
  53. package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
  54. package/lib/typescript/lib/module/NativeBufferViewNativeComponent.web.d.ts +5 -0
  55. package/lib/typescript/lib/module/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
  56. package/lib/typescript/lib/module/main/index.web.d.ts +1 -0
  57. package/lib/typescript/lib/module/utils.d.ts +2 -0
  58. package/lib/typescript/lib/module/utils.d.ts.map +1 -1
  59. package/lib/typescript/lib/module/video.d.ts +1 -1
  60. package/lib/typescript/lib/module/video.d.ts.map +1 -1
  61. package/lib/typescript/src/NativeBufferView.d.ts +6 -1
  62. package/lib/typescript/src/NativeBufferView.d.ts.map +1 -1
  63. package/lib/typescript/src/NativeBufferViewNativeComponent.web.d.ts +14 -0
  64. package/lib/typescript/src/NativeBufferViewNativeComponent.web.d.ts.map +1 -0
  65. package/lib/typescript/src/index.d.ts +3 -3
  66. package/lib/typescript/src/index.d.ts.map +1 -1
  67. package/lib/typescript/src/main/index.web.d.ts +1 -0
  68. package/lib/typescript/src/main/index.web.d.ts.map +1 -1
  69. package/lib/typescript/src/types.d.ts +12 -0
  70. package/lib/typescript/src/types.d.ts.map +1 -1
  71. package/lib/typescript/src/utils.d.ts +2 -0
  72. package/lib/typescript/src/utils.d.ts.map +1 -1
  73. package/lib/typescript/src/video.d.ts +2 -2
  74. package/lib/typescript/src/video.d.ts.map +1 -1
  75. package/package.json +1 -1
  76. package/scripts/prepare-apple-binaries.sh +9 -3
  77. package/src/NativeBufferView.tsx +6 -1
  78. package/src/NativeBufferViewNativeComponent.web.ts +119 -0
  79. package/src/WebPolyfillGPUModule.ts +75 -1
  80. package/src/index.tsx +7 -2
  81. package/src/main/index.web.tsx +1 -0
  82. package/src/types.ts +13 -0
  83. package/src/utils.ts +25 -0
  84. package/src/video.ts +6 -1
@@ -51,7 +51,8 @@ namespace external_texture_color_space {
51
51
  // The JS names of the members of a source color space, the Dawn enums
52
52
  // spelled the way the frame producers report them (see
53
53
  // NativeBufferColorSpace in src/types.ts).
54
- inline wgpu::ColorSpaceYCbCrMatrixDawn parseMatrix(const std::string &name) {
54
+ inline wgpu::ColorSpaceYCbCrMatrixDawn parseMatrix(const std::string &owner,
55
+ const std::string &name) {
55
56
  if (name == "identity") {
56
57
  return wgpu::ColorSpaceYCbCrMatrixDawn::Identity;
57
58
  }
@@ -64,12 +65,13 @@ inline wgpu::ColorSpaceYCbCrMatrixDawn parseMatrix(const std::string &name) {
64
65
  if (name == "rec2020") {
65
66
  return wgpu::ColorSpaceYCbCrMatrixDawn::Rec2020;
66
67
  }
67
- throw std::runtime_error("sourceColorSpace.matrix: unknown value '" + name +
68
+ throw std::runtime_error(owner + ".matrix: unknown value '" + name +
68
69
  "' (expected 'identity', 'rec601', 'rec709' or "
69
70
  "'rec2020')");
70
71
  }
71
72
 
72
- inline wgpu::ColorSpaceYCbCrRangeDawn parseRange(const std::string &name) {
73
+ inline wgpu::ColorSpaceYCbCrRangeDawn parseRange(const std::string &owner,
74
+ const std::string &name) {
73
75
  if (name == "identity") {
74
76
  return wgpu::ColorSpaceYCbCrRangeDawn::Identity;
75
77
  }
@@ -79,11 +81,12 @@ inline wgpu::ColorSpaceYCbCrRangeDawn parseRange(const std::string &name) {
79
81
  if (name == "full") {
80
82
  return wgpu::ColorSpaceYCbCrRangeDawn::Full;
81
83
  }
82
- throw std::runtime_error("sourceColorSpace.range: unknown value '" + name +
84
+ throw std::runtime_error(owner + ".range: unknown value '" + name +
83
85
  "' (expected 'identity', 'narrow' or 'full')");
84
86
  }
85
87
 
86
- inline wgpu::ColorSpacePrimariesDawn parsePrimaries(const std::string &name) {
88
+ inline wgpu::ColorSpacePrimariesDawn parsePrimaries(const std::string &owner,
89
+ const std::string &name) {
87
90
  if (name == "srgb") {
88
91
  return wgpu::ColorSpacePrimariesDawn::SRGB;
89
92
  }
@@ -99,13 +102,13 @@ inline wgpu::ColorSpacePrimariesDawn parsePrimaries(const std::string &name) {
99
102
  if (name == "display-p3") {
100
103
  return wgpu::ColorSpacePrimariesDawn::DisplayP3;
101
104
  }
102
- throw std::runtime_error("sourceColorSpace.primaries: unknown value '" +
103
- name +
105
+ throw std::runtime_error(owner + ".primaries: unknown value '" + name +
104
106
  "' (expected 'srgb', 'rec709', 'rec601', "
105
107
  "'rec2020' or 'display-p3')");
106
108
  }
107
109
 
108
- inline wgpu::ColorSpaceTransferDawn parseTransfer(const std::string &name) {
110
+ inline wgpu::ColorSpaceTransferDawn parseTransfer(const std::string &owner,
111
+ const std::string &name) {
109
112
  if (name == "identity") {
110
113
  return wgpu::ColorSpaceTransferDawn::Identity;
111
114
  }
@@ -127,13 +130,16 @@ inline wgpu::ColorSpaceTransferDawn parseTransfer(const std::string &name) {
127
130
  if (name == "bt-1886") {
128
131
  return wgpu::ColorSpaceTransferDawn::BT_1886;
129
132
  }
130
- throw std::runtime_error("sourceColorSpace.transfer: unknown value '" + name +
133
+ throw std::runtime_error(owner + ".transfer: unknown value '" + name +
131
134
  "' (expected 'identity', 'srgb', 'display-p3', "
132
135
  "'smpte-170m', 'hlg', 'pq' or 'bt-1886')");
133
136
  }
134
137
 
138
+ // `owner` names the member being parsed in the error messages
139
+ // ("sourceColorSpace", "colorSpace").
135
140
  inline VideoFrameColorSpace parse(jsi::Runtime &runtime,
136
- const jsi::Object &value) {
141
+ const jsi::Object &value,
142
+ const std::string &owner) {
137
143
  VideoFrameColorSpace colorSpace;
138
144
  auto member = [&](const char *name) -> std::optional<std::string> {
139
145
  if (!value.hasProperty(runtime, name)) {
@@ -146,16 +152,16 @@ inline VideoFrameColorSpace parse(jsi::Runtime &runtime,
146
152
  return prop.asString(runtime).utf8(runtime);
147
153
  };
148
154
  if (auto matrix = member("matrix")) {
149
- colorSpace.matrix = parseMatrix(*matrix);
155
+ colorSpace.matrix = parseMatrix(owner, *matrix);
150
156
  }
151
157
  if (auto range = member("range")) {
152
- colorSpace.range = parseRange(*range);
158
+ colorSpace.range = parseRange(owner, *range);
153
159
  }
154
160
  if (auto primaries = member("primaries")) {
155
- colorSpace.primaries = parsePrimaries(*primaries);
161
+ colorSpace.primaries = parsePrimaries(owner, *primaries);
156
162
  }
157
163
  if (auto transfer = member("transfer")) {
158
- colorSpace.transfer = parseTransfer(*transfer);
164
+ colorSpace.transfer = parseTransfer(owner, *transfer);
159
165
  }
160
166
  return colorSpace;
161
167
  }
@@ -204,7 +210,7 @@ struct JSIConverter<std::shared_ptr<rnwgpu::GPUExternalTextureDescriptor>> {
204
210
  auto prop = value.getProperty(runtime, "sourceColorSpace");
205
211
  if (prop.isObject()) {
206
212
  result->sourceColorSpace = external_texture_color_space::parse(
207
- runtime, prop.getObject(runtime));
213
+ runtime, prop.getObject(runtime), "sourceColorSpace");
208
214
  }
209
215
  }
210
216
  if (value.hasProperty(runtime, "rotation")) {
@@ -20,8 +20,9 @@ class RuntimeContext;
20
20
  * Represents a pending asynchronous WebGPU operation that can be converted into
21
21
  * a JavaScript Promise.
22
22
  *
23
- * The resolve and reject functions run on any thread (the instance's waiter
24
- * thread, usually) and never touch JSI: they hand the settling to the owning
23
+ * The resolve and reject functions run on any thread (whichever one Dawn
24
+ * completes the operation on) and never touch JSI: they hand the settling to
25
+ * the owning
25
26
  * RuntimeContext, which runs it on its runtime's own thread (see
26
27
  * RuntimeContext::post).
27
28
  */
@@ -0,0 +1,105 @@
1
+ #include "DeviceTicker.h"
2
+
3
+ #include <atomic>
4
+ #include <cstring>
5
+ #include <memory>
6
+ #include <utility>
7
+
8
+ #include "dawn/native/DawnNative.h"
9
+
10
+ #include "RuntimeContext.h"
11
+
12
+ namespace rnwgpu::async {
13
+
14
+ namespace {
15
+
16
+ bool hasToggle(const wgpu::Device &device, const char *name) {
17
+ for (const char *toggle : dawn::native::GetTogglesUsed(device.Get())) {
18
+ if (std::strcmp(toggle, name) == 0) {
19
+ return true;
20
+ }
21
+ }
22
+ return false;
23
+ }
24
+
25
+ } // namespace
26
+
27
+ DeviceTicker::DeviceTicker(wgpu::Device device,
28
+ std::weak_ptr<RuntimeContext> context, bool owned)
29
+ : _device(std::move(device)), _context(std::move(context)), _owned(owned),
30
+ _synchronized(
31
+ _device.HasFeature(wgpu::FeatureName::ImplicitDeviceSynchronization)),
32
+ _spontaneous(hasToggle(_device, "spontaneous_queue_events")) {}
33
+
34
+ std::shared_ptr<void> DeviceTicker::operationStarted() {
35
+ if (_spontaneous) {
36
+ return nullptr;
37
+ }
38
+ if (_synchronized) {
39
+ return DawnEventPump::shared().operationStarted({_device.Get(), nullptr},
40
+ poll());
41
+ }
42
+ auto context = _context.lock();
43
+ if (context == nullptr) {
44
+ // The runtime that could tick the device is gone, and its promises with
45
+ // it.
46
+ return nullptr;
47
+ }
48
+ return DawnEventPump::shared().operationStarted(
49
+ {_device.Get(), context.get()}, poll());
50
+ }
51
+
52
+ void DeviceTicker::workSubmitted() {
53
+ if (!_owned) {
54
+ return;
55
+ }
56
+ if (_synchronized) {
57
+ DawnEventPump::shared().workSubmitted({_device.Get(), nullptr}, poll());
58
+ return;
59
+ }
60
+ if (auto context = _context.lock()) {
61
+ DawnEventPump::shared().workSubmitted({_device.Get(), context.get()},
62
+ poll());
63
+ }
64
+ }
65
+
66
+ const DawnEventPump::Poll &DeviceTicker::poll() {
67
+ std::call_once(_pollOnce, [this] {
68
+ if (_synchronized) {
69
+ _poll = [device = _device]() {
70
+ return dawn::native::DeviceTick(device.Get());
71
+ };
72
+ return;
73
+ }
74
+ // The tick is the runtime thread's to make, so the pump posts it there:
75
+ // one at a time, so that a busy runtime does not find a pile of them,
76
+ // and without waking a runtime that polls its mailbox, which is polling
77
+ // already while it awaits a promise. What Dawn answers there is not
78
+ // waited for: the poll says there is work left, and the lazy polls
79
+ // after a submit are all made, a handful of them. The poll holds this
80
+ // ticker, and its device, weakly: their last reference must go on the
81
+ // runtime's thread, not on the pump's.
82
+ auto posted = std::make_shared<std::atomic<bool>>(false);
83
+ _poll = [weak = weak_from_this(), weakContext = _context, posted]() {
84
+ auto context = weakContext.lock();
85
+ if (context == nullptr || weak.expired()) {
86
+ return false;
87
+ }
88
+ if (posted->exchange(true, std::memory_order_acq_rel)) {
89
+ return true;
90
+ }
91
+ context->post(
92
+ [weak, posted](jsi::Runtime &) {
93
+ posted->store(false, std::memory_order_release);
94
+ if (auto self = weak.lock()) {
95
+ dawn::native::DeviceTick(self->_device.Get());
96
+ }
97
+ },
98
+ RuntimeContext::Wake::No);
99
+ return true;
100
+ };
101
+ });
102
+ return _poll;
103
+ }
104
+
105
+ } // namespace rnwgpu::async
@@ -0,0 +1,71 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <mutex>
5
+
6
+ #include "webgpu/webgpu_cpp.h"
7
+
8
+ #include "DawnEventPump.h"
9
+
10
+ namespace rnwgpu::async {
11
+
12
+ class RuntimeContext;
13
+
14
+ /**
15
+ * Has one device asked about its work (see DawnEventPump for why and when):
16
+ * what a poll of that device is, and which thread makes it. Made with the
17
+ * device's wrapper and shared with what starts asynchronous work on it (its
18
+ * queue, its buffers), which keeps the device alive with them, as in Dawn's
19
+ * Node binding.
20
+ *
21
+ * A poll is a tick of the device (dawn::native::DeviceTick), which never
22
+ * waits:
23
+ *
24
+ * - On the pump's thread when Dawn locks the device itself
25
+ * (ImplicitDeviceSynchronization, the default).
26
+ * - On the thread of the runtime the device was made on otherwise, the only
27
+ * one that may use it: the pump posts the tick there, one at a time.
28
+ *
29
+ * Which devices are polled:
30
+ *
31
+ * - While an operation is awaited (operationStarted): any device whose queue
32
+ * events do not complete by themselves, this library's or an imported one.
33
+ * Dawn tells with the device's spontaneous_queue_events toggle, which only
34
+ * Metal sets today: nothing polls for a promise there.
35
+ * - After a submit (workSubmitted): the devices this library made, on every
36
+ * backend. An imported device is its owner's to keep tidy.
37
+ */
38
+ class DeviceTicker : public std::enable_shared_from_this<DeviceTicker> {
39
+ public:
40
+ // `context`: the runtime the device's wrapper was made on. `owned`: whether
41
+ // this library made the device (requestDevice), rather than imported it.
42
+ DeviceTicker(wgpu::Device device, std::weak_ptr<RuntimeContext> context,
43
+ bool owned);
44
+
45
+ // An operation someone awaits is in flight on the device, its Dawn callback
46
+ // not run yet. The device is polled until the returned token goes; null
47
+ // when nothing needs to poll for it. Throws when a poll is needed and no
48
+ // thread could be had to make it. Any thread that may use the device.
49
+ [[nodiscard]] std::shared_ptr<void> operationStarted();
50
+
51
+ // queue.submit(): once nothing else is submitted for a while, the device
52
+ // is polled until Dawn has nothing left on it. Any thread.
53
+ void workSubmitted();
54
+
55
+ private:
56
+ // A poll of the device, made once: the pump copies it when it does not
57
+ // know the device yet.
58
+ const DawnEventPump::Poll &poll();
59
+
60
+ wgpu::Device _device;
61
+ std::weak_ptr<RuntimeContext> _context;
62
+ const bool _owned;
63
+ // Dawn locks the device itself: any thread may tick it.
64
+ const bool _synchronized;
65
+ // The device's queue events complete without anyone asking.
66
+ const bool _spontaneous;
67
+ std::once_flag _pollOnce;
68
+ DawnEventPump::Poll _poll;
69
+ };
70
+
71
+ } // namespace rnwgpu::async
@@ -1,22 +1,17 @@
1
1
  #include "RuntimeContext.h"
2
2
 
3
- #include <condition_variable>
4
- #include <cstdint>
5
- #include <deque>
6
3
  #include <memory>
4
+ #include <mutex>
7
5
  #include <stdexcept>
8
- #include <thread>
6
+ #include <string>
9
7
  #include <unordered_map>
10
8
  #include <utility>
11
9
  #include <vector>
12
10
 
13
- #if defined(__APPLE__) || defined(__ANDROID__)
14
- #include <pthread.h>
15
- #endif
16
-
17
11
  #include <ReactCommon/CallInvoker.h>
18
12
 
19
13
  #include "AsyncTaskHandle.h"
14
+ #include "DeviceTicker.h"
20
15
  #include "WGPULogger.h"
21
16
 
22
17
  namespace rnwgpu::async {
@@ -28,8 +23,8 @@ struct RuntimeData {
28
23
  constexpr const char *TAG = "RuntimeContext";
29
24
 
30
25
  // The main JS runtime and its CallInvoker, registered on install (again
31
- // after a reload) on the JS thread, and read from any thread: the waiter
32
- // thread posts through them.
26
+ // after a reload) on the JS thread, and read from any thread: whichever
27
+ // thread Dawn completes an operation on posts through them.
33
28
  std::mutex sMainMutex;
34
29
  jsi::Runtime *sMainRuntime = nullptr;
35
30
  std::shared_ptr<facebook::react::CallInvoker> sMainInvoker;
@@ -56,65 +51,42 @@ void logException(const char *what, const std::exception_ptr &error) {
56
51
  }
57
52
  }
58
53
 
59
- /**
60
- * The thread waiting on the futures of one instance: one future at a time,
61
- * in the order they were handed over, in Instance::WaitAny, which sleeps
62
- * until the GPU or Dawn's worker is done and then runs the callback. Never
63
- * destroyed: the instance it retains is shared by every runtime, and a
64
- * future may be outstanding during process teardown.
65
- */
66
- class Waiter {
54
+ // An operation's hold on the polling of its device (see DeviceTicker), which
55
+ // ends when its Dawn callback has settled the promise, on whichever thread
56
+ // that is, and at the latest when the callback goes.
57
+ class Polling {
67
58
  public:
68
- static Waiter &forInstance(const wgpu::Instance &instance) {
69
- static std::mutex registryMutex;
70
- static std::unordered_map<WGPUInstance, Waiter *> registry;
71
- std::lock_guard<std::mutex> lock(registryMutex);
72
- auto &slot = registry[instance.Get()];
73
- if (slot == nullptr) {
74
- slot = new Waiter(instance);
59
+ // Has the device polled, unless the operation is over already.
60
+ void start(const std::shared_ptr<DeviceTicker> &ticker) {
61
+ std::shared_ptr<void> token;
62
+ {
63
+ std::lock_guard<std::mutex> lock(_mutex);
64
+ if (_finished) {
65
+ return;
66
+ }
67
+ }
68
+ // Outside the lock: the pump is asked, and the callback may run
69
+ // meanwhile.
70
+ token = ticker->operationStarted();
71
+ std::lock_guard<std::mutex> lock(_mutex);
72
+ if (!_finished) {
73
+ _token = std::move(token);
75
74
  }
76
- return *slot;
77
75
  }
78
76
 
79
- void enqueue(wgpu::Future future) {
77
+ void finish() {
78
+ std::shared_ptr<void> token;
80
79
  {
81
80
  std::lock_guard<std::mutex> lock(_mutex);
82
- _futures.push_back(future);
81
+ _finished = true;
82
+ token.swap(_token);
83
83
  }
84
- _condition.notify_one();
85
84
  }
86
85
 
87
86
  private:
88
- explicit Waiter(wgpu::Instance instance) : _instance(std::move(instance)) {
89
- std::thread([this]() { run(); }).detach();
90
- }
91
-
92
- void run() {
93
- #if defined(__APPLE__)
94
- pthread_setname_np("RNWebGPU Waiter");
95
- #elif defined(__ANDROID__)
96
- pthread_setname_np(pthread_self(), "RNWebGPU Waiter");
97
- #endif
98
- for (;;) {
99
- wgpu::Future future;
100
- {
101
- std::unique_lock<std::mutex> lock(_mutex);
102
- _condition.wait(lock, [this]() { return !_futures.empty(); });
103
- future = _futures.front();
104
- _futures.pop_front();
105
- }
106
- auto status = _instance.WaitAny(future, UINT64_MAX);
107
- if (status != wgpu::WaitStatus::Success) {
108
- Logger::logToConsole("[%s] WaitAny failed with status %d", TAG,
109
- static_cast<int>(status));
110
- }
111
- }
112
- }
113
-
114
- wgpu::Instance _instance;
115
87
  std::mutex _mutex;
116
- std::condition_variable _condition;
117
- std::deque<wgpu::Future> _futures;
88
+ bool _finished = false;
89
+ std::shared_ptr<void> _token;
118
90
  };
119
91
  } // namespace
120
92
 
@@ -201,7 +173,9 @@ bool RuntimeContext::canSettle() const {
201
173
  return false;
202
174
  }
203
175
 
204
- AsyncTaskHandle RuntimeContext::postTask(const TaskCallback &callback) {
176
+ AsyncTaskHandle
177
+ RuntimeContext::postTask(const TaskCallback &callback,
178
+ const std::shared_ptr<DeviceTicker> &ticker) {
205
179
  if (!canSettle()) {
206
180
  throw std::runtime_error("Nothing can settle a promise on this runtime: "
207
181
  "react-native-webgpu is not installed on it.");
@@ -221,10 +195,25 @@ AsyncTaskHandle RuntimeContext::postTask(const TaskCallback &callback) {
221
195
 
222
196
  auto resolve = handle.createResolveFunction();
223
197
  auto reject = handle.createRejectFunction();
198
+ std::shared_ptr<Polling> polling;
199
+ if (ticker != nullptr) {
200
+ // The two functions end the polling too: Dawn's callback calls one of
201
+ // them, and nothing is left to learn about the operation then.
202
+ polling = std::make_shared<Polling>();
203
+ resolve = [polling, resolve = std::move(resolve)](
204
+ AsyncTaskHandle::ValueFactory factory) {
205
+ resolve(std::move(factory));
206
+ polling->finish();
207
+ };
208
+ reject = [polling, reject = std::move(reject)](std::string reason) {
209
+ reject(std::move(reason));
210
+ polling->finish();
211
+ };
212
+ }
224
213
  try {
225
214
  auto future = callback(resolve, reject);
226
- if (future.has_value()) {
227
- awaitFuture(*future);
215
+ if (future.has_value() && !complete(*future) && polling != nullptr) {
216
+ polling->start(ticker);
228
217
  }
229
218
  } catch (const std::exception &exception) {
230
219
  reject(exception.what());
@@ -234,20 +223,17 @@ AsyncTaskHandle RuntimeContext::postTask(const TaskCallback &callback) {
234
223
  return handle;
235
224
  }
236
225
 
237
- void RuntimeContext::awaitFuture(wgpu::Future future) {
238
- // Complete already (requestAdapter, popErrorScope, a lost device): the
239
- // callback runs here, and nothing waits.
240
- if (_instance.WaitAny(future, 0) == wgpu::WaitStatus::Success) {
241
- return;
242
- }
243
- Waiter::forInstance(_instance).enqueue(future);
226
+ bool RuntimeContext::complete(wgpu::Future future) {
227
+ // The zero timeout never waits. A future Dawn no longer knows is one
228
+ // whose callback has run, here or on another thread: Success too.
229
+ return _instance.WaitAny(future, 0) == wgpu::WaitStatus::Success;
244
230
  }
245
231
 
246
232
  void RuntimeContext::onTaskSettled() {
247
233
  _outstanding.fetch_sub(1, std::memory_order_acq_rel);
248
234
  }
249
235
 
250
- void RuntimeContext::post(Job job) {
236
+ void RuntimeContext::post(Job job, Wake wake) {
251
237
  switch (_kind) {
252
238
  case Kind::Main: {
253
239
  auto invoker = mainInvokerSlot();
@@ -263,7 +249,7 @@ void RuntimeContext::post(Job job) {
263
249
  std::lock_guard<std::mutex> lock(_mailboxMutex);
264
250
  _mailbox.push_back(std::move(job));
265
251
  }
266
- if (_kind == Kind::UI) {
252
+ if (_kind == Kind::UI && wake == Wake::Yes) {
267
253
  wakeUI();
268
254
  }
269
255
  return;
@@ -23,6 +23,8 @@ class CallInvoker;
23
23
 
24
24
  namespace rnwgpu::async {
25
25
 
26
+ class DeviceTicker;
27
+
26
28
  /**
27
29
  * How asynchronous WebGPU operations get back to the JS runtime that
28
30
  * requested them. One per (JS runtime, Dawn instance), made on first use and
@@ -31,17 +33,22 @@ namespace rnwgpu::async {
31
33
  * a device passed to importDevice() can live on another instance, which then
32
34
  * gets a context of its own.
33
35
  *
34
- * Waiting: Dawn operations are registered with CallbackMode::WaitAnyOnly, and
35
- * their futures handed to awaitFuture(). One already complete runs its
36
- * callback right there; the others go to a thread per instance that sleeps
37
- * in Instance::WaitAny until the GPU (or Dawn's worker) is done, then runs
38
- * the callback. Nothing polls meanwhile: neither the JS thread nor anyone
39
- * else calls ProcessEvents.
36
+ * Completion: nothing waits in Dawn (see DawnEventPump for why). Dawn
37
+ * operations are registered with CallbackMode::AllowSpontaneous, so that Dawn
38
+ * runs their callback as soon as it learns that they are done, on whichever
39
+ * thread that is: here in postTask() when the operation is complete already
40
+ * or once its commands are flushed, a Dawn worker (a pipeline compiled), the
41
+ * thread Metal reports a command buffer's completion on, or any thread that
42
+ * ticks the device, which a submit does. Where nothing reports the GPU's
43
+ * completions (Vulkan), the operation's device is ticked until the callback
44
+ * has run (see DeviceTicker).
40
45
  *
41
- * Settling: a callback runs on the waiter thread (or wherever a non-Dawn
46
+ * Settling: a callback runs on any of those threads, possibly inside a call
47
+ * into Dawn and with Dawn's device lock held (or wherever a non-Dawn
42
48
  * operation finishes, see GPUQueue::drawElementImageToTexture), so it never
43
- * touches JSI; it hands a settle action to post(), which runs it on the
44
- * runtime's own thread. How depends on the runtime:
49
+ * touches JSI nor Dawn; it hands a settle action to post(), which runs it on
50
+ * the runtime's own thread. Promises settle in the order their operations
51
+ * complete. How depends on the runtime:
45
52
  *
46
53
  * - The main React Native runtime: its CallInvoker (registerMainRuntime).
47
54
  * - Any other runtime (the Reanimated UI runtime, createWorkletRuntime, a
@@ -76,7 +83,7 @@ namespace rnwgpu::async {
76
83
  *
77
84
  * Threading contract: postTask() runs on the runtime's thread (it is the
78
85
  * entry point of every async method, called with the calling runtime, see
79
- * GPUBuffer::mapAsync); awaitFuture() and post() run on any thread.
86
+ * GPUBuffer::mapAsync); post() runs on any thread.
80
87
  */
81
88
  class RuntimeContext : public std::enable_shared_from_this<RuntimeContext> {
82
89
  public:
@@ -116,21 +123,27 @@ public:
116
123
 
117
124
  // Starts an asynchronous operation whose promise settles on this runtime:
118
125
  // `callback` gets the resolve and reject functions, starts the work, and
119
- // returns the Dawn future to wait for, if the work is Dawn's (it is awaited
120
- // like awaitFuture does). Called on the runtime's thread. Throws when
121
- // nothing could settle the promise (see canSettle).
122
- AsyncTaskHandle postTask(const TaskCallback &callback);
126
+ // returns its Dawn future, if the work is Dawn's. Dawn is asked about the
127
+ // future once, here (see complete), and `ticker`, the one of the
128
+ // operation's device, has the device asked from then on until one of the
129
+ // two functions is called. It may be left out for work that is complete as
130
+ // soon as it is started (requestAdapter, popErrorScope) and for work that
131
+ // is not Dawn's. Called on the runtime's thread. Throws when nothing could
132
+ // settle the promise (see canSettle).
133
+ AsyncTaskHandle postTask(const TaskCallback &callback,
134
+ const std::shared_ptr<DeviceTicker> &ticker = {});
123
135
 
124
136
  // Whether a job posted here reaches the runtime at all: false on the main
125
137
  // runtime before its CallInvoker is registered.
126
138
  bool canSettle() const;
127
139
 
128
- // Has the callback of `future` run: now, when it is complete already, else
129
- // on the instance's waiter thread once it is. Any thread.
130
- void awaitFuture(wgpu::Future future);
140
+ // Whether a posted job is worth waking the runtime for, ahead of what it
141
+ // does by itself. Only the UI runtime knows the difference (see wakeUI):
142
+ // the main runtime is always reached at once, the others only poll.
143
+ enum class Wake { Yes, No };
131
144
 
132
145
  // Runs `job` on this runtime's thread, later, with the runtime. Any thread.
133
- void post(Job job);
146
+ void post(Job job, Wake wake = Wake::Yes);
134
147
 
135
148
  // Invoked by a settle action once it has run, on the runtime's thread.
136
149
  void onTaskSettled();
@@ -141,6 +154,12 @@ private:
141
154
  static jsi::UUID runtimeDataUUID();
142
155
  static Kind kindOf(jsi::Runtime &runtime);
143
156
 
157
+ // Asks Dawn about `future` without waiting, and returns whether it is
158
+ // complete, its callback run. Dawn submits the commands the future waits
159
+ // for on the way (the clear of a buffer mapped for the first time, say),
160
+ // which nothing else would. On the runtime's thread.
161
+ bool complete(wgpu::Future future);
162
+
144
163
  // False when no tick can run on the runtime: it has no setTimeout, or
145
164
  // calling it threw.
146
165
  bool armTick(jsi::Runtime &runtime);
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_NativeBufferViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","NativeBufferView","resizeMode","onPixelSizeChange","ref","props","viewId","useState","RNWebGPU","allocateNativeBufferViewId","useImperativeHandle","present","frame","done","presentNativeBuffer","useLayoutEffect","retainNativeBufferView","releaseNativeBufferView","onNativePixelSizeChange","useCallback","event","width","height","nativeEvent","createElement","exports","useNativeBufferSize","debounceMs","size","setSize","current","useRef","timer","next","clearTimeout","settle","previous","setTimeout","useEffect"],"sourceRoot":"../../src","sources":["NativeBufferView.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAUA,IAAAC,gCAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAuE,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAR,uBAAA,YAAAA,CAAAI,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CAAA,gBAAAG,CAAA,OAAAW,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAG,CAAA,OAAAK,CAAA,IAAAD,CAAA,GAAAS,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAG,CAAA,OAAAK,CAAA,CAAAI,GAAA,IAAAJ,CAAA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AG,IAAI;MACpB,MAAMM,QAAQ,GAAGN,OAAO,CAACA,OAAO;MAChC,IACEM,QAAQ,KAAK,IAAI,IACjBA,QAAQ,CAACf,KAAK,KAAKY,IAAI,CAACZ,KAAK,IAC7Be,QAAQ,CAACd,MAAM,KAAKW,IAAI,CAACX,MAAM,EAC/B;QACAQ,OAAO,CAACA,OAAO,GAAGG,IAAI;QACtBJ,OAAO,CAACI,IAAI,CAAC;MACf;IACF,CAAC;IACD,IAAIH,OAAO,CAACA,OAAO,KAAK,IAAI,IAAIH,UAAU,IAAI,CAAC,EAAE;MAC/CQ,MAAM,CAAC,CAAC;IACV,CAAC,MAAM;MACLH,KAAK,CAACF,OAAO,GAAGO,UAAU,CAACF,MAAM,EAAER,UAAU,CAAC;IAChD;EACF,CAAC,EACD,CAACA,UAAU,CACb,CAAC;EAED,IAAAW,gBAAS,EACP,MAAM,MAAM;IACV,IAAIN,KAAK,CAACF,OAAO,KAAK,IAAI,EAAE;MAC1BI,YAAY,CAACF,KAAK,CAACF,OAAO,CAAC;IAC7B;EACF,CAAC,EACD,EACF,CAAC;EAED,OAAO;IAAEF,IAAI;IAAEzB;EAAkB,CAAC;AACpC,CAAC;AAACsB,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_NativeBufferViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","NativeBufferView","resizeMode","onPixelSizeChange","ref","props","viewId","useState","RNWebGPU","allocateNativeBufferViewId","useImperativeHandle","present","frame","done","presentNativeBuffer","useLayoutEffect","retainNativeBufferView","releaseNativeBufferView","onNativePixelSizeChange","useCallback","event","width","height","nativeEvent","createElement","exports","useNativeBufferSize","debounceMs","size","setSize","current","useRef","timer","next","clearTimeout","settle","previous","setTimeout","useEffect"],"sourceRoot":"../../src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