diff options
Diffstat (limited to 'platform/macos')
-rw-r--r-- | platform/macos/detect.py | 22 | ||||
-rw-r--r-- | platform/macos/display_server_macos.h | 3 | ||||
-rw-r--r-- | platform/macos/display_server_macos.mm | 20 | ||||
-rw-r--r-- | platform/macos/export/export_plugin.cpp | 1 |
4 files changed, 42 insertions, 4 deletions
diff --git a/platform/macos/detect.py b/platform/macos/detect.py index 1ce7c86c7b..bfd18bea99 100644 --- a/platform/macos/detect.py +++ b/platform/macos/detect.py @@ -56,6 +56,7 @@ def get_flags(): return { "arch": detect_arch(), "use_volk": False, + "metal": True, "supported": ["mono"], } @@ -239,9 +240,22 @@ def configure(env: "SConsEnvironment"): env.Append(LINKFLAGS=["-rpath", "@executable_path/../Frameworks", "-rpath", "@executable_path"]) + if env["metal"] and env["arch"] != "arm64": + # Only supported on arm64, so skip it for x86_64 builds. + env["metal"] = False + + extra_frameworks = set() + + if env["metal"]: + env.AppendUnique(CPPDEFINES=["METAL_ENABLED", "RD_ENABLED"]) + extra_frameworks.add("Metal") + extra_frameworks.add("MetalKit") + env.Prepend(CPPPATH=["#thirdparty/spirv-cross"]) + if env["vulkan"]: - env.Append(CPPDEFINES=["VULKAN_ENABLED", "RD_ENABLED"]) - env.Append(LINKFLAGS=["-framework", "Metal", "-framework", "IOSurface"]) + env.AppendUnique(CPPDEFINES=["VULKAN_ENABLED", "RD_ENABLED"]) + extra_frameworks.add("Metal") + extra_frameworks.add("IOSurface") if not env["use_volk"]: env.Append(LINKFLAGS=["-lMoltenVK"]) @@ -260,3 +274,7 @@ def configure(env: "SConsEnvironment"): "MoltenVK SDK installation directory not found, use 'vulkan_sdk_path' SCons parameter to specify SDK path." ) sys.exit(255) + + if len(extra_frameworks) > 0: + frameworks = [item for key in extra_frameworks for item in ["-framework", key]] + env.Append(LINKFLAGS=frameworks) diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h index bd3c6af273..97af6d0a5a 100644 --- a/platform/macos/display_server_macos.h +++ b/platform/macos/display_server_macos.h @@ -47,6 +47,9 @@ #if defined(VULKAN_ENABLED) #include "rendering_context_driver_vulkan_macos.h" #endif // VULKAN_ENABLED +#if defined(METAL_ENABLED) +#include "drivers/metal/rendering_context_driver_metal.h" +#endif #endif // RD_ENABLED #define BitMap _QDBitMap // Suppress deprecated QuickDraw definition. diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index b2243dd8d5..3e0a5efe52 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -139,12 +139,20 @@ DisplayServerMacOS::WindowID DisplayServerMacOS::_create_window(WindowMode p_mod #ifdef VULKAN_ENABLED RenderingContextDriverVulkanMacOS::WindowPlatformData vulkan; #endif +#ifdef METAL_ENABLED + RenderingContextDriverMetal::WindowPlatformData metal; +#endif } wpd; #ifdef VULKAN_ENABLED if (rendering_driver == "vulkan") { wpd.vulkan.layer_ptr = (CAMetalLayer *const *)&layer; } #endif +#ifdef METAL_ENABLED + if (rendering_driver == "metal") { + wpd.metal.layer = (CAMetalLayer *)layer; + } +#endif Error err = rendering_context->window_create(window_id_counter, &wpd); ERR_FAIL_COND_V_MSG(err != OK, INVALID_WINDOW_ID, vformat("Can't create a %s context", rendering_driver)); @@ -2700,7 +2708,7 @@ void DisplayServerMacOS::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_ gl_manager_legacy->set_use_vsync(p_vsync_mode != DisplayServer::VSYNC_DISABLED); } #endif -#if defined(VULKAN_ENABLED) +#if defined(RD_ENABLED) if (rendering_context) { rendering_context->window_set_vsync_mode(p_window, p_vsync_mode); } @@ -2717,7 +2725,7 @@ DisplayServer::VSyncMode DisplayServerMacOS::window_get_vsync_mode(WindowID p_wi return (gl_manager_legacy->is_using_vsync() ? DisplayServer::VSyncMode::VSYNC_ENABLED : DisplayServer::VSyncMode::VSYNC_DISABLED); } #endif -#if defined(VULKAN_ENABLED) +#if defined(RD_ENABLED) if (rendering_context) { return rendering_context->window_get_vsync_mode(p_window); } @@ -3301,6 +3309,9 @@ Vector<String> DisplayServerMacOS::get_rendering_drivers_func() { #if defined(VULKAN_ENABLED) drivers.push_back("vulkan"); #endif +#if defined(METAL_ENABLED) + drivers.push_back("metal"); +#endif #if defined(GLES3_ENABLED) drivers.push_back("opengl3"); drivers.push_back("opengl3_angle"); @@ -3623,6 +3634,11 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM rendering_context = memnew(RenderingContextDriverVulkanMacOS); } #endif +#if defined(METAL_ENABLED) + if (rendering_driver == "metal") { + rendering_context = memnew(RenderingContextDriverMetal); + } +#endif if (rendering_context) { if (rendering_context->initialize() != OK) { diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 057fb4ec16..290b0082fc 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -458,6 +458,7 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/platform_build"), "14C18")); + // TODO(sgc): Need to set appropriate version when using Metal r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_version"), "13.1")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_build"), "22C55")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_name"), "macosx13.1")); |