Skip to contentSkip to conversation

swap complete event handling fixes

RFC New Jesse Barnes 2 participants 9 messages May 3, 2011 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Ended up moving over to generic events since the GLX type code is part of the GLX namespace and larger than 8 bits.

Apparently no one had ever tried ChangeDrawableAttributes with indirect clients, because simply going a glXSelectEvent causes a crash in that case. So this patch set includes a fix for that issue and has been tested with both direct and indirect clients, both with and without client and server support.

New clients with old servers should get a 0 sbc rather than garbage. New servers will send old clients a 0 sbc, but the clients will still copy garbage into the event actually sent to clients. New servers with new clients should work both in the direct and indirect cases and get whatever values the server sends for each field.

As always, testing and review appreciated. Piglit's glx-swap-event case now checks for swap count sanity (i.e. increasing, nonzero value) and allows you to dump the current values in verbose mode. I also added a few more return value checks to the test.

Thanks,
Jesse

A message that is not in the archive (sent off-list or not yet received): 1304445561-9910-1-git-send-email-jbarnes-Y1mF5jBUw70BENJcbMCuUQ@public.gmane.org

#2 lore raw

PATCH 1/1 DRI2: fix swap complete event size by using a generic event

The existing swap complete event is too large to fit in an XEvent, so use a generic event instead. New servers and clients can use this structure to fully pass the swap count along with the media stamp counter, swap complete type, and timestamp.

---
 configure.ac |    2 +-
 dri2proto.h  |   22 ++++++++++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)
configure.ac +1 -1
index 5b78d6b..9505f56 100644
@@ -1,5 +1,5 @@
 AC_PREREQ([2.60])
