godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Add option to prioritize integrated GPU for exported games/apps #5230

Open obackhoff opened 2 years ago

obackhoff commented 2 years ago

Describe the project you are working on

Game tools / Desktop GUI app that do not require much power to run: a server config GUI app, tool to import assets to a game, etc.

Describe the problem or limitation you are having in your project

Having a laptop with hybrid graphics sometimes I don't want my apps to turn on the dedicated GPU as it draws more power, making the fans ramp up and the temperature go up.

Even with the low processor mode, the dedicated GPU gets used when starting an exported app. This makes sense for games, naturally, but it's not ideal for small companion tools or GUI apps that we make with Godot which do not require any intensive GPU workload.

I know that one can force the OS to use one or the other but this is a bit cumbersome and I think having that as an option for a specific project/export would be much better.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

A simple checkbox in the project settings or while exporting that allows us to make the app/game prioritize the use the integrated GPU by default.

I think this could be a good feature to complement the low processor mode and would help out people looking for creating light desktop apps using Godot.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  1. Open project settings (or export project dialog)
  2. In the Application/run settings there would be a setting for prioritizing integrated GPU
  3. Exported game/app will not turn on the dedicated GPU by default, even when the laptop is plugged in

If this enhancement will not be used often, can it be worked around with a few lines of script?

There might be a way to write scripts for this depending on the OS (maybe not so easy) but it would be much nicer to have it as an option within the Editor to go along with the low processor mode.

Is there a reason why this should be core and not an add-on in the asset library?

It probably needs to be implemented in the core, where the options are set for exported games/apps, setting up a flag or something similar.

alvinhochun commented 1 month ago

Semi-related to https://github.com/godotengine/godot/pull/93985. This is certainly doable when using RenderingDevice (Vulkan), since Godot decides which GPU to use.

For GL compatibility, at least on Windows the default depends on the NVIDIA driver or AMD driver checking for the NvOptimusEnablement or AmdPowerXpressRequestHighPerformance export symbols respectively. It seems at least for NVIDIA if you do set the value of the exported symbol to 0 before any OpenGL stuff is loaded, then it does not choose the discrete graphics by default. (No idea if this works for AMD.)

But annoyingly, on NVIDIA merely loading nvapi64.dll causes the discrete GPU to be used, even if NvOptimusEnablement is set to 0. Godot seems to load this DLL to deal with NVIDIA profile stuff to disable threaded optimization, which we probably don't want to skip.