react-native-webgpu 0.11.1 → 0.12.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/cpp/rnwgpu/api/GPUAdapter.cpp +20 -32
- package/cpp/rnwgpu/api/GPUDevice.cpp +1 -6
- package/cpp/rnwgpu/api/GPUExternalTexture.cpp +61 -0
- package/cpp/rnwgpu/api/NativeFrameFeatures.h +40 -0
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +13 -13
- package/package.json +1 -1
- package/cpp/rnwgpu/api/RnFeatures.h +0 -53
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#include "GPUFeatures.h"
|
|
19
19
|
#include "JSIConverter.h"
|
|
20
|
-
#include "
|
|
20
|
+
#include "NativeFrameFeatures.h"
|
|
21
21
|
#include "WGPULogger.h"
|
|
22
22
|
|
|
23
23
|
namespace rnwgpu {
|
|
@@ -25,29 +25,24 @@ namespace rnwgpu {
|
|
|
25
25
|
async::AsyncTaskHandle GPUAdapter::requestDevice(
|
|
26
26
|
jsi::Runtime &runtime,
|
|
27
27
|
std::optional<std::shared_ptr<GPUDeviceDescriptor>> descriptor) {
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
// a no-op and device creation is unaffected.
|
|
36
|
-
// - Requesting a feature the adapter doesn't support makes RequestDevice
|
|
37
|
-
// fail, hence the support check below.
|
|
38
|
-
// Callers can still pass "rnwebgpu/native-texture" explicitly; the dedupe
|
|
39
|
-
// keeps that idempotent.
|
|
28
|
+
// Native frame import (importSharedTextureMemory, importExternalTexture,
|
|
29
|
+
// copyExternalImageToTexture with a NativeVideoFrame) needs no feature
|
|
30
|
+
// request, like importExternalTexture on the web: the Dawn features behind
|
|
31
|
+
// it are added to requiredFeatures here, each one when the adapter supports
|
|
32
|
+
// it. Requesting a feature the adapter lacks would make RequestDevice fail,
|
|
33
|
+
// so a fallback adapter (emulators, the web) still gets a device, without
|
|
34
|
+
// the capability; the first import then reports what is missing.
|
|
40
35
|
{
|
|
41
|
-
auto
|
|
42
|
-
if (!
|
|
36
|
+
auto native = nativeFrameImportFeatures();
|
|
37
|
+
if (!native.empty()) {
|
|
43
38
|
wgpu::SupportedFeatures supported;
|
|
44
39
|
_instance.GetFeatures(&supported);
|
|
45
40
|
std::unordered_set<wgpu::FeatureName> supportedSet(
|
|
46
41
|
supported.features, supported.features + supported.featureCount);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
for (auto f : native) {
|
|
43
|
+
if (supportedSet.count(f) == 0) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
51
46
|
if (!descriptor.has_value()) {
|
|
52
47
|
descriptor = std::make_shared<GPUDeviceDescriptor>();
|
|
53
48
|
}
|
|
@@ -56,11 +51,8 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
|
|
|
56
51
|
desc->requiredFeatures = std::vector<wgpu::FeatureName>{};
|
|
57
52
|
}
|
|
58
53
|
auto &features = desc->requiredFeatures.value();
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
features.end()) {
|
|
62
|
-
features.push_back(f);
|
|
63
|
-
}
|
|
54
|
+
if (std::find(features.begin(), features.end(), f) == features.end()) {
|
|
55
|
+
features.push_back(f);
|
|
64
56
|
}
|
|
65
57
|
}
|
|
66
58
|
}
|
|
@@ -101,8 +93,7 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
|
|
|
101
93
|
if (std::find(features.begin(), features.end(),
|
|
102
94
|
wgpu::FeatureName::ImplicitDeviceSynchronization) ==
|
|
103
95
|
features.end()) {
|
|
104
|
-
features.push_back(
|
|
105
|
-
wgpu::FeatureName::ImplicitDeviceSynchronization);
|
|
96
|
+
features.push_back(wgpu::FeatureName::ImplicitDeviceSynchronization);
|
|
106
97
|
}
|
|
107
98
|
}
|
|
108
99
|
}
|
|
@@ -211,7 +202,8 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
|
|
|
211
202
|
}
|
|
212
203
|
}
|
|
213
204
|
}
|
|
214
|
-
// TODO: in the latest version of Dawn, this won't be needed
|
|
205
|
+
// TODO: in the latest version of Dawn, this won't be needed
|
|
206
|
+
// (https://issues.chromium.org/issues/42241591)
|
|
215
207
|
#if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
|
|
216
208
|
// The iOS Simulator only advertises MTLFeatureSet_iOS_GPUFamily2, so
|
|
217
209
|
// Dawn defaults disable_base_instance/disable_base_vertex on and then
|
|
@@ -311,17 +303,13 @@ std::unordered_set<std::string> GPUAdapter::getFeatures() {
|
|
|
311
303
|
wgpu::SupportedFeatures supportedFeatures;
|
|
312
304
|
_instance.GetFeatures(&supportedFeatures);
|
|
313
305
|
std::unordered_set<std::string> result;
|
|
314
|
-
std::unordered_set<wgpu::FeatureName> enabled;
|
|
315
306
|
for (size_t i = 0; i < supportedFeatures.featureCount; ++i) {
|
|
316
|
-
auto feature = supportedFeatures.features[i];
|
|
317
|
-
enabled.insert(feature);
|
|
318
307
|
std::string name;
|
|
319
|
-
convertEnumToJSUnion(
|
|
308
|
+
convertEnumToJSUnion(supportedFeatures.features[i], &name);
|
|
320
309
|
if (name != "") {
|
|
321
310
|
result.insert(name);
|
|
322
311
|
}
|
|
323
312
|
}
|
|
324
|
-
maybeSynthesizeRnNativeTextureFeature(enabled, result);
|
|
325
313
|
return result;
|
|
326
314
|
}
|
|
327
315
|
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
#include "GPUInternalError.h"
|
|
16
16
|
#include "GPUOutOfMemoryError.h"
|
|
17
17
|
#include "GPUValidationError.h"
|
|
18
|
-
#include "RnFeatures.h"
|
|
19
18
|
#include "SurfaceRegistry.h"
|
|
20
19
|
|
|
21
20
|
namespace rnwgpu {
|
|
@@ -570,15 +569,11 @@ std::unordered_set<std::string> GPUDevice::getFeatures() {
|
|
|
570
569
|
wgpu::SupportedFeatures supportedFeatures;
|
|
571
570
|
_instance.GetFeatures(&supportedFeatures);
|
|
572
571
|
std::unordered_set<std::string> result;
|
|
573
|
-
std::unordered_set<wgpu::FeatureName> enabled;
|
|
574
572
|
for (size_t i = 0; i < supportedFeatures.featureCount; ++i) {
|
|
575
|
-
auto feature = supportedFeatures.features[i];
|
|
576
|
-
enabled.insert(feature);
|
|
577
573
|
std::string name;
|
|
578
|
-
convertEnumToJSUnion(
|
|
574
|
+
convertEnumToJSUnion(supportedFeatures.features[i], &name);
|
|
579
575
|
result.insert(name);
|
|
580
576
|
}
|
|
581
|
-
maybeSynthesizeRnNativeTextureFeature(enabled, result);
|
|
582
577
|
return result;
|
|
583
578
|
}
|
|
584
579
|
|
|
@@ -8,8 +8,47 @@
|
|
|
8
8
|
|
|
9
9
|
#include "GPUExternalTextureDescriptor.h"
|
|
10
10
|
|
|
11
|
+
#if defined(__ANDROID__)
|
|
12
|
+
#include <android/hardware_buffer.h>
|
|
13
|
+
#endif
|
|
14
|
+
|
|
11
15
|
namespace rnwgpu {
|
|
12
16
|
|
|
17
|
+
#if defined(__ANDROID__)
|
|
18
|
+
// Whether Dawn imports an AHardwareBuffer of this format as an
|
|
19
|
+
// OpaqueYCbCrAndroid texture. Mirrors FormatFromAHardwareBufferFormat
|
|
20
|
+
// (dawn/native/AHBFunctions.cpp): the color and depth formats with a WebGPU
|
|
21
|
+
// equivalent import as that format; the YUV formats and the formats outside
|
|
22
|
+
// the public enum, which drivers use for the camera and the video decoder,
|
|
23
|
+
// import as OpaqueYCbCrAndroid.
|
|
24
|
+
static bool isOpaqueYCbCrFormat(uint32_t format) {
|
|
25
|
+
switch (format) {
|
|
26
|
+
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
|
|
27
|
+
case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
|
|
28
|
+
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
|
|
29
|
+
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
|
|
30
|
+
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
|
|
31
|
+
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
|
|
32
|
+
case AHARDWAREBUFFER_FORMAT_BLOB:
|
|
33
|
+
case AHARDWAREBUFFER_FORMAT_D16_UNORM:
|
|
34
|
+
case AHARDWAREBUFFER_FORMAT_D24_UNORM:
|
|
35
|
+
case AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT:
|
|
36
|
+
case AHARDWAREBUFFER_FORMAT_D32_FLOAT:
|
|
37
|
+
case AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT:
|
|
38
|
+
case AHARDWAREBUFFER_FORMAT_S8_UINT:
|
|
39
|
+
// Single-channel formats of the API 33 and 34 headers, by value so that
|
|
40
|
+
// older NDKs compile.
|
|
41
|
+
case 0x38: // AHARDWAREBUFFER_FORMAT_R8_UNORM
|
|
42
|
+
case 0x39: // AHARDWAREBUFFER_FORMAT_R16_UINT
|
|
43
|
+
case 0x3a: // AHARDWAREBUFFER_FORMAT_R16G16_UINT
|
|
44
|
+
case 0x3b: // AHARDWAREBUFFER_FORMAT_R10G10B10A10_UNORM
|
|
45
|
+
return false;
|
|
46
|
+
default:
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
#endif
|
|
51
|
+
|
|
13
52
|
// Identity gamut (BT.709 -> sRGB, same primaries) as a 3x3 column-major matrix.
|
|
14
53
|
static const float kIdentityGamutMatrix[9] = {
|
|
15
54
|
1.0f, 0.0f, 0.0f, //
|
|
@@ -254,6 +293,28 @@ std::shared_ptr<GPUExternalTexture> GPUExternalTexture::Create(
|
|
|
254
293
|
// sampled texel is already RGB.
|
|
255
294
|
kYuvPassthroughMatrix);
|
|
256
295
|
#elif defined(__ANDROID__)
|
|
296
|
+
// 0. A YUV frame imports as an OpaqueYCbCrAndroid texture, which Dawn only
|
|
297
|
+
// accepts on a device with OpaqueYCbCrAndroidForExternalTexture.
|
|
298
|
+
// requestDevice() enables the feature whenever the adapter supports it;
|
|
299
|
+
// a device created by another library (importDevice) has to request it
|
|
300
|
+
// itself. Fail with the cause here: Dawn's own report is a bare
|
|
301
|
+
// "Unsupported texture format TextureFormat::OpaqueYCbCrAndroid" device
|
|
302
|
+
// error, followed by the failure of every call made with the result.
|
|
303
|
+
if (!device.HasFeature(
|
|
304
|
+
wgpu::FeatureName::OpaqueYCbCrAndroidForExternalTexture)) {
|
|
305
|
+
AHardwareBuffer_Desc ahbDesc{};
|
|
306
|
+
AHardwareBuffer_describe(static_cast<AHardwareBuffer *>(frame.handle),
|
|
307
|
+
&ahbDesc);
|
|
308
|
+
if (isOpaqueYCbCrFormat(ahbDesc.format)) {
|
|
309
|
+
throw std::runtime_error(
|
|
310
|
+
"GPUExternalTexture::Create(): a YUV frame can only be imported on "
|
|
311
|
+
"a device with the 'opaque-ycbcr-android-for-external-texture' "
|
|
312
|
+
"feature. requestDevice() enables it whenever the adapter supports "
|
|
313
|
+
"it; a device imported from another library has to request it "
|
|
314
|
+
"itself.");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
257
318
|
// 1. Import the AHardwareBuffer as SharedTextureMemory. For YUV AHBs this
|
|
258
319
|
// yields a Dawn texture in the implementation-defined OpaqueYCbCrAndroid
|
|
259
320
|
// format; for RGBA AHBs, a regular single-plane texture.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <vector>
|
|
4
|
+
|
|
5
|
+
#include "webgpu/webgpu_cpp.h"
|
|
6
|
+
|
|
7
|
+
namespace rnwgpu {
|
|
8
|
+
|
|
9
|
+
// The Dawn features behind native frame import on the current platform:
|
|
10
|
+
// importSharedTextureMemory, importExternalTexture and
|
|
11
|
+
// copyExternalImageToTexture with a NativeVideoFrame. Like
|
|
12
|
+
// importExternalTexture on the web, the capability needs no feature request:
|
|
13
|
+
// requestDevice() enables each of these the adapter supports (see
|
|
14
|
+
// GPUAdapter::requestDevice). A device created by another library and wrapped
|
|
15
|
+
// with importDevice() has to request them itself for its frames to import.
|
|
16
|
+
inline std::vector<wgpu::FeatureName> nativeFrameImportFeatures() {
|
|
17
|
+
#if defined(__APPLE__)
|
|
18
|
+
return {
|
|
19
|
+
// IOSurface import, and the MTLSharedEvent fence that EndAccess exports
|
|
20
|
+
wgpu::FeatureName::SharedTextureMemoryIOSurface,
|
|
21
|
+
wgpu::FeatureName::SharedFenceMTLSharedEvent,
|
|
22
|
+
// The biplanar NV12 layout of camera frames
|
|
23
|
+
wgpu::FeatureName::DawnMultiPlanarFormats,
|
|
24
|
+
};
|
|
25
|
+
#elif defined(__ANDROID__)
|
|
26
|
+
return {
|
|
27
|
+
// AHardwareBuffer import, and the sync-fd fence that EndAccess exports
|
|
28
|
+
wgpu::FeatureName::SharedTextureMemoryAHardwareBuffer,
|
|
29
|
+
wgpu::FeatureName::SharedFenceSyncFD,
|
|
30
|
+
// The YUV buffers of the video decoder and of the camera: Dawn imports
|
|
31
|
+
// them as OpaqueYCbCrAndroid textures, a format it only accepts, and
|
|
32
|
+
// only samples as an external texture, with this feature
|
|
33
|
+
wgpu::FeatureName::OpaqueYCbCrAndroidForExternalTexture,
|
|
34
|
+
};
|
|
35
|
+
#else
|
|
36
|
+
return {};
|
|
37
|
+
#endif
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
} // namespace rnwgpu
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
#include <map>
|
|
4
4
|
#include <memory>
|
|
5
|
+
#include <stdexcept>
|
|
5
6
|
#include <string>
|
|
6
7
|
#include <vector>
|
|
7
8
|
|
|
8
9
|
#include "webgpu/webgpu_cpp.h"
|
|
9
10
|
|
|
10
11
|
#include "JSIConverter.h"
|
|
11
|
-
#include "RnFeatures.h"
|
|
12
12
|
#include "WGPULogger.h"
|
|
13
13
|
|
|
14
14
|
#include "GPUDawnTogglesDescriptor.h"
|
|
@@ -57,13 +57,14 @@ template <> struct JSIConverter<std::vector<wgpu::FeatureName>> {
|
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
auto str = elementValue.asString(runtime).utf8(runtime);
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
// The umbrella feature of earlier versions. Native frame import is on
|
|
61
|
+
// by default now and the name is gone; say so rather than reject it as
|
|
62
|
+
// an unknown feature.
|
|
63
|
+
if (str == "rnwebgpu/native-texture") {
|
|
64
|
+
throw std::runtime_error(
|
|
65
|
+
"requestDevice: the 'rnwebgpu/native-texture' feature has been "
|
|
66
|
+
"removed. Native frame import is enabled by default whenever the "
|
|
67
|
+
"adapter supports it; drop the name from requiredFeatures.");
|
|
67
68
|
}
|
|
68
69
|
vector.emplace_back(JSIConverter<wgpu::FeatureName>::fromJSI(
|
|
69
70
|
runtime, elementValue, outOfBounds));
|
|
@@ -109,13 +110,12 @@ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUDeviceDescriptor>> {
|
|
|
109
110
|
}
|
|
110
111
|
if (value.hasProperty(runtime, "dawnToggles")) {
|
|
111
112
|
auto prop = value.getProperty(runtime, "dawnToggles");
|
|
112
|
-
result->dawnToggles = JSIConverter<
|
|
113
|
-
std::
|
|
114
|
-
|
|
113
|
+
result->dawnToggles = JSIConverter<std::optional<
|
|
114
|
+
std::shared_ptr<GPUDawnTogglesDescriptor>>>::fromJSI(runtime, prop,
|
|
115
|
+
false);
|
|
115
116
|
}
|
|
116
117
|
if (value.hasProperty(runtime, "implicitDeviceSynchronization")) {
|
|
117
|
-
auto prop =
|
|
118
|
-
value.getProperty(runtime, "implicitDeviceSynchronization");
|
|
118
|
+
auto prop = value.getProperty(runtime, "implicitDeviceSynchronization");
|
|
119
119
|
result->implicitDeviceSynchronization =
|
|
120
120
|
JSIConverter<std::optional<bool>>::fromJSI(runtime, prop, false);
|
|
121
121
|
}
|
package/package.json
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <string>
|
|
4
|
-
#include <unordered_set>
|
|
5
|
-
#include <vector>
|
|
6
|
-
|
|
7
|
-
#include "webgpu/webgpu_cpp.h"
|
|
8
|
-
|
|
9
|
-
namespace rnwgpu {
|
|
10
|
-
|
|
11
|
-
// Umbrella feature name owned by react-native-wgpu. Backed by a
|
|
12
|
-
// platform-specific pair of Dawn features. The prefix is intentional: this
|
|
13
|
-
// string is not part of the WebGPU spec, it is our API surface for the
|
|
14
|
-
// "import a native surface as a sampleable texture" capability.
|
|
15
|
-
inline constexpr const char *kRnNativeTextureFeature =
|
|
16
|
-
"rnwebgpu/native-texture";
|
|
17
|
-
|
|
18
|
-
// Dawn features that back the umbrella on the current platform. Empty on
|
|
19
|
-
// platforms where the capability is not available, in which case the umbrella
|
|
20
|
-
// behaves as a no-op (it won't appear in adapter.features and asking for it
|
|
21
|
-
// in requiredFeatures expands to nothing).
|
|
22
|
-
inline std::vector<wgpu::FeatureName> rnNativeTextureBackingFeatures() {
|
|
23
|
-
#if defined(__APPLE__)
|
|
24
|
-
return {wgpu::FeatureName::SharedTextureMemoryIOSurface,
|
|
25
|
-
wgpu::FeatureName::SharedFenceMTLSharedEvent};
|
|
26
|
-
#elif defined(__ANDROID__)
|
|
27
|
-
return {wgpu::FeatureName::SharedTextureMemoryAHardwareBuffer,
|
|
28
|
-
wgpu::FeatureName::SharedFenceSyncFD};
|
|
29
|
-
#else
|
|
30
|
-
return {};
|
|
31
|
-
#endif
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// If every Dawn feature backing the umbrella is in `enabled`, add the
|
|
35
|
-
// umbrella name to `out`. Used by adapter.features / device.features so JS
|
|
36
|
-
// callers can see (and call .has on) the same name they pass in.
|
|
37
|
-
inline void
|
|
38
|
-
maybeSynthesizeRnNativeTextureFeature(
|
|
39
|
-
const std::unordered_set<wgpu::FeatureName> &enabled,
|
|
40
|
-
std::unordered_set<std::string> &out) {
|
|
41
|
-
auto backing = rnNativeTextureBackingFeatures();
|
|
42
|
-
if (backing.empty()) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
for (auto f : backing) {
|
|
46
|
-
if (enabled.find(f) == enabled.end()) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
out.insert(kRnNativeTextureFeature);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
} // namespace rnwgpu
|