-AC_INIT([DRI2Proto], [2.3], [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg])
+AC_INIT([DRI2Proto], [2.4], [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
 
dri2proto.h +20 -2
index 9708a4a..5a7d3e1 100644
@@ -35,7 +35,7 @@
 
 #define DRI2_NAME			"DRI2"
 #define DRI2_MAJOR			1
-#define DRI2_MINOR			3
+#define DRI2_MINOR			4
 
 #define DRI2NumberErrors		0
 #define DRI2NumberEvents		2
@@ -298,7 +298,25 @@ typedef struct {
     CARD32 sbc_hi B32;
     CARD32 sbc_lo B32;
 } xDRI2BufferSwapComplete;
-#define sz_xDRI2BufferSwapComplete 32
+#define sz_xDRI2BufferSwapComplete 32 /* This should have been 36 */
+
+/* Use a generic event so we can transmit the sbc_lo value as well */
+typedef struct {
+    BYTE type;
+    CARD8 extension;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32; /* should always be 8 for this event */
+    CARD16 evtype B16;
+    CARD16 swap_event_type B16;
+    CARD32 drawable B32;
+    CARD32 ust_hi B32;
+    CARD32 ust_lo B32;
+    CARD32 msc_hi B32;
+    CARD32 msc_lo B32;
+    CARD32 sbc_hi B32;
+    CARD32 sbc_lo B32;
+} xDRI2BufferSwapComplete2;
+#define sz_xDRI2BufferSwapComplete2 38
 
 typedef struct {
     CARD8 type;
Signature · 6 lines
1.7.4.1

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel
#3 lore raw

PATCH 1/1 GLX: fix broken swap event size by using a generic event

In reply to a message not in the archive

The existing event is too large for an XEvent meaning that the swap count is never sent to clients. Create a generic event instead for use by new clients & servers.

---
 configure.ac |    2 +-
 glxproto.h   |   18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletions(-)
configure.ac +1 -1
index d88e6df..a3047e4 100644
@@ -1,5 +1,5 @@
 AC_PREREQ([2.60])
-AC_INIT([GLProto], [1.4.12], [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg])
+AC_INIT([GLProto], [1.4.13], [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
 
glxproto.h +18 -0
index 0ff44e3..d026d4d 100644
@@ -1384,6 +1384,24 @@ typedef struct {
     CARD32 sbc_lo B32;
 } xGLXBufferSwapComplete;
 
+/* The above is actually too large to fit in an XEvent, so use a generic
+ * event so we can send the sbc count as well. */
+typedef struct {
+    BYTE type;
+    CARD8 extension;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32; /* should always be 8 for this event */
+    CARD16 evtype B16;
+    CARD16 swap_event_type B16;
+    CARD32 drawable B32;
+    CARD32 ust_hi B32;
+    CARD32 ust_lo B32;
+    CARD32 msc_hi B32;
+    CARD32 msc_lo B32;
+    CARD32 sbc_hi B32;
+    CARD32 sbc_lo B32;
+} xGLXBufferSwapComplete2;
+
 /************************************************************************/
 
 /*
Signature · 6 lines
1.7.4.1

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel
#4 lore raw

PATCH 3/5 GLX: don't crash when indirect clients try to set an event mask

In reply to a message not in the archive

After sending the GLXChangeDrawableAttributes request, we also set a local set of attributes on the DRI drawable. But in the indirect case this array won't be present, so skip the setting in that case to avoid a crash.

---
 src/glx/glx_pbuffer.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
src/glx/glx_pbuffer.c +3 -0
index 5f91bc6..ec54f1e 100644
@@ -137,6 +137,9 @@ ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
 #ifdef GLX_DIRECT_RENDERING
    pdraw = GetGLXDRIDrawable(dpy, drawable);
 
+   if (!pdraw)
+      return;
+
    for (i = 0; i < num_attribs; i++) {
       switch(attribs[i * 2]) {
       case GLX_EVENT_MASK:
Signature · 6 lines
1.7.4.1

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel
#5 lore raw

PATCH 4/5 DRI2: support generic swap event handling

In reply to a message not in the archive

The existing swap event structure is too large to fit in an XEvent, so new servers will send a generic event if the client supports it. This allows a valid swap count value to be sent along with the event type, timestamp, and media stamp. Check for server support based on the advertised DRI2 version and look for generic events in the event stream with DRI2 in the extension field.

---
 configure.ac        |    2 +-
 src/glx/dri2.c      |  105 ++++++++++++++++++++++++++++++++++++--------------
 src/glx/dri2.h      |    3 +-
 src/glx/dri2_glx.c  |   31 +++++++++++++-
 src/glx/glxclient.h |    2 +
 5 files changed, 108 insertions(+), 35 deletions(-)
configure.ac +1 -1
index 3b05ca3..92d11af 100644
@@ -21,7 +21,7 @@ dnl Versions for external dependencies
 LIBDRM_REQUIRED=2.4.24
 LIBDRM_RADEON_REQUIRED=2.4.24
 LIBDRM_INTEL_REQUIRED=2.4.24
-DRI2PROTO_REQUIRED=2.1
+DRI2PROTO_REQUIRED=2.4
 GLPROTO_REQUIRED=1.4.11
 LIBDRM_XORG_REQUIRED=2.4.24
 LIBKMS_XORG_REQUIRED=1.0.0
src/glx/dri2.c +75 -30

142 lines not on this page · raw message

src/glx/dri2.h +2 -1
index 114e9f8..b3a9918 100644
@@ -46,7 +46,8 @@ typedef struct
 } DRI2Buffer;
 
 extern Bool
-DRI2QueryExtension(Display * display, int *eventBase, int *errorBase);
+DRI2QueryExtension(Display * display, int *extBase, int *eventBase,
+		   int *errorBase);
 
 extern Bool
 DRI2QueryVersion(Display * display, int *major, int *minor);
src/glx/dri2_glx.c +28 -3
index fc0237a..19be513 100644
@@ -55,12 +55,14 @@
 #define DRI_CONF_VBLANK_ALWAYS_SYNC 3
 
 #undef DRI2_MINOR
-#define DRI2_MINOR 1
+#define DRI2_MINOR 4
 
 struct dri2_display
 {
    __GLXDRIdisplay base;
 
+   int majorOpcode;
+
    /*
     ** XFree86-DRI version information
     */
@@ -791,6 +793,28 @@ static const struct glx_screen_vtable dri2_screen_vtable = {
    dri2_create_context
 };
 
+int
+dri2ServerSupportsSBC(Display *dpy)
+{
+   struct glx_display *dpyPriv = __glXInitialize(dpy);
+   struct dri2_display *pdp =
+      (struct dri2_display *) dpyPriv->dri2Display;
+
+   if (pdp->driMajor > 1 || (pdp->driMajor == 1 && pdp->driMinor > 3))
+      return 1;
+
+   return 0;
+}
+
+int dri2Event(Display *dpy, int extension)
+{
+   struct glx_display *dpyPriv = __glXInitialize(dpy);
+   struct dri2_display *pdp =
+      (struct dri2_display *) dpyPriv->dri2Display;
+
+   return pdp->majorOpcode == extension;
+}
+
 static struct glx_screen *
 dri2CreateScreen(int screen, struct glx_display * priv)
 {
@@ -973,9 +997,9 @@ _X_HIDDEN __GLXDRIdisplay *
 dri2CreateDisplay(Display * dpy)
 {
    struct dri2_display *pdp;
-   int eventBase, errorBase, i;
+   int extBase, eventBase, errorBase, i;
 
-   if (!DRI2QueryExtension(dpy, &eventBase, &errorBase))
+   if (!DRI2QueryExtension(dpy, &extBase, &eventBase, &errorBase))
       return NULL;
 
    pdp = Xmalloc(sizeof *pdp);
@@ -987,6 +1011,7 @@ dri2CreateDisplay(Display * dpy)
       return NULL;
    }
 
+   pdp->majorOpcode = extBase;
    pdp->driPatch = 0;
    pdp->swapAvailable = (pdp->driMinor >= 2);
    pdp->invalidateAvailable = (pdp->driMinor >= 3);
src/glx/glxclient.h +2 -0
index 2b6966f..755a66d 100644
@@ -149,6 +149,8 @@ extern __GLXDRIdisplay *driCreateDisplay(Display * dpy);
 extern __GLXDRIdisplay *dri2CreateDisplay(Display * dpy);
 extern void dri2InvalidateBuffers(Display *dpy, XID drawable);
 extern unsigned dri2GetSwapEventType(Display *dpy, XID drawable);
+extern int dri2ServerSupportsSBC(Display *dpy);
+extern int dri2Event(Display *dpy, int extension);
 
 
 /*
Signature · 6 lines
1.7.4.1

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel
#6 lore raw

PATCH 5/5 GLX: support generic swap events

In reply to Jesse Barnes

The existing swap event structure is too big to fit in an XEvent, so support servers that send generic events instead. Do this by advertising the GLX proto version we support when connecting and check for generic events in the event stream. Convert any received events into regular swap complete events for client compatibility.

---
 configure.ac        |    2 +-
 src/glx/glxclient.h |    2 +-
 src/glx/glxext.c    |   55 ++++++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 50 insertions(+), 9 deletions(-)
configure.ac +1 -1
index 92d11af..94fb6f7 100644
@@ -22,7 +22,7 @@ LIBDRM_REQUIRED=2.4.24
 LIBDRM_RADEON_REQUIRED=2.4.24
 LIBDRM_INTEL_REQUIRED=2.4.24
 DRI2PROTO_REQUIRED=2.4
-GLPROTO_REQUIRED=1.4.11
+GLPROTO_REQUIRED=1.4.13
 LIBDRM_XORG_REQUIRED=2.4.24
 LIBKMS_XORG_REQUIRED=1.0.0
 
src/glx/glxclient.h +1 -1
index 755a66d..cdef2a1 100644
@@ -63,7 +63,7 @@
 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
 
 #define GLX_MAJOR_VERSION 1       /* current version numbers */
-#define GLX_MINOR_VERSION 4
+#define GLX_MINOR_VERSION 5
 
 #define __GLX_MAX_TEXTURE_UNITS 32
 
src/glx/glxext.c +48 -7

80 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#7 lore raw

PATCH 6/8 GLX/DRI2: pass drawable correctly for indirect swap events

In reply to Jesse Barnes

Pass the right drawable pointer as data to the swap complete function.

---
 glx/glxdri2.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
glx/glxdri2.c +1 -1
index d979717..93c5e5b 100644
@@ -222,7 +222,7 @@ __glXDRIdrawableSwapBuffers(ClientPtr client, __GLXdrawable *drawable)
 #endif
 
     if (DRI2SwapBuffers(client, drawable->pDraw, 0, 0, 0, &unused,
-			__glXdriSwapEvent, drawable->pDraw) != Success)
+			__glXdriSwapEvent, drawable) != Success)
 	return FALSE;
 
     return TRUE;
Signature · 1 line
1.7.4.1
#8 lore raw

PATCH 7/8 DRI2: support generic swap events

In reply to Jesse Barnes

Send the new generic swap event type if the client supports it. This means checking the client's DRI2 proto version at connect time and then constructing a new generic event at swap complete time. To track the client version, we need to add a new DRI2 client private type and track it for the lifetime of the client.

---
 configure.ac              |    2 +-
 glx/glxdri2.c             |   20 +++++++++++++++
 hw/xfree86/dri2/dri2.c    |   57 ++++++++++++++++++++++++++++++++++++++++++++-
 hw/xfree86/dri2/dri2.h    |    6 ++++
 hw/xfree86/dri2/dri2ext.c |   47 +++++++++++++++++++++++++++---------
 5 files changed, 118 insertions(+), 14 deletions(-)
configure.ac +1 -1
index 6eb780c..8e00fe7 100644
@@ -771,7 +771,7 @@ RECORDPROTO="recordproto >= 1.13.99.1"
 SCRNSAVERPROTO="scrnsaverproto >= 1.1"
 RESOURCEPROTO="resourceproto"
 DRIPROTO="xf86driproto >= 2.1.0"
-DRI2PROTO="dri2proto >= 2.3"
+DRI2PROTO="dri2proto >= 2.4"
 XINERAMAPROTO="xineramaproto"
 BIGFONTPROTO="xf86bigfontproto >= 1.2.0"
 DGAPROTO="xf86dgaproto >= 2.0.99.1"
glx/glxdri2.c +20 -0
index 93c5e5b..a17b4d5 100644
@@ -228,6 +228,23 @@ __glXDRIdrawableSwapBuffers(ClientPtr client, __GLXdrawable *drawable)
     return TRUE;
 }
 
+static void
+__glXDRIclientCallback(CallbackListPtr	*list,
+		   pointer		closure,
+		   pointer		data)
+{
+    NewClientInfoRec	*clientinfo = (NewClientInfoRec *) data;
+    ClientPtr		pClient = clientinfo->client;
+
+    switch (pClient->clientState) {
+    case ClientStateGone:
+	DRI2ClientGone(pClient);
+	break;
+    default:
+	break;
+    }
+}
+
 static int
 __glXDRIdrawableSwapInterval(__GLXdrawable *drawable, int interval)
 {
@@ -769,6 +786,9 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     screen->leaveVT = pScrn->LeaveVT;
     pScrn->LeaveVT = glxDRILeaveVT;
 
+    if (!AddCallback (&ClientStateCallback, __glXDRIclientCallback, 0))
+	return NULL;
+
     LogMessage(X_INFO,
 	       "AIGLX: Loaded and initialized %s\n", driverName);
 
hw/xfree86/dri2/dri2.c +56 -1

93 lines not on this page · raw message

hw/xfree86/dri2/dri2.h +6 -0
index fe0bf6c..97e8e86 100644
@@ -192,6 +192,7 @@ typedef struct {
 }  DRI2InfoRec, *DRI2InfoPtr;
 
 extern _X_EXPORT int DRI2EventBase;
+extern _X_EXPORT int DRI2ExtCode;
 
 extern _X_EXPORT Bool DRI2ScreenInit(ScreenPtr	pScreen,
 		    DRI2InfoPtr info);
@@ -283,5 +284,10 @@ extern _X_EXPORT void DRI2SwapComplete(ClientPtr client, DrawablePtr pDraw,
 extern _X_EXPORT void DRI2WaitMSCComplete(ClientPtr client, DrawablePtr pDraw,
 					  int frame, unsigned int tv_sec,
 					  unsigned int tv_usec);
+extern _X_EXPORT Bool DRI2ClientSupportsSBC(ClientPtr client);
+extern _X_EXPORT void DRI2ClientGone(ClientPtr client);
+extern _X_EXPORT void DRI2InitClient(ClientPtr client, CARD32 major,
+				     CARD32 minor);
+
 
 #endif
hw/xfree86/dri2/dri2ext.c +35 -12

73 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#9 lore raw

PATCH 8/8 GLX: support generic swap events

In reply to Jesse Barnes

Send the new generic GLX swap event if supported by the client. This means checking the client GLX version at swap complete time and constructing a new generic swap completion event at swap complete time.

---
 configure.ac                |    2 +-
 glx/glxdri2.c               |   99 +++++++++++++++++++++++++++++++-----------
 glx/glxext.c                |    2 +
 glx/glxserver.h             |    1 +
 include/protocol-versions.h |    2 +-
 5 files changed, 78 insertions(+), 28 deletions(-)
configure.ac +1 -1
index 8e00fe7..87194a5 100644
@@ -775,7 +775,7 @@ DRI2PROTO="dri2proto >= 2.4"
 XINERAMAPROTO="xineramaproto"
 BIGFONTPROTO="xf86bigfontproto >= 1.2.0"
 DGAPROTO="xf86dgaproto >= 2.0.99.1"
-GLPROTO="glproto >= 1.4.10"
+GLPROTO="glproto >= 1.4.13"
 DMXPROTO="dmxproto >= 2.2.99.1"
 VIDMODEPROTO="xf86vidmodeproto >= 2.2.99.1"
 WINDOWSWMPROTO="windowswmproto"
glx/glxdri2.c +73 -26

121 lines not on this page · raw message

glx/glxext.c +2 -0
index 9cfc096..01960a0 100644
@@ -242,6 +242,7 @@ GLboolean __glXErrorOccured(void)
 
 static int __glXErrorBase;
 int __glXEventBase;
+int __glXExtBase;
 
 int __glXError(int error)
 {
@@ -365,6 +366,7 @@ void GlxExtensionInit(void)
 
     __glXErrorBase = extEntry->errorBase;
     __glXEventBase = extEntry->eventBase;
+    __glXExtBase = extEntry->base;
 }
 
 /************************************************************************/
glx/glxserver.h +1 -0
index 891315b..0b8539c 100644
@@ -233,5 +233,6 @@ extern unsigned glxMajorVersion;
 extern unsigned glxMinorVersion;
 
 extern int __glXEventBase;
+extern int __glXExtBase;
 
 #endif /* !__GLX_server_h__ */
include/protocol-versions.h +1 -1
index 8692ded..8fde917 100644
@@ -57,7 +57,7 @@
 
 /* GLX */
 #define SERVER_GLX_MAJOR_VERSION		1
-#define SERVER_GLX_MINOR_VERSION		4
+#define SERVER_GLX_MINOR_VERSION		5
 
 /* Xinerama */
 #define SERVER_PANORAMIX_MAJOR_VERSION          1
Signature · 1 line
1.7.4.1