我完成了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();
Run Code Online (Sandbox Code Playgroud)
我应该创建一个新的commandBuffer,commandEncoder和一个编译第二个内核函数的单独的pipelineState吗?这将把第一个滤波器的输出作为第二个滤波器的输入.有没有更有效的方法来做到这一点,或者这是最佳的?
我是Metal的初学者,因此对管道如何工作的任何解释都受到高度赞赏.