Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift 5中的金属顶点着色器警告_Ios_Swift_Xcode_Metal_Vertex Shader - Fatal编程技术网

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

Ios Swift 5中的金属顶点着色器警告,ios,swift,xcode,metal,vertex-shader,Ios,Swift,Xcode,Metal,Vertex Shader,我从苹果的示例代码中得到了这个穿透顶点着色器: vertex VertexIO vertexPassThrough(device packed_float4 *pPosition [[ buffer(0) ]], device packed_float2 *pTexCoords [[ buffer(1) ]], uint vi

我从苹果的示例代码中得到了这个穿透顶点着色器:

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;
}
这在Swift 4/Xcode 10/iOS 12中起作用。现在我使用Swift 5/Xcode 11/iOS 13,我得到以下警告:

writable resources in non-void vertex function

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

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

尝试
const device…
查找这些缓冲区。完美!警告消失了!请将此作为答案发布,以便我可以标记。您能解释一下为什么我们需要确保对这些缓冲区的只读访问吗?这背后的原因是什么?我对这一点还不熟悉,并试图理解基本概念。我也认为这会让你的答案更好。谢谢@通常,alobaili图形API对CPU和/或GPU是否可以读/写缓冲区非常感兴趣,因此它知道在哪里分配这些缓冲区。
const
的使用强化了GPU只希望读取这些缓冲区的概念。