mesa: don't update draw buffer bounds in _mesa_update_state
authorMarek Olšák <marek.olsak@amd.com>
Fri, 9 Jun 2017 20:19:33 +0000 (22:19 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 21 Jun 2017 23:51:02 +0000 (01:51 +0200)
st/mesa doesn't need the draw bounds for draw calls. I've added the call
where it's necessary in core Mesa and drivers, but I suspect that most
drivers can just move the call to the right places.

The core Mesa places aren't hot paths, so the call overhead doesn't matter
there.

For now, only st/mesa is made such that this function is invoked very
rarely.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
13 files changed:
src/mesa/drivers/dri/i915/i915_context.c
src/mesa/drivers/dri/i915/intel_context.c
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/nouveau/nouveau_state.c
src/mesa/drivers/dri/r200/r200_state.c
src/mesa/drivers/dri/radeon/radeon_state.c
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/drivers/osmesa/osmesa.c
src/mesa/drivers/x11/xm_dd.c
src/mesa/main/accum.c
src/mesa/main/state.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c

index 4d89af1..4f6bdb7 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "i915_context.h"
 #include "main/api_exec.h"
+#include "main/framebuffer.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/version.h"
@@ -62,6 +63,9 @@ i915InvalidateState(struct gl_context * ctx)
    _tnl_invalidate_vertex_state(ctx, new_state);
    intel_context(ctx)->NewGLState |= new_state;
 
+   if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    /* Todo: gather state values under which tracked parameters become
     * invalidated, add callbacks for things like
     * ProgramLocalParameters, etc.
index 7f39245..e0766a0 100644 (file)
@@ -324,6 +324,9 @@ intelInvalidateState(struct gl_context * ctx)
 
    intel->NewGLState |= new_state;
 
+   if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    if (intel->vtbl.invalidate_state)
       intel->vtbl.invalidate_state( intel, new_state );
 }
index e9de5b7..e921a41 100644 (file)
@@ -203,6 +203,9 @@ intel_update_state(struct gl_context * ctx)
 
    _mesa_unlock_context_textures(ctx);
 
+   if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    if (new_state & (_NEW_STENCIL | _NEW_BUFFERS)) {
       brw->stencil_enabled = _mesa_stencil_is_enabled(ctx);
       brw->stencil_two_sided = _mesa_stencil_is_two_sided(ctx);
index 6d998fc..1aa26e9 100644 (file)
@@ -32,6 +32,7 @@
 #include "swrast/swrast.h"
 #include "tnl/tnl.h"
 #include "util/bitscan.h"
+#include "main/framebuffer.h"
 
 static void
 nouveau_alpha_func(struct gl_context *ctx, GLenum func, GLfloat ref)
@@ -456,6 +457,9 @@ nouveau_update_state(struct gl_context *ctx)
        GLbitfield new_state = ctx->NewState;
        int i;
 
+       if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+               _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
        if (new_state & (_NEW_PROJECTION | _NEW_MODELVIEW))
                context_dirty(ctx, PROJECTION);
 
index 30437e3..b157572 100644 (file)
@@ -2282,6 +2282,9 @@ static void r200InvalidateState(struct gl_context *ctx)
 
    r200ContextPtr rmesa = R200_CONTEXT(ctx);
 
+   if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    _swrast_InvalidateState( ctx, new_state );
    _swsetup_InvalidateState( ctx, new_state );
    _tnl_InvalidateState( ctx, new_state );
index 940f8de..d2ca812 100644 (file)
@@ -2048,6 +2048,9 @@ static void radeonInvalidateState(struct gl_context *ctx)
 {
    GLuint new_state = ctx->NewState;
 
+   if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    _swrast_InvalidateState( ctx, new_state );
    _swsetup_InvalidateState( ctx, new_state );
    _tnl_InvalidateState( ctx, new_state );
index 3b1de42..e66b225 100644 (file)
@@ -701,6 +701,9 @@ update_state(struct gl_context *ctx)
 {
     GLuint new_state = ctx->NewState;
 
+    if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
     /* not much to do here - pass it on */
     _swrast_InvalidateState( ctx, new_state );
     _swsetup_InvalidateState( ctx, new_state );
index c77dcc4..734a4e8 100644 (file)
@@ -119,6 +119,9 @@ get_string( struct gl_context *ctx, GLenum name )
 static void
 osmesa_update_state(struct gl_context *ctx, GLuint new_state)
 {
+   if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    /* easy - just propogate */
    _swrast_InvalidateState( ctx, new_state );
    _swsetup_InvalidateState( ctx, new_state );
index 61aa6c8..27534da 100644 (file)
@@ -684,6 +684,9 @@ xmesa_update_state(struct gl_context *ctx)
    GLbitfield new_state = ctx->NewState;
    const XMesaContext xmesa = XMESA_CONTEXT(ctx);
 
+   if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
+      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    /* Propagate statechange information to swrast and swrast_setup
     * modules.  The X11 driver has no internal GL-dependent state.
     */
index c0a3e7e..2b15b6e 100644 (file)
@@ -28,6 +28,7 @@
 #include "context.h"
 #include "format_unpack.h"
 #include "format_pack.h"
+#include "framebuffer.h"
 #include "imports.h"
 #include "macros.h"
 #include "state.h"
@@ -73,6 +74,8 @@ _mesa_clear_accum_buffer(struct gl_context *ctx)
    if (!accRb)
       return;   /* missing accum buffer, not an error */
 
+   _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    /* bounds, with scissor */
    x = ctx->DrawBuffer->_Xmin;
    y = ctx->DrawBuffer->_Ymin;
@@ -398,6 +401,8 @@ accum(struct gl_context *ctx, GLenum op, GLfloat value)
    if (!_mesa_check_conditional_render(ctx))
       return;
 
+   _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    xpos = ctx->DrawBuffer->_Xmin;
    ypos = ctx->DrawBuffer->_Ymin;
    width =  ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
index 7972798..8df03f0 100644 (file)
@@ -336,9 +336,6 @@ _mesa_update_state_locked( struct gl_context *ctx )
    if (new_state & _NEW_BUFFERS)
       _mesa_update_framebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer);
 
-   if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
-      _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
-
    if (new_state & _NEW_LIGHT)
       _mesa_update_lighting( ctx );
 
index 175e2e8..cda9c71 100644 (file)
@@ -36,6 +36,7 @@
 #include "main/glheader.h"
 #include "main/accum.h"
 #include "main/formats.h"
+#include "main/framebuffer.h"
 #include "main/macros.h"
 #include "main/glformats.h"
 #include "program/prog_instruction.h"
@@ -179,6 +180,9 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
    const struct gl_framebuffer *fb = ctx->DrawBuffer;
    const GLfloat fb_width = (GLfloat) fb->Width;
    const GLfloat fb_height = (GLfloat) fb->Height;
+
+   _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin / fb_width * 2.0f - 1.0f;
    const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax / fb_width * 2.0f - 1.0f;
    const GLfloat y0 = (GLfloat) ctx->DrawBuffer->_Ymin / fb_height * 2.0f - 1.0f;
index 33d10f6..092b418 100644 (file)
@@ -1072,6 +1072,8 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
    /* Mesa state should be up to date by now */
    assert(ctx->NewState == 0x0);
 
+   _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    st_flush_bitmap_cache(st);
    st_invalidate_readpix_cache(st);
 
@@ -1437,6 +1439,8 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
    GLint readX, readY, readW, readH;
    struct gl_pixelstore_attrib pack = ctx->DefaultPacking;
 
+   _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
+
    st_flush_bitmap_cache(st);
    st_invalidate_readpix_cache(st);