react-native-webgpu 0.7.0 → 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/cpp/rnwgpu/api/GPUTexture.h +8 -0
- package/cpp/rnwgpu/api/RNWebGPU.h +16 -0
- package/lib/commonjs/importDevice.js +20 -1
- package/lib/commonjs/importDevice.js.map +1 -1
- package/lib/module/importDevice.js +18 -0
- package/lib/module/importDevice.js.map +1 -1
- package/lib/typescript/lib/commonjs/importDevice.d.ts +1 -0
- package/lib/typescript/lib/commonjs/importDevice.d.ts.map +1 -1
- package/lib/typescript/lib/module/importDevice.d.ts +1 -0
- package/lib/typescript/lib/module/importDevice.d.ts.map +1 -1
- package/lib/typescript/src/importDevice.d.ts +12 -0
- package/lib/typescript/src/importDevice.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/importDevice.ts +20 -0
- package/src/index.tsx +11 -0
|
@@ -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);
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include "GPU.h"
|
|
11
11
|
#include "GPUCanvasContext.h"
|
|
12
12
|
#include "GPUDevice.h"
|
|
13
|
+
#include "GPUTexture.h"
|
|
13
14
|
#include "rnwgpu/async/RuntimeContext.h"
|
|
14
15
|
#include "ImageBitmap.h"
|
|
15
16
|
#include "PlatformContext.h"
|
|
@@ -100,6 +101,20 @@ public:
|
|
|
100
101
|
return std::make_shared<GPUDevice>(device, ctx, "Imported Device");
|
|
101
102
|
}
|
|
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
|
+
|
|
103
118
|
jsi::Value createImageBitmap(jsi::Runtime &runtime,
|
|
104
119
|
const jsi::Value & /*thisVal*/,
|
|
105
120
|
const jsi::Value *args, size_t count) {
|
|
@@ -309,6 +324,7 @@ public:
|
|
|
309
324
|
&RNWebGPU::createVideoFrameFromNativeBuffer);
|
|
310
325
|
installMethodWithRuntime(runtime, prototype, "importDevice",
|
|
311
326
|
&RNWebGPU::importDevice);
|
|
327
|
+
installMethod(runtime, prototype, "adoptTexture", &RNWebGPU::adoptTexture);
|
|
312
328
|
installMethod(runtime, prototype, "createVideoPlayer",
|
|
313
329
|
&RNWebGPU::createVideoPlayer);
|
|
314
330
|
installMethod(runtime, prototype, "writeTestVideoFile",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.importDevice = void 0;
|
|
6
|
+
exports.importDevice = exports.adoptTexture = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Wraps an externally created WGPUDevice pointer into a GPUDevice.
|
|
9
9
|
*
|
|
@@ -24,5 +24,24 @@ const importDevice = pointer => {
|
|
|
24
24
|
}
|
|
25
25
|
return RNWebGPU.importDevice(pointer);
|
|
26
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
|
+
*/
|
|
27
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;
|
|
28
47
|
//# sourceMappingURL=importDevice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["importDevice","pointer","RNWebGPU","Error","exports"],"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;
|
|
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":[]}
|
|
@@ -18,4 +18,22 @@ export const importDevice = pointer => {
|
|
|
18
18
|
}
|
|
19
19
|
return RNWebGPU.importDevice(pointer);
|
|
20
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
|
+
};
|
|
21
39
|
//# sourceMappingURL=importDevice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["importDevice","pointer","RNWebGPU","Error"],"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","ignoreList":[]}
|
|
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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../commonjs/importDevice.js"],"names":[],"mappings":";AAMA;;;;;;;;;;;;;GAaG;AACH,sDAKC"}
|
|
1
|
+
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../commonjs/importDevice.js"],"names":[],"mappings":";AAMA;;;;;;;;;;;;;GAaG;AACH,sDAKC;AAcD,uDAKC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../module/importDevice.js"],"names":[],"mappings":"AAcO,sDAKN"}
|
|
1
|
+
{"version":3,"file":"importDevice.d.ts","sourceRoot":"","sources":["../../../module/importDevice.js"],"names":[],"mappings":"AAcO,sDAKN;AAaM,uDAKN"}
|
|
@@ -13,4 +13,16 @@
|
|
|
13
13
|
* Graphite builds do both).
|
|
14
14
|
*/
|
|
15
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;
|
|
16
28
|
//# sourceMappingURL=importDevice.d.ts.map
|
|
@@ -1 +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"}
|
|
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"}
|
|
@@ -20,9 +20,13 @@ declare global {
|
|
|
20
20
|
createTestVideoFrame: (width: number, height: number) => NativeVideoFrame;
|
|
21
21
|
createVideoFrameFromNativeBuffer: (pointer: bigint) => NativeVideoFrame;
|
|
22
22
|
importDevice: (pointer: bigint) => GPUDevice;
|
|
23
|
+
adoptTexture: (pointer: bigint) => GPUTexture;
|
|
23
24
|
createVideoPlayer: (path: string, pixelFormat?: NativeVideoPixelFormat) => VideoPlayer;
|
|
24
25
|
writeTestVideoFile: () => string;
|
|
25
26
|
};
|
|
27
|
+
interface GPUTexture {
|
|
28
|
+
readonly nativePointer: bigint;
|
|
29
|
+
}
|
|
26
30
|
interface GPUDevice {
|
|
27
31
|
importSharedTextureMemory(descriptor: GPUSharedTextureMemoryDescriptor): GPUSharedTextureMemory;
|
|
28
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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,MAAM,KAAK,gBAAgB,CAAC;QAI1E,gCAAgC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,gBAAgB,CAAC;QAIxE,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,SAAS,CAAC;QAI7C,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC;QAC9C,iBAAiB,EAAE,CACjB,IAAI,EAAE,MAAM,EACZ,WAAW,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"}
|
package/package.json
CHANGED
package/src/importDevice.ts
CHANGED
|
@@ -20,3 +20,23 @@ export const importDevice = (pointer: bigint): GPUDevice => {
|
|
|
20
20
|
}
|
|
21
21
|
return RNWebGPU.importDevice(pointer);
|
|
22
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
|
@@ -62,6 +62,10 @@ declare global {
|
|
|
62
62
|
// device from Skia.getNativeDevice()) into a GPUDevice. Requires the
|
|
63
63
|
// exporter to share this process's single Dawn instance.
|
|
64
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;
|
|
65
69
|
createVideoPlayer: (
|
|
66
70
|
path: string,
|
|
67
71
|
pixelFormat?: NativeVideoPixelFormat,
|
|
@@ -69,6 +73,13 @@ declare global {
|
|
|
69
73
|
writeTestVideoFile: () => string;
|
|
70
74
|
};
|
|
71
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
|
+
|
|
72
83
|
interface GPUDevice {
|
|
73
84
|
importSharedTextureMemory(
|
|
74
85
|
descriptor: GPUSharedTextureMemoryDescriptor,
|