Swift 5中的金属顶点着色器警告

时间:2019-08-28 12:35:24

标签: ios swift xcode metal vertex-shader

我从Apple的示例代码中获得了这个直通顶点着色器:

{
  "dependencies": {
    "cool-lib": "1.0.0"
  }
}

这在Swift 4 / Xcode 10 / iOS 12中有效。现在,我在Swift 5 / Xcode 11 / iOS 13中,收到以下警告:

vertex VertexIO vertexPassThrough(device packed_float4 *pPosition  [[ buffer(0) ]],
                                  device packed_float2 *pTexCoords [[ buffer(1) ]],
                                  uint                  vid        [[ vertex_id ]])
{
    VertexIO outVertex;

    outVertex.position = pPosition[vid];
    outVertex.textureCoord = pTexCoords[vid];

    return outVertex;
}

1 个答案:

答案 0 :(得分:5)

您需要确保着色器只能从那些缓冲区读取,因此您需要将声明更改为const device

vertex VertexIO vertexPassThrough(const device packed_float4 *pPosition  [[ buffer(0) ]],
                                  const device packed_float2 *pTexCoords [[ buffer(1) ]],
                                  uint                  vid        [[ vertex_id ]])
{
...
}