react-native-webgpu 0.15.2 → 0.16.1

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.
Files changed (73) hide show
  1. package/android/CMakeLists.txt +5 -0
  2. package/android/build.gradle +11 -1
  3. package/android/cpp/cpp-adapter.cpp +109 -11
  4. package/android/src/main/java/com/webgpu/SurfaceFrameRateVote.java +97 -85
  5. package/android/src/main/java/com/webgpu/WebGPUView.java +97 -42
  6. package/apple/ApplePlatformContext.h +1 -0
  7. package/cpp/jsi/JSICache.cpp +2 -0
  8. package/cpp/jsi/NativeObject.h +81 -17
  9. package/cpp/rnwgpu/RNWebGPUManager.cpp +51 -41
  10. package/cpp/rnwgpu/RNWebGPUManager.h +10 -0
  11. package/cpp/rnwgpu/SurfaceRegistry.h +4 -4
  12. package/cpp/rnwgpu/api/GPUDevice.cpp +96 -0
  13. package/cpp/rnwgpu/api/GPUDevice.h +22 -0
  14. package/cpp/rnwgpu/api/GPUError.h +1 -0
  15. package/cpp/rnwgpu/api/GPUExtent2D.h +56 -0
  16. package/cpp/rnwgpu/api/GPUExternalTexture.cpp +32 -408
  17. package/cpp/rnwgpu/api/GPUExternalTexture.h +12 -37
  18. package/cpp/rnwgpu/api/GPUInternalError.h +1 -0
  19. package/cpp/rnwgpu/api/GPUNativeBufferExternalTexture.h +60 -0
  20. package/cpp/rnwgpu/api/GPUNativeBufferTexture.h +52 -0
  21. package/cpp/rnwgpu/api/GPUNativeBufferWrapper.cpp +144 -0
  22. package/cpp/rnwgpu/api/GPUNativeBufferWrapper.h +143 -0
  23. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +1 -0
  24. package/cpp/rnwgpu/api/GPUQueue.h +1 -0
  25. package/cpp/rnwgpu/api/GPUSharedFence.h +1 -0
  26. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +12 -44
  27. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +1 -0
  28. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +1 -0
  29. package/cpp/rnwgpu/api/GPUValidationError.h +1 -0
  30. package/cpp/rnwgpu/api/NativeFrameImport.cpp +638 -0
  31. package/cpp/rnwgpu/api/NativeFrameImport.h +86 -0
  32. package/cpp/rnwgpu/api/VideoFrame.h +21 -7
  33. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +153 -1
  34. package/cpp/rnwgpu/api/descriptors/GPUNativeBufferTextureDescriptor.h +55 -0
  35. package/cpp/rnwgpu/async/RuntimeContext.cpp +1 -0
  36. package/lib/commonjs/Canvas.js +51 -0
  37. package/lib/commonjs/Canvas.js.map +1 -1
  38. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/install.js +26 -7
  41. package/lib/commonjs/install.js.map +1 -1
  42. package/lib/module/Canvas.js +51 -0
  43. package/lib/module/Canvas.js.map +1 -1
  44. package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  45. package/lib/module/index.js.map +1 -1
  46. package/lib/module/install.js +26 -7
  47. package/lib/module/install.js.map +1 -1
  48. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
  49. package/lib/typescript/lib/commonjs/install.d.ts +10 -7
  50. package/lib/typescript/lib/commonjs/install.d.ts.map +1 -1
  51. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  52. package/lib/typescript/lib/module/install.d.ts.map +1 -1
  53. package/lib/typescript/src/Canvas.d.ts +20 -35
  54. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  55. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +1 -0
  56. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  57. package/lib/typescript/src/index.d.ts +4 -2
  58. package/lib/typescript/src/index.d.ts.map +1 -1
  59. package/lib/typescript/src/install.d.ts +10 -7
  60. package/lib/typescript/src/install.d.ts.map +1 -1
  61. package/lib/typescript/src/types.d.ts +34 -1
  62. package/lib/typescript/src/types.d.ts.map +1 -1
  63. package/package.json +6 -5
  64. package/plugin/build/index.js +2 -1
  65. package/plugin/build/setMinSdkVersion.d.ts +9 -0
  66. package/plugin/build/setMinSdkVersion.js +25 -0
  67. package/plugin/build/withMinSdkVersion.d.ts +11 -0
  68. package/plugin/build/withMinSdkVersion.js +20 -0
  69. package/src/Canvas.tsx +74 -40
  70. package/src/external/reanimated/registerWebGPUForReanimated.ts +4 -0
  71. package/src/index.tsx +24 -0
  72. package/src/install.ts +26 -7
  73. package/src/types.ts +98 -1
