freedreno/batch: Move query_buf allocation

This lets us move fd_batch_update_queries() after resource tracking.
Which will become needed in the next patch which adds validation to
assert needed BOs are attached to the submit.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25465>
This commit is contained in:
Rob Clark
2023-09-26 12:51:53 -07:00
committed by Marge Bot
parent 2189920e49
commit c6f17d89c7
3 changed files with 38 additions and 27 deletions
@@ -440,6 +440,34 @@ alloc_batch_locked(struct fd_batch_cache *cache, struct fd_context *ctx,
return batch;
}
static void
alloc_query_buf(struct fd_context *ctx, struct fd_batch *batch)
{
if (batch->query_buf)
return;
if ((ctx->screen->gen < 3) || (ctx->screen->gen > 4))
return;
/* For gens that use fd_hw_query, pre-allocate an initially zero-sized
* (unbacked) query buffer. This simplifies draw/grid/etc-time resource
* tracking.
*/
struct pipe_screen *pscreen = &ctx->screen->base;
struct pipe_resource templ = {
.target = PIPE_BUFFER,
.format = PIPE_FORMAT_R8_UNORM,
.bind = PIPE_BIND_QUERY_BUFFER,
.width0 = 0, /* create initially zero size buffer */
.height0 = 1,
.depth0 = 1,
.array_size = 1,
.last_level = 0,
.nr_samples = 1,
};
batch->query_buf = pscreen->resource_create(pscreen, &templ);
}
struct fd_batch *
fd_bc_alloc_batch(struct fd_context *ctx, bool nondraw)
{
@@ -457,6 +485,8 @@ fd_bc_alloc_batch(struct fd_context *ctx, bool nondraw)
batch = alloc_batch_locked(cache, ctx, nondraw);
fd_screen_unlock(ctx->screen);
alloc_query_buf(ctx, batch);
if (batch && nondraw)
fd_context_switch_to(ctx, batch);
@@ -552,6 +582,8 @@ fd_batch_from_fb(struct fd_context *ctx,
struct fd_batch *batch = batch_from_key(ctx, key);
fd_screen_unlock(ctx->screen);
alloc_query_buf(ctx, batch);
fd_batch_set_fb(batch, pfb);
return batch;
+6 -11
View File
@@ -234,13 +234,8 @@ batch_draw_tracking(struct fd_batch *batch, const struct pipe_draw_info *info,
{
struct fd_context *ctx = batch->ctx;
/* NOTE: needs to be before resource_written(batch->query_buf), otherwise
* query_buf may not be created yet.
*/
fd_batch_update_queries(batch);
if (!needs_draw_tracking(batch, info, indirect))
return;
goto out;
/*
* Figure out the buffers/features we need:
@@ -268,6 +263,9 @@ batch_draw_tracking(struct fd_batch *batch, const struct pipe_draw_info *info,
resource_written(batch, batch->query_buf);
fd_screen_unlock(ctx->screen);
out:
fd_batch_update_queries(batch);
}
static void
@@ -585,11 +583,6 @@ fd_launch_grid(struct pipe_context *pctx,
fd_batch_reference(&save_batch, ctx->batch);
fd_batch_reference(&ctx->batch, batch);
/* NOTE: needs to be before resource_written(batch->query_buf), otherwise
* query_buf may not be created yet.
*/
fd_batch_update_queries(batch);
fd_screen_lock(ctx->screen);
/* Mark SSBOs */
@@ -636,6 +629,8 @@ fd_launch_grid(struct pipe_context *pctx,
fd_screen_unlock(ctx->screen);
fd_batch_update_queries(batch);
DBG("%p: work_dim=%u, block=%ux%ux%u, grid=%ux%ux%u",
batch, info->work_dim,
info->block[0], info->block[1], info->block[2],
@@ -299,22 +299,6 @@ fd_hw_sample_init(struct fd_batch *batch, uint32_t size)
samp->tile_stride = 0;
batch->next_sample_offset += size;
if (!batch->query_buf) {
struct pipe_screen *pscreen = &batch->ctx->screen->base;
struct pipe_resource templ = {
.target = PIPE_BUFFER,
.format = PIPE_FORMAT_R8_UNORM,
.bind = PIPE_BIND_QUERY_BUFFER,
.width0 = 0, /* create initially zero size buffer */
.height0 = 1,
.depth0 = 1,
.array_size = 1,
.last_level = 0,
.nr_samples = 1,
};
batch->query_buf = pscreen->resource_create(pscreen, &templ);
}
pipe_resource_reference(&samp->prsc, batch->query_buf);
return samp;