1
0
Fork 0
godot/servers/rendering
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
..
dummy Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
environment
renderer_rd Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
storage Implemented multimesh_get_buffer_rd_rid function into RenderingServer. 2024-11-14 15:52:08 -06:00
SCsub SCons: Add unobtrusive type hints in SCons files 2024-09-25 09:34:35 -05:00
renderer_canvas_cull.cpp Merge pull request #85359 from miv391/faster-exit-from-cull_canvas_item 2024-11-18 09:23:51 -06:00
renderer_canvas_cull.h Don't recalculate final render transforms for Y-sorted canvas items 2024-09-05 17:45:38 +02:00
renderer_canvas_render.cpp
renderer_canvas_render.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_compositor.cpp fix missing cleanup and null checks for various singletons 2024-06-18 01:05:30 -07:00
renderer_compositor.h Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
renderer_geometry_instance.cpp
renderer_geometry_instance.h
renderer_scene_cull.cpp Get rid of easily removable uses of const_cast 2024-12-01 17:50:13 -08:00
renderer_scene_cull.h Get rid of easily removable uses of const_cast 2024-12-01 17:50:13 -08:00
renderer_scene_occlusion_cull.cpp
renderer_scene_occlusion_cull.h Merge pull request #97934 from adamscott/give-AThousandShips-a-break 2024-10-29 19:25:36 -05:00
renderer_scene_render.cpp Merge pull request #86138 from EnlightenedOne/master 2024-11-04 21:52:07 -06:00
renderer_scene_render.h Merge pull request #86138 from EnlightenedOne/master 2024-11-04 21:52:07 -06:00
renderer_viewport.cpp Apply snap 2D transforms to pixel to viewport 2024-09-23 20:34:11 +08:00
renderer_viewport.h Ensure MovieWriter output is in gamma space when using HDR 2D 2024-05-28 15:30:13 -07:00
rendering_context_driver.cpp Disable extra memory tracking by default 2024-08-24 20:52:39 -03:00
rendering_context_driver.h Disable extra memory tracking by default 2024-08-24 20:52:39 -03:00
rendering_device.compat.inc Resolve load and store ops automatically for render passes for discardable textures. 2024-11-25 11:27:48 -03:00
rendering_device.cpp Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
rendering_device.h Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
rendering_device_binds.cpp Adding ability to include build-in include files (precursor to custom shader templates) 2024-11-24 08:47:45 +11:00
rendering_device_binds.h Resolve load and store ops automatically for render passes for discardable textures. 2024-11-25 11:27:48 -03:00
rendering_device_commons.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
rendering_device_commons.h Resolve load and store ops automatically for render passes for discardable textures. 2024-11-25 11:27:48 -03:00
rendering_device_driver.cpp Add dependency detection improvements to the render graph. 2024-11-01 09:46:52 -03:00
rendering_device_driver.h Merge pull request #98910 from darksylinc/matias-id_arm32 2024-11-10 12:12:53 -06:00
rendering_device_graph.cpp Resolve load and store ops automatically for render passes for discardable textures. 2024-11-25 11:27:48 -03:00
rendering_device_graph.h Resolve load and store ops automatically for render passes for discardable textures. 2024-11-25 11:27:48 -03:00
rendering_light_culler.cpp Tighter light culling - fix directional lights colinear case 2024-05-10 09:13:05 +01:00
rendering_light_culler.h Tight shadow culling - increase epsilon to prevent flickering 2024-05-18 14:14:27 +01:00
rendering_method.cpp
rendering_method.h Added external camera feed from external plugin on Android 2024-10-30 18:30:28 +01:00
rendering_server_constants.h Fixed Timestep Interpolation (3D) 2024-07-07 22:15:23 +02:00
rendering_server_default.cpp Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
rendering_server_default.h Keep processing Graphics if there are pending operations 2024-12-11 14:13:29 -03:00
rendering_server_globals.cpp
rendering_server_globals.h
shader_compiler.cpp Add prefix to struct member names in shader compiler 2024-11-02 12:13:23 +03:00
shader_compiler.h Fix broken sky shader 2024-09-13 08:53:26 +03:00
shader_include_db.cpp Adding ability to include build-in include files (precursor to custom shader templates) 2024-11-24 08:47:45 +11:00
shader_include_db.h Adding ability to include build-in include files (precursor to custom shader templates) 2024-11-24 08:47:45 +11:00
shader_language.cpp Fix orphan strings in shader preprocessor 2024-11-28 11:22:17 +03:00
shader_language.h Fix orphan strings in shader preprocessor 2024-11-28 11:22:17 +03:00
shader_preprocessor.cpp Fix orphan strings in shader preprocessor 2024-11-28 11:22:17 +03:00
shader_preprocessor.h Fix orphan strings in shader preprocessor 2024-11-28 11:22:17 +03:00
shader_types.cpp Allow `SCREEN_UV` to be used in light function of spatial shader 2024-11-19 11:39:49 +03:00
shader_types.h
shader_warnings.cpp Warn users when assigning VERTEX directly to POSITION due to compatibility breakage from reverse z changes 2024-04-12 10:38:35 -07:00
shader_warnings.h Warn users when assigning VERTEX directly to POSITION due to compatibility breakage from reverse z changes 2024-04-12 10:38:35 -07:00