package/src/Canvas.tsx CHANGED
@@ -2,64 +2,38 @@ import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
2
2
  import type { ViewProps } from "react-native";
3
3
  import { Platform, View } from "react-native";
4
4
 
5
+ import type { CanvasRef, RNCanvasContext } from "./types";
5
6
  import WebGPUNativeView from "./WebGPUViewNativeComponent";
6
7
 
8
+ export type { CanvasRef, NativeCanvas, RNCanvasContext } from "./types";
9
+
7
10
  let CONTEXT_COUNTER = 1;
8
11
  function generateContextId() {
9
12
  return CONTEXT_COUNTER++;
10
13
  }
11
14
 
12
- type SurfacePointer = bigint;
13
-
14
- export interface NativeCanvas {
15
- surface: SurfacePointer;
16
- width: number;
17
- height: number;
18
- clientWidth: number;
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;
27
- }
28
-
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
- */
39
- present: () => void;
40
- };
41
-
42
- export interface CanvasRef {
43
- getContextId: () => number;
44
- getContext(contextName: "webgpu"): RNCanvasContext | null;
45
- getNativeSurface: () => NativeCanvas;
46
- }
47
-
48
15
  export type AndroidSurfaceType =
49
16
  "SurfaceView" | "TextureView" | "HardwareBufferView";
50
17
 
18
+ /**
19
+ * Android-only rendering options. They select the backing view, which is
20
+ * chosen when the canvas mounts and kept: a later change is ignored, with a
21
+ * warning in development. Remount the canvas, with a `key`, to change it.
22
+ */
51
23
  export interface AndroidCanvasProps {
52
24
  /**
53
- * Backing view. Defaults to `SurfaceView` when the canvas is opaque and to
54
- * `TextureView` otherwise; both composite correctly in React Native
25
+ * Backing view. Defaults to `SurfaceView` when the canvas mounts opaque and
26
+ * to `TextureView` otherwise; both composite correctly in React Native
55
27
  * stacking order without further flags. `HardwareBufferView` (Android 10+,
56
28
  * a plain View that draws each frame's AHardwareBuffer inline with no extra
57
29
  * copy) is opt-in and experimental; on older devices it uses `TextureView`.
30
+ * Read once, at mount.
58
31
  */
59
32
  surfaceType?: AndroidSurfaceType;
60
33
  /**
61
34
  * SurfaceView only: composite above every React Native view in the window,
62
- * ignoring `zIndex`. Ignored for TextureView. Defaults to false.
35
+ * ignoring `zIndex`. Ignored for TextureView. Defaults to false. Applied in
36
+ * place on Android 11 and later; read once, at mount, before that.
63
37
  */
64
38
  zOrderOnTop?: boolean;
65
39
  }
@@ -69,9 +43,16 @@ export interface CanvasProps extends ViewProps {
69
43
  * Defaults to true. Set to false to alpha-composite the canvas over the
70
44
  * views behind it (pair it with `alphaMode: "premultiplied"` and an alpha-0
71
45
  * clear color). Android and web only; on iOS `alphaMode` alone controls it.
46
+ * On Android the backing view is chosen from it when the canvas mounts; a
47
+ * later change updates that view in place.
72
48
  */
73
49
  opaque?: boolean;
74
- /** Android-only rendering options. Ignored on iOS and web. */
50
+ /**
51
+ * Android-only rendering options. They select the backing view, which is
52
+ * chosen when the canvas mounts and kept: a later change is ignored, with a
53
+ * warning in development. Remount the canvas, with a `key`, to change it.
54
+ * Ignored on iOS and web.
55
+ */
75
56
  android?: AndroidCanvasProps;
76
57
  ref?: React.Ref<CanvasRef>;
77
58
  }
