GS/Metal: Align texture upload pitch to 32 bytes

This commit is contained in:
Stenzek 2023-03-09 16:39:27 +10:00 committed by lightningterror
parent 98c611e404
commit b219ee9049
2 changed files with 5 additions and 4 deletions

View File

@ -93,9 +93,6 @@ public:
void Flush() override;
private:
// TODO: Is there an optimal transfer pitch alignment for Metal?
static constexpr u32 PITCH_ALIGNMENT = 32;
GSDownloadTextureMTL(GSDeviceMTL* dev, MRCOwned<id<MTLBuffer>> buffer, u32 width, u32 height, GSTexture::Format format);
GSDeviceMTL* m_dev;

View File

@ -17,10 +17,14 @@
#include "GS/Renderers/Metal/GSTextureMTL.h"
#include "GS/Renderers/Metal/GSDeviceMTL.h"
#include "GS/GSPerfMon.h"
#include "common/Align.h"
#include "common/Console.h"
#ifdef __APPLE__
// Uploads/downloads need 32-byte alignment for AVX2.
static constexpr u32 PITCH_ALIGNMENT = 32;
GSTextureMTL::GSTextureMTL(GSDeviceMTL* dev, MRCOwned<id<MTLTexture>> texture, Type type, Format format)
: m_dev(dev)
, m_texture(std::move(texture))
@ -119,7 +123,7 @@ bool GSTextureMTL::Map(GSMap& m, const GSVector4i* _r, int layer)
GSVector4i r = _r ? *_r : GSVector4i(0, 0, m_size.x, m_size.y);
u32 block_size = GetCompressedBlockSize();
u32 blocks_wide = (r.width() + block_size - 1) / block_size;
m.pitch = blocks_wide * GetCompressedBytesPerBlock();
m.pitch = Common::AlignUpPow2(blocks_wide * GetCompressedBytesPerBlock(), PITCH_ALIGNMENT);
if (void* buffer = MapWithPitch(r, m.pitch, layer))
{
m.bits = static_cast<u8*>(buffer);