react-native-webgpu 0.8.3 → 0.8.5
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/lib/commonjs/WebGPUViewNativeComponent.web.js +6 -49
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/commonjs/index.js +11 -10
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/install.js +64 -17
- package/lib/commonjs/install.js.map +1 -1
- package/lib/commonjs/main/index.js +3 -0
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/commonjs/mock.js +0 -12
- package/lib/commonjs/mock.js.map +1 -1
- package/lib/module/WebGPUViewNativeComponent.web.js +5 -48
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -1
- package/lib/module/index.js +1 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/install.js +61 -16
- package/lib/module/install.js.map +1 -1
- package/lib/module/main/index.js +3 -0
- package/lib/module/main/index.js.map +1 -1
- package/lib/module/mock.js +0 -1
- package/lib/module/mock.js.map +1 -1
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/index.d.ts +1 -0
- package/lib/typescript/lib/commonjs/install.d.ts +3 -30
- package/lib/typescript/lib/commonjs/install.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/lib/module/index.d.ts +1 -1
- package/lib/typescript/lib/module/install.d.ts +1 -0
- package/lib/typescript/lib/module/install.d.ts.map +1 -1
- package/lib/typescript/lib/module/mock.d.ts +0 -1
- package/lib/typescript/lib/module/mock.d.ts.map +1 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/install.d.ts +33 -16
- package/lib/typescript/src/install.d.ts.map +1 -1
- package/lib/typescript/src/main/index.d.ts.map +1 -1
- package/lib/typescript/src/mock.d.ts +0 -1
- package/lib/typescript/src/mock.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/WebGPUViewNativeComponent.web.ts +4 -60
- package/src/index.tsx +1 -1
- package/src/install.ts +56 -16
- package/src/main/index.tsx +3 -0
- package/src/mock.ts +0 -1
|
@@ -4,43 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = WebGPUViewNativeComponent;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _utils = require("./utils");
|
|
10
|
-
function
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
function debounce(func, wait, immediate = false) {
|
|
13
|
-
let timeout;
|
|
14
|
-
return function debounced(...args) {
|
|
15
|
-
const context = this;
|
|
16
|
-
const callNow = immediate && !timeout;
|
|
17
|
-
if (timeout) {
|
|
18
|
-
clearTimeout(timeout);
|
|
19
|
-
}
|
|
20
|
-
timeout = setTimeout(() => {
|
|
21
|
-
timeout = undefined;
|
|
22
|
-
if (!immediate) {
|
|
23
|
-
func.apply(context, args);
|
|
24
|
-
}
|
|
25
|
-
}, wait);
|
|
26
|
-
if (callNow) {
|
|
27
|
-
func.apply(context, args);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function resizeCanvas(canvas) {
|
|
32
|
-
if (!canvas) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const dpr = window.devicePixelRatio || 1;
|
|
36
|
-
const {
|
|
37
|
-
height,
|
|
38
|
-
width
|
|
39
|
-
} = canvas.getBoundingClientRect();
|
|
40
|
-
canvas.setAttribute("height", (height * dpr).toString());
|
|
41
|
-
canvas.setAttribute("width", (width * dpr).toString());
|
|
42
|
-
}
|
|
43
|
-
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
44
11
|
// eslint-disable-next-line import/no-default-export
|
|
45
12
|
function WebGPUViewNativeComponent(props) {
|
|
46
13
|
const {
|
|
@@ -49,14 +16,10 @@ function WebGPUViewNativeComponent(props) {
|
|
|
49
16
|
transparent,
|
|
50
17
|
...rest
|
|
51
18
|
} = props;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return () => {
|
|
57
|
-
window.removeEventListener("resize", onResize);
|
|
58
|
-
};
|
|
59
|
-
}, []);
|
|
19
|
+
|
|
20
|
+
// MakeWebGPUCanvasContext sets the initial drawing-buffer size. Subsequent
|
|
21
|
+
// resizes belong to the renderer so it can recreate depth/MSAA attachments
|
|
22
|
+
// together; changing canvas.width/height here would invalidate its textures.
|
|
60
23
|
return /*#__PURE__*/_react.default.createElement("canvas", {
|
|
61
24
|
...rest,
|
|
62
25
|
id: (0, _utils.contextIdToId)(contextId),
|
|
@@ -67,12 +30,6 @@ function WebGPUViewNativeComponent(props) {
|
|
|
67
30
|
backgroundColor: "white"
|
|
68
31
|
} : {}),
|
|
69
32
|
...(typeof style === "object" ? style : {})
|
|
70
|
-
},
|
|
71
|
-
ref: ref => {
|
|
72
|
-
canvasElm.current = ref;
|
|
73
|
-
if (ref) {
|
|
74
|
-
resizeCanvas(ref);
|
|
75
|
-
}
|
|
76
33
|
}
|
|
77
34
|
});
|
|
78
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_utils","e","__esModule","default","WebGPUViewNativeComponent","props","contextId","style","transparent","rest","React","createElement","id","contextIdToId","styles","view","flex1","backgroundColor","StyleSheet","create","flex","alignItems","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","zIndex"],"sourceRoot":"../../src","sources":["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AAC;IACXC,OAAO,EAAE,CAAC;IACVC,QAAQ,EAAE,UAAU;IACpBC,MAAM,EAAE;EACV;AACF,CAAC,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,9 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
installWebGPU: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "installWebGPU", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _install.installWebGPU;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
var _main = require("./main");
|
|
7
16
|
Object.keys(_main).forEach(function (key) {
|
|
8
17
|
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
9
19
|
if (key in exports && exports[key] === _main[key]) return;
|
|
10
20
|
Object.defineProperty(exports, key, {
|
|
11
21
|
enumerable: true,
|
|
@@ -17,6 +27,7 @@ Object.keys(_main).forEach(function (key) {
|
|
|
17
27
|
var _constants = require("./constants");
|
|
18
28
|
Object.keys(_constants).forEach(function (key) {
|
|
19
29
|
if (key === "default" || key === "__esModule") return;
|
|
30
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
31
|
if (key in exports && exports[key] === _constants[key]) return;
|
|
21
32
|
Object.defineProperty(exports, key, {
|
|
22
33
|
enumerable: true,
|
|
@@ -26,14 +37,4 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
26
37
|
});
|
|
27
38
|
});
|
|
28
39
|
var _install = require("./install");
|
|
29
|
-
Object.keys(_install).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _install[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _install[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_main","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_constants","_install"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_main","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_constants","_install"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;AAcA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,UAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,UAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,QAAA,GAAAd,OAAA","ignoreList":[]}
|
package/lib/commonjs/install.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.installWebGPU = void 0;
|
|
6
|
+
exports.provideGPUForInstall = exports.installWebGPU = void 0;
|
|
7
7
|
var _constants = require("./constants");
|
|
8
|
+
/// <reference types="@webgpu/types" />
|
|
9
|
+
|
|
8
10
|
// Globals that this function installs on the calling runtime. These are the
|
|
9
11
|
// native-derived flag constants re-exported from `./constants` (a single source
|
|
10
12
|
// of truth, matching the native `wgpu::*Usage` enums), so they are safe to set
|
|
@@ -17,38 +19,69 @@ const constants = {
|
|
|
17
19
|
GPUMapMode: _constants.GPUMapMode
|
|
18
20
|
};
|
|
19
21
|
|
|
22
|
+
// The GPU instance destined for `navigator.gpu` on other runtimes, wrapped in
|
|
23
|
+
// a holder object. It cannot be read at module evaluation: this module can be
|
|
24
|
+
// evaluated before the native install has populated `RNWebGPU.gpu`, so
|
|
25
|
+
// `main/index.tsx` fills the holder right after installing. The holder itself
|
|
26
|
+
// is captured into the `installWebGPU` worklet closure; when a worklet is
|
|
27
|
+
// serialized (always after startup, so after the holder is filled), the
|
|
28
|
+
// Worklets custom serializer boxes the GPU object inside it, and unboxing on
|
|
29
|
+
// the target runtime installs the GPU prototype there.
|
|
30
|
+
const holder = {};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal Called once by `main/index.tsx` after the native install, so
|
|
34
|
+
* `installWebGPU()` can put `navigator.gpu` on other runtimes.
|
|
35
|
+
*/
|
|
36
|
+
const provideGPUForInstall = gpu => {
|
|
37
|
+
holder.gpu = gpu;
|
|
38
|
+
};
|
|
39
|
+
|
|
20
40
|
/**
|
|
21
41
|
* Install WebGPU on the runtime that calls it.
|
|
22
42
|
*
|
|
23
|
-
* The native module
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
43
|
+
* The native module sets up WebGPU on the main JS runtime, but worklet
|
|
44
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
45
|
+
* processors) start without it: `navigator.gpu` and the flag constants
|
|
46
|
+
* (`GPUBufferUsage`, `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`,
|
|
47
|
+
* `GPUMapMode`) are all `undefined` there.
|
|
28
48
|
*
|
|
29
|
-
* Call `installWebGPU()` once at the top of a worklet to make
|
|
30
|
-
* available there, instead of importing each constant by hand:
|
|
49
|
+
* Call `installWebGPU()` once at the top of a worklet to make them available:
|
|
31
50
|
*
|
|
32
51
|
* ```tsx
|
|
33
52
|
* import { installWebGPU } from "react-native-webgpu";
|
|
34
53
|
*
|
|
35
|
-
* const work = (
|
|
54
|
+
* const work = () => {
|
|
36
55
|
* "worklet";
|
|
37
56
|
* installWebGPU();
|
|
38
|
-
*
|
|
39
|
-
*
|
|
57
|
+
* globalThis.navigator.gpu.requestAdapter().then((adapter) => {
|
|
58
|
+
* // ...
|
|
40
59
|
* });
|
|
41
60
|
* };
|
|
42
61
|
* ```
|
|
43
62
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
63
|
+
* Known limitations:
|
|
64
|
+
*
|
|
65
|
+
* - Read `navigator` through `globalThis.navigator`: the Worklets Babel
|
|
66
|
+
* plugin does not treat a bare `navigator` as a known global, so it would
|
|
67
|
+
* capture the main runtime's `navigator` object by closure instead of
|
|
68
|
+
* reading the one this function installed. Fixed upstream in
|
|
69
|
+
* react-native-reanimated#10364; the prefix becomes unnecessary on
|
|
70
|
+
* react-native-worklets versions that include it.
|
|
71
|
+
* - Spontaneous events are main-runtime only: on a device created on a
|
|
72
|
+
* worklet runtime, `device.lost` never settles (unless the device is
|
|
73
|
+
* already lost when read) and `uncapturederror` listeners never fire.
|
|
74
|
+
* Observe those on a device created on the main JS thread.
|
|
47
75
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
76
|
+
* Everything is captured into the worklet by closure: the constants like a
|
|
77
|
+
* shader string would be, and the GPU object through the Worklets custom
|
|
78
|
+
* serializer, which installs the native prototypes on the target runtime when
|
|
79
|
+
* it crosses. Promises returned by `requestAdapter`/`requestDevice` settle on
|
|
80
|
+
* the calling runtime (each runtime gets its own async pump). Calling it on a
|
|
81
|
+
* runtime that already has the globals (e.g. the main JS runtime) is a safe
|
|
82
|
+
* no-op.
|
|
51
83
|
*/
|
|
84
|
+
exports.provideGPUForInstall = provideGPUForInstall;
|
|
52
85
|
const installWebGPU = () => {
|
|
53
86
|
"worklet";
|
|
54
87
|
|
|
@@ -58,6 +91,20 @@ const installWebGPU = () => {
|
|
|
58
91
|
g[key] = value;
|
|
59
92
|
}
|
|
60
93
|
}
|
|
94
|
+
const {
|
|
95
|
+
gpu
|
|
96
|
+
} = holder;
|
|
97
|
+
if (gpu !== undefined) {
|
|
98
|
+
const nav = g.navigator;
|
|
99
|
+
if (nav === undefined) {
|
|
100
|
+
g.navigator = {
|
|
101
|
+
gpu,
|
|
102
|
+
userAgent: "react-native"
|
|
103
|
+
};
|
|
104
|
+
} else if (nav.gpu === undefined) {
|
|
105
|
+
nav.gpu = gpu;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
61
108
|
};
|
|
62
109
|
exports.installWebGPU = installWebGPU;
|
|
63
110
|
//# sourceMappingURL=install.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_constants","require","constants","GPUBufferUsage","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode","installWebGPU","g","globalThis","key","value","Object","entries","undefined","
|
|
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;AACA;AA3CAC,OAAA,CAAAF,oBAAA,GAAAA,oBAAA;AA4CO,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":[]}
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "WebGPUModule", {
|
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
var _external = require("../external");
|
|
16
|
+
var _install = require("../install");
|
|
16
17
|
var _NativeWebGPUModule = _interopRequireDefault(require("../NativeWebGPUModule"));
|
|
17
18
|
var _Canvas = require("../Canvas");
|
|
18
19
|
Object.keys(_Canvas).forEach(function (key) {
|
|
@@ -121,6 +122,8 @@ if (typeof RNWebGPU !== "undefined") {
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
global.createImageBitmap = global.createImageBitmap ?? RNWebGPU.createImageBitmap.bind(RNWebGPU);
|
|
125
|
+
// Let installWebGPU() put navigator.gpu on other runtimes (see install.ts).
|
|
126
|
+
(0, _install.provideGPUForInstall)(RNWebGPU.gpu);
|
|
124
127
|
} else {
|
|
125
128
|
console.warn(`[react-native-webgpu] install() returned ${_installOk} but RNWebGPU global is not available`);
|
|
126
129
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_external","require","_NativeWebGPUModule","_interopRequireDefault","_Canvas","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_Offscreen","_WebGPUViewNativeComponent","_hooks","_GPUDeviceProvider","_importDevice","_formats","e","__esModule","default","_installOk","WebGPUModule","install","registerWebGPUForReanimated","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind","console","warn"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAC,sBAAA,
|
|
1
|
+
{"version":3,"names":["_external","require","_install","_NativeWebGPUModule","_interopRequireDefault","_Canvas","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_Offscreen","_WebGPUViewNativeComponent","_hooks","_GPUDeviceProvider","_importDevice","_formats","e","__esModule","default","_installOk","WebGPUModule","install","registerWebGPUForReanimated","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind","provideGPUForInstall","console","warn"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AAAAK,MAAA,CAAAC,IAAA,CAAAF,OAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,OAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,OAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAjB,OAAA;AAAAK,MAAA,CAAAC,IAAA,CAAAW,UAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,UAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OA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A;AAI3B,MAAMG,UAAU,GAAGC,2BAAY,CAACC,OAAO,CAAC,CAAC;AAEzC,IAAAC,qCAA2B,EAAC,CAAC;AAE7B,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EACnC,IAAI,CAACC,SAAS,EAAE;IACd;IACAA,SAAS,GAAG;MACVC,GAAG,EAAEF,QAAQ,CAACE,GAAG;MACjBC,SAAS,EAAE;IACb,CAAC;EACH,CAAC,MAAM;IACLF,SAAS,CAACC,GAAG,GAAGF,QAAQ,CAACE,GAAG;IAC5B,IAAI,OAAOD,SAAS,CAACE,SAAS,KAAK,QAAQ,EAAE;MAC3C,IAAI;QACF;QACA;QACAF,SAAS,CAACE,SAAS,GAAG,cAAc;MACtC,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;EACAC,MAAM,CAACC,iBAAiB,GACtBD,MAAM,CAACC,iBAAiB,IAAIL,QAAQ,CAACK,iBAAiB,CAACC,IAAI,CAACN,QAAQ,CAAC;EACvE;EACA,IAAAO,6BAAoB,EAACP,QAAQ,CAACE,GAAG,CAAC;AACpC,CAAC,MAAM;EACLM,OAAO,CAACC,IAAI,CACV,4CAA4Cb,UAAU,uCACxD,CAAC;AACH","ignoreList":[]}
|
package/lib/commonjs/mock.js
CHANGED
|
@@ -31,18 +31,6 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
|
-
var _install = require("./install");
|
|
35
|
-
Object.keys(_install).forEach(function (key) {
|
|
36
|
-
if (key === "default" || key === "__esModule") return;
|
|
37
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
38
|
-
if (key in exports && exports[key] === _install[key]) return;
|
|
39
|
-
Object.defineProperty(exports, key, {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function () {
|
|
42
|
-
return _install[key];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
34
|
var _formats = require("./formats");
|
|
47
35
|
Object.keys(_formats).forEach(function (key) {
|
|
48
36
|
if (key === "default" || key === "__esModule") return;
|
package/lib/commonjs/mock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_constants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_constants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_formats","e","__esModule","default","NOT_AVAILABLE_UNDER_JEST","Canvas","transparent","_transparent","ref","props","React","useImperativeHandle","getContextId","getContext","_contextName","getNativeSurface","Error","createElement","View","useCanvasRef","useRef","useSurface","surface","warnIfNotHardwareAccelerated","undefined","useDevice","adapter","device","GPUDeviceProvider","children","useMainDevice","importDevice","_pointer","adoptTexture","installWebGPU","WebGPUModule","install"],"sourceRoot":"../../src","sources":["mock.ts"],"mappings":";;;;;;;;;;;;;;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAgBA,IAAAE,UAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,UAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,UAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,UAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,QAAA,GAAAf,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAA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import { StyleSheet } from "react-native";
|
|
3
3
|
import { contextIdToId } from "./utils";
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
function debounce(func, wait, immediate = false) {
|
|
6
|
-
let timeout;
|
|
7
|
-
return function debounced(...args) {
|
|
8
|
-
const context = this;
|
|
9
|
-
const callNow = immediate && !timeout;
|
|
10
|
-
if (timeout) {
|
|
11
|
-
clearTimeout(timeout);
|
|
12
|
-
}
|
|
13
|
-
timeout = setTimeout(() => {
|
|
14
|
-
timeout = undefined;
|
|
15
|
-
if (!immediate) {
|
|
16
|
-
func.apply(context, args);
|
|
17
|
-
}
|
|
18
|
-
}, wait);
|
|
19
|
-
if (callNow) {
|
|
20
|
-
func.apply(context, args);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function resizeCanvas(canvas) {
|
|
25
|
-
if (!canvas) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const dpr = window.devicePixelRatio || 1;
|
|
29
|
-
const {
|
|
30
|
-
height,
|
|
31
|
-
width
|
|
32
|
-
} = canvas.getBoundingClientRect();
|
|
33
|
-
canvas.setAttribute("height", (height * dpr).toString());
|
|
34
|
-
canvas.setAttribute("width", (width * dpr).toString());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
4
|
// eslint-disable-next-line import/no-default-export
|
|
38
5
|
export default function WebGPUViewNativeComponent(props) {
|
|
39
6
|
const {
|
|
@@ -42,14 +9,10 @@ export default function WebGPUViewNativeComponent(props) {
|
|
|
42
9
|
transparent,
|
|
43
10
|
...rest
|
|
44
11
|
} = props;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return () => {
|
|
50
|
-
window.removeEventListener("resize", onResize);
|
|
51
|
-
};
|
|
52
|
-
}, []);
|
|
12
|
+
|
|
13
|
+
// MakeWebGPUCanvasContext sets the initial drawing-buffer size. Subsequent
|
|
14
|
+
// resizes belong to the renderer so it can recreate depth/MSAA attachments
|
|
15
|
+
// together; changing canvas.width/height here would invalidate its textures.
|
|
53
16
|
return /*#__PURE__*/React.createElement("canvas", {
|
|
54
17
|
...rest,
|
|
55
18
|
id: contextIdToId(contextId),
|
|
@@ -60,12 +23,6 @@ export default function WebGPUViewNativeComponent(props) {
|
|
|
60
23
|
backgroundColor: "white"
|
|
61
24
|
} : {}),
|
|
62
25
|
...(typeof style === "object" ? style : {})
|
|
63
|
-
},
|
|
64
|
-
ref: ref => {
|
|
65
|
-
canvasElm.current = ref;
|
|
66
|
-
if (ref) {
|
|
67
|
-
resizeCanvas(ref);
|
|
68
|
-
}
|
|
69
26
|
}
|
|
70
27
|
});
|
|
71
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
1
|
+
{"version":3,"names":["React","StyleSheet","contextIdToId","WebGPUViewNativeComponent","props","contextId","style","transparent","rest","createElement","id","styles","view","flex1","backgroundColor","create","flex","alignItems","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","zIndex"],"sourceRoot":"../../src","sources":["WebGPUViewNativeComponent.web.ts"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,UAAU,QAAQ,cAAc;AAIzC,SAASC,aAAa,QAAQ,SAAS;AAOvC;AACA,eAAe,SAASC,yBAAyBA,CAC/CC,KAAkB,EACC;EACnB,MAAM;IAAEC,SAAS;IAAEC,KAAK;IAAEC,WAAW;IAAE,GAAGC;EAAK,CAAC,GAAGJ,KAAK;;EAExD;EACA;EACA;EACA,oBAAOJ,KAAK,CAACS,aAAa,CAAC,QAAQ,EAAE;IACnC,GAAGD,IAAI;IACPE,EAAE,EAAER,aAAa,CAACG,SAAS,CAAC;IAC5BC,KAAK,EAAE;MACL,GAAGK,MAAM,CAACC,IAAI;MACd,GAAGD,MAAM,CAACE,KAAK;MACf,IAAIN,WAAW,KAAK,KAAK,GAAG;QAAEO,eAAe,EAAE;MAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;MAC9D,IAAI,OAAOR,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAG,CAAC,CAAC;IAC5C;EACF,CAAC,CAAC;AACJ;AAEA,MAAMK,MAAM,GAAGV,UAAU,CAACc,MAAM,CAAC;EAC/BF,KAAK,EAAE;IACLG,IAAI,EAAE;EACR,CAAC;EACDJ,IAAI,EAAE;IACJK,UAAU,EAAE,SAAS;IACrBH,eAAe,EAAE,aAAa;IAC9B;IACA;IACAI,MAAM,EAAE,eAAe;IACvBC,SAAS,EAAE,YAAY;IACvBC,OAAO,EAAE,MAAM;IACfC,SAAS,EAAE,MAAM;IACjBC,aAAa,EAAE,QAAQ;IACvBC,UAAU,EAAE,CAAC;IACbC,SAAS,EAAE,MAAM;IACjBC,MAAM,EAAE,CAAC;IACTC,SAAS,EAAE,CAAC;IACZC,QAAQ,EAAE,CAAC;IACXC,OAAO,EAAE,CAAC;IACVC,QAAQ,EAAE,UAAU;IACpBC,MAAM,EAAE;EACV;AACF,CAAC,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA;;AAcA,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,
|
|
1
|
+
{"version":3,"names":["installWebGPU"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA;;AAcA,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,SAASA,aAAa,QAAQ,WAAW","ignoreList":[]}
|
package/lib/module/install.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
1
2
|
import { GPUBufferUsage, GPUColorWrite, GPUMapMode, GPUShaderStage, GPUTextureUsage } from "./constants";
|
|
2
3
|
|
|
3
4
|
// Globals that this function installs on the calling runtime. These are the
|
|
@@ -12,37 +13,67 @@ const constants = {
|
|
|
12
13
|
GPUMapMode
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
// The GPU instance destined for `navigator.gpu` on other runtimes, wrapped in
|
|
17
|
+
// a holder object. It cannot be read at module evaluation: this module can be
|
|
18
|
+
// evaluated before the native install has populated `RNWebGPU.gpu`, so
|
|
19
|
+
// `main/index.tsx` fills the holder right after installing. The holder itself
|
|
20
|
+
// is captured into the `installWebGPU` worklet closure; when a worklet is
|
|
21
|
+
// serialized (always after startup, so after the holder is filled), the
|
|
22
|
+
// Worklets custom serializer boxes the GPU object inside it, and unboxing on
|
|
23
|
+
// the target runtime installs the GPU prototype there.
|
|
24
|
+
const holder = {};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @internal Called once by `main/index.tsx` after the native install, so
|
|
28
|
+
* `installWebGPU()` can put `navigator.gpu` on other runtimes.
|
|
29
|
+
*/
|
|
30
|
+
export const provideGPUForInstall = gpu => {
|
|
31
|
+
holder.gpu = gpu;
|
|
32
|
+
};
|
|
33
|
+
|
|
15
34
|
/**
|
|
16
35
|
* Install WebGPU on the runtime that calls it.
|
|
17
36
|
*
|
|
18
|
-
* The native module
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
37
|
+
* The native module sets up WebGPU on the main JS runtime, but worklet
|
|
38
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
39
|
+
* processors) start without it: `navigator.gpu` and the flag constants
|
|
40
|
+
* (`GPUBufferUsage`, `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`,
|
|
41
|
+
* `GPUMapMode`) are all `undefined` there.
|
|
23
42
|
*
|
|
24
|
-
* Call `installWebGPU()` once at the top of a worklet to make
|
|
25
|
-
* available there, instead of importing each constant by hand:
|
|
43
|
+
* Call `installWebGPU()` once at the top of a worklet to make them available:
|
|
26
44
|
*
|
|
27
45
|
* ```tsx
|
|
28
46
|
* import { installWebGPU } from "react-native-webgpu";
|
|
29
47
|
*
|
|
30
|
-
* const work = (
|
|
48
|
+
* const work = () => {
|
|
31
49
|
* "worklet";
|
|
32
50
|
* installWebGPU();
|
|
33
|
-
*
|
|
34
|
-
*
|
|
51
|
+
* globalThis.navigator.gpu.requestAdapter().then((adapter) => {
|
|
52
|
+
* // ...
|
|
35
53
|
* });
|
|
36
54
|
* };
|
|
37
55
|
* ```
|
|
38
56
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
57
|
+
* Known limitations:
|
|
58
|
+
*
|
|
59
|
+
* - Read `navigator` through `globalThis.navigator`: the Worklets Babel
|
|
60
|
+
* plugin does not treat a bare `navigator` as a known global, so it would
|
|
61
|
+
* capture the main runtime's `navigator` object by closure instead of
|
|
62
|
+
* reading the one this function installed. Fixed upstream in
|
|
63
|
+
* react-native-reanimated#10364; the prefix becomes unnecessary on
|
|
64
|
+
* react-native-worklets versions that include it.
|
|
65
|
+
* - Spontaneous events are main-runtime only: on a device created on a
|
|
66
|
+
* worklet runtime, `device.lost` never settles (unless the device is
|
|
67
|
+
* already lost when read) and `uncapturederror` listeners never fire.
|
|
68
|
+
* Observe those on a device created on the main JS thread.
|
|
42
69
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
70
|
+
* Everything is captured into the worklet by closure: the constants like a
|
|
71
|
+
* shader string would be, and the GPU object through the Worklets custom
|
|
72
|
+
* serializer, which installs the native prototypes on the target runtime when
|
|
73
|
+
* it crosses. Promises returned by `requestAdapter`/`requestDevice` settle on
|
|
74
|
+
* the calling runtime (each runtime gets its own async pump). Calling it on a
|
|
75
|
+
* runtime that already has the globals (e.g. the main JS runtime) is a safe
|
|
76
|
+
* no-op.
|
|
46
77
|
*/
|
|
47
78
|
export const installWebGPU = () => {
|
|
48
79
|
"worklet";
|
|
@@ -53,5 +84,19 @@ export const installWebGPU = () => {
|
|
|
53
84
|
g[key] = value;
|
|
54
85
|
}
|
|
55
86
|
}
|
|
87
|
+
const {
|
|
88
|
+
gpu
|
|
89
|
+
} = holder;
|
|
90
|
+
if (gpu !== undefined) {
|
|
91
|
+
const nav = g.navigator;
|
|
92
|
+
if (nav === undefined) {
|
|
93
|
+
g.navigator = {
|
|
94
|
+
gpu,
|
|
95
|
+
userAgent: "react-native"
|
|
96
|
+
};
|
|
97
|
+
} else if (nav.gpu === undefined) {
|
|
98
|
+
nav.gpu = gpu;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
56
101
|
};
|
|
57
102
|
//# sourceMappingURL=install.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GPUBufferUsage","GPUColorWrite","GPUMapMode","GPUShaderStage","GPUTextureUsage","constants","installWebGPU","g","globalThis","key","value","Object","entries","undefined"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":"AAAA,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;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,
|
|
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;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/module/main/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { registerWebGPUForReanimated } from "../external";
|
|
2
|
+
import { provideGPUForInstall } from "../install";
|
|
2
3
|
import WebGPUModule from "../NativeWebGPUModule";
|
|
3
4
|
export * from "../Canvas";
|
|
4
5
|
export * from "../Offscreen";
|
|
@@ -30,6 +31,8 @@ if (typeof RNWebGPU !== "undefined") {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
global.createImageBitmap = global.createImageBitmap ?? RNWebGPU.createImageBitmap.bind(RNWebGPU);
|
|
34
|
+
// Let installWebGPU() put navigator.gpu on other runtimes (see install.ts).
|
|
35
|
+
provideGPUForInstall(RNWebGPU.gpu);
|
|
33
36
|
} else {
|
|
34
37
|
console.warn(`[react-native-webgpu] install() returned ${_installOk} but RNWebGPU global is not available`);
|
|
35
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerWebGPUForReanimated","WebGPUModule","default","_installOk","install","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind","console","warn"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,aAAa;AACzD,OAAOC,YAAY,MAAM,uBAAuB;AAEhD,cAAc,WAAW;AACzB,cAAc,cAAc;AAC5B,cAAc,8BAA8B;AAC5C,cAAc,UAAU;AACxB,cAAc,sBAAsB;AACpC,cAAc,iBAAiB;AAC/B,cAAc,YAAY;AAE1B,SAASC,OAAO,IAAID,YAAY,QAAQ,uBAAuB;AAE/D,MAAME,UAAU,GAAGF,YAAY,CAACG,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"names":["registerWebGPUForReanimated","provideGPUForInstall","WebGPUModule","default","_installOk","install","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind","console","warn"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,aAAa;AACzD,SAASC,oBAAoB,QAAQ,YAAY;AACjD,OAAOC,YAAY,MAAM,uBAAuB;AAEhD,cAAc,WAAW;AACzB,cAAc,cAAc;AAC5B,cAAc,8BAA8B;AAC5C,cAAc,UAAU;AACxB,cAAc,sBAAsB;AACpC,cAAc,iBAAiB;AAC/B,cAAc,YAAY;AAE1B,SAASC,OAAO,IAAID,YAAY,QAAQ,uBAAuB;AAE/D,MAAME,UAAU,GAAGF,YAAY,CAACG,OAAO,CAAC,CAAC;AAEzCL,2BAA2B,CAAC,CAAC;AAE7B,IAAI,OAAOM,QAAQ,KAAK,WAAW,EAAE;EACnC,IAAI,CAACC,SAAS,EAAE;IACd;IACAA,SAAS,GAAG;MACVC,GAAG,EAAEF,QAAQ,CAACE,GAAG;MACjBC,SAAS,EAAE;IACb,CAAC;EACH,CAAC,MAAM;IACLF,SAAS,CAACC,GAAG,GAAGF,QAAQ,CAACE,GAAG;IAC5B,IAAI,OAAOD,SAAS,CAACE,SAAS,KAAK,QAAQ,EAAE;MAC3C,IAAI;QACF;QACA;QACAF,SAAS,CAACE,SAAS,GAAG,cAAc;MACtC,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;EACAC,MAAM,CAACC,iBAAiB,GACtBD,MAAM,CAACC,iBAAiB,IAAIL,QAAQ,CAACK,iBAAiB,CAACC,IAAI,CAACN,QAAQ,CAAC;EACvE;EACAL,oBAAoB,CAACK,QAAQ,CAACE,GAAG,CAAC;AACpC,CAAC,MAAM;EACLK,OAAO,CAACC,IAAI,CACV,4CAA4CV,UAAU,uCACxD,CAAC;AACH","ignoreList":[]}
|
package/lib/module/mock.js
CHANGED
|
@@ -13,7 +13,6 @@ import { View } from "react-native";
|
|
|
13
13
|
// `./importDevice.ts`).
|
|
14
14
|
|
|
15
15
|
export * from "./constants";
|
|
16
|
-
export * from "./install";
|
|
17
16
|
export * from "./formats";
|
|
18
17
|
const NOT_AVAILABLE_UNDER_JEST = "is not available under Jest - react-native-webgpu has no native implementation in tests (see react-native-webgpu/jestSetup.js)";
|
|
19
18
|
export const Canvas = ({
|
package/lib/module/mock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","View","NOT_AVAILABLE_UNDER_JEST","Canvas","transparent","_transparent","ref","props","useImperativeHandle","getContextId","getContext","_contextName","getNativeSurface","Error","createElement","useCanvasRef","useRef","useSurface","surface","warnIfNotHardwareAccelerated","undefined","useDevice","adapter","device","GPUDeviceProvider","children","useMainDevice","importDevice","_pointer","adoptTexture","installWebGPU","WebGPUModule","install"],"sourceRoot":"../../src","sources":["mock.ts"],"mappings":"AAAA;AACA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,IAAI,QAAQ,cAAc;AAKnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,cAAc,aAAa;AAC3B,cAAc,WAAW;
|
|
1
|
+
{"version":3,"names":["React","View","NOT_AVAILABLE_UNDER_JEST","Canvas","transparent","_transparent","ref","props","useImperativeHandle","getContextId","getContext","_contextName","getNativeSurface","Error","createElement","useCanvasRef","useRef","useSurface","surface","warnIfNotHardwareAccelerated","undefined","useDevice","adapter","device","GPUDeviceProvider","children","useMainDevice","importDevice","_pointer","adoptTexture","installWebGPU","WebGPUModule","install"],"sourceRoot":"../../src","sources":["mock.ts"],"mappings":"AAAA;AACA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,IAAI,QAAQ,cAAc;AAKnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,cAAc,aAAa;AAC3B,cAAc,WAAW;AAEzB,MAAMC,wBAAwB,GAC5B,gIAAgI;AASlI,OAAO,MAAMC,MAAM,GAAGA,CAAC;EACrBC,WAAW,EAAEC,YAAY;EACzBC,GAAG;EACH,GAAGC;AACQ,CAAC,KAAK;EACjBP,KAAK,CAACQ,mBAAmB,CAACF,GAAG,EAAE,OAAO;IACpCG,YAAY,EAAEA,CAAA,KAAM,CAAC,CAAC;IACtBC,UAAU,EAAGC,YAAsB,IAA6B,IAAI;IACpEC,gBAAgB,EAAEA,CAAA,KAAoB;MACpC,MAAM,IAAIC,KAAK,CAAC,6BAA6BX,wBAAwB,EAAE,CAAC;IAC1E;EACF,CAAC,CAAC,CAAC;EACH,oBAAOF,KAAK,CAACc,aAAa,CAACb,IAAI,EAAEM,KAAK,CAAC;AACzC,CAAC;AAED,OAAO,MAAMQ,YAAY,GAAGA,CAAA,KAAMf,KAAK,CAACgB,MAAM,CAAC,IAAI,CAAC;AACpD,OAAO,MAAMC,UAAU,GAAGA,CAAA,MAAO;EAAEX,GAAG,EAAEN,KAAK,CAACgB,MAAM,CAAC,IAAI,CAAC;EAAEE,OAAO,EAAE;AAAK,CAAC,CAAC;AAC5E,OAAO,MAAMC,4BAA4B,GAAGA,CAAA,KAAMC,SAAS;AAE3D,OAAO,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE,IAAI;EAAEC,MAAM,EAAE;AAAK,CAAC,CAAC;AAEhE,OAAO,MAAMC,iBAAiB,GAAGA,CAAC;EAAEC;AAAmC,CAAC,KACtEA,QAAQ,IAAI,IAAI;AAElB,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAa;EACxC,MAAM,IAAIb,KAAK,CAAC,mBAAmBX,wBAAwB,EAAE,CAAC;AAChE,CAAC;AAED,OAAO,MAAMyB,YAAY,GAAIC,QAAgB,IAAgB;EAC3D,MAAM,IAAIf,KAAK,CAAC,kBAAkBX,wBAAwB,EAAE,CAAC;AAC/D,CAAC;AAED,OAAO,MAAM2B,YAAY,GAAID,QAAgB,IAAiB;EAC5D,MAAM,IAAIf,KAAK,CAAC,kBAAkBX,wBAAwB,EAAE,CAAC;AAC/D,CAAC;AAED,OAAO,MAAM4B,aAAa,GAAGA,CAAA,KAAMV,SAAS;AAE5C,OAAO,MAAMW,YAAY,GAAG;EAAEC,OAAO,EAAEA,CAAA,KAAM;AAAM,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../commonjs/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../commonjs/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":";;AAWA,4DAuBC"}
|
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
export const __esModule: boolean;
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* The native module installs the WebGPU flag constants (`GPUBufferUsage`,
|
|
6
|
-
* `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`, `GPUMapMode`) as globals
|
|
7
|
-
* on the main JS runtime, but worklet runtimes (Reanimated UI, dedicated worklet
|
|
8
|
-
* runtimes, Vision Camera frame processors) start without them, so referencing
|
|
9
|
-
* the bare global inside a worklet yields `undefined`.
|
|
10
|
-
*
|
|
11
|
-
* Call `installWebGPU()` once at the top of a worklet to make those globals
|
|
12
|
-
* available there, instead of importing each constant by hand:
|
|
13
|
-
*
|
|
14
|
-
* ```tsx
|
|
15
|
-
* import { installWebGPU } from "react-native-webgpu";
|
|
16
|
-
*
|
|
17
|
-
* const work = (device: GPUDevice) => {
|
|
18
|
-
* "worklet";
|
|
19
|
-
* installWebGPU();
|
|
20
|
-
* device.createBuffer({
|
|
21
|
-
* usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
|
|
22
|
-
* });
|
|
23
|
-
* };
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* The constants are captured into the worklet by closure (the same way a shader
|
|
27
|
-
* string is), so they work on every runtime. Calling it on a runtime that
|
|
28
|
-
* already has the globals (e.g. the main JS runtime) is a safe no-op.
|
|
29
|
-
*
|
|
30
|
-
* This is the explicit entry point for runtime setup; for now it only installs
|
|
31
|
-
* the flag constants, but it is the place where other per-runtime WebGPU setup
|
|
32
|
-
* (e.g. `navigator.gpu`) can be wired in later.
|
|
3
|
+
* @internal Called once by `main/index.tsx` after the native install, so
|
|
4
|
+
* `installWebGPU()` can put `navigator.gpu` on other runtimes.
|
|
33
5
|
*/
|
|
6
|
+
export function provideGPUForInstall(gpu: any): void;
|
|
34
7
|
export function installWebGPU(): void;
|
|
35
8
|
//# sourceMappingURL=install.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../commonjs/install.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../commonjs/install.js"],"names":[],"mappings":";AA+BA;;;GAGG;AACH,qDAEC;AA+CD,sCAuBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../commonjs/mock.js"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../commonjs/mock.js"],"names":[],"mappings":";;IA4GW,4BAAW;;AAhDtB;;;;QAaC;AAED,oCAAsD;AAEtD;;;EAGE;AAEF,0DAAoD;AAEpD;;;EAGE;AAEF;;QAEsB;AAEtB,uCAEC;AAED,mDAEC;AAED,mDAEC;AAED,2CAAqC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../module/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../module/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":"AAIA,gHAuBC;kBA3BiB,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../module/install.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../module/install.js"],"names":[],"mappings":"AA6BO,qDAEN;AA8CM,sCAuBN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../module/mock.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../module/mock.js"],"names":[],"mappings":";;AAiBO;;;;2DAaN;AACM,6DAA6C;AAC7C;;;EAGL;AACK,0DAAoD;AACpD;;;EAGL;AACK;;QAEe;AACf,uCAEN;AACM,mDAEN;AACM,mDAEN;AACM,2CAAqC;;IAEjC,4BAAW;;qBArDD,cAAc;kBADjB,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB;AAGD,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,KAAK,EAAE,WAAW,GACjB,KAAK,CAAC,GAAG,CAAC,OAAO,CAgBnB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GPUSharedFence, GPUSharedFenceDescriptor, GPUDawnTogglesDescriptor, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, NativeCanvas, RNCanvasContext, VideoPlayer, NativeVideoFrame, NativeVideoPixelFormat } from "./types";
|
|
2
2
|
export * from "./main";
|
|
3
3
|
export * from "./constants";
|
|
4
|
-
export
|
|
4
|
+
export { installWebGPU } from "./install";
|
|
5
5
|
export type { NativeVideoFrame, VideoPlayer, GPUSharedFence, GPUSharedFenceDescriptor, GPUSharedFenceExportInfo, GPUSharedFenceState, GPUSharedFenceType, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, GPUSharedTextureMemoryEndAccessState, NativeVideoPixelFormat, CreateVideoPlayerOptions, GPUDawnTogglesDescriptor, } from "./types";
|
|
6
6
|
declare global {
|
|
7
7
|
interface Navigator {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EAChC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EAChC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,gCAAgC,EAChC,oCAAoC,EACpC,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,SAAS;QACjB,GAAG,EAAE,GAAG,CAAC;KACV;IAED,IAAI,SAAS,EAAE,SAAS,CAAC;IAEzB,IAAI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,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,CAAC;QAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB;IASD,UAAU,kBAAkB;QAC1B,OAAO,IAAI,IAAI,CAAC;QAShB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;KACnC;IAGD,SAAS,iBAAiB,CACxB,KAAK,EAAE,WAAW,GAAG,eAAe,EACpC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
|
|
@@ -1,34 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal Called once by `main/index.tsx` after the native install, so
|
|
3
|
+
* `installWebGPU()` can put `navigator.gpu` on other runtimes.
|
|
4
|
+
*/
|
|
5
|
+
export declare const provideGPUForInstall: (gpu: GPU) => void;
|
|
1
6
|
/**
|
|
2
7
|
* Install WebGPU on the runtime that calls it.
|
|
3
8
|
*
|
|
4
|
-
* The native module
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
+
* The native module sets up WebGPU on the main JS runtime, but worklet
|
|
10
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
11
|
+
* processors) start without it: `navigator.gpu` and the flag constants
|
|
12
|
+
* (`GPUBufferUsage`, `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`,
|
|
13
|
+
* `GPUMapMode`) are all `undefined` there.
|
|
9
14
|
*
|
|
10
|
-
* Call `installWebGPU()` once at the top of a worklet to make
|
|
11
|
-
* available there, instead of importing each constant by hand:
|
|
15
|
+
* Call `installWebGPU()` once at the top of a worklet to make them available:
|
|
12
16
|
*
|
|
13
17
|
* ```tsx
|
|
14
18
|
* import { installWebGPU } from "react-native-webgpu";
|
|
15
19
|
*
|
|
16
|
-
* const work = (
|
|
20
|
+
* const work = () => {
|
|
17
21
|
* "worklet";
|
|
18
22
|
* installWebGPU();
|
|
19
|
-
*
|
|
20
|
-
*
|
|
23
|
+
* globalThis.navigator.gpu.requestAdapter().then((adapter) => {
|
|
24
|
+
* // ...
|
|
21
25
|
* });
|
|
22
26
|
* };
|
|
23
27
|
* ```
|
|
24
28
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
29
|
+
* Known limitations:
|
|
30
|
+
*
|
|
31
|
+
* - Read `navigator` through `globalThis.navigator`: the Worklets Babel
|
|
32
|
+
* plugin does not treat a bare `navigator` as a known global, so it would
|
|
33
|
+
* capture the main runtime's `navigator` object by closure instead of
|
|
34
|
+
* reading the one this function installed. Fixed upstream in
|
|
35
|
+
* react-native-reanimated#10364; the prefix becomes unnecessary on
|
|
36
|
+
* react-native-worklets versions that include it.
|
|
37
|
+
* - Spontaneous events are main-runtime only: on a device created on a
|
|
38
|
+
* worklet runtime, `device.lost` never settles (unless the device is
|
|
39
|
+
* already lost when read) and `uncapturederror` listeners never fire.
|
|
40
|
+
* Observe those on a device created on the main JS thread.
|
|
28
41
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
42
|
+
* Everything is captured into the worklet by closure: the constants like a
|
|
43
|
+
* shader string would be, and the GPU object through the Worklets custom
|
|
44
|
+
* serializer, which installs the native prototypes on the target runtime when
|
|
45
|
+
* it crosses. Promises returned by `requestAdapter`/`requestDevice` settle on
|
|
46
|
+
* the calling runtime (each runtime gets its own async pump). Calling it on a
|
|
47
|
+
* runtime that already has the globals (e.g. the main JS runtime) is a safe
|
|
48
|
+
* no-op.
|
|
32
49
|
*/
|
|
33
50
|
export declare const installWebGPU: () => void;
|
|
34
51
|
//# sourceMappingURL=install.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,aAAa,YAiBzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/index.tsx"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -3,7 +3,6 @@ import type { ReactNode } from "react";
|
|
|
3
3
|
import { View } from "react-native";
|
|
4
4
|
import type { ViewProps } from "react-native";
|
|
5
5
|
export * from "./constants";
|
|
6
|
-
export * from "./install";
|
|
7
6
|
export * from "./formats";
|
|
8
7
|
export type { CanvasRef, NativeCanvas, RNCanvasContext } from "./Canvas";
|
|
9
8
|
interface CanvasProps extends ViewProps {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/mock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAe9C,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/mock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAe9C,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAK1B,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEzE,UAAU,WAAY,SAAQ,SAAS;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED,eAAO,MAAM,MAAM,GAAI,8CAIpB,WAAW,oCASb,CAAC;AAEF,eAAO,MAAM,YAAY,oCAA2B,CAAC;AACrD,eAAO,MAAM,UAAU;;;CAAqD,CAAC;AAC7E,eAAO,MAAM,4BAA4B,iBAAkB,CAAC;AAE5D,eAAO,MAAM,SAAS;;;CAA0C,CAAC;AAEjE,eAAO,MAAM,iBAAiB,GAAI,cAAc;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,sIACtD,CAAC;AAEnB,eAAO,MAAM,aAAa,QAAO,KAEhC,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,KAAG,SAE/C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,KAAG,UAE/C,CAAC;AAEF,eAAO,MAAM,aAAa,iBAAkB,CAAC;AAE7C,eAAO,MAAM,YAAY;;CAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { StyleSheet } from "react-native";
|
|
3
3
|
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
4
4
|
import type { ViewProps } from "react-native";
|
|
@@ -10,65 +10,15 @@ export interface NativeProps extends ViewProps {
|
|
|
10
10
|
transparent: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
function debounce<T extends (...args: any[]) => void>(
|
|
15
|
-
func: T,
|
|
16
|
-
wait: number,
|
|
17
|
-
immediate = false,
|
|
18
|
-
) {
|
|
19
|
-
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
20
|
-
return function debounced(
|
|
21
|
-
this: ThisParameterType<T>,
|
|
22
|
-
...args: Parameters<T>
|
|
23
|
-
) {
|
|
24
|
-
const context = this;
|
|
25
|
-
const callNow = immediate && !timeout;
|
|
26
|
-
if (timeout) {
|
|
27
|
-
clearTimeout(timeout);
|
|
28
|
-
}
|
|
29
|
-
timeout = setTimeout(() => {
|
|
30
|
-
timeout = undefined;
|
|
31
|
-
if (!immediate) {
|
|
32
|
-
func.apply(context, args);
|
|
33
|
-
}
|
|
34
|
-
}, wait);
|
|
35
|
-
if (callNow) {
|
|
36
|
-
func.apply(context, args);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function resizeCanvas(canvas: HTMLCanvasElement | null) {
|
|
42
|
-
if (!canvas) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const dpr = window.devicePixelRatio || 1;
|
|
47
|
-
|
|
48
|
-
const { height, width } = canvas.getBoundingClientRect();
|
|
49
|
-
canvas.setAttribute("height", (height * dpr).toString());
|
|
50
|
-
canvas.setAttribute("width", (width * dpr).toString());
|
|
51
|
-
}
|
|
52
|
-
|
|
53
13
|
// eslint-disable-next-line import/no-default-export
|
|
54
14
|
export default function WebGPUViewNativeComponent(
|
|
55
15
|
props: NativeProps,
|
|
56
16
|
): React.JSX.Element {
|
|
57
17
|
const { contextId, style, transparent, ...rest } = props;
|
|
58
18
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const onResize = debounce(
|
|
63
|
-
() => resizeCanvas(canvasElm.current ?? null),
|
|
64
|
-
100,
|
|
65
|
-
);
|
|
66
|
-
window.addEventListener("resize", onResize);
|
|
67
|
-
return () => {
|
|
68
|
-
window.removeEventListener("resize", onResize);
|
|
69
|
-
};
|
|
70
|
-
}, []);
|
|
71
|
-
|
|
19
|
+
// MakeWebGPUCanvasContext sets the initial drawing-buffer size. Subsequent
|
|
20
|
+
// resizes belong to the renderer so it can recreate depth/MSAA attachments
|
|
21
|
+
// together; changing canvas.width/height here would invalidate its textures.
|
|
72
22
|
return React.createElement("canvas", {
|
|
73
23
|
...rest,
|
|
74
24
|
id: contextIdToId(contextId),
|
|
@@ -78,12 +28,6 @@ export default function WebGPUViewNativeComponent(
|
|
|
78
28
|
...(transparent === false ? { backgroundColor: "white" } : {}),
|
|
79
29
|
...(typeof style === "object" ? style : {}),
|
|
80
30
|
},
|
|
81
|
-
ref: (ref: HTMLCanvasElement) => {
|
|
82
|
-
canvasElm.current = ref;
|
|
83
|
-
if (ref) {
|
|
84
|
-
resizeCanvas(ref);
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
31
|
});
|
|
88
32
|
}
|
|
89
33
|
|
package/src/index.tsx
CHANGED
package/src/install.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
1
2
|
import {
|
|
2
3
|
GPUBufferUsage,
|
|
3
4
|
GPUColorWrite,
|
|
@@ -18,37 +19,67 @@ const constants = {
|
|
|
18
19
|
GPUMapMode,
|
|
19
20
|
};
|
|
20
21
|
|
|
22
|
+
// The GPU instance destined for `navigator.gpu` on other runtimes, wrapped in
|
|
23
|
+
// a holder object. It cannot be read at module evaluation: this module can be
|
|
24
|
+
// evaluated before the native install has populated `RNWebGPU.gpu`, so
|
|
25
|
+
// `main/index.tsx` fills the holder right after installing. The holder itself
|
|
26
|
+
// is captured into the `installWebGPU` worklet closure; when a worklet is
|
|
27
|
+
// serialized (always after startup, so after the holder is filled), the
|
|
28
|
+
// Worklets custom serializer boxes the GPU object inside it, and unboxing on
|
|
29
|
+
// the target runtime installs the GPU prototype there.
|
|
30
|
+
const holder: { gpu?: GPU } = {};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal Called once by `main/index.tsx` after the native install, so
|
|
34
|
+
* `installWebGPU()` can put `navigator.gpu` on other runtimes.
|
|
35
|
+
*/
|
|
36
|
+
export const provideGPUForInstall = (gpu: GPU) => {
|
|
37
|
+
holder.gpu = gpu;
|
|
38
|
+
};
|
|
39
|
+
|
|
21
40
|
/**
|
|
22
41
|
* Install WebGPU on the runtime that calls it.
|
|
23
42
|
*
|
|
24
|
-
* The native module
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
43
|
+
* The native module sets up WebGPU on the main JS runtime, but worklet
|
|
44
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
45
|
+
* processors) start without it: `navigator.gpu` and the flag constants
|
|
46
|
+
* (`GPUBufferUsage`, `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`,
|
|
47
|
+
* `GPUMapMode`) are all `undefined` there.
|
|
29
48
|
*
|
|
30
|
-
* Call `installWebGPU()` once at the top of a worklet to make
|
|
31
|
-
* available there, instead of importing each constant by hand:
|
|
49
|
+
* Call `installWebGPU()` once at the top of a worklet to make them available:
|
|
32
50
|
*
|
|
33
51
|
* ```tsx
|
|
34
52
|
* import { installWebGPU } from "react-native-webgpu";
|
|
35
53
|
*
|
|
36
|
-
* const work = (
|
|
54
|
+
* const work = () => {
|
|
37
55
|
* "worklet";
|
|
38
56
|
* installWebGPU();
|
|
39
|
-
*
|
|
40
|
-
*
|
|
57
|
+
* globalThis.navigator.gpu.requestAdapter().then((adapter) => {
|
|
58
|
+
* // ...
|
|
41
59
|
* });
|
|
42
60
|
* };
|
|
43
61
|
* ```
|
|
44
62
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
63
|
+
* Known limitations:
|
|
64
|
+
*
|
|
65
|
+
* - Read `navigator` through `globalThis.navigator`: the Worklets Babel
|
|
66
|
+
* plugin does not treat a bare `navigator` as a known global, so it would
|
|
67
|
+
* capture the main runtime's `navigator` object by closure instead of
|
|
68
|
+
* reading the one this function installed. Fixed upstream in
|
|
69
|
+
* react-native-reanimated#10364; the prefix becomes unnecessary on
|
|
70
|
+
* react-native-worklets versions that include it.
|
|
71
|
+
* - Spontaneous events are main-runtime only: on a device created on a
|
|
72
|
+
* worklet runtime, `device.lost` never settles (unless the device is
|
|
73
|
+
* already lost when read) and `uncapturederror` listeners never fire.
|
|
74
|
+
* Observe those on a device created on the main JS thread.
|
|
48
75
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
76
|
+
* Everything is captured into the worklet by closure: the constants like a
|
|
77
|
+
* shader string would be, and the GPU object through the Worklets custom
|
|
78
|
+
* serializer, which installs the native prototypes on the target runtime when
|
|
79
|
+
* it crosses. Promises returned by `requestAdapter`/`requestDevice` settle on
|
|
80
|
+
* the calling runtime (each runtime gets its own async pump). Calling it on a
|
|
81
|
+
* runtime that already has the globals (e.g. the main JS runtime) is a safe
|
|
82
|
+
* no-op.
|
|
52
83
|
*/
|
|
53
84
|
export const installWebGPU = () => {
|
|
54
85
|
"worklet";
|
|
@@ -58,4 +89,13 @@ export const installWebGPU = () => {
|
|
|
58
89
|
g[key] = value;
|
|
59
90
|
}
|
|
60
91
|
}
|
|
92
|
+
const { gpu } = holder;
|
|
93
|
+
if (gpu !== undefined) {
|
|
94
|
+
const nav = g.navigator as { gpu?: GPU; userAgent?: string } | undefined;
|
|
95
|
+
if (nav === undefined) {
|
|
96
|
+
g.navigator = { gpu, userAgent: "react-native" };
|
|
97
|
+
} else if (nav.gpu === undefined) {
|
|
98
|
+
nav.gpu = gpu;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
61
101
|
};
|
package/src/main/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { registerWebGPUForReanimated } from "../external";
|
|
2
|
+
import { provideGPUForInstall } from "../install";
|
|
2
3
|
import WebGPUModule from "../NativeWebGPUModule";
|
|
3
4
|
|
|
4
5
|
export * from "../Canvas";
|
|
@@ -36,6 +37,8 @@ if (typeof RNWebGPU !== "undefined") {
|
|
|
36
37
|
}
|
|
37
38
|
global.createImageBitmap =
|
|
38
39
|
global.createImageBitmap ?? RNWebGPU.createImageBitmap.bind(RNWebGPU);
|
|
40
|
+
// Let installWebGPU() put navigator.gpu on other runtimes (see install.ts).
|
|
41
|
+
provideGPUForInstall(RNWebGPU.gpu);
|
|
39
42
|
} else {
|
|
40
43
|
console.warn(
|
|
41
44
|
`[react-native-webgpu] install() returned ${_installOk} but RNWebGPU global is not available`,
|