react-native-wgpu 0.2.10 → 0.3.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 (248) hide show
  1. package/README.md +155 -69
  2. package/android/CMakeLists.txt +4 -5
  3. package/android/build.gradle +7 -18
  4. package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +34 -10
  5. package/apple/MetalView.mm +0 -19
  6. package/apple/WebGPUModule.h +1 -9
  7. package/apple/WebGPUModule.mm +0 -3
  8. package/apple/WebGPUView.h +0 -3
  9. package/apple/WebGPUView.mm +0 -2
  10. package/cpp/WGPULogger.h +10 -0
  11. package/cpp/dawn/dawn_proc_table.h +1 -1
  12. package/cpp/dawn/webgpu.h +4855 -0
  13. package/cpp/dawn/webgpu_cpp.h +10168 -0
  14. package/cpp/dawn/wire/client/webgpu.h +354 -0
  15. package/cpp/dawn/wire/client/webgpu_cpp.h +10343 -0
  16. package/cpp/dawn/wire/client/webgpu_cpp_print.h +2715 -0
  17. package/cpp/jsi/RNFJSIConverter.h +17 -59
  18. package/cpp/rnwgpu/RNWebGPUManager.cpp +1 -9
  19. package/cpp/rnwgpu/api/GPU.cpp +51 -26
  20. package/cpp/rnwgpu/api/GPU.h +5 -18
  21. package/cpp/rnwgpu/api/GPUAdapter.cpp +75 -54
  22. package/cpp/rnwgpu/api/GPUAdapter.h +6 -6
  23. package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -1
  24. package/cpp/rnwgpu/api/GPUBindGroup.h +1 -3
  25. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -3
  26. package/cpp/rnwgpu/api/GPUBuffer.cpp +35 -32
  27. package/cpp/rnwgpu/api/GPUBuffer.h +9 -7
  28. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +5 -1
  29. package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -2
  30. package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -3
  31. package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -3
  32. package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -2
  33. package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -3
  34. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -3
  35. package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -3
  36. package/cpp/rnwgpu/api/GPUDevice.cpp +183 -128
  37. package/cpp/rnwgpu/api/GPUDevice.h +22 -21
  38. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -3
  39. package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -3
  40. package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -3
  41. package/cpp/rnwgpu/api/GPUQuerySet.h +1 -3
  42. package/cpp/rnwgpu/api/GPUQueue.cpp +19 -8
  43. package/cpp/rnwgpu/api/GPUQueue.h +7 -6
  44. package/cpp/rnwgpu/api/GPURenderBundle.h +1 -3
  45. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -3
  46. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -3
  47. package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -3
  48. package/cpp/rnwgpu/api/GPUSampler.h +1 -3
  49. package/cpp/rnwgpu/api/GPUShaderModule.cpp +42 -28
  50. package/cpp/rnwgpu/api/GPUShaderModule.h +6 -6
  51. package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -3
  52. package/cpp/rnwgpu/api/GPUTexture.h +1 -3
  53. package/cpp/rnwgpu/api/GPUTextureView.h +1 -3
  54. package/cpp/rnwgpu/api/RNWebGPU.h +1 -7
  55. package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
  56. package/cpp/rnwgpu/async/AsyncRunner.cpp +215 -0
  57. package/cpp/rnwgpu/async/AsyncRunner.h +53 -0
  58. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +181 -0
  59. package/cpp/rnwgpu/async/AsyncTaskHandle.h +55 -0
  60. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +23 -0
  61. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +22 -0
  62. package/cpp/webgpu/webgpu.h +5 -4827
  63. package/cpp/webgpu/webgpu_cpp.h +5 -10140
  64. package/cpp/{dawn/native/WebGPUBackend.h → webgpu/webgpu_cpp_print.h} +4 -20
  65. package/lib/commonjs/Canvas.js +6 -66
  66. package/lib/commonjs/Canvas.js.map +1 -1
  67. package/lib/commonjs/hooks.js +6 -42
  68. package/lib/commonjs/hooks.js.map +1 -1
  69. package/lib/module/Canvas.js +7 -67
  70. package/lib/module/Canvas.js.map +1 -1
  71. package/lib/module/hooks.js +5 -40
  72. package/lib/module/hooks.js.map +1 -1
  73. package/lib/typescript/lib/commonjs/hooks.d.ts +1 -5
  74. package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
  75. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  76. package/lib/typescript/lib/module/hooks.d.ts +1 -5
  77. package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
  78. package/lib/typescript/src/Canvas.d.ts +0 -1
  79. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  80. package/lib/typescript/src/hooks.d.ts +2 -7
  81. package/lib/typescript/src/hooks.d.ts.map +1 -1
  82. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  83. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  84. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  85. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  86. package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +5 -35
  87. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  88. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  89. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
  90. package/package.json +4 -3
  91. package/react-native-wgpu.podspec +12 -16
  92. package/src/Canvas.tsx +8 -69
  93. package/src/hooks.tsx +14 -48
  94. package/android/cpp/platform/ThreadUtils.cpp +0 -41
  95. package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +0 -23
  96. package/android/src/oldarch/com/webgpu/WebGPUViewManagerSpec.java +0 -12
  97. package/apple/WebGPUViewManager.mm +0 -24
  98. package/apple/platform/ThreadUtils.cpp +0 -34
  99. package/cpp/dawn/dawn_proc.h +0 -50
  100. package/cpp/dawn/dawn_thread_dispatch_proc.h +0 -47
  101. package/cpp/dawn/native/D3D11Backend.h +0 -77
  102. package/cpp/dawn/native/D3D12Backend.h +0 -68
  103. package/cpp/dawn/native/D3DBackend.h +0 -56
  104. package/cpp/dawn/native/MetalBackend.h +0 -56
  105. package/cpp/dawn/platform/DawnPlatform.h +0 -167
  106. package/cpp/dawn/platform/dawn_platform_export.h +0 -49
  107. package/cpp/platform/ThreadUtils.h +0 -30
  108. package/cpp/rnwgpu/api/AsyncRunner.h +0 -30
  109. package/cpp/threading/CallInvokerDispatcher.h +0 -37
  110. package/cpp/threading/Dispatcher.cpp +0 -55
  111. package/cpp/threading/Dispatcher.h +0 -93
  112. package/cpp/threading/ThreadPool.cpp +0 -88
  113. package/cpp/threading/ThreadPool.h +0 -53
  114. package/cpp/webgpu/webgpu_glfw.h +0 -88
  115. package/lib/typescript/src/__tests__/Alpha.spec.d.ts +0 -2
  116. package/lib/typescript/src/__tests__/Alpha.spec.d.ts.map +0 -1
  117. package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +0 -2
  118. package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +0 -1
  119. package/lib/typescript/src/__tests__/Buffer.spec.d.ts +0 -2
  120. package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +0 -1
  121. package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +0 -2
  122. package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +0 -1
  123. package/lib/typescript/src/__tests__/Constants.spec.d.ts +0 -2
  124. package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +0 -1
  125. package/lib/typescript/src/__tests__/Device.spec.d.ts +0 -2
  126. package/lib/typescript/src/__tests__/Device.spec.d.ts.map +0 -1
  127. package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts +0 -2
  128. package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts.map +0 -1
  129. package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +0 -2
  130. package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +0 -1
  131. package/lib/typescript/src/__tests__/GPU.spec.d.ts +0 -2
  132. package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +0 -1
  133. package/lib/typescript/src/__tests__/ImageData.spec.d.ts +0 -2
  134. package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +0 -1
  135. package/lib/typescript/src/__tests__/Shaders.spec.d.ts +0 -2
  136. package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +0 -1
  137. package/lib/typescript/src/__tests__/Texture.spec.d.ts +0 -2
  138. package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +0 -1
  139. package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +0 -3
  140. package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +0 -1
  141. package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +0 -29
  142. package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +0 -1
  143. package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +0 -5
  144. package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +0 -1
  145. package/lib/typescript/src/__tests__/components/cube.d.ts +0 -7
  146. package/lib/typescript/src/__tests__/components/cube.d.ts.map +0 -1
  147. package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +0 -22
  148. package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +0 -1
  149. package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +0 -12
  150. package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +0 -1
  151. package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +0 -7
  152. package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +0 -1
  153. package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +0 -6
  154. package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +0 -1
  155. package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +0 -6
  156. package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +0 -1
  157. package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +0 -10
  158. package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +0 -1
  159. package/lib/typescript/src/__tests__/components/triangle.d.ts +0 -3
  160. package/lib/typescript/src/__tests__/components/triangle.d.ts.map +0 -1
  161. package/lib/typescript/src/__tests__/config.d.ts +0 -3
  162. package/lib/typescript/src/__tests__/config.d.ts.map +0 -1
  163. package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +0 -2
  164. package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +0 -1
  165. package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +0 -2
  166. package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +0 -1
  167. package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +0 -2
  168. package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +0 -1
  169. package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +0 -2
  170. package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +0 -1
  171. package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +0 -2
  172. package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +0 -1
  173. package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +0 -2
  174. package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +0 -1
  175. package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +0 -2
  176. package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +0 -1
  177. package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +0 -2
  178. package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +0 -1
  179. package/lib/typescript/src/__tests__/globalSetup.d.ts +0 -3
  180. package/lib/typescript/src/__tests__/globalSetup.d.ts.map +0 -1
  181. package/lib/typescript/src/__tests__/globalTeardown.d.ts +0 -3
  182. package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +0 -1
  183. package/lib/typescript/src/__tests__/setup.d.ts +0 -63
  184. package/lib/typescript/src/__tests__/setup.d.ts.map +0 -1
  185. package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
  186. package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  187. package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
  188. package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
  189. package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
  190. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
  191. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
  192. package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
  193. package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  194. package/libs/dawn.json +0 -4670
  195. package/src/__tests__/Alpha.spec.ts +0 -28
  196. package/src/__tests__/ArrayBuffer.spec.ts +0 -76
  197. package/src/__tests__/Buffer.spec.ts +0 -357
  198. package/src/__tests__/ComputeShader.spec.ts +0 -375
  199. package/src/__tests__/Constants.spec.ts +0 -89
  200. package/src/__tests__/Device.spec.ts +0 -84
  201. package/src/__tests__/ErrorScope.spec.ts +0 -92
  202. package/src/__tests__/ExternalTexture.spec.ts +0 -284
  203. package/src/__tests__/GPU.spec.ts +0 -272
  204. package/src/__tests__/ImageData.spec.ts +0 -26
  205. package/src/__tests__/Shaders.spec.ts +0 -232
  206. package/src/__tests__/Texture.spec.ts +0 -197
  207. package/src/__tests__/assets/Di-3d.png +0 -0
  208. package/src/__tests__/components/Wireframe/Shaders.ts +0 -138
  209. package/src/__tests__/components/Wireframe/models.ts +0 -113
  210. package/src/__tests__/components/Wireframe/utils.ts +0 -22
  211. package/src/__tests__/components/cube.ts +0 -51
  212. package/src/__tests__/components/meshes/mesh.ts +0 -96
  213. package/src/__tests__/components/meshes/sphere.ts +0 -103
  214. package/src/__tests__/components/meshes/stanfordDragon.ts +0 -44
  215. package/src/__tests__/components/meshes/stanfordDragonData.ts +0 -5
  216. package/src/__tests__/components/meshes/teapot.ts +0 -13
  217. package/src/__tests__/components/meshes/utils.ts +0 -235
  218. package/src/__tests__/components/triangle.ts +0 -17
  219. package/src/__tests__/config.ts +0 -2
  220. package/src/__tests__/demos/ABuffer.spec.ts +0 -890
  221. package/src/__tests__/demos/Blur.spec.ts +0 -398
  222. package/src/__tests__/demos/Cube.spec.ts +0 -929
  223. package/src/__tests__/demos/FractalCube.spec.ts +0 -240
  224. package/src/__tests__/demos/OcclusionQuery.spec.ts +0 -376
  225. package/src/__tests__/demos/RenderBundles.spec.ts +0 -580
  226. package/src/__tests__/demos/Triangle.spec.ts +0 -266
  227. package/src/__tests__/demos/Wireframe.spec.ts +0 -188
  228. package/src/__tests__/globalSetup.ts +0 -45
  229. package/src/__tests__/globalTeardown.ts +0 -11
  230. package/src/__tests__/setup.ts +0 -423
  231. package/src/__tests__/snapshots/abuffer.png +0 -0
  232. package/src/__tests__/snapshots/asteroid.png +0 -0
  233. package/src/__tests__/snapshots/blur.png +0 -0
  234. package/src/__tests__/snapshots/buffer.png +0 -0
  235. package/src/__tests__/snapshots/constant-triangle.png +0 -0
  236. package/src/__tests__/snapshots/cube.png +0 -0
  237. package/src/__tests__/snapshots/f.png +0 -0
  238. package/src/__tests__/snapshots/f2.png +0 -0
  239. package/src/__tests__/snapshots/fractal-cubes.png +0 -0
  240. package/src/__tests__/snapshots/instanced-cubes.png +0 -0
  241. package/src/__tests__/snapshots/occlusion-query.png +0 -0
  242. package/src/__tests__/snapshots/ref.png +0 -0
  243. package/src/__tests__/snapshots/semi-opaque-cyan.png +0 -0
  244. package/src/__tests__/snapshots/texture.png +0 -0
  245. package/src/__tests__/snapshots/textured-cube.png +0 -0
  246. package/src/__tests__/snapshots/triangle-msaa.png +0 -0
  247. package/src/__tests__/snapshots/triangle.png +0 -0
  248. package/src/__tests__/snapshots/two-cube.png +0 -0
