r300g: Always emit scissors.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Tue, 12 Jan 2010 10:09:07 +0000 (02:09 -0800)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Tue, 12 Jan 2010 10:33:55 +0000 (02:33 -0800)
Save some code, improve FPS, and fix piglit tests. Everybody wins.

src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_texture.c

index af95bbe789c49f068cdd6ef81fcd0c53708fd71b..be83c3eca80bc5b01362e36cb3d6b92605a4ce62 100644 (file)
@@ -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);
index 5937f0e2cc542539d9e291956e0f3346d1787e1c..34a759e494838724f0ce8dc793fee6338702010b 100644 (file)
@@ -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 */
index 5ac6ed866f38e30f4e3217acfe453370757a73a5..2f5df6a00a569f0d4182b2b15745dad7413a9ea8 100644 (file)
@@ -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;
         }
index 4c22d4ebc45bf5bf41dbe14a26c4d1ca14cfa158..a08aa3493d94b635de327b9d512042ae9e64f5f5 100644 (file)
@@ -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,
index 9a96206a4dc186f72828191488466321cfe9e205..2784916ddf4dd36c86cb2b42e9c85b3cb5a24a56 100644 (file)
@@ -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);
     }
 }