draw/so: maintain an exact number of written vertices
authorZack Rusin <zackr@vmware.com>
Fri, 29 Mar 2013 11:52:29 +0000 (04:52 -0700)
committerZack Rusin <zackr@vmware.com>
Wed, 3 Apr 2013 17:16:25 +0000 (10:16 -0700)
It's quite helpful during the rendering when we know
exactly the count of the vertices available in the
buffer.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/draw/draw_context.h
src/gallium/auxiliary/draw/draw_pt.c
src/gallium/auxiliary/draw/draw_pt_so_emit.c

index 369f6c80fa0422c4b348b56e6a776125d289fbbe..b333457775c01545eb93b87bb4ff5fb001a46e08 100644 (file)
@@ -60,6 +60,7 @@ struct draw_so_target {
    struct pipe_stream_output_target target;
    void *mapping;
    int internal_offset;
+   int emitted_vertices;
 };
 
 struct draw_context *draw_create( struct pipe_context *pipe );
index 50b9efab7eaca0146cc74a8204ccc419970afd5f..853bd6716e635e4c90d8e280921a1e7892b2fefd 100644 (file)
@@ -451,6 +451,28 @@ draw_arrays_instanced(struct draw_context *draw,
    draw_vbo(draw, &info);
 }
 
+/**
+ * Resolve true values within pipe_draw_info.
+ * If we're rendering from transform feedback/stream output
+ * buffers both the count and max_index need to be computed
+ * from the attached stream output target. 
+ */
+static void
+resolve_draw_info(const struct pipe_draw_info *raw_info,
+                  struct pipe_draw_info *info)
+{
+   memcpy(info, raw_info, sizeof(struct pipe_draw_info));
+
+   if (raw_info->count_from_stream_output) {
+      struct draw_so_target *target =
+         (struct draw_so_target *)info->count_from_stream_output;
+      info->count = target->emitted_vertices;
+
+      /* Stream output draw can not be indexed */
+      debug_assert(!info->indexed);
+      info->max_index = info->count - 1;
+   }
+}
 
 /**
  * Draw vertex arrays.
@@ -465,9 +487,16 @@ draw_vbo(struct draw_context *draw,
    unsigned instance;
    unsigned index_limit;
    unsigned count;
+   struct pipe_draw_info resolved_info;
+
+   resolve_draw_info(info, &resolved_info);
+   info = &resolved_info;
+
    assert(info->instance_count > 0);
    if (info->indexed)
       assert(draw->pt.user.elts);
+   
+   count = info->count;
 
    draw->pt.user.eltBias = info->index_bias;
    draw->pt.user.min_index = info->min_index;
@@ -518,12 +547,6 @@ draw_vbo(struct draw_context *draw,
 
    draw->pt.max_index = index_limit - 1;
 
-   count = info->count;
-   if (count == 0) {
-      if (info->count_from_stream_output)
-         count = draw->pt.max_index + 1;
-   }
-
    /*
     * TODO: We could use draw->pt.max_index to further narrow
     * the min_index/max_index hints given by the state tracker.
index 25584a9b62e33a1a739f6d6054bc4bfaeb6f76c0..ae071a678b6c5733f20b9096b5dd8e7abec437c3 100644 (file)
@@ -174,8 +174,10 @@ static void so_emit_prim(struct pt_so_emit *so,
          else
             memcpy(buffer, &input[idx][start_comp], num_comps * sizeof(float));
       }
-      for (ob = 0; ob < draw->so.num_targets; ++ob)
+      for (ob = 0; ob < draw->so.num_targets; ++ob) {
          draw->so.targets[ob]->internal_offset += state->stride[ob] * sizeof(float);
+         draw->so.targets[ob]->emitted_vertices += 1;
+      }
    }
    so->emitted_vertices += num_vertices;
    ++so->emitted_primitives;