react-native-webgpu 0.19.2 → 0.20.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.
- package/Package.swift +19 -7
- package/android/build.gradle +7 -0
- package/apple/ApplePlatformContext.h +6 -1
- package/apple/ApplePlatformContext.mm +7 -8
- package/apple/MetalLayerColorSpace.mm +17 -1
- package/apple/WebGPUModule.mm +15 -1
- package/cpp/jsi/Promise.cpp +4 -0
- package/cpp/jsi/Promise.h +3 -0
- package/cpp/rnwgpu/CanvasColorSpace.h +5 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +2 -4
- package/cpp/rnwgpu/SurfaceRegistry.h +16 -7
- package/cpp/rnwgpu/WebGPURuntime.cpp +2 -1
- package/cpp/rnwgpu/api/GPU.cpp +6 -6
- package/cpp/rnwgpu/api/GPU.h +1 -1
- package/cpp/rnwgpu/api/GPUAdapter.cpp +28 -2
- package/cpp/rnwgpu/api/GPUBuffer.cpp +5 -6
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +2 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +38 -47
- package/cpp/rnwgpu/api/GPUDevice.h +4 -5
- package/cpp/rnwgpu/api/GPUQueue.cpp +4 -2
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +2 -2
- package/cpp/rnwgpu/api/RNWebGPU.h +9 -9
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +24 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +33 -45
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +5 -6
- package/cpp/rnwgpu/async/RuntimeContext.cpp +321 -112
- package/cpp/rnwgpu/async/RuntimeContext.h +90 -82
- package/lib/commonjs/Canvas.js +1 -0
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +19 -1
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
- package/lib/commonjs/install.js +6 -5
- package/lib/commonjs/install.js.map +1 -1
- package/lib/module/Canvas.js +1 -0
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js +19 -1
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
- package/lib/module/install.js +6 -5
- package/lib/module/install.js.map +1 -1
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/install.d.ts +6 -5
- 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/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
- package/lib/typescript/lib/module/install.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +6 -7
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +2 -3
- package/lib/typescript/src/WebGPUViewNativeComponent.web.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 +6 -5
- package/lib/typescript/src/install.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Canvas.tsx +4 -2
- package/src/WebGPUViewNativeComponent.ts +6 -10
- package/src/WebGPUViewNativeComponent.web.ts +2 -3
- package/src/external/reanimated/registerWebGPUForReanimated.ts +21 -1
- package/src/install.ts +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5D,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,YAAY,CAAC,KAAK,CAAC;IAE9B,kBAAkB,CAAC,EAAE,YAAY,CAAC,WAAW,CAC3C,aAAa,GAAG,aAAa,GAAG,oBAAoB,EACpD,aAAa,CACd,CAAC;IACF,aAAa,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACzD,kBAAkB,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC9D,yBAAyB,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CACtE;;AAGD,wBAAiE"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type {
|
|
3
|
-
import type { ViewProps } from "react-native";
|
|
2
|
+
import type { CodegenTypes, ViewProps } from "react-native";
|
|
4
3
|
export interface NativeProps extends ViewProps {
|
|
5
|
-
contextId: Int32;
|
|
4
|
+
contextId: CodegenTypes.Int32;
|
|
6
5
|
androidBackingView?: "TextureView" | "SurfaceView" | "HardwareBufferView";
|
|
7
6
|
androidOpaque?: boolean;
|
|
8
7
|
androidZOrderOnTop?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI5D,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,YAAY,CAAC,KAAK,CAAC;IAE9B,kBAAkB,CAAC,EAAE,aAAa,GAAG,aAAa,GAAG,oBAAoB,CAAC;IAC1E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAGD,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,KAAK,EAAE,WAAW,GACjB,KAAK,CAAC,GAAG,CAAC,OAAO,CAuBnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../src/external/reanimated/registerWebGPUForReanimated.ts"],"names":[],"mappings":"AAMA,UAAU,oBAAoB;IAI5B,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAC5C,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,iBAAiB,CAAC;IAI1C,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,UAAU,iBAAiB;IACzB,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,aAAa,EAAE,IAAI,CAAC;CACrB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,sBAAsB,EAAE,oBAAoB,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../src/external/reanimated/registerWebGPUForReanimated.ts"],"names":[],"mappings":"AAMA,UAAU,oBAAoB;IAI5B,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAC5C,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,iBAAiB,CAAC;IAI1C,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,UAAU,iBAAiB;IACzB,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,aAAa,EAAE,IAAI,CAAC;CACrB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,sBAAsB,EAAE,oBAAoB,GAAG,SAAS,CAAC;IAC7D,IAAI,oBAAoB,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACnE;AAID;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YAoDvC,CAAC"}
|
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
* not treat a bare `navigator` as a known global, so they capture the main
|
|
31
31
|
* runtime's `navigator` object by closure instead of reading the one this
|
|
32
32
|
* function installed.
|
|
33
|
-
* -
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
33
|
+
* - On a worklet runtime of your own (`createWorkletRuntime`, a frame
|
|
34
|
+
* processor), results are delivered while an operation is awaited there:
|
|
35
|
+
* `device.lost` and `uncapturederror` arrive with the next awaited
|
|
36
|
+
* operation on that runtime, not on their own. The main JS runtime and
|
|
37
|
+
* the Reanimated UI runtime receive them right away.
|
|
37
38
|
*
|
|
38
39
|
* Everything is captured into the worklet by closure: the constants like a
|
|
39
40
|
* shader string would be, the GPU object through the Worklets custom
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
* it crosses, and the native helper that installs the class constructors,
|
|
42
43
|
* which worklets hands to every runtime by reference. Promises returned by
|
|
43
44
|
* `requestAdapter`/`requestDevice` settle on the calling runtime (each
|
|
44
|
-
* runtime
|
|
45
|
+
* runtime has its own way of being reached, see RuntimeContext). Calling it on a runtime that already has
|
|
45
46
|
* the globals (e.g. the main JS runtime) is a safe no-op.
|
|
46
47
|
*/
|
|
47
48
|
export declare const installWebGPU: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AAwCA
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,aAAa,YAuBzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-webgpu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"yargs": "^17.7.2"
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
|
-
"react-native-webgpu-dawn": "157.
|
|
114
|
+
"react-native-webgpu-dawn": "157.1.0"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
117
|
"react": "*",
|
package/src/Canvas.tsx
CHANGED
|
@@ -208,7 +208,9 @@ const useBackingViewWarning = (android?: AndroidCanvasProps) => {
|
|
|
208
208
|
// asynchronously, so the DOM node is read directly: clientWidth/clientHeight
|
|
209
209
|
// are layout values that ignore transforms too (unlike getBoundingClientRect)
|
|
210
210
|
// and are what browser WebGPU code sizes a canvas from.
|
|
211
|
-
|
|
211
|
+
type ViewRef = React.ComponentRef<typeof View>;
|
|
212
|
+
|
|
213
|
+
const measureLayout = (view: ViewRef) => {
|
|
212
214
|
if (Platform.OS === "web") {
|
|
213
215
|
const { clientWidth, clientHeight } = view as unknown as HTMLElement;
|
|
214
216
|
return { width: clientWidth, height: clientHeight };
|
|
@@ -221,7 +223,7 @@ const measureLayout = (view: View) => {
|
|
|
221
223
|
};
|
|
222
224
|
|
|
223
225
|
export const Canvas = ({ android, ref, ...props }: CanvasProps) => {
|
|
224
|
-
const viewRef = useRef<
|
|
226
|
+
const viewRef = useRef<ViewRef>(null);
|
|
225
227
|
const [contextId, _] = useState(() => generateContextId());
|
|
226
228
|
useBackingViewWarning(android);
|
|
227
229
|
// Retire the native registry entry for this contextId on unmount. When a
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { codegenNativeComponent } from "react-native";
|
|
2
|
-
import type {
|
|
3
|
-
Int32,
|
|
4
|
-
WithDefault,
|
|
5
|
-
} from "react-native/Libraries/Types/CodegenTypes";
|
|
6
|
-
import type { ViewProps } from "react-native";
|
|
2
|
+
import type { CodegenTypes, ViewProps } from "react-native";
|
|
7
3
|
|
|
8
4
|
export interface NativeProps extends ViewProps {
|
|
9
|
-
contextId: Int32;
|
|
5
|
+
contextId: CodegenTypes.Int32;
|
|
10
6
|
// The `android` prop, resolved (see Canvas.tsx)
|
|
11
|
-
androidBackingView?: WithDefault<
|
|
7
|
+
androidBackingView?: CodegenTypes.WithDefault<
|
|
12
8
|
"TextureView" | "SurfaceView" | "HardwareBufferView",
|
|
13
9
|
"TextureView"
|
|
14
10
|
>;
|
|
15
|
-
androidOpaque?: WithDefault<boolean, false>;
|
|
16
|
-
androidZOrderOnTop?: WithDefault<boolean, false>;
|
|
17
|
-
androidZOrderMediaOverlay?: WithDefault<boolean, false>;
|
|
11
|
+
androidOpaque?: CodegenTypes.WithDefault<boolean, false>;
|
|
12
|
+
androidZOrderOnTop?: CodegenTypes.WithDefault<boolean, false>;
|
|
13
|
+
androidZOrderMediaOverlay?: CodegenTypes.WithDefault<boolean, false>;
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
// eslint-disable-next-line import/no-default-export
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { StyleSheet } from "react-native";
|
|
3
|
-
import type {
|
|
4
|
-
import type { ViewProps } from "react-native";
|
|
3
|
+
import type { CodegenTypes, ViewProps } from "react-native";
|
|
5
4
|
|
|
6
5
|
import { contextIdToId } from "./utils";
|
|
7
6
|
|
|
8
7
|
export interface NativeProps extends ViewProps {
|
|
9
|
-
contextId: Int32;
|
|
8
|
+
contextId: CodegenTypes.Int32;
|
|
10
9
|
// The `android` prop, resolved: Android-only, never reaches the DOM
|
|
11
10
|
androidBackingView?: "TextureView" | "SurfaceView" | "HardwareBufferView";
|
|
12
11
|
androidOpaque?: boolean;
|
|
@@ -23,6 +23,7 @@ interface BoxedWebGPUObject {
|
|
|
23
23
|
|
|
24
24
|
declare global {
|
|
25
25
|
var __webgpuWorkletHelpers: WebGPUWorkletHelpers | undefined;
|
|
26
|
+
var __webgpuScheduleOnUI: ((job: () => void) => void) | undefined;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
let isRegistered = false;
|
|
@@ -46,7 +47,26 @@ export const registerWebGPUForReanimated = () => {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
try {
|
|
49
|
-
const {
|
|
50
|
+
const {
|
|
51
|
+
registerCustomSerializable,
|
|
52
|
+
scheduleOnUI,
|
|
53
|
+
} = require("react-native-worklets");
|
|
54
|
+
|
|
55
|
+
// A promise created on the UI runtime (requestDevice() in a worklet, a
|
|
56
|
+
// mapAsync() there) settles on the UI runtime through a timer the
|
|
57
|
+
// runtime arms on itself; this hook settles it sooner, and delivers
|
|
58
|
+
// device.lost and uncapturederror right away: native hands a function
|
|
59
|
+
// that drains the runtime's mailbox, a host function, to this hook on
|
|
60
|
+
// the main runtime, and worklets runs it on the UI runtime (see
|
|
61
|
+
// cpp/rnwgpu/async/RuntimeContext.h).
|
|
62
|
+
if (typeof scheduleOnUI === "function") {
|
|
63
|
+
globalThis.__webgpuScheduleOnUI = (job: () => void) => {
|
|
64
|
+
scheduleOnUI(() => {
|
|
65
|
+
"worklet";
|
|
66
|
+
job();
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
50
70
|
|
|
51
71
|
registerCustomSerializable({
|
|
52
72
|
name: "WebGPU",
|
package/src/install.ts
CHANGED
|
@@ -70,10 +70,11 @@ const helpers = globalThis.__webgpuWorkletHelpers;
|
|
|
70
70
|
* not treat a bare `navigator` as a known global, so they capture the main
|
|
71
71
|
* runtime's `navigator` object by closure instead of reading the one this
|
|
72
72
|
* function installed.
|
|
73
|
-
* -
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
73
|
+
* - On a worklet runtime of your own (`createWorkletRuntime`, a frame
|
|
74
|
+
* processor), results are delivered while an operation is awaited there:
|
|
75
|
+
* `device.lost` and `uncapturederror` arrive with the next awaited
|
|
76
|
+
* operation on that runtime, not on their own. The main JS runtime and
|
|
77
|
+
* the Reanimated UI runtime receive them right away.
|
|
77
78
|
*
|
|
78
79
|
* Everything is captured into the worklet by closure: the constants like a
|
|
79
80
|
* shader string would be, the GPU object through the Worklets custom
|
|
@@ -81,7 +82,7 @@ const helpers = globalThis.__webgpuWorkletHelpers;
|
|
|
81
82
|
* it crosses, and the native helper that installs the class constructors,
|
|
82
83
|
* which worklets hands to every runtime by reference. Promises returned by
|
|
83
84
|
* `requestAdapter`/`requestDevice` settle on the calling runtime (each
|
|
84
|
-
* runtime
|
|
85
|
+
* runtime has its own way of being reached, see RuntimeContext). Calling it on a runtime that already has
|
|
85
86
|
* the globals (e.g. the main JS runtime) is a safe no-op.
|
|
86
87
|
*/
|
|
87
88
|
export const installWebGPU = () => {
|