From: Asahi Lina Date: Fri, 3 Mar 2023 09:55:24 +0000 (+0900) Subject: asahi: Support importing sync objects on BO export X-Git-Tag: upstream/23.3.3~11528 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e6b565699fcc22a3f68377b80f03c17f5204c1da;p=platform%2Fupstream%2Fmesa.git asahi: Support importing sync objects on BO export When a BO is exported, implicit sync convention requires that writers signal a fence on the object when complete. We already do this for BOs that are *already* exported, but it is possible for a BO to be written to, then exported for the first time. Add a field to agx_bo to keep track of the current writer syncobj handle. On first export, we use this to import it into the DMA-BUF. Signed-off-by: Asahi Lina Part-of: --- diff --git a/src/asahi/lib/agx_bo.h b/src/asahi/lib/agx_bo.h index e749e4d..f39a2aa 100644 --- a/src/asahi/lib/agx_bo.h +++ b/src/asahi/lib/agx_bo.h @@ -98,6 +98,9 @@ struct agx_bo { /* DMA-BUF fd clone for adding fences to imports/exports */ int prime_fd; + /* Syncobj handle of the current writer, if any */ + int writer_syncobj; + /* Globally unique value (system wide) for tracing. Exists for resources, * command buffers, GPU submissions, segments, segmentent lists, encoders, * accelerators, and channels. Corresponds to Instruments' magic table diff --git a/src/asahi/lib/agx_device.c b/src/asahi/lib/agx_device.c index bd3e343..c5f9536 100644 --- a/src/asahi/lib/agx_device.c +++ b/src/asahi/lib/agx_device.c @@ -239,11 +239,28 @@ agx_bo_export(struct agx_bo *bo) if (drmPrimeHandleToFD(bo->dev->fd, bo->handle, DRM_CLOEXEC, &fd)) return -1; - bo->flags |= AGX_BO_SHARED; - if (bo->prime_fd == -1) + if (!(bo->flags & AGX_BO_SHARED)) { + bo->flags |= AGX_BO_SHARED; + assert(bo->prime_fd == -1); bo->prime_fd = dup(fd); - assert(bo->prime_fd >= 0); + /* If there is a pending writer to this BO, import it into the buffer + * for implicit sync. + */ + if (bo->writer_syncobj) { + int out_sync_fd = -1; + int ret = drmSyncobjExportSyncFile(bo->dev->fd, bo->writer_syncobj, + &out_sync_fd); + assert(ret >= 0); + assert(out_sync_fd >= 0); + + ret = agx_import_sync_file(bo->dev, bo, out_sync_fd); + assert(ret >= 0); + close(out_sync_fd); + } + } + + assert(bo->prime_fd >= 0); return fd; }