Game Development Community

T3D vsync broken (Resolved) - RESOLVED

by Ivan Mandzhukov · in Torque 3D Professional · 03/16/2011 (5:31 am) · 18 replies

Hi everybody,
I'm hitting problems when vsync is enabled - the picture motion is very jumpy.
This happens only fullscreen.
I wouldn't like to make fast decisions,but probably it is because of a bad vsync implementation.

1280 X 1024 fullscreen, no vsync - no problems
1280 X 1024 windowed, no vsync - no problems
1280 X 1024 windowed, vsync on - no problems
1280 X 1024 fullscreen, vsync on - jumpy rendering

I have tested this on several PCs and all of them have the same problems,the resolution doesn't matter,even 640 x 480 is jumpy.
I get over 100 fps and the motion is still jumpy.

I did several test with other games,so this is not driver related issues.

#1
03/16/2011 (10:21 am)
Hey Ivan.

Could you please include the specs of the machines you tested this on? That will help me make this a proper ticket.

Thanks!

- Dave
#2
03/16/2011 (11:15 am)
PC1:
Quad Core Q9450
ATI 5670
4 GB RAM

PC2:
Core Duo 2.4 Ghz
ATI Radeon X1950XTX
4 GB RAM

Dave,I did several test to restrict the fps.
In TimeManager::_updateTime() I restricted the sleep time so I can get round about 60Hz (my monitor refresh rate)

S32 msTillThresh = 18 - delta;

Now the rendering is a bit choppy,but the jumpy picture is gone.
That mean this is a serious bug.
#3
03/16/2011 (11:47 am)
i dont understand how you are getting 100fps when your monitor refresh is 60 if vsync is enabled.

have you tried setting the driver to force that particular app to use vsync to see if you have the same problem? ive no idea how to do that on an ATI system however as i'm an nvidia user.

I use vsync almost all of the time and havent seen this issue on either my GTX 260 or GTX 460, maybe is a vendor specific issue lord knows we nvidia users have our share too :P
#4
03/16/2011 (11:56 am)
I get over 100 fps without vsync enabled. It means that I have enough frames.
With vsync enabled I have 60 fps.
In windowed mode with vsync enabled I have 60 fps, but here the problems are gone.
Only fullscreen is the problem.
No vsync = No problems, but the tearing is not an acceptable solution.
#5
03/16/2011 (10:55 pm)
Could you try to replace the TimeManager::_updateTime() function with this one? It solved my jumpy rendering issues. I'm not using Sleep() because is very unprecise. Sometimes takes too long.

void TimeManager::_updateTime()
{
	static HRTimer hrtimer;
	hrtimer.stopTimer();

	while(hrtimer.getElapsedTime()*1000.0<16.667) //60Hz
		hrtimer.stopTimer();

	S32 finalDelta = hrtimer.getElapsedTime()*1000.0;
	hrtimer.startTimer();

	timeEvent.trigger(finalDelta);
}

The HRTimer class can be downloaded from
http://www.cs.up.ac.za/cs/banguelov/blog/HRTimer.h
#6
03/17/2011 (2:05 am)
Well I'm glad that others also see the jumpy frames.
BTW the value of 17 (59 Hz) is removing the jumpy rendering,while 16 (62 Hz) has it: a synchronization issue or a bad frame swapping.

@Francisco
Thanks for your reply,I'll provide several tests with your code today.
#7
03/17/2011 (2:51 am)
I can confirm that this is a workable solution!
Thank you very much,Francisco!
#8
03/17/2011 (3:37 am)
As I said in the thread "Camera movement not tied to actual frame rate?!?!?"
http://www.garagegames.com/community/forums/viewthread/113305/2#comment-801407

This is a non portable solution.

I think the developers of Torque should have take this problem on count.
#9
03/17/2011 (3:58 am)
I remember that Pat Wilson spoke about that GG had the same problem in Marble Blast and they have solved the flickering with something similar..
This seems to be an ancient bug in Torque.
#10
03/17/2011 (4:48 am)
Ivan,
could you share your implementation?
I, for one, would like to use this too.
#11
03/17/2011 (5:19 am)
@deepscratch

The implementation is right there - post #5
Place HRTimer.h in platformWin32 directory

In platformTimer.cpp add:

#include "platformWin32/HRTimer.h"

And replace _updateTime() with the new method.

btw it could be coded this timer to use the refresh value from the prefs.cs
This would allow to be used 75,85 and 100Hz
#12
03/17/2011 (3:04 pm)
what is the #include??

I mean from the download, there is an empty include, and tons of errors,
shouldnt there be a cpp file too?
#13
03/17/2011 (3:27 pm)
just download this file http://www.cs.up.ac.za/cs/banguelov/blog/HRTimer.h

Most likely you haven't included it into the project and that's why you get tons of errors.
No, there is not a cpp file.
#14
03/17/2011 (3:29 pm)
I have included it.

what is this??

#include class HRTimer

wtf?

I just get a jumbled file...


/************************************************************************************ * High Resolution Windows Timer * ----------------------------- * code by : bobby anguelov - banguelov@cs.up.ac.za * downloaded from : takinginitiative.wordpress.org * * code is free for use in whatever way you want, however if you work for a game * development firm you are obliged to offer me a job :P (haha i wish) ************************************************************************************/ #ifndef HRTIMER #define HRTIMER #include class HRTimer { private: LARGE_INTEGER start; LARGE_INTEGER stop; LARGE_INTEGER frequency; LARGE_INTEGER timeElapsed; public: HRTimer() { //get CPU frequency QueryPerformanceFrequency( &frequency ); } void startTimer() { //store initial value QueryPerformanceCounter( &start ) ; } void stopTimer() { //store end value QueryPerformanceCounter( &stop ) ; } double getElapsedTime() { //get elapsed time timeElapsed.QuadPart = stop.QuadPart - start.QuadPart; double elapsedS = (double)timeElapsed.QuadPart / (double)frequency.QuadPart; //return elapsed time in seconds return elapsedS; } }; #endif
#15
03/17/2011 (3:33 pm)
1.Place HRTimer.h into platformWin32
2.Include it in the Project
3.Open platformTimer.cpp.
4.add #include "platformWin32/HRTimer.h" in the beginning of platformTimer.cpp
5.replace the current _updateTime() function with this:

void TimeManager::_updateTime()
{
static HRTimer hrtimer;
hrtimer.stopTimer();

while(hrtimer.getElapsedTime()*1000.0<16.667) //60Hz
hrtimer.stopTimer();

S32 finalDelta = hrtimer.getElapsedTime()*1000.0;
hrtimer.startTimer();

timeEvent.trigger(finalDelta);
}

P.S. HRTimer.h seems to be fine. Just download the file and place it where I told you without editing it or opening it.
#16
03/17/2011 (4:04 pm)
I posted the file above, exactly as it came......

I dont get a download from that link, just a page with that on it....


oooo kkkkk,

right click on the page,
view source.

got it
#17
03/21/2011 (8:42 am)
Greetings!

Logged as THREED-1497. Thanks!

- Dave
#18
10/06/2011 (5:38 pm)
Fixed in 1.2, should be fixed in 1.1 as well.