当我所有的表面都在GPU上时,为什么CoreImage做memcpy

时间:2019-09-13 12:52:20

标签: macos metal ciimage iosurface

当尝试调试为什么某些CoreImage渲染显着增加了CPU使用率时,我可以在示例跟踪中看到,当我以某些方式裁剪和合成图像时,CoreImage正在执行memcpys。当我取出作物过滤器时,它消失了。我正在将其用于实时2D视频管道,所以这不好。

我所有的图像都在GPU上,所以我对其在CPU上复制的内容感到困惑。

任何人都知道这可能在做什么吗?

+                       ! 457 -[CIContext render:toCVPixelBuffer:bounds:colorSpace:]  (in CoreImage) + 1296  [0x7fff8db01111]
+                       !   457 -[CIContext render:toIOSurface:bounds:colorSpace:]  (in CoreImage) + 1907  [0x7fff8db030e5]
+                       !     455 CI::image_render_to_surface(CI::Context*, CI::Image*, CGRect, CGColorSpace*, __IOSurface*, CGPoint, CI::PixelFormat)  (in CoreImage) + 1862  [0x7fff8db1d8a9]
+                       !     : 451 CI::_image_render(char const*, CI::Context*, CI::Image*, CGRect, CGColorSpace*, CI::PixelFormat, unsigned long, CGPoint const&, CI::swizzle_info const&)  (in CoreImage) + 869  [0x7fff8db1cdda]
+                       !     : | 443 CI::tile_node_graph(CI::Context*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, void (CI::Node*, CGRect) block_pointer)  (in CoreImage) + 834  [0x7fff8db1ffe1]
+                       !     : | + 416 ___ZN2CIL13_image_renderEPKcPNS_7ContextEPNS_5ImageE6CGRectP12CGColorSpaceNS_11PixelFormatEmRK7CGPointRKNS_12swizzle_infoE_block_invoke  (in CoreImage) + 22  [0x7fff8db22d54]
+                       !     : | + ! 416 CI::Context::render(CI::Node*, CGRect const&)  (in CoreImage) + 75  [0x7fff8db0efb1]
+                       !     : | + !   413 CI::Context::recursive_render(CI::Node*, CGRect const&, CI::Node*)  (in CoreImage) + 1285  [0x7fff8db0ee95]
+                       !     : | + !   : 277 CI::MetalContext::render_root_node(CI::ProgramNode*, CGRect const&, void () block_pointer)  (in CoreImage) + 105  [0x7fff8dc09549]
+                       !     : | + !   : | 273 CI::MetalContext::render_node(CI::ProgramNode*, CGRect const&, void const**, unsigned long, bool)  (in CoreImage) + 765  [0x7fff8dc08ddb]
+                       !     : | + !   : | + 269 CI::MetalContext::bind_arguments(CI::ProgramNode const*, CGRect const&, CGRect const&)  (in CoreImage) + 532  [0x7fff8dc0906a]
+                       !     : | + !   : | + ! 252 CI::Context::bind_sampler(CI::TextureSampler const*, CGRect const&, int, CI::KernelArgumentType)  (in CoreImage) + 992  [0x7fff8db0f3a6]
+                       !     : | + !   : | + ! : 232 CI::SurfaceNode::surfaceForROI(CI::Context const*, CGRect) const  (in CoreImage) + 718  [0x7fff8db71dc2]
+                       !     : | + !   : | + ! : | 142 SurfaceApplyPlaneReadOnlyBlock  (in CoreImage) + 170  [0x7fff8dbdcd39]
+                       !     : | + !   : | + ! : | + 142 ___ZNK2CI11SurfaceNode13surfaceForROIEPKNS_7ContextE6CGRect_block_invoke  (in CoreImage) + 123  [0x7fff8db71e5c]
+                       !     : | + !   : | + ! : | +   139 SurfaceApplyPlaneBlock  (in CoreImage) + 196  [0x7fff8dbdcbeb]
+                       !     : | + !   : | + ! : | +   ! 133 ___ZNK2CI11SurfaceNode13surfaceForROIEPKNS_7ContextE6CGRect_block_invoke_2  (in CoreImage) + 367  [0x7fff8db71fd1]
+                       !     : | + !   : | + ! : | +   ! : 133 _platform_memmove$VARIANT$Haswell  (in libsystem_platform.dylib) + 324,224,...  [0x7fffa2a63fe4,0x7fffa2a63f80,...]

更新:

这是包含作物的渲染管道。这与上面的memcpy一起使用了大量的CPU。所有来源均为IOSurfaces。它要拍摄两张图像并创建一个分屏:

<CIImage: 0x618000623e20 extent [infinite]>
  colorkernel _sourceOver(src,dst) extent=[infinite]
    crop [1280 0 1280 1440] extent=[1280 0 1280 1440]
      affine [3.13725 0 0 3.13725 825.098 0] extent=[825.098 0 2189.8 1440]
        affine [1 0 0 -1 0 459] extent=[0 0 698 459]
          IOSurface 0x610000010300 BGRA8 extent=[0 0 698 459]
    colorkernel _sourceOver(src,dst) extent=[infinite]
      crop [0 0 1281 1440] extent=[0 0 1281 1440] opaque
        affine [-2.00156 -0 0 2 1921.5 0] extent=[-640.5 0 2562 1440] opaque
          affine [1 0 0 -1 0 720] extent=[0 0 1280 720] opaque
            IOSurface 0x60000000b650 YCC420v 709 alpha_one extent=[0 0 1280 720] opaque
      fill [0 0 0 1 "Generic Gray Profile"] extent=[infinite][0 0 1 1] opaque

-

如果我将农作物取出,这是不使用CPU且不会沿着surfaceForROI路径运行的管道:

<CIImage: 0x618000225040 extent [infinite]>
  colorkernel _sourceOver(src,dst) extent=[infinite]
    affine [3.13725 0 0 3.13725 825.098 0] extent=[825.098 0 2189.8 1440]
      affine [1 0 0 -1 0 459] extent=[0 0 698 459]
        IOSurface 0x6180000077c0 BGRA8 extent=[0 0 698 459]
    colorkernel _sourceOver(src,dst) extent=[infinite]
      affine [-2.00156 -0 0 2 1921.5 0] extent=[-640.5 0 2562 1440] opaque
        affine [1 0 0 -1 0 720] extent=[0 0 1280 720] opaque
          IOSurface 0x61000000c730 YCC420v 709 alpha_one extent=[0 0 1280 720] opaque
      fill [0 0 0 1 "Generic Gray Profile"] extent=[infinite][0 0 1 1] opaque

0 个答案:

没有答案