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 Shading Language Specification, there's a pretty clear table of which types are supported within a Metal shader file. However, there's plenty of sample code available that seems to use additional types that are part of SIMD. On the macOS (Objective-C) side of things, the Metal types are not available but the SIMD ones are and I'm not sure which ones I'm supposed to be used.
For example:
In the Metal Spec, there's float2
that is described as a "vector" data type representing two floating components.
On the app side, the following all seem to be used or represented in some capacity:
float2
, which istypedef ::simd_float2 float2
in vector_types.hNoted: "In C or Objective-C, this type is available as simd_float2."
vector_float2
, which istypedef simd_float2 vector_float2
Noted: "This type is deprecated; you should use simd_float2 or simd::float2 instead"
simd_float2
, which istypedef __attribute__((__ext_vector_type__(2))) float simd_float2
::simd_float2
andsimd::float2
?
A similar situation exists for matrix types:
matrix_float4x4
,simd_float4x4
,::simd_float4x4
andfloat4x4
,
Could someone please shed some light on why there are so many typedefs with seemingly overlapping functionality? If you were writing a new application today (2018) in Objective-C / Objective-C++, which type should you use to represent two floating values (x/y) and which type for matrix transforms that can be shared between app code and Metal?