@shopify/react-native-skia 2.10.0 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +7 -41
- package/android/build.gradle +33 -0
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +1 -2
- package/cpp/api/JsiNativeBuffer.h +14 -20
- package/cpp/api/JsiSkAnimatedImage.h +13 -16
- package/cpp/api/JsiSkAnimatedImageFactory.h +9 -7
- package/cpp/api/JsiSkApi.h +94 -90
- package/cpp/api/JsiSkCanvas.h +108 -251
- package/cpp/api/JsiSkColorFilterFactory.h +45 -63
- package/cpp/api/JsiSkContourMeasure.h +19 -29
- package/cpp/api/JsiSkContourMeasureIter.h +6 -6
- package/cpp/api/JsiSkConverters.h +410 -0
- package/cpp/api/JsiSkDataFactory.h +9 -15
- package/cpp/api/JsiSkFont.h +99 -180
- package/cpp/api/JsiSkFontMgr.h +19 -21
- package/cpp/api/JsiSkFontMgrFactory.h +4 -5
- package/cpp/api/JsiSkImage.h +66 -66
- package/cpp/api/JsiSkImageFactory.h +66 -63
- package/cpp/api/JsiSkImageFilterFactory.h +354 -608
- package/cpp/api/JsiSkImageInfo.h +10 -13
- package/cpp/api/JsiSkMaskFilterFactory.h +8 -11
- package/cpp/api/JsiSkMatrix.h +36 -73
- package/cpp/api/JsiSkNativeObjects.h +60 -92
- package/cpp/api/JsiSkPaint.h +73 -131
- package/cpp/api/JsiSkParagraph.h +36 -53
- package/cpp/api/JsiSkParagraphBuilder.h +36 -64
- package/cpp/api/JsiSkParagraphBuilderFactory.h +11 -16
- package/cpp/api/JsiSkPath.h +216 -349
- package/cpp/api/JsiSkPathBuilder.h +133 -269
- package/cpp/api/JsiSkPathBuilderFactory.h +11 -11
- package/cpp/api/JsiSkPathEffectFactory.h +52 -72
- package/cpp/api/JsiSkPathFactory.h +129 -195
- package/cpp/api/JsiSkPicture.h +12 -18
- package/cpp/api/JsiSkPictureRecorder.h +14 -15
- package/cpp/api/JsiSkPoint.h +4 -4
- package/cpp/api/JsiSkRRect.h +7 -8
- package/cpp/api/JsiSkRSXform.h +10 -23
- package/cpp/api/JsiSkRect.h +23 -31
- package/cpp/api/JsiSkRuntimeEffect.h +67 -83
- package/cpp/api/JsiSkRuntimeEffectFactory.h +6 -10
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +5 -14
- package/cpp/api/JsiSkSVG.h +4 -4
- package/cpp/api/JsiSkShaderFactory.h +153 -225
- package/cpp/api/JsiSkSkottie.h +104 -126
- package/cpp/api/JsiSkSurface.h +11 -14
- package/cpp/api/JsiSkSurfaceFactory.h +6 -7
- package/cpp/api/JsiSkTextBlobFactory.h +31 -54
- package/cpp/api/JsiSkTypeface.h +8 -12
- package/cpp/api/JsiSkTypefaceFactory.h +9 -7
- package/cpp/api/JsiSkTypefaceFontProvider.h +22 -23
- package/cpp/api/JsiSkTypefaceFontProviderFactory.h +5 -6
- package/cpp/api/JsiSkVertices.h +6 -8
- package/cpp/api/JsiSkiaContext.h +10 -11
- package/cpp/api/JsiVideo.h +31 -71
- package/cpp/jsi/JSIConverter.h +0 -31
- package/cpp/jsi/NativeObject.h +11 -6
- package/cpp/rnskia/RNDawnContext.h +18 -2
- package/cpp/rnskia/RNDawnInterop.cpp +19 -0
- package/cpp/rnskia/RNDawnUtils.h +18 -1
- package/cpp/rnskia/RNSkManager.cpp +5 -162
- package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h +2 -0
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +15 -6
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +5 -15
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +0 -1
- package/lib/commonjs/skia/types/index.js +0 -11
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +1 -4
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/views/index.d.ts +0 -1
- package/lib/commonjs/views/index.js +0 -11
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +15 -6
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +5 -15
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +0 -1
- package/lib/module/skia/types/index.js +0 -1
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/module/skia/web/JsiSkImageFactory.js +2 -2
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +1 -4
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/views/index.d.ts +0 -1
- package/lib/module/views/index.js +0 -1
- package/lib/module/views/index.js.map +1 -1
- package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -2
- package/lib/typescript/lib/module/mock/index.d.ts +0 -2
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -2
- package/lib/typescript/lib/module/skia/types/index.d.ts +0 -1
- package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -2
- package/lib/typescript/lib/module/views/index.d.ts +0 -1
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +15 -6
- package/lib/typescript/src/skia/types/Skia.d.ts +5 -15
- package/lib/typescript/src/skia/types/index.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/typescript/src/views/index.d.ts +0 -1
- package/package.json +3 -4
- package/react-native-skia.podspec +38 -4
- package/src/mock/index.ts +0 -1
- package/src/skia/types/Image/ImageFactory.ts +15 -6
- package/src/skia/types/Skia.ts +5 -15
- package/src/skia/types/index.ts +0 -1
- package/src/skia/web/JsiSkImageFactory.ts +3 -3
- package/src/skia/web/JsiSkia.ts +2 -5
- package/src/views/index.ts +0 -1
- package/android/cpp/jni/JniWebGPUView.cpp +0 -112
- package/android/cpp/rnskia-android/SkiaPlatformContext.h +0 -26
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +0 -43
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +0 -50
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +0 -98
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +0 -19
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +0 -58
- package/apple/RNWebGPUAppleNativeBuffer.mm +0 -33
- package/apple/SkiaPlatformContext.h +0 -20
- package/apple/SkiaPlatformContext.mm +0 -21
- package/apple/SkiaWebGPUView.mm +0 -81
- package/apple/WebGPUMetalView.mm +0 -136
- package/cpp/rnwgpu/ArrayBuffer.h +0 -116
- package/cpp/rnwgpu/Canvas.h +0 -52
- package/cpp/rnwgpu/PlatformContext.h +0 -18
- package/cpp/rnwgpu/SurfaceRegistry.h +0 -605
- package/cpp/rnwgpu/api/AppleNativeBuffer.h +0 -22
- package/cpp/rnwgpu/api/Convertors.h +0 -783
- package/cpp/rnwgpu/api/External.h +0 -12
- package/cpp/rnwgpu/api/GPU.cpp +0 -162
- package/cpp/rnwgpu/api/GPU.h +0 -60
- package/cpp/rnwgpu/api/GPUAdapter.cpp +0 -239
- package/cpp/rnwgpu/api/GPUAdapter.h +0 -60
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -57
- package/cpp/rnwgpu/api/GPUBindGroup.cpp +0 -3
- package/cpp/rnwgpu/api/GPUBindGroup.h +0 -51
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +0 -52
- package/cpp/rnwgpu/api/GPUBuffer.cpp +0 -107
- package/cpp/rnwgpu/api/GPUBuffer.h +0 -88
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +0 -75
- package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -70
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +0 -45
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +0 -179
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +0 -111
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -79
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +0 -36
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +0 -60
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +0 -85
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +0 -12
- package/cpp/rnwgpu/api/GPUComputePipeline.h +0 -60
- package/cpp/rnwgpu/api/GPUDevice.cpp +0 -613
- package/cpp/rnwgpu/api/GPUDevice.h +0 -258
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +0 -7
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +0 -40
- package/cpp/rnwgpu/api/GPUError.h +0 -35
- package/cpp/rnwgpu/api/GPUExtent3D.h +0 -66
- package/cpp/rnwgpu/api/GPUExternalTexture.cpp +0 -139
- package/cpp/rnwgpu/api/GPUExternalTexture.h +0 -95
- package/cpp/rnwgpu/api/GPUFeatures.h +0 -203
- package/cpp/rnwgpu/api/GPUInternalError.h +0 -31
- package/cpp/rnwgpu/api/GPUOrigin2D.h +0 -55
- package/cpp/rnwgpu/api/GPUOrigin3D.h +0 -62
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +0 -33
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +0 -45
- package/cpp/rnwgpu/api/GPUQuerySet.cpp +0 -11
- package/cpp/rnwgpu/api/GPUQuerySet.h +0 -73
- package/cpp/rnwgpu/api/GPUQueue.cpp +0 -179
- package/cpp/rnwgpu/api/GPUQueue.h +0 -84
- package/cpp/rnwgpu/api/GPURenderBundle.h +0 -44
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +0 -131
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +0 -110
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +0 -165
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +0 -130
- package/cpp/rnwgpu/api/GPURenderPipeline.cpp +0 -13
- package/cpp/rnwgpu/api/GPURenderPipeline.h +0 -61
- package/cpp/rnwgpu/api/GPUSampler.h +0 -44
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +0 -56
- package/cpp/rnwgpu/api/GPUShaderModule.h +0 -66
- package/cpp/rnwgpu/api/GPUSharedFence.cpp +0 -80
- package/cpp/rnwgpu/api/GPUSharedFence.h +0 -53
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +0 -135
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +0 -75
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +0 -129
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +0 -131
- package/cpp/rnwgpu/api/GPUTexture.cpp +0 -47
- package/cpp/rnwgpu/api/GPUTexture.h +0 -162
- package/cpp/rnwgpu/api/GPUTextureView.h +0 -44
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -60
- package/cpp/rnwgpu/api/GPUValidationError.h +0 -32
- package/cpp/rnwgpu/api/ImageBitmap.h +0 -62
- package/cpp/rnwgpu/api/NativeBufferUtils.h +0 -87
- package/cpp/rnwgpu/api/RNWebGPU.h +0 -82
- package/cpp/rnwgpu/api/WebGPUConstants.h +0 -36
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +0 -64
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +0 -78
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +0 -97
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +0 -57
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +0 -52
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +0 -59
- package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +0 -39
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +0 -76
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +0 -66
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +0 -58
- package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +0 -29
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +0 -45
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +0 -45
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +0 -58
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +0 -67
- package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +0 -103
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +0 -109
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +0 -38
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +0 -90
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +0 -73
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +0 -62
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +0 -63
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +0 -65
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +0 -81
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +0 -54
- package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +0 -22
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +0 -54
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +0 -57
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +0 -69
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +0 -61
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +0 -55
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +0 -43
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +0 -45
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +0 -80
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +0 -81
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +0 -101
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +0 -92
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +0 -58
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +0 -103
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +0 -51
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +0 -45
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +0 -110
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +0 -60
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +0 -62
- package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +0 -25
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +0 -58
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +0 -51
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +0 -73
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +0 -64
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +0 -59
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +0 -59
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +0 -91
- package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +0 -29
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +0 -91
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +0 -64
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +0 -53
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +0 -62
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +0 -73
- package/cpp/rnwgpu/api/descriptors/Unions.h +0 -1969
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +0 -213
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +0 -58
- package/cpp/rnwgpu/async/RuntimeContext.cpp +0 -199
- package/cpp/rnwgpu/async/RuntimeContext.h +0 -134
- package/lib/commonjs/skia/types/WebGPU.d.ts +0 -184
- package/lib/commonjs/skia/types/WebGPU.js +0 -105
- package/lib/commonjs/skia/types/WebGPU.js.map +0 -1
- package/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -8
- package/lib/commonjs/specs/WebGPUViewNativeComponent.js +0 -10
- package/lib/commonjs/specs/WebGPUViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js +0 -103
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/specs/utils.d.ts +0 -1
- package/lib/commonjs/specs/utils.js +0 -11
- package/lib/commonjs/specs/utils.js.map +0 -1
- package/lib/commonjs/views/WebGPUCanvas.d.ts +0 -33
- package/lib/commonjs/views/WebGPUCanvas.js +0 -79
- package/lib/commonjs/views/WebGPUCanvas.js.map +0 -1
- package/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -23
- package/lib/commonjs/views/WebGPUCanvas.web.js +0 -20
- package/lib/commonjs/views/WebGPUCanvas.web.js.map +0 -1
- package/lib/module/skia/types/WebGPU.d.ts +0 -184
- package/lib/module/skia/types/WebGPU.js +0 -99
- package/lib/module/skia/types/WebGPU.js.map +0 -1
- package/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -8
- package/lib/module/specs/WebGPUViewNativeComponent.js +0 -4
- package/lib/module/specs/WebGPUViewNativeComponent.js.map +0 -1
- package/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
- package/lib/module/specs/WebGPUViewNativeComponent.web.js +0 -96
- package/lib/module/specs/WebGPUViewNativeComponent.web.js.map +0 -1
- package/lib/module/specs/utils.d.ts +0 -1
- package/lib/module/specs/utils.js +0 -5
- package/lib/module/specs/utils.js.map +0 -1
- package/lib/module/views/WebGPUCanvas.d.ts +0 -33
- package/lib/module/views/WebGPUCanvas.js +0 -70
- package/lib/module/views/WebGPUCanvas.js.map +0 -1
- package/lib/module/views/WebGPUCanvas.web.d.ts +0 -23
- package/lib/module/views/WebGPUCanvas.web.js +0 -12
- package/lib/module/views/WebGPUCanvas.web.js.map +0 -1
- package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +0 -2
- package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -4
- package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -3
- package/lib/typescript/lib/commonjs/specs/utils.d.ts +0 -2
- package/lib/typescript/lib/commonjs/views/WebGPUCanvas.d.ts +0 -6
- package/lib/typescript/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -6
- package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +0 -31
- package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -2
- package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -2
- package/lib/typescript/lib/module/specs/utils.d.ts +0 -1
- package/lib/typescript/lib/module/views/WebGPUCanvas.d.ts +0 -7
- package/lib/typescript/lib/module/views/WebGPUCanvas.web.d.ts +0 -8
- package/lib/typescript/src/skia/types/WebGPU.d.ts +0 -184
- package/lib/typescript/src/specs/WebGPUViewNativeComponent.d.ts +0 -8
- package/lib/typescript/src/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
- package/lib/typescript/src/specs/utils.d.ts +0 -1
- package/lib/typescript/src/views/WebGPUCanvas.d.ts +0 -33
- package/lib/typescript/src/views/WebGPUCanvas.web.d.ts +0 -23
- package/src/skia/types/WebGPU.ts +0 -226
- package/src/specs/WebGPUViewNativeComponent.ts +0 -11
- package/src/specs/WebGPUViewNativeComponent.web.ts +0 -110
- package/src/specs/utils.ts +0 -4
- package/src/views/WebGPUCanvas.tsx +0 -125
- package/src/views/WebGPUCanvas.web.tsx +0 -36
|
@@ -1,613 +0,0 @@
|
|
|
1
|
-
#include "GPUDevice.h"
|
|
2
|
-
|
|
3
|
-
#include <memory>
|
|
4
|
-
#include <string>
|
|
5
|
-
#include <unordered_set>
|
|
6
|
-
#include <utility>
|
|
7
|
-
#include <vector>
|
|
8
|
-
|
|
9
|
-
#include <ReactCommon/CallInvoker.h>
|
|
10
|
-
|
|
11
|
-
#include "Convertors.h"
|
|
12
|
-
#include "NativeBufferUtils.h"
|
|
13
|
-
#include "jsi/JSIConverter.h"
|
|
14
|
-
|
|
15
|
-
#include "GPUFeatures.h"
|
|
16
|
-
#include "GPUInternalError.h"
|
|
17
|
-
#include "GPUOutOfMemoryError.h"
|
|
18
|
-
#include "GPUValidationError.h"
|
|
19
|
-
|
|
20
|
-
namespace rnwgpu {
|
|
21
|
-
|
|
22
|
-
void GPUDevice::notifyDeviceLost(wgpu::DeviceLostReason reason,
|
|
23
|
-
std::string message) {
|
|
24
|
-
std::optional<async::AsyncTaskHandle::ResolveFunction> resolveToCall;
|
|
25
|
-
std::shared_ptr<GPUDeviceLostInfo> info;
|
|
26
|
-
{
|
|
27
|
-
std::lock_guard<std::mutex> lock(_lostMutex);
|
|
28
|
-
if (_lostSettled) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
_lostSettled = true;
|
|
33
|
-
_lostInfo = std::make_shared<GPUDeviceLostInfo>(reason, std::move(message));
|
|
34
|
-
info = _lostInfo;
|
|
35
|
-
|
|
36
|
-
if (_lostResolve.has_value()) {
|
|
37
|
-
resolveToCall = std::move(*_lostResolve);
|
|
38
|
-
_lostResolve.reset();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
_lostHandle.reset();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Settle outside the lock: resolve() only enqueues onto the JS thread.
|
|
45
|
-
if (resolveToCall.has_value()) {
|
|
46
|
-
(*resolveToCall)([info](jsi::Runtime &runtime) mutable {
|
|
47
|
-
return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(runtime,
|
|
48
|
-
info);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
void GPUDevice::forceLossForTesting() {
|
|
54
|
-
// wgpu::StringView view("forceLossForTesting invoked from JS");
|
|
55
|
-
_instance.ForceLoss(wgpu::DeviceLostReason::Unknown,
|
|
56
|
-
"forceLossForTesting invoked from JS");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
std::shared_ptr<GPUBuffer>
|
|
60
|
-
GPUDevice::createBuffer(std::shared_ptr<GPUBufferDescriptor> descriptor) {
|
|
61
|
-
wgpu::BufferDescriptor desc;
|
|
62
|
-
Convertor conv;
|
|
63
|
-
if (!conv(desc, descriptor)) {
|
|
64
|
-
throw std::runtime_error(
|
|
65
|
-
"GPUDevice::createBuffer(): Error with GPUBufferDescriptor");
|
|
66
|
-
}
|
|
67
|
-
auto result = _instance.CreateBuffer(&desc);
|
|
68
|
-
return std::make_shared<GPUBuffer>(result, _async,
|
|
69
|
-
descriptor->label.value_or(""));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
std::shared_ptr<GPUSupportedLimits> GPUDevice::getLimits() {
|
|
73
|
-
wgpu::Limits limits{};
|
|
74
|
-
if (!_instance.GetLimits(&limits)) {
|
|
75
|
-
throw std::runtime_error("failed to get device limits");
|
|
76
|
-
}
|
|
77
|
-
return std::make_shared<GPUSupportedLimits>(limits);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
std::shared_ptr<GPUQueue> GPUDevice::getQueue() {
|
|
81
|
-
auto result = _instance.GetQueue();
|
|
82
|
-
return std::make_shared<GPUQueue>(result, _async, _label);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
std::shared_ptr<GPUCommandEncoder> GPUDevice::createCommandEncoder(
|
|
86
|
-
std::optional<std::shared_ptr<GPUCommandEncoderDescriptor>> descriptor) {
|
|
87
|
-
wgpu::CommandEncoderDescriptor desc;
|
|
88
|
-
Convertor conv;
|
|
89
|
-
if (!conv(desc, descriptor)) {
|
|
90
|
-
throw std::runtime_error("Error with GPUCommandEncoderDescriptor");
|
|
91
|
-
}
|
|
92
|
-
auto result = _instance.CreateCommandEncoder(&desc);
|
|
93
|
-
return std::make_shared<GPUCommandEncoder>(
|
|
94
|
-
result,
|
|
95
|
-
descriptor.has_value() ? descriptor.value()->label.value_or("") : "");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
void GPUDevice::destroy() {
|
|
99
|
-
_instance.Destroy();
|
|
100
|
-
notifyDeviceLost(wgpu::DeviceLostReason::Destroyed, "device was destroyed");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
std::shared_ptr<GPUTexture>
|
|
104
|
-
GPUDevice::createTexture(std::shared_ptr<GPUTextureDescriptor> descriptor) {
|
|
105
|
-
wgpu::TextureDescriptor desc;
|
|
106
|
-
Convertor conv;
|
|
107
|
-
if (!conv(desc, descriptor)) {
|
|
108
|
-
throw std::runtime_error("Error with GPUTextureDescriptor");
|
|
109
|
-
}
|
|
110
|
-
auto texture = _instance.CreateTexture(&desc);
|
|
111
|
-
return std::make_shared<GPUTexture>(texture, descriptor->label.value_or(""));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
std::shared_ptr<GPUShaderModule> GPUDevice::createShaderModule(
|
|
115
|
-
std::shared_ptr<GPUShaderModuleDescriptor> descriptor) {
|
|
116
|
-
wgpu::ShaderSourceWGSL wgsl_desc{};
|
|
117
|
-
wgpu::ShaderModuleDescriptor sm_desc{};
|
|
118
|
-
Convertor conv;
|
|
119
|
-
if (!conv(wgsl_desc.code, descriptor->code) ||
|
|
120
|
-
!conv(sm_desc.label, descriptor->label)) {
|
|
121
|
-
return {};
|
|
122
|
-
}
|
|
123
|
-
sm_desc.nextInChain = &wgsl_desc;
|
|
124
|
-
if (descriptor->code.find('\0') != std::string::npos) {
|
|
125
|
-
auto mod = _instance.CreateErrorShaderModule(
|
|
126
|
-
&sm_desc, "The WGSL shader contains an illegal character '\\0'");
|
|
127
|
-
return std::make_shared<GPUShaderModule>(mod, _async, sm_desc.label.data);
|
|
128
|
-
}
|
|
129
|
-
auto module = _instance.CreateShaderModule(&sm_desc);
|
|
130
|
-
return std::make_shared<GPUShaderModule>(module, _async,
|
|
131
|
-
descriptor->label.value_or(""));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
std::shared_ptr<GPURenderPipeline> GPUDevice::createRenderPipeline(
|
|
135
|
-
std::shared_ptr<GPURenderPipelineDescriptor> descriptor) {
|
|
136
|
-
wgpu::RenderPipelineDescriptor desc{};
|
|
137
|
-
Convertor conv;
|
|
138
|
-
if (!conv(desc, descriptor)) {
|
|
139
|
-
throw std::runtime_error("Error with GPURenderPipelineDescriptor");
|
|
140
|
-
}
|
|
141
|
-
// assert(desc.fragment != nullptr && "Fragment state must not be null");
|
|
142
|
-
auto renderPipeline = _instance.CreateRenderPipeline(&desc);
|
|
143
|
-
return std::make_shared<GPURenderPipeline>(renderPipeline,
|
|
144
|
-
descriptor->label.value_or(""));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
std::shared_ptr<GPUBindGroup>
|
|
148
|
-
GPUDevice::createBindGroup(std::shared_ptr<GPUBindGroupDescriptor> descriptor) {
|
|
149
|
-
Convertor conv;
|
|
150
|
-
wgpu::BindGroupDescriptor desc{};
|
|
151
|
-
if (!conv(desc.label, descriptor->label) ||
|
|
152
|
-
!conv(desc.layout, descriptor->layout) ||
|
|
153
|
-
!conv(desc.entries, desc.entryCount, descriptor->entries)) {
|
|
154
|
-
throw std::runtime_error(
|
|
155
|
-
"GPUBindGroup::createBindGroup(): Error with GPUBindGroupDescriptor");
|
|
156
|
-
}
|
|
157
|
-
auto bindGroup = _instance.CreateBindGroup(&desc);
|
|
158
|
-
return std::make_shared<GPUBindGroup>(bindGroup,
|
|
159
|
-
descriptor->label.value_or(""));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
std::shared_ptr<GPUSampler> GPUDevice::createSampler(
|
|
163
|
-
std::optional<std::shared_ptr<GPUSamplerDescriptor>> descriptor) {
|
|
164
|
-
wgpu::SamplerDescriptor desc;
|
|
165
|
-
Convertor conv;
|
|
166
|
-
if (!conv(desc, descriptor)) {
|
|
167
|
-
throw std::runtime_error("GPUDevice::createSampler(): Error with "
|
|
168
|
-
"GPUSamplerDescriptor");
|
|
169
|
-
}
|
|
170
|
-
auto sampler = _instance.CreateSampler(&desc);
|
|
171
|
-
return std::make_shared<GPUSampler>(
|
|
172
|
-
sampler,
|
|
173
|
-
descriptor.has_value() ? descriptor.value()->label.value_or("") : "");
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
std::shared_ptr<GPUComputePipeline> GPUDevice::createComputePipeline(
|
|
177
|
-
std::shared_ptr<GPUComputePipelineDescriptor> descriptor) {
|
|
178
|
-
wgpu::ComputePipelineDescriptor desc;
|
|
179
|
-
Convertor conv;
|
|
180
|
-
if (!conv(desc, descriptor)) {
|
|
181
|
-
throw std::runtime_error("GPUDevice::createComputePipeline(): Error with "
|
|
182
|
-
"GPUComputePipelineDescriptor");
|
|
183
|
-
}
|
|
184
|
-
auto computePipeline = _instance.CreateComputePipeline(&desc);
|
|
185
|
-
return std::make_shared<GPUComputePipeline>(computePipeline,
|
|
186
|
-
descriptor->label.value_or(""));
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
std::shared_ptr<GPUQuerySet>
|
|
190
|
-
GPUDevice::createQuerySet(std::shared_ptr<GPUQuerySetDescriptor> descriptor) {
|
|
191
|
-
wgpu::QuerySetDescriptor desc;
|
|
192
|
-
Convertor conv;
|
|
193
|
-
if (!conv(desc, descriptor)) {
|
|
194
|
-
throw std::runtime_error("GPUDevice::createQuerySet(): Error with "
|
|
195
|
-
"GPUQuerySetDescriptor");
|
|
196
|
-
}
|
|
197
|
-
auto querySet = _instance.CreateQuerySet(&desc);
|
|
198
|
-
return std::make_shared<GPUQuerySet>(querySet,
|
|
199
|
-
descriptor->label.value_or(""));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
std::shared_ptr<GPURenderBundleEncoder> GPUDevice::createRenderBundleEncoder(
|
|
203
|
-
std::shared_ptr<GPURenderBundleEncoderDescriptor> descriptor) {
|
|
204
|
-
Convertor conv;
|
|
205
|
-
|
|
206
|
-
wgpu::RenderBundleEncoderDescriptor desc{};
|
|
207
|
-
if (!conv(desc.label, descriptor->label) ||
|
|
208
|
-
!conv(desc.colorFormats, desc.colorFormatCount,
|
|
209
|
-
descriptor->colorFormats) ||
|
|
210
|
-
!conv(desc.depthStencilFormat, descriptor->depthStencilFormat) ||
|
|
211
|
-
!conv(desc.sampleCount, descriptor->sampleCount) ||
|
|
212
|
-
!conv(desc.depthReadOnly, descriptor->depthReadOnly) ||
|
|
213
|
-
!conv(desc.stencilReadOnly, descriptor->stencilReadOnly)) {
|
|
214
|
-
return {};
|
|
215
|
-
}
|
|
216
|
-
return std::make_shared<GPURenderBundleEncoder>(
|
|
217
|
-
_instance.CreateRenderBundleEncoder(&desc),
|
|
218
|
-
descriptor->label.value_or(""));
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
std::shared_ptr<GPUBindGroupLayout> GPUDevice::createBindGroupLayout(
|
|
222
|
-
std::shared_ptr<GPUBindGroupLayoutDescriptor> descriptor) {
|
|
223
|
-
Convertor conv;
|
|
224
|
-
|
|
225
|
-
wgpu::BindGroupLayoutDescriptor desc{};
|
|
226
|
-
if (!conv(desc.label, descriptor->label) ||
|
|
227
|
-
!conv(desc.entries, desc.entryCount, descriptor->entries)) {
|
|
228
|
-
return {};
|
|
229
|
-
}
|
|
230
|
-
return std::make_shared<GPUBindGroupLayout>(
|
|
231
|
-
_instance.CreateBindGroupLayout(&desc), descriptor->label.value_or(""));
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
std::shared_ptr<GPUPipelineLayout> GPUDevice::createPipelineLayout(
|
|
235
|
-
std::shared_ptr<GPUPipelineLayoutDescriptor> descriptor) {
|
|
236
|
-
Convertor conv;
|
|
237
|
-
|
|
238
|
-
wgpu::PipelineLayoutDescriptor desc{};
|
|
239
|
-
if (!conv(desc.label, descriptor->label) ||
|
|
240
|
-
!conv(desc.bindGroupLayouts, desc.bindGroupLayoutCount,
|
|
241
|
-
descriptor->bindGroupLayouts)) {
|
|
242
|
-
return {};
|
|
243
|
-
}
|
|
244
|
-
return std::make_shared<GPUPipelineLayout>(
|
|
245
|
-
_instance.CreatePipelineLayout(&desc), descriptor->label.value_or(""));
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
std::shared_ptr<GPUExternalTexture> GPUDevice::importExternalTexture(
|
|
249
|
-
std::shared_ptr<GPUExternalTextureDescriptor> descriptor) {
|
|
250
|
-
// The import / begin-access / descriptor-build logic, plus the matching
|
|
251
|
-
// EndAccess, all live on GPUExternalTexture so the begin/end lifecycle stays
|
|
252
|
-
// in one translation unit (see GPUExternalTexture.cpp).
|
|
253
|
-
return GPUExternalTexture::Create(_instance, std::move(descriptor));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
std::shared_ptr<GPUSharedTextureMemory> GPUDevice::importSharedTextureMemory(
|
|
257
|
-
std::shared_ptr<GPUSharedTextureMemoryDescriptor> descriptor) {
|
|
258
|
-
if (!descriptor || descriptor->handle == 0) {
|
|
259
|
-
throw std::runtime_error(
|
|
260
|
-
"GPUDevice::importSharedTextureMemory(): handle must be a non-null "
|
|
261
|
-
"native buffer pointer (from Skia.NativeBuffer.MakeFromImage)");
|
|
262
|
-
}
|
|
263
|
-
void *bufferPtr =
|
|
264
|
-
reinterpret_cast<void *>(static_cast<uintptr_t>(descriptor->handle));
|
|
265
|
-
std::string label = descriptor->label.value_or("");
|
|
266
|
-
|
|
267
|
-
auto memory = importNativeBufferAsSharedTextureMemory(
|
|
268
|
-
_instance, bufferPtr, label, /*outWidth=*/nullptr, /*outHeight=*/nullptr);
|
|
269
|
-
if (memory == nullptr) {
|
|
270
|
-
throw std::runtime_error(
|
|
271
|
-
"GPUDevice::importSharedTextureMemory(): ImportSharedTextureMemory "
|
|
272
|
-
"returned null - is the 'shared-texture-memory-iosurface' (Apple) or "
|
|
273
|
-
"'shared-texture-memory-ahardware-buffer' (Android) feature enabled on "
|
|
274
|
-
"the device?");
|
|
275
|
-
}
|
|
276
|
-
return std::make_shared<GPUSharedTextureMemory>(std::move(memory),
|
|
277
|
-
std::move(label));
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
std::shared_ptr<GPUSharedFence> GPUDevice::importSharedFence(
|
|
281
|
-
std::shared_ptr<GPUSharedFenceDescriptor> descriptor) {
|
|
282
|
-
if (!descriptor || descriptor->handle == nullptr) {
|
|
283
|
-
throw std::runtime_error("GPUDevice::importSharedFence(): handle must be a "
|
|
284
|
-
"non-null native handle");
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
wgpu::SharedFenceDescriptor desc{};
|
|
288
|
-
std::string label = descriptor->label.value_or("");
|
|
289
|
-
if (!label.empty()) {
|
|
290
|
-
desc.label = wgpu::StringView(label.c_str(), label.size());
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// The chained platform descriptor must outlive the synchronous
|
|
294
|
-
// ImportSharedFence() below; declare them all and chain the matching one.
|
|
295
|
-
wgpu::SharedFenceMTLSharedEventDescriptor mtlDesc{};
|
|
296
|
-
wgpu::SharedFenceSyncFDDescriptor syncFdDesc{};
|
|
297
|
-
wgpu::SharedFenceVkSemaphoreOpaqueFDDescriptor vkFdDesc{};
|
|
298
|
-
|
|
299
|
-
const std::string &type = descriptor->type;
|
|
300
|
-
if (type == "mtl-shared-event") {
|
|
301
|
-
// handle is an id<MTLSharedEvent> pointer.
|
|
302
|
-
mtlDesc.sharedEvent = descriptor->handle;
|
|
303
|
-
desc.nextInChain = &mtlDesc;
|
|
304
|
-
} else if (type == "sync-fd") {
|
|
305
|
-
// handle is an OS file descriptor.
|
|
306
|
-
syncFdDesc.handle =
|
|
307
|
-
static_cast<int>(reinterpret_cast<uintptr_t>(descriptor->handle));
|
|
308
|
-
desc.nextInChain = &syncFdDesc;
|
|
309
|
-
} else if (type == "vk-semaphore-opaque-fd") {
|
|
310
|
-
vkFdDesc.handle =
|
|
311
|
-
static_cast<int>(reinterpret_cast<uintptr_t>(descriptor->handle));
|
|
312
|
-
desc.nextInChain = &vkFdDesc;
|
|
313
|
-
} else {
|
|
314
|
-
throw std::runtime_error(
|
|
315
|
-
"GPUDevice::importSharedFence(): unsupported fence type '" + type +
|
|
316
|
-
"' (expected 'mtl-shared-event', 'sync-fd' or "
|
|
317
|
-
"'vk-semaphore-opaque-fd')");
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
auto fence = _instance.ImportSharedFence(&desc);
|
|
321
|
-
if (fence == nullptr) {
|
|
322
|
-
throw std::runtime_error(
|
|
323
|
-
"GPUDevice::importSharedFence(): ImportSharedFence returned null - is "
|
|
324
|
-
"the matching 'shared-fence-*' feature enabled on the device?");
|
|
325
|
-
}
|
|
326
|
-
return std::make_shared<GPUSharedFence>(std::move(fence), std::move(label));
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
|
|
330
|
-
jsi::Runtime &runtime,
|
|
331
|
-
std::shared_ptr<GPUComputePipelineDescriptor> descriptor) {
|
|
332
|
-
wgpu::ComputePipelineDescriptor desc{};
|
|
333
|
-
Convertor conv;
|
|
334
|
-
if (!conv(desc, descriptor)) {
|
|
335
|
-
throw std::runtime_error("GPUDevice::createComputePipeline(): Error with "
|
|
336
|
-
"GPUComputePipelineDescriptor");
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
auto label = std::string(
|
|
340
|
-
descriptor->label.has_value() ? descriptor->label.value() : "");
|
|
341
|
-
auto pipelineHolder = std::make_shared<GPUComputePipeline>(nullptr, label);
|
|
342
|
-
|
|
343
|
-
// Post to the CALLING runtime's context so the promise settles on the
|
|
344
|
-
// thread that requested it (see GPUBuffer::mapAsync).
|
|
345
|
-
auto context =
|
|
346
|
-
async::RuntimeContext::getOrCreate(runtime, _async->instance());
|
|
347
|
-
return context->postTask([device = _instance, desc, descriptor,
|
|
348
|
-
pipelineHolder](
|
|
349
|
-
const async::AsyncTaskHandle::ResolveFunction
|
|
350
|
-
&resolve,
|
|
351
|
-
const async::AsyncTaskHandle::RejectFunction
|
|
352
|
-
&reject) {
|
|
353
|
-
(void)descriptor;
|
|
354
|
-
device.CreateComputePipelineAsync(
|
|
355
|
-
&desc, wgpu::CallbackMode::AllowProcessEvents,
|
|
356
|
-
[pipelineHolder, resolve,
|
|
357
|
-
reject](wgpu::CreatePipelineAsyncStatus status,
|
|
358
|
-
wgpu::ComputePipeline pipeline, wgpu::StringView msg) {
|
|
359
|
-
if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
|
|
360
|
-
pipelineHolder->_instance = pipeline;
|
|
361
|
-
resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
|
|
362
|
-
return JSIConverter<std::shared_ptr<GPUComputePipeline>>::toJSI(
|
|
363
|
-
runtime, pipelineHolder);
|
|
364
|
-
});
|
|
365
|
-
} else {
|
|
366
|
-
std::string error = msg.length
|
|
367
|
-
? std::string(msg.data, msg.length)
|
|
368
|
-
: "Failed to create compute pipeline";
|
|
369
|
-
reject(std::move(error));
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
|
|
376
|
-
jsi::Runtime &runtime,
|
|
377
|
-
std::shared_ptr<GPURenderPipelineDescriptor> descriptor) {
|
|
378
|
-
wgpu::RenderPipelineDescriptor desc{};
|
|
379
|
-
Convertor conv;
|
|
380
|
-
if (!conv(desc, descriptor)) {
|
|
381
|
-
throw std::runtime_error(
|
|
382
|
-
"GPUDevice::createRenderPipelineAsync(): Error with "
|
|
383
|
-
"GPURenderPipelineDescriptor");
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
auto label = std::string(
|
|
387
|
-
descriptor->label.has_value() ? descriptor->label.value() : "");
|
|
388
|
-
auto pipelineHolder = std::make_shared<GPURenderPipeline>(nullptr, label);
|
|
389
|
-
|
|
390
|
-
// Post to the CALLING runtime's context so the promise settles on the
|
|
391
|
-
// thread that requested it (see GPUBuffer::mapAsync).
|
|
392
|
-
auto context =
|
|
393
|
-
async::RuntimeContext::getOrCreate(runtime, _async->instance());
|
|
394
|
-
return context->postTask([device = _instance, desc, descriptor,
|
|
395
|
-
pipelineHolder](
|
|
396
|
-
const async::AsyncTaskHandle::ResolveFunction
|
|
397
|
-
&resolve,
|
|
398
|
-
const async::AsyncTaskHandle::RejectFunction
|
|
399
|
-
&reject) {
|
|
400
|
-
(void)descriptor;
|
|
401
|
-
device.CreateRenderPipelineAsync(
|
|
402
|
-
&desc, wgpu::CallbackMode::AllowProcessEvents,
|
|
403
|
-
[pipelineHolder, resolve,
|
|
404
|
-
reject](wgpu::CreatePipelineAsyncStatus status,
|
|
405
|
-
wgpu::RenderPipeline pipeline, wgpu::StringView msg) {
|
|
406
|
-
if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
|
|
407
|
-
pipelineHolder->_instance = pipeline;
|
|
408
|
-
resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
|
|
409
|
-
return JSIConverter<std::shared_ptr<GPURenderPipeline>>::toJSI(
|
|
410
|
-
runtime, pipelineHolder);
|
|
411
|
-
});
|
|
412
|
-
} else {
|
|
413
|
-
std::string error = msg.length ? std::string(msg.data, msg.length)
|
|
414
|
-
: "Failed to create render pipeline";
|
|
415
|
-
reject(std::move(error));
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
void GPUDevice::pushErrorScope(wgpu::ErrorFilter filter) {
|
|
422
|
-
_instance.PushErrorScope(filter);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
async::AsyncTaskHandle GPUDevice::popErrorScope(jsi::Runtime &runtime) {
|
|
426
|
-
auto device = _instance;
|
|
427
|
-
|
|
428
|
-
// Post to the CALLING runtime's context so the promise settles on the
|
|
429
|
-
// thread that requested it (see GPUBuffer::mapAsync).
|
|
430
|
-
auto context =
|
|
431
|
-
async::RuntimeContext::getOrCreate(runtime, _async->instance());
|
|
432
|
-
return context->postTask([device](
|
|
433
|
-
const async::AsyncTaskHandle::ResolveFunction
|
|
434
|
-
&resolve,
|
|
435
|
-
const async::AsyncTaskHandle::RejectFunction
|
|
436
|
-
&reject) {
|
|
437
|
-
device.PopErrorScope(
|
|
438
|
-
wgpu::CallbackMode::AllowProcessEvents,
|
|
439
|
-
[resolve, reject](wgpu::PopErrorScopeStatus status,
|
|
440
|
-
wgpu::ErrorType type, wgpu::StringView message) {
|
|
441
|
-
if (status == wgpu::PopErrorScopeStatus::Error ||
|
|
442
|
-
status == wgpu::PopErrorScopeStatus::CallbackCancelled) {
|
|
443
|
-
reject("PopErrorScope failed");
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
std::string messageString =
|
|
448
|
-
message.length ? std::string(message.data, message.length) : "";
|
|
449
|
-
|
|
450
|
-
switch (type) {
|
|
451
|
-
case wgpu::ErrorType::NoError:
|
|
452
|
-
resolve([](jsi::Runtime &runtime) mutable {
|
|
453
|
-
return jsi::Value::null();
|
|
454
|
-
});
|
|
455
|
-
break;
|
|
456
|
-
case wgpu::ErrorType::Validation: {
|
|
457
|
-
auto error = std::make_shared<GPUValidationError>(messageString);
|
|
458
|
-
resolve([error](jsi::Runtime &runtime) mutable {
|
|
459
|
-
return JSIConverter<std::shared_ptr<GPUValidationError>>::toJSI(
|
|
460
|
-
runtime, error);
|
|
461
|
-
});
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
case wgpu::ErrorType::OutOfMemory: {
|
|
465
|
-
auto error = std::make_shared<GPUOutOfMemoryError>(messageString);
|
|
466
|
-
resolve([error](jsi::Runtime &runtime) mutable {
|
|
467
|
-
return JSIConverter<std::shared_ptr<GPUOutOfMemoryError>>::toJSI(
|
|
468
|
-
runtime, error);
|
|
469
|
-
});
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
case wgpu::ErrorType::Internal:
|
|
473
|
-
case wgpu::ErrorType::Unknown: {
|
|
474
|
-
auto error = std::make_shared<GPUInternalError>(messageString);
|
|
475
|
-
resolve([error](jsi::Runtime &runtime) mutable {
|
|
476
|
-
return JSIConverter<std::shared_ptr<GPUInternalError>>::toJSI(
|
|
477
|
-
runtime, error);
|
|
478
|
-
});
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
default:
|
|
482
|
-
reject("Unhandled GPU error type");
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
std::unordered_set<std::string> GPUDevice::getFeatures() {
|
|
490
|
-
wgpu::SupportedFeatures supportedFeatures;
|
|
491
|
-
_instance.GetFeatures(&supportedFeatures);
|
|
492
|
-
std::unordered_set<std::string> result;
|
|
493
|
-
for (size_t i = 0; i < supportedFeatures.featureCount; ++i) {
|
|
494
|
-
auto feature = supportedFeatures.features[i];
|
|
495
|
-
std::string name;
|
|
496
|
-
convertEnumToJSUnion(feature, &name);
|
|
497
|
-
result.insert(name);
|
|
498
|
-
}
|
|
499
|
-
return result;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
async::AsyncTaskHandle GPUDevice::getLost() {
|
|
503
|
-
// Held across the whole body: the postTask callback below runs synchronously
|
|
504
|
-
// on this (JS) thread and touches the same _lost* fields, so it must not
|
|
505
|
-
// re-lock. notifyDeviceLost() takes the same lock from its (possibly worker)
|
|
506
|
-
// thread.
|
|
507
|
-
std::lock_guard<std::mutex> lock(_lostMutex);
|
|
508
|
-
if (_lostHandle.has_value()) {
|
|
509
|
-
return *_lostHandle;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
if (_lostSettled && _lostInfo) {
|
|
513
|
-
return _async->postTask(
|
|
514
|
-
[info = _lostInfo](
|
|
515
|
-
const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
516
|
-
const async::AsyncTaskHandle::RejectFunction & /*reject*/) {
|
|
517
|
-
resolve([info](jsi::Runtime &runtime) mutable {
|
|
518
|
-
return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(
|
|
519
|
-
runtime, info);
|
|
520
|
-
});
|
|
521
|
-
},
|
|
522
|
-
/*keepPumping=*/false);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
auto handle = _async->postTask(
|
|
526
|
-
[this](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
527
|
-
const async::AsyncTaskHandle::RejectFunction & /*reject*/) {
|
|
528
|
-
if (_lostSettled && _lostInfo) {
|
|
529
|
-
resolve([info = _lostInfo](jsi::Runtime &runtime) mutable {
|
|
530
|
-
return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(
|
|
531
|
-
runtime, info);
|
|
532
|
-
});
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
// Resolved later from notifyDeviceLost().
|
|
537
|
-
_lostResolve = resolve;
|
|
538
|
-
},
|
|
539
|
-
/*keepPumping=*/false);
|
|
540
|
-
|
|
541
|
-
_lostHandle = handle;
|
|
542
|
-
return handle;
|
|
543
|
-
}
|
|
544
|
-
void GPUDevice::addEventListener(std::string type, jsi::Function callback) {
|
|
545
|
-
std::lock_guard<std::mutex> lock(_listenersMutex);
|
|
546
|
-
auto sharedCallback = std::make_shared<jsi::Function>(std::move(callback));
|
|
547
|
-
_eventListeners[type].push_back(sharedCallback);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
void GPUDevice::removeEventListener(std::string type, jsi::Function callback) {
|
|
551
|
-
std::lock_guard<std::mutex> lock(_listenersMutex);
|
|
552
|
-
auto it = _eventListeners.find(type);
|
|
553
|
-
if (it != _eventListeners.end()) {
|
|
554
|
-
auto &listeners = it->second;
|
|
555
|
-
// Remove the last listener of this type (simple approach since we can't
|
|
556
|
-
// easily compare jsi::Function objects)
|
|
557
|
-
if (!listeners.empty()) {
|
|
558
|
-
listeners.pop_back();
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
void GPUDevice::notifyUncapturedError(GPUErrorVariant error) {
|
|
564
|
-
// Dawn can surface an uncaptured error from any ProcessEvents pump (a worklet
|
|
565
|
-
// runtime sharing this instance may pump it on the wrong thread). Marshal to
|
|
566
|
-
// the owning runtime's JS thread via its CallInvoker before touching JSI. The
|
|
567
|
-
// invoker is wired only for the main JS runtime, so a device created on a
|
|
568
|
-
// worklet runtime does not deliver uncaptured errors to JS (best-effort; see
|
|
569
|
-
// the Threading model).
|
|
570
|
-
auto invoker = _async ? _async->callInvoker() : nullptr;
|
|
571
|
-
if (!invoker) {
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
auto self = shared_from_this();
|
|
575
|
-
invoker->invokeAsync([self, error = std::move(error)]() mutable {
|
|
576
|
-
self->deliverUncapturedError(std::move(error));
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
void GPUDevice::deliverUncapturedError(GPUErrorVariant error) {
|
|
581
|
-
auto runtime = getCreationRuntime();
|
|
582
|
-
if (runtime == nullptr) {
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
std::vector<std::shared_ptr<jsi::Function>> listeners;
|
|
587
|
-
{
|
|
588
|
-
std::lock_guard<std::mutex> lock(_listenersMutex);
|
|
589
|
-
auto it = _eventListeners.find("uncapturederror");
|
|
590
|
-
if (it != _eventListeners.end()) {
|
|
591
|
-
listeners = it->second;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
if (listeners.empty()) {
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// Create the event object
|
|
600
|
-
auto event = std::make_shared<GPUUncapturedErrorEvent>(std::move(error));
|
|
601
|
-
auto eventValue = GPUUncapturedErrorEvent::create(*runtime, event);
|
|
602
|
-
|
|
603
|
-
// Call all listeners
|
|
604
|
-
for (const auto &listener : listeners) {
|
|
605
|
-
try {
|
|
606
|
-
listener->call(*runtime, eventValue);
|
|
607
|
-
} catch (const std::exception &e) {
|
|
608
|
-
fprintf(stderr, "Error in uncapturederror listener: %s\n", e.what());
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
} // namespace rnwgpu
|