pouët.net

vsync on/off problem

category: code [glöplog]
 
Hi boys and girls.

I have a vsync problem. Using two thread in the program, with glfw for windowing.


windows event thread
Code: // renderer is now running beside this thread while(running) { //Thread.sleep(dur!("msecs")(1)); // if runing pollevent glfwWaitEvents(); if(glfwWindowShouldClose(window)) { // stop the rendering thread before terminate and make the current thread handle the context running = false; renderingThread.join(true); } }


GL thread:
Code: double delta = 0; double currentTime = glfwGetTime(); double oldTime = currentTime; double oldTime2 = oldTime; int frames = 0; int lastFps = 0; int fps = 0; while(running) { update(delta); glfwSwapBuffers(window); //Thread.sleep(dur!("msecs")(1)); // seem to not impact the performance OO // compute delta & fps oldTime2 = currentTime; currentTime = glfwGetTime(); delta = currentTime - oldTime2; if((currentTime-oldTime) > 1.0 || frames == 0) { fps = cast(int) (frames / (currentTime-oldTime)); lastFps = fps; oldTime = currentTime; frames = 0; glfwSetWindowTitle(window, toStringz(format("%s - FPS: %s", windowTitle, fps))); } frames++; }



You can see that i compute delta time every frame and then update the whole things. This seem to work fine, at least i have an accurate FPS counting (verifying with fraps), but when i turn on/off the vsync, i have some kind of offset who appears.

ex: vsync off: screen 1 terminate at 35 seconds
ex: vsync on: screen 1 terminate at 45 seconds, synchro fucked up.

I update all my value for movements with shit like "X = x * delta * 400;" so it can be the problem, it is?

I dunno what to think about that problem. I'm stuck on it since yesterday, having missed some hour of sleep and work because I want to understand what is happening :/ If you have an idea..
added on the 2013-07-10 11:54:31 by Romain337 Romain337
I would assume "update(delta);" is your rendering call?
added on the 2013-07-10 12:00:21 by Gargaj Gargaj
Yes it is

it just contain some drawing stuff.

I have also a global counter updated each frime by delta. This counter show different at end of the scene if i turno on/off vsync.
added on the 2013-07-10 12:02:49 by Romain337 Romain337
What is your average FPS with vsync off?
added on the 2013-07-10 13:03:41 by Gargaj Gargaj
It is exactly 59 and do not move.

With vsync off i ran between 1000 / 4000 depending off the computer and the other task running on it.

I'm trying to see if the problem is not in my animation logic but if i remember i had the very same problem with my others prods without taking care of it at the time.
added on the 2013-07-10 13:18:36 by Romain337 Romain337
Sure that the sync is wrong with vsync on?

>1000fps very much sounds like you get problems with the timer resolution without vsync. If you synced your stuff to this you might be in for a nasty surprise.

(Hint: Just dump the delta to the debug output each frame and have a thorough look at the numbers. They should be around 16.~6 with vsync and at least make sense without. Also, try Sleep()ing for 10 milliseconds instead for testing)
added on the 2013-07-10 13:28:43 by kb_ kb_
Report with VSYNC ON (about 1 seconds) : http://pastebin.com/bW8NvWwm

Report with VSYNC OFF (about 1 seconds):
http://pastebin.com/hJYcePk1

+ The total source code of what i am doing now:
http://www.notnotme.com/misc/Vendetta.zip

You can compile it simply by installing DMD2 then click "build.exe" (assuming dmd is in your path).

This is just a test sorry for the lack of credits...

added on the 2013-07-10 13:40:19 by Romain337 Romain337
+

@kb_ Yes it is probably with VSYNC OFF the problem. I'll take a look this evening after the work. I'm sure it is something stupid.

I've linked the source in case where somebody want to test or if you need some infos that i can't provide to you due to my broken english plus the fact that i'm just tired as hell and need to sleep but i'am at work.

I'm not the kind of guys who ask for a magic function. I just need some help in this case :/

Thanks to you
added on the 2013-07-10 13:54:58 by Romain337 Romain337
The timer resolution...

And yes I have synced with the bad time elapsed :) it was a kind of random sync anyway. I've added a function to cap the fps to 60 but i'm still a bit confused.

I let the whole source on the server, for at least 1 weeks the time for this thread to die ^^
added on the 2013-07-10 22:49:05 by Romain337 Romain337
btw i recall setwindowtitlin' each frame doesnt really help
added on the 2013-07-10 23:14:44 by superplek superplek
Once per second dude, once per second ;)
added on the 2013-07-11 07:55:46 by Romain337 Romain337

login