-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
High CPU usage on FreeBSD #6043
Comments
If you're getting 500FPS it means you're uncapped. You haven't shared code however, but if you're using glfw and opengl3, you want to cap glfw's swap interval. See https://www.glfw.org/docs/3.3/group__context.html#ga6d4e0cdf151b5e579bd67f13202994ed You'll want to call this function with a value of 1. |
Either rely on vsync to tie your framerate to monitor refresh rate, or add a timing/waiting mechanism to throttle your framerate to an arbitrary refresh rate. Please note that Dear ImGui and those examples are coming from a background of game programming, where people tend to refresh the entire display many times a seconds (typically 60 FPS). If you don't have an underlying game engine running in the background, you may be interested in rendering at slower and variable framerate to tend toward 0 cost on idle. It is possible to load lazy rendering (some references #2749 #4076 #5599) not currently out of the box but possible to setup yourself if you understand the underlying system. Future version should make it easier and better supported out of the box. |
The code I'm talking about is in the examples and I see it is enabling vsync. Sorry for not being more clear in the first place. Is there anything I'm missing? Thank you! |
Thanks for confirming. |
OK, but can I do something to figure out what's wrong on my system? Or is there an easy way to limit ImGui renders to like 60 FPS or something? I'm just not good enough GUI developer. |
If you can't get vsync working the more imprecise way of doing this is to sleep manually instead. Something like this void update_loop() {
float time = read_time();
// update imgui, etc here
float delta_time = read_time() - time;
float time_to_sleep_sec = (1.0f / 60.0f) - delta_time;
sleep(time_to_sleep_sec);
} I haven't included any error checking, but the idea here is that you calculate how much time all your update code took including dear imgui and then you sleep your CPU to the delta up to 16.666 ms (60 fps) That being said getting vsync working is a better approach and the above should be seen as a workround |
If |
Same problem when I use Wayland and/or if I use sdl+opengl. I guess the problem is deeper in the OpenGL on FreeBSD. If I find the solution, I'll post it here. |
You may want to also try Vulkan. I'll close this issue as non being Dear ImGui specific, but happy to hear if you find something. |
Finally found some free time to fiddle with this and using vulkan gives expected results. For some reason I believed vulkan is only for AMD. Thank you for the tip and I will probably switch to vulkan as a more recent standard. |
Version/Branch of Dear ImGui:
Version: 1.89.2
Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: Clang 13.0
Operating System: FreeBSD
My Issue/Question:
FPS is not the one of the display. Depending on the situation, it gets as high as 500 FPS and it's killing the CPU. If you could help me narrow it down, I would be grateful. Just for reference
xrandr | grep '*+'
output is1366x768 60.00*+
Screenshots/Video
Standalone, minimal, complete and verifiable example: (see #2261)
The text was updated successfully, but these errors were encountered: