radeonsi: delay aux context initialization to first use

This avoids creating unneeded contexts.

Reviewed-by: David Rosca <david.rosca@amd.com>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41133>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2026-04-15 11:27:18 +02:00
parent 01c7a82760
commit 931fc57f2a
5 changed files with 33 additions and 29 deletions

View file

@ -199,7 +199,7 @@ bool si_alloc_resource(struct si_screen *sscreen, struct si_resource *res)
if (res->b.b.flags & SI_RESOURCE_FLAG_CLEAR) {
struct si_aux_context *auxctx = res->flags & RADEON_FLAG_ENCRYPTED ?
&sscreen->aux_context.general : &sscreen->aux_context.compute_resource_init;
struct si_context *ctx = si_get_aux_context(auxctx);
struct si_context *ctx = si_get_aux_context(sscreen, auxctx);
uint32_t value = 0;
si_clear_buffer(ctx, &res->b.b, 0, res->bo_size, &value, 4, SI_AUTO_SELECT_CLEAR_METHOD,

View file

@ -877,7 +877,10 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen, unsign
/* Check if the aux_context needs to be recreated */
for (unsigned i = 0; i < ARRAY_SIZE(sscreen->aux_contexts); i++) {
struct si_context *saux = si_get_aux_context(&sscreen->aux_contexts[i]);
if (!sscreen->aux_contexts[i].ctx)
continue;
struct si_context *saux = si_get_aux_context(sscreen, &sscreen->aux_contexts[i]);
enum pipe_reset_status status =
sctx->ws->ctx_query_reset_status(saux->ctx, true, NULL, NULL);
@ -1065,7 +1068,7 @@ void si_destroy_screen(struct pipe_screen *pscreen)
if (!sscreen->aux_contexts[i].ctx)
continue;
struct si_context *saux = si_get_aux_context(&sscreen->aux_contexts[i]);
struct si_context *saux = si_get_aux_context(sscreen, &sscreen->aux_contexts[i]);
struct u_log_context *aux_log = saux->log;
if (aux_log) {
saux->b.set_log_context(&saux->b, NULL);
@ -1648,27 +1651,9 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws,
2 * 1024 * 1024);
}
/* Create the auxiliary context. This must be done last. */
for (unsigned i = 0; i < ARRAY_SIZE(sscreen->aux_contexts); i++) {
for (unsigned i = 0; i < ARRAY_SIZE(sscreen->aux_contexts); i++)
(void)mtx_init(&sscreen->aux_contexts[i].lock, mtx_plain | mtx_recursive);
bool compute = !sscreen->info.has_graphics ||
&sscreen->aux_contexts[i] == &sscreen->aux_context.compute_resource_init ||
&sscreen->aux_contexts[i] == &sscreen->aux_context.shader_upload;
sscreen->aux_contexts[i].ctx =
si_create_context(&sscreen->b,
SI_CONTEXT_FLAG_AUX | PIPE_CONTEXT_LOSE_CONTEXT_ON_RESET |
(sscreen->options.aux_debug ? PIPE_CONTEXT_DEBUG : 0) |
(compute ? PIPE_CONTEXT_COMPUTE_ONLY : 0));
if (sscreen->options.aux_debug) {
u_log_context_init(&sscreen->aux_contexts[i].log);
struct pipe_context *ctx = sscreen->aux_contexts[i].ctx;
ctx->set_log_context(ctx, &sscreen->aux_contexts[i].log);
}
}
if (test_flags & DBG(TEST_CLEAR_BUFFER))
si_test_clear_buffer(sscreen);
@ -1741,10 +1726,29 @@ struct pipe_screen *radeonsi_screen_create(int fd, const struct pipe_screen_conf
return rw ? rw->screen : NULL;
}
struct si_context *si_get_aux_context(struct si_aux_context *ctx)
struct si_context *si_get_aux_context(struct si_screen *sscreen, struct si_aux_context *actx)
{
mtx_lock(&ctx->lock);
return (struct si_context*)ctx->ctx;
mtx_lock(&actx->lock);
/* Init aux_context on demand. */
if (actx->ctx == NULL) {
bool compute = !sscreen->info.has_graphics ||
actx == &sscreen->aux_context.compute_resource_init ||
actx == &sscreen->aux_context.shader_upload;
actx->ctx =
si_create_context(&sscreen->b,
SI_CONTEXT_FLAG_AUX | PIPE_CONTEXT_LOSE_CONTEXT_ON_RESET |
(sscreen->options.aux_debug ? PIPE_CONTEXT_DEBUG : 0) |
(compute ? PIPE_CONTEXT_COMPUTE_ONLY : 0));
assert(actx->ctx);
if (sscreen->options.aux_debug) {
u_log_context_init(&actx->log);
struct pipe_context *ctx = actx->ctx;
ctx->set_log_context(ctx, &actx->log);
}
}
return (struct si_context*)actx->ctx;
}
void si_put_aux_context_flush(struct si_aux_context *ctx)

View file

@ -1616,7 +1616,7 @@ MESAPROC void si_init_compute_functions(struct si_context *sctx) TAILV;
/* si_pipe.c */
struct ac_llvm_compiler *si_create_llvm_compiler(struct si_screen *sscreen);
void si_init_aux_async_compute_ctx(struct si_screen *sscreen);
struct si_context *si_get_aux_context(struct si_aux_context *ctx);
struct si_context *si_get_aux_context(struct si_screen *sscreen, struct si_aux_context *ctx);
void si_put_aux_context_flush(struct si_aux_context *ctx);
void si_get_scratch_tmpring_size(struct si_context *sctx, unsigned bytes_per_wave,
bool is_compute, unsigned *spi_tmpring_size);

View file

@ -152,7 +152,7 @@ static void *pre_upload_binary(struct si_screen *sscreen, struct si_shader *shad
if (dma_upload) {
/* First upload into a staging buffer. */
*upload_ctx = si_get_aux_context(&sscreen->aux_context.shader_upload);
*upload_ctx = si_get_aux_context(sscreen, &sscreen->aux_context.shader_upload);
void *ret;
u_upload_alloc_ref((*upload_ctx)->b.stream_uploader, 0, binary_size, 256,

View file

@ -778,7 +778,7 @@ static bool si_texture_get_handle(struct pipe_screen *screen, struct pipe_contex
bool flush = false;
ctx = threaded_context_unwrap_sync(ctx);
sctx = ctx ? (struct si_context *)ctx : si_get_aux_context(&sscreen->aux_context.general);
sctx = ctx ? (struct si_context *)ctx : si_get_aux_context(sscreen, &sscreen->aux_context.general);
if (resource->target != PIPE_BUFFER) {
unsigned plane = whandle->plane;
@ -1334,7 +1334,7 @@ static struct si_texture *si_texture_create_object(struct pipe_screen *screen,
if (num_clears) {
struct si_aux_context *auxctx = tex->buffer.flags & RADEON_FLAG_ENCRYPTED ?
&sscreen->aux_context.general : &sscreen->aux_context.compute_resource_init;
struct si_context *sctx = si_get_aux_context(auxctx);
struct si_context *sctx = si_get_aux_context(sscreen, auxctx);
si_execute_clears(sctx, clears, num_clears, false);
si_put_aux_context_flush(auxctx);