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>
This commit is contained in:
Emma Anholt
2021-06-15 11:17:27 -07:00
committed by Marge Bot
parent 447b6f60a6
commit 74ede4b353
3 changed files with 47 additions and 25 deletions
@@ -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, ...)
{
@@ -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);
@@ -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);
}
}