Repository: godot
Issue: nVidia "Threaded Optimization" Driver Setting Intefering with Godot Preload Capabilities
Labels: bug,platform:windows,topic:rendering,topic:thirdparty,needs testing

<!-- Please search existing issues for potential duplicates before filing yours:
https://github.com/godotengine/godot/issues?q=is%3Aissue
-->

**Godot version:** 3.2.3.stable.official (Steam Release)
<!-- Specify commit hash if using non-official build. -->


**OS/device including version:**
Windows 10 Pro 19041.423
CPU: AMD FX-8350 4 GHz
GPU: GeForce GTX 1070 - 8 GB VRAM
RAM: 16 GB
Using an HDD, not SSD, for Storage
<!-- Specify GPU model, drivers, and the backend (GLES2, GLES3, Vulkan) if graphics-related. -->


**Issue description:**
Just a couple days ago I made a report on an issue I was having with the particle system which didn't seem related to shader caching. I reported it here: https://github.com/godotengine/godot/issues/45613 . It is important to keep in mind while I explain the following issue that it seems the particle issue I reported may or may not be related, it's actually really hard to tell.

Anyways, after some investigation I discovered I was getting hiccups with instancing literally ANYTHING which was going to render a shader of any kind, it was just much more noticeable with particles for whatever reason. These hiccups were only occurring the first time an instanced object would become visible in a scene, so naturally the thought would be a caching issue and that stuff would need to be preloaded... except... I AM preloading things, and if I run my projects in a window instead of full screen, these hiccups disappear. Some mysterious difference was occurring between running my projects in a window versus full screen which was causing preloading/caching to fail.

After MANY hours of investigation, I have discovered something insidious: nVidia GeForce drivers have a setting called "Threaded Optimization", normally set to "Auto" which is used to spread CPU usage by hardware accelerated games over multiple cores. 99% of the time, changing this has zero effect on the performance of a game, though it often changes how the CPU usage for a game is spread across a multi-core processor.

...however, if I force "Threaded Optimization" into an "Off" state in my driver settings, the hiccups I was having with first-time instancing of supposedly preloaded objects while running my Godot projects full screen disappears!

So... there seems to be some sort of incompatibility with preloading assets in Godot, while running a Godot app full screen, on a GeForce card, with the card's Threaded Optimization driver setting set to on or auto, keeping in mind, it's set to "Auto" by default.

...I don't have a clue how this is supposed to be addressed by the Godot devs, since the problem is a driver setting. If this was just a single game you'd just contact nVidia and say, "Hey, could you include a profile which disables Threaded Optimization for our game? Thanks!" ...but for a game ENGINE, which makes multiple games, I really don't know what the solution here is, other than to instruct players how to disable this setting manually. :/


**Steps to reproduce:**
1. This must be done on a system with a GeForce graphics chipset.
2. Go into the nVidia driver settings and set the global profile's "Threaded Optimization" setting to "Auto" or "On". It should already be "Auto" by default.
3.  Ensure that Godot Engine itself and any projects made with it are NOT in the list of settings for individual programs in the nVidia driver settings.
4. Open any Godot project which has the ability to instance objects on command and run it full screen.
5. The very first time a shader appears on screen when instancing an object, there will be a very slight hiccup in the framerate. Subsequent instances of the object will not produce this skip in the framerate.
6. Go back into the editor and switch the project to run in a window. The hiccups will no longer occur.
7. Go back into the editor and go back to running full screen, but also go into the nVidia driver settings again and set "Threaded Optimization" to "Off". Run the project and the hiccups remain gone.
8. Turn Threaded Optimization back to "On" or "Auto" and the hiccups return.


**Minimal reproduction project:**
Literally any project which instances objects with unique shaders applied to them and is run full screen will trigger this issue.