Skip to content

[3.x] Disable GPU threaded optimizations option #106556

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

Draft
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented May 18, 2025

We can disable indirectly by enabling verbose GL debug output.

Fixes #33969
Alternative to #106551

PR on hold for now as it requires testing and refinement with a user that has hardware which exhibits the problem in order to proceed.

A long standing issue on Windows with Nvidia drivers has been the threaded optimization driver setting. This seems to cause significant stuttering for some users.

Godot 4 tries the approach of using the Nvidia SDK to turn off the optimization directly in the driver (#71472), however that has caused a number of regressions.

Instead users have reported that enabling OpenGL debug logging seems to fix the issue, believed to be by forcing the driver to disable the feature. This is not ideal for exports, because Godot does significant processing to print these debug logs.

Here we add a similar feature which turns on debug logging, but instead provides a pass through so that no processing takes place on Godot side, minimizing the cost of the technique.

Notes

  • Only disables for video adapter with "nvidia" in the name, on windows only.
  • Also might be a good option for 4.x.
  • I can't fully test this, as I don't have windows or nvidia GPU, so it would be good if a user with the problem can test the artifacts from this PR.
  • I'm not quite sure whether this should be on by default or not, as from what I have read online, some people prefer having their nvidia driver set to OFF, and some to AUTO and some to ON, and this takes the choice away from them (unless the game has a settings page where you can change the godot setting).
  • verbose_logging takes precedence, but by definition if that is on, it will also disable threaded optimization. So probably no need to mention it in the docs.
  • Added a command line switch --allow-gpu-threaded to override the project setting just in case an end user wants to play a game with multithread optimizations enabled.
  • Welcome any suggestions for changes to the names.
  • I've added a print_line here just for initial testing so we can see it's active. It would have been a print_verbose, but by definition, we can't use this new mode when verbose is on. 😁

@lawnjelly lawnjelly added this to the 3.7 milestone May 18, 2025
@lawnjelly lawnjelly force-pushed the disable_gpu_threaded_opt branch 3 times, most recently from 1f7a779 to 1866c3a Compare May 18, 2025 15:41
@lawnjelly lawnjelly marked this pull request as ready for review May 18, 2025 15:44
@lawnjelly lawnjelly requested review from a team as code owners May 18, 2025 15:44
@lawnjelly lawnjelly requested a review from clayjohn May 18, 2025 15:51
@lawnjelly lawnjelly force-pushed the disable_gpu_threaded_opt branch 3 times, most recently from e696b9a to 02da94d Compare May 18, 2025 18:42
@lawnjelly lawnjelly force-pushed the disable_gpu_threaded_opt branch from 02da94d to f2724b3 Compare May 19, 2025 08:26
@lawnjelly lawnjelly force-pushed the disable_gpu_threaded_opt branch from f2724b3 to 938644e Compare May 19, 2025 10:44
@lawnjelly lawnjelly marked this pull request as draft May 19, 2025 11:28
@lawnjelly lawnjelly force-pushed the disable_gpu_threaded_opt branch 2 times, most recently from 6ca3328 to d0a4504 Compare May 19, 2025 13:04
@lawnjelly lawnjelly marked this pull request as ready for review May 19, 2025 13:05
We can disable indirectly by enabling verbose GL debug output.
@lawnjelly lawnjelly force-pushed the disable_gpu_threaded_opt branch from d0a4504 to d210959 Compare May 19, 2025 17:24
@lawnjelly
Copy link
Member Author

lawnjelly commented May 20, 2025

Moved here, addressed to @elvisish:

Unfortunately it still takes 4 seconds to run the game, it also took around 30 seconds to start Godot :/

Also checking the code, all this is switched off when running the editor, it only is active when you are running the game itself. If you are getting slowdowns in the editor, it suggests something else is going on, totally unrelated to this PR.

  • Are you running the most recent artifact?
  • Have you run your project or loaded it in 3.6 and confirm it works normally without slowdown?

The relevant switch in GLES2 and GLES3 is:

if (!OS::get_singleton()->is_stdout_verbose() && !Engine::get_singleton()->is_editor_hint() && OS::get_singleton()->get_name() == "Windows") {

In both cases it should not be active in the editor (when is_editor_hint() is true).

Additionally the correct artifact should print "Attempting to disable GPU Driver threaded optimization via OpenGL debugging" when it is active, this is dependent on you having an adapter name with the string "nvidia" in it.

To clarify, the whole system WILL ONLY BE ACTIVE when verbose output is off.


I'll see if I can find out what is causing this. To clarify, how long does it take to start with verbose mode?

It shouldn't take longer than verbose mode, providing the same debug options are selected (and should take considerably less). It's likely some of the settings I have applied are resulting in more logging, maybe I can test this by emulating it in Linux.

UPDATE: I've tested in linux and don't get any debug logs in Trucktown, 3D Platformer or TPS demo.
However this could be my graphics driver is having no errors etc (Intel iGPU a780).

Another possibility is that our debug printing itself is what is causing the difference and maybe flushing std::out or something, in which case the original hypothesis that this is disabling multitheaded optimization might have been incorrect. 🤔

Also would you be able to copy into the post some of the verbose logs you get, just to check these are not actually GL errors that are occurring on your GPU. If these are errors then anything could be happening.

To clarify let me know (in a post on the PR) whether you are testing on GLES2 or GLES3, that will help.

Also an MRP would be useful, does this slowdown occur with an empty project? Can you also test with an empty project?

Also if you run the editor from the artifact, then select help->copy_system_info from the menu, then paste your system specs here, that might be useful. e.g.:

Godot Engine v3.7.dev.custom_build [83474bc39] - X11 - 2 monitors - GLES3 - Mesa Intel(R) Graphics (RPL-S) - 13th Gen Intel(R) Core(TM) i7-13700T (24 threads)

@lawnjelly lawnjelly marked this pull request as draft May 21, 2025 16:32
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.

1 participant