Skip to content
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

Only render on changes #5340

Closed
rajdevsharma opened this issue May 23, 2022 · 2 comments
Closed

Only render on changes #5340

rajdevsharma opened this issue May 23, 2022 · 2 comments

Comments

@rajdevsharma
Copy link

Version/Branch of Dear ImGui:

Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx12.cpp + imgui_impl_win32.cpp
Compiler: Visual Studio 2022
Operating System: Windows

My Issue/Question:

I am working on using ImGui for a desktop application. Since it redraws at 60fps, it uses a lot of GPU %, and I was wondering if it is possible to make it so that it only redraws when something actually changes.

I have done this in previous applications I have built which were built based on OpenGL. Basically, I constructed a list of render commands each frame, and diff'd it against the commands from the prior frame. If they were the same, then I skipped the render. While this does use a little bit of CPU, it is well worth it to save the GPU the work of redrawing the whole frame.

Would it be feasible to do something like this with ImGui? If so, maybe I might take a stab at it if I get time. In theory, since ImGui just comes up with lists of things to draw, I'd imagine it is possible, but just curious if you might know any reason it couldn't be done.

Before posting this I tried to research if someone had asked the same thing, but I didn't see an exact version of my question (apologies if I missed it). I saw some different posts mentioning different ideas for power saving modes, but I didn't see my idea of diffing the draw lists.

Some of the suggestions I saw:

  • Render only on input, or if there is an animation - Another Power Saving Mode #5116. This seems like the best solution so far, but it requires the code notifying when animations are happening.
  • Another one which renders only on inputs and has some provision for animations - Added power saving mode #2749. To me it seems like it has the same issue that it requires components to specify when animations are happening.

These solutions are a little more efficient than what I'm looking to do, because they don't require diffing the draw lists each frame. However, I'd like something which is foolproof - from the perspective of the coder, I'd rather not have to worry about whether I remembered to trigger a render or not. I've worked on apps in the past where there would be tricky bugs due to forgetting to re-render, so I like the idea of just attempting a render 60 times a second, and then only sending to the GPU when it actually changed.

@ocornut
Copy link
Owner

ocornut commented May 23, 2022

but just curious if you might know any reason it couldn't be done.

Of course it could be done, you would simply need to deep-hash ImDrawData and skip rendering if it is the same.
You can include an early-out optimization for the case where things changed, by first hashing the ImDrawCmd without the vertices, since this is more likely to change, and then only if the same you can hash the vertex and index buffers.

We're probably going to finish and merge #4076 / #2749 at some point (or other equivalent PR).

@rajdevsharma
Copy link
Author

Cool, thanks a lot for the suggestions on how to implement this!

Ah, that's great to know those PRs may be finished/merged at some point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants