我有一个MPSImageGaussianBlur
对象在计算传递的每一帧上进行工作(模糊中间纹理的内容)。渲染管道中的MPSImageGaussianBlur
虽然该应用程序仍以60fps运行没有问题,但启用模糊通行证后,CPU使用率增加了约15%。我想知道这是否正常?
我只是好奇MPSImageGaussianBlur
的encodeToCommandBuffer:
操作将会看到如此多的CPU利用率。在我的(虽然幼稚)的理解,我想有也只是沿着线的一些简单的编码:
MPSImageGaussianBlur.encodeToCommandBuffer:
伪方法:
func encodeToCommandBuffer(commandBuffer: MTLCommandBuffer, sourceTexture: MTLTexture, destinationTexture: MTLTexture) {
let encoder = commandBuffer.computeCommandEncoder()
encoder.setComputePipelineState(...)
encoder.setTexture(sourceTexture, atIndex: 0)
encoder.setTexture(destinationTexture, atIndex: 1)
// kernel weights would be built at initialization and
// present here as a `kernelWeights` property
encoder.setTexture(self.kernelWeights, atIndex: 2)
let threadgroupsPerGrid = ...
let threadsPerThreadgroup = ...
encoder.dispatchThreadgroups(threadgroupsPerGrid, threadsPerThreadgroup: threadsPerThreadgroup)
encoder.endEncoding()
}
大部分的性能魔法'将在计算内核函数中运行的算法上实现。我可以理解这一点,因为性能(在GPU上)非常棒,独立于blurRadius,我初始化了MPSImageGaussianBlur
。
关于我的具体设置一些可能不相关的细节:
MPSImageGaussianBlur
与模糊半径8像素初始化。- 我模糊的纹理是128乘128像素。
- 在MTKViewDelegate的
drawInMTKView:
方法中执行所有渲染。
我希望这个问题有点清楚,它的意图。
可以肯定的是,您只是创建了一个'MPSImageGaussianBlur'实例,然后跨帧复用它,是否正确? – warrenm
是的,只是一个实例 – jameslintaylor
哪个设备和iOS版本是你看到的这种行为? – warrenm