Ios 由于执行期间出错,命令缓冲区的执行被中止

Ios 由于执行期间出错,命令缓冲区的执行被中止,ios,swift,metal,metalkit,Ios,Swift,Metal,Metalkit,我已经在这上面呆了一段时间了;这不是一个特别昂贵的着色器(至少,基于我对金属的有限经验),但在前几帧中,我仍然得到了以下信息: Execution of the command buffer was aborted due to an error during execution. Caused GPU Hang Error (IOAF code 3) 然后我在所有后续帧中得到这个: Execution of the command buffer was aborted due to an e

我已经在这上面呆了一段时间了;这不是一个特别昂贵的着色器(至少,基于我对金属的有限经验),但在前几帧中,我仍然得到了以下信息:

Execution of the command buffer was aborted due to an error during execution. Caused GPU Hang Error (IOAF code 3)
然后我在所有后续帧中得到这个:

Execution of the command buffer was aborted due to an error during execution. Ignored (for causing prior/excessive GPU errors) (IOAF code 4)
这是顶点着色器,它实际上什么都不做:

vertex VertexOut viewportProgram(uint vertexID [[ vertex_id ]],
                                 constant float2 *positions [[ buffer(0) ]],
                                 constant float2 *texcoords [[ buffer(1) ]]) {
    VertexOut out;

    out.position.xy = positions[vertexID];
    out.position.z = 0.0; // Only 2D; no depth
    out.position.w = 1.0; // Only 2D; no perspective divide

    out.texcoord = texcoords[vertexID];

    return out;
}
这是我的片段着色器,它将颜色从YUV转换为RGB:

fragment float4 colorConvertProgram(VertexOut in [[stage_in]],
                                texture2d<float, access::sample> yTexture [[ texture(0) ]],
                                texture2d<float, access::sample> uvTexture [[ texture(1) ]],
                                sampler textureSampler [[ sampler(0) ]]) {


    float3 colorOffset = float3(-(16.0/255.0), -0.5, -0.5);
    float3x3 colorMatrix = float3x3(float3(1.164,  0.000,  1.596),
                                    float3(1.164, -0.392, -0.813),
                                    float3(1.164,  2.017,  0.000));

    float3 yuv = float3(yTexture.sample(textureSampler, in.texcoord).r,
                    uvTexture.sample(textureSampler, in.texcoord).rg);
    float3 rgb = (yuv + colorOffset) * colorMatrix;

    return float4(rgb, 1.0);
}

您是手动触发绘图代码,还是由metal view代理自动触发?不知道这是否是问题所在,但znear值无效。来自:“znear和zfar的值必须分别在0.0和1.0之间。”@miweinst我正在触发它manually@KenThomases我不知道,谢谢!不幸的是,这不是问题,虽然,仍然有相同的错误信息,我应该说,一个GPU挂起总是一个驱动程序错误。无论提交什么任务,用户级进程都不能挂起GPU。所以,寻找解决方法是有意义的,这并不是你的错。你应该向苹果公司提交一个bug。
    let samplerDescriptor = MTLSamplerDescriptor()
    samplerDescriptor.minFilter = .linear
    samplerDescriptor.mipFilter = .linear
    samplerDescriptor.sAddressMode = .clampToZero
    samplerDescriptor.tAddressMode = .clampToZero
    let sampler = device.makeSamplerState(descriptor: samplerDescriptor)

    renderEncoder.setViewport(MTLViewport(originX: 0.0, originY: 0.0,
                                          width: Double(bounds.width),
                                          height: Double(bounds.height),
                                          znear: -1.0, zfar: 1.0))
    renderEncoder.setRenderPipelineState(renderPipelineState)
    renderEncoder.setVertexBuffer(vertexPositionBuffer, offset: 0, index: 0)
    renderEncoder.setVertexBuffer(vertexTexcoordBuffer, offset: 0, index: 1)
    renderEncoder.setFragmentTexture(yTexture, index: 0)
    renderEncoder.setFragmentTexture(uvTexture, index: 1)
    renderEncoder.setFragmentSamplerState(sampler, index: 0)
    renderEncoder.drawPrimitives(type: .triangleStrip, vertexStart: 0, vertexCount: 4)
    renderEncoder.endEncoding()

    commandBuffer.present(drawable)
    commandBuffer.commit()