From 3b2d4e7e37475caa8dde187aac6f4a0f04bf247d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Nov 2026 20:53:27 +0530 Subject: [PATCH] Bump generated MSL version to that used on macOS 14 --- gpu/metal/driver.m | 2 +- gpu/metal/pipelines.m | 4 ++-- gpu/metal/version.h | 5 +++-- kitty/shaders/slang.py | 9 ++++++--- kitty_tests/slang.py | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/gpu/metal/driver.m b/gpu/metal/driver.m index 8f120fb36..e2f56b50e 100644 --- a/gpu/metal/driver.m +++ b/gpu/metal/driver.m @@ -124,7 +124,7 @@ connect_to_display(void *driver, const GPUNativeWindow *display) { set_error(d, "No Metal capable GPU found"); return false; } - // MSL 2.4 needs macOS 12, every Mac that can run it supports the Mac2 or Apple7 GPU families. + // MSL 3.1 needs macOS 14, every Mac that can run it supports the Mac2 or Apple7 GPU families. // Mac2 is deprecated from macOS 27, which no longer supports the Intel Macs that need it. #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" diff --git a/gpu/metal/pipelines.m b/gpu/metal/pipelines.m index e98258dc9..1541ae948 100644 --- a/gpu/metal/pipelines.m +++ b/gpu/metal/pipelines.m @@ -16,7 +16,7 @@ #include "version.h" // The language version passed to the MSL compiler, see compile_library() -_Static_assert(MSL_VERSION == 24, "Update the MTLLanguageVersion used for compiling shaders"); +_Static_assert(MSL_VERSION == 31, "Update the MTLLanguageVersion used for compiling shaders"); #define AS_PIPELINE(handle) ((Pipeline *)(uintptr_t)(handle)) #define AS_LAYOUT(handle) ((VertexLayout *)(uintptr_t)(handle)) @@ -127,7 +127,7 @@ compile_library(Driver *d, const GPUShaderSource *s) { return nil; } MTLCompileOptions *opts = [[[MTLCompileOptions alloc] init] autorelease]; - [opts setLanguageVersion:MTLLanguageVersion2_4]; + [opts setLanguageVersion:MTLLanguageVersion3_1]; // OpenGL on Apple GPUs is implemented on top of Metal and uses fast // math, so that is needed for rendering to match it exactly, for // example in the pow() of the gamma adjustments of text. Relaxed math diff --git a/gpu/metal/version.h b/gpu/metal/version.h index 1653e0a2f..213a8e38e 100644 --- a/gpu/metal/version.h +++ b/gpu/metal/version.h @@ -8,5 +8,6 @@ #pragma once // The version of the Metal Shading Language shaders are compiled to, as -// major * 10 + minor. MSL 2.4 is supported from macOS 12, kitty requires macOS 14. -#define MSL_VERSION 24 +// major * 10 + minor. MSL 3.1 is the version supported by macOS 14, the +// minimum macOS version required by kitty. +#define MSL_VERSION 31 diff --git a/kitty/shaders/slang.py b/kitty/shaders/slang.py index a02499ba0..73da2fcdc 100644 --- a/kitty/shaders/slang.py +++ b/kitty/shaders/slang.py @@ -208,7 +208,7 @@ def variant_name(variant: dict[str, str], default: dict[str, str]) -> str: class ShaderTarget(NamedTuple): # The shader target consumed by a GPU driver, identified by strings of the # form family-version, for example glsl-140, spirv-16 (SPIR-V 1.6) or - # msl-24 (Metal Shading Language 2.4). Built-in shaders are compiled for + # msl-31 (Metal Shading Language 3.1). Built-in shaders are compiled for # the targets of the drivers being built, at build time, and custom # shaders for the target of the loaded driver, at runtime. GLSL targets # produce one text file per stage, SPIR-V and MSL targets a single module, @@ -1208,9 +1208,12 @@ def metal_compiler_available() -> bool: def msl_validation_command(target: ShaderTarget, path: str) -> list[str]: - # Compile the MSL with the Metal compiler, discarding the output + # Compile the MSL with the Metal compiler, discarding the output. From + # Metal 3.0 the language standard is shared by all platforms and so has no + # platform prefix. major, minor = divmod(target.version, 10) - return ['xcrun', '-sdk', 'macosx', 'metal', f'-std=macos-metal{major}.{minor}', '-c', path, '-o', os.devnull] + std = f'metal{major}.{minor}' if major >= 3 else f'macos-metal{major}.{minor}' + return ['xcrun', '-sdk', 'macosx', 'metal', f'-std={std}', '-c', path, '-o', os.devnull] # }}} diff --git a/kitty_tests/slang.py b/kitty_tests/slang.py index 1df661742..477334ec5 100644 --- a/kitty_tests/slang.py +++ b/kitty_tests/slang.py @@ -162,7 +162,7 @@ struct vertex_main_Result_0 # Slang assigns Metal argument table indices itself, they are passed # as native names, while the slots remain those of SHADER_BINDING_SLOTS - target = ShaderTarget.parse('msl-24') + target = ShaderTarget.parse('msl-31') self.assertTrue(target.is_msl and target.is_single_module) scalar = {'kind': 'scalar', 'scalarType': 'float32'} @@ -197,7 +197,7 @@ struct vertex_main_Result_0 'entryPoints': [{'name': 'vertex_main', 'stage': 'vertex', 'parameters': []}, {'name': 'fragment_main', 'stage': 'fragment', 'parameters': []}], } m = program_metadata(target, [refl], GLSLMetadata()) - self.ae(m['target'], 'msl-24') + self.ae(m['target'], 'msl-31') self.ae(m['entry_points'], {'vertex': 'vertex_main', 'fragment': 'fragment_main'}) self.ae(m['textures'], {'sprites': 0}) self.ae(m['blocks']['CellRenderData']['slot'], 6)