[Mesa-dev] [PATCH] glx/dri3: Implement LIBGL_SHOW_FPS=1 for DRI3/Present.

Keith Packard keithp at keithp.com
Wed Oct 29 07:23:03 PDT 2014


Kenneth Graunke <kenneth at whitecape.org> writes:

> v2: Use the UST value provided in the PRESENT_COMPLETE_NOTIFY event
>     rather than gettimeofday(), which gives us the presentation time
>     instead of the time when SwapBuffers was called.  Suggested by
>     Keith Packard.  This relies on the fact that the X Present
>     implementation uses microseconds for UST.
>
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> Cc: Keith Packard <keithp at keithp.com>
> Cc: Marek Olšák <marek.olsak at amd.com>
> ---
>  src/glx/dri3_glx.c  | 33 ++++++++++++++++++++++++++++++++-
>  src/glx/dri3_priv.h |  6 +++++-
>  2 files changed, 37 insertions(+), 2 deletions(-)
>
> Is this what you had in mind, Keith?  It seems to work fine as well,
> and as long as we can rely on UST being in microseconds, it definitely
> seems nicer.

Present doesn't actually define UST at this point, but I think we can
just fix that; it seems useless to *not* define it, and microseconds
seems like a fine resolution for this clock. Certainly anything using
DRI3 will use microseconds as that's the kind of time stamps it uses.

> diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
> index e8e5c4a..ff9c2f3 100644
> --- a/src/glx/dri3_glx.c
> +++ b/src/glx/dri3_glx.c
> @@ -361,12 +361,34 @@ dri3_create_drawable(struct glx_screen *base, XID xDrawable,
>     return &pdraw->base;
>  }
>  
> +static void
> +show_fps(struct dri3_drawable *draw)
> +{
> +   const int interval =
> +      ((struct dri3_screen *) draw->base.psc)->show_fps_interval;
> +
> +   draw->frames++;
> +
> +   /* The Present extension uses microseconds for UST. */
> +   if (draw->previous_ust + interval * 1000000 <= draw->ust) {

Might want a cast here before the multiply, otherwise that gets done
with only 32 bits. It probably doesn't matter because interval is likely
to be small.

> +      if (draw->previous_ust) {
> +         fprintf(stderr, "libGL: FPS = %.1f\n",
> +                 ((uint64_t)draw->frames * 1000000) /
> +                 (double)(draw->ust - draw->previous_ust));
> +      }
> +      draw->frames = 0;
> +      draw->previous_ust = draw->ust;
> +   }
> +}
> +
>  /*
>   * Process one Present event
>   */
>  static void
>  dri3_handle_present_event(struct dri3_drawable *priv, xcb_present_generic_event_t *ge)
>  {
> +   struct dri3_screen *psc = (struct dri3_screen *) priv->base.psc;
> +
>     switch (ge->evtype) {
>     case XCB_PRESENT_CONFIGURE_NOTIFY: {
>        xcb_present_configure_notify_event_t *ce = (void *) ge;
> @@ -400,6 +422,10 @@ dri3_handle_present_event(struct dri3_drawable *priv, xcb_present_generic_event_
>        }
>        priv->ust = ce->ust;
>        priv->msc = ce->msc;
> +
> +      if (psc->show_fps_interval) {
> +         show_fps(priv);
> +      }

This actually needs to be inside the COMPLETE_KIND_PIXMAP; this same
event is delivered when the application gets the current MSC, and you
don't want to count those.

-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 810 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141029/164767e8/attachment.sig>


More information about the mesa-dev mailing list