[PATCH xserver 1/9] Create/Destroy/Trigger/Reset Fence Sync objects

James Jones jajones at nvidia.com
Tue Sep 21 16:32:11 PDT 2010


Initial server side implementation of fence sync
objects.  Allows creation and management of
binary state objects.  Currently they are not
useful as there is no way to wait for them or
query their state.

The basic trigger operation added here triggers
relative to a given X screen's rendering operations.
To perform this operation, fence sync objects must
be tied to a screen.  As Aaron Plattner pointed out,
screens are identified but a drawable in X protocol,
so a drawable argument is included in
XSyncCreateFence().  The screen also could have been
specified as part of the trigger operation.  However,
it is also desireable to associate a screen with
fence sync objects at creation time so that the
associated screen's driver can allocate any HW-
specific resources needed by the fence object up
front.

Signed-off-by: James Jones <jajones at nvidia.com>
Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
Reviewed-by: Robert Morell <rmorell at nvidia.com>
---
 Xext/sync.c    |  181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 Xext/syncsrv.h |    6 ++
 2 files changed, 187 insertions(+), 0 deletions(-)

diff --git a/Xext/sync.c b/Xext/sync.c
index a51262a..18d2477 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -63,6 +63,7 @@ PERFORMANCE OF THIS SOFTWARE.
 #include "os.h"
 #include "extnsionst.h"
 #include "dixstruct.h"
+#include "pixmapstr.h"
 #include "resource.h"
 #include "opaque.h"
 #include <X11/extensions/syncproto.h>
@@ -84,6 +85,7 @@ static RESTYPE  RTCounter = 0;
 static RESTYPE  RTAwait;
 static RESTYPE  RTAlarm;
 static RESTYPE  RTAlarmClient;
+static RESTYPE  RTFence;
 static int SyncNumSystemCounters = 0;
 static SyncCounter **SysCounterList = NULL;
 
@@ -115,6 +117,10 @@ static DISPATCH_PROC(ProcSyncQueryAlarm);
 static DISPATCH_PROC(ProcSyncQueryCounter);
 static DISPATCH_PROC(ProcSyncSetCounter);
 static DISPATCH_PROC(ProcSyncSetPriority);
+static DISPATCH_PROC(ProcSyncCreateFence);
+static DISPATCH_PROC(ProcSyncTriggerFence);
+static DISPATCH_PROC(ProcSyncResetFence);
+static DISPATCH_PROC(ProcSyncDestroyFence);
 static DISPATCH_PROC(SProcSyncAwait);
 static DISPATCH_PROC(SProcSyncChangeAlarm);
 static DISPATCH_PROC(SProcSyncChangeCounter);
@@ -130,6 +136,10 @@ static DISPATCH_PROC(SProcSyncQueryAlarm);
 static DISPATCH_PROC(SProcSyncQueryCounter);
 static DISPATCH_PROC(SProcSyncSetCounter);
 static DISPATCH_PROC(SProcSyncSetPriority);
+static DISPATCH_PROC(SProcSyncCreateFence);
+static DISPATCH_PROC(SProcSyncTriggerFence);
+static DISPATCH_PROC(SProcSyncResetFence);
+static DISPATCH_PROC(SProcSyncDestroyFence);
 
 /*  Each counter maintains a simple linked list of triggers that are
  *  interested in the counter.  The two functions below are used to
@@ -1762,6 +1772,108 @@ ProcSyncDestroyAlarm(ClientPtr client)
     return Success;
 }
 
+static int
+ProcSyncCreateFence(ClientPtr client)
+{
+    REQUEST(xSyncCreateFenceReq);
+    DrawablePtr pDraw;
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncCreateFenceReq);
+
+    rc = dixLookupDrawable(&pDraw, stuff->d, client, M_ANY, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
+    LEGAL_NEW_RESOURCE(stuff->fid, client);
+
+    if (!(pFence = malloc(sizeof(SyncFence))))
+	return BadAlloc;
+
+    if (!AddResource(stuff->fid, RTFence, (pointer) pFence))
+    {
+	free(pFence);
+	return BadAlloc;
+    }
+
+    pFence->pScreen = pDraw->pScreen;
+    pFence->client = client;
+    pFence->id = stuff->fid;
+    pFence->triggered = stuff->initially_triggered;
+
+    return client->noClientException;
+}
+
+static int
+FreeFence(void *obj, XID id)
+{
+    SyncFence *pFence = (SyncFence *) obj;
+
+    free(pFence);
+
+    return Success;
+}
+
+static int
+ProcSyncTriggerFence(ClientPtr client)
+{
+    REQUEST(xSyncTriggerFenceReq);
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncTriggerFenceReq);
+
+    rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence,
+				 client, DixWriteAccess);
+    if (rc != Success)
+	return rc;
+
+    pFence->triggered = TRUE;
+
+    return client->noClientException;
+}
+
+static int
+ProcSyncResetFence(ClientPtr client)
+{
+    REQUEST(xSyncResetFenceReq);
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncResetFenceReq);
+
+    rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence,
+				 client, DixWriteAccess);
+    if (rc != Success)
+	return rc;
+
+    if (pFence->triggered != TRUE)
+	return BadMatch;
+
+    pFence->triggered = FALSE;
+
+    return client->noClientException;
+}
+
+static int
+ProcSyncDestroyFence(ClientPtr client)
+{
+    REQUEST(xSyncDestroyFenceReq);
+    SyncFence *pFence;
+    int rc;
+
+    REQUEST_SIZE_MATCH(xSyncDestroyFenceReq);
+
+    rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid, RTFence,
+				 client, DixDestroyAccess);
+    if (rc != Success)
+	return rc;
+
+    FreeResource(stuff->fid, RT_NONE);
+    return client->noClientException;
+}
+
 /*
  * ** Given an extension request, call the appropriate request procedure
  */
