Mesa (master): r300g: Always emit scissors.

Corbin Simpson csimpson at kemper.freedesktop.org
Tue Jan 12 10:34:03 UTC 2010


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

Author: Corbin Simpson <MostAwesomeDude at gmail.com>
Date:   Tue Jan 12 02:09:07 2010 -0800

r300g: Always emit scissors.

Save some code, improve FPS, and fix piglit tests. Everybody wins.

---

 src/gallium/drivers/r300/r300_context.c |    4 ++-
 src/gallium/drivers/r300/r300_context.h |   11 +------
 src/gallium/drivers/r300/r300_emit.c    |   50 +++++++++++++++++++++---------
 src/gallium/drivers/r300/r300_state.c   |   43 +-------------------------
 src/gallium/drivers/r300/r300_texture.c |    6 ++-
 5 files changed, 45 insertions(+), 69 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
index af95bbe..be83c3e 100644
--- a/src/gallium/drivers/r300/r300_context.c
+++ b/src/gallium/drivers/r300/r300_context.c
@@ -127,6 +127,8 @@ static void r300_setup_atoms(struct r300_context* r300)
     R300_INIT_ATOM(rs);
     R300_INIT_ATOM(scissor);
     R300_INIT_ATOM(viewport);
+
+    r300->scissor_state.always_dirty = TRUE;
 }
 
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
@@ -182,7 +184,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
     r300->blend_color_state.state = CALLOC_STRUCT(r300_blend_color_state);
     r300->clip_state.state = CALLOC_STRUCT(pipe_clip_state);
     r300->rs_block = CALLOC_STRUCT(r300_rs_block);
