[Mesa-dev] [PATCH] glx/dri2: print FPS when env var MESA_SHOW_FPS is 1

Michel Dänzer michel at daenzer.net
Wed Jan 4 06:39:42 PST 2012


On Mit, 2012-01-04 at 15:04 +0100, Marek Olšák wrote: 
> 2012/1/4 Michel Dänzer <michel at daenzer.net>:
> > On Mit, 2012-01-04 at 06:05 +0100, Marek Olšák wrote:
> >> This is useful for apps which don't print FPS.
> >> Only enabled in SwapBuffers.
> >> ---
> >>  src/glx/dri2_glx.c |   36 +++++++++++++++++++++++++++++++++++-
> >>  1 files changed, 35 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
> >> index a9bcebf..394823a 100644
> >> --- a/src/glx/dri2_glx.c
> >> +++ b/src/glx/dri2_glx.c
> >> @@ -576,6 +582,26 @@ unsigned dri2GetSwapEventType(Display* dpy, XID drawable)
> >>        return glx_dpy->codes->first_event + GLX_BufferSwapComplete;
> >>  }
> >>
> >> +static void show_fps()
> >> +{
> >> +   struct glx_context *gc = __glXGetCurrentContext();
> >> +   struct dri2_context *ctx = (struct dri2_context *)gc;
> >
> > glXSwapBuffers doesn't require a current context (or that the drawable
> > being swapped is bound to the current context). The information should
> > probably be tracked per drawable instead.
> 
> Okay, I'll make the state per drawable,

Thanks.

> but dri2Throttle calls __glXGetCurrentContext() too.

However, it handles the return value being NULL. Your code would have
crashed in that case.

While we've had a number of such artifical dependencies on a current
context in the SwapBuffers paths, I'm trying to prevent more from
getting added.


> >> #endif
> >>      }
> >>
> >> +    if (psc->show_fps) {
> >> +       show_fps();
> >> +    }
> >> +
> >>      /* Old servers don't send invalidate events */
> >>      if (!pdp->invalidateAvailable)
> >>         dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
> >
> > This really measures how quickly requests are sent to the X server. When
> > possible, it might be more accurate to use the information from the
> > completion events instead. Not a blocker though.
> 
> Sorry, I am adding something to glx/dri2 for the first time. What
> completion events? It doesn't matter if the measuring is done before
> or after SwapBuffers. The only requirement is that it must be done
> once per frame.

See the hits for

grep -i swap.*complete src/glx/*.[ch]

Basically, the X server sends an event to the client with information
about when the swap actually occurred. That might allow for more
accurate measurements at least in some cases, but as I said it's not a
blocker but could always be done as a followup change later on if
anyone's so inclined.


-- 
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer


More information about the mesa-dev mailing list