From e6f9444567ba9e7b9505bc6142d5b5b4ae874485 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 11 Mar 2023 16:19:43 -0500 Subject: [PATCH] asahi: Fix occlusion query lifetime Theoretical lifetime issue, now easy to hit with the batch sync changes. Fixes memory badness. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/asahi/agx_query.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/asahi/agx_query.c b/src/gallium/drivers/asahi/agx_query.c index 44df4d1..a0ff593 100644 --- a/src/gallium/drivers/asahi/agx_query.c +++ b/src/gallium/drivers/asahi/agx_query.c @@ -17,8 +17,19 @@ agx_create_query(struct pipe_context *ctx, unsigned query_type, unsigned index) } static void -agx_destroy_query(struct pipe_context *ctx, struct pipe_query *query) +agx_destroy_query(struct pipe_context *ctx, struct pipe_query *pquery) { + struct agx_query *query = (struct agx_query *)pquery; + + /* It is legal for the query to be destroyed before its value is read, + * particularly during application teardown. In this case, don't leave a + * dangling reference to the query. + */ + if (query->writer) { + *util_dynarray_element(&query->writer->occlusion_queries, + struct agx_query *, query->writer_index) = NULL; + } + free(query); } @@ -154,6 +165,11 @@ agx_finish_batch_occlusion_queries(struct agx_batch *batch) util_dynarray_foreach(&batch->occlusion_queries, struct agx_query *, it) { struct agx_query *query = *it; + + /* Skip queries that have since been destroyed */ + if (query == NULL) + continue; + assert(query->writer == batch); /* Get the result for this batch. If results is NULL, it means that no -- 2.7.4