perf stuff

This commit is contained in:
2023-01-16 02:10:57 +01:00
parent 99354918f7
commit a62ee9f811
5 changed files with 110 additions and 8 deletions

View File

@@ -448,6 +448,12 @@ int startImgui(ImGuiCallbacks& callbacks, const char* title, int windowWidth, in
ImGui_ImplVulkan_DestroyFontUploadObjects();
}
PerfTimer setupTimer{};
PerfTimer drawTimer{};
PerfTimer renderTimer{};
PerfTimer displayTimer{};
int drawCounter = IMGUI_REDRAW_COUNT;
// Main loop
while (!glfwWindowShouldClose(window))
{
@@ -456,7 +462,18 @@ int startImgui(ImGuiCallbacks& callbacks, const char* title, int windowWidth, in
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
glfwPollEvents();
if (false && drawCounter == 0)
{
glfwWaitEvents();
drawCounter = IMGUI_REDRAW_COUNT;
}
else
{
glfwPollEvents();
drawCounter--;
}
setupTimer.Start();
// Resize swap chain?
if (g_SwapChainRebuild)
@@ -480,6 +497,9 @@ int startImgui(ImGuiCallbacks& callbacks, const char* title, int windowWidth, in
ImVec2 prevWindowSize = getWindowSize(window);
drawData.window_size = prevWindowSize;
setupTimer.End();
drawTimer.Start();
if (callbacks.drawFunc)
{
callbacks.drawFunc(drawData);
@@ -490,8 +510,12 @@ int startImgui(ImGuiCallbacks& callbacks, const char* title, int windowWidth, in
glfwSetWindowSize(window, drawData.window_size.x, drawData.window_size.y);
}
drawTimer.End();
renderTimer.Start();
// Rendering
ImGui::Render();
ImDrawData* draw_data = ImGui::GetDrawData();
const bool is_minimized = (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f);
if (!is_minimized)
@@ -501,8 +525,21 @@ int startImgui(ImGuiCallbacks& callbacks, const char* title, int windowWidth, in
wd->ClearValue.color.float32[2] = drawData.clear_color.z * drawData.clear_color.w;
wd->ClearValue.color.float32[3] = drawData.clear_color.w;
FrameRender(wd, draw_data);
renderTimer.End();
displayTimer.Start();
FramePresent(wd);
displayTimer.End();
}
else
{
renderTimer.End();
}
drawData.frameTimeSetup = setupTimer.resultSeconds;
drawData.frameTimeDraw = drawTimer.resultSeconds;
drawData.frameTimeRender = renderTimer.resultSeconds;
drawData.frameTimeDisplay = displayTimer.resultSeconds;
}
// Cleanup