From 16e0702ec7103c06f2f33654b6e41498e2eabf8e Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Mon, 24 Oct 2022 18:40:50 +0200 Subject: [PATCH] etnaviv: properly reference flush_resources The flush_resources recorded in the context need to stay alive until the context is flushed, at which point additional resolve operations are done to those resources. While the backing BO is alive due to being referenced in the cmdstream, the resource might already be destroyed at this point. Keep a reference to the resource to make sure it is still available at context flush time. Fixes: 7b9d8d1936d7 ("etnaviv: flush used render buffers on context flush when neccessary") Signed-off-by: Lucas Stach Reviewed-by: Philipp Zabel Part-of: --- src/gallium/drivers/etnaviv/etnaviv_context.c | 1 + src/gallium/drivers/etnaviv/etnaviv_state.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c b/src/gallium/drivers/etnaviv/etnaviv_context.c index da1af2e6b4a..cabb0c75fe0 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_context.c +++ b/src/gallium/drivers/etnaviv/etnaviv_context.c @@ -518,6 +518,7 @@ etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence, struct pipe_resource *prsc = (struct pipe_resource *)entry->key; pctx->flush_resource(pctx, prsc); + pipe_resource_reference(&prsc, NULL); } _mesa_set_clear(ctx->flush_resources, NULL); diff --git a/src/gallium/drivers/etnaviv/etnaviv_state.c b/src/gallium/drivers/etnaviv/etnaviv_state.c index 6cc7d92cdde..6bc836459eb 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_state.c +++ b/src/gallium/drivers/etnaviv/etnaviv_state.c @@ -793,8 +793,14 @@ etna_record_flush_resources(struct etna_context *ctx) if (fb->nr_cbufs > 0) { struct etna_surface *surf = etna_surface(fb->cbufs[0]); - if (!etna_resource(surf->prsc)->explicit_flush) - _mesa_set_add(ctx->flush_resources, surf->prsc); + if (!etna_resource(surf->prsc)->explicit_flush) { + bool found; + + _mesa_set_search_or_add(ctx->flush_resources, surf->prsc, &found); + + if (!found) + pipe_reference(NULL, &surf->prsc->reference); + } } return true;