@@ -87,6 +68,58 @@ const resolveSurfaceType = (
87
68
  ? surfaceType
88
69
  : "auto";
89
70
 
71
+ // The props the Android backing view is chosen from when the canvas mounts.
72
+ interface BackingViewProps {
73
+ opaque: boolean;
74
+ android?: AndroidCanvasProps;
75
+ }
76
+
77
+ // The backing view the props select, see WebGPUView.resolveKind().
78
+ const resolveKind = ({ opaque, android }: BackingViewProps) => {
79
+ const surfaceType = resolveSurfaceType(android?.surfaceType);
80
+ if (surfaceType !== "auto") {
81
+ return surfaceType;
82
+ }
83
+ return opaque ? "SurfaceView" : "TextureView";
84
+ };
85
+
86
+ const warnIgnored = (prop: string) =>
87
+ console.warn(
88
+ `Ignoring a change of ${prop} on a mounted canvas: the backing view is ` +
89
+ "chosen when the canvas mounts. Remount the canvas (give it a new key) " +
90
+ "to change it.",
91
+ );
92
+
93
+ // Warns, in development on Android, about a change of these props that the
94
+ // native view ignores: the backing view is chosen from them when the canvas
95
+ // mounts (see WebGPUView.java, whose setters these rules mirror). The native
96
+ // side only says so in logcat, which is not where a JS developer looks.
97
+ const useBackingViewWarning = (props: BackingViewProps) => {
98
+ const mount = useRef(props);
99
+ const prev = useRef(props);
100
+ useEffect(() => {
101
+ if (__DEV__ && Platform.OS === "android") {
102
+ const { current: before } = prev;
103
+ if (
104
+ resolveSurfaceType(before.android?.surfaceType) !==
105
+ resolveSurfaceType(props.android?.surfaceType)
106
+ ) {
107
+ warnIgnored("android.surfaceType");
108
+ }
109
+ // Only a SurfaceView has a z-order of its own, which Android 11 and
110
+ // later changes in place.
111
+ if (
112
+ !!before.android?.zOrderOnTop !== !!props.android?.zOrderOnTop &&
113
+ resolveKind(mount.current) === "SurfaceView" &&
114
+ Number(Platform.Version) < 30
115
+ ) {
116
+ warnIgnored("android.zOrderOnTop");
117
+ }
118
+ }
119
+ prev.current = props;
120
+ });
121
+ };
122
+
90
123
  // A view measured relative to itself gets its layout size, without the
91
124
  // transforms getBoundingClientRect() includes; measureLayout() calls back
92
125
  // synchronously on the new architecture. On the web react-native-web measures
@@ -113,6 +146,7 @@ export const Canvas = ({
113
146
  }: CanvasProps) => {
114
147
  const viewRef = useRef<View>(null);
115
148
  const [contextId, _] = useState(() => generateContextId());
149
+ useBackingViewWarning({ opaque, android });
116
150
  // Retire the native registry entry for this contextId on unmount. When a
117
151
  // native surface is still attached, this is a no-op and the native view's
118
152
  // own teardown retires the entry instead — which keeps StrictMode's
@@ -10,6 +10,10 @@ interface WebGPUWorkletHelpers {
10
10
  // WebGPU prototype are rejected, and no JS property is ever read.
11
11
  isNativeObject: (value: unknown) => boolean;
12
12
  box: (value: object) => BoxedWebGPUObject;
13
+ // Installs the constructor of every WebGPU class on the calling runtime,
14
+ // skipping the ones already there. installWebGPU() calls it so `instanceof`
15
+ // works on worklet runtimes.
16
+ installConstructors: () => void;
13
17
  }
14
18
 
15
19
  interface BoxedWebGPUObject {
package/src/index.tsx CHANGED
@@ -9,6 +9,10 @@
9
9
  import "./main/installNative";
10
10
 
11
11
  import type {
12
+ GPUNativeBufferExternalTexture,
13
+ GPUNativeBufferExternalTextureDescriptor,
14
+ GPUNativeBufferTexture,
15
+ GPUNativeBufferTextureDescriptor,
12
16
  GPUDrawElementImageDestination,
13
17
  GPUDrawElementImageSource,
14
18
  GPUSharedFence,
@@ -44,6 +48,13 @@ export type {
44
48
  GPUCopyExternalNativeFrameSourceInfo,
45
49
  GPUDawnTogglesDescriptor,
46
50
  GPUNativeExternalTextureDescriptor,
51
+ NativeVideoFrameColorSpace,
52
+ GPUExtent2D,
53
+ GPUNativeBufferExternalTextureDescriptor,
54
+ GPUNativeBufferTextureDescriptor,
55
+ GPUNativeBufferWrapper,
56
+ GPUNativeBufferTexture,
57
+ GPUNativeBufferExternalTexture,
47
58
  GPUDrawElementImageDestination,
48
59
  GPUDrawElementImageSource,
49
60
  GPUDrawElementImageSourceView,
@@ -120,6 +131,19 @@ declare global {
120
131
  descriptor: GPUSharedTextureMemoryDescriptor,
121
132
  ): GPUSharedTextureMemory;
122
133
  importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;
134
+ // Non-spec RN extensions, the counterparts of createTexture /
135
+ // createExternalTexture in GPUAndroidHardwareBufferUtil of Dawn's Android
136
+ // layer: import a native buffer once, as a regular texture or as an
137
+ // external texture, and bracket each use with beginAccess() / endAccess()
138
+ // on the wrapper instead of importing the buffer again per frame.
139
+ createNativeBufferTexture(
140
+ source: NativeVideoFrame,
141
+ descriptor?: GPUNativeBufferTextureDescriptor,
142
+ ): GPUNativeBufferTexture;
143
+ createNativeBufferExternalTexture(
144
+ source: NativeVideoFrame,
145
+ descriptor?: GPUNativeBufferExternalTextureDescriptor,
146
+ ): GPUNativeBufferExternalTexture;
123
147
  }
124
148
 
125
149
  // Non-spec RN extension modeled on the html-in-canvas proposal's
package/src/install.ts CHANGED
@@ -29,14 +29,25 @@ const constants = {
29
29
  const gpu: GPU | undefined =
30
30
  typeof RNWebGPU === "undefined" ? undefined : RNWebGPU.gpu;
31
31
 
32
+ // The native half of the worklet serializer (see registerWebGPUForReanimated),
33
+ // read from the main runtime like `gpu` above and captured into the worklet
34
+ // closure: worklets hands a HostObject to every runtime by reference, so it is
35
+ // callable on the target runtime without installing anything there. Its
36
+ // installConstructors() installs the WebGPU class constructors on the runtime
37
+ // that calls it. Undefined on web and node, where the native module is not
38
+ // installed.
39
+ const helpers = globalThis.__webgpuWorkletHelpers;
40
+
32
41
  /**
33
42
  * Install WebGPU on the runtime that calls it.
34
43
  *
35
44
  * The native module sets up WebGPU on the main JS runtime, but worklet
36
45
  * runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
37
- * processors) start without it: `navigator.gpu` and the flag constants
46
+ * processors) start without it: `navigator.gpu`, the flag constants
38
47
  * (`GPUBufferUsage`, `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`,
39
- * `GPUMapMode`) are all `undefined` there.
48
+ * `GPUMapMode`) and the class constructors (`GPUBuffer`, `GPUTexture`,
49
+ * `GPURenderBundleEncoder`, ...) are all `undefined` there. Without the
50
+ * constructors, `instanceof` against a WebGPU class throws a ReferenceError.
40
51
  *
41
52
  * Call `installWebGPU()` once at the top of a worklet to make them available:
42
53
  *
@@ -65,12 +76,13 @@ const gpu: GPU | undefined =
65
76
  * Observe those on a device created on the main JS thread.
66
77
  *
67
78
  * Everything is captured into the worklet by closure: the constants like a
68
- * shader string would be, and the GPU object through the Worklets custom
79
+ * shader string would be, the GPU object through the Worklets custom
69
80
  * serializer, which installs the native prototypes on the target runtime when
70
- * it crosses. Promises returned by `requestAdapter`/`requestDevice` settle on
71
- * the calling runtime (each runtime gets its own async pump). Calling it on a
72
- * runtime that already has the globals (e.g. the main JS runtime) is a safe
73
- * no-op.
81
+ * it crosses, and the native helper that installs the class constructors,
82
+ * which worklets hands to every runtime by reference. Promises returned by
83
+ * `requestAdapter`/`requestDevice` settle on the calling runtime (each
84
+ * runtime gets its own async pump). Calling it on a runtime that already has
85
+ * the globals (e.g. the main JS runtime) is a safe no-op.
74
86
  */
75
87
  export const installWebGPU = () => {
76
88
  "worklet";
@@ -88,4 +100,11 @@ export const installWebGPU = () => {
88
100
  nav.gpu = gpu;
89
101
  }
90
102
  }
103
+ // The class constructors, so `instanceof` works against any WebGPU class on
104
+ // this runtime (three.js checks `pass instanceof GPURenderBundleEncoder` on
105
+ // every render, for instance). Unboxing an object installs only its own
106
+ // class; this installs the rest and skips the ones already there.
107
+ if (helpers !== undefined) {
108
+ helpers.installConstructors();
109
+ }
91
110
  };
package/src/types.ts CHANGED
@@ -21,7 +21,7 @@ export type RNCanvasContext = GPUCanvasContext & {
21
21
  *
22
22
  * Call this after `queue.submit()` on every runtime: the main JS runtime, the
23
23
  * Reanimated UI runtime, and dedicated worklet runtimes (e.g.
24
- * `createWorkletRuntime` / `runOnRuntime`, or a Vision Camera frame
24
+ * `createWorkletRuntime` / `scheduleOnRuntime`, or a Vision Camera frame
25
25
  * processor). It runs synchronously on the calling thread, so the frame is
26
26
  * presented from whichever thread did the rendering.
27
27
  */
@@ -52,6 +52,13 @@ export type NativeVideoPixelFormat = "bgra8" | "nv12";
52
52
  // - pixelFormat describes the surface layout: 'bgra8' for a sampled
53
53
  // GPUTexture; 'nv12' (biplanar Y + CbCr) for the importExternalTexture
54
54
  // path.
55
+ // - acquireFenceFd is the sync fd the producer of the frame (the decoder,
56
+ // the camera) signals once it has written the buffer, as a BigInt, on
57
+ // Android; null when the frame has none (Apple platforms, a released
58
+ // frame). importExternalTexture() waits for it on its own; a hardware
59
+ // buffer wrapper takes it through importSharedFence({ type: "sync-fd",
60
+ // handle }) in beginAccess(). The frame owns the descriptor: import it
61
+ // before release(), and never close it.
55
62
  // - release() drops the underlying backing object (a CVPixelBuffer on Apple).
56
63
  // The frame is also released when the JS wrapper is garbage-collected; call
57
64
  // release() eagerly when you know you're done.
@@ -60,9 +67,31 @@ export interface NativeVideoFrame {
60
67
  readonly width: number;
61
68
  readonly height: number;
62
69
  readonly pixelFormat: NativeVideoPixelFormat;
70
+ readonly acquireFenceFd: bigint | null;
63
71
  release(): void;
64
72
  }
65
73
 
74
+ // The color space of a YUV frame, the way its producer reports it: the YCbCr
75
+ // matrix and range that encode the samples, and the primaries and transfer
76
+ // function of the RGB they encode. Each member is optional; what is left out
77
+ // comes from the frame, then from the platform's best guess for the buffer.
78
+ export interface NativeVideoFrameColorSpace {
79
+ matrix?: "identity" | "rec601" | "rec709" | "rec2020";
80
+ range?: "identity" | "narrow" | "full";
81
+ primaries?: "srgb" | "rec709" | "rec601" | "rec2020" | "display-p3";
82
+ transfer?:
83
+ | "identity"
84
+ | "srgb"
85
+ | "display-p3"
86
+ | "smpte-170m"
87
+ | "hlg"
88
+ | "pq"
89
+ | "bt-1886";
90
+ }
91
+
92
+ // A 2D size, as { width, height } or [width, height].
93
+ export type GPUExtent2D = { width: number; height: number } | [number, number];
94
+
66
95
  // GPUExternalTextureDescriptor with a NativeVideoFrame as the source: what
67
96
  // GPUDevice.importExternalTexture() takes on React Native, where there is no
68
97
  // HTMLVideoElement or WebCodecs VideoFrame. The other members (label,
@@ -72,6 +101,74 @@ export interface GPUNativeExternalTextureDescriptor extends Omit<
72
101
  "source"
73
102
  > {
74
103
  source: NativeVideoFrame;
104
+ // Overrides the members of the frame's own color space, for a buffer that
105
+ // carries none (one wrapped from another library) or reports it wrong.
106
+ sourceColorSpace?: NativeVideoFrameColorSpace;
107
+ // The part of the frame the external texture shows, the whole frame by
108
+ // default (Dawn's cropOrigin / cropSize).
109
+ cropOrigin?: GPUOrigin2D;
110
+ cropSize?: GPUExtent2D;
111
+ }
112
+
113
+ // The descriptor of GPUDevice.createNativeBufferExternalTexture(): the same
114
+ // options as importExternalTexture(), without the source (the frame is the
115
+ // first argument).
116
+ export type GPUNativeBufferExternalTextureDescriptor = Omit<
117
+ GPUNativeExternalTextureDescriptor,
118
+ "source"
119
+ >;
120
+
121
+ // The options of GPUDevice.createNativeBufferTexture(). `usage` defaults to
122
+ // every usage the buffer allows, as GPUSharedTextureMemory.createTexture()
123
+ // without a descriptor.
124
+ export interface GPUNativeBufferTextureDescriptor {
125
+ usage?: GPUTextureUsageFlags;
126
+ label?: string;
127
+ }
128
+
129
+ // A native buffer imported once, with the access window of each use explicit:
130
+ // the counterpart of GPUHardwareBufferWrapper in Dawn's Android layer
131
+ // (androidx.webgpu). A decoder or a camera renders into the same few buffers
132
+ // in turn; keep one wrapper per buffer (keyed by NativeVideoFrame.handle), and
133
+ // bracket each frame with beginAccess() / endAccess() instead of importing it
134
+ // again. The wrapper keeps the frame it was created from alive until
135
+ // destroy().
136
+ export interface GPUNativeBufferWrapper {
137
+ label: string;
138
+ // Begins an access to the buffer: the GPU waits for each fence to reach its
139
+ // signaledValue first (the producer's fence for the frame, e.g. the frame's
140
+ // acquireFenceFd imported with importSharedFence, 1n for a sync fd). Throws,
141
+ // after a validation error, on a destroyed wrapper or fence, and if Dawn
142
+ // rejects the access (one is already open).
143
+ beginAccess(fences?: GPUSharedFenceState[]): void;
144
+ // Ends the access, after the queue.submit() that used the buffer, and
145
+ // returns the one fence that signals once that GPU work is done (on Android,
146
+ // the sync fds of the access merged into one), or null when there is none.
147
+ // Hand it to the producer before it reuses the buffer, or destroy it.
148
+ endAccess(): GPUSharedFenceState | null;
149
+ // Releases the import (and the frame) now rather than when the object is
150
+ // garbage collected. An access still open is a validation error; it is
151
+ // ended, and its fence is lost. A later use is a validation error and a
152
+ // throw.
153
+ destroy(): void;
154
+ }
155
+
156
+ // A color buffer (an RGBA / R8 / ... AHardwareBuffer, a BGRA IOSurface)
157
+ // imported once as a regular texture. Bind `texture` only between
158
+ // beginAccess() and endAccess().
159
+ export interface GPUNativeBufferTexture extends GPUNativeBufferWrapper {
160
+ readonly __brand: "GPUNativeBufferTexture";
161
+ readonly texture: GPUTexture;
162
+ }
163
+
164
+ // A frame buffer (the YUV AHardwareBuffer of a decoder or a camera, an NV12 or
165
+ // BGRA IOSurface) imported once as an external texture, color conversion
166
+ // included. Bind `externalTexture` only between beginAccess() and endAccess();
167
+ // destroying it on its own (externalTexture.destroy()) only releases the
168
+ // external texture, the wrapper keeps the import.
169
+ export interface GPUNativeBufferExternalTexture extends GPUNativeBufferWrapper {
170
+ readonly __brand: "GPUNativeBufferExternalTexture";
171
+ readonly externalTexture: GPUExternalTexture;
75
172
  }
76
173
 
77
174
  // A decoded video, modeled on HTMLMediaElement: play(), pause(), paused,