From 11f56d8265425d075dbfb109460c5bfb634620d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sat, 22 Feb 2025 23:43:35 +0100 Subject: [PATCH 1/3] Revert "Always allow selecting any rendering driver in the settings, add "auto" option." This reverts commit dea20c4a9b76136dc93e3d3036a6095c198c0ffa. This had unforeseen consequences for editor code that relies on querying these settings, and possibly thirdparty code that would do the same. In hindsight, it's a bit too late in the release cycle to make such a compatibility breaking change. --- doc/classes/ProjectSettings.xml | 54 +++++--------------- main/main.cpp | 88 +++++++++++++++++++-------------- 2 files changed, 64 insertions(+), 78 deletions(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index c0c5bc04c1..94c975b468 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2684,38 +2684,26 @@ Base size used to determine size of froxel buffer in the camera X-axis and Y-axis. The final size is scaled by the aspect ratio of the screen, so actual values may differ from what is set. Set a larger size for more detailed fog, set a smaller size for better performance. - + Sets the driver to be used by the renderer when using the Compatibility renderer. This property can not be edited directly, instead, set the driver using the platform-specific overrides. - Supported values are: - - [code]auto[/code], currently defaults to [code]opengl3[/code] on all platforms. - - [code]opengl3[/code], OpenGL 3.3 on desktop platforms, OpenGL ES 3.0 on mobile platforms, WebGL 2.0 on web. - - [code]opengl3_angle[/code], OpenGL ES 3.0 over ANGLE compatibility layer, supported on macOS (over native OpenGL) and Windows (over Direct3D 11). - - [code]opengl3_es[/code], OpenGL ES 3.0 on Linux/BSD. - [b]Note:[/b] The availability of these options depends on whether the engine was compiled with support for them (determined by SCons options [code]opengl3[/code] and [code]angle_libs[/code]). - + Android override for [member rendering/gl_compatibility/driver]. - The [code]auto[/code] setting is equivalent to [code]opengl3[/code] on this platform. - + iOS override for [member rendering/gl_compatibility/driver]. - The [code]auto[/code] setting is equivalent to [code]opengl3[/code] on this platform. - + LinuxBSD override for [member rendering/gl_compatibility/driver]. - The [code]auto[/code] setting is equivalent to [code]opengl3[/code] on this platform. [code]opengl3_es[/code] is available as an option, which is also used as a fallback on devices that don't support OpenGL 3.3. - + macOS override for [member rendering/gl_compatibility/driver]. - The [code]auto[/code] setting is equivalent to [code]opengl3[/code] on this platform. [code]opengl3_angle[/code] is available as an option if ANGLE support was compiled in. - + Web override for [member rendering/gl_compatibility/driver]. - The [code]auto[/code] setting is equivalent to [code]opengl3[/code] on this platform. - + Windows override for [member rendering/gl_compatibility/driver]. - The [code]auto[/code] setting is equivalent to [code]opengl3[/code] on this platform. [code]opengl3_angle[/code] is available as an option if ANGLE supported was compiled in. In such case, ANGLE is used preferentially on lower end devices with known problematic native OpenGL drivers (see [member rendering/gl_compatibility/force_angle_on_devices]). If [code]true[/code], the compatibility renderer will fall back to ANGLE if native OpenGL is not supported or the device is listed in [member rendering/gl_compatibility/force_angle_on_devices]. @@ -2981,40 +2969,24 @@ The number of entries in the sampler descriptors heap the Direct3D 12 rendering driver uses each frame, used for most rendering operations. Depending on the complexity of scenes, this value may be lowered or may need to be raised. - + Sets the driver to be used by the renderer when using a RenderingDevice-based renderer like the Forward+ or Mobile renderers. This property can't be edited directly. Instead, set the driver using the platform-specific overrides. This can be overridden using the [code]--rendering-driver <driver>[/code] command line argument. - Supported values are: - - [code]auto[/code], Metal on Apple Silicon Macs and iOS, Vulkan on other built-in platforms. On Windows, Direct3D 12 is the default if the engine was compiled without Vulkan support. - - [code]metal[/code], Metal (supported on Apple Silicon Macs and iOS). - - [code]vulkan[/code], Vulkan (supported on all desktop and mobile platforms). - - [code]d3d12[/code], Direct3D 12 (supported on Windows). - [b]Note:[/b] The availability of these options depends on whether the engine was compiled with support for them (determined by SCons options [code]vulkan[/code], [code]metal[/code], and [code]d3d12[/code]). [b]Note:[/b] The actual rendering driver may be automatically changed by the engine as a result of a fallback, or a user-specified command line argument. To get the actual rendering driver that is used at runtime, use [method RenderingServer.get_current_rendering_driver_name] instead of reading this project setting's value. - + Android override for [member rendering/rendering_device/driver]. - The [code]auto[/code] setting is equivalent to [code]vulkan[/code] on this platform. - [b]Note:[/b] If Vulkan was disabled at compile time, there is no alternative RenderingDevice driver. - + iOS override for [member rendering/rendering_device/driver]. - The [code]auto[/code] setting is equivalent to [code]metal[/code] on this platform. - [b]Note:[/b] If Metal was disabled at compile time, the default becomes [code]vulkan[/code]. If both Metal and Vulkan were disabled at compile time, there is no alternative RenderingDevice driver. - + LinuxBSD override for [member rendering/rendering_device/driver]. - The [code]auto[/code] setting is equivalent to [code]vulkan[/code] on this platform. - [b]Note:[/b] If Vulkan was disabled at compile time, there is no alternative RenderingDevice driver. - + macOS override for [member rendering/rendering_device/driver]. - The [code]auto[/code] setting is equivalent to [code]metal[/code] on Apple Silicon Macs, and [code]vulkan[/code] (MoltenVK) on Intel Macs. Metal isn't supported on Intel Macs, so even if setting [code]metal[/code] explicitly, it will fallback to Vulkan on Intel Macs. - [b]Note:[/b] If Metal was disabled at compile time, the default becomes [code]vulkan[/code] for both Apple Silicon and Intel Macs. If both Metal and Vulkan were disabled at compile time, there is no alternative RenderingDevice driver. - + Windows override for [member rendering/rendering_device/driver]. - The [code]auto[/code] setting is equivalent to [code]vulkan[/code] on this platform. - [b]Note:[/b] If Vulkan was disabled at compile time, the default becomes [code]d3d12[/code]. If both Vulkan and Direct3D 12 were disabled at compile time, there is no alternative RenderingDevice driver. If [code]true[/code], the forward renderer will fall back to Direct3D 12 if Vulkan is not supported. diff --git a/main/main.cpp b/main/main.cpp index bf5f9dfeca..40b9fc8cd9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2031,13 +2031,40 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph Logger::set_flush_stdout_on_print(GLOBAL_GET("application/run/flush_stdout_on_print")); { + String driver_hints = ""; + String driver_hints_with_d3d12 = ""; + String driver_hints_with_metal = ""; + + { + Vector driver_hints_arr; +#ifdef VULKAN_ENABLED + driver_hints_arr.push_back("vulkan"); +#endif + driver_hints = String(",").join(driver_hints_arr); + +#ifdef D3D12_ENABLED + driver_hints_arr.push_back("d3d12"); +#endif + driver_hints_with_d3d12 = String(",").join(driver_hints_arr); + +#ifdef METAL_ENABLED + // Make metal the preferred and default driver. + driver_hints_arr.insert(0, "metal"); +#endif + driver_hints_with_metal = String(",").join(driver_hints_arr); + } + + String default_driver = driver_hints.get_slice(",", 0); + String default_driver_with_d3d12 = driver_hints_with_d3d12.get_slice(",", 0); + String default_driver_with_metal = driver_hints_with_metal.get_slice(",", 0); + // For now everything defaults to vulkan when available. This can change in future updates. - GLOBAL_DEF_RST("rendering/rendering_device/driver", "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.windows", PROPERTY_HINT_ENUM, "auto,vulkan,d3d12"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.linuxbsd", PROPERTY_HINT_ENUM, "auto,vulkan"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.android", PROPERTY_HINT_ENUM, "auto,vulkan"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.ios", PROPERTY_HINT_ENUM, "auto,metal,vulkan"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.macos", PROPERTY_HINT_ENUM, "auto,metal,vulkan"), "auto"); + GLOBAL_DEF_RST_NOVAL("rendering/rendering_device/driver", default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.windows", PROPERTY_HINT_ENUM, driver_hints_with_d3d12), default_driver_with_d3d12); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.linuxbsd", PROPERTY_HINT_ENUM, driver_hints), default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.android", PROPERTY_HINT_ENUM, driver_hints), default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.ios", PROPERTY_HINT_ENUM, driver_hints_with_metal), default_driver_with_metal); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.macos", PROPERTY_HINT_ENUM, driver_hints_with_metal), default_driver_with_metal); GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_vulkan", true); GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_d3d12", true); @@ -2045,13 +2072,24 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } { - GLOBAL_DEF_RST("rendering/gl_compatibility/driver", "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.windows", PROPERTY_HINT_ENUM, "auto,opengl3,opengl3_angle"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.linuxbsd", PROPERTY_HINT_ENUM, "auto,opengl3,opengl3_es"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.web", PROPERTY_HINT_ENUM, "auto,opengl3"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.android", PROPERTY_HINT_ENUM, "auto,opengl3"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.ios", PROPERTY_HINT_ENUM, "auto,opengl3"), "auto"); - GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.macos", PROPERTY_HINT_ENUM, "auto,opengl3,opengl3_angle"), "auto"); + String driver_hints = ""; + String driver_hints_angle = ""; + String driver_hints_egl = ""; +#ifdef GLES3_ENABLED + driver_hints = "opengl3"; + driver_hints_angle = "opengl3,opengl3_angle"; // macOS, Windows. + driver_hints_egl = "opengl3,opengl3_es"; // Linux. +#endif + + String default_driver = driver_hints.get_slice(",", 0); + + GLOBAL_DEF_RST_NOVAL("rendering/gl_compatibility/driver", default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.windows", PROPERTY_HINT_ENUM, driver_hints_angle), default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.linuxbsd", PROPERTY_HINT_ENUM, driver_hints_egl), default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.web", PROPERTY_HINT_ENUM, driver_hints), default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.android", PROPERTY_HINT_ENUM, driver_hints), default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.ios", PROPERTY_HINT_ENUM, driver_hints), default_driver); + GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.macos", PROPERTY_HINT_ENUM, driver_hints_angle), default_driver); GLOBAL_DEF_RST("rendering/gl_compatibility/nvidia_disable_threaded_optimization", true); GLOBAL_DEF_RST("rendering/gl_compatibility/fallback_to_angle", true); @@ -2385,30 +2423,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph // always convert to lower case for consistency in the code rendering_driver = rendering_driver.to_lower(); - if (rendering_method == "gl_compatibility") { -#ifdef GLES3_ENABLED - if (rendering_driver == "auto") { - rendering_driver = "opengl3"; - } -#endif - } else { -#ifdef METAL_ENABLED - if (rendering_driver == "auto") { - rendering_driver = "metal"; - } -#endif -#ifdef VULKAN_ENABLED - if (rendering_driver == "auto") { - rendering_driver = "vulkan"; - } -#endif -#ifdef D3D12_ENABLED - if (rendering_driver == "auto") { - rendering_driver = "d3d12"; - } -#endif - } - OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); OS::get_singleton()->set_current_rendering_method(rendering_method); From b77423370a5a2d857ffe4ddf0afa2504e08fbd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 23 Feb 2025 00:42:44 +0100 Subject: [PATCH 2/3] Fix cross-platform configuration of rendering driver settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simpler alternative to #103026 which avoids breaking compatibility. Instead of introducing a new `auto` default value, we ensure that all supported drivers are registered regardless of the editor's host platform, and that the defaults are the intended ones. This solves the following issues: - macOS exports are meant to default to Metal in 4.4, but they would default to Vulkan if exported from Linux, Windows, or Android editors. - Windows exports couldn't be made with Direct3D 12 from Linux, macOS, or Android editors, as the option couldn't be selected outside Windows. Unlike #103026, it doesn't solve the issue of not always saving the rendering drivers to `project.godot`, but now the defaults are at least consistent between editor platforms. Co-authored-by: Pāvels Nadtočajevs <7645683+bruvzg@users.noreply.github.com> --- doc/classes/ProjectSettings.xml | 78 ++++++++++++++++----- main/main.cpp | 73 ++++++------------- platform/macos/display_server_macos.mm | 5 +- platform/windows/display_server_windows.cpp | 9 ++- 4 files changed, 93 insertions(+), 72 deletions(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 94c975b468..a8eb4a8da9 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2684,26 +2684,48 @@ Base size used to determine size of froxel buffer in the camera X-axis and Y-axis. The final size is scaled by the aspect ratio of the screen, so actual values may differ from what is set. Set a larger size for more detailed fog, set a smaller size for better performance. - - Sets the driver to be used by the renderer when using the Compatibility renderer. This property can not be edited directly, instead, set the driver using the platform-specific overrides. + + Sets the driver to be used by the renderer when using the Compatibility renderer. Editing this property has no effect in the default configuration, as first-party platforms each have platform-specific overrides. Use those overrides to configure the driver for each platform. + This can be overridden using the [code]--rendering-driver <driver>[/code] command line argument. + Supported values are: + - [code]opengl3[/code], OpenGL 3.3 on desktop platforms, OpenGL ES 3.0 on mobile platforms, WebGL 2.0 on web. + - [code]opengl3_angle[/code], OpenGL ES 3.0 using the ANGLE compatibility layer, supported on macOS (over native OpenGL) and Windows (over Direct3D 11). + - [code]opengl3_es[/code], OpenGL ES 3.0 on Linux/BSD. + [b]Note:[/b] The availability of these options depends on whether the engine was compiled with support for them (determined by SCons options [code]opengl3[/code] and [code]angle_libs[/code]). + [b]Note:[/b] The actual rendering driver may be automatically changed by the engine as a result of a fallback, or a user-specified command line argument. To get the actual rendering driver that is used at runtime, use [method RenderingServer.get_current_rendering_driver_name] instead of reading this project setting's value. - + Android override for [member rendering/gl_compatibility/driver]. + Only one option is supported: + - [code]opengl3[/code], OpenGL ES 3.0 from native drivers. - + iOS override for [member rendering/gl_compatibility/driver]. + Only one option is supported: + - [code]opengl3[/code], OpenGL ES 3.0 from native drivers. - + LinuxBSD override for [member rendering/gl_compatibility/driver]. + Two options are supported: + - [code]opengl3[/code] (default), OpenGL 3.3 from native drivers. + - [code]opengl3_es[/code], OpenGL ES 3.0 from native drivers. If [member rendering/gl_compatibility/fallback_to_gles] is enabled, this is used as a fallback if OpenGL 3.3 is not supported. - + macOS override for [member rendering/gl_compatibility/driver]. + Two options are supported: + - [code]opengl3[/code] (default), OpenGL 3.3 from native drivers. If [member rendering/gl_compatibility/fallback_to_native] is enabled, this is used as a fallback if ANGLE is configured as the preferred driver but not supported. + - [code]opengl3_angle[/code], OpenGL ES 3.0 using the ANGLE compatibility layer over native OpenGL drivers. If [member rendering/gl_compatibility/fallback_to_angle] is enabled, this is used as a fallback if OpenGL 3.3 is not supported. - + Web override for [member rendering/gl_compatibility/driver]. + Only one option is supported: + - [code]opengl3[/code], WebGL 2.0. The underlying native API depends on the target OS, browser, and browser configuration. - + Windows override for [member rendering/gl_compatibility/driver]. + Two options are supported: + - [code]opengl3[/code] (default), OpenGL 3.3 from native drivers. If [member rendering/gl_compatibility/fallback_to_native] is enabled, this is used as a fallback if ANGLE is configured as the preferred driver but not supported. + - [code]opengl3_angle[/code], OpenGL ES 3.0 using the ANGLE compatibility layer over native Direct3D 11 drivers. If [member rendering/gl_compatibility/fallback_to_angle] is enabled, this is used as a fallback if OpenGL 3.3 is not supported. By default, ANGLE is used as the default driver for some devices listed in [member rendering/gl_compatibility/force_angle_on_devices]. If [code]true[/code], the compatibility renderer will fall back to ANGLE if native OpenGL is not supported or the device is listed in [member rendering/gl_compatibility/force_angle_on_devices]. @@ -2969,27 +2991,49 @@ The number of entries in the sampler descriptors heap the Direct3D 12 rendering driver uses each frame, used for most rendering operations. Depending on the complexity of scenes, this value may be lowered or may need to be raised. - - Sets the driver to be used by the renderer when using a RenderingDevice-based renderer like the Forward+ or Mobile renderers. This property can't be edited directly. Instead, set the driver using the platform-specific overrides. This can be overridden using the [code]--rendering-driver <driver>[/code] command line argument. + + Sets the driver to be used by the renderer when using a RenderingDevice-based renderer like the Forward+ or Mobile renderers. Editing this property has no effect in the default configuration, as first-party platforms each have platform-specific overrides. Use those overrides to configure the driver for each platform. + This can be overridden using the [code]--rendering-driver <driver>[/code] command line argument. + Supported values are: + - [code]metal[/code], Metal (supported on Apple Silicon Macs and iOS). + - [code]vulkan[/code], Vulkan (supported on all desktop and mobile platforms). + - [code]d3d12[/code], Direct3D 12 (supported on Windows). + [b]Note:[/b] The availability of these options depends on whether the engine was compiled with support for them (determined by SCons options [code]vulkan[/code], [code]metal[/code], and [code]d3d12[/code]). + [b]Note:[/b] If a given platform has no registered drivers, it can fall back to the Compatibility renderer (OpenGL 3) if [member rendering/rendering_device/fallback_to_opengl3] is enabled. This fallback happens automatically for the Web platform regardless of that property. [b]Note:[/b] The actual rendering driver may be automatically changed by the engine as a result of a fallback, or a user-specified command line argument. To get the actual rendering driver that is used at runtime, use [method RenderingServer.get_current_rendering_driver_name] instead of reading this project setting's value. - + Android override for [member rendering/rendering_device/driver]. + Only one option is supported: + - [code]vulkan[/code], Vulkan from native drivers. + [b]Note:[/b] If Vulkan was disabled at compile time, there is no alternative RenderingDevice driver. - + iOS override for [member rendering/rendering_device/driver]. + Two options are supported: + - [code]metal[/code] (default), Metal from native drivers. + - [code]vulkan[/code], Vulkan over Metal via MoltenVK. - + LinuxBSD override for [member rendering/rendering_device/driver]. + Only one option is supported: + - [code]vulkan[/code], Vulkan from native drivers. + [b]Note:[/b] If Vulkan was disabled at compile time, there is no alternative RenderingDevice driver. - + macOS override for [member rendering/rendering_device/driver]. + Two options are supported: + - [code]metal[/code] (default), Metal from native drivers, only supported on Apple Silicon Macs. On Intel Macs, it will automatically fall back to [code]vulkan[/code] as Metal support is not implemented. + - [code]vulkan[/code], Vulkan over Metal via MoltenVK, supported on both Apple Silicon and Intel Macs. - + Windows override for [member rendering/rendering_device/driver]. + Two options are supported: + - [code]vulkan[/code] (default), Vulkan from native drivers. If [member rendering/rendering_device/fallback_to_vulkan] is enabled, this is used as a fallback if Direct3D 12 is not supported. + - [code]d3d12[/code], Direct3D 12 from native drivers. If [member rendering/rendering_device/fallback_to_d3d12] is enabled, this is used as a fallback if Vulkan is not supported. - If [code]true[/code], the forward renderer will fall back to Direct3D 12 if Vulkan is not supported. + If [code]true[/code], the forward renderer will fall back to Direct3D 12 if Vulkan is not supported. The fallback is always attempted regardless of this setting if Vulkan driver support was disabled at compile time. [b]Note:[/b] This setting is implemented only on Windows. @@ -2997,7 +3041,7 @@ [b]Note:[/b] This setting is implemented only on Windows, Android, macOS, iOS, and Linux/X11. - If [code]true[/code], the forward renderer will fall back to Vulkan if Direct3D 12 (on Windows) or Metal (on macOS x86_64) are not supported. + If [code]true[/code], the forward renderer will fall back to Vulkan if Direct3D 12 (on Windows) or Metal (on macOS x86_64) are not supported. The fallback is always attempted regardless of this setting if Direct3D 12 (Windows) or Metal (macOS) driver support was disabled at compile time. [b]Note:[/b] This setting is implemented only on Windows and macOS. diff --git a/main/main.cpp b/main/main.cpp index 40b9fc8cd9..6fbe386762 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2030,41 +2030,20 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph Logger::set_flush_stdout_on_print(GLOBAL_GET("application/run/flush_stdout_on_print")); + // Rendering drivers configuration. + + // Always include all supported drivers as hint, as this is used by the editor host platform + // for project settings. For example, a Linux user should be able to configure that they want + // to export for D3D12 on Windows and Metal on macOS even if their host platform can't use those. + { - String driver_hints = ""; - String driver_hints_with_d3d12 = ""; - String driver_hints_with_metal = ""; - - { - Vector driver_hints_arr; -#ifdef VULKAN_ENABLED - driver_hints_arr.push_back("vulkan"); -#endif - driver_hints = String(",").join(driver_hints_arr); - -#ifdef D3D12_ENABLED - driver_hints_arr.push_back("d3d12"); -#endif - driver_hints_with_d3d12 = String(",").join(driver_hints_arr); - -#ifdef METAL_ENABLED - // Make metal the preferred and default driver. - driver_hints_arr.insert(0, "metal"); -#endif - driver_hints_with_metal = String(",").join(driver_hints_arr); - } - - String default_driver = driver_hints.get_slice(",", 0); - String default_driver_with_d3d12 = driver_hints_with_d3d12.get_slice(",", 0); - String default_driver_with_metal = driver_hints_with_metal.get_slice(",", 0); - - // For now everything defaults to vulkan when available. This can change in future updates. - GLOBAL_DEF_RST_NOVAL("rendering/rendering_device/driver", default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.windows", PROPERTY_HINT_ENUM, driver_hints_with_d3d12), default_driver_with_d3d12); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.linuxbsd", PROPERTY_HINT_ENUM, driver_hints), default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.android", PROPERTY_HINT_ENUM, driver_hints), default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.ios", PROPERTY_HINT_ENUM, driver_hints_with_metal), default_driver_with_metal); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.macos", PROPERTY_HINT_ENUM, driver_hints_with_metal), default_driver_with_metal); + // RenderingDevice driver overrides per platform. + GLOBAL_DEF_RST("rendering/rendering_device/driver", "vulkan"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.windows", PROPERTY_HINT_ENUM, "vulkan,d3d12"), "vulkan"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.linuxbsd", PROPERTY_HINT_ENUM, "vulkan"), "vulkan"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.android", PROPERTY_HINT_ENUM, "vulkan"), "vulkan"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.ios", PROPERTY_HINT_ENUM, "metal,vulkan"), "metal"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.macos", PROPERTY_HINT_ENUM, "metal,vulkan"), "metal"); GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_vulkan", true); GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_d3d12", true); @@ -2072,24 +2051,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } { - String driver_hints = ""; - String driver_hints_angle = ""; - String driver_hints_egl = ""; -#ifdef GLES3_ENABLED - driver_hints = "opengl3"; - driver_hints_angle = "opengl3,opengl3_angle"; // macOS, Windows. - driver_hints_egl = "opengl3,opengl3_es"; // Linux. -#endif - - String default_driver = driver_hints.get_slice(",", 0); - - GLOBAL_DEF_RST_NOVAL("rendering/gl_compatibility/driver", default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.windows", PROPERTY_HINT_ENUM, driver_hints_angle), default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.linuxbsd", PROPERTY_HINT_ENUM, driver_hints_egl), default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.web", PROPERTY_HINT_ENUM, driver_hints), default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.android", PROPERTY_HINT_ENUM, driver_hints), default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.ios", PROPERTY_HINT_ENUM, driver_hints), default_driver); - GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.macos", PROPERTY_HINT_ENUM, driver_hints_angle), default_driver); + // GL Compatibility driver overrides per platform. + GLOBAL_DEF_RST("rendering/gl_compatibility/driver", "opengl3"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.windows", PROPERTY_HINT_ENUM, "opengl3,opengl3_angle"), "opengl3"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.linuxbsd", PROPERTY_HINT_ENUM, "opengl3,opengl3_es"), "opengl3"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.web", PROPERTY_HINT_ENUM, "opengl3"), "opengl3"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.android", PROPERTY_HINT_ENUM, "opengl3"), "opengl3"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.ios", PROPERTY_HINT_ENUM, "opengl3"), "opengl3"); + GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.macos", PROPERTY_HINT_ENUM, "opengl3,opengl3_angle"), "opengl3"); GLOBAL_DEF_RST("rendering/gl_compatibility/nvidia_disable_threaded_optimization", true); GLOBAL_DEF_RST("rendering/gl_compatibility/fallback_to_angle", true); diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 346faef842..556c4c966e 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -3791,8 +3791,11 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM #if defined(VULKAN_ENABLED) #if defined(__x86_64__) bool fallback_to_vulkan = GLOBAL_GET("rendering/rendering_device/fallback_to_vulkan"); + if (!fallback_to_vulkan) { + WARN_PRINT("Metal is not supported on Intel Macs, switching to Vulkan."); + } // Metal rendering driver not available on Intel. - if (fallback_to_vulkan && rendering_driver == "metal") { + if (rendering_driver == "metal") { rendering_driver = "vulkan"; OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); } diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 6f71950e2f..18bbba342b 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -6764,24 +6764,30 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win _register_raw_input_devices(INVALID_WINDOW_ID); #if defined(RD_ENABLED) + bool fallback_to_vulkan = GLOBAL_GET("rendering/rendering_device/fallback_to_vulkan"); + bool fallback_to_d3d12 = GLOBAL_GET("rendering/rendering_device/fallback_to_d3d12"); + #if defined(VULKAN_ENABLED) if (rendering_driver == "vulkan") { rendering_context = memnew(RenderingContextDriverVulkanWindows); tested_drivers.set_flag(DRIVER_ID_RD_VULKAN); } +#else + fallback_to_d3d12 = true; // Always enable fallback if engine was built w/o other driver support. #endif #if defined(D3D12_ENABLED) if (rendering_driver == "d3d12") { rendering_context = memnew(RenderingContextDriverD3D12); tested_drivers.set_flag(DRIVER_ID_RD_D3D12); } +#else + fallback_to_vulkan = true; // Always enable fallback if engine was built w/o other driver support. #endif if (rendering_context) { if (rendering_context->initialize() != OK) { bool failed = true; #if defined(VULKAN_ENABLED) - bool fallback_to_vulkan = GLOBAL_GET("rendering/rendering_device/fallback_to_vulkan"); if (failed && fallback_to_vulkan && rendering_driver != "vulkan") { memdelete(rendering_context); rendering_context = memnew(RenderingContextDriverVulkanWindows); @@ -6795,7 +6801,6 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win } #endif #if defined(D3D12_ENABLED) - bool fallback_to_d3d12 = GLOBAL_GET("rendering/rendering_device/fallback_to_d3d12"); if (failed && fallback_to_d3d12 && rendering_driver != "d3d12") { memdelete(rendering_context); rendering_context = memnew(RenderingContextDriverD3D12); From 28d1dccf6370a1754c9bd49b9e5ec3f15db1e535 Mon Sep 17 00:00:00 2001 From: Anish Mishra Date: Sat, 22 Feb 2025 09:23:32 +0530 Subject: [PATCH 3/3] Android: Fix export and runtime logic to check if using Vulkan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fix iOS export logic that would force a min target of iOS 14.0 (for Metal) even when targeting the Compatibility renderer. Co-authored-by: Pāvels Nadtočajevs <7645683+bruvzg@users.noreply.github.com> --- platform/android/export/export_plugin.cpp | 6 +++--- .../java/lib/src/org/godotengine/godot/Godot.kt | 7 ++++--- .../java/lib/src/org/godotengine/godot/GodotLib.java | 9 +++++++++ platform/android/java_godot_lib_jni.cpp | 11 +++++++++++ platform/android/java_godot_lib_jni.h | 1 + platform/ios/export/export_plugin.cpp | 4 +++- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 0f50f72525..13d721da5d 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -856,9 +856,9 @@ bool EditorExportPlatformAndroid::_has_manage_external_storage_permission(const } bool EditorExportPlatformAndroid::_uses_vulkan() { - String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method.mobile"); - bool uses_vulkan = (current_renderer == "forward_plus" || current_renderer == "mobile") && GLOBAL_GET("rendering/rendering_device/driver.android") == "vulkan"; - return uses_vulkan; + String rendering_method = GLOBAL_GET("rendering/renderer/rendering_method.mobile"); + String rendering_driver = GLOBAL_GET("rendering/rendering_device/driver.android"); + return (rendering_method == "forward_plus" || rendering_method == "mobile") && rendering_driver == "vulkan"; } void EditorExportPlatformAndroid::_notification(int p_what) { diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index 2e043745c4..550fbe94de 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -825,10 +825,11 @@ class Godot(private val context: Context) { * Returns true if `Vulkan` is used for rendering. */ private fun usesVulkan(): Boolean { - var rendererSource = "ProjectSettings" - var renderer = GodotLib.getGlobal("rendering/renderer/rendering_method") + val rendererInfo = GodotLib.getRendererInfo() var renderingDeviceSource = "ProjectSettings" - var renderingDevice = GodotLib.getGlobal("rendering/rendering_device/driver") + var renderingDevice = rendererInfo[0] + var rendererSource = "ProjectSettings" + var renderer = rendererInfo[1] val cmdline = getCommandLine() var index = cmdline.indexOf("--rendering-method") if (index > -1 && cmdline.size > index + 1) { diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java index 9bccf76241..d70915a9b3 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -189,6 +189,15 @@ public class GodotLib { */ public static native String getGlobal(String p_key); + /** + * Used to get info about the current rendering system. + * + * @return A String array with two elements: + * [0] Rendering driver name. + * [1] Rendering method. + */ + public static native String[] getRendererInfo(); + /** * Used to access Godot's editor settings. * @param settingKey Setting key diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index b56a9dbd2a..054c809c6e 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -474,6 +474,17 @@ JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv * return env->NewStringUTF(setting_value.utf8().get_data()); } +JNIEXPORT jobjectArray JNICALL Java_org_godotengine_godot_GodotLib_getRendererInfo(JNIEnv *env, jclass clazz) { + String rendering_driver = RenderingServer::get_singleton()->get_current_rendering_driver_name(); + String rendering_method = RenderingServer::get_singleton()->get_current_rendering_method(); + + jobjectArray result = env->NewObjectArray(2, env->FindClass("java/lang/String"), nullptr); + env->SetObjectArrayElement(result, 0, env->NewStringUTF(rendering_driver.utf8().get_data())); + env->SetObjectArrayElement(result, 1, env->NewStringUTF(rendering_method.utf8().get_data())); + + return result; +} + JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getEditorSetting(JNIEnv *env, jclass clazz, jstring p_setting_key) { String editor_setting_value = ""; #ifdef TOOLS_ENABLED diff --git a/platform/android/java_godot_lib_jni.h b/platform/android/java_godot_lib_jni.h index c5d68b1ac2..22fd9ae560 100644 --- a/platform/android/java_godot_lib_jni.h +++ b/platform/android/java_godot_lib_jni.h @@ -61,6 +61,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz); JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path); +JNIEXPORT jobjectArray JNICALL Java_org_godotengine_godot_GodotLib_getRendererInfo(JNIEnv *env, jclass clazz); JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getEditorSetting(JNIEnv *env, jclass clazz, jstring p_setting_key); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setEditorSetting(JNIEnv *env, jclass clazz, jstring p_key, jobject p_data); JNIEXPORT jobject JNICALL Java_org_godotengine_godot_GodotLib_getEditorProjectMetadata(JNIEnv *env, jclass clazz, jstring p_section, jstring p_key, jobject p_default_value); diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp index f253e11ec5..84bf722d14 100644 --- a/platform/ios/export/export_plugin.cpp +++ b/platform/ios/export/export_plugin.cpp @@ -2540,7 +2540,9 @@ bool EditorExportPlatformIOS::has_valid_export_configuration(const Refget("application/min_ios_version").operator String().to_float(); if (version < 14.0) { err += TTR("Metal renderer require iOS 14+.") + "\n";