Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metal Vertex Shader Warning in Swift 5

I got this passthrough vertex shader I used from Apple's sample code:

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;
}

This worked in Swift 4/Xcode 10/iOS 12. Now I with Swift 5/Xcode 11/iOS 13, I get this warning:

writable resources in non-void vertex function
like image 583
Gizmodo Avatar asked Aug 28 '19 12:08

Gizmodo


1 Answers

You need to ensure the shader can only read from those buffers, so you need to change the declaration to const device:

vertex VertexIO vertexPassThrough(const device packed_float4 *pPosition  [[ buffer(0) ]],
                                  const device packed_float2 *pTexCoords [[ buffer(1) ]],
                                  uint                  vid        [[ vertex_id ]])
{
...
}
like image 64
trojanfoe Avatar answered Oct 24 '22 09:10

trojanfoe