This information is from here.
float4has 16byte alignment . This means that a memory address of this type (for example, 0x12345670) will be divided by 16(as well as the last hexadecimal digit 0).
packed_float4on the other hand has alignment 4 bytes. The last digit of the address will be 0, 4, 8orc
. , 2 float 1 float4/packed_float4:
struct A{
float x, y;
float4 z;
}
struct B{
float x, y;
packed_float4 z;
}
A: float4 16, float4 float s, 8 y z. A :
Address | 0x200 | 0x204 | 0x208 | 0x20c | 0x210 | 0x214 | 0x218 | 0x21c |
Content | x | y | - | - | z1 | z2 | z3 | z4 |
^Has to be 16 byte aligned
B: packed_float4 4, , float, float :
Address | 0x200 | 0x204 | 0x208 | 0x20c | 0x210 | 0x214 |
Content | x | y | z1 | z2 | z3 | z4 |
, A 32 , B 24 . , A 8 . .
, float4 , , GPU 4 , packed_float4 s, packed_float4 . - , .
: Swift :
struct S {
let x, y: Float
let z : (Float, Float, Float, Float)
}
B , A. packed_floatN.
, packed_float3, packed_short2, ect.