在命令缓冲区对象上设置可绘制对象时出现编译时错误。
以下是我的函数,它是从子类的draw
方法调用的MTKView
。
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 更改?