react-native-wgpu 0.1.23 → 0.2.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/dawn/dawn_proc_table.h +17 -25
- package/cpp/dawn/native/D3D11Backend.h +7 -0
- package/cpp/dawn/native/DawnNative.h +70 -26
- package/cpp/dawn/native/WebGPUBackend.h +35 -0
- package/cpp/dawn/platform/DawnPlatform.h +1 -0
- package/cpp/dawn/webgpu_cpp_print.h +338 -293
- package/cpp/dawn_logging.cpp +122 -0
- package/cpp/jsi/RNFJSIConverter.h +5 -2
- package/cpp/rnwgpu/SurfaceRegistry.h +3 -2
- package/cpp/rnwgpu/api/Convertors.h +38 -42
- package/cpp/rnwgpu/api/GPU.cpp +20 -18
- package/cpp/rnwgpu/api/GPU.h +6 -2
- package/cpp/rnwgpu/api/GPUAdapter.cpp +49 -40
- package/cpp/rnwgpu/api/GPUBuffer.cpp +21 -19
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +1 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +6 -6
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -9
- package/cpp/rnwgpu/api/GPUDevice.cpp +7 -10
- package/cpp/rnwgpu/api/GPUFeatures.h +5 -14
- package/cpp/rnwgpu/api/GPUQueue.cpp +4 -4
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +0 -3
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +31 -35
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +3 -7
- package/cpp/rnwgpu/api/descriptors/Unions.h +8 -28
- package/cpp/webgpu/webgpu.h +2197 -1863
- package/cpp/webgpu/webgpu_cpp.h +2800 -2479
- package/cpp/webgpu/webgpu_cpp_print.h +33 -0
- package/cpp/webgpu/webgpu_glfw.h +17 -0
- package/lib/commonjs/Canvas.js +1 -3
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/module/Canvas.js +1 -3
- package/lib/module/Canvas.js.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/setup.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- 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/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +11 -11
- 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/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
- package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/dawn.json +659 -798
- package/package.json +4 -4
- package/src/Canvas.tsx +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#include <sstream>
|
|
2
|
+
#include <string>
|
|
3
|
+
|
|
4
|
+
#ifdef __ANDROID__
|
|
5
|
+
#include <android/log.h>
|
|
6
|
+
#elif defined(__APPLE__)
|
|
7
|
+
#include <os/log.h>
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
namespace dawn {
|
|
11
|
+
|
|
12
|
+
enum class LogSeverity {
|
|
13
|
+
Debug,
|
|
14
|
+
Info,
|
|
15
|
+
Warning,
|
|
16
|
+
Error,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Forward declare to match Dawn's exact interface
|
|
20
|
+
class LogMessage {
|
|
21
|
+
public:
|
|
22
|
+
explicit LogMessage(LogSeverity severity);
|
|
23
|
+
~LogMessage();
|
|
24
|
+
|
|
25
|
+
LogMessage(LogMessage&& other);
|
|
26
|
+
LogMessage& operator=(LogMessage&& other);
|
|
27
|
+
|
|
28
|
+
template <typename T>
|
|
29
|
+
LogMessage& operator<<(T&& value) {
|
|
30
|
+
mStream << value;
|
|
31
|
+
return *this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private:
|
|
35
|
+
LogMessage(const LogMessage& other) = delete;
|
|
36
|
+
LogMessage& operator=(const LogMessage& other) = delete;
|
|
37
|
+
|
|
38
|
+
LogSeverity mSeverity;
|
|
39
|
+
std::ostringstream mStream;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Implementation of LogMessage methods
|
|
43
|
+
LogMessage::LogMessage(LogSeverity severity) : mSeverity(severity) {}
|
|
44
|
+
|
|
45
|
+
LogMessage::LogMessage(LogMessage&& other)
|
|
46
|
+
: mSeverity(other.mSeverity), mStream(std::move(other.mStream)) {}
|
|
47
|
+
|
|
48
|
+
LogMessage& LogMessage::operator=(LogMessage&& other) {
|
|
49
|
+
if (this != &other) {
|
|
50
|
+
mSeverity = other.mSeverity;
|
|
51
|
+
mStream = std::move(other.mStream);
|
|
52
|
+
}
|
|
53
|
+
return *this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
LogMessage::~LogMessage() {
|
|
57
|
+
std::string fullMessage = mStream.str();
|
|
58
|
+
|
|
59
|
+
if (fullMessage.empty()) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const char* severityName;
|
|
64
|
+
switch (mSeverity) {
|
|
65
|
+
case LogSeverity::Debug: severityName = "Debug"; break;
|
|
66
|
+
case LogSeverity::Info: severityName = "Info"; break;
|
|
67
|
+
case LogSeverity::Warning: severityName = "Warning"; break;
|
|
68
|
+
case LogSeverity::Error: severityName = "Error"; break;
|
|
69
|
+
default: severityName = "Unknown"; break;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#ifdef __ANDROID__
|
|
73
|
+
int androidPriority;
|
|
74
|
+
switch (mSeverity) {
|
|
75
|
+
case LogSeverity::Debug: androidPriority = ANDROID_LOG_DEBUG; break;
|
|
76
|
+
case LogSeverity::Info: androidPriority = ANDROID_LOG_INFO; break;
|
|
77
|
+
case LogSeverity::Warning: androidPriority = ANDROID_LOG_WARN; break;
|
|
78
|
+
case LogSeverity::Error: androidPriority = ANDROID_LOG_ERROR; break;
|
|
79
|
+
default: androidPriority = ANDROID_LOG_ERROR; break;
|
|
80
|
+
}
|
|
81
|
+
__android_log_print(androidPriority, "ReactNativeWebGPU", "%s: %s", severityName, fullMessage.c_str());
|
|
82
|
+
#elif defined(__APPLE__)
|
|
83
|
+
os_log_type_t logType;
|
|
84
|
+
switch (mSeverity) {
|
|
85
|
+
case LogSeverity::Debug: logType = OS_LOG_TYPE_DEBUG; break;
|
|
86
|
+
case LogSeverity::Info: logType = OS_LOG_TYPE_INFO; break;
|
|
87
|
+
case LogSeverity::Warning: logType = OS_LOG_TYPE_DEFAULT; break;
|
|
88
|
+
case LogSeverity::Error: logType = OS_LOG_TYPE_ERROR; break;
|
|
89
|
+
default: logType = OS_LOG_TYPE_ERROR; break;
|
|
90
|
+
}
|
|
91
|
+
os_log_with_type(OS_LOG_DEFAULT, logType, "[ReactNativeWebGPU] %s: %s", severityName, fullMessage.c_str());
|
|
92
|
+
#else
|
|
93
|
+
FILE* outputStream = (mSeverity == LogSeverity::Warning || mSeverity == LogSeverity::Error) ? stderr : stdout;
|
|
94
|
+
fprintf(outputStream, "[ReactNativeWebGPU] %s: %s\n", severityName, fullMessage.c_str());
|
|
95
|
+
fflush(outputStream);
|
|
96
|
+
#endif
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Factory functions
|
|
100
|
+
LogMessage DebugLog() {
|
|
101
|
+
return LogMessage(LogSeverity::Debug);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
LogMessage InfoLog() {
|
|
105
|
+
return LogMessage(LogSeverity::Info);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
LogMessage WarningLog() {
|
|
109
|
+
return LogMessage(LogSeverity::Warning);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
LogMessage ErrorLog() {
|
|
113
|
+
return LogMessage(LogSeverity::Error);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
LogMessage DebugLog(const char* file, const char* function, int line) {
|
|
117
|
+
LogMessage message = DebugLog();
|
|
118
|
+
message << file << ":" << line << "(" << function << ")";
|
|
119
|
+
return message;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
} // namespace dawn
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
#include "Dispatcher.h"
|
|
29
29
|
#include "ThreadPool.h"
|
|
30
30
|
|
|
31
|
+
// This number is the maximum integer that can be represented exactly as a double
|
|
32
|
+
#define MAX_SAFE_INTEGER uint64_t(9007199254740991)
|
|
33
|
+
|
|
31
34
|
#if __has_include(<cxxabi.h>)
|
|
32
35
|
#include <cxxabi.h>
|
|
33
36
|
#endif
|
|
@@ -122,7 +125,7 @@ template <> struct JSIConverter<uint64_t> {
|
|
|
122
125
|
static uint64_t fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
123
126
|
if (arg.isNumber()) {
|
|
124
127
|
double value = arg.asNumber();
|
|
125
|
-
if (value < 0 || value >
|
|
128
|
+
if (value < 0 || value > MAX_SAFE_INTEGER) {
|
|
126
129
|
throw jsi::JSError(runtime, "Number out of range for uint64_t");
|
|
127
130
|
}
|
|
128
131
|
return static_cast<uint64_t>(value);
|
|
@@ -132,7 +135,7 @@ template <> struct JSIConverter<uint64_t> {
|
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
static jsi::Value toJSI(jsi::Runtime& runtime, uint64_t arg) {
|
|
135
|
-
if (arg <=
|
|
138
|
+
if (arg <= MAX_SAFE_INTEGER) {
|
|
136
139
|
return jsi::Value(static_cast<double>(arg));
|
|
137
140
|
} else {
|
|
138
141
|
throw jsi::JSError(runtime, "Number too large to be represented as a double");
|
|
@@ -38,6 +38,7 @@ public:
|
|
|
38
38
|
config = newConfig;
|
|
39
39
|
config.width = width;
|
|
40
40
|
config.height = height;
|
|
41
|
+
config.presentMode = wgpu::PresentMode::Fifo;
|
|
41
42
|
_configure();
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -83,10 +84,10 @@ public:
|
|
|
83
84
|
auto device = config.device;
|
|
84
85
|
wgpu::CommandEncoder encoder = device.CreateCommandEncoder(&encoderDesc);
|
|
85
86
|
|
|
86
|
-
wgpu::
|
|
87
|
+
wgpu::TexelCopyTextureInfo sourceTexture = {};
|
|
87
88
|
sourceTexture.texture = texture;
|
|
88
89
|
|
|
89
|
-
wgpu::
|
|
90
|
+
wgpu::TexelCopyTextureInfo destinationTexture = {};
|
|
90
91
|
wgpu::SurfaceTexture surfaceTexture;
|
|
91
92
|
surface.GetCurrentTexture(&surfaceTexture);
|
|
92
93
|
destinationTexture.texture = surfaceTexture.texture;
|
|
@@ -309,7 +309,7 @@ public:
|
|
|
309
309
|
Convert(out.label, in.label);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
[[nodiscard]] bool Convert(wgpu::
|
|
312
|
+
[[nodiscard]] bool Convert(wgpu::PassTimestampWrites &out,
|
|
313
313
|
const GPUComputePassTimestampWrites &in) {
|
|
314
314
|
return Convert(out.querySet, in.querySet) &&
|
|
315
315
|
Convert(out.beginningOfPassWriteIndex,
|
|
@@ -348,74 +348,70 @@ public:
|
|
|
348
348
|
|
|
349
349
|
if (in.requiredLimits.has_value()) {
|
|
350
350
|
const auto &limits = in.requiredLimits.value();
|
|
351
|
-
auto *requiredLimits = Allocate<wgpu::
|
|
351
|
+
auto *requiredLimits = Allocate<wgpu::Limits>();
|
|
352
352
|
for (const auto &[key, value] : limits) {
|
|
353
353
|
if (key == "maxTextureDimension1D") {
|
|
354
|
-
requiredLimits->
|
|
354
|
+
requiredLimits->maxTextureDimension1D = value;
|
|
355
355
|
} else if (key == "maxTextureDimension2D") {
|
|
356
|
-
requiredLimits->
|
|
356
|
+
requiredLimits->maxTextureDimension2D = value;
|
|
357
357
|
} else if (key == "maxTextureDimension3D") {
|
|
358
|
-
requiredLimits->
|
|
358
|
+
requiredLimits->maxTextureDimension3D = value;
|
|
359
359
|
} else if (key == "maxTextureArrayLayers") {
|
|
360
|
-
requiredLimits->
|
|
360
|
+
requiredLimits->maxTextureArrayLayers = value;
|
|
361
361
|
} else if (key == "maxBindGroups") {
|
|
362
|
-
requiredLimits->
|
|
362
|
+
requiredLimits->maxBindGroups = value;
|
|
363
363
|
} else if (key == "maxBindGroupsPlusVertexBuffers") {
|
|
364
|
-
requiredLimits->
|
|
364
|
+
requiredLimits->maxBindGroupsPlusVertexBuffers = value;
|
|
365
365
|
} else if (key == "maxBindingsPerBindGroup") {
|
|
366
|
-
requiredLimits->
|
|
366
|
+
requiredLimits->maxBindingsPerBindGroup = value;
|
|
367
367
|
} else if (key == "maxDynamicUniformBuffersPerPipelineLayout") {
|
|
368
|
-
requiredLimits->
|
|
369
|
-
value;
|
|
368
|
+
requiredLimits->maxDynamicUniformBuffersPerPipelineLayout = value;
|
|
370
369
|
} else if (key == "maxDynamicStorageBuffersPerPipelineLayout") {
|
|
371
|
-
requiredLimits->
|
|
372
|
-
value;
|
|
370
|
+
requiredLimits->maxDynamicStorageBuffersPerPipelineLayout = value;
|
|
373
371
|
} else if (key == "maxSampledTexturesPerShaderStage") {
|
|
374
|
-
requiredLimits->
|
|
372
|
+
requiredLimits->maxSampledTexturesPerShaderStage = value;
|
|
375
373
|
} else if (key == "maxSamplersPerShaderStage") {
|
|
376
|
-
requiredLimits->
|
|
374
|
+
requiredLimits->maxSamplersPerShaderStage = value;
|
|
377
375
|
} else if (key == "maxStorageBuffersPerShaderStage") {
|
|
378
|
-
requiredLimits->
|
|
376
|
+
requiredLimits->maxStorageBuffersPerShaderStage = value;
|
|
379
377
|
} else if (key == "maxStorageTexturesPerShaderStage") {
|
|
380
|
-
requiredLimits->
|
|
378
|
+
requiredLimits->maxStorageTexturesPerShaderStage = value;
|
|
381
379
|
} else if (key == "maxUniformBuffersPerShaderStage") {
|
|
382
|
-
requiredLimits->
|
|
380
|
+
requiredLimits->maxUniformBuffersPerShaderStage = value;
|
|
383
381
|
} else if (key == "maxUniformBufferBindingSize") {
|
|
384
|
-
requiredLimits->
|
|
382
|
+
requiredLimits->maxUniformBufferBindingSize = value;
|
|
385
383
|
} else if (key == "maxStorageBufferBindingSize") {
|
|
386
|
-
requiredLimits->
|
|
384
|
+
requiredLimits->maxStorageBufferBindingSize = value;
|
|
387
385
|
} else if (key == "minUniformBufferOffsetAlignment") {
|
|
388
|
-
requiredLimits->
|
|
386
|
+
requiredLimits->minUniformBufferOffsetAlignment = value;
|
|
389
387
|
} else if (key == "minStorageBufferOffsetAlignment") {
|
|
390
|
-
requiredLimits->
|
|
388
|
+
requiredLimits->minStorageBufferOffsetAlignment = value;
|
|
391
389
|
} else if (key == "maxVertexBuffers") {
|
|
392
|
-
requiredLimits->
|
|
390
|
+
requiredLimits->maxVertexBuffers = value;
|
|
393
391
|
} else if (key == "maxBufferSize") {
|
|
394
|
-
requiredLimits->
|
|
392
|
+
requiredLimits->maxBufferSize = value;
|
|
395
393
|
} else if (key == "maxVertexAttributes") {
|
|
396
|
-
requiredLimits->
|
|
394
|
+
requiredLimits->maxVertexAttributes = value;
|
|
397
395
|
} else if (key == "maxVertexBufferArrayStride") {
|
|
398
|
-
requiredLimits->
|
|
399
|
-
} else if (key == "maxInterStageShaderComponents") {
|
|
400
|
-
requiredLimits->limits.maxInterStageShaderComponents = value;
|
|
396
|
+
requiredLimits->maxVertexBufferArrayStride = value;
|
|
401
397
|
} else if (key == "maxInterStageShaderVariables") {
|
|
402
|
-
requiredLimits->
|
|
398
|
+
requiredLimits->maxInterStageShaderVariables = value;
|
|
403
399
|
} else if (key == "maxColorAttachments") {
|
|
404
|
-
requiredLimits->
|
|
400
|
+
requiredLimits->maxColorAttachments = value;
|
|
405
401
|
} else if (key == "maxColorAttachmentBytesPerSample") {
|
|
406
|
-
requiredLimits->
|
|
402
|
+
requiredLimits->maxColorAttachmentBytesPerSample = value;
|
|
407
403
|
} else if (key == "maxComputeWorkgroupStorageSize") {
|
|
408
|
-
requiredLimits->
|
|
404
|
+
requiredLimits->maxComputeWorkgroupStorageSize = value;
|
|
409
405
|
} else if (key == "maxComputeInvocationsPerWorkgroup") {
|
|
410
|
-
requiredLimits->
|
|
406
|
+
requiredLimits->maxComputeInvocationsPerWorkgroup = value;
|
|
411
407
|
} else if (key == "maxComputeWorkgroupSizeX") {
|
|
412
|
-
requiredLimits->
|
|
408
|
+
requiredLimits->maxComputeWorkgroupSizeX = value;
|
|
413
409
|
} else if (key == "maxComputeWorkgroupSizeY") {
|
|
414
|
-
requiredLimits->
|
|
410
|
+
requiredLimits->maxComputeWorkgroupSizeY = value;
|
|
415
411
|
} else if (key == "maxComputeWorkgroupSizeZ") {
|
|
416
|
-
requiredLimits->
|
|
412
|
+
requiredLimits->maxComputeWorkgroupSizeZ = value;
|
|
417
413
|
} else if (key == "maxComputeWorkgroupsPerDimension") {
|
|
418
|
-
requiredLimits->
|
|
414
|
+
requiredLimits->maxComputeWorkgroupsPerDimension = value;
|
|
419
415
|
}
|
|
420
416
|
}
|
|
421
417
|
out.requiredLimits = requiredLimits;
|
|
@@ -452,7 +448,7 @@ public:
|
|
|
452
448
|
Convert(out.constants, out.constantCount, in.constants);
|
|
453
449
|
}
|
|
454
450
|
|
|
455
|
-
[[nodiscard]] bool Convert(wgpu::
|
|
451
|
+
[[nodiscard]] bool Convert(wgpu::TexelCopyBufferInfo &out,
|
|
456
452
|
const GPUImageCopyBuffer &in) {
|
|
457
453
|
out = {};
|
|
458
454
|
out.buffer = in.buffer->get();
|
|
@@ -461,13 +457,13 @@ public:
|
|
|
461
457
|
Convert(out.layout.rowsPerImage, in.rowsPerImage);
|
|
462
458
|
}
|
|
463
459
|
|
|
464
|
-
[[nodiscard]] bool Convert(wgpu::
|
|
460
|
+
[[nodiscard]] bool Convert(wgpu::TexelCopyTextureInfo &out,
|
|
465
461
|
const GPUImageCopyTexture &in) {
|
|
466
462
|
return Convert(out.origin, in.origin) && Convert(out.texture, in.texture) &&
|
|
467
463
|
Convert(out.mipLevel, in.mipLevel) && Convert(out.aspect, in.aspect);
|
|
468
464
|
}
|
|
469
465
|
|
|
470
|
-
[[nodiscard]] bool Convert(wgpu::
|
|
466
|
+
[[nodiscard]] bool Convert(wgpu::TexelCopyBufferLayout &out,
|
|
471
467
|
const GPUImageDataLayout &in) {
|
|
472
468
|
out = {};
|
|
473
469
|
return Convert(out.bytesPerRow, in.bytesPerRow) &&
|
|
@@ -502,7 +498,7 @@ public:
|
|
|
502
498
|
Convert(out.cullMode, in.cullMode);
|
|
503
499
|
}
|
|
504
500
|
|
|
505
|
-
[[nodiscard]] bool Convert(wgpu::
|
|
501
|
+
[[nodiscard]] bool Convert(wgpu::ComputeState &out,
|
|
506
502
|
const GPUProgrammableStage &in) {
|
|
507
503
|
out = {};
|
|
508
504
|
out.module = in.module->get();
|
|
@@ -554,7 +550,7 @@ public:
|
|
|
554
550
|
Convert(out.stencilReadOnly, in.stencilReadOnly);
|
|
555
551
|
}
|
|
556
552
|
|
|
557
|
-
[[nodiscard]] bool Convert(wgpu::
|
|
553
|
+
[[nodiscard]] bool Convert(wgpu::PassTimestampWrites &out,
|
|
558
554
|
const GPURenderPassTimestampWrites &in) {
|
|
559
555
|
return Convert(out.querySet, in.querySet) &&
|
|
560
556
|
Convert(out.beginningOfPassWriteIndex,
|
package/cpp/rnwgpu/api/GPU.cpp
CHANGED
|
@@ -27,15 +27,16 @@ GPU::requestAdapter(
|
|
|
27
27
|
aOptions.backendType = kDefaultBackendType;
|
|
28
28
|
wgpu::Adapter adapter = nullptr;
|
|
29
29
|
_instance.RequestAdapter(
|
|
30
|
-
&aOptions,
|
|
31
|
-
[](
|
|
32
|
-
|
|
30
|
+
&aOptions, wgpu::CallbackMode::AllowSpontaneous,
|
|
31
|
+
[](wgpu::RequestAdapterStatus status, wgpu::Adapter adapter,
|
|
32
|
+
wgpu::StringView message, wgpu::Adapter *userdata) {
|
|
33
33
|
if (message.length) {
|
|
34
34
|
fprintf(stderr, "%s", message.data);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
if (status == wgpu::RequestAdapterStatus::Success) {
|
|
38
|
+
*userdata = std::move(adapter);
|
|
39
|
+
}
|
|
39
40
|
},
|
|
40
41
|
&adapter);
|
|
41
42
|
if (!adapter) {
|
|
@@ -47,38 +48,39 @@ GPU::requestAdapter(
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
std::unordered_set<std::string> GPU::getWgslLanguageFeatures() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
wgpu::SupportedWGSLLanguageFeatures supportedFeatures = {};
|
|
52
|
+
_instance.GetWGSLLanguageFeatures(&supportedFeatures);
|
|
53
|
+
|
|
53
54
|
std::unordered_set<std::string> result;
|
|
54
|
-
for (
|
|
55
|
+
for (size_t i = 0; i < supportedFeatures.featureCount; i++) {
|
|
56
|
+
wgpu::WGSLLanguageFeatureName feature = supportedFeatures.features[i];
|
|
55
57
|
std::string name;
|
|
56
58
|
switch (feature) {
|
|
57
|
-
case wgpu::
|
|
59
|
+
case wgpu::WGSLLanguageFeatureName::ReadonlyAndReadwriteStorageTextures:
|
|
58
60
|
name = "readonly_and_readwrite_storage_textures";
|
|
59
61
|
break;
|
|
60
|
-
case wgpu::
|
|
62
|
+
case wgpu::WGSLLanguageFeatureName::Packed4x8IntegerDotProduct:
|
|
61
63
|
name = "packed_4x8_integer_dot_product";
|
|
62
64
|
break;
|
|
63
|
-
case wgpu::
|
|
65
|
+
case wgpu::WGSLLanguageFeatureName::UnrestrictedPointerParameters:
|
|
64
66
|
name = "unrestricted_pointer_parameters";
|
|
65
67
|
break;
|
|
66
|
-
case wgpu::
|
|
68
|
+
case wgpu::WGSLLanguageFeatureName::PointerCompositeAccess:
|
|
67
69
|
name = "pointer_composite_access";
|
|
68
70
|
break;
|
|
69
|
-
case wgpu::
|
|
71
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingUnimplemented:
|
|
70
72
|
name = "chromium_testing_unimplemented";
|
|
71
73
|
break;
|
|
72
|
-
case wgpu::
|
|
74
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingUnsafeExperimental:
|
|
73
75
|
name = "chromium_testing_unsafe_experimental";
|
|
74
76
|
break;
|
|
75
|
-
case wgpu::
|
|
77
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingExperimental:
|
|
76
78
|
name = "chromium_testing_experimental";
|
|
77
79
|
break;
|
|
78
|
-
case wgpu::
|
|
80
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingShippedWithKillswitch:
|
|
79
81
|
name = "chromium_testing_shipped_with_killswitch";
|
|
80
82
|
break;
|
|
81
|
-
case wgpu::
|
|
83
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingShipped:
|
|
82
84
|
name = "chromium_testing_shipped";
|
|
83
85
|
break;
|
|
84
86
|
}
|
package/cpp/rnwgpu/api/GPU.h
CHANGED
|
@@ -12,11 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
#include "AsyncRunner.h"
|
|
14
14
|
|
|
15
|
+
#include "dawn/dawn_proc.h"
|
|
16
|
+
#include "dawn/native/DawnNative.h"
|
|
15
17
|
#include "webgpu/webgpu_cpp.h"
|
|
16
18
|
|
|
17
19
|
#include "GPUAdapter.h"
|
|
18
20
|
#include "GPURequestAdapterOptions.h"
|
|
19
21
|
|
|
22
|
+
#include <webgpu/webgpu.h>
|
|
23
|
+
|
|
20
24
|
namespace rnwgpu {
|
|
21
25
|
|
|
22
26
|
namespace m = margelo;
|
|
@@ -25,8 +29,8 @@ class GPU : public m::HybridObject {
|
|
|
25
29
|
public:
|
|
26
30
|
GPU() : HybridObject("GPU") {
|
|
27
31
|
wgpu::InstanceDescriptor instanceDesc;
|
|
28
|
-
instanceDesc.
|
|
29
|
-
instanceDesc.
|
|
32
|
+
instanceDesc.capabilities.timedWaitAnyEnable = true;
|
|
33
|
+
instanceDesc.capabilities.timedWaitAnyMaxCount = 64;
|
|
30
34
|
_instance = wgpu::CreateInstance(&instanceDesc);
|
|
31
35
|
auto instance = &_instance;
|
|
32
36
|
_async = std::make_shared<AsyncRunner>(instance);
|
|
@@ -21,15 +21,17 @@ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
|
|
|
21
21
|
if (!conv(aDescriptor, descriptor)) {
|
|
22
22
|
throw std::runtime_error("Failed to convert GPUDeviceDescriptor");
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
// Set device lost callback using new template API
|
|
25
|
+
aDescriptor.SetDeviceLostCallback(
|
|
26
|
+
wgpu::CallbackMode::AllowSpontaneous,
|
|
27
|
+
[](const wgpu::Device &device, wgpu::DeviceLostReason reason,
|
|
28
|
+
wgpu::StringView message) {
|
|
27
29
|
const char *lostReason = "";
|
|
28
30
|
switch (reason) {
|
|
29
|
-
case
|
|
31
|
+
case wgpu::DeviceLostReason::Destroyed:
|
|
30
32
|
lostReason = "Destroyed";
|
|
31
33
|
break;
|
|
32
|
-
case
|
|
34
|
+
case wgpu::DeviceLostReason::Unknown:
|
|
33
35
|
lostReason = "Unknown";
|
|
34
36
|
break;
|
|
35
37
|
default:
|
|
@@ -37,43 +39,46 @@ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
|
|
|
37
39
|
}
|
|
38
40
|
Logger::logToConsole("GPU Device Lost (%s): %s", lostReason,
|
|
39
41
|
message.data);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
auto creationRuntime = static_cast<jsi::Runtime *>(userdata);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Set uncaptured error callback using new template API
|
|
45
|
+
aDescriptor.SetUncapturedErrorCallback([](const wgpu::Device &device,
|
|
46
|
+
wgpu::ErrorType type,
|
|
47
|
+
wgpu::StringView message) {
|
|
47
48
|
const char *errorType = "";
|
|
48
49
|
switch (type) {
|
|
49
|
-
case
|
|
50
|
+
case wgpu::ErrorType::Validation:
|
|
50
51
|
errorType = "Validation";
|
|
51
52
|
break;
|
|
52
|
-
case
|
|
53
|
+
case wgpu::ErrorType::OutOfMemory:
|
|
53
54
|
errorType = "Out of Memory";
|
|
54
55
|
break;
|
|
55
|
-
case
|
|
56
|
+
case wgpu::ErrorType::Internal:
|
|
56
57
|
errorType = "Internal";
|
|
57
58
|
break;
|
|
58
|
-
case
|
|
59
|
+
case wgpu::ErrorType::Unknown:
|
|
59
60
|
errorType = "Unknown";
|
|
60
61
|
break;
|
|
61
62
|
default:
|
|
62
63
|
errorType = "Unknown";
|
|
63
64
|
}
|
|
64
|
-
std::string fullMessage =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
std::string fullMessage =
|
|
66
|
+
message.length > 0 ? std::string(errorType) + ": " +
|
|
67
|
+
std::string(message.data, message.length)
|
|
68
|
+
: "no message";
|
|
69
|
+
fprintf(stderr, "%s", fullMessage.c_str());
|
|
70
|
+
});
|
|
68
71
|
_instance.RequestDevice(
|
|
69
|
-
&aDescriptor,
|
|
70
|
-
[](
|
|
71
|
-
|
|
72
|
+
&aDescriptor, wgpu::CallbackMode::AllowSpontaneous,
|
|
73
|
+
[](wgpu::RequestDeviceStatus status, wgpu::Device device,
|
|
74
|
+
wgpu::StringView message, wgpu::Device *userdata) {
|
|
72
75
|
if (message.length) {
|
|
73
76
|
fprintf(stderr, "%s", message.data);
|
|
74
77
|
return;
|
|
75
78
|
}
|
|
76
|
-
|
|
79
|
+
if (status == wgpu::RequestDeviceStatus::Success) {
|
|
80
|
+
*userdata = std::move(device);
|
|
81
|
+
}
|
|
77
82
|
},
|
|
78
83
|
&device);
|
|
79
84
|
|
|
@@ -81,28 +86,32 @@ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
|
|
|
81
86
|
throw std::runtime_error("Failed to request device");
|
|
82
87
|
}
|
|
83
88
|
device.SetLoggingCallback(
|
|
84
|
-
[](
|
|
85
|
-
|
|
89
|
+
[creationRuntime = _creationRuntime](wgpu::LoggingType type,
|
|
90
|
+
wgpu::StringView message) {
|
|
86
91
|
const char *logLevel = "";
|
|
87
92
|
switch (type) {
|
|
88
|
-
case
|
|
93
|
+
case wgpu::LoggingType::Warning:
|
|
89
94
|
logLevel = "Warning";
|
|
90
|
-
Logger::warnToJavascriptConsole(
|
|
95
|
+
Logger::warnToJavascriptConsole(
|
|
96
|
+
*creationRuntime, std::string(message.data, message.length));
|
|
91
97
|
break;
|
|
92
|
-
case
|
|
98
|
+
case wgpu::LoggingType::Error:
|
|
93
99
|
logLevel = "Error";
|
|
94
|
-
Logger::errorToJavascriptConsole(
|
|
100
|
+
Logger::errorToJavascriptConsole(
|
|
101
|
+
*creationRuntime, std::string(message.data, message.length));
|
|
95
102
|
break;
|
|
96
|
-
case
|
|
103
|
+
case wgpu::LoggingType::Verbose:
|
|
97
104
|
logLevel = "Verbose";
|
|
98
|
-
|
|
105
|
+
break;
|
|
106
|
+
case wgpu::LoggingType::Info:
|
|
99
107
|
logLevel = "Info";
|
|
108
|
+
break;
|
|
100
109
|
default:
|
|
101
110
|
logLevel = "Unknown";
|
|
102
|
-
Logger::logToConsole("%s:
|
|
111
|
+
Logger::logToConsole("%s: %.*s", logLevel,
|
|
112
|
+
static_cast<int>(message.length), message.data);
|
|
103
113
|
}
|
|
104
|
-
}
|
|
105
|
-
_creationRuntime);
|
|
114
|
+
});
|
|
106
115
|
std::string label =
|
|
107
116
|
descriptor.has_value() ? descriptor.value()->label.value_or("") : "";
|
|
108
117
|
promise.set_value(
|
|
@@ -111,11 +120,11 @@ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
|
|
|
111
120
|
}
|
|
112
121
|
|
|
113
122
|
std::unordered_set<std::string> GPUAdapter::getFeatures() {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
_instance.EnumerateFeatures(features.data());
|
|
123
|
+
wgpu::SupportedFeatures supportedFeatures;
|
|
124
|
+
_instance.GetFeatures(&supportedFeatures);
|
|
117
125
|
std::unordered_set<std::string> result;
|
|
118
|
-
for (
|
|
126
|
+
for (size_t i = 0; i < supportedFeatures.featureCount; ++i) {
|
|
127
|
+
auto feature = supportedFeatures.features[i];
|
|
119
128
|
std::string name;
|
|
120
129
|
convertEnumToJSUnion(feature, &name);
|
|
121
130
|
if (name != "") {
|
|
@@ -126,7 +135,7 @@ std::unordered_set<std::string> GPUAdapter::getFeatures() {
|
|
|
126
135
|
}
|
|
127
136
|
|
|
128
137
|
std::shared_ptr<GPUSupportedLimits> GPUAdapter::getLimits() {
|
|
129
|
-
wgpu::
|
|
138
|
+
wgpu::Limits limits{};
|
|
130
139
|
if (!_instance.GetLimits(&limits)) {
|
|
131
140
|
throw std::runtime_error("Failed to get limits");
|
|
132
141
|
}
|
|
@@ -54,25 +54,27 @@ std::future<void> GPUBuffer::mapAsync(uint64_t modeIn,
|
|
|
54
54
|
// is already mapped"))); return future;
|
|
55
55
|
// }
|
|
56
56
|
// }
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
57
|
+
return _instance.MapAsync(
|
|
58
|
+
mode, offset.value_or(0), rangeSize, wgpu::CallbackMode::WaitAnyOnly,
|
|
59
|
+
[](wgpu::MapAsyncStatus status, wgpu::StringView message) {
|
|
60
|
+
switch (status) {
|
|
61
|
+
case wgpu::MapAsyncStatus::Success:
|
|
62
|
+
break;
|
|
63
|
+
case wgpu::MapAsyncStatus::CallbackCancelled:
|
|
64
|
+
throw std::runtime_error("MapAsyncStatus::CallbackCancelled");
|
|
65
|
+
break;
|
|
66
|
+
case wgpu::MapAsyncStatus::Error:
|
|
67
|
+
throw std::runtime_error("MapAsyncStatus::Error");
|
|
68
|
+
break;
|
|
69
|
+
case wgpu::MapAsyncStatus::Aborted:
|
|
70
|
+
throw std::runtime_error("MapAsyncStatus::Aborted");
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
throw std::runtime_error("MapAsyncStatus: " +
|
|
74
|
+
std::to_string(static_cast<int>(status)));
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
80
|
|