我无法在手机中运行任何金属计算着色器



我正试图在iPhone SE.上运行我的金属程序

我尝试了许多关于线程PerThreadGroup和线程PerGrid大小的数字,所有这些数字都给了我这个错误:TLValidateFeatureSupport:3539: failed assertion `Dispatch Threads with Non-Uniform Threadgroup Size is only supported on MTLGPUFamilyApple4 and later.'

这是我的密码。

var threadsPerThreadGroup: MTLSize
var threadsPerGrid: MTLSize
computeCommandEncoder.setComputePipelineState(updateShader)
let w = updateShader.threadExecutionWidth
threadsPerThreadGroup = MTLSize(width: w, height: 1, depth: 1)
threadsPerGrid = MTLSize(width: Int(constants.bufferLength), height: 1, depth: 1)
if(frames % 2 == 0) {
computeCommandEncoder.setBuffer(buffer1, offset: 0, index: 0)
computeCommandEncoder.setBuffer(buffer2, offset: 0, index: 1)
} else {
computeCommandEncoder.setBuffer(buffer2, offset: 0, index: 0)
computeCommandEncoder.setBuffer(buffer1, offset: 0, index: 1)
}
computeCommandEncoder.setBytes(&constants, length: MemoryLayout<MyConstants>.stride, index: 2)
computeCommandEncoder.dispatchThreads(threadsPerGrid, threadsPerThreadgroup: threadsPerThreadGroup)
frames += 1

我使用的是iOS 13.4和XCode 11.4。

threadExecutionWidth的计算结果为32,且常数为。bufferLength为512。

仅当设备支持非均匀线程组大小时才使用[dispatchThreads]。

这句话没有尽可能清晰。这意味着dispatchThreads在A11之前的GPU上不起作用

如果你想要一个适用于所有设备的解决方案,你必须自己计算有多少线程组进入一个网格,并使用dispatchThreadgroups。

如果您想在代码中同时使用这两种方法,可以在运行时检测设备的功能集。

最新更新