首页 > 解决方案 > Metal Shader 顶点属性 - 无法将属性从 MTLAttributeFormatUInt 转换为 float1

问题描述

我有一个看起来像这样的着色器:

struct VertexIn {
  float a_customIdx [[attribute(0)]];
  ...
};

vertex vec4 vertex_func(VertexIn v_in [[stage_in]], ...) {...}

在我的缓冲区中,我实际上传递了一个uint32_tfor a_customIdx,所以在我的缓冲区中,MTLVertexAttributeDescriptor我将其类型指定为MTLAttributeFormatUInt。当我创建RenderPipelineState我得到错误:

cannot convert attribute from MTLAttributeFormatUInt to float1

如果我使用 . 我会得到相同的错误MTLAttributeFormatInt,但可以成功转换MTLAttributeFormatUShort.

为什么这不是一个有效的操作?根据format 的文档,“将任何 MTLVertexFormat 转换为 float 或 half 是有效的”。

我知道有多种方法可以解决这个问题,但我很好奇为什么这是无效的——也许我在这里遗漏了一些关于对齐和字节大小的东西。

标签: iosgraphicsmetalmetalkit

解决方案


推荐阅读