panfrost: Split "flush writer" from "flush accessing"

Since writers are counted in the accessor set, the old implementation
had a redundant flush in the "flush accessing" case. To fix, split the
two modes into separate functions, removing the redundancy and offering
a much more ergonomic API.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11077>
This commit is contained in:
Alyssa Rosenzweig 2021-05-28 18:23:37 -04:00 committed by Marge Bot
parent cecb889481
commit 5100c42cbb
5 changed files with 22 additions and 19 deletions

View File

@ -1132,7 +1132,7 @@ panfrost_map_constant_buffer_cpu(struct panfrost_context *ctx,
if (rsrc) {
panfrost_bo_mmap(rsrc->image.data.bo);
panfrost_flush_batches_accessing_rsrc(ctx, rsrc, false);
panfrost_flush_writer(ctx, rsrc);
panfrost_bo_wait(rsrc->image.data.bo, INT64_MAX, false);
return rsrc->image.data.bo->ptr.cpu + cb->buffer_offset;

View File

@ -1821,7 +1821,7 @@ panfrost_get_query_result(struct pipe_context *pipe,
case PIPE_QUERY_OCCLUSION_COUNTER:
case PIPE_QUERY_OCCLUSION_PREDICATE:
case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
panfrost_flush_batches_accessing_rsrc(ctx, rsrc, false);
panfrost_flush_writer(ctx, rsrc);
panfrost_bo_wait(rsrc->image.data.bo, INT64_MAX, false);
/* Read back the query results */

View File

@ -905,21 +905,20 @@ panfrost_flush_all_batches(struct panfrost_context *ctx)
}
}
/* We always flush writers. We might also need to flush readers */
void
panfrost_flush_batches_accessing_rsrc(struct panfrost_context *ctx,
struct panfrost_resource *rsrc,
bool flush_readers)
panfrost_flush_writer(struct panfrost_context *ctx,
struct panfrost_resource *rsrc)
{
if (rsrc->track.writer) {
panfrost_batch_submit(rsrc->track.writer, ctx->syncobj, ctx->syncobj);
rsrc->track.writer = NULL;
}
}
if (!flush_readers)
return;
void
panfrost_flush_batches_accessing_rsrc(struct panfrost_context *ctx,
struct panfrost_resource *rsrc)
{
unsigned i;
BITSET_FOREACH_SET(i, rsrc->track.users, PAN_MAX_BATCHES) {
panfrost_batch_submit(&ctx->batches.slots[i],
@ -927,6 +926,7 @@ panfrost_flush_batches_accessing_rsrc(struct panfrost_context *ctx,
}
assert(!BITSET_COUNT(rsrc->track.users));
rsrc->track.writer = NULL;
}
void

View File

@ -174,8 +174,11 @@ panfrost_flush_all_batches(struct panfrost_context *ctx);
void
panfrost_flush_batches_accessing_rsrc(struct panfrost_context *ctx,
struct panfrost_resource *rsrc,
bool flush_readers);
struct panfrost_resource *rsrc);
void
panfrost_flush_writer(struct panfrost_context *ctx,
struct panfrost_resource *rsrc);
void
panfrost_batch_adjust_stack_size(struct panfrost_batch *batch);

View File

@ -843,11 +843,11 @@ panfrost_ptr_map(struct pipe_context *pctx,
/* TODO: Eliminate this flush. It's only there to determine if
* we're initialized or not, when the initialization could come
* from a pending batch XXX */
panfrost_flush_batches_accessing_rsrc(ctx, rsrc, true);
panfrost_flush_batches_accessing_rsrc(ctx, rsrc);
if ((usage & PIPE_MAP_READ) && BITSET_TEST(rsrc->valid.data, level)) {
pan_blit_to_staging(pctx, transfer);
panfrost_flush_batches_accessing_rsrc(ctx, staging, true);
panfrost_flush_batches_accessing_rsrc(ctx, staging);
panfrost_bo_wait(staging->image.data.bo, INT64_MAX, false);
}
@ -876,7 +876,7 @@ panfrost_ptr_map(struct pipe_context *pctx,
* to flush and split the frame in two.
*/
panfrost_flush_batches_accessing_rsrc(ctx, rsrc, false);
panfrost_flush_writer(ctx, rsrc);
panfrost_bo_wait(bo, INT64_MAX, false);
create_new_bo = true;
@ -919,7 +919,7 @@ panfrost_ptr_map(struct pipe_context *pctx,
/* Allocation failed or was impossible, let's
* fall back on a flush+wait.
*/
panfrost_flush_batches_accessing_rsrc(ctx, rsrc, true);
panfrost_flush_batches_accessing_rsrc(ctx, rsrc);
panfrost_bo_wait(bo, INT64_MAX, true);
}
}
@ -929,10 +929,10 @@ panfrost_ptr_map(struct pipe_context *pctx,
/* No flush for writes to uninitialized */
} else if (!(usage & PIPE_MAP_UNSYNCHRONIZED)) {
if (usage & PIPE_MAP_WRITE) {
panfrost_flush_batches_accessing_rsrc(ctx, rsrc, true);
panfrost_flush_batches_accessing_rsrc(ctx, rsrc);
panfrost_bo_wait(bo, INT64_MAX, true);
} else if (usage & PIPE_MAP_READ) {
panfrost_flush_batches_accessing_rsrc(ctx, rsrc, false);
panfrost_flush_writer(ctx, rsrc);
panfrost_bo_wait(bo, INT64_MAX, false);
}
}
@ -1100,7 +1100,7 @@ panfrost_ptr_unmap(struct pipe_context *pctx,
panfrost_bo_reference(prsrc->image.data.bo);
} else {
pan_blit_from_staging(pctx, trans);
panfrost_flush_batches_accessing_rsrc(pan_context(pctx), pan_resource(trans->staging.rsrc), true);
panfrost_flush_batches_accessing_rsrc(pan_context(pctx), pan_resource(trans->staging.rsrc));
}
}