dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] present: Send GLX_BufferSwapComplete events from present extension
@ 2013-11-22  6:54 Keith Packard
       [not found] ` <1385103256-24620-1-git-send-email-keithp-aN4HjG94KOLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Keith Packard @ 2013-11-22  6:54 UTC (permalink / raw)
  To: xorg-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: mesa-dev-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

This allows GL to support the GLX_INTEL_swap_event extension

Signed-off-by: Keith Packard <keithp-aN4HjG94KOLQT0dZR+AlfA@public.gmane.org>
---

This is the X server side; the mesa patch will be sent shortly (it's tiny)

 glx/Makefile.am         |  3 ++-
 glx/glxcmds.c           | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
 glx/glxdri2.c           | 26 +++++--------------
 glx/glxext.c            |  3 +++
 glx/glxserver.h         |  9 +++++++
 present/present.h       |  9 +++++++
 present/present_event.c | 10 +++++++
 7 files changed, 109 insertions(+), 20 deletions(-)

diff --git a/glx/Makefile.am b/glx/Makefile.am
index 5f28e87..44d3a7d 100644
--- a/glx/Makefile.am
+++ b/glx/Makefile.am
@@ -20,7 +20,8 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/hw/xfree86/os-support/bus \
 	-I$(top_srcdir)/hw/xfree86/common \
 	-I$(top_srcdir)/hw/xfree86/dri \
-	-I$(top_srcdir)/mi
+	-I$(top_srcdir)/mi \
+	-I$(top_srcdir)/present
 
 if DRI2_AIGLX
 AM_CPPFLAGS += -I$(top_srcdir)/hw/xfree86/dri2
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index efa4aec..2c5de70 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2468,3 +2468,72 @@ __glXDisp_ClientInfo(__GLXclientState * cl, GLbyte * pc)
 
     return Success;
 }
+
+#include <GL/glxtokens.h>
+
+void
+__glXsendSwapEvent(__GLXdrawable *drawable, int type, CARD64 ust,
+                   CARD64 msc, CARD32 sbc)
+{
+    ClientPtr client = clients[CLIENT_ID(drawable->drawId)];
+
+    xGLXBufferSwapComplete2 wire =  {
+        .type = __glXEventBase + GLX_BufferSwapComplete
+    };
+
+    if (!client)
+        return;
+
+    if (!(drawable->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
+        return;
+
+    wire.event_type = type;
+    wire.drawable = drawable->drawId;
+    wire.ust_hi = ust >> 32;
+    wire.ust_lo = ust & 0xffffffff;
+    wire.msc_hi = msc >> 32;
+    wire.msc_lo = msc & 0xffffffff;
+    wire.sbc = sbc;
+
+    WriteEventsToClient(client, 1, (xEvent *) &wire);
+}
+
+#if PRESENT
+static void
+__glXpresentCompleteNotify(WindowPtr window, CARD8 present_mode, CARD32 serial,
+                           uint64_t ust, uint64_t msc)
+{
+    __GLXdrawable *drawable;
+    int error;
+    int glx_type;
+    int rc;
+
+    rc = dixLookupResourceByType((pointer *) &drawable, window->drawable.id,
+                                 __glXDrawableRes, serverClient, DixGetAttrAccess);
+
+    if (rc != Success)
+        return;
+
+    switch(present_mode) {
+    case PresentCompleteModeFlip:
+        glx_type = GLX_FLIP_COMPLETE_INTEL;
+        break;
+    case PresentCompleteModeCopy:
+        glx_type = GLX_BLIT_COMPLETE_INTEL;
+        break;
+    default:
+        glx_type = 0;
+        break;
+    }
+        
+    __glXsendSwapEvent(drawable, glx_type, ust, msc, serial);
+}
+
+#include <present.h>
+
+void
+__glXregisterPresentCompleteNotify(void)
+{
+    present_register_complete_notify(__glXpresentCompleteNotify);
+}
+#endif
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 1d74c8f..9d3f3c3 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -177,36 +177,24 @@ __glXdriSwapEvent(ClientPtr client, void *data, int type, CARD64 ust,
                   CARD64 msc, CARD32 sbc)
 {
     __GLXdrawable *drawable = data;
-    xGLXBufferSwapComplete2 wire =  {
-        .type = __glXEventBase + GLX_BufferSwapComplete
-    };
-
-    if (!(drawable->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
-        return;
-
+    int glx_type;
     switch (type) {
     case DRI2_EXCHANGE_COMPLETE:
-        wire.event_type = GLX_EXCHANGE_COMPLETE_INTEL;
+        glx_type = GLX_EXCHANGE_COMPLETE_INTEL;
         break;
     case DRI2_BLIT_COMPLETE:
-        wire.event_type = GLX_BLIT_COMPLETE_INTEL;
+        glx_type = GLX_BLIT_COMPLETE_INTEL;
         break;
     case DRI2_FLIP_COMPLETE:
-        wire.event_type = GLX_FLIP_COMPLETE_INTEL;
+        glx_type = GLX_FLIP_COMPLETE_INTEL;
         break;
     default:
         /* unknown swap completion type */
-        wire.event_type = 0;
+        glx_type = 0;
         break;
     }
-    wire.drawable = drawable->drawId;
-    wire.ust_hi = ust >> 32;
-    wire.ust_lo = ust & 0xffffffff;
-    wire.msc_hi = msc >> 32;
-    wire.msc_lo = msc & 0xffffffff;
-    wire.sbc = sbc;
-
-    WriteEventsToClient(client, 1, (xEvent *) &wire);
+    
+    __glXsendSwapEvent(drawable, glx_type, ust, msc, sbc);
 }
 
 /*
diff --git a/glx/glxext.c b/glx/glxext.c
index 3a7de28..601d08a 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -399,6 +399,9 @@ GlxExtensionInit(void)
 
     __glXErrorBase = extEntry->errorBase;
     __glXEventBase = extEntry->eventBase;
+#if PRESENT
+    __glXregisterPresentCompleteNotify();
+#endif
 }
 
 /************************************************************************/
diff --git a/glx/glxserver.h b/glx/glxserver.h
index 5e29abb..f862b63 100644
--- a/glx/glxserver.h
+++ b/glx/glxserver.h
@@ -120,6 +120,15 @@ void glxResumeClients(void);
 void __glXsetGetProcAddress(void (*(*get_proc_address) (const char *)) (void));
 void *__glGetProcAddress(const char *);
 
+void
+__glXsendSwapEvent(__GLXdrawable *drawable, int type, CARD64 ust,
+                   CARD64 msc, CARD32 sbc);
+
+#if PRESENT
+void
+__glXregisterPresentCompleteNotify(void);
+#endif
+
 /*
 ** State kept per client.
 */
diff --git a/present/present.h b/present/present.h
index 6a451fb..0e3bdc0 100644
--- a/present/present.h
+++ b/present/present.h
@@ -115,4 +115,13 @@ present_event_abandon(RRCrtcPtr crtc);
 extern _X_EXPORT Bool
 present_screen_init(ScreenPtr screen, present_screen_info_ptr info);
 
+typedef void (*present_complete_notify_proc)(WindowPtr window,
+                                             CARD8 mode,
+                                             CARD32 serial,
+                                             uint64_t ust,
+                                             uint64_t msc);
+
+extern _X_EXPORT void
+present_register_complete_notify(present_complete_notify_proc proc);
+
 #endif /* _PRESENT_H_ */
diff --git a/present/present_event.c b/present/present_event.c
index a8f7176..f0d509e 100644
--- a/present/present_event.c
+++ b/present/present_event.c
@@ -137,6 +137,14 @@ present_send_config_notify(WindowPtr window, int x, int y, int w, int h, int bw,
     }
 }
 
+static present_complete_notify_proc complete_notify;
+
+void
+present_register_complete_notify(present_complete_notify_proc proc)
+{
+    complete_notify = proc;
+}
+
 void
 present_send_complete_notify(WindowPtr window, CARD8 kind, CARD8 mode, CARD32 serial, uint64_t ust, uint64_t msc)
 {
@@ -165,6 +173,8 @@ present_send_complete_notify(WindowPtr window, CARD8 kind, CARD8 mode, CARD32 se
             }
         }
     }
+    if (complete_notify)
+        (*complete_notify)(window, mode, serial, ust, msc);
 }
 
 void
-- 
1.8.4.2

_______________________________________________
xorg-devel-go0+a7rfsptAfugRpC6u6w@public.gmane.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] present: Send GLX_BufferSwapComplete events from present extension
       [not found] ` <1385103256-24620-1-git-send-email-keithp-aN4HjG94KOLQT0dZR+AlfA@public.gmane.org>
