When working with Metal, I find there\'s a bewildering number of types and it\'s not always clear to me which type I should be using in which context.
In Apple\'s Metal
The types with vector_
and matrix_
prefixes have been deprecated in favor of those with the simd_
prefix, so the general guidance (using float4
as an example) would be:
simd_float4
type. (You have to include the prefix unless you provide your own typedef
, since C doesn't have namespaces.)simd::float4
type, which you can shorten to float4
by using namespace simd;
.float4
type, since float4
is a fundamental type in the Metal Shading Language [1].float4
type, since the simd_
types are typealiased to shorter names.float4
and related types have been deprecated in favor of SIMD4
and related types.These types are all fundamentally equivalent, and all have the same size and alignment characteristics so you can use them across languages. That is, in fact, one of the design goals of the simd framework.
I'll leave a discussion of packed types to another day, since you didn't ask.
[1] Metal is an unusual case since it defines float4
in the global namespace, then imports it into the metal
namespace, which is also exported as the simd
namespace. It additionally aliases float4
as vector_float4
. So, you can use any of the above names for this vector type (except simd_float4
). Prefer float4
.