From c0bc0ecf9eaf964ceb4a1573595da8b8b4585cc4 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Tue, 7 Feb 2023 09:17:00 -0800 Subject: [PATCH] freedreno: Avoid screen lock when no rsc tracking needed In case there is no dirty state that requires resource tracking we can skip taking the screen lock. Indirect draw and index buffer are a special case, but we can inexpensively check if they are already referenced by the batch. Signed-off-by: Rob Clark Part-of: --- .../drivers/freedreno/freedreno_draw.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/gallium/drivers/freedreno/freedreno_draw.c b/src/gallium/drivers/freedreno/freedreno_draw.c index cf40c191098..9709d31290a 100644 --- a/src/gallium/drivers/freedreno/freedreno_draw.c +++ b/src/gallium/drivers/freedreno/freedreno_draw.c @@ -42,6 +42,13 @@ #include "freedreno_state.h" #include "freedreno_util.h" +static bool +batch_references_resource(struct fd_batch *batch, struct pipe_resource *prsc) + assert_dt +{ + return fd_batch_references_resource(batch, fd_resource(prsc)); +} + static void resource_read(struct fd_batch *batch, struct pipe_resource *prsc) assert_dt { @@ -197,6 +204,29 @@ batch_draw_tracking_for_dirty_bits(struct fd_batch *batch) assert_dt batch->resolve |= buffers; } +static bool +needs_draw_tracking(struct fd_batch *batch, const struct pipe_draw_info *info, + const struct pipe_draw_indirect_info *indirect) + assert_dt +{ + struct fd_context *ctx = batch->ctx; + + if (ctx->dirty & FD_DIRTY_RESOURCE) + return true; + + if (info->index_size && !batch_references_resource(batch, info->index.resource)) + return true; + + if (indirect) { + if (indirect->buffer && !batch_references_resource(batch, indirect->buffer)) + return true; + if (indirect->count_from_stream_output) + return true; + } + + return false; +} + static void batch_draw_tracking(struct fd_batch *batch, const struct pipe_draw_info *info, const struct pipe_draw_indirect_info *indirect) assert_dt @@ -208,6 +238,9 @@ batch_draw_tracking(struct fd_batch *batch, const struct pipe_draw_info *info, */ fd_batch_update_queries(batch); + if (!needs_draw_tracking(batch, info, indirect)) + return; + /* * Figure out the buffers/features we need: */