godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 68 forks source link

Temporarily stop rendering 2D/3D views when unfocused #10042

Open Sectonidse opened 3 days ago

Sectonidse commented 3 days ago

Describe the project you are working on

A winter-themed game, menu of which has a lot of 3D particles resembling snowflakes

Describe the problem or limitation you are having in your project

I have a laptop without a dedicated GPU with two screens, and when i focus to a different app (Chrome), the 3D view starts to struggle (GPU time increases from ~8 ms and 109 fps to ~36 ms and 33 fps), which i don't like to see, considering this is a laptop with a battery and not a PC.

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

It will consume less resources when the editor is unfocused

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

When user moves focus to another window, the 2D/3D Views stop rendering. However, when it's focused to another window OF the Godot Engine's Editor, then it will keep renderint (useful when writing tool scripts or shaders!) Here's the concept art that i did: UnfocusedRendering_ConceptArt

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

I don't think so...

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

This will improve laptop's performance

AThousandShips commented 3 days ago

This should be a setting IMO, it's perfectly valid to want to see what's going on if you have some windows open

Mickeon commented 3 days ago

Related to https://github.com/godotengine/godot-proposals/issues/2001

Your GPU settings should have "FPS when out-of-focus" setting for each application you run. It should work with Godot too (I know it does for me).

I think completely halting rendering would be quite disorienting, so it should probably be an FPS slider of sorts.

Edit: @Calinou was in fact working on this https://github.com/godotengine/godot/pull/47812 , but it was never merged.

Zireael07 commented 3 days ago

Your GPU settings should have "FPS when out-of-focus"

Which GPU/drivers is that? I never had such a setting on any computer I owned, not AMD, not NVIDIA...

AThousandShips commented 3 days ago

Indeed my bad thought the suggestion was for having it happen when focusing other Godot windows, this is a bug I believe, the editor already supports this, but it breaks in some hardware and OSs, the editor should not process and redraw when unfocused:

// Set a low FPS cap to decrease CPU/GPU usage while the editor is unfocused.
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec")));
Sectonidse commented 3 days ago

Your GPU settings should have "FPS when out-of-focus" setting for each application you run.

Well, as i said i don't have a dedicated GPU in my laptop so i bet that i'll find it in a Control Panel for my Integrated graphics if there even is one

I think completely halting rendering would be quite disorienting, so it should probably be an FPS slider of sorts.

Perhaps we can get add an FPS limiter that if you set it to 0, then you'll see what i did in the concept art (i apologize for my bad English here).

Calinou commented 2 days ago

I think https://github.com/godotengine/godot-proposals/issues/942 is a better solution to this problem. It's already in place in 3.5 (enable Vital Updates Only in the Editor Settings or by clicking the update spinner if it's shown), but hasn't been ported to 4.x yet.

As a workaround, hide your particles in the editor and show() them in a script.

the editor should not process and redraw when unfocused:

It should if there's animated content in its viewport, such as an active AnimationPlayer/AnimationTree, particles, or a shader using TIME. One exception to this rule is with the aforementioned Vital Updates Only option, which specifically ignores these redraw requests (and only those).