Memory usage keeps rising on older devices using Metal

徘徊边缘 提交于 2019-12-04 08:23:16

This is a bug in Xcode's diagnostic features (Metal validation and/or GPU frame capture). If you turn those off, the memory usage should be similar to when running outside of Xcode.

Here are a few observations, but I'm not sure if one of them actually causes the memory usage you're seeing:

  • In applyFilter you are creating a new ColorMix filter every frame. Additionally, inside the instance method use(image:, time:) you are creating another one on every call. That's a lot of overhead, especially since the filter loads it's kernel every time on init. It would be advisable to just create a single ColorMix filter during setup and just update its inputImage and inputTime on every frame.
  • outputImage is not a func, but a var that you override from the CIFilter super class:

    override var outputImage: CIImage? { /* your code here */ }

  • Is your colorMix kernel performing any kind of convolution? If not, it could be a CIColorKernel instead.

  • If you need the size of the input inside your kernel, you don't need to pass it as extra argument. You can just call .size() on the input sampler.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!