From fc0cb61c6cb5ab3040e1a36d082f24d8999d72d9 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Wed, 1 Jul 2026 14:03:20 -0300 Subject: [PATCH] metal: improve canvas creation performance. Prefer initializing textures by using a render target clear rather than a blank data upload, when possible. --- src/modules/graphics/metal/Texture.mm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/graphics/metal/Texture.mm b/src/modules/graphics/metal/Texture.mm index 3200be440..c203e7a3e 100644 --- a/src/modules/graphics/metal/Texture.mm +++ b/src/modules/graphics/metal/Texture.mm @@ -147,15 +147,6 @@ Texture::Texture(love::graphics::Graphics *gfxbase, id device, const shouldgeneratemips = true; continue; } - else if (getMSAA() <= 1 && !isPixelFormatDepthStencil(format) && !isPixelFormatCompressed(format)) - { - // Initialize to transparent black. - if (emptydata.empty()) - emptydata.resize(getPixelFormatSliceSize(format, w, h)); - - Rect r = {0, 0, getPixelWidth(mip), getPixelHeight(mip)}; - uploadByteData(emptydata.data(), emptydata.size(), mip, slice, r); - } else if (isRenderTarget()) { // Clear to transparent black. @@ -201,6 +192,15 @@ Texture::Texture(love::graphics::Graphics *gfxbase, id device, const id encoder = [cmd renderCommandEncoderWithDescriptor:passdesc]; [encoder endEncoding]; } + else if (getMSAA() <= 1 && !isPixelFormatDepthStencil(format) && !isPixelFormatCompressed(format)) + { + // Initialize to transparent black. + if (emptydata.empty()) + emptydata.resize(getPixelFormatSliceSize(format, w, h)); + + Rect r = {0, 0, getPixelWidth(mip), getPixelHeight(mip)}; + uploadByteData(emptydata.data(), emptydata.size(), mip, slice, r); + } else { // Shouldn't be possible to get here.