High GPU usage even when drawing nothing on the window, and even with framerate limiting

I’m using Windows 10 and a GTX 980 Ti. Here’s my code:

#include<iostream>
#include<glad/glad.h>
#include<GLFW/glfw3.h>

int windowWidth = 800;
int windowHeight = 800;

int main()
{
    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
    
    GLFWwindow* window = glfwCreateWindow(windowWidth, windowHeight, "OpenGL", NULL, NULL);
    glfwMakeContextCurrent(window);

    gladLoadGL();
    glViewport(0, 0, windowWidth, windowHeight);

    glfwSwapInterval(1);

    while (!glfwWindowShouldClose(window))
    {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

I’m using GLFW-3.3.5. When I run this code on my machine, the GPU usage stat on task manager stays at 3-4% for a few seconds, then quickly starts climbing to 20% and stays at 20% once it gets there. This isn’t a case of the GPU working as quickly as it can, because glfwSwapInterval(1) is enabled, and I’m getting 144 FPS. I feel like since I’m drawing literally nothing, and only swapping the buffer, the GPU usage shouldn’t be at 20%. Anyone know why this is happening? Sorry if this is annoying or has already been answered before

Questions:

  • You do have the latest released version of NVIDIA’s graphics drivers installed, correct?
  • What’s your monitor’s display rate? 60Hz? 120Hz? See Display Settings or NVIDIA Control Panel.
  • Are you overriding the app’s VSync policy in the NVIDIA Control Panel to be VSync OFF (SwapInterval 0)? If so, stop doing that so the app can run VSync ON (SwapInterval 1).
  • How do you know you’re getting 144 fps?
  • Run a CPU profiler like VerySleepy to confirm where all of your time is being spent.

You appear do not to be rendering to a full-screen window. Keep in mind with this that your rendered window contents aren’t displayed directly. They need to pass through the compositor, and be composited and re-rendered with the entire content of your display/monitor. Depending on your system, driver, and compositor setup, this might take more GPU than you think. Fullscreen focused windows (on single-GPU systems) can generally bypass much of this overhead, and latency.

1 Like

Thanks for responding!

  1. I do have the newest drivers installed.
  2. It’s at 144hz.
  3. I have vertical sync set to “use the 3D application’s setting”. When I set it to just “On”, it still climbed to 20%, but it took way longer, like 10 or 15 seconds, before it actually started climbing there from 4%.
  4. I measured it by incrementing an int by 1 every frame and setting a timer in the main loop with glfwGetTime() that outputs and reset the int to 0 at the end of every second. It outputted 144 or 145 every second. Also, the Alt+Z Geforce Experience overlay said it was running at 144 fps.
  5. Most of the CPU time is being spent in WaitForSingleObjectEx and DwmFlush. I selected these two and pressed “profile selected”, and a whole bunch of shit appeared that I don’t know what means. I can post a screenshot of this if needed.

I set the window to fullscreen and the size to 1920x1080 and the issue was fixed. The GPU usage stayed at 2-3% the entire time. Thank you

@Dark_Photon It seems setting the program to fullscreen has given birth to a brand new problem.
I checked Task Manager while running this, and while the GPU usage was indeed fixed, the CPU usage was at 12-16% the whole time. I ran VerySleepy and pressed Profile All, and got these results (this is just from the top):


I looked it up, and people have had problems with high CPU usage from RtlUserThreadStart before, but I didn’t actually find any solutions, and they were all just marked as bugs of the original program they were found on. Also, the graph looks pretty similar on the old windowed program, except there are less entries between RtlUserThreadStart and my int main() function.
Any ideas?

Sorry for the delay. Have been out on-break.

Some good ideas here. Search for RtlUserThreadStart. Anyway, doesn’t sound like an OpenGL driver problem.

And for DrvValidateVersion, this thread suggests it may be associated with running in Flip presentation mode (fullscreen focused window on single-GPU) on Windows.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.