Mesa (master): r300g: remove unnecessary state emissions and clean up

Marek Olšák mareko at kemper.freedesktop.org
Mon Mar 8 03:34:31 UTC 2010


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

Author: Marek Olšák <maraeo at gmail.com>
Date:   Mon Mar  8 04:31:03 2010 +0100

r300g: remove unnecessary state emissions and clean up

---

 src/gallium/drivers/r300/r300_context.h |    2 +
 src/gallium/drivers/r300/r300_emit.c    |    2 +-
 src/gallium/drivers/r300/r300_state.c   |   37 +++++++++++++++++++-----------
 3 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index 0d1518a..8c52d88 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -368,6 +368,8 @@ struct r300_context {
     boolean polygon_offset_enabled;
     /* Z buffer bit depth. */
     uint32_t zbuffer_bpp;
+    /* Whether scissor is enabled. */
+    boolean scissor_enabled;
 };
 
 /* Convenience cast wrapper. */
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index a1d31d5..51fc590 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -675,7 +675,7 @@ void r300_emit_scissor_state(struct r300_context* r300,
     maxx = fb->width;
     maxy = fb->height;
 
-    if (((struct r300_rs_state*)r300->rs_state.state)->rs.scissor) {
+    if (r300->scissor_enabled) {
         minx = MAX2(minx, scissor->minx);
         miny = MAX2(miny, scissor->miny);
         maxx = MIN2(maxx, scissor->maxx);
diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index de3ee0e..31259b5 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -571,6 +571,7 @@ static void
 {
     struct r300_context* r300 = r300_context(pipe);
     struct r300_screen* r300screen = r300_screen(pipe->screen);
+    struct pipe_framebuffer_state *old_state = r300->fb_state.state;
     unsigned max_width, max_height;
     uint32_t zbuffer_bpp = 0;
 
@@ -595,11 +596,24 @@ static void
         return;
     }
 
-
     if (r300->draw) {
         draw_flush(r300->draw);
     }
 
+    r300->fb_state.dirty = TRUE;
+
+    /* If nr_cbufs is changed from zero to non-zero or vice versa... */
+    if (!!old_state->nr_cbufs != !!state->nr_cbufs) {
+        r300->blend_state.dirty = TRUE;
+    }
+    /* If zsbuf is set from NULL to non-NULL or vice versa.. */
+    if (!!old_state->zsbuf != !!state->zsbuf) {
+        r300->dsa_state.dirty = TRUE;
+    }
+    if (!r300->scissor_enabled) {
+        r300->scissor_state.dirty = TRUE;
+    }
+
     memcpy(r300->fb_state.state, state, sizeof(struct pipe_framebuffer_state));
 
     r300->fb_state.size = (10 * state->nr_cbufs) + (2 * (4 - state->nr_cbufs)) +
@@ -607,11 +621,6 @@ static void
 
     r300_fb_update_tiling_flags(r300, r300->fb_state.state, state);
 
-    /* XXX wait what */
-    r300->blend_state.dirty = TRUE;
-    r300->dsa_state.dirty = TRUE;
-    r300->fb_state.dirty = TRUE;
-    r300->scissor_state.dirty = TRUE;
 
     /* Polygon offset depends on the zbuffer bit depth. */
     if (state->zsbuf && r300->polygon_offset_enabled) {
@@ -806,6 +815,7 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
 {
     struct r300_context* r300 = r300_context(pipe);
     struct r300_rs_state* rs = (struct r300_rs_state*)state;
+    boolean scissor_was_enabled = r300->scissor_enabled;
 
     if (r300->draw) {
         draw_flush(r300->draw);
@@ -814,20 +824,17 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
 
     if (rs) {
         r300->polygon_offset_enabled = rs->rs.offset_cw || rs->rs.offset_ccw;
+        r300->scissor_enabled = rs->rs.scissor;
     } else {
         r300->polygon_offset_enabled = FALSE;
+        r300->scissor_enabled = FALSE;
     }
 
     UPDATE_STATE(state, r300->rs_state);
     r300->rs_state.size = 17 + (r300->polygon_offset_enabled ? 5 : 0);
 
-    /* XXX Why is this still needed, dammit!? */
-    r300->scissor_state.dirty = TRUE;
-    r300->viewport_state.dirty = TRUE;
-
-    /* XXX Clean these up when we move to atom emits */
-    if (r300->fs && r300->fs->inputs.wpos != ATTR_UNUSED) {
-        r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
+    if (scissor_was_enabled != r300->scissor_enabled) {
+        r300->scissor_state.dirty = TRUE;
     }
 }
 
@@ -972,7 +979,9 @@ static void r300_set_scissor_state(struct pipe_context* pipe,
     memcpy(r300->scissor_state.state, state,
         sizeof(struct pipe_scissor_state));
 
-    r300->scissor_state.dirty = TRUE;
+    if (r300->scissor_enabled) {
+        r300->scissor_state.dirty = TRUE;
+    }
 }
 
 static void r300_set_viewport_state(struct pipe_context* pipe,




More information about the mesa-commit mailing list