我完成了Simon Gladman(@flexmonkey)的此教程,用于从AVFoundation
中捕获图像并对输出应用滤镜。然而,我正在努力寻找一种方法来用自己的计算着色器替换模糊滤镜。换句话说,在那里提到的YCbCrColorConversion
滤镜之后,我需要将我的自定义着色器连接起来。
let commandBuffer = commandQueue.makeCommandBuffer()
let commandEncoder = commandBuffer.makeComputeCommandEncoder()
// pipelineState has compiled YCbCrColorConversion filter
commandEncoder.setComputePipelineState(pipelineState)
commandEncoder.setTexture(ytexture, at: 0)
commandEncoder.setTexture(cbcrTexture, at: 1)
commandEncoder.setTexture(drawable.texture, at: 2) // out texture
commandEncoder.dispatchThreadgroups(threadGroups,threadsPerThreadgroup: threadGroupCount)
commandEncoder.endEncoding()
let inPlaceTexture = UnsafeMutablePointer<MTLTexture> .allocate(capacity: 1)
inPlaceTexture.initialize(to: drawable.texture)
// How to replace this blur with my own filter?????
blur.encodeToCommandBuffer(commandBuffer, inPlaceTexture: inPlaceTexture, fallbackCopyAllocator: nil)
commandBuffer.presentDrawable(drawable)
commandBuffer.commit();
我应该创建一个新的commandBuffer、commandEncoder和单独的pipelineState来编译第二个内核函数吗?这将把第一个过滤器的输出作为第二个过滤器的输入。有没有更有效的方法来实现这一点,或者这是最优的方法?
我是Metal的初学者,因此非常欢迎对管道工作原理的任何解释。