@@ -1,6 +1,5 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
3
  #include <memory>
5
4
  #include <string>
6
5
  #include <vector>
@@ -9,7 +8,8 @@
9
8
 
10
9
  #include "RNFHybridObject.h"
11
10
 
12
- #include "AsyncRunner.h"
11
+ #include "rnwgpu/async/AsyncRunner.h"
12
+ #include "rnwgpu/async/AsyncTaskHandle.h"
13
13
 
14
14
  #include "webgpu/webgpu_cpp.h"
15
15
 
@@ -25,7 +25,8 @@ namespace m = margelo;
25
25
 
26
26
  class GPUQueue : public m::HybridObject {
27
27
  public:
28
- explicit GPUQueue(wgpu::Queue instance, std::shared_ptr<AsyncRunner> async,
28
+ explicit GPUQueue(wgpu::Queue instance,
29
+ std::shared_ptr<async::AsyncRunner> async,
29
30
  std::string label)
30
31
  : HybridObject("GPUQueue"), _instance(instance), _async(async),
31
32
  _label(label) {}
@@ -34,7 +35,7 @@ public:
34
35
  std::string getBrand() { return _name; }
35
36
 
36
37
  void submit(std::vector<std::shared_ptr<GPUCommandBuffer>> commandBuffers);
37
- std::future<void> onSubmittedWorkDone();
38
+ async::AsyncTaskHandle onSubmittedWorkDone();
38
39
  void writeBuffer(std::shared_ptr<GPUBuffer> buffer, uint64_t bufferOffset,
39
40
  std::shared_ptr<ArrayBuffer> data,
40
41
  std::optional<uint64_t> dataOffsetElements,
@@ -72,8 +73,8 @@ public:
72
73
 
73
74
  private:
74
75
  wgpu::Queue _instance;
75
- std::shared_ptr<AsyncRunner> _async;
76
+ std::shared_ptr<async::AsyncRunner> _async;
76
77
  std::string _label;
77
78
  };
78
79
 
79
- } // namespace rnwgpu
80
+ } // namespace rnwgpu
@@ -6,8 +6,6 @@
6
6
 
