react-native-webgpu 0.16.0 → 0.16.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/android/build.gradle +11 -1
- package/android/src/main/java/com/webgpu/WebGPUView.java +84 -34
- package/cpp/jsi/NativeObject.h +45 -5
- package/cpp/rnwgpu/RNWebGPUManager.cpp +49 -43
- package/cpp/rnwgpu/RNWebGPUManager.h +10 -0
- package/cpp/rnwgpu/api/GPUNativeBufferWrapper.h +1 -0
- package/lib/commonjs/Canvas.js +51 -0
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
- package/lib/commonjs/install.js +26 -7
- package/lib/commonjs/install.js.map +1 -1
- package/lib/module/Canvas.js +51 -0
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
- package/lib/module/install.js +26 -7
- package/lib/module/install.js.map +1 -1
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/install.d.ts +10 -7
- package/lib/typescript/lib/commonjs/install.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/install.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +18 -4
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +1 -0
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
- package/lib/typescript/src/install.d.ts +10 -7
- package/lib/typescript/src/install.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +1 -1
- package/package.json +6 -5
- package/plugin/build/index.js +2 -1
- package/plugin/build/setMinSdkVersion.d.ts +9 -0
- package/plugin/build/setMinSdkVersion.js +25 -0
- package/plugin/build/withMinSdkVersion.d.ts +11 -0
- package/plugin/build/withMinSdkVersion.js +20 -0
- package/src/Canvas.tsx +71 -4
- package/src/external/reanimated/registerWebGPUForReanimated.ts +4 -0
- package/src/install.ts +26 -7
- package/src/types.ts +1 -1
package/src/install.ts
CHANGED
|
@@ -29,14 +29,25 @@ const constants = {
|
|
|
29
29
|
const gpu: GPU | undefined =
|
|
30
30
|
typeof RNWebGPU === "undefined" ? undefined : RNWebGPU.gpu;
|
|
31
31
|
|
|
32
|
+
// The native half of the worklet serializer (see registerWebGPUForReanimated),
|
|
33
|
+
// read from the main runtime like `gpu` above and captured into the worklet
|
|
34
|
+
// closure: worklets hands a HostObject to every runtime by reference, so it is
|
|
35
|
+
// callable on the target runtime without installing anything there. Its
|
|
36
|
+
// installConstructors() installs the WebGPU class constructors on the runtime
|
|
37
|
+
// that calls it. Undefined on web and node, where the native module is not
|
|
38
|
+
// installed.
|
|
39
|
+
const helpers = globalThis.__webgpuWorkletHelpers;
|
|
40
|
+
|
|
32
41
|
/**
|
|
33
42
|
* Install WebGPU on the runtime that calls it.
|
|
34
43
|
*
|
|
35
44
|
* The native module sets up WebGPU on the main JS runtime, but worklet
|
|
36
45
|
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
37
|
-
* processors) start without it: `navigator.gpu
|
|
46
|
+
* processors) start without it: `navigator.gpu`, the flag constants
|
|
38
47
|
* (`GPUBufferUsage`, `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`,
|
|
39
|
-
* `GPUMapMode`)
|
|
48
|
+
* `GPUMapMode`) and the class constructors (`GPUBuffer`, `GPUTexture`,
|
|
49
|
+
* `GPURenderBundleEncoder`, ...) are all `undefined` there. Without the
|
|
50
|
+
* constructors, `instanceof` against a WebGPU class throws a ReferenceError.
|
|
40
51
|
*
|
|
41
52
|
* Call `installWebGPU()` once at the top of a worklet to make them available:
|
|
42
53
|
*
|
|
@@ -65,12 +76,13 @@ const gpu: GPU | undefined =
|
|
|
65
76
|
* Observe those on a device created on the main JS thread.
|
|
66
77
|
*
|
|
67
78
|
* Everything is captured into the worklet by closure: the constants like a
|
|
68
|
-
* shader string would be,
|
|
79
|
+
* shader string would be, the GPU object through the Worklets custom
|
|
69
80
|
* serializer, which installs the native prototypes on the target runtime when
|
|
70
|
-
* it crosses
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
81
|
+
* it crosses, and the native helper that installs the class constructors,
|
|
82
|
+
* which worklets hands to every runtime by reference. Promises returned by
|
|
83
|
+
* `requestAdapter`/`requestDevice` settle on the calling runtime (each
|
|
84
|
+
* runtime gets its own async pump). Calling it on a runtime that already has
|
|
85
|
+
* the globals (e.g. the main JS runtime) is a safe no-op.
|
|
74
86
|
*/
|
|
75
87
|
export const installWebGPU = () => {
|
|
76
88
|
"worklet";
|
|
@@ -88,4 +100,11 @@ export const installWebGPU = () => {
|
|
|
88
100
|
nav.gpu = gpu;
|
|
89
101
|
}
|
|
90
102
|
}
|
|
103
|
+
// The class constructors, so `instanceof` works against any WebGPU class on
|
|
104
|
+
// this runtime (three.js checks `pass instanceof GPURenderBundleEncoder` on
|
|
105
|
+
// every render, for instance). Unboxing an object installs only its own
|
|
106
|
+
// class; this installs the rest and skips the ones already there.
|
|
107
|
+
if (helpers !== undefined) {
|
|
108
|
+
helpers.installConstructors();
|
|
109
|
+
}
|
|
91
110
|
};
|
package/src/types.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type RNCanvasContext = GPUCanvasContext & {
|
|
|
21
21
|
*
|
|
22
22
|
* Call this after `queue.submit()` on every runtime: the main JS runtime, the
|
|
23
23
|
* Reanimated UI runtime, and dedicated worklet runtimes (e.g.
|
|
24
|
-
* `createWorkletRuntime` / `
|
|
24
|
+
* `createWorkletRuntime` / `scheduleOnRuntime`, or a Vision Camera frame
|
|
25
25
|
* processor). It runs synchronously on the calling thread, so the frame is
|
|
26
26
|
* presented from whichever thread did the rendering.
|
|
27
27
|
*/
|