【发布时间】:2016-10-20 18:33:54
【问题描述】:
我完成了 Simon Gladman (@flexmonkey) 的 this tutorial 以从 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 的初学者,因此非常感谢您对管道如何工作的任何解释。
【问题讨论】: