Mesa (master): glx/dri2: use uint64_t instead of double to represent time for FPS calculation

Marek Olšák mareko at kemper.freedesktop.org
Wed Oct 3 15:15:47 UTC 2012


Module: Mesa
Branch: master
Commit: 53d06ecdd02d36769cfd3da55d99a569c00b7878
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=53d06ecdd02d36769cfd3da55d99a569c00b7878

Author: Marek Olšák <maraeo at gmail.com>
Date:   Sun Sep 30 21:41:33 2012 +0200

glx/dri2: use uint64_t instead of double to represent time for FPS calculation

Wine or a windows app changes fpucw to 0x7f, causing doubles to be equivalent
to floats, which broke the calculation of FPS.
We should be very careful about using doubles in Mesa.

Henri Verbeet adds:
  For reference, this is done by for example d3d9 when a D3D device is
  created without D3DCREATE_FPU_PRESERVE set. In the general case
  applications can do all kinds of terrible things to the FPU control
  word of course.

---

 src/glx/dri2_glx.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index f2fc187..4ff0b9e 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -112,7 +112,7 @@ struct dri2_drawable
    int have_fake_front;
    int swap_interval;
 
-   double previous_time;
+   uint64_t previous_time;
    unsigned frames;
 };
 
@@ -676,17 +676,18 @@ unsigned dri2GetSwapEventType(Display* dpy, XID drawable)
 static void show_fps(struct dri2_drawable *draw)
 {
    struct timeval tv;
-   double current_time;
+   uint64_t current_time;
 
    gettimeofday(&tv, 0);
-   current_time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
+   current_time = (uint64_t)tv.tv_sec*1000000 + (uint64_t)tv.tv_usec;
 
    draw->frames++;
 
-   if (draw->previous_time + 1 < current_time) {
+   if (draw->previous_time + 1000000 <= current_time) {
       if (draw->previous_time) {
          fprintf(stderr, "libGL: FPS = %.1f\n",
-                 draw->frames / (current_time - draw->previous_time));
+                 ((uint64_t)draw->frames * 1000000) /
+                 (double)(current_time - draw->previous_time));
       }
       draw->frames = 0;
       draw->previous_time = current_time;




More information about the mesa-commit mailing list