Skip to content

Fallback to OpenGL 3 if other rendering drivers are not supported#97142

Merged
akien-mga merged 1 commit into
godotengine:masterfrom
SheepYhangCN:master
Sep 20, 2024
Merged

Fallback to OpenGL 3 if other rendering drivers are not supported#97142
akien-mga merged 1 commit into
godotengine:masterfrom
SheepYhangCN:master

Conversation

@SheepYhangCN

@SheepYhangCN SheepYhangCN commented Sep 18, 2024

Copy link
Copy Markdown
Contributor

Add an option to allow renderer fall back to OpenGL 3 if Vulkan (and D3D12 on Windows, Metal on Apple devices) are not supported
Free players from using --rendering-driver opengl3 manually
Free developers from recieving "Why my game crashed with a message that I can't understand"

Bugsquad edit:

@SheepYhangCN SheepYhangCN requested review from a team as code owners September 18, 2024 11:34
@akien-mga

akien-mga commented Sep 18, 2024

Copy link
Copy Markdown
Member

This might solve godotengine/godot-proposals#8006, but it should support all platforms, not just Windows.

I support the idea in general, I think this is indeed needed to better handle users who don't support modern graphics APIs.

@SheepYhangCN

SheepYhangCN commented Sep 18, 2024

Copy link
Copy Markdown
Contributor Author

but it should support all platforms, not just Windows.

I will try to do this for other platforms later
Since Metal is native now so MacOS/iOS shouldn't need for OpenGL fallback?

@SheepYhangCN SheepYhangCN changed the title Fallback to OpenGL 3 if both D3D12 and Vulkan are not supported [Windows] Fallback to OpenGL 3 if both D3D12 and Vulkan are not supported Sep 18, 2024
@SheepYhangCN SheepYhangCN changed the title [Windows] Fallback to OpenGL 3 if both D3D12 and Vulkan are not supported Fallback to OpenGL 3 if both D3D12 and Vulkan are not supported Sep 18, 2024
@SheepYhangCN SheepYhangCN requested review from a team as code owners September 18, 2024 12:22
@SheepYhangCN SheepYhangCN changed the title Fallback to OpenGL 3 if both D3D12 and Vulkan are not supported Fallback to OpenGL 3 if Vulkan (and D3D12 on Windows) are not supported Sep 18, 2024
@Calinou

Calinou commented Sep 18, 2024

Copy link
Copy Markdown
Member

Since Metal is native now so MacOS/iOS shouldn't need for OpenGL fallback?

Metal support is only available on Apple Silicon hardware, but most Intel Macs have Vulkan support through MoltenVK. That said, old Intel Macs can't run Vulkan through MoltenVK due to missing hardware features, so the Vulkan -> OpenGL fallback would still be needed on macOS.

The same goes for iOS - old devices can't run Vulkan through MoltenVK either: #74227

@SheepYhangCN

Copy link
Copy Markdown
Contributor Author

Since Metal is native now so MacOS/iOS shouldn't need for OpenGL fallback?

Metal support is only available on Apple Silicon hardware, but most Intel Macs have Vulkan support through MoltenVK. That said, old Intel Macs can't run Vulkan through MoltenVK due to missing hardware features, so the Vulkan -> OpenGL fallback would still be needed on macOS.

Understood

@SheepYhangCN SheepYhangCN changed the title Fallback to OpenGL 3 if Vulkan (and D3D12 on Windows) are not supported Fallback to OpenGL 3 if other rendering drivers are not supported Sep 18, 2024
@SheepYhangCN SheepYhangCN requested review from a team as code owners September 18, 2024 13:01
@clayjohn

Copy link
Copy Markdown
Member

The code looks good, but when I test locally (with modifications to make rendering_context->initialize() fail), I get a deadlock. But only when opening the project through the project manager. If the project is opened on its own, it falls back correctly.

I'm investigating further now.

@clayjohn

Copy link
Copy Markdown
Member

I figured out the issue, the fallback code wasn't setting the rendering_method, therefore, any calls to OS::get_singleton()->get_current_rendering_method() returned the wrong value.

We don't use the current rendering method often, but we do check it when rendering to ensure that the opengl context is bound to the correct window:

if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
// This is currently needed for GLES to keep the current window being rendered to up to date
DisplayServer::get_singleton()->gl_window_make_current(p_viewport->viewport_to_screen);
}

In the editor, this code wouldn't get called. So the "loading" popup would take the openGL context and then not return it leading to the main screen never updating. So it wasn't a deadlock after all!

The solution is to set the rendering_method at the same time that we set the driver:


OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
OS::get_singleton()->set_current_rendering_method("gl_compatibility");

@SheepYhangCN

Copy link
Copy Markdown
Contributor Author

Fixed

@clayjohn clayjohn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! The final step before merging is to squash all the commits together so that the whole PR only contains 1 big commit with all your changes. We like to merge one commit at a time to keep the git history clean and navigable.

If you don't know how to do that, we have a helpful tutorial in the official documentation https://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html#the-interactive-rebase

Comment thread doc/classes/ProjectSettings.xml Outdated
@SheepYhangCN

Copy link
Copy Markdown
Contributor Author

Everything should be okay now I think

@clayjohn clayjohn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep, looks great! Thank you

@clayjohn clayjohn modified the milestones: 4.x, 4.4 Sep 19, 2024
@akien-mga akien-mga merged commit c2564f4 into godotengine:master Sep 20, 2024
@akien-mga

Copy link
Copy Markdown
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@joelldt

joelldt commented May 6, 2025

Copy link
Copy Markdown

I would like to note that I have had several users who need compatibility mode to play my game (their GPUs do not support Vulkan), and they are simply seeing the game crash once opened (through Steam), unless the parameters "--rendering-driver opengl3" are ran manually.

I can't replicate this myself nor have access to their machines to see the problem, so I'm sorry I can't be more helpful, but I thought I would note it here (and see if anyone else is having the same issue).

What I do have is one of their Godot.log error logs, it appears to try to default to "Direct3D 12"? This code block is followed by another 300 or so shader error lines.

USER WARNING: Your video card drivers seem not to support Vulkan, switching to Direct3D 12.
   at: DisplayServerWindows (platform/windows/display_server_windows.cpp:5985)
D3D12 11_0 - Forward+ - Using Device #0: Intel - Intel(R) HD Graphics 5500
USER WARNING: PSO caching is not implemented yet in the Direct3D 12 driver.
   at: pipeline_cache_create (drivers/d3d12/rendering_device_driver_d3d12.cpp:4906)
USER ERROR: Shader translation at stage Compute failed.
USER ERROR: Shader translation at stage Compute failed.
   at: shader_compile_binary_from_spirv (drivers/d3d12/rendering_device_driver_d3d12.cpp:3289)
   at: shader_compile_binary_from_spirv (drivers/d3d12/rendering_device_driver_d3d12.cpp:3289)
USER ERROR: Condition "shader_data.is_empty()" is true.
USER ERROR: Condition "shader_data.is_empty()" is true.
   at: _compile_variant (servers/rendering/renderer_rd/shader_rd.cpp:304)
   at: _compile_variant (servers/rendering/renderer_rd/shader_rd.cpp:304)```

@clayjohn

clayjohn commented May 6, 2025

Copy link
Copy Markdown
Member

@joelldt The fallback works for devices that don't have support for Vulkan of D3D12, but it looks like that device supports D3D12, but there is something broken in the implementation which causes Godot to crash

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

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Implement fallback to OpenGL 3 / Compatibility renderer when Vulkan is not supported

6 participants