booglybob / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

vsync issues on Windows 7 #679

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am currently running from the repos, recent as of a couple of days ago.

Under some (simple) conditions, vsync fails to sync correctly. This does not 
happen on Linux (64-bit, Ubuntu 13.10) with the same hardware (NVIDIA graphics 
card with latest drivers), so the issue appears to be with Windows. I am 
running Windows 7 64-bit, with a 32-bit Python. Also note that my screen has a 
144Hz refresh rate, so the intervals should be ~7ms.

The output of `python -m pyglet.info` is attached as a text file.

The following code demonstrates different inter-flip intervals based on whether 
I call time.sleep() somewhere in the code (as a proxy for doing some operation 
that takes linger than one frame cycle). Can anyone reproduce this? Note that 
the intervals should all be ~7ms, which they are for the blue case (no 
time.sleep() call) but they aren't for the green case.

---

import timeit
import time
import pyglet
import numpy as np

win = pyglet.window.Window(config=pyglet.gl.Config(double_buffer=True),
                           vsync=True)
n_try = 200
times = np.empty((2, n_try))  # no sleep, sleep
for di in [0, 1]:  # no sleep, sleep
    for ti in xrange(n_try):
        if di == 1:
            time.sleep(0.01)
        win.flip()
        t1 = timeit.default_timer()
        win.flip()
        t2 = timeit.default_timer()
        times[di, ti] = (t2 - t1)
win.close()
times *= 1000  # convert to ms

import matplotlib.pyplot as mpl
mpl.ion()
ax = mpl.axes()
xs = 1000 * np.arange(0.0025, 0.0125, 0.001)
ax.hist(times.T, xs)
ax.set_xlabel('Inter-frame interval (ms)')
ax.set_xticks((xs[1:] + xs[:-1]) / 2.)
ideal = (1. / 144.) * 1000.
ax.plot([ideal, ideal], ax.get_ylim(), color='r')

Original issue reported on code.google.com by larson.e...@gmail.com on 1 Nov 2013 at 8:45

Attachments:

GoogleCodeExporter commented 8 years ago
It was pointed out to me on a different forum that my code might not be correct:

https://github.com/Eric89GXL/psychopy/commit/d5c79efb5e86f7f4d88c87ea2568be8502c
3b343#commitcomment-4495274

If it's the case that I need to draw a pixel and do glFinish() as suggested 
there, then it means that Windows might work fine, but on Linux I was getting a 
72 Hz redraw instead of 144 Hz using that method. I can investigate more and 
try to track this down, unless someone else has insight.

Original comment by larson.e...@gmail.com on 2 Nov 2013 at 5:16

GoogleCodeExporter commented 8 years ago
Turns out this issue is only a problem when the window is not full-screen. I 
suppose this makes sense since I've read that flip timing can't be guaranteed 
when in windowed mode. Devs, feel free to close this issue if you agree with 
this explanation.

I'm not sure if there's a better way to let users know about this limitation -- 
maybe add it to (or make ti more prominent in) the docs?

Original comment by larson.e...@gmail.com on 5 Nov 2013 at 12:51

GoogleCodeExporter commented 8 years ago
I understand your explanation and I'm happy to close the issue but I can't 
contribute any comment as I'm mostly developing on Linux.

I'm closing the issue as "DriverBug", although it's not really that.

Thanks for the report!

Original comment by useboxnet on 28 Nov 2013 at 7:05