diff --git a/src/gallium/drivers/radeonsi/si_buffer.c b/src/gallium/drivers/radeonsi/si_buffer.c index b591accfd93..2d3597b2765 100644 --- a/src/gallium/drivers/radeonsi/si_buffer.c +++ b/src/gallium/drivers/radeonsi/si_buffer.c @@ -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, diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index d0fed896dfc..d982b7ba2ff 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -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) diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index b3bc8982774..37ec80af0d3 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -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); diff --git a/src/gallium/drivers/radeonsi/si_shader_binary.c b/src/gallium/drivers/radeonsi/si_shader_binary.c index 43f81491602..ed87f360c8d 100644 --- a/src/gallium/drivers/radeonsi/si_shader_binary.c +++ b/src/gallium/drivers/radeonsi/si_shader_binary.c @@ -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, diff --git a/src/gallium/drivers/radeonsi/si_texture.c b/src/gallium/drivers/radeonsi/si_texture.c index 1f1ea4e040a..c1be883a06f 100644 --- a/src/gallium/drivers/radeonsi/si_texture.c +++ b/src/gallium/drivers/radeonsi/si_texture.c @@ -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);