u_vbuf_mgr: make u_vbuf_mgr_draw_begin return flags in a bitmask
authorMarek Olšák <maraeo@gmail.com>
Sun, 19 Jun 2011 19:02:42 +0000 (21:02 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 19 Jun 2011 19:09:18 +0000 (21:09 +0200)
src/gallium/auxiliary/util/u_vbuf_mgr.c
src/gallium/auxiliary/util/u_vbuf_mgr.h
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r600/r600_state_common.c

index fdfa9fcca3d25572746b7ca5f237b23348e810f5..374fc336b83a88f43667d3991299eedc393d0010 100644 (file)
@@ -152,9 +152,9 @@ void u_vbuf_mgr_destroy(struct u_vbuf_mgr *mgrb)
 }
 
 
-static void u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
-                                   int min_index, int max_index,
-                                   boolean *upload_flushed)
+static enum u_vbuf_return_flags
+u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
+                       int min_index, int max_index)
 {
    struct translate_key key;
    struct translate_element *te;
@@ -166,6 +166,7 @@ static void u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
    struct pipe_resource *out_buffer = NULL;
    unsigned i, num_verts, out_offset;
    struct pipe_vertex_element new_velems[PIPE_MAX_ATTRIBS];
+   boolean upload_flushed = FALSE;
 
    memset(&key, 0, sizeof(key));
    memset(tr_elem_index, 0xff, sizeof(tr_elem_index));
@@ -248,7 +249,7 @@ static void u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
    u_upload_alloc(mgr->b.uploader,
                   key.output_stride * min_index,
                   key.output_stride * num_verts,
-                  &out_offset, &out_buffer, upload_flushed,
+                  &out_offset, &out_buffer, &upload_flushed,
                   (void**)&out_map);
 
    out_offset -= key.output_stride * min_index;
@@ -308,6 +309,8 @@ static void u_vbuf_translate_begin(struct u_vbuf_mgr_priv *mgr,
    }
 
    pipe_resource_reference(&out_buffer, NULL);
+
+   return upload_flushed ? U_VBUF_UPLOAD_FLUSHED : 0;
 }
 
 static void u_vbuf_translate_end(struct u_vbuf_mgr_priv *mgr)
@@ -510,14 +513,15 @@ void u_vbuf_mgr_set_vertex_buffers(struct u_vbuf_mgr *mgrb,
    mgr->b.nr_real_vertex_buffers = count;
 }
 
-static void u_vbuf_upload_buffers(struct u_vbuf_mgr_priv *mgr,
-                                  int min_index, int max_index,
-                                  unsigned instance_count,
-                                  boolean *upload_flushed)
+static enum u_vbuf_return_flags
+u_vbuf_upload_buffers(struct u_vbuf_mgr_priv *mgr,
+                      int min_index, int max_index,
+                      unsigned instance_count)
 {
    unsigned i, nr = mgr->ve->count;
    unsigned count = max_index + 1 - min_index;
    boolean uploaded[PIPE_MAX_ATTRIBS] = {0};
+   enum u_vbuf_return_flags retval = 0;
 
    for (i = 0; i < nr; i++) {
       unsigned index = mgr->ve->ve[i].vertex_buffer_index;
@@ -556,11 +560,14 @@ static void u_vbuf_upload_buffers(struct u_vbuf_mgr_priv *mgr,
          vb->buffer_offset -= first;
 
          uploaded[index] = TRUE;
-         *upload_flushed = *upload_flushed || flushed;
+         if (flushed)
+            retval |= U_VBUF_UPLOAD_FLUSHED;
       } else {
          assert(mgr->b.real_vertex_buffer[index]);
       }
    }
+
+   return retval;
 }
 
 static void u_vbuf_mgr_compute_max_index(struct u_vbuf_mgr_priv *mgr)
@@ -602,14 +609,13 @@ static void u_vbuf_mgr_compute_max_index(struct u_vbuf_mgr_priv *mgr)
    }
 }
 
