dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Keith Packard <keithp@keithp.com>
To: mesa-dev@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH 07/18] dri3: Track full 64-bit SBC numbers, instead of just 32-bits
Date: Fri, 13 Dec 2013 17:25:19 -0800	[thread overview]
Message-ID: <1386984330-26074-8-git-send-email-keithp@keithp.com> (raw)
In-Reply-To: <1386984330-26074-1-git-send-email-keithp@keithp.com>

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 4c0dc29..b9a786f 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);
@@ -1281,15 +1289,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 */
@@ -1301,7 +1309,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 4adef50..4c5579e 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

  parent reply	other threads:[~2013-12-14  1:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-14  1:25 [PATCH 00/18] dri3+gallium patch series Keith Packard
2013-12-14  1:25 ` [PATCH 01/18] Remove glBlendColor and glBlendEquations decls from glext.h Keith Packard
2013-12-14  2:28   ` [Mesa-dev] " Kenneth Graunke
2013-12-14  6:56     ` Keith Packard
2013-12-20 18:24   ` Ian Romanick
2013-12-14  1:25 ` [PATCH 02/18] dri/swrast: Passing dri_context * instead of gl_context* to driContextSetFlags Keith Packard
2013-12-14  1:25 ` [PATCH 03/18] Don't use libudev for glx/dri3 Keith Packard
2013-12-14  1:25 ` [PATCH 04/18] dri3: Switch to libxshmfence version 1.1 Keith Packard
2013-12-14  2:35   ` [Mesa-dev] " Kenneth Graunke
2013-12-14  7:00     ` Keith Packard
2013-12-14  1:25 ` [PATCH 05/18] dri3: Free resources when drawable is destroyed Keith Packard
2013-12-14  1:25 ` [PATCH 06/18] dri3: Clean up struct dri3_drawable Keith Packard
2013-12-14  1:25 ` Keith Packard [this message]
2013-12-14  1:25 ` [PATCH 08/18] dri3: Fix dri3_wait_for_sbc to wait for completion of requested SBC Keith Packard
2013-12-14  1:25 ` [PATCH 09/18] dri3: Enable GLX_INTEL_swap_event Keith Packard
2013-12-14  1:25 ` [PATCH 10/18] i965: Correct check for re-bound buffer in intel_update_image_buffer Keith Packard
2013-12-14  1:25 ` [PATCH 11/18] i965: Set fast color clear mcs_state on newly allocated image miptrees Keith Packard
2013-12-14  1:25 ` [PATCH 12/18] dri3: Rename DRI3_MAX_BACK to DRI3_NUM_BACK Keith Packard
2013-12-14  1:25 ` [PATCH 13/18] dri3: Flush XCB before blocking for special events Keith Packard
2013-12-14  1:25 ` [PATCH 14/18] dri3, i915, i965: Add __DRI_IMAGE_FOURCC_SARGB8888 Keith Packard
2013-12-14  1:25 ` [PATCH 15/18] gallium: Add __DRIimageDriverExtension support to gallium Keith Packard
2013-12-14 11:27   ` Marek Olšák
2013-12-27 20:27     ` Keith Packard
2014-01-03 20:03       ` Marek Olšák
2013-12-14  1:25 ` [PATCH 16/18] gallium/dri: fix unsetting of format when encountering depth/stencil Keith Packard
2013-12-14  1:25 ` [PATCH 17/18] nvc0: fix segfault if nv50_miptree_from_handle() fails Keith Packard
2013-12-14  1:25 ` [PATCH 18/18] gallium: Use base.stamp for all drawable invalidation checks Keith Packard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386984330-26074-8-git-send-email-keithp@keithp.com \
    --to=keithp@keithp.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mesa-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).