@shopify/react-native-skia 2.6.6 → 2.6.7
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/CMakeLists.txt +1 -2
- package/apple/RNSkiaModule.mm +8 -2
- package/apple/SkiaManager.mm +10 -5
- package/cpp/api/JsiSkApi.h +6 -6
- package/cpp/api/JsiSkMaskFilter.h +1 -0
- package/cpp/jsi2/NativeObject.h +39 -0
- package/cpp/rnskia/RNSkManager.cpp +27 -11
- package/cpp/rnwgpu/SurfaceRegistry.h +33 -1
- package/cpp/rnwgpu/api/GPU.cpp +15 -12
- package/cpp/rnwgpu/api/GPU.h +6 -3
- package/cpp/rnwgpu/api/GPUAdapter.cpp +2 -2
- package/cpp/rnwgpu/api/GPUAdapter.h +3 -3
- 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 +48 -13
- package/cpp/rnwgpu/api/GPUDevice.h +12 -3
- package/cpp/rnwgpu/api/GPUQueue.h +3 -3
- package/cpp/rnwgpu/api/GPUShaderModule.h +3 -3
- package/cpp/rnwgpu/api/WebGPUConstants.h +36 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +55 -22
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +8 -5
- package/cpp/rnwgpu/async/RuntimeContext.cpp +194 -0
- package/cpp/rnwgpu/async/RuntimeContext.h +121 -0
- package/lib/commonjs/skia/types/WebGPU.d.ts +31 -0
- package/lib/commonjs/skia/types/WebGPU.js +99 -0
- package/lib/commonjs/skia/types/WebGPU.js.map +1 -1
- package/lib/module/skia/types/WebGPU.d.ts +31 -0
- package/lib/module/skia/types/WebGPU.js +98 -1
- package/lib/module/skia/types/WebGPU.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +1 -0
- package/lib/typescript/lib/module/mock/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +31 -1
- package/lib/typescript/src/skia/types/WebGPU.d.ts +31 -0
- package/package.json +1 -1
- package/src/skia/types/WebGPU.ts +40 -0
- package/cpp/rnwgpu/async/AsyncDispatcher.h +0 -28
- package/cpp/rnwgpu/async/AsyncRunner.cpp +0 -182
- package/cpp/rnwgpu/async/AsyncRunner.h +0 -57
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +0 -23
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +0 -22
|
@@ -3,4 +3,103 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.installWebGPU = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
|
|
9
|
+
* `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
|
|
10
|
+
* that calls this.
|
|
11
|
+
*
|
|
12
|
+
* The native module installs these globals on the main JS runtime, but worklet
|
|
13
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
14
|
+
* processors) start without them, so referencing the bare global inside a
|
|
15
|
+
* worklet yields `undefined`. Call `installWebGPU()` once at the top of a
|
|
16
|
+
* worklet to install them there:
|
|
17
|
+
*
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { installWebGPU } from "@shopify/react-native-skia";
|
|
20
|
+
*
|
|
21
|
+
* const work = (device: GPUDevice) => {
|
|
22
|
+
* "worklet";
|
|
23
|
+
* installWebGPU();
|
|
24
|
+
* device.createBuffer({
|
|
25
|
+
* usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
|
|
26
|
+
* });
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* `installWebGPU` is a native host function. When captured into a worklet, the
|
|
31
|
+
* Worklets serializer re-creates it on the worklet runtime, so calling it there
|
|
32
|
+
* installs the constants on that runtime. The values come from the native
|
|
33
|
+
* `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
|
|
34
|
+
* Calling it on a runtime that already has the constants is a safe no-op, and on
|
|
35
|
+
* web (where the constants are always global) it is a no-op too.
|
|
36
|
+
*/
|
|
37
|
+
const installWebGPU = exports.installWebGPU = (() => {
|
|
38
|
+
const g = typeof global !== "undefined" ? global : undefined;
|
|
39
|
+
return g && typeof g.installWebGPU === "function" ? g.installWebGPU : () => {};
|
|
40
|
+
})();
|
|
41
|
+
|
|
42
|
+
// Skia's Graphite/Dawn backend extends the standard WebGPU API (typed by
|
|
43
|
+
// @webgpu/types) with a few Skia- and Dawn-specific entry points. These are
|
|
44
|
+
// only available on native (SK_GRAPHITE) builds, reachable through
|
|
45
|
+
// `Skia.getDevice()`.
|
|
46
|
+
//
|
|
47
|
+
// The exported interfaces below describe the descriptors and objects those
|
|
48
|
+
// entry points use; the `declare global` block augments the standard WebGPU
|
|
49
|
+
// interfaces so the new methods are typed without casting to `any`.
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Descriptor for {@link GPUDevice.importExternalTexture} when the source is a
|
|
53
|
+
* Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).
|
|
54
|
+
*
|
|
55
|
+
* `source` is the handle returned by `Skia.NativeBuffer.MakeFromImage`: a
|
|
56
|
+
* `CVPixelBufferRef` on Apple, an `AHardwareBuffer*` on Android. The caller
|
|
57
|
+
* owns its lifetime (release it with `Skia.NativeBuffer.Release`) and must keep
|
|
58
|
+
* it alive until the imported texture is destroyed.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Descriptor for {@link GPUDevice.importSharedTextureMemory}. `handle` is the
|
|
63
|
+
* NativeBuffer returned by `Skia.NativeBuffer.MakeFromImage` (see
|
|
64
|
+
* {@link SkiaGPUExternalTextureDescriptor} for the platform-specific types and
|
|
65
|
+
* lifetime rules).
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The kind of native synchronization primitive a {@link GPUSharedFence} wraps,
|
|
70
|
+
* matching the `shared-fence-*` device feature names. Limited to the kinds
|
|
71
|
+
* react-native-skia targets (iOS/Metal and Android/Vulkan); `importSharedFence`
|
|
72
|
+
* accepts these and `export()` reports them.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Descriptor for {@link GPUDevice.importSharedFence}.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A native GPU synchronization primitive shared across queues/APIs. Produced by
|
|
81
|
+
* {@link GPUSharedTextureMemory.endAccess}, consumed by
|
|
82
|
+
* {@link GPUSharedTextureMemory.beginAccess}, or imported from a consumer's
|
|
83
|
+
* fence with {@link GPUDevice.importSharedFence}.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/** A fence and the timeline value to wait for (0n for binary sync-fd fences). */
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The result of {@link GPUSharedTextureMemory.endAccess}: each fence is signaled
|
|
90
|
+
* at its `signaledValue` once Dawn's GPU work for the access completes.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Shared texture memory imported from a platform native buffer via
|
|
95
|
+
* {@link GPUDevice.importSharedTextureMemory}. Create a texture that aliases
|
|
96
|
+
* the memory, then bracket the GPU work that touches it with
|
|
97
|
+
* {@link GPUSharedTextureMemory.beginAccess} / {@link GPUSharedTextureMemory.endAccess}.
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Dawn-specific toggles, passed via {@link GPUDeviceDescriptor.dawnToggles} to
|
|
102
|
+
* `adapter.requestDevice`. This is a non-spec, Dawn-only extension; see Dawn's
|
|
103
|
+
* toggle list for valid names.
|
|
104
|
+
*/
|
|
6
105
|
//# sourceMappingURL=WebGPU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["WebGPU.ts"],"sourcesContent":["import type { NativeBuffer } from \"./NativeBuffer\";\n\n// Skia's Graphite/Dawn backend extends the standard WebGPU API (typed by\n// @webgpu/types) with a few Skia- and Dawn-specific entry points. These are\n// only available on native (SK_GRAPHITE) builds, reachable through\n// `Skia.getDevice()`.\n//\n// The exported interfaces below describe the descriptors and objects those\n// entry points use; the `declare global` block augments the standard WebGPU\n// interfaces so the new methods are typed without casting to `any`.\n\n/**\n * Descriptor for {@link GPUDevice.importExternalTexture} when the source is a\n * Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).\n *\n * `source` is the handle returned by `Skia.NativeBuffer.MakeFromImage`: a\n * `CVPixelBufferRef` on Apple, an `AHardwareBuffer*` on Android. The caller\n * owns its lifetime (release it with `Skia.NativeBuffer.Release`) and must keep\n * it alive until the imported texture is destroyed.\n */\nexport interface SkiaGPUExternalTextureDescriptor extends GPUObjectDescriptorBase {\n source: NativeBuffer;\n /** Rotation applied while sampling, in degrees. One of 0 | 90 | 180 | 270. */\n rotation?: number;\n /** Mirror horizontally while sampling. */\n mirrored?: boolean;\n}\n\n/**\n * Descriptor for {@link GPUDevice.importSharedTextureMemory}. `handle` is the\n * NativeBuffer returned by `Skia.NativeBuffer.MakeFromImage` (see\n * {@link SkiaGPUExternalTextureDescriptor} for the platform-specific types and\n * lifetime rules).\n */\nexport interface GPUSharedTextureMemoryDescriptor extends GPUObjectDescriptorBase {\n handle: NativeBuffer;\n}\n\n/**\n * The kind of native synchronization primitive a {@link GPUSharedFence} wraps,\n * matching the `shared-fence-*` device feature names. Limited to the kinds\n * react-native-skia targets (iOS/Metal and Android/Vulkan); `importSharedFence`\n * accepts these and `export()` reports them.\n */\nexport type GPUSharedFenceType =\n | \"mtl-shared-event\"\n | \"sync-fd\"\n | \"vk-semaphore-opaque-fd\";\n\n/**\n * Descriptor for {@link GPUDevice.importSharedFence}.\n */\nexport interface GPUSharedFenceDescriptor {\n /**\n * The fence kind to import. Must match a `shared-fence-*` feature enabled on\n * the device.\n */\n type: GPUSharedFenceType;\n /**\n * The raw native handle as a BigInt: an `id<MTLSharedEvent>` pointer for\n * `\"mtl-shared-event\"`, or an OS file descriptor for the `*-fd` kinds.\n */\n handle: bigint;\n label?: string;\n}\n\nexport interface GPUSharedFenceExportInfo {\n type: GPUSharedFenceType;\n /**\n * An `id<MTLSharedEvent>` pointer (Apple) or file descriptor (Android), as a\n * BigInt. The caller takes ownership; e.g. an exported sync-fd must be closed\n * once consumed.\n */\n handle: bigint;\n}\n\n/**\n * A native GPU synchronization primitive shared across queues/APIs. Produced by\n * {@link GPUSharedTextureMemory.endAccess}, consumed by\n * {@link GPUSharedTextureMemory.beginAccess}, or imported from a consumer's\n * fence with {@link GPUDevice.importSharedFence}.\n */\nexport interface GPUSharedFence {\n readonly __brand: \"GPUSharedFence\";\n label: string;\n export(): GPUSharedFenceExportInfo;\n}\n\n/** A fence and the timeline value to wait for (0n for binary sync-fd fences). */\nexport interface GPUSharedFenceState {\n fence: GPUSharedFence;\n signaledValue: bigint;\n}\n\n/**\n * The result of {@link GPUSharedTextureMemory.endAccess}: each fence is signaled\n * at its `signaledValue` once Dawn's GPU work for the access completes.\n */\nexport interface GPUSharedTextureMemoryEndAccessState {\n initialized: boolean;\n fences: GPUSharedFenceState[];\n}\n\n/**\n * Shared texture memory imported from a platform native buffer via\n * {@link GPUDevice.importSharedTextureMemory}. Create a texture that aliases\n * the memory, then bracket the GPU work that touches it with\n * {@link GPUSharedTextureMemory.beginAccess} / {@link GPUSharedTextureMemory.endAccess}.\n */\nexport interface GPUSharedTextureMemory extends GPUObjectBase {\n /** Create a texture that aliases the shared memory. */\n createTexture(descriptor?: GPUTextureDescriptor): GPUTexture;\n /**\n * Acquire the memory for GPU access. `initialized` marks whether the existing\n * contents should be preserved (pass `true` for an already-rendered frame).\n * Optional `fences` are wait fences: Dawn waits for each to reach its\n * `signaledValue` before writing the surface. Throws if the access could not\n * be acquired.\n */\n beginAccess(\n texture: GPUTexture,\n initialized: boolean,\n fences?: GPUSharedFenceState[]\n ): void;\n /**\n * Release the memory after the GPU work that accessed it has been submitted,\n * and return the fences Dawn produced for the access. Throws on failure.\n */\n endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;\n}\n\n/**\n * Dawn-specific toggles, passed via {@link GPUDeviceDescriptor.dawnToggles} to\n * `adapter.requestDevice`. This is a non-spec, Dawn-only extension; see Dawn's\n * toggle list for valid names.\n */\nexport interface GPUDawnTogglesDescriptor {\n enabledToggles?: string[];\n disabledToggles?: string[];\n}\n\ndeclare global {\n interface GPUDeviceDescriptor {\n /** Dawn-specific toggles (Skia/Graphite extension, non-spec). */\n dawnToggles?: GPUDawnTogglesDescriptor;\n }\n\n interface GPUExternalTexture {\n /**\n * Skia extension: end the imported buffer's shared-memory access window and\n * release the underlying resources. Call right after the `queue.submit()`\n * that sampled this texture (never before). Idempotent, and also runs at\n * garbage collection as a fallback.\n */\n destroy(): void;\n }\n\n interface GPUDevice {\n /**\n * Skia extension: import a NativeBuffer (from\n * `Skia.NativeBuffer.MakeFromImage`) as a {@link GPUExternalTexture}, sampled\n * with `texture_external` in WGSL. The returned texture owns the\n * shared-memory access window; call `destroy()` on it after the sampling\n * `queue.submit()`.\n */\n importExternalTexture(\n descriptor: SkiaGPUExternalTextureDescriptor\n ): GPUExternalTexture;\n /**\n * Skia extension: import a NativeBuffer (from\n * `Skia.NativeBuffer.MakeFromImage`) as {@link GPUSharedTextureMemory}, the\n * lower-level path that lets you create an aliasing texture and manage the\n * begin/end access window yourself.\n */\n importSharedTextureMemory(\n descriptor: GPUSharedTextureMemoryDescriptor\n ): GPUSharedTextureMemory;\n /**\n * Skia extension: import a native synchronization primitive (an\n * `id<MTLSharedEvent>` on Apple, a sync-fd / VkSemaphore on Android) as a\n * {@link GPUSharedFence}, e.g. to wait on a fence a consumer produced. The\n * matching `shared-fence-*` feature must be enabled on the device.\n */\n importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;\n }\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["installWebGPU","exports","g","global","undefined"],"sources":["WebGPU.ts"],"sourcesContent":["import type { NativeBuffer } from \"./NativeBuffer\";\n\n/**\n * Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,\n * `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime\n * that calls this.\n *\n * The native module installs these globals on the main JS runtime, but worklet\n * runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame\n * processors) start without them, so referencing the bare global inside a\n * worklet yields `undefined`. Call `installWebGPU()` once at the top of a\n * worklet to install them there:\n *\n * ```tsx\n * import { installWebGPU } from \"@shopify/react-native-skia\";\n *\n * const work = (device: GPUDevice) => {\n * \"worklet\";\n * installWebGPU();\n * device.createBuffer({\n * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,\n * });\n * };\n * ```\n *\n * `installWebGPU` is a native host function. When captured into a worklet, the\n * Worklets serializer re-creates it on the worklet runtime, so calling it there\n * installs the constants on that runtime. The values come from the native\n * `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.\n * Calling it on a runtime that already has the constants is a safe no-op, and on\n * web (where the constants are always global) it is a no-op too.\n */\nexport const installWebGPU: () => void = (() => {\n const g =\n typeof global !== \"undefined\"\n ? (global as unknown as { installWebGPU?: () => void })\n : undefined;\n return g && typeof g.installWebGPU === \"function\"\n ? g.installWebGPU\n : () => {};\n})();\n\n// Skia's Graphite/Dawn backend extends the standard WebGPU API (typed by\n// @webgpu/types) with a few Skia- and Dawn-specific entry points. These are\n// only available on native (SK_GRAPHITE) builds, reachable through\n// `Skia.getDevice()`.\n//\n// The exported interfaces below describe the descriptors and objects those\n// entry points use; the `declare global` block augments the standard WebGPU\n// interfaces so the new methods are typed without casting to `any`.\n\n/**\n * Descriptor for {@link GPUDevice.importExternalTexture} when the source is a\n * Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).\n *\n * `source` is the handle returned by `Skia.NativeBuffer.MakeFromImage`: a\n * `CVPixelBufferRef` on Apple, an `AHardwareBuffer*` on Android. The caller\n * owns its lifetime (release it with `Skia.NativeBuffer.Release`) and must keep\n * it alive until the imported texture is destroyed.\n */\nexport interface SkiaGPUExternalTextureDescriptor extends GPUObjectDescriptorBase {\n source: NativeBuffer;\n /** Rotation applied while sampling, in degrees. One of 0 | 90 | 180 | 270. */\n rotation?: number;\n /** Mirror horizontally while sampling. */\n mirrored?: boolean;\n}\n\n/**\n * Descriptor for {@link GPUDevice.importSharedTextureMemory}. `handle` is the\n * NativeBuffer returned by `Skia.NativeBuffer.MakeFromImage` (see\n * {@link SkiaGPUExternalTextureDescriptor} for the platform-specific types and\n * lifetime rules).\n */\nexport interface GPUSharedTextureMemoryDescriptor extends GPUObjectDescriptorBase {\n handle: NativeBuffer;\n}\n\n/**\n * The kind of native synchronization primitive a {@link GPUSharedFence} wraps,\n * matching the `shared-fence-*` device feature names. Limited to the kinds\n * react-native-skia targets (iOS/Metal and Android/Vulkan); `importSharedFence`\n * accepts these and `export()` reports them.\n */\nexport type GPUSharedFenceType =\n | \"mtl-shared-event\"\n | \"sync-fd\"\n | \"vk-semaphore-opaque-fd\";\n\n/**\n * Descriptor for {@link GPUDevice.importSharedFence}.\n */\nexport interface GPUSharedFenceDescriptor {\n /**\n * The fence kind to import. Must match a `shared-fence-*` feature enabled on\n * the device.\n */\n type: GPUSharedFenceType;\n /**\n * The raw native handle as a BigInt: an `id<MTLSharedEvent>` pointer for\n * `\"mtl-shared-event\"`, or an OS file descriptor for the `*-fd` kinds.\n */\n handle: bigint;\n label?: string;\n}\n\nexport interface GPUSharedFenceExportInfo {\n type: GPUSharedFenceType;\n /**\n * An `id<MTLSharedEvent>` pointer (Apple) or file descriptor (Android), as a\n * BigInt. The caller takes ownership; e.g. an exported sync-fd must be closed\n * once consumed.\n */\n handle: bigint;\n}\n\n/**\n * A native GPU synchronization primitive shared across queues/APIs. Produced by\n * {@link GPUSharedTextureMemory.endAccess}, consumed by\n * {@link GPUSharedTextureMemory.beginAccess}, or imported from a consumer's\n * fence with {@link GPUDevice.importSharedFence}.\n */\nexport interface GPUSharedFence {\n readonly __brand: \"GPUSharedFence\";\n label: string;\n export(): GPUSharedFenceExportInfo;\n}\n\n/** A fence and the timeline value to wait for (0n for binary sync-fd fences). */\nexport interface GPUSharedFenceState {\n fence: GPUSharedFence;\n signaledValue: bigint;\n}\n\n/**\n * The result of {@link GPUSharedTextureMemory.endAccess}: each fence is signaled\n * at its `signaledValue` once Dawn's GPU work for the access completes.\n */\nexport interface GPUSharedTextureMemoryEndAccessState {\n initialized: boolean;\n fences: GPUSharedFenceState[];\n}\n\n/**\n * Shared texture memory imported from a platform native buffer via\n * {@link GPUDevice.importSharedTextureMemory}. Create a texture that aliases\n * the memory, then bracket the GPU work that touches it with\n * {@link GPUSharedTextureMemory.beginAccess} / {@link GPUSharedTextureMemory.endAccess}.\n */\nexport interface GPUSharedTextureMemory extends GPUObjectBase {\n /** Create a texture that aliases the shared memory. */\n createTexture(descriptor?: GPUTextureDescriptor): GPUTexture;\n /**\n * Acquire the memory for GPU access. `initialized` marks whether the existing\n * contents should be preserved (pass `true` for an already-rendered frame).\n * Optional `fences` are wait fences: Dawn waits for each to reach its\n * `signaledValue` before writing the surface. Throws if the access could not\n * be acquired.\n */\n beginAccess(\n texture: GPUTexture,\n initialized: boolean,\n fences?: GPUSharedFenceState[]\n ): void;\n /**\n * Release the memory after the GPU work that accessed it has been submitted,\n * and return the fences Dawn produced for the access. Throws on failure.\n */\n endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;\n}\n\n/**\n * Dawn-specific toggles, passed via {@link GPUDeviceDescriptor.dawnToggles} to\n * `adapter.requestDevice`. This is a non-spec, Dawn-only extension; see Dawn's\n * toggle list for valid names.\n */\nexport interface GPUDawnTogglesDescriptor {\n enabledToggles?: string[];\n disabledToggles?: string[];\n}\n\ndeclare global {\n interface GPUDeviceDescriptor {\n /** Dawn-specific toggles (Skia/Graphite extension, non-spec). */\n dawnToggles?: GPUDawnTogglesDescriptor;\n }\n\n interface GPUExternalTexture {\n /**\n * Skia extension: end the imported buffer's shared-memory access window and\n * release the underlying resources. Call right after the `queue.submit()`\n * that sampled this texture (never before). Idempotent, and also runs at\n * garbage collection as a fallback.\n */\n destroy(): void;\n }\n\n interface GPUDevice {\n /**\n * Skia extension: import a NativeBuffer (from\n * `Skia.NativeBuffer.MakeFromImage`) as a {@link GPUExternalTexture}, sampled\n * with `texture_external` in WGSL. The returned texture owns the\n * shared-memory access window; call `destroy()` on it after the sampling\n * `queue.submit()`.\n */\n importExternalTexture(\n descriptor: SkiaGPUExternalTextureDescriptor\n ): GPUExternalTexture;\n /**\n * Skia extension: import a NativeBuffer (from\n * `Skia.NativeBuffer.MakeFromImage`) as {@link GPUSharedTextureMemory}, the\n * lower-level path that lets you create an aliasing texture and manage the\n * begin/end access window yourself.\n */\n importSharedTextureMemory(\n descriptor: GPUSharedTextureMemoryDescriptor\n ): GPUSharedTextureMemory;\n /**\n * Skia extension: import a native synchronization primitive (an\n * `id<MTLSharedEvent>` on Apple, a sync-fd / VkSemaphore on Android) as a\n * {@link GPUSharedFence}, e.g. to wait on a fence a consumer produced. The\n * matching `shared-fence-*` feature must be enabled on the device.\n */\n importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;\n }\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,aAAyB,GAAAC,OAAA,CAAAD,aAAA,GAAG,CAAC,MAAM;EAC9C,MAAME,CAAC,GACL,OAAOC,MAAM,KAAK,WAAW,GACxBA,MAAM,GACPC,SAAS;EACf,OAAOF,CAAC,IAAI,OAAOA,CAAC,CAACF,aAAa,KAAK,UAAU,GAC7CE,CAAC,CAACF,aAAa,GACf,MAAM,CAAC,CAAC;AACd,CAAC,EAAE,CAAC;;AAEJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;;AAyBA;AACA;AACA;AACA;AACA;AACA;;AAOA;;AAMA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;;AAuBA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
import type { NativeBuffer } from "./NativeBuffer";
|
|
2
|
+
/**
|
|
3
|
+
* Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
|
|
4
|
+
* `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
|
|
5
|
+
* that calls this.
|
|
6
|
+
*
|
|
7
|
+
* The native module installs these globals on the main JS runtime, but worklet
|
|
8
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
9
|
+
* processors) start without them, so referencing the bare global inside a
|
|
10
|
+
* worklet yields `undefined`. Call `installWebGPU()` once at the top of a
|
|
11
|
+
* worklet to install them there:
|
|
12
|
+
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { installWebGPU } from "@shopify/react-native-skia";
|
|
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
|
+
* `installWebGPU` is a native host function. When captured into a worklet, the
|
|
26
|
+
* Worklets serializer re-creates it on the worklet runtime, so calling it there
|
|
27
|
+
* installs the constants on that runtime. The values come from the native
|
|
28
|
+
* `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
|
|
29
|
+
* Calling it on a runtime that already has the constants is a safe no-op, and on
|
|
30
|
+
* web (where the constants are always global) it is a no-op too.
|
|
31
|
+
*/
|
|
32
|
+
export declare const installWebGPU: () => void;
|
|
2
33
|
/**
|
|
3
34
|
* Descriptor for {@link GPUDevice.importExternalTexture} when the source is a
|
|
4
35
|
* Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).
|
|
@@ -1,2 +1,99 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
|
|
3
|
+
* `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
|
|
4
|
+
* that calls this.
|
|
5
|
+
*
|
|
6
|
+
* The native module installs these globals on the main JS runtime, but worklet
|
|
7
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
8
|
+
* processors) start without them, so referencing the bare global inside a
|
|
9
|
+
* worklet yields `undefined`. Call `installWebGPU()` once at the top of a
|
|
10
|
+
* worklet to install them there:
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { installWebGPU } from "@shopify/react-native-skia";
|
|
14
|
+
*
|
|
15
|
+
* const work = (device: GPUDevice) => {
|
|
16
|
+
* "worklet";
|
|
17
|
+
* installWebGPU();
|
|
18
|
+
* device.createBuffer({
|
|
19
|
+
* usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
|
|
20
|
+
* });
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* `installWebGPU` is a native host function. When captured into a worklet, the
|
|
25
|
+
* Worklets serializer re-creates it on the worklet runtime, so calling it there
|
|
26
|
+
* installs the constants on that runtime. The values come from the native
|
|
27
|
+
* `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
|
|
28
|
+
* Calling it on a runtime that already has the constants is a safe no-op, and on
|
|
29
|
+
* web (where the constants are always global) it is a no-op too.
|
|
30
|
+
*/
|
|
31
|
+
export const installWebGPU = (() => {
|
|
32
|
+
const g = typeof global !== "undefined" ? global : undefined;
|
|
33
|
+
return g && typeof g.installWebGPU === "function" ? g.installWebGPU : () => {};
|
|
34
|
+
})();
|
|
35
|
+
|
|
36
|
+
// Skia's Graphite/Dawn backend extends the standard WebGPU API (typed by
|
|
37
|
+
// @webgpu/types) with a few Skia- and Dawn-specific entry points. These are
|
|
38
|
+
// only available on native (SK_GRAPHITE) builds, reachable through
|
|
39
|
+
// `Skia.getDevice()`.
|
|
40
|
+
//
|
|
41
|
+
// The exported interfaces below describe the descriptors and objects those
|
|
42
|
+
// entry points use; the `declare global` block augments the standard WebGPU
|
|
43
|
+
// interfaces so the new methods are typed without casting to `any`.
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Descriptor for {@link GPUDevice.importExternalTexture} when the source is a
|
|
47
|
+
* Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).
|
|
48
|
+
*
|
|
49
|
+
* `source` is the handle returned by `Skia.NativeBuffer.MakeFromImage`: a
|
|
50
|
+
* `CVPixelBufferRef` on Apple, an `AHardwareBuffer*` on Android. The caller
|
|
51
|
+
* owns its lifetime (release it with `Skia.NativeBuffer.Release`) and must keep
|
|
52
|
+
* it alive until the imported texture is destroyed.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Descriptor for {@link GPUDevice.importSharedTextureMemory}. `handle` is the
|
|
57
|
+
* NativeBuffer returned by `Skia.NativeBuffer.MakeFromImage` (see
|
|
58
|
+
* {@link SkiaGPUExternalTextureDescriptor} for the platform-specific types and
|
|
59
|
+
* lifetime rules).
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The kind of native synchronization primitive a {@link GPUSharedFence} wraps,
|
|
64
|
+
* matching the `shared-fence-*` device feature names. Limited to the kinds
|
|
65
|
+
* react-native-skia targets (iOS/Metal and Android/Vulkan); `importSharedFence`
|
|
66
|
+
* accepts these and `export()` reports them.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Descriptor for {@link GPUDevice.importSharedFence}.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A native GPU synchronization primitive shared across queues/APIs. Produced by
|
|
75
|
+
* {@link GPUSharedTextureMemory.endAccess}, consumed by
|
|
76
|
+
* {@link GPUSharedTextureMemory.beginAccess}, or imported from a consumer's
|
|
77
|
+
* fence with {@link GPUDevice.importSharedFence}.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/** A fence and the timeline value to wait for (0n for binary sync-fd fences). */
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The result of {@link GPUSharedTextureMemory.endAccess}: each fence is signaled
|
|
84
|
+
* at its `signaledValue` once Dawn's GPU work for the access completes.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Shared texture memory imported from a platform native buffer via
|
|
89
|
+
* {@link GPUDevice.importSharedTextureMemory}. Create a texture that aliases
|
|
90
|
+
* the memory, then bracket the GPU work that touches it with
|
|
91
|
+
* {@link GPUSharedTextureMemory.beginAccess} / {@link GPUSharedTextureMemory.endAccess}.
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Dawn-specific toggles, passed via {@link GPUDeviceDescriptor.dawnToggles} to
|
|
96
|
+
* `adapter.requestDevice`. This is a non-spec, Dawn-only extension; see Dawn's
|
|
97
|
+
* toggle list for valid names.
|
|
98
|
+
*/
|
|
2
99
|
//# sourceMappingURL=WebGPU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["WebGPU.ts"],"sourcesContent":["import type { NativeBuffer } from \"./NativeBuffer\";\n\n// Skia's Graphite/Dawn backend extends the standard WebGPU API (typed by\n// @webgpu/types) with a few Skia- and Dawn-specific entry points. These are\n// only available on native (SK_GRAPHITE) builds, reachable through\n// `Skia.getDevice()`.\n//\n// The exported interfaces below describe the descriptors and objects those\n// entry points use; the `declare global` block augments the standard WebGPU\n// interfaces so the new methods are typed without casting to `any`.\n\n/**\n * Descriptor for {@link GPUDevice.importExternalTexture} when the source is a\n * Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).\n *\n * `source` is the handle returned by `Skia.NativeBuffer.MakeFromImage`: a\n * `CVPixelBufferRef` on Apple, an `AHardwareBuffer*` on Android. The caller\n * owns its lifetime (release it with `Skia.NativeBuffer.Release`) and must keep\n * it alive until the imported texture is destroyed.\n */\nexport interface SkiaGPUExternalTextureDescriptor extends GPUObjectDescriptorBase {\n source: NativeBuffer;\n /** Rotation applied while sampling, in degrees. One of 0 | 90 | 180 | 270. */\n rotation?: number;\n /** Mirror horizontally while sampling. */\n mirrored?: boolean;\n}\n\n/**\n * Descriptor for {@link GPUDevice.importSharedTextureMemory}. `handle` is the\n * NativeBuffer returned by `Skia.NativeBuffer.MakeFromImage` (see\n * {@link SkiaGPUExternalTextureDescriptor} for the platform-specific types and\n * lifetime rules).\n */\nexport interface GPUSharedTextureMemoryDescriptor extends GPUObjectDescriptorBase {\n handle: NativeBuffer;\n}\n\n/**\n * The kind of native synchronization primitive a {@link GPUSharedFence} wraps,\n * matching the `shared-fence-*` device feature names. Limited to the kinds\n * react-native-skia targets (iOS/Metal and Android/Vulkan); `importSharedFence`\n * accepts these and `export()` reports them.\n */\nexport type GPUSharedFenceType =\n | \"mtl-shared-event\"\n | \"sync-fd\"\n | \"vk-semaphore-opaque-fd\";\n\n/**\n * Descriptor for {@link GPUDevice.importSharedFence}.\n */\nexport interface GPUSharedFenceDescriptor {\n /**\n * The fence kind to import. Must match a `shared-fence-*` feature enabled on\n * the device.\n */\n type: GPUSharedFenceType;\n /**\n * The raw native handle as a BigInt: an `id<MTLSharedEvent>` pointer for\n * `\"mtl-shared-event\"`, or an OS file descriptor for the `*-fd` kinds.\n */\n handle: bigint;\n label?: string;\n}\n\nexport interface GPUSharedFenceExportInfo {\n type: GPUSharedFenceType;\n /**\n * An `id<MTLSharedEvent>` pointer (Apple) or file descriptor (Android), as a\n * BigInt. The caller takes ownership; e.g. an exported sync-fd must be closed\n * once consumed.\n */\n handle: bigint;\n}\n\n/**\n * A native GPU synchronization primitive shared across queues/APIs. Produced by\n * {@link GPUSharedTextureMemory.endAccess}, consumed by\n * {@link GPUSharedTextureMemory.beginAccess}, or imported from a consumer's\n * fence with {@link GPUDevice.importSharedFence}.\n */\nexport interface GPUSharedFence {\n readonly __brand: \"GPUSharedFence\";\n label: string;\n export(): GPUSharedFenceExportInfo;\n}\n\n/** A fence and the timeline value to wait for (0n for binary sync-fd fences). */\nexport interface GPUSharedFenceState {\n fence: GPUSharedFence;\n signaledValue: bigint;\n}\n\n/**\n * The result of {@link GPUSharedTextureMemory.endAccess}: each fence is signaled\n * at its `signaledValue` once Dawn's GPU work for the access completes.\n */\nexport interface GPUSharedTextureMemoryEndAccessState {\n initialized: boolean;\n fences: GPUSharedFenceState[];\n}\n\n/**\n * Shared texture memory imported from a platform native buffer via\n * {@link GPUDevice.importSharedTextureMemory}. Create a texture that aliases\n * the memory, then bracket the GPU work that touches it with\n * {@link GPUSharedTextureMemory.beginAccess} / {@link GPUSharedTextureMemory.endAccess}.\n */\nexport interface GPUSharedTextureMemory extends GPUObjectBase {\n /** Create a texture that aliases the shared memory. */\n createTexture(descriptor?: GPUTextureDescriptor): GPUTexture;\n /**\n * Acquire the memory for GPU access. `initialized` marks whether the existing\n * contents should be preserved (pass `true` for an already-rendered frame).\n * Optional `fences` are wait fences: Dawn waits for each to reach its\n * `signaledValue` before writing the surface. Throws if the access could not\n * be acquired.\n */\n beginAccess(\n texture: GPUTexture,\n initialized: boolean,\n fences?: GPUSharedFenceState[]\n ): void;\n /**\n * Release the memory after the GPU work that accessed it has been submitted,\n * and return the fences Dawn produced for the access. Throws on failure.\n */\n endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;\n}\n\n/**\n * Dawn-specific toggles, passed via {@link GPUDeviceDescriptor.dawnToggles} to\n * `adapter.requestDevice`. This is a non-spec, Dawn-only extension; see Dawn's\n * toggle list for valid names.\n */\nexport interface GPUDawnTogglesDescriptor {\n enabledToggles?: string[];\n disabledToggles?: string[];\n}\n\ndeclare global {\n interface GPUDeviceDescriptor {\n /** Dawn-specific toggles (Skia/Graphite extension, non-spec). */\n dawnToggles?: GPUDawnTogglesDescriptor;\n }\n\n interface GPUExternalTexture {\n /**\n * Skia extension: end the imported buffer's shared-memory access window and\n * release the underlying resources. Call right after the `queue.submit()`\n * that sampled this texture (never before). Idempotent, and also runs at\n * garbage collection as a fallback.\n */\n destroy(): void;\n }\n\n interface GPUDevice {\n /**\n * Skia extension: import a NativeBuffer (from\n * `Skia.NativeBuffer.MakeFromImage`) as a {@link GPUExternalTexture}, sampled\n * with `texture_external` in WGSL. The returned texture owns the\n * shared-memory access window; call `destroy()` on it after the sampling\n * `queue.submit()`.\n */\n importExternalTexture(\n descriptor: SkiaGPUExternalTextureDescriptor\n ): GPUExternalTexture;\n /**\n * Skia extension: import a NativeBuffer (from\n * `Skia.NativeBuffer.MakeFromImage`) as {@link GPUSharedTextureMemory}, the\n * lower-level path that lets you create an aliasing texture and manage the\n * begin/end access window yourself.\n */\n importSharedTextureMemory(\n descriptor: GPUSharedTextureMemoryDescriptor\n ): GPUSharedTextureMemory;\n /**\n * Skia extension: import a native synchronization primitive (an\n * `id<MTLSharedEvent>` on Apple, a sync-fd / VkSemaphore on Android) as a\n * {@link GPUSharedFence}, e.g. to wait on a fence a consumer produced. The\n * matching `shared-fence-*` feature must be enabled on the device.\n */\n importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;\n }\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["installWebGPU","g","global","undefined"],"sources":["WebGPU.ts"],"sourcesContent":["import type { NativeBuffer } from \"./NativeBuffer\";\n\n/**\n * Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,\n * `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime\n * that calls this.\n *\n * The native module installs these globals on the main JS runtime, but worklet\n * runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame\n * processors) start without them, so referencing the bare global inside a\n * worklet yields `undefined`. Call `installWebGPU()` once at the top of a\n * worklet to install them there:\n *\n * ```tsx\n * import { installWebGPU } from \"@shopify/react-native-skia\";\n *\n * const work = (device: GPUDevice) => {\n * \"worklet\";\n * installWebGPU();\n * device.createBuffer({\n * usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,\n * });\n * };\n * ```\n *\n * `installWebGPU` is a native host function. When captured into a worklet, the\n * Worklets serializer re-creates it on the worklet runtime, so calling it there\n * installs the constants on that runtime. The values come from the native\n * `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.\n * Calling it on a runtime that already has the constants is a safe no-op, and on\n * web (where the constants are always global) it is a no-op too.\n */\nexport const installWebGPU: () => void = (() => {\n const g =\n typeof global !== \"undefined\"\n ? (global as unknown as { installWebGPU?: () => void })\n : undefined;\n return g && typeof g.installWebGPU === \"function\"\n ? g.installWebGPU\n : () => {};\n})();\n\n// Skia's Graphite/Dawn backend extends the standard WebGPU API (typed by\n// @webgpu/types) with a few Skia- and Dawn-specific entry points. These are\n// only available on native (SK_GRAPHITE) builds, reachable through\n// `Skia.getDevice()`.\n//\n// The exported interfaces below describe the descriptors and objects those\n// entry points use; the `declare global` block augments the standard WebGPU\n// interfaces so the new methods are typed without casting to `any`.\n\n/**\n * Descriptor for {@link GPUDevice.importExternalTexture} when the source is a\n * Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).\n *\n * `source` is the handle returned by `Skia.NativeBuffer.MakeFromImage`: a\n * `CVPixelBufferRef` on Apple, an `AHardwareBuffer*` on Android. The caller\n * owns its lifetime (release it with `Skia.NativeBuffer.Release`) and must keep\n * it alive until the imported texture is destroyed.\n */\nexport interface SkiaGPUExternalTextureDescriptor extends GPUObjectDescriptorBase {\n source: NativeBuffer;\n /** Rotation applied while sampling, in degrees. One of 0 | 90 | 180 | 270. */\n rotation?: number;\n /** Mirror horizontally while sampling. */\n mirrored?: boolean;\n}\n\n/**\n * Descriptor for {@link GPUDevice.importSharedTextureMemory}. `handle` is the\n * NativeBuffer returned by `Skia.NativeBuffer.MakeFromImage` (see\n * {@link SkiaGPUExternalTextureDescriptor} for the platform-specific types and\n * lifetime rules).\n */\nexport interface GPUSharedTextureMemoryDescriptor extends GPUObjectDescriptorBase {\n handle: NativeBuffer;\n}\n\n/**\n * The kind of native synchronization primitive a {@link GPUSharedFence} wraps,\n * matching the `shared-fence-*` device feature names. Limited to the kinds\n * react-native-skia targets (iOS/Metal and Android/Vulkan); `importSharedFence`\n * accepts these and `export()` reports them.\n */\nexport type GPUSharedFenceType =\n | \"mtl-shared-event\"\n | \"sync-fd\"\n | \"vk-semaphore-opaque-fd\";\n\n/**\n * Descriptor for {@link GPUDevice.importSharedFence}.\n */\nexport interface GPUSharedFenceDescriptor {\n /**\n * The fence kind to import. Must match a `shared-fence-*` feature enabled on\n * the device.\n */\n type: GPUSharedFenceType;\n /**\n * The raw native handle as a BigInt: an `id<MTLSharedEvent>` pointer for\n * `\"mtl-shared-event\"`, or an OS file descriptor for the `*-fd` kinds.\n */\n handle: bigint;\n label?: string;\n}\n\nexport interface GPUSharedFenceExportInfo {\n type: GPUSharedFenceType;\n /**\n * An `id<MTLSharedEvent>` pointer (Apple) or file descriptor (Android), as a\n * BigInt. The caller takes ownership; e.g. an exported sync-fd must be closed\n * once consumed.\n */\n handle: bigint;\n}\n\n/**\n * A native GPU synchronization primitive shared across queues/APIs. Produced by\n * {@link GPUSharedTextureMemory.endAccess}, consumed by\n * {@link GPUSharedTextureMemory.beginAccess}, or imported from a consumer's\n * fence with {@link GPUDevice.importSharedFence}.\n */\nexport interface GPUSharedFence {\n readonly __brand: \"GPUSharedFence\";\n label: string;\n export(): GPUSharedFenceExportInfo;\n}\n\n/** A fence and the timeline value to wait for (0n for binary sync-fd fences). */\nexport interface GPUSharedFenceState {\n fence: GPUSharedFence;\n signaledValue: bigint;\n}\n\n/**\n * The result of {@link GPUSharedTextureMemory.endAccess}: each fence is signaled\n * at its `signaledValue` once Dawn's GPU work for the access completes.\n */\nexport interface GPUSharedTextureMemoryEndAccessState {\n initialized: boolean;\n fences: GPUSharedFenceState[];\n}\n\n/**\n * Shared texture memory imported from a platform native buffer via\n * {@link GPUDevice.importSharedTextureMemory}. Create a texture that aliases\n * the memory, then bracket the GPU work that touches it with\n * {@link GPUSharedTextureMemory.beginAccess} / {@link GPUSharedTextureMemory.endAccess}.\n */\nexport interface GPUSharedTextureMemory extends GPUObjectBase {\n /** Create a texture that aliases the shared memory. */\n createTexture(descriptor?: GPUTextureDescriptor): GPUTexture;\n /**\n * Acquire the memory for GPU access. `initialized` marks whether the existing\n * contents should be preserved (pass `true` for an already-rendered frame).\n * Optional `fences` are wait fences: Dawn waits for each to reach its\n * `signaledValue` before writing the surface. Throws if the access could not\n * be acquired.\n */\n beginAccess(\n texture: GPUTexture,\n initialized: boolean,\n fences?: GPUSharedFenceState[]\n ): void;\n /**\n * Release the memory after the GPU work that accessed it has been submitted,\n * and return the fences Dawn produced for the access. Throws on failure.\n */\n endAccess(texture: GPUTexture): GPUSharedTextureMemoryEndAccessState;\n}\n\n/**\n * Dawn-specific toggles, passed via {@link GPUDeviceDescriptor.dawnToggles} to\n * `adapter.requestDevice`. This is a non-spec, Dawn-only extension; see Dawn's\n * toggle list for valid names.\n */\nexport interface GPUDawnTogglesDescriptor {\n enabledToggles?: string[];\n disabledToggles?: string[];\n}\n\ndeclare global {\n interface GPUDeviceDescriptor {\n /** Dawn-specific toggles (Skia/Graphite extension, non-spec). */\n dawnToggles?: GPUDawnTogglesDescriptor;\n }\n\n interface GPUExternalTexture {\n /**\n * Skia extension: end the imported buffer's shared-memory access window and\n * release the underlying resources. Call right after the `queue.submit()`\n * that sampled this texture (never before). Idempotent, and also runs at\n * garbage collection as a fallback.\n */\n destroy(): void;\n }\n\n interface GPUDevice {\n /**\n * Skia extension: import a NativeBuffer (from\n * `Skia.NativeBuffer.MakeFromImage`) as a {@link GPUExternalTexture}, sampled\n * with `texture_external` in WGSL. The returned texture owns the\n * shared-memory access window; call `destroy()` on it after the sampling\n * `queue.submit()`.\n */\n importExternalTexture(\n descriptor: SkiaGPUExternalTextureDescriptor\n ): GPUExternalTexture;\n /**\n * Skia extension: import a NativeBuffer (from\n * `Skia.NativeBuffer.MakeFromImage`) as {@link GPUSharedTextureMemory}, the\n * lower-level path that lets you create an aliasing texture and manage the\n * begin/end access window yourself.\n */\n importSharedTextureMemory(\n descriptor: GPUSharedTextureMemoryDescriptor\n ): GPUSharedTextureMemory;\n /**\n * Skia extension: import a native synchronization primitive (an\n * `id<MTLSharedEvent>` on Apple, a sync-fd / VkSemaphore on Android) as a\n * {@link GPUSharedFence}, e.g. to wait on a fence a consumer produced. The\n * matching `shared-fence-*` feature must be enabled on the device.\n */\n importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;\n }\n}\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,aAAyB,GAAG,CAAC,MAAM;EAC9C,MAAMC,CAAC,GACL,OAAOC,MAAM,KAAK,WAAW,GACxBA,MAAM,GACPC,SAAS;EACf,OAAOF,CAAC,IAAI,OAAOA,CAAC,CAACD,aAAa,KAAK,UAAU,GAC7CC,CAAC,CAACD,aAAa,GACf,MAAM,CAAC,CAAC;AACd,CAAC,EAAE,CAAC;;AAEJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;;AAyBA;AACA;AACA;AACA;AACA;AACA;;AAOA;;AAMA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;;AAuBA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -306,6 +306,7 @@ export function Mock(CanvasKit: any): {
|
|
|
306
306
|
isNativeBufferAddr: (buffer: any) => buffer is BigInt;
|
|
307
307
|
isNativeBufferWeb: (buffer: any) => boolean;
|
|
308
308
|
isNativeBufferNode: (buffer: any) => buffer is ArrayBuffer;
|
|
309
|
+
installWebGPU: any;
|
|
309
310
|
LineBreakType: {};
|
|
310
311
|
VerticalTextAlign: {};
|
|
311
312
|
ResizePolicy: {};
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
|
|
3
|
+
* `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
|
|
4
|
+
* that calls this.
|
|
5
|
+
*
|
|
6
|
+
* The native module installs these globals on the main JS runtime, but worklet
|
|
7
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
8
|
+
* processors) start without them, so referencing the bare global inside a
|
|
9
|
+
* worklet yields `undefined`. Call `installWebGPU()` once at the top of a
|
|
10
|
+
* worklet to install them there:
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { installWebGPU } from "@shopify/react-native-skia";
|
|
14
|
+
*
|
|
15
|
+
* const work = (device: GPUDevice) => {
|
|
16
|
+
* "worklet";
|
|
17
|
+
* installWebGPU();
|
|
18
|
+
* device.createBuffer({
|
|
19
|
+
* usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
|
|
20
|
+
* });
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* `installWebGPU` is a native host function. When captured into a worklet, the
|
|
25
|
+
* Worklets serializer re-creates it on the worklet runtime, so calling it there
|
|
26
|
+
* installs the constants on that runtime. The values come from the native
|
|
27
|
+
* `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
|
|
28
|
+
* Calling it on a runtime that already has the constants is a safe no-op, and on
|
|
29
|
+
* web (where the constants are always global) it is a no-op too.
|
|
30
|
+
*/
|
|
31
|
+
export const installWebGPU: any;
|
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
import type { NativeBuffer } from "./NativeBuffer";
|
|
2
|
+
/**
|
|
3
|
+
* Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
|
|
4
|
+
* `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
|
|
5
|
+
* that calls this.
|
|
6
|
+
*
|
|
7
|
+
* The native module installs these globals on the main JS runtime, but worklet
|
|
8
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
9
|
+
* processors) start without them, so referencing the bare global inside a
|
|
10
|
+
* worklet yields `undefined`. Call `installWebGPU()` once at the top of a
|
|
11
|
+
* worklet to install them there:
|
|
12
|
+
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { installWebGPU } from "@shopify/react-native-skia";
|
|
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
|
+
* `installWebGPU` is a native host function. When captured into a worklet, the
|
|
26
|
+
* Worklets serializer re-creates it on the worklet runtime, so calling it there
|
|
27
|
+
* installs the constants on that runtime. The values come from the native
|
|
28
|
+
* `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
|
|
29
|
+
* Calling it on a runtime that already has the constants is a safe no-op, and on
|
|
30
|
+
* web (where the constants are always global) it is a no-op too.
|
|
31
|
+
*/
|
|
32
|
+
export declare const installWebGPU: () => void;
|
|
2
33
|
/**
|
|
3
34
|
* Descriptor for {@link GPUDevice.importExternalTexture} when the source is a
|
|
4
35
|
* Skia NativeBuffer (Skia has no WebCodecs `VideoFrame`).
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
|
9
9
|
},
|
|
10
10
|
"title": "React Native Skia",
|
|
11
|
-
"version": "2.6.
|
|
11
|
+
"version": "2.6.7",
|
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
|
13
13
|
"main": "lib/module/index.js",
|
|
14
14
|
"react-native": "src/index.ts",
|
package/src/skia/types/WebGPU.ts
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
import type { NativeBuffer } from "./NativeBuffer";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Make the WebGPU flag constants (`GPUBufferUsage`, `GPUColorWrite`,
|
|
5
|
+
* `GPUMapMode`, `GPUShaderStage`, `GPUTextureUsage`) available on the runtime
|
|
6
|
+
* that calls this.
|
|
7
|
+
*
|
|
8
|
+
* The native module installs these globals on the main JS runtime, but worklet
|
|
9
|
+
* runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
|
|
10
|
+
* processors) start without them, so referencing the bare global inside a
|
|
11
|
+
* worklet yields `undefined`. Call `installWebGPU()` once at the top of a
|
|
12
|
+
* worklet to install them there:
|
|
13
|
+
*
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { installWebGPU } from "@shopify/react-native-skia";
|
|
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
|
+
* `installWebGPU` is a native host function. When captured into a worklet, the
|
|
27
|
+
* Worklets serializer re-creates it on the worklet runtime, so calling it there
|
|
28
|
+
* installs the constants on that runtime. The values come from the native
|
|
29
|
+
* `wgpu::*Usage` enums, so they stay a single source of truth across runtimes.
|
|
30
|
+
* Calling it on a runtime that already has the constants is a safe no-op, and on
|
|
31
|
+
* web (where the constants are always global) it is a no-op too.
|
|
32
|
+
*/
|
|
33
|
+
export const installWebGPU: () => void = (() => {
|
|
34
|
+
const g =
|
|
35
|
+
typeof global !== "undefined"
|
|
36
|
+
? (global as unknown as { installWebGPU?: () => void })
|
|
37
|
+
: undefined;
|
|
38
|
+
return g && typeof g.installWebGPU === "function"
|
|
39
|
+
? g.installWebGPU
|
|
40
|
+
: () => {};
|
|
41
|
+
})();
|
|
42
|
+
|
|
3
43
|
// Skia's Graphite/Dawn backend extends the standard WebGPU API (typed by
|
|
4
44
|
// @webgpu/types) with a few Skia- and Dawn-specific entry points. These are
|
|
5
45
|
// only available on native (SK_GRAPHITE) builds, reachable through
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <functional>
|
|
4
|
-
#include <memory>
|
|
5
|
-
|
|
6
|
-
#include <jsi/jsi.h>
|
|
7
|
-
|
|
8
|
-
namespace rnwgpu::async {
|
|
9
|
-
|
|
10
|
-
namespace jsi = facebook::jsi;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Abstract dispatcher used by the AsyncRunner to enqueue work back onto the
|
|
14
|
-
* JavaScript thread.
|
|
15
|
-
*/
|
|
16
|
-
class AsyncDispatcher {
|
|
17
|
-
public:
|
|
18
|
-
using Work = std::function<void(jsi::Runtime &)>;
|
|
19
|
-
|
|
20
|
-
virtual ~AsyncDispatcher() = default;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Enqueue a unit of work that will be executed on the JavaScript thread.
|
|
24
|
-
*/
|
|
25
|
-
virtual void post(Work work) = 0;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
} // namespace rnwgpu::async
|