godot
godot copied to clipboard
Disable GPU threaded optimizations option (GL debug)
We can disable indirectly by enabling verbose GL debug output.
Forward port of #106556
Discussion
A long standing issue on Windows with Nvidia drivers has been the threaded optimization (T.O.) 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 (e.g. #85111).
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.
Switching on and interactions with Nvidia specific code
This will probably take some discussion and bikeshedding as there are a number of ways of doing this, but after some testing of alternatives I'm currently most in favour of this approach:
- Use the existing
nvidia_disable_threaded_optimizationas a master switch - Add a new
tune_nvidia_driversetting
This latter setting determines two things:
- Whether the Nvidia driver is accessed at all (to change gsync & T.O.)
- Whether T.O. is disabled (using the driver directly, or indirectly via debug logging, determined by (1))
In the course of developing these PRs I also tried alternative approaches, like having an independent switch for nvidia disable and debug log disable. The problem here is that the nvidia code also controls gsync, and thus regressions with the driver occur if it is accessed at all (as I understand it). So the obvious options are 3 settings (disable nvidia, gsync nvidia and disable logging, with descriptions of the combinations possible) or these two presented in this PR. So far these two seem like the best compromise (albeit being a little tricky to explain).
Notes
- Only disables for video adapter with "nvidia" in the name, on windows only.
- Tested by @elvisish and confirmed to work (I can't fully test this, as I don't have windows or nvidia GPU).
- Added a command line switch
--allow-gdriver-toto override the project setting just in case an end user wants to play a game with multithread optimizations enabled. This also works for the nvidia driver method. verbose_loggingtakes precedence, but by definition if that is on, it will also disable threaded optimization. So probably no need to mention it in the docs.- We might not need the full complement of debug logging in order to trick the driver into disabling T.O.. It might be possible to call a subset of the commands, or toggle the logging on then off. Unfortunately I can't test this as I don't have the required hardware but would welcome testing / modifications / follow up PRs if we can minimize the logging requirements further.