r300g: put validating buffers after flushing
authorMarek Olšák <maraeo@gmail.com>
Sat, 27 Feb 2010 16:00:03 +0000 (17:00 +0100)
committerMarek Olšák <maraeo@gmail.com>
Sat, 27 Feb 2010 23:46:35 +0000 (00:46 +0100)
Also cleaning up the nasty validation process.

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

index 013611018b0d453589913420f81c53fb7cc206f9..d66fa0dbdba742053d2f3dc0bebfb20d932e2886 100644 (file)
@@ -1010,11 +1010,16 @@ void r300_emit_texture_cache_inval(struct r300_context* r300, unsigned size, voi
     END_CS;
 }
 
-void r300_emit_buffer_validate(struct r300_context *r300)
+void r300_emit_buffer_validate(struct r300_context *r300,
+                               boolean do_validate_vertex_buffers,
+                               struct pipe_buffer *index_buffer)
 {
     struct pipe_framebuffer_state* fb =
         (struct pipe_framebuffer_state*)r300->fb_state.state;
     struct r300_texture* tex;
+    struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
+    struct pipe_vertex_element *velem = r300->vertex_element;
+    struct pipe_buffer *pbuf;
     unsigned i;
     boolean invalid = FALSE;
 
@@ -1061,16 +1066,35 @@ validate:
             goto validate;
         }
     }
-    /* ...and vertex buffer. */
+    /* ...vertex buffer for SWTCL path... */
     if (r300->vbo) {
         if (!r300->winsys->add_buffer(r300->winsys, r300->vbo,
                     RADEON_GEM_DOMAIN_GTT, 0)) {
             r300->context.flush(&r300->context, 0, NULL);
             goto validate;
         }
-    } else {
-        /* debug_printf("No VBO while emitting dirty state!\n"); */
     }
+    /* ...vertex buffers for HWTCL path... */
+    if (do_validate_vertex_buffers) {
+        for (i = 0; i < r300->vertex_element_count; i++) {
+            pbuf = vbuf[velem[i].vertex_buffer_index].buffer;
+
+            if (!r300->winsys->add_buffer(r300->winsys, pbuf,
+                                          RADEON_GEM_DOMAIN_GTT, 0)) {
+                r300->context.flush(&r300->context, 0, NULL);
+                goto validate;
+            }
+        }
+    }
+    /* ...and index buffer for HWTCL path. */
+    if (index_buffer) {
+        if (!r300->winsys->add_buffer(r300->winsys, index_buffer,
+                                      RADEON_GEM_DOMAIN_GTT, 0)) {
+            r300->context.flush(&r300->context, 0, NULL);
+            goto validate;
+        }
+    }
+
     if (!r300->winsys->validate(r300->winsys)) {
         r300->context.flush(&r300->context, 0, NULL);
         if (invalid) {
index c73b016b76c96ba6dd21556f5ad13af3f5062833..4a3f94087bf230c9f03c903946eff63463109572 100644 (file)
@@ -105,6 +105,8 @@ unsigned r300_get_num_dirty_dwords(struct r300_context *r300);
 /* Emit all dirty state. */
 void r300_emit_dirty_state(struct r300_context* r300);
 
-void r300_emit_buffer_validate(struct r300_context *r300);
+void r300_emit_buffer_validate(struct r300_context *r300,
+                               boolean do_validate_vertex_buffers,
+                               struct pipe_buffer *index_buffer);
 
 #endif /* R300_EMIT_H */
index e4f7615368db08b835e925976f77f857dd5575e6..c5baf5508e508f5d793aa6aa4bd7d5faaeaf1cd9 100644 (file)
@@ -186,6 +186,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
     dwords = 10 + count * vertex_size;
 
     r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + dwords);
+    r300_emit_buffer_validate(r300, FALSE, 0);
     r300_emit_dirty_state(r300);
 
     BEGIN_CS(dwords);
@@ -313,31 +314,6 @@ static void r300_emit_draw_elements(struct r300_context *r300,
     END_CS;
 }
 
-static boolean r300_setup_vertex_buffers(struct r300_context *r300)
-{
-    struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
-    struct pipe_vertex_element *velem = r300->vertex_element;
-    struct pipe_buffer *pbuf;
-
-validate:
-    for (int i = 0; i < r300->vertex_element_count; i++) {
-        pbuf = vbuf[velem[i].vertex_buffer_index].buffer;
-
-        if (!r300->winsys->add_buffer(r300->winsys, pbuf,
-                                      RADEON_GEM_DOMAIN_GTT, 0)) {
-            r300->context.flush(&r300->context, 0, NULL);
-            goto validate;
-        }
-    }
-
-    if (!r300->winsys->validate(r300->winsys)) {
-        r300->context.flush(&r300->context, 0, NULL);
-        return r300->winsys->validate(r300->winsys);
-    }
-
-    return TRUE;
-}
-
 static void r300_shorten_ubyte_elts(struct r300_context* r300,
                                     struct pipe_buffer** elts,
                                     unsigned count)
@@ -393,30 +369,16 @@ void r300_draw_range_elements(struct pipe_context* pipe,
         return;
     }
 
-    r300_update_derived_state(r300);
-
-    r300_emit_buffer_validate(r300);
-
-    if (!r300_setup_vertex_buffers(r300)) {
-        return;
-    }
-
     if (indexSize == 1) {
         r300_shorten_ubyte_elts(r300, &indexBuffer, count);
         indexSize = 2;
     }
 
-    if (!r300->winsys->add_buffer(r300->winsys, indexBuffer,
-                                  RADEON_GEM_DOMAIN_GTT, 0)) {
-        goto cleanup;
-    }
-
-    if (!r300->winsys->validate(r300->winsys)) {
-        goto cleanup;
-    }
+    r300_update_derived_state(r300);
 
     /* 128 dwords for emit_aos and emit_draw_elements */
     r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + 128);
+    r300_emit_buffer_validate(r300, TRUE, indexBuffer);
     r300_emit_dirty_state(r300);
     r300_emit_aos(r300, 0);
 
@@ -434,13 +396,13 @@ void r300_draw_range_elements(struct pipe_context* pipe,
 
             /* 16 spare dwords are enough for emit_draw_elements. */
             if (count && r300_reserve_cs_space(r300, 16)) {
+                r300_emit_buffer_validate(r300, TRUE, indexBuffer);
                 r300_emit_dirty_state(r300);
                 r300_emit_aos(r300, 0);
             }
         } while (count);
     }
 
-cleanup:
     if (indexBuffer != orgIndexBuffer) {
         pipe->screen->buffer_destroy(indexBuffer);
     }
@@ -477,18 +439,13 @@ void r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
 
     r300_update_derived_state(r300);
 
-    r300_emit_buffer_validate(r300);
-
     if (immd_is_good_idea(r300, count)) {
         r300_emit_draw_arrays_immediate(r300, mode, start, count);
     } else {
-        if (!r300_setup_vertex_buffers(r300)) {
-            return;
-        }
-
         /* Make sure there are at least 128 spare dwords in the command buffer.
          * (most of it being consumed by emit_aos) */
         r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + 128);
+        r300_emit_buffer_validate(r300, TRUE, 0);
         r300_emit_dirty_state(r300);
 
         if (alt_num_verts || count <= 65535) {
@@ -506,6 +463,7 @@ void r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
                 /* Again, we emit both AOS and draw_arrays so there should be
                  * at least 128 spare dwords. */
                 if (count && r300_reserve_cs_space(r300, 128)) {
+                    r300_emit_buffer_validate(r300, TRUE, 0);
                     r300_emit_dirty_state(r300);
                 }
             } while (count);