Rendering dry run
Version/Branch of Dear ImGui:
docking
Back-ends:
SDL3 + SDL GPU
Compiler, OS:
MSVC 2022
Full config/build information:
No response
Details:
Wondering if there is, or could be a way to make an ImGui tick while making all ImDrawList calls essentially no-op.
ImGui does seem to support headless operation, but building the DrawList is far from free (noticeable enough in my small profiling sessions)
My use-case is down the road to let users build up commands (most likely using the test engine) at runtime, and then tick the application at a rate possibly higher than its refresh rate. In which case I would still require ImGui logic but without the rendering.
I assume that it could be exposed as an ImGui::NewFrame parameter.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response
Setting ImGuiStyleVar_Alpha to 0 will no-op a vast majority of ImDrawList operations.
It has successfully made my app runs faster, but it seems to make BeginChild returns false constantly. Commenting the push/pop code below does affect imgui logic (I am only sure about BeginChild as this broke an important feature of mine, but I wouldn't be surprised if it affected other things)
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.f);
// UI
ImGui::PopStyleVar();
More specifically, this is the child I am creating
constexpr ImGuiWindowFlags child_flags = ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeX | ImGuiChildFlags_ResizeY;
if (ImGui::BeginChild("Compute action", ImVec2(150, 100), child_flags)) {
// Never execute
}
Are you sure it's not related to altering display size in a way that made child window not visible?
BeginChild() return false when clipped/not visible, which is desirable.
Ah right, we indeed have a fast path in Begin() that allow windows to be clipped:
// Don't render if style alpha is 0.0 at the time of Begin(). This is arbitrary and inconsistent but has been there for a long while (may remove at some point)
if (style.Alpha <= 0.0f)
window->HiddenFramesCanSkipItems = 1;
It's rather eager but quite a useful optimization. In what way does a child that's out of sight breaks your logic?
I am making use of the alpha 0.f when pausing, so the app continues ticking without the rendering.
In this case, pausing the app stops BeginChild() from ever returning true (which it did before the pause), I can resume back to make it working again.
I wasn't aware of the child returning false when out of view either, so I guess it is user error and I should move the logic elsewhere.
The way I use it right now I don't think is mandatory, when Autorun is toggled I am essentially simulating a Run click every tick
if (ImGui::Button("Run") || (program.signaled && program.auto_run)) {
// User script
}
Though it does make it a weird edge-case, as I ideally want pausing to have no logic impact at all.
If the window was moved enough for the child to be off-screen it would return true as well, so that auto-run should probably be processed elsewhere.
Replaced BeginChild with ImGui::CollapsingHeader("Compute action") and I am noticing the same issue. Setting the alpha to 0 make it return false, but moving the window out of view still works as expected.
Make me wonder if setting the alpha should be the proper way to handle dry-runs. Guess that I could move all this ticking stuff completely outside of imgui but it would result in a fair amount of duplicated code (and room for error)
I think it is a legitimate idea and I am happy to investigate further.
You may also see all ImGuiStyle colors to zero temporarily, this will have the same effect but without that bug.