-    r300->scissor_state.state = CALLOC_STRUCT(r300_scissor_state);
+    r300->scissor_state.state = CALLOC_STRUCT(pipe_scissor_state);
     r300->vertex_info = CALLOC_STRUCT(r300_vertex_info);
     r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state);
     r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state);
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index 5937f0e..34a759e 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -40,6 +40,7 @@ struct r300_atom {
     void* state;
     void (*emit)(struct r300_context*, void*);
     boolean dirty;
+    boolean always_dirty;
 };
 
 struct r300_blend_state {
@@ -106,16 +107,6 @@ struct r300_sampler_state {
     unsigned min_lod, max_lod;
 };
 
-struct r300_scissor_regs {
-    uint32_t top_left;     /* R300_SC_SCISSORS_TL: 0x43e0 */
-    uint32_t bottom_right; /* R300_SC_SCISSORS_BR: 0x43e4 */
-};
-
-struct r300_scissor_state {
-    struct r300_scissor_regs framebuffer;
-    struct r300_scissor_regs scissor;
-};
-
 struct r300_texture_state {
     uint32_t format0; /* R300_TX_FORMAT0: 0x4480 */
     uint32_t format1; /* R300_TX_FORMAT1: 0x44c0 */
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index 5ac6ed8..2f5df6a 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -638,27 +638,47 @@ void r300_emit_rs_block_state(struct r300_context* r300,
     END_CS;
 }
 
-static void r300_emit_scissor_regs(struct r300_context* r300,
-                                   struct r300_scissor_regs* scissor)
+void r300_emit_scissor_state(struct r300_context* r300, void* state)
 {
+    unsigned minx, miny, maxx, maxy;
+    uint32_t top_left, bottom_right;
+    struct r300_screen* r300screen = r300_screen(r300->context.screen);
+    struct pipe_scissor_state* scissor = (struct pipe_scissor_state*)state;
     CS_LOCALS(r300);
 
-    BEGIN_CS(3);
-    OUT_CS_REG_SEQ(R300_SC_SCISSORS_TL, 2);
-    OUT_CS(scissor->top_left);
-    OUT_CS(scissor->bottom_right);
-    END_CS;
-}
+    minx = miny = 0;
+    maxx = r300->framebuffer_state.width;
+    maxy = r300->framebuffer_state.height;
 
-void r300_emit_scissor_state(struct r300_context* r300, void* state)
-{
-    struct r300_scissor_state* scissor = (struct r300_scissor_state*)state;
-    /* XXX argfl! */
     if (((struct r300_rs_state*)r300->rs_state.state)->rs.scissor) {
-        r300_emit_scissor_regs(r300, &scissor->scissor);
+        minx = MAX2(minx, scissor->minx);
+        miny = MAX2(miny, scissor->miny);
+        maxx = MIN2(maxx, scissor->maxx);
+        maxy = MIN2(maxy, scissor->maxy);
+    }
+
+    if (r300screen->caps->is_r500) {
+        top_left =
+            (minx << R300_SCISSORS_X_SHIFT) |
+            (miny << R300_SCISSORS_Y_SHIFT);
+        bottom_right =
+            ((maxx - 1) << R300_SCISSORS_X_SHIFT) |
+            ((maxy - 1) << R300_SCISSORS_Y_SHIFT);
     } else {
-        r300_emit_scissor_regs(r300, &scissor->framebuffer);
+        /* Offset of 1440 in non-R500 chipsets. */
+        top_left =
+            ((minx + 1440) << R300_SCISSORS_X_SHIFT) |
+            ((miny + 1440) << R300_SCISSORS_Y_SHIFT);
+        bottom_right =
+            (((maxx - 1) + 1440) << R300_SCISSORS_X_SHIFT) |
+            (((maxy - 1) + 1440) << R300_SCISSORS_Y_SHIFT);
     }
+
+    BEGIN_CS(3);
+    OUT_CS_REG_SEQ(R300_SC_SCISSORS_TL, 2);
+    OUT_CS(top_left);
+    OUT_CS(bottom_right);
+    END_CS;
 }
 
 void r300_emit_texture(struct r300_context* r300,
@@ -1072,7 +1092,7 @@ validate:
     }
 
     foreach(atom, &r300->atom_list) {
-        if (atom->dirty) {
+        if (atom->dirty || atom->always_dirty) {
             atom->emit(r300, atom->state);
             atom->dirty = FALSE;
         }
diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index 4c22d4e..a08aa34 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -474,36 +474,11 @@ static void r300_delete_dsa_state(struct pipe_context* pipe,
     FREE(state);
 }
 
-static void r300_set_scissor_regs(const struct pipe_scissor_state* state,
-                                  struct r300_scissor_regs *scissor,
-                                  boolean is_r500)
-{
-    if (is_r500) {
-        scissor->top_left =
-            (state->minx << R300_SCISSORS_X_SHIFT) |
-            (state->miny << R300_SCISSORS_Y_SHIFT);
-        scissor->bottom_right =
-            ((state->maxx - 1) << R300_SCISSORS_X_SHIFT) |
-            ((state->maxy - 1) << R300_SCISSORS_Y_SHIFT);
-    } else {
-        /* Offset of 1440 in non-R500 chipsets. */
-        scissor->top_left =
-            ((state->minx + 1440) << R300_SCISSORS_X_SHIFT) |
-            ((state->miny + 1440) << R300_SCISSORS_Y_SHIFT);
-        scissor->bottom_right =
-            (((state->maxx - 1) + 1440) << R300_SCISSORS_X_SHIFT) |
-            (((state->maxy - 1) + 1440) << R300_SCISSORS_Y_SHIFT);
-    }
-}
-
 static void
     r300_set_framebuffer_state(struct pipe_context* pipe,
                                const struct pipe_framebuffer_state* state)
 {
     struct r300_context* r300 = r300_context(pipe);
-    struct r300_scissor_state* scissor =
-        (struct r300_scissor_state*)r300->scissor_state.state;
-    struct pipe_scissor_state pscissor;
 
     if (r300->draw) {
         draw_flush(r300->draw);
@@ -511,19 +486,11 @@ static void
 
     r300->framebuffer_state = *state;
 
-    /* XXX Arg. This is silly. */
-    pscissor.minx = pscissor.miny = 0;
-    pscissor.maxx = state->width;
-    pscissor.maxy = state->height;
-    r300_set_scissor_regs(&pscissor, &scissor->framebuffer,
-                          r300_screen(r300->context.screen)->caps->is_r500);
-
     /* Don't rely on the order of states being set for the first time. */
     r300->dirty_state |= R300_NEW_FRAMEBUFFERS;
 
     r300->blend_state.dirty = TRUE;
     r300->dsa_state.dirty = TRUE;
-    r300->scissor_state.dirty = TRUE;
 }
 
 /* Create fragment shader state. */
@@ -725,8 +692,6 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
 
     r300->rs_state.state = rs;
     r300->rs_state.dirty = TRUE;
-    /* 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 */
@@ -868,13 +833,9 @@ static void r300_set_scissor_state(struct pipe_context* pipe,
                                    const struct pipe_scissor_state* state)
 {
     struct r300_context* r300 = r300_context(pipe);
-    struct r300_scissor_state* scissor =
-        (struct r300_scissor_state*)r300->scissor_state.state;
-
-    r300_set_scissor_regs(state, &scissor->scissor,
-                          r300_screen(r300->context.screen)->caps->is_r500);
 
-    r300->scissor_state.dirty = TRUE;
+    memcpy(r300->scissor_state.state, state,
+        sizeof(struct pipe_scissor_state));
 }
 
 static void r300_set_viewport_state(struct pipe_context* pipe,
diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c
index 9a96206..2784916 100644
--- a/src/gallium/drivers/r300/r300_texture.c
+++ b/src/gallium/drivers/r300/r300_texture.c
@@ -115,6 +115,8 @@ static void r300_setup_miptree(struct r300_texture* tex)
     int stride, size, layer_size;
     int i;
 
+    debug_printf("r300: Making miptree for texture, format %s\n", pf_name(base->format));
+
     for (i = 0; i <= base->last_level; i++) {
         unsigned nblocksy = util_format_get_nblocksy(base->format, u_minify(base->height0, i));
 
@@ -132,9 +134,9 @@ static void r300_setup_miptree(struct r300_texture* tex)
         tex->pitch[i] = stride / util_format_get_blocksize(base->format);
 
         debug_printf("r300: Texture miptree: Level %d "
-                "(%dx%dx%d px, pitch %d bytes)\n",
+                "(%dx%dx%d px, pitch %d bytes) %d bytes total\n",
                 i, u_minify(base->width0, i), u_minify(base->height0, i),
-                u_minify(base->depth0, i), stride);
+                u_minify(base->depth0, i), stride, tex->size);
     }
 }
 




More information about the mesa-commit mailing list