@ 2013-11-25 22:46   ` Eric Anholt
  2013-11-26  2:39     ` Keith Packard
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Anholt @ 2013-11-25 22:46 UTC (permalink / raw)
  To: Keith Packard, xorg-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: mesa-dev-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 716 bytes --]

Keith Packard <keithp-aN4HjG94KOLQT0dZR+AlfA@public.gmane.org> writes:

> This allows GL to support the GLX_INTEL_swap_event extension
>
> Signed-off-by: Keith Packard <keithp-aN4HjG94KOLQT0dZR+AlfA@public.gmane.org>

There's a minor behavior change that the event now gets sent to the
drawable owner rather than the caller of DRI2SwapBuffers.

I don't expect it to matter in practice (I expect that the
swap-requesting client using this GLX extension is also the
drawable-creating one), and either choice seems wrong compared to "send
the event to everyone listening for the event on this drawable".  That
would be a separate change, anyway.

Reviewed-by: Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>

[-- Attachment #1.2: Type: application/pgp-signature, Size: 835 bytes --]

[-- Attachment #2: Type: text/plain, Size: 219 bytes --]

_______________________________________________
xorg-devel-go0+a7rfsptAfugRpC6u6w@public.gmane.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] present: Send GLX_BufferSwapComplete events from present extension
  2013-11-25 22:46   ` Eric Anholt
@ 2013-11-26  2:39     ` Keith Packard
  2013-11-26  5:35       ` [PATCH 0/4] Clean up dri3 SBC handling, enable GLX_INTEL_swap_event Keith Packard
  0 siblings, 1 reply; 9+ messages in thread
From: Keith Packard @ 2013-11-26  2:39 UTC (permalink / raw)
  To: Eric Anholt, xorg-devel; +Cc: mesa-dev, dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 1135 bytes --]

Eric Anholt <eric@anholt.net> writes:

> There's a minor behavior change that the event now gets sent to the
> drawable owner rather than the caller of DRI2SwapBuffers.

Yeah, probably not ideal, especially when the GLX drawable is created
using the window XID (as is the case for some older GLX clients). I
don't have the original client at the time the event is generated, but I
think I can go back and stick it in; will require tracking when the
client exits, of course.

> I don't expect it to matter in practice (I expect that the
> swap-requesting client using this GLX extension is also the
> drawable-creating one), and either choice seems wrong compared to "send
> the event to everyone listening for the event on this drawable".  That
> would be a separate change, anyway.

I think the original behaviour, sending the event to the client who sent
the PresentPixmap request is the only sane plan, and only a bit more
complicated than sending it to the drawable owner.

I'll cook up an alternate patch and send that along; we can then compare
the two approaches at least.

-- 
keith.packard@intel.com

[-- Attachment #1.2: Type: application/pgp-signature, Size: 827 bytes --]

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 0/4] Clean up dri3 SBC handling, enable GLX_INTEL_swap_event
  2013-11-26  2:39     ` Keith Packard
@ 2013-11-26  5:35       ` Keith Packard
  2013-11-26  5:35         ` [PATCH 1/4] dri3: Clean up struct dri3_drawable Keith Packard
                           ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Keith Packard @ 2013-11-26  5:35 UTC (permalink / raw)
  To: mesa-dev, Eric Anholt; +Cc: dri-devel

I've split the GLX_INTEL_swap_event enabling patch into four bits -- the first
three just fix the existing code to track SBC values correctly and to fix
wait_for_sbc. The fourth is the trivial patch to actually turn on the new
extension; all of the hard work for that is actually dealt with in the X
server.

 [PATCH 1/4] dri3: Clean up struct dri3_drawable

Trivial struct member cleanup -- a couple of unused fields, and one oddly
placed field.

 [PATCH 2/4] dri3: Track full 64-bit SBC numbers, instead of just

This switches all of the internal SBC tracking to use 64-bit values. I use
uint64_t because I don't trust compilers with signed integer comparisons that
may wrap any more.

 [PATCH 3/4] dri3: Fix dri3_wait_for_sbc to wait for completion of

This one makes wait_for_sbc actually wait for the completion of the specified
swap, rather than the queuing of that value. Makes *far* more sense this way.

 [PATCH 4/4] dri3: Enable GLX_INTEL_swap_event

The trivial patch that just adds the extension to the list.

-keith

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] dri3: Clean up struct dri3_drawable
  2013-11-26  5:35       ` [PATCH 0/4] Clean up dri3 SBC handling, enable GLX_INTEL_swap_event Keith Packard
@ 2013-11-26  5:35         ` Keith Packard
  2013-12-13 23:01           ` Kenneth Graunke
  2013-11-26  5:35         ` [PATCH 2/4] dri3: Track full 64-bit SBC numbers, instead of just 32-bits Keith Packard
                           ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Keith Packard @ 2013-11-26  5:35 UTC (permalink / raw)
  To: mesa-dev, Eric Anholt; +Cc: dri-devel

