react-native-webgpu 0.5.14 → 0.5.16
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/README.md +19 -6
- package/android/CMakeLists.txt +2 -2
- package/cpp/jsi/NativeObject.h +39 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +8 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +33 -1
- package/cpp/rnwgpu/api/Canvas.h +18 -0
- package/cpp/rnwgpu/api/GPU.cpp +14 -11
- package/cpp/rnwgpu/api/GPU.h +6 -4
- package/cpp/rnwgpu/api/GPUAdapter.cpp +5 -8
- package/cpp/rnwgpu/api/GPUAdapter.h +3 -3
- package/cpp/rnwgpu/api/GPUBuffer.cpp +23 -24
- package/cpp/rnwgpu/api/GPUBuffer.h +3 -3
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +13 -16
- package/cpp/rnwgpu/api/GPUCanvasContext.h +3 -0
- package/cpp/rnwgpu/api/GPUDevice.cpp +103 -19
- package/cpp/rnwgpu/api/GPUDevice.h +17 -3
- package/cpp/rnwgpu/api/GPUQueue.h +3 -3
- package/cpp/rnwgpu/api/GPUShaderModule.h +3 -3
- package/cpp/rnwgpu/api/GPUSharedFence.cpp +77 -0
- package/cpp/rnwgpu/api/GPUSharedFence.h +53 -0
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +60 -11
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +13 -9
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +51 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +55 -23
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +8 -5
- package/cpp/rnwgpu/async/RuntimeContext.cpp +193 -0
- package/cpp/rnwgpu/async/RuntimeContext.h +122 -0
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/GPUDeviceProvider.js +33 -0
- package/lib/commonjs/GPUDeviceProvider.js.map +1 -0
- package/lib/commonjs/Offscreen.js +1 -1
- package/lib/commonjs/WebPolyfillGPUModule.js +9 -1
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -1
- package/lib/commonjs/constants.js +55 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/hooks.js +2 -26
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js +22 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/install.js +63 -0
- package/lib/commonjs/install.js.map +1 -0
- package/lib/commonjs/main/index.js +12 -0
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/commonjs/main/index.web.js +11 -0
- package/lib/commonjs/main/index.web.js.map +1 -1
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/GPUDeviceProvider.js +24 -0
- package/lib/module/GPUDeviceProvider.js.map +1 -0
- package/lib/module/Offscreen.js +1 -1
- package/lib/module/WebPolyfillGPUModule.js +9 -1
- package/lib/module/WebPolyfillGPUModule.js.map +1 -1
- package/lib/module/constants.js +44 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/hooks.js +1 -22
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/install.js +57 -0
- package/lib/module/install.js.map +1 -0
- package/lib/module/main/index.js +1 -0
- package/lib/module/main/index.js.map +1 -1
- package/lib/module/main/index.web.js +1 -0
- package/lib/module/main/index.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/GPUDeviceProvider.d.ts +8 -0
- package/lib/typescript/lib/commonjs/GPUDeviceProvider.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/constants.d.ts +7 -0
- package/lib/typescript/lib/commonjs/constants.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/hooks.d.ts +4 -9
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/install.d.ts +35 -0
- package/lib/typescript/lib/commonjs/install.d.ts.map +1 -0
- package/lib/typescript/lib/module/GPUDeviceProvider.d.ts +8 -0
- package/lib/typescript/lib/module/GPUDeviceProvider.d.ts.map +1 -0
- package/lib/typescript/lib/module/constants.d.ts +6 -0
- package/lib/typescript/lib/module/constants.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks.d.ts +2 -9
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/module/index.d.ts +2 -0
- package/lib/typescript/lib/module/install.d.ts +2 -0
- package/lib/typescript/lib/module/install.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/index.d.ts +1 -0
- package/lib/typescript/lib/module/main/index.web.d.ts +1 -0
- package/lib/typescript/src/Canvas.d.ts +14 -0
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/GPUDeviceProvider.d.ts +15 -0
- package/lib/typescript/src/GPUDeviceProvider.d.ts.map +1 -0
- package/lib/typescript/src/constants.d.ts +6 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/hooks.d.ts +2 -17
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/install.d.ts +34 -0
- package/lib/typescript/src/install.d.ts.map +1 -0
- package/lib/typescript/src/main/index.d.ts +1 -0
- package/lib/typescript/src/main/index.d.ts.map +1 -1
- package/lib/typescript/src/main/index.web.d.ts +1 -0
- package/lib/typescript/src/main/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +39 -2
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +12 -3
- package/src/Canvas.tsx +16 -0
- package/src/GPUDeviceProvider.tsx +39 -0
- package/src/Offscreen.ts +1 -1
- package/src/WebPolyfillGPUModule.ts +9 -3
- package/src/constants.ts +37 -0
- package/src/hooks.tsx +3 -41
- package/src/index.tsx +13 -2
- package/src/install.ts +61 -0
- package/src/main/index.tsx +1 -0
- package/src/main/index.web.tsx +1 -0
- package/src/types.ts +76 -3
- package/cpp/rnwgpu/async/AsyncDispatcher.h +0 -28
- package/cpp/rnwgpu/async/AsyncRunner.cpp +0 -215
- package/cpp/rnwgpu/async/AsyncRunner.h +0 -53
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +0 -23
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +0 -22
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../commonjs/constants.js"],"names":[],"mappings":""}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
export const __esModule: boolean;
|
|
2
2
|
export function warnIfNotHardwareAccelerated(adapter: any): void;
|
|
3
|
-
export function GPUDeviceProvider({ children, adapterOptions, deviceDescriptor }: {
|
|
4
|
-
children: any;
|
|
5
|
-
adapterOptions: any;
|
|
6
|
-
deviceDescriptor: any;
|
|
7
|
-
}): any;
|
|
8
3
|
export function useSurface(): {
|
|
9
|
-
ref:
|
|
10
|
-
surface:
|
|
4
|
+
ref: _react.MutableRefObject<null>;
|
|
5
|
+
surface: null;
|
|
11
6
|
};
|
|
12
|
-
export function
|
|
13
|
-
export function useCanvasRef(): any;
|
|
7
|
+
export function useCanvasRef(): _react.MutableRefObject<null>;
|
|
14
8
|
export function useDevice(adapterOptions: any, deviceDescriptor: any): {
|
|
15
9
|
adapter: any;
|
|
16
10
|
device: any;
|
|
17
11
|
};
|
|
12
|
+
import _react = require("react");
|
|
18
13
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../commonjs/hooks.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../commonjs/hooks.js"],"names":[],"mappings":";AAOA,iEAMC;AAED;;;EAWC;AAED,8DAAmD;AAEnD;;;EA0BC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Install WebGPU on the runtime that calls it.
|
|
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.
|
|
33
|
+
*/
|
|
34
|
+
export function installWebGPU(): void;
|
|
35
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../commonjs/install.js"],"names":[],"mappings":";AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,sCASC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function GPUDeviceProvider({ children, adapterOptions, deviceDescriptor }: {
|
|
2
|
+
children: any;
|
|
3
|
+
adapterOptions: any;
|
|
4
|
+
deviceDescriptor: any;
|
|
5
|
+
}): React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> | null;
|
|
6
|
+
export function useMainDevice(): never;
|
|
7
|
+
import React from "react";
|
|
8
|
+
//# sourceMappingURL=GPUDeviceProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GPUDeviceProvider.d.ts","sourceRoot":"","sources":["../../../module/GPUDeviceProvider.js"],"names":[],"mappings":"AAGO;;;;yGAYN;AACM,uCAMN;kBAtBgD,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../module/constants.js"],"names":[],"mappings":""}
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
export function warnIfNotHardwareAccelerated(adapter: any): void;
|
|
2
|
-
export function GPUDeviceProvider({ children, adapterOptions, deviceDescriptor }: {
|
|
3
|
-
children: any;
|
|
4
|
-
adapterOptions: any;
|
|
5
|
-
deviceDescriptor: any;
|
|
6
|
-
}): React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> | null;
|
|
7
2
|
export function useSurface(): {
|
|
8
|
-
ref:
|
|
3
|
+
ref: import("react").MutableRefObject<null>;
|
|
9
4
|
surface: null;
|
|
10
5
|
};
|
|
11
|
-
export function
|
|
12
|
-
export function useCanvasRef(): React.MutableRefObject<null>;
|
|
6
|
+
export function useCanvasRef(): import("react").MutableRefObject<null>;
|
|
13
7
|
export function useDevice(adapterOptions: any, deviceDescriptor: any): {
|
|
14
8
|
adapter: any;
|
|
15
9
|
device: any;
|
|
16
10
|
};
|
|
17
|
-
import React from "react";
|
|
18
11
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../module/hooks.js"],"names":[],"mappings":"AACO,iEAMN;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../module/hooks.js"],"names":[],"mappings":"AACO,iEAMN;AACM;;;EAWN;AACM,uEAAuC;AACvC;;;EA0BN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../module/install.js"],"names":[],"mappings":"AA8CO,sCASN"}
|
|
@@ -2,5 +2,6 @@ export * from "../Canvas";
|
|
|
2
2
|
export * from "../Offscreen";
|
|
3
3
|
export * from "../WebGPUViewNativeComponent";
|
|
4
4
|
export * from "../hooks";
|
|
5
|
+
export * from "../GPUDeviceProvider";
|
|
5
6
|
export { default as WebGPUModule } from "../NativeWebGPUModule";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -7,8 +7,22 @@ export interface NativeCanvas {
|
|
|
7
7
|
height: number;
|
|
8
8
|
clientWidth: number;
|
|
9
9
|
clientHeight: number;
|
|
10
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
11
|
+
removeEventListener(type: string, listener: EventListener): void;
|
|
12
|
+
dispatchEvent(event: Event): void;
|
|
13
|
+
setPointerCapture(pointerId: number): void;
|
|
14
|
+
releasePointerCapture(pointerId: number): void;
|
|
10
15
|
}
|
|
11
16
|
export type RNCanvasContext = GPUCanvasContext & {
|
|
17
|
+
/**
|
|
18
|
+
* Present the current frame.
|
|
19
|
+
*
|
|
20
|
+
* Call this after `queue.submit()` on every runtime: the main JS runtime, the
|
|
21
|
+
* Reanimated UI runtime, and dedicated worklet runtimes (e.g.
|
|
22
|
+
* `createWorkletRuntime` / `runOnRuntime`, or a Vision Camera frame
|
|
23
|
+
* processor). It runs synchronously on the calling thread, so the frame is
|
|
24
|
+
* presented from whichever thread did the rendering.
|
|
25
|
+
*/
|
|
12
26
|
present: () => void;
|
|
13
27
|
};
|
|
14
28
|
export interface CanvasRef {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgD,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgD,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IAGrB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9D,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IACjE,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAClC,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAChD;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,UAAU,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAC;IAC1D,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACtC;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,MAAM,GAAI,gCAAgC,WAAW,sBAuCjE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
interface DeviceContextValue {
|
|
4
|
+
device: GPUDevice | null;
|
|
5
|
+
adapter: GPUAdapter | null;
|
|
6
|
+
}
|
|
7
|
+
interface DeviceProviderProps {
|
|
8
|
+
children?: ReactNode | ReactNode[];
|
|
9
|
+
adapterOptions?: GPURequestAdapterOptions;
|
|
10
|
+
deviceDescriptor?: GPUDeviceDescriptor;
|
|
11
|
+
}
|
|
12
|
+
export declare const GPUDeviceProvider: ({ children, adapterOptions, deviceDescriptor, }: DeviceProviderProps) => React.JSX.Element | null;
|
|
13
|
+
export declare const useMainDevice: () => DeviceContextValue;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=GPUDeviceProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GPUDeviceProvider.d.ts","sourceRoot":"","sources":["../../../src/GPUDeviceProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,UAAU,kBAAkB;IAC1B,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;CAC5B;AAID,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IACnC,cAAc,CAAC,EAAE,wBAAwB,CAAC;IAC1C,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,GAAI,iDAI/B,mBAAmB,6BAQrB,CAAC;AAEF,eAAO,MAAM,aAAa,0BAMzB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const GPUBufferUsage: GPUBufferUsage;
|
|
2
|
+
export declare const GPUTextureUsage: GPUTextureUsage;
|
|
3
|
+
export declare const GPUShaderStage: GPUShaderStage;
|
|
4
|
+
export declare const GPUColorWrite: GPUColorWrite;
|
|
5
|
+
export declare const GPUMapMode: GPUMapMode;
|
|
6
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAQ,cAAc,gBAAe,CAAC;AAE7C,eAAO,MAAQ,eAAe,iBAAe,CAAC;AAE9C,eAAO,MAAQ,cAAc,gBAAe,CAAC;AAE7C,eAAO,MAAQ,aAAa,eAAe,CAAC;AAE5C,eAAO,MAAQ,UAAU,YAAe,CAAC"}
|
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
1
|
import type { CanvasRef, NativeCanvas } from "./Canvas";
|
|
4
2
|
export declare const warnIfNotHardwareAccelerated: (adapter: GPUAdapter) => void;
|
|
5
|
-
interface DeviceContext {
|
|
6
|
-
device: GPUDevice | null;
|
|
7
|
-
adapter: GPUAdapter | null;
|
|
8
|
-
}
|
|
9
|
-
declare const DeviceContext: React.Context<DeviceContext | null>;
|
|
10
|
-
interface DeviceProviderProps {
|
|
11
|
-
children?: ReactNode | ReactNode[];
|
|
12
|
-
adapterOptions?: GPURequestAdapterOptions;
|
|
13
|
-
deviceDescriptor?: GPUDeviceDescriptor;
|
|
14
|
-
}
|
|
15
|
-
export declare const GPUDeviceProvider: ({ children, adapterOptions, deviceDescriptor, }: DeviceProviderProps) => React.JSX.Element | null;
|
|
16
3
|
export declare const useSurface: () => {
|
|
17
|
-
ref:
|
|
4
|
+
ref: import("react").RefObject<CanvasRef>;
|
|
18
5
|
surface: NativeCanvas | null;
|
|
19
6
|
};
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const useCanvasRef: () => React.RefObject<CanvasRef>;
|
|
7
|
+
export declare const useCanvasRef: () => import("react").RefObject<CanvasRef>;
|
|
22
8
|
export declare const useDevice: (adapterOptions?: GPURequestAdapterOptions, deviceDescriptor?: GPUDeviceDescriptor) => {
|
|
23
9
|
adapter: GPUAdapter | null;
|
|
24
10
|
device: GPUDevice | null;
|
|
25
11
|
};
|
|
26
|
-
export {};
|
|
27
12
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,4BAA4B,GAAI,SAAS,UAAU,SAQ/D,CAAC;AAOF,eAAO,MAAM,UAAU;;;CAQtB,CAAC;AAEF,eAAO,MAAM,YAAY,4CAAgC,CAAC;AAE1D,eAAO,MAAM,SAAS,GACpB,iBAAiB,wBAAwB,EACzC,mBAAmB,mBAAmB;;;CAqBvC,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { GPUDawnTogglesDescriptor, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, NativeCanvas, RNCanvasContext, VideoPlayer, NativeVideoFrame, NativeVideoPixelFormat } from "./types";
|
|
1
|
+
import type { GPUSharedFence, GPUSharedFenceDescriptor, GPUDawnTogglesDescriptor, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, NativeCanvas, RNCanvasContext, VideoPlayer, NativeVideoFrame, NativeVideoPixelFormat } from "./types";
|
|
2
2
|
export * from "./main";
|
|
3
|
-
export
|
|
3
|
+
export * from "./constants";
|
|
4
|
+
export * from "./install";
|
|
5
|
+
export type { NativeVideoFrame, VideoPlayer, GPUSharedFence, GPUSharedFenceDescriptor, GPUSharedFenceExportInfo, GPUSharedFenceState, GPUSharedFenceType, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, GPUSharedTextureMemoryEndAccessState, NativeVideoPixelFormat, CreateVideoPlayerOptions, GPUDawnTogglesDescriptor, } from "./types";
|
|
4
6
|
declare global {
|
|
5
7
|
interface Navigator {
|
|
6
8
|
gpu: GPU;
|
|
@@ -21,6 +23,7 @@ declare global {
|
|
|
21
23
|
};
|
|
22
24
|
interface GPUDevice {
|
|
23
25
|
importSharedTextureMemory(descriptor: GPUSharedTextureMemoryDescriptor): GPUSharedTextureMemory;
|
|
26
|
+
importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;
|
|
24
27
|
}
|
|
25
28
|
interface GPUDeviceDescriptor {
|
|
26
29
|
dawnToggles?: GPUDawnTogglesDescriptor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EAChC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,
|
|
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,cAAc,WAAW,CAAC;AAC1B,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,QAAQ,EAAE;QACZ,GAAG,EAAE,GAAG,CAAC;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC;QACtD,uBAAuB,EAAE,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,KACX,eAAe,CAAC;QACrB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,GAAG,WAAW,KAAK,MAAM,CAAC;QACvE,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;QAC5C,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,CAAC;QACnD,oBAAoB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,gBAAgB,CAAC;QAI1E,gCAAgC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,gBAAgB,CAAC;QACxE,iBAAiB,EAAE,CACjB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,sBAAsB,KACjC,WAAW,CAAC;QACjB,kBAAkB,EAAE,MAAM,MAAM,CAAC;KAClC,CAAC;IAEF,UAAU,SAAS;QACjB,yBAAyB,CACvB,UAAU,EAAE,gCAAgC,GAC3C,sBAAsB,CAAC;QAC1B,iBAAiB,CAAC,UAAU,EAAE,wBAAwB,GAAG,cAAc,CAAC;KACzE;IAID,UAAU,mBAAmB;QAC3B,WAAW,CAAC,EAAE,wBAAwB,CAAC;KACxC;IAMD,UAAU,4BAA4B;QACpC,QAAQ,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;KACjB;IAGD,SAAS,iBAAiB,CACxB,KAAK,EAAE,WAAW,GAAG,eAAe,GACnC,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Install WebGPU on the runtime that calls it.
|
|
3
|
+
*
|
|
4
|
+
* The native module installs the WebGPU flag constants (`GPUBufferUsage`,
|
|
5
|
+
* `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`, `GPUMapMode`) as globals
|
|
6
|
+
* on the main JS runtime, but worklet runtimes (Reanimated UI, dedicated worklet
|
|
7
|
+
* runtimes, Vision Camera frame processors) start without them, so referencing
|
|
8
|
+
* the bare global inside a worklet yields `undefined`.
|
|
9
|
+
*
|
|
10
|
+
* Call `installWebGPU()` once at the top of a worklet to make those globals
|
|
11
|
+
* available there, instead of importing each constant by hand:
|
|
12
|
+
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { installWebGPU } from "react-native-webgpu";
|
|
15
|
+
*
|
|
16
|
+
* const work = (device: GPUDevice) => {
|
|
17
|
+
* "worklet";
|
|
18
|
+
* installWebGPU();
|
|
19
|
+
* device.createBuffer({
|
|
20
|
+
* usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
|
|
21
|
+
* });
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* The constants are captured into the worklet by closure (the same way a shader
|
|
26
|
+
* string is), so they work on every runtime. Calling it on a runtime that
|
|
27
|
+
* already has the globals (e.g. the main JS runtime) is a safe no-op.
|
|
28
|
+
*
|
|
29
|
+
* This is the explicit entry point for runtime setup; for now it only installs
|
|
30
|
+
* the flag constants, but it is the place where other per-runtime WebGPU setup
|
|
31
|
+
* (e.g. `navigator.gpu`) can be wired in later.
|
|
32
|
+
*/
|
|
33
|
+
export declare const installWebGPU: () => void;
|
|
34
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,aAAa,YAQzB,CAAC"}
|
|
@@ -2,5 +2,6 @@ export * from "../Canvas";
|
|
|
2
2
|
export * from "../Offscreen";
|
|
3
3
|
export * from "../WebGPUViewNativeComponent";
|
|
4
4
|
export * from "../hooks";
|
|
5
|
+
export * from "../GPUDeviceProvider";
|
|
5
6
|
export { default as WebGPUModule } from "../NativeWebGPUModule";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/index.tsx"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/index.tsx"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AAErC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../src/main/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../src/main/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC"}
|
|
@@ -5,8 +5,22 @@ export interface NativeCanvas {
|
|
|
5
5
|
height: number;
|
|
6
6
|
clientWidth: number;
|
|
7
7
|
clientHeight: number;
|
|
8
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
9
|
+
removeEventListener(type: string, listener: EventListener): void;
|
|
10
|
+
dispatchEvent(event: Event): void;
|
|
11
|
+
setPointerCapture(pointerId: number): void;
|
|
12
|
+
releasePointerCapture(pointerId: number): void;
|
|
8
13
|
}
|
|
9
14
|
export type RNCanvasContext = GPUCanvasContext & {
|
|
15
|
+
/**
|
|
16
|
+
* Present the current frame.
|
|
17
|
+
*
|
|
18
|
+
* Call this after `queue.submit()` on every runtime: the main JS runtime, the
|
|
19
|
+
* Reanimated UI runtime, and dedicated worklet runtimes (e.g.
|
|
20
|
+
* `createWorkletRuntime` / `runOnRuntime`, or a Vision Camera frame
|
|
21
|
+
* processor). It runs synchronously on the calling thread, so the frame is
|
|
22
|
+
* presented from whichever thread did the rendering.
|
|
23
|
+
*/
|
|
10
24
|
present: () => void;
|
|
11
25
|
};
|
|
12
26
|
export interface CanvasRef {
|
|
@@ -35,6 +49,29 @@ export interface GPUSharedTextureMemoryDescriptor {
|
|
|
35
49
|
handle: bigint;
|
|
36
50
|
label?: string;
|
|
37
51
|
}
|
|
52
|
+
export type GPUSharedFenceType = "mtl-shared-event" | "sync-fd" | "vk-semaphore-opaque-fd";
|
|
53
|
+
export interface GPUSharedFenceDescriptor {
|
|
54
|
+
type: GPUSharedFenceType;
|
|
55
|
+
handle: bigint;
|
|
56
|
+
label?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface GPUSharedFenceExportInfo {
|
|
59
|
+
type: GPUSharedFenceType;
|
|
60
|
+
handle: bigint;
|
|
61
|
+
}
|
|
62
|
+
export interface GPUSharedFence {
|
|
63
|
+
readonly __brand: "GPUSharedFence";
|
|
64
|
+
label: string;
|
|
65
|
+
export(): GPUSharedFenceExportInfo;
|
|
66
|
+
}
|
|
67
|
+
export interface GPUSharedFenceState {
|
|
68
|
+
fence: GPUSharedFence;
|
|
69
|
+
signaledValue: bigint;
|
|
70
|
+
}
|
|
71
|
+
export interface GPUSharedTextureMemoryEndAccessState {
|
|
72
|
+
initialized: boolean;
|
|
73
|
+
fences: GPUSharedFenceState[];
|
|
74
|
+
}
|
|
38
75
|
export interface GPUDawnTogglesDescriptor {
|
|
39
76
|
enabledToggles?: string[];
|
|
40
77
|
disabledToggles?: string[];
|
|
@@ -43,8 +80,8 @@ export interface GPUSharedTextureMemory {
|
|
|
43
80
|
readonly __brand: "GPUSharedTextureMemory";
|
|
44
81
|
label: string;
|
|
45
82
|
createTexture(descriptor?: GPUTextureDescriptor): GPUTexture;
|
|
46
|
-
beginAccess(texture: GPUTexture, initialized: boolean):
|
|
47
|
-
endAccess(texture: GPUTexture):
|
|
83
|
+
beginAccess(texture: GPUTexture, initialized: boolean, fences?: GPUSharedFenceState[]): void;
|
|
84
|
+
endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;
|
|
48
85
|
}
|
|
49
86
|
export {};
|
|
50
87
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-webgpu",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.16",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --fix",
|
|
28
28
|
"tsc": "tsc --noEmit",
|
|
29
29
|
"build": "bob build",
|
|
30
|
+
"release": "semantic-release",
|
|
30
31
|
"build-dawn": "tsx scripts/build/dawn.ts",
|
|
31
32
|
"clean-dawn": "rimraf ./libs && rimraf ../../externals/dawn/out",
|
|
32
33
|
"clang-format": "yarn clang-format-ios && yarn clang-format-android && yarn clang-format-common",
|
|
@@ -51,11 +52,17 @@
|
|
|
51
52
|
"bugs": {
|
|
52
53
|
"url": "https://github.com/wcandillon/react-native-webgpu/issues"
|
|
53
54
|
},
|
|
54
|
-
"homepage": "https://github.
|
|
55
|
+
"homepage": "https://wcandillon.github.io/react-native-webgpu/",
|
|
55
56
|
"publishConfig": {
|
|
56
|
-
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
"registry": "https://registry.npmjs.org/",
|
|
58
|
+
"access": "public",
|
|
59
|
+
"provenance": true
|
|
57
60
|
},
|
|
58
61
|
"devDependencies": {
|
|
62
|
+
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
63
|
+
"@semantic-release/exec": "^7.0.3",
|
|
64
|
+
"@semantic-release/github": "^10.3.3",
|
|
65
|
+
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
59
66
|
"@types/jest": "^29.5.12",
|
|
60
67
|
"@types/lodash": "^4.17.5",
|
|
61
68
|
"@types/node": "^20.14.7",
|
|
@@ -87,6 +94,8 @@
|
|
|
87
94
|
"react-native-worklets": "0.8.3",
|
|
88
95
|
"rimraf": "^5.0.7",
|
|
89
96
|
"seedrandom": "^3.0.5",
|
|
97
|
+
"semantic-release": "^24.1.0",
|
|
98
|
+
"semantic-release-yarn": "^3.0.2",
|
|
90
99
|
"teapot": "^1.0.0",
|
|
91
100
|
"ts-morph": "^22.0.0",
|
|
92
101
|
"tsx": "^4.20.5",
|
package/src/Canvas.tsx
CHANGED
|
@@ -17,9 +17,25 @@ export interface NativeCanvas {
|
|
|
17
17
|
height: number;
|
|
18
18
|
clientWidth: number;
|
|
19
19
|
clientHeight: number;
|
|
20
|
+
// No-op DOM-compatibility stubs so web renderers (Three.js,
|
|
21
|
+
// react-three-fiber) can treat the canvas like an HTMLCanvasElement.
|
|
22
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
23
|
+
removeEventListener(type: string, listener: EventListener): void;
|
|
24
|
+
dispatchEvent(event: Event): void;
|
|
25
|
+
setPointerCapture(pointerId: number): void;
|
|
26
|
+
releasePointerCapture(pointerId: number): void;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
export type RNCanvasContext = GPUCanvasContext & {
|
|
30
|
+
/**
|
|
31
|
+
* Present the current frame.
|
|
32
|
+
*
|
|
33
|
+
* Call this after `queue.submit()` on every runtime: the main JS runtime, the
|
|
34
|
+
* Reanimated UI runtime, and dedicated worklet runtimes (e.g.
|
|
35
|
+
* `createWorkletRuntime` / `runOnRuntime`, or a Vision Camera frame
|
|
36
|
+
* processor). It runs synchronously on the calling thread, so the frame is
|
|
37
|
+
* presented from whichever thread did the rendering.
|
|
38
|
+
*/
|
|
23
39
|
present: () => void;
|
|
24
40
|
};
|
|
25
41
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, { createContext, useContext } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import { useDevice } from "./hooks";
|
|
5
|
+
|
|
6
|
+
interface DeviceContextValue {
|
|
7
|
+
device: GPUDevice | null;
|
|
8
|
+
adapter: GPUAdapter | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const DeviceContext = createContext<DeviceContextValue | null>(null);
|
|
12
|
+
|
|
13
|
+
interface DeviceProviderProps {
|
|
14
|
+
children?: ReactNode | ReactNode[];
|
|
15
|
+
adapterOptions?: GPURequestAdapterOptions;
|
|
16
|
+
deviceDescriptor?: GPUDeviceDescriptor;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const GPUDeviceProvider = ({
|
|
20
|
+
children,
|
|
21
|
+
adapterOptions,
|
|
22
|
+
deviceDescriptor,
|
|
23
|
+
}: DeviceProviderProps) => {
|
|
24
|
+
const state = useDevice(adapterOptions, deviceDescriptor);
|
|
25
|
+
if (!state.device) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return (
|
|
29
|
+
<DeviceContext.Provider value={state}>{children}</DeviceContext.Provider>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const useMainDevice = () => {
|
|
34
|
+
const ctx = useContext(DeviceContext);
|
|
35
|
+
if (!ctx) {
|
|
36
|
+
throw new Error("No DeviceContext found.");
|
|
37
|
+
}
|
|
38
|
+
return ctx;
|
|
39
|
+
};
|
package/src/Offscreen.ts
CHANGED
|
@@ -15,6 +15,12 @@ function getNativeSurface(contextId: number) {
|
|
|
15
15
|
width,
|
|
16
16
|
clientHeight: height,
|
|
17
17
|
clientWidth: width,
|
|
18
|
+
// On web the real DOM canvas handles events; delegate to it.
|
|
19
|
+
addEventListener: canvas.addEventListener.bind(canvas),
|
|
20
|
+
removeEventListener: canvas.removeEventListener.bind(canvas),
|
|
21
|
+
dispatchEvent: canvas.dispatchEvent.bind(canvas),
|
|
22
|
+
setPointerCapture: canvas.setPointerCapture.bind(canvas),
|
|
23
|
+
releasePointerCapture: canvas.releasePointerCapture.bind(canvas),
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
26
|
|
|
@@ -40,9 +46,9 @@ function makeWebGPUCanvasContext(
|
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
const context = canvas.getContext("webgpu")!;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
49
|
+
// On web there is no manual present; expose a no-op so RNCanvasContext's
|
|
50
|
+
// present() (called after queue.submit() on native) is callable here too.
|
|
51
|
+
return Object.assign(context, { present: () => {} });
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
// @ts-expect-error - polyfill for RNWebGPU native module
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
|
|
3
|
+
// WebGPU flag constants as importable JS values.
|
|
4
|
+
//
|
|
5
|
+
// The native module installs `GPUBufferUsage`, `GPUTextureUsage`,
|
|
6
|
+
// `GPUShaderStage`, `GPUColorWrite` and `GPUMapMode` as globals, but only on the
|
|
7
|
+
// main JS runtime. Worklet runtimes (Reanimated UI, dedicated worklet runtimes,
|
|
8
|
+
// Vision Camera frame processors) do not get those globals, so referencing the
|
|
9
|
+
// bare global inside a worklet yields `undefined`.
|
|
10
|
+
//
|
|
11
|
+
// Rather than hardcode the bit values here (which could drift from the native
|
|
12
|
+
// `wgpu::*Usage` enums), we re-export the globals the native module already
|
|
13
|
+
// installed (see `GPUBufferUsage.h` and friends, which derive their values from
|
|
14
|
+
// the Dawn enums with `static_assert`s). This keeps a single source of truth.
|
|
15
|
+
// Importing them into a worklet lets the Worklets serializer capture them by
|
|
16
|
+
// closure (the same way module-level shader strings are captured), making them
|
|
17
|
+
// available on every runtime without passing them in by hand:
|
|
18
|
+
//
|
|
19
|
+
// import { GPUBufferUsage } from "react-native-webgpu";
|
|
20
|
+
// const work = () => {
|
|
21
|
+
// "worklet";
|
|
22
|
+
// device.createBuffer({ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ });
|
|
23
|
+
// };
|
|
24
|
+
//
|
|
25
|
+
// These are read at module evaluation time. The package entry (`index.tsx`)
|
|
26
|
+
// re-exports `./main` before `./constants`, and `./main` installs the native
|
|
27
|
+
// module synchronously, so the globals always exist by the time this runs.
|
|
28
|
+
|
|
29
|
+
export const { GPUBufferUsage } = globalThis;
|
|
30
|
+
|
|
31
|
+
export const { GPUTextureUsage } = globalThis;
|
|
32
|
+
|
|
33
|
+
export const { GPUShaderStage } = globalThis;
|
|
34
|
+
|
|
35
|
+
export const { GPUColorWrite } = globalThis;
|
|
36
|
+
|
|
37
|
+
export const { GPUMapMode } = globalThis;
|