-void u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgrb,
-                           const struct pipe_draw_info *info,
-                           boolean *buffers_updated,
-                           boolean *uploader_flushed)
+enum u_vbuf_return_flags
+u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgrb,
+                      const struct pipe_draw_info *info)
 {
    struct u_vbuf_mgr_priv *mgr = (struct u_vbuf_mgr_priv*)mgrb;
-   boolean bufs_updated = FALSE, upload_flushed = FALSE;
    int min_index, max_index;
+   enum u_vbuf_return_flags retval = 0;
 
    u_vbuf_mgr_compute_max_index(mgr);
 
@@ -622,27 +628,20 @@ void u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgrb,
 
    /* Translate vertices with non-native layouts or formats. */
    if (mgr->incompatible_vb_layout || mgr->ve->incompatible_layout) {
-      u_vbuf_translate_begin(mgr, min_index, max_index, &upload_flushed);
+      retval |= u_vbuf_translate_begin(mgr, min_index, max_index);
 
       if (mgr->fallback_ve) {
-         bufs_updated = TRUE;
+         retval |= U_VBUF_BUFFERS_UPDATED;
       }
    }
 
    /* Upload user buffers. */
    if (mgr->any_user_vbs) {
-      u_vbuf_upload_buffers(mgr, min_index, max_index, info->instance_count,
-                            &upload_flushed);
-      bufs_updated = TRUE;
-   }
-
-   /* Set the return values. */
-   if (buffers_updated) {
-      *buffers_updated = bufs_updated;
-   }
-   if (uploader_flushed) {
-      *uploader_flushed = upload_flushed;
+      retval |= u_vbuf_upload_buffers(mgr, min_index, max_index,
+                                      info->instance_count);
+      retval |= U_VBUF_BUFFERS_UPDATED;
    }
+   return retval;
 }
 
 void u_vbuf_mgr_draw_end(struct u_vbuf_mgr *mgrb)
index 9380dce4f7284aed1923fca3e64ca41670e8c063..4e6372435d8652fcf9127881633c3fc9fe77b6e2 100644 (file)
@@ -78,6 +78,11 @@ enum u_fetch_alignment {
    U_VERTEX_FETCH_DWORD_ALIGNED
 };
 
+enum u_vbuf_return_flags {
+   U_VBUF_BUFFERS_UPDATED = 1,
+   U_VBUF_UPLOAD_FLUSHED = 2
+};
+
 
 struct u_vbuf_mgr *
 u_vbuf_mgr_create(struct pipe_context *pipe,
@@ -105,10 +110,9 @@ void u_vbuf_mgr_set_vertex_buffers(struct u_vbuf_mgr *mgr,
                                    unsigned count,
                                    const struct pipe_vertex_buffer *bufs);
 
-void u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgr,
-                           const struct pipe_draw_info *info,
-                           boolean *buffers_updated,
-                           boolean *uploader_flushed);
+enum u_vbuf_return_flags
+u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgr,
+                      const struct pipe_draw_info *info);
 
 void u_vbuf_mgr_draw_end(struct u_vbuf_mgr *mgr);
 
index 7cf0aba2ed079f394b9ea9400097787ceaf17f5e..b31141a518eacfe8157a39b29374024e56222cc2 100644 (file)
@@ -768,7 +768,6 @@ static void r300_draw_vbo(struct pipe_context* pipe,
 {
     struct r300_context* r300 = r300_context(pipe);
     struct pipe_draw_info info = *dinfo;
-    boolean buffers_updated, uploader_flushed;
 
     info.indexed = info.indexed && r300->index_buffer.buffer;
 
@@ -780,9 +779,7 @@ static void r300_draw_vbo(struct pipe_context* pipe,
     r300_update_derived_state(r300);
 
     /* Start the vbuf manager and update buffers if needed. */
-    u_vbuf_mgr_draw_begin(r300->vbuf_mgr, &info,
-                          &buffers_updated, &uploader_flushed);
-    if (buffers_updated) {
+    if (u_vbuf_mgr_draw_begin(r300->vbuf_mgr, &info) & U_VBUF_BUFFERS_UPDATED) {
         r300->vertex_arrays_dirty = TRUE;
     }
 
index 5f9f398bf25ecaf26944b5100ad7c38e893c9af3..816508a3bef85225f9b87597489fbd1720f6f747 100644 (file)
@@ -543,7 +543,7 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
                if (rctx->have_depth_fb || rctx->have_depth_texture)
                        r600_flush_depth_textures(rctx);
        }
-       u_vbuf_mgr_draw_begin(rctx->vbuf_mgr, info, NULL, NULL);
+       u_vbuf_mgr_draw_begin(rctx->vbuf_mgr, info);
        r600_vertex_buffer_update(rctx);
 
        draw.info = *info;