react-native-wgpu 0.2.10 → 0.3.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/README.md +155 -69
- package/android/CMakeLists.txt +5 -7
- package/android/build.gradle +7 -18
- package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +34 -10
- package/apple/MetalView.mm +0 -19
- package/apple/WebGPUModule.h +1 -9
- package/apple/WebGPUModule.mm +0 -3
- package/apple/WebGPUView.h +0 -3
- package/apple/WebGPUView.mm +0 -2
- package/cpp/WGPULogger.h +10 -0
- package/cpp/dawn/dawn_proc_table.h +1 -1
- package/cpp/dawn/webgpu.h +4855 -0
- package/cpp/dawn/webgpu_cpp.h +10168 -0
- package/cpp/dawn/wire/client/webgpu.h +354 -0
- package/cpp/dawn/wire/client/webgpu_cpp.h +10343 -0
- package/cpp/dawn/wire/client/webgpu_cpp_print.h +2715 -0
- package/cpp/jsi/RNFHybridObject.cpp +8 -4
- package/cpp/jsi/RNFHybridObject.h +7 -2
- package/cpp/jsi/RNFJSIConverter.h +13 -102
- package/cpp/jsi/RNFJSIHelper.h +5 -3
- package/cpp/jsi/RNFRuntimeState.cpp +18 -0
- package/cpp/jsi/RNFRuntimeState.h +106 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +1 -9
- package/cpp/rnwgpu/api/GPU.cpp +51 -26
- package/cpp/rnwgpu/api/GPU.h +5 -18
- package/cpp/rnwgpu/api/GPUAdapter.cpp +79 -54
- package/cpp/rnwgpu/api/GPUAdapter.h +6 -6
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -1
- package/cpp/rnwgpu/api/GPUBindGroup.h +1 -3
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -3
- package/cpp/rnwgpu/api/GPUBuffer.cpp +35 -32
- package/cpp/rnwgpu/api/GPUBuffer.h +9 -7
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +5 -1
- package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -2
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -3
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -2
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -3
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -3
- package/cpp/rnwgpu/api/GPUDevice.cpp +183 -128
- package/cpp/rnwgpu/api/GPUDevice.h +22 -21
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -3
- package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -3
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -3
- package/cpp/rnwgpu/api/GPUQuerySet.h +1 -3
- package/cpp/rnwgpu/api/GPUQueue.cpp +19 -8
- package/cpp/rnwgpu/api/GPUQueue.h +7 -6
- package/cpp/rnwgpu/api/GPURenderBundle.h +1 -3
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -3
- package/cpp/rnwgpu/api/GPUSampler.h +1 -3
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +42 -28
- package/cpp/rnwgpu/api/GPUShaderModule.h +6 -6
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -3
- package/cpp/rnwgpu/api/GPUTexture.h +1 -3
- package/cpp/rnwgpu/api/GPUTextureView.h +1 -3
- package/cpp/rnwgpu/api/RNWebGPU.h +1 -7
- package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
- package/cpp/rnwgpu/async/AsyncRunner.cpp +215 -0
- package/cpp/rnwgpu/async/AsyncRunner.h +53 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +181 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +55 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +23 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +22 -0
- package/cpp/webgpu/webgpu.h +5 -4827
- package/cpp/webgpu/webgpu_cpp.h +5 -10140
- package/cpp/{dawn/native/WebGPUBackend.h → webgpu/webgpu_cpp_print.h} +4 -20
- package/lib/commonjs/Canvas.js +6 -66
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/hooks.js +6 -42
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/module/Canvas.js +7 -67
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/hooks.js +5 -40
- package/lib/module/hooks.js.map +1 -1
- package/lib/typescript/lib/commonjs/hooks.d.ts +1 -5
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/hooks.d.ts +1 -5
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +0 -1
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts +2 -7
- 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/libwebgpu_dawn.xcframework/Info.plist +5 -35
- 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 +4 -3
- package/react-native-wgpu.podspec +12 -16
- package/src/Canvas.tsx +8 -69
- package/src/hooks.tsx +14 -48
- package/android/cpp/platform/ThreadUtils.cpp +0 -41
- package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +0 -23
- package/android/src/oldarch/com/webgpu/WebGPUViewManagerSpec.java +0 -12
- package/apple/WebGPUViewManager.mm +0 -24
- package/apple/platform/ThreadUtils.cpp +0 -34
- package/cpp/dawn/dawn_proc.h +0 -50
- package/cpp/dawn/dawn_thread_dispatch_proc.h +0 -47
- package/cpp/dawn/native/D3D11Backend.h +0 -77
- package/cpp/dawn/native/D3D12Backend.h +0 -68
- package/cpp/dawn/native/D3DBackend.h +0 -56
- package/cpp/dawn/native/MetalBackend.h +0 -56
- package/cpp/dawn/platform/DawnPlatform.h +0 -167
- package/cpp/dawn/platform/dawn_platform_export.h +0 -49
- package/cpp/jsi/RNFRuntimeCache.cpp +0 -57
- package/cpp/jsi/RNFRuntimeCache.h +0 -79
- package/cpp/jsi/RNFWorkletRuntimeCollector.h +0 -43
- package/cpp/jsi/RNFWorkletRuntimeRegistry.cpp +0 -12
- package/cpp/jsi/RNFWorkletRuntimeRegistry.h +0 -44
- package/cpp/platform/ThreadUtils.h +0 -30
- package/cpp/rnwgpu/api/AsyncRunner.h +0 -30
- package/cpp/threading/CallInvokerDispatcher.h +0 -37
- package/cpp/threading/Dispatcher.cpp +0 -55
- package/cpp/threading/Dispatcher.h +0 -93
- package/cpp/threading/ThreadPool.cpp +0 -88
- package/cpp/threading/ThreadPool.h +0 -53
- package/cpp/webgpu/webgpu_glfw.h +0 -88
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Constants.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Device.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Device.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/GPU.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Texture.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +0 -3
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +0 -29
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +0 -5
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/cube.d.ts +0 -7
- package/lib/typescript/src/__tests__/components/cube.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +0 -22
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +0 -12
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +0 -7
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +0 -6
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +0 -6
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +0 -10
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/triangle.d.ts +0 -3
- package/lib/typescript/src/__tests__/components/triangle.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/config.d.ts +0 -3
- package/lib/typescript/src/__tests__/config.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/globalSetup.d.ts +0 -3
- package/lib/typescript/src/__tests__/globalSetup.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/globalTeardown.d.ts +0 -3
- package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/setup.d.ts +0 -63
- package/lib/typescript/src/__tests__/setup.d.ts.map +0 -1
- 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/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 +0 -4670
- package/src/__tests__/Alpha.spec.ts +0 -28
- package/src/__tests__/ArrayBuffer.spec.ts +0 -76
- package/src/__tests__/Buffer.spec.ts +0 -357
- package/src/__tests__/ComputeShader.spec.ts +0 -375
- package/src/__tests__/Constants.spec.ts +0 -89
- package/src/__tests__/Device.spec.ts +0 -84
- package/src/__tests__/ErrorScope.spec.ts +0 -92
- package/src/__tests__/ExternalTexture.spec.ts +0 -284
- package/src/__tests__/GPU.spec.ts +0 -272
- package/src/__tests__/ImageData.spec.ts +0 -26
- package/src/__tests__/Shaders.spec.ts +0 -232
- package/src/__tests__/Texture.spec.ts +0 -197
- package/src/__tests__/assets/Di-3d.png +0 -0
- package/src/__tests__/components/Wireframe/Shaders.ts +0 -138
- package/src/__tests__/components/Wireframe/models.ts +0 -113
- package/src/__tests__/components/Wireframe/utils.ts +0 -22
- package/src/__tests__/components/cube.ts +0 -51
- package/src/__tests__/components/meshes/mesh.ts +0 -96
- package/src/__tests__/components/meshes/sphere.ts +0 -103
- package/src/__tests__/components/meshes/stanfordDragon.ts +0 -44
- package/src/__tests__/components/meshes/stanfordDragonData.ts +0 -5
- package/src/__tests__/components/meshes/teapot.ts +0 -13
- package/src/__tests__/components/meshes/utils.ts +0 -235
- package/src/__tests__/components/triangle.ts +0 -17
- package/src/__tests__/config.ts +0 -2
- package/src/__tests__/demos/ABuffer.spec.ts +0 -890
- package/src/__tests__/demos/Blur.spec.ts +0 -398
- package/src/__tests__/demos/Cube.spec.ts +0 -929
- package/src/__tests__/demos/FractalCube.spec.ts +0 -240
- package/src/__tests__/demos/OcclusionQuery.spec.ts +0 -376
- package/src/__tests__/demos/RenderBundles.spec.ts +0 -580
- package/src/__tests__/demos/Triangle.spec.ts +0 -266
- package/src/__tests__/demos/Wireframe.spec.ts +0 -188
- package/src/__tests__/globalSetup.ts +0 -45
- package/src/__tests__/globalTeardown.ts +0 -11
- package/src/__tests__/setup.ts +0 -423
- package/src/__tests__/snapshots/abuffer.png +0 -0
- package/src/__tests__/snapshots/asteroid.png +0 -0
- package/src/__tests__/snapshots/blur.png +0 -0
- package/src/__tests__/snapshots/buffer.png +0 -0
- package/src/__tests__/snapshots/constant-triangle.png +0 -0
- package/src/__tests__/snapshots/cube.png +0 -0
- package/src/__tests__/snapshots/f.png +0 -0
- package/src/__tests__/snapshots/f2.png +0 -0
- package/src/__tests__/snapshots/fractal-cubes.png +0 -0
- package/src/__tests__/snapshots/instanced-cubes.png +0 -0
- package/src/__tests__/snapshots/occlusion-query.png +0 -0
- package/src/__tests__/snapshots/ref.png +0 -0
- package/src/__tests__/snapshots/semi-opaque-cyan.png +0 -0
- package/src/__tests__/snapshots/texture.png +0 -0
- package/src/__tests__/snapshots/textured-cube.png +0 -0
- package/src/__tests__/snapshots/triangle-msaa.png +0 -0
- package/src/__tests__/snapshots/triangle.png +0 -0
- package/src/__tests__/snapshots/two-cube.png +0 -0
|
@@ -3,14 +3,43 @@
|
|
|
3
3
|
#include <memory>
|
|
4
4
|
#include <string>
|
|
5
5
|
#include <unordered_set>
|
|
6
|
+
#include <utility>
|
|
6
7
|
#include <vector>
|
|
7
8
|
|
|
8
9
|
#include "Convertors.h"
|
|
10
|
+
#include "RNFJSIConverter.h"
|
|
9
11
|
|
|
10
12
|
#include "GPUFeatures.h"
|
|
11
13
|
|
|
12
14
|
namespace rnwgpu {
|
|
13
15
|
|
|
16
|
+
void GPUDevice::notifyDeviceLost(wgpu::DeviceLostReason reason,
|
|
17
|
+
std::string message) {
|
|
18
|
+
if (_lostSettled) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_lostSettled = true;
|
|
23
|
+
_lostInfo = std::make_shared<GPUDeviceLostInfo>(reason, std::move(message));
|
|
24
|
+
|
|
25
|
+
if (_lostResolve.has_value()) {
|
|
26
|
+
auto resolve = std::move(*_lostResolve);
|
|
27
|
+
_lostResolve.reset();
|
|
28
|
+
resolve([info = _lostInfo](jsi::Runtime &runtime) mutable {
|
|
29
|
+
return margelo::JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(
|
|
30
|
+
runtime, info);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_lostHandle.reset();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void GPUDevice::forceLossForTesting() {
|
|
38
|
+
// wgpu::StringView view("forceLossForTesting invoked from JS");
|
|
39
|
+
_instance.ForceLoss(wgpu::DeviceLostReason::Unknown,
|
|
40
|
+
"forceLossForTesting invoked from JS");
|
|
41
|
+
}
|
|
42
|
+
|
|
14
43
|
std::shared_ptr<GPUBuffer>
|
|
15
44
|
GPUDevice::createBuffer(std::shared_ptr<GPUBufferDescriptor> descriptor) {
|
|
16
45
|
wgpu::BufferDescriptor desc;
|
|
@@ -52,9 +81,7 @@ std::shared_ptr<GPUCommandEncoder> GPUDevice::createCommandEncoder(
|
|
|
52
81
|
|
|
53
82
|
void GPUDevice::destroy() {
|
|
54
83
|
_instance.Destroy();
|
|
55
|
-
|
|
56
|
-
wgpu::DeviceLostReason::Destroyed, "device was destroyed");
|
|
57
|
-
m_lostPromise->set_value(lostInfo);
|
|
84
|
+
notifyDeviceLost(wgpu::DeviceLostReason::Destroyed, "device was destroyed");
|
|
58
85
|
}
|
|
59
86
|
|
|
60
87
|
std::shared_ptr<GPUTexture>
|
|
@@ -208,139 +235,135 @@ std::shared_ptr<GPUExternalTexture> GPUDevice::importExternalTexture(
|
|
|
208
235
|
"GPUDevice::importExternalTexture(): Not implemented");
|
|
209
236
|
}
|
|
210
237
|
|
|
211
|
-
|
|
212
|
-
GPUDevice::createComputePipelineAsync(
|
|
238
|
+
async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
|
|
213
239
|
std::shared_ptr<GPUComputePipelineDescriptor> descriptor) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
240
|
+
wgpu::ComputePipelineDescriptor desc{};
|
|
241
|
+
Convertor conv;
|
|
242
|
+
if (!conv(desc, descriptor)) {
|
|
243
|
+
throw std::runtime_error("GPUDevice::createComputePipeline(): Error with "
|
|
244
|
+
"GPUComputePipelineDescriptor");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
auto label = std::string(
|
|
248
|
+
descriptor->label.has_value() ? descriptor->label.value() : "");
|
|
249
|
+
auto pipelineHolder = std::make_shared<GPUComputePipeline>(nullptr, label);
|
|
250
|
+
|
|
251
|
+
return _async->postTask(
|
|
252
|
+
[device = _instance, desc, descriptor,
|
|
253
|
+
pipelineHolder](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
254
|
+
const async::AsyncTaskHandle::RejectFunction &reject) {
|
|
255
|
+
(void)descriptor;
|
|
256
|
+
device.CreateComputePipelineAsync(
|
|
257
|
+
&desc, wgpu::CallbackMode::AllowProcessEvents,
|
|
258
|
+
[pipelineHolder, resolve,
|
|
259
|
+
reject](wgpu::CreatePipelineAsyncStatus status,
|
|
260
|
+
wgpu::ComputePipeline pipeline, const char *msg) mutable {
|
|
261
|
+
if (status == wgpu::CreatePipelineAsyncStatus::Success &&
|
|
262
|
+
pipeline) {
|
|
263
|
+
pipelineHolder->_instance = pipeline;
|
|
264
|
+
resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
|
|
265
|
+
return margelo::
|
|
266
|
+
JSIConverter<std::shared_ptr<GPUComputePipeline>>::toJSI(
|
|
267
|
+
runtime, pipelineHolder);
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
std::string error = msg ? std::string(msg)
|
|
271
|
+
: "Failed to create compute pipeline";
|
|
272
|
+
reject(std::move(error));
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
241
276
|
}
|
|
242
277
|
|
|
243
|
-
|
|
244
|
-
GPUDevice::createRenderPipelineAsync(
|
|
278
|
+
async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
|
|
245
279
|
std::shared_ptr<GPURenderPipelineDescriptor> descriptor) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
wgpu::RenderPipelineDescriptor desc{};
|
|
281
|
+
Convertor conv;
|
|
282
|
+
if (!conv(desc, descriptor)) {
|
|
283
|
+
throw std::runtime_error(
|
|
284
|
+
"GPUDevice::createRenderPipelineAsync(): Error with "
|
|
285
|
+
"GPURenderPipelineDescriptor");
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
auto label = std::string(
|
|
289
|
+
descriptor->label.has_value() ? descriptor->label.value() : "");
|
|
290
|
+
auto pipelineHolder = std::make_shared<GPURenderPipeline>(nullptr, label);
|
|
291
|
+
|
|
292
|
+
return _async->postTask(
|
|
293
|
+
[device = _instance, desc, descriptor,
|
|
294
|
+
pipelineHolder](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
295
|
+
const async::AsyncTaskHandle::RejectFunction &reject) {
|
|
296
|
+
(void)descriptor;
|
|
297
|
+
device.CreateRenderPipelineAsync(
|
|
298
|
+
&desc, wgpu::CallbackMode::AllowProcessEvents,
|
|
299
|
+
[pipelineHolder, resolve,
|
|
300
|
+
reject](wgpu::CreatePipelineAsyncStatus status,
|
|
301
|
+
wgpu::RenderPipeline pipeline, const char *msg) mutable {
|
|
302
|
+
if (status == wgpu::CreatePipelineAsyncStatus::Success &&
|
|
303
|
+
pipeline) {
|
|
304
|
+
pipelineHolder->_instance = pipeline;
|
|
305
|
+
resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
|
|
306
|
+
return margelo::
|
|
307
|
+
JSIConverter<std::shared_ptr<GPURenderPipeline>>::toJSI(
|
|
308
|
+
runtime, pipelineHolder);
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
311
|
+
std::string error =
|
|
312
|
+
msg ? std::string(msg) : "Failed to create render pipeline";
|
|
313
|
+
reject(std::move(error));
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
});
|
|
274
317
|
}
|
|
275
318
|
|
|
276
319
|
void GPUDevice::pushErrorScope(wgpu::ErrorFilter filter) {
|
|
277
320
|
_instance.PushErrorScope(filter);
|
|
278
321
|
}
|
|
279
322
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
case wgpu::ErrorType::Unknown:
|
|
325
|
-
result = std::make_shared<GPUError>(wgpu::ErrorType::Unknown,
|
|
326
|
-
std::string(message));
|
|
327
|
-
break;
|
|
328
|
-
default:
|
|
329
|
-
throw std::runtime_error(
|
|
330
|
-
"unhandled error type (" +
|
|
331
|
-
std::to_string(
|
|
332
|
-
static_cast<std::underlying_type<wgpu::ErrorType>::type>(
|
|
333
|
-
type)) +
|
|
334
|
-
")");
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
323
|
+
async::AsyncTaskHandle GPUDevice::popErrorScope() {
|
|
324
|
+
auto device = _instance;
|
|
325
|
+
|
|
326
|
+
return _async->postTask(
|
|
327
|
+
[device](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
328
|
+
const async::AsyncTaskHandle::RejectFunction &reject) {
|
|
329
|
+
device.PopErrorScope(
|
|
330
|
+
wgpu::CallbackMode::AllowProcessEvents,
|
|
331
|
+
[resolve, reject](wgpu::PopErrorScopeStatus status,
|
|
332
|
+
wgpu::ErrorType type, wgpu::StringView message) {
|
|
333
|
+
if (status == wgpu::PopErrorScopeStatus::Error ||
|
|
334
|
+
status == wgpu::PopErrorScopeStatus::CallbackCancelled) {
|
|
335
|
+
reject("PopErrorScope failed");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUError>> result =
|
|
340
|
+
nullptr;
|
|
341
|
+
|
|
342
|
+
switch (type) {
|
|
343
|
+
case wgpu::ErrorType::NoError:
|
|
344
|
+
break;
|
|
345
|
+
case wgpu::ErrorType::OutOfMemory:
|
|
346
|
+
case wgpu::ErrorType::Validation:
|
|
347
|
+
case wgpu::ErrorType::Internal:
|
|
348
|
+
case wgpu::ErrorType::Unknown: {
|
|
349
|
+
std::string messageString =
|
|
350
|
+
message.length ? std::string(message.data, message.length)
|
|
351
|
+
: "";
|
|
352
|
+
result = std::make_shared<GPUError>(type, messageString);
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
default:
|
|
356
|
+
reject("Unhandled GPU error type");
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
resolve([result =
|
|
361
|
+
std::move(result)](jsi::Runtime &runtime) mutable {
|
|
362
|
+
return margelo::JSIConverter<decltype(result)>::toJSI(runtime,
|
|
363
|
+
result);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
337
366
|
});
|
|
338
|
-
|
|
339
|
-
// Wait synchronously on main thread - both push and pop now on same thread
|
|
340
|
-
_async->instance->WaitAny(wgpu_future, UINT64_MAX);
|
|
341
|
-
|
|
342
|
-
promise->set_value(result);
|
|
343
|
-
return future;
|
|
344
367
|
}
|
|
345
368
|
|
|
346
369
|
std::unordered_set<std::string> GPUDevice::getFeatures() {
|
|
@@ -356,8 +379,40 @@ std::unordered_set<std::string> GPUDevice::getFeatures() {
|
|
|
356
379
|
return result;
|
|
357
380
|
}
|
|
358
381
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
382
|
+
async::AsyncTaskHandle GPUDevice::getLost() {
|
|
383
|
+
if (_lostHandle.has_value()) {
|
|
384
|
+
return *_lostHandle;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (_lostSettled && _lostInfo) {
|
|
388
|
+
return _async->postTask(
|
|
389
|
+
[info = _lostInfo](
|
|
390
|
+
const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
391
|
+
const async::AsyncTaskHandle::RejectFunction & /*reject*/) {
|
|
392
|
+
resolve([info](jsi::Runtime &runtime) mutable {
|
|
393
|
+
return margelo::JSIConverter<
|
|
394
|
+
std::shared_ptr<GPUDeviceLostInfo>>::toJSI(runtime, info);
|
|
395
|
+
});
|
|
396
|
+
},
|
|
397
|
+
false);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
auto handle = _async->postTask(
|
|
401
|
+
[this](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
402
|
+
const async::AsyncTaskHandle::RejectFunction & /*reject*/) {
|
|
403
|
+
if (_lostSettled && _lostInfo) {
|
|
404
|
+
resolve([info = _lostInfo](jsi::Runtime &runtime) mutable {
|
|
405
|
+
return margelo::JSIConverter<
|
|
406
|
+
std::shared_ptr<GPUDeviceLostInfo>>::toJSI(runtime, info);
|
|
407
|
+
});
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
_lostResolve = resolve;
|
|
412
|
+
},
|
|
413
|
+
false);
|
|
414
|
+
|
|
415
|
+
_lostHandle = handle;
|
|
416
|
+
return handle;
|
|
362
417
|
}
|
|
363
418
|
} // namespace rnwgpu
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include <future>
|
|
4
3
|
#include <memory>
|
|
4
|
+
#include <optional>
|
|
5
5
|
#include <string>
|
|
6
6
|
#include <unordered_set>
|
|
7
|
+
#include <utility>
|
|
7
8
|
#include <variant>
|
|
8
9
|
|
|
9
10
|
#include "Unions.h"
|
|
10
11
|
|
|
11
12
|
#include "RNFHybridObject.h"
|
|
12
13
|
|
|
13
|
-
#include "AsyncRunner.h"
|
|
14
|
+
#include "rnwgpu/async/AsyncRunner.h"
|
|
15
|
+
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
14
16
|
|
|
15
17
|
#include "webgpu/webgpu_cpp.h"
|
|
16
18
|
|
|
@@ -51,17 +53,11 @@ namespace m = margelo;
|
|
|
51
53
|
|
|
52
54
|
class GPUDevice : public m::HybridObject {
|
|
53
55
|
public:
|
|
54
|
-
explicit GPUDevice(wgpu::Device instance,
|
|
56
|
+
explicit GPUDevice(wgpu::Device instance,
|
|
57
|
+
std::shared_ptr<async::AsyncRunner> async,
|
|
55
58
|
std::string label)
|
|
56
59
|
: HybridObject("GPUDevice"), _instance(instance), _async(async),
|
|
57
|
-
_label(label) {
|
|
58
|
-
m_lostPromise =
|
|
59
|
-
std::make_shared<std::promise<std::shared_ptr<GPUDeviceLostInfo>>>();
|
|
60
|
-
|
|
61
|
-
auto sharedFuture = m_lostPromise->get_future().share();
|
|
62
|
-
m_lostSharedFuture = std::make_shared<
|
|
63
|
-
std::shared_future<std::shared_ptr<GPUDeviceLostInfo>>>(sharedFuture);
|
|
64
|
-
}
|
|
60
|
+
_label(label) {}
|
|
65
61
|
|
|
66
62
|
public:
|
|
67
63
|
std::string getBrand() { return _name; }
|
|
@@ -87,9 +83,9 @@ public:
|
|
|
87
83
|
std::shared_ptr<GPUComputePipelineDescriptor> descriptor);
|
|
88
84
|
std::shared_ptr<GPURenderPipeline>
|
|
89
85
|
createRenderPipeline(std::shared_ptr<GPURenderPipelineDescriptor> descriptor);
|
|
90
|
-
|
|
86
|
+
async::AsyncTaskHandle createComputePipelineAsync(
|
|
91
87
|
std::shared_ptr<GPUComputePipelineDescriptor> descriptor);
|
|
92
|
-
|
|
88
|
+
async::AsyncTaskHandle createRenderPipelineAsync(
|
|
93
89
|
std::shared_ptr<GPURenderPipelineDescriptor> descriptor);
|
|
94
90
|
std::shared_ptr<GPUCommandEncoder> createCommandEncoder(
|
|
95
91
|
std::optional<std::shared_ptr<GPUCommandEncoderDescriptor>> descriptor);
|
|
@@ -98,13 +94,14 @@ public:
|
|
|
98
94
|
std::shared_ptr<GPUQuerySet>
|
|
99
95
|
createQuerySet(std::shared_ptr<GPUQuerySetDescriptor> descriptor);
|
|
100
96
|
void pushErrorScope(wgpu::ErrorFilter filter);
|
|
101
|
-
|
|
102
|
-
popErrorScope();
|
|
97
|
+
async::AsyncTaskHandle popErrorScope();
|
|
103
98
|
|
|
104
99
|
std::unordered_set<std::string> getFeatures();
|
|
105
100
|
std::shared_ptr<GPUSupportedLimits> getLimits();
|
|
106
101
|
std::shared_ptr<GPUQueue> getQueue();
|
|
107
|
-
|
|
102
|
+
async::AsyncTaskHandle getLost();
|
|
103
|
+
void notifyDeviceLost(wgpu::DeviceLostReason reason, std::string message);
|
|
104
|
+
void forceLossForTesting();
|
|
108
105
|
|
|
109
106
|
std::string getLabel() { return _label; }
|
|
110
107
|
void setLabel(const std::string &label) {
|
|
@@ -148,18 +145,22 @@ public:
|
|
|
148
145
|
registerHybridGetter("lost", &GPUDevice::getLost, this);
|
|
149
146
|
registerHybridGetter("label", &GPUDevice::getLabel, this);
|
|
150
147
|
registerHybridSetter("label", &GPUDevice::setLabel, this);
|
|
148
|
+
registerHybridMethod("forceLossForTesting", &GPUDevice::forceLossForTesting,
|
|
149
|
+
this);
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
inline const wgpu::Device get() { return _instance; }
|
|
154
153
|
|
|
155
154
|
private:
|
|
155
|
+
friend class GPUAdapter;
|
|
156
|
+
|
|
156
157
|
wgpu::Device _instance;
|
|
157
|
-
std::shared_ptr<AsyncRunner> _async;
|
|
158
|
+
std::shared_ptr<async::AsyncRunner> _async;
|
|
158
159
|
std::string _label;
|
|
159
|
-
std::
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
std::optional<async::AsyncTaskHandle> _lostHandle;
|
|
161
|
+
std::shared_ptr<GPUDeviceLostInfo> _lostInfo;
|
|
162
|
+
bool _lostSettled = false;
|
|
163
|
+
std::optional<async::AsyncTaskHandle::ResolveFunction> _lostResolve;
|
|
163
164
|
};
|
|
164
165
|
|
|
165
166
|
} // namespace rnwgpu
|
|
@@ -78,14 +78,25 @@ void GPUQueue::writeBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
|
78
78
|
static_cast<size_t>(size64));
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
async::AsyncTaskHandle GPUQueue::onSubmittedWorkDone() {
|
|
82
|
+
auto queue = _instance;
|
|
83
|
+
return _async->postTask(
|
|
84
|
+
[queue](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
85
|
+
const async::AsyncTaskHandle::RejectFunction &reject) {
|
|
86
|
+
queue.OnSubmittedWorkDone(
|
|
87
|
+
wgpu::CallbackMode::AllowProcessEvents,
|
|
88
|
+
[resolve, reject](wgpu::QueueWorkDoneStatus status,
|
|
89
|
+
wgpu::StringView message) {
|
|
90
|
+
if (status == wgpu::QueueWorkDoneStatus::Success) {
|
|
91
|
+
resolve(nullptr);
|
|
92
|
+
} else {
|
|
93
|
+
std::string error =
|
|
94
|
+
message.length ? std::string(message.data, message.length)
|
|
95
|
+
: "Queue work did not complete successfully";
|
|
96
|
+
reject(std::move(error));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
89
100
|
}
|
|
90
101
|
|
|
91
102
|
void GPUQueue::copyExternalImageToTexture(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include <future>
|
|
4
3
|
#include <memory>
|
|
5
4
|
#include <string>
|
|
6
5
|
#include <vector>
|
|
@@ -9,7 +8,8 @@
|
|
|
9
8
|
|
|
10
9
|
#include "RNFHybridObject.h"
|
|
11
10
|
|
|
12
|
-
#include "AsyncRunner.h"
|
|
11
|
+
#include "rnwgpu/async/AsyncRunner.h"
|
|
12
|
+
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
13
13
|
|
|
14
14
|
#include "webgpu/webgpu_cpp.h"
|
|
15
15
|
|
|
@@ -25,7 +25,8 @@ namespace m = margelo;
|
|
|
25
25
|
|
|
26
26
|
class GPUQueue : public m::HybridObject {
|
|
27
27
|
public:
|
|
28
|
-
explicit GPUQueue(wgpu::Queue instance,
|
|
28
|
+
explicit GPUQueue(wgpu::Queue instance,
|
|
29
|
+
std::shared_ptr<async::AsyncRunner> async,
|
|
29
30
|
std::string label)
|
|
30
31
|
: HybridObject("GPUQueue"), _instance(instance), _async(async),
|
|
31
32
|
_label(label) {}
|
|
@@ -34,7 +35,7 @@ public:
|
|
|
34
35
|
std::string getBrand() { return _name; }
|
|
35
36
|
|
|
36
37
|
void submit(std::vector<std::shared_ptr<GPUCommandBuffer>> commandBuffers);
|
|
37
|
-
|
|
38
|
+
async::AsyncTaskHandle onSubmittedWorkDone();
|
|
38
39
|
void writeBuffer(std::shared_ptr<GPUBuffer> buffer, uint64_t bufferOffset,
|
|
39
40
|
std::shared_ptr<ArrayBuffer> data,
|
|
40
41
|
std::optional<uint64_t> dataOffsetElements,
|
|
@@ -72,8 +73,8 @@ public:
|
|
|
72
73
|
|
|
73
74
|
private:
|
|
74
75
|
wgpu::Queue _instance;
|
|
75
|
-
std::shared_ptr<AsyncRunner> _async;
|
|
76
|
+
std::shared_ptr<async::AsyncRunner> _async;
|
|
76
77
|
std::string _label;
|
|
77
78
|
};
|
|
78
79
|
|
|
79
|
-
} // namespace rnwgpu
|
|
80
|
+
} // namespace rnwgpu
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
#include "RNFHybridObject.h"
|
|
12
12
|
|
|
13
|
-
#include "AsyncRunner.h"
|
|
14
|
-
|
|
15
13
|
#include "webgpu/webgpu_cpp.h"
|
|
16
14
|
|
|
17
15
|
#include "GPUBindGroup.h"
|
|
@@ -106,4 +104,4 @@ private:
|
|
|
106
104
|
std::string _label;
|
|
107
105
|
};
|
|
108
106
|
|
|
109
|
-
} // namespace rnwgpu
|
|
107
|
+
} // namespace rnwgpu
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
#include "RNFHybridObject.h"
|
|
12
12
|
|
|
13
|
-
#include "AsyncRunner.h"
|
|
14
|
-
|
|
15
13
|
#include "webgpu/webgpu_cpp.h"
|
|
16
14
|
|
|
17
15
|
#include "GPUBindGroup.h"
|
|
@@ -127,4 +125,4 @@ private:
|
|
|
127
125
|
std::string _label;
|
|
128
126
|
};
|
|
129
127
|
|
|
130
|
-
} // namespace rnwgpu
|
|
128
|
+
} // namespace rnwgpu
|