freedreno: rebind resource in all contexts
authorRob Clark <robdclark@chromium.org>
Fri, 24 Apr 2020 22:00:20 +0000 (15:00 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Apr 2020 00:08:57 +0000 (00:08 +0000)
If the resource is rebound, we need to invalidate in all contexts.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4744>

src/gallium/drivers/freedreno/freedreno_context.c
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/freedreno/freedreno_screen.h

index 4969172e449062f88392472a95fae91f4c1c6701..529b58e8b54a6a0cc669babbdd1b60cc2b5fbcc5 100644 (file)
@@ -178,6 +178,10 @@ fd_context_destroy(struct pipe_context *pctx)
 
        DBG("");
 
+       mtx_lock(&ctx->screen->lock);
+       list_del(&ctx->node);
+       mtx_unlock(&ctx->screen->lock);
+
        fd_log_process(ctx, true);
        assert(list_is_empty(&ctx->log_chunks));
 
@@ -419,6 +423,10 @@ fd_context_init(struct fd_context *ctx, struct pipe_screen *pscreen,
        list_inithead(&ctx->acc_active_queries);
        list_inithead(&ctx->log_chunks);
 
+       mtx_lock(&ctx->screen->lock);
+       list_add(&ctx->node, &ctx->screen->context_list);
+       mtx_unlock(&ctx->screen->lock);
+
        ctx->log_out = stdout;
 
        if ((fd_mesa_debug & FD_DBG_LOG) &&
index faaade508fa9d2fc80d3f3c9ea95490422fb9859..57a172eede8f7732ede68314bd3a5cdf58b7976e 100644 (file)
@@ -162,6 +162,8 @@ enum fd_dirty_shader_state {
 struct fd_context {
        struct pipe_context base;
 
+       struct list_head node;   /* node in screen->context_list */
+
        /* We currently need to serialize emitting GMEM batches, because of
         * VSC state access in the context.
         *
index 0f846c7b2555b565d65b68acb0d9d38a06d41f56..a4933acdf3bcacea3025ac730b19070bfe884ebc 100644 (file)
@@ -146,11 +146,19 @@ rebind_resource_in_ctx(struct fd_context *ctx, struct fd_resource *rsc)
 }
 
 static void
-rebind_resource(struct fd_context *ctx, struct fd_resource *rsc)
+rebind_resource(struct fd_resource *rsc)
 {
+       struct fd_screen *screen = fd_screen(rsc->base.screen);
+
+       mtx_lock(&screen->lock);
        fd_resource_lock(rsc);
-       rebind_resource_in_ctx(ctx, rsc);
+
+       if (rsc->dirty)
+               list_for_each_entry (struct fd_context, ctx, &screen->context_list, node)
+                       rebind_resource_in_ctx(ctx, rsc);
+
        fd_resource_unlock(rsc);
+       mtx_unlock(&screen->lock);
 }
 
 static void
@@ -379,17 +387,7 @@ fd_resource_uncompress(struct fd_context *ctx, struct fd_resource *rsc)
        /* shadow should not fail in any cases where we need to uncompress: */
        debug_assert(success);
 
-       /*
-        * TODO what if rsc is used in other contexts, we don't currently
-        * have a good way to rebind_resource() in other contexts.  And an
-        * app that is reading one resource in multiple contexts, isn't
-        * going to expect that the resource is modified.
-        *
-        * Hopefully the edge cases where we need to uncompress are rare
-        * enough that they mostly only show up in deqp.
-        */
-
-       rebind_resource(ctx, rsc);
+       rebind_resource(rsc);
 }
 
 static struct fd_resource *
@@ -638,7 +636,7 @@ fd_resource_transfer_map(struct pipe_context *pctx,
        if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
                if (needs_flush || fd_resource_busy(rsc, op)) {
                        realloc_bo(rsc, fd_bo_size(rsc->bo));
-                       rebind_resource(ctx, rsc);
+                       rebind_resource(rsc);
                }
        } else if ((usage & PIPE_TRANSFER_WRITE) &&
                           prsc->target == PIPE_BUFFER &&
@@ -681,7 +679,7 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                        if (needs_flush && fd_try_shadow_resource(ctx, rsc, level,
                                                        box, DRM_FORMAT_MOD_LINEAR)) {
                                needs_flush = busy = false;
-                               rebind_resource(ctx, rsc);
+                               rebind_resource(rsc);
                                ctx->stats.shadow_uploads++;
                        } else {
                                struct fd_resource *staging_rsc;
index 0838412138f1c72029f24a6a932edba88027f000..143b601f3b7fe85e13db392bbac776e0dc82a7b6 100644 (file)
@@ -961,6 +961,8 @@ fd_screen_create(struct fd_device *dev, struct renderonly *ro)
 
        fd_bc_init(&screen->batch_cache);
 
+       list_inithead(&screen->context_list);
+
        (void) mtx_init(&screen->lock, mtx_plain);
 
        pscreen->destroy = fd_screen_destroy;
index 534d0a2f85934c51e9fd5cd185e5d04a9c4b8661..c46d1c8793dbbde12f02f3c3c4e4f3bee00bae6b 100644 (file)
@@ -46,6 +46,8 @@ struct fd_bo;
 struct fd_screen {
        struct pipe_screen base;
 
+       struct list_head context_list;
+
        mtx_t lock;
 
        /* it would be tempting to use pipe_reference here, but that