Skip to content

Commit

Permalink
metal: texel buffers align their size according to device requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Jan 1, 2024
1 parent 0523aa6 commit af840bb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/modules/graphics/metal/Buffer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "Buffer.h"
#include "Graphics.h"

#include "common/memory.h"

namespace love
{
namespace graphics
Expand Down Expand Up @@ -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;
Expand All @@ -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.");
Expand Down

0 comments on commit af840bb

Please sign in to comment.