react-native-webgpu 0.13.1 → 0.14.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 (43) hide show
  1. package/android/CMakeLists.txt +1 -0
  2. package/android/cpp/AndroidPlatformContext.h +0 -9
  3. package/android/cpp/cpp-adapter.cpp +6 -4
  4. package/android/src/main/java/com/webgpu/WebGPUView.java +8 -0
  5. package/apple/ApplePlatformContext.h +0 -3
  6. package/apple/ApplePlatformContext.mm +0 -10
  7. package/apple/MetalView.mm +4 -3
  8. package/cpp/jsi/JSIConverter.h +6 -11
  9. package/cpp/jsi/NativeObject.h +130 -18
  10. package/cpp/rnwgpu/EnforceRange.h +68 -0
  11. package/cpp/rnwgpu/PlatformContext.h +0 -2
  12. package/cpp/rnwgpu/RNWebGPUManager.cpp +7 -95
  13. package/cpp/rnwgpu/RNWebGPUManager.h +4 -3
  14. package/cpp/rnwgpu/WebGPURuntime.cpp +91 -0
  15. package/cpp/rnwgpu/WebGPURuntime.h +36 -0
  16. package/cpp/rnwgpu/api/Convertors.h +10 -1
  17. package/cpp/rnwgpu/api/DestroyedError.h +26 -0
  18. package/cpp/rnwgpu/api/GPU.cpp +3 -57
  19. package/cpp/rnwgpu/api/GPUDevice.cpp +17 -9
  20. package/cpp/rnwgpu/api/GPUError.h +15 -0
  21. package/cpp/rnwgpu/api/GPUInternalError.h +2 -0
  22. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +2 -0
  23. package/cpp/rnwgpu/api/GPUQueue.cpp +7 -21
  24. package/cpp/rnwgpu/api/GPUSharedFence.cpp +39 -12
  25. package/cpp/rnwgpu/api/GPUSharedFence.h +21 -4
  26. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +80 -4
  27. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +29 -6
  28. package/cpp/rnwgpu/api/GPUTexture.h +6 -0
  29. package/cpp/rnwgpu/api/GPUValidationError.h +2 -0
  30. package/cpp/rnwgpu/api/descriptors/Unions.h +80 -0
  31. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +13 -3
  32. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  33. package/lib/module/external/reanimated/registerWebGPUForReanimated.js +13 -3
  34. package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  35. package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  36. package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  37. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +12 -0
  38. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  39. package/lib/typescript/src/types.d.ts +2 -0
  40. package/lib/typescript/src/types.d.ts.map +1 -1
  41. package/package.json +2 -2
  42. package/src/external/reanimated/registerWebGPUForReanimated.ts +29 -7
  43. package/src/types.ts +14 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webgpu",
3
- "version": "0.13.1",
3
+ "version": "0.14.1",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -82,7 +82,7 @@
82
82
  "clang-format": "^1.8.0",
83
83
  "del-cli": "^5.1.0",
84
84
  "eslint": "9.35.0",
85
- "eslint-config-react-native-wcandillon": "5.0.0",
85
+ "eslint-config-react-native-wcandillon": "5.0.1",
86
86
  "eslint-plugin-import": "2.32.0",
87
87
  "eslint-plugin-jest": "^28.8.2",
88
88
  "eslint-plugin-prettier": "^5.2.1",
@@ -1,9 +1,25 @@
1
- // Declare global WebGPU worklet helper functions (installed by native module)
2
- declare function __webgpuIsWebGPUObject(obj: unknown): boolean;
3
- declare function __webgpuBox(obj: object): {
1
+ // The native half of the serializer (WebGPUWorkletHelpers in
2
+ // cpp/jsi/NativeObject.h), installed on the main runtime by the native module.
3
+ // determine/pack capture it by closure, and worklets hands a HostObject to
4
+ // every runtime by reference, so the serializer works wherever a WebGPU object
5
+ // is captured (Reanimated UI runtime, createWorkletRuntime, Vision Camera frame
6
+ // processors) without installing anything on those runtimes.
7
+ interface WebGPUWorkletHelpers {
8
+ // True only for WebGPU objects (their NativeState is a WebGPU class). Other
9
+ // native-state objects, such as Skia's, and objects merely inheriting from a
10
+ // WebGPU prototype are rejected, and no JS property is ever read.
11
+ isNativeObject: (value: unknown) => boolean;
12
+ box: (value: object) => BoxedWebGPUObject;
13
+ }
14
+
15
+ interface BoxedWebGPUObject {
4
16
  unbox: () => object;
5
17
  __boxedWebGPU: true;
6
- };
18
+ }
19
+
20
+ declare global {
21
+ var __webgpuWorkletHelpers: WebGPUWorkletHelpers | undefined;
22
+ }
7
23
 
8
24
  let isRegistered = false;
9
25
 
@@ -19,6 +35,12 @@ export const registerWebGPUForReanimated = () => {
19
35
  }
20
36
  isRegistered = true;
21
37
 
38
+ const helpers = globalThis.__webgpuWorkletHelpers;
39
+ if (helpers === undefined) {
40
+ // The native module is not installed (web, node): nothing to serialize.
41
+ return;
42
+ }
43
+
22
44
  try {
23
45
  const { registerCustomSerializable } = require("react-native-worklets");
24
46
 
@@ -26,13 +48,13 @@ export const registerWebGPUForReanimated = () => {
26
48
  name: "WebGPU",
27
49
  determine: (value: object): value is object => {
28
50
  "worklet";
29
- return __webgpuIsWebGPUObject(value);
51
+ return helpers.isNativeObject(value);
30
52
  },
31
53
  pack: (value: object) => {
32
54
  "worklet";
33
- return __webgpuBox(value);
55
+ return helpers.box(value);
34
56
  },
35
- unpack: (boxed: { unbox: () => object }) => {
57
+ unpack: (boxed: BoxedWebGPUObject) => {
36
58
  "worklet";
37
59
  return boxed.unbox();
38
60
  },
package/src/types.ts CHANGED
@@ -204,10 +204,17 @@ export interface GPUSharedFenceExportInfo {
204
204
  export interface GPUSharedFence {
205
205
  readonly __brand: "GPUSharedFence";
206
206
  label: string;
207
+ // Throws, after a validation error says why, if the fence was destroyed or
208
+ // Dawn can't export it.
207
209
  export(): GPUSharedFenceExportInfo;
210
+ // Releases the fence now (closing its sync fd on Android) rather than when
211
+ // the object is garbage collected. A later use is a validation error, and
212
+ // export() and beginAccess() then throw.
213
+ destroy(): void;
208
214
  }
209
215
 
210
- // A fence and the timeline value to wait for (0n for binary sync-fd fences).
216
+ // A fence and the timeline value to wait for. Binary fences (sync-fd on
217
+ // Vulkan) must use 1n: Dawn rejects any other value.
211
218
  export interface GPUSharedFenceState {
212
219
  fence: GPUSharedFence;
213
220
  signaledValue: bigint;
@@ -252,4 +259,10 @@ export interface GPUSharedTextureMemory {
252
259
  // Ends the access and returns the fences Dawn produced for it. Throws if the
253
260
  // access could not be ended.
254
261
  endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;
262
+ // Releases the memory (the imported native buffer) now rather than when the
263
+ // object is garbage collected. End the access first (a destroy() during one
264
+ // is a validation error, and the access stays open) and destroy the textures
265
+ // created from it. A later use is a validation error: createTexture() then
266
+ // returns an invalid texture, beginAccess() and endAccess() throw.
267
+ destroy(): void;
255
268
  }