This is a weird XCode 13 beta bug (including beta 5). Metal Core Image kernels fail to load from the library giving error
2021-08-26 12:05:23.806226+0400 MetalFilter[23183:1751438] [api] +[CIKernel kernelWithFunctionName:fromMetalLibraryData:options:error:] Cannot initialize kernel with given library data.
[ERROR] Failed to create CIColorKernel: Error Domain=CIKernel Code=6 "(null)" UserInfo={CINonLocalizedDescriptionKey=Cannot initialize kernel with given library data.}
But there is no such error with XCode 12.5. The kernel loads fine. Only on XCode 13 beta there is an error.
It should work when you remove the -I $MTL_HEADER_SEARCH_PATHS
part from your custom build rule.
Though it is mentioned in the WWDC video, it actually causes problems when MTL_HEADER_SEARCH_PATHS
is empty. See this answer to a related question.
Usually, you don't need that parameter if you don't have a complicated file graph or external dependencies.