react-native-webgpu 0.13.0 → 0.14.0
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 -0
- package/android/cpp/AndroidPlatformContext.h +0 -9
- package/android/cpp/cpp-adapter.cpp +6 -4
- package/android/src/main/java/com/webgpu/WebGPUView.java +8 -0
- package/apple/ApplePlatformContext.h +0 -3
- package/apple/ApplePlatformContext.mm +0 -10
- package/apple/MetalView.mm +4 -3
- package/cpp/jsi/JSIConverter.h +6 -11
- package/cpp/jsi/NativeObject.h +130 -18
- package/cpp/rnwgpu/EnforceRange.h +68 -0
- package/cpp/rnwgpu/PlatformContext.h +0 -2
- package/cpp/rnwgpu/RNWebGPUManager.cpp +7 -95
- package/cpp/rnwgpu/RNWebGPUManager.h +4 -3
- package/cpp/rnwgpu/WebGPURuntime.cpp +91 -0
- package/cpp/rnwgpu/WebGPURuntime.h +36 -0
- package/cpp/rnwgpu/api/Convertors.h +10 -1
- package/cpp/rnwgpu/api/GPU.cpp +3 -57
- package/cpp/rnwgpu/api/GPUError.h +15 -0
- package/cpp/rnwgpu/api/GPUInternalError.h +2 -0
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +2 -0
- package/cpp/rnwgpu/api/GPUQueue.cpp +7 -21
- package/cpp/rnwgpu/api/GPUTexture.h +6 -0
- package/cpp/rnwgpu/api/GPUValidationError.h +2 -0
- package/cpp/rnwgpu/api/descriptors/Unions.h +80 -0
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +13 -3
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
- package/lib/commonjs/install.js +6 -7
- package/lib/commonjs/install.js.map +1 -1
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js +13 -3
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
- package/lib/module/install.js +6 -7
- package/lib/module/install.js.map +1 -1
- package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/install.d.ts.map +1 -1
- package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
- package/lib/typescript/lib/module/install.d.ts.map +1 -1
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +12 -0
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
- package/lib/typescript/src/install.d.ts +6 -7
- package/lib/typescript/src/install.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/external/reanimated/registerWebGPUForReanimated.ts +29 -7
- package/src/install.ts +6 -7
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#include "WebGPURuntime.h"
|
|
2
|
+
|
|
3
|
+
#include <dlfcn.h>
|
|
4
|
+
|
|
5
|
+
#include <iterator>
|
|
6
|
+
|
|
7
|
+
namespace rnwgpu {
|
|
8
|
+
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
wgpu::Instance createInstance() {
|
|
12
|
+
// If a Graphite build of react-native-skia is loaded in this
|
|
13
|
+
// process, adopt its wgpu::Instance instead of creating our own, so
|
|
14
|
+
// Graphite's device and every JS-created device live on one instance. That
|
|
15
|
+
// makes pointer-based handoff (RNWebGPU.importDevice of Skia's device)
|
|
16
|
+
// sound: the async pump serves the shared instance, so callbacks on
|
|
17
|
+
// imported devices settle. Discovered at runtime via dlsym so there is no
|
|
18
|
+
// build-time coupling and native-module init order does not matter. Both
|
|
19
|
+
// packages must link the same single Dawn copy (they vendor the same
|
|
20
|
+
// artifact) for the handle to be meaningful.
|
|
21
|
+
using GetInstanceFn = WGPUInstance (*)();
|
|
22
|
+
if (auto getSkiaInstance = reinterpret_cast<GetInstanceFn>(
|
|
23
|
+
dlsym(RTLD_DEFAULT, "rnskia_getWGPUInstance"))) {
|
|
24
|
+
if (WGPUInstance external = getSkiaInstance()) {
|
|
25
|
+
wgpuInstanceAddRef(external);
|
|
26
|
+
return wgpu::Instance::Acquire(external);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static const auto kTimedWaitAny = wgpu::InstanceFeatureName::TimedWaitAny;
|
|
31
|
+
wgpu::InstanceDescriptor instanceDesc{.requiredFeatureCount = 1,
|
|
32
|
+
.requiredFeatures = &kTimedWaitAny};
|
|
33
|
+
|
|
34
|
+
wgpu::InstanceLimits limits{.timedWaitAnyMaxCount = 64};
|
|
35
|
+
instanceDesc.requiredLimits = &limits;
|
|
36
|
+
|
|
37
|
+
// Expose Dawn's experimental adapter features. Several features needed by
|
|
38
|
+
// our Android external-texture path (YCbCrVulkanSamplers,
|
|
39
|
+
// OpaqueYCbCrAndroidForExternalTexture) are tagged Experimental in Dawn's
|
|
40
|
+
// feature table and are otherwise filtered out of adapter.features by
|
|
41
|
+
// PhysicalDeviceBase::GetSupportedFeatures. The allow_unsafe_apis toggle
|
|
42
|
+
// disables that filter so the features become visible;
|
|
43
|
+
// expose_wgsl_experimental_features is the parallel toggle for WGSL language
|
|
44
|
+
// features.
|
|
45
|
+
//
|
|
46
|
+
// Trade-off: these are instance-level Dawn toggles, so they apply to every
|
|
47
|
+
// adapter/device created from this instance, not just the external-texture
|
|
48
|
+
// path. There is no finer-grained, per-feature mechanism to surface these.
|
|
49
|
+
// The exposure is acceptable because the toggle only *un-hides* experimental
|
|
50
|
+
// features in adapter.features; it does not enable any of them. Nothing
|
|
51
|
+
// experimental becomes active unless application code explicitly lists that
|
|
52
|
+
// feature in requiredFeatures at device creation, so the default behavior of
|
|
53
|
+
// a device that asks for no experimental features is unchanged.
|
|
54
|
+
static const char *const kEnabledToggles[] = {
|
|
55
|
+
"allow_unsafe_apis",
|
|
56
|
+
"expose_wgsl_experimental_features",
|
|
57
|
+
};
|
|
58
|
+
wgpu::DawnTogglesDescriptor toggles;
|
|
59
|
+
toggles.enabledToggleCount = std::size(kEnabledToggles);
|
|
60
|
+
toggles.enabledToggles = kEnabledToggles;
|
|
61
|
+
instanceDesc.nextInChain = &toggles;
|
|
62
|
+
|
|
63
|
+
return wgpu::CreateInstance(&instanceDesc);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} // namespace
|
|
67
|
+
|
|
68
|
+
WebGPURuntime &WebGPURuntime::shared() {
|
|
69
|
+
static auto *runtime = new WebGPURuntime();
|
|
70
|
+
return *runtime;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
wgpu::Instance WebGPURuntime::instance() {
|
|
74
|
+
std::call_once(_instanceOnce, [this] { _instance = createInstance(); });
|
|
75
|
+
return _instance;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
wgpu::Surface WebGPURuntime::makeSurface(void *nativeSurface) {
|
|
79
|
+
#if defined(__ANDROID__)
|
|
80
|
+
wgpu::SurfaceSourceAndroidNativeWindow source;
|
|
81
|
+
source.window = nativeSurface;
|
|
82
|
+
#else
|
|
83
|
+
wgpu::SurfaceSourceMetalLayer source;
|
|
84
|
+
source.layer = nativeSurface;
|
|
85
|
+
#endif
|
|
86
|
+
wgpu::SurfaceDescriptor descriptor;
|
|
87
|
+
descriptor.nextInChain = &source;
|
|
88
|
+
return instance().CreateSurface(&descriptor);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <mutex>
|
|
4
|
+
|
|
5
|
+
#include "webgpu/webgpu_cpp.h"
|
|
6
|
+
|
|
7
|
+
namespace rnwgpu {
|
|
8
|
+
|
|
9
|
+
// Process-lifetime GPU state shared by every React instance, JS runtime and
|
|
10
|
+
// thread. It holds nothing tied to one React instance (no jsi::Runtime,
|
|
11
|
+
// CallInvoker or BlobModule): those stay with the per-instance module.
|
|
12
|
+
// Intentionally never destroyed, so there is no static-destruction ordering to
|
|
13
|
+
// get wrong and it outlives a React reload.
|
|
14
|
+
class WebGPURuntime {
|
|
15
|
+
public:
|
|
16
|
+
static WebGPURuntime &shared();
|
|
17
|
+
|
|
18
|
+
// The process-wide instance: Skia Graphite's when that is loaded, otherwise
|
|
19
|
+
// our own. Created on first use. Safe to call from any thread.
|
|
20
|
+
wgpu::Instance instance();
|
|
21
|
+
|
|
22
|
+
// Creates a surface on the shared instance for a CAMetalLayer (Apple) or an
|
|
23
|
+
// ANativeWindow (Android). Safe to call from any thread.
|
|
24
|
+
wgpu::Surface makeSurface(void *nativeSurface);
|
|
25
|
+
|
|
26
|
+
WebGPURuntime(const WebGPURuntime &) = delete;
|
|
27
|
+
WebGPURuntime &operator=(const WebGPURuntime &) = delete;
|
|
28
|
+
|
|
29
|
+
private:
|
|
30
|
+
WebGPURuntime() = default;
|
|
31
|
+
|
|
32
|
+
std::once_flag _instanceOnce;
|
|
33
|
+
wgpu::Instance _instance;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
} // namespace rnwgpu
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
#include "webgpu/webgpu_cpp.h"
|
|
12
12
|
|
|
13
|
+
#include "EnforceRange.h"
|
|
13
14
|
#include "GPUBindGroupDescriptor.h"
|
|
14
15
|
#include "GPUBindGroupEntry.h"
|
|
15
16
|
#include "GPUBindGroupLayoutDescriptor.h"
|
|
@@ -161,11 +162,19 @@ public:
|
|
|
161
162
|
return true;
|
|
162
163
|
}
|
|
163
164
|
|
|
165
|
+
// JS numbers destined for an integer field are WebIDL [EnforceRange]
|
|
166
|
+
// integers in WebGPU, so an out-of-range value is a TypeError rather than a
|
|
167
|
+
// silent wrap (and an undefined cast). Flags are enums here and keep the
|
|
168
|
+
// plain cast, as GPUFlagsConstant is not [EnforceRange].
|
|
164
169
|
template <typename T>
|
|
165
170
|
[[nodiscard]] typename std::enable_if<
|
|
166
171
|
(std::is_arithmetic<T>::value || std::is_enum<T>::value), bool>::type
|
|
167
172
|
Convert(T &out, const double &in) {
|
|
168
|
-
|
|
173
|
+
if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) {
|
|
174
|
+
out = enforceRange<T>(in);
|
|
175
|
+
} else {
|
|
176
|
+
out = static_cast<T>(in);
|
|
177
|
+
}
|
|
169
178
|
return true;
|
|
170
179
|
}
|
|
171
180
|
|
package/cpp/rnwgpu/api/GPU.cpp
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
#include "GPU.h"
|
|
2
2
|
|
|
3
|
-
#include <dlfcn.h>
|
|
4
|
-
|
|
5
3
|
#include <cstdio>
|
|
6
4
|
#include <memory>
|
|
7
5
|
#include <string>
|
|
@@ -11,65 +9,13 @@
|
|
|
11
9
|
|
|
12
10
|
#include "Convertors.h"
|
|
13
11
|
#include "JSIConverter.h"
|
|
12
|
+
#include "WebGPURuntime.h"
|
|
14
13
|
#include "rnwgpu/async/RuntimeContext.h"
|
|
15
14
|
|
|
16
15
|
namespace rnwgpu {
|
|
17
16
|
|
|
18
|
-
GPU::GPU(jsi::Runtime & /*runtime*/)
|
|
19
|
-
|
|
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
|
-
|
|
38
|
-
static const auto kTimedWaitAny = wgpu::InstanceFeatureName::TimedWaitAny;
|
|
39
|
-
wgpu::InstanceDescriptor instanceDesc{.requiredFeatureCount = 1,
|
|
40
|
-
.requiredFeatures = &kTimedWaitAny};
|
|
41
|
-
|
|
42
|
-
wgpu::InstanceLimits limits{.timedWaitAnyMaxCount = 64};
|
|
43
|
-
instanceDesc.requiredLimits = &limits;
|
|
44
|
-
|
|
45
|
-
// Expose Dawn's experimental adapter features. Several features needed by
|
|
46
|
-
// our Android external-texture path (YCbCrVulkanSamplers,
|
|
47
|
-
// OpaqueYCbCrAndroidForExternalTexture) are tagged Experimental in Dawn's
|
|
48
|
-
// feature table and are otherwise filtered out of adapter.features by
|
|
49
|
-
// PhysicalDeviceBase::GetSupportedFeatures. The allow_unsafe_apis toggle
|
|
50
|
-
// disables that filter so the features become visible;
|
|
51
|
-
// expose_wgsl_experimental_features is the parallel toggle for WGSL language
|
|
52
|
-
// features.
|
|
53
|
-
//
|
|
54
|
-
// Trade-off: these are instance-level Dawn toggles, so they apply to every
|
|
55
|
-
// adapter/device created from this instance, not just the external-texture
|
|
56
|
-
// path. There is no finer-grained, per-feature mechanism to surface these.
|
|
57
|
-
// The exposure is acceptable because the toggle only *un-hides* experimental
|
|
58
|
-
// features in adapter.features; it does not enable any of them. Nothing
|
|
59
|
-
// experimental becomes active unless application code explicitly lists that
|
|
60
|
-
// feature in requiredFeatures at device creation, so the default behavior of
|
|
61
|
-
// a device that asks for no experimental features is unchanged.
|
|
62
|
-
static const char *const kEnabledToggles[] = {
|
|
63
|
-
"allow_unsafe_apis",
|
|
64
|
-
"expose_wgsl_experimental_features",
|
|
65
|
-
};
|
|
66
|
-
wgpu::DawnTogglesDescriptor toggles;
|
|
67
|
-
toggles.enabledToggleCount = std::size(kEnabledToggles);
|
|
68
|
-
toggles.enabledToggles = kEnabledToggles;
|
|
69
|
-
instanceDesc.nextInChain = &toggles;
|
|
70
|
-
|
|
71
|
-
_instance = wgpu::CreateInstance(&instanceDesc);
|
|
72
|
-
}
|
|
17
|
+
GPU::GPU(jsi::Runtime & /*runtime*/)
|
|
18
|
+
: NativeObject(CLASS_NAME), _instance(WebGPURuntime::shared().instance()) {}
|
|
73
19
|
|
|
74
20
|
async::AsyncTaskHandle GPU::requestAdapter(
|
|
75
21
|
jsi::Runtime &runtime,
|
|
@@ -24,6 +24,21 @@ public:
|
|
|
24
24
|
installGetter(runtime, prototype, "message", &GPUError::getMessage);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
// GPUValidationError, GPUOutOfMemoryError and GPUInternalError extend
|
|
28
|
+
// GPUError in the spec: chain their prototype to GPUError.prototype so
|
|
29
|
+
// `error instanceof GPUError` holds.
|
|
30
|
+
static void inheritPrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
31
|
+
installPrototype(runtime);
|
|
32
|
+
auto *parent = getCachedPrototype(runtime);
|
|
33
|
+
if (parent == nullptr) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
auto objectCtor = runtime.global().getPropertyAsObject(runtime, "Object");
|
|
37
|
+
auto setPrototypeOf =
|
|
38
|
+
objectCtor.getPropertyAsFunction(runtime, "setPrototypeOf");
|
|
39
|
+
setPrototypeOf.call(runtime, prototype, *parent);
|
|
40
|
+
}
|
|
41
|
+
|
|
27
42
|
protected:
|
|
28
43
|
// Protected constructor for subclasses
|
|
29
44
|
GPUError(const char *className, std::string message)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include <string>
|
|
4
4
|
|
|
5
|
+
#include "GPUError.h"
|
|
5
6
|
#include "NativeObject.h"
|
|
6
7
|
|
|
7
8
|
namespace rnwgpu {
|
|
@@ -20,6 +21,7 @@ public:
|
|
|
20
21
|
std::string getMessage() { return _message; }
|
|
21
22
|
|
|
22
23
|
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
24
|
+
GPUError::inheritPrototype(runtime, prototype);
|
|
23
25
|
installGetter(runtime, prototype, "__brand", &GPUInternalError::getBrand);
|
|
24
26
|
installGetter(runtime, prototype, "message", &GPUInternalError::getMessage);
|
|
25
27
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include <string>
|
|
4
4
|
|
|
5
|
+
#include "GPUError.h"
|
|
5
6
|
#include "NativeObject.h"
|
|
6
7
|
|
|
7
8
|
namespace rnwgpu {
|
|
@@ -20,6 +21,7 @@ public:
|
|
|
20
21
|
std::string getMessage() { return _message; }
|
|
21
22
|
|
|
22
23
|
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
24
|
+
GPUError::inheritPrototype(runtime, prototype);
|
|
23
25
|
installGetter(runtime, prototype, "__brand",
|
|
24
26
|
&GPUOutOfMemoryError::getBrand);
|
|
25
27
|
installGetter(runtime, prototype, "message",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#include <vector>
|
|
10
10
|
|
|
11
11
|
#include "Convertors.h"
|
|
12
|
+
#include "EnforceRange.h"
|
|
12
13
|
#include "ImageBitmap.h"
|
|
13
14
|
#include "PlatformContext.h"
|
|
14
15
|
|
|
@@ -126,15 +127,9 @@ void GPUQueue::copyVideoFrameToTexture(
|
|
|
126
127
|
throw std::runtime_error(
|
|
127
128
|
"copyExternalImageToTexture: a native frame is a single 2D image");
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (!(value >= 0) || value > kMaxCoordinate) {
|
|
133
|
-
throw std::runtime_error(std::string("copyExternalImageToTexture: ") +
|
|
134
|
-
name +
|
|
135
|
-
" must be a non-negative integer coordinate");
|
|
136
|
-
}
|
|
137
|
-
return static_cast<uint32_t>(value);
|
|
130
|
+
// GPUOrigin2D coordinates are [EnforceRange] unsigned long.
|
|
131
|
+
auto coordinate = [](double value, const char * /*name*/) {
|
|
132
|
+
return enforceRange<uint32_t>(value);
|
|
138
133
|
};
|
|
139
134
|
const double rotation = source.rotation.value_or(0);
|
|
140
135
|
if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270) {
|
|
@@ -208,18 +203,9 @@ void GPUQueue::copyExternalImageToTexture(
|
|
|
208
203
|
}
|
|
209
204
|
|
|
210
205
|
const auto origin = source->origin.value_or(nullptr);
|
|
211
|
-
// GPUOrigin2D coordinates are [EnforceRange] unsigned long
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
constexpr double kMaxOrigin =
|
|
215
|
-
static_cast<double>(std::numeric_limits<uint32_t>::max());
|
|
216
|
-
if (origin && (!(origin->x >= 0) || !(origin->y >= 0) ||
|
|
217
|
-
origin->x > kMaxOrigin || origin->y > kMaxOrigin)) {
|
|
218
|
-
throw std::runtime_error(
|
|
219
|
-
"The source origin must be a non-negative integer coordinate.");
|
|
220
|
-
}
|
|
221
|
-
const size_t sourceOriginX = origin ? static_cast<size_t>(origin->x) : 0;
|
|
222
|
-
const size_t sourceOriginY = origin ? static_cast<size_t>(origin->y) : 0;
|
|
206
|
+
// GPUOrigin2D coordinates are [EnforceRange] unsigned long.
|
|
207
|
+
const size_t sourceOriginX = origin ? enforceRange<uint32_t>(origin->x) : 0;
|
|
208
|
+
const size_t sourceOriginY = origin ? enforceRange<uint32_t>(origin->y) : 0;
|
|
223
209
|
if (sourceOriginX > source->source->getWidth() ||
|
|
224
210
|
sz.width > source->source->getWidth() - sourceOriginX ||
|
|
225
211
|
sourceOriginY > source->source->getHeight() ||
|
|
@@ -101,6 +101,8 @@ public:
|
|
|
101
101
|
case wgpu::TextureFormat::Stencil8:
|
|
102
102
|
bytesPerPixel = 1;
|
|
103
103
|
break;
|
|
104
|
+
case wgpu::TextureFormat::R16Unorm:
|
|
105
|
+
case wgpu::TextureFormat::R16Snorm:
|
|
104
106
|
case wgpu::TextureFormat::R16Uint:
|
|
105
107
|
case wgpu::TextureFormat::R16Sint:
|
|
106
108
|
case wgpu::TextureFormat::R16Float:
|
|
@@ -122,6 +124,8 @@ public:
|
|
|
122
124
|
case wgpu::TextureFormat::R32Float:
|
|
123
125
|
case wgpu::TextureFormat::R32Uint:
|
|
124
126
|
case wgpu::TextureFormat::R32Sint:
|
|
127
|
+
case wgpu::TextureFormat::RG16Unorm:
|
|
128
|
+
case wgpu::TextureFormat::RG16Snorm:
|
|
125
129
|
case wgpu::TextureFormat::RG16Uint:
|
|
126
130
|
case wgpu::TextureFormat::RG16Sint:
|
|
127
131
|
case wgpu::TextureFormat::RG16Float:
|
|
@@ -133,6 +137,8 @@ public:
|
|
|
133
137
|
case wgpu::TextureFormat::RG32Float:
|
|
134
138
|
case wgpu::TextureFormat::RG32Uint:
|
|
135
139
|
case wgpu::TextureFormat::RG32Sint:
|
|
140
|
+
case wgpu::TextureFormat::RGBA16Unorm:
|
|
141
|
+
case wgpu::TextureFormat::RGBA16Snorm:
|
|
136
142
|
case wgpu::TextureFormat::RGBA16Uint:
|
|
137
143
|
case wgpu::TextureFormat::RGBA16Sint:
|
|
138
144
|
case wgpu::TextureFormat::RGBA16Float:
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include <string>
|
|
4
4
|
|
|
5
|
+
#include "GPUError.h"
|
|
5
6
|
#include "NativeObject.h"
|
|
6
7
|
|
|
7
8
|
namespace rnwgpu {
|
|
@@ -20,6 +21,7 @@ public:
|
|
|
20
21
|
std::string getMessage() { return _message; }
|
|
21
22
|
|
|
22
23
|
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
24
|
+
GPUError::inheritPrototype(runtime, prototype);
|
|
23
25
|
installGetter(runtime, prototype, "__brand", &GPUValidationError::getBrand);
|
|
24
26
|
installGetter(runtime, prototype, "message",
|
|
25
27
|
&GPUValidationError::getMessage);
|
|
@@ -866,6 +866,10 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
|
|
|
866
866
|
*outEnum = wgpu::TextureFormat::R16Sint;
|
|
867
867
|
} else if (inUnion == "r16float") {
|
|
868
868
|
*outEnum = wgpu::TextureFormat::R16Float;
|
|
869
|
+
} else if (inUnion == "r16unorm") {
|
|
870
|
+
*outEnum = wgpu::TextureFormat::R16Unorm;
|
|
871
|
+
} else if (inUnion == "r16snorm") {
|
|
872
|
+
*outEnum = wgpu::TextureFormat::R16Snorm;
|
|
869
873
|
} else if (inUnion == "rg8unorm") {
|
|
870
874
|
*outEnum = wgpu::TextureFormat::RG8Unorm;
|
|
871
875
|
} else if (inUnion == "rg8snorm") {
|
|
@@ -886,6 +890,10 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
|
|
|
886
890
|
*outEnum = wgpu::TextureFormat::RG16Sint;
|
|
887
891
|
} else if (inUnion == "rg16float") {
|
|
888
892
|
*outEnum = wgpu::TextureFormat::RG16Float;
|
|
893
|
+
} else if (inUnion == "rg16unorm") {
|
|
894
|
+
*outEnum = wgpu::TextureFormat::RG16Unorm;
|
|
895
|
+
} else if (inUnion == "rg16snorm") {
|
|
896
|
+
*outEnum = wgpu::TextureFormat::RG16Snorm;
|
|
889
897
|
} else if (inUnion == "rgba8unorm") {
|
|
890
898
|
*outEnum = wgpu::TextureFormat::RGBA8Unorm;
|
|
891
899
|
} else if (inUnion == "rgba8unorm-srgb") {
|
|
@@ -920,6 +928,10 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
|
|
|
920
928
|
*outEnum = wgpu::TextureFormat::RGBA16Sint;
|
|
921
929
|
} else if (inUnion == "rgba16float") {
|
|
922
930
|
*outEnum = wgpu::TextureFormat::RGBA16Float;
|
|
931
|
+
} else if (inUnion == "rgba16unorm") {
|
|
932
|
+
*outEnum = wgpu::TextureFormat::RGBA16Unorm;
|
|
933
|
+
} else if (inUnion == "rgba16snorm") {
|
|
934
|
+
*outEnum = wgpu::TextureFormat::RGBA16Snorm;
|
|
923
935
|
} else if (inUnion == "rgba32uint") {
|
|
924
936
|
*outEnum = wgpu::TextureFormat::RGBA32Uint;
|
|
925
937
|
} else if (inUnion == "rgba32sint") {
|
|
@@ -1072,6 +1084,12 @@ inline void convertEnumToJSUnion(wgpu::TextureFormat inEnum,
|
|
|
1072
1084
|
case wgpu::TextureFormat::R16Float:
|
|
1073
1085
|
*outUnion = "r16float";
|
|
1074
1086
|
break;
|
|
1087
|
+
case wgpu::TextureFormat::R16Unorm:
|
|
1088
|
+
*outUnion = "r16unorm";
|
|
1089
|
+
break;
|
|
1090
|
+
case wgpu::TextureFormat::R16Snorm:
|
|
1091
|
+
*outUnion = "r16snorm";
|
|
1092
|
+
break;
|
|
1075
1093
|
case wgpu::TextureFormat::RG8Unorm:
|
|
1076
1094
|
*outUnion = "rg8unorm";
|
|
1077
1095
|
break;
|
|
@@ -1102,6 +1120,12 @@ inline void convertEnumToJSUnion(wgpu::TextureFormat inEnum,
|
|
|
1102
1120
|
case wgpu::TextureFormat::RG16Float:
|
|
1103
1121
|
*outUnion = "rg16float";
|
|
1104
1122
|
break;
|
|
1123
|
+
case wgpu::TextureFormat::RG16Unorm:
|
|
1124
|
+
*outUnion = "rg16unorm";
|
|
1125
|
+
break;
|
|
1126
|
+
case wgpu::TextureFormat::RG16Snorm:
|
|
1127
|
+
*outUnion = "rg16snorm";
|
|
1128
|
+
break;
|
|
1105
1129
|
case wgpu::TextureFormat::RGBA8Unorm:
|
|
1106
1130
|
*outUnion = "rgba8unorm";
|
|
1107
1131
|
break;
|
|
@@ -1153,6 +1177,12 @@ inline void convertEnumToJSUnion(wgpu::TextureFormat inEnum,
|
|
|
1153
1177
|
case wgpu::TextureFormat::RGBA16Float:
|
|
1154
1178
|
*outUnion = "rgba16float";
|
|
1155
1179
|
break;
|
|
1180
|
+
case wgpu::TextureFormat::RGBA16Unorm:
|
|
1181
|
+
*outUnion = "rgba16unorm";
|
|
1182
|
+
break;
|
|
1183
|
+
case wgpu::TextureFormat::RGBA16Snorm:
|
|
1184
|
+
*outUnion = "rgba16snorm";
|
|
1185
|
+
break;
|
|
1156
1186
|
case wgpu::TextureFormat::RGBA32Uint:
|
|
1157
1187
|
*outUnion = "rgba32uint";
|
|
1158
1188
|
break;
|
|
@@ -1431,38 +1461,56 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
|
|
|
1431
1461
|
*outEnum = wgpu::VertexFormat::Uint8x2;
|
|
1432
1462
|
} else if (inUnion == "uint8x4") {
|
|
1433
1463
|
*outEnum = wgpu::VertexFormat::Uint8x4;
|
|
1464
|
+
} else if (inUnion == "uint8") {
|
|
1465
|
+
*outEnum = wgpu::VertexFormat::Uint8;
|
|
1434
1466
|
} else if (inUnion == "sint8x2") {
|
|
1435
1467
|
*outEnum = wgpu::VertexFormat::Sint8x2;
|
|
1436
1468
|
} else if (inUnion == "sint8x4") {
|
|
1437
1469
|
*outEnum = wgpu::VertexFormat::Sint8x4;
|
|
1470
|
+
} else if (inUnion == "sint8") {
|
|
1471
|
+
*outEnum = wgpu::VertexFormat::Sint8;
|
|
1438
1472
|
} else if (inUnion == "unorm8x2") {
|
|
1439
1473
|
*outEnum = wgpu::VertexFormat::Unorm8x2;
|
|
1440
1474
|
} else if (inUnion == "unorm8x4") {
|
|
1441
1475
|
*outEnum = wgpu::VertexFormat::Unorm8x4;
|
|
1476
|
+
} else if (inUnion == "unorm8") {
|
|
1477
|
+
*outEnum = wgpu::VertexFormat::Unorm8;
|
|
1442
1478
|
} else if (inUnion == "snorm8x2") {
|
|
1443
1479
|
*outEnum = wgpu::VertexFormat::Snorm8x2;
|
|
1444
1480
|
} else if (inUnion == "snorm8x4") {
|
|
1445
1481
|
*outEnum = wgpu::VertexFormat::Snorm8x4;
|
|
1482
|
+
} else if (inUnion == "snorm8") {
|
|
1483
|
+
*outEnum = wgpu::VertexFormat::Snorm8;
|
|
1446
1484
|
} else if (inUnion == "uint16x2") {
|
|
1447
1485
|
*outEnum = wgpu::VertexFormat::Uint16x2;
|
|
1448
1486
|
} else if (inUnion == "uint16x4") {
|
|
1449
1487
|
*outEnum = wgpu::VertexFormat::Uint16x4;
|
|
1488
|
+
} else if (inUnion == "uint16") {
|
|
1489
|
+
*outEnum = wgpu::VertexFormat::Uint16;
|
|
1450
1490
|
} else if (inUnion == "sint16x2") {
|
|
1451
1491
|
*outEnum = wgpu::VertexFormat::Sint16x2;
|
|
1452
1492
|
} else if (inUnion == "sint16x4") {
|
|
1453
1493
|
*outEnum = wgpu::VertexFormat::Sint16x4;
|
|
1494
|
+
} else if (inUnion == "sint16") {
|
|
1495
|
+
*outEnum = wgpu::VertexFormat::Sint16;
|
|
1454
1496
|
} else if (inUnion == "unorm16x2") {
|
|
1455
1497
|
*outEnum = wgpu::VertexFormat::Unorm16x2;
|
|
1456
1498
|
} else if (inUnion == "unorm16x4") {
|
|
1457
1499
|
*outEnum = wgpu::VertexFormat::Unorm16x4;
|
|
1500
|
+
} else if (inUnion == "unorm16") {
|
|
1501
|
+
*outEnum = wgpu::VertexFormat::Unorm16;
|
|
1458
1502
|
} else if (inUnion == "snorm16x2") {
|
|
1459
1503
|
*outEnum = wgpu::VertexFormat::Snorm16x2;
|
|
1460
1504
|
} else if (inUnion == "snorm16x4") {
|
|
1461
1505
|
*outEnum = wgpu::VertexFormat::Snorm16x4;
|
|
1506
|
+
} else if (inUnion == "snorm16") {
|
|
1507
|
+
*outEnum = wgpu::VertexFormat::Snorm16;
|
|
1462
1508
|
} else if (inUnion == "float16x2") {
|
|
1463
1509
|
*outEnum = wgpu::VertexFormat::Float16x2;
|
|
1464
1510
|
} else if (inUnion == "float16x4") {
|
|
1465
1511
|
*outEnum = wgpu::VertexFormat::Float16x4;
|
|
1512
|
+
} else if (inUnion == "float16") {
|
|
1513
|
+
*outEnum = wgpu::VertexFormat::Float16;
|
|
1466
1514
|
} else if (inUnion == "float32") {
|
|
1467
1515
|
*outEnum = wgpu::VertexFormat::Float32;
|
|
1468
1516
|
} else if (inUnion == "float32x2") {
|
|
@@ -1487,6 +1535,8 @@ inline void convertJSUnionToEnum(const std::string &inUnion,
|
|
|
1487
1535
|
*outEnum = wgpu::VertexFormat::Sint32x4;
|
|
1488
1536
|
} else if (inUnion == "unorm10-10-10-2") {
|
|
1489
1537
|
*outEnum = wgpu::VertexFormat::Unorm10_10_10_2;
|
|
1538
|
+
} else if (inUnion == "unorm8x4-bgra") {
|
|
1539
|
+
*outEnum = wgpu::VertexFormat::Unorm8x4BGRA;
|
|
1490
1540
|
} else {
|
|
1491
1541
|
throw invalidUnion(inUnion);
|
|
1492
1542
|
}
|
|
@@ -1504,54 +1554,81 @@ inline void convertEnumToJSUnion(wgpu::VertexFormat inEnum,
|
|
|
1504
1554
|
case wgpu::VertexFormat::Uint8x4:
|
|
1505
1555
|
*outUnion = "uint8x4";
|
|
1506
1556
|
break;
|
|
1557
|
+
case wgpu::VertexFormat::Uint8:
|
|
1558
|
+
*outUnion = "uint8";
|
|
1559
|
+
break;
|
|
1507
1560
|
case wgpu::VertexFormat::Sint8x2:
|
|
1508
1561
|
*outUnion = "sint8x2";
|
|
1509
1562
|
break;
|
|
1510
1563
|
case wgpu::VertexFormat::Sint8x4:
|
|
1511
1564
|
*outUnion = "sint8x4";
|
|
1512
1565
|
break;
|
|
1566
|
+
case wgpu::VertexFormat::Sint8:
|
|
1567
|
+
*outUnion = "sint8";
|
|
1568
|
+
break;
|
|
1513
1569
|
case wgpu::VertexFormat::Unorm8x2:
|
|
1514
1570
|
*outUnion = "unorm8x2";
|
|
1515
1571
|
break;
|
|
1516
1572
|
case wgpu::VertexFormat::Unorm8x4:
|
|
1517
1573
|
*outUnion = "unorm8x4";
|
|
1518
1574
|
break;
|
|
1575
|
+
case wgpu::VertexFormat::Unorm8:
|
|
1576
|
+
*outUnion = "unorm8";
|
|
1577
|
+
break;
|
|
1519
1578
|
case wgpu::VertexFormat::Snorm8x2:
|
|
1520
1579
|
*outUnion = "snorm8x2";
|
|
1521
1580
|
break;
|
|
1522
1581
|
case wgpu::VertexFormat::Snorm8x4:
|
|
1523
1582
|
*outUnion = "snorm8x4";
|
|
1524
1583
|
break;
|
|
1584
|
+
case wgpu::VertexFormat::Snorm8:
|
|
1585
|
+
*outUnion = "snorm8";
|
|
1586
|
+
break;
|
|
1525
1587
|
case wgpu::VertexFormat::Uint16x2:
|
|
1526
1588
|
*outUnion = "uint16x2";
|
|
1527
1589
|
break;
|
|
1528
1590
|
case wgpu::VertexFormat::Uint16x4:
|
|
1529
1591
|
*outUnion = "uint16x4";
|
|
1530
1592
|
break;
|
|
1593
|
+
case wgpu::VertexFormat::Uint16:
|
|
1594
|
+
*outUnion = "uint16";
|
|
1595
|
+
break;
|
|
1531
1596
|
case wgpu::VertexFormat::Sint16x2:
|
|
1532
1597
|
*outUnion = "sint16x2";
|
|
1533
1598
|
break;
|
|
1534
1599
|
case wgpu::VertexFormat::Sint16x4:
|
|
1535
1600
|
*outUnion = "sint16x4";
|
|
1536
1601
|
break;
|
|
1602
|
+
case wgpu::VertexFormat::Sint16:
|
|
1603
|
+
*outUnion = "sint16";
|
|
1604
|
+
break;
|
|
1537
1605
|
case wgpu::VertexFormat::Unorm16x2:
|
|
1538
1606
|
*outUnion = "unorm16x2";
|
|
1539
1607
|
break;
|
|
1540
1608
|
case wgpu::VertexFormat::Unorm16x4:
|
|
1541
1609
|
*outUnion = "unorm16x4";
|
|
1542
1610
|
break;
|
|
1611
|
+
case wgpu::VertexFormat::Unorm16:
|
|
1612
|
+
*outUnion = "unorm16";
|
|
1613
|
+
break;
|
|
1543
1614
|
case wgpu::VertexFormat::Snorm16x2:
|
|
1544
1615
|
*outUnion = "snorm16x2";
|
|
1545
1616
|
break;
|
|
1546
1617
|
case wgpu::VertexFormat::Snorm16x4:
|
|
1547
1618
|
*outUnion = "snorm16x4";
|
|
1548
1619
|
break;
|
|
1620
|
+
case wgpu::VertexFormat::Snorm16:
|
|
1621
|
+
*outUnion = "snorm16";
|
|
1622
|
+
break;
|
|
1549
1623
|
case wgpu::VertexFormat::Float16x2:
|
|
1550
1624
|
*outUnion = "float16x2";
|
|
1551
1625
|
break;
|
|
1552
1626
|
case wgpu::VertexFormat::Float16x4:
|
|
1553
1627
|
*outUnion = "float16x4";
|
|
1554
1628
|
break;
|
|
1629
|
+
case wgpu::VertexFormat::Float16:
|
|
1630
|
+
*outUnion = "float16";
|
|
1631
|
+
break;
|
|
1555
1632
|
case wgpu::VertexFormat::Float32:
|
|
1556
1633
|
*outUnion = "float32";
|
|
1557
1634
|
break;
|
|
@@ -1588,6 +1665,9 @@ inline void convertEnumToJSUnion(wgpu::VertexFormat inEnum,
|
|
|
1588
1665
|
case wgpu::VertexFormat::Unorm10_10_10_2:
|
|
1589
1666
|
*outUnion = "unorm10-10-10-2";
|
|
1590
1667
|
break;
|
|
1668
|
+
case wgpu::VertexFormat::Unorm8x4BGRA:
|
|
1669
|
+
*outUnion = "unorm8x4-bgra";
|
|
1670
|
+
break;
|
|
1591
1671
|
default:
|
|
1592
1672
|
throw invalidEnum(inEnum);
|
|
1593
1673
|
}
|
|
@@ -4,7 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.registerWebGPUForReanimated = void 0;
|
|
7
|
-
//
|
|
7
|
+
// The native half of the serializer (WebGPUWorkletHelpers in
|
|
8
|
+
// cpp/jsi/NativeObject.h), installed on the main runtime by the native module.
|
|
9
|
+
// determine/pack capture it by closure, and worklets hands a HostObject to
|
|
10
|
+
// every runtime by reference, so the serializer works wherever a WebGPU object
|
|
11
|
+
// is captured (Reanimated UI runtime, createWorkletRuntime, Vision Camera frame
|
|
12
|
+
// processors) without installing anything on those runtimes.
|
|
8
13
|
|
|
9
14
|
let isRegistered = false;
|
|
10
15
|
|
|
@@ -19,6 +24,11 @@ const registerWebGPUForReanimated = () => {
|
|
|
19
24
|
return;
|
|
20
25
|
}
|
|
21
26
|
isRegistered = true;
|
|
27
|
+
const helpers = globalThis.__webgpuWorkletHelpers;
|
|
28
|
+
if (helpers === undefined) {
|
|
29
|
+
// The native module is not installed (web, node): nothing to serialize.
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
22
32
|
try {
|
|
23
33
|
const {
|
|
24
34
|
registerCustomSerializable
|
|
@@ -28,12 +38,12 @@ const registerWebGPUForReanimated = () => {
|
|
|
28
38
|
determine: value => {
|
|
29
39
|
"worklet";
|
|
30
40
|
|
|
31
|
-
return
|
|
41
|
+
return helpers.isNativeObject(value);
|
|
32
42
|
},
|
|
33
43
|
pack: value => {
|
|
34
44
|
"worklet";
|
|
35
45
|
|
|
36
|
-
return
|
|
46
|
+
return helpers.box(value);
|
|
37
47
|
},
|
|
38
48
|
unpack: boxed => {
|
|
39
49
|
"worklet";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isRegistered","registerWebGPUForReanimated","registerCustomSerializable","require","name","determine","value","
|
|
1
|
+
{"version":3,"names":["isRegistered","registerWebGPUForReanimated","helpers","globalThis","__webgpuWorkletHelpers","undefined","registerCustomSerializable","require","name","determine","value","isNativeObject","pack","box","unpack","boxed","unbox","exports"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAkBA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,MAAME,OAAO,GAAGC,UAAU,CAACC,sBAAsB;EACjD,IAAIF,OAAO,KAAKG,SAAS,EAAE;IACzB;IACA;EACF;EAEA,IAAI;IACF,MAAM;MAAEC;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOR,OAAO,CAACS,cAAc,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOR,OAAO,CAACW,GAAG,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAAwB,IAAK;QACpC,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC;AAACC,OAAA,CAAAhB,2BAAA,GAAAA,2BAAA","ignoreList":[]}
|