r300g/swtcl: fix CS overrun
authorMarek Olšák <maraeo@gmail.com>
Thu, 16 Sep 2010 00:04:37 +0000 (02:04 +0200)
committerMarek Olšák <maraeo@gmail.com>
Thu, 16 Sep 2010 18:33:43 +0000 (20:33 +0200)
https://bugs.freedesktop.org/show_bug.cgi?id=29901

src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_render.c

index 8eddf72b7041ff73ce468cbd13f6215663ea69c0..7f655dbfd21990da20eb0f0c278e2f67d2c64350 100644 (file)
@@ -457,6 +457,7 @@ struct r300_context {
     size_t draw_vbo_size;
     /* Whether the VBO must not be flushed. */
     boolean draw_vbo_locked;
+    boolean draw_first_emitted;
 
     /* Accelerated blit support. */
     struct blitter_context* blitter;
index 177850dea2f56f0a55eab9f4439531acac5b5959..2f00c878f5b19240b2f5cb0552d987999e50810b 100644 (file)
@@ -753,6 +753,7 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
     draw_set_mapped_index_buffer(r300->draw, indices);
 
     r300->draw_vbo_locked = TRUE;
+    r300->draw_first_emitted = FALSE;
     draw_vbo(r300->draw, info);
     draw_flush(r300->draw);
     r300->draw_vbo_locked = FALSE;
@@ -907,10 +908,17 @@ static void r300_render_draw_arrays(struct vbuf_render* render,
 
     DBG(r300, DBG_DRAW, "r300: render_draw_arrays (count: %d)\n", count);
 
-    if (!r300_emit_states(r300,
-            PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL,
-            NULL, 0, 0))
-        return;
+    if (r300->draw_first_emitted) {
+        if (!r300_prepare_for_rendering(r300,
+                PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL,
+                NULL, 6, 0, 0))
+            return;
+    } else {
+        if (!r300_emit_states(r300,
+                PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL,
+                NULL, 0, 0))
+            return;
+    }
 
     /* Uncomment to dump all VBOs rendered through this interface.
      * Slow and noisy!
@@ -937,6 +945,8 @@ static void r300_render_draw_arrays(struct vbuf_render* render,
     OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) |
            r300render->hwprim);
     END_CS;
+
+    r300->draw_first_emitted = TRUE;
 }
 
 static void r300_render_draw_elements(struct vbuf_render* render,
@@ -955,10 +965,17 @@ static void r300_render_draw_elements(struct vbuf_render* render,
     CS_LOCALS(r300);
     DBG(r300, DBG_DRAW, "r300: render_draw_elements (count: %d)\n", count);
 
-    if (!r300_emit_states(r300,
-            PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
-            NULL, 0, 0))
-        return;
+    if (r300->draw_first_emitted) {
+        if (!r300_prepare_for_rendering(r300,
+                PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
+                NULL, 256, 0, 0))
+            return;
+    } else {
+        if (!r300_emit_states(r300,
+                PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED,
+                NULL, 0, 0))
+            return;
+    }
 
     /* Below we manage the CS space manually because there may be more
      * indices than it can fit in CS. */
@@ -999,6 +1016,8 @@ static void r300_render_draw_elements(struct vbuf_render* render,
             end_cs_dwords = r300_get_num_cs_end_dwords(r300);
         }
     }
+
+    r300->draw_first_emitted = TRUE;
 }
 
 static void r300_render_destroy(struct vbuf_render* render)