[mutter/wip/carlosg/performance-improvements: 32/38] cogl: Ensure to only clear the depth buffer if depth testing is enabled
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/performance-improvements: 32/38] cogl: Ensure to only clear the depth buffer if depth testing is enabled
- Date: Mon, 22 May 2017 15:44:24 +0000 (UTC)
commit 864bc793aaa55d33e13fe396e5565e0d8f06ef91
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon May 8 15:10:58 2017 +0200
cogl: Ensure to only clear the depth buffer if depth testing is enabled
The depth buffer is marked as invalid when 1) the framebuffer is just created,
and 2) whenever GL_DEPTH_TEST is enabled on it. This will ensure the
framebuffers attached depth buffer (if any) is properly cleared before it's
actually used, while saving needless clears while depth testing is disabled
(the default).
https://bugzilla.gnome.org/show_bug.cgi?id=782344
cogl/cogl/cogl-framebuffer-private.h | 5 +++++
cogl/cogl/cogl-framebuffer.c | 11 +++++++++++
cogl/cogl/driver/gl/cogl-pipeline-opengl.c | 6 +++++-
3 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/cogl/cogl/cogl-framebuffer-private.h b/cogl/cogl/cogl-framebuffer-private.h
index 99ac2fb..756e34d 100644
--- a/cogl/cogl/cogl-framebuffer-private.h
+++ b/cogl/cogl/cogl-framebuffer-private.h
@@ -193,6 +193,11 @@ struct _CoglFramebuffer
CoglFramebufferBits bits;
int samples_per_pixel;
+
+ /* Whether the depth buffer was enabled for this framebuffer,
+ * usually means it needs to be cleared before being reused next.
+ */
+ CoglBool depth_buffer_clear_needed;
};
typedef enum {
diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c
index 55b9e37..6b10508 100644
--- a/cogl/cogl/cogl-framebuffer.c
+++ b/cogl/cogl/cogl-framebuffer.c
@@ -117,6 +117,7 @@ _cogl_framebuffer_init (CoglFramebuffer *framebuffer,
framebuffer->viewport_age_for_scissor_workaround = -1;
framebuffer->dither_enabled = TRUE;
framebuffer->depth_writing_enabled = TRUE;
+ framebuffer->depth_buffer_clear_needed = TRUE;
framebuffer->modelview_stack = cogl_matrix_stack_new (ctx);
framebuffer->projection_stack = cogl_matrix_stack_new (ctx);
@@ -268,6 +269,13 @@ cogl_framebuffer_clear4f (CoglFramebuffer *framebuffer,
int scissor_y1;
CoglBool saved_viewport_scissor_workaround;
+ if (!framebuffer->depth_buffer_clear_needed &&
+ (buffers & COGL_BUFFER_BIT_DEPTH))
+ buffers &= ~(COGL_BUFFER_BIT_DEPTH);
+
+ if (buffers == 0)
+ return;
+
_cogl_clip_stack_get_bounds (clip_stack,
&scissor_x0, &scissor_y0,
&scissor_x1, &scissor_y1);
@@ -415,6 +423,9 @@ cleared:
_cogl_framebuffer_mark_mid_scene (framebuffer);
_cogl_framebuffer_mark_clear_clip_dirty (framebuffer);
+ if (buffers & COGL_BUFFER_BIT_DEPTH)
+ framebuffer->depth_buffer_clear_needed = FALSE;
+
if (buffers & COGL_BUFFER_BIT_COLOR && buffers & COGL_BUFFER_BIT_DEPTH)
{
/* For our fast-path for reading back a single pixel of simple
diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c
index 1782696..4f1f69f 100644
--- a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c
+++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c
@@ -418,7 +418,11 @@ flush_depth_state (CoglContext *ctx,
if (ctx->depth_test_enabled_cache != depth_state->test_enabled)
{
if (depth_state->test_enabled == TRUE)
- GE (ctx, glEnable (GL_DEPTH_TEST));
+ {
+ GE (ctx, glEnable (GL_DEPTH_TEST));
+ if (ctx->current_draw_buffer)
+ ctx->current_draw_buffer->depth_buffer_clear_needed = TRUE;
+ }
else
GE (ctx, glDisable (GL_DEPTH_TEST));
ctx->depth_test_enabled_cache = depth_state->test_enabled;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]