freedreno: push resource tracking down into batch
authorRob Clark <robclark@freedesktop.org>
Sat, 21 May 2016 00:05:26 +0000 (20:05 -0400)
committerRob Clark <robdclark@gmail.com>
Sat, 30 Jul 2016 13:23:42 +0000 (09:23 -0400)
Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/freedreno_batch.c
src/gallium/drivers/freedreno/freedreno_batch.h
src/gallium/drivers/freedreno/freedreno_context.c
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_resource.h

index c202ff0e94299010f7da7503e73a53efb0a09b0b..51a61d96e029b55c67a4b6db8913f40f91d36bfb 100644 (file)
  *    Rob Clark <robclark@freedesktop.org>
  */
 
+#include "util/list.h"
 #include "util/u_string.h"
 
 #include "freedreno_batch.h"
 #include "freedreno_context.h"
+#include "freedreno_resource.h"
 
 struct fd_batch *
 fd_batch_create(struct fd_context *ctx)
@@ -54,6 +56,8 @@ fd_batch_create(struct fd_context *ctx)
        fd_ringbuffer_set_parent(batch->draw, batch->gmem);
        fd_ringbuffer_set_parent(batch->binning, batch->gmem);
 
+       list_inithead(&batch->used_resources);
+
        return batch;
 }
 
@@ -76,7 +80,38 @@ __fd_batch_describe(char* buf, const struct fd_batch *batch)
 void
 fd_batch_flush(struct fd_batch *batch)
 {
+       struct fd_resource *rsc, *rsc_tmp;
+
        fd_gmem_render_tiles(batch->ctx);
+
+       /* go through all the used resources and clear their reading flag */
+       LIST_FOR_EACH_ENTRY_SAFE(rsc, rsc_tmp, &batch->used_resources, list) {
+               debug_assert(rsc->pending_batch == batch);
+               debug_assert(rsc->status != 0);
+               rsc->status = 0;
+               fd_batch_reference(&rsc->pending_batch, NULL);
+               list_delinit(&rsc->list);
+       }
+
+       assert(LIST_IS_EMPTY(&batch->used_resources));
+}
+
+void
+fd_batch_resource_used(struct fd_batch *batch, struct fd_resource *rsc,
+               enum fd_resource_status status)
+{
+       rsc->status |= status;
+
+       if (rsc->stencil)
+               rsc->stencil->status |= status;
+
+       /* TODO resources can actually be shared across contexts,
+        * so I'm not sure a single list-head will do the trick?
+        */
+       debug_assert((rsc->pending_batch == batch) || !rsc->pending_batch);
+       list_delinit(&rsc->list);
+       list_addtail(&rsc->list, &batch->used_resources);
+       fd_batch_reference(&rsc->pending_batch, batch);
 }
 
 void
index 2134624f833018e15bceca0748ce91633d2fc883..69779d8c8f46b5cab4a0bfff4b69bbbfaa44f3f9 100644 (file)
@@ -32,6 +32,8 @@
 #include "freedreno_util.h"
 
 struct fd_context;
+struct fd_resource;
+enum fd_resource_status;
 
 /* A batch tracks everything about a cmdstream batch/submit, including the
  * ringbuffers used for binning, draw, and gmem cmds, list of associated
@@ -48,11 +50,16 @@ struct fd_batch {
        struct fd_ringbuffer *binning;
        /** tiling/gmem (IB0) cmdstream: */
        struct fd_ringbuffer *gmem;
+
+       /** list of resources used by currently-unsubmitted batch */
+       struct list_head used_resources;
 };
 
 struct fd_batch * fd_batch_create(struct fd_context *ctx);
 
 void fd_batch_flush(struct fd_batch *batch);
+void fd_batch_resource_used(struct fd_batch *batch, struct fd_resource *rsc,
+               enum fd_resource_status status);
 void fd_batch_check_size(struct fd_batch *batch);
 
 /* not called directly: */
index d3a631e3a008e9ea67d851cff9ab241d04a7278d..3614370bf333a2fa59bac814ac3fe3f66bc16257 100644 (file)
@@ -45,7 +45,6 @@ void
 fd_context_render(struct pipe_context *pctx)
 {
        struct fd_context *ctx = fd_context(pctx);
-       struct fd_resource *rsc, *rsc_tmp;
 
        DBG("needs_flush: %d", ctx->needs_flush);
 
@@ -61,16 +60,6 @@ fd_context_render(struct pipe_context *pctx)
        ctx->cleared = ctx->partial_cleared = ctx->restore = ctx->resolve = 0;
        ctx->gmem_reason = 0;
        ctx->num_draws = 0;
-
-       /* go through all the used resources and clear their reading flag */
-       LIST_FOR_EACH_ENTRY_SAFE(rsc, rsc_tmp, &ctx->used_resources, list) {
-               debug_assert(rsc->status != 0);
-               rsc->status = 0;
-               rsc->pending_ctx = NULL;
-               list_delinit(&rsc->list);
-       }
-
-       assert(LIST_IS_EMPTY(&ctx->used_resources));
 }
 
 static void
