react-native-wgpu 0.5.10 → 0.5.13
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 +84 -0
- package/android/CMakeLists.txt +2 -0
- package/android/cpp/AndroidPlatformContext.h +127 -5
- package/apple/ApplePlatformContext.h +17 -4
- package/apple/ApplePlatformContext.mm +161 -16
- package/apple/AppleVideoPlayer.h +31 -0
- package/apple/AppleVideoPlayer.mm +314 -0
- package/apple/WebGPUModule.h +2 -1
- package/apple/WebGPUModule.mm +4 -2
- package/cpp/rnwgpu/ArrayBuffer.h +51 -7
- package/cpp/rnwgpu/PlatformContext.h +91 -8
- package/cpp/rnwgpu/RNWebGPUManager.cpp +12 -0
- package/cpp/rnwgpu/api/Convertors.h +33 -11
- package/cpp/rnwgpu/api/GPU.cpp +27 -0
- package/cpp/rnwgpu/api/GPUAdapter.cpp +109 -33
- package/cpp/rnwgpu/api/GPUDevice.cpp +58 -5
- package/cpp/rnwgpu/api/GPUDevice.h +6 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.cpp +335 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +47 -2
- package/cpp/rnwgpu/api/GPUFeatures.h +7 -13
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +2 -3
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +80 -0
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +71 -0
- package/cpp/rnwgpu/api/ImageBitmap.h +8 -0
- package/cpp/rnwgpu/api/RNWebGPU.h +70 -32
- package/cpp/rnwgpu/api/RnFeatures.h +53 -0
- package/cpp/rnwgpu/api/VideoFrame.h +76 -0
- package/cpp/rnwgpu/api/VideoPlayer.h +69 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +4 -1
- package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +18 -3
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +35 -33
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +62 -0
- package/cpp/rnwgpu/api/descriptors/Unions.h +10 -15
- package/cpp/webgpu/webgpu.h +312 -188
- package/cpp/webgpu/webgpu_cpp.h +1611 -1720
- package/cpp/webgpu/webgpu_cpp_print.h +190 -61
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +0 -10
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +20 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +32 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
- package/libs/android/x86/libwebgpu_dawn.so +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +8 -8
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/package.json +5 -5
- package/src/Canvas.tsx +0 -15
- package/src/index.tsx +62 -2
- package/src/types.ts +83 -1
- package/libs/dawn.json +0 -4693
package/src/Canvas.tsx
CHANGED
|
@@ -9,21 +9,6 @@ function generateContextId() {
|
|
|
9
9
|
return CONTEXT_COUNTER++;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
declare global {
|
|
13
|
-
var RNWebGPU: {
|
|
14
|
-
gpu: GPU;
|
|
15
|
-
fabric: boolean;
|
|
16
|
-
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
17
|
-
MakeWebGPUCanvasContext: (
|
|
18
|
-
contextId: number,
|
|
19
|
-
width: number,
|
|
20
|
-
height: number,
|
|
21
|
-
) => RNCanvasContext;
|
|
22
|
-
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
23
|
-
createImageBitmap: typeof createImageBitmap;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
12
|
type SurfacePointer = bigint;
|
|
28
13
|
|
|
29
14
|
export interface NativeCanvas {
|
package/src/index.tsx
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
/// <reference types="@webgpu/types" />
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
GPUDawnTogglesDescriptor,
|
|
4
|
+
GPUSharedTextureMemory,
|
|
5
|
+
GPUSharedTextureMemoryDescriptor,
|
|
6
|
+
NativeCanvas,
|
|
7
|
+
RNCanvasContext,
|
|
8
|
+
VideoPlayer,
|
|
9
|
+
NativeVideoFrame,
|
|
10
|
+
NativeVideoPixelFormat,
|
|
11
|
+
} from "./types";
|
|
4
12
|
|
|
5
13
|
export * from "./main";
|
|
14
|
+
export type {
|
|
15
|
+
NativeVideoFrame,
|
|
16
|
+
VideoPlayer,
|
|
17
|
+
NativeVideoPixelFormat,
|
|
18
|
+
CreateVideoPlayerOptions,
|
|
19
|
+
GPUSharedTextureMemory,
|
|
20
|
+
GPUSharedTextureMemoryDescriptor,
|
|
21
|
+
GPUDawnTogglesDescriptor,
|
|
22
|
+
} from "./types";
|
|
6
23
|
|
|
7
24
|
declare global {
|
|
8
25
|
interface Navigator {
|
|
@@ -22,8 +39,51 @@ declare global {
|
|
|
22
39
|
) => RNCanvasContext;
|
|
23
40
|
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
24
41
|
createImageBitmap: typeof createImageBitmap;
|
|
42
|
+
loadVideoFrame: (path: string) => NativeVideoFrame;
|
|
43
|
+
createTestVideoFrame: (width: number, height: number) => NativeVideoFrame;
|
|
44
|
+
// Wrap a NativeBuffer.pointer (CVPixelBufferRef on iOS / AHardwareBuffer*
|
|
45
|
+
// on Android) into a NativeVideoFrame. Matches the shape used by libraries
|
|
46
|
+
// that emit NativeBuffer (e.g. react-native-vision-camera).
|
|
47
|
+
createVideoFrameFromNativeBuffer: (pointer: bigint) => NativeVideoFrame;
|
|
48
|
+
createVideoPlayer: (
|
|
49
|
+
path: string,
|
|
50
|
+
pixelFormat?: NativeVideoPixelFormat,
|
|
51
|
+
) => VideoPlayer;
|
|
52
|
+
writeTestVideoFile: () => string;
|
|
25
53
|
};
|
|
26
54
|
|
|
55
|
+
interface GPUDevice {
|
|
56
|
+
importSharedTextureMemory(
|
|
57
|
+
descriptor: GPUSharedTextureMemoryDescriptor,
|
|
58
|
+
): GPUSharedTextureMemory;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Non-standard, Dawn-only. Lets callers set Dawn device-stage toggles at
|
|
62
|
+
// device creation: adapter.requestDevice({ dawnToggles: { ... } }).
|
|
63
|
+
interface GPUDeviceDescriptor {
|
|
64
|
+
dawnToggles?: GPUDawnTogglesDescriptor;
|
|
65
|
+
}
|
|
66
|
+
// Non-spec extension: camera frames arrive in the sensor's native
|
|
67
|
+
// orientation, which differs between iOS and Android. `rotation` (degrees,
|
|
68
|
+
// one of 0/90/180/270) and `mirrored` (horizontal flip) are baked into the
|
|
69
|
+
// sampling transform by Dawn, so the shader sees an upright frame. Maps
|
|
70
|
+
// directly onto VisionCamera's `frame.orientation` / `frame.isMirrored`.
|
|
71
|
+
interface GPUExternalTextureDescriptor {
|
|
72
|
+
rotation?: 0 | 90 | 180 | 270;
|
|
73
|
+
mirrored?: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Non-spec extension: a GPUExternalTexture imported from a native surface
|
|
77
|
+
// holds an open shared-memory access window on that surface until this
|
|
78
|
+
// wrapper is destroyed. Call destroy() right after the queue.submit() that
|
|
79
|
+
// sampled it (never before) to release the surface back to its producer
|
|
80
|
+
// immediately, instead of waiting for garbage collection. Forgetting to call
|
|
81
|
+
// it is not fatal (GC still cleans up), but it can starve a producer's buffer
|
|
82
|
+
// pool (e.g. a camera/video player) and pile up GPU resources.
|
|
83
|
+
interface GPUExternalTexture {
|
|
84
|
+
destroy(): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
27
87
|
// Extend createImageBitmap to accept ArrayBuffer/TypedArray (encoded image bytes)
|
|
28
88
|
function createImageBitmap(
|
|
29
89
|
image: ArrayBuffer | ArrayBufferView,
|
package/src/types.ts
CHANGED
|
@@ -16,5 +16,87 @@ export interface CanvasRef {
|
|
|
16
16
|
getContextId: () => number;
|
|
17
17
|
getContext(contextName: "webgpu"): RNCanvasContext | null;
|
|
18
18
|
getNativeSurface: () => NativeCanvas;
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Pixel layout of a NativeVideoFrame. NOT the WebCodecs `VideoPixelFormat`
|
|
22
|
+
// enum — these are the two native surface layouts we support, lower-cased to
|
|
23
|
+
// avoid being mistaken for the spec values ("NV12", "BGRA", …).
|
|
24
|
+
export type NativeVideoPixelFormat = "bgra8" | "nv12";
|
|
25
|
+
|
|
26
|
+
// A native, GPU-shareable handle to a single video frame.
|
|
27
|
+
//
|
|
28
|
+
// NOT the WebCodecs `VideoFrame`: there is no `close()`/`format`/`timestamp`,
|
|
29
|
+
// the surface is referenced by a raw native pointer, and disposal is
|
|
30
|
+
// `release()`. Named with a `Native` prefix so it doesn't shadow the global
|
|
31
|
+
// WebCodecs type or imply spec semantics it doesn't have.
|
|
32
|
+
//
|
|
33
|
+
// - handle is the raw pointer (IOSurfaceRef on Apple, AHardwareBuffer* on
|
|
34
|
+
// Android) encoded as a BigInt. Pass it to
|
|
35
|
+
// GPUDevice.importSharedTextureMemory.
|
|
36
|
+
// - pixelFormat describes the surface layout: 'bgra8' for a sampled
|
|
37
|
+
// GPUTexture; 'nv12' (biplanar Y + CbCr) for the importExternalTexture
|
|
38
|
+
// path.
|
|
39
|
+
// - release() drops the underlying backing object (a CVPixelBuffer on Apple).
|
|
40
|
+
// The frame is also released when the JS wrapper is garbage-collected; call
|
|
41
|
+
// release() eagerly when you know you're done.
|
|
42
|
+
export interface NativeVideoFrame {
|
|
43
|
+
readonly handle: bigint;
|
|
44
|
+
readonly width: number;
|
|
45
|
+
readonly height: number;
|
|
46
|
+
readonly pixelFormat: NativeVideoPixelFormat;
|
|
47
|
+
release(): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// A handle to a decoded video stream. Poll copyLatestFrame() each render tick
|
|
51
|
+
// to obtain the most recently decoded frame as an IOSurface/AHardwareBuffer
|
|
52
|
+
// (returns null between frames so callers can skip the import work).
|
|
53
|
+
export interface VideoPlayer {
|
|
54
|
+
copyLatestFrame(): NativeVideoFrame | null;
|
|
55
|
+
play(): void;
|
|
56
|
+
pause(): void;
|
|
57
|
+
release(): void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface CreateVideoPlayerOptions {
|
|
61
|
+
// 'bgra8' (default): emit a single-plane BGRA surface, suitable for
|
|
62
|
+
// SharedTextureMemory and a regular sampled GPUTexture.
|
|
63
|
+
// 'nv12': emit biplanar Y + CbCr surfaces, suitable for
|
|
64
|
+
// GPUDevice.importExternalTexture.
|
|
65
|
+
pixelFormat?: NativeVideoPixelFormat;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface GPUSharedTextureMemoryDescriptor {
|
|
69
|
+
// Raw native handle (IOSurfaceRef on Apple, AHardwareBuffer* on Android),
|
|
70
|
+
// encoded as a BigInt. The caller is responsible for keeping the underlying
|
|
71
|
+
// object alive for as long as the shared memory (and any textures derived
|
|
72
|
+
// from it) are in use. Using NativeVideoFrame.handle handles this
|
|
73
|
+
// automatically.
|
|
74
|
+
handle: bigint;
|
|
75
|
+
label?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Non-standard, Dawn-only device toggles. Mirrors Dawn's DawnTogglesDescriptor
|
|
79
|
+
// and is chained onto the native device descriptor at requestDevice time.
|
|
80
|
+
// Pass it via the (augmented) GPUDeviceDescriptor: adapter.requestDevice({
|
|
81
|
+
// dawnToggles: { enabledToggles: ["dump_shaders"] } }). Toggle names are open
|
|
82
|
+
// strings (see Dawn's Toggles.cpp); these flags are Dawn-specific and
|
|
83
|
+
// non-portable.
|
|
84
|
+
export interface GPUDawnTogglesDescriptor {
|
|
85
|
+
enabledToggles?: string[];
|
|
86
|
+
disabledToggles?: string[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// A piece of shared GPU memory backed by a native surface. Use createTexture()
|
|
90
|
+
// to obtain a regular GPUTexture that aliases the surface's pixels. The
|
|
91
|
+
// returned texture must be bracketed by beginAccess/endAccess around any
|
|
92
|
+
// command-buffer submission that uses it.
|
|
93
|
+
export interface GPUSharedTextureMemory {
|
|
94
|
+
readonly __brand: "GPUSharedTextureMemory";
|
|
95
|
+
label: string;
|
|
96
|
+
createTexture(descriptor?: GPUTextureDescriptor): GPUTexture;
|
|
97
|
+
// `initialized` declares whether the surface already holds meaningful pixels
|
|
98
|
+
// (true for an incoming video/camera frame, false if the next pass will fully
|
|
99
|
+
// overwrite it).
|
|
100
|
+
beginAccess(texture: GPUTexture, initialized: boolean): boolean;
|
|
101
|
+
endAccess(texture: GPUTexture): boolean;
|
|
20
102
|
}
|