react-native-webgpu 0.14.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/cpp/AndroidColorSpace.h +107 -0
- package/android/cpp/AndroidPlatformContext.h +100 -9
- package/android/cpp/AndroidVideoPlayer.h +46 -1
- package/android/cpp/cpp-adapter.cpp +53 -1
- package/android/src/main/java/com/webgpu/SyncFences.java +88 -0
- package/android/src/main/java/com/webgpu/ViewSnapshot.java +66 -23
- package/android/src/main/java/com/webgpu/WebGPUModule.java +69 -5
- package/android/src/main/java/com/webgpu/WebGPUVideoPlayer.java +109 -0
- package/apple/ApplePlatformContext.h +5 -5
- package/apple/ApplePlatformContext.mm +75 -3
- package/apple/AppleVideoPlayer.mm +68 -35
- package/cpp/dawn/common/ExternalTextureParams.h +67 -0
- package/cpp/rnwgpu/PlatformContext.h +65 -16
- package/cpp/rnwgpu/SurfaceRegistry.h +39 -5
- package/cpp/rnwgpu/api/GPUAdapter.cpp +35 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.cpp +172 -156
- package/cpp/rnwgpu/api/GPUExternalTexture.h +2 -19
- package/cpp/rnwgpu/api/GPUQueue.cpp +98 -3
- package/cpp/rnwgpu/api/RNWebGPU.h +12 -3
- package/cpp/rnwgpu/api/VideoFrameBlit.h +39 -24
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +10 -3
- package/lib/commonjs/Canvas.js +36 -6
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/WebPolyfillGPUModule.js +6 -3
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -1
- package/lib/commonjs/constants.js +6 -3
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/index.js +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/install.js +9 -22
- package/lib/commonjs/install.js.map +1 -1
- package/lib/commonjs/main/index.js +8 -7
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/commonjs/main/index.web.js +1 -1
- package/lib/commonjs/main/installNative.js +20 -0
- package/lib/commonjs/main/installNative.js.map +1 -0
- package/lib/commonjs/main/installNative.web.js +4 -0
- package/lib/commonjs/main/installNative.web.js.map +1 -0
- package/lib/commonjs/mock.js +60 -13
- package/lib/commonjs/mock.js.map +1 -1
- package/lib/module/Canvas.js +37 -7
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/WebPolyfillGPUModule.js +6 -3
- package/lib/module/WebPolyfillGPUModule.js.map +1 -1
- package/lib/module/constants.js +6 -3
- package/lib/module/constants.js.map +1 -1
- package/lib/module/index.js +8 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/install.js +8 -20
- package/lib/module/install.js.map +1 -1
- package/lib/module/main/index.js +6 -7
- package/lib/module/main/index.js.map +1 -1
- package/lib/module/main/index.web.js +1 -1
- package/lib/module/main/index.web.js.map +1 -1
- package/lib/module/main/installNative.js +18 -0
- package/lib/module/main/installNative.js.map +1 -0
- package/lib/module/main/installNative.web.js +6 -0
- package/lib/module/main/installNative.web.js.map +1 -0
- package/lib/module/mock.js +55 -1
- package/lib/module/mock.js.map +1 -1
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/install.d.ts +41 -3
- package/lib/typescript/lib/commonjs/install.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/main/installNative.d.ts +2 -0
- package/lib/typescript/lib/commonjs/main/installNative.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/main/installNative.web.d.ts +2 -0
- package/lib/typescript/lib/commonjs/main/installNative.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/mock.d.ts +39 -0
- package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/install.d.ts +0 -1
- package/lib/typescript/lib/module/install.d.ts.map +1 -1
- package/lib/typescript/lib/module/main/installNative.d.ts +2 -0
- package/lib/typescript/lib/module/main/installNative.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/installNative.web.d.ts +2 -0
- package/lib/typescript/lib/module/main/installNative.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/mock.d.ts +39 -1
- package/lib/typescript/lib/module/mock.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/constants.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/install.d.ts +0 -5
- package/lib/typescript/src/install.d.ts.map +1 -1
- 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 -1
- package/lib/typescript/src/main/index.web.d.ts.map +1 -1
- package/lib/typescript/src/main/installNative.d.ts +2 -0
- package/lib/typescript/src/main/installNative.d.ts.map +1 -0
- package/lib/typescript/src/main/installNative.web.d.ts +2 -0
- package/lib/typescript/src/main/installNative.web.d.ts.map +1 -0
- package/lib/typescript/src/mock.d.ts +5 -1
- package/lib/typescript/src/mock.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Canvas.tsx +48 -29
- package/src/WebPolyfillGPUModule.ts +3 -1
- package/src/constants.ts +6 -3
- package/src/index.tsx +18 -10
- package/src/install.ts +9 -18
- package/src/main/index.tsx +7 -10
- package/src/main/index.web.tsx +1 -1
- package/src/main/installNative.ts +20 -0
- package/src/main/installNative.web.ts +5 -0
- package/src/mock.ts +60 -1
|
@@ -1,5 +1,43 @@
|
|
|
1
|
-
export * from "./constants";
|
|
2
1
|
export * from "./formats";
|
|
2
|
+
export namespace GPUBufferUsage {
|
|
3
|
+
let MAP_READ: number;
|
|
4
|
+
let MAP_WRITE: number;
|
|
5
|
+
let COPY_SRC: number;
|
|
6
|
+
let COPY_DST: number;
|
|
7
|
+
let INDEX: number;
|
|
8
|
+
let VERTEX: number;
|
|
9
|
+
let UNIFORM: number;
|
|
10
|
+
let STORAGE: number;
|
|
11
|
+
let INDIRECT: number;
|
|
12
|
+
let QUERY_RESOLVE: number;
|
|
13
|
+
}
|
|
14
|
+
export namespace GPUTextureUsage {
|
|
15
|
+
let COPY_SRC_1: number;
|
|
16
|
+
export { COPY_SRC_1 as COPY_SRC };
|
|
17
|
+
let COPY_DST_1: number;
|
|
18
|
+
export { COPY_DST_1 as COPY_DST };
|
|
19
|
+
export let TEXTURE_BINDING: number;
|
|
20
|
+
export let STORAGE_BINDING: number;
|
|
21
|
+
export let RENDER_ATTACHMENT: number;
|
|
22
|
+
export let TRANSIENT_ATTACHMENT: number;
|
|
23
|
+
}
|
|
24
|
+
export namespace GPUShaderStage {
|
|
25
|
+
let VERTEX_1: number;
|
|
26
|
+
export { VERTEX_1 as VERTEX };
|
|
27
|
+
export let FRAGMENT: number;
|
|
28
|
+
export let COMPUTE: number;
|
|
29
|
+
}
|
|
30
|
+
export namespace GPUColorWrite {
|
|
31
|
+
let RED: number;
|
|
32
|
+
let GREEN: number;
|
|
33
|
+
let BLUE: number;
|
|
34
|
+
let ALPHA: number;
|
|
35
|
+
let ALL: number;
|
|
36
|
+
}
|
|
37
|
+
export namespace GPUMapMode {
|
|
38
|
+
let READ: number;
|
|
39
|
+
let WRITE: number;
|
|
40
|
+
}
|
|
3
41
|
export function Canvas({ opaque: _opaque, android: _android, ref, ...props }: {
|
|
4
42
|
[x: string]: any;
|
|
5
43
|
opaque: any;
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEO;;;;;2DAcN;AACM,6DAA6C;AAC7C;;;EAGL;AACK,0DAAoD;AACpD;;;EAGL;AACK;;QAEe;AACf,uCAEN;AACM,mDAEN;AAC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AQ,GAAG,eAAe,GAAG,IAAI,CAAC;IAC1D,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACtC;AAED,MAAM,MAAM,kBAAkB,GAC5B,aAAa,GAAG,aAAa,GAAG,oBAAoB,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CAC5B;AA+BD,eAAO,MAAM,MAAM,GAAI,oCAKpB,WAAW,sBAoDb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AA+BA,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,3 +1,4 @@
|
|
|
1
|
+
import "./main/installNative";
|
|
1
2
|
import type { GPUDrawElementImageDestination, GPUDrawElementImageSource, GPUSharedFence, GPUSharedFenceDescriptor, GPUDawnTogglesDescriptor, GPUNativeExternalTextureDescriptor, GPUSharedTextureMemory, GPUSharedTextureMemoryDescriptor, GPUCopyExternalNativeFrameSourceInfo, NativeCanvas, RNCanvasContext, VideoPlayer, NativeVideoFrame, NativeVideoPixelFormat } from "./types";
|
|
2
3
|
export * from "./main";
|
|
3
4
|
export * from "./constants";
|
|
@@ -17,7 +18,7 @@ declare global {
|
|
|
17
18
|
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
18
19
|
createImageBitmap: typeof createImageBitmap;
|
|
19
20
|
loadVideoFrame: (path: string) => NativeVideoFrame;
|
|
20
|
-
createTestVideoFrame: (width: number, height: number) => NativeVideoFrame;
|
|
21
|
+
createTestVideoFrame: (width: number, height: number, pixelFormat?: NativeVideoPixelFormat) => NativeVideoFrame;
|
|
21
22
|
createVideoFrameFromNativeBuffer: (pointer: bigint) => NativeVideoFrame;
|
|
22
23
|
importDevice: (pointer: bigint) => GPUDevice;
|
|
23
24
|
adoptTexture: (pointer: bigint) => GPUTexture;
|
|
@@ -46,7 +47,6 @@ declare global {
|
|
|
46
47
|
}
|
|
47
48
|
interface GPUExternalTexture {
|
|
48
49
|
destroy(): void;
|
|
49
|
-
readonly yuvToRgbMatrix: number[];
|
|
50
50
|
}
|
|
51
51
|
function createImageBitmap(image: ArrayBuffer | ArrayBufferView, options?: ImageBitmapOptions): Promise<ImageBitmap>;
|
|
52
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAQA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EACV,8BAA8B,EAC9B,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,kCAAkC,EAClC,sBAAsB,EACtB,gCAAgC,EAChC,oCAAoC,EACpC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,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WebGPU()` can put `navigator.gpu` on other runtimes.
|
|
4
|
-
*/
|
|
5
|
-
export declare const provideGPUForInstall: (gpu: GPU) => void;
|
|
6
1
|
/**
|
|
7
2
|
* Install WebGPU on the runtime that calls it.
|
|
8
3
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AA+BA
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,aAAa,YAgBzB,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":"AAKA,OAAO,iBAAiB,CAAC;AAoDzB,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,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAE3B,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,
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../src/main/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AAEzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installNative.d.ts","sourceRoot":"","sources":["../../../../src/main/installNative.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installNative.web.d.ts","sourceRoot":"","sources":["../../../../src/main/installNative.web.ts"],"names":[],"mappings":"AAIA,OAAO,yBAAyB,CAAC"}
|
|
@@ -2,8 +2,12 @@ import React from "react";
|
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
import { View } from "react-native";
|
|
4
4
|
import type { CanvasProps } from "./Canvas";
|
|
5
|
-
export * from "./constants";
|
|
6
5
|
export * from "./formats";
|
|
6
|
+
export declare const GPUBufferUsage: GPUBufferUsage;
|
|
7
|
+
export declare const GPUTextureUsage: GPUTextureUsage;
|
|
8
|
+
export declare const GPUShaderStage: GPUShaderStage;
|
|
9
|
+
export declare const GPUColorWrite: GPUColorWrite;
|
|
10
|
+
export declare const GPUMapMode: GPUMapMode;
|
|
7
11
|
export type { AndroidCanvasProps, AndroidSurfaceType, CanvasProps, CanvasRef, NativeCanvas, RNCanvasContext, } from "./Canvas";
|
|
8
12
|
export declare const Canvas: ({ opaque: _opaque, android: _android, ref, ...props }: CanvasProps) => React.CElement<import("react-native").ViewProps, View>;
|
|
9
13
|
export declare const useCanvasRef: () => React.MutableRefObject<null>;
|
|
@@ -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;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAiC,MAAM,UAAU,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canvas.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
2
2
|
import type { ViewProps } from "react-native";
|
|
3
|
-
import { View } from "react-native";
|
|
3
|
+
import { Platform, View } from "react-native";
|
|
4
4
|
|
|
5
5
|
import WebGPUNativeView from "./WebGPUViewNativeComponent";
|
|
6
6
|
|
|
@@ -87,50 +87,69 @@ const resolveSurfaceType = (
|
|
|
87
87
|
? surfaceType
|
|
88
88
|
: "auto";
|
|
89
89
|
|
|
90
|
+
// A view measured relative to itself gets its layout size, without the
|
|
91
|
+
// transforms getBoundingClientRect() includes; measureLayout() calls back
|
|
92
|
+
// synchronously on the new architecture. On the web react-native-web measures
|
|
93
|
+
// asynchronously, so the DOM node is read directly: clientWidth/clientHeight
|
|
94
|
+
// are layout values that ignore transforms too (unlike getBoundingClientRect)
|
|
95
|
+
// and are what browser WebGPU code sizes a canvas from.
|
|
96
|
+
const measureLayout = (view: View) => {
|
|
97
|
+
if (Platform.OS === "web") {
|
|
98
|
+
const { clientWidth, clientHeight } = view as unknown as HTMLElement;
|
|
99
|
+
return { width: clientWidth, height: clientHeight };
|
|
100
|
+
}
|
|
101
|
+
let size = { width: 0, height: 0 };
|
|
102
|
+
view.measureLayout(view, (_left, _top, width, height) => {
|
|
103
|
+
size = { width, height };
|
|
104
|
+
});
|
|
105
|
+
return size;
|
|
106
|
+
};
|
|
107
|
+
|
|
90
108
|
export const Canvas = ({
|
|
91
109
|
opaque = true,
|
|
92
110
|
android,
|
|
93
111
|
ref,
|
|
94
112
|
...props
|
|
95
113
|
}: CanvasProps) => {
|
|
96
|
-
const viewRef = useRef(null);
|
|
114
|
+
const viewRef = useRef<View>(null);
|
|
97
115
|
const [contextId, _] = useState(() => generateContextId());
|
|
98
116
|
// Retire the native registry entry for this contextId on unmount. When a
|
|
99
117
|
// native surface is still attached, this is a no-op and the native view's
|
|
100
118
|
// own teardown retires the entry instead — which keeps StrictMode's
|
|
101
119
|
// simulated unmount (which re-runs effects without unmounting native views)
|
|
102
|
-
// from orphaning a live surface.
|
|
120
|
+
// from orphaning a live surface. When no surface is attached yet (StrictMode
|
|
121
|
+
// runs this cleanup right after mount, possibly before the UI thread got to
|
|
122
|
+
// it), a context kept from the first effect run keeps its surface entry,
|
|
123
|
+
// which the native view takes over when it attaches.
|
|
103
124
|
useEffect(() => {
|
|
104
125
|
return () => {
|
|
105
126
|
RNWebGPU.destroyContext(contextId);
|
|
106
127
|
};
|
|
107
128
|
}, [contextId]);
|
|
108
|
-
useImperativeHandle(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
},
|
|
133
|
-
}));
|
|
129
|
+
useImperativeHandle(
|
|
130
|
+
ref,
|
|
131
|
+
() => ({
|
|
132
|
+
getContextId: () => contextId,
|
|
133
|
+
getNativeSurface: () => {
|
|
134
|
+
return RNWebGPU.getNativeSurface(contextId);
|
|
135
|
+
},
|
|
136
|
+
getContext(contextName: "webgpu"): RNCanvasContext | null {
|
|
137
|
+
if (contextName !== "webgpu") {
|
|
138
|
+
throw new Error(`[WebGPU] Unsupported context: ${contextName}`);
|
|
139
|
+
}
|
|
140
|
+
if (!viewRef.current) {
|
|
141
|
+
throw new Error("[WebGPU] Cannot get context before mount");
|
|
142
|
+
}
|
|
143
|
+
const size = measureLayout(viewRef.current);
|
|
144
|
+
return RNWebGPU.MakeWebGPUCanvasContext(
|
|
145
|
+
contextId,
|
|
146
|
+
size.width,
|
|
147
|
+
size.height,
|
|
148
|
+
);
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
[contextId],
|
|
152
|
+
);
|
|
134
153
|
|
|
135
154
|
return (
|
|
136
155
|
<View collapsable={false} ref={viewRef} {...props}>
|
|
@@ -7,7 +7,9 @@ function getNativeSurface(contextId: number) {
|
|
|
7
7
|
contextIdToId(contextId),
|
|
8
8
|
) as HTMLCanvasElement;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// Layout size, like the native view size in dp: unlike
|
|
11
|
+
// getBoundingClientRect() it ignores CSS transforms.
|
|
12
|
+
const { clientHeight: height, clientWidth: width } = canvas;
|
|
11
13
|
|
|
12
14
|
return {
|
|
13
15
|
surface: BigInt(contextId),
|
package/src/constants.ts
CHANGED
|
@@ -22,9 +22,12 @@
|
|
|
22
22
|
// device.createBuffer({ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ });
|
|
23
23
|
// };
|
|
24
24
|
//
|
|
25
|
-
// These are read at module evaluation time
|
|
26
|
-
//
|
|
27
|
-
//
|
|
25
|
+
// These are read at module evaluation time, so the native module must be
|
|
26
|
+
// installed first: the package entry (`./index.tsx`) starts with a bare
|
|
27
|
+
// `import "./main/installNative"` (so does `./main`), which runs the install
|
|
28
|
+
// before this file is reached, directly or through `./install`. An import is
|
|
29
|
+
// evaluated before the body of the module that declares it, so installing in
|
|
30
|
+
// the body of `./main` left every flag undefined.
|
|
28
31
|
|
|
29
32
|
export const { GPUBufferUsage } = globalThis;
|
|
30
33
|
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
/// <reference types="@webgpu/types" />
|
|
2
|
+
// Must stay the FIRST import, and a bare one: it installs the native module
|
|
3
|
+
// (`./main/installNative.ts`; the web variant loads the RNWebGPU polyfill),
|
|
4
|
+
// and `./constants` reads the globals it installs while being evaluated.
|
|
5
|
+
// Putting it here, rather than relying on `./main` being exported before
|
|
6
|
+
// `./constants` below, makes the order of the `export *` lines irrelevant. A
|
|
7
|
+
// bare import is never deferred by `inlineRequires`, and `import/order --fix`
|
|
8
|
+
// never moves an import across one.
|
|
9
|
+
import "./main/installNative";
|
|
10
|
+
|
|
2
11
|
import type {
|
|
3
12
|
GPUDrawElementImageDestination,
|
|
4
13
|
GPUDrawElementImageSource,
|
|
@@ -62,7 +71,15 @@ declare global {
|
|
|
62
71
|
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
63
72
|
createImageBitmap: typeof createImageBitmap;
|
|
64
73
|
loadVideoFrame: (path: string) => NativeVideoFrame;
|
|
65
|
-
|
|
74
|
+
// A synthetic frame: an RGB gradient ('bgra8', the default) or a biplanar
|
|
75
|
+
// YUV frame ('nv12', BT.709 limited range, red on the left half and green
|
|
76
|
+
// on the right) that exercises the color conversion of
|
|
77
|
+
// importExternalTexture.
|
|
78
|
+
createTestVideoFrame: (
|
|
79
|
+
width: number,
|
|
80
|
+
height: number,
|
|
81
|
+
pixelFormat?: NativeVideoPixelFormat,
|
|
82
|
+
) => NativeVideoFrame;
|
|
66
83
|
// Wrap a NativeBuffer.pointer (CVPixelBufferRef on iOS / AHardwareBuffer*
|
|
67
84
|
// on Android) into a NativeVideoFrame. Matches the shape used by libraries
|
|
68
85
|
// that emit NativeBuffer (e.g. react-native-vision-camera).
|
|
@@ -172,15 +189,6 @@ declare global {
|
|
|
172
189
|
// pool (e.g. a camera/video player) and pile up GPU resources.
|
|
173
190
|
interface GPUExternalTexture {
|
|
174
191
|
destroy(): void;
|
|
175
|
-
// Non-spec extension: a 3x4 row-major matrix (12 numbers) mapping the
|
|
176
|
-
// sampled texel [r, g, b, 1] to gamma-encoded R'G'B'. On the Android
|
|
177
|
-
// opaque-YCbCr camera path, textureSampleBaseClampToEdge returns raw
|
|
178
|
-
// [Y, Cb, Cr] (Dawn hard-codes an RGB_IDENTITY Vulkan conversion); this
|
|
179
|
-
// matrix is derived per-buffer from the driver's suggested YCbCr model and
|
|
180
|
-
// range (BT.601/709/2020, full/narrow). Everywhere else (iOS, RGBA
|
|
181
|
-
// surfaces) it is the identity passthrough, so shaders can apply it
|
|
182
|
-
// unconditionally. Upload it as a uniform and multiply after sampling.
|
|
183
|
-
readonly yuvToRgbMatrix: number[];
|
|
184
192
|
}
|
|
185
193
|
|
|
186
194
|
// Extend createImageBitmap to accept ArrayBuffer/TypedArray (encoded image bytes)
|
package/src/install.ts
CHANGED
|
@@ -19,23 +19,15 @@ const constants = {
|
|
|
19
19
|
GPUMapMode,
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
// The GPU instance destined for `navigator.gpu` on other runtimes,
|
|
23
|
-
//
|
|
24
|
-
// evaluated
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
};
|
|
22
|
+
// The GPU instance destined for `navigator.gpu` on other runtimes, read from
|
|
23
|
+
// the native install like the flags above (the package entry runs the install
|
|
24
|
+
// before this module is evaluated). Undefined on web, where the RNWebGPU
|
|
25
|
+
// polyfill has no gpu and the browser already provides navigator.gpu. Captured
|
|
26
|
+
// into the `installWebGPU` worklet closure: when a worklet is serialized, the
|
|
27
|
+
// Worklets custom serializer boxes the GPU object, and unboxing on the target
|
|
28
|
+
// runtime installs the GPU prototype there.
|
|
29
|
+
const gpu: GPU | undefined =
|
|
30
|
+
typeof RNWebGPU === "undefined" ? undefined : RNWebGPU.gpu;
|
|
39
31
|
|
|
40
32
|
/**
|
|
41
33
|
* Install WebGPU on the runtime that calls it.
|
|
@@ -88,7 +80,6 @@ export const installWebGPU = () => {
|
|
|
88
80
|
g[key] = value;
|
|
89
81
|
}
|
|
90
82
|
}
|
|
91
|
-
const { gpu } = holder;
|
|
92
83
|
if (gpu !== undefined) {
|
|
93
84
|
const nav = g.navigator as { gpu?: GPU; userAgent?: string } | undefined;
|
|
94
85
|
if (nav === undefined) {
|
package/src/main/index.tsx
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
// Must stay the FIRST import, and a bare one: it installs the native module
|
|
2
|
+
// (the RNWebGPU global and the WebGPU globals) before anything else here is
|
|
3
|
+
// evaluated; the package entry imports it first as well, see ./installNative.ts.
|
|
4
|
+
// An import with bindings could be deferred to its first use by
|
|
5
|
+
// `inlineRequires`; a bare import is not.
|
|
6
|
+
import "./installNative";
|
|
7
|
+
|
|
1
8
|
import { findNodeHandle } from "react-native";
|
|
2
9
|
|
|
3
10
|
import { registerWebGPUForReanimated } from "../external";
|
|
4
|
-
import { provideGPUForInstall } from "../install";
|
|
5
|
-
import WebGPUModule from "../NativeWebGPUModule";
|
|
6
11
|
import type { GPUDrawElementImageSourceView } from "../types";
|
|
7
12
|
|
|
8
13
|
// Resolve the `source` of drawElementImageToTexture to a React tag on the
|
|
@@ -61,8 +66,6 @@ export * from "../formats";
|
|
|
61
66
|
|
|
62
67
|
export { default as WebGPUModule } from "../NativeWebGPUModule";
|
|
63
68
|
|
|
64
|
-
const _installOk = WebGPUModule.install();
|
|
65
|
-
|
|
66
69
|
registerWebGPUForReanimated();
|
|
67
70
|
|
|
68
71
|
if (typeof RNWebGPU !== "undefined") {
|
|
@@ -87,10 +90,4 @@ if (typeof RNWebGPU !== "undefined") {
|
|
|
87
90
|
global.createImageBitmap =
|
|
88
91
|
global.createImageBitmap ?? RNWebGPU.createImageBitmap.bind(RNWebGPU);
|
|
89
92
|
installDrawElementImageToTexture();
|
|
90
|
-
// Let installWebGPU() put navigator.gpu on other runtimes (see install.ts).
|
|
91
|
-
provideGPUForInstall(RNWebGPU.gpu);
|
|
92
|
-
} else {
|
|
93
|
-
console.warn(
|
|
94
|
-
`[react-native-webgpu] install() returned ${_installOk} but RNWebGPU global is not available`,
|
|
95
|
-
);
|
|
96
93
|
}
|
package/src/main/index.web.tsx
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import WebGPUModule from "../NativeWebGPUModule";
|
|
2
|
+
|
|
3
|
+
// Installs the native module: the RNWebGPU global, and the WebGPU globals of
|
|
4
|
+
// the main runtime (GPUBufferUsage, GPUTextureUsage, GPUShaderStage...).
|
|
5
|
+
//
|
|
6
|
+
// A module of its own, imported FIRST (as a bare import) by the package entry
|
|
7
|
+
// `../index.tsx` and by `./index.tsx`, because `../constants` reads those
|
|
8
|
+
// globals while it is evaluated, and every import of a module is evaluated
|
|
9
|
+
// before that module's body. Installing in the body of `./index.tsx` came too
|
|
10
|
+
// late: the flags exported by the package were all undefined.
|
|
11
|
+
const installOk = WebGPUModule.install();
|
|
12
|
+
|
|
13
|
+
if (typeof RNWebGPU === "undefined") {
|
|
14
|
+
// install() logs the reason natively (e.g. a null jsi::Runtime on iOS).
|
|
15
|
+
// Nothing works from here on (navigator.gpu, the flag constants, Canvas),
|
|
16
|
+
// so fail at import time rather than leave every export undefined.
|
|
17
|
+
throw new Error(
|
|
18
|
+
`[react-native-webgpu] the native module failed to install (install() returned ${installOk}): the RNWebGPU global is not available. Make sure the native dependencies are installed and rebuild the app.`,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Web counterpart of ./installNative.ts, so the package entry can import
|
|
2
|
+
// `./main/installNative` on every platform without reaching the TurboModule
|
|
3
|
+
// here. The browser provides the WebGPU globals (navigator.gpu, the flag
|
|
4
|
+
// constants); the polyfill provides the RNWebGPU global that Canvas relies on.
|
|
5
|
+
import "../WebPolyfillGPUModule";
|
package/src/mock.ts
CHANGED
|
@@ -16,9 +16,68 @@ import type { CanvasProps, NativeCanvas, RNCanvasContext } from "./Canvas";
|
|
|
16
16
|
// missing native install (see `importDevice`/`adoptTexture` in
|
|
17
17
|
// `./importDevice.ts`).
|
|
18
18
|
|
|
19
|
-
export * from "./constants";
|
|
20
19
|
export * from "./formats";
|
|
21
20
|
|
|
21
|
+
// The flag constants. The real package re-exports the globals the native
|
|
22
|
+
// module installs (`./constants.ts`); nothing installs them under Jest, so the
|
|
23
|
+
// mock defines the spec values itself and, like the native install, also puts
|
|
24
|
+
// them on globalThis for code that references the bare globals.
|
|
25
|
+
export const GPUBufferUsage: GPUBufferUsage = {
|
|
26
|
+
MAP_READ: 0x0001,
|
|
27
|
+
MAP_WRITE: 0x0002,
|
|
28
|
+
COPY_SRC: 0x0004,
|
|
29
|
+
COPY_DST: 0x0008,
|
|
30
|
+
INDEX: 0x0010,
|
|
31
|
+
VERTEX: 0x0020,
|
|
32
|
+
UNIFORM: 0x0040,
|
|
33
|
+
STORAGE: 0x0080,
|
|
34
|
+
INDIRECT: 0x0100,
|
|
35
|
+
QUERY_RESOLVE: 0x0200,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const GPUTextureUsage: GPUTextureUsage = {
|
|
39
|
+
COPY_SRC: 0x01,
|
|
40
|
+
COPY_DST: 0x02,
|
|
41
|
+
TEXTURE_BINDING: 0x04,
|
|
42
|
+
STORAGE_BINDING: 0x08,
|
|
43
|
+
RENDER_ATTACHMENT: 0x10,
|
|
44
|
+
TRANSIENT_ATTACHMENT: 0x20,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const GPUShaderStage: GPUShaderStage = {
|
|
48
|
+
VERTEX: 0x1,
|
|
49
|
+
FRAGMENT: 0x2,
|
|
50
|
+
COMPUTE: 0x4,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const GPUColorWrite: GPUColorWrite = {
|
|
54
|
+
RED: 0x1,
|
|
55
|
+
GREEN: 0x2,
|
|
56
|
+
BLUE: 0x4,
|
|
57
|
+
ALPHA: 0x8,
|
|
58
|
+
ALL: 0xf,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const GPUMapMode: GPUMapMode = {
|
|
62
|
+
READ: 0x1,
|
|
63
|
+
WRITE: 0x2,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
{
|
|
67
|
+
const g = globalThis as unknown as Record<string, unknown>;
|
|
68
|
+
for (const [key, value] of Object.entries({
|
|
69
|
+
GPUBufferUsage,
|
|
70
|
+
GPUTextureUsage,
|
|
71
|
+
GPUShaderStage,
|
|
72
|
+
GPUColorWrite,
|
|
73
|
+
GPUMapMode,
|
|
74
|
+
})) {
|
|
75
|
+
if (g[key] === undefined) {
|
|
76
|
+
g[key] = value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
22
81
|
const NOT_AVAILABLE_UNDER_JEST =
|
|
23
82
|
"is not available under Jest - react-native-webgpu has no native implementation in tests (see react-native-webgpu/jestSetup.js)";
|
|
24
83
|
|