Mesa (master): st/mesa: minor optimization in st_DrawBuffers()

Brian Paul brianp at kemper.freedesktop.org
Thu Apr 13 03:45:05 UTC 2017


Module: Mesa
Branch: master
Commit: c36d224921da0846b808a317d5b71a78b31bfd3d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c36d224921da0846b808a317d5b71a78b31bfd3d

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Apr 10 21:09:41 2017 -0600

st/mesa: minor optimization in st_DrawBuffers()

We only do on-demand renderbuffer allocation for window-system FBOs,
not user-created FBOs.  So put the loop inside a conditional.

Plus, add some comments.  No piglit regressions.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>

---

 src/mesa/state_tracker/st_cb_fbo.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index dce4239438..21fc5420d5 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -690,31 +690,39 @@ st_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 
 
 /**
- * Called via glDrawBuffer.
+ * Called via glDrawBuffer.  We only provide this driver function so that we
+ * can check if we need to allocate a new renderbuffer.  Specifically, we
+ * don't usually allocate a front color buffer when using a double-buffered
+ * visual.  But if the app calls glDrawBuffer(GL_FRONT) we need to allocate
+ * that buffer.  Note, this is only for window system buffers, not user-
+ * created FBOs.
  */
 static void
 st_DrawBuffers(struct gl_context *ctx, GLsizei count, const GLenum *buffers)
 {
    struct st_context *st = st_context(ctx);
    struct gl_framebuffer *fb = ctx->DrawBuffer;
-   GLuint i;
 
    (void) count;
    (void) buffers;
 
-   /* add the renderbuffers on demand */
-   for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
-      GLint idx = fb->_ColorDrawBufferIndexes[i];
+   if (_mesa_is_winsys_fbo(fb)) {
+      GLuint i;
+      /* add the renderbuffers on demand */
+      for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
+         GLint idx = fb->_ColorDrawBufferIndexes[i];
 
-      if (idx >= 0) {
-         st_manager_add_color_renderbuffer(st, fb, idx);
+         if (idx >= 0) {
+            st_manager_add_color_renderbuffer(st, fb, idx);
+         }
       }
    }
 }
 
 
 /**
- * Called via glReadBuffer.
+ * Called via glReadBuffer.  As with st_DrawBuffers, we use this function
+ * to check if we need to allocate a renderbuffer on demand.
  */
 static void
 st_ReadBuffer(struct gl_context *ctx, GLenum buffer)




More information about the mesa-commit mailing list