summaryrefslogtreecommitdiffstats
path: root/platform/ios
diff options
context:
space:
mode:
authorStuart Carnie <stuart.carnie@gmail.com>2024-02-20 05:52:00 +1100
committerRémi Verschelde <rverschelde@gmail.com>2024-08-20 12:11:06 +0200
commit2d0165574de6ac21aa2730215dcab60e4ce88d08 (patch)
treef1710c694c12f9360e853111a1ca396f285844bb /platform/ios
parent826de7976a6add282c7b14d4be2a7e6d775821d8 (diff)
downloadredot-engine-2d0165574de6ac21aa2730215dcab60e4ce88d08.tar.gz
Add Metal support for macOS (arm64) and iOS
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/detect.py17
-rw-r--r--platform/ios/display_server_ios.h4
-rw-r--r--platform/ios/display_server_ios.mm26
-rw-r--r--platform/ios/export/export_plugin.cpp8
-rw-r--r--platform/ios/godot_view.mm2
5 files changed, 54 insertions, 3 deletions
diff --git a/platform/ios/detect.py b/platform/ios/detect.py
index 53b367a0a7..ecd1f3d32d 100644
--- a/platform/ios/detect.py
+++ b/platform/ios/detect.py
@@ -51,6 +51,7 @@ def get_flags():
"arch": "arm64",
"target": "template_debug",
"use_volk": False,
+ "metal": True,
"supported": ["mono"],
"builtin_pcre2_with_jit": False,
}
@@ -154,8 +155,22 @@ def configure(env: "SConsEnvironment"):
env.Prepend(CPPPATH=["#platform/ios"])
env.Append(CPPDEFINES=["IOS_ENABLED", "UNIX_ENABLED", "COREAUDIO_ENABLED"])
+ if env["metal"] and env["arch"] != "arm64":
+ # Only supported on arm64, so skip it for x86_64 builds.
+ env["metal"] = False
+
+ if env["metal"]:
+ env.AppendUnique(CPPDEFINES=["METAL_ENABLED", "RD_ENABLED"])
+ env.Prepend(
+ CPPPATH=[
+ "$IOS_SDK_PATH/System/Library/Frameworks/Metal.framework/Headers",
+ "$IOS_SDK_PATH/System/Library/Frameworks/QuartzCore.framework/Headers",
+ ]
+ )
+ env.Prepend(CPPPATH=["#thirdparty/spirv-cross"])
+
if env["vulkan"]:
- env.Append(CPPDEFINES=["VULKAN_ENABLED", "RD_ENABLED"])
+ env.AppendUnique(CPPDEFINES=["VULKAN_ENABLED", "RD_ENABLED"])
if env["opengl3"]:
env.Append(CPPDEFINES=["GLES3_ENABLED", "GLES_SILENCE_DEPRECATION"])
diff --git a/platform/ios/display_server_ios.h b/platform/ios/display_server_ios.h
index 4dded5aa29..bbb758074d 100644
--- a/platform/ios/display_server_ios.h
+++ b/platform/ios/display_server_ios.h
@@ -47,6 +47,10 @@
#include <vulkan/vulkan.h>
#endif
#endif // VULKAN_ENABLED
+
+#if defined(METAL_ENABLED)
+#include "drivers/metal/rendering_context_driver_metal.h"
+#endif // METAL_ENABLED
#endif // RD_ENABLED
#if defined(GLES3_ENABLED)
diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm
index 802fbefc0d..5a027e0196 100644
--- a/platform/ios/display_server_ios.mm
+++ b/platform/ios/display_server_ios.mm
@@ -73,6 +73,13 @@ DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode
#ifdef VULKAN_ENABLED
RenderingContextDriverVulkanIOS::WindowPlatformData vulkan;
#endif
+#ifdef METAL_ENABLED
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability"
+ // Eliminate "RenderingContextDriverMetal is only available on iOS 14.0 or newer".
+ RenderingContextDriverMetal::WindowPlatformData metal;
+#pragma clang diagnostic pop
+#endif
} wpd;
#if defined(VULKAN_ENABLED)
@@ -85,7 +92,19 @@ DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode
rendering_context = memnew(RenderingContextDriverVulkanIOS);
}
#endif
-
+#ifdef METAL_ENABLED
+ if (rendering_driver == "metal") {
+ if (@available(iOS 14.0, *)) {
+ layer = [AppDelegate.viewController.godotView initializeRenderingForDriver:@"metal"];
+ wpd.metal.layer = (CAMetalLayer *)layer;
+ rendering_context = memnew(RenderingContextDriverMetal);
+ } else {
+ OS::get_singleton()->alert("Metal is only supported on iOS 14.0 and later.");
+ r_error = ERR_UNAVAILABLE;
+ return;
+ }
+ }
+#endif
if (rendering_context) {
if (rendering_context->initialize() != OK) {
ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver));
@@ -172,6 +191,11 @@ Vector<String> DisplayServerIOS::get_rendering_drivers_func() {
#if defined(VULKAN_ENABLED)
drivers.push_back("vulkan");
#endif
+#if defined(METAL_ENABLED)
+ if (@available(ios 14.0, *)) {
+ drivers.push_back("metal");
+ }
+#endif
#if defined(GLES3_ENABLED)
drivers.push_back("opengl3");
#endif
diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp
index 580e3ba789..e4b5392c4e 100644
--- a/platform/ios/export/export_plugin.cpp
+++ b/platform/ios/export/export_plugin.cpp
@@ -282,6 +282,7 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
+ // TODO(sgc): set to iOS 14.0 for Metal
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_ios_version"), "12.0"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT), ""));
@@ -2656,6 +2657,13 @@ bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref<EditorExp
}
}
+ if (GLOBAL_GET("rendering/rendering_device/driver.ios") == "metal") {
+ float version = p_preset->get("application/min_ios_version").operator String().to_float();
+ if (version < 14.0) {
+ err += TTR("Metal renderer require iOS 14+.") + "\n";
+ }
+ }
+
if (!err.is_empty()) {
r_error = err;
}
diff --git a/platform/ios/godot_view.mm b/platform/ios/godot_view.mm
index e910036198..552c4c262c 100644
--- a/platform/ios/godot_view.mm
+++ b/platform/ios/godot_view.mm
@@ -71,7 +71,7 @@ static const float earth_gravity = 9.80665;
CALayer<DisplayLayer> *layer;
- if ([driverName isEqualToString:@"vulkan"]) {
+ if ([driverName isEqualToString:@"vulkan"] || [driverName isEqualToString:@"metal"]) {
#if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
if (@available(iOS 13, *)) {
layer = [GodotMetalLayer layer];