From dab174b120d7597c3699fc61452136fd60d90f1f Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 24 Dec 2021 18:04:11 -0400 Subject: [PATCH] metal: fix a couple compiler warnings --- src/modules/graphics/metal/Metal.h | 3 ++- src/modules/graphics/metal/Shader.mm | 28 ++++++++++++++++++--------- src/modules/graphics/metal/Texture.mm | 16 ++++++++++----- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/modules/graphics/metal/Metal.h b/src/modules/graphics/metal/Metal.h index dd959d58d..81d763c51 100644 --- a/src/modules/graphics/metal/Metal.h +++ b/src/modules/graphics/metal/Metal.h @@ -36,13 +36,14 @@ class Metal { public: - struct PixelFormatDesc + struct API_AVAILABLE(macos(10.15), ios(13.0)) PixelFormatDesc { MTLPixelFormat format; bool swizzled = false; MTLTextureSwizzleChannels swizzle; }; + API_AVAILABLE(macos(10.15), ios(13.0)) static PixelFormatDesc convertPixelFormat(PixelFormat format, bool &isSRGB); }; // Metal diff --git a/src/modules/graphics/metal/Shader.mm b/src/modules/graphics/metal/Shader.mm index 321c7f8da..deb2af50d 100644 --- a/src/modules/graphics/metal/Shader.mm +++ b/src/modules/graphics/metal/Shader.mm @@ -926,9 +926,14 @@ id Shader::getCachedRenderPipeline(const RenderPipelineK MTLRenderPipelineColorAttachmentDescriptor *attachment = desc.colorAttachments[i]; - bool isSRGB = false; - auto formatdesc = Metal::convertPixelFormat(format, isSRGB); - attachment.pixelFormat = formatdesc.format; + if (@available(macOS 10.15, iOS 13, *)) + { + // We already don't really support metal on older systems, this just + // silences a compiler warning about it. + bool isSRGB = false; + auto formatdesc = Metal::convertPixelFormat(format, isSRGB); + attachment.pixelFormat = formatdesc.format; + } if (key.blend.enable) { @@ -959,12 +964,17 @@ id Shader::getCachedRenderPipeline(const RenderPipelineK auto dsformat = (PixelFormat) key.depthStencilFormat; if (isPixelFormatDepthStencil(dsformat)) { - bool isSRGB = false; - auto formatdesc = Metal::convertPixelFormat(dsformat, isSRGB); - if (isPixelFormatDepth(dsformat)) - desc.depthAttachmentPixelFormat = formatdesc.format; - if (isPixelFormatStencil(dsformat)) - desc.stencilAttachmentPixelFormat = formatdesc.format; + if (@available(macOS 10.15, iOS 13, *)) + { + // We already don't really support metal on older systems, this just + // silences a compiler warning about it. + bool isSRGB = false; + auto formatdesc = Metal::convertPixelFormat(dsformat, isSRGB); + if (isPixelFormatDepth(dsformat)) + desc.depthAttachmentPixelFormat = formatdesc.format; + if (isPixelFormatStencil(dsformat)) + desc.stencilAttachmentPixelFormat = formatdesc.format; + } } { diff --git a/src/modules/graphics/metal/Texture.mm b/src/modules/graphics/metal/Texture.mm index ca3ffb107..ba2148c67 100644 --- a/src/modules/graphics/metal/Texture.mm +++ b/src/modules/graphics/metal/Texture.mm @@ -52,17 +52,23 @@ Texture::Texture(love::graphics::Graphics *gfx, id device, const Sett int w = pixelWidth; int h = pixelHeight; - auto formatdesc = Metal::convertPixelFormat(format, sRGB); - desc.width = w; desc.height = h; desc.depth = depth; desc.arrayLength = layers; desc.mipmapLevelCount = mipmapCount; desc.textureType = getMTLTextureType(texType, 1); - desc.pixelFormat = formatdesc.format; - if (formatdesc.swizzled) - desc.swizzle = formatdesc.swizzle; + if (@available(macOS 10.15, iOS 13, *)) + { + // We already don't really support metal on older systems, this just + // silences a compiler warning about it. + auto formatdesc = Metal::convertPixelFormat(format, sRGB); + desc.pixelFormat = formatdesc.format; + if (formatdesc.swizzled) + desc.swizzle = formatdesc.swizzle; + } + else + throw love::Exception("Metal backend is only supported on macOS 10.15+ and iOS 13+."); desc.storageMode = MTLStorageModePrivate; if (readable)