index cdf40146881574c8f6563b5bf450e22ac5bd0f60..88e103ea6c3daafaaca5d4048e0abfbfb9de2d2c 100644 (file)
@@ -185,9 +185,6 @@ struct fd_context {
        struct fd_bo *query_bo;
        uint32_t query_tile_stride;
 
-       /* list of resources used by currently-unsubmitted renders */
-       struct list_head used_resources;
-
        /* table with PIPE_PRIM_MAX entries mapping PIPE_PRIM_x to
         * DI_PT_x value to use for draw initiator.  There are some
         * slight differences between generation:
index 26164f2109e1b8e0a5f48086c0c1070bf4b0c9e4..2c76333cf12663ba7b54ade104dfbd9f8e99517f 100644 (file)
 #include "freedreno_util.h"
 
 static void
-resource_used(struct fd_context *ctx, struct pipe_resource *prsc,
-               enum fd_resource_status status)
+resource_read(struct fd_context *ctx, struct pipe_resource *prsc)
 {
-       struct fd_resource *rsc;
-
        if (!prsc)
                return;
-
-       rsc = fd_resource(prsc);
-       rsc->status |= status;
-       if (rsc->stencil)
-               rsc->stencil->status |= status;
-
-       /* TODO resources can actually be shared across contexts,
-        * so I'm not sure a single list-head will do the trick?
-        */
-       debug_assert((rsc->pending_ctx == ctx) || !rsc->pending_ctx);
-       list_delinit(&rsc->list);
-       list_addtail(&rsc->list, &ctx->used_resources);
-       rsc->pending_ctx = ctx;
-}
-
-static void
-resource_read(struct fd_context *ctx, struct pipe_resource *prsc)
-{
-       resource_used(ctx, prsc, FD_PENDING_READ);
+       fd_batch_resource_used(ctx->batch, fd_resource(prsc), FD_PENDING_READ);
 }
 
 static void
 resource_written(struct fd_context *ctx, struct pipe_resource *prsc)
 {
-       resource_used(ctx, prsc, FD_PENDING_WRITE);
+       if (!prsc)
+               return;
+       fd_batch_resource_used(ctx->batch, fd_resource(prsc), FD_PENDING_WRITE);
 }
 
 static void
@@ -300,8 +281,6 @@ fd_clear_depth_stencil(struct pipe_context *pctx, struct pipe_surface *ps,
 void
 fd_draw_init(struct pipe_context *pctx)
 {
-       list_inithead(&fd_context(pctx)->used_resources);
-
        pctx->draw_vbo = fd_draw_vbo;
        pctx->clear = fd_clear;
        pctx->clear_render_target = fd_clear_render_target;
index 41f46a69c3e104baa4742051048b161e7120633b..eea53c606964b6fa4be46c5373cabf40191e0bc6 100644 (file)
@@ -109,7 +109,7 @@ realloc_bo(struct fd_resource *rsc, uint32_t size)
        rsc->bo = fd_bo_new(screen->dev, size, flags);
        rsc->timestamp = 0;
        rsc->status = 0;
-       rsc->pending_ctx = NULL;
+       fd_batch_reference(&rsc->pending_batch, NULL);
        list_delinit(&rsc->list);
        util_range_set_empty(&rsc->valid_buffer_range);
 }
@@ -453,6 +453,7 @@ fd_resource_destroy(struct pipe_screen *pscreen,
        struct fd_resource *rsc = fd_resource(prsc);
        if (rsc->bo)
                fd_bo_del(rsc->bo);
+       fd_batch_reference(&rsc->pending_batch, NULL);
        list_delinit(&rsc->list);
        util_range_destroy(&rsc->valid_buffer_range);
        FREE(rsc);
index 9a9b0d08244a8905d0fbd61fd93b48d1f55b84c9..f8131c774ecedfc7ac2064e82d9ff0e973f9eca9 100644 (file)
@@ -33,6 +33,7 @@
 #include "util/u_range.h"
 #include "util/u_transfer.h"
 
+#include "freedreno_batch.h"
 #include "freedreno_util.h"
 
 /* Texture Layout on a3xx:
@@ -91,7 +92,7 @@ struct fd_resource {
         * in the used_resources list.
         */
        struct list_head list;
-       struct fd_context *pending_ctx;
+       struct fd_batch *pending_batch;
 };
 
 static inline struct fd_resource *