react-native-wgpu 0.4.2 → 0.5.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/README.md +31 -0
- package/android/CMakeLists.txt +3 -3
- package/cpp/jsi/{RNFEnumMapper.h → EnumMapper.h} +2 -6
- package/cpp/jsi/{RNFJSIConverter.h → JSIConverter.h} +27 -110
- package/cpp/jsi/NativeObject.h +607 -0
- package/cpp/jsi/{RNFPromise.cpp → Promise.cpp} +3 -6
- package/cpp/jsi/{RNFPromise.h → Promise.h} +2 -5
- package/cpp/jsi/RuntimeAwareCache.cpp +7 -0
- package/cpp/jsi/RuntimeAwareCache.h +100 -0
- package/cpp/jsi/RuntimeLifecycleMonitor.cpp +72 -0
- package/cpp/jsi/RuntimeLifecycleMonitor.h +32 -0
- package/cpp/rnwgpu/ArrayBuffer.h +8 -12
- package/cpp/rnwgpu/RNWebGPUManager.cpp +187 -28
- package/cpp/rnwgpu/RNWebGPUManager.h +7 -0
- package/cpp/rnwgpu/api/Canvas.h +14 -12
- package/cpp/rnwgpu/api/GPU.cpp +4 -6
- package/cpp/rnwgpu/api/GPU.h +13 -11
- package/cpp/rnwgpu/api/GPUAdapter.cpp +9 -9
- package/cpp/rnwgpu/api/GPUAdapter.h +14 -11
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +17 -15
- package/cpp/rnwgpu/api/GPUBindGroup.h +11 -10
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +12 -11
- package/cpp/rnwgpu/api/GPUBuffer.h +19 -16
- package/cpp/rnwgpu/api/GPUCanvasContext.h +17 -13
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +12 -10
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +35 -32
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +19 -19
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +10 -7
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +28 -27
- package/cpp/rnwgpu/api/GPUComputePipeline.h +14 -13
- package/cpp/rnwgpu/api/GPUDevice.cpp +111 -95
- package/cpp/rnwgpu/api/GPUDevice.h +51 -43
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +12 -10
- package/cpp/rnwgpu/api/GPUError.h +19 -29
- package/cpp/rnwgpu/api/GPUExtent3D.h +7 -10
- package/cpp/rnwgpu/api/GPUExternalTexture.h +12 -11
- package/cpp/rnwgpu/api/GPUInternalError.h +31 -0
- package/cpp/rnwgpu/api/GPUOrigin2D.h +6 -10
- package/cpp/rnwgpu/api/GPUOrigin3D.h +6 -10
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +33 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +12 -10
- package/cpp/rnwgpu/api/GPUQuerySet.h +14 -12
- package/cpp/rnwgpu/api/GPUQueue.h +18 -17
- package/cpp/rnwgpu/api/GPURenderBundle.h +11 -10
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +36 -33
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +49 -47
- package/cpp/rnwgpu/api/GPURenderPipeline.h +14 -12
- package/cpp/rnwgpu/api/GPUSampler.h +11 -10
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +7 -8
- package/cpp/rnwgpu/api/GPUShaderModule.h +13 -12
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +73 -93
- package/cpp/rnwgpu/api/GPUTexture.h +24 -20
- package/cpp/rnwgpu/api/GPUTextureView.h +11 -10
- package/cpp/rnwgpu/api/GPUValidationError.h +32 -0
- package/cpp/rnwgpu/api/ImageBitmap.h +10 -6
- package/cpp/rnwgpu/api/RNWebGPU.h +21 -21
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +7 -11
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +28 -32
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +18 -20
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +11 -14
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +14 -16
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +18 -29
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/Unions.h +3 -3
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +10 -10
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +2 -2
- package/lib/commonjs/external/ModuleProxy.js +36 -0
- package/lib/commonjs/external/ModuleProxy.js.map +1 -0
- package/lib/commonjs/external/index.js +17 -0
- package/lib/commonjs/external/index.js.map +1 -0
- package/lib/commonjs/external/reanimated/ReanimatedProxy.js +18 -0
- package/lib/commonjs/external/reanimated/ReanimatedProxy.js.map +1 -0
- package/lib/commonjs/external/reanimated/index.js +21 -0
- package/lib/commonjs/external/reanimated/index.js.map +1 -0
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +50 -0
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -0
- package/lib/commonjs/main/index.js +2 -142
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/module/external/ModuleProxy.js +28 -0
- package/lib/module/external/ModuleProxy.js.map +1 -0
- package/lib/module/external/index.js +2 -0
- package/lib/module/external/index.js.map +1 -0
- package/lib/module/external/reanimated/ReanimatedProxy.js +12 -0
- package/lib/module/external/reanimated/ReanimatedProxy.js.map +1 -0
- package/lib/module/external/reanimated/index.js +3 -0
- package/lib/module/external/reanimated/index.js.map +1 -0
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js +43 -0
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -0
- package/lib/module/main/index.js +2 -141
- package/lib/module/main/index.js.map +1 -1
- package/lib/typescript/babel.config.d.ts +1 -0
- package/lib/typescript/lib/commonjs/external/ModuleProxy.d.ts +12 -0
- package/lib/typescript/lib/commonjs/external/ModuleProxy.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/external/index.d.ts +2 -0
- package/lib/typescript/lib/commonjs/external/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts +6 -0
- package/lib/typescript/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/external/reanimated/index.d.ts +4 -0
- package/lib/typescript/lib/commonjs/external/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts +9 -0
- package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/ModuleProxy.d.ts +7 -0
- package/lib/typescript/lib/module/external/ModuleProxy.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/index.d.ts +2 -0
- package/lib/typescript/lib/module/external/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/reanimated/ReanimatedProxy.d.ts +5 -0
- package/lib/typescript/lib/module/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/reanimated/index.d.ts +3 -0
- package/lib/typescript/lib/module/external/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts +2 -0
- package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
- package/lib/typescript/src/external/ModuleProxy.d.ts +11 -0
- package/lib/typescript/src/external/ModuleProxy.d.ts.map +1 -0
- package/lib/typescript/src/external/index.d.ts +2 -0
- package/lib/typescript/src/external/index.d.ts.map +1 -0
- package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts +4 -0
- package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
- package/lib/typescript/src/external/reanimated/index.d.ts +3 -0
- package/lib/typescript/src/external/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +8 -0
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
- package/package.json +16 -3
- package/src/external/ModuleProxy.ts +30 -0
- package/src/external/index.ts +1 -0
- package/src/external/reanimated/ReanimatedProxy.ts +19 -0
- package/src/external/reanimated/index.ts +2 -0
- package/src/external/reanimated/registerWebGPUForReanimated.ts +43 -0
- package/src/main/index.tsx +3 -170
- package/cpp/jsi/RNFHybridObject.cpp +0 -150
- package/cpp/jsi/RNFHybridObject.h +0 -181
- package/cpp/jsi/RNFJSIHelper.h +0 -51
- package/cpp/jsi/RNFPointerHolder.h +0 -95
- package/cpp/jsi/RNFRuntimeState.cpp +0 -18
- package/cpp/jsi/RNFRuntimeState.h +0 -106
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
#include "Unions.h"
|
|
10
10
|
|
|
11
|
-
#include "
|
|
11
|
+
#include "NativeObject.h"
|
|
12
12
|
|
|
13
13
|
#include "webgpu/webgpu_cpp.h"
|
|
14
14
|
|
|
@@ -18,17 +18,18 @@
|
|
|
18
18
|
|
|
19
19
|
namespace rnwgpu {
|
|
20
20
|
|
|
21
|
-
namespace
|
|
21
|
+
namespace jsi = facebook::jsi;
|
|
22
22
|
|
|
23
|
-
class GPUComputePassEncoder : public
|
|
23
|
+
class GPUComputePassEncoder : public NativeObject<GPUComputePassEncoder> {
|
|
24
24
|
public:
|
|
25
|
+
static constexpr const char *CLASS_NAME = "GPUComputePassEncoder";
|
|
26
|
+
|
|
25
27
|
explicit GPUComputePassEncoder(wgpu::ComputePassEncoder instance,
|
|
26
28
|
std::string label)
|
|
27
|
-
:
|
|
28
|
-
_label(label) {}
|
|
29
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
|
|
29
30
|
|
|
30
31
|
public:
|
|
31
|
-
std::string getBrand() { return
|
|
32
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
32
33
|
|
|
33
34
|
void setPipeline(std::shared_ptr<GPUComputePipeline> pipeline);
|
|
34
35
|
void dispatchWorkgroups(uint32_t workgroupCountX,
|
|
@@ -51,27 +52,27 @@ public:
|
|
|
51
52
|
_instance.SetLabel(_label.c_str());
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
void
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
56
|
+
installGetter(runtime, prototype, "__brand",
|
|
57
|
+
&GPUComputePassEncoder::getBrand);
|
|
58
|
+
installMethod(runtime, prototype, "setPipeline",
|
|
59
|
+
&GPUComputePassEncoder::setPipeline);
|
|
60
|
+
installMethod(runtime, prototype, "dispatchWorkgroups",
|
|
61
|
+
&GPUComputePassEncoder::dispatchWorkgroups);
|
|
62
|
+
installMethod(runtime, prototype, "dispatchWorkgroupsIndirect",
|
|
63
|
+
&GPUComputePassEncoder::dispatchWorkgroupsIndirect);
|
|
64
|
+
installMethod(runtime, prototype, "end", &GPUComputePassEncoder::end);
|
|
65
|
+
installMethod(runtime, prototype, "pushDebugGroup",
|
|
66
|
+
&GPUComputePassEncoder::pushDebugGroup);
|
|
67
|
+
installMethod(runtime, prototype, "popDebugGroup",
|
|
68
|
+
&GPUComputePassEncoder::popDebugGroup);
|
|
69
|
+
installMethod(runtime, prototype, "insertDebugMarker",
|
|
70
|
+
&GPUComputePassEncoder::insertDebugMarker);
|
|
71
|
+
installMethod(runtime, prototype, "setBindGroup",
|
|
72
|
+
&GPUComputePassEncoder::setBindGroup);
|
|
73
|
+
installGetterSetter(runtime, prototype, "label",
|
|
74
|
+
&GPUComputePassEncoder::getLabel,
|
|
75
|
+
&GPUComputePassEncoder::setLabel);
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
inline const wgpu::ComputePassEncoder get() { return _instance; }
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
#include "Unions.h"
|
|
7
7
|
|
|
8
|
-
#include "
|
|
8
|
+
#include "NativeObject.h"
|
|
9
9
|
|
|
10
10
|
#include "webgpu/webgpu_cpp.h"
|
|
11
11
|
|
|
@@ -13,16 +13,17 @@
|
|
|
13
13
|
|
|
14
14
|
namespace rnwgpu {
|
|
15
15
|
|
|
16
|
-
namespace
|
|
16
|
+
namespace jsi = facebook::jsi;
|
|
17
17
|
|
|
18
|
-
class GPUComputePipeline : public
|
|
18
|
+
class GPUComputePipeline : public NativeObject<GPUComputePipeline> {
|
|
19
19
|
public:
|
|
20
|
+
static constexpr const char *CLASS_NAME = "GPUComputePipeline";
|
|
21
|
+
|
|
20
22
|
explicit GPUComputePipeline(wgpu::ComputePipeline instance, std::string label)
|
|
21
|
-
:
|
|
22
|
-
}
|
|
23
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
|
|
23
24
|
|
|
24
25
|
public:
|
|
25
|
-
std::string getBrand() { return
|
|
26
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
26
27
|
|
|
27
28
|
std::shared_ptr<GPUBindGroupLayout> getBindGroupLayout(uint32_t index);
|
|
28
29
|
|
|
@@ -32,13 +33,13 @@ public:
|
|
|
32
33
|
_instance.SetLabel(_label.c_str());
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
void
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
37
|
+
installGetter(runtime, prototype, "__brand", &GPUComputePipeline::getBrand);
|
|
38
|
+
installMethod(runtime, prototype, "getBindGroupLayout",
|
|
39
|
+
&GPUComputePipeline::getBindGroupLayout);
|
|
40
|
+
installGetterSetter(runtime, prototype, "label",
|
|
41
|
+
&GPUComputePipeline::getLabel,
|
|
42
|
+
&GPUComputePipeline::setLabel);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
inline const wgpu::ComputePipeline get() { return _instance; }
|
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
#include <vector>
|
|
8
8
|
|
|
9
9
|
#include "Convertors.h"
|
|
10
|
-
#include "
|
|
10
|
+
#include "JSIConverter.h"
|
|
11
11
|
|
|
12
12
|
#include "GPUFeatures.h"
|
|
13
|
+
#include "GPUInternalError.h"
|
|
14
|
+
#include "GPUOutOfMemoryError.h"
|
|
15
|
+
#include "GPUValidationError.h"
|
|
13
16
|
|
|
14
17
|
namespace rnwgpu {
|
|
15
18
|
|
|
@@ -26,8 +29,8 @@ void GPUDevice::notifyDeviceLost(wgpu::DeviceLostReason reason,
|
|
|
26
29
|
auto resolve = std::move(*_lostResolve);
|
|
27
30
|
_lostResolve.reset();
|
|
28
31
|
resolve([info = _lostInfo](jsi::Runtime &runtime) mutable {
|
|
29
|
-
return
|
|
30
|
-
|
|
32
|
+
return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(runtime,
|
|
33
|
+
info);
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -248,31 +251,31 @@ async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
|
|
|
248
251
|
descriptor->label.has_value() ? descriptor->label.value() : "");
|
|
249
252
|
auto pipelineHolder = std::make_shared<GPUComputePipeline>(nullptr, label);
|
|
250
253
|
|
|
251
|
-
return _async->postTask(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
});
|
|
269
|
-
} else {
|
|
270
|
-
std::string error = msg ? std::string(msg)
|
|
271
|
-
: "Failed to create compute pipeline";
|
|
272
|
-
reject(std::move(error));
|
|
273
|
-
}
|
|
254
|
+
return _async->postTask([device = _instance, desc, descriptor,
|
|
255
|
+
pipelineHolder](
|
|
256
|
+
const async::AsyncTaskHandle::ResolveFunction
|
|
257
|
+
&resolve,
|
|
258
|
+
const async::AsyncTaskHandle::RejectFunction
|
|
259
|
+
&reject) {
|
|
260
|
+
(void)descriptor;
|
|
261
|
+
device.CreateComputePipelineAsync(
|
|
262
|
+
&desc, wgpu::CallbackMode::AllowProcessEvents,
|
|
263
|
+
[pipelineHolder, resolve,
|
|
264
|
+
reject](wgpu::CreatePipelineAsyncStatus status,
|
|
265
|
+
wgpu::ComputePipeline pipeline, const char *msg) mutable {
|
|
266
|
+
if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
|
|
267
|
+
pipelineHolder->_instance = pipeline;
|
|
268
|
+
resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
|
|
269
|
+
return JSIConverter<std::shared_ptr<GPUComputePipeline>>::toJSI(
|
|
270
|
+
runtime, pipelineHolder);
|
|
274
271
|
});
|
|
275
|
-
|
|
272
|
+
} else {
|
|
273
|
+
std::string error =
|
|
274
|
+
msg ? std::string(msg) : "Failed to create compute pipeline";
|
|
275
|
+
reject(std::move(error));
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
});
|
|
276
279
|
}
|
|
277
280
|
|
|
278
281
|
async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
|
|
@@ -289,31 +292,31 @@ async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
|
|
|
289
292
|
descriptor->label.has_value() ? descriptor->label.value() : "");
|
|
290
293
|
auto pipelineHolder = std::make_shared<GPURenderPipeline>(nullptr, label);
|
|
291
294
|
|
|
292
|
-
return _async->postTask(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
310
|
-
} else {
|
|
311
|
-
std::string error =
|
|
312
|
-
msg ? std::string(msg) : "Failed to create render pipeline";
|
|
313
|
-
reject(std::move(error));
|
|
314
|
-
}
|
|
295
|
+
return _async->postTask([device = _instance, desc, descriptor,
|
|
296
|
+
pipelineHolder](
|
|
297
|
+
const async::AsyncTaskHandle::ResolveFunction
|
|
298
|
+
&resolve,
|
|
299
|
+
const async::AsyncTaskHandle::RejectFunction
|
|
300
|
+
&reject) {
|
|
301
|
+
(void)descriptor;
|
|
302
|
+
device.CreateRenderPipelineAsync(
|
|
303
|
+
&desc, wgpu::CallbackMode::AllowProcessEvents,
|
|
304
|
+
[pipelineHolder, resolve,
|
|
305
|
+
reject](wgpu::CreatePipelineAsyncStatus status,
|
|
306
|
+
wgpu::RenderPipeline pipeline, const char *msg) mutable {
|
|
307
|
+
if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
|
|
308
|
+
pipelineHolder->_instance = pipeline;
|
|
309
|
+
resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
|
|
310
|
+
return JSIConverter<std::shared_ptr<GPURenderPipeline>>::toJSI(
|
|
311
|
+
runtime, pipelineHolder);
|
|
315
312
|
});
|
|
316
|
-
|
|
313
|
+
} else {
|
|
314
|
+
std::string error =
|
|
315
|
+
msg ? std::string(msg) : "Failed to create render pipeline";
|
|
316
|
+
reject(std::move(error));
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
317
320
|
}
|
|
318
321
|
|
|
319
322
|
void GPUDevice::pushErrorScope(wgpu::ErrorFilter filter) {
|
|
@@ -323,47 +326,60 @@ void GPUDevice::pushErrorScope(wgpu::ErrorFilter filter) {
|
|
|
323
326
|
async::AsyncTaskHandle GPUDevice::popErrorScope() {
|
|
324
327
|
auto device = _instance;
|
|
325
328
|
|
|
326
|
-
return _async->postTask(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
});
|
|
329
|
+
return _async->postTask([device](const async::AsyncTaskHandle::ResolveFunction
|
|
330
|
+
&resolve,
|
|
331
|
+
const async::AsyncTaskHandle::RejectFunction
|
|
332
|
+
&reject) {
|
|
333
|
+
device.PopErrorScope(
|
|
334
|
+
wgpu::CallbackMode::AllowProcessEvents,
|
|
335
|
+
[resolve, reject](wgpu::PopErrorScopeStatus status,
|
|
336
|
+
wgpu::ErrorType type, wgpu::StringView message) {
|
|
337
|
+
if (status == wgpu::PopErrorScopeStatus::Error ||
|
|
338
|
+
status == wgpu::PopErrorScopeStatus::CallbackCancelled) {
|
|
339
|
+
reject("PopErrorScope failed");
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
std::string messageString =
|
|
344
|
+
message.length ? std::string(message.data, message.length) : "";
|
|
345
|
+
|
|
346
|
+
switch (type) {
|
|
347
|
+
case wgpu::ErrorType::NoError:
|
|
348
|
+
resolve([](jsi::Runtime &runtime) mutable {
|
|
349
|
+
return jsi::Value::null();
|
|
365
350
|
});
|
|
366
|
-
|
|
351
|
+
break;
|
|
352
|
+
case wgpu::ErrorType::Validation: {
|
|
353
|
+
auto error = std::make_shared<GPUValidationError>(messageString);
|
|
354
|
+
resolve([error](jsi::Runtime &runtime) mutable {
|
|
355
|
+
return JSIConverter<std::shared_ptr<GPUValidationError>>::toJSI(
|
|
356
|
+
runtime, error);
|
|
357
|
+
});
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case wgpu::ErrorType::OutOfMemory: {
|
|
361
|
+
auto error = std::make_shared<GPUOutOfMemoryError>(messageString);
|
|
362
|
+
resolve([error](jsi::Runtime &runtime) mutable {
|
|
363
|
+
return JSIConverter<std::shared_ptr<GPUOutOfMemoryError>>::toJSI(
|
|
364
|
+
runtime, error);
|
|
365
|
+
});
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case wgpu::ErrorType::Internal:
|
|
369
|
+
case wgpu::ErrorType::Unknown: {
|
|
370
|
+
auto error = std::make_shared<GPUInternalError>(messageString);
|
|
371
|
+
resolve([error](jsi::Runtime &runtime) mutable {
|
|
372
|
+
return JSIConverter<std::shared_ptr<GPUInternalError>>::toJSI(
|
|
373
|
+
runtime, error);
|
|
374
|
+
});
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
default:
|
|
378
|
+
reject("Unhandled GPU error type");
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
});
|
|
367
383
|
}
|
|
368
384
|
|
|
369
385
|
std::unordered_set<std::string> GPUDevice::getFeatures() {
|
|
@@ -390,8 +406,8 @@ async::AsyncTaskHandle GPUDevice::getLost() {
|
|
|
390
406
|
const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
391
407
|
const async::AsyncTaskHandle::RejectFunction & /*reject*/) {
|
|
392
408
|
resolve([info](jsi::Runtime &runtime) mutable {
|
|
393
|
-
return
|
|
394
|
-
|
|
409
|
+
return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(
|
|
410
|
+
runtime, info);
|
|
395
411
|
});
|
|
396
412
|
},
|
|
397
413
|
false);
|
|
@@ -402,8 +418,8 @@ async::AsyncTaskHandle GPUDevice::getLost() {
|
|
|
402
418
|
const async::AsyncTaskHandle::RejectFunction & /*reject*/) {
|
|
403
419
|
if (_lostSettled && _lostInfo) {
|
|
404
420
|
resolve([info = _lostInfo](jsi::Runtime &runtime) mutable {
|
|
405
|
-
return
|
|
406
|
-
|
|
421
|
+
return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(
|
|
422
|
+
runtime, info);
|
|
407
423
|
});
|
|
408
424
|
return;
|
|
409
425
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
#include "Unions.h"
|
|
11
11
|
|
|
12
|
-
#include "
|
|
12
|
+
#include "NativeObject.h"
|
|
13
13
|
|
|
14
14
|
#include "rnwgpu/async/AsyncRunner.h"
|
|
15
15
|
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
@@ -49,18 +49,20 @@
|
|
|
49
49
|
|
|
50
50
|
namespace rnwgpu {
|
|
51
51
|
|
|
52
|
-
namespace
|
|
52
|
+
namespace jsi = facebook::jsi;
|
|
53
53
|
|
|
54
|
-
class GPUDevice : public
|
|
54
|
+
class GPUDevice : public NativeObject<GPUDevice> {
|
|
55
55
|
public:
|
|
56
|
+
static constexpr const char *CLASS_NAME = "GPUDevice";
|
|
57
|
+
|
|
56
58
|
explicit GPUDevice(wgpu::Device instance,
|
|
57
59
|
std::shared_ptr<async::AsyncRunner> async,
|
|
58
60
|
std::string label)
|
|
59
|
-
:
|
|
61
|
+
: NativeObject(CLASS_NAME), _instance(instance), _async(async),
|
|
60
62
|
_label(label) {}
|
|
61
63
|
|
|
62
64
|
public:
|
|
63
|
-
std::string getBrand() { return
|
|
65
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
64
66
|
|
|
65
67
|
void destroy();
|
|
66
68
|
std::shared_ptr<GPUBuffer>
|
|
@@ -109,44 +111,50 @@ public:
|
|
|
109
111
|
_instance.SetLabel(_label.c_str());
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
void
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
114
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
115
|
+
installGetter(runtime, prototype, "__brand", &GPUDevice::getBrand);
|
|
116
|
+
installMethod(runtime, prototype, "destroy", &GPUDevice::destroy);
|
|
117
|
+
installMethod(runtime, prototype, "createBuffer", &GPUDevice::createBuffer);
|
|
118
|
+
installMethod(runtime, prototype, "createTexture",
|
|
119
|
+
&GPUDevice::createTexture);
|
|
120
|
+
installMethod(runtime, prototype, "createSampler",
|
|
121
|
+
&GPUDevice::createSampler);
|
|
122
|
+
installMethod(runtime, prototype, "importExternalTexture",
|
|
123
|
+
&GPUDevice::importExternalTexture);
|
|
124
|
+
installMethod(runtime, prototype, "createBindGroupLayout",
|
|
125
|
+
&GPUDevice::createBindGroupLayout);
|
|
126
|
+
installMethod(runtime, prototype, "createPipelineLayout",
|
|
127
|
+
&GPUDevice::createPipelineLayout);
|
|
128
|
+
installMethod(runtime, prototype, "createBindGroup",
|
|
129
|
+
&GPUDevice::createBindGroup);
|
|
130
|
+
installMethod(runtime, prototype, "createShaderModule",
|
|
131
|
+
&GPUDevice::createShaderModule);
|
|
132
|
+
installMethod(runtime, prototype, "createComputePipeline",
|
|
133
|
+
&GPUDevice::createComputePipeline);
|
|
134
|
+
installMethod(runtime, prototype, "createRenderPipeline",
|
|
135
|
+
&GPUDevice::createRenderPipeline);
|
|
136
|
+
installMethod(runtime, prototype, "createComputePipelineAsync",
|
|
137
|
+
&GPUDevice::createComputePipelineAsync);
|
|
138
|
+
installMethod(runtime, prototype, "createRenderPipelineAsync",
|
|
139
|
+
&GPUDevice::createRenderPipelineAsync);
|
|
140
|
+
installMethod(runtime, prototype, "createCommandEncoder",
|
|
141
|
+
&GPUDevice::createCommandEncoder);
|
|
142
|
+
installMethod(runtime, prototype, "createRenderBundleEncoder",
|
|
143
|
+
&GPUDevice::createRenderBundleEncoder);
|
|
144
|
+
installMethod(runtime, prototype, "createQuerySet",
|
|
145
|
+
&GPUDevice::createQuerySet);
|
|
146
|
+
installMethod(runtime, prototype, "pushErrorScope",
|
|
147
|
+
&GPUDevice::pushErrorScope);
|
|
148
|
+
installMethod(runtime, prototype, "popErrorScope",
|
|
149
|
+
&GPUDevice::popErrorScope);
|
|
150
|
+
installGetter(runtime, prototype, "features", &GPUDevice::getFeatures);
|
|
151
|
+
installGetter(runtime, prototype, "limits", &GPUDevice::getLimits);
|
|
152
|
+
installGetter(runtime, prototype, "queue", &GPUDevice::getQueue);
|
|
153
|
+
installGetter(runtime, prototype, "lost", &GPUDevice::getLost);
|
|
154
|
+
installGetterSetter(runtime, prototype, "label", &GPUDevice::getLabel,
|
|
155
|
+
&GPUDevice::setLabel);
|
|
156
|
+
installMethod(runtime, prototype, "forceLossForTesting",
|
|
157
|
+
&GPUDevice::forceLossForTesting);
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
inline const wgpu::Device get() { return _instance; }
|
|
@@ -4,30 +4,32 @@
|
|
|
4
4
|
|
|
5
5
|
#include "Unions.h"
|
|
6
6
|
|
|
7
|
-
#include "
|
|
7
|
+
#include "NativeObject.h"
|
|
8
8
|
|
|
9
9
|
#include "webgpu/webgpu_cpp.h"
|
|
10
10
|
|
|
11
11
|
namespace rnwgpu {
|
|
12
12
|
|
|
13
|
-
namespace
|
|
13
|
+
namespace jsi = facebook::jsi;
|
|
14
14
|
|
|
15
|
-
class GPUDeviceLostInfo : public
|
|
15
|
+
class GPUDeviceLostInfo : public NativeObject<GPUDeviceLostInfo> {
|
|
16
16
|
public:
|
|
17
|
+
static constexpr const char *CLASS_NAME = "GPUDeviceLostInfo";
|
|
18
|
+
|
|
17
19
|
explicit GPUDeviceLostInfo(wgpu::DeviceLostReason reason, std::string message)
|
|
18
|
-
:
|
|
20
|
+
: NativeObject(CLASS_NAME), _reason(reason), _message(message) {}
|
|
19
21
|
|
|
20
22
|
public:
|
|
21
|
-
std::string getBrand() { return
|
|
23
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
22
24
|
|
|
23
25
|
wgpu::DeviceLostReason getReason() { return _reason; }
|
|
24
26
|
std::string getMessage() { return _message; }
|
|
25
27
|
|
|
26
|
-
void
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
29
|
+
installGetter(runtime, prototype, "__brand", &GPUDeviceLostInfo::getBrand);
|
|
30
|
+
installGetter(runtime, prototype, "reason", &GPUDeviceLostInfo::getReason);
|
|
31
|
+
installGetter(runtime, prototype, "message",
|
|
32
|
+
&GPUDeviceLostInfo::getMessage);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
private:
|
|
@@ -1,45 +1,35 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include <memory>
|
|
4
3
|
#include <string>
|
|
5
|
-
#include <utility>
|
|
6
4
|
|
|
7
|
-
#include "
|
|
8
|
-
|
|
9
|
-
#include "RNFEnumMapper.h"
|
|
10
|
-
#include "RNFJSIConverter.h"
|
|
5
|
+
#include "NativeObject.h"
|
|
11
6
|
|
|
12
7
|
namespace rnwgpu {
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
namespace jsi = facebook::jsi;
|
|
15
10
|
|
|
11
|
+
class GPUError : public NativeObject<GPUError> {
|
|
16
12
|
public:
|
|
17
|
-
|
|
18
|
-
: type(aType), message(std::move(aMessage)) {}
|
|
13
|
+
static constexpr const char *CLASS_NAME = "GPUError";
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
15
|
+
explicit GPUError(std::string message)
|
|
16
|
+
: NativeObject(CLASS_NAME), _message(std::move(message)) {}
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
public:
|
|
19
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
20
|
+
std::string getMessage() { return _message; }
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
23
|
+
installGetter(runtime, prototype, "__brand", &GPUError::getBrand);
|
|
24
|
+
installGetter(runtime, prototype, "message", &GPUError::getMessage);
|
|
25
|
+
}
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
protected:
|
|
28
|
+
// Protected constructor for subclasses
|
|
29
|
+
GPUError(const char *className, std::string message)
|
|
30
|
+
: NativeObject(className), _message(std::move(message)) {}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
static std::shared_ptr<rnwgpu::GPUBindGroupEntry>
|
|
32
|
-
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
|
|
33
|
-
throw std::runtime_error("Invalid GPUBindGroupEntry::fromJSI()");
|
|
34
|
-
}
|
|
35
|
-
static jsi::Value toJSI(jsi::Runtime &runtime,
|
|
36
|
-
std::shared_ptr<rnwgpu::GPUError> arg) {
|
|
37
|
-
jsi::Object result(runtime);
|
|
38
|
-
result.setProperty(
|
|
39
|
-
runtime, "message",
|
|
40
|
-
jsi::String::createFromUtf8(runtime, arg->message.c_str()));
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
32
|
+
std::string _message;
|
|
43
33
|
};
|
|
44
34
|
|
|
45
|
-
} // namespace
|
|
35
|
+
} // namespace rnwgpu
|