react-native-webgpu 0.19.1 → 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.
Files changed (65) hide show
  1. package/Package.swift +19 -7
  2. package/android/build.gradle +7 -0
  3. package/apple/ApplePlatformContext.h +6 -1
  4. package/apple/ApplePlatformContext.mm +7 -8
  5. package/apple/MetalLayerColorSpace.mm +17 -1
  6. package/apple/WebGPUModule.mm +15 -1
  7. package/cpp/jsi/Promise.cpp +4 -0
  8. package/cpp/jsi/Promise.h +3 -0
  9. package/cpp/rnwgpu/CanvasColorSpace.h +5 -0
  10. package/cpp/rnwgpu/RNWebGPUManager.cpp +2 -4
  11. package/cpp/rnwgpu/SurfaceRegistry.h +16 -7
  12. package/cpp/rnwgpu/WebGPURuntime.cpp +2 -1
  13. package/cpp/rnwgpu/api/GPU.cpp +6 -6
  14. package/cpp/rnwgpu/api/GPU.h +1 -1
  15. package/cpp/rnwgpu/api/GPUAdapter.cpp +41 -3
  16. package/cpp/rnwgpu/api/GPUBuffer.cpp +5 -6
  17. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +2 -1
  18. package/cpp/rnwgpu/api/GPUDevice.cpp +38 -47
  19. package/cpp/rnwgpu/api/GPUDevice.h +4 -5
  20. package/cpp/rnwgpu/api/GPUQueue.cpp +4 -2
  21. package/cpp/rnwgpu/api/GPUShaderModule.cpp +2 -2
  22. package/cpp/rnwgpu/api/RNWebGPU.h +9 -9
  23. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +24 -0
  24. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +33 -45
  25. package/cpp/rnwgpu/async/AsyncTaskHandle.h +5 -6
  26. package/cpp/rnwgpu/async/RuntimeContext.cpp +321 -112
  27. package/cpp/rnwgpu/async/RuntimeContext.h +90 -82
  28. package/lib/commonjs/Canvas.js +1 -0
  29. package/lib/commonjs/Canvas.js.map +1 -1
  30. package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
  31. package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -1
  32. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +19 -1
  33. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  34. package/lib/commonjs/install.js +6 -5
  35. package/lib/commonjs/install.js.map +1 -1
  36. package/lib/module/Canvas.js +1 -0
  37. package/lib/module/Canvas.js.map +1 -1
  38. package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
  39. package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -1
  40. package/lib/module/external/reanimated/registerWebGPUForReanimated.js +19 -1
  41. package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  42. package/lib/module/install.js +6 -5
  43. package/lib/module/install.js.map +1 -1
  44. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
  45. package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  46. package/lib/typescript/lib/commonjs/install.d.ts +6 -5
  47. package/lib/typescript/lib/commonjs/install.d.ts.map +1 -1
  48. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  49. package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  50. package/lib/typescript/lib/module/install.d.ts.map +1 -1
  51. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  52. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +6 -7
  53. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  54. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +2 -3
  55. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
  56. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +1 -0
  57. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  58. package/lib/typescript/src/install.d.ts +6 -5
  59. package/lib/typescript/src/install.d.ts.map +1 -1
  60. package/package.json +2 -2
  61. package/src/Canvas.tsx +4 -2
  62. package/src/WebGPUViewNativeComponent.ts +6 -10
  63. package/src/WebGPUViewNativeComponent.web.ts +2 -3
  64. package/src/external/reanimated/registerWebGPUForReanimated.ts +21 -1
  65. 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,EACV,KAAK,EACL,WAAW,EACZ,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IAEjB,kBAAkB,CAAC,EAAE,WAAW,CAC9B,aAAa,GAAG,aAAa,GAAG,oBAAoB,EACpD,aAAa,CACd,CAAC;IACF,aAAa,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5C,kBAAkB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACjD,yBAAyB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CACzD;;AAGD,wBAAiE"}
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 { Int32 } from "react-native/Libraries/Types/CodegenTypes";
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,KAAK,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IAEjB,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
+ {"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"}
@@ -9,6 +9,7 @@ interface BoxedWebGPUObject {
9
9
  }
10
10
  declare global {
11
11
  var __webgpuWorkletHelpers: WebGPUWorkletHelpers | undefined;
12
+ var __webgpuScheduleOnUI: ((job: () => void) => void) | undefined;
12
13
  }
13
14
  /**
14
15
  * Register WebGPU objects for Worklets serialization.
@@ -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;CAC9D;AAID;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YAiCvC,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
- * - Spontaneous events are main-runtime only: on a device created on a
34
- * worklet runtime, `device.lost` never settles (unless the device is
35
- * already lost when read) and `uncapturederror` listeners never fire.
36
- * Observe those on a device created on the main JS thread.
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 gets its own async pump). Calling it on a runtime that already has
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,aAAa,YAuBzB,CAAC"}
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.19.1",
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.0.0"
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
- const measureLayout = (view: View) => {
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<View>(null);
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 { Int32 } from "react-native/Libraries/Types/CodegenTypes";
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 { registerCustomSerializable } = require("react-native-worklets");
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
- * - Spontaneous events are main-runtime only: on a device created on a
74
- * worklet runtime, `device.lost` never settles (unless the device is
75
- * already lost when read) and `uncapturederror` listeners never fire.
76
- * Observe those on a device created on the main JS thread.
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 gets its own async pump). Calling it on a runtime that already has
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 = () => {