我有以下代码,该代码模糊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()