diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 4f7f3728646a..22c25dd5e57e 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2765,6 +2765,14 @@ Windows override for [member rendering/rendering_device/driver]. + + If [code]true[/code], the forward renderer will fall back to Direct3D 12 if Vulkan is not supported. + [b]Note:[/b] This setting is implemented only on Windows. + + + If [code]true[/code], the forward renderer will fall back to Vulkan if Direct3D 12 is not supported. + [b]Note:[/b] This setting is implemented only on Windows. + Enable the pipeline cache that is saved to disk if the graphics API supports it. [b]Note:[/b] This property is unable to control the pipeline caching the GPU driver itself does. Only turn this off along with deleting the contents of the driver's cache if you wish to simulate the experience a user will get when starting the game for the first time. diff --git a/main/main.cpp b/main/main.cpp index e1d53e7f1bee..c7c0c08fad9c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1956,6 +1956,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph 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), default_driver); GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.macos", PROPERTY_HINT_ENUM, driver_hints), default_driver); + + GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_vulkan", true); + GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_d3d12", true); } { diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index f29048b16d73..ae8d1cace021 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -5929,10 +5929,37 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win if (rendering_context) { if (rendering_context->initialize() != OK) { - memdelete(rendering_context); - rendering_context = nullptr; - r_error = ERR_UNAVAILABLE; - return; + 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); + if (rendering_context->initialize() == OK) { + WARN_PRINT("Your video card drivers seem not to support Direct3D 12, switching to Vulkan."); + rendering_driver = "vulkan"; + failed = false; + } + } +#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); + if (rendering_context->initialize() == OK) { + WARN_PRINT("Your video card drivers seem not to support Vulkan, switching to Direct3D 12."); + rendering_driver = "d3d12"; + failed = false; + } + } +#endif + if (failed) { + memdelete(rendering_context); + rendering_context = nullptr; + r_error = ERR_UNAVAILABLE; + return; + } } } #endif