panfrost: Remove panfrost_bo_access type

It's just whether it writes or not, which is already implied by the
presence/absence of a writer. So no need to track explicitly.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5859>
This commit is contained in:
Alyssa Rosenzweig 2020-05-26 14:47:21 -04:00 committed by Marge Bot
parent 62ec4e02f6
commit c6ebff3ecd
3 changed files with 24 additions and 44 deletions

View file

@ -43,8 +43,7 @@
* better GPU utilization. * better GPU utilization.
* *
* Each accessed BO has a corresponding entry in the ->accessed_bos hash table. * Each accessed BO has a corresponding entry in the ->accessed_bos hash table.
* A BO is either being written or read at any time, that's what the type field * A BO is either being written or read at any time (see if writer != NULL).
* encodes.
* When the last access is a write, the batch writing the BO might have read * When the last access is a write, the batch writing the BO might have read
* dependencies (readers that have not been executed yet and want to read the * dependencies (readers that have not been executed yet and want to read the
* previous BO content), and when the last access is a read, all readers might * previous BO content), and when the last access is a read, all readers might
@ -56,7 +55,6 @@
* updated to point to the new writer. * updated to point to the new writer.
*/ */
struct panfrost_bo_access { struct panfrost_bo_access {
uint32_t type;
struct util_dynarray readers; struct util_dynarray readers;
struct panfrost_batch_fence *writer; struct panfrost_batch_fence *writer;
}; };
@ -415,36 +413,31 @@ panfrost_batch_in_readers(struct panfrost_batch *batch,
static void static void
panfrost_batch_update_bo_access(struct panfrost_batch *batch, panfrost_batch_update_bo_access(struct panfrost_batch *batch,
struct panfrost_bo *bo, uint32_t access_type, struct panfrost_bo *bo, bool writes,
bool already_accessed) bool already_accessed)
{ {
struct panfrost_context *ctx = batch->ctx; struct panfrost_context *ctx = batch->ctx;
struct panfrost_bo_access *access; struct panfrost_bo_access *access;
uint32_t old_access_type; bool old_writes = false;
struct hash_entry *entry; struct hash_entry *entry;
assert(access_type == PAN_BO_ACCESS_WRITE ||
access_type == PAN_BO_ACCESS_READ);
entry = _mesa_hash_table_search(ctx->accessed_bos, bo); entry = _mesa_hash_table_search(ctx->accessed_bos, bo);
access = entry ? entry->data : NULL; access = entry ? entry->data : NULL;
if (access) { if (access) {
old_access_type = access->type; old_writes = access->writer != NULL;
} else { } else {
access = rzalloc(ctx, struct panfrost_bo_access); access = rzalloc(ctx, struct panfrost_bo_access);
util_dynarray_init(&access->readers, access); util_dynarray_init(&access->readers, access);
_mesa_hash_table_insert(ctx->accessed_bos, bo, access); _mesa_hash_table_insert(ctx->accessed_bos, bo, access);
/* We are the first to access this BO, let's initialize /* We are the first to access this BO, let's initialize
* old_access_type to our own access type in that case. * old_writes to our own access type in that case.
*/ */
old_access_type = access_type; old_writes = writes;
access->type = access_type;
} }
assert(access); assert(access);
if (access_type == PAN_BO_ACCESS_WRITE && if (writes && !old_writes) {
old_access_type == PAN_BO_ACCESS_READ) {
/* Previous access was a read and we want to write this BO. /* Previous access was a read and we want to write this BO.
* We first need to add explicit deps between our batch and * We first need to add explicit deps between our batch and
* the previous readers. * the previous readers.
@ -467,7 +460,6 @@ panfrost_batch_update_bo_access(struct panfrost_batch *batch,
/* We now are the new writer. */ /* We now are the new writer. */
access->writer = batch->out_sync; access->writer = batch->out_sync;
access->type = access_type;
/* Release the previous readers and reset the readers array. */ /* Release the previous readers and reset the readers array. */
util_dynarray_foreach(&access->readers, util_dynarray_foreach(&access->readers,
@ -479,10 +471,8 @@ panfrost_batch_update_bo_access(struct panfrost_batch *batch,
} }
util_dynarray_clear(&access->readers); util_dynarray_clear(&access->readers);
} else if (access_type == PAN_BO_ACCESS_WRITE && } else if (writes && old_writes) {
old_access_type == PAN_BO_ACCESS_WRITE) { /* First check if we were the previous writer, in that case
/* Previous access was a write and we want to write this BO.
* First check if we were the previous writer, in that case
* there's nothing to do. Otherwise we need to add a * there's nothing to do. Otherwise we need to add a
* dependency between the new writer and the old one. * dependency between the new writer and the old one.
*/ */
@ -494,10 +484,8 @@ panfrost_batch_update_bo_access(struct panfrost_batch *batch,
panfrost_batch_fence_reference(batch->out_sync); panfrost_batch_fence_reference(batch->out_sync);
access->writer = batch->out_sync; access->writer = batch->out_sync;
} }
} else if (access_type == PAN_BO_ACCESS_READ && } else if (!writes && old_writes) {
old_access_type == PAN_BO_ACCESS_WRITE) { /* First check if we were the previous writer, in that case
/* Previous access was a write and we want to read this BO.
* First check if we were the previous writer, in that case
* we want to keep the access type unchanged, as a write is * we want to keep the access type unchanged, as a write is
* more constraining than a read. * more constraining than a read.
*/ */
@ -516,7 +504,7 @@ panfrost_batch_update_bo_access(struct panfrost_batch *batch,
util_dynarray_append(&access->readers, util_dynarray_append(&access->readers,
struct panfrost_batch_fence *, struct panfrost_batch_fence *,
batch->out_sync); batch->out_sync);
access->type = PAN_BO_ACCESS_READ; access->writer = NULL;
} }
} else { } else {
/* We already accessed this BO before, so we should already be /* We already accessed this BO before, so we should already be
@ -587,11 +575,9 @@ panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo,
if (batch == batch->ctx->wallpaper_batch) if (batch == batch->ctx->wallpaper_batch)
return; return;
/* Only pass R/W flags to the dep tracking logic. */
assert(flags & PAN_BO_ACCESS_RW); assert(flags & PAN_BO_ACCESS_RW);
flags = (flags & PAN_BO_ACCESS_WRITE) ? panfrost_batch_update_bo_access(batch, bo, flags & PAN_BO_ACCESS_WRITE,
PAN_BO_ACCESS_WRITE : PAN_BO_ACCESS_READ; old_flags != 0);
panfrost_batch_update_bo_access(batch, bo, flags, old_flags != 0);
} }
static void static void
@ -1160,28 +1146,25 @@ panfrost_pending_batches_access_bo(struct panfrost_context *ctx,
return false; return false;
} }
/* We always flush writers. We might also need to flush readers */
void void
panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx, panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx,
struct panfrost_bo *bo, struct panfrost_bo *bo,
uint32_t access_type) bool flush_readers)
{ {
struct panfrost_bo_access *access; struct panfrost_bo_access *access;
struct hash_entry *hentry; struct hash_entry *hentry;
/* It doesn't make any to flush only the readers. */
assert(access_type == PAN_BO_ACCESS_WRITE ||
access_type == PAN_BO_ACCESS_RW);
hentry = _mesa_hash_table_search(ctx->accessed_bos, bo); hentry = _mesa_hash_table_search(ctx->accessed_bos, bo);
access = hentry ? hentry->data : NULL; access = hentry ? hentry->data : NULL;
if (!access) if (!access)
return; return;
if (access_type & PAN_BO_ACCESS_WRITE && access->writer && if (access->writer && access->writer->batch)
access->writer->batch)
panfrost_batch_submit(access->writer->batch); panfrost_batch_submit(access->writer->batch);
if (!(access_type & PAN_BO_ACCESS_READ)) if (!flush_readers)
return; return;
util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *, util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *,

View file

@ -173,7 +173,7 @@ panfrost_pending_batches_access_bo(struct panfrost_context *ctx,
void void
panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx, panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx,
struct panfrost_bo *bo, uint32_t flags); struct panfrost_bo *bo, bool flush_readers);
void void
panfrost_batch_set_requirements(struct panfrost_batch *batch); panfrost_batch_set_requirements(struct panfrost_batch *batch);

View file

@ -644,14 +644,11 @@ panfrost_transfer_map(struct pipe_context *pctx,
rsrc->bo = newbo; rsrc->bo = newbo;
bo = newbo; bo = newbo;
} else { } else {
uint32_t access = PAN_BO_ACCESS_RW;
/* Allocation failed or was impossible, let's /* Allocation failed or was impossible, let's
* fall back on a flush+wait. * fall back on a flush+wait.
*/ */
panfrost_flush_batches_accessing_bo(ctx, bo, panfrost_flush_batches_accessing_bo(ctx, bo, true);
access); panfrost_bo_wait(bo, INT64_MAX, true);
panfrost_bo_wait(bo, INT64_MAX, access);
} }
} }
} else if ((usage & PIPE_TRANSFER_WRITE) } else if ((usage & PIPE_TRANSFER_WRITE)
@ -660,10 +657,10 @@ panfrost_transfer_map(struct pipe_context *pctx,
/* No flush for writes to uninitialized */ /* No flush for writes to uninitialized */
} else if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) { } else if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
if (usage & PIPE_TRANSFER_WRITE) { if (usage & PIPE_TRANSFER_WRITE) {
panfrost_flush_batches_accessing_bo(ctx, bo, PAN_BO_ACCESS_RW); panfrost_flush_batches_accessing_bo(ctx, bo, true);
panfrost_bo_wait(bo, INT64_MAX, PAN_BO_ACCESS_RW); panfrost_bo_wait(bo, INT64_MAX, PAN_BO_ACCESS_RW);
} else if (usage & PIPE_TRANSFER_READ) { } else if (usage & PIPE_TRANSFER_READ) {
panfrost_flush_batches_accessing_bo(ctx, bo, PAN_BO_ACCESS_WRITE); panfrost_flush_batches_accessing_bo(ctx, bo, false);
panfrost_bo_wait(bo, INT64_MAX, PAN_BO_ACCESS_WRITE); panfrost_bo_wait(bo, INT64_MAX, PAN_BO_ACCESS_WRITE);
} }
} }