tag:blogger.com,1999:blog-5246987755651065286.post8244852121137874665..comments2024-02-22T16:15:42.388-08:00Comments on cbloom rants: 03-02-09 - Sleep Sucks and VSync Woescbloomhttp://www.blogger.com/profile/10714564834899413045noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-5246987755651065286.post-24449538914204626342010-04-30T07:18:27.122-07:002010-04-30T07:18:27.122-07:00Read your thread with multi CPU's becoming com...Read your thread with multi CPU's becoming common if you SetThreadAffinityMask to issolate your output process thread to a CPU help? By the way this is maddening and has been an issue for a decade. Just shows how stupid MS and Windows really is.Unknownhttps://www.blogger.com/profile/06134724168509686681noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-58778994426124088562010-01-09T18:50:07.225-08:002010-01-09T18:50:07.225-08:00yo having the same problem, i wish vsync could be ...yo having the same problem, i wish vsync could be a non-busy wait :(Unknownhttps://www.blogger.com/profile/11413200282177259936noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-73285127507958529302009-06-05T12:38:59.650-07:002009-06-05T12:38:59.650-07:00I assume this is Nick from meshula?
Yeah, I just ...I assume this is Nick from meshula?<br /><br />Yeah, I just mean "doesn't work" as in "doesn't reliably actually wait for the amount you asked for".<br /><br />If you do the priority-bump trick and timeBeginPeriod() it helps a lot, but it doesn't actually 100% make it reliable.<br /><br />You won't see the bad behavior unless you actually have other threads running (and in particular other threads doing IO).<br /><br />Also, the Waitable Timer fractional precision seems to be a bit of a false promise. I don't think it's actually used at all unless your machine is completely idle. If you actually have to switch from another running thread, it's still done on the scheduler granularity, which is never less than 1 milli.<br /><br />Hell if I could reliably even get 1 milli precision I'd be very happy.cbloomhttps://www.blogger.com/profile/10714564834899413045noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-46540758539850938952009-06-05T12:14:08.004-07:002009-06-05T12:14:08.004-07:00I am curious about what you meant by "doesn&#...I am curious about what you meant by "doesn't work"? I'm guessing that by adding the priority boost, you got a stable result?<br /><br />I'm going to dig through my app and see if I had a lurking priority boost hanging around in a dark corner.Nickhttps://www.blogger.com/profile/07554585746004123227noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-8606058784926841912009-03-23T10:48:00.000-07:002009-03-23T10:48:00.000-07:00"I was wondering, but wouldn't it be easier to jus..."I was wondering, but wouldn't it be easier to just use dynamic timesteps to update everything?"<BR/><BR/>I do use dynamic timesteps, but I still want to hit vsync if possible for various reasons.<BR/><BR/>1. you avoid tearing<BR/><BR/>2. there's no point in rendering faster than vsync<BR/><BR/>3. the game feels better if it's at constant framerate even with very good dynamic timestep support<BR/><BR/>"Further setting the priority in windows is a suggestion."<BR/><BR/>Yeah I mentioned a little about that. It definitely does help, though it makes stability a real risk and it's a pain during development. (partly this is because the damn stupid way that TaskMgr is just a normal process and it's not very high priority)cbloomhttps://www.blogger.com/profile/10714564834899413045noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-18700205037612078192009-03-23T10:38:00.000-07:002009-03-23T10:38:00.000-07:00I was wondering, but wouldn't it be easier to just...I was wondering, but wouldn't it be easier to just use dynamic timesteps to update everything? <BR/>If the user is browsing the web then the application is out of focus which means you can use another update scheme or just reduce the priority all the way and use a different rendering scheme or put a sleep of 100 ms in it to reduce fps to 10. The game time will continue to have the same speed (thanks to deltatime) but since you calculate once every 100 ms you free up the rest of the time.<BR/><BR/>Further setting the priority in windows is a suggestion. If you tell windows that you are time critical (and assuming all the other applications are asleep) it might still not allocate all it's processing power to you. <BR/><BR/>Besides that some cards report that vsync works while they are running far above the vertical refresh speedElonNaraihttps://www.blogger.com/profile/04884079894818615058noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-86218305172379289072009-03-04T15:23:00.000-08:002009-03-04T15:23:00.000-08:00Mmm.. I take that back, maybe WaitableTimer is bet...Mmm.. I take that back, maybe WaitableTimer is better. But the code sample on meshula doesn't work. You have to use the priority boost trick :<BR/><BR/><BR/><BR/> int oldpri = GetThreadPriority( GetCurrentThread() );<BR/> SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );<BR/><BR/> WaitForSingleObject(Timer,INFINITE);<BR/><BR/> SetThreadPriority( GetCurrentThread(), oldpri );<BR/><BR/><BR/>and that actually seems pretty reliable so far.cbloomhttps://www.blogger.com/profile/10714564834899413045noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-20987544034676461152009-03-04T15:20:00.000-08:002009-03-04T15:20:00.000-08:00WaitableTimers don't seem to be any more reliable ...WaitableTimers don't seem to be any more reliable than Sleep()<BR/><BR/>this is what I just got from WaitableTimer :<BR/><BR/>sleepMillis : 14 , actualMillis : 26.492477<BR/>sleepMillis : 15 , actualMillis : 28.600931<BR/>sleepMillis : 15 , actualMillis : 32.035351<BR/>sleepMillis : 15 , actualMillis : 20.810127<BR/>sleepMillis : 15 , actualMillis : 32.970428cbloomhttps://www.blogger.com/profile/10714564834899413045noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-20161387838633171292009-03-04T14:57:00.000-08:002009-03-04T14:57:00.000-08:00What about CreateWaitableTimer? Have you tried tha...What about CreateWaitableTimer? Have you tried that?<BR/><BR/><A HREF="http://meshula.net/wordpress/?p=189" REL="nofollow">http://meshula.net/wordpress/?p=189</A>castanohttps://www.blogger.com/profile/08088335278984724562noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-84004200386162787092009-03-04T01:02:00.000-08:002009-03-04T01:02:00.000-08:00A lot of games have horrible tearing in windowed m...<I>A lot of games have horrible tearing in windowed mode. It seems to me that you could fix this by using the Dx9+ GetRasterStatus calls.</I><BR/><BR/>The popcap framework uses one of those sorts of APIs to do exactly that, try to avoid tearing. I replicated their algorithm for Lost in the Static, but I didn't test on lots of machines so I'm not positive I got it right. I used a DirectDraw function GetScanLine, and blit the window in two pieces; the top piece draws after the raster position reaches the bottom half (but not too close to the bottom edge), and then as soon as the raster pos passes the bottom of the window blit the rest. This scales properly between windowed and fullscreen and would can handle slow blits without tearing, up to the point where the blit takes 1.5 frames to complete, although I eventually added code to allow it to start blitting during vertical blank but that requires the blit to be faster than the refresh, plus actually it looks like it's just broken in that case actually.<BR/><BR/><A HREF="http://rafb.net/p/EhQuLq82.html" REL="nofollow">code snippet</A><BR/><BR/>And I've never tried to make it work for OpenGL windowed apps or such.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-60435290253318566012009-03-03T14:10:00.000-08:002009-03-03T14:10:00.000-08:00Yeah so the Casey method is pretty good I think. ...Yeah so the Casey method is pretty good I think. I still get some bad over-time sleeps though. It helps if I bump the main thread up to HIGHEST all the time. And I think it also helps if I bump the whole Process priority class up.<BR/><BR/>Basically the goal is that the main rendering loop is super high priority so it only gives up time when it really wants to.<BR/><BR/>This does have two disadvantages though :<BR/><BR/>1. It increases the latency of IO because now IO really only runs in the time slot where you yield to the worker thread. Ideally you could let it get some IO's started earlier in the frame and then have it sleep waiting for them to finish, and it could process them in the time slot you give it later.<BR/><BR/>2. You have to worry about starvation and getting behind. Because you're only giving up the little time gap that you can afford to give up without missing framerate, if you aren't rendering fast enough so you keep giving up too little time, your background work can keep building up and up. Now you need some heuristic to go ahead and eat a big hitch and flush the processing queues.<BR/><BR/>Sigh.cbloomhttps://www.blogger.com/profile/10714564834899413045noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-87069031512422944542009-03-03T13:58:00.000-08:002009-03-03T13:58:00.000-08:00Yeah I linked to Casey's post, there's a lot of st...Yeah I linked to Casey's post, there's a lot of stuff he gets right in there.<BR/><BR/>One is that if you let your machine speedstep, all bets are off. That sucks because I would like to let my lappy chill out, but it doesn't seem possible. So you need a super low priority thread to just spin.<BR/><BR/>The other thing is about the priorities and the thread switching. Maybe one reason Windows was seeing those particular weird priority issues is because of the boosting :<BR/><BR/>http://msdn.microsoft.com/en-us/library/ms684828(VS.85).aspx<BR/><BR/>Presumably the background thread is getting stuff like IO Completions which will give it a boost and mess up what you're trying to accomplish.<BR/><BR/>I guess one issue is that Windows schedules threads *globally* - so if you want your threads to really get the time slices you ask for, you may need to bump up all your priorities so that you're higher than everything else in the system.cbloomhttps://www.blogger.com/profile/10714564834899413045noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-61276653955894074222009-03-03T13:53:00.000-08:002009-03-03T13:53:00.000-08:00Urg I need to fix the damn blogger putting things ...Urg I need to fix the damn blogger putting things out of order.cbloomhttps://www.blogger.com/profile/10714564834899413045noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-76975242424652564702009-03-03T12:34:00.000-08:002009-03-03T12:34:00.000-08:00Reminds me a bit of this:https://mollyrocket.com/f...Reminds me a bit of this:<BR/><BR/>https://mollyrocket.com/forums/viewtopic.php?t=520<BR/><BR/>Also, I'm curious if SwitchToThread helps you at all.<BR/><BR/>http://msdn.microsoft.com/en-us/library/ms686352(VS.85).aspxwon3dhttps://www.blogger.com/profile/09787472194187459747noreply@blogger.com