7
7
  #include "RNFHybridObject.h"
8
8
 
9
- #include "AsyncRunner.h"
10
-
11
9
  #include "webgpu/webgpu_cpp.h"
12
10
 
13
11
  namespace rnwgpu {
@@ -42,4 +40,4 @@ private:
42
40
  std::string _label;
43
41
  };
44
42
 
45
- } // namespace rnwgpu
43
+ } // namespace rnwgpu
@@ -10,8 +10,6 @@
10
10
 
11
11
  #include "RNFHybridObject.h"
12
12
 
13
- #include "AsyncRunner.h"
14
-
15
13
  #include "webgpu/webgpu_cpp.h"
16
14
 
17
15
  #include "GPUBindGroup.h"
@@ -106,4 +104,4 @@ private:
106
104
  std::string _label;
107
105
  };
108
106
 
109
- } // namespace rnwgpu
107
+ } // namespace rnwgpu
@@ -10,8 +10,6 @@
10
10
 
11
11
  #include "RNFHybridObject.h"
12
12
 
13
- #include "AsyncRunner.h"
14
-
15
13
  #include "webgpu/webgpu_cpp.h"
16
14
 
17
15
  #include "GPUBindGroup.h"
@@ -127,4 +125,4 @@ private:
127
125
  std::string _label;
