From 6c2edb976262d72f89eb44180aa3ab0fc4c19d28 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Fri, 24 Jan 2025 15:03:53 +0100 Subject: [PATCH] radeonsi: cache u_trace_perfetto_active value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit u_trace_perfetto_active uses an atomic read so avoid doing it too much in hot path. Reviewed-by: Marek Olšák Part-of: --- src/gallium/drivers/radeonsi/si_compute.c | 4 ++-- src/gallium/drivers/radeonsi/si_fence.c | 3 +-- src/gallium/drivers/radeonsi/si_gfx_cs.c | 11 +++++++---- src/gallium/drivers/radeonsi/si_pipe.h | 2 ++ src/gallium/drivers/radeonsi/si_state_draw.cpp | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c index 1abc69e3d9c..2dd329d3695 100644 --- a/src/gallium/drivers/radeonsi/si_compute.c +++ b/src/gallium/drivers/radeonsi/si_compute.c @@ -1237,7 +1237,7 @@ static void si_launch_grid(struct pipe_context *ctx, const struct pipe_grid_info } } - if (u_trace_perfetto_active(&sctx->ds.trace_context)) + if (sctx->perfetto_enabled) trace_si_begin_compute(&sctx->trace); if (sctx->bo_list_add_all_compute_resources) @@ -1310,7 +1310,7 @@ static void si_launch_grid(struct pipe_context *ctx, const struct pipe_grid_info sctx->compute_is_busy = true; sctx->num_compute_calls++; - if (u_trace_perfetto_active(&sctx->ds.trace_context)) + if (sctx->perfetto_enabled) trace_si_end_compute(&sctx->trace, info->grid[0], info->grid[1], info->grid[2]); if (cs_regalloc_hang) { diff --git a/src/gallium/drivers/radeonsi/si_fence.c b/src/gallium/drivers/radeonsi/si_fence.c index 1d2406df9fd..bcb56f23d96 100644 --- a/src/gallium/drivers/radeonsi/si_fence.c +++ b/src/gallium/drivers/radeonsi/si_fence.c @@ -474,9 +474,8 @@ static void si_flush_all_queues(struct pipe_context *ctx, si_handle_sqtt(sctx, &sctx->gfx_cs); } - if (u_trace_perfetto_active(&sctx->ds.trace_context)) { + if (sctx->perfetto_enabled) u_trace_context_process(&sctx->ds.trace_context, flags & PIPE_FLUSH_END_OF_FRAME); - } } else { /* Instead of flushing, create a deferred fence. Constraints: * - the gallium frontend must allow a deferred flush. diff --git a/src/gallium/drivers/radeonsi/si_gfx_cs.c b/src/gallium/drivers/radeonsi/si_gfx_cs.c index 2465c599d24..85c7c3a02f1 100644 --- a/src/gallium/drivers/radeonsi/si_gfx_cs.c +++ b/src/gallium/drivers/radeonsi/si_gfx_cs.c @@ -192,7 +192,9 @@ void si_flush_gfx_cs(struct si_context *ctx, unsigned flags, struct pipe_fence_h flags |= RADEON_FLUSH_NOOP; uint64_t start_ts = 0, submission_id = 0; - if (u_trace_perfetto_active(&ctx->ds.trace_context)) { + const bool perfetto = ctx->perfetto_enabled; + + if (perfetto) { start_ts = si_ds_begin_submit(&ctx->ds_queue); submission_id = ctx->ds_queue.submission_id; } @@ -200,9 +202,8 @@ void si_flush_gfx_cs(struct si_context *ctx, unsigned flags, struct pipe_fence_h /* Flush the CS. */ ws->cs_flush(cs, flags, &ctx->last_gfx_fence); - if (u_trace_perfetto_active(&ctx->ds.trace_context) && start_ts > 0) { + if (perfetto) si_ds_end_submit(&ctx->ds_queue, start_ts); - } tc_driver_internal_flush_notify(ctx->tc); if (fence) @@ -227,7 +228,7 @@ void si_flush_gfx_cs(struct si_context *ctx, unsigned flags, struct pipe_fence_h if (ctx->current_saved_cs) si_saved_cs_reference(&ctx->current_saved_cs, NULL); - if (u_trace_perfetto_active(&ctx->ds.trace_context)) + if (perfetto) si_utrace_flush(ctx, submission_id); si_begin_new_gfx_cs(ctx, false); @@ -433,6 +434,8 @@ void si_begin_new_gfx_cs(struct si_context *ctx, bool first_cs) if (!first_cs) u_trace_fini(&ctx->trace); + ctx->perfetto_enabled = u_trace_perfetto_active(&ctx->ds.trace_context); + u_trace_init(&ctx->trace, &ctx->ds.trace_context); if (unlikely(radeon_uses_secure_bos(ctx->ws))) { diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index bd2479f4eef..db0750fb59e 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -1345,6 +1345,8 @@ struct si_context { enum rgp_sqtt_marker_event_type sqtt_next_event; bool sqtt_enabled; + bool perfetto_enabled; + unsigned context_flags; /* Shaders. */ diff --git a/src/gallium/drivers/radeonsi/si_state_draw.cpp b/src/gallium/drivers/radeonsi/si_state_draw.cpp index fea041f1663..04f1cbfae09 100644 --- a/src/gallium/drivers/radeonsi/si_state_draw.cpp +++ b/src/gallium/drivers/radeonsi/si_state_draw.cpp @@ -2085,7 +2085,7 @@ static void si_draw(struct pipe_context *ctx, si_need_gfx_cs_space(sctx, num_draws, ALT_HIZ_LOGIC ? 8 : 0); - if (u_trace_perfetto_active(&sctx->ds.trace_context)) + if (sctx->perfetto_enabled) trace_si_begin_draw(&sctx->trace); unsigned instance_count = info->instance_count; @@ -2437,7 +2437,7 @@ static void si_draw(struct pipe_context *ctx, zstex->depth_cleared_level_mask &= ~BITFIELD_BIT(sctx->framebuffer.state.zsbuf->u.tex.level); } - if (u_trace_perfetto_active(&sctx->ds.trace_context)) { + if (sctx->perfetto_enabled) { /* Just use the draw[0] vertex count for perfetto. */ trace_si_end_draw(&sctx->trace, draws[0].count); }