The Obscure Question The Obscure Question - 7 months ago 42
iOS Question

Is it possible to use Metal data types in Objective-C?

I want to use some of the vector data types defined in Metal (such as

, docs) in Objective-C for my iOS app. However, I haven't been able to find any information about whether or not this is possible.


Those types are in <simd/SIMD.h> for C and C++ (and by extension, for Objective-C and Objective-C++).

They're actually the same types, with the same data layout, and the same associated functions, as those that you use from a Metal shader. So using them in CPU-side code where you expect to interface with Metal is a great idea. For example, you can define your own struct for vertex shader input in a C++ header file, then import that header and use the same struct definition in both your CPU code and the shader.

Note that the names differ a bit: e.g. uint2 is vector_uint2 in C, but simd::uint2 in C++.