v3d: use the GPU to record primitives written to transform feedback
[mesa.git] / src / gallium / drivers / v3d / v3dx_state.c
index b6a57249044a26862b4791fa6f3d7509e7b212cb..c709b476f99933df78440ea62fba6cce01893de7 100644 (file)
@@ -1222,6 +1222,14 @@ v3d_set_stream_output_targets(struct pipe_context *pctx,
 
         assert(num_targets <= ARRAY_SIZE(so->targets));
 
+        /* Update recorded vertex counts when we are ending the recording of
+         * transform feedback. We do this when we switch primitive types
+         * at draw time, but if we haven't switched primitives in our last
+         * draw we need to do it here as well.
+         */
+        if (num_targets == 0 && so->num_targets > 0)
+                v3d_tf_update_counters(ctx);
+
         for (i = 0; i < num_targets; i++) {
                 if (offsets[i] != -1)
                         so->offsets[i] = offsets[i];
@@ -1234,6 +1242,15 @@ v3d_set_stream_output_targets(struct pipe_context *pctx,
 
         so->num_targets = num_targets;
 
+        /* Create primitive counters BO if needed */
+        if (num_targets > 0 && !ctx->prim_counts) {
+                uint32_t zeroes[7] = { 0 }; /* Init all 7 counters to 0 */
+                u_upload_data(ctx->uploader,
+                              0, sizeof(zeroes), 32, zeroes,
+                              &ctx->prim_counts_offset,
+                              &ctx->prim_counts);
+        }
+
         ctx->dirty |= VC5_DIRTY_STREAMOUT;
 }