Module: Mesa
Branch: main
Commit: ba551d293fcc915071727b847bec21721899c77a
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ba551d293fcc915071727b847bec21721899c77a

Author: Alyssa Rosenzweig <[email protected]>
Date:   Thu Oct 20 22:42:39 2022 -0400

asahi: Hold a reference to BOs in a batch

Fixes GPU-side use after frees, e.g. in 
dEQP-GLES2.functional.texture.vertex.2d.wrap.clamp_mirror

Signed-off-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19215>

---

 src/gallium/drivers/asahi/agx_pipe.c  | 4 ++++
 src/gallium/drivers/asahi/agx_state.h | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/src/gallium/drivers/asahi/agx_pipe.c 
b/src/gallium/drivers/asahi/agx_pipe.c
index 541c764041e..9d2ed609617 100644
--- a/src/gallium/drivers/asahi/agx_pipe.c
+++ b/src/gallium/drivers/asahi/agx_pipe.c
@@ -567,6 +567,10 @@ agx_flush(struct pipe_context *pctx,
       agxdecode_next_frame();
    }
 
+   AGX_BATCH_FOREACH_BO_HANDLE(batch, handle) {
+      agx_bo_unreference(agx_lookup_bo(dev, handle));
+   }
+
    memset(batch->bo_list.set, 0, batch->bo_list.word_count * 
sizeof(BITSET_WORD));
    agx_pool_cleanup(&ctx->batch->pool);
    agx_pool_cleanup(&ctx->batch->pipeline_pool);
diff --git a/src/gallium/drivers/asahi/agx_state.h 
b/src/gallium/drivers/asahi/agx_state.h
index 81499553172..f87ea367712 100644
--- a/src/gallium/drivers/asahi/agx_state.h
+++ b/src/gallium/drivers/asahi/agx_state.h
@@ -369,6 +369,12 @@ agx_batch_add_bo(struct agx_batch *batch, struct agx_bo 
*bo)
       batch->bo_list.word_count *= 2;
    }
 
+   /* The batch holds a single reference to each BO in the batch, released when
+    * the batch finishes execution.
+    */
+   if (!BITSET_TEST(batch->bo_list.set, bo->handle))
+      agx_bo_reference(bo);
+
    BITSET_SET(batch->bo_list.set, bo->handle);
 }
 

Reply via email to