react-native-wgpu 0.1.0 → 0.1.3
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 +132 -0
- package/android/cpp/cpp-adapter.cpp +70 -4
- package/android/src/main/java/com/webgpu/WebGPUModule.java +69 -21
- 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 +29 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +13 -11
- package/cpp/rnwgpu/RNWebGPUManager.h +9 -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 +81 -23
- package/cpp/rnwgpu/api/GPU.h +24 -6
- package/cpp/rnwgpu/api/GPUAdapter.cpp +138 -24
- 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 +44 -8
- 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 +153 -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/ImageBitmap.h +34 -0
- package/cpp/rnwgpu/api/RNWebGPU.h +100 -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 +32 -31
- 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 +19 -0
- package/ios/IOSPlatformContext.mm +68 -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 +47 -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 +183 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils.js +39 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/Canvas.js +40 -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 +158 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils.js +31 -0
- package/lib/module/utils.js.map +1 -0
- 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/commonjs/utils.d.ts +5 -0
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
- 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 +3 -3
- package/lib/typescript/lib/module/utils.d.ts +3 -0
- package/lib/typescript/lib/module/utils.d.ts.map +1 -0
- package/lib/typescript/src/Canvas.d.ts +29 -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 +3 -7
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +7 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- 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 +73 -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 +191 -8
- package/src/utils.ts +40 -0
- 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
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>AvailableLibraries</key>
|
|
6
|
+
<array>
|
|
7
|
+
<dict>
|
|
8
|
+
<key>BinaryPath</key>
|
|
9
|
+
<string>libwebgpu_dawn.a</string>
|
|
10
|
+
<key>LibraryIdentifier</key>
|
|
11
|
+
<string>ios-arm64_x86_64-simulator</string>
|
|
12
|
+
<key>LibraryPath</key>
|
|
13
|
+
<string>libwebgpu_dawn.a</string>
|
|
14
|
+
<key>SupportedArchitectures</key>
|
|
15
|
+
<array>
|
|
16
|
+
<string>arm64</string>
|
|
17
|
+
<string>x86_64</string>
|
|
18
|
+
</array>
|
|
19
|
+
<key>SupportedPlatform</key>
|
|
20
|
+
<string>ios</string>
|
|
21
|
+
<key>SupportedPlatformVariant</key>
|
|
22
|
+
<string>simulator</string>
|
|
23
|
+
</dict>
|
|
24
|
+
<dict>
|
|
25
|
+
<key>BinaryPath</key>
|
|
26
|
+
<string>libwebgpu_dawn.a</string>
|
|
27
|
+
<key>LibraryIdentifier</key>
|
|
28
|
+
<string>ios-arm64</string>
|
|
29
|
+
<key>LibraryPath</key>
|
|
30
|
+
<string>libwebgpu_dawn.a</string>
|
|
31
|
+
<key>SupportedArchitectures</key>
|
|
32
|
+
<array>
|
|
33
|
+
<string>arm64</string>
|
|
34
|
+
</array>
|
|
35
|
+
<key>SupportedPlatform</key>
|
|
36
|
+
<string>ios</string>
|
|
37
|
+
</dict>
|
|
38
|
+
</array>
|
|
39
|
+
<key>CFBundlePackageType</key>
|
|
40
|
+
<string>XFWK</string>
|
|
41
|
+
<key>XCFrameworkFormatVersion</key>
|
|
42
|
+
<string>1.0</string>
|
|
43
|
+
</dict>
|
|
44
|
+
</plist>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-wgpu",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "React Native WebGPU",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"ios",
|
|
15
15
|
"cpp",
|
|
16
16
|
"*.podspec",
|
|
17
|
+
"libs/**",
|
|
18
|
+
"!scripts",
|
|
17
19
|
"!ios/build",
|
|
18
20
|
"!android/build",
|
|
19
21
|
"!android/gradle",
|
|
@@ -27,10 +29,12 @@
|
|
|
27
29
|
],
|
|
28
30
|
"scripts": {
|
|
29
31
|
"example": "yarn workspace react-native-webgpu-example",
|
|
30
|
-
"test": "jest",
|
|
32
|
+
"test": "jest -i",
|
|
33
|
+
"test:ref": "REFERENCE=true yarn test -i",
|
|
31
34
|
"tsc": "tsc --noEmit",
|
|
32
35
|
"lint": "eslint \"**/*.{ts,tsx}\"",
|
|
33
36
|
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
37
|
+
"prepare": "bob build",
|
|
34
38
|
"build-dawn": "ts-node scripts/build/dawn.ts",
|
|
35
39
|
"clean-dawn": "rimraf ./libs && rimraf ../externals/dawn/out",
|
|
36
40
|
"clang-format": "yarn clang-format-ios && yarn clang-format-android && yarn clang-format-common",
|
|
@@ -48,14 +52,14 @@
|
|
|
48
52
|
],
|
|
49
53
|
"repository": {
|
|
50
54
|
"type": "git",
|
|
51
|
-
"url": "git+https://github.com/wcandillon/react-native-
|
|
55
|
+
"url": "git+https://github.com/wcandillon/react-native-webgpu.git"
|
|
52
56
|
},
|
|
53
57
|
"author": "William Candillon <wcandillon@gmail.com> (https://github.com/wcandillon)",
|
|
54
58
|
"license": "MIT",
|
|
55
59
|
"bugs": {
|
|
56
|
-
"url": "https://github.com/wcandillon/react-native-
|
|
60
|
+
"url": "https://github.com/wcandillon/react-native-webgpu/issues"
|
|
57
61
|
},
|
|
58
|
-
"homepage": "https://github.com/wcandillon/react-native-
|
|
62
|
+
"homepage": "https://github.com/wcandillon/react-native-webgpu#readme",
|
|
59
63
|
"publishConfig": {
|
|
60
64
|
"registry": "https://registry.npmjs.org/"
|
|
61
65
|
},
|
|
@@ -64,7 +68,10 @@
|
|
|
64
68
|
"@types/jest": "^29.5.12",
|
|
65
69
|
"@types/lodash": "^4.17.5",
|
|
66
70
|
"@types/node": "^20.14.7",
|
|
71
|
+
"@types/pixelmatch": "5.2.4",
|
|
72
|
+
"@types/pngjs": "^6.0.5",
|
|
67
73
|
"@types/react": "^18.2.44",
|
|
74
|
+
"@types/seedrandom": "^3.0.8",
|
|
68
75
|
"@types/ws": "^8.5.10",
|
|
69
76
|
"@typescript-eslint/eslint-plugin": "^7.13.1",
|
|
70
77
|
"@webgpu/types": "^0.1.42",
|
|
@@ -76,19 +83,26 @@
|
|
|
76
83
|
"eslint-plugin-prettier": "^5.1.3",
|
|
77
84
|
"jest": "^29.7.0",
|
|
78
85
|
"lodash": "^4.17.21",
|
|
86
|
+
"pixelmatch": "5.3.0",
|
|
87
|
+
"pngjs": "^7.0.0",
|
|
79
88
|
"prettier": "^3.0.3",
|
|
89
|
+
"puppeteer": "22",
|
|
80
90
|
"react": "18.2.0",
|
|
81
91
|
"react-native": "0.74.2",
|
|
82
92
|
"react-native-builder-bob": "^0.23.2",
|
|
83
93
|
"rimraf": "^5.0.7",
|
|
94
|
+
"seedrandom": "^3.0.5",
|
|
95
|
+
"teapot": "^1.0.0",
|
|
84
96
|
"ts-morph": "^22.0.0",
|
|
85
97
|
"ts-node": "^10.9.2",
|
|
86
98
|
"turbo": "^1.10.7",
|
|
87
99
|
"typescript": "^5.2.2",
|
|
100
|
+
"wgpu-matrix": "^3.0.2",
|
|
88
101
|
"ws": "^8.18.0"
|
|
89
102
|
},
|
|
90
103
|
"resolutions": {
|
|
91
|
-
"@types/react": "^18.2.44"
|
|
104
|
+
"@types/react": "^18.2.44",
|
|
105
|
+
"@webgpu/types": "^0.1.42"
|
|
92
106
|
},
|
|
93
107
|
"peerDependencies": {
|
|
94
108
|
"react": "*",
|
|
@@ -114,7 +128,10 @@
|
|
|
114
128
|
},
|
|
115
129
|
"codegenConfig": {
|
|
116
130
|
"name": "RNWgpuViewSpec",
|
|
117
|
-
"type": "
|
|
118
|
-
"jsSrcsDir": "src"
|
|
131
|
+
"type": "all",
|
|
132
|
+
"jsSrcsDir": "src",
|
|
133
|
+
"android": {
|
|
134
|
+
"javaPackageName": "com.webgpu"
|
|
135
|
+
}
|
|
119
136
|
}
|
|
120
137
|
}
|
|
@@ -4,7 +4,7 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
|
4
4
|
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
5
|
|
|
6
6
|
Pod::Spec.new do |s|
|
|
7
|
-
s.name = "react-native-
|
|
7
|
+
s.name = "react-native-wgpu"
|
|
8
8
|
s.version = package["version"]
|
|
9
9
|
s.summary = package["description"]
|
|
10
10
|
s.homepage = package["homepage"]
|
|
@@ -19,16 +19,13 @@ Pod::Spec.new do |s|
|
|
|
19
19
|
"cpp/**/*.{h,cpp}"
|
|
20
20
|
]
|
|
21
21
|
|
|
22
|
-
s.pod_target_xcconfig = {
|
|
23
|
-
"HEADER_SEARCH_PATHS" => "$(PODS_TARGET_SRCROOT)/cpp"
|
|
24
|
-
}
|
|
25
22
|
s.ios.vendored_frameworks = [
|
|
26
|
-
'libs/ios/libwebgpu_dawn.xcframework',
|
|
27
|
-
'libs/ios/libdawn_common.xcframework',
|
|
28
|
-
'libs/ios/libdawn_native.xcframework',
|
|
29
|
-
'libs/ios/libdawn_proc.xcframework'
|
|
23
|
+
'libs/ios/libwebgpu_dawn.xcframework',
|
|
30
24
|
]
|
|
31
|
-
|
|
25
|
+
|
|
26
|
+
s.pod_target_xcconfig = {
|
|
27
|
+
'HEADER_SEARCH_PATHS' => '$(PODS_TARGET_SRCROOT)/cpp',
|
|
28
|
+
}
|
|
32
29
|
|
|
33
30
|
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
34
31
|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
package/src/Canvas.tsx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ViewProps } from "react-native";
|
|
2
|
+
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
3
|
+
|
|
4
|
+
import WebGPUNativeView from "./WebGPUViewNativeComponent";
|
|
5
|
+
import WebGPUNativeModule from "./NativeWebGPUModule";
|
|
6
|
+
|
|
7
|
+
let CONTEXT_COUNTER = 1;
|
|
8
|
+
function generateContextId() {
|
|
9
|
+
return CONTEXT_COUNTER++;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
// eslint-disable-next-line no-var
|
|
14
|
+
var __WebGPUContextRegistry: Record<number, NativeCanvas>;
|
|
15
|
+
// eslint-disable-next-line no-var
|
|
16
|
+
var RNWebGPU: {
|
|
17
|
+
gpu: GPU;
|
|
18
|
+
MakeWebGPUCanvasContext: (nativeCanvas: NativeCanvas) => CanvasContext;
|
|
19
|
+
DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
|
|
20
|
+
createImageBitmap: typeof createImageBitmap;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NativeCanvas {
|
|
25
|
+
surface: bigint;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
clientWidth: number;
|
|
29
|
+
clientHeight: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
global.__WebGPUContextRegistry = {};
|
|
33
|
+
const WebGPUContextRegistry = global.__WebGPUContextRegistry;
|
|
34
|
+
|
|
35
|
+
type CanvasContext = GPUCanvasContext & {
|
|
36
|
+
present: () => void;
|
|
37
|
+
getNativeSurface: () => NativeCanvas;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export interface CanvasRef {
|
|
41
|
+
getContext(contextName: "webgpu"): CanvasContext | null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const Canvas = forwardRef<CanvasRef, ViewProps>((props, ref) => {
|
|
45
|
+
const [contextId, _] = useState(() => generateContextId());
|
|
46
|
+
|
|
47
|
+
useImperativeHandle(ref, () => ({
|
|
48
|
+
getNativeSurface: () => {
|
|
49
|
+
WebGPUNativeModule.createSurfaceContext(contextId);
|
|
50
|
+
return WebGPUContextRegistry[contextId];
|
|
51
|
+
},
|
|
52
|
+
getContext(contextName: "webgpu"): CanvasContext | null {
|
|
53
|
+
if (contextName !== "webgpu") {
|
|
54
|
+
throw new Error(`[WebGPU] Unsupported context: ${contextName}`);
|
|
55
|
+
}
|
|
56
|
+
WebGPUNativeModule.createSurfaceContext(contextId);
|
|
57
|
+
const nativeSurface = WebGPUContextRegistry[contextId];
|
|
58
|
+
if (!nativeSurface) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const ctx = RNWebGPU.MakeWebGPUCanvasContext(nativeSurface);
|
|
62
|
+
return ctx;
|
|
63
|
+
},
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
return () => {
|
|
68
|
+
delete WebGPUContextRegistry[contextId];
|
|
69
|
+
};
|
|
70
|
+
}, [contextId]);
|
|
71
|
+
|
|
72
|
+
return <WebGPUNativeView {...props} contextId={contextId} />;
|
|
73
|
+
});
|
|
File without changes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
|
|
2
2
|
import type { ViewProps } from "react-native";
|
|
3
|
+
import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
4
|
|
|
4
5
|
interface NativeProps extends ViewProps {
|
|
5
|
-
|
|
6
|
+
contextId?: Int32;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
// eslint-disable-next-line import/no-default-export
|
package/src/index.tsx
CHANGED
|
@@ -1,13 +1,196 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import WebGPUNativeModule from "./NativeWebGPUModule";
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
+
export * from "./Canvas";
|
|
4
5
|
export * from "./WebGPUViewNativeComponent";
|
|
5
|
-
export
|
|
6
|
+
export * from "./utils";
|
|
7
|
+
export { default as WebGPUModule } from "./NativeWebGPUModule";
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
9
|
+
const GPU: any = {};
|
|
10
|
+
GPU[Symbol.hasInstance] = function (instance: object) {
|
|
11
|
+
return "__brand" in instance && instance.__brand === "GPU";
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const GPUAdapter: any = {};
|
|
15
|
+
GPUAdapter[Symbol.hasInstance] = function (instance: object) {
|
|
16
|
+
return "__brand" in instance && instance.__brand === "GPUAdapter";
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const GPUAdapterInfo: any = {};
|
|
20
|
+
GPUAdapterInfo[Symbol.hasInstance] = function (instance: object) {
|
|
21
|
+
return "__brand" in instance && instance.__brand === "GPUAdapterInfo";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const GPUBindGroup: any = {};
|
|
25
|
+
GPUBindGroup[Symbol.hasInstance] = function (instance: object) {
|
|
26
|
+
return "__brand" in instance && instance.__brand === "GPUBindGroup";
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const GPUBindGroupLayout: any = {};
|
|
30
|
+
GPUBindGroupLayout[Symbol.hasInstance] = function (instance: object) {
|
|
31
|
+
return "__brand" in instance && instance.__brand === "GPUBindGroupLayout";
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const GPUBuffer: any = {};
|
|
35
|
+
GPUBuffer[Symbol.hasInstance] = function (instance: object) {
|
|
36
|
+
return "__brand" in instance && instance.__brand === "GPUBuffer";
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const GPUCanvasContext: any = {};
|
|
40
|
+
GPUCanvasContext[Symbol.hasInstance] = function (instance: object) {
|
|
41
|
+
return "__brand" in instance && instance.__brand === "GPUCanvasContext";
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const GPUCommandBuffer: any = {};
|
|
45
|
+
GPUCommandBuffer[Symbol.hasInstance] = function (instance: object) {
|
|
46
|
+
return "__brand" in instance && instance.__brand === "GPUCommandBuffer";
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const GPUCommandEncoder: any = {};
|
|
50
|
+
GPUCommandEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
51
|
+
return "__brand" in instance && instance.__brand === "GPUCommandEncoder";
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const GPUCompilationInfo: any = {};
|
|
55
|
+
GPUCompilationInfo[Symbol.hasInstance] = function (instance: object) {
|
|
56
|
+
return "__brand" in instance && instance.__brand === "GPUCompilationInfo";
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const GPUCompilationMessage: any = {};
|
|
60
|
+
GPUCompilationMessage[Symbol.hasInstance] = function (instance: object) {
|
|
61
|
+
return "__brand" in instance && instance.__brand === "GPUCompilationMessage";
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const GPUComputePassEncoder: any = {};
|
|
65
|
+
GPUComputePassEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
66
|
+
return "__brand" in instance && instance.__brand === "GPUComputePassEncoder";
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const GPUComputePipeline: any = {};
|
|
70
|
+
GPUComputePipeline[Symbol.hasInstance] = function (instance: object) {
|
|
71
|
+
return "__brand" in instance && instance.__brand === "GPUComputePipeline";
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const GPUDevice: any = {};
|
|
75
|
+
GPUDevice[Symbol.hasInstance] = function (instance: object) {
|
|
76
|
+
return "__brand" in instance && instance.__brand === "GPUDevice";
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const GPUDeviceLostInfo: any = {};
|
|
80
|
+
GPUDeviceLostInfo[Symbol.hasInstance] = function (instance: object) {
|
|
81
|
+
return "__brand" in instance && instance.__brand === "GPUDeviceLostInfo";
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const GPUError: any = {};
|
|
85
|
+
GPUError[Symbol.hasInstance] = function (instance: object) {
|
|
86
|
+
return "__brand" in instance && instance.__brand === "GPUError";
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const GPUExternalTexture: any = {};
|
|
90
|
+
GPUExternalTexture[Symbol.hasInstance] = function (instance: object) {
|
|
91
|
+
return "__brand" in instance && instance.__brand === "GPUExternalTexture";
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const GPUPipelineLayout: any = {};
|
|
95
|
+
GPUPipelineLayout[Symbol.hasInstance] = function (instance: object) {
|
|
96
|
+
return "__brand" in instance && instance.__brand === "GPUPipelineLayout";
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const GPUQuerySet: any = {};
|
|
100
|
+
GPUQuerySet[Symbol.hasInstance] = function (instance: object) {
|
|
101
|
+
return "__brand" in instance && instance.__brand === "GPUQuerySet";
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const GPUQueue: any = {};
|
|
105
|
+
GPUQueue[Symbol.hasInstance] = function (instance: object) {
|
|
106
|
+
return "__brand" in instance && instance.__brand === "GPUQueue";
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const GPURenderBundle: any = {};
|
|
110
|
+
GPURenderBundle[Symbol.hasInstance] = function (instance: object) {
|
|
111
|
+
return "__brand" in instance && instance.__brand === "GPURenderBundle";
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const GPURenderBundleEncoder: any = {};
|
|
115
|
+
GPURenderBundleEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
116
|
+
return "__brand" in instance && instance.__brand === "GPURenderBundleEncoder";
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const GPURenderPassEncoder: any = {};
|
|
120
|
+
GPURenderPassEncoder[Symbol.hasInstance] = function (instance: object) {
|
|
121
|
+
return "__brand" in instance && instance.__brand === "GPURenderPassEncoder";
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const GPURenderPipeline: any = {};
|
|
125
|
+
GPURenderPipeline[Symbol.hasInstance] = function (instance: object) {
|
|
126
|
+
return "__brand" in instance && instance.__brand === "GPURenderPipeline";
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const GPUSampler: any = {};
|
|
130
|
+
GPUSampler[Symbol.hasInstance] = function (instance: object) {
|
|
131
|
+
return "__brand" in instance && instance.__brand === "GPUSampler";
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const GPUShaderModule: any = {};
|
|
135
|
+
GPUShaderModule[Symbol.hasInstance] = function (instance: object) {
|
|
136
|
+
return "__brand" in instance && instance.__brand === "GPUShaderModule";
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const GPUTexture: any = {};
|
|
140
|
+
GPUTexture[Symbol.hasInstance] = function (instance: object) {
|
|
141
|
+
return "__brand" in instance && instance.__brand === "GPUTexture";
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const GPUTextureView: any = {};
|
|
145
|
+
GPUTextureView[Symbol.hasInstance] = function (instance: object) {
|
|
146
|
+
return "__brand" in instance && instance.__brand === "GPUTextureView";
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
global.GPU = GPU;
|
|
150
|
+
global.GPUAdapter = GPUAdapter;
|
|
151
|
+
global.GPUAdapterInfo = GPUAdapterInfo;
|
|
152
|
+
global.GPUBindGroup = GPUBindGroup;
|
|
153
|
+
global.GPUBindGroupLayout = GPUBindGroupLayout;
|
|
154
|
+
global.GPUBuffer = GPUBuffer;
|
|
155
|
+
global.GPUCanvasContext = GPUCanvasContext;
|
|
156
|
+
global.GPUCommandBuffer = GPUCommandBuffer;
|
|
157
|
+
global.GPUCommandEncoder = GPUCommandEncoder;
|
|
158
|
+
global.GPUCompilationInfo = GPUCompilationInfo;
|
|
159
|
+
global.GPUCompilationMessage = GPUCompilationMessage;
|
|
160
|
+
global.GPUComputePassEncoder = GPUComputePassEncoder;
|
|
161
|
+
global.GPUComputePipeline = GPUComputePipeline;
|
|
162
|
+
global.GPUDevice = GPUDevice;
|
|
163
|
+
global.GPUDeviceLostInfo = GPUDeviceLostInfo;
|
|
164
|
+
global.GPUError = GPUError;
|
|
165
|
+
global.GPUExternalTexture = GPUExternalTexture;
|
|
166
|
+
global.GPUPipelineLayout = GPUPipelineLayout;
|
|
167
|
+
global.GPUQuerySet = GPUQuerySet;
|
|
168
|
+
global.GPUQueue = GPUQueue;
|
|
169
|
+
global.GPURenderBundle = GPURenderBundle;
|
|
170
|
+
global.GPURenderBundleEncoder = GPURenderBundleEncoder;
|
|
171
|
+
global.GPURenderPassEncoder = GPURenderPassEncoder;
|
|
172
|
+
global.GPURenderPipeline = GPURenderPipeline;
|
|
173
|
+
global.GPUSampler = GPUSampler;
|
|
174
|
+
global.GPUShaderModule = GPUShaderModule;
|
|
175
|
+
global.GPUTexture = GPUTexture;
|
|
176
|
+
global.GPUTextureView = GPUTextureView;
|
|
11
177
|
|
|
12
178
|
WebGPUNativeModule.install();
|
|
13
|
-
|
|
179
|
+
|
|
180
|
+
if (!navigator) {
|
|
181
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
182
|
+
// @ts-expect-error
|
|
183
|
+
navigator = {};
|
|
184
|
+
}
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
186
|
+
// @ts-expect-error
|
|
187
|
+
navigator.gpu = RNWebGPU.gpu;
|
|
188
|
+
|
|
189
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
190
|
+
// @ts-expect-error
|
|
191
|
+
navigator.userAgent = "react-native";
|
|
192
|
+
|
|
193
|
+
global.createImageBitmap =
|
|
194
|
+
global.createImageBitmap ??
|
|
195
|
+
((...params: Parameters<typeof createImageBitmap>) =>
|
|
196
|
+
new Promise((resolve) => resolve(RNWebGPU.createImageBitmap(...params))));
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import type { CanvasRef } from "./Canvas";
|
|
4
|
+
|
|
5
|
+
type Unsubscribe = () => void;
|
|
6
|
+
|
|
7
|
+
export const warnIfNotHardwareAccelerated = (adapter: GPUAdapter) => {
|
|
8
|
+
if (adapter.info.architecture === "swiftshader") {
|
|
9
|
+
console.warn(
|
|
10
|
+
"GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow.",
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const useCanvasEffect = (
|
|
16
|
+
effect: () => void | Unsubscribe | Promise<void | Unsubscribe>,
|
|
17
|
+
) => {
|
|
18
|
+
const ref = useRef<CanvasRef>(null);
|
|
19
|
+
const unsubscribe = useRef<Unsubscribe>();
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
requestAnimationFrame(async () => {
|
|
22
|
+
// const adapter = await navigator.gpu.requestAdapter();
|
|
23
|
+
// if (!adapter) {
|
|
24
|
+
// return;
|
|
25
|
+
// }
|
|
26
|
+
// const device = await adapter.requestDevice();
|
|
27
|
+
const unsub = await effect();
|
|
28
|
+
if (unsub) {
|
|
29
|
+
unsubscribe.current = unsub;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return () => {
|
|
33
|
+
if (unsubscribe.current) {
|
|
34
|
+
unsubscribe.current();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
}, []);
|
|
39
|
+
return ref;
|
|
40
|
+
};
|
|
@@ -1,48 +0,0 @@
|
|
|
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 MutableJSIBuffer : jsi::MutableBuffer {
|
|
13
|
-
MutableJSIBuffer(void *data, size_t size) : _data(data), _size(size) {}
|
|
14
|
-
|
|
15
|
-
size_t size() const override { return _size; }
|
|
16
|
-
|
|
17
|
-
uint8_t *data() override { return reinterpret_cast<uint8_t *>(_data); }
|
|
18
|
-
|
|
19
|
-
void *_data;
|
|
20
|
-
size_t _size;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
} // namespace rnwgpu
|
|
24
|
-
|
|
25
|
-
namespace margelo {
|
|
26
|
-
|
|
27
|
-
template <> struct JSIConverter<std::shared_ptr<rnwgpu::MutableJSIBuffer>> {
|
|
28
|
-
static std::shared_ptr<rnwgpu::MutableJSIBuffer>
|
|
29
|
-
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBound) {
|
|
30
|
-
if (!arg.getObject(runtime).isArrayBuffer(runtime)) {
|
|
31
|
-
throw std::runtime_error(
|
|
32
|
-
"Buffer::fromJSI: argument is not an ArrayBuffer");
|
|
33
|
-
}
|
|
34
|
-
auto data = arg.getObject(runtime).getArrayBuffer(runtime);
|
|
35
|
-
auto result = std::make_unique<rnwgpu::MutableJSIBuffer>(
|
|
36
|
-
data.data(runtime), data.size(runtime));
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static jsi::Value toJSI(jsi::Runtime &runtime,
|
|
41
|
-
std::shared_ptr<rnwgpu::MutableJSIBuffer> arg) {
|
|
42
|
-
auto val = jsi::ArrayBuffer(runtime, arg);
|
|
43
|
-
auto d = val.data(runtime);
|
|
44
|
-
return val;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
} // namespace margelo
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <future>
|
|
4
|
-
#include <memory>
|
|
5
|
-
#include <string>
|
|
6
|
-
|
|
7
|
-
#include "Unions.h"
|
|
8
|
-
#include <RNFHybridObject.h>
|
|
9
|
-
|
|
10
|
-
#include "MutableBuffer.h"
|
|
11
|
-
|
|
12
|
-
#include "webgpu/webgpu_cpp.h"
|
|
13
|
-
|
|
14
|
-
namespace rnwgpu {
|
|
15
|
-
|
|
16
|
-
namespace m = margelo;
|
|
17
|
-
|
|
18
|
-
class GPUUncapturedErrorEvent : public m::HybridObject {
|
|
19
|
-
public:
|
|
20
|
-
explicit GPUUncapturedErrorEvent(wgpu::UncapturedErrorEvent instance)
|
|
21
|
-
: HybridObject("GPUUncapturedErrorEvent"), _instance(instance) {}
|
|
22
|
-
|
|
23
|
-
public:
|
|
24
|
-
std::string getBrand() { return _name; }
|
|
25
|
-
|
|
26
|
-
void loadHybridMethods() override {
|
|
27
|
-
registerHybridGetter("__brand", &GPUUncapturedErrorEvent::getBrand, this);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private:
|
|
31
|
-
wgpu::UncapturedErrorEvent _instance;
|
|
32
|
-
};
|
|
33
|
-
} // namespace rnwgpu
|