freedreno: add transform-feedback state
authorRob Clark <robclark@freedesktop.org>
Sat, 25 Jul 2015 14:56:39 +0000 (10:56 -0400)
committerRob Clark <robclark@freedesktop.org>
Mon, 27 Jul 2015 17:51:06 +0000 (13:51 -0400)
Signed-off-by: Rob Clark <robclark@freedesktop.org>
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_state.c

index bc5267aa96e5fb77d2f895d5ea098eddb8095dc4..cc585af1b3f55ff58912a1e03ff1ff1284f114c1 100644 (file)
@@ -82,6 +82,20 @@ struct fd_vertex_stateobj {
        unsigned num_elements;
 };
 
+struct fd_streamout_stateobj {
+       struct pipe_stream_output_target *targets[PIPE_MAX_SO_BUFFERS];
+       unsigned num_targets;
+       /* Track offset from vtxcnt for streamout data.  This counter
+        * is just incremented by # of vertices on each draw until
+        * reset or new streamout buffer bound.
+        *
+        * When we eventually have GS, the CPU won't actually know the
+        * number of vertices per draw, so I think we'll have to do
+        * something more clever.
+        */
+       unsigned offsets[PIPE_MAX_SO_BUFFERS];
+};
+
 /* group together the vertex and vertexbuf state.. for ease of passing
  * around, and because various internal operations (gmem<->mem, etc)
  * need their own vertex state:
@@ -319,6 +333,7 @@ struct fd_context {
                FD_DIRTY_VTXBUF      = (1 << 15),
                FD_DIRTY_INDEXBUF    = (1 << 16),
                FD_DIRTY_SCISSOR     = (1 << 17),
+               FD_DIRTY_STREAMOUT   = (1 << 18),
        } dirty;
 
        struct pipe_blend_state *blend;
@@ -339,6 +354,7 @@ struct fd_context {
        struct pipe_viewport_state viewport;
        struct fd_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
        struct pipe_index_buffer indexbuf;
+       struct fd_streamout_stateobj streamout;
 
        /* GMEM/tile handling fxns: */
        void (*emit_tile_init)(struct fd_context *ctx);
index ae75b3efdccf1db1ce8733f2ffa2f97ad2ea1742..f88654063faa34f3540f608efb48fa463af98324 100644 (file)
@@ -62,7 +62,7 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        struct fd_context *ctx = fd_context(pctx);
        struct pipe_framebuffer_state *pfb = &ctx->framebuffer;
        struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
