Reputation: 47354
I'm trying to experiment with using smaller data structures to store Metal vertex data. The Particle
struct is shared between Swift and Metal, but am getting the following error:
Unknown type name 'simd_half3'; did you mean 'simd_char3'
What do I need to import to get over this compilation error?
(The same struct compiles when pasted directly into the metal shaders file). Is it because there is no half
type in Swift?
ShaderTypes.h
- C Header file
#ifndef ShaderTypes_h
#define ShaderTypes_h
#include <simd/simd.h>
struct Particle {
simd_float3 floatTuple; // works fine
simd_char3 charTuple; // works fine
simd_half3 halfTuple; // Unknown type name 'simd_half3'; did you mean 'simd_char3'
};
#endif /* ShaderTypes_h */
All these types are defined in the same file, and using the command-click, I can jump to their definition (so the editor knows about the types), but I still get that build error.
Upvotes: 1
Views: 850
Reputation: 4378
There is a half
type in Swift, it's Float16
. As for simd types, in Swift, simd_floatN
is just a typealias
for SIMDN<Float>
.
It's defined like this: public typealias simd_float3 = SIMD3<Float>
Since Swift supports Float16
now for half precision floats, you can just pass it to SIMDN
generic, since it's defined as following (SIMD3
for example)
@frozen public struct SIMD3<Scalar> : SIMD where Scalar : SIMDScalar
and there's an extension
extension Float16 : SIMDScalar
to make Float16
conform to SIMDScalar
So you can use SIMDN<Float16>
and if you want you can probably even typealias it in your code.
Upvotes: 1
Reputation: 10408
I think the problem is that there was no Half
type in Swift until recently (there is Float16
now with Xcode 12). But there still seems to be no simd_halfN
, at least it's not listed in the simd/vector_types.h
header.
The easiest option for you is probably to just work with float
for now.
Upvotes: 1