We are developing interactive 3D applications using OpenGL 4, relying on glfw (3.3.8) to get the window the the OpenGL context.
On my environment, I get noticeable stuttering. I decided to try the glfw samples (provided in glfw repo) and observe the same behaviour. It does not seem to be the cases on the other developers’ machines (which have largely different hardware). My setup is Windows 10, 1080 Ti, drivers 516.94.
To confirm my observations, I ran the samples in Nvidia Nsight Systems 2022.3.4. Turns out there are two different kinds of stuttering:
- Very long (> 100ms)
_glfwCreateContextWGL() missing a frame-period (16.6ms) deadline.
I also measured some nvpro OpenGL samples from github (sorry, I am a new user, so I can only put one link in my post…)
I realized those samples are creating a custom OpenGL context on Windows. So I tried to replicate this custom context in my application. This seems to completely eliminate stuttering type 2, but the type 1 (
glClear()) is still present.
I am running out of idea to try and solve this blocking call to glClear(). Any guidance on how to address the issue or further test I could run to better understand the issue would be greatly appreciated!
Here is a complete report of my attempts and measures so far, as well as screenshots of the Nsight timelines.
Thank you for the detailed description and analysis.
It is a bit hard to give any advice without actually looking at your code that causes the issues.
glClear() only causes these kind of issues if there is a synchronization issue somewhere in the code. Some problems can be solved by using explicit
glFinish() calls. But other than that you should check if any of your buffers affected by the
glClear() might be blocked by some CPU or memory access.
Now how this might be connected to your specific Hardware setup, that is even more difficult to assess. The only thing that might come to mind is if you have an integrated GPU with your CPU and you still have OpenGL drivers installe dthat are using that GPU. But apart from that your setup is very standard and should not cause any problems.
Thank you for taking the time to post an answer.
Interestingly, it turns out that even a trivial application using the Win32 API directly (without glfw) has the
glClear() issue. Thus I made a minimal example showing the problem, which can be found here:
All the code fits in
We ran this minimal example in
Nsight Systems on a two other systems:
- A laptop with an Intel video card, and there is no stuttering at all.
- Another desktop equipped with a 2060, and
glClear() exhibit the same blocking patterns as on my environment.
(edit: None of the desktop machines have integrated GPUs, only one discrete video card).
Also interestingly, these blocking calls always seem to occur around 2 seconds and 28 seconds, on both Nvidia systems.