[Mesa-dev] [PATCH 5/5] st/mesa: don't update unrelated states in non-draw calls such as Clear

Marek Olšák maraeo at gmail.com
Thu Feb 23 00:07:51 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

If a VAO isn't bound and u_vbuf isn't enabled because of the Core profile,
we'll get user vertex buffers in drivers if we update vertex buffers
in glClear. So don't do that.

This fixes a regression since disabling u_vbuf for Core profiles.
---
 src/mesa/state_tracker/st_atom.c          | 10 ++++++++++
 src/mesa/state_tracker/st_atom.h          |  7 +++++++
 src/mesa/state_tracker/st_cb_clear.c      |  2 +-
 src/mesa/state_tracker/st_cb_fbo.c        |  2 +-
 src/mesa/state_tracker/st_cb_msaa.c       |  2 +-
 src/mesa/state_tracker/st_cb_readpixels.c |  2 +-
 6 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
index 65ac517..4bef342 100644
--- a/src/mesa/state_tracker/st_atom.c
+++ b/src/mesa/state_tracker/st_atom.c
@@ -169,20 +169,30 @@ void st_validate_state( struct st_context *st, enum st_pipeline pipeline )
    case ST_PIPELINE_RENDER:
       if (st->ctx->API == API_OPENGL_COMPAT)
          check_attrib_edgeflag(st);
 
       check_program_state(st);
       st_manager_validate_framebuffers(st);
 
       pipeline_mask = ST_PIPELINE_RENDER_STATE_MASK;
       break;
 
+   case ST_PIPELINE_CLEAR:
+      st_manager_validate_framebuffers(st);
+      pipeline_mask = ST_PIPELINE_CLEAR_STATE_MASK;
+      break;
+
+   case ST_PIPELINE_UPDATE_FRAMEBUFFER:
+      st_manager_validate_framebuffers(st);
+      pipeline_mask = ST_PIPELINE_UPDATE_FB_STATE_MASK;
+      break;
+
    case ST_PIPELINE_COMPUTE: {
       struct st_compute_program *old_cp = st->cp;
       struct gl_program *new_cp = ctx->ComputeProgram._Current;
 
       if (new_cp != &old_cp->Base) {
          if (old_cp)
             st->dirty |= old_cp->affected_states;
          assert(new_cp);
          st->dirty |= st_compute_program(new_cp)->affected_states;
       }
diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h
index 37e382c..45c3e48 100644
--- a/src/mesa/state_tracker/st_atom.h
+++ b/src/mesa/state_tracker/st_atom.h
@@ -36,20 +36,22 @@
 
 #include "main/glheader.h"
 
 struct st_context;
 
 /**
  * Enumeration of state tracker pipelines.
  */
 enum st_pipeline {
    ST_PIPELINE_RENDER,
+   ST_PIPELINE_CLEAR,
+   ST_PIPELINE_UPDATE_FRAMEBUFFER,
    ST_PIPELINE_COMPUTE,
 };
 
 struct st_tracked_state {
    void (*update)( struct st_context *st );
 };
 
 
 void st_init_atoms( struct st_context *st );
 void st_destroy_atoms( struct st_context *st );
@@ -138,15 +140,20 @@ enum {
                                  ST_NEW_SAMPLERS | \
                                  ST_NEW_CONSTANTS | \
                                  ST_NEW_UNIFORM_BUFFER | \
                                  ST_NEW_ATOMIC_BUFFER | \
                                  ST_NEW_STORAGE_BUFFER | \
                                  ST_NEW_IMAGE_UNITS)
 
 /* All state flags within each group: */
 #define ST_PIPELINE_RENDER_STATE_MASK  (ST_NEW_CS_STATE - 1)
 #define ST_PIPELINE_COMPUTE_STATE_MASK (0xffllu << ST_NEW_CS_STATE_INDEX)
+#define ST_PIPELINE_CLEAR_STATE_MASK (ST_NEW_FB_STATE | \
+                                      ST_NEW_SCISSOR | \
+                                      ST_NEW_WINDOW_RECTANGLES)
+/* For ReadPixels, ReadBuffer, GetSamplePosition: */
+#define ST_PIPELINE_UPDATE_FB_STATE_MASK (ST_NEW_FB_STATE)
 
 #define ST_ALL_STATES_MASK (ST_PIPELINE_RENDER_STATE_MASK | \
                             ST_PIPELINE_COMPUTE_STATE_MASK)
 
 #endif
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 158efc1..f507775 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -399,21 +399,21 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
    struct gl_renderbuffer *stencilRb
       = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
    GLbitfield quad_buffers = 0x0;
    GLbitfield clear_buffers = 0x0;
    GLuint i;
 
    st_flush_bitmap_cache(st);
    st_invalidate_readpix_cache(st);
 
    /* This makes sure the pipe has the latest scissor, etc values */
