react-native-webgpu 0.13.1 → 0.14.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 (34) 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/GPU.cpp +3 -57
  18. package/cpp/rnwgpu/api/GPUError.h +15 -0
  19. package/cpp/rnwgpu/api/GPUInternalError.h +2 -0
  20. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +2 -0
  21. package/cpp/rnwgpu/api/GPUQueue.cpp +7 -21
  22. package/cpp/rnwgpu/api/GPUTexture.h +6 -0
  23. package/cpp/rnwgpu/api/GPUValidationError.h +2 -0
  24. package/cpp/rnwgpu/api/descriptors/Unions.h +80 -0
  25. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +13 -3
  26. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  27. package/lib/module/external/reanimated/registerWebGPUForReanimated.js +13 -3
  28. package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  29. package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  30. package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  31. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +12 -0
  32. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/src/external/reanimated/registerWebGPUForReanimated.ts +29 -7
@@ -1,4 +1,9 @@
1
- // Declare global WebGPU worklet helper functions (installed by native module)
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.
2
7
 
3
8
  let isRegistered = false;
4
9
 
@@ -13,6 +18,11 @@ export const registerWebGPUForReanimated = () => {
13
18
  return;
14
19
  }
15
20
  isRegistered = true;
21
+ const helpers = globalThis.__webgpuWorkletHelpers;
22
+ if (helpers === undefined) {
23
+ // The native module is not installed (web, node): nothing to serialize.
24
+ return;
25
+ }
16
26
  try {
17
27
  const {
18
28
  registerCustomSerializable
@@ -22,12 +32,12 @@ export const registerWebGPUForReanimated = () => {
22
32
  determine: value => {
23
33
  "worklet";
24
34
 
25
- return __webgpuIsWebGPUObject(value);
35
+ return helpers.isNativeObject(value);
26
36
  },
27
37
  pack: value => {
28
38
  "worklet";
29
39
 
30
- return __webgpuBox(value);
40
+ return helpers.box(value);
31
41
  },
32
42
  unpack: boxed => {
33
43
  "worklet";
@@ -1 +1 @@
1
- {"version":3,"names":["isRegistered","registerWebGPUForReanimated","registerCustomSerializable","require","name","determine","value","__webgpuIsWebGPUObject","pack","__webgpuBox","unpack","boxed","unbox"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":"AAAA;;AAOA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,IAAI;IACF,MAAM;MAAEE;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOC,sBAAsB,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOG,WAAW,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAA8B,IAAK;QAC1C,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["isRegistered","registerWebGPUForReanimated","helpers","globalThis","__webgpuWorkletHelpers","undefined","registerCustomSerializable","require","name","determine","value","isNativeObject","pack","box","unpack","boxed","unbox"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;;AAkBA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,MAAME,OAAO,GAAGC,UAAU,CAACC,sBAAsB;EACjD,IAAIF,OAAO,KAAKG,SAAS,EAAE;IACzB;IACA;EACF;EAEA,IAAI;IACF,MAAM;MAAEC;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOR,OAAO,CAACS,cAAc,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOR,OAAO,CAACW,GAAG,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAAwB,IAAK;QACpC,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../commonjs/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":";AAUA;;;;;GAKG;AACH,oDA8BC"}
1
+ {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../commonjs/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":";AAeA;;;;;GAKG;AACH,oDAmCC"}
@@ -1 +1 @@
1
- {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../module/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":"AAUO,oDA8BN"}
1
+ {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../module/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":"AAeO,oDAmCN"}
@@ -1,3 +1,14 @@
1
+ interface WebGPUWorkletHelpers {
2
+ isNativeObject: (value: unknown) => boolean;
3
+ box: (value: object) => BoxedWebGPUObject;
4
+ }
5
+ interface BoxedWebGPUObject {
6
+ unbox: () => object;
7
+ __boxedWebGPU: true;
8
+ }
9
+ declare global {
10
+ var __webgpuWorkletHelpers: WebGPUWorkletHelpers | undefined;
11
+ }
1
12
  /**
2
13
  * Register WebGPU objects for Worklets serialization.
3
14
  * This allows GPUDevice, GPUCanvasContext, etc. to be passed to worklets.
@@ -5,4 +16,5 @@
5
16
  * This is called automatically when the module loads if react-native-worklets is installed.
6
17
  */
7
18
  export declare const registerWebGPUForReanimated: () => void;
19
+ export {};
8
20
  //# sourceMappingURL=registerWebGPUForReanimated.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../src/external/reanimated/registerWebGPUForReanimated.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YA2BvC,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;CAC3C;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"}
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.0",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -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
  },