128
126
  };
129
127
 
130
- } // namespace rnwgpu
128
+ } // namespace rnwgpu
@@ -7,8 +7,6 @@
7
7
 
8
8
  #include "RNFHybridObject.h"
9
9
 
10
- #include "AsyncRunner.h"
11
-
12
10
  #include "webgpu/webgpu_cpp.h"
13
11
 
14
12
  #include "GPUBindGroupLayout.h"
@@ -58,4 +56,4 @@ private:
58
56
  friend class GPUDevice;
59
57
  };
60
58
 
61
- } // namespace rnwgpu
59
+ } // namespace rnwgpu
@@ -6,8 +6,6 @@
6
6
 
7
7
  #include "RNFHybridObject.h"
8
8
 
9
- #include "AsyncRunner.h"
10
-
11
9
  #include "webgpu/webgpu_cpp.h"
12
10
 
13
11
  namespace rnwgpu {
@@ -42,4 +40,4 @@ private:
42
40
  std::string _label;
43
41
  };
44
42
 
45
- } // namespace rnwgpu
43
+ } // namespace rnwgpu
@@ -3,36 +3,50 @@
3
3
  #include <memory>
4
4
  #include <utility>
5
5
 
6
+ #include "RNFJSIConverter.h"
7
+
6
8
  namespace rnwgpu {
7
9
 
8
- std::future<std::shared_ptr<GPUCompilationInfo>>
9
- GPUShaderModule::getCompilationInfo() {
10
- return _async->runAsync([=](wgpu::Instance *instance) {
11
- wgpu::CompilationInfo compilationInfo;
12
- auto result = std::make_shared<GPUCompilationInfo>();
13
- auto future = _instance.GetCompilationInfo(
14
- wgpu::CallbackMode::WaitAnyOnly,
15
- [&result](wgpu::CompilationInfoRequestStatus status,
16
- wgpu::CompilationInfo const *compilationInfo) {
17
- if (status == wgpu::CompilationInfoRequestStatus::Success &&
18
- compilationInfo) {
19
- for (size_t i = 0; i < compilationInfo->messageCount; ++i) {
20
- const auto &wgpuMessage = compilationInfo->messages[i];
21
- GPUCompilationMessage message;
22
- message.message =
23
- wgpuMessage.message.length ? wgpuMessage.message.data : "";
24
- message.type = wgpuMessage.type;
25
- message.lineNum = wgpuMessage.lineNum;
26
- message.linePos = wgpuMessage.linePos;
27
- message.offset = wgpuMessage.offset;
28
- message.length = wgpuMessage.length;
29
- result->_messages.push_back(std::move(message));
30
- }
31
- }
32
- });
33
- instance->WaitAny(future, UINT64_MAX);
34
- return result;
35
- });
10
+ async::AsyncTaskHandle GPUShaderModule::getCompilationInfo() {
11
+ auto module = _instance;
12
+
13
+ return _async->postTask(
14
+ [module](const async::AsyncTaskHandle::ResolveFunction &resolve,
15
+ const async::AsyncTaskHandle::RejectFunction &reject) {
16
+ auto result = std::make_shared<GPUCompilationInfo>();
17
+ module.GetCompilationInfo(
18
+ wgpu::CallbackMode::AllowProcessEvents,
19
+ [result, resolve,
20
+ reject](wgpu::CompilationInfoRequestStatus status,
21
+ const wgpu::CompilationInfo *compilationInfo) mutable {
22
+ if (status != wgpu::CompilationInfoRequestStatus::Success ||
23
+ compilationInfo == nullptr) {
24
+ reject("Failed to get compilation info");
25
+ return;
26
+ }
27
+
28
+ result->_messages.reserve(compilationInfo->messageCount);
29
+ for (size_t i = 0; i < compilationInfo->messageCount; ++i) {
30
+ const auto &wgpuMessage = compilationInfo->messages[i];
31
+ GPUCompilationMessage message;
32
+ message.message =
33
+ wgpuMessage.message.length ? wgpuMessage.message.data : "";
34
+ message.type = wgpuMessage.type;
35
+ message.lineNum = wgpuMessage.lineNum;
36
+ message.linePos = wgpuMessage.linePos;
37
+ message.offset = wgpuMessage.offset;
38
+ message.length = wgpuMessage.length;
39
+ result->_messages.push_back(std::move(message));
40
+ }
41
+
42
+ resolve(
43
+ [result = std::move(result)](jsi::Runtime &runtime) mutable {
44
+ return margelo::JSIConverter<
45
+ std::shared_ptr<GPUCompilationInfo>>::toJSI(runtime,
46
+ result);
47
+ });
48
+ });
49
+ });
36
50
  }
37
51
 
38
52
  } // namespace rnwgpu
@@ -1,6 +1,5 @@
1
1
  #pragma once
2
2
 
3
- #include <future>
4
3
  #include <memory>
5
4
  #include <string>
6
5
 
@@ -8,7 +7,8 @@
8
7
 
9
8
  #include "RNFHybridObject.h"
10
9
 
11
- #include "AsyncRunner.h"
10
+ #include "rnwgpu/async/AsyncRunner.h"
11
+ #include "rnwgpu/async/AsyncTaskHandle.h"
12
12
 
13
13
  #include "webgpu/webgpu_cpp.h"
14
14
 
@@ -21,7 +21,7 @@ namespace m = margelo;
21
21
  class GPUShaderModule : public m::HybridObject {
22
22
  public:
23
23
  explicit GPUShaderModule(wgpu::ShaderModule instance,
24
- std::shared_ptr<AsyncRunner> async,
24
+ std::shared_ptr<async::AsyncRunner> async,
25
25
  std::string label)
26
26
  : HybridObject("GPUShaderModule"), _instance(instance), _async(async),
27
27
  _label(label) {}
@@ -29,7 +29,7 @@ public:
29
29
  public:
30
30
  std::string getBrand() { return _name; }
31
31
 
32
- std::future<std::shared_ptr<GPUCompilationInfo>> getCompilationInfo();
32
+ async::AsyncTaskHandle getCompilationInfo();
33
33
 
34
34
  std::string getLabel() { return _label; }
35
35
  void setLabel(const std::string &label) {
@@ -58,8 +58,8 @@ public:
58
58
 
59
59
  private:
60
60
  wgpu::ShaderModule _instance;
61
- std::shared_ptr<AsyncRunner> _async;
61
+ std::shared_ptr<async::AsyncRunner> _async;
62
62
  std::string _label;
63
63
  };
64
64
 
65
- } // namespace rnwgpu
65
+ } // namespace rnwgpu
@@ -6,8 +6,6 @@
6
6
 
