From 792690b73dc0c9f84c67c118e295cae1d04195b7 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Fri, 24 Jul 2026 17:03:15 -0300 Subject: [PATCH] metal: support shader atomics for int/uint textures, on macOS 14+ and iOS 17+. --- src/modules/graphics/metal/Graphics.mm | 5 +++++ src/modules/graphics/metal/Shader.mm | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/metal/Graphics.mm b/src/modules/graphics/metal/Graphics.mm index c0b8cdcc3..4650e7e9d 100644 --- a/src/modules/graphics/metal/Graphics.mm +++ b/src/modules/graphics/metal/Graphics.mm @@ -2025,6 +2025,11 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage) case PIXELFORMAT_RGB10A2_UINT: // If MSAA support for int formats is added this should be split up. flags |= sample | rt | computewrite; + if (format == PIXELFORMAT_R32_INT || format == PIXELFORMAT_R32_UINT) + { + if (@available(macOS 14.0, iOS 17.0, *)) + flags |= PIXELFORMATUSAGEFLAGS_SHADERATOMICS; + } break; case PIXELFORMAT_RGBA4_UNORM: diff --git a/src/modules/graphics/metal/Shader.mm b/src/modules/graphics/metal/Shader.mm index b476f2ae1..15bada46d 100644 --- a/src/modules/graphics/metal/Shader.mm +++ b/src/modules/graphics/metal/Shader.mm @@ -537,7 +537,10 @@ void Shader::compileFromGLSLang(id device, const glslang::TProgram &p } CompilerMSL::Options options; - options.set_msl_version(2, 1); + if (@available(macOS 14.0, iOS 17.0, *)) + options.set_msl_version(3, 1); // For image atomics. + else + options.set_msl_version(2, 1); options.texture_buffer_native = true; #ifdef LOVE_IOS options.platform = CompilerMSL::Options::iOS; @@ -556,8 +559,9 @@ void Shader::compileFromGLSLang(id device, const glslang::TProgram &p MTLCompileOptions *opts = [MTLCompileOptions new]; - // Silences warning. We already only use metal on these OS versions. - if (@available(macOS 10.14, iOS 12.0, *)) + if (@available(macOS 14.0, iOS 17.0, *)) + opts.languageVersion = MTLLanguageVersion3_1; // For image atomics. + else opts.languageVersion = MTLLanguageVersion2_1; NSError *err = nil;