[RFC v2 05/12] dri3: Add DMA fences requests

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Wed Sep 27 05:19:56 UTC 2017


Bump DRI3 version to v1.2 that adds requests:

    * FenceFromDMAFenceFD is used to create a sync fence
      from a sync file fence.
    * DMAFenceFDFromFence is used to retrieve the sync
      file fd from a fence.

Drivers need to check the SyncFence type to make use of it
when possible.

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
---
 dri3/dri3_request.c         | 94 +++++++++++++++++++++++++++++++++++++++++++++
 include/protocol-versions.h |  2 +-
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/dri3/dri3_request.c b/dri3/dri3_request.c
index e5bb626f3..cfbc343a4 100644
--- a/dri3/dri3_request.c
+++ b/dri3/dri3_request.c
@@ -526,6 +526,72 @@ proc_dri3_buffers_from_pixmap(ClientPtr client)
     return Success;
 }
 
+static int
+proc_dri3_fence_from_dma_fence_fd(ClientPtr client)
+{
+    REQUEST(xDRI3FenceFromDMAFenceFDReq);
+    DrawablePtr drawable;
+    int fd;
+    int status;
+
+    SetReqFds(client, 1);
+    REQUEST_SIZE_MATCH(xDRI3FenceFromDMAFenceFDReq);
+    LEGAL_NEW_RESOURCE(stuff->fence, client);
+
+    status = dixLookupDrawable(&drawable, stuff->drawable, client, M_ANY, DixGetAttrAccess);
+    if (status != Success)
+        return status;
+
+    fd = ReadFdFromClient(client);
+    if (fd < 0)
+        return BadValue;
+
+    status = SyncCreateFenceFromDMAFenceFD(client, drawable, stuff->fence, fd);
+    close(fd);
+
+    return status;
+}
+
+static int
+proc_dri3_dma_fence_fd_from_fence(ClientPtr client)
+{
+    REQUEST(xDRI3DMAFenceFDFromFenceReq);
+    xDRI3DMAFenceFDFromFenceReply rep = {
+        .type = X_Reply,
+        .nfd = 1,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+    };
+    DrawablePtr drawable;
+    int fd;
+    int status;
+    SyncFence *fence;
+
+    REQUEST_SIZE_MATCH(xDRI3DMAFenceFDFromFenceReq);
+
+    status = dixLookupDrawable(&drawable, stuff->drawable, client, M_ANY, DixGetAttrAccess);
+    if (status != Success)
+        return status;
+    status = SyncVerifyFence(&fence, stuff->fence, client, DixWriteAccess);
+    if (status != Success)
+        return status;
+
+    fd = SyncDMAFenceFDFromFence(client, drawable, fence);
+    if (fd < 0)
+        return BadMatch;
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+    }
+    if (WriteFdToClient(client, fd, FALSE) < 0)
+        return BadAlloc;
+
+    WriteToClient(client, sizeof(rep), &rep);
+
+    return Success;
+}
+
 int (*proc_dri3_vector[DRI3NumberRequests]) (ClientPtr) = {
     proc_dri3_query_version,            /* 0 */
     proc_dri3_open,                     /* 1 */
@@ -536,6 +602,8 @@ int (*proc_dri3_vector[DRI3NumberRequests]) (ClientPtr) = {
     proc_dri3_get_supported_modifiers,  /* 6 */
     proc_dri3_pixmap_from_buffers,      /* 7 */
     proc_dri3_buffers_from_pixmap,      /* 8 */
+    proc_dri3_fence_from_dma_fence_fd,  /* 9 */
+    proc_dri3_dma_fence_fd_from_fence,  /* 10 */
 };
 
 int
@@ -669,6 +737,30 @@ sproc_dri3_buffers_from_pixmap(ClientPtr client)
     return (*proc_dri3_vector[stuff->dri3ReqType]) (client);
 }
 
+static int _X_COLD
+sproc_dri3_dma_fence_fd_from_fence(ClientPtr client)
+{
+    REQUEST(xDRI3DMAFenceFDFromFenceReq);
+    REQUEST_SIZE_MATCH(xDRI3DMAFenceFDFromFenceReq);
+
+    swaps(&stuff->length);
+    swapl(&stuff->drawable);
+    swapl(&stuff->fence);
+    return (*proc_dri3_vector[stuff->dri3ReqType]) (client);
+}
+
+static int _X_COLD
+sproc_dri3_fence_from_dma_fence_fd(ClientPtr client)
+{
+    REQUEST(xDRI3FenceFromDMAFenceFDReq);
+    REQUEST_SIZE_MATCH(xDRI3FenceFromDMAFenceFDReq);
+
+    swaps(&stuff->length);
+    swapl(&stuff->drawable);
+    swapl(&stuff->fence);
+    return (*proc_dri3_vector[stuff->dri3ReqType]) (client);
+}
+
 int (*sproc_dri3_vector[DRI3NumberRequests]) (ClientPtr) = {
     sproc_dri3_query_version,           /* 0 */
     sproc_dri3_open,                    /* 1 */
@@ -679,6 +771,8 @@ int (*sproc_dri3_vector[DRI3NumberRequests]) (ClientPtr) = {
     sproc_dri3_get_supported_modifiers, /* 6 */
     sproc_dri3_pixmap_from_buffers,     /* 7 */
     sproc_dri3_buffers_from_pixmap,     /* 8 */
+    sproc_dri3_fence_from_dma_fence_fd, /* 9 */
+    sproc_dri3_dma_fence_fd_from_fence, /* 10 */
 };
 
 int _X_COLD
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 27cb10c74..ecaebfd74 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -48,7 +48,7 @@
 
 /* DRI3 */
 #define SERVER_DRI3_MAJOR_VERSION               1
-#define SERVER_DRI3_MINOR_VERSION               1
+#define SERVER_DRI3_MINOR_VERSION               2
 
 /* DMX */
 #define SERVER_DMX_MAJOR_VERSION		2
-- 
2.13.0



More information about the xorg-devel mailing list