MTKView:表达式类型不明确,在commandBuffer.present上没有更多上下文

问题描述 投票:0回答:1

在命令缓冲区对象上设置可绘制对象时,出现编译时错误。

以下是我的函数,该函数从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更改?

swift metal mtkview
1个回答
0
投票

我认为您缺少?。修复:

commandBuffer?.present(drawable)
© www.soinside.com 2019 - 2024. All rights reserved.