Add performance metrics plot

This commit is contained in:
Guillaume Meunier
2024-02-18 09:03:46 +01:00
parent e51a195f2c
commit 2e53f91f93
19 changed files with 518 additions and 156 deletions
+41 -2
View File
@@ -501,6 +501,7 @@ void application::initialize_vulkan()
#endif
vk_physical_device = xr_system_id.physical_device(vk_instance);
physical_device_properties = vk_physical_device.getProperties();
spdlog::info("Available Vulkan device extensions:");
for(vk::ExtensionProperties & i: vk_physical_device.enumerateDeviceExtensionProperties())
@@ -826,6 +827,21 @@ void application::initialize()
vk_cmdpool = vk::raii::CommandPool{vk_device, cmdpool_create_info};
// Create timestamp queries
query_pool = vk::raii::QueryPool(vk_device, vk::QueryPoolCreateInfo{.queryType = vk::QueryType::eTimestamp, .queryCount = 6});
query_command_buffers = vk_device.allocateCommandBuffers(vk::CommandBufferAllocateInfo{.commandPool = *vk_cmdpool, .commandBufferCount = 6});
for(int i = 0; i < 6; i+=2)
{
query_command_buffers[i].begin({});
query_command_buffers[i].resetQueryPool(*query_pool, i, 2);
query_command_buffers[i].writeTimestamp(vk::PipelineStageFlagBits::eTopOfPipe, *query_pool, i);
query_command_buffers[i].end();
query_command_buffers[i+1].begin({});
query_command_buffers[i+1].writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, i+1);
query_command_buffers[i+1].end();
}
initialize_actions();
interaction_profile_changed();
@@ -1026,7 +1042,6 @@ void application::loop()
}
else
{
auto scene = current_scene();
if (scene)
{
@@ -1041,7 +1056,31 @@ void application::loop()
last_scene = scene;
}
scene->render();
XrFrameState framestate = xr_session.wait_frame();
auto t1 = std::chrono::steady_clock::now();
vk_queue.submit(vk::SubmitInfo{
.commandBufferCount = 1,
.pCommandBuffers = &*query_command_buffers[(current_query%3) * 2],
}, nullptr);
scene->render(framestate.predictedDisplayTime, framestate.shouldRender);
last_scene_cpu_time = std::chrono::steady_clock::now() - t1;
vk_queue.submit(vk::SubmitInfo{
.commandBufferCount = 1,
.pCommandBuffers = &*query_command_buffers[(current_query%3) * 2 + 1],
}, nullptr);
current_query = current_query + 1;
if (current_query > 3)
{
auto [res, timestamps] = query_pool.getResults<uint64_t>((current_query%3)*2, 2, 2 * sizeof(uint64_t), sizeof(uint64_t), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait);
if (res == vk::Result::eSuccess)
last_scene_gpu_time = std::chrono::nanoseconds((int)((timestamps[1] - timestamps[0]) * physical_device_properties.limits.timestampPeriod));
}
}
else
{