asahi: Do not leak staging resources for PIPE_MAP_READ
authorAsahi Lina <lina@asahilina.net>
Wed, 7 Dec 2022 09:33:46 +0000 (18:33 +0900)
committerMarge Bot <emma+marge@anholt.net>
Sat, 17 Dec 2022 18:10:28 +0000 (18:10 +0000)
We were only dereferencing the resource in the PIPE_MAP_WRITE path of
agx_transfer_unmap, which means that read-only transfers leaked the
staging resource/BO. Always free the staging resource unconditionally.

Signed-off-by: Asahi Lina <lina@asahilina.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20365>

src/gallium/drivers/asahi/agx_pipe.c

index d039e77..a567d43 100644 (file)
@@ -845,7 +845,6 @@ agx_transfer_unmap(struct pipe_context *pctx,
          agx_blit_from_staging(pctx, trans);
          agx_flush_readers(agx_context(pctx), agx_resource(trans->staging.rsrc),
                            "GPU write staging blit");
-         pipe_resource_reference(&trans->staging.rsrc, NULL);
    } else if (trans->map && (transfer->usage & PIPE_MAP_WRITE)) {
       assert(rsrc->modifier == DRM_FORMAT_MOD_APPLE_TWIDDLED);
 
@@ -869,6 +868,7 @@ agx_transfer_unmap(struct pipe_context *pctx,
 
    /* Free the transfer */
    free(trans->map);
+   pipe_resource_reference(&trans->staging.rsrc, NULL);
    pipe_resource_reference(&transfer->resource, NULL);
    FREE(transfer);
 }