I am going through the Metal iOS Swift example trying to understand the triple buffering practice they suggest. This is shown inside of the demo for the uniform animations.
As I understand it aligned memory simply starts at a specefic increment that is a multiple of some byte amount that the device really likes. My confusion is this line of code
// The 256 byte aligned size of our uniform structure
let alignedUniformsSize = (MemoryLayout<Uniforms>.size & ~0xFF) + 0x100
they use it to find the size and byte of the Uniforms struct. I am confused about why there are binary operations here I am really not sure what they do.
If it helps this aligned size is used to create a buffer like this. I am fairly sure that buffer allocates byte aligned memory automatically and is henceforth used as the memory storage location for the uniforms.
let buffer = self.device.makeBuffer(length:alignedUniformsSize * 3, options:[MTLResourceOptions.storageModeShared])
So essentially rather than going through the trouble of allocating byte aligned memory by yourself they let metal do it for them.
Is there any reason that the strategy they used when they did let allignedUniformsSize = would not work for other types such as Int or Float etc?