2

I'm trying to write vertex descriptor for my vertex shader which takes following struct as stage_in input.

struct VertexIn {
      float2x2 foo;
}

vertex float4 vertexShader(const VertexIn in [[stage_in]]) {...}

Now when defining vertex descriptor's attribute what should be the MTLVertexFormat? vertexDescriptor.attributes[0].format = ???

I went through the documentation, I didn't find any enum case for Matrices. Is it fine if say set format as float2 and give size 2 * size of float2?

Hamid Yusifli
  • 9,688
  • 2
  • 24
  • 48
ImShrey
  • 380
  • 4
  • 12

1 Answers1

2

According The Metal Feature Set Tables:


You can declare only one argument of the vertex, fragment, or kernel function with the [[stage_in]] attribute. For a user-defined structure declared with the [[stage_in]] attribute, the members of the structure can be:

  • A scalar integer or floating-point value.
  • A vector of integer or floating-point values.
  • An interpolant<T,P> value for fragment function input.

You cannot use the stage_in attribute to declare members of the structure that are packed vectors, matrices, structures, bitfields, references or pointers to a type, or arrays of scalars, vectors, or matrices.


Hamid Yusifli
  • 9,688
  • 2
  • 24
  • 48
  • Hmm nice find, somehow I missed last part, but now I wonder why matrices are not allowed as attributes? Upon more digging I found similar case for OpenGL as well, so is there HW design/optimization constraint on this? – ImShrey Aug 26 '22 at 06:38