1
0
Fork 0
godot/servers/rendering/renderer_rd
Matias N. Goldberg acf439e96d Keep processing Graphics if there are pending operations
Fixes #90017
Fixes #90030
Fixes #98044

This PR makes the following changes:

# Force processing of GPU commands for frame_count frames

The variable `frames_pending_resources_for_processing` is added to track
this.

The ticket #98044 suggested to use `_flush_and_stall_for_all_frames()`
while minimized.

Technically this works and is a viable solution.

However I noticed that this issue was happening because Logic/Physics
continue to work "business as usual" while minimized(\*). Only Graphics
was being deactivated (which caused commands to accumulate until window
is restored).

To continue this behavior of "business as usual", I decided that GPU
work should also "continue as usual" by buffering commands in a double
or triple buffer scheme until all commands are done processing (if they
ever stop coming). This is specially important if the app specifically
intends to keep processing while minimized.

Calling `_flush_and_stall_for_all_frames()` would fix the leak, but it
would make  Godot's behavior different while minimized vs while the
window is presenting.

\* `OS::add_frame_delay` _does_ consider being minimized, but it just
throttles CPU usage. Some platforms such as Android completely disable
processing because the higher level code stops being called when the app
goes into background. But this seems like an implementation-detail that
diverges from the rest of the platforms (e.g. Windows, Linux & macOS
continue to process while minimized).

# Rename p_swap_buffers for p_present

**This is potentially a breaking change** (if it actually breaks
anything, I ignore. But I strongly suspect it doesn't break anything).

"Swap Buffers" is a concept carried from OpenGL, where a frame is "done"
when `glSwapBuffers()` is called, which basically means "present to the
screen".

However it _also_ means that OpenGL internally swaps its internal
buffers in a double/triple buffer scheme (in Vulkan, we do that
ourselves and is tracked by `RenderingDevice::frame`).

Modern APIs like Vulkan differentiate between "submitting GPU work" and
"presenting".

Before this PR, calling `RendererCompositorRD::end_frame(false)` would
literally do nothing. This is often undesired and the cause of the leak.
After this PR, calling `RendererCompositorRD::end_frame(false)` will now
process commands, swap our internal buffers in a double/triple buffer
scheme **but avoid presenting to the screen**.

Hence the rename of the variable from `p_swap_buffers` to `p_present`
(which slightly alters its behavior).
If we want `RendererCompositorRD::end_frame(false)` to do nothing, then
we should not call it at all.

This PR reflects such change: When we're minimized **_and_**
`has_pending_resources_for_processing()` returns false, we don't call
`RendererCompositorRD::end_frame()` at all.

But if `has_pending_resources_for_processing()` returns true, we will
call it, but with `p_present = false` because we're minimized.

There's still the issue that Godot keeps processing work (logic,
scripts, physics) while minimized, which we shouldn't do by default. But
that's work for follow up PR.
2024-12-11 14:13:29 -03:00
..
effects Optimize RenderForwardClustered::_setup_render_pass_uniform_set by reducing Vector allocations during push_back operations 2024-12-02 15:03:50 +01:00
environment Optimize RenderForwardClustered::_setup_render_pass_uniform_set by reducing Vector allocations during push_back operations 2024-12-02 15:03:50 +01:00
forward_clustered Optimize RenderForwardClustered::_setup_render_pass_uniform_set by reducing Vector allocations during push_back operations 2024-12-02 15:03:50 +01:00
forward_mobile Add specialization for directional light split blend and fog. 2024-12-03 15:12:46 -03:00
shaders Merge pull request #94193 from BastiaanOlij/buildin_includes 2024-12-05 14:12:23 -06:00
spirv-reflect SCons: Add unobtrusive type hints in SCons files 2024-09-25 09:34:35 -05:00
storage_rd Merge pull request #100064 from clayjohn/atlas-realloc-time 2024-12-05 14:12:19 -06:00
SCsub SCons: Add unobtrusive type hints in SCons files 2024-09-25 09:34:35 -05:00
cluster_builder_rd.cpp Resolve load and store ops automatically for render passes for discardable textures. 2024-11-25 11:27:48 -03:00
cluster_builder_rd.h Add Metal support for macOS (arm64) and iOS 2024-08-20 12:11:06 +02:00
framebuffer_cache_rd.cpp Implement hooks into renderer 2024-02-18 21:54:21 +11:00
framebuffer_cache_rd.h Implement hooks into renderer 2024-02-18 21:54:21 +11:00
pipeline_cache_rd.cpp Implement asynchronous transfer queues, thread guards on RenderingDevice. Add ubershaders and rework pipeline caches for Forward+ and Mobile. 2024-10-02 15:11:58 -03:00
pipeline_cache_rd.h Implement asynchronous transfer queues, thread guards on RenderingDevice. Add ubershaders and rework pipeline caches for Forward+ and Mobile. 2024-10-02 15:11:58 -03:00
pipeline_hash_map_rd.h Implement asynchronous transfer queues, thread guards on RenderingDevice. Add ubershaders and rework pipeline caches for Forward+ and Mobile. 2024-10-02 15:11:58 -03:00
renderer_canvas_render_rd.cpp Optimize RenderForwardClustered::_setup_render_pass_uniform_set by reducing Vector allocations during push_back operations 2024-12-02 15:03:50 +01:00
renderer_canvas_render_rd.h Mask out shadows on CanvasItems that don't have a matching item_shadow_mask 2024-11-21 22:15:54 -08:00
renderer_compositor_rd.cpp Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
renderer_compositor_rd.h Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
renderer_scene_render_rd.cpp Merge pull request #94193 from BastiaanOlij/buildin_includes 2024-12-05 14:12:23 -06:00
renderer_scene_render_rd.h Set clang-format `RemoveSemicolon` rule to `true` 2024-10-25 13:49:43 -04:00
shader_rd.cpp Adding ability to include build-in include files (precursor to custom shader templates) 2024-11-24 08:47:45 +11:00
shader_rd.h Implement asynchronous transfer queues, thread guards on RenderingDevice. Add ubershaders and rework pipeline caches for Forward+ and Mobile. 2024-10-02 15:11:58 -03:00
uniform_set_cache_rd.cpp Optimize RenderForwardClustered::_setup_render_pass_uniform_set by reducing Vector allocations during push_back operations 2024-12-02 15:03:50 +01:00
uniform_set_cache_rd.h Optimize RenderForwardClustered::_setup_render_pass_uniform_set by reducing Vector allocations during push_back operations 2024-12-02 15:03:50 +01:00