[Mesa-dev] [PATCH 18/20] i915: Drop broken front_buffer_reading/drawing optimization

ville.syrjala at linux.intel.com ville.syrjala at linux.intel.com
Mon Mar 23 05:47:34 PDT 2015


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Bring the following commit over to i915:
 commit ec542d74578bbef6b55125dd6aba1dc7f5079e65
 Author: Eric Anholt <eric at anholt.net>
 Date:   Mon Mar 3 10:43:10 2014 -0800

    i965: Drop broken front_buffer_reading/drawing optimization.

Not sure if it might fix anything, but since the i965 and i915 used to
share a bunch of that code, it would seem reasonable the same problems
could be present in the i915 code still, and the i965 approach is well
tested by now so bringing it over seems fairly safe.

No piglit regressions on 855.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 src/mesa/drivers/dri/i915/intel_buffers.c | 47 ++++++++++++++++++-------------
 src/mesa/drivers/dri/i915/intel_buffers.h |  3 ++
 src/mesa/drivers/dri/i915/intel_context.c | 12 ++++----
 src/mesa/drivers/dri/i915/intel_context.h | 16 -----------
 4 files changed, 37 insertions(+), 41 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/intel_buffers.c b/src/mesa/drivers/dri/i915/intel_buffers.c
index 51eaea4..d413998 100644
--- a/src/mesa/drivers/dri/i915/intel_buffers.c
+++ b/src/mesa/drivers/dri/i915/intel_buffers.c
@@ -52,23 +52,36 @@ intel_check_front_buffer_rendering(struct intel_context *intel)
    }
 }
 