-       unsigned i, buffers = 0;
+       unsigned i, prims, buffers = 0;
 
        /* if we supported transform feedback, we'd have to disable this: */
        if (((scissor->maxx - scissor->minx) *
@@ -144,11 +144,17 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                if (ctx->fragtex.textures[i])
                        resource_used(ctx, ctx->fragtex.textures[i]->texture, true);
 
+       /* Mark streamout buffers as being read.. actually they are written.. */
+       for (i = 0; i < ctx->streamout.num_targets; i++)
+               if (ctx->streamout.targets[i])
+                       resource_used(ctx, ctx->streamout.targets[i]->buffer, false);
+
        ctx->num_draws++;
 
+       prims = u_reduced_prims_for_vertices(info->mode, info->count);
+
        ctx->stats.draw_calls++;
-       ctx->stats.prims_emitted +=
-               u_reduced_prims_for_vertices(info->mode, info->count);
+       ctx->stats.prims_emitted += prims;
 
        /* any buffers that haven't been cleared yet, we need to restore: */
        ctx->restore |= buffers & (FD_BUFFER_ALL & ~ctx->cleared);
@@ -162,6 +168,9 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        fd_hw_query_set_stage(ctx, ctx->ring, FD_STAGE_DRAW);
        ctx->draw_vbo(ctx, info);
 
+       for (i = 0; i < ctx->streamout.num_targets; i++)
+               ctx->streamout.offsets[i] += prims;
+
        /* if an app (or, well, piglit test) does many thousands of draws
         * without flush (or anything which implicitly flushes, like
         * changing render targets), we can exceed the ringbuffer size.
index de3cb64ed5b9ce513994d6cf873843bf4f1cc8f5..d649925af48aa5310a42ddd2da91c08be09e1483 100644 (file)
@@ -647,6 +647,8 @@ fd_blitter_pipe_begin(struct fd_context *ctx)
        util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vtx.vertexbuf.vb);
        util_blitter_save_vertex_elements(ctx->blitter, ctx->vtx.vtx);
        util_blitter_save_vertex_shader(ctx->blitter, ctx->prog.vp);
+       util_blitter_save_so_targets(ctx->blitter, ctx->streamout.num_targets,
+                       ctx->streamout.targets);
        util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer);
        util_blitter_save_viewport(ctx->blitter, &ctx->viewport);
        util_blitter_save_scissor(ctx->blitter, &ctx->scissor);
index 77aa4f21d3bd51f3decbf002ddd75134b736a28c..7bf8bdb45070691ed4cc22c2bbeaf8ded156f0dd 100644 (file)
@@ -300,6 +300,67 @@ fd_vertex_state_bind(struct pipe_context *pctx, void *hwcso)
        ctx->dirty |= FD_DIRTY_VTXSTATE;
 }
 
+static struct pipe_stream_output_target *
+fd_create_stream_output_target(struct pipe_context *pctx,
+               struct pipe_resource *prsc, unsigned buffer_offset,
+               unsigned buffer_size)
+{
+       struct pipe_stream_output_target *target;
+
+       target = CALLOC_STRUCT(pipe_stream_output_target);
+       if (!target)
+               return NULL;
+
+       pipe_reference_init(&target->reference, 1);
+       pipe_resource_reference(&target->buffer, prsc);
+
+       target->context = pctx;
+       target->buffer_offset = buffer_offset;
+       target->buffer_size = buffer_size;
+
+       return target;
+}
+
+static void
+fd_stream_output_target_destroy(struct pipe_context *pctx,
+               struct pipe_stream_output_target *target)
+{
+       pipe_resource_reference(&target->buffer, NULL);
+       FREE(target);
+}
+
+static void
+fd_set_stream_output_targets(struct pipe_context *pctx,
+               unsigned num_targets, struct pipe_stream_output_target **targets,
+               const unsigned *offsets)
+{
+       struct fd_context *ctx = fd_context(pctx);
+       struct fd_streamout_stateobj *so = &ctx->streamout;
+       unsigned i;
+
+       debug_assert(num_targets <= ARRAY_SIZE(so->targets));
+
+       for (i = 0; i < num_targets; i++) {
+               boolean changed = targets[i] != so->targets[i];
+               boolean append = (offsets[i] == (unsigned)-1);
+
+               if (!changed && append)
+                       continue;
+
+               so->offsets[i] = 0;
+
+               pipe_so_target_reference(&so->targets[i], targets[i]);
+       }
+
+       for (; i < so->num_targets; i++) {
+               pipe_so_target_reference(&so->targets[i], NULL);
+       }
+
+       so->num_targets = num_targets;
+
+       ctx->dirty |= FD_DIRTY_STREAMOUT;
+}
+
 void
 fd_state_init(struct pipe_context *pctx)
 {
@@ -328,4 +389,8 @@ fd_state_init(struct pipe_context *pctx)
        pctx->create_vertex_elements_state = fd_vertex_state_create;
        pctx->delete_vertex_elements_state = fd_vertex_state_delete;
        pctx->bind_vertex_elements_state = fd_vertex_state_bind;
+
+       pctx->create_stream_output_target = fd_create_stream_output_target;
+       pctx->stream_output_target_destroy = fd_stream_output_target_destroy;
+       pctx->set_stream_output_targets = fd_set_stream_output_targets;
 }