This question pertains to both wwdc21-10159 and wwdc20-10009.
Let's say I have a simple Core Image kernel that does some simple operation as shown below.
#include <metal_stdlib>
#include <CoreImage/CoreImage.h> // includes CIKernelMetalLib.h
using namespace metal;
extern "C" float4 HDRHighlight(coreimage::sample_t s, float time, coreimage::destination dest)
{
return float4(2.0, 0.0, 0.0, 1.0);
}
In my build rules, I have the appropriate command to compile and link the .ci.metal source into the ci.metallib library.
I can confirm internally in the resources that this library file is generated.
However, when I import the kernel using CIColorKernel in Swift, I am given an error that states the kernel function failed to load.
In the logs, I see that it says:
[api] reflect Function 'HDRHighlight' does not exist.
Fatal error: Unable to load the kernel.
Turns out, the issue was because of a simple flag in my build rule.
The -I
flag removes the current directory from the compile search space, which was leading to the actual kernel not compiling into the library.
Removing it fixed the issue.
Here's what my build rules look like now.