From 523b27e2672efa1a2a1901fb6352e6c50f57f039 Mon Sep 17 00:00:00 2001 From: Erico Nunes Date: Tue, 16 Nov 2021 16:44:39 +0100 Subject: [PATCH] cogl/onscreen: Discard depth/stencil before swapping buffers Marking the the depth/stencil as discarded before swapping buffers for the screen signals the GPU that we don't need to keep them around for the future. This helps performance by reducing memory bandwidth usage in some GPUs which may optimize to not write those buffers back to memory at all after rendering, when they would just be cleared right after that anyway. It is not necessary to mark buffers as discarded after swapping buffers. This should have no effect according to the spec (since that is going to be followed by new rendering commands which make the buffer valid again) and removing that has shown no impact in performance tests. Signed-off-by: Erico Nunes Part-of: --- cogl/cogl/cogl-onscreen.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cogl/cogl/cogl-onscreen.c b/cogl/cogl/cogl-onscreen.c index ff9e1749a..842ececf7 100644 --- a/cogl/cogl/cogl-onscreen.c +++ b/cogl/cogl/cogl-onscreen.c @@ -334,17 +334,16 @@ cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen, if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SYNC_FRAME))) cogl_framebuffer_finish (framebuffer); + cogl_framebuffer_discard_buffers (framebuffer, + COGL_BUFFER_BIT_DEPTH | + COGL_BUFFER_BIT_STENCIL); + klass->swap_buffers_with_damage (onscreen, rectangles, n_rectangles, info, user_data); - cogl_framebuffer_discard_buffers (framebuffer, - COGL_BUFFER_BIT_COLOR | - COGL_BUFFER_BIT_DEPTH | - COGL_BUFFER_BIT_STENCIL); - if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) { CoglFrameInfo *info; @@ -395,17 +394,16 @@ cogl_onscreen_swap_region (CoglOnscreen *onscreen, COGL_WINSYS_FEATURE_SWAP_REGION */ g_return_if_fail (klass->swap_region); + cogl_framebuffer_discard_buffers (framebuffer, + COGL_BUFFER_BIT_DEPTH | + COGL_BUFFER_BIT_STENCIL); + klass->swap_region (onscreen, rectangles, n_rectangles, info, user_data); - cogl_framebuffer_discard_buffers (framebuffer, - COGL_BUFFER_BIT_COLOR | - COGL_BUFFER_BIT_DEPTH | - COGL_BUFFER_BIT_STENCIL); - if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) { CoglFrameInfo *info;