I have trouble understanding something about simd_packed vectors in the simd module in Swift. I use the example of float4, I hope someone can help.
My understanding is that simd_float4
is a typealias
of SIMD4< Float>
, and MemoryLayout<SIMD4< Float>>.alignment = 16
(bytes), hence MemoryLayout<simd_float4>.alignment = 16
. Makes sense.
But the following I do not understand: simd_packed_float4
is also a typealias
of SIMD4<Float>
. And so MemoryLayout<simd_packed_float4>.alignment = 16
.
What is the point of the "packed" in simd_packed_float4
, then? Where is the "relaxed alignment" that the documentation talks about?
In the Metal Shader Language Specification (Version 2.4) (
https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf)
in Table 2.4 (p.28), it says the alignment of packed_float4
is 4 (which is also the alignment of the scalar type, float), so this IS a "relaxed alignment" (as compared to the 16). That makes sense on its own, but how do I reconcile this to the above (simd_packed_float4
is typealias of SIMD4<Float>
and MemoryLayout<simd_packed_float4> = 16
)?