react-native-webgpu 0.5.11
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/LICENSE +20 -0
- package/README.md +319 -0
- package/android/CMakeLists.txt +108 -0
- package/android/build.gradle +138 -0
- package/android/cpp/AndroidPlatformContext.h +207 -0
- package/android/cpp/cpp-adapter.cpp +71 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/webgpu/WebGPUAHBView.java +298 -0
- package/android/src/main/java/com/webgpu/WebGPUAPI.java +20 -0
- package/android/src/main/java/com/webgpu/WebGPUBaseView.java +61 -0
- package/android/src/main/java/com/webgpu/WebGPUModule.java +50 -0
- package/android/src/main/java/com/webgpu/WebGPUSurfaceView.java +41 -0
- package/android/src/main/java/com/webgpu/WebGPUSurfaceViewWithSC.java +79 -0
- package/android/src/main/java/com/webgpu/WebGPUTextureView.java +46 -0
- package/android/src/main/java/com/webgpu/WebGPUView.java +108 -0
- package/android/src/main/java/com/webgpu/WebGPUViewManager.java +38 -0
- package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +50 -0
- package/android/src/newarch/com/webgpu/WebGPUViewManagerSpec.java +24 -0
- package/apple/ApplePlatformContext.h +31 -0
- package/apple/ApplePlatformContext.mm +157 -0
- package/apple/MetalView.h +13 -0
- package/apple/MetalView.mm +50 -0
- package/apple/RNWGUIKit.h +16 -0
- package/apple/WebGPUModule.h +13 -0
- package/apple/WebGPUModule.mm +89 -0
- package/apple/WebGPUView.h +12 -0
- package/apple/WebGPUView.mm +66 -0
- package/cpp/WGPULogger.h +100 -0
- package/cpp/dawn_logging.cpp +119 -0
- package/cpp/jsi/EnumMapper.h +45 -0
- package/cpp/jsi/JSIConverter.h +473 -0
- package/cpp/jsi/NativeObject.h +607 -0
- package/cpp/jsi/Promise.cpp +44 -0
- package/cpp/jsi/Promise.h +35 -0
- 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 +73 -0
- package/cpp/rnwgpu/PlatformContext.h +46 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +225 -0
- package/cpp/rnwgpu/RNWebGPUManager.h +46 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +230 -0
- package/cpp/rnwgpu/api/Canvas.h +57 -0
- package/cpp/rnwgpu/api/Convertors.h +761 -0
- package/cpp/rnwgpu/api/External.h +12 -0
- package/cpp/rnwgpu/api/GPU.cpp +127 -0
- package/cpp/rnwgpu/api/GPU.h +58 -0
- package/cpp/rnwgpu/api/GPUAdapter.cpp +191 -0
- package/cpp/rnwgpu/api/GPUAdapter.h +59 -0
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +57 -0
- package/cpp/rnwgpu/api/GPUBindGroup.cpp +3 -0
- package/cpp/rnwgpu/api/GPUBindGroup.h +51 -0
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +52 -0
- package/cpp/rnwgpu/api/GPUBuffer.cpp +97 -0
- package/cpp/rnwgpu/api/GPUBuffer.h +87 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +67 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.h +66 -0
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +45 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +179 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +111 -0
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +79 -0
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +36 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +60 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +85 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +12 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.h +60 -0
- package/cpp/rnwgpu/api/GPUDevice.cpp +492 -0
- package/cpp/rnwgpu/api/GPUDevice.h +259 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +7 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +40 -0
- package/cpp/rnwgpu/api/GPUError.h +35 -0
- package/cpp/rnwgpu/api/GPUExtent3D.h +66 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +45 -0
- package/cpp/rnwgpu/api/GPUFeatures.h +203 -0
- package/cpp/rnwgpu/api/GPUInternalError.h +31 -0
- package/cpp/rnwgpu/api/GPUOrigin2D.h +55 -0
- package/cpp/rnwgpu/api/GPUOrigin3D.h +62 -0
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +33 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +45 -0
- package/cpp/rnwgpu/api/GPUQuerySet.cpp +11 -0
- package/cpp/rnwgpu/api/GPUQuerySet.h +73 -0
- package/cpp/rnwgpu/api/GPUQueue.cpp +169 -0
- package/cpp/rnwgpu/api/GPUQueue.h +81 -0
- package/cpp/rnwgpu/api/GPURenderBundle.h +44 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +131 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +110 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +165 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +130 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.cpp +13 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.h +61 -0
- package/cpp/rnwgpu/api/GPUSampler.h +44 -0
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +51 -0
- package/cpp/rnwgpu/api/GPUShaderModule.h +66 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +129 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +131 -0
- package/cpp/rnwgpu/api/GPUTexture.cpp +47 -0
- package/cpp/rnwgpu/api/GPUTexture.h +162 -0
- package/cpp/rnwgpu/api/GPUTextureView.h +44 -0
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +71 -0
- package/cpp/rnwgpu/api/GPUValidationError.h +32 -0
- package/cpp/rnwgpu/api/ImageBitmap.h +40 -0
- package/cpp/rnwgpu/api/RNWebGPU.h +199 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +65 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +78 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +98 -0
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +53 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +60 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +39 -0
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +76 -0
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +67 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +29 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +46 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +46 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +68 -0
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +104 -0
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +100 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +39 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +80 -0
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +74 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +63 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +63 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +66 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +82 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +55 -0
- package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +22 -0
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +55 -0
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +70 -0
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +44 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +46 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +81 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +82 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +102 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +93 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +104 -0
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +52 -0
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +46 -0
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +111 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +61 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +63 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +25 -0
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +65 -0
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +60 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +60 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +92 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +29 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +92 -0
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +65 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +54 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +63 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +74 -0
- package/cpp/rnwgpu/api/descriptors/Unions.h +1969 -0
- package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
- package/cpp/rnwgpu/async/AsyncRunner.cpp +215 -0
- package/cpp/rnwgpu/async/AsyncRunner.h +53 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +181 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +55 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +23 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +22 -0
- package/cpp/webgpu/webgpu.h +4918 -0
- package/cpp/webgpu/webgpu_cpp.h +10294 -0
- package/cpp/webgpu/webgpu_cpp_chained_struct.h +57 -0
- package/cpp/webgpu/webgpu_cpp_print.h +2755 -0
- package/cpp/webgpu/webgpu_enum_class_bitmasks.h +161 -0
- package/lib/commonjs/Canvas.js +55 -0
- package/lib/commonjs/Canvas.js.map +1 -0
- package/lib/commonjs/NativeWebGPUModule.js +10 -0
- package/lib/commonjs/NativeWebGPUModule.js.map +1 -0
- package/lib/commonjs/Offscreen.js +103 -0
- package/lib/commonjs/Offscreen.js.map +1 -0
- package/lib/commonjs/WebGPUViewNativeComponent.js +10 -0
- package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -0
- package/lib/commonjs/WebGPUViewNativeComponent.web.js +103 -0
- package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/WebPolyfillGPUModule.js +40 -0
- package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -0
- 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 +49 -0
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -0
- package/lib/commonjs/hooks.js +83 -0
- package/lib/commonjs/hooks.js.map +1 -0
- package/lib/commonjs/index.js +17 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/main/index.js +91 -0
- package/lib/commonjs/main/index.js.map +1 -0
- package/lib/commonjs/main/index.web.js +51 -0
- package/lib/commonjs/main/index.web.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils.js +11 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/Canvas.js +46 -0
- package/lib/module/Canvas.js.map +1 -0
- package/lib/module/NativeWebGPUModule.js +4 -0
- package/lib/module/NativeWebGPUModule.js.map +1 -0
- package/lib/module/Offscreen.js +96 -0
- package/lib/module/Offscreen.js.map +1 -0
- package/lib/module/WebGPUViewNativeComponent.js +4 -0
- package/lib/module/WebGPUViewNativeComponent.js.map +1 -0
- package/lib/module/WebGPUViewNativeComponent.web.js +96 -0
- package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -0
- package/lib/module/WebPolyfillGPUModule.js +38 -0
- package/lib/module/WebPolyfillGPUModule.js.map +1 -0
- 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 +42 -0
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -0
- package/lib/module/hooks.js +70 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/main/index.js +33 -0
- package/lib/module/main/index.js.map +1 -0
- package/lib/module/main/index.web.js +8 -0
- package/lib/module/main/index.web.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +5 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/babel.config.d.ts +3 -0
- package/lib/typescript/babel.config.d.ts.map +1 -0
- package/lib/typescript/eslint.config.d.mts +3 -0
- package/lib/typescript/eslint.config.d.mts.map +1 -0
- package/lib/typescript/jest.config.d.ts +9 -0
- package/lib/typescript/jest.config.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts +7 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/NativeWebGPUModule.d.ts +5 -0
- package/lib/typescript/lib/commonjs/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/Offscreen.d.ts +26 -0
- package/lib/typescript/lib/commonjs/Offscreen.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.d.ts +5 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts +4 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts.map +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/commonjs/hooks.d.ts +18 -0
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +2 -0
- package/lib/typescript/lib/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/main/index.d.ts +3 -0
- package/lib/typescript/lib/commonjs/main/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/main/index.web.d.ts +2 -0
- package/lib/typescript/lib/commonjs/main/index.web.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/types.d.ts +1 -0
- package/lib/typescript/lib/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/utils.d.ts +3 -0
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
- package/lib/typescript/lib/module/Canvas.d.ts +8 -0
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -0
- package/lib/typescript/lib/module/NativeWebGPUModule.d.ts +3 -0
- package/lib/typescript/lib/module/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/module/Offscreen.d.ts +25 -0
- package/lib/typescript/lib/module/Offscreen.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.d.ts +3 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts +3 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/lib/module/WebPolyfillGPUModule.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/lib/module/hooks.d.ts +18 -0
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +2 -0
- package/lib/typescript/lib/module/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/index.d.ts +6 -0
- package/lib/typescript/lib/module/main/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/main/index.web.d.ts +5 -0
- package/lib/typescript/lib/module/main/index.web.d.ts.map +1 -0
- package/lib/typescript/lib/module/types.d.ts +1 -0
- package/lib/typescript/lib/module/types.d.ts.map +1 -0
- package/lib/typescript/lib/module/utils.d.ts +2 -0
- package/lib/typescript/lib/module/utils.d.ts.map +1 -0
- package/lib/typescript/src/Canvas.d.ts +35 -0
- package/lib/typescript/src/Canvas.d.ts.map +1 -0
- package/lib/typescript/src/NativeWebGPUModule.d.ts +7 -0
- package/lib/typescript/src/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/src/Offscreen.d.ts +30 -0
- package/lib/typescript/src/Offscreen.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +9 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +9 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/src/WebPolyfillGPUModule.d.ts +2 -0
- package/lib/typescript/src/WebPolyfillGPUModule.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/lib/typescript/src/hooks.d.ts +27 -0
- package/lib/typescript/src/hooks.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +18 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/main/index.d.ts +6 -0
- package/lib/typescript/src/main/index.d.ts.map +1 -0
- package/lib/typescript/src/main/index.web.d.ts +6 -0
- package/lib/typescript/src/main/index.web.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +19 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +2 -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/apple/libwebgpu_dawn.xcframework/Info.plist +59 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/package.json +139 -0
- package/react-native-wgpu.podspec +47 -0
- package/src/Canvas.tsx +91 -0
- package/src/NativeWebGPUModule.ts +9 -0
- package/src/Offscreen.ts +113 -0
- package/src/WebGPUViewNativeComponent.ts +11 -0
- package/src/WebGPUViewNativeComponent.web.ts +113 -0
- package/src/WebPolyfillGPUModule.ts +53 -0
- 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/hooks.tsx +93 -0
- package/src/index.tsx +31 -0
- package/src/main/index.tsx +40 -0
- package/src/main/index.web.tsx +8 -0
- package/src/types.ts +20 -0
- package/src/utils.ts +4 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
|
|
5
|
+
#include <cassert>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <unordered_map>
|
|
8
|
+
#include <utility>
|
|
9
|
+
|
|
10
|
+
#include "RuntimeLifecycleMonitor.h"
|
|
11
|
+
|
|
12
|
+
namespace rnwgpu {
|
|
13
|
+
|
|
14
|
+
namespace jsi = facebook::jsi;
|
|
15
|
+
|
|
16
|
+
class BaseRuntimeAwareCache {
|
|
17
|
+
public:
|
|
18
|
+
static void setMainJsRuntime(jsi::Runtime *rt) { _mainRuntime = rt; }
|
|
19
|
+
static jsi::Runtime *getMainJsRuntime() {
|
|
20
|
+
assert(_mainRuntime != nullptr &&
|
|
21
|
+
"Expected main Javascript runtime to be set in the "
|
|
22
|
+
"BaseRuntimeAwareCache class.");
|
|
23
|
+
|
|
24
|
+
return _mainRuntime;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private:
|
|
28
|
+
static jsi::Runtime *_mainRuntime;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Provides a way to keep data specific to a jsi::Runtime instance that gets
|
|
33
|
+
* cleaned up when that runtime is destroyed. This is necessary because JSI does
|
|
34
|
+
* not allow for its associated objects to be retained past the runtime
|
|
35
|
+
* lifetime. If an object (e.g. jsi::Values or jsi::Function instances) is kept
|
|
36
|
+
* after the runtime is torn down, its destructor (once it is destroyed
|
|
37
|
+
* eventually) will result in a crash (JSI objects keep a pointer to memory
|
|
38
|
+
* managed by the runtime, accessing that portion of the memory after runtime is
|
|
39
|
+
* deleted is the root cause of that crash).
|
|
40
|
+
*
|
|
41
|
+
* In order to provide an efficient implementation that does not add an overhead
|
|
42
|
+
* for the cases when only a single runtime is used, which is the primary
|
|
43
|
+
* usecase, the following assumption has been made: Only for secondary runtimes
|
|
44
|
+
* we track destruction and clean up the store associated with that runtime. For
|
|
45
|
+
* the first runtime we assume that the object holding the store is destroyed
|
|
46
|
+
* prior to the destruction of that runtime.
|
|
47
|
+
*
|
|
48
|
+
* The above assumption makes it work without any overhead when only single
|
|
49
|
+
* runtime is in use. Specifically, we don't perform any additional operations
|
|
50
|
+
* related to tracking runtime lifecycle when only a single runtime is used.
|
|
51
|
+
*/
|
|
52
|
+
template <typename T>
|
|
53
|
+
class RuntimeAwareCache : public BaseRuntimeAwareCache,
|
|
54
|
+
public RuntimeLifecycleListener {
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
void onRuntimeDestroyed(jsi::Runtime *rt) override {
|
|
58
|
+
if (getMainJsRuntime() != rt) {
|
|
59
|
+
// We are removing a secondary runtime
|
|
60
|
+
_secondaryRuntimeCaches.erase(rt);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
~RuntimeAwareCache() {
|
|
65
|
+
for (auto &cache : _secondaryRuntimeCaches) {
|
|
66
|
+
RuntimeLifecycleMonitor::removeListener(
|
|
67
|
+
*static_cast<jsi::Runtime *>(cache.first), this);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
T &get(jsi::Runtime &rt) {
|
|
72
|
+
// We check if we're accessing the main runtime - this is the happy path
|
|
73
|
+
// to avoid us having to lookup by runtime for caches that only has a single
|
|
74
|
+
// runtime
|
|
75
|
+
if (getMainJsRuntime() == &rt) {
|
|
76
|
+
return _primaryCache;
|
|
77
|
+
} else {
|
|
78
|
+
if (_secondaryRuntimeCaches.count(&rt) == 0) {
|
|
79
|
+
// we only add listener when the secondary runtime is used, this assumes
|
|
80
|
+
// that the secondary runtime is terminated first. This lets us avoid
|
|
81
|
+
// additional complexity for the majority of cases when objects are not
|
|
82
|
+
// shared between runtimes. Otherwise we'd have to register all objecrts
|
|
83
|
+
// with the RuntimeMonitor as opposed to only registering ones that are
|
|
84
|
+
// used in secondary runtime. Note that we can't register listener here
|
|
85
|
+
// with the primary runtime as it may run on a separate thread.
|
|
86
|
+
RuntimeLifecycleMonitor::addListener(rt, this);
|
|
87
|
+
|
|
88
|
+
T cache;
|
|
89
|
+
_secondaryRuntimeCaches.emplace(&rt, std::move(cache));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return _secondaryRuntimeCaches.at(&rt);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private:
|
|
96
|
+
std::unordered_map<void *, T> _secondaryRuntimeCaches;
|
|
97
|
+
T _primaryCache;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#include "RuntimeLifecycleMonitor.h"
|
|
2
|
+
|
|
3
|
+
#include <mutex>
|
|
4
|
+
#include <unordered_map>
|
|
5
|
+
#include <unordered_set>
|
|
6
|
+
#include <utility>
|
|
7
|
+
|
|
8
|
+
namespace rnwgpu {
|
|
9
|
+
|
|
10
|
+
static std::unordered_map<jsi::Runtime *,
|
|
11
|
+
std::unordered_set<RuntimeLifecycleListener *>>
|
|
12
|
+
listeners;
|
|
13
|
+
static std::mutex listenersMutex;
|
|
14
|
+
|
|
15
|
+
struct RuntimeLifecycleMonitorObject : public jsi::HostObject {
|
|
16
|
+
jsi::Runtime *_rt;
|
|
17
|
+
explicit RuntimeLifecycleMonitorObject(jsi::Runtime *rt) : _rt(rt) {}
|
|
18
|
+
~RuntimeLifecycleMonitorObject() {
|
|
19
|
+
std::unordered_set<RuntimeLifecycleListener *> listenersCopy;
|
|
20
|
+
{
|
|
21
|
+
std::lock_guard<std::mutex> lock(listenersMutex);
|
|
22
|
+
auto listenersSet = listeners.find(_rt);
|
|
23
|
+
if (listenersSet != listeners.end()) {
|
|
24
|
+
listenersCopy = listenersSet->second;
|
|
25
|
+
listeners.erase(listenersSet);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (auto listener : listenersCopy) {
|
|
29
|
+
listener->onRuntimeDestroyed(_rt);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
void RuntimeLifecycleMonitor::addListener(jsi::Runtime &rt,
|
|
35
|
+
RuntimeLifecycleListener *listener) {
|
|
36
|
+
bool shouldInstallMonitor = false;
|
|
37
|
+
{
|
|
38
|
+
std::lock_guard<std::mutex> lock(listenersMutex);
|
|
39
|
+
auto listenersSet = listeners.find(&rt);
|
|
40
|
+
if (listenersSet == listeners.end()) {
|
|
41
|
+
std::unordered_set<RuntimeLifecycleListener *> newSet;
|
|
42
|
+
newSet.insert(listener);
|
|
43
|
+
listeners.emplace(&rt, std::move(newSet));
|
|
44
|
+
shouldInstallMonitor = true;
|
|
45
|
+
} else {
|
|
46
|
+
listenersSet->second.insert(listener);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (shouldInstallMonitor) {
|
|
50
|
+
// We install a global host object in the provided runtime, this way we can
|
|
51
|
+
// use that host object destructor to get notified when the runtime is being
|
|
52
|
+
// terminated. We use a unique name for the object as it gets saved with the
|
|
53
|
+
// runtime's global object.
|
|
54
|
+
rt.global().setProperty(
|
|
55
|
+
rt, "__rnwgpu_rt_lifecycle_monitor",
|
|
56
|
+
jsi::Object::createFromHostObject(
|
|
57
|
+
rt, std::make_shared<RuntimeLifecycleMonitorObject>(&rt)));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void RuntimeLifecycleMonitor::removeListener(
|
|
62
|
+
jsi::Runtime &rt, RuntimeLifecycleListener *listener) {
|
|
63
|
+
std::lock_guard<std::mutex> lock(listenersMutex);
|
|
64
|
+
auto listenersSet = listeners.find(&rt);
|
|
65
|
+
if (listenersSet == listeners.end()) {
|
|
66
|
+
// nothing to do here
|
|
67
|
+
} else {
|
|
68
|
+
listenersSet->second.erase(listener);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
|
|
5
|
+
#include <memory>
|
|
6
|
+
|
|
7
|
+
namespace rnwgpu {
|
|
8
|
+
|
|
9
|
+
namespace jsi = facebook::jsi;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Listener interface that allows for getting notified when a jsi::Runtime
|
|
13
|
+
* instance is destroyed.
|
|
14
|
+
*/
|
|
15
|
+
struct RuntimeLifecycleListener {
|
|
16
|
+
virtual ~RuntimeLifecycleListener() {}
|
|
17
|
+
virtual void onRuntimeDestroyed(jsi::Runtime *) = 0;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This class provides an API via static methods for registering and
|
|
22
|
+
* unregistering runtime lifecycle listeners. The listeners can be used to
|
|
23
|
+
* cleanup any data that references a given jsi::Runtime instance before it gets
|
|
24
|
+
* destroyed.
|
|
25
|
+
*/
|
|
26
|
+
struct RuntimeLifecycleMonitor {
|
|
27
|
+
static void addListener(jsi::Runtime &rt, RuntimeLifecycleListener *listener);
|
|
28
|
+
static void removeListener(jsi::Runtime &rt,
|
|
29
|
+
RuntimeLifecycleListener *listener);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <jsi/jsi.h>
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
6
|
+
#include "JSIConverter.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
|
+
static std::shared_ptr<ArrayBuffer>
|
|
28
|
+
createArrayBufferFromJSI(jsi::Runtime &runtime,
|
|
29
|
+
const jsi::ArrayBuffer &arrayBuffer,
|
|
30
|
+
size_t bytesPerElement) {
|
|
31
|
+
auto size = arrayBuffer.size(runtime);
|
|
32
|
+
return std::make_shared<ArrayBuffer>(arrayBuffer.data(runtime), size,
|
|
33
|
+
bytesPerElement);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
template <> struct JSIConverter<std::shared_ptr<ArrayBuffer>> {
|
|
37
|
+
static std::shared_ptr<ArrayBuffer>
|
|
38
|
+
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBound) {
|
|
39
|
+
if (arg.isObject()) {
|
|
40
|
+
auto obj = arg.getObject(runtime);
|
|
41
|
+
if (obj.isArrayBuffer(runtime)) {
|
|
42
|
+
return createArrayBufferFromJSI(runtime, obj.getArrayBuffer(runtime),
|
|
43
|
+
1);
|
|
44
|
+
}
|
|
45
|
+
if (obj.hasProperty(runtime, "buffer")) {
|
|
46
|
+
auto bufferProp = obj.getProperty(runtime, "buffer");
|
|
47
|
+
if (bufferProp.isObject() &&
|
|
48
|
+
bufferProp.getObject(runtime).isArrayBuffer(runtime)) {
|
|
49
|
+
auto buff = bufferProp.getObject(runtime);
|
|
50
|
+
auto bytesPerElements =
|
|
51
|
+
obj.getProperty(runtime, "BYTES_PER_ELEMENT").asNumber();
|
|
52
|
+
auto arrayBuffer = buff.getArrayBuffer(runtime);
|
|
53
|
+
auto byteOffset = static_cast<size_t>(
|
|
54
|
+
obj.getProperty(runtime, "byteOffset").asNumber());
|
|
55
|
+
auto byteLength = static_cast<size_t>(
|
|
56
|
+
obj.getProperty(runtime, "byteLength").asNumber());
|
|
57
|
+
return std::make_shared<ArrayBuffer>(
|
|
58
|
+
arrayBuffer.data(runtime) + byteOffset, byteLength,
|
|
59
|
+
static_cast<size_t>(bytesPerElements));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw std::runtime_error("ArrayBuffer::fromJSI: argument is not an object "
|
|
64
|
+
"with an ArrayBuffer 'buffer' property");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static jsi::Value toJSI(jsi::Runtime &runtime,
|
|
68
|
+
std::shared_ptr<ArrayBuffer> arg) {
|
|
69
|
+
return jsi::ArrayBuffer(runtime, arg);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <functional>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <span>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
#include "webgpu/webgpu_cpp.h"
|
|
10
|
+
|
|
11
|
+
namespace rnwgpu {
|
|
12
|
+
|
|
13
|
+
struct ImageData {
|
|
14
|
+
std::vector<uint8_t> data;
|
|
15
|
+
size_t width;
|
|
16
|
+
size_t height;
|
|
17
|
+
wgpu::TextureFormat format;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
class PlatformContext {
|
|
21
|
+
public:
|
|
22
|
+
PlatformContext() = default;
|
|
23
|
+
virtual ~PlatformContext() = default;
|
|
24
|
+
|
|
25
|
+
virtual wgpu::Surface makeSurface(wgpu::Instance instance, void *surface,
|
|
26
|
+
int width, int height) = 0;
|
|
27
|
+
virtual ImageData createImageBitmap(std::string blobId, double offset,
|
|
28
|
+
double size) = 0;
|
|
29
|
+
|
|
30
|
+
// Async version that performs image decoding on a background thread
|
|
31
|
+
virtual void
|
|
32
|
+
createImageBitmapAsync(std::string blobId, double offset, double size,
|
|
33
|
+
std::function<void(ImageData)> onSuccess,
|
|
34
|
+
std::function<void(std::string)> onError) = 0;
|
|
35
|
+
|
|
36
|
+
// Create ImageBitmap from raw encoded image bytes (PNG/JPEG/etc.)
|
|
37
|
+
virtual ImageData
|
|
38
|
+
createImageBitmapFromData(std::span<const uint8_t> data) = 0;
|
|
39
|
+
|
|
40
|
+
virtual void
|
|
41
|
+
createImageBitmapFromDataAsync(std::span<const uint8_t> data,
|
|
42
|
+
std::function<void(ImageData)> onSuccess,
|
|
43
|
+
std::function<void(std::string)> onError) = 0;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#include "RNWebGPUManager.h"
|
|
2
|
+
|
|
3
|
+
#include "GPU.h"
|
|
4
|
+
#include "NativeObject.h"
|
|
5
|
+
#include "RNWebGPU.h"
|
|
6
|
+
|
|
7
|
+
// GPU API classes (for instanceof support)
|
|
8
|
+
#include "GPUAdapter.h"
|
|
9
|
+
#include "GPUAdapterInfo.h"
|
|
10
|
+
#include "GPUBindGroup.h"
|
|
11
|
+
#include "GPUBindGroupLayout.h"
|
|
12
|
+
#include "GPUBuffer.h"
|
|
13
|
+
#include "GPUCanvasContext.h"
|
|
14
|
+
#include "GPUCommandBuffer.h"
|
|
15
|
+
#include "GPUCommandEncoder.h"
|
|
16
|
+
#include "GPUCompilationInfo.h"
|
|
17
|
+
#include "GPUCompilationMessage.h"
|
|
18
|
+
#include "GPUComputePassEncoder.h"
|
|
19
|
+
#include "GPUComputePipeline.h"
|
|
20
|
+
#include "GPUDevice.h"
|
|
21
|
+
#include "GPUDeviceLostInfo.h"
|
|
22
|
+
#include "GPUError.h"
|
|
23
|
+
#include "GPUExternalTexture.h"
|
|
24
|
+
#include "GPUInternalError.h"
|
|
25
|
+
#include "GPUOutOfMemoryError.h"
|
|
26
|
+
#include "GPUPipelineLayout.h"
|
|
27
|
+
#include "GPUQuerySet.h"
|
|
28
|
+
#include "GPUQueue.h"
|
|
29
|
+
#include "GPURenderBundle.h"
|
|
30
|
+
#include "GPURenderBundleEncoder.h"
|
|
31
|
+
#include "GPURenderPassEncoder.h"
|
|
32
|
+
#include "GPURenderPipeline.h"
|
|
33
|
+
#include "GPUSampler.h"
|
|
34
|
+
#include "GPUShaderModule.h"
|
|
35
|
+
#include "GPUSupportedLimits.h"
|
|
36
|
+
#include "GPUTexture.h"
|
|
37
|
+
#include "GPUTextureView.h"
|
|
38
|
+
#include "GPUUncapturedErrorEvent.h"
|
|
39
|
+
#include "GPUValidationError.h"
|
|
40
|
+
|
|
41
|
+
// Enums
|
|
42
|
+
#include "GPUBufferUsage.h"
|
|
43
|
+
#include "GPUColorWrite.h"
|
|
44
|
+
#include "GPUMapMode.h"
|
|
45
|
+
#include "GPUShaderStage.h"
|
|
46
|
+
#include "GPUTextureUsage.h"
|
|
47
|
+
|
|
48
|
+
#include <memory>
|
|
49
|
+
#include <utility>
|
|
50
|
+
|
|
51
|
+
namespace rnwgpu {
|
|
52
|
+
|
|
53
|
+
RNWebGPUManager::RNWebGPUManager(
|
|
54
|
+
jsi::Runtime *jsRuntime,
|
|
55
|
+
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
|
|
56
|
+
std::shared_ptr<PlatformContext> platformContext)
|
|
57
|
+
: _jsRuntime(jsRuntime), _jsCallInvoker(jsCallInvoker),
|
|
58
|
+
_platformContext(platformContext) {
|
|
59
|
+
|
|
60
|
+
// Register main runtime for RuntimeAwareCache
|
|
61
|
+
BaseRuntimeAwareCache::setMainJsRuntime(_jsRuntime);
|
|
62
|
+
|
|
63
|
+
auto gpu = std::make_shared<GPU>(*_jsRuntime);
|
|
64
|
+
auto rnWebGPU =
|
|
65
|
+
std::make_shared<RNWebGPU>(gpu, _platformContext, _jsCallInvoker);
|
|
66
|
+
_gpu = gpu->get();
|
|
67
|
+
_jsRuntime->global().setProperty(*_jsRuntime, "RNWebGPU",
|
|
68
|
+
RNWebGPU::create(*_jsRuntime, rnWebGPU));
|
|
69
|
+
|
|
70
|
+
// Install constructors for instanceof support
|
|
71
|
+
GPU::installConstructor(*_jsRuntime);
|
|
72
|
+
GPUAdapter::installConstructor(*_jsRuntime);
|
|
73
|
+
GPUAdapterInfo::installConstructor(*_jsRuntime);
|
|
74
|
+
GPUBindGroup::installConstructor(*_jsRuntime);
|
|
75
|
+
GPUBindGroupLayout::installConstructor(*_jsRuntime);
|
|
76
|
+
GPUBuffer::installConstructor(*_jsRuntime);
|
|
77
|
+
GPUCanvasContext::installConstructor(*_jsRuntime);
|
|
78
|
+
GPUCommandBuffer::installConstructor(*_jsRuntime);
|
|
79
|
+
GPUCommandEncoder::installConstructor(*_jsRuntime);
|
|
80
|
+
GPUCompilationInfo::installConstructor(*_jsRuntime);
|
|
81
|
+
GPUCompilationMessage::installConstructor(*_jsRuntime);
|
|
82
|
+
GPUComputePassEncoder::installConstructor(*_jsRuntime);
|
|
83
|
+
GPUComputePipeline::installConstructor(*_jsRuntime);
|
|
84
|
+
GPUDevice::installConstructor(*_jsRuntime);
|
|
85
|
+
GPUDeviceLostInfo::installConstructor(*_jsRuntime);
|
|
86
|
+
GPUError::installConstructor(*_jsRuntime);
|
|
87
|
+
GPUExternalTexture::installConstructor(*_jsRuntime);
|
|
88
|
+
GPUInternalError::installConstructor(*_jsRuntime);
|
|
89
|
+
GPUOutOfMemoryError::installConstructor(*_jsRuntime);
|
|
90
|
+
GPUValidationError::installConstructor(*_jsRuntime);
|
|
91
|
+
GPUUncapturedErrorEvent::installConstructor(*_jsRuntime);
|
|
92
|
+
GPUPipelineLayout::installConstructor(*_jsRuntime);
|
|
93
|
+
GPUQuerySet::installConstructor(*_jsRuntime);
|
|
94
|
+
GPUQueue::installConstructor(*_jsRuntime);
|
|
95
|
+
GPURenderBundle::installConstructor(*_jsRuntime);
|
|
96
|
+
GPURenderBundleEncoder::installConstructor(*_jsRuntime);
|
|
97
|
+
GPURenderPassEncoder::installConstructor(*_jsRuntime);
|
|
98
|
+
GPURenderPipeline::installConstructor(*_jsRuntime);
|
|
99
|
+
GPUSampler::installConstructor(*_jsRuntime);
|
|
100
|
+
GPUShaderModule::installConstructor(*_jsRuntime);
|
|
101
|
+
GPUSupportedLimits::installConstructor(*_jsRuntime);
|
|
102
|
+
GPUTexture::installConstructor(*_jsRuntime);
|
|
103
|
+
GPUTextureView::installConstructor(*_jsRuntime);
|
|
104
|
+
|
|
105
|
+
// Install constant objects as plain JS objects with own properties
|
|
106
|
+
_jsRuntime->global().setProperty(*_jsRuntime, "GPUBufferUsage",
|
|
107
|
+
GPUBufferUsage::create(*_jsRuntime));
|
|
108
|
+
_jsRuntime->global().setProperty(*_jsRuntime, "GPUColorWrite",
|
|
109
|
+
GPUColorWrite::create(*_jsRuntime));
|
|
110
|
+
_jsRuntime->global().setProperty(*_jsRuntime, "GPUMapMode",
|
|
111
|
+
GPUMapMode::create(*_jsRuntime));
|
|
112
|
+
_jsRuntime->global().setProperty(*_jsRuntime, "GPUShaderStage",
|
|
113
|
+
GPUShaderStage::create(*_jsRuntime));
|
|
114
|
+
_jsRuntime->global().setProperty(*_jsRuntime, "GPUTextureUsage",
|
|
115
|
+
GPUTextureUsage::create(*_jsRuntime));
|
|
116
|
+
|
|
117
|
+
// Install global helper functions for Worklets serialization
|
|
118
|
+
// These are standalone functions that don't require RNWebGPU instance
|
|
119
|
+
installWebGPUWorkletHelpers(*_jsRuntime);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
void RNWebGPUManager::installWebGPUWorkletHelpers(jsi::Runtime &runtime) {
|
|
123
|
+
// __webgpuIsWebGPUObject - checks if a value is a WebGPU NativeObject
|
|
124
|
+
auto isWebGPUObjectFunc = jsi::Function::createFromHostFunction(
|
|
125
|
+
runtime, jsi::PropNameID::forUtf8(runtime, "__webgpuIsWebGPUObject"), 1,
|
|
126
|
+
[](jsi::Runtime &rt, const jsi::Value & /*thisVal*/,
|
|
127
|
+
const jsi::Value *args, size_t count) -> jsi::Value {
|
|
128
|
+
if (count < 1 || !args[0].isObject()) {
|
|
129
|
+
return jsi::Value(false);
|
|
130
|
+
}
|
|
131
|
+
auto obj = args[0].getObject(rt);
|
|
132
|
+
|
|
133
|
+
// Check if it has native state
|
|
134
|
+
if (!obj.hasNativeState(rt)) {
|
|
135
|
+
return jsi::Value(false);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Check if it has Symbol.toStringTag on its prototype (WebGPU objects
|
|
139
|
+
// do)
|
|
140
|
+
auto objectCtor = rt.global().getPropertyAsObject(rt, "Object");
|
|
141
|
+
auto getPrototypeOf =
|
|
142
|
+
objectCtor.getPropertyAsFunction(rt, "getPrototypeOf");
|
|
143
|
+
auto proto = getPrototypeOf.call(rt, obj);
|
|
144
|
+
|
|
145
|
+
if (!proto.isObject()) {
|
|
146
|
+
return jsi::Value(false);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
auto protoObj = proto.getObject(rt);
|
|
150
|
+
auto symbolCtor = rt.global().getPropertyAsObject(rt, "Symbol");
|
|
151
|
+
auto toStringTag = symbolCtor.getProperty(rt, "toStringTag");
|
|
152
|
+
if (toStringTag.isUndefined()) {
|
|
153
|
+
return jsi::Value(false);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
auto getOwnPropertyDescriptor =
|
|
157
|
+
objectCtor.getPropertyAsFunction(rt, "getOwnPropertyDescriptor");
|
|
158
|
+
auto desc = getOwnPropertyDescriptor.call(rt, protoObj, toStringTag);
|
|
159
|
+
return jsi::Value(desc.isObject());
|
|
160
|
+
});
|
|
161
|
+
runtime.global().setProperty(runtime, "__webgpuIsWebGPUObject",
|
|
162
|
+
std::move(isWebGPUObjectFunc));
|
|
163
|
+
|
|
164
|
+
// __webgpuBox - boxes a WebGPU object for Worklets serialization
|
|
165
|
+
auto boxFunc = jsi::Function::createFromHostFunction(
|
|
166
|
+
runtime, jsi::PropNameID::forUtf8(runtime, "__webgpuBox"), 1,
|
|
167
|
+
[](jsi::Runtime &rt, const jsi::Value & /*thisVal*/,
|
|
168
|
+
const jsi::Value *args, size_t count) -> jsi::Value {
|
|
169
|
+
if (count < 1 || !args[0].isObject()) {
|
|
170
|
+
throw jsi::JSError(rt,
|
|
171
|
+
"__webgpuBox() requires a WebGPU object argument");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
auto obj = args[0].getObject(rt);
|
|
175
|
+
|
|
176
|
+
// Check if it has native state
|
|
177
|
+
if (!obj.hasNativeState(rt)) {
|
|
178
|
+
throw jsi::JSError(
|
|
179
|
+
rt, "Object has no native state - not a WebGPU object");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Get the brand name from Symbol.toStringTag on the prototype
|
|
183
|
+
auto objectCtor = rt.global().getPropertyAsObject(rt, "Object");
|
|
184
|
+
auto getPrototypeOf =
|
|
185
|
+
objectCtor.getPropertyAsFunction(rt, "getPrototypeOf");
|
|
186
|
+
auto proto = getPrototypeOf.call(rt, obj);
|
|
187
|
+
|
|
188
|
+
std::string brand;
|
|
189
|
+
if (proto.isObject()) {
|
|
190
|
+
auto protoObj = proto.getObject(rt);
|
|
191
|
+
auto symbolCtor = rt.global().getPropertyAsObject(rt, "Symbol");
|
|
192
|
+
auto toStringTag = symbolCtor.getProperty(rt, "toStringTag");
|
|
193
|
+
if (!toStringTag.isUndefined()) {
|
|
194
|
+
auto getOwnPropertyDescriptor = objectCtor.getPropertyAsFunction(
|
|
195
|
+
rt, "getOwnPropertyDescriptor");
|
|
196
|
+
auto desc =
|
|
197
|
+
getOwnPropertyDescriptor.call(rt, protoObj, toStringTag);
|
|
198
|
+
if (desc.isObject()) {
|
|
199
|
+
auto descObj = desc.getObject(rt);
|
|
200
|
+
auto value = descObj.getProperty(rt, "value");
|
|
201
|
+
if (value.isString()) {
|
|
202
|
+
brand = value.getString(rt).utf8(rt);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (brand.empty()) {
|
|
209
|
+
throw jsi::JSError(rt, "Cannot determine WebGPU object type - no "
|
|
210
|
+
"Symbol.toStringTag found");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
auto nativeState = obj.getNativeState(rt);
|
|
214
|
+
auto boxed = std::make_shared<BoxedWebGPUObject>(nativeState, brand);
|
|
215
|
+
return jsi::Object::createFromHostObject(rt, boxed);
|
|
216
|
+
});
|
|
217
|
+
runtime.global().setProperty(runtime, "__webgpuBox", std::move(boxFunc));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
RNWebGPUManager::~RNWebGPUManager() {
|
|
221
|
+
_jsRuntime = nullptr;
|
|
222
|
+
_jsCallInvoker = nullptr;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
|
|
5
|
+
#include "GPU.h"
|
|
6
|
+
#include "PlatformContext.h"
|
|
7
|
+
#include "SurfaceRegistry.h"
|
|
8
|
+
|
|
9
|
+
namespace facebook {
|
|
10
|
+
namespace jsi {
|
|
11
|
+
class Runtime;
|
|
12
|
+
} // namespace jsi
|
|
13
|
+
namespace react {
|
|
14
|
+
class CallInvoker;
|
|
15
|
+
}
|
|
16
|
+
} // namespace facebook
|
|
17
|
+
|
|
18
|
+
namespace rnwgpu {
|
|
19
|
+
|
|
20
|
+
namespace jsi = facebook::jsi;
|
|
21
|
+
namespace react = facebook::react;
|
|
22
|
+
|
|
23
|
+
class RNWebGPUManager {
|
|
24
|
+
public:
|
|
25
|
+
RNWebGPUManager(jsi::Runtime *jsRuntime,
|
|
26
|
+
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
|
|
27
|
+
std::shared_ptr<PlatformContext> platformContext);
|
|
28
|
+
~RNWebGPUManager();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Install global helper functions for Worklets serialization.
|
|
32
|
+
* This installs __webgpuIsWebGPUObject and __webgpuBox on the global object.
|
|
33
|
+
* Can be called on any runtime (main JS, UI, or custom worklet runtimes).
|
|
34
|
+
*/
|
|
35
|
+
static void installWebGPUWorkletHelpers(jsi::Runtime &runtime);
|
|
36
|
+
|
|
37
|
+
private:
|
|
38
|
+
jsi::Runtime *_jsRuntime;
|
|
39
|
+
std::shared_ptr<facebook::react::CallInvoker> _jsCallInvoker;
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
wgpu::Instance _gpu;
|
|
43
|
+
std::shared_ptr<PlatformContext> _platformContext;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
} // namespace rnwgpu
|