+bool
+intel_is_front_buffer_reading(struct gl_framebuffer *fb)
+{
+   if (!fb || _mesa_is_user_fbo(fb))
+      return false;
+
+   return fb->_ColorReadBufferIndex == BUFFER_FRONT_LEFT;
+}
+
+bool
+intel_is_front_buffer_drawing(struct gl_framebuffer *fb)
+{
+   if (!fb || _mesa_is_user_fbo(fb))
+      return false;
+
+   return (fb->_NumColorDrawBuffers >= 1 &&
+           fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT);
+}
+
 static void
 intelDrawBuffer(struct gl_context * ctx, GLenum mode)
 {
-   if (ctx->DrawBuffer && _mesa_is_winsys_fbo(ctx->DrawBuffer)) {
+   if (intel_is_front_buffer_drawing(ctx->DrawBuffer)) {
       struct intel_context *const intel = intel_context(ctx);
-      const bool was_front_buffer_rendering =
-	intel->is_front_buffer_rendering;
 
-      intel->is_front_buffer_rendering = (mode == GL_FRONT_LEFT)
-	|| (mode == GL_FRONT) || (mode == GL_FRONT_AND_BACK);
-
-      /* If we weren't front-buffer rendering before but we are now,
-       * invalidate our DRI drawable so we'll ask for new buffers
+      /* If we might be front-buffer rendering on this buffer for the first
+       * time, invalidate our DRI drawable so we'll ask for new buffers
        * (including the fake front) before we start rendering again.
        */
-      if (!was_front_buffer_rendering && intel->is_front_buffer_rendering)
-	 dri2InvalidateDrawable(intel->driContext->driDrawablePriv);
+      dri2InvalidateDrawable(intel->driContext->driDrawablePriv);
    }
 
    intel_draw_buffer(ctx);
@@ -78,20 +91,14 @@ intelDrawBuffer(struct gl_context * ctx, GLenum mode)
 static void
 intelReadBuffer(struct gl_context * ctx, GLenum mode)
 {
-   if (ctx->ReadBuffer && _mesa_is_winsys_fbo(ctx->ReadBuffer)) {
+   if (intel_is_front_buffer_reading(ctx->ReadBuffer)) {
       struct intel_context *const intel = intel_context(ctx);
-      const bool was_front_buffer_reading =
-	intel->is_front_buffer_reading;
-
-      intel->is_front_buffer_reading = (mode == GL_FRONT_LEFT)
-	|| (mode == GL_FRONT);
 
-      /* If we weren't front-buffer reading before but we are now,
-       * invalidate our DRI drawable so we'll ask for new buffers
+      /* If we might be front-buffer reading on this buffer for the first
+       * time, invalidate our DRI drawable so we'll ask for new buffers
        * (including the fake front) before we start reading again.
        */
-      if (!was_front_buffer_reading && intel->is_front_buffer_reading)
-	 dri2InvalidateDrawable(intel->driContext->driReadablePriv);
+      dri2InvalidateDrawable(intel->driContext->driReadablePriv);
    }
 }
 
diff --git a/src/mesa/drivers/dri/i915/intel_buffers.h b/src/mesa/drivers/dri/i915/intel_buffers.h
index 42d84bc..890444c 100644
--- a/src/mesa/drivers/dri/i915/intel_buffers.h
+++ b/src/mesa/drivers/dri/i915/intel_buffers.h
@@ -49,4 +49,7 @@ intel_draw_buffer(struct gl_context * ctx)
 extern void intelInitBufferFuncs(struct dd_function_table *functions);
 void intelCalcViewport(struct gl_context * ctx);
 
+bool intel_is_front_buffer_reading(struct gl_framebuffer *fb);
+bool intel_is_front_buffer_drawing(struct gl_framebuffer *fb);
+
 #endif /* INTEL_BUFFERS_H */
diff --git a/src/mesa/drivers/dri/i915/intel_context.c b/src/mesa/drivers/dri/i915/intel_context.c
index 5f45125..be209dc 100644
--- a/src/mesa/drivers/dri/i915/intel_context.c
+++ b/src/mesa/drivers/dri/i915/intel_context.c
@@ -243,7 +243,7 @@ intel_prepare_render(struct intel_context *intel)
     * that will happen next will probably dirty the front buffer.  So
     * mark it as dirty here.
     */
-   if (intel->is_front_buffer_rendering)
+   if (intel_is_front_buffer_drawing(intel->ctx.DrawBuffer))
       intel->front_buffer_dirty = true;
 
    /* Wait for the swapbuffers before the one we just emitted, so we
@@ -356,7 +356,7 @@ intel_glFlush(struct gl_context *ctx)
 
    intel_flush(ctx);
    intel_flush_front(ctx);
-   if (intel->is_front_buffer_rendering)
+   if (intel_is_front_buffer_drawing(ctx->DrawBuffer))
       intel->need_throttle = true;
 }
 
@@ -701,8 +701,8 @@ intel_query_dri2_buffers(struct intel_context *intel,
    back_rb = intel_get_renderbuffer(fb, BUFFER_BACK_LEFT);
 
    memset(attachments, 0, sizeof(attachments));
-   if ((intel->is_front_buffer_rendering ||
-	intel->is_front_buffer_reading ||
+   if ((intel_is_front_buffer_drawing(fb) ||
+        intel_is_front_buffer_reading(fb) ||
 	!back_rb) && front_rb) {
       /* If a fake front buffer is in use, then querying for
        * __DRI_BUFFER_FRONT_LEFT will cause the server to copy the image from
@@ -867,8 +867,10 @@ intel_update_image_buffers(struct intel_context *intel, __DRIdrawable *drawable)
    else
       return;
 
-   if ((intel->is_front_buffer_rendering || intel->is_front_buffer_reading || !back_rb) && front_rb)
+   if (front_rb && (intel_is_front_buffer_drawing(fb) ||
+                    intel_is_front_buffer_reading(fb) || !back_rb)) {
       buffer_mask |= __DRI_IMAGE_BUFFER_FRONT;
+   }
 
    if (back_rb)
       buffer_mask |= __DRI_IMAGE_BUFFER_BACK;
diff --git a/src/mesa/drivers/dri/i915/intel_context.h b/src/mesa/drivers/dri/i915/intel_context.h
index 1bbd58f..1f60abc 100644
--- a/src/mesa/drivers/dri/i915/intel_context.h
+++ b/src/mesa/drivers/dri/i915/intel_context.h
@@ -255,22 +255,6 @@ struct intel_context
     */
    bool front_buffer_dirty;
 
-   /**
-    * Track whether front-buffer rendering is currently enabled
-    *
-    * A separate flag is used to track this in order to support MRT more
-    * easily.
-    */
-   bool is_front_buffer_rendering;
-   /**
-    * Track whether front-buffer is the current read target.
-    *
-    * This is closely associated with is_front_buffer_rendering, but may
-    * be set separately.  The DRI2 fake front buffer must be referenced
-    * either way.
-    */
-   bool is_front_buffer_reading;
-
    bool use_early_z;
 
    int driFd;
-- 
2.0.5



More information about the mesa-dev mailing list