【问题标题】:Metal Vertex Shader Warning in Swift 5Swift 5 中的金属顶点着色器警告
【发布时间】:2020-01-01 16:35:20
【问题描述】:

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

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 ... 获取这些缓冲区。
  • 完美!警告消失了!请将此作为答案发布,以便我标记。

标签: ios swift xcode metal vertex-shader


【解决方案1】:

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

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

【讨论】:

  • 您能否解释一下为什么我们需要确保对这些缓冲区的只读访问?背后的原因是什么?我对此很陌生,并试图理解基本概念。我也认为这会让你的答案更好。谢谢!
  • @alobaili 图形 API 通常对 CPU 和/或 GPU 是否可以读取/写入缓冲区非常感兴趣,因此它知道在哪里分配这些缓冲区。 const 的使用强化了 GPU 只想读取这些缓冲区的概念。
猜你喜欢
  • 2017-06-13
  • 1970-01-01
  • 1970-01-01
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-23
  • 1970-01-01
相关资源
最近更新 更多