Imgui: Dear ImGui FPS starting high and falling to 0

Created on 11 Dec 2019  路  10Comments  路  Source: ocornut/imgui

Version: v1.74
Branch: master
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Operating System: Windows10

I have been using ImGui for a while in my project and it got pretty big. However, recently I noticed that the fps counter ImGui is reading from metrics starts at around 400fps and drops... forever. I left it on for about 10 minutes and came back and it was at 24fps. I decided to figure out what the problem was (since I hadn't checked the fps in a while I couldn't narrow it down to recent changes.) I eventually decided to delete all the code I am using for ImGui and test.

Here is my ImGui/OpenGL related startup code:

glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(MessageCallback, 0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();

ImGuiStyle* style = &ImGui::GetStyle();
style->Colors[ImGuiCol_WindowBg].w = 1;

ImGui_ImplGlfw_InitForOpenGL(_window, true);
ImGui_ImplOpenGL3_Init("#version 460");

and here is the code for the rendering function (all my code for ImGui (~300lines) is in a function called _setupImGui() but it is commented out)

glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

//_setupImGui();
ImGui::Render();
VOFOG_CORE_LOG("{}",ImGui::GetIO().Framerate);

ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

glfwSwapBuffers(_window);

The FPS started at about 400 and steadily falls to about 144fps.. then it hangs there for about 10 seconds and then falls to 60fps and then exponentially slower continues to fall. After 10 min of running it lands at around 25fps and after 20 min its at about 22 fps. My game loop however runs at 250+fps. The things being rendered are smooth and fast but the ImGui client is completely stalling. I didn't alter any of the files of ImGui so I am unsure how this could be happening since I am not really using ImGui in the ran code.

Also, if I render my full ImGui code or do what I have above (which renders nothing intentionally) it seems to drop fps at same rate.

backenbinding

Most helpful comment

You were right, I was sending more items to ImGui in flush and only resetting the objects sent in for the application render but not for ImGui so it was getting bogged down.

All 10 comments

Hello,

Please first confirm if it happens with a vanilla (100% unmodified) version of examples_glfw_opengl3.

Also try to update your GPU drivers. They are often drivers bugs for OpenG under Windows.

It doesn't happen on a clean build. I removed the files I was using that caue fps issues and replaced them with the clean build files and I still have the same issue. The ImGui files are ALL unedited. I have all updated drivers as well. I found out it happens when I try to render anything through my batch renderer. This is the code that causes the drop in fps. If i comment this out, it runs fine:

for(int i = 0; i < _layers.size(); i++){
    if(_useRenderableShader)
        _layers[i]->render();
    if(_useGuiShader)
        _layers[i]->render(_guiShader);
    }
}

I have to comment out _layers[i]->render(_guiShader); For this code to not cause massive drops in fps.
That render function runs with a default shader if you don't give it a shader; the gui shader is a shader that uses a geometry shader to create an outline of the objects rendered by the _layers[i]->render();

void render(ShaderProgram& shader) override{
m_shaderProgram->use();
m_renderer->begin();
m_shaderProgram->setUniformMat4("u_vertexMVP", &m_camera->getCombinedMatrix()[0][0]);

for(int i = 0; i < m_renderables.size(); i++)
    m_renderer->submit(m_renderables[i]);
m_renderer->end();
m_renderer->flush();

The submit, begin, flush, end etc all simply bind buffers and map data to buffers. I have 0 idea why this would be causing massive issues.

Thanks for clarifying.
The bottom line is that it seems this is not an issue with dear imgui nor it's imgui_impl_opengl3.cpp back-end, but probably something in your code, however mysterious?

My code is very simple I am unsure how my code could run at 250fps+ but the ImGui side is struggling. Is there some type of way I need to order the layering of my shaders to not interfere with ImGui?

I wrote a test where I only render ONE thing. My FPS for my application is at 120 and 250 for application.

This is with most the ImGui editor I wrote not in(just enough to get this test running.) After 15 seconds of running the ImGui fps went from 350 to 142. I don't know if this helps but every single time I run the program the fps steadily falls until it reaches 144. It always gets stuck there for 5-10 seconds and then rapidly falls. It does this every single time.

I'm not sure I understand what you are saying in e.g.

My game loop however runs at 250+fps. The things being rendered are smooth and fast but the ImGui client is completely stalling.

The framerate is calculated from the io.DeltaTime value passed by the back-end which is simply calling glfwGetTime(), it's not an "ImGui framerate", it is essentially reflecting the framerate of your application...

(Is 144 Hz the refresh rate of your monitor? If you were to wait for vsync (which is recommended) it is natural that your throtlled framerate would cap at 144 FPS.)

My gut feeling is that your _useGuiShader bit is causing an issue in your system and that has nothing to do with dear imgui.

I wrote a test where I only render ONE thing. My FPS for my application is at the top left and right next to it is the FPS counted for ImGui

Another gut feeling is your application FPS is actually wrong here, or you are messing with imgui_impl_glfw calls in a very unusual way (not calling ImGui_ImplOpenGL3_NewFrame() every frame of your application etc.)

What I mean is my render loop runs 250 frames per second and with moving objects in the scene it looks very smooth. But when I mess with ImGui after its been running for a while(like the color picker) it looks super skipping around at 20fps. This may because I force my update to continue until it catches up to the render time (i.e. update runs more times than render if it falls behind game logic)

Whatever you are doing wrong, it doesn't seem to be related to dear imgui...

The fact that your own calculated FPS doesn't match the one derived by dear imgui from raw time value also suggested your own calculated FPS may be wrong in the first place. If you are trying to play catchup between render/logic and your times are wrong it's probably not a good thing.

You were right, I was sending more items to ImGui in flush and only resetting the objects sent in for the application render but not for ImGui so it was getting bogged down.

Was this page helpful?
0 / 5 - 0 ratings