Metal:为MSL cikernel设置编译器和链接器选项后,.metal文件中定义的vertexFunction变为nil [英] Metal: vertexFunction defined in .metal file becomes nil once setting Compiler and Linker Options for MSL cikernel

查看:334
本文介绍了Metal:为MSL cikernel设置编译器和链接器选项后,.metal文件中定义的vertexFunction变为nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.metal文件中定义的VertexFunction和FragmentFunction可以很好地工作,但是一旦我在

VertexFunction and FragmentFunction defined in .metal file worked nicely, but they became nil once I specified Compiler and Linker Options following Apple's doc: -fcikernel flag in the Other Metal Compiler Flags option, and -cikernel flat in MTLLINKER_FLAGS in User-Defined setting.

我需要使用MSL(金属阴影语言)的香ker的上述设置.实际上,使用Core Image Kernel Language的cikernel在12.0中已弃用.

I need the settings above for cikernel with MSL (metal shading language). Indeed, cikernel with Core Image Kernel Language deprecated in 12.0.

我如何同时使用顶点/片段金属着色器和MSL香石?

How could I use both vertex/fragment Metal shader and MSL cikernel together?

let library = self.device?.makeDefaultLibrary()!
let pipeLineDescriptor = MTLRenderPipelineDescriptor()
pipeLineDescriptor.vertexFunction=library.makeFunction(name: "myVertexShader")
pipeLineDescriptor.fragmentFunction=library.makeFunction(name: "myFragmentShader")

推荐答案

我想您必须分别编译过滤器内核,而不是使用默认的Metal库.

I guess you have to compile your filter kernels separately instead of with your default Metal library.

为此,例如,您可以给他们另一个文件扩展名,例如.kernel,并添加一个自定义的 Build Rule ,如下所示:

To do so, you could for instance give them another file extension, like .kernel and add a custom Build Rule like so:

然后添加一个自定义的 Build Phase ,将已编译的内核metallib复制到您的应用程序包中:

Then add a custom Build Phase that copies the compiled kernel metallibs into your app bundle:

要使用正确的金属源初始化CIKernel,您可以执行以下操作:

To initialize the CIKernel with the correct metal source, you can do something like this:

let url = Bundle(for: type(of: self)).url(forResource: "<#name of your .kernel file#>", withExtension: "metallib")!
let data = try! Data(contentsOf: url)
let kernel = try! CIKernel(functionName: "<#kernel function name#>", fromMetalLibraryData: data)

(请注意,应从项目设置中再次删除编译器和liker标志,以使其他Metal源再次正确编译.)

(Note that you should remove the compiler and liker flags again from your project settings to have your other Metal sources compile properly again.)

这篇关于Metal:为MSL cikernel设置编译器和链接器选项后,.metal文件中定义的vertexFunction变为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