Understanding Buffer Memory Alignment

In the project template for using ARKit with Metal, there's a definition for the memory alignment of the buffer that holds the SharedUniforms structure. It is defined like this:

// The 16 byte aligned size of our uniform structures
let kAlignedSharedUniformsSize: Int = (MemoryLayout<SharedUniforms>.size & ~0xFF) + 0x100

If I understood correctly, this line of code does this:

  1. Calculates the size of the SharedUniforms structure in bytes
  2. Clears out the last 8 bits of the size representation
  3. Adds 256 bytes to the size

So if I'm not mistaken, this will round up the size of the SharedUniforms structure to the 256 bytes, and not 16 bytes as the comment suggests.

Is there something I've overlooked since I can't wrap my head around how will this align the size to 16 bytes?

Post not yet marked as solved Up vote post of BanSee Down vote post of BanSee
273 views