@shopify/react-native-skia 2.6.5 → 2.6.7
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 +2 -2
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerDelegate.java +35 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerInterface.java +17 -0
- package/apple/RNSkiaModule.mm +8 -2
- package/apple/SkiaManager.mm +10 -5
- package/cpp/api/JsiSkApi.h +6 -6
- package/cpp/api/JsiSkCanvas.h +33 -0
- package/cpp/api/JsiSkImage.h +12 -4
- package/cpp/api/JsiSkMaskFilter.h +1 -0
- package/cpp/api/JsiSkSurface.h +5 -1
- package/cpp/jsi2/NativeObject.h +39 -0
- package/cpp/rnskia/RNSkManager.cpp +27 -11
- package/cpp/rnwgpu/SurfaceRegistry.h +33 -1
- package/cpp/rnwgpu/api/GPU.cpp +15 -15
- package/cpp/rnwgpu/api/GPU.h +6 -3
- package/cpp/rnwgpu/api/GPUAdapter.cpp +11 -7
- package/cpp/rnwgpu/api/GPUAdapter.h +3 -3
- package/cpp/rnwgpu/api/GPUBuffer.h +3 -3
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +13 -16
- package/cpp/rnwgpu/api/GPUCanvasContext.h +3 -0
- package/cpp/rnwgpu/api/GPUDevice.cpp +103 -17
- package/cpp/rnwgpu/api/GPUDevice.h +18 -3
- package/cpp/rnwgpu/api/GPUQueue.h +3 -3
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -1
- package/cpp/rnwgpu/api/GPUShaderModule.h +3 -3
- package/cpp/rnwgpu/api/GPUSharedFence.cpp +80 -0
- package/cpp/rnwgpu/api/GPUSharedFence.h +53 -0
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +64 -11
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +13 -8
- package/cpp/rnwgpu/api/WebGPUConstants.h +36 -0
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +51 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +55 -22
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +8 -5
- package/cpp/rnwgpu/async/RuntimeContext.cpp +194 -0
- package/cpp/rnwgpu/async/RuntimeContext.h +121 -0
- package/cpp/skia/include/android/GrAHardwareBufferUtils.h +1 -1
- package/cpp/skia/include/android/SkAndroidFrameworkUtils.h +1 -1
- package/cpp/skia/include/android/SkAnimatedImage.h +1 -1
- package/cpp/skia/include/codec/SkCodec.h +0 -8
- package/cpp/skia/include/codec/SkEncodedOrigin.h +1 -1
- package/cpp/skia/include/codec/SkPngRustDecoder.h +1 -1
- package/cpp/skia/include/core/SkBitmap.h +2 -8
- package/cpp/skia/include/core/SkCPURecorder.h +3 -1
- package/cpp/skia/include/core/SkCanvasVirtualEnforcer.h +1 -1
- package/cpp/skia/include/core/SkColorType.h +5 -3
- package/cpp/skia/include/core/SkContourMeasure.h +1 -1
- package/cpp/skia/include/core/SkCoverageMode.h +1 -1
- package/cpp/skia/include/core/SkCubicMap.h +1 -1
- package/cpp/skia/include/core/SkExecutor.h +1 -1
- package/cpp/skia/include/core/SkFont.h +15 -0
- package/cpp/skia/include/core/SkFontArguments.h +6 -1
- package/cpp/skia/include/core/SkFontMetrics.h +1 -1
- package/cpp/skia/include/core/SkFontMgr.h +36 -1
- package/cpp/skia/include/core/SkFontParameters.h +1 -1
- package/cpp/skia/include/core/SkFontScanner.h +1 -1
- package/cpp/skia/include/core/SkFontTypes.h +1 -1
- package/cpp/skia/include/core/SkM44.h +1 -1
- package/cpp/skia/include/core/SkMilestone.h +1 -1
- package/cpp/skia/include/core/SkOpenTypeSVGDecoder.h +1 -1
- package/cpp/skia/include/core/SkPathBuilder.h +10 -4
- package/cpp/skia/include/core/SkPathIter.h +1 -1
- package/cpp/skia/include/core/SkPathTypes.h +1 -1
- package/cpp/skia/include/core/SkPixelRef.h +4 -1
- package/cpp/skia/include/core/SkRecorder.h +2 -1
- package/cpp/skia/include/core/SkRegion.h +7 -1
- package/cpp/skia/include/core/SkSamplingOptions.h +1 -1
- package/cpp/skia/include/core/SkSerialProcs.h +8 -1
- package/cpp/skia/include/core/SkShader.h +3 -5
- package/cpp/skia/include/core/SkSpan.h +1 -1
- package/cpp/skia/include/core/SkStream.h +1 -1
- package/cpp/skia/include/core/SkStrikeRef.h +80 -0
- package/cpp/skia/include/core/SkTileMode.h +1 -1
- package/cpp/skia/include/core/SkVertices.h +1 -1
- package/cpp/skia/include/core/SkYUVAPixmaps.h +3 -5
- package/cpp/skia/include/docs/SkPDFDocument.h +1 -1
- package/cpp/skia/include/docs/SkXPSDocument.h +1 -1
- package/cpp/skia/include/effects/SkGradient.h +1 -1
- package/cpp/skia/include/effects/SkHighContrastFilter.h +1 -1
- package/cpp/skia/include/effects/SkShaderMaskFilter.h +1 -1
- package/cpp/skia/include/effects/SkTrimPathEffect.h +1 -1
- package/cpp/skia/include/encode/SkEncoder.h +1 -1
- package/cpp/skia/include/encode/SkJpegEncoder.h +1 -1
- package/cpp/skia/include/encode/SkPngEncoder.h +1 -1
- package/cpp/skia/include/encode/SkPngRustEncoder.h +1 -1
- package/cpp/skia/include/encode/SkWebpEncoder.h +1 -1
- package/cpp/skia/include/gpu/GpuTypes.h +2 -0
- package/cpp/skia/include/gpu/MutableTextureState.h +1 -1
- package/cpp/skia/include/gpu/ganesh/GrBackendSemaphore.h +1 -1
- package/cpp/skia/include/gpu/ganesh/GrBackendSurface.h +6 -62
- package/cpp/skia/include/gpu/ganesh/GrContextThreadSafeProxy.h +1 -1
- package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +1 -1
- package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkarounds.h +1 -1
- package/cpp/skia/include/gpu/ganesh/GrRecordingContext.h +2 -1
- package/cpp/skia/include/gpu/ganesh/mock/GrMockBackendSurface.h +59 -0
- package/cpp/skia/include/gpu/ganesh/mock/GrMockTypes.h +1 -1
- package/cpp/skia/include/gpu/ganesh/mtl/GrMtlBackendContext.h +1 -1
- package/cpp/skia/include/gpu/ganesh/mtl/GrMtlTypes.h +1 -1
- package/cpp/skia/include/gpu/ganesh/vk/GrBackendDrawableInfo.h +1 -1
- package/cpp/skia/include/gpu/graphite/Context.h +11 -4
- package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +6 -0
- package/cpp/skia/include/gpu/graphite/Image.h +82 -9
- package/cpp/skia/include/gpu/graphite/PrecompileContext.h +7 -2
- package/cpp/skia/include/gpu/graphite/Recorder.h +6 -4
- package/cpp/skia/include/gpu/graphite/precompile/PrecompileColorFilter.h +11 -1
- package/cpp/skia/include/gpu/graphite/precompile/PrecompileShader.h +1 -0
- package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +1 -1
- package/cpp/skia/include/gpu/mtl/MtlMemoryAllocator.h +1 -1
- package/cpp/skia/include/gpu/vk/VulkanExtensions.h +1 -1
- package/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +1 -1
- package/cpp/skia/include/gpu/vk/VulkanTypes.h +1 -1
- package/cpp/skia/include/ports/SkCFObject.h +1 -1
- package/cpp/skia/include/ports/SkFontMgr_Fontations.h +1 -1
- package/cpp/skia/include/ports/SkFontMgr_android_ndk.h +1 -1
- package/cpp/skia/include/ports/SkFontMgr_data.h +1 -1
- package/cpp/skia/include/ports/SkFontMgr_fuchsia.h +1 -1
- package/cpp/skia/include/ports/SkFontMgr_mac_ct.h +1 -1
- package/cpp/skia/include/ports/SkFontScanner_Fontations.h +1 -1
- package/cpp/skia/include/ports/SkFontScanner_FreeType.h +1 -1
- package/cpp/skia/include/ports/SkTypeface_fontations.h +1 -1
- package/cpp/skia/include/private/SkExif.h +1 -1
- package/cpp/skia/include/private/SkGainmapInfo.h +1 -1
- package/cpp/skia/include/private/SkGainmapShader.h +1 -1
- package/cpp/skia/include/private/SkHdrMetadata.h +21 -0
- package/cpp/skia/include/private/SkJpegGainmapEncoder.h +1 -1
- package/cpp/skia/include/private/SkPixelStorage.h +37 -0
- package/cpp/skia/include/private/SkXmp.h +1 -1
- package/cpp/skia/include/private/base/SkAssert.h +6 -5
- package/cpp/skia/include/private/base/SkContainers.h +1 -1
- package/cpp/skia/include/private/base/SkFeatures.h +30 -30
- package/cpp/skia/include/private/base/SkLog.h +1 -7
- package/cpp/skia/include/private/base/SkLogPriority.h +4 -5
- package/cpp/skia/include/private/base/SkMacros.h +1 -1
- package/cpp/skia/include/private/base/SkMalloc.h +1 -1
- package/cpp/skia/include/private/base/SkSafe32.h +1 -1
- package/cpp/skia/include/private/base/SkSpan_impl.h +1 -1
- package/cpp/skia/include/private/base/SkTDArray.h +13 -1
- package/cpp/skia/include/private/base/SkTPin.h +1 -1
- package/cpp/skia/include/private/base/SkTo.h +1 -1
- package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +1 -1
- package/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +1 -1
- package/cpp/skia/include/private/chromium/SkCodecsICCProfileChromium.h +52 -0
- package/cpp/skia/include/private/chromium/SkExifChromium.h +26 -0
- package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +1 -1
- package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +1 -1
- package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +2 -1
- package/cpp/skia/include/private/gpu/vk/SkiaVulkan.h +1 -1
- package/cpp/skia/include/sksl/SkSLDebugTrace.h +1 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_icd.h +41 -51
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_layer.h +42 -53
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_platform.h +2 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std.h +158 -154
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std_decode.h +68 -65
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std_encode.h +90 -87
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std.h +9 -9
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_decode.h +2 -2
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_encode.h +82 -79
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std.h +24 -24
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_decode.h +2 -2
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_encode.h +95 -96
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_vp9std.h +151 -0
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_vp9std_decode.h +68 -0
- package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codecs_common.h +1 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan.h +5 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_android.h +7 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_beta.h +291 -158
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_core.h +13174 -10113
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_directfb.h +23 -19
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_fuchsia.h +159 -165
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ggp.h +22 -19
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ios.h +3 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_macos.h +3 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_metal.h +94 -88
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ohos.h +120 -0
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_screen.h +55 -51
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_vi.h +18 -15
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_wayland.h +23 -19
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_win32.h +31 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xcb.h +5 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xlib.h +27 -27
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xlib_xrandr.h +20 -16
- package/cpp/skia/include/utils/SkEventTracer.h +6 -1
- package/cpp/skia/include/utils/SkOrderedFontMgr.h +1 -1
- package/cpp/skia/include/utils/SkShadowUtils.h +1 -1
- package/cpp/skia/include/utils/SkTextUtils.h +1 -1
- package/cpp/skia/modules/jsonreader/SkJSONReader.cpp +20 -4
- package/cpp/skia/modules/skcms/src/Transform_inl.h +11 -15
- package/cpp/skia/modules/skcms/src/skcms_public.h +2 -0
- package/cpp/skia/modules/skottie/include/ExternalLayer.h +1 -1
- package/cpp/skia/modules/skottie/include/Skottie.h +1 -1
- package/cpp/skia/modules/skottie/include/SkottieProperty.h +1 -1
- package/cpp/skia/modules/skottie/include/SlotManager.h +1 -1
- package/cpp/skia/modules/skottie/include/TextShaper.h +1 -1
- package/cpp/skia/modules/skottie/src/SkottieValue.h +1 -1
- package/cpp/skia/modules/skottie/src/animator/Animator.h +1 -1
- package/cpp/skia/modules/skottie/src/text/Font.h +1 -1
- package/cpp/skia/modules/skottie/src/text/TextAdapter.h +1 -1
- package/cpp/skia/modules/skottie/src/text/TextAnimator.h +3 -2
- package/cpp/skia/modules/skottie/src/text/TextValue.h +1 -1
- package/cpp/skia/modules/skparagraph/include/DartTypes.h +1 -1
- package/cpp/skia/modules/skparagraph/include/FontArguments.h +1 -1
- package/cpp/skia/modules/skparagraph/include/FontCollection.h +5 -1
- package/cpp/skia/modules/skparagraph/include/Metrics.h +1 -1
- package/cpp/skia/modules/skparagraph/include/Paragraph.h +1 -1
- package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +1 -1
- package/cpp/skia/modules/skparagraph/include/ParagraphCache.h +1 -1
- package/cpp/skia/modules/skparagraph/include/ParagraphPainter.h +1 -1
- package/cpp/skia/modules/skparagraph/include/ParagraphStyle.h +12 -5
- package/cpp/skia/modules/skparagraph/include/TextShadow.h +1 -1
- package/cpp/skia/modules/skparagraph/include/TextStyle.h +1 -1
- package/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGClipEffect.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGColorFilter.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGDraw.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGEffectNode.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGGeometryEffect.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGGeometryNode.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGGradient.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGGroup.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGImage.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGInvalidationController.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGMaskEffect.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGMerge.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGNode.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGOpacityEffect.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGPaint.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGPath.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGPlane.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGRect.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGRenderEffect.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGRenderNode.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGScene.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGText.h +1 -1
- package/cpp/skia/modules/sksg/include/SkSGTransform.h +1 -1
- package/cpp/skia/modules/skshaper/include/SkShaper_coretext.h +8 -1
- package/cpp/skia/modules/svg/include/SkSVGFe.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeBlend.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeColorMatrix.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeComponentTransfer.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeComposite.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeDisplacementMap.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeFlood.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeGaussianBlur.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeImage.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeLightSource.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeLighting.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeMerge.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeMorphology.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeOffset.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeTurbulence.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFilter.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFilterContext.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGGradient.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGImage.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGMask.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGOpenTypeSVGDecoder.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGPattern.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGRadialGradient.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGText.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGUse.h +1 -1
- package/cpp/skia/src/base/SkAutoLocaleSetter.h +94 -0
- package/cpp/skia/src/base/SkUTF.h +1 -1
- package/lib/commonjs/skia/types/WebGPU.d.ts +101 -5
- package/lib/commonjs/skia/types/WebGPU.js +99 -0
- package/lib/commonjs/skia/types/WebGPU.js.map +1 -1
- package/lib/module/skia/types/WebGPU.d.ts +101 -5
- package/lib/module/skia/types/WebGPU.js +98 -1
- package/lib/module/skia/types/WebGPU.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +1 -0
- package/lib/typescript/lib/module/mock/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +31 -1
- package/lib/typescript/src/skia/types/WebGPU.d.ts +101 -5
- package/package.json +5 -5
- package/src/skia/types/WebGPU.ts +123 -5
- package/cpp/rnwgpu/async/AsyncDispatcher.h +0 -28
- package/cpp/rnwgpu/async/AsyncRunner.cpp +0 -182
- package/cpp/rnwgpu/async/AsyncRunner.h +0 -57
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +0 -23
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +0 -22
|
@@ -2,14 +2,6 @@
|
|
|
2
2
|
#include "Convertors.h"
|
|
3
3
|
#include <memory>
|
|
4
4
|
|
|
5
|
-
#ifdef __APPLE__
|
|
6
|
-
namespace dawn::native::metal {
|
|
7
|
-
|
|
8
|
-
void WaitForCommandsToBeScheduled(WGPUDevice device);
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
#endif
|
|
12
|
-
|
|
13
5
|
namespace rnwgpu {
|
|
14
6
|
|
|
15
7
|
void GPUCanvasContext::configure(
|
|
@@ -46,19 +38,24 @@ std::shared_ptr<GPUTexture> GPUCanvasContext::getCurrentTexture() {
|
|
|
46
38
|
if (sizeHasChanged) {
|
|
47
39
|
_surfaceInfo->reconfigure(width, height);
|
|
48
40
|
}
|
|
41
|
+
|
|
49
42
|
auto texture = _surfaceInfo->getCurrentTexture();
|
|
50
|
-
return std::make_shared<GPUTexture>(texture, "", false);
|
|
51
|
-
}
|
|
52
43
|
|
|
53
|
-
void GPUCanvasContext::present() {
|
|
54
|
-
#ifdef __APPLE__
|
|
55
|
-
dawn::native::metal::WaitForCommandsToBeScheduled(
|
|
56
|
-
_surfaceInfo->getDevice().Get());
|
|
57
|
-
#endif
|
|
58
44
|
auto size = _surfaceInfo->getSize();
|
|
59
45
|
_canvas->setClientWidth(size.width);
|
|
60
46
|
_canvas->setClientHeight(size.height);
|
|
61
|
-
|
|
47
|
+
|
|
48
|
+
return std::make_shared<GPUTexture>(texture, "", false);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
void GPUCanvasContext::present() {
|
|
52
|
+
// Present runs synchronously on the calling thread (the one that did
|
|
53
|
+
// getCurrentTexture / submit), preserving Dawn surface thread-affinity.
|
|
54
|
+
// Required on every runtime (main JS, Reanimated UI, dedicated worklet);
|
|
55
|
+
// offscreen surfaces have no wgpu::Surface so they no-op.
|
|
56
|
+
if (_surfaceInfo->hasSurface()) {
|
|
57
|
+
_surfaceInfo->presentFrame();
|
|
58
|
+
}
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
} // namespace rnwgpu
|
|
@@ -54,6 +54,9 @@ public:
|
|
|
54
54
|
void configure(std::shared_ptr<GPUCanvasConfiguration> configuration);
|
|
55
55
|
void unconfigure();
|
|
56
56
|
std::shared_ptr<GPUTexture> getCurrentTexture();
|
|
57
|
+
// Present is explicit on every runtime (main JS, Reanimated UI, and dedicated
|
|
58
|
+
// worklet runtimes). It runs synchronously on the calling thread, preserving
|
|
59
|
+
// Dawn surface thread-affinity; offscreen surfaces no-op.
|
|
57
60
|
void present();
|
|
58
61
|
|
|
59
62
|
private:
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
#include <utility>
|
|
7
7
|
#include <vector>
|
|
8
8
|
|
|
9
|
+
#include <ReactCommon/CallInvoker.h>
|
|
10
|
+
|
|
9
11
|
#include "Convertors.h"
|
|
10
12
|
#include "NativeBufferUtils.h"
|
|
11
13
|
#include "jsi2/JSIConverter.h"
|
|
@@ -19,23 +21,33 @@ namespace rnwgpu {
|
|
|
19
21
|
|
|
20
22
|
void GPUDevice::notifyDeviceLost(wgpu::DeviceLostReason reason,
|
|
21
23
|
std::string message) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
}
|
|
25
40
|
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
_lostHandle.reset();
|
|
42
|
+
}
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
resolve([info = _lostInfo](jsi::Runtime &runtime) mutable {
|
|
44
|
+
// Settle outside the lock: resolve() only enqueues onto the JS thread.
|
|
45
|
+
if (resolveToCall.has_value()) {
|
|
46
|
+
(*resolveToCall)([info](jsi::Runtime &runtime) mutable {
|
|
33
47
|
return JSIConverter<std::shared_ptr<GPUDeviceLostInfo>>::toJSI(runtime,
|
|
34
48
|
info);
|
|
35
49
|
});
|
|
36
50
|
}
|
|
37
|
-
|
|
38
|
-
_lostHandle.reset();
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
void GPUDevice::forceLossForTesting() {
|
|
@@ -265,6 +277,55 @@ std::shared_ptr<GPUSharedTextureMemory> GPUDevice::importSharedTextureMemory(
|
|
|
265
277
|
std::move(label));
|
|
266
278
|
}
|
|
267
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
|
+
|
|
268
329
|
async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
|
|
269
330
|
std::shared_ptr<GPUComputePipelineDescriptor> descriptor) {
|
|
270
331
|
wgpu::ComputePipelineDescriptor desc{};
|
|
@@ -289,7 +350,7 @@ async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
|
|
|
289
350
|
&desc, wgpu::CallbackMode::AllowProcessEvents,
|
|
290
351
|
[pipelineHolder, resolve,
|
|
291
352
|
reject](wgpu::CreatePipelineAsyncStatus status,
|
|
292
|
-
wgpu::ComputePipeline pipeline,
|
|
353
|
+
wgpu::ComputePipeline pipeline, wgpu::StringView msg) {
|
|
293
354
|
if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
|
|
294
355
|
pipelineHolder->_instance = pipeline;
|
|
295
356
|
resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
|
|
@@ -298,7 +359,8 @@ async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
|
|
|
298
359
|
});
|
|
299
360
|
} else {
|
|
300
361
|
std::string error =
|
|
301
|
-
msg ? std::string(msg)
|
|
362
|
+
msg.length ? std::string(msg.data, msg.length)
|
|
363
|
+
: "Failed to create compute pipeline";
|
|
302
364
|
reject(std::move(error));
|
|
303
365
|
}
|
|
304
366
|
});
|
|
@@ -330,7 +392,7 @@ async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
|
|
|
330
392
|
&desc, wgpu::CallbackMode::AllowProcessEvents,
|
|
331
393
|
[pipelineHolder, resolve,
|
|
332
394
|
reject](wgpu::CreatePipelineAsyncStatus status,
|
|
333
|
-
wgpu::RenderPipeline pipeline,
|
|
395
|
+
wgpu::RenderPipeline pipeline, wgpu::StringView msg) {
|
|
334
396
|
if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
|
|
335
397
|
pipelineHolder->_instance = pipeline;
|
|
336
398
|
resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
|
|
@@ -339,7 +401,8 @@ async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
|
|
|
339
401
|
});
|
|
340
402
|
} else {
|
|
341
403
|
std::string error =
|
|
342
|
-
msg ? std::string(msg)
|
|
404
|
+
msg.length ? std::string(msg.data, msg.length)
|
|
405
|
+
: "Failed to create render pipeline";
|
|
343
406
|
reject(std::move(error));
|
|
344
407
|
}
|
|
345
408
|
});
|
|
@@ -423,6 +486,11 @@ std::unordered_set<std::string> GPUDevice::getFeatures() {
|
|
|
423
486
|
}
|
|
424
487
|
|
|
425
488
|
async::AsyncTaskHandle GPUDevice::getLost() {
|
|
489
|
+
// Held across the whole body: the postTask callback below runs synchronously
|
|
490
|
+
// on this (JS) thread and touches the same _lost* fields, so it must not
|
|
491
|
+
// re-lock. notifyDeviceLost() takes the same lock from its (possibly worker)
|
|
492
|
+
// thread.
|
|
493
|
+
std::lock_guard<std::mutex> lock(_lostMutex);
|
|
426
494
|
if (_lostHandle.has_value()) {
|
|
427
495
|
return *_lostHandle;
|
|
428
496
|
}
|
|
@@ -437,7 +505,7 @@ async::AsyncTaskHandle GPUDevice::getLost() {
|
|
|
437
505
|
runtime, info);
|
|
438
506
|
});
|
|
439
507
|
},
|
|
440
|
-
false);
|
|
508
|
+
/*keepPumping=*/false);
|
|
441
509
|
}
|
|
442
510
|
|
|
443
511
|
auto handle = _async->postTask(
|
|
@@ -451,9 +519,10 @@ async::AsyncTaskHandle GPUDevice::getLost() {
|
|
|
451
519
|
return;
|
|
452
520
|
}
|
|
453
521
|
|
|
522
|
+
// Resolved later from notifyDeviceLost().
|
|
454
523
|
_lostResolve = resolve;
|
|
455
524
|
},
|
|
456
|
-
false);
|
|
525
|
+
/*keepPumping=*/false);
|
|
457
526
|
|
|
458
527
|
_lostHandle = handle;
|
|
459
528
|
return handle;
|
|
@@ -478,6 +547,23 @@ void GPUDevice::removeEventListener(std::string type, jsi::Function callback) {
|
|
|
478
547
|
}
|
|
479
548
|
|
|
480
549
|
void GPUDevice::notifyUncapturedError(GPUErrorVariant error) {
|
|
550
|
+
// Dawn can surface an uncaptured error from any ProcessEvents pump (a worklet
|
|
551
|
+
// runtime sharing this instance may pump it on the wrong thread). Marshal to
|
|
552
|
+
// the owning runtime's JS thread via its CallInvoker before touching JSI. The
|
|
553
|
+
// invoker is wired only for the main JS runtime, so a device created on a
|
|
554
|
+
// worklet runtime does not deliver uncaptured errors to JS (best-effort; see
|
|
555
|
+
// the Threading model).
|
|
556
|
+
auto invoker = _async ? _async->callInvoker() : nullptr;
|
|
557
|
+
if (!invoker) {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
auto self = shared_from_this();
|
|
561
|
+
invoker->invokeAsync([self, error = std::move(error)]() mutable {
|
|
562
|
+
self->deliverUncapturedError(std::move(error));
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
void GPUDevice::deliverUncapturedError(GPUErrorVariant error) {
|
|
481
567
|
auto runtime = getCreationRuntime();
|
|
482
568
|
if (runtime == nullptr) {
|
|
483
569
|
return;
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
#include "jsi2/NativeObject.h"
|
|
17
17
|
|
|
18
|
-
#include "rnwgpu/async/AsyncRunner.h"
|
|
19
18
|
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
19
|
+
#include "rnwgpu/async/RuntimeContext.h"
|
|
20
20
|
|
|
21
21
|
#include "webgpu/webgpu_cpp.h"
|
|
22
22
|
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
#include "GPURenderPipeline.h"
|
|
38
38
|
#include "GPUSampler.h"
|
|
39
39
|
#include "GPUShaderModule.h"
|
|
40
|
+
#include "GPUSharedFence.h"
|
|
40
41
|
#include "GPUSharedTextureMemory.h"
|
|
41
42
|
#include "GPUSupportedLimits.h"
|
|
42
43
|
#include "GPUTexture.h"
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
#include "descriptors/GPURenderPipelineDescriptor.h"
|
|
53
54
|
#include "descriptors/GPUSamplerDescriptor.h"
|
|
54
55
|
#include "descriptors/GPUShaderModuleDescriptor.h"
|
|
56
|
+
#include "descriptors/GPUSharedFenceDescriptor.h"
|
|
55
57
|
#include "descriptors/GPUSharedTextureMemoryDescriptor.h"
|
|
56
58
|
#include "descriptors/GPUTextureDescriptor.h"
|
|
57
59
|
|
|
@@ -97,7 +99,7 @@ public:
|
|
|
97
99
|
static constexpr const char *CLASS_NAME = "GPUDevice";
|
|
98
100
|
|
|
99
101
|
explicit GPUDevice(wgpu::Device instance,
|
|
100
|
-
std::shared_ptr<async::
|
|
102
|
+
std::shared_ptr<async::RuntimeContext> async,
|
|
101
103
|
std::string label)
|
|
102
104
|
: NativeObject(CLASS_NAME), _instance(instance), _async(async),
|
|
103
105
|
_label(label) {
|
|
@@ -124,6 +126,8 @@ public:
|
|
|
124
126
|
std::shared_ptr<GPUExternalTextureDescriptor> descriptor);
|
|
125
127
|
std::shared_ptr<GPUSharedTextureMemory> importSharedTextureMemory(
|
|
126
128
|
std::shared_ptr<GPUSharedTextureMemoryDescriptor> descriptor);
|
|
129
|
+
std::shared_ptr<GPUSharedFence>
|
|
130
|
+
importSharedFence(std::shared_ptr<GPUSharedFenceDescriptor> descriptor);
|
|
127
131
|
std::shared_ptr<GPUBindGroupLayout> createBindGroupLayout(
|
|
128
132
|
std::shared_ptr<GPUBindGroupLayoutDescriptor> descriptor);
|
|
129
133
|
std::shared_ptr<GPUPipelineLayout>
|
|
@@ -179,6 +183,8 @@ public:
|
|
|
179
183
|
&GPUDevice::importExternalTexture);
|
|
180
184
|
installMethod(runtime, prototype, "importSharedTextureMemory",
|
|
181
185
|
&GPUDevice::importSharedTextureMemory);
|
|
186
|
+
installMethod(runtime, prototype, "importSharedFence",
|
|
187
|
+
&GPUDevice::importSharedFence);
|
|
182
188
|
installMethod(runtime, prototype, "createBindGroupLayout",
|
|
183
189
|
&GPUDevice::createBindGroupLayout);
|
|
184
190
|
installMethod(runtime, prototype, "createPipelineLayout",
|
|
@@ -224,9 +230,18 @@ public:
|
|
|
224
230
|
private:
|
|
225
231
|
friend class GPUAdapter;
|
|
226
232
|
|
|
233
|
+
// Runs the uncapturederror listeners on the creation runtime's JS thread.
|
|
234
|
+
// Invoked from notifyUncapturedError via the main CallInvoker.
|
|
235
|
+
void deliverUncapturedError(GPUErrorVariant error);
|
|
236
|
+
|
|
227
237
|
wgpu::Device _instance;
|
|
228
|
-
std::shared_ptr<async::
|
|
238
|
+
std::shared_ptr<async::RuntimeContext> _async;
|
|
229
239
|
std::string _label;
|
|
240
|
+
// Guards the device-lost state below. In the ProcessEvents model both
|
|
241
|
+
// notifyDeviceLost() (fired by Dawn during ProcessEvents) and getLost() run on
|
|
242
|
+
// the owning runtime's own thread, but device destruction can also trigger
|
|
243
|
+
// notifyDeviceLost() synchronously, so the mutex keeps these fields safe.
|
|
244
|
+
std::mutex _lostMutex;
|
|
230
245
|
std::optional<async::AsyncTaskHandle> _lostHandle;
|
|
231
246
|
std::shared_ptr<GPUDeviceLostInfo> _lostInfo;
|
|
232
247
|
bool _lostSettled = false;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
#include "jsi2/NativeObject.h"
|
|
10
10
|
|
|
11
|
-
#include "rnwgpu/async/AsyncRunner.h"
|
|
12
11
|
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
12
|
+
#include "rnwgpu/async/RuntimeContext.h"
|
|
13
13
|
|
|
14
14
|
#include "webgpu/webgpu_cpp.h"
|
|
15
15
|
|
|
@@ -31,7 +31,7 @@ public:
|
|
|
31
31
|
static constexpr const char *CLASS_NAME = "GPUQueue";
|
|
32
32
|
|
|
33
33
|
explicit GPUQueue(wgpu::Queue instance,
|
|
34
|
-
std::shared_ptr<async::
|
|
34
|
+
std::shared_ptr<async::RuntimeContext> async,
|
|
35
35
|
std::string label)
|
|
36
36
|
: NativeObject(CLASS_NAME), _instance(instance), _async(async),
|
|
37
37
|
_label(label) {}
|
|
@@ -77,7 +77,7 @@ public:
|
|
|
77
77
|
|
|
78
78
|
private:
|
|
79
79
|
wgpu::Queue _instance;
|
|
80
|
-
std::shared_ptr<async::
|
|
80
|
+
std::shared_ptr<async::RuntimeContext> _async;
|
|
81
81
|
std::string _label;
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -18,7 +18,7 @@ async::AsyncTaskHandle GPUShaderModule::getCompilationInfo() {
|
|
|
18
18
|
wgpu::CallbackMode::AllowProcessEvents,
|
|
19
19
|
[result, resolve,
|
|
20
20
|
reject](wgpu::CompilationInfoRequestStatus status,
|
|
21
|
-
const wgpu::CompilationInfo *compilationInfo)
|
|
21
|
+
const wgpu::CompilationInfo *compilationInfo) {
|
|
22
22
|
if (status != wgpu::CompilationInfoRequestStatus::Success ||
|
|
23
23
|
compilationInfo == nullptr) {
|
|
24
24
|
reject("Failed to get compilation info");
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
#include "jsi2/NativeObject.h"
|
|
9
9
|
|
|
10
|
-
#include "rnwgpu/async/AsyncRunner.h"
|
|
11
10
|
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
11
|
+
#include "rnwgpu/async/RuntimeContext.h"
|
|
12
12
|
|
|
13
13
|
#include "webgpu/webgpu_cpp.h"
|
|
14
14
|
|
|
@@ -23,7 +23,7 @@ public:
|
|
|
23
23
|
static constexpr const char *CLASS_NAME = "GPUShaderModule";
|
|
24
24
|
|
|
25
25
|
explicit GPUShaderModule(wgpu::ShaderModule instance,
|
|
26
|
-
std::shared_ptr<async::
|
|
26
|
+
std::shared_ptr<async::RuntimeContext> async,
|
|
27
27
|
std::string label)
|
|
28
28
|
: NativeObject(CLASS_NAME), _instance(instance), _async(async),
|
|
29
29
|
_label(label) {}
|
|
@@ -59,7 +59,7 @@ public:
|
|
|
59
59
|
|
|
60
60
|
private:
|
|
61
61
|
wgpu::ShaderModule _instance;
|
|
62
|
-
std::shared_ptr<async::
|
|
62
|
+
std::shared_ptr<async::RuntimeContext> _async;
|
|
63
63
|
std::string _label;
|
|
64
64
|
};
|
|
65
65
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#include "GPUSharedFence.h"
|
|
2
|
+
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#if defined(__ANDROID__)
|
|
7
|
+
#include <fcntl.h>
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
namespace rnwgpu {
|
|
11
|
+
|
|
12
|
+
namespace {
|
|
13
|
+
|
|
14
|
+
// Kebab-case names matching the shared-fence-* feature strings (see Unions.h /
|
|
15
|
+
// GPUFeatures.h).
|
|
16
|
+
std::string sharedFenceTypeToString(wgpu::SharedFenceType type) {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case wgpu::SharedFenceType::MTLSharedEvent:
|
|
19
|
+
return "mtl-shared-event";
|
|
20
|
+
case wgpu::SharedFenceType::SyncFD:
|
|
21
|
+
return "sync-fd";
|
|
22
|
+
case wgpu::SharedFenceType::VkSemaphoreOpaqueFD:
|
|
23
|
+
return "vk-semaphore-opaque-fd";
|
|
24
|
+
case wgpu::SharedFenceType::VkSemaphoreZirconHandle:
|
|
25
|
+
return "vk-semaphore-zircon-handle";
|
|
26
|
+
case wgpu::SharedFenceType::DXGISharedHandle:
|
|
27
|
+
return "dxgi-shared-handle";
|
|
28
|
+
case wgpu::SharedFenceType::EGLSync:
|
|
29
|
+
return "egl-sync";
|
|
30
|
+
default:
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
} // namespace
|
|
36
|
+
|
|
37
|
+
jsi::Value GPUSharedFence::exportInfo(jsi::Runtime &runtime, const jsi::Value &,
|
|
38
|
+
const jsi::Value *, size_t) {
|
|
39
|
+
wgpu::SharedFenceExportInfo info{};
|
|
40
|
+
uint64_t handle = 0;
|
|
41
|
+
|
|
42
|
+
#if defined(__APPLE__)
|
|
43
|
+
// Apple: the handle is an id<MTLSharedEvent> pointer.
|
|
44
|
+
wgpu::SharedFenceMTLSharedEventExportInfo mtlInfo{};
|
|
45
|
+
info.nextInChain = &mtlInfo;
|
|
46
|
+
_instance.ExportInfo(&info);
|
|
47
|
+
handle = reinterpret_cast<uint64_t>(mtlInfo.sharedEvent);
|
|
48
|
+
#elif defined(__ANDROID__)
|
|
49
|
+
// Android: the handle is an OS file descriptor (sync_fd). Dawn's ExportInfo
|
|
50
|
+
// returns a BORROWED fd: it is owned by the SharedFence and closed when the
|
|
51
|
+
// fence is destroyed. This exported handle is documented as caller-owned (the
|
|
52
|
+
// caller must close() it), so dup() it. Without the dup the same fd is closed
|
|
53
|
+
// twice (once by the caller and once by Dawn on fence destruction), tripping
|
|
54
|
+
// Android's fdsan (double-close abort).
|
|
55
|
+
wgpu::SharedFenceSyncFDExportInfo fdInfo{};
|
|
56
|
+
info.nextInChain = &fdInfo;
|
|
57
|
+
_instance.ExportInfo(&info);
|
|
58
|
+
int exportedFd = fdInfo.handle >= 0
|
|
59
|
+
? ::fcntl(fdInfo.handle, F_DUPFD_CLOEXEC, 0)
|
|
60
|
+
: fdInfo.handle;
|
|
61
|
+
handle = static_cast<uint64_t>(static_cast<uint32_t>(exportedFd));
|
|
62
|
+
#else
|
|
63
|
+
// react-native-skia only targets Apple (Metal) and Android (Vulkan). On any
|
|
64
|
+
// other platform there is no native handle convention to expose, so fail
|
|
65
|
+
// loudly rather than handing back a meaningless handle of 0.
|
|
66
|
+
throw jsi::JSError(runtime,
|
|
67
|
+
"GPUSharedFence::export(): unsupported platform (only "
|
|
68
|
+
"Apple/Metal and Android/Vulkan are supported)");
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
jsi::Object result(runtime);
|
|
72
|
+
result.setProperty(
|
|
73
|
+
runtime, "type",
|
|
74
|
+
jsi::String::createFromUtf8(runtime, sharedFenceTypeToString(info.type)));
|
|
75
|
+
result.setProperty(runtime, "handle",
|
|
76
|
+
jsi::BigInt::fromUint64(runtime, handle));
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "jsi2/NativeObject.h"
|
|
7
|
+
|
|
8
|
+
#include "webgpu/webgpu_cpp.h"
|
|
9
|
+
|
|
10
|
+
namespace rnwgpu {
|
|
11
|
+
|
|
12
|
+
namespace jsi = facebook::jsi;
|
|
13
|
+
|
|
14
|
+
// Wraps a wgpu::SharedFence: a native GPU sync primitive (id<MTLSharedEvent> on
|
|
15
|
+
// Apple, sync-fd / VkSemaphore on Android).
|
|
16
|
+
class GPUSharedFence : public NativeObject<GPUSharedFence> {
|
|
17
|
+
public:
|
|
18
|
+
static constexpr const char *CLASS_NAME = "GPUSharedFence";
|
|
19
|
+
|
|
20
|
+
explicit GPUSharedFence(wgpu::SharedFence instance, std::string label)
|
|
21
|
+
: NativeObject(CLASS_NAME), _instance(std::move(instance)),
|
|
22
|
+
_label(std::move(label)) {}
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
26
|
+
|
|
27
|
+
// export() -> { type, handle }: exposes the native handle (as a BigInt) so
|
|
28
|
+
// app code can wait on or signal the fence. The caller owns the returned
|
|
29
|
+
// handle (e.g. an exported sync-fd must be close()d).
|
|
30
|
+
jsi::Value exportInfo(jsi::Runtime &runtime, const jsi::Value &thisVal,
|
|
31
|
+
const jsi::Value *args, size_t count);
|
|
32
|
+
|
|
33
|
+
std::string getLabel() { return _label; }
|
|
34
|
+
void setLabel(const std::string &label) {
|
|
35
|
+
_label = label;
|
|
36
|
+
_instance.SetLabel(_label.c_str());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
40
|
+
installGetter(runtime, prototype, "__brand", &GPUSharedFence::getBrand);
|
|
41
|
+
installMethod(runtime, prototype, "export", &GPUSharedFence::exportInfo);
|
|
42
|
+
installGetterSetter(runtime, prototype, "label", &GPUSharedFence::getLabel,
|
|
43
|
+
&GPUSharedFence::setLabel);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
inline wgpu::SharedFence get() { return _instance; }
|
|
47
|
+
|
|
48
|
+
private:
|
|
49
|
+
wgpu::SharedFence _instance;
|
|
50
|
+
std::string _label;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
} // namespace rnwgpu
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#include "GPUSharedTextureMemory.h"
|
|
2
2
|
|
|
3
|
+
#include <cstdint>
|
|
3
4
|
#include <memory>
|
|
5
|
+
#include <optional>
|
|
4
6
|
#include <stdexcept>
|
|
5
7
|
#include <string>
|
|
8
|
+
#include <vector>
|
|
6
9
|
|
|
7
10
|
#include "Convertors.h"
|
|
8
11
|
|
|
@@ -29,8 +32,9 @@ std::shared_ptr<GPUTexture> GPUSharedTextureMemory::createTexture(
|
|
|
29
32
|
texture, descriptor.value()->label.value_or(""), false);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
void GPUSharedTextureMemory::beginAccess(
|
|
36
|
+
std::shared_ptr<GPUTexture> texture, bool initialized,
|
|
37
|
+
std::optional<std::vector<std::shared_ptr<GPUSharedFenceState>>> fences) {
|
|
34
38
|
if (!texture) {
|
|
35
39
|
throw std::runtime_error(
|
|
36
40
|
"GPUSharedTextureMemory::beginAccess(): texture is null");
|
|
@@ -38,9 +42,28 @@ bool GPUSharedTextureMemory::beginAccess(std::shared_ptr<GPUTexture> texture,
|
|
|
38
42
|
wgpu::SharedTextureMemoryBeginAccessDescriptor desc{};
|
|
39
43
|
desc.initialized = initialized;
|
|
40
44
|
desc.concurrentRead = false;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
|
|
46
|
+
// Built in lockstep so fenceCount covers both arrays, and kept in locals so
|
|
47
|
+
// the raw pointers outlive the synchronous BeginAccess() below.
|
|
48
|
+
std::vector<wgpu::SharedFence> rawFences;
|
|
49
|
+
std::vector<uint64_t> values;
|
|
50
|
+
if (fences.has_value()) {
|
|
51
|
+
for (const auto &state : *fences) {
|
|
52
|
+
if (state && state->fence) {
|
|
53
|
+
rawFences.push_back(state->fence->get());
|
|
54
|
+
values.push_back(state->signaledValue);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!rawFences.empty()) {
|
|
59
|
+
desc.fenceCount = rawFences.size();
|
|
60
|
+
desc.fences = rawFences.data();
|
|
61
|
+
desc.signaledValues = values.data();
|
|
62
|
+
} else {
|
|
63
|
+
desc.fenceCount = 0;
|
|
64
|
+
desc.fences = nullptr;
|
|
65
|
+
desc.signaledValues = nullptr;
|
|
66
|
+
}
|
|
44
67
|
|
|
45
68
|
#if defined(__ANDROID__)
|
|
46
69
|
// Dawn's Vulkan backend (AHardwareBuffer) validates that the begin-access
|
|
@@ -57,14 +80,21 @@ bool GPUSharedTextureMemory::beginAccess(std::shared_ptr<GPUTexture> texture,
|
|
|
57
80
|
#endif
|
|
58
81
|
|
|
59
82
|
auto status = _instance.BeginAccess(texture->get(), &desc);
|
|
60
|
-
|
|
83
|
+
if (!status) {
|
|
84
|
+
throw std::runtime_error("GPUSharedTextureMemory::beginAccess() failed");
|
|
85
|
+
}
|
|
61
86
|
}
|
|
62
87
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
88
|
+
jsi::Value GPUSharedTextureMemory::endAccess(jsi::Runtime &runtime,
|
|
89
|
+
const jsi::Value &,
|
|
90
|
+
const jsi::Value *args,
|
|
91
|
+
size_t count) {
|
|
92
|
+
if (count < 1 || !args[0].isObject()) {
|
|
93
|
+
throw jsi::JSError(
|
|
94
|
+
runtime, "GPUSharedTextureMemory::endAccess(): expected (texture)");
|
|
67
95
|
}
|
|
96
|
+
auto texture = GPUTexture::fromValue(runtime, args[0]);
|
|
97
|
+
|
|
68
98
|
wgpu::SharedTextureMemoryEndAccessState state{};
|
|
69
99
|
|
|
70
100
|
#if defined(__ANDROID__)
|
|
@@ -76,7 +106,30 @@ bool GPUSharedTextureMemory::endAccess(std::shared_ptr<GPUTexture> texture) {
|
|
|
76
106
|
#endif
|
|
77
107
|
|
|
78
108
|
auto status = _instance.EndAccess(texture->get(), &state);
|
|
79
|
-
|
|
109
|
+
if (!status) {
|
|
110
|
+
throw jsi::JSError(runtime, "GPUSharedTextureMemory::endAccess() failed");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Copy each wgpu::SharedFence (ref-counted) into its own GPUSharedFence
|
|
114
|
+
// wrapper before `state` is destroyed.
|
|
115
|
+
jsi::Array fences(runtime, state.fenceCount);
|
|
116
|
+
for (size_t i = 0; i < state.fenceCount; i++) {
|
|
117
|
+
wgpu::SharedFence fence = state.fences[i];
|
|
118
|
+
auto wrapper = std::make_shared<GPUSharedFence>(std::move(fence), "");
|
|
119
|
+
jsi::Object entry(runtime);
|
|
120
|
+
entry.setProperty(runtime, "fence",
|
|
121
|
+
GPUSharedFence::create(runtime, std::move(wrapper)));
|
|
122
|
+
entry.setProperty(
|
|
123
|
+
runtime, "signaledValue",
|
|
124
|
+
jsi::BigInt::fromUint64(runtime, state.signaledValues[i]));
|
|
125
|
+
fences.setValueAtIndex(runtime, i, std::move(entry));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
jsi::Object result(runtime);
|
|
129
|
+
result.setProperty(runtime, "initialized",
|
|
130
|
+
jsi::Value(static_cast<bool>(state.initialized)));
|
|
131
|
+
result.setProperty(runtime, "fences", std::move(fences));
|
|
132
|
+
return result;
|
|
80
133
|
}
|
|
81
134
|
|
|
82
135
|
} // namespace rnwgpu
|