4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cocoapodsでmetalファイルを含めて配布する方法と、CoreImageで使う方法

Posted at

cocoapodsでMetalファイルを含めて配布する場合は、podspecにmetalファイルを追加します。

LibraryName.podspec
s.source_files = 'LibraryName/Classes/**/*.{swift,metal}'

また、CoreImageのCIKernelとして呼ぶ場合は次のような設定を追加します。

LibraryName.podspec
s.pod_target_xcconfig = {
  'MTLLINKER_FLAGS' => '-cikernel',
  'MTL_COMPILER_FLAGS' => '-fcikernel'
}

これでMetalファイルに含まれる関数がCoreImage用としてコンパイルされます。

CIKernelをライブラリ内で生成するには、自身のバンドルを指定します。

private final class BundleToken {}

let url = Bundle(for: BundleToken.self).url(forResource: "default", withExtension: "metallib")!
let data = try! Data(contentsOf: url)
let kernel = try! CIColorKernel(functionName: "filterName", fromMetalLibraryData: data)
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?