Move the depth field up with width and height.

Remove unused previous_time and frames fields.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 src/glx/dri3_priv.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/glx/dri3_priv.h b/src/glx/dri3_priv.h
index 05f66cf..34c67a6 100644
--- a/src/glx/dri3_priv.h
+++ b/src/glx/dri3_priv.h
@@ -177,7 +177,7 @@ dri3_pixmap_buf_id(enum dri3_buffer_type buffer_type)
 struct dri3_drawable {
    __GLXDRIdrawable base;
    __DRIdrawable *driDrawable;
-   int width, height;
+   int width, height, depth;
    int swap_interval;
    uint8_t have_back;
    uint8_t have_fake_front;
@@ -193,13 +193,9 @@ struct dri3_drawable {
    /* For WaitMSC */
    uint32_t present_msc_request_serial;
    uint32_t present_msc_event_serial;
-   
-   uint64_t previous_time;
-   unsigned frames;
 
    struct dri3_buffer *buffers[DRI3_NUM_BUFFERS];
    int cur_back;
-   int depth;
 
    uint32_t *stamp;
 
-- 
1.8.4.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] dri3: Track full 64-bit SBC numbers, instead of just 32-bits
  2013-11-26  5:35       ` [PATCH 0/4] Clean up dri3 SBC handling, enable GLX_INTEL_swap_event Keith Packard
  2013-11-26  5:35         ` [PATCH 1/4] dri3: Clean up struct dri3_drawable Keith Packard
@ 2013-11-26  5:35         ` Keith Packard
  2013-11-26  5:35         ` [PATCH 3/4] dri3: Fix dri3_wait_for_sbc to wait for completion of requested SBC Keith Packard
  2013-11-26  5:35         ` [PATCH 4/4] dri3: Enable GLX_INTEL_swap_event Keith Packard
  3 siblings, 0 replies; 9+ messages in thread
From: Keith Packard @ 2013-11-26  5:35 UTC (permalink / raw)
  To: mesa-dev, Eric Anholt; +Cc: dri-devel

Tracking the full 64-bit SBC values makes it clearer how those values are
being used, and simplifies the wait_msc code. The only trick is in
re-constructing the full 64-bit value from Present's 32-bit serial number that
we use to pass the SBC value from request to event.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 src/glx/dri3_glx.c  | 34 +++++++++++++++++++++-------------
 src/glx/dri3_priv.h | 16 +++++++++-------
 2 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index 669f0bb..c0915f2 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -364,10 +364,17 @@ dri3_handle_present_event(struct dri3_drawable *priv, xcb_present_generic_event_
    case XCB_PRESENT_COMPLETE_NOTIFY: {
       xcb_present_complete_notify_event_t *ce = (void *) ge;
 
-      if (ce->kind == XCB_PRESENT_COMPLETE_KIND_PIXMAP)
-         priv->present_event_serial = ce->serial;
-      else
-         priv->present_msc_event_serial = ce->serial;
+      /* Compute the processed SBC number from the received 32-bit serial number merged
+       * with the upper 32-bits of the sent 64-bit serial number while checking for
+       * wrap
+       */
+      if (ce->kind == XCB_PRESENT_COMPLETE_KIND_PIXMAP) {
+         priv->recv_sbc = (priv->send_sbc & 0xffffffff00000000LL) | ce->serial;
+         if (priv->recv_sbc > priv->send_sbc)
+            priv->recv_sbc -= 0x100000000;
+      } else {
+         priv->recv_msc_serial = ce->serial;
+      }
       priv->ust = ce->ust;
       priv->msc = ce->msc;
       break;
@@ -398,12 +405,13 @@ dri3_wait_for_msc(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
    struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
    xcb_generic_event_t *ev;
    xcb_present_generic_event_t *ge;
+   uint32_t msc_serial;
 
    /* Ask for the an event for the target MSC */
-   ++priv->present_msc_request_serial;
+   msc_serial = ++priv->send_msc_serial;
    xcb_present_notify_msc(c,
                           priv->base.xDrawable,
-                          priv->present_msc_request_serial,
+                          msc_serial,
                           target_msc,
                           divisor,
                           remainder);
@@ -412,7 +420,7 @@ dri3_wait_for_msc(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
 
    /* Wait for the event */
    if (priv->special_event) {
-      while (priv->present_msc_request_serial != priv->present_msc_event_serial) {
+      while ((int32_t) (msc_serial - priv->recv_msc_serial) > 0) {
          ev = xcb_wait_for_special_event(c, priv->special_event);
          if (!ev)
             break;
@@ -423,7 +431,7 @@ dri3_wait_for_msc(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
 
    *ust = priv->ust;
    *msc = priv->msc;
-   *sbc = priv->sbc;
+   *sbc = priv->recv_sbc;
 
    return 1;
 }
@@ -450,7 +458,7 @@ dri3_wait_for_sbc(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
 {
    struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
 
-   while (priv->sbc < target_sbc) {
+   while (priv->send_sbc < target_sbc) {
       sleep(1);
    }
    return dri3_wait_for_msc(pdraw, 0, 0, 0, ust, msc, sbc);
@@ -1282,15 +1290,15 @@ dri3_swap_buffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
       /* Compute when we want the frame shown by taking the last known successful
        * MSC and adding in a swap interval for each outstanding swap request
        */
-      ++priv->present_request_serial;
+      ++priv->send_sbc;
       if (target_msc == 0)
-         target_msc = priv->msc + priv->swap_interval * (priv->present_request_serial - priv->present_event_serial);
+         target_msc = priv->msc + priv->swap_interval * (priv->send_sbc - priv->recv_sbc);
 
       priv->buffers[buf_id]->busy = 1;
       xcb_present_pixmap(c,
                          priv->base.xDrawable,
                          priv->buffers[buf_id]->pixmap,
-                         priv->present_request_serial,
+                         (uint32_t) priv->send_sbc,
                          0,                                    /* valid */
                          0,                                    /* update */
                          0,                                    /* x_off */
@@ -1302,7 +1310,7 @@ dri3_swap_buffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
                          target_msc,
                          divisor,
                          remainder, 0, NULL);
-      ret = ++priv->sbc;
+      ret = (int64_t) priv->send_sbc;
 
       /* If there's a fake front, then copy the source back buffer
        * to the fake front to keep it up to date. This needs
diff --git a/src/glx/dri3_priv.h b/src/glx/dri3_priv.h
index 34c67a6..f1fec3c 100644
--- a/src/glx/dri3_priv.h
+++ b/src/glx/dri3_priv.h
@@ -183,16 +183,18 @@ struct dri3_drawable {
    uint8_t have_fake_front;
    uint8_t is_pixmap;
 
-   uint32_t present_request_serial;
-   uint32_t present_event_serial;
-
-   uint64_t sbc;
+   /* SBC numbers are tracked by using the serial numbers
+    * in the present request and complete events
+    */
+   uint64_t send_sbc;
+   uint64_t recv_sbc;
 
+   /* Last received UST/MSC values */
    uint64_t ust, msc;
 
-   /* For WaitMSC */
-   uint32_t present_msc_request_serial;
-   uint32_t present_msc_event_serial;
+   /* Serial numbers for tracking wait_for_msc events */
+   uint32_t send_msc_serial;
+   uint32_t recv_msc_serial;
 
    struct dri3_buffer *buffers[DRI3_NUM_BUFFERS];
    int cur_back;
-- 
1.8.4.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] dri3: Fix dri3_wait_for_sbc to wait for completion of requested SBC
  2013-11-26  5:35       ` [PATCH 0/4] Clean up dri3 SBC handling, enable GLX_INTEL_swap_event Keith Packard
  2013-11-26  5:35         ` [PATCH 1/4] dri3: Clean up struct dri3_drawable Keith Packard
  2013-11-26  5:35         ` [PATCH 2/4] dri3: Track full 64-bit SBC numbers, instead of just 32-bits Keith Packard
@ 2013-11-26  5:35         ` Keith Packard
  2013-11-26  5:35         ` [PATCH 4/4] dri3: Enable GLX_INTEL_swap_event Keith Packard
  3 siblings, 0 replies; 9+ messages in thread
From: Keith Packard @ 2013-11-26  5:35 UTC (permalink / raw)
  To: mesa-dev, Eric Anholt; +Cc: dri-devel

Eric figured out that glXWaitForSbcOML wanted to block until the requested SBC
had been completed, which means to wait until the PresentCompleteNotify event
for that SBC had been received.

This replaces the simple sleep(1) loop (which was bogus) with a loop that just
checks to see if we've seen the specified SBC value come back in a
PresentCompleteNotify event yet.

The change is a bit larger than that as I've broken out a piece of common code
to wait for and process a single Present event for the target drawable.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 src/glx/dri3_glx.c | 55 ++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 39 insertions(+), 16 deletions(-)

diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index c0915f2..da3f08b 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -397,14 +397,33 @@ dri3_handle_present_event(struct dri3_drawable *priv, xcb_present_generic_event_
    free(ge);
 }
 
+static bool
+dri3_wait_for_event(__GLXDRIdrawable *pdraw)
+{
+   xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
+   struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
+   xcb_generic_event_t *ev;
+   xcb_present_generic_event_t *ge;
+
+   ev = xcb_wait_for_special_event(c, priv->special_event);
+   if (!ev)
+      return false;
+   ge = (void *) ev;
+   dri3_handle_present_event(priv, ge);
+   return true;
+}
+
+/** dri3_wait_for_msc
+ *
+ * Get the X server to send an event when the target msc/divisor/remainder is
+ * reached.
+ */
 static int
 dri3_wait_for_msc(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
                   int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc)
 {
    xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
    struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
-   xcb_generic_event_t *ev;
-   xcb_present_generic_event_t *ge;
    uint32_t msc_serial;
 
    /* Ask for the an event for the target MSC */
@@ -421,11 +440,8 @@ dri3_wait_for_msc(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
    /* Wait for the event */
    if (priv->special_event) {
       while ((int32_t) (msc_serial - priv->recv_msc_serial) > 0) {
-         ev = xcb_wait_for_special_event(c, priv->special_event);
-         if (!ev)
-            break;
-         ge = (void *) ev;
-         dri3_handle_present_event(priv, ge);
+         if (!dri3_wait_for_event(pdraw))
+            return 0;
       }
    }
 
@@ -436,6 +452,11 @@ dri3_wait_for_msc(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
    return 1;
 }
 
+/** dri3_drawable_get_msc
+ *
+ * Return the current UST/MSC/SBC triplet by asking the server
+ * for an event
+ */
 static int
 dri3_drawable_get_msc(struct glx_screen *psc, __GLXDRIdrawable *pdraw,
                       int64_t *ust, int64_t *msc, int64_t *sbc)
@@ -445,12 +466,9 @@ dri3_drawable_get_msc(struct glx_screen *psc, __GLXDRIdrawable *pdraw,
 
 /** dri3_wait_for_sbc
  *
- * Wait for the swap buffer count to increase. The only way this
- * can happen is if some other thread is doing swap buffers as
- * we no longer share swap buffer counts with other processes.
- *
- * I'm not sure this is actually useful as such, and so this
- * implementation is a kludge that just polls once a second
+ * Wait for the completed swap buffer count to reach the specified
+ * target. Presumably the application knows that this will be reached with
+ * outstanding complete events, or we're going to be here awhile.
  */
 static int
 dri3_wait_for_sbc(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
@@ -458,10 +476,15 @@ dri3_wait_for_sbc(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
 {
    struct dri3_drawable *priv = (struct dri3_drawable *) pdraw;
 
-   while (priv->send_sbc < target_sbc) {
-      sleep(1);
+   while (priv->recv_sbc < target_sbc) {
+      if (!dri3_wait_for_event(pdraw))
+         return 0;
    }
-   return dri3_wait_for_msc(pdraw, 0, 0, 0, ust, msc, sbc);
+
+   *ust = priv->ust;
+   *msc = priv->msc;
+   *sbc = priv->recv_sbc;
+   return 1;
 }
 
 /**
-- 
1.8.4.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] dri3: Enable GLX_INTEL_swap_event
  2013-11-26  5:35       ` [PATCH 0/4] Clean up dri3 SBC handling, enable GLX_INTEL_swap_event Keith Packard
                           ` (2 preceding siblings ...)
  2013-11-26  5:35         ` [PATCH 3/4] dri3: Fix dri3_wait_for_sbc to wait for completion of requested SBC Keith Packard
@ 2013-11-26  5:35         ` Keith Packard
  3 siblings, 0 replies; 9+ messages in thread
From: Keith Packard @ 2013-11-26  5:35 UTC (permalink / raw)
  To: mesa-dev, Eric Anholt; +Cc: dri-devel

Now that we're tracking SBC values correctly, and the X server has the ability
to send the GLX swap events from a PresentPixmap request, enable this extension.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 src/glx/dri3_glx.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index da3f08b..aa5dd21 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -1525,23 +1525,7 @@ dri3_bind_extensions(struct dri3_screen *psc, struct glx_display * priv,
    __glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control");
    __glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control");
    __glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read");
-
-   /*
-    * GLX_INTEL_swap_event is broken on the server side, where it's
-    * currently unconditionally enabled. This completely breaks
-    * systems running on drivers which don't support that extension.
-    * There's no way to test for its presence on this side, so instead
-    * of disabling it unconditionally, just disable it for drivers
-    * which are known to not support it, or for DDX drivers supporting
-    * only an older (pre-ScheduleSwap) version of DRI2.
-    *
-    * This is a hack which is required until:
-    * http://lists.x.org/archives/xorg-devel/2013-February/035449.html
-    * is merged and updated xserver makes it's way into distros:
-    */
-//   if (pdp->swapAvailable && strcmp(driverName, "vmwgfx") != 0) {
-//      __glXEnableDirectExtension(&psc->base, "GLX_INTEL_swap_event");
-//   }
+   __glXEnableDirectExtension(&psc->base, "GLX_INTEL_swap_event");
 
    mask = psc->image_driver->getAPIMask(psc->driScreen);
 
-- 
1.8.4.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] dri3: Clean up struct dri3_drawable
  2013-11-26  5:35         ` [PATCH 1/4] dri3: Clean up struct dri3_drawable Keith Packard
@ 2013-12-13 23:01           ` Kenneth Graunke
  0 siblings, 0 replies; 9+ messages in thread
From: Kenneth Graunke @ 2013-12-13 23:01 UTC (permalink / raw)
  To: Keith Packard, mesa-dev, Eric Anholt; +Cc: dri-devel

On 11/25/2013 09:35 PM, Keith Packard wrote:
> Move the depth field up with width and height.
> 
> Remove unused previous_time and frames fields.
> 
> Signed-off-by: Keith Packard <keithp@keithp.com>
> ---
>  src/glx/dri3_priv.h | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/src/glx/dri3_priv.h b/src/glx/dri3_priv.h
> index 05f66cf..34c67a6 100644
> --- a/src/glx/dri3_priv.h
> +++ b/src/glx/dri3_priv.h
> @@ -177,7 +177,7 @@ dri3_pixmap_buf_id(enum dri3_buffer_type buffer_type)
>  struct dri3_drawable {
>     __GLXDRIdrawable base;
>     __DRIdrawable *driDrawable;
> -   int width, height;
> +   int width, height, depth;
>     int swap_interval;
>     uint8_t have_back;
>     uint8_t have_fake_front;
> @@ -193,13 +193,9 @@ struct dri3_drawable {
>     /* For WaitMSC */
>     uint32_t present_msc_request_serial;
>     uint32_t present_msc_event_serial;
> -   
> -   uint64_t previous_time;
> -   unsigned frames;
>  
>     struct dri3_buffer *buffers[DRI3_NUM_BUFFERS];
>     int cur_back;
> -   int depth;
>  
>     uint32_t *stamp;
>  
> 

This one is easy.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>

I plan to push it - hopefully today.  I don't feel qualified to review
the SBC and swap event handling patches, so hopefully someone else can
take a look...

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-12-13 23:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-22  6:54 [PATCH] present: Send GLX_BufferSwapComplete events from present extension Keith Packard
     [not found] ` <1385103256-24620-1-git-send-email-keithp-aN4HjG94KOLQT0dZR+AlfA@public.gmane.org>
2013-11-25 22:46   ` Eric Anholt
2013-11-26  2:39     ` Keith Packard
2013-11-26  5:35       ` [PATCH 0/4] Clean up dri3 SBC handling, enable GLX_INTEL_swap_event Keith Packard
2013-11-26  5:35         ` [PATCH 1/4] dri3: Clean up struct dri3_drawable Keith Packard
2013-12-13 23:01           ` Kenneth Graunke
2013-11-26  5:35         ` [PATCH 2/4] dri3: Track full 64-bit SBC numbers, instead of just 32-bits Keith Packard
2013-11-26  5:35         ` [PATCH 3/4] dri3: Fix dri3_wait_for_sbc to wait for completion of requested SBC Keith Packard
2013-11-26  5:35         ` [PATCH 4/4] dri3: Enable GLX_INTEL_swap_event Keith Packard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).