react-native-webgpu 0.6.4 → 0.7.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.
- package/apple/WebGPUView.mm +1 -2
- package/cpp/rnwgpu/api/GPU.cpp +21 -0
- package/cpp/rnwgpu/api/GPUTexture.h +8 -0
- package/cpp/rnwgpu/api/RNWebGPU.h +40 -0
- package/lib/commonjs/importDevice.js +47 -0
- package/lib/commonjs/importDevice.js.map +1 -0
- package/lib/commonjs/main/index.js +12 -0
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/module/importDevice.js +39 -0
- package/lib/module/importDevice.js.map +1 -0
- package/lib/module/main/index.js +1 -0
- package/lib/module/main/index.js.map +1 -1
- package/lib/typescript/lib/commonjs/importDevice.d.ts +18 -0
- package/lib/typescript/lib/commonjs/importDevice.d.ts.map +1 -0
- package/lib/typescript/lib/module/importDevice.d.ts +3 -0
- package/lib/typescript/lib/module/importDevice.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/index.d.ts +1 -0
- package/lib/typescript/src/importDevice.d.ts +28 -0
- package/lib/typescript/src/importDevice.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.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/package.json +1 -1
- package/react-native-webgpu.podspec +5 -0
- package/src/importDevice.ts +42 -0
- package/src/index.tsx +15 -0
- package/src/main/index.tsx +1 -0
package/apple/WebGPUView.mm
CHANGED
package/cpp/rnwgpu/api/GPU.cpp
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#include "GPU.h"
|
|
2
2
|
|
|
3
|
+
#include <dlfcn.h>
|
|
4
|
+
|
|
3
5
|
#include <cstdio>
|
|
4
6
|
#include <memory>
|
|
5
7
|
#include <string>
|
|
@@ -14,6 +16,25 @@
|
|
|
14
16
|
namespace rnwgpu {
|
|
15
17
|
|
|
16
18
|
GPU::GPU(jsi::Runtime & /*runtime*/) : NativeObject(CLASS_NAME) {
|
|
19
|
+
// If a Graphite build of @shopify/react-native-skia is loaded in this
|
|
20
|
+
// process, adopt its wgpu::Instance instead of creating our own, so
|
|
21
|
+
// Graphite's device and every JS-created device live on one instance. That
|
|
22
|
+
// makes pointer-based handoff (RNWebGPU.importDevice of Skia's device)
|
|
23
|
+
// sound: the async pump serves the shared instance, so callbacks on
|
|
24
|
+
// imported devices settle. Discovered at runtime via dlsym so there is no
|
|
25
|
+
// build-time coupling and native-module init order does not matter. Both
|
|
26
|
+
// packages must link the same single Dawn copy (they vendor the same
|
|
27
|
+
// artifact) for the handle to be meaningful.
|
|
28
|
+
using GetInstanceFn = WGPUInstance (*)();
|
|
29
|
+
if (auto getSkiaInstance = reinterpret_cast<GetInstanceFn>(
|
|
30
|
+
dlsym(RTLD_DEFAULT, "rnskia_getWGPUInstance"))) {
|
|
31
|
+
if (WGPUInstance external = getSkiaInstance()) {
|
|
32
|
+
wgpuInstanceAddRef(external);
|
|
33
|
+
_instance = wgpu::Instance::Acquire(external);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
17
38
|
static const auto kTimedWaitAny = wgpu::InstanceFeatureName::TimedWaitAny;
|
|
18
39
|
wgpu::InstanceDescriptor instanceDesc{.requiredFeatureCount = 1,
|
|
19
40
|
.requiredFeatures = &kTimedWaitAny};
|
|
@@ -42,6 +42,12 @@ public:
|
|
|
42
42
|
wgpu::TextureFormat getFormat();
|
|
43
43
|
double getUsage();
|
|
44
44
|
|
|
45
|
+
// Non-spec RN extension: the raw WGPUTexture handle as a BigInt, for
|
|
46
|
+
// pointer-based interop (e.g. Skia's Image.MakeImageFromNativeTexture).
|
|
47
|
+
// Borrowed: this GPUTexture keeps ownership; the consumer must retain the
|
|
48
|
+
// JS object (or AddRef natively) for as long as it uses the pointer.
|
|
49
|
+
void *getNativePointer() { return _instance.Get(); }
|
|
50
|
+
|
|
45
51
|
std::string getLabel() { return _label; }
|
|
46
52
|
void setLabel(const std::string &label) {
|
|
47
53
|
_label = label;
|
|
@@ -50,6 +56,8 @@ public:
|
|
|
50
56
|
|
|
51
57
|
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
52
58
|
installGetter(runtime, prototype, "__brand", &GPUTexture::getBrand);
|
|
59
|
+
installGetter(runtime, prototype, "nativePointer",
|
|
60
|
+
&GPUTexture::getNativePointer);
|
|
53
61
|
installMethod(runtime, prototype, "createView", &GPUTexture::createView);
|
|
54
62
|
installMethod(runtime, prototype, "destroy", &GPUTexture::destroy);
|
|
55
63
|
installGetter(runtime, prototype, "width", &GPUTexture::getWidth);
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
#include "Canvas.h"
|
|
10
10
|
#include "GPU.h"
|
|
11
11
|
#include "GPUCanvasContext.h"
|
|
12
|
+
#include "GPUDevice.h"
|
|
13
|
+
#include "GPUTexture.h"
|
|
14
|
+
#include "rnwgpu/async/RuntimeContext.h"
|
|
12
15
|
#include "ImageBitmap.h"
|
|
13
16
|
#include "PlatformContext.h"
|
|
14
17
|
#include "VideoFrame.h"
|
|
@@ -78,6 +81,40 @@ public:
|
|
|
78
81
|
return ctx;
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
// Wrap an externally created WGPUDevice (passed as a BigInt pointer, e.g.
|
|
85
|
+
// Skia's Graphite device from Skia.getNativeDevice()) in a GPUDevice.
|
|
86
|
+
// AddRefs the handle, so the original owner keeps its reference. Only sound
|
|
87
|
+
// because the process links a single Dawn copy and the GPU instance is
|
|
88
|
+
// shared with the exporter (see the GPU constructor): the calling runtime's
|
|
89
|
+
// pump serves the instance the device lives on, so its async callbacks
|
|
90
|
+
// settle normally.
|
|
91
|
+
std::shared_ptr<GPUDevice> importDevice(jsi::Runtime &runtime,
|
|
92
|
+
void *pointer) {
|
|
93
|
+
if (pointer == nullptr) {
|
|
94
|
+
throw std::runtime_error(
|
|
95
|
+
"importDevice: expected a non-null WGPUDevice pointer (BigInt)");
|
|
96
|
+
}
|
|
97
|
+
auto raw = reinterpret_cast<WGPUDevice>(pointer);
|
|
98
|
+
wgpuDeviceAddRef(raw);
|
|
99
|
+
wgpu::Device device = wgpu::Device::Acquire(raw);
|
|
100
|
+
auto ctx = async::RuntimeContext::getOrCreate(runtime, _gpu->get());
|
|
101
|
+
return std::make_shared<GPUDevice>(device, ctx, "Imported Device");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Wrap an externally created WGPUTexture in a GPUTexture, TAKING OWNERSHIP
|
|
105
|
+
// of one reference (unlike importDevice, which borrows): the returned
|
|
106
|
+
// GPUTexture releases it when destroyed. Pair with producers that return a
|
|
107
|
+
// +1 pointer, e.g. Skia.Image.MakeNativeTextureFromImage().
|
|
108
|
+
std::shared_ptr<GPUTexture> adoptTexture(void *pointer) {
|
|
109
|
+
if (pointer == nullptr) {
|
|
110
|
+
throw std::runtime_error(
|
|
111
|
+
"adoptTexture: expected a non-null WGPUTexture pointer (BigInt)");
|
|
112
|
+
}
|
|
113
|
+
wgpu::Texture texture =
|
|
114
|
+
wgpu::Texture::Acquire(reinterpret_cast<WGPUTexture>(pointer));
|
|
115
|
+
return std::make_shared<GPUTexture>(texture, "Adopted Texture");
|
|
116
|
+
}
|
|
117
|
+
|
|
81
118
|
jsi::Value createImageBitmap(jsi::Runtime &runtime,
|
|
82
119
|
const jsi::Value & /*thisVal*/,
|
|
83
120
|
const jsi::Value *args, size_t count) {
|
|
@@ -285,6 +322,9 @@ public:
|
|
|
285
322
|
&RNWebGPU::createTestVideoFrame);
|
|
286
323
|
installMethod(runtime, prototype, "createVideoFrameFromNativeBuffer",
|
|
287
324
|
&RNWebGPU::createVideoFrameFromNativeBuffer);
|
|
325
|
+
installMethodWithRuntime(runtime, prototype, "importDevice",
|
|
326
|
+
&RNWebGPU::importDevice);
|
|
327
|
+
installMethod(runtime, prototype, "adoptTexture", &RNWebGPU::adoptTexture);
|
|
288
328
|
installMethod(runtime, prototype, "createVideoPlayer",
|
|
289
329
|
&RNWebGPU::createVideoPlayer);
|
|
290
330
|
installMethod(runtime, prototype, "writeTestVideoFile",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.importDevice = exports.adoptTexture = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Wraps an externally created WGPUDevice pointer into a GPUDevice.
|
|
9
|
+
*
|
|
10
|
+
* The canonical use case is adopting the Graphite device from a
|
|
11
|
+
* @shopify/react-native-skia Graphite build:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const device = importDevice(Skia.getNativeDevice());
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* This is only sound when the exporting library links the same single Dawn
|
|
18
|
+
* copy as react-native-webgpu and shares its wgpu::Instance (react-native-skia
|
|
19
|
+
* Graphite builds do both).
|
|
20
|
+
*/
|
|
21
|
+
const importDevice = pointer => {
|
|
22
|
+
if (typeof RNWebGPU === "undefined") {
|
|
23
|
+
throw new Error("react-native-webgpu is not installed natively; importDevice is unavailable");
|
|
24
|
+
}
|
|
25
|
+
return RNWebGPU.importDevice(pointer);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Wraps an externally created WGPUTexture pointer into a GPUTexture, taking
|
|
30
|
+
* ownership of one reference: the returned texture releases it when destroyed.
|
|
31
|
+
*
|
|
32
|
+
* Pair with producers that hand out a +1 reference, such as
|
|
33
|
+
* `Skia.Image.MakeNativeTextureFromImage()`:
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const texture = adoptTexture(Skia.Image.MakeNativeTextureFromImage(image));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
exports.importDevice = importDevice;
|
|
40
|
+
const adoptTexture = pointer => {
|
|
41
|
+
if (typeof RNWebGPU === "undefined") {
|
|
42
|
+
throw new Error("react-native-webgpu is not installed natively; adoptTexture is unavailable");
|
|
43
|
+
}
|
|
44
|
+
return RNWebGPU.adoptTexture(pointer);
|
|
45
|
+
};
|
|
46
|
+
exports.adoptTexture = adoptTexture;
|
|
47
|
+
//# sourceMappingURL=importDevice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["importDevice","pointer","RNWebGPU","Error","exports","adoptTexture"],"sourceRoot":"../../src","sources":["importDevice.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAIC,OAAe,IAAgB;EAC1D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACF,YAAY,CAACC,OAAO,CAAC;AACvC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAVAG,OAAA,CAAAJ,YAAA,GAAAA,YAAA;AAWO,MAAMK,YAAY,GAAIJ,OAAe,IAAiB;EAC3D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACG,YAAY,CAACJ,OAAO,CAAC;AACvC,CAAC;AAACG,OAAA,CAAAC,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -74,6 +74,18 @@ Object.keys(_GPUDeviceProvider).forEach(function (key) {
|
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
|
+
var _importDevice = require("../importDevice");
|
|
78
|
+
Object.keys(_importDevice).forEach(function (key) {
|
|
79
|
+
if (key === "default" || key === "__esModule") return;
|
|
80
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
81
|
+
if (key in exports && exports[key] === _importDevice[key]) return;
|
|
82
|
+
Object.defineProperty(exports, key, {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function () {
|
|
85
|
+
return _importDevice[key];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
77
89
|
var _formats = require("../formats");
|
|
78
90
|
Object.keys(_formats).forEach(function (key) {
|
|
79
91
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_external","require","_NativeWebGPUModule","_interopRequireDefault","_Canvas","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_Offscreen","_WebGPUViewNativeComponent","_hooks","_GPUDeviceProvider","_formats","e","__esModule","default","_installOk","WebGPUModule","install","registerWebGPUForReanimated","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind","console","warn"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAF,OAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,OAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,OAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAhB,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAW,UAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAA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A;AAAA;AACA,IAAAY,kBAAA,GAAAnB,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAc,kBAAA,EAAAb,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAY,kBAAA,CAAAZ,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,kBAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA;AACA,IAAAa,
|
|
1
|
+
{"version":3,"names":["_external","require","_NativeWebGPUModule","_interopRequireDefault","_Canvas","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_Offscreen","_WebGPUViewNativeComponent","_hooks","_GPUDeviceProvider","_importDevice","_formats","e","__esModule","default","_installOk","WebGPUModule","install","registerWebGPUForReanimated","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind","console","warn"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAF,OAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,OAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,E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ice.
|
|
3
|
+
*
|
|
4
|
+
* The canonical use case is adopting the Graphite device from a
|
|
5
|
+
* @shopify/react-native-skia Graphite build:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const device = importDevice(Skia.getNativeDevice());
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* This is only sound when the exporting library links the same single Dawn
|
|
12
|
+
* copy as react-native-webgpu and shares its wgpu::Instance (react-native-skia
|
|
13
|
+
* Graphite builds do both).
|
|
14
|
+
*/
|
|
15
|
+
export const importDevice = pointer => {
|
|
16
|
+
if (typeof RNWebGPU === "undefined") {
|
|
17
|
+
throw new Error("react-native-webgpu is not installed natively; importDevice is unavailable");
|
|
18
|
+
}
|
|
19
|
+
return RNWebGPU.importDevice(pointer);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Wraps an externally created WGPUTexture pointer into a GPUTexture, taking
|
|
24
|
+
* ownership of one reference: the returned texture releases it when destroyed.
|
|
25
|
+
*
|
|
26
|
+
* Pair with producers that hand out a +1 reference, such as
|
|
27
|
+
* `Skia.Image.MakeNativeTextureFromImage()`:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const texture = adoptTexture(Skia.Image.MakeNativeTextureFromImage(image));
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const adoptTexture = pointer => {
|
|
34
|
+
if (typeof RNWebGPU === "undefined") {
|
|
35
|
+
throw new Error("react-native-webgpu is not installed natively; adoptTexture is unavailable");
|
|
36
|
+
}
|
|
37
|
+
return RNWebGPU.adoptTexture(pointer);
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=importDevice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["importDevice","pointer","RNWebGPU","Error","adoptTexture"],"sourceRoot":"../../src","sources":["importDevice.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,YAAY,GAAIC,OAAe,IAAgB;EAC1D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACF,YAAY,CAACC,OAAO,CAAC;AACvC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,YAAY,GAAIH,OAAe,IAAiB;EAC3D,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,4EACF,CAAC;EACH;EACA,OAAOD,QAAQ,CAACE,YAAY,CAACH,OAAO,CAAC;AACvC,CAAC","ignoreList":[]}
|
package/lib/module/main/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "../Offscreen";
|
|
|
5
5
|
export * from "../WebGPUViewNativeComponent";
|
|
6
6
|
export * from "../hooks";
|
|
7
7
|
export * from "../GPUDeviceProvider";
|
|
8
|
+
export * from "../importDevice";
|
|
8
9
|
export * from "../formats";
|
|
9
10
|
export { default as WebGPUModule } from "../NativeWebGPUModule";
|
|
10
11
|
const _installOk = WebGPUModule.install();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerWebGPUForReanimated","WebGPUModule","default","_installOk","install","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind","console","warn"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,aAAa;AACzD,OAAOC,YAAY,MAAM,uBAAuB;AAEhD,cAAc,WAAW;AACzB,cAAc,cAAc;AAC5B,cAAc,8BAA8B;AAC5C,cAAc,UAAU;AACxB,cAAc,sBAAsB;AACpC,cAAc,YAAY;AAE1B,SAASC,OAAO,IAAID,YAAY,QAAQ,uBAAuB;AAE/D,MAAME,UAAU,GAAGF,YAAY,CAACG,OAAO,CAAC,CAAC;AAEzCJ,2BAA2B,CAAC,CAAC;AAE7B,IAAI,OAAOK,QAAQ,KAAK,WAAW,EAAE;EACnC,IAAI,CAACC,SAAS,EAAE;IACd;IACAA,SAAS,GAAG;MACVC,GAAG,EAAEF,QAAQ,CAACE,GAAG;MACjBC,SAAS,EAAE;IACb,CAAC;EACH,CAAC,MAAM;IACLF,SAAS,CAACC,GAAG,GAAGF,QAAQ,CAACE,GAAG;IAC5B,IAAI,OAAOD,SAAS,CAACE,SAAS,KAAK,QAAQ,EAAE;MAC3C,IAAI;QACF;QACA;QACAF,SAAS,CAACE,SAAS,GAAG,cAAc;MACtC,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;EACAC,MAAM,CAACC,iBAAiB,GACtBD,MAAM,CAACC,iBAAiB,IAAIL,QAAQ,CAACK,iBAAiB,CAACC,IAAI,CAACN,QAAQ,CAAC;AACzE,CAAC,MAAM;EACLO,OAAO,CAACC,IAAI,CACV,4CAA4CV,UAAU,uCACxD,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["registerWebGPUForReanimated","WebGPUModule","default","_installOk","install","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind","console","warn"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,aAAa;AACzD,OAAOC,YAAY,MAAM,uBAAuB;AAEhD,cAAc,WAAW;AACzB,cAAc,cAAc;AAC5B,cAAc,8BAA8B;AAC5C,cAAc,UAAU;AACxB,cAAc,sBAAsB;AACpC,cAAc,iBAAiB;AAC/B,cAAc,YAAY;AAE1B,SAASC,OAAO,IAAID,YAAY,QAAQ,uBAAuB;AAE/D,MAAME,UAAU,GAAGF,YAAY,CAACG,OAAO,CAAC,CAAC;AAEzCJ,2BAA2B,CAAC,CAAC;AAE7B,IAAI,OAAOK,QAAQ,KAAK,WAAW,EAAE;EACnC,IAAI,CAACC,SAAS,EAAE;IACd;IACAA,SAAS,GAAG;MACVC,GAAG,EAAEF,QAAQ,CAACE,GAAG;MACjBC,SAAS,EAAE;IACb,CAAC;EACH,CAAC,MAAM;IACLF,SAAS,CAACC,GAAG,GAAGF,QAAQ,CAACE,GAAG;IAC5B,IAAI,OAAOD,SAAS,CAACE,SAAS,KAAK,QAAQ,EAAE;MAC3C,IAAI;QACF;QACA;QACAF,SAAS,CAACE,SAAS,GAAG,cAAc;MACtC,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;EACAC,MAAM,CAACC,iBAAiB,GACtBD,MAAM,CAACC,iBAAiB,IAAIL,QAAQ,CAACK,iBAAiB,CAACC,IAAI,CAACN,QAAQ,CAAC;AACzE,CAAC,MAAM;EACLO,OAAO,CAACC,IAAI,CACV,4CAA4CV,UAAU,uCACxD,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Wraps an externally created WGPUDevice pointer into a GPUDevice.
|
|
4
|
+
*
|
|
5
|
+
* The canonical use case is adopting the Graphite device from a
|
|
6
|
+
* @shopify/react-native-skia Graphite build:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const device = importDevice(Skia.getNativeDevice());
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* This is only sound when the exporting library links the same single Dawn
|
|
13
|
+
* copy as react-native-webgpu and shares its wgpu::Instance (react-native-skia
|
|
14
|
+
* Graphite builds do both).
|
|
15
|
+
*/
|
|
16
|
+
export function importDevice(pointer: any): GPUDevice;
|
|
17
|
+
export function adoptTexture(pointer: any): GPUTexture;
|
|
18
|
+
//# sourceMappingURL=importDevice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../commonjs/importDevice.js"],"names":[],"mappings":";AAMA;;;;;;;;;;;;;GAaG;AACH,sDAKC;AAcD,uDAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../module/importDevice.js"],"names":[],"mappings":"AAcO,sDAKN;AAaM,uDAKN"}
|
|
@@ -3,6 +3,7 @@ export * from "../Offscreen";
|
|
|
3
3
|
export * from "../WebGPUViewNativeComponent";
|
|
4
4
|
export * from "../hooks";
|
|
5
5
|
export * from "../GPUDeviceProvider";
|
|
6
|
+
export * from "../importDevice";
|
|
6
7
|
export * from "../formats";
|
|
7
8
|
export { default as WebGPUModule } from "../NativeWebGPUModule";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps an externally created WGPUDevice pointer into a GPUDevice.
|
|
3
|
+
*
|
|
4
|
+
* The canonical use case is adopting the Graphite device from a
|
|
5
|
+
* @shopify/react-native-skia Graphite build:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const device = importDevice(Skia.getNativeDevice());
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* This is only sound when the exporting library links the same single Dawn
|
|
12
|
+
* copy as react-native-webgpu and shares its wgpu::Instance (react-native-skia
|
|
13
|
+
* Graphite builds do both).
|
|
14
|
+
*/
|
|
15
|
+
export declare const importDevice: (pointer: bigint) => GPUDevice;
|
|
16
|
+
/**
|
|
17
|
+
* Wraps an externally created WGPUTexture pointer into a GPUTexture, taking
|
|
18
|
+
* ownership of one reference: the returned texture releases it when destroyed.
|
|
19
|
+
*
|
|
20
|
+
* Pair with producers that hand out a +1 reference, such as
|
|
21
|
+
* `Skia.Image.MakeNativeTextureFromImage()`:
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const texture = adoptTexture(Skia.Image.MakeNativeTextureFromImage(image));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const adoptTexture: (pointer: bigint) => GPUTexture;
|
|
28
|
+
//# sourceMappingURL=importDevice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../src/importDevice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,SAO9C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,UAO9C,CAAC"}
|
|
@@ -19,9 +19,14 @@ declare global {
|
|
|
19
19
|
loadVideoFrame: (path: string) => NativeVideoFrame;
|
|
20
20
|
createTestVideoFrame: (width: number, height: number) => NativeVideoFrame;
|
|
21
21
|
createVideoFrameFromNativeBuffer: (pointer: bigint) => NativeVideoFrame;
|
|
22
|
+
importDevice: (pointer: bigint) => GPUDevice;
|
|
23
|
+
adoptTexture: (pointer: bigint) => GPUTexture;
|
|
22
24
|
createVideoPlayer: (path: string, pixelFormat?: NativeVideoPixelFormat) => VideoPlayer;
|
|
23
25
|
writeTestVideoFile: () => string;
|
|
24
26
|
};
|
|
27
|
+
interface GPUTexture {
|
|
28
|
+
readonly nativePointer: bigint;
|
|
29
|
+
}
|
|
25
30
|
interface GPUDevice {
|
|
26
31
|
importSharedTextureMemory(descriptor: GPUSharedTextureMemoryDescriptor): GPUSharedTextureMemory;
|
|
27
32
|
importSharedFence(descriptor: GPUSharedFenceDescriptor): GPUSharedFence;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EAChC,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,YAAY,EACV,gBAAgB,EAChB,W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,CAAC,EAAE,sBAAsB,KACjC,WAAW,CAAC;QACjB,kBAAkB,EAAE,MAAM,MAAM,CAAC;KAClC,CAAC;IAEF,UAAU,UAAU;QAIlB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;KAChC;IAED,UAAU,SAAS;QACjB,yBAAyB,CACvB,UAAU,EAAE,gCAAgC,GAC3C,sBAAsB,CAAC;QAC1B,iBAAiB,CAAC,UAAU,EAAE,wBAAwB,GAAG,cAAc,CAAC;KACzE;IAID,UAAU,mBAAmB;QAC3B,WAAW,CAAC,EAAE,wBAAwB,CAAC;KACxC;IAMD,UAAU,4BAA4B;QACpC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,CAAC;QAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB;IASD,UAAU,kBAAkB;QAC1B,OAAO,IAAI,IAAI,CAAC;QAShB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;KACnC;IAGD,SAAS,iBAAiB,CACxB,KAAK,EAAE,WAAW,GAAG,eAAe,EACpC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
|
|
@@ -3,6 +3,7 @@ export * from "../Offscreen";
|
|
|
3
3
|
export * from "../WebGPUViewNativeComponent";
|
|
4
4
|
export * from "../hooks";
|
|
5
5
|
export * from "../GPUDeviceProvider";
|
|
6
|
+
export * from "../importDevice";
|
|
6
7
|
export * from "../formats";
|
|
7
8
|
export { default as WebGPUModule } from "../NativeWebGPUModule";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/index.tsx"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/main/index.tsx"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -28,6 +28,11 @@ Pod::Spec.new do |s|
|
|
|
28
28
|
|
|
29
29
|
s.pod_target_xcconfig = {
|
|
30
30
|
'HEADER_SEARCH_PATHS' => '$(PODS_TARGET_SRCROOT)/cpp',
|
|
31
|
+
# Xcode's all-target headermaps let same-named headers leak across pods
|
|
32
|
+
# (e.g. @shopify/react-native-skia keeps a jsi/ helper layer with
|
|
33
|
+
# identical relative header paths). Resolve includes strictly through our
|
|
34
|
+
# own search paths instead.
|
|
35
|
+
'USE_HEADERMAP' => 'NO',
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps an externally created WGPUDevice pointer into a GPUDevice.
|
|
3
|
+
*
|
|
4
|
+
* The canonical use case is adopting the Graphite device from a
|
|
5
|
+
* @shopify/react-native-skia Graphite build:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const device = importDevice(Skia.getNativeDevice());
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* This is only sound when the exporting library links the same single Dawn
|
|
12
|
+
* copy as react-native-webgpu and shares its wgpu::Instance (react-native-skia
|
|
13
|
+
* Graphite builds do both).
|
|
14
|
+
*/
|
|
15
|
+
export const importDevice = (pointer: bigint): GPUDevice => {
|
|
16
|
+
if (typeof RNWebGPU === "undefined") {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"react-native-webgpu is not installed natively; importDevice is unavailable",
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return RNWebGPU.importDevice(pointer);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Wraps an externally created WGPUTexture pointer into a GPUTexture, taking
|
|
26
|
+
* ownership of one reference: the returned texture releases it when destroyed.
|
|
27
|
+
*
|
|
28
|
+
* Pair with producers that hand out a +1 reference, such as
|
|
29
|
+
* `Skia.Image.MakeNativeTextureFromImage()`:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const texture = adoptTexture(Skia.Image.MakeNativeTextureFromImage(image));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export const adoptTexture = (pointer: bigint): GPUTexture => {
|
|
36
|
+
if (typeof RNWebGPU === "undefined") {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"react-native-webgpu is not installed natively; adoptTexture is unavailable",
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return RNWebGPU.adoptTexture(pointer);
|
|
42
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -58,6 +58,14 @@ declare global {
|
|
|
58
58
|
// on Android) into a NativeVideoFrame. Matches the shape used by libraries
|
|
59
59
|
// that emit NativeBuffer (e.g. react-native-vision-camera).
|
|
60
60
|
createVideoFrameFromNativeBuffer: (pointer: bigint) => NativeVideoFrame;
|
|
61
|
+
// Wrap an externally created WGPUDevice pointer (e.g. Skia's Graphite
|
|
62
|
+
// device from Skia.getNativeDevice()) into a GPUDevice. Requires the
|
|
63
|
+
// exporter to share this process's single Dawn instance.
|
|
64
|
+
importDevice: (pointer: bigint) => GPUDevice;
|
|
65
|
+
// Wrap an externally created WGPUTexture pointer into a GPUTexture,
|
|
66
|
+
// taking ownership of one reference (pair with producers that return a
|
|
67
|
+
// +1 pointer, e.g. Skia.Image.MakeNativeTextureFromImage()).
|
|
68
|
+
adoptTexture: (pointer: bigint) => GPUTexture;
|
|
61
69
|
createVideoPlayer: (
|
|
62
70
|
path: string,
|
|
63
71
|
pixelFormat?: NativeVideoPixelFormat,
|
|
@@ -65,6 +73,13 @@ declare global {
|
|
|
65
73
|
writeTestVideoFile: () => string;
|
|
66
74
|
};
|
|
67
75
|
|
|
76
|
+
interface GPUTexture {
|
|
77
|
+
// Non-spec RN extension: raw WGPUTexture handle as a BigInt for
|
|
78
|
+
// pointer-based interop (e.g. Skia.Image.MakeImageFromNativeTexture).
|
|
79
|
+
// Borrowed: keep this GPUTexture alive while the pointer is in use.
|
|
80
|
+
readonly nativePointer: bigint;
|
|
81
|
+
}
|
|
82
|
+
|
|
68
83
|
interface GPUDevice {
|
|
69
84
|
importSharedTextureMemory(
|
|
70
85
|
descriptor: GPUSharedTextureMemoryDescriptor,
|
package/src/main/index.tsx
CHANGED
|
@@ -6,6 +6,7 @@ export * from "../Offscreen";
|
|
|
6
6
|
export * from "../WebGPUViewNativeComponent";
|
|
7
7
|
export * from "../hooks";
|
|
8
8
|
export * from "../GPUDeviceProvider";
|
|
9
|
+
export * from "../importDevice";
|
|
9
10
|
export * from "../formats";
|
|
10
11
|
|
|
11
12
|
export { default as WebGPUModule } from "../NativeWebGPUModule";
|