imgui performance window

feature/softbody-runtime-control
Benjamin Kraft 3 months ago
parent 47e5367219
commit 1695940c6a
  1. 10
      imgui.ini
  2. 8
      include/application.hpp
  3. 40
      src/application.cpp

@ -23,5 +23,15 @@ Pos=153,27
Size=353,999 Size=353,999
Collapsed=0 Collapsed=0
[Window][Test]
Pos=1246,20
Size=249,166
Collapsed=0
[Window][Performance]
Pos=1617,2
Size=302,1002
Collapsed=0
[Docking][Data] [Docking][Data]

@ -42,7 +42,13 @@ public:
void mainLoop(); void mainLoop();
~Application(); ~Application();
private: private:
void initIMGUI(); void imGuiWindows();
struct PerformanceInformation {
float totalUpdateDuration;
float updateDuration;
float frameDuration;
} performanceInformation {};
void createSyncObjects(); void createSyncObjects();
unique_ptr<Semaphore> imageAvailable; unique_ptr<Semaphore> imageAvailable;

@ -141,8 +141,6 @@ Application::Application() {
void Application::mainLoop() { void Application::mainLoop() {
vkDeviceWaitIdle(Instance::GetDevice()); vkDeviceWaitIdle(Instance::GetDevice());
std::future compute = std::async(std::launch::async, [this](){ std::future compute = std::async(std::launch::async, [this](){
setbuf(stdout, NULL);
descriptorPool->bindBuffer(*vertexBuffers[1 - currentDrawVertexBuffer], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, DescriptorSet::MESH, 0);
while (!glfwWindowShouldClose(Instance::instance->window)){ while (!glfwWindowShouldClose(Instance::instance->window)){
auto t1 = system_clock::now(); auto t1 = system_clock::now();
update(); update();
@ -152,27 +150,19 @@ void Application::mainLoop() {
auto requestedUpdateDuration = duration<float>(simulationPropertiesBuffer->access<SimulationUniformData>().dt); auto requestedUpdateDuration = duration<float>(simulationPropertiesBuffer->access<SimulationUniformData>().dt);
std::this_thread::sleep_for(requestedUpdateDuration - measuredUpdateDuration); std::this_thread::sleep_for(requestedUpdateDuration - measuredUpdateDuration);
auto totalUpdateDuration = std::max(requestedUpdateDuration, measuredUpdateDuration); performanceInformation.updateDuration = measuredUpdateDuration.count();
printf("\r%f", totalUpdateDuration.count()); performanceInformation.totalUpdateDuration = std::max(requestedUpdateDuration, measuredUpdateDuration).count();
} }
}); });
bool show_demo_window = true;
auto t1 = system_clock::now(); auto t1 = system_clock::now();
while (!glfwWindowShouldClose(Instance::instance->window)){ while (!glfwWindowShouldClose(Instance::instance->window)){
glfwPollEvents(); glfwPollEvents();
imGuiWindows();
ImGui_ImplVulkan_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::ShowDemoWindow(&show_demo_window);
ImGui::Render();
auto t2 = system_clock::now(); auto t2 = system_clock::now();
float seconds = duration<float>(t2 - t1).count(); float seconds = duration<float>(t2 - t1).count();
performanceInformation.frameDuration = seconds;
t1 = system_clock::now(); t1 = system_clock::now();
drawFrame(seconds); drawFrame(seconds);
} }
@ -180,9 +170,7 @@ void Application::mainLoop() {
vkDeviceWaitIdle(Instance::GetDevice()); vkDeviceWaitIdle(Instance::GetDevice());
} }
Application::~Application() { Application::~Application() = default;
}
void Application::createSyncObjects() { void Application::createSyncObjects() {
imageAvailable = make_unique<Semaphore>(); imageAvailable = make_unique<Semaphore>();
@ -377,7 +365,9 @@ void Application::drawFrame(float dt) {
uint32_t imageIndex; uint32_t imageIndex;
VkResult result = vkAcquireNextImageKHR(Instance::GetDevice(), swapchain->handle, UINT64_MAX, imageAvailable->handle, VK_NULL_HANDLE, &imageIndex); VkResult result = vkAcquireNextImageKHR(Instance::GetDevice(), swapchain->handle, UINT64_MAX, imageAvailable->handle, VK_NULL_HANDLE, &imageIndex);
if (result == VK_ERROR_OUT_OF_DATE_KHR){ if (result == VK_ERROR_OUT_OF_DATE_KHR){
submitMutex.lock();
swapchain->recreateSwapchain(); swapchain->recreateSwapchain();
submitMutex.unlock();
return; return;
} }
@ -443,6 +433,7 @@ void Application::drawFrame(float dt) {
recordDrawCommands(cmdBuffer); recordDrawCommands(cmdBuffer);
ImGui::Render();
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmdBuffer); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmdBuffer);
vkCmdEndRenderPass(cmdBuffer); vkCmdEndRenderPass(cmdBuffer);
@ -484,7 +475,9 @@ void Application::drawFrame(float dt) {
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || Instance::instance->windowResized){ if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || Instance::instance->windowResized){
Instance::instance->windowResized = false; Instance::instance->windowResized = false;
submitMutex.lock();
swapchain->recreateSwapchain(); swapchain->recreateSwapchain();
submitMutex.unlock();
} }
} }
@ -710,3 +703,16 @@ void Application::recordNormalCommands(VkCommandBuffer cmdBuffer) {
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &barrier, 0, nullptr, 0, nullptr); vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &barrier, 0, nullptr, 0, nullptr);
} }
void Application::imGuiWindows() {
ImGui_ImplVulkan_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::Begin("Performance");
ImGui::Text("Update time: %f", performanceInformation.updateDuration);
ImGui::Text("Updates per second: %f", 1 / performanceInformation.totalUpdateDuration);
ImGui::Text("Frame time: %f", performanceInformation.frameDuration);
ImGui::Text("Frames per second: %f", 1 / performanceInformation.frameDuration);
ImGui::End();
}

Loading…
Cancel
Save