I have this declaration in my metal shader implementation:
struct InVertex {
packed_float3 pos;
packed_float2 textureCoord;
packed_uchar4 color;
};
Is there any speed penalty to use packed declaration ? If yes how to measure it ?
Based on this Metal Shading Language Specification
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.
MSL functions and arguments have these additional restrictions: The return type of a vertex or fragment function cannot include an element that is a packed vector type, matrix type, a structure type, a reference, or a pointer to a type.
You can use an array index to access components of a packed vector data type. However, you cannot use the .xyzw or .rgba selection syntax to access components of a packed vector data type.
Is there any speed penalty to use packed vertex structure?
It's described very well in this answer, in short you would benefit from using it, in terms of speed, especially when passing around a lot of data.