Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cross-platform configuration of rendering driver settings (narrower approach) #103197

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

akien-mga
Copy link
Member

@akien-mga akien-mga commented Feb 22, 2025

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. So that issue is a lot less problematic,
or maybe not even an issue anymore, but may be considered working as
intended (so we can keep changing defaults if we want and have projects
auto-upgrade).


Before (Linux editor):

image

After (Linux editor):

image

@bruvzg
Copy link
Member

bruvzg commented Feb 23, 2025

There are issues with this approach:

  • Intel Mac users will have almost no indication they aren't running with Metal renderer (since Vulkan will be selected via fallback), which might be confusing.
  • Custom builds without Metal support on macOS or without Vulkan support on Windows, or projects with rendering/rendering_device/fallback_to_vulkan/rendering/rendering_device/fallback_to_d3d12 disabled will crash on start, current fallback system works only in specific conditions.

@bruvzg
Copy link
Member

bruvzg commented Feb 23, 2025

So I do not see how it's safer, making project crash by unchecking one setting vs incorrect user code might no longer work in some cases doesn't feel safer.

Most of #103144 is still relevant (everything except || x == "auto" parts).

@bruvzg
Copy link
Member

bruvzg commented Feb 23, 2025

Or we should at least relax fallback requirements (ignore fallback setting on Intel mac, and on Windows build with only one rendering driver):

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 fff237f10c..b3ce38b038 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -6763,24 +6763,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);
@@ -6794,7 +6800,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);

@akien-mga
Copy link
Member Author

So I do not see how it's safer, making project crash by unchecking one setting vs incorrect user code might no longer work in some cases doesn't feel safer.

To clarify, by "safer" I don't mean that it's more bullet-proof for edge case situations. I meant "safer" in the context of the 4.4 release cycle, by making changes which have minimal impact compared to the 4.4-beta4 state, and won't break potential user code that relies on querying the driver settings.

Adding auto helps cover more of the edge cases with smooth fallbacks but exposes uncertainty by not being able to really know which driver is going to be used.

So I want to go back to the previous state, make minimal improvements that help fix bugs without creating new ones, and then we can rework things further for 4.5, earlier on in that dev cycle.

So for example the fact that setting an unsupported driver leads to a crash is not something added by this PR. Before this and #103026, you could also use the official Windows editor builds on Windows, set d3d12 as driver, and then use custom export templates without d3d12 support, leading to a broken export.

This PR doesn't aim to address this which is IMO an edge case (doesn't happen with official builds), but if we can address it without risk then I'm not against it.

Intel Mac users will have almost no indication they aren't running with Metal renderer (since Vulkan will be selected via fallback), which might be confusing.

That's true, but I don't think it's a deal breaker for 4.4. The startup message in the output dock when they run the game should show that it's running Vulkan over MoltenVK I believe. The documentation I added also makes it clear that metal for macOS actually falls back to vulkan for Intel Macs. #103042 should help address that further once there's a consensus on the design.

Custom builds without Metal support on macOS or without Vulkan support on Windows, or projects with rendering/rendering_device/fallback_to_vulkan/rendering/rendering_device/fallback_to_d3d12 disabled will crash on start, current fallback system works only in specific conditions.

I'll add your patch which should address this.

@akien-mga akien-mga changed the title Fix cross-platform configuration of rendering driver settings (safer approach) Fix cross-platform configuration of rendering driver settings (narrower approach) Feb 23, 2025
akien-mga and others added 3 commits February 23, 2025 12:19
…add "auto" option."

This reverts commit dea20c4.

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.
Simpler alternative to godotengine#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 godotengine#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 <[email protected]>
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 <[email protected]>
@akien-mga akien-mga force-pushed the safer-rendering-driver-selection branch from 2dd2d67 to 28d1dcc Compare February 23, 2025 11:29
@akien-mga akien-mga requested review from a team as code owners February 23, 2025 11:29
@akien-mga
Copy link
Member Author

Custom builds without Metal support on macOS or without Vulkan support on Windows, or projects with rendering/rendering_device/fallback_to_vulkan/rendering/rendering_device/fallback_to_d3d12 disabled will crash on start, current fallback system works only in specific conditions.

I'll add your patch which should address this.

Done.

Most of #103144 is still relevant (everything except || x == "auto" parts).

Yes, I've included it here (CC @syntaxerror247) so we can review/test everything together.

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested macOS editor (both ARM64 and Intel), iOS export, Android export and Android editor with Vulkan project. All seems to be working as expected.

Comment on lines -859 to +861
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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akien-mga Now that auto has been removed, this change only affects the style, while the logic remains the same as before. It would be better to revert it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[4.4RC1] Android: Leaving Rendering Device Driver Set To Auto Crashes Exported Project
3 participants