react-native-webgpu 0.13.0 → 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.
- package/android/CMakeLists.txt +1 -0
- package/android/cpp/AndroidPlatformContext.h +0 -9
- package/android/cpp/cpp-adapter.cpp +6 -4
- package/android/src/main/java/com/webgpu/WebGPUView.java +8 -0
- package/apple/ApplePlatformContext.h +0 -3
- package/apple/ApplePlatformContext.mm +0 -10
- package/apple/MetalView.mm +4 -3
- package/cpp/jsi/JSIConverter.h +6 -11
- package/cpp/jsi/NativeObject.h +130 -18
- package/cpp/rnwgpu/EnforceRange.h +68 -0
- package/cpp/rnwgpu/PlatformContext.h +0 -2
- package/cpp/rnwgpu/RNWebGPUManager.cpp +7 -95
- package/cpp/rnwgpu/RNWebGPUManager.h +4 -3
- package/cpp/rnwgpu/WebGPURuntime.cpp +91 -0
- package/cpp/rnwgpu/WebGPURuntime.h +36 -0
- package/cpp/rnwgpu/api/Convertors.h +10 -1
- package/cpp/rnwgpu/api/GPU.cpp +3 -57
- package/cpp/rnwgpu/api/GPUError.h +15 -0
- package/cpp/rnwgpu/api/GPUInternalError.h +2 -0
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +2 -0
- package/cpp/rnwgpu/api/GPUQueue.cpp +7 -21
- package/cpp/rnwgpu/api/GPUTexture.h +6 -0
- package/cpp/rnwgpu/api/GPUValidationError.h +2 -0
- package/cpp/rnwgpu/api/descriptors/Unions.h +80 -0
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +13 -3
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
- package/lib/commonjs/install.js +6 -7
- package/lib/commonjs/install.js.map +1 -1
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js +13 -3
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
- package/lib/module/install.js +6 -7
- package/lib/module/install.js.map +1 -1
- package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/install.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/external/reanimated/registerWebGPUForReanimated.d.ts +12 -0
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
- package/lib/typescript/src/install.d.ts +6 -7
- package/lib/typescript/src/install.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/external/reanimated/registerWebGPUForReanimated.ts +29 -7
- package/src/install.ts +6 -7
package/lib/commonjs/install.js
CHANGED
|
@@ -54,7 +54,7 @@ const provideGPUForInstall = gpu => {
|
|
|
54
54
|
* const work = () => {
|
|
55
55
|
* "worklet";
|
|
56
56
|
* installWebGPU();
|
|
57
|
-
*
|
|
57
|
+
* navigator.gpu.requestAdapter().then((adapter) => {
|
|
58
58
|
* // ...
|
|
59
59
|
* });
|
|
60
60
|
* };
|
|
@@ -62,12 +62,11 @@ const provideGPUForInstall = gpu => {
|
|
|
62
62
|
*
|
|
63
63
|
* Known limitations:
|
|
64
64
|
*
|
|
65
|
-
* -
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* react-native-worklets versions that include it.
|
|
65
|
+
* - On react-native-worklets < 0.13.0, read `navigator` through
|
|
66
|
+
* `globalThis.navigator`: older versions of the Worklets Babel plugin do
|
|
67
|
+
* not treat a bare `navigator` as a known global, so they capture the main
|
|
68
|
+
* runtime's `navigator` object by closure instead of reading the one this
|
|
69
|
+
* function installed.
|
|
71
70
|
* - Spontaneous events are main-runtime only: on a device created on a
|
|
72
71
|
* worklet runtime, `device.lost` never settles (unless the device is
|
|
73
72
|
* already lost when read) and `uncapturederror` listeners never fire.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_constants","require","constants","GPUBufferUsage","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode","holder","provideGPUForInstall","gpu","exports","installWebGPU","g","globalThis","key","value","Object","entries","undefined","nav","navigator","userAgent"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AADA;;AASA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBC,cAAc,EAAdA,yBAAc;EACdC,eAAe,EAAfA,0BAAe;EACfC,cAAc,EAAdA,yBAAc;EACdC,aAAa,EAAbA,wBAAa;EACbC,UAAU,EAAVA;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,MAAqB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACO,MAAMC,oBAAoB,GAAIC,GAAQ,IAAK;EAChDF,MAAM,CAACE,GAAG,GAAGA,GAAG;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"names":["_constants","require","constants","GPUBufferUsage","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode","holder","provideGPUForInstall","gpu","exports","installWebGPU","g","globalThis","key","value","Object","entries","undefined","nav","navigator","userAgent"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AADA;;AASA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBC,cAAc,EAAdA,yBAAc;EACdC,eAAe,EAAfA,0BAAe;EACfC,cAAc,EAAdA,yBAAc;EACdC,aAAa,EAAbA,wBAAa;EACbC,UAAU,EAAVA;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,MAAqB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACO,MAAMC,oBAAoB,GAAIC,GAAQ,IAAK;EAChDF,MAAM,CAACE,GAAG,GAAGA,GAAG;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA1CAC,OAAA,CAAAF,oBAAA,GAAAA,oBAAA;AA2CO,MAAMG,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAAChB,SAAS,CAAC,EAAE;IACpD,IAAIW,CAAC,CAACE,GAAG,CAAC,KAAKI,SAAS,EAAE;MACxBN,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;EACA,MAAM;IAAEN;EAAI,CAAC,GAAGF,MAAM;EACtB,IAAIE,GAAG,KAAKS,SAAS,EAAE;IACrB,MAAMC,GAAG,GAAGP,CAAC,CAACQ,SAA0D;IACxE,IAAID,GAAG,KAAKD,SAAS,EAAE;MACrBN,CAAC,CAACQ,SAAS,GAAG;QAAEX,GAAG;QAAEY,SAAS,EAAE;MAAe,CAAC;IAClD,CAAC,MAAM,IAAIF,GAAG,CAACV,GAAG,KAAKS,SAAS,EAAE;MAChCC,GAAG,CAACV,GAAG,GAAGA,GAAG;IACf;EACF;AACF,CAAC;AAACC,OAAA,CAAAC,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
//
|
|
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
|
|
35
|
+
return helpers.isNativeObject(value);
|
|
26
36
|
},
|
|
27
37
|
pack: value => {
|
|
28
38
|
"worklet";
|
|
29
39
|
|
|
30
|
-
return
|
|
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","
|
|
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":[]}
|
package/lib/module/install.js
CHANGED
|
@@ -48,7 +48,7 @@ export const provideGPUForInstall = gpu => {
|
|
|
48
48
|
* const work = () => {
|
|
49
49
|
* "worklet";
|
|
50
50
|
* installWebGPU();
|
|
51
|
-
*
|
|
51
|
+
* navigator.gpu.requestAdapter().then((adapter) => {
|
|
52
52
|
* // ...
|
|
53
53
|
* });
|
|
54
54
|
* };
|
|
@@ -56,12 +56,11 @@ export const provideGPUForInstall = gpu => {
|
|
|
56
56
|
*
|
|
57
57
|
* Known limitations:
|
|
58
58
|
*
|
|
59
|
-
* -
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* react-native-worklets versions that include it.
|
|
59
|
+
* - On react-native-worklets < 0.13.0, read `navigator` through
|
|
60
|
+
* `globalThis.navigator`: older versions of the Worklets Babel plugin do
|
|
61
|
+
* not treat a bare `navigator` as a known global, so they capture the main
|
|
62
|
+
* runtime's `navigator` object by closure instead of reading the one this
|
|
63
|
+
* function installed.
|
|
65
64
|
* - Spontaneous events are main-runtime only: on a device created on a
|
|
66
65
|
* worklet runtime, `device.lost` never settles (unless the device is
|
|
67
66
|
* already lost when read) and `uncapturederror` listeners never fire.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GPUBufferUsage","GPUColorWrite","GPUMapMode","GPUShaderStage","GPUTextureUsage","constants","holder","provideGPUForInstall","gpu","installWebGPU","g","globalThis","key","value","Object","entries","undefined","nav","navigator","userAgent"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":"AAAA;AACA,SACEA,cAAc,EACdC,aAAa,EACbC,UAAU,EACVC,cAAc,EACdC,eAAe,QACV,aAAa;;AAEpB;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBL,cAAc;EACdI,eAAe;EACfD,cAAc;EACdF,aAAa;EACbC;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,MAAqB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAIC,GAAQ,IAAK;EAChDF,MAAM,CAACE,GAAG,GAAGA,GAAG;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA
|
|
1
|
+
{"version":3,"names":["GPUBufferUsage","GPUColorWrite","GPUMapMode","GPUShaderStage","GPUTextureUsage","constants","holder","provideGPUForInstall","gpu","installWebGPU","g","globalThis","key","value","Object","entries","undefined","nav","navigator","userAgent"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":"AAAA;AACA,SACEA,cAAc,EACdC,aAAa,EACbC,UAAU,EACVC,cAAc,EACdC,eAAe,QACV,aAAa;;AAEpB;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBL,cAAc;EACdI,eAAe;EACfD,cAAc;EACdF,aAAa;EACbC;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,MAAqB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAIC,GAAQ,IAAK;EAChDF,MAAM,CAACE,GAAG,GAAGA,GAAG;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACV,SAAS,CAAC,EAAE;IACpD,IAAIK,CAAC,CAACE,GAAG,CAAC,KAAKI,SAAS,EAAE;MACxBN,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;EACA,MAAM;IAAEL;EAAI,CAAC,GAAGF,MAAM;EACtB,IAAIE,GAAG,KAAKQ,SAAS,EAAE;IACrB,MAAMC,GAAG,GAAGP,CAAC,CAACQ,SAA0D;IACxE,IAAID,GAAG,KAAKD,SAAS,EAAE;MACrBN,CAAC,CAACQ,SAAS,GAAG;QAAEV,GAAG;QAAEW,SAAS,EAAE;MAAe,CAAC;IAClD,CAAC,MAAM,IAAIF,GAAG,CAACT,GAAG,KAAKQ,SAAS,EAAE;MAChCC,GAAG,CAACT,GAAG,GAAGA,GAAG;IACf;EACF;AACF,CAAC","ignoreList":[]}
|
package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../commonjs/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":";
|
|
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":"install.d.ts","sourceRoot":"","sources":["../../../commonjs/install.js"],"names":[],"mappings":";AA+BA;;;GAGG;AACH,qDAEC;
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../commonjs/install.js"],"names":[],"mappings":";AA+BA;;;GAGG;AACH,qDAEC;AA8CD,sCAuBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../module/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registerWebGPUForReanimated.d.ts","sourceRoot":"","sources":["../../../../../module/external/reanimated/registerWebGPUForReanimated.js"],"names":[],"mappings":"AAeO,oDAmCN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../module/install.js"],"names":[],"mappings":"AA6BO,qDAEN;
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../module/install.js"],"names":[],"mappings":"AA6BO,qDAEN;AA6CM,sCAuBN"}
|
|
@@ -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":"
|
|
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"}
|
|
@@ -20,7 +20,7 @@ export declare const provideGPUForInstall: (gpu: GPU) => void;
|
|
|
20
20
|
* const work = () => {
|
|
21
21
|
* "worklet";
|
|
22
22
|
* installWebGPU();
|
|
23
|
-
*
|
|
23
|
+
* navigator.gpu.requestAdapter().then((adapter) => {
|
|
24
24
|
* // ...
|
|
25
25
|
* });
|
|
26
26
|
* };
|
|
@@ -28,12 +28,11 @@ export declare const provideGPUForInstall: (gpu: GPU) => void;
|
|
|
28
28
|
*
|
|
29
29
|
* Known limitations:
|
|
30
30
|
*
|
|
31
|
-
* -
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* react-native-worklets versions that include it.
|
|
31
|
+
* - On react-native-worklets < 0.13.0, read `navigator` through
|
|
32
|
+
* `globalThis.navigator`: older versions of the Worklets Babel plugin do
|
|
33
|
+
* not treat a bare `navigator` as a known global, so they capture the main
|
|
34
|
+
* runtime's `navigator` object by closure instead of reading the one this
|
|
35
|
+
* function installed.
|
|
37
36
|
* - Spontaneous events are main-runtime only: on a device created on a
|
|
38
37
|
* worklet runtime, `device.lost` never settles (unless the device is
|
|
39
38
|
* already lost when read) and `uncapturederror` listeners never fire.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AA+BA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,GAAG,SAE5C,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AA+BA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,GAAG,SAE5C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,aAAa,YAiBzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-webgpu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"yargs": "^17.7.2"
|
|
111
111
|
},
|
|
112
112
|
"dependencies": {
|
|
113
|
-
"react-native-webgpu-dawn": "154.
|
|
113
|
+
"react-native-webgpu-dawn": "154.3.0"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
116
|
"react": "*",
|
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
51
|
+
return helpers.isNativeObject(value);
|
|
30
52
|
},
|
|
31
53
|
pack: (value: object) => {
|
|
32
54
|
"worklet";
|
|
33
|
-
return
|
|
55
|
+
return helpers.box(value);
|
|
34
56
|
},
|
|
35
|
-
unpack: (boxed:
|
|
57
|
+
unpack: (boxed: BoxedWebGPUObject) => {
|
|
36
58
|
"worklet";
|
|
37
59
|
return boxed.unbox();
|
|
38
60
|
},
|
package/src/install.ts
CHANGED
|
@@ -54,7 +54,7 @@ export const provideGPUForInstall = (gpu: GPU) => {
|
|
|
54
54
|
* const work = () => {
|
|
55
55
|
* "worklet";
|
|
56
56
|
* installWebGPU();
|
|
57
|
-
*
|
|
57
|
+
* navigator.gpu.requestAdapter().then((adapter) => {
|
|
58
58
|
* // ...
|
|
59
59
|
* });
|
|
60
60
|
* };
|
|
@@ -62,12 +62,11 @@ export const provideGPUForInstall = (gpu: GPU) => {
|
|
|
62
62
|
*
|
|
63
63
|
* Known limitations:
|
|
64
64
|
*
|
|
65
|
-
* -
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* react-native-worklets versions that include it.
|
|
65
|
+
* - On react-native-worklets < 0.13.0, read `navigator` through
|
|
66
|
+
* `globalThis.navigator`: older versions of the Worklets Babel plugin do
|
|
67
|
+
* not treat a bare `navigator` as a known global, so they capture the main
|
|
68
|
+
* runtime's `navigator` object by closure instead of reading the one this
|
|
69
|
+
* function installed.
|
|
71
70
|
* - Spontaneous events are main-runtime only: on a device created on a
|
|
72
71
|
* worklet runtime, `device.lost` never settles (unless the device is
|
|
73
72
|
* already lost when read) and `uncapturederror` listeners never fire.
|