react-native-wgpu 0.1.0 → 0.1.2
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 +221 -13
- package/android/CMakeLists.txt +15 -1
- package/android/build.gradle +0 -18
- package/android/cpp/AndroidPlatformContext.h +26 -0
- package/android/cpp/cpp-adapter.cpp +66 -3
- package/android/src/main/java/com/webgpu/WebGPUModule.java +64 -22
- package/android/src/main/java/com/webgpu/WebGPUView.java +63 -8
- package/android/src/main/java/com/webgpu/WebGPUViewManager.java +5 -6
- package/android/src/newarch/{WgpuViewManagerSpec.java → com/webgpu/WebGPUViewManagerSpec.java} +5 -5
- package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +23 -0
- package/android/src/oldarch/{WebGPUViewManagerSpec.java → com/webgpu/WebGPUViewManagerSpec.java} +1 -1
- package/cpp/{Logger.h → WGPULogger.h} +13 -6
- package/cpp/dawn/webgpu.h +9 -0
- package/cpp/dawn/webgpu_cpp.h +95 -43
- package/cpp/dawn/webgpu_cpp_print.h +6 -0
- package/cpp/dawn/wire/client/webgpu_cpp.h +80 -43
- package/cpp/jsi/RNFHybridObject.cpp +1 -1
- package/cpp/jsi/RNFHybridObject.h +4 -4
- package/cpp/jsi/RNFJSIConverter.h +204 -17
- package/cpp/rnwgpu/ArrayBuffer.h +72 -0
- package/cpp/rnwgpu/PlatformContext.h +16 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +14 -9
- package/cpp/rnwgpu/RNWebGPUManager.h +12 -1
- package/cpp/rnwgpu/SurfaceRegistry.h +36 -0
- package/cpp/rnwgpu/api/AsyncRunner.h +30 -0
- package/cpp/rnwgpu/api/Canvas.h +55 -0
- package/cpp/rnwgpu/api/Convertors.h +765 -0
- package/cpp/rnwgpu/api/External.h +12 -0
- package/cpp/rnwgpu/api/GPU.cpp +100 -23
- package/cpp/rnwgpu/api/GPU.h +24 -6
- package/cpp/rnwgpu/api/GPUAdapter.cpp +122 -8
- package/cpp/rnwgpu/api/GPUAdapter.h +24 -5
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +19 -7
- package/cpp/rnwgpu/api/GPUBindGroup.cpp +3 -0
- package/cpp/rnwgpu/api/GPUBindGroup.h +11 -4
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +11 -4
- package/cpp/rnwgpu/api/GPUBuffer.cpp +82 -7
- package/cpp/rnwgpu/api/GPUBuffer.h +43 -7
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +63 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.h +51 -8
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +11 -4
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +177 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +75 -3
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +65 -8
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +6 -4
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +58 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +49 -3
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +11 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.h +18 -3
- package/cpp/rnwgpu/api/GPUDevice.cpp +330 -3
- package/cpp/rnwgpu/api/GPUDevice.h +119 -5
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +6 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +14 -7
- package/cpp/rnwgpu/api/GPUError.h +42 -0
- package/cpp/rnwgpu/api/GPUExtent3D.h +69 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +11 -4
- package/cpp/rnwgpu/api/GPUFeatures.h +221 -0
- package/cpp/rnwgpu/api/GPUOrigin2D.h +59 -0
- package/cpp/rnwgpu/api/GPUOrigin3D.h +66 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +11 -4
- package/cpp/rnwgpu/api/GPUQuerySet.cpp +11 -0
- package/cpp/rnwgpu/api/GPUQuerySet.h +19 -5
- package/cpp/rnwgpu/api/GPUQueue.cpp +110 -0
- package/cpp/rnwgpu/api/GPUQueue.h +45 -4
- package/cpp/rnwgpu/api/GPURenderBundle.h +11 -4
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +128 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +72 -3
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +161 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +93 -3
- package/cpp/rnwgpu/api/GPURenderPipeline.cpp +13 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.h +18 -3
- package/cpp/rnwgpu/api/GPUSampler.h +11 -4
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +39 -0
- package/cpp/rnwgpu/api/GPUShaderModule.h +23 -4
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +133 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +128 -4
- package/cpp/rnwgpu/api/GPUTexture.cpp +47 -0
- package/cpp/rnwgpu/api/GPUTexture.h +38 -4
- package/cpp/rnwgpu/api/GPUTextureView.h +11 -4
- package/cpp/rnwgpu/api/ImageData.h +50 -0
- package/cpp/rnwgpu/api/Navigator.h +46 -0
- package/cpp/rnwgpu/api/WebGPUCanvasContextFactory.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +31 -43
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +40 -31
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +24 -32
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +56 -49
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +27 -20
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +23 -31
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +25 -36
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +25 -25
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +26 -46
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +31 -53
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +72 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +27 -33
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +24 -25
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +25 -42
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +32 -42
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +58 -76
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +38 -30
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +11 -11
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +43 -34
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +39 -46
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +29 -45
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +25 -34
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +32 -36
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +42 -44
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +24 -34
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +24 -32
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +25 -35
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +35 -26
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +29 -35
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +23 -43
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +49 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +41 -57
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +42 -61
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +54 -66
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +52 -55
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +25 -42
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +60 -56
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +21 -20
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +17 -14
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +63 -63
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +28 -27
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +28 -49
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +32 -23
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +27 -29
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +27 -20
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +49 -76
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +48 -64
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +29 -31
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +23 -44
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +30 -36
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +39 -38
- package/cpp/rnwgpu/api/descriptors/Unions.h +57 -2
- package/ios/IOSPlatformContext.h +16 -0
- package/ios/IOSPlatformContext.mm +18 -0
- package/ios/MetalView.h +10 -0
- package/ios/MetalView.mm +27 -0
- package/ios/SurfaceUtils.h +13 -0
- package/ios/SurfaceUtils.mm +24 -0
- package/ios/WebGPUModule.h +8 -7
- package/ios/WebGPUModule.mm +47 -14
- package/ios/WebGPUView.h +6 -3
- package/ios/WebGPUView.mm +36 -24
- package/ios/WebGPUViewComponentDescriptor.h +61 -0
- package/ios/WebGPUViewManager.mm +6 -4
- package/lib/commonjs/Canvas.js +49 -0
- package/lib/commonjs/Canvas.js.map +1 -0
- package/lib/commonjs/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
- package/lib/commonjs/{WebGPUNativeModule.js.map → NativeWebGPUModule.js.map} +1 -1
- package/lib/commonjs/WebGPUView.js +2 -0
- package/lib/commonjs/WebGPUView.js.map +1 -0
- package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/commonjs/index.js +158 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Canvas.js +42 -0
- package/lib/module/Canvas.js.map +1 -0
- package/lib/module/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
- package/lib/module/NativeWebGPUModule.js.map +1 -0
- package/lib/module/WebGPUView.js +2 -0
- package/lib/module/WebGPUView.js.map +1 -0
- package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/module/index.js +144 -6
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/example/src/Triangle/triangle.d.ts +3 -0
- package/lib/typescript/example/src/Triangle/triangle.d.ts.map +1 -0
- package/lib/typescript/example/src/Wireframe/Shaders.d.ts +3 -0
- package/lib/typescript/example/src/Wireframe/Shaders.d.ts.map +1 -0
- package/lib/typescript/example/src/Wireframe/models.d.ts +29 -0
- package/lib/typescript/example/src/Wireframe/models.d.ts.map +1 -0
- package/lib/typescript/example/src/components/DrawingContext.d.ts +13 -0
- package/lib/typescript/example/src/components/DrawingContext.d.ts.map +1 -0
- package/lib/typescript/example/src/components/cube.d.ts +7 -0
- package/lib/typescript/example/src/components/cube.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/sphere.d.ts +12 -0
- package/lib/typescript/example/src/components/meshes/sphere.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/teapot.d.ts +6 -0
- package/lib/typescript/example/src/components/meshes/teapot.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/utils.d.ts +10 -0
- package/lib/typescript/example/src/components/meshes/utils.d.ts.map +1 -0
- package/lib/typescript/jest.config.d.ts +4 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts +4 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
- package/lib/typescript/lib/commonjs/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts +1 -0
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +0 -2
- package/lib/typescript/lib/module/Canvas.d.ts +2 -0
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -0
- package/lib/typescript/lib/module/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
- package/lib/typescript/lib/module/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebGPUView.d.ts +1 -0
- package/lib/typescript/lib/module/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +2 -3
- package/lib/typescript/src/Canvas.d.ts +22 -0
- package/lib/typescript/src/Canvas.d.ts.map +1 -0
- package/lib/typescript/src/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +2 -1
- package/lib/typescript/src/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUView.d.ts +1 -0
- package/lib/typescript/src/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +2 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -7
- package/lib/typescript/src/index.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/dawn.json +4597 -0
- package/libs/ios/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/ios/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.xcframework/Info.plist +44 -0
- package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/ios/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/package.json +25 -8
- package/{react-native-webgpu.podspec → react-native-wgpu.podspec} +6 -9
- package/src/Canvas.tsx +68 -0
- package/src/{WebGPUNativeModule.ts → NativeWebGPUModule.ts} +1 -0
- package/src/WebGPUView.tsx +0 -0
- package/src/WebGPUViewNativeComponent.ts +2 -1
- package/src/index.tsx +172 -8
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/cpp/rnwgpu/MutableBuffer.h +0 -48
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -33
- package/cpp/rnwgpu/api/descriptors/GPUColorDict.h +0 -81
- package/cpp/rnwgpu/api/descriptors/GPUExtent3DDict.h +0 -76
- package/cpp/rnwgpu/api/descriptors/GPUExtent3DDictStrict.h +0 -91
- package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDict.h +0 -61
- package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDictStrict.h +0 -75
- package/cpp/rnwgpu/api/descriptors/GPUOrigin3DDict.h +0 -71
- package/cpp/rnwgpu/api/descriptors/GPUPipelineErrorInit.h +0 -54
- package/cpp/rnwgpu/api/descriptors/GPURenderPassLayout.h +0 -83
- package/ios/RNFAppleLogger.mm +0 -22
- package/ios/Utils.h +0 -5
- package/ios/Utils.m +0 -26
- package/lib/module/WebGPUNativeModule.js.map +0 -1
- package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts.map +0 -1
- package/lib/typescript/lib/module/WebGPUNativeModule.d.ts.map +0 -1
- package/lib/typescript/scripts/build/copy-artifacts.d.ts +0 -2
- package/lib/typescript/scripts/build/copy-artifacts.d.ts.map +0 -1
- package/lib/typescript/scripts/build/dawn.d.ts +0 -2
- package/lib/typescript/scripts/build/dawn.d.ts.map +0 -1
- package/lib/typescript/scripts/build/util.d.ts +0 -13
- package/lib/typescript/scripts/build/util.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/codegen.d.ts +0 -2
- package/lib/typescript/scripts/codegen/codegen.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/model/dawn.d.ts +0 -2
- package/lib/typescript/scripts/codegen/model/dawn.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/model/model.d.ts +0 -8
- package/lib/typescript/scripts/codegen/model/model.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts +0 -4
- package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Enum.d.ts +0 -3
- package/lib/typescript/scripts/codegen/templates/Enum.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts +0 -3
- package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Unions.d.ts +0 -6
- package/lib/typescript/scripts/codegen/templates/Unions.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/common.d.ts +0 -9
- package/lib/typescript/scripts/codegen/templates/common.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/util.d.ts +0 -2
- package/lib/typescript/scripts/codegen/util.d.ts.map +0 -1
- package/lib/typescript/src/WebGPUNativeModule.d.ts.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <jsi/jsi.h>
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
6
|
+
#include "RNFJSIConverter.h"
|
|
7
|
+
|
|
8
|
+
namespace rnwgpu {
|
|
9
|
+
|
|
10
|
+
namespace jsi = facebook::jsi;
|
|
11
|
+
|
|
12
|
+
struct ArrayBuffer : jsi::MutableBuffer {
|
|
13
|
+
ArrayBuffer(void *data, size_t size, size_t bytesPerElement)
|
|
14
|
+
: _data(data), _size(size), _bytesPerElement(bytesPerElement) {}
|
|
15
|
+
|
|
16
|
+
~ArrayBuffer() override {}
|
|
17
|
+
|
|
18
|
+
size_t size() const override { return _size; }
|
|
19
|
+
|
|
20
|
+
uint8_t *data() override { return static_cast<uint8_t *>(_data); }
|
|
21
|
+
|
|
22
|
+
void *_data;
|
|
23
|
+
size_t _size;
|
|
24
|
+
size_t _bytesPerElement;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
} // namespace rnwgpu
|
|
28
|
+
|
|
29
|
+
namespace margelo {
|
|
30
|
+
|
|
31
|
+
static std::shared_ptr<rnwgpu::ArrayBuffer>
|
|
32
|
+
createArrayBufferFromJSI(jsi::Runtime &runtime,
|
|
33
|
+
const jsi::ArrayBuffer &arrayBuffer,
|
|
34
|
+
size_t bytesPerElement) {
|
|
35
|
+
auto size = arrayBuffer.size(runtime);
|
|
36
|
+
return std::make_shared<rnwgpu::ArrayBuffer>(arrayBuffer.data(runtime), size,
|
|
37
|
+
bytesPerElement);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
template <> struct JSIConverter<std::shared_ptr<rnwgpu::ArrayBuffer>> {
|
|
41
|
+
static std::shared_ptr<rnwgpu::ArrayBuffer>
|
|
42
|
+
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBound) {
|
|
43
|
+
if (arg.isObject()) {
|
|
44
|
+
auto obj = arg.getObject(runtime);
|
|
45
|
+
if (obj.isArrayBuffer(runtime)) {
|
|
46
|
+
return createArrayBufferFromJSI(runtime, obj.getArrayBuffer(runtime),
|
|
47
|
+
1);
|
|
48
|
+
}
|
|
49
|
+
if (obj.hasProperty(runtime, "buffer")) {
|
|
50
|
+
auto bufferProp = obj.getProperty(runtime, "buffer");
|
|
51
|
+
if (bufferProp.isObject() &&
|
|
52
|
+
bufferProp.getObject(runtime).isArrayBuffer(runtime)) {
|
|
53
|
+
auto buff = bufferProp.getObject(runtime);
|
|
54
|
+
auto bytesPerElements =
|
|
55
|
+
obj.getProperty(runtime, "BYTES_PER_ELEMENT").asNumber();
|
|
56
|
+
return createArrayBufferFromJSI(
|
|
57
|
+
runtime, buff.getArrayBuffer(runtime),
|
|
58
|
+
static_cast<size_t>(bytesPerElements));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
throw std::runtime_error("ArrayBuffer::fromJSI: argument is not an object "
|
|
63
|
+
"with an ArrayBuffer 'buffer' property");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static jsi::Value toJSI(jsi::Runtime &runtime,
|
|
67
|
+
std::shared_ptr<rnwgpu::ArrayBuffer> arg) {
|
|
68
|
+
return jsi::ArrayBuffer(runtime, arg);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
} // namespace margelo
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "webgpu/webgpu_cpp.h"
|
|
4
|
+
|
|
5
|
+
namespace rnwgpu {
|
|
6
|
+
|
|
7
|
+
class PlatformContext {
|
|
8
|
+
public:
|
|
9
|
+
PlatformContext() = default;
|
|
10
|
+
virtual ~PlatformContext() = default;
|
|
11
|
+
|
|
12
|
+
virtual wgpu::Surface makeSurface(wgpu::Instance instance, void *surface,
|
|
13
|
+
int width, int height) = 0;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
} // namespace rnwgpu
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#include "RNWebGPUManager.h"
|
|
2
2
|
|
|
3
3
|
#include "GPU.h"
|
|
4
|
+
#include "Navigator.h"
|
|
5
|
+
|
|
4
6
|
// Enums
|
|
5
7
|
#include "GPUBufferUsage.h"
|
|
6
8
|
#include "GPUColorWrite.h"
|
|
@@ -12,16 +14,16 @@
|
|
|
12
14
|
#include <utility>
|
|
13
15
|
|
|
14
16
|
namespace rnwgpu {
|
|
17
|
+
|
|
15
18
|
RNWebGPUManager::RNWebGPUManager(
|
|
16
19
|
jsi::Runtime *jsRuntime,
|
|
17
|
-
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker
|
|
18
|
-
|
|
20
|
+
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
|
|
21
|
+
std::shared_ptr<PlatformContext> platformContext)
|
|
22
|
+
: _jsRuntime(jsRuntime), _jsCallInvoker(jsCallInvoker),
|
|
23
|
+
_platformContext(platformContext) {
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
instanceDesc.features.timedWaitAnyMaxCount = 64;
|
|
23
|
-
auto gpu =
|
|
24
|
-
std::make_shared<GPU>(std::move(wgpu::CreateInstance(&instanceDesc)));
|
|
25
|
+
_gpu = std::make_shared<GPU>();
|
|
26
|
+
auto navigator = std::make_shared<Navigator>(_gpu, _platformContext);
|
|
25
27
|
|
|
26
28
|
auto bufferUsage = std::make_shared<GPUBufferUsage>();
|
|
27
29
|
_jsRuntime->global().setProperty(
|
|
@@ -49,12 +51,15 @@ RNWebGPUManager::RNWebGPUManager(
|
|
|
49
51
|
jsi::Object::createFromHostObject(*_jsRuntime, std::move(textureUsage)));
|
|
50
52
|
|
|
51
53
|
_jsRuntime->global().setProperty(
|
|
52
|
-
*_jsRuntime, "
|
|
53
|
-
jsi::Object::createFromHostObject(*_jsRuntime,
|
|
54
|
+
*_jsRuntime, "navigator",
|
|
55
|
+
jsi::Object::createFromHostObject(*_jsRuntime, navigator));
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
RNWebGPUManager::~RNWebGPUManager() {
|
|
57
59
|
_jsRuntime = nullptr;
|
|
58
60
|
_jsCallInvoker = nullptr;
|
|
59
61
|
}
|
|
62
|
+
|
|
63
|
+
std::shared_ptr<GPU> RNWebGPUManager::getGPU() { return _gpu; }
|
|
64
|
+
|
|
60
65
|
} // namespace rnwgpu
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
#include <memory>
|
|
4
4
|
|
|
5
|
+
#include "GPU.h"
|
|
6
|
+
#include "PlatformContext.h"
|
|
7
|
+
#include "SurfaceRegistry.h"
|
|
8
|
+
|
|
5
9
|
namespace facebook {
|
|
6
10
|
namespace jsi {
|
|
7
11
|
class Runtime;
|
|
@@ -19,12 +23,19 @@ namespace react = facebook::react;
|
|
|
19
23
|
class RNWebGPUManager {
|
|
20
24
|
public:
|
|
21
25
|
RNWebGPUManager(jsi::Runtime *jsRuntime,
|
|
22
|
-
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker
|
|
26
|
+
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
|
|
27
|
+
std::shared_ptr<PlatformContext> platformContext);
|
|
23
28
|
~RNWebGPUManager();
|
|
24
29
|
|
|
30
|
+
SurfaceRegistry surfacesRegistry;
|
|
31
|
+
|
|
32
|
+
std::shared_ptr<GPU> getGPU();
|
|
33
|
+
|
|
25
34
|
private:
|
|
26
35
|
jsi::Runtime *_jsRuntime;
|
|
27
36
|
std::shared_ptr<facebook::react::CallInvoker> _jsCallInvoker;
|
|
37
|
+
std::shared_ptr<PlatformContext> _platformContext;
|
|
38
|
+
std::shared_ptr<GPU> _gpu;
|
|
28
39
|
};
|
|
29
40
|
|
|
30
41
|
} // namespace rnwgpu
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <unordered_map>
|
|
5
|
+
|
|
6
|
+
#include "webgpu/webgpu_cpp.h"
|
|
7
|
+
|
|
8
|
+
#include "Canvas.h"
|
|
9
|
+
|
|
10
|
+
namespace rnwgpu {
|
|
11
|
+
|
|
12
|
+
class SurfaceRegistry {
|
|
13
|
+
std::unordered_map<int, std::shared_ptr<Canvas>> _registry;
|
|
14
|
+
|
|
15
|
+
public:
|
|
16
|
+
void addSurface(const int contextId, void *surface, float width,
|
|
17
|
+
float height) {
|
|
18
|
+
_registry[contextId] = std::make_shared<Canvas>(
|
|
19
|
+
reinterpret_cast<uint64_t>(surface), width, height);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
std::shared_ptr<Canvas> getSurface(const int contextId) {
|
|
23
|
+
return _registry[contextId];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
void removeSurface(const int contextId) { _registry.erase(contextId); }
|
|
27
|
+
|
|
28
|
+
void updateSurface(const int contextId, float width, float height) {
|
|
29
|
+
if (_registry.find(contextId) != _registry.end()) {
|
|
30
|
+
_registry[contextId]->setClientWidth(width);
|
|
31
|
+
_registry[contextId]->setClientHeight(height);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "webgpu/webgpu_cpp.h"
|
|
4
|
+
|
|
5
|
+
#include <future>
|
|
6
|
+
#include <utility>
|
|
7
|
+
|
|
8
|
+
namespace rnwgpu {
|
|
9
|
+
|
|
10
|
+
class AsyncRunner {
|
|
11
|
+
public:
|
|
12
|
+
explicit AsyncRunner(wgpu::Instance *instance) : instance(instance) {}
|
|
13
|
+
|
|
14
|
+
template <typename F> auto runAsync(F &&func) {
|
|
15
|
+
return std::async(
|
|
16
|
+
std::launch::async, [this, func = std::forward<F>(func)]() {
|
|
17
|
+
if constexpr (std::is_invocable_v<F, wgpu::Instance *>) {
|
|
18
|
+
return func(instance);
|
|
19
|
+
} else {
|
|
20
|
+
auto future = func();
|
|
21
|
+
instance->WaitAny(future, UINT64_MAX);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private:
|
|
27
|
+
wgpu::Instance *instance;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "Unions.h"
|
|
7
|
+
|
|
8
|
+
#include "webgpu/webgpu_cpp.h"
|
|
9
|
+
|
|
10
|
+
#include "RNFHybridObject.h"
|
|
11
|
+
|
|
12
|
+
namespace rnwgpu {
|
|
13
|
+
|
|
14
|
+
namespace m = margelo;
|
|
15
|
+
|
|
16
|
+
class Canvas : public m::HybridObject {
|
|
17
|
+
public:
|
|
18
|
+
explicit Canvas(uint64_t surface, const float width, const float height)
|
|
19
|
+
: HybridObject("Canvas"), _surface(surface), _width(width),
|
|
20
|
+
_height(height), _clientWidth(width), _clientHeight(height) {}
|
|
21
|
+
|
|
22
|
+
float getWidth() { return _width; }
|
|
23
|
+
float getHeight() { return _height; }
|
|
24
|
+
|
|
25
|
+
void setWidth(const float width) { _width = width; }
|
|
26
|
+
void setHeight(const float height) { _height = height; }
|
|
27
|
+
|
|
28
|
+
float getClientWidth() { return _clientWidth; }
|
|
29
|
+
float getClientHeight() { return _clientHeight; }
|
|
30
|
+
|
|
31
|
+
void setClientWidth(const float width) { _clientWidth = width; }
|
|
32
|
+
|
|
33
|
+
void setClientHeight(const float height) { _clientHeight = height; }
|
|
34
|
+
|
|
35
|
+
uint64_t getSurface() { return _surface; }
|
|
36
|
+
|
|
37
|
+
void loadHybridMethods() override {
|
|
38
|
+
registerHybridGetter("surface", &Canvas::getSurface, this);
|
|
39
|
+
registerHybridGetter("width", &Canvas::getWidth, this);
|
|
40
|
+
registerHybridGetter("height", &Canvas::getHeight, this);
|
|
41
|
+
registerHybridGetter("clientWidth", &Canvas::getClientWidth, this);
|
|
42
|
+
registerHybridGetter("clientHeight", &Canvas::getClientHeight, this);
|
|
43
|
+
registerHybridSetter("width", &Canvas::setWidth, this);
|
|
44
|
+
registerHybridSetter("height", &Canvas::setHeight, this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private:
|
|
48
|
+
uint64_t _surface;
|
|
49
|
+
float _width;
|
|
50
|
+
float _height;
|
|
51
|
+
float _clientWidth;
|
|
52
|
+
float _clientHeight;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace rnwgpu
|