I've been struggling with a bug with a Metal CIKernel call.
The kernel looks like this:
extern "C" float4 FeedbackIn(coreimage::sampler src, coreimage::sampler gradient, coreimage::sampler feedback, float time, float threshold, float optionValue, coreimage::destination dest )
{
float4 input = src.sample(src.coord());
return input;
}
The call from Swift looks like this:
let result = ciKernel!.apply(extent: self.inputImage!.extent,
roiCallback: { [self]
(index, rect) -> CGRect in
let roiRect = rect.insetBy(dx: -1 * range, dy: -1 * range )
return roiRect
},
arguments: [self.inputImage!, gradient!, feedback!, time, threshold, scaledOption])
// CIImage, CIImage, CIImage, Float, Float, Float
When I remove the 'feedback' from the Kernel and corresponding argument from the list in the Swift code, there is no issue. With the code as displayed, the export function will gradually slow down and memory size increase in Instruments Leaks. Instruments Leaks does not show any leaks.
I am running Xcode 13.3, macOS 12.1.1 on an iMac (Retina 5K, 27-inch, Late 2015).
Any insight on this is greatly appreciated! I don't know if passing the third CIImage is allowed or this is a bug.
Thanks to all in advance!
I found a workaround. The CIImage that was queued for feedback had several Kernel filters applied to it. This seemed to be the cause of the memory issue. My workaround is to convert the CIImage to NSImage and then back to CIImage when adding it to the feedback queue. The CIImage from the NSImage has eliminated all of the intermediate operations that were in the original CIImage.
This is not very elegant, but it works. The virtual memory size is rock solid.