Create/Destroy/Trigger/Reset/Query Fence Sync objs

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

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@nvidia.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
James Jones 2010-06-25 17:59:14 -07:00
parent 53ea965d64
commit 397dfd9f87
4 changed files with 273 additions and 5 deletions

View File

@ -15,7 +15,7 @@ INCLUDES = -I$(top_srcdir)/hw/xfree86/dixmods/extmod
AM_CFLAGS = $(DIX_CFLAGS)
if XORG
sdk_HEADERS = xvdix.h xvmcext.h geext.h geint.h shmint.h
sdk_HEADERS = xvdix.h xvmcext.h geext.h geint.h shmint.h syncsdk.h
endif
# Sources always included in libXextbuiltin.la & libXext.la
@ -26,6 +26,7 @@ BUILTIN_SRCS = \
sleepuntil.c \
sleepuntil.h \
sync.c \
syncsdk.h \
syncsrv.h \
xcmisc.c \
xtest.c

View File

@ -63,10 +63,12 @@ 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>
#include "syncsrv.h"
#include "syncsdk.h"
#include "protocol-versions.h"
#include <stdio.h>
@ -85,6 +87,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;
@ -850,23 +853,34 @@ SyncCreate(ClientPtr client, XID id, unsigned char type)
{
SyncObject *pSync;
RESTYPE resType;
unsigned long syncSize;
switch (type) {
case SYNC_COUNTER:
resType = RTCounter;
syncSize = sizeof(SyncCounter);
pSync = malloc(sizeof(SyncCounter));
break;
case SYNC_FENCE:
resType = RTFence;
pSync = dixAllocateObjectWithPrivates(SyncFence,
PRIVATE_SYNC_FENCE);
break;
default:
return NULL;
}
if (!(pSync = (SyncObject *)malloc(syncSize)))
if (!pSync)
return NULL;
if (!AddResource(id, resType, (pointer) pSync))
{
free(pSync);
switch (type) {
case SYNC_FENCE:
dixFreeObjectWithPrivates((SyncFence *)pSync, PRIVATE_SYNC_FENCE);
break;
default:
free(pSync);
}
return NULL;
}
@ -1866,6 +1880,145 @@ 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 = (SyncFence *)SyncCreate(client,
stuff->fid,
SYNC_FENCE)))
return BadAlloc;
miSyncInitFence(pDraw->pScreen, pFence, stuff->initially_triggered);
return client->noClientException;
}
static int
FreeFence(void *obj, XID id)
{
SyncFence *pFence = (SyncFence *) obj;
miSyncDestroyFence(pFence);
return Success;
}
int SyncVerifyFence(SyncFence **ppSyncFence, XID fid,
ClientPtr client, Mask mode)
{
int rc = dixLookupResourceByType((pointer *)ppSyncFence, fid, RTFence,
client, mode);
if (rc != Success)
client->errorValue = fid;
return rc;
}
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;
miSyncTriggerFence(pFence);
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->funcs.CheckTriggered(pFence) != TRUE)
return BadMatch;
pFence->funcs.Reset(pFence);
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;
}
static int
ProcSyncQueryFence(ClientPtr client)
{
REQUEST(xSyncQueryFenceReq);
xSyncQueryFenceReply rep;
SyncFence *pFence;
int rc;
REQUEST_SIZE_MATCH(xSyncQueryFenceReq);
rc = dixLookupResourceByType((pointer *)&pFence, stuff->fid,
RTFence, client, DixReadAccess);
if (rc != Success)
return rc;
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.triggered = pFence->funcs.CheckTriggered(pFence);
if (client->swapped)
{
char n;
swaps(&rep.sequenceNumber, n);
swapl(&rep.length, n);
}
WriteToClient(client, sizeof(xSyncQueryFenceReply), (char *) &rep);
return client->noClientException;
}
/*
* ** Given an extension request, call the appropriate request procedure
*/
@ -2103,6 +2256,70 @@ 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
SProcSyncQueryFence(ClientPtr client)
{
REQUEST(xSyncQueryFenceReq);
char n;
swaps(&stuff->length, n);
REQUEST_SIZE_MATCH (xSyncQueryFenceReq);
swapl(&stuff->fid, n);
return ProcSyncQueryFence(client);
}
static int
SProcSyncDispatch(ClientPtr client)
@ -2210,6 +2427,7 @@ SyncExtensionInit(void)
}
RTAlarm = CreateNewResourceType(FreeAlarm, "SyncAlarm");
RTAwait = CreateNewResourceType(FreeAwait, "SyncAwait");
RTFence = CreateNewResourceType(FreeFence, "SyncFence");
if (RTAwait)
RTAwait |= RC_NEVERRETAIN;
RTAlarmClient = CreateNewResourceType(FreeAlarmClient, "SyncAlarmClient");
@ -2236,6 +2454,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

47
Xext/syncsdk.h Normal file
View File

@ -0,0 +1,47 @@
/*
* Copyright © 2010 NVIDIA Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef _SYNCSDK_H_
#define _SYNCSDK_H_
#include "misync.h"
extern _X_EXPORT int
SyncVerifyFence(SyncFence **ppFence, XID fid, ClientPtr client, Mask mode);
#define VERIFY_SYNC_FENCE(pFence, fid, client, mode) \
do { \
int rc; \
rc = SyncVerifyFence(&(pFence), (fid), (client), (mode)); \
if (Success != rc) return rc; \
} while (0)
#define VERIFY_SYNC_FENCE_OR_NONE(pFence, fid, client, mode) \
do { \
pFence = 0; \
if (None != fid) \
VERIFY_SYNC_FENCE((pFence), (fid), (client), (mode)); \
} while (0)
#endif /* _SYNCSDK_H_ */

View File

@ -53,6 +53,7 @@ cat > sdksyms.c << EOF
#include "geext.h"
#include "geint.h"
#include "shmint.h"
#include "syncsdk.h"
#if XINERAMA
# include "panoramiXsrv.h"
# include "panoramiX.h"