@@ -1800,6 +1912,14 @@ ProcSyncDispatch(ClientPtr client)
 	return ProcSyncSetPriority(client);
       case X_SyncGetPriority:
 	return ProcSyncGetPriority(client);
+      case X_SyncCreateFence:
+	return ProcSyncCreateFence(client);
+      case X_SyncTriggerFence:
+	return ProcSyncTriggerFence(client);
+      case X_SyncResetFence:
+	return ProcSyncResetFence(client);
+      case X_SyncDestroyFence:
+	return ProcSyncDestroyFence(client);
       default:
 	return BadRequest;
     }
@@ -1999,6 +2119,57 @@ SProcSyncGetPriority(ClientPtr client)
     return ProcSyncGetPriority(client);
 }
 
+static int
+SProcSyncCreateFence(ClientPtr client)
+{
+    REQUEST(xSyncCreateFenceReq);
+    char n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncCreateFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncCreateFence(client);
+}
+
+static int
+SProcSyncTriggerFence(ClientPtr client)
+{
+    REQUEST(xSyncTriggerFenceReq);
+    char n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncTriggerFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncTriggerFence(client);
+}
+
+static int
+SProcSyncResetFence(ClientPtr client)
+{
+    REQUEST(xSyncResetFenceReq);
+    char n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncResetFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncResetFence(client);
+}
+
+static int
+SProcSyncDestroyFence(ClientPtr client)
+{
+    REQUEST(xSyncDestroyFenceReq);
+    char n;
+
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH (xSyncDestroyFenceReq);
+    swapl(&stuff->fid, n);
+
+    return ProcSyncDestroyFence(client);
+}
 
 static int
 SProcSyncDispatch(ClientPtr client)
@@ -2035,6 +2206,14 @@ SProcSyncDispatch(ClientPtr client)
 	return SProcSyncSetPriority(client);
       case X_SyncGetPriority:
 	return SProcSyncGetPriority(client);
+      case X_SyncCreateFence:
+	return SProcSyncCreateFence(client);
+      case X_SyncTriggerFence:
+	return SProcSyncTriggerFence(client);
+      case X_SyncResetFence:
+	return SProcSyncResetFence(client);
+      case X_SyncDestroyFence:
+	return SProcSyncDestroyFence(client);
       default:
 	return BadRequest;
     }
@@ -2103,6 +2282,7 @@ SyncExtensionInit(void)
     }
     RTAlarm = CreateNewResourceType(FreeAlarm, "SyncAlarm");
     RTAwait = CreateNewResourceType(FreeAwait, "SyncAwait");
+    RTFence = CreateNewResourceType(FreeFence, "SyncFence");
     if (RTAwait)
 	RTAwait |= RC_NEVERRETAIN;
     RTAlarmClient = CreateNewResourceType(FreeAlarmClient, "SyncAlarmClient");
@@ -2129,6 +2309,7 @@ SyncExtensionInit(void)
 
     SetResourceTypeErrorValue(RTCounter, SyncErrorBase + XSyncBadCounter);
     SetResourceTypeErrorValue(RTAlarm, SyncErrorBase + XSyncBadAlarm);
+    SetResourceTypeErrorValue(RTFence, SyncErrorBase + XSyncBadFence);
 
     /*
      * Although SERVERTIME is implemented by the OS layer, we initialise it
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index 6d0e3d6..a805f28 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -148,6 +148,12 @@ typedef union {
     SyncAwait	    await;
 } SyncAwaitUnion;
 
+typedef struct _SyncFence {
+    ClientPtr		client;		/* Owning client. */
+    XSyncFence		id;		/* resource ID */
+    ScreenPtr           pScreen;	/* Screen of this fence object */
+    Bool		triggered;	/* fence state */
+} SyncFence;
 
 extern pointer SyncCreateSystemCounter(
     char *	/* name */,
-- 
1.7.1



More information about the xorg-devel mailing list