Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Slows when GLControl Out of View #28

Open
sdreb3421 opened this issue Sep 3, 2022 · 11 comments
Open

Application Slows when GLControl Out of View #28

sdreb3421 opened this issue Sep 3, 2022 · 11 comments
Labels
4.0 bug Something isn't working needs verification
Milestone

Comments

@sdreb3421
Copy link

sdreb3421 commented Sep 3, 2022

Setup:
Windows 10 Pro 21H2.
OpenGL 3.3 core running on a NVIDIA GeForce GTX 1050.
Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz CPU
WinForms NET 6
OpenTK 4.7.4
OpenTK.WinForms 4.0.0-pre-6

Issue:
When the parent form of the GLControl is minimized, or the GLControl is hidden from view on an unseen tab page of a tab control, the refresh rate of OpenGL drops from 2ms to ~33ms. Additionally, the entire application UI runs about 20x slower than normal. Completely unrelated child forms that normally open in ~250ms to open take ~5 seconds to open.

Notes:
This issue did not occur when using NET 4.8 with the original GLControl. The only obvious difference with the NET 4.8 GLControl version is that VSync was set to False (VSync property does not exist with new version).

@sdreb3421 sdreb3421 changed the title Frame Rate Drops when GLControl Out of View Application Slows when GLControl Out of View Sep 3, 2022
@seanofw
Copy link
Collaborator

seanofw commented Sep 5, 2022

This seems odd, but I haven't done a lot with the GLControl and background threads. Your notes seem to suggest that maybe there's runaway window messaging going on. Does the CPU usage spike as well when the refresh rate or performance drops?

Also, can you describe a little about what hardware you're running on? Which version of Windows (presumably this is Windows?), CPU, GPU, etc?

@sdreb3421
Copy link
Author

sdreb3421 commented Sep 5, 2022

I only notice an increase in CPU when opening up a child form while the GLControl is out of view. Normally it would take 1 core an additional 10% for a very short period, but when the issue is happening the 1 core goes up 10% for 5 seconds.

@sdreb3421
Copy link
Author

I could probably make a demo project. Would that be helpful in this scenario?

@sdreb3421
Copy link
Author

sdreb3421 commented Sep 6, 2022

I found that the slowdown is associated with the NVIDIA GPU. When the application is set to use the INTEL GPU the issue goes away. Additionally, it happens equally when using the UI thread or a background thread for OpenTK drawing.

Check out the demo project and video below. The video shows how the frame rate changes when switching between tabs (hiding the GLControl), first illustrating INTEL and second illustrating NVIDIA.

I've tried changing between the NVIDIA Game Ready and Studio drivers (516.94) with the same result. I've also tried messing with other NVIDIA control panel settings (PhysX, etc) with the same result.

If you have a NVIDIA GPU I'd be curios if you could reproduce this using the demo below.

OpenTkDemo.zip

OpenTK.Graphics.Card.Demo.mp4

@sdreb3421
Copy link
Author

UPDATE: Tested on another computer with a NVIDIA RTX 2070 and the issue is not present.

@sdreb3421
Copy link
Author

All of the delay happens in the swap buffers line. If I downloaded the OpenTK source is there anything that might be debuggable inside of the swap buffers method, or is this an unsolvable driver issue of some sort?

@seanofw
Copy link
Collaborator

seanofw commented Sep 7, 2022

Ouch. Sadly, no, SwapBuffers() forwards pretty directly through OpenTK and GLFW, and goes directly into the video driver. If you're experiencing slowdowns there, it's a driver issue and there's not much that can be done about it other than detecting when the panel is in a hidden tab and then not rendering.

@NogginBops
Copy link
Member

Definitely a weird issue. My recommendation/workaround is just to avoid submitting drawcalls for stuff that isn't going to appear on the screen. You can just avoid calling SwapBuffers entirely when the control isn't shown.

@sdreb3421
Copy link
Author

That's doable. The only other difference in API from the original is the ability to set Vsync. Probably not related, but is there a way to set this in OpenTK 4?

@NogginBops
Copy link
Member

OpenTK 4 NativeWindow has a setting for this, but I don't know if this would work for this control.
I would have to delegate that question to @seanofw for now.

@NogginBops
Copy link
Member

I'll look into enabling VSync in GLControl for 4.0 release.
Opening a separate issue for that in #36

@NogginBops NogginBops added bug Something isn't working 4.0 needs verification labels Oct 10, 2023
@NogginBops NogginBops added this to the 4.0 milestone Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.0 bug Something isn't working needs verification
Projects
None yet
Development

No branches or pull requests

3 participants