UltravioletFramework / ultraviolet

The Ultraviolet Framework is a .NET game development framework written in C#.
https://github.com/UltravioletFramework/ultraviolet/wiki
MIT License
541 stars 46 forks source link

Reocurring frame drop every second. #143

Closed fireball87 closed 3 years ago

fireball87 commented 3 years ago

I am having issues running on linux, but haven't verified that it reproduces in windows. I get frame drops once a second seconds, where time to draw jumps above to around 17ms. This would miss a frame at 60 slightly, but drops several at a higher frame rate which I am used to drawing at.

Reproducing this is easy at least on my machine, open the sample project for uvgame. turn IsFixedTimeStep and SynchronizeWithVerticalRetrace to false

Then throw this in the draw section to test.

            System.Console.WriteLine($"ticks since last draw {time.ElapsedTime.Ticks}," +
                                         $" {GC.CollectionCount(0)}, {GC.CollectionCount(1)}, {GC.CollectionCount(2)}");

At least for me, the general draw happens incredibly frequently as there's no real code in this sample, but for some reason once every almost exactly a second you'll get a 17 or 18ms frame.

This causes some pretty unpleasant jitters for me.

I can reproduce this using 2021.5.0.4563 (which the samples use) and current (which I use). I could not reproduce this in 2020.40.0.4287 (which the samples use).

It doesn't appear to have anything to do with Garbage Collections (which shouldn't happen much in an empty game but I tested when trying to figure it out in my own game).

It also doesn't appear to have anything to do with sleep times (which shouldn't happen in this configuration).

tlgkccampbell commented 3 years ago

Are you using an NVIDIA graphics device?

fireball87 commented 3 years ago

Yes

tlgkccampbell commented 3 years ago

I've seen similar behavior on Windows that I could only fix by disabling "threaded optimzations" in the NVIDIA driver. I have no idea if a similar issue exists on Linux. If this is the same issue, I was never able to figure out a good fix for it.

fireball87 commented 3 years ago

There appears to be a __GL_THREADED_OPTIMIZATION environment variable you can set to control this, but setting it in either direction doesn't affect this. I will make a test windows build and see if the issue happens there too, and if it does if the NVIDIA setting fixes it there.

fireball87 commented 3 years ago

From my windows tests, I do not reproduce this issue in my game at all from what I can tell. I do get periodic cases (maybe once every 5 seconds) where frame-times are in that similarly high 17-18ms but there's a lot of stuff that could be. Turning off the threading optimization there just makes me slightly miss a lot of frames instead.

fireball87 commented 3 years ago

Since this doesn't occur on windows, I'm gonna close this and not worry about it until I can create some way of figuring out more what the issue is, as I'm going to focus on things that are more relevant in the immediate (I develop on windows but my customer base isn't there at this moment).