7
7
  #include "RNFHybridObject.h"
8
8
 
9
- #include "AsyncRunner.h"
10
-
11
9
  #include "webgpu/webgpu_cpp.h"
12
10
 
13
11
  namespace rnwgpu {
@@ -150,4 +148,4 @@ private:
150
148
  wgpu::Limits _instance;
151
149
  };
152
150
 
153
- } // namespace rnwgpu
151
+ } // namespace rnwgpu
@@ -8,8 +8,6 @@
8
8
 
9
9
  #include "RNFHybridObject.h"
10
10
 
11
- #include "AsyncRunner.h"
12
-
13
11
  #include "webgpu/webgpu_cpp.h"
14
12
 
15
13
  #include "GPUTextureView.h"
@@ -145,4 +143,4 @@ private:
145
143
  std::string _label;
146
144
  };
147
145
 
148
- } // namespace rnwgpu
146
+ } // namespace rnwgpu
@@ -6,8 +6,6 @@
6
6
 
7
7
  #include "RNFHybridObject.h"
8
8
 
9
- #include "AsyncRunner.h"
10
-
11
9
  #include "webgpu/webgpu_cpp.h"
12
10
 
13
11
  namespace rnwgpu {
@@ -42,4 +40,4 @@ private:
42
40
  std::string _label;
43
41
  };
44
42
 
45
- } // namespace rnwgpu
43
+ } // namespace rnwgpu
@@ -30,13 +30,7 @@ public:
30
30
 
31
31
  std::shared_ptr<GPU> getGPU() { return _gpu; }
32
32
 
33
- bool getFabric() {
34
- #ifdef RCT_NEW_ARCH_ENABLED
35
- return true;
36
- #else
37
- return false;
38
- #endif
39
- }
33
+ bool getFabric() { return true; }
40
34
 
41
35
  std::shared_ptr<GPUCanvasContext>
42
36
  MakeWebGPUCanvasContext(int contextId, float width, float height) {
@@ -0,0 +1,28 @@
1
+ #pragma once
2
+
3
+ #include <functional>
4
+ #include <memory>
5
+
6
+ #include <jsi/jsi.h>
7
+
8
+ namespace rnwgpu::async {
9
+
10
+ namespace jsi = facebook::jsi;
11
+
12
+ /**
13
+ * Abstract dispatcher used by the AsyncRunner to enqueue work back onto the
14
+ * JavaScript thread.
15
+ */
16
+ class AsyncDispatcher {
17
+ public:
18
+ using Work = std::function<void(jsi::Runtime &)>;
19
+
20
+ virtual ~AsyncDispatcher() = default;
21
+
22
+ /**
23
+ * Enqueue a unit of work that will be executed on the JavaScript thread.
24
+ */
25
+ virtual void post(Work work) = 0;
26
+ };
27
+
28
+ } // namespace rnwgpu::async
@@ -0,0 +1,215 @@
1
+ #include "AsyncRunner.h"
2
+
3
+ #include <chrono>
4
+ #include <stdexcept>
5
+ #include <utility>
6
+
7
+ #include "AsyncTaskHandle.h"
8
+ #include "WGPULogger.h"
9
+
10
+ namespace rnwgpu::async {
11
+
12
+ namespace {
13
+ struct RuntimeData {
14
+ std::shared_ptr<AsyncRunner> runner;
15
+ };
16
+ constexpr const char *TAG = "AsyncRunner";
17
+ } // namespace
18
+
19
+ AsyncRunner::AsyncRunner(wgpu::Instance instance,
20
+ std::shared_ptr<AsyncDispatcher> dispatcher)
21
+ : _instance(std::move(instance)), _dispatcher(std::move(dispatcher)),
22
+ _pendingTasks(0), _pumpTasks(0), _tickScheduled(false),
23
+ _lastTickTimeNs(0) {
24
+ if (!_dispatcher) {
25
+ throw std::runtime_error("AsyncRunner requires a valid dispatcher.");
26
+ }
27
+ Logger::logToConsole("[%s] Created runner (dispatcher=%p)", TAG,
28
+ _dispatcher.get());
29
+ }
30
+
31
+ std::shared_ptr<AsyncRunner> AsyncRunner::get(jsi::Runtime &runtime) {
32
+ auto data = runtime.getRuntimeData(runtimeDataUUID());
33
+ if (!data) {
34
+ return nullptr;
35
+ }
36
+ auto stored = std::static_pointer_cast<RuntimeData>(data);
37
+ return stored->runner;
38
+ }
39
+
40
+ std::shared_ptr<AsyncRunner>
41
+ AsyncRunner::getOrCreate(jsi::Runtime &runtime, wgpu::Instance instance,
42
+ std::shared_ptr<AsyncDispatcher> dispatcher) {
43
+ auto existing = get(runtime);
44
+ if (existing) {
45
+ return existing;
46
+ }
47
+
48
+ auto runner =
49
+ std::make_shared<AsyncRunner>(std::move(instance), std::move(dispatcher));
50
+ auto data = std::make_shared<RuntimeData>();
51
+ data->runner = runner;
52
+ runtime.setRuntimeData(runtimeDataUUID(), data);
53
+ return runner;
54
+ }
55
+
56
+ AsyncTaskHandle AsyncRunner::postTask(const TaskCallback &callback,
57
+ bool keepPumping) {
58
+ auto handle = AsyncTaskHandle::create(shared_from_this(), keepPumping);
59
+ if (!handle.valid()) {
60
+ throw std::runtime_error("Failed to create AsyncTaskHandle.");
61
+ }
62
+
63
+ _pendingTasks.fetch_add(1, std::memory_order_acq_rel);
64
+ if (keepPumping) {
65
+ _pumpTasks.fetch_add(1, std::memory_order_acq_rel);
66
+ }
67
+ requestTick();
68
+
69
+ Logger::logToConsole(
70
+ "[%s] postTask (keepPumping=%s, pending=%zu, pumping=%zu)", TAG,
71
+ keepPumping ? "true" : "false",
72
+ _pendingTasks.load(std::memory_order_acquire),
73
+ _pumpTasks.load(std::memory_order_acquire));
74
+
75
+ auto resolve = handle.createResolveFunction();
76
+ auto reject = handle.createRejectFunction();
77
+
78
+ try {
79
+ callback(resolve, reject);
80
+ } catch (const std::exception &exception) {
81
+ reject(exception.what());
82
+ } catch (...) {
83
+ reject("Unknown native error in AsyncRunner::postTask.");
84
+ }
85
+
86
+ return handle;
87
+ }
88
+
89
+ void AsyncRunner::requestTick() {
90
+ bool expected = false;
91
+ if (!_tickScheduled.compare_exchange_strong(expected, true,
92
+ std::memory_order_acq_rel)) {
93
+ return;
94
+ }
95
+
96
+ auto self = shared_from_this();
97
+ _dispatcher->post([self](jsi::Runtime &runtime) {
98
+ auto tickCallback = jsi::Function::createFromHostFunction(
99
+ runtime, jsi::PropNameID::forAscii(runtime, "AsyncRunnerTick"), 0,
100
+ [self](jsi::Runtime &runtime, const jsi::Value & /*thisValue*/,
101
+ const jsi::Value * /*args*/, size_t /*count*/) -> jsi::Value {
102
+ self->tick(runtime);
103
+ return jsi::Value::undefined();
104
+ });
105
+
106
+ #if defined(ANDROID) || defined(__ANDROID__)
107
+ auto global = runtime.global();
108
+ auto setImmediateValue = global.getProperty(runtime, "setImmediate");
109
+ constexpr auto kMinTickInterval = std::chrono::milliseconds(4);
110
+ const int64_t nowNs =
111
+ std::chrono::duration_cast<std::chrono::nanoseconds>(
112
+ std::chrono::steady_clock::now().time_since_epoch())
113
+ .count();
114
+ const int64_t lastNs =
115
+ self->_lastTickTimeNs.load(std::memory_order_acquire);
116
+ int delayMs = 0;
117
+ if (lastNs > 0) {
118
+ const int64_t elapsedNs = nowNs - lastNs;
119
+ const int64_t minIntervalNs = kMinTickInterval.count() * 1000000LL;
120
+ if (elapsedNs < minIntervalNs) {
121
+ const int64_t remainingNs = minIntervalNs - elapsedNs;
122
+ delayMs = static_cast<int>((remainingNs + 999999) / 1000000);
123
+ }
124
+ }
125
+
126
+ auto tryScheduleTimeout = [&](int ms) {
127
+ auto setTimeoutValue = global.getProperty(runtime, "setTimeout");
128
+ if (!setTimeoutValue.isObject()) {
129
+ return false;
130
+ }
131
+ auto setTimeoutObj = setTimeoutValue.asObject(runtime);
132
+ if (!setTimeoutObj.isFunction(runtime)) {
133
+ return false;
134
+ }
135
+ Logger::logToConsole("[%s] requestTick scheduled via setTimeout(%d)", TAG,
136
+ ms);
137
+ auto setTimeoutFn = setTimeoutObj.asFunction(runtime);
138
+ jsi::Value callbackArg(runtime, tickCallback);
139
+ jsi::Value delayArg(static_cast<double>(ms));
140
+ setTimeoutFn.call(runtime, callbackArg, delayArg);
141
+ return true;
142
+ };
143
+
144
+ if (delayMs > 0) {
145
+ if (tryScheduleTimeout(delayMs)) {
146
+ return;
147
+ }
148
+ // If setTimeout unavailable fall through to immediate scheduling.
149
+ }
150
+
151
+ if (setImmediateValue.isObject()) {
152
+ auto setImmediateObj = setImmediateValue.asObject(runtime);
153
+ if (setImmediateObj.isFunction(runtime)) {
154
+ Logger::logToConsole("[%s] requestTick scheduled via setImmediate",
155
+ TAG);
156
+ auto setImmediateFn = setImmediateObj.asFunction(runtime);
157
+ jsi::Value callbackArg(runtime, tickCallback);
158
+ setImmediateFn.call(runtime, callbackArg);
159
+ return;
160
+ }
161
+ }
162
+
163
+ int timeoutDelayMs = delayMs > 0 ? delayMs : 0;
164
+ if (tryScheduleTimeout(timeoutDelayMs)) {
165
+ return;
166
+ }
167
+
168
+ Logger::logToConsole("[%s] requestTick scheduled via microtask fallback",
169
+ TAG);
170
+ runtime.queueMicrotask(std::move(tickCallback));
171
+ #else
172
+ Logger::logToConsole("[%s] requestTick scheduled microtask (non-Android)",
173
+ TAG);
174
+ runtime.queueMicrotask(std::move(tickCallback));
175
+ #endif
176
+ });
177
+ }
178
+
179
+ void AsyncRunner::tick(jsi::Runtime & /*runtime*/) {
180
+ _tickScheduled.store(false, std::memory_order_release);
181
+ _instance.ProcessEvents();
182
+ const auto nowNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
183
+ std::chrono::steady_clock::now().time_since_epoch())
184
+ .count();
185
+ _lastTickTimeNs.store(nowNs, std::memory_order_release);
186
+ Logger::logToConsole("[%s] tick processed events (pending=%zu, pumping=%zu)",
187
+ TAG, _pendingTasks.load(std::memory_order_acquire),
188
+ _pumpTasks.load(std::memory_order_acquire));
189
+ if (_pumpTasks.load(std::memory_order_acquire) > 0) {
190
+ requestTick();
191
+ }
192
+ }
193
+
194
+ void AsyncRunner::onTaskSettled(bool keepPumping) {
195
+ _pendingTasks.fetch_sub(1, std::memory_order_acq_rel);
196
+ if (keepPumping) {
197
+ _pumpTasks.fetch_sub(1, std::memory_order_acq_rel);
198
+ }
199
+ Logger::logToConsole(
200
+ "[%s] onTaskSettled (keepPumping=%s, pending=%zu, pumping=%zu)", TAG,
201
+ keepPumping ? "true" : "false",
202
+ _pendingTasks.load(std::memory_order_acquire),
203
+ _pumpTasks.load(std::memory_order_acquire));
204
+ }
205
+
206
+ std::shared_ptr<AsyncDispatcher> AsyncRunner::dispatcher() const {
207
+ return _dispatcher;
208
+ }
209
+
210
+ jsi::UUID AsyncRunner::runtimeDataUUID() {
211
+ static const auto uuid = jsi::UUID();
212
+ return uuid;
213
+ }
214
+
215
+ } // namespace rnwgpu::async
@@ -0,0 +1,53 @@
1
+ #pragma once
2
+
3
+ #include <atomic>
4
+ #include <cstdint>
5
+ #include <functional>
6
+ #include <memory>
7
+
8
+ #include <jsi/jsi.h>
9
+
10
+ #include "AsyncDispatcher.h"
11
+ #include "AsyncTaskHandle.h"
12
+
13
+ #include "webgpu/webgpu_cpp.h"
14
+
15
+ namespace jsi = facebook::jsi;
16
+
17
+ namespace rnwgpu::async {
18
+
19
+ class AsyncRunner : public std::enable_shared_from_this<AsyncRunner> {
20
+ public:
21
+ using TaskCallback =
22
+ std::function<void(const AsyncTaskHandle::ResolveFunction &,
23
+ const AsyncTaskHandle::RejectFunction &)>;
24
+
25
+ AsyncRunner(wgpu::Instance instance,
26
+ std::shared_ptr<AsyncDispatcher> dispatcher);
27
+
28
+ static std::shared_ptr<AsyncRunner> get(jsi::Runtime &runtime);
29
+ static std::shared_ptr<AsyncRunner>
30
+ getOrCreate(jsi::Runtime &runtime, wgpu::Instance instance,
31
+ std::shared_ptr<AsyncDispatcher> dispatcher);
32
+
33
+ AsyncTaskHandle postTask(const TaskCallback &callback,
34
+ bool keepPumping = true);
35
+
36
+ void requestTick();
37
+ void tick(jsi::Runtime &runtime);
38
+ void onTaskSettled(bool keepPumping);
39
+
40
+ std::shared_ptr<AsyncDispatcher> dispatcher() const;
41
+
42
+ private:
43
+ static jsi::UUID runtimeDataUUID();
44
+
45
+ wgpu::Instance _instance;
46
+ std::shared_ptr<AsyncDispatcher> _dispatcher;
47
+ std::atomic<size_t> _pendingTasks;
48
+ std::atomic<size_t> _pumpTasks;
49
+ std::atomic<bool> _tickScheduled;
50
+ std::atomic<int64_t> _lastTickTimeNs;
51
+ };
52
+
53
+ } // namespace rnwgpu::async