3

I'm currently developing a game using OpenTK for rendering; C#, .Net 4.0, OpenGL 2.

Running maximized (not full screen, but taking up all the available screen space) on 1280x1024 resolution, I'm seeing about 400 FPS average. On 1680x1050 resolution, I'm seeing about 315 FPS average. Despite this high frame-rate, I'm experiencing intermittent stuttering.

Basically, for about 3 full seconds, the rendering will visibly stutter, then it is perfectly smooth for about 0.5 to 1 seconds. This cycle repeats forever.

There is no frame-rate drop showing on my FPS counter in accordance with the stuttering. I'm calculating the frame rate by counting the frames until I reach a desired update frequency, then calculating the frame-rate using the number of ticks in a second, the number of ticks in the update frequency, and the number of frames that were counted. With this method, I only see an update once every split second, but I've never seen the frame-rate drop far below where I would expect it to be.

The issue is exacerbated significantly if I drag the game window to my second display.

Running the application in a Release build did not resolve the issue.

I performance profiled the application using ANTS by redgate. This pointed out a good few issues that I've since fixed.

Any suggestions here?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Kelsie
  • 1,000
  • 1
  • 9
  • 21
  • 1
    My crystal ball says... its line 602 of the main.cs file. – Blindy Dec 24 '10 at 01:41
  • LOL. Thanks. Is there any information I might be able to provide such that you would have more to work with than your crystal ball? – Kelsie Dec 24 '10 at 01:43
  • Well any information is better than no information, but don't expect miracles since we can't profile the entire application for you. Just keep chipping at it with ants until you figure out exactly what's going on when it's spiking. – Blindy Dec 24 '10 at 01:45
  • 1
    I guess I had hoped that somebody (you perhaps?) would suggest something specific to look for in the profiler. The only suspicious thing that I am noticing in the profiler at the moment is that the allocations per second is spiking about every second, but this doesn't seem to coincide well with the 3 second stuttering cycle that I'm seeing. – Kelsie Dec 24 '10 at 15:31
  • Can you describe the "visibly stutter" behavior further? Are you double-buffering? – holtavolt Dec 24 '10 at 04:30
  • During the stutter cycles, anything moving on screen appears to stay still for a barely comprehensible duration of time then jumps to the position it would have been at had the "pause" not occurred. This happens so rapidly that it is just barely noticeable, but enough to be annoying. It doesn't look smooth. I am double buffering. – Kelsie Dec 24 '10 at 15:28
  • Can you simplify your project as far as possible (and still having the described problem) and make it available for download? – Eduard Wirch Feb 06 '14 at 09:27

1 Answers1

3

This kind of stuttering is generally caused by the garbage collector.

Monitor your collection count and check whether they correspond to stuttering periods (call GC.CollectionCount() with 0, 1 and 2 as parameters). If this is indeed the cause, you will need to profile and reduce memory allocations (object pools can help significantly here, as can structures in place of short-lived classes).

As a rule of thumb, you don't want any gen-1 or gen-2 collections during regular gameplay.

Edit: disable the soft frame-limiter (i.e. call Run() or Run(60) but not Run(60, 60)) and enable vsync. This might help reduce stutter.

Additionally, make sure both monitors are synced to the same rate. Even slight differences will introduce stutter when dragging a window from the primary to a secondary monitor (I've seen this happen in differences as small as 60Hz vs 59.9Hz).

The Fiddler
  • 2,726
  • 22
  • 28
  • Thanks for the tips here, I'll check out the garbage collection stuff and see what I come up with. I'm not using the built in OpenTK message pump, so the Run(..., ...) is not applicable. Instead, I've got a dedicated thread for the render loop and I use the standard Application.Run message pump to handle the Form. I'm creating a GraphicsContext in the rendering thread instead of using an OpenTK GLControl or GameWindow. I'll try VSync as well. – Kelsie Dec 25 '10 at 17:42
  • The refresh rate suggestion looks very promising. My main screen's refresh rates can be set to 50 or 60 Hz. My secondary screen's refresh rates can be set to 60, 70, and 75 Hz. If both are set to 60 like it was before, the stuttering is intermittent on and off, as described. If either screen's refresh is changed to something else, the issue is nearly constant, maybe smooth for a split second once in a 10-20 second period. Is there a way to really address this issue? I may open a new question with this specific info and accept your answer here. – Kelsie Dec 27 '10 at 15:05
  • Video drivers always sync to the refresh rate of the first monitor. Is the stutter visible on the first monitor, second monitor or both? – The Fiddler Jan 05 '11 at 00:36