Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: High FPS unstable frametimes?  (Read 11125 times)

0 Members and 1 Guest are viewing this topic.

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
High FPS unstable frametimes?
« on: October 19, 2015, 11:08:31 pm »
I've been searching for several hours, and tweaking my code, trying to determine exactly what's causing my problem, but to no avail.

I've been spending the past few days tweaking my game and making it frame-rate independent, and running into frametime inconsistencies that I can't seem to eliminate. I've been working on implementing a time step like that described in Gaffer's "Fix your timestep" article (fixed physics update intervals, variable rendering w/ interpolation), and I understand the loop inside and out, but I for some reason can't eliminate some timing discrepancies.

I've commented out every game loop aspect besides
1) Calculating frametime (to determine how many fixed-interval physics updates to calculate per cycle)
2) Basic drawing of debug info. And I've even tried not printing the debug info, and still I get spikes(just printing spikes to the console).

No matter what pollrate and fps settings I use, I still get frametime spikes every 5-6 seconds or so. This is manageable, considering the game adjusts for the increased frametime, and updates the physics more times per cycle to compensate, but the noticeable hitching when frametimes sometimes spike above 50-70 ms (I'm trying to have stability at 144 fps, so 7-8 ms) is very irritating, and I can't seem to figure out why this is happening.

I am not using setFrameRateLimit at the moment (my experience is that it limits the speed of the whole thread, and this caused some inconsistencies for me), but even when setting the framerate limit, I still get  frame time spikes. Enabling vsync yielded less overall spikes, but the spikes were far higher (sometimes 80+ ms). I can provide my code if needed, but again, literally all it is doing is calculating frametime (at the pollrate, 60-150 times a second, depending on my settings), and drawing debug info (60-144 fps, depending). I have also tried calculating frametimes with millisecond and microseconds, and both still get frametime spikes.

Does anyone have experience running SFML games stable at high refresh rates? Is this a threading problem?
I wasn't sure if multi-threading would solve my problem, but am certainly more than willing to try it at this point, as I'm at my wits' end.

Any help would be greatly appreciated.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10853
    • View Profile
    • development blog
    • Email
High FPS unstable frametimes?
« Reply #1 on: October 19, 2015, 11:49:24 pm »
First off multi-threading won't solve anything in most likely would make things only worse. ;)

What's your OS, GPU, etc?
Is your GPU driver uptodate?
Do you experience the same issue in release mode?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: High FPS unstable frametimes?
« Reply #2 on: October 20, 2015, 12:06:56 am »
First off multi-threading won't solve anything in most likely would make things only worse. ;)
Yeah that's what I figured. I did notice that 1 core is running at 99%, with drop-offs whenever I get frametime spikes. I wouldn't assume that it's a CPU throttling issue though, is that right?; Does SFML typically run a single core at high usage like that?

And for specs, I'm on Windows 10 with a 980Ti, drivers are up to date.

You did clue me in that I had been running in release mode this entire time! Yikes! Running in debug mode actually yielded less spikes overall, but there are still occasions where I get 50+ms for several game ticks, before returning to regular times for another ~20 seconds or so.

I'll try experimenting with pollrate and fps settings in debug, see if that helps. And perhaps this is the wrong place to ask, but what is the difference between debug and release mode? I assume VS keeps a closer eye on system resources and the like in debug mode?

Thank you for your help!

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: High FPS unstable frametimes?
« Reply #3 on: October 20, 2015, 12:57:25 am »
Still getting spikes :/ No changing to fps or pollrates has fixed it, debug or release mode. It seems almost as if the whole program is "hiccuping" with CPU performance, and then goes right back to normal.

Not game-breaking by any means, but I'm trying to work my way up from the most baseline performance issues, and back to the regular working state of my game before I start re-adding stuff that could further reduce overall performance. Cpu usage on core 0 stays at 99%, then drops to 50% or so when the program has a frametime spike, then hops back up to 99% again.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10853
    • View Profile
    • development blog
    • Email
Re: High FPS unstable frametimes?
« Reply #4 on: October 20, 2015, 02:03:40 am »
What if you disable multi-threaded rendering in your GPU driver's settings?

It sounds a bit like the OS is pausing your application on the CPU for a bit, but not sure why. Then again at best you use some profiling tool to figure out where exactly the time is spent.

Does SFML typically run a single core at high usage like that?
Well by not limiting your framerate in  anyway, you're telling the CPU to run as fast as possible, which then obviously will try to max out one core.

And perhaps this is the wrong place to ask, but what is the difference between debug and release mode? I assume VS keeps a closer eye on system resources and the like in debug mode?
If you don't know the difference, you might want to learn a few more things about your toolchain etc.
A debug build contains debug information, like symbols information. Additionally it usually is also not optimized and more of a 1:1 translation of the code. This makes it possible to step through the full source code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: High FPS unstable frametimes?
« Reply #5 on: October 20, 2015, 02:33:41 am »
What if you disable multi-threaded rendering in your GPU driver's settings?

Well by not limiting your framerate in  anyway, you're telling the CPU to run as fast as possible, which then obviously will try to max out one core.
Yeah, went ahead and disabled multi-threaded rendering, and capped the SFML frame rate (just to make sure it's not needlessly adding to the timecounter every cpu cycle). Same problem. :/

And yes, I really should take the time to properly learn VS. I've been using C++ for a while, but I'm brand new to VS, there's a lot going on haha.
I'll see what I can do as far as profiling, thanks for the suggestions.

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: High FPS unstable frametimes?
« Reply #6 on: October 20, 2015, 02:47:31 am »
Interestingly enough, task manager and resource monitor both list the game as constantly not responding...

Also, if I open a program while the game is running, it immediately causes a reproducible spasm of frametime jumps (which I guess is actually pretty typical of many games, to a certain extent). Raising the priority of the game in task manager also has no effect

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: High FPS unstable frametimes?
« Reply #7 on: October 20, 2015, 03:18:41 am »
Interestingly enough, task manager and resource monitor both list the game as constantly not responding.
That sounds like you are not processing events regularly.

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: High FPS unstable frametimes?
« Reply #8 on: October 20, 2015, 03:27:37 am »
That sounds like you are not processing events regularly.
Ah, thank you, I was wondering which part of my debug commenting caused that to start happening. I wanted to eliminate as many performance barriers as possible in my game loop when testing this problem.

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: High FPS unstable frametimes?
« Reply #9 on: October 20, 2015, 06:44:32 am »
Yeah still no luck :/ If anyone has any sort of CPU monitoring tools in mind that might help me resolve this weird issue, it would be greatly appreciated (or rather, what exactly to google).

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: High FPS unstable frametimes?
« Reply #10 on: October 20, 2015, 06:53:02 am »
You're using Visual Studio, right? It has a profiler built in.

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: High FPS unstable frametimes?
« Reply #11 on: October 20, 2015, 08:26:07 am »
You're using Visual Studio, right? It has a profiler built in.
Ah, thank you, that's a really cool part of VS I've never even explored!

I discovered that when in windowed mode, whenever I move the window, the game stops responding, and whenever I let go/release the window, it resumes, and catches up the time that was lost.

I noticed that in the CPU usage analytics, window events seem to be the only functions called. Does this mean I should be putting my game loop within the loop that is just responsible for polling window events, or finding a way to bail out of checking too many events? (i:e moving the window so much, it never gets out of the window event poll loop) That doesn't seem right, but those are the only function calls during my game's periodic "blackouts". That being said, commenting out my window event polling loop still gives me the original small frametime spikes, just not the larger, reproducible ones (because I can't actually move the window without the event polling...).

I also tried requesting window focus whenever it is lost, but that doesn't seem to work, either (it doesn't actually even request the focus until the window returns back to it's normal responsive state). So it looks like the small frametime spikes I've been having are some sort of window-focus related issue.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10853
    • View Profile
    • development blog
    • Email
High FPS unstable frametimes?
« Reply #12 on: October 20, 2015, 08:33:21 am »
Do you have any controllers/joysticks plugged in?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MrSoupSox

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: High FPS unstable frametimes?
« Reply #13 on: October 20, 2015, 10:06:31 am »
Do you have any controllers/joysticks plugged in?
Nope, neither of those. Tried disabling and turning off most background programs as well

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: High FPS unstable frametimes?
« Reply #14 on: October 21, 2015, 12:15:49 am »
Although I agree that spikes are unpleasant. You do realize that that you can never elliminate such spikes - right? So you have to be prepared to deal with them.
Yes, if SFML is causing unneeded spikes, then that's a bug to be fixed. But just the fact that there are spikes - that's not a bug in itself. You can never count on a stable frame rate..