-   st_validate_state( st, ST_PIPELINE_RENDER );
+   st_validate_state(st, ST_PIPELINE_CLEAR);
 
    if (mask & BUFFER_BITS_COLOR) {
       for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
          GLint b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
 
          if (b >= 0 && mask & (1 << b)) {
             struct gl_renderbuffer *rb
                = ctx->DrawBuffer->Attachment[b].Renderbuffer;
             struct st_renderbuffer *strb = st_renderbuffer(rb);
             int colormask_index = ctx->Extensions.EXT_draw_buffers2 ? i : 0;
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index d762ca6..78433bf 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -727,21 +727,21 @@ st_ReadBuffer(struct gl_context *ctx, GLenum buffer)
    /* Check if we need to allocate a front color buffer.
     * Front buffers are often allocated on demand (other color buffers are
     * always allocated in advance).
     */
    if ((fb->_ColorReadBufferIndex == BUFFER_FRONT_LEFT ||
         fb->_ColorReadBufferIndex == BUFFER_FRONT_RIGHT) &&
        fb->Attachment[fb->_ColorReadBufferIndex].Type == GL_NONE) {
       /* add the buffer */
       st_manager_add_color_renderbuffer(st, fb, fb->_ColorReadBufferIndex);
       _mesa_update_state(ctx);
-      st_validate_state(st, ST_PIPELINE_RENDER);
+      st_validate_state(st, ST_PIPELINE_UPDATE_FRAMEBUFFER);
    }
 }
 
 
 
 /**
  * Called via ctx->Driver.MapRenderbuffer.
  */
 static void
 st_MapRenderbuffer(struct gl_context *ctx,
diff --git a/src/mesa/state_tracker/st_cb_msaa.c b/src/mesa/state_tracker/st_cb_msaa.c
index 22001e4..7f1b4fd 100644
--- a/src/mesa/state_tracker/st_cb_msaa.c
+++ b/src/mesa/state_tracker/st_cb_msaa.c
@@ -38,21 +38,21 @@
 
 
 static void
 st_GetSamplePosition(struct gl_context *ctx,
                      struct gl_framebuffer *fb,
                      GLuint index,
                      GLfloat *outPos)
 {
    struct st_context *st = st_context(ctx);
 
-   st_validate_state(st, ST_PIPELINE_RENDER);
+   st_validate_state(st, ST_PIPELINE_UPDATE_FRAMEBUFFER);
 
    if (st->pipe->get_sample_position)
       st->pipe->get_sample_position(st->pipe,
                                     _mesa_geometric_samples(fb),
                                     index, outPos);
    else
       outPos[0] = outPos[1] = 0.5f;
 }
 
 
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
index 2bcc6be..ec6fd37 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -410,21 +410,21 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
    struct pipe_resource *src;
    struct pipe_resource *dst = NULL;
    enum pipe_format dst_format, src_format;
    unsigned bind;
    struct pipe_transfer *tex_xfer;
    ubyte *map = NULL;
    int dst_x, dst_y;
 
    /* Validate state (to be sure we have up-to-date framebuffer surfaces)
     * and flush the bitmap cache prior to reading. */
-   st_validate_state(st, ST_PIPELINE_RENDER);
+   st_validate_state(st, ST_PIPELINE_UPDATE_FRAMEBUFFER);
    st_flush_bitmap_cache(st);
 
    if (!st->prefer_blit_based_texture_transfer) {
       goto fallback;
    }
 
    /* This must be done after state validation. */
    src = strb->texture;
 
    /* XXX Fallback for depth-stencil formats due to an incomplete
-- 
2.7.4



More information about the mesa-dev mailing list