virabhadra's picture

Performance problem in the fullscreen mode

Hello together!

My program makes a scene with flying particles based on one idea from one example. I already don't remember where it goes from.
I use OpenTK.GameWindow

And now I have a strange (at least for me) performance problem.

1 case:
The program starts in full screen mode, it works smooth and nice, but after some seconds the CPU load increases and uses permanently one core for 100%. (see picture 1)

2 case:
If I start the program and immediately switch to another window (f.e. task manager) putting the GL-window to work on the background, but still visible behind, it doesn't load CPU, only some percents. (see pictire 2).
I tested it and during many minutes it works constantly with very low CPU load.

The behavior doesn't depend on a number of objects: same for 50 and 5000 particles.

P.S.
I cannot load the code example. It writes me that the spam filter is triggered.
I will try to upload it to a comment.

Inline Images
picture 1
picture 2

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
virabhadra's picture

retrocopy.com/blog/29/nvidia-threaded-optimization-oxymoron.aspx

winterhell's picture

The threaded optimization indeed increases the CPU usage, but it also increases the amount of draw calls you can make per second.
I didnt like the integrated vsync behaviour so I used a Stopwatch to measure the elapsed frame time, do sleep for the whole number of left milliseconds, and then an empty loop to squeeze out the rest of the cycles. It makes about 1-2% CPU usage on 1 Core tops.

virabhadra's picture

What kind of timer do you use for stopwatch:
System.Timers
System.Threading
System. Windows.Forms

?

mominur's picture

.-+*+-.thanks for all friend.-+*+-.

winterhell's picture
virabhadra wrote:

What kind of timer do you use for stopwatch:
System.Timers
System.Threading
System. Windows.Forms

?

Not a timer but a System.Diagnostics.Stopwatch
You time the interval to Update, Render and SwapBuffer your frame, then see if you have some time left for the current frame( if you have a target framerate that is), and then make it Sleep and stuff.

virabhadra's picture

How to get the actual monitor frequency?
I tried to investigate the question. I have found only that this is not easy in C# and there is no built-in OpenTK functions getting this value.
The OpenTK functions return only the resulting frequency of the application.

Definitions related to my example:

// in Main():
	GL4_Window w = new GL4_Window();
	w.Run();
 
//  in class "GL4_Window : GameWindow":
	Stopwatch sw = new Stopwatch();
	int system_interval;
 
// in the class constructor:
	VSync = VSyncMode.On;
 
	system_interval = (int) (1000d / 60d);
	sw.Start();
 
// in "OnRenderFrame" function:
	sw.Stop();
	int dt = sw.Elapsed.Milliseconds;
	if(system_interval > dt)
		System.Threading.Thread.Sleep(system_interval - dt);
	sw.Reset();
	sw.Start();

I have defined the value "system_interval" as round(1000 ms / 60 Hz), but the monitor frequency may be different.

the Fiddler's picture

OpenTK.DisplayDevice.GetDisplay(int)

virabhadra's picture

Thank you, it's grate!