Metal Shader vertex attributes - cannot convert attribute from MTLAttributeFormatUInt to float1

Viewed 145

I have a shader that looks like this:

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

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

In my buffer I'm actually passing in a uint32_t for a_customIdx, so in my MTLVertexAttributeDescriptor I specify its type to be MTLAttributeFormatUInt. When I create the RenderPipelineState I get the error:

cannot convert attribute from MTLAttributeFormatUInt to float1

I get the same error if I use MTLAttributeFormatInt, but can successfully convert a MTLAttributeFormatUShort.

Why is this not a valid operation? According to the documentation for format, "Casting any MTLVertexFormat to a float or half is valid".

I know there are multiple ways I can get around this problem, but I'm curious about why this is invalid - perhaps there's something about alignments and byte sizes I'm missing here.

0 Answers
Related