我在命令缓冲区对象上设置可绘制对象时遇到编译时错误。
以下是我的函数,它从MTKView
子类的方法调用draw
。
fileprivate func executeMetalShader() {
guard let pipelineState = self.pipelineState,
let threadgroupsPerGrid = self.threadgroupsPerGrid,
let threadsPerThreadgroup = self.threadsPerThreadgroup
else { return }
guard let drawable: CAMetalDrawable = self.currentDrawable else { fatalError("Failed to create drawable") }
let commandBuffer = commandQueue?.makeCommandBuffer()
let commandEncoder = commandBuffer?.makeComputeCommandEncoder()
commandEncoder?.setComputePipelineState(pipelineState)
commandEncoder?.setTexture(yTexture, index: 0)
commandEncoder?.setTexture(uTexture, index: 1)
commandEncoder?.setTexture(vTexture, index: 2)
commandEncoder?.setTexture(outTexture, index: 3)
commandEncoder?.dispatchThreadgroups(threadgroupsPerGrid,
threadsPerThreadgroup: threadsPerThreadgroup)
commandEncoder?.endEncoding()
commandBuffer.present(drawable) //. Error: Type of expression is ambiguous without more context
commandBuffer?.commit()
print("shader execution finish")
}
我做错了什么,或者 Swift 5 中有一些 API 更改吗?
我认为你错过了一个?
.修复:
commandBuffer?.present(drawable)