lima: track write submits of context (v3)
authorQiang Yu <yuq825@gmail.com>
Thu, 6 Feb 2020 12:02:31 +0000 (20:02 +0800)
committerMarge Bot <eric+marge@anholt.net>
Mon, 17 Feb 2020 02:54:15 +0000 (02:54 +0000)
We need to flush submit which write to the FBO before read it as
texture.

v2:
rename lima_flush_previous_write_submit to
lima_flush_previous_submit_writing_resouce.

v3:
delay add submit to hash_table to lima_update_submit_wb when really
know the render target will be written.

Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3755>

src/gallium/drivers/lima/lima_context.h
src/gallium/drivers/lima/lima_draw.c
src/gallium/drivers/lima/lima_submit.c
src/gallium/drivers/lima/lima_texture.c

index b434a60f94380cfd5fcc08dcf64afb3561535bfa..9bb1a931da5402f9f44ae6217bed122c28bb148a 100644 (file)
@@ -244,6 +244,9 @@ struct lima_context {
    /* map from lima_submit_key to lima_submit */
    struct hash_table *submits;
 
+   /* map from pipe_resource to lima_submit which write to it */
+   struct hash_table *write_submits;
+
    int in_sync_fd;
    uint32_t in_sync[2];
    uint32_t out_sync[2];
@@ -301,5 +304,7 @@ lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
 void lima_flush(struct lima_context *ctx);
 void lima_flush_submit_accessing_bo(
    struct lima_context *ctx, struct lima_bo *bo, bool write);
+void lima_flush_previous_submit_writing_resource(
+   struct lima_context *ctx, struct pipe_resource *prsc);
 
 #endif
index cfb07b665ddee428dab254574b364ba1d5abaafa..cf30a8acc833fea03b43ddbbe895c8a61df197d5 100644 (file)
@@ -33,6 +33,7 @@
 #include "util/u_upload_mgr.h"
 #include "util/u_prim.h"
 #include "util/u_vbuf.h"
+#include "util/hash_table.h"
 
 #include "lima_context.h"
 #include "lima_screen.h"
@@ -69,6 +70,7 @@ lima_update_submit_wb(struct lima_context *ctx, unsigned buffers)
        !(ctx->resolve & PIPE_CLEAR_COLOR0)) {
       struct lima_resource *res = lima_resource(fb->base.cbufs[0]->texture);
       lima_flush_submit_accessing_bo(ctx, res->bo, true);
+      _mesa_hash_table_insert(ctx->write_submits, &res->base, submit);
       lima_submit_add_bo(submit, LIMA_PIPE_PP, res->bo, LIMA_SUBMIT_BO_WRITE);
    }
 
@@ -77,6 +79,7 @@ lima_update_submit_wb(struct lima_context *ctx, unsigned buffers)
        !(ctx->resolve & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL))) {
       struct lima_resource *res = lima_resource(fb->base.zsbuf->texture);
       lima_flush_submit_accessing_bo(ctx, res->bo, true);
+      _mesa_hash_table_insert(ctx->write_submits, &res->base, submit);
       lima_submit_add_bo(submit, LIMA_PIPE_PP, res->bo, LIMA_SUBMIT_BO_WRITE);
    }
 
index 1cf2eacfbfc67d3bc425e283f1f1c84b7b14becf..8bc16ebf048171eb0fe56bcffde08b5f1bb15924 100644 (file)
@@ -78,6 +78,11 @@ lima_submit_free(struct lima_submit *submit)
 
    _mesa_hash_table_remove_key(ctx->submits, &submit->key);
 
+   if (submit->key.cbuf && (ctx->resolve & PIPE_CLEAR_COLOR0))
+      _mesa_hash_table_remove_key(ctx->write_submits, submit->key.cbuf->texture);
+   if (submit->key.zsbuf && (ctx->resolve & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)))
+      _mesa_hash_table_remove_key(ctx->write_submits, submit->key.zsbuf->texture);
+
    pipe_surface_reference(&submit->key.cbuf, NULL);
    pipe_surface_reference(&submit->key.zsbuf, NULL);
 
@@ -921,14 +926,15 @@ lima_do_submit(struct lima_submit *submit)
    ctx->damage_rect.minx = ctx->damage_rect.miny = 0xffff;
    ctx->damage_rect.maxx = ctx->damage_rect.maxy = 0;
 
-   ctx->resolve = 0;
-
    lima_dump_file_next();
 
    if (ctx->submit == submit)
       ctx->submit = NULL;
 
    lima_submit_free(submit);
+
+   /* lima_submit_free still need this */
+   ctx->resolve = 0;
 }
 
 void
@@ -951,6 +957,25 @@ lima_flush_submit_accessing_bo(
    }
 }
 
+/*
+ * This is for current submit flush previous submit which write to the resource it wants
+ * to read. Tipical usage is flush the FBO which is used as current task's texture.
+ */
+void
+lima_flush_previous_submit_writing_resource(
+   struct lima_context *ctx, struct pipe_resource *prsc)
+{
+   struct hash_entry *entry = _mesa_hash_table_search(ctx->write_submits, prsc);
+
+   if (entry) {
+      struct lima_submit *submit = entry->data;
+
+      /* do not flush current submit */
+      if (submit != ctx->submit)
+         lima_do_submit(submit);
+   }
+}
+
 static void
 lima_pipe_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
                 unsigned flags)
@@ -988,6 +1013,11 @@ bool lima_submit_init(struct lima_context *ctx)
    if (!ctx->submits)
       return false;
 
+   ctx->write_submits = _mesa_hash_table_create(
+      ctx, _mesa_hash_pointer, _mesa_key_pointer_equal);
+   if (!ctx->write_submits)
+      return false;
+
    ctx->in_sync_fd = -1;
 
    for (int i = 0; i < 2; i++) {
index 4d925427b527e744a18c7ca4ef9451d4846bb31b..5426894347bb5e01fb402f6175786b43cbbd11f3 100644 (file)
@@ -270,6 +270,7 @@ lima_update_textures(struct lima_context *ctx)
    for (int i = 0; i < lima_tex->num_samplers; i++) {
       struct lima_sampler_view *texture = lima_sampler_view(lima_tex->textures[i]);
       struct lima_resource *rsc = lima_resource(texture->base.texture);
+      lima_flush_previous_submit_writing_resource(ctx, texture->base.texture);
       lima_submit_add_bo(submit, LIMA_PIPE_PP, rsc->bo, LIMA_SUBMIT_BO_READ);
    }