react-native-wgpu 0.5.9 → 0.5.11
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/cpp/AndroidPlatformContext.h +6 -5
- package/apple/ApplePlatformContext.h +4 -4
- package/apple/ApplePlatformContext.mm +16 -16
- package/apple/WebGPUModule.h +2 -1
- package/apple/WebGPUModule.mm +4 -2
- package/cpp/rnwgpu/PlatformContext.h +10 -8
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +3 -1
- package/cpp/rnwgpu/api/GPUFeatures.h +3 -12
- package/cpp/rnwgpu/api/GPUTexture.h +14 -2
- package/cpp/rnwgpu/api/RNWebGPU.h +8 -12
- package/cpp/rnwgpu/api/descriptors/Unions.h +0 -15
- package/cpp/webgpu/webgpu.h +251 -188
- package/cpp/webgpu/webgpu_cpp.h +687 -561
- package/cpp/webgpu/webgpu_cpp_print.h +101 -61
- package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
- package/libs/android/x86/libwebgpu_dawn.so +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +5 -5
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/package.json +2 -2
- package/libs/dawn.json +0 -4693
|
@@ -93,10 +93,10 @@ public:
|
|
|
93
93
|
return createImageBitmapFromData(data);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
void
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
void
|
|
97
|
+
createImageBitmapAsync(std::string blobId, double offset, double size,
|
|
98
|
+
std::function<void(ImageData)> onSuccess,
|
|
99
|
+
std::function<void(std::string)> onError) override {
|
|
100
100
|
std::thread([this, blobId = std::move(blobId), offset, size,
|
|
101
101
|
onSuccess = std::move(onSuccess),
|
|
102
102
|
onError = std::move(onError)]() {
|
|
@@ -189,7 +189,8 @@ public:
|
|
|
189
189
|
void createImageBitmapFromDataAsync(
|
|
190
190
|
std::span<const uint8_t> data, std::function<void(ImageData)> onSuccess,
|
|
191
191
|
std::function<void(std::string)> onError) override {
|
|
192
|
-
std::thread([this,
|
|
192
|
+
std::thread([this,
|
|
193
|
+
ownedData = std::vector<uint8_t>(data.begin(), data.end()),
|
|
193
194
|
onSuccess = std::move(onSuccess),
|
|
194
195
|
onError = std::move(onError)]() mutable {
|
|
195
196
|
jni::Environment::ensureCurrentThreadIsAttached();
|
|
@@ -16,10 +16,10 @@ public:
|
|
|
16
16
|
ImageData createImageBitmap(std::string blobId, double offset,
|
|
17
17
|
double size) override;
|
|
18
18
|
|
|
19
|
-
void
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
void
|
|
20
|
+
createImageBitmapAsync(std::string blobId, double offset, double size,
|
|
21
|
+
std::function<void(ImageData)> onSuccess,
|
|
22
|
+
std::function<void(std::string)> onError) override;
|
|
23
23
|
|
|
24
24
|
ImageData createImageBitmapFromData(std::span<const uint8_t> data) override;
|
|
25
25
|
|
|
@@ -82,17 +82,18 @@ void ApplePlatformContext::createImageBitmapAsync(
|
|
|
82
82
|
std::move(onError));
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
ImageData
|
|
86
|
-
|
|
85
|
+
ImageData
|
|
86
|
+
ApplePlatformContext::createImageBitmapFromData(std::span<const uint8_t> data) {
|
|
87
87
|
// This avoids a copy by assuming the UIImage/NSImage constructors
|
|
88
88
|
// decode `nsData` eagerly before the memory for the wrapped `data`
|
|
89
89
|
// is freed.
|
|
90
90
|
//
|
|
91
91
|
// Since we get the `CGImageRef` from `image` and then throw
|
|
92
92
|
// it away, that's a fairly safe assumption.
|
|
93
|
-
NSData *nsData =
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
NSData *nsData =
|
|
94
|
+
[NSData dataWithBytesNoCopy:const_cast<uint8_t *>(data.data())
|
|
95
|
+
length:data.size()
|
|
96
|
+
freeWhenDone:NO];
|
|
96
97
|
|
|
97
98
|
#if !TARGET_OS_OSX
|
|
98
99
|
UIImage *image = [UIImage imageWithData:nsData];
|
|
@@ -141,17 +142,16 @@ void ApplePlatformContext::createImageBitmapFromDataAsync(
|
|
|
141
142
|
auto ownedData =
|
|
142
143
|
std::make_shared<std::vector<uint8_t>>(data.begin(), data.end());
|
|
143
144
|
|
|
144
|
-
dispatch_async(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
145
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
|
|
146
|
+
@autoreleasepool {
|
|
147
|
+
try {
|
|
148
|
+
auto result = createImageBitmapFromData(*ownedData);
|
|
149
|
+
onSuccess(std::move(result));
|
|
150
|
+
} catch (const std::exception &e) {
|
|
151
|
+
onError(e.what());
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
} // namespace rnwgpu
|
package/apple/WebGPUModule.h
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
#import <React/RCTCallInvokerModule.h>
|
|
6
6
|
#import <React/RCTEventEmitter.h>
|
|
7
7
|
|
|
8
|
-
@interface WebGPUModule
|
|
8
|
+
@interface WebGPUModule
|
|
9
|
+
: RCTEventEmitter <NativeWebGPUModuleSpec, RCTCallInvokerModule>
|
|
9
10
|
|
|
10
11
|
+ (std::shared_ptr<rnwgpu::RNWebGPUManager>)getManager;
|
|
11
12
|
|
package/apple/WebGPUModule.mm
CHANGED
|
@@ -55,11 +55,13 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
|
|
55
55
|
return @true;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
// self.bridge works in both Legacy (RCTBridge) and Bridgeless
|
|
58
|
+
// self.bridge works in both Legacy (RCTBridge) and Bridgeless
|
|
59
|
+
// (RCTBridgeProxy).
|
|
59
60
|
jsi::Runtime *runtime = (jsi::Runtime *)self.bridge.runtime;
|
|
60
61
|
if (!runtime) {
|
|
61
62
|
NSLog(@"Failed to install react-native-wgpu: jsi::Runtime* was null! "
|
|
62
|
-
@"(self.bridge=%@)",
|
|
63
|
+
@"(self.bridge=%@)",
|
|
64
|
+
self.bridge);
|
|
63
65
|
return [NSNumber numberWithBool:NO];
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -28,17 +28,19 @@ public:
|
|
|
28
28
|
double size) = 0;
|
|
29
29
|
|
|
30
30
|
// Async version that performs image decoding on a background thread
|
|
31
|
-
virtual void
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
virtual void
|
|
32
|
+
createImageBitmapAsync(std::string blobId, double offset, double size,
|
|
33
|
+
std::function<void(ImageData)> onSuccess,
|
|
34
|
+
std::function<void(std::string)> onError) = 0;
|
|
35
35
|
|
|
36
36
|
// Create ImageBitmap from raw encoded image bytes (PNG/JPEG/etc.)
|
|
37
|
-
virtual ImageData
|
|
37
|
+
virtual ImageData
|
|
38
|
+
createImageBitmapFromData(std::span<const uint8_t> data) = 0;
|
|
38
39
|
|
|
39
|
-
virtual void
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
virtual void
|
|
41
|
+
createImageBitmapFromDataAsync(std::span<const uint8_t> data,
|
|
42
|
+
std::function<void(ImageData)> onSuccess,
|
|
43
|
+
std::function<void(std::string)> onError) = 0;
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
} // namespace rnwgpu
|
|
@@ -48,7 +48,9 @@ std::shared_ptr<GPUTexture> GPUCanvasContext::getCurrentTexture() {
|
|
|
48
48
|
_surfaceInfo->reconfigure(width, height);
|
|
49
49
|
}
|
|
50
50
|
auto texture = _surfaceInfo->getCurrentTexture();
|
|
51
|
-
|
|
51
|
+
// Pass reportsMemoryPressure=false to avoid triggering spurious Hermes GC
|
|
52
|
+
// cycles every frame since the canvas texture doesn't own the buffer.
|
|
53
|
+
return std::make_shared<GPUTexture>(texture, "", false);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
void GPUCanvasContext::present() {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
#include <string>
|
|
4
4
|
|
|
5
|
-
#include
|
|
5
|
+
#include <cstdio>
|
|
6
6
|
|
|
7
|
-
#include "
|
|
7
|
+
#include "webgpu/webgpu_cpp.h"
|
|
8
8
|
|
|
9
9
|
namespace rnwgpu {
|
|
10
10
|
|
|
@@ -89,9 +89,6 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
|
89
89
|
case wgpu::FeatureName::Unorm16TextureFormats:
|
|
90
90
|
*outUnion = "unorm16-texture-formats";
|
|
91
91
|
break;
|
|
92
|
-
case wgpu::FeatureName::Snorm16TextureFormats:
|
|
93
|
-
*outUnion = "snorm16-texture-formats";
|
|
94
|
-
break;
|
|
95
92
|
case wgpu::FeatureName::MultiPlanarFormatExtendedUsages:
|
|
96
93
|
*outUnion = "multi-planar-format-extended-usages";
|
|
97
94
|
break;
|
|
@@ -122,18 +119,12 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
|
122
119
|
case wgpu::FeatureName::AdapterPropertiesVk:
|
|
123
120
|
*outUnion = "adapter-properties-vk";
|
|
124
121
|
break;
|
|
125
|
-
case wgpu::FeatureName::R8UnormStorage:
|
|
126
|
-
*outUnion = "r8unorm-storage";
|
|
127
|
-
break;
|
|
128
122
|
case wgpu::FeatureName::DawnFormatCapabilities:
|
|
129
123
|
*outUnion = "format-capabilities";
|
|
130
124
|
break;
|
|
131
125
|
case wgpu::FeatureName::DawnDrmFormatCapabilities:
|
|
132
126
|
*outUnion = "drm-format-capabilities";
|
|
133
127
|
break;
|
|
134
|
-
case wgpu::FeatureName::Norm16TextureFormats:
|
|
135
|
-
*outUnion = "norm16-texture-formats";
|
|
136
|
-
break;
|
|
137
128
|
case wgpu::FeatureName::MultiPlanarFormatNv16:
|
|
138
129
|
*outUnion = "multi-planar-format-nv16";
|
|
139
130
|
break;
|
|
@@ -204,7 +195,7 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
|
204
195
|
*outUnion = "dawn-load-resolve-texture";
|
|
205
196
|
break;
|
|
206
197
|
default:
|
|
207
|
-
|
|
198
|
+
fprintf(stderr, "Unknown feature name %d\n", static_cast<int>(inEnum));
|
|
208
199
|
*outUnion = "";
|
|
209
200
|
}
|
|
210
201
|
}
|
|
@@ -21,8 +21,10 @@ class GPUTexture : public NativeObject<GPUTexture> {
|
|
|
21
21
|
public:
|
|
22
22
|
static constexpr const char *CLASS_NAME = "GPUTexture";
|
|
23
23
|
|
|
24
|
-
explicit GPUTexture(wgpu::Texture instance, std::string label
|
|
25
|
-
|
|
24
|
+
explicit GPUTexture(wgpu::Texture instance, std::string label,
|
|
25
|
+
bool reportsMemoryPressure = true)
|
|
26
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label),
|
|
27
|
+
_reportsMemoryPressure(reportsMemoryPressure) {}
|
|
26
28
|
|
|
27
29
|
public:
|
|
28
30
|
std::string getBrand() { return CLASS_NAME; }
|
|
@@ -68,6 +70,9 @@ public:
|
|
|
68
70
|
inline const wgpu::Texture get() { return _instance; }
|
|
69
71
|
|
|
70
72
|
size_t getMemoryPressure() override {
|
|
73
|
+
if (!_reportsMemoryPressure) {
|
|
74
|
+
return sizeof(GPUTexture);
|
|
75
|
+
}
|
|
71
76
|
// Calculate approximate memory usage based on texture properties
|
|
72
77
|
uint32_t width = getWidth();
|
|
73
78
|
uint32_t height = getHeight();
|
|
@@ -85,6 +90,7 @@ public:
|
|
|
85
90
|
case wgpu::TextureFormat::R8Snorm:
|
|
86
91
|
case wgpu::TextureFormat::R8Uint:
|
|
87
92
|
case wgpu::TextureFormat::R8Sint:
|
|
93
|
+
case wgpu::TextureFormat::Stencil8:
|
|
88
94
|
bytesPerPixel = 1;
|
|
89
95
|
break;
|
|
90
96
|
case wgpu::TextureFormat::R16Uint:
|
|
@@ -94,6 +100,7 @@ public:
|
|
|
94
100
|
case wgpu::TextureFormat::RG8Snorm:
|
|
95
101
|
case wgpu::TextureFormat::RG8Uint:
|
|
96
102
|
case wgpu::TextureFormat::RG8Sint:
|
|
103
|
+
case wgpu::TextureFormat::Depth16Unorm:
|
|
97
104
|
bytesPerPixel = 2;
|
|
98
105
|
break;
|
|
99
106
|
case wgpu::TextureFormat::RGBA8Unorm:
|
|
@@ -110,6 +117,9 @@ public:
|
|
|
110
117
|
case wgpu::TextureFormat::RG16Uint:
|
|
111
118
|
case wgpu::TextureFormat::RG16Sint:
|
|
112
119
|
case wgpu::TextureFormat::RG16Float:
|
|
120
|
+
case wgpu::TextureFormat::Depth24Plus:
|
|
121
|
+
case wgpu::TextureFormat::Depth24PlusStencil8:
|
|
122
|
+
case wgpu::TextureFormat::Depth32Float:
|
|
113
123
|
bytesPerPixel = 4;
|
|
114
124
|
break;
|
|
115
125
|
case wgpu::TextureFormat::RG32Float:
|
|
@@ -118,6 +128,7 @@ public:
|
|
|
118
128
|
case wgpu::TextureFormat::RGBA16Uint:
|
|
119
129
|
case wgpu::TextureFormat::RGBA16Sint:
|
|
120
130
|
case wgpu::TextureFormat::RGBA16Float:
|
|
131
|
+
case wgpu::TextureFormat::Depth32FloatStencil8:
|
|
121
132
|
bytesPerPixel = 8;
|
|
122
133
|
break;
|
|
123
134
|
case wgpu::TextureFormat::RGBA32Float:
|
|
@@ -145,6 +156,7 @@ public:
|
|
|
145
156
|
private:
|
|
146
157
|
wgpu::Texture _instance;
|
|
147
158
|
std::string _label;
|
|
159
|
+
bool _reportsMemoryPressure = true;
|
|
148
160
|
};
|
|
149
161
|
|
|
150
162
|
} // namespace rnwgpu
|
|
@@ -103,8 +103,7 @@ public:
|
|
|
103
103
|
auto bufferVal = obj.getProperty(runtime, "buffer");
|
|
104
104
|
if (bufferVal.isObject() &&
|
|
105
105
|
bufferVal.getObject(runtime).isArrayBuffer(runtime)) {
|
|
106
|
-
const auto &ab =
|
|
107
|
-
bufferVal.getObject(runtime).getArrayBuffer(runtime);
|
|
106
|
+
const auto &ab = bufferVal.getObject(runtime).getArrayBuffer(runtime);
|
|
108
107
|
auto byteOffset = static_cast<size_t>(
|
|
109
108
|
obj.getProperty(runtime, "byteOffset").asNumber());
|
|
110
109
|
auto byteLength = static_cast<size_t>(
|
|
@@ -120,15 +119,13 @@ public:
|
|
|
120
119
|
|
|
121
120
|
return Promise::createPromise(
|
|
122
121
|
runtime,
|
|
123
|
-
[platformContext, callInvoker,
|
|
124
|
-
dataCopy = std::move(dataCopy)](
|
|
122
|
+
[platformContext, callInvoker, dataCopy = std::move(dataCopy)](
|
|
125
123
|
jsi::Runtime & /*runtime*/,
|
|
126
124
|
std::shared_ptr<Promise> promise) mutable {
|
|
127
125
|
platformContext->createImageBitmapFromDataAsync(
|
|
128
126
|
dataCopy,
|
|
129
127
|
[callInvoker, promise](ImageData imageData) {
|
|
130
|
-
auto imageBitmap =
|
|
131
|
-
std::make_shared<ImageBitmap>(imageData);
|
|
128
|
+
auto imageBitmap = std::make_shared<ImageBitmap>(imageData);
|
|
132
129
|
callInvoker->invokeAsync([promise, imageBitmap]() {
|
|
133
130
|
promise->resolve(
|
|
134
131
|
JSIConverter<std::shared_ptr<ImageBitmap>>::toJSI(
|
|
@@ -158,12 +155,11 @@ public:
|
|
|
158
155
|
blobId, offset, size,
|
|
159
156
|
[callInvoker, promise](ImageData imageData) {
|
|
160
157
|
auto imageBitmap = std::make_shared<ImageBitmap>(imageData);
|
|
161
|
-
callInvoker->invokeAsync(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
});
|
|
158
|
+
callInvoker->invokeAsync([promise, imageBitmap]() {
|
|
159
|
+
promise->resolve(
|
|
160
|
+
JSIConverter<std::shared_ptr<ImageBitmap>>::toJSI(
|
|
161
|
+
promise->runtime, imageBitmap));
|
|
162
|
+
});
|
|
167
163
|
},
|
|
168
164
|
[callInvoker, promise](std::string error) {
|
|
169
165
|
callInvoker->invokeAsync(
|
|
@@ -463,8 +463,6 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
|
|
|
463
463
|
*outEnum = wgpu::FeatureName::PixelLocalStorageNonCoherent;
|
|
464
464
|
} else if (inUnion == "unorm16-texture-formats") {
|
|
465
465
|
*outEnum = wgpu::FeatureName::Unorm16TextureFormats;
|
|
466
|
-
} else if (inUnion == "snorm16-texture-formats") {
|
|
467
|
-
*outEnum = wgpu::FeatureName::Snorm16TextureFormats;
|
|
468
466
|
} else if (inUnion == "multi-planar-format-extended-usages") {
|
|
469
467
|
*outEnum = wgpu::FeatureName::MultiPlanarFormatExtendedUsages;
|
|
470
468
|
} else if (inUnion == "multi-planar-format-p010") {
|
|
@@ -485,12 +483,8 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
|
|
|
485
483
|
*outEnum = wgpu::FeatureName::AdapterPropertiesD3D;
|
|
486
484
|
} else if (inUnion == "adapter-properties-vk") {
|
|
487
485
|
*outEnum = wgpu::FeatureName::AdapterPropertiesVk;
|
|
488
|
-
} else if (inUnion == "r8unorm-storage") {
|
|
489
|
-
*outEnum = wgpu::FeatureName::R8UnormStorage;
|
|
490
486
|
} else if (inUnion == "format-capabilities") {
|
|
491
487
|
*outEnum = wgpu::FeatureName::DawnFormatCapabilities;
|
|
492
|
-
} else if (inUnion == "norm16-texture-formats") {
|
|
493
|
-
*outEnum = wgpu::FeatureName::Norm16TextureFormats;
|
|
494
488
|
} else if (inUnion == "multi-planar-format-nv16") {
|
|
495
489
|
*outEnum = wgpu::FeatureName::MultiPlanarFormatNv16;
|
|
496
490
|
} else if (inUnion == "multi-planar-format-nv24") {
|
|
@@ -629,9 +623,6 @@ inline void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
|
629
623
|
case wgpu::FeatureName::Unorm16TextureFormats:
|
|
630
624
|
*outUnion = "unorm16-texture-formats";
|
|
631
625
|
break;
|
|
632
|
-
case wgpu::FeatureName::Snorm16TextureFormats:
|
|
633
|
-
*outUnion = "snorm16-texture-formats";
|
|
634
|
-
break;
|
|
635
626
|
case wgpu::FeatureName::MultiPlanarFormatExtendedUsages:
|
|
636
627
|
*outUnion = "multi-planar-format-extended-usages";
|
|
637
628
|
break;
|
|
@@ -662,12 +653,6 @@ inline void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
|
662
653
|
case wgpu::FeatureName::AdapterPropertiesVk:
|
|
663
654
|
*outUnion = "adapter-properties-vk";
|
|
664
655
|
break;
|
|
665
|
-
case wgpu::FeatureName::R8UnormStorage:
|
|
666
|
-
*outUnion = "r8unorm-storage";
|
|
667
|
-
break;
|
|
668
|
-
case wgpu::FeatureName::Norm16TextureFormats:
|
|
669
|
-
*outUnion = "norm16-texture-formats";
|
|
670
|
-
break;
|
|
671
656
|
case wgpu::FeatureName::MultiPlanarFormatNv16:
|
|
672
657
|
*outUnion = "multi-planar-format-nv16";
|
|
673
658
|
break;
|