#std::mem::size_of::<Transform>() returns 48 bytes instead of 40

14 messages · Page 1 of 1 (latest)

oblique ginkgo
#

Does a transform store more then a Position, Rotation, and Size?

cerulean quarry
#
pub struct Transform {
    /// Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering.
    ///
    /// See the [`translations`] example for usage.
    ///
    /// [`translations`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/translation.rs
    pub translation: Vec3,
    /// Rotation of the entity.
    ///
    /// See the [`3d_rotation`] example for usage.
    ///
    /// [`3d_rotation`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/3d_rotation.rs
    pub rotation: Quat,
    /// Scale of the entity.
    ///
    /// See the [`scale`] example for usage.
    ///
    /// [`scale`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/scale.rs
    pub scale: Vec3,
}
#

this is its definition

proper tiger
#

there's probably 4 bytes of padding after each Vec3 to keep the fields aligned to 8 byte offsets

cerulean quarry
#

I find that unlikely actually

#

for vec3a, yes

#

but they should be 4-aligned, since they're vec3<f32>

#

quat, however, is 16-byte aligned

#

I'd think rust could reorder that to guarantee 40 bytes anyway but if not maybe this?:
[ 12 ][ pad: 4][16][12] = 44?

#

oh wait

#

Vec3 can get repr(simd) which almost definitely bumps align to 16

#

then it's 16 + 16 + 16 = 48