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.
- package/README.md +155 -69
- package/android/CMakeLists.txt +5 -7
- package/android/build.gradle +7 -18
- package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +34 -10
- package/apple/MetalView.mm +0 -19
- package/apple/WebGPUModule.h +1 -9
- package/apple/WebGPUModule.mm +0 -3
- package/apple/WebGPUView.h +0 -3
- package/apple/WebGPUView.mm +0 -2
- package/cpp/WGPULogger.h +10 -0
- package/cpp/dawn/dawn_proc_table.h +1 -1
- package/cpp/dawn/webgpu.h +4855 -0
- package/cpp/dawn/webgpu_cpp.h +10168 -0
- package/cpp/dawn/wire/client/webgpu.h +354 -0
- package/cpp/dawn/wire/client/webgpu_cpp.h +10343 -0
- package/cpp/dawn/wire/client/webgpu_cpp_print.h +2715 -0
- package/cpp/jsi/RNFHybridObject.cpp +8 -4
- package/cpp/jsi/RNFHybridObject.h +7 -2
- package/cpp/jsi/RNFJSIConverter.h +13 -102
- package/cpp/jsi/RNFJSIHelper.h +5 -3
- package/cpp/jsi/RNFRuntimeState.cpp +18 -0
- package/cpp/jsi/RNFRuntimeState.h +106 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +1 -9
- package/cpp/rnwgpu/api/GPU.cpp +51 -26
- package/cpp/rnwgpu/api/GPU.h +5 -18
- package/cpp/rnwgpu/api/GPUAdapter.cpp +79 -54
- package/cpp/rnwgpu/api/GPUAdapter.h +6 -6
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -1
- package/cpp/rnwgpu/api/GPUBindGroup.h +1 -3
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -3
- package/cpp/rnwgpu/api/GPUBuffer.cpp +35 -32
- package/cpp/rnwgpu/api/GPUBuffer.h +9 -7
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +5 -1
- package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -2
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -3
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -2
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -3
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -3
- package/cpp/rnwgpu/api/GPUDevice.cpp +183 -128
- package/cpp/rnwgpu/api/GPUDevice.h +22 -21
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -3
- package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -3
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -3
- package/cpp/rnwgpu/api/GPUQuerySet.h +1 -3
- package/cpp/rnwgpu/api/GPUQueue.cpp +19 -8
- package/cpp/rnwgpu/api/GPUQueue.h +7 -6
- package/cpp/rnwgpu/api/GPURenderBundle.h +1 -3
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -3
- package/cpp/rnwgpu/api/GPUSampler.h +1 -3
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +42 -28
- package/cpp/rnwgpu/api/GPUShaderModule.h +6 -6
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -3
- package/cpp/rnwgpu/api/GPUTexture.h +1 -3
- package/cpp/rnwgpu/api/GPUTextureView.h +1 -3
- package/cpp/rnwgpu/api/RNWebGPU.h +1 -7
- package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
- package/cpp/rnwgpu/async/AsyncRunner.cpp +215 -0
- package/cpp/rnwgpu/async/AsyncRunner.h +53 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +181 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +55 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +23 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +22 -0
- package/cpp/webgpu/webgpu.h +5 -4827
- package/cpp/webgpu/webgpu_cpp.h +5 -10140
- package/cpp/{dawn/native/WebGPUBackend.h → webgpu/webgpu_cpp_print.h} +4 -20
- package/lib/commonjs/Canvas.js +6 -66
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/hooks.js +6 -42
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/module/Canvas.js +7 -67
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/hooks.js +5 -40
- package/lib/module/hooks.js.map +1 -1
- package/lib/typescript/lib/commonjs/hooks.d.ts +1 -5
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/hooks.d.ts +1 -5
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +0 -1
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts +2 -7
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
- package/libs/android/x86/libwebgpu_dawn.so +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +5 -35
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/package.json +4 -3
- package/react-native-wgpu.podspec +12 -16
- package/src/Canvas.tsx +8 -69
- package/src/hooks.tsx +14 -48
- package/android/cpp/platform/ThreadUtils.cpp +0 -41
- package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +0 -23
- package/android/src/oldarch/com/webgpu/WebGPUViewManagerSpec.java +0 -12
- package/apple/WebGPUViewManager.mm +0 -24
- package/apple/platform/ThreadUtils.cpp +0 -34
- package/cpp/dawn/dawn_proc.h +0 -50
- package/cpp/dawn/dawn_thread_dispatch_proc.h +0 -47
- package/cpp/dawn/native/D3D11Backend.h +0 -77
- package/cpp/dawn/native/D3D12Backend.h +0 -68
- package/cpp/dawn/native/D3DBackend.h +0 -56
- package/cpp/dawn/native/MetalBackend.h +0 -56
- package/cpp/dawn/platform/DawnPlatform.h +0 -167
- package/cpp/dawn/platform/dawn_platform_export.h +0 -49
- package/cpp/jsi/RNFRuntimeCache.cpp +0 -57
- package/cpp/jsi/RNFRuntimeCache.h +0 -79
- package/cpp/jsi/RNFWorkletRuntimeCollector.h +0 -43
- package/cpp/jsi/RNFWorkletRuntimeRegistry.cpp +0 -12
- package/cpp/jsi/RNFWorkletRuntimeRegistry.h +0 -44
- package/cpp/platform/ThreadUtils.h +0 -30
- package/cpp/rnwgpu/api/AsyncRunner.h +0 -30
- package/cpp/threading/CallInvokerDispatcher.h +0 -37
- package/cpp/threading/Dispatcher.cpp +0 -55
- package/cpp/threading/Dispatcher.h +0 -93
- package/cpp/threading/ThreadPool.cpp +0 -88
- package/cpp/threading/ThreadPool.h +0 -53
- package/cpp/webgpu/webgpu_glfw.h +0 -88
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Constants.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Device.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Device.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/GPU.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Texture.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +0 -3
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +0 -29
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +0 -5
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/cube.d.ts +0 -7
- package/lib/typescript/src/__tests__/components/cube.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +0 -22
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +0 -12
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +0 -7
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +0 -6
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +0 -6
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +0 -10
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/triangle.d.ts +0 -3
- package/lib/typescript/src/__tests__/components/triangle.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/config.d.ts +0 -3
- package/lib/typescript/src/__tests__/config.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/globalSetup.d.ts +0 -3
- package/lib/typescript/src/__tests__/globalSetup.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/globalTeardown.d.ts +0 -3
- package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/setup.d.ts +0 -63
- package/lib/typescript/src/__tests__/setup.d.ts.map +0 -1
- package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
- package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/dawn.json +0 -4670
- package/src/__tests__/Alpha.spec.ts +0 -28
- package/src/__tests__/ArrayBuffer.spec.ts +0 -76
- package/src/__tests__/Buffer.spec.ts +0 -357
- package/src/__tests__/ComputeShader.spec.ts +0 -375
- package/src/__tests__/Constants.spec.ts +0 -89
- package/src/__tests__/Device.spec.ts +0 -84
- package/src/__tests__/ErrorScope.spec.ts +0 -92
- package/src/__tests__/ExternalTexture.spec.ts +0 -284
- package/src/__tests__/GPU.spec.ts +0 -272
- package/src/__tests__/ImageData.spec.ts +0 -26
- package/src/__tests__/Shaders.spec.ts +0 -232
- package/src/__tests__/Texture.spec.ts +0 -197
- package/src/__tests__/assets/Di-3d.png +0 -0
- package/src/__tests__/components/Wireframe/Shaders.ts +0 -138
- package/src/__tests__/components/Wireframe/models.ts +0 -113
- package/src/__tests__/components/Wireframe/utils.ts +0 -22
- package/src/__tests__/components/cube.ts +0 -51
- package/src/__tests__/components/meshes/mesh.ts +0 -96
- package/src/__tests__/components/meshes/sphere.ts +0 -103
- package/src/__tests__/components/meshes/stanfordDragon.ts +0 -44
- package/src/__tests__/components/meshes/stanfordDragonData.ts +0 -5
- package/src/__tests__/components/meshes/teapot.ts +0 -13
- package/src/__tests__/components/meshes/utils.ts +0 -235
- package/src/__tests__/components/triangle.ts +0 -17
- package/src/__tests__/config.ts +0 -2
- package/src/__tests__/demos/ABuffer.spec.ts +0 -890
- package/src/__tests__/demos/Blur.spec.ts +0 -398
- package/src/__tests__/demos/Cube.spec.ts +0 -929
- package/src/__tests__/demos/FractalCube.spec.ts +0 -240
- package/src/__tests__/demos/OcclusionQuery.spec.ts +0 -376
- package/src/__tests__/demos/RenderBundles.spec.ts +0 -580
- package/src/__tests__/demos/Triangle.spec.ts +0 -266
- package/src/__tests__/demos/Wireframe.spec.ts +0 -188
- package/src/__tests__/globalSetup.ts +0 -45
- package/src/__tests__/globalTeardown.ts +0 -11
- package/src/__tests__/setup.ts +0 -423
- package/src/__tests__/snapshots/abuffer.png +0 -0
- package/src/__tests__/snapshots/asteroid.png +0 -0
- package/src/__tests__/snapshots/blur.png +0 -0
- package/src/__tests__/snapshots/buffer.png +0 -0
- package/src/__tests__/snapshots/constant-triangle.png +0 -0
- package/src/__tests__/snapshots/cube.png +0 -0
- package/src/__tests__/snapshots/f.png +0 -0
- package/src/__tests__/snapshots/f2.png +0 -0
- package/src/__tests__/snapshots/fractal-cubes.png +0 -0
- package/src/__tests__/snapshots/instanced-cubes.png +0 -0
- package/src/__tests__/snapshots/occlusion-query.png +0 -0
- package/src/__tests__/snapshots/ref.png +0 -0
- package/src/__tests__/snapshots/semi-opaque-cyan.png +0 -0
- package/src/__tests__/snapshots/texture.png +0 -0
- package/src/__tests__/snapshots/textured-cube.png +0 -0
- package/src/__tests__/snapshots/triangle-msaa.png +0 -0
- package/src/__tests__/snapshots/triangle.png +0 -0
- package/src/__tests__/snapshots/two-cube.png +0 -0
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
React Native implementation of WebGPU using [Dawn](https://dawn.googlesource.com/dawn).
|
|
4
4
|
This is currently a technical preview for early adopters.
|
|
5
5
|
|
|
6
|
+
React Native WebGPU requires React Native 0.81 or newer and doesn't run on legacy architecture.
|
|
7
|
+
|
|
6
8
|
## Installation
|
|
7
9
|
|
|
8
10
|
Please note that the package name is `react-native-wgpu`.
|
|
@@ -17,7 +19,15 @@ https://github.com/user-attachments/assets/116a41b2-2cf8-49f1-9f16-a5c83637c198
|
|
|
17
19
|
|
|
18
20
|
Starting from `r168`, Three.js runs out of the box with React Native WebGPU.
|
|
19
21
|
You need to have a slight modification of [the metro config](/apps/example/metro.config.js) to resolve Three.js to the WebGPU build.
|
|
20
|
-
We also support [three-fiber](/apps/example/src/ThreeJS/Fiber.tsx).
|
|
22
|
+
We also support [react-three-fiber](/apps/example/src/ThreeJS/Fiber.tsx); to make it work, patch `node_modules/@react-three/fiber/package.json` (for instance via `patch-package`) so that it resolves to the WebGPU entry point instead of the React Native bundle:
|
|
23
|
+
|
|
24
|
+
```diff
|
|
25
|
+
diff --git a/node_modules/@react-three/fiber/package.json b/node_modules/@react-three/fiber/package.json
|
|
26
|
+
@@
|
|
27
|
+
- "react-native": "native/dist/react-three-fiber-native.cjs.js",
|
|
28
|
+
+ "react-native": "dist/react-three-fiber.cjs.js",
|
|
29
|
+
```
|
|
30
|
+
|
|
21
31
|
For model loading, we also need [the following polyfill](/apps/example/src/App.tsx#29).
|
|
22
32
|
|
|
23
33
|
https://github.com/user-attachments/assets/5b49ef63-0a3c-4679-aeb5-e4b4dddfcc1d
|
|
@@ -26,89 +36,100 @@ We also provide prebuilt binaries for visionOS and macOS.
|
|
|
26
36
|
|
|
27
37
|
https://github.com/user-attachments/assets/2d5c618e-5b15-4cef-8558-d4ddf8c70667
|
|
28
38
|
|
|
39
|
+
## Diagnostics
|
|
40
|
+
|
|
41
|
+
Two diagnostic screens were added to the example app so you can reproduce the issues highlighted in the code review:
|
|
42
|
+
|
|
43
|
+
- `Async Runner Starvation` (`apps/example/src/Diagnostics/AsyncStarvation.tsx`) shows that a zero-delay `setTimeout` never fires before `device.createRenderPipelineAsync()` resolves because the event loop is kept busy. Launch the example app and open the screen from the home list to observe the stalled timer.
|
|
44
|
+
- `Device Lost Promise Hang` (`apps/example/src/Diagnostics/DeviceLostHang.tsx`) forces a synthetic device loss by calling the native `forceLossForTesting()` helper. On the current build the `device.lost` promise remains pending indefinitely, confirming that the loss callback is never delivered once pumping stops.
|
|
45
|
+
|
|
29
46
|
## Usage
|
|
30
47
|
|
|
31
|
-
|
|
48
|
+
Usage is identical to Web.
|
|
32
49
|
|
|
33
50
|
```tsx
|
|
34
51
|
import React from "react";
|
|
35
52
|
import { StyleSheet, View, PixelRatio } from "react-native";
|
|
36
|
-
import { Canvas,
|
|
53
|
+
import { Canvas, CanvasRef } from "react-native-wgpu";
|
|
37
54
|
|
|
38
55
|
import { redFragWGSL, triangleVertWGSL } from "./triangle";
|
|
39
56
|
|
|
40
57
|
export function HelloTriangle() {
|
|
41
|
-
const ref =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
const ref = useRef<CanvasRef>(null);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const helloTriangle = async () => {
|
|
61
|
+
const adapter = await navigator.gpu.requestAdapter();
|
|
62
|
+
if (!adapter) {
|
|
63
|
+
throw new Error("No adapter");
|
|
64
|
+
}
|
|
65
|
+
const device = await adapter.requestDevice();
|
|
66
|
+
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
67
|
+
|
|
68
|
+
const context = ref.current!.getContext("webgpu")!;
|
|
69
|
+
const canvas = context.canvas as HTMLCanvasElement;
|
|
70
|
+
canvas.width = canvas.clientWidth * PixelRatio.get();
|
|
71
|
+
canvas.height = canvas.clientHeight * PixelRatio.get();
|
|
72
|
+
|
|
73
|
+
if (!context) {
|
|
74
|
+
throw new Error("No context");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
context.configure({
|
|
78
|
+
device,
|
|
79
|
+
format: presentationFormat,
|
|
80
|
+
alphaMode: "opaque",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const pipeline = device.createRenderPipeline({
|
|
84
|
+
layout: "auto",
|
|
85
|
+
vertex: {
|
|
86
|
+
module: device.createShaderModule({
|
|
87
|
+
code: triangleVertWGSL,
|
|
88
|
+
}),
|
|
89
|
+
entryPoint: "main",
|
|
90
|
+
},
|
|
91
|
+
fragment: {
|
|
92
|
+
module: device.createShaderModule({
|
|
93
|
+
code: redFragWGSL,
|
|
94
|
+
}),
|
|
95
|
+
entryPoint: "main",
|
|
96
|
+
targets: [
|
|
97
|
+
{
|
|
98
|
+
format: presentationFormat,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
primitive: {
|
|
103
|
+
topology: "triangle-list",
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const commandEncoder = device.createCommandEncoder();
|
|
108
|
+
|
|
109
|
+
const textureView = context.getCurrentTexture().createView();
|
|
110
|
+
|
|
111
|
+
const renderPassDescriptor: GPURenderPassDescriptor = {
|
|
112
|
+
colorAttachments: [
|
|
78
113
|
{
|
|
79
|
-
|
|
114
|
+
view: textureView,
|
|
115
|
+
clearValue: [0, 0, 0, 1],
|
|
116
|
+
loadOp: "clear",
|
|
117
|
+
storeOp: "store",
|
|
80
118
|
},
|
|
81
119
|
],
|
|
82
|
-
}
|
|
83
|
-
primitive: {
|
|
84
|
-
topology: "triangle-list",
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const commandEncoder = device.createCommandEncoder();
|
|
89
|
-
|
|
90
|
-
const textureView = context.getCurrentTexture().createView();
|
|
91
|
-
|
|
92
|
-
const renderPassDescriptor: GPURenderPassDescriptor = {
|
|
93
|
-
colorAttachments: [
|
|
94
|
-
{
|
|
95
|
-
view: textureView,
|
|
96
|
-
clearValue: [0, 0, 0, 1],
|
|
97
|
-
loadOp: "clear",
|
|
98
|
-
storeOp: "store",
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
};
|
|
120
|
+
};
|
|
102
121
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
123
|
+
passEncoder.setPipeline(pipeline);
|
|
124
|
+
passEncoder.draw(3);
|
|
125
|
+
passEncoder.end();
|
|
107
126
|
|
|
108
|
-
|
|
127
|
+
device.queue.submit([commandEncoder.finish()]);
|
|
109
128
|
|
|
110
|
-
|
|
111
|
-
|
|
129
|
+
context.present();
|
|
130
|
+
};
|
|
131
|
+
helloTriangle();
|
|
132
|
+
}, [ref]);
|
|
112
133
|
|
|
113
134
|
return (
|
|
114
135
|
<View style={style.container}>
|
|
@@ -129,7 +150,7 @@ const style = StyleSheet.create({
|
|
|
129
150
|
|
|
130
151
|
## Example App
|
|
131
152
|
|
|
132
|
-
To run the example app you first need to [
|
|
153
|
+
To run the example app you first need to [install Dawn](#installing-dawn).
|
|
133
154
|
|
|
134
155
|
From there you will be able to run the example app properly.
|
|
135
156
|
|
|
@@ -184,3 +205,68 @@ device.queue.copyExternalImageToTexture(
|
|
|
184
205
|
[imageBitmap.width, imageBitmap.height],
|
|
185
206
|
);
|
|
186
207
|
```
|
|
208
|
+
|
|
209
|
+
## Troubleshooting
|
|
210
|
+
|
|
211
|
+
### iOS
|
|
212
|
+
|
|
213
|
+
To run the React Native WebGPU project on the iOS simulator, you need to disable the Metal validation API.
|
|
214
|
+
In "Edit Scheme," uncheck "Metal Validation". Learn more [here](https://developer.apple.com/documentation/xcode/validating-your-apps-metal-api-usage/).
|
|
215
|
+
|
|
216
|
+
<img width="1052" alt="Uncheck 'Metal Validation'" src="https://github.com/user-attachments/assets/2676e5cc-e351-4a97-bdc8-22cbd7df2ef2">
|
|
217
|
+
|
|
218
|
+
## Library Development
|
|
219
|
+
|
|
220
|
+
Make sure to check out the submodules:
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
git submodule update --init
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Make sure you have all the tools required for building the Skia libraries (Android Studio, XCode, Ninja, CMake, Android NDK/build tools).
|
|
227
|
+
|
|
228
|
+
### Installing Dawn
|
|
229
|
+
|
|
230
|
+
There is an alternative way which is to install the prebuilt binaries from GitHub.
|
|
231
|
+
|
|
232
|
+
```sh
|
|
233
|
+
$ yarn
|
|
234
|
+
$ cd packages/webgpu
|
|
235
|
+
$ yarn install-dawn
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Building Dawn
|
|
239
|
+
|
|
240
|
+
Alternatively, you can build Dawn locally.
|
|
241
|
+
|
|
242
|
+
```sh
|
|
243
|
+
yarn
|
|
244
|
+
cd packages/webgpu
|
|
245
|
+
yarn build-dawn
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Upgrading
|
|
249
|
+
|
|
250
|
+
1. `git submodule update --remote`
|
|
251
|
+
2. `yarn clean-dawn`
|
|
252
|
+
3. `yarn build-dawn`
|
|
253
|
+
|
|
254
|
+
### Codegen
|
|
255
|
+
|
|
256
|
+
* `cd packages/webgpu && yarn codegen`
|
|
257
|
+
|
|
258
|
+
### Testing
|
|
259
|
+
|
|
260
|
+
In the `package` folder, to run the test against Chrome for reference:
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
yarn test:ref
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
To run the e2e test, open the example app on the e2e screen.
|
|
267
|
+
By default, it will try to connect to a localhost test server.
|
|
268
|
+
If you want to run the test suite on a physical device, you can modify the address [here](/apps/example/src/useClient.ts#L4).
|
|
269
|
+
|
|
270
|
+
```
|
|
271
|
+
yarn test
|
|
272
|
+
```
|
package/android/CMakeLists.txt
CHANGED
|
@@ -25,7 +25,6 @@ find_package(fbjni REQUIRED CONFIG)
|
|
|
25
25
|
|
|
26
26
|
add_library(${PACKAGE_NAME} SHARED
|
|
27
27
|
./cpp/cpp-adapter.cpp
|
|
28
|
-
./cpp/platform/ThreadUtils.cpp
|
|
29
28
|
../cpp/rnwgpu/api/GPU.cpp
|
|
30
29
|
../cpp/rnwgpu/api/GPUAdapter.cpp
|
|
31
30
|
../cpp/rnwgpu/api/GPUSupportedLimits.cpp
|
|
@@ -47,10 +46,10 @@ add_library(${PACKAGE_NAME} SHARED
|
|
|
47
46
|
../cpp/rnwgpu/RNWebGPUManager.cpp
|
|
48
47
|
../cpp/jsi/RNFPromise.cpp
|
|
49
48
|
../cpp/jsi/RNFHybridObject.cpp
|
|
50
|
-
../cpp/jsi/
|
|
51
|
-
../cpp/
|
|
52
|
-
../cpp/
|
|
53
|
-
../cpp/
|
|
49
|
+
../cpp/jsi/RNFRuntimeState.cpp
|
|
50
|
+
../cpp/rnwgpu/async/AsyncRunner.cpp
|
|
51
|
+
../cpp/rnwgpu/async/AsyncTaskHandle.cpp
|
|
52
|
+
../cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp
|
|
54
53
|
)
|
|
55
54
|
|
|
56
55
|
target_include_directories(
|
|
@@ -72,7 +71,6 @@ target_include_directories(
|
|
|
72
71
|
../cpp/rnwgpu/api/descriptors
|
|
73
72
|
../cpp/jsi
|
|
74
73
|
../cpp/webgpu
|
|
75
|
-
../cpp/threading
|
|
76
74
|
../cpp/platform
|
|
77
75
|
|
|
78
76
|
${libfbjni_include_DIRS}
|
|
@@ -106,4 +104,4 @@ else()
|
|
|
106
104
|
ReactAndroid::reactnativejni
|
|
107
105
|
webgpu_dawn
|
|
108
106
|
)
|
|
109
|
-
endif()
|
|
107
|
+
endif()
|
package/android/build.gradle
CHANGED
|
@@ -16,15 +16,8 @@ def reactNativeArchitectures() {
|
|
|
16
16
|
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
def isNewArchitectureEnabled() {
|
|
20
|
-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
19
|
apply plugin: "com.android.library"
|
|
24
|
-
|
|
25
|
-
if (isNewArchitectureEnabled()) {
|
|
26
|
-
apply plugin: "com.facebook.react"
|
|
27
|
-
}
|
|
20
|
+
apply plugin: "com.facebook.react"
|
|
28
21
|
|
|
29
22
|
static def findNodeModules(baseDir) {
|
|
30
23
|
// Check if we are building the example app:
|
|
@@ -75,7 +68,7 @@ android {
|
|
|
75
68
|
defaultConfig {
|
|
76
69
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
77
70
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
78
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED",
|
|
71
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"
|
|
79
72
|
externalNativeBuild {
|
|
80
73
|
cmake {
|
|
81
74
|
cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
|
|
@@ -116,15 +109,11 @@ android {
|
|
|
116
109
|
|
|
117
110
|
sourceSets {
|
|
118
111
|
main {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
]
|
|
125
|
-
} else {
|
|
126
|
-
java.srcDirs += ["src/oldarch"]
|
|
127
|
-
}
|
|
112
|
+
java.srcDirs += [
|
|
113
|
+
"src/newarch",
|
|
114
|
+
// This is needed to build Kotlin project with NewArch enabled
|
|
115
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
116
|
+
]
|
|
128
117
|
}
|
|
129
118
|
}
|
|
130
119
|
|
|
@@ -1,26 +1,50 @@
|
|
|
1
1
|
|
|
2
2
|
package com.webgpu;
|
|
3
3
|
|
|
4
|
-
import com.facebook.react.
|
|
4
|
+
import com.facebook.react.TurboReactPackage;
|
|
5
5
|
import com.facebook.react.bridge.NativeModule;
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
7
10
|
import com.facebook.react.uimanager.ViewManager;
|
|
8
11
|
|
|
9
|
-
import java.util.
|
|
10
|
-
import java.util.
|
|
12
|
+
import java.util.Collections;
|
|
13
|
+
import java.util.HashMap;
|
|
11
14
|
import java.util.List;
|
|
15
|
+
import java.util.Map;
|
|
12
16
|
|
|
13
|
-
public class WebGPUViewPackage
|
|
17
|
+
public class WebGPUViewPackage extends TurboReactPackage {
|
|
14
18
|
@Override
|
|
15
|
-
public
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
|
|
20
|
+
if (name.equals(WebGPUModule.NAME)) {
|
|
21
|
+
return new WebGPUModule(reactContext);
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
19
24
|
}
|
|
20
25
|
|
|
26
|
+
@Override
|
|
27
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
28
|
+
return () -> {
|
|
29
|
+
Map<String, ReactModuleInfo> map = new HashMap<>();
|
|
30
|
+
map.put(
|
|
31
|
+
WebGPUModule.NAME,
|
|
32
|
+
new ReactModuleInfo(
|
|
33
|
+
WebGPUModule.NAME,
|
|
34
|
+
WebGPUModule.class.getName(),
|
|
35
|
+
false,
|
|
36
|
+
false,
|
|
37
|
+
false,
|
|
38
|
+
false,
|
|
39
|
+
true // isTurboModule
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
return map;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
21
45
|
|
|
22
46
|
@Override
|
|
23
|
-
public List<
|
|
24
|
-
|
|
47
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
48
|
+
return Collections.singletonList(new WebGPUViewManager());
|
|
25
49
|
}
|
|
26
50
|
}
|
package/apple/MetalView.mm
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
#import "MetalView.h"
|
|
2
2
|
#import "webgpu_cpp.h"
|
|
3
3
|
|
|
4
|
-
#ifndef RCT_NEW_ARCH_ENABLED
|
|
5
|
-
#import <React/RCTViewManager.h>
|
|
6
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
|
7
|
-
|
|
8
4
|
@implementation MetalView {
|
|
9
5
|
BOOL _isConfigured;
|
|
10
6
|
}
|
|
@@ -51,19 +47,4 @@
|
|
|
51
47
|
registry.removeSurfaceInfo([_contextId intValue]);
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
#ifndef RCT_NEW_ARCH_ENABLED
|
|
55
|
-
// Paper only method
|
|
56
|
-
// TODO: this method is wrong, it appears to call configureSurface instead of
|
|
57
|
-
// updateSurface sometimes
|
|
58
|
-
- (void)reactSetFrame:(CGRect)frame {
|
|
59
|
-
[super reactSetFrame:frame];
|
|
60
|
-
if (!_isConfigured) {
|
|
61
|
-
[self configure];
|
|
62
|
-
_isConfigured = YES;
|
|
63
|
-
} else {
|
|
64
|
-
[self update];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
#endif // RCT_NEW_ARCH_ENABLED
|
|
68
|
-
|
|
69
50
|
@end
|
package/apple/WebGPUModule.h
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
3
|
#import "RNWebGPUManager.h"
|
|
4
|
-
#import <
|
|
4
|
+
#import <RNWgpuViewSpec/RNWgpuViewSpec.h>
|
|
5
5
|
#import <React/RCTEventEmitter.h>
|
|
6
6
|
|
|
7
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
8
|
-
#import <RNWgpuViewSpec/RNWgpuViewSpec.h>
|
|
9
7
|
@interface WebGPUModule : RCTEventEmitter <NativeWebGPUModuleSpec>
|
|
10
|
-
#else
|
|
11
|
-
@interface WebGPUModule : RCTEventEmitter <RCTBridgeModule>
|
|
12
|
-
#endif
|
|
13
|
-
|
|
14
|
-
@property(nonatomic, weak) RCTBridge *bridge;
|
|
15
|
-
@property(nonatomic, weak) RCTModuleRegistry *moduleRegistry;
|
|
16
8
|
|
|
17
9
|
+ (std::shared_ptr<rnwgpu::RNWebGPUManager>)getManager;
|
|
18
10
|
|
package/apple/WebGPUModule.mm
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
#import <React/RCTBridge+Private.h>
|
|
6
6
|
#import <React/RCTLog.h>
|
|
7
|
-
#import <React/RCTUIManagerUtils.h>
|
|
8
7
|
#import <ReactCommon/RCTTurboModule.h>
|
|
9
8
|
#import <jsi/jsi.h>
|
|
10
9
|
#import <memory>
|
|
@@ -74,11 +73,9 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
|
|
74
73
|
return @true;
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
78
76
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
79
77
|
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
80
78
|
return std::make_shared<facebook::react::NativeWebGPUModuleSpecJSI>(params);
|
|
81
79
|
}
|
|
82
|
-
#endif
|
|
83
80
|
|
|
84
81
|
@end
|
package/apple/WebGPUView.h
CHANGED
package/apple/WebGPUView.mm
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
1
|
#import "WebGPUView.h"
|
|
3
2
|
|
|
4
3
|
#import <react/renderer/components/RNWgpuViewSpec/ComponentDescriptors.h>
|
|
@@ -65,4 +64,3 @@ using namespace facebook::react;
|
|
|
65
64
|
Class<RCTComponentViewProtocol> WebGPUViewCls(void) { return WebGPUView.class; }
|
|
66
65
|
|
|
67
66
|
@end
|
|
68
|
-
#endif
|
package/cpp/WGPULogger.h
CHANGED
|
@@ -27,12 +27,17 @@ public:
|
|
|
27
27
|
* @param message Message to be written out
|
|
28
28
|
*/
|
|
29
29
|
static void logToConsole(std::string message) {
|
|
30
|
+
#ifdef DEBUG
|
|
30
31
|
#if defined(ANDROID) || defined(__ANDROID__)
|
|
31
32
|
__android_log_write(ANDROID_LOG_INFO, "WebGPU", message.c_str());
|
|
32
33
|
#endif
|
|
33
34
|
|
|
34
35
|
#ifdef __APPLE__
|
|
35
36
|
syslog(LOG_ERR, "%s\n", message.c_str());
|
|
37
|
+
#endif
|
|
38
|
+
#else
|
|
39
|
+
// In release mode, do nothing
|
|
40
|
+
(void)message;
|
|
36
41
|
#endif
|
|
37
42
|
}
|
|
38
43
|
|
|
@@ -42,6 +47,7 @@ public:
|
|
|
42
47
|
* @param ... Arguments to format string
|
|
43
48
|
*/
|
|
44
49
|
static void logToConsole(const char *fmt, ...) {
|
|
50
|
+
#ifdef DEBUG
|
|
45
51
|
va_list args;
|
|
46
52
|
va_start(args, fmt);
|
|
47
53
|
|
|
@@ -54,6 +60,10 @@ public:
|
|
|
54
60
|
syslog(LOG_ERR, "WebGPU: %s\n", buffer);
|
|
55
61
|
#endif
|
|
56
62
|
va_end(args);
|
|
63
|
+
#else
|
|
64
|
+
// In release mode, do nothing
|
|
65
|
+
(void)fmt;
|
|
66
|
+
#endif
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
static void logToJavascriptConsole(jsi::Runtime &runtime,
|