金属命令缓冲区最适合模糊处理,然后显示MTLTexture

时间:2018-08-02 11:47:22

标签: swift gpu metal

我有以下代码,该代码模糊MTLTexture然后将其渲染到MTKView,但是命令缓冲区的顺序是否最佳?

blur是Metal Performance Shader,计算着色器仅编写纹理,这是一个简单的传递。

var t: MTLTexture? = mtlLayer.currentSceneDrawable?.texture


    let drawableTexture: MTLTexture? = metalView.currentDrawable!.texture

    let commandBuffer: MTLCommandBuffer = commandQueue.makeCommandBuffer()!


    blur.encode(commandBuffer: commandBuffer, inPlaceTexture: &t!, fallbackCopyAllocator: nil)

    let commandEncoder = commandBuffer.makeComputeCommandEncoder()!
    commandEncoder.setComputePipelineState(pipelineState)
    commandEncoder.setTexture(t, index: 0)
    commandEncoder.setTexture(drawableTexture, index: 1)
    commandEncoder.dispatchThreadgroups(threadgroupsPerGrid, threadsPerThreadgroup: threadsPerThreadgroup)
    commandEncoder.endEncoding()

    commandBuffer.present(metalView.currentDrawable!)
    metalView.draw()

    commandBuffer.commit();
    commandBuffer.waitUntilCompleted()

0 个答案:

没有答案