Page 1 of 1

opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

Posted: 21 Nov 2023, 14:21
by dengfan
Hello, everyone:

I have tried multiple versions of native SDK + opengl on windows, integrated glud or glfw, x86 or x64, and finally the generated exe has a high CPU usage when it runs.

But after the other samples are compiled, the CPU usage is very, very low, most of the time 0%.

Why is that?
How do I fix this?
2023-11-21 211209.png

Re: opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

Posted: 21 Nov 2023, 14:39
by jsantos
The IntegrationGLUT example is always using OpenGL while the other examples take by default Direct3D (you can override this with --render GL). For some reasons, your GL driver is disabling vsync, this could be the reason of high cpu usage. You can debug the source code of GLRenderContext, the Init() function take the boolean vsync for enabling vertical sync.

Re: opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

Posted: 22 Nov 2023, 08:26
by dengfan
The IntegrationGLUT example is always using OpenGL while the other examples take by default Direct3D (you can override this with --render GL). For some reasons, your GL driver is disabling vsync, this could be the reason of high cpu usage. You can debug the source code of GLRenderContext, the Init() function take the boolean vsync for enabling vertical sync.
After testing, it is indeed a problem with vsync.
I switched to GLFW,
add under line code,
glfwSwapInterval(1); 
and the problem was fixed.

Thanks very much!

Re: opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

Posted: 22 Nov 2023, 19:22
by jsantos
Our GLUT implementation in the IntegrationGLUT sample is already doing:
typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int);
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT != 0)
{
    wglSwapIntervalEXT(1);
}
I assume this was not working on your machine?

Re: opengl + native sdk, Why "IntegrationGLUT" sample High CPU usage when running

Posted: 24 Nov 2023, 11:35
by dengfan
Our GLUT implementation in the IntegrationGLUT sample is already doing:
typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int);
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT != 0)
{
 wglSwapIntervalEXT(1);
}
I assume this was not working on your machine?
Yes, this didn't work under GLUT, so I switched to GLFW