Mesa (main): freedreno: Move the rsc-based batch flushing to helper functions.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jun 21 21:22:47 UTC 2021
Module: Mesa
Branch: main
Commit: 74ede4b353bcac7451a56c75712e25151f7c6b63
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=74ede4b353bcac7451a56c75712e25151f7c6b63
Author: Emma Anholt <emma at anholt.net>
Date: Tue Jun 15 11:17:27 2021 -0700
freedreno: Move the rsc-based batch flushing to helper functions.
I want to reuse these, and this gives them nice names.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11455>
---
.../drivers/freedreno/freedreno_batch_cache.c | 43 ++++++++++++++++++++++
.../drivers/freedreno/freedreno_batch_cache.h | 2 +
src/gallium/drivers/freedreno/freedreno_resource.c | 27 +-------------
3 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/src/gallium/drivers/freedreno/freedreno_batch_cache.c b/src/gallium/drivers/freedreno/freedreno_batch_cache.c
index 16378e77067..681db868787 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch_cache.c
+++ b/src/gallium/drivers/freedreno/freedreno_batch_cache.c
@@ -194,6 +194,49 @@ fd_bc_flush(struct fd_context *ctx, bool deferred) assert_dt
}
}
+/**
+ * Flushes the batch (if any) writing this resource. Must not hold the screen
+ * lock.
+ */
+void
+fd_bc_flush_writer(struct fd_context *ctx, struct fd_resource *rsc) assert_dt
+{
+ fd_screen_lock(ctx->screen);
+ struct fd_batch *write_batch = NULL;
+ fd_batch_reference_locked(&write_batch, rsc->track->write_batch);
+ fd_screen_unlock(ctx->screen);
+
+ if (write_batch) {
+ fd_batch_flush(write_batch);
+ fd_batch_reference(&write_batch, NULL);
+ }
+}
+
+/**
+ * Flushes any batches reading this resource. Must not hold the screen lock.
+ */
+void
+fd_bc_flush_readers(struct fd_context *ctx, struct fd_resource *rsc) assert_dt
+{
+ struct fd_batch *batch, *batches[32] = {};
+ uint32_t batch_count = 0;
+
+ /* This is a bit awkward, probably a fd_batch_flush_locked()
+ * would make things simpler.. but we need to hold the lock
+ * to iterate the batches which reference this resource. So
+ * we must first grab references under a lock, then flush.
+ */
+ fd_screen_lock(ctx->screen);
+ foreach_batch (batch, &ctx->screen->batch_cache, rsc->track->batch_mask)
+ fd_batch_reference_locked(&batches[batch_count++], batch);
+ fd_screen_unlock(ctx->screen);
+
+ for (int i = 0; i < batch_count; i++) {
+ fd_batch_flush(batches[i]);
+ fd_batch_reference(&batches[i], NULL);
+ }
+}
+
void
fd_bc_dump(struct fd_context *ctx, const char *fmt, ...)
{
diff --git a/src/gallium/drivers/freedreno/freedreno_batch_cache.h b/src/gallium/drivers/freedreno/freedreno_batch_cache.h
index d9d6c2c307e..4b2737bac80 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch_cache.h
+++ b/src/gallium/drivers/freedreno/freedreno_batch_cache.h
@@ -67,6 +67,8 @@ void fd_bc_init(struct fd_batch_cache *cache);
void fd_bc_fini(struct fd_batch_cache *cache);
void fd_bc_flush(struct fd_context *ctx, bool deferred) assert_dt;
+void fd_bc_flush_writer(struct fd_context *ctx, struct fd_resource *rsc) assert_dt;
+void fd_bc_flush_readers(struct fd_context *ctx, struct fd_resource *rsc) assert_dt;
void fd_bc_dump(struct fd_context *ctx, const char *fmt, ...)
_util_printf_format(2, 3);
diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
index 6b27cead2e3..89d27504286 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -667,32 +667,9 @@ flush_resource(struct fd_context *ctx, struct fd_resource *rsc,
unsigned usage) assert_dt
{
if (usage & PIPE_MAP_WRITE) {
- struct fd_batch *batch, *batches[32] = {};
- uint32_t batch_count = 0;
-
- /* This is a bit awkward, probably a fd_batch_flush_locked()
- * would make things simpler.. but we need to hold the lock
- * to iterate the batches which reference this resource. So
- * we must first grab references under a lock, then flush.
- */
- fd_screen_lock(ctx->screen);
- foreach_batch (batch, &ctx->screen->batch_cache, rsc->track->batch_mask)
- fd_batch_reference_locked(&batches[batch_count++], batch);
- fd_screen_unlock(ctx->screen);
-
- for (int i = 0; i < batch_count; i++) {
- fd_batch_flush(batches[i]);
- fd_batch_reference(&batches[i], NULL);
- }
+ fd_bc_flush_readers(ctx, rsc);
} else {
- struct fd_batch *write_batch = NULL;
- fd_screen_lock(ctx->screen);
- fd_batch_reference_locked(&write_batch, rsc->track->write_batch);
- fd_screen_unlock(ctx->screen);
- if (write_batch) {
- fd_batch_flush(write_batch);
- fd_batch_reference(&write_batch, NULL);
- }
+ fd_bc_flush_writer(ctx, rsc);
}
}
More information about the mesa-commit
mailing list