MTKView: тип выражения неоднозначен без дополнительного контекста в commandBuffer.present - PullRequest
2 голосов
/ 11 января 2020

Я получаю ошибку времени компиляции при установке drawable на объекте буфера команд.

Ниже приведена моя функция, которая вызывается из 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?

1 Ответ

3 голосов
/ 11 января 2020

Я думаю, что вам не хватает ?. Исправить:

commandBuffer?.present(drawable)
...