react-native-wgpu 0.2.10 → 0.3.1

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 (258) hide show
  1. package/README.md +155 -69
  2. package/android/CMakeLists.txt +5 -7
  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/RNFHybridObject.cpp +8 -4
  18. package/cpp/jsi/RNFHybridObject.h +7 -2
  19. package/cpp/jsi/RNFJSIConverter.h +13 -102
  20. package/cpp/jsi/RNFJSIHelper.h +5 -3
  21. package/cpp/jsi/RNFRuntimeState.cpp +18 -0
  22. package/cpp/jsi/RNFRuntimeState.h +106 -0
  23. package/cpp/rnwgpu/RNWebGPUManager.cpp +1 -9
  24. package/cpp/rnwgpu/api/GPU.cpp +51 -26
  25. package/cpp/rnwgpu/api/GPU.h +5 -18
  26. package/cpp/rnwgpu/api/GPUAdapter.cpp +79 -54
  27. package/cpp/rnwgpu/api/GPUAdapter.h +6 -6
  28. package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -1
  29. package/cpp/rnwgpu/api/GPUBindGroup.h +1 -3
  30. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -3
  31. package/cpp/rnwgpu/api/GPUBuffer.cpp +35 -32
  32. package/cpp/rnwgpu/api/GPUBuffer.h +9 -7
  33. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +5 -1
  34. package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -2
  35. package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -3
  36. package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -3
  37. package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -2
  38. package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -3
  39. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -3
  40. package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -3
  41. package/cpp/rnwgpu/api/GPUDevice.cpp +183 -128
  42. package/cpp/rnwgpu/api/GPUDevice.h +22 -21
  43. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -3
  44. package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -3
  45. package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -3
  46. package/cpp/rnwgpu/api/GPUQuerySet.h +1 -3
  47. package/cpp/rnwgpu/api/GPUQueue.cpp +19 -8
  48. package/cpp/rnwgpu/api/GPUQueue.h +7 -6
  49. package/cpp/rnwgpu/api/GPURenderBundle.h +1 -3
  50. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -3
  51. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -3
  52. package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -3
  53. package/cpp/rnwgpu/api/GPUSampler.h +1 -3
  54. package/cpp/rnwgpu/api/GPUShaderModule.cpp +42 -28
  55. package/cpp/rnwgpu/api/GPUShaderModule.h +6 -6
  56. package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -3
  57. package/cpp/rnwgpu/api/GPUTexture.h +1 -3
  58. package/cpp/rnwgpu/api/GPUTextureView.h +1 -3
  59. package/cpp/rnwgpu/api/RNWebGPU.h +1 -7
  60. package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
  61. package/cpp/rnwgpu/async/AsyncRunner.cpp +215 -0
  62. package/cpp/rnwgpu/async/AsyncRunner.h +53 -0
  63. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +181 -0
  64. package/cpp/rnwgpu/async/AsyncTaskHandle.h +55 -0
  65. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +23 -0
  66. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +22 -0
  67. package/cpp/webgpu/webgpu.h +5 -4827
  68. package/cpp/webgpu/webgpu_cpp.h +5 -10140
  69. package/cpp/{dawn/native/WebGPUBackend.h → webgpu/webgpu_cpp_print.h} +4 -20
  70. package/lib/commonjs/Canvas.js +6 -66
  71. package/lib/commonjs/Canvas.js.map +1 -1
  72. package/lib/commonjs/hooks.js +6 -42
  73. package/lib/commonjs/hooks.js.map +1 -1
  74. package/lib/module/Canvas.js +7 -67
  75. package/lib/module/Canvas.js.map +1 -1
  76. package/lib/module/hooks.js +5 -40
  77. package/lib/module/hooks.js.map +1 -1
  78. package/lib/typescript/lib/commonjs/hooks.d.ts +1 -5
  79. package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
  80. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  81. package/lib/typescript/lib/module/hooks.d.ts +1 -5
  82. package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
  83. package/lib/typescript/src/Canvas.d.ts +0 -1
  84. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  85. package/lib/typescript/src/hooks.d.ts +2 -7
  86. package/lib/typescript/src/hooks.d.ts.map +1 -1
  87. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  88. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  89. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  90. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  91. package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +5 -35
  92. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  93. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  94. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
  95. package/package.json +4 -3
  96. package/react-native-wgpu.podspec +12 -16
  97. package/src/Canvas.tsx +8 -69
  98. package/src/hooks.tsx +14 -48
  99. package/android/cpp/platform/ThreadUtils.cpp +0 -41
  100. package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +0 -23
  101. package/android/src/oldarch/com/webgpu/WebGPUViewManagerSpec.java +0 -12
  102. package/apple/WebGPUViewManager.mm +0 -24
  103. package/apple/platform/ThreadUtils.cpp +0 -34
  104. package/cpp/dawn/dawn_proc.h +0 -50
  105. package/cpp/dawn/dawn_thread_dispatch_proc.h +0 -47
  106. package/cpp/dawn/native/D3D11Backend.h +0 -77
  107. package/cpp/dawn/native/D3D12Backend.h +0 -68
  108. package/cpp/dawn/native/D3DBackend.h +0 -56
  109. package/cpp/dawn/native/MetalBackend.h +0 -56
  110. package/cpp/dawn/platform/DawnPlatform.h +0 -167
  111. package/cpp/dawn/platform/dawn_platform_export.h +0 -49
  112. package/cpp/jsi/RNFRuntimeCache.cpp +0 -57
  113. package/cpp/jsi/RNFRuntimeCache.h +0 -79
  114. package/cpp/jsi/RNFWorkletRuntimeCollector.h +0 -43
  115. package/cpp/jsi/RNFWorkletRuntimeRegistry.cpp +0 -12
  116. package/cpp/jsi/RNFWorkletRuntimeRegistry.h +0 -44
  117. package/cpp/platform/ThreadUtils.h +0 -30
  118. package/cpp/rnwgpu/api/AsyncRunner.h +0 -30
  119. package/cpp/threading/CallInvokerDispatcher.h +0 -37
  120. package/cpp/threading/Dispatcher.cpp +0 -55
  121. package/cpp/threading/Dispatcher.h +0 -93
  122. package/cpp/threading/ThreadPool.cpp +0 -88
  123. package/cpp/threading/ThreadPool.h +0 -53
  124. package/cpp/webgpu/webgpu_glfw.h +0 -88
  125. package/lib/typescript/src/__tests__/Alpha.spec.d.ts +0 -2
  126. package/lib/typescript/src/__tests__/Alpha.spec.d.ts.map +0 -1
  127. package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +0 -2
  128. package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +0 -1
  129. package/lib/typescript/src/__tests__/Buffer.spec.d.ts +0 -2
  130. package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +0 -1
  131. package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +0 -2
  132. package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +0 -1
  133. package/lib/typescript/src/__tests__/Constants.spec.d.ts +0 -2
  134. package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +0 -1
  135. package/lib/typescript/src/__tests__/Device.spec.d.ts +0 -2
  136. package/lib/typescript/src/__tests__/Device.spec.d.ts.map +0 -1
  137. package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts +0 -2
  138. package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts.map +0 -1
  139. package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +0 -2
  140. package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +0 -1
  141. package/lib/typescript/src/__tests__/GPU.spec.d.ts +0 -2
  142. package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +0 -1
  143. package/lib/typescript/src/__tests__/ImageData.spec.d.ts +0 -2
  144. package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +0 -1
  145. package/lib/typescript/src/__tests__/Shaders.spec.d.ts +0 -2
  146. package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +0 -1
  147. package/lib/typescript/src/__tests__/Texture.spec.d.ts +0 -2
  148. package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +0 -1
  149. package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +0 -3
  150. package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +0 -1
  151. package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +0 -29
  152. package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +0 -1
  153. package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +0 -5
  154. package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +0 -1
  155. package/lib/typescript/src/__tests__/components/cube.d.ts +0 -7
  156. package/lib/typescript/src/__tests__/components/cube.d.ts.map +0 -1
  157. package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +0 -22
  158. package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +0 -1
  159. package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +0 -12
  160. package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +0 -1
  161. package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +0 -7
  162. package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +0 -1
  163. package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +0 -6
  164. package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +0 -1
  165. package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +0 -6
  166. package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +0 -1
  167. package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +0 -10
  168. package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +0 -1
  169. package/lib/typescript/src/__tests__/components/triangle.d.ts +0 -3
  170. package/lib/typescript/src/__tests__/components/triangle.d.ts.map +0 -1
  171. package/lib/typescript/src/__tests__/config.d.ts +0 -3
  172. package/lib/typescript/src/__tests__/config.d.ts.map +0 -1
  173. package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +0 -2
  174. package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +0 -1
  175. package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +0 -2
  176. package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +0 -1
  177. package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +0 -2
  178. package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +0 -1
  179. package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +0 -2
  180. package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +0 -1
  181. package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +0 -2
  182. package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +0 -1
  183. package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +0 -2
  184. package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +0 -1
  185. package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +0 -2
  186. package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +0 -1
  187. package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +0 -2
  188. package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +0 -1
  189. package/lib/typescript/src/__tests__/globalSetup.d.ts +0 -3
  190. package/lib/typescript/src/__tests__/globalSetup.d.ts.map +0 -1
  191. package/lib/typescript/src/__tests__/globalTeardown.d.ts +0 -3
  192. package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +0 -1
  193. package/lib/typescript/src/__tests__/setup.d.ts +0 -63
  194. package/lib/typescript/src/__tests__/setup.d.ts.map +0 -1
  195. package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
  196. package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  197. package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
  198. package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
  199. package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
  200. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
  201. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
  202. package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
  203. package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  204. package/libs/dawn.json +0 -4670
  205. package/src/__tests__/Alpha.spec.ts +0 -28
  206. package/src/__tests__/ArrayBuffer.spec.ts +0 -76
  207. package/src/__tests__/Buffer.spec.ts +0 -357
  208. package/src/__tests__/ComputeShader.spec.ts +0 -375
  209. package/src/__tests__/Constants.spec.ts +0 -89
  210. package/src/__tests__/Device.spec.ts +0 -84
  211. package/src/__tests__/ErrorScope.spec.ts +0 -92
  212. package/src/__tests__/ExternalTexture.spec.ts +0 -284
  213. package/src/__tests__/GPU.spec.ts +0 -272
  214. package/src/__tests__/ImageData.spec.ts +0 -26
  215. package/src/__tests__/Shaders.spec.ts +0 -232
  216. package/src/__tests__/Texture.spec.ts +0 -197
  217. package/src/__tests__/assets/Di-3d.png +0 -0
  218. package/src/__tests__/components/Wireframe/Shaders.ts +0 -138
  219. package/src/__tests__/components/Wireframe/models.ts +0 -113
  220. package/src/__tests__/components/Wireframe/utils.ts +0 -22
  221. package/src/__tests__/components/cube.ts +0 -51
  222. package/src/__tests__/components/meshes/mesh.ts +0 -96
  223. package/src/__tests__/components/meshes/sphere.ts +0 -103
  224. package/src/__tests__/components/meshes/stanfordDragon.ts +0 -44
  225. package/src/__tests__/components/meshes/stanfordDragonData.ts +0 -5
  226. package/src/__tests__/components/meshes/teapot.ts +0 -13
  227. package/src/__tests__/components/meshes/utils.ts +0 -235
  228. package/src/__tests__/components/triangle.ts +0 -17
  229. package/src/__tests__/config.ts +0 -2
  230. package/src/__tests__/demos/ABuffer.spec.ts +0 -890
  231. package/src/__tests__/demos/Blur.spec.ts +0 -398
  232. package/src/__tests__/demos/Cube.spec.ts +0 -929
  233. package/src/__tests__/demos/FractalCube.spec.ts +0 -240
  234. package/src/__tests__/demos/OcclusionQuery.spec.ts +0 -376
  235. package/src/__tests__/demos/RenderBundles.spec.ts +0 -580
  236. package/src/__tests__/demos/Triangle.spec.ts +0 -266
  237. package/src/__tests__/demos/Wireframe.spec.ts +0 -188
  238. package/src/__tests__/globalSetup.ts +0 -45
  239. package/src/__tests__/globalTeardown.ts +0 -11
  240. package/src/__tests__/setup.ts +0 -423
  241. package/src/__tests__/snapshots/abuffer.png +0 -0
  242. package/src/__tests__/snapshots/asteroid.png +0 -0
  243. package/src/__tests__/snapshots/blur.png +0 -0
  244. package/src/__tests__/snapshots/buffer.png +0 -0
  245. package/src/__tests__/snapshots/constant-triangle.png +0 -0
  246. package/src/__tests__/snapshots/cube.png +0 -0
  247. package/src/__tests__/snapshots/f.png +0 -0
  248. package/src/__tests__/snapshots/f2.png +0 -0
  249. package/src/__tests__/snapshots/fractal-cubes.png +0 -0
  250. package/src/__tests__/snapshots/instanced-cubes.png +0 -0
  251. package/src/__tests__/snapshots/occlusion-query.png +0 -0
  252. package/src/__tests__/snapshots/ref.png +0 -0
  253. package/src/__tests__/snapshots/semi-opaque-cyan.png +0 -0
  254. package/src/__tests__/snapshots/texture.png +0 -0
  255. package/src/__tests__/snapshots/textured-cube.png +0 -0
  256. package/src/__tests__/snapshots/triangle-msaa.png +0 -0
  257. package/src/__tests__/snapshots/triangle.png +0 -0
  258. package/src/__tests__/snapshots/two-cube.png +0 -0
@@ -1,56 +0,0 @@
1
- // Copyright 2023 The Dawn & Tint Authors
2
- //
3
- // Redistribution and use in source and binary forms, with or without
4
- // modification, are permitted provided that the following conditions are met:
5
- //
6
- // 1. Redistributions of source code must retain the above copyright notice, this
7
- // list of conditions and the following disclaimer.
8
- //
9
- // 2. Redistributions in binary form must reproduce the above copyright notice,
10
- // this list of conditions and the following disclaimer in the documentation
11
- // and/or other materials provided with the distribution.
12
- //
13
- // 3. Neither the name of the copyright holder nor the names of its
14
- // contributors may be used to endorse or promote products derived from
15
- // this software without specific prior written permission.
16
- //
17
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
- // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- #ifndef INCLUDE_DAWN_NATIVE_D3DBACKEND_H_
29
- #define INCLUDE_DAWN_NATIVE_D3DBACKEND_H_
30
-
31
- #include <dxgi1_4.h>
32
- #include <webgpu/webgpu_cpp_chained_struct.h>
33
- #include <wrl/client.h>
34
-
35
- #include <memory>
36
- #include <vector>
37
-
38
- #include "dawn/native/DawnNative.h"
39
-
40
- namespace dawn::native::d3d {
41
-
42
- DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<IDXGIAdapter> GetDXGIAdapter(WGPUAdapter adapter);
43
-
44
- // Can be chained in WGPURequestAdapterOptions
45
- struct DAWN_NATIVE_EXPORT RequestAdapterOptionsLUID : wgpu::ChainedStruct {
46
- RequestAdapterOptionsLUID();
47
-
48
- ::LUID adapterLUID;
49
- };
50
-
51
- // Chrome uses 0 as acquire key.
52
- static constexpr uint64_t kDXGIKeyedMutexAcquireKey = 0;
53
-
54
- } // namespace dawn::native::d3d
55
-
56
- #endif // INCLUDE_DAWN_NATIVE_D3DBACKEND_H_
@@ -1,56 +0,0 @@
1
- // Copyright 2018 The Dawn & Tint Authors
2
- //
3
- // Redistribution and use in source and binary forms, with or without
4
- // modification, are permitted provided that the following conditions are met:
5
- //
6
- // 1. Redistributions of source code must retain the above copyright notice, this
7
- // list of conditions and the following disclaimer.
8
- //
9
- // 2. Redistributions in binary form must reproduce the above copyright notice,
10
- // this list of conditions and the following disclaimer in the documentation
11
- // and/or other materials provided with the distribution.
12
- //
13
- // 3. Neither the name of the copyright holder nor the names of its
14
- // contributors may be used to endorse or promote products derived from
15
- // this software without specific prior written permission.
16
- //
17
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
- // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- #ifndef INCLUDE_DAWN_NATIVE_METALBACKEND_H_
29
- #define INCLUDE_DAWN_NATIVE_METALBACKEND_H_
30
-
31
- #include <webgpu/webgpu.h>
32
-
33
- #include "dawn/native/dawn_native_export.h"
34
-
35
- #if defined(__OBJC__)
36
- #import <Metal/Metal.h>
37
- #endif
38
-
39
- namespace dawn::native::metal {
40
-
41
- // When making Metal interop with other APIs, we need to be careful that QueueSubmit doesn't
42
- // mean that the operations will be visible to other APIs/Metal devices right away. macOS
43
- // does have a global queue of graphics operations, but the command buffers are inserted there
44
- // when they are "scheduled". Submitting other operations before the command buffer is
45
- // scheduled could lead to races in who gets scheduled first and incorrect rendering.
46
- // TODO(crbug.com/444702048): Remove after migrating Chromium to commands scheduled futures.
47
- DAWN_NATIVE_EXPORT void WaitForCommandsToBeScheduled(WGPUDevice device);
48
-
49
- #if defined(__OBJC__)
50
- // Return the MTLDevice corresponding to the WGPUDevice.
51
- DAWN_NATIVE_EXPORT id<MTLDevice> GetMTLDevice(WGPUDevice device);
52
- #endif
53
-
54
- } // namespace dawn::native::metal
55
-
56
- #endif // INCLUDE_DAWN_NATIVE_METALBACKEND_H_
@@ -1,167 +0,0 @@
1
- // Copyright 2019 The Dawn & Tint Authors
2
- //
3
- // Redistribution and use in source and binary forms, with or without
4
- // modification, are permitted provided that the following conditions are met:
5
- //
6
- // 1. Redistributions of source code must retain the above copyright notice, this
7
- // list of conditions and the following disclaimer.
8
- //
9
- // 2. Redistributions in binary form must reproduce the above copyright notice,
10
- // this list of conditions and the following disclaimer in the documentation
11
- // and/or other materials provided with the distribution.
12
- //
13
- // 3. Neither the name of the copyright holder nor the names of its
14
- // contributors may be used to endorse or promote products derived from
15
- // this software without specific prior written permission.
16
- //
17
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
- // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- #ifndef INCLUDE_DAWN_PLATFORM_DAWNPLATFORM_H_
29
- #define INCLUDE_DAWN_PLATFORM_DAWNPLATFORM_H_
30
-
31
- #include <webgpu/webgpu.h>
32
-
33
- #include <cstddef>
34
- #include <cstdint>
35
- #include <memory>
36
-
37
- #include "dawn/platform/dawn_platform_export.h"
38
-
39
- namespace dawn::platform {
40
-
41
- enum class TraceCategory {
42
- General, // General trace events
43
- Validation, // Dawn validation
44
- Recording, // Native command recording
45
- GPUWork, // Actual GPU work
46
- };
47
-
48
- class DAWN_PLATFORM_EXPORT CachingInterface {
49
- public:
50
- CachingInterface();
51
- virtual ~CachingInterface();
52
-
53
- // LoadData has two modes. The first mode is used to get a value which
54
- // corresponds to the |key|. The |valueOut| is a caller provided buffer
55
- // allocated to the size |valueSize| which is loaded with data of the
56
- // size returned. The second mode is used to query for the existence of
57
- // the |key| where |valueOut| is nullptr and |valueSize| must be 0.
58
- // The return size is non-zero if the |key| exists.
59
- virtual size_t LoadData(const void* key, size_t keySize, void* valueOut, size_t valueSize) = 0;
60
-
61
- // StoreData puts a |value| in the cache which corresponds to the |key|.
62
- virtual void StoreData(const void* key,
63
- size_t keySize,
64
- const void* value,
65
- size_t valueSize) = 0;
66
-
67
- private:
68
- CachingInterface(const CachingInterface&) = delete;
69
- CachingInterface& operator=(const CachingInterface&) = delete;
70
- };
71
-
72
- class DAWN_PLATFORM_EXPORT WaitableEvent {
73
- public:
74
- WaitableEvent() = default;
75
- virtual ~WaitableEvent() = default;
76
-
77
- WaitableEvent(const WaitableEvent&) = delete;
78
- WaitableEvent& operator=(const WaitableEvent&) = delete;
79
-
80
- virtual void Wait() = 0; // Wait for completion
81
- virtual bool IsComplete() = 0; // Non-blocking check if the event is complete
82
- };
83
-
84
- using PostWorkerTaskCallback = void (*)(void* userdata);
85
-
86
- class DAWN_PLATFORM_EXPORT WorkerTaskPool {
87
- public:
88
- WorkerTaskPool() = default;
89
- virtual ~WorkerTaskPool() = default;
90
-
91
- WorkerTaskPool(const WorkerTaskPool&) = delete;
92
- WorkerTaskPool& operator=(const WorkerTaskPool&) = delete;
93
-
94
- virtual std::unique_ptr<WaitableEvent> PostWorkerTask(PostWorkerTaskCallback,
95
- void* userdata) = 0;
96
- };
97
-
98
- // These features map to similarly named ones in src/chromium/src/gpu/config/gpu_finch_features.h
99
- // in `namespace features`.
100
- enum class Features {
101
- kWebGPUUseDXC,
102
- kWebGPUUseVulkanMemoryModel,
103
- kWebGPUEnableRangeAnalysisForRobustness,
104
- kWebGPUUseSpirv14,
105
- };
106
-
107
- class DAWN_PLATFORM_EXPORT Platform {
108
- public:
109
- Platform();
110
- virtual ~Platform();
111
-
112
- virtual const unsigned char* GetTraceCategoryEnabledFlag(TraceCategory category);
113
-
114
- virtual double MonotonicallyIncreasingTime();
115
-
116
- virtual uint64_t AddTraceEvent(char phase,
117
- const unsigned char* categoryGroupEnabled,
118
- const char* name,
119
- uint64_t id,
120
- double timestamp,
121
- int numArgs,
122
- const char** argNames,
123
- const unsigned char* argTypes,
124
- const uint64_t* argValues,
125
- unsigned char flags);
126
-
127
- // Invoked to add a UMA histogram count-based sample
128
- virtual void HistogramCustomCounts(const char* name,
129
- int sample,
130
- int min,
131
- int max,
132
- int bucketCount);
133
-
134
- // Invoked to add a UMA histogram count-based sample that requires high-performance
135
- // counter (HPC) support.
136
- virtual void HistogramCustomCountsHPC(const char* name,
137
- int sample,
138
- int min,
139
- int max,
140
- int bucketCount);
141
-
142
- // Invoked to add a UMA histogram enumeration sample
143
- virtual void HistogramEnumeration(const char* name, int sample, int boundaryValue);
144
-
145
- // Invoked to add a UMA histogram sparse sample
146
- virtual void HistogramSparse(const char* name, int sample);
147
-
148
- // Invoked to add a UMA histogram boolean sample
149
- virtual void HistogramBoolean(const char* name, bool sample);
150
-
151
- // The returned CachingInterface is expected to outlive the device which uses it to persistently
152
- // cache objects.
153
- virtual CachingInterface* GetCachingInterface();
154
-
155
- virtual std::unique_ptr<WorkerTaskPool> CreateWorkerTaskPool();
156
-
157
- // Hook for querying if a Finch feature is enabled.
158
- virtual bool IsFeatureEnabled(Features feature);
159
-
160
- private:
161
- Platform(const Platform&) = delete;
162
- Platform& operator=(const Platform&) = delete;
163
- };
164
-
165
- } // namespace dawn::platform
166
-
167
- #endif // INCLUDE_DAWN_PLATFORM_DAWNPLATFORM_H_
@@ -1,49 +0,0 @@
1
- // Copyright 2020 The Dawn & Tint Authors
2
- //
3
- // Redistribution and use in source and binary forms, with or without
4
- // modification, are permitted provided that the following conditions are met:
5
- //
6
- // 1. Redistributions of source code must retain the above copyright notice, this
7
- // list of conditions and the following disclaimer.
8
- //
9
- // 2. Redistributions in binary form must reproduce the above copyright notice,
10
- // this list of conditions and the following disclaimer in the documentation
11
- // and/or other materials provided with the distribution.
12
- //
13
- // 3. Neither the name of the copyright holder nor the names of its
14
- // contributors may be used to endorse or promote products derived from
15
- // this software without specific prior written permission.
16
- //
17
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
- // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- #ifndef INCLUDE_DAWN_PLATFORM_DAWN_PLATFORM_EXPORT_H_
29
- #define INCLUDE_DAWN_PLATFORM_DAWN_PLATFORM_EXPORT_H_
30
-
31
- #if defined(DAWN_PLATFORM_SHARED_LIBRARY)
32
- #if defined(_WIN32)
33
- #if defined(DAWN_PLATFORM_IMPLEMENTATION)
34
- #define DAWN_PLATFORM_EXPORT __declspec(dllexport)
35
- #else
36
- #define DAWN_PLATFORM_EXPORT __declspec(dllimport)
37
- #endif
38
- #else // defined(_WIN32)
39
- #if defined(DAWN_PLATFORM_IMPLEMENTATION)
40
- #define DAWN_PLATFORM_EXPORT __attribute__((visibility("default")))
41
- #else
42
- #define DAWN_PLATFORM_EXPORT
43
- #endif
44
- #endif // defined(_WIN32)
45
- #else // defined(DAWN_PLATFORM_SHARED_LIBRARY)
46
- #define DAWN_PLATFORM_EXPORT
47
- #endif // defined(DAWN_PLATFORM_SHARED_LIBRARY)
48
-
49
- #endif // INCLUDE_DAWN_PLATFORM_DAWN_PLATFORM_EXPORT_H_
@@ -1,57 +0,0 @@
1
- //
2
- // Created by Marc Rousavy on 22.02.24.
3
- //
4
- #include <jsi/jsi.h>
5
-
6
- #include <memory>
7
- #include <unordered_map>
8
- #include <unordered_set>
9
- #include <utility>
10
-
11
- #include "RNFRuntimeCache.h"
12
-
13
- namespace margelo {
14
-
15
- static std::unordered_map<jsi::Runtime*, std::unordered_set<RuntimeLifecycleListener*>> listeners;
16
-
17
- struct RuntimeLifecycleMonitorObject : public jsi::HostObject {
18
- jsi::Runtime* _rt;
19
- explicit RuntimeLifecycleMonitorObject(jsi::Runtime* rt) : _rt(rt) {}
20
- ~RuntimeLifecycleMonitorObject() {
21
- auto listenersSet = listeners.find(_rt);
22
- if (listenersSet != listeners.end()) {
23
- for (auto listener : listenersSet->second) {
24
- listener->onRuntimeDestroyed(_rt);
25
- }
26
- listeners.erase(listenersSet);
27
- }
28
- }
29
- };
30
-
31
- void RuntimeLifecycleMonitor::addListener(jsi::Runtime& rt, RuntimeLifecycleListener* listener) {
32
- auto listenersSet = listeners.find(&rt);
33
- if (listenersSet == listeners.end()) {
34
- // We install a global host object in the provided runtime, this way we can
35
- // use that host object destructor to get notified when the runtime is being
36
- // terminated. We use a unique name for the object as it gets saved with the
37
- // runtime's global object.
38
- rt.global().setProperty(rt, "__rnfl_rt_lifecycle_monitor",
39
- jsi::Object::createFromHostObject(rt, std::make_shared<RuntimeLifecycleMonitorObject>(&rt)));
40
- std::unordered_set<RuntimeLifecycleListener*> newSet;
41
- newSet.insert(listener);
42
- listeners.emplace(&rt, std::move(newSet));
43
- } else {
44
- listenersSet->second.insert(listener);
45
- }
46
- }
47
-
48
- void RuntimeLifecycleMonitor::removeListener(jsi::Runtime& rt, RuntimeLifecycleListener* listener) {
49
- auto listenersSet = listeners.find(&rt);
50
- if (listenersSet == listeners.end()) {
51
- // nothing to do here
52
- } else {
53
- listenersSet->second.erase(listener);
54
- }
55
- }
56
-
57
- } // namespace margelo
@@ -1,79 +0,0 @@
1
- //
2
- // Created by Marc Rousavy on 22.02.24.
3
- //
4
- #pragma once
5
-
6
- #include <jsi/jsi.h>
7
-
8
- #include <memory>
9
- #include <unordered_map>
10
- #include <unordered_set>
11
- #include <utility>
12
-
13
- namespace margelo {
14
-
15
- namespace jsi = facebook::jsi;
16
-
17
- /**
18
- * Listener interface that allows for getting notified when a jsi::Runtime
19
- * instance is destroyed.
20
- */
21
- struct RuntimeLifecycleListener {
22
- virtual ~RuntimeLifecycleListener() {}
23
- virtual void onRuntimeDestroyed(jsi::Runtime*) = 0;
24
- };
25
-
26
- /**
27
- * This class provides an API via static methods for registering and
28
- * unregistering runtime lifecycle listeners. The listeners can be used to
29
- * cleanup any data that references a given jsi::Runtime instance before it gets
30
- * destroyed.
31
- */
32
- struct RuntimeLifecycleMonitor {
33
- static void addListener(jsi::Runtime& rt, RuntimeLifecycleListener* listener);
34
- static void removeListener(jsi::Runtime& rt, RuntimeLifecycleListener* listener);
35
- };
36
-
37
- /**
38
- * Provides a way to keep data specific to a jsi::Runtime instance that gets
39
- * cleaned up when that runtime is destroyed. This is necessary because JSI does
40
- * not allow for its associated objects to be retained past the runtime
41
- * lifetime. If an object (e.g. jsi::Values or jsi::Function instances) is kept
42
- * after the runtime is torn down, its destructor (once it is destroyed
43
- * eventually) will result in a crash (JSI objects keep a pointer to memory
44
- * managed by the runtime, accessing that portion of the memory after runtime is
45
- * deleted is the root cause of that crash).
46
- */
47
- template <typename T> class RuntimeAwareCache : public RuntimeLifecycleListener {
48
-
49
- public:
50
- void onRuntimeDestroyed(jsi::Runtime* rt) override {
51
- // A runtime has been destroyed, so destroy the related cache.
52
- _runtimeCaches.erase(rt);
53
- }
54
-
55
- ~RuntimeAwareCache() {
56
- for (auto& cache : _runtimeCaches) {
57
- // remove all `onRuntimeDestroyed` listeners.
58
- RuntimeLifecycleMonitor::removeListener(*cache.first, this);
59
- }
60
- }
61
-
62
- T& get(jsi::Runtime& rt) {
63
- if (_runtimeCaches.count(&rt) == 0) {
64
- // This is the first time this Runtime has been accessed.
65
- // We set up a `onRuntimeDestroyed` listener for it and
66
- // initialize the cache map.
67
- RuntimeLifecycleMonitor::addListener(rt, this);
68
-
69
- T cache;
70
- _runtimeCaches.emplace(&rt, std::move(cache));
71
- }
72
- return _runtimeCaches.at(&rt);
73
- }
74
-
75
- private:
76
- std::unordered_map<jsi::Runtime*, T> _runtimeCaches;
77
- };
78
-
79
- } // namespace margelo
@@ -1,43 +0,0 @@
1
- //
2
- // Created by Marc Rousavy on 22.02.24.
3
- //
4
- #pragma once
5
-
6
- #include "RNFWorkletRuntimeRegistry.h"
7
-
8
- #include <jsi/jsi.h>
9
-
10
- #include <memory>
11
-
12
- namespace margelo {
13
-
14
- // From:
15
- // https://github.com/software-mansion/react-native-reanimated/blob/6cb1a66f1a68cac8079de2b6b305d22359847e51/Common/cpp/ReanimatedRuntime/WorkletRuntimeCollector.h
16
- class WorkletRuntimeCollector : public jsi::HostObject {
17
- // When worklet runtime is created, we inject an instance of this class as a
18
- // `jsi::HostObject` into the global object. When worklet runtime is
19
- // terminated, the object is garbage-collected, which runs the C++ destructor.
20
- // In the destructor, we unregister the worklet runtime from the registry.
21
-
22
- public:
23
- explicit WorkletRuntimeCollector(jsi::Runtime& runtime) : _runtime(runtime) {
24
- Logger::log("WorkletRuntimeCollector", "Registering WorkletRuntime %p", &runtime);
25
- RNFWorkletRuntimeRegistry::registerRuntime(_runtime);
26
- }
27
-
28
- ~WorkletRuntimeCollector() {
29
- Logger::log("WorkletRuntimeCollector", "Unregistering WorkletRuntime %p", &_runtime);
30
- RNFWorkletRuntimeRegistry::unregisterRuntime(_runtime);
31
- }
32
-
33
- static void install(jsi::Runtime& rt) {
34
- auto collector = std::make_shared<WorkletRuntimeCollector>(rt);
35
- auto object = jsi::Object::createFromHostObject(rt, collector);
36
- rt.global().setProperty(rt, "__workletRuntimeCollector", object);
37
- }
38
-
39
- private:
40
- jsi::Runtime& _runtime;
41
- };
42
-
43
- } // namespace margelo
@@ -1,12 +0,0 @@
1
- //
2
- // Created by Marc Rousavy on 22.02.24.
3
- //
4
- #include "RNFWorkletRuntimeRegistry.h"
5
- #include <set>
6
-
7
- namespace margelo {
8
-
9
- std::set<jsi::Runtime*> RNFWorkletRuntimeRegistry::registry_{};
10
- std::mutex RNFWorkletRuntimeRegistry::mutex_{};
11
-
12
- } // namespace margelo
@@ -1,44 +0,0 @@
1
- //
2
- // Created by Marc Rousavy on 22.02.24.
3
- //
4
- #pragma once
5
-
6
- #include <jsi/jsi.h>
7
-
8
- #include <mutex>
9
- #include <set>
10
-
11
- namespace jsi = facebook::jsi;
12
-
13
- namespace margelo {
14
-
15
- // From:
16
- // https://github.com/software-mansion/react-native-reanimated/blob/6cb1a66f1a68cac8079de2b6b305d22359847e51/Common/cpp/ReanimatedRuntime/WorkletRuntimeRegistry.h
17
- class RNFWorkletRuntimeRegistry {
18
- private:
19
- static std::set<jsi::Runtime*> registry_;
20
- static std::mutex mutex_; // Protects `registry_`.
21
-
22
- RNFWorkletRuntimeRegistry() {} // private ctor
23
-
24
- static void registerRuntime(jsi::Runtime& runtime) {
25
- std::lock_guard<std::mutex> lock(mutex_);
26
- registry_.insert(&runtime);
27
- }
28
-
29
- static void unregisterRuntime(jsi::Runtime& runtime) {
30
- std::lock_guard<std::mutex> lock(mutex_);
31
- registry_.erase(&runtime);
32
- }
33
-
34
- friend class WorkletRuntimeCollector;
35
-
36
- public:
37
- static bool isRuntimeAlive(jsi::Runtime* runtime) {
38
- assert(runtime != nullptr);
39
- std::lock_guard<std::mutex> lock(mutex_);
40
- return registry_.find(runtime) != registry_.end();
41
- }
42
- };
43
-
44
- } // namespace margelo
@@ -1,30 +0,0 @@
1
- //
2
- // ThreadUtils.hpp
3
- // react-native-nitro
4
- //
5
- // Created by Marc Rousavy on 14.07.24.
6
- //
7
- #pragma once
8
-
9
- #include <string>
10
-
11
- namespace margelo {
12
-
13
- class ThreadUtils final {
14
- public:
15
- ThreadUtils() = delete;
16
-
17
- /**
18
- * Get the current Thread's name.
19
- * This is implemented differently on iOS and Android.
20
- */
21
- static std::string getThreadName();
22
-
23
- /**
24
- * Set the current Thread's name.
25
- * This is implemented differently on iOS and Android.
26
- */
27
- static void setThreadName(const std::string &name);
28
- };
29
-
30
- } // namespace margelo
@@ -1,30 +0,0 @@
1
- #pragma once
2
-
3
- #include "webgpu/webgpu_cpp.h"
4
-
5
- #include <future>
6
- #include <utility>
7
-
8
- namespace rnwgpu {
9
-
10
- class AsyncRunner {
11
- public:
12
- explicit AsyncRunner(wgpu::Instance *instance) : instance(instance) {}
13
-
14
- template <typename F> auto runAsync(F &&func) {
15
- return std::async(
16
- std::launch::async, [this, func = std::forward<F>(func)]() {
17
- if constexpr (std::is_invocable_v<F, wgpu::Instance *>) {
18
- return func(instance);
19
- } else {
20
- auto future = func();
21
- instance->WaitAny(future, UINT64_MAX);
22
- }
23
- });
24
- }
25
-
26
- public:
27
- wgpu::Instance *instance;
28
- };
29
-
30
- } // namespace rnwgpu
@@ -1,37 +0,0 @@
1
-
2
- //
3
- // Created by Marc Rousavy on 27.03.24.
4
- //
5
-
6
- #pragma once
7
-
8
- #include "Dispatcher.h"
9
-
10
- #include <utility>
11
- #include <memory>
12
- #include <ReactCommon/CallInvoker.h>
13
-
14
- namespace margelo {
15
-
16
- /**
17
- * A Dispatcher that uses react::CallInvoker for it's implementation
18
- */
19
- class CallInvokerDispatcher final : public Dispatcher {
20
- public:
21
- explicit CallInvokerDispatcher(
22
- std::shared_ptr<react::CallInvoker> callInvoker)
23
- : _callInvoker(callInvoker) {}
24
-
25
- void runAsync(std::function<void()> &&function) override {
26
- _callInvoker->invokeAsync(std::move(function));
27
- }
28
-
29
- void runSync(std::function<void()> &&function) override {
30
- _callInvoker->invokeSync(std::move(function));
31
- }
32
-
33
- private:
34
- std::shared_ptr<react::CallInvoker> _callInvoker;
35
- };
36
-
37
- } // namespace margelo