diff --git a/src/modules/graphics/metal/Buffer.mm b/src/modules/graphics/metal/Buffer.mm index 20394d0aa..c3b964ff2 100644 --- a/src/modules/graphics/metal/Buffer.mm +++ b/src/modules/graphics/metal/Buffer.mm @@ -21,6 +21,8 @@ #include "Buffer.h" #include "Graphics.h" +#include "common/memory.h" + namespace love { namespace graphics @@ -65,6 +67,19 @@ static MTLPixelFormat getMTLPixelFormat(DataFormat format) size = getSize(); arraylength = getArrayLength(); + if (usageFlags & BUFFERUSAGEFLAG_TEXEL) + { + if (@available(iOS 12, macOS 10.14, *)) + { + MTLPixelFormat pixformat = getMTLPixelFormat(getDataMember(0).decl.format); + NSUInteger alignment = 1; + if (pixformat != MTLPixelFormatInvalid) + alignment = [device minimumTextureBufferAlignmentForPixelFormat:pixformat]; + + size = alignUp(size, (size_t) alignment); + } + } + MTLResourceOptions opts = 0; if (settings.dataUsage == BUFFERDATAUSAGE_READBACK) opts |= MTLResourceStorageModeShared; @@ -83,8 +98,6 @@ static MTLPixelFormat getMTLPixelFormat(DataFormat format) { if (@available(iOS 12, macOS 10.14, *)) { - // TODO: minimumTextureBufferAlignmentForPixelFormat - MTLPixelFormat pixformat = getMTLPixelFormat(getDataMember(0).decl.format); if (pixformat == MTLPixelFormatInvalid) throw love::Exception("Could not create Metal texel buffer: invalid format.");