Memory usage keeps rising on older devices using Metal
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 newColorMix
filter every frame. Additionally, inside the instance methoduse(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 oninit
. It would be advisable to just create a singleColorMix
filter during setup and just update itsinputImage
andinputTime
on every frame. outputImage
is not afunc
, but avar
that you override from theCIFilter
super class:override var outputImage: CIImage? { /* your code here */ }
Is your
colorMix
kernel performing any kind of convolution? If not, it could be aCIColorKernel
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 inputsampler
.