Add compositor timings to debug GUI
This commit is contained in:
@@ -205,6 +205,13 @@ vk::Extent3D render_extent(const wivrn::from_headset::headset_info_packet & info
|
|||||||
namespace wivrn
|
namespace wivrn
|
||||||
{
|
{
|
||||||
|
|
||||||
|
void compositor::timings::add(float us)
|
||||||
|
{
|
||||||
|
int index = this->index;
|
||||||
|
this->index = (this->index + 1) % values.size();
|
||||||
|
values[index] = us;
|
||||||
|
}
|
||||||
|
|
||||||
xrt_result_t compositor::predict_frame(int64_t * out_frame_id,
|
xrt_result_t compositor::predict_frame(int64_t * out_frame_id,
|
||||||
int64_t * out_wake_time_ns,
|
int64_t * out_wake_time_ns,
|
||||||
int64_t * out_predicted_gpu_time_ns,
|
int64_t * out_predicted_gpu_time_ns,
|
||||||
@@ -286,6 +293,9 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
|
|||||||
cmd.reset();
|
cmd.reset();
|
||||||
cmd.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
|
cmd.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
|
||||||
|
|
||||||
|
cmd.resetQueryPool(*query_pool, 0, 3);
|
||||||
|
cmd.writeTimestamp(vk::PipelineStageFlagBits::eTopOfPipe, *query_pool, 0);
|
||||||
|
|
||||||
bool flip_y = false;
|
bool flip_y = false;
|
||||||
std::array<vk::ImageView, 2> src;
|
std::array<vk::ImageView, 2> src;
|
||||||
std::array<xrt_rect, 2> src_rect;
|
std::array<xrt_rect, 2> src_rect;
|
||||||
@@ -340,7 +350,9 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
|
|||||||
.srcStageMask = vk::PipelineStageFlagBits2::eComputeShader,
|
.srcStageMask = vk::PipelineStageFlagBits2::eComputeShader,
|
||||||
.srcAccessMask = vk::AccessFlagBits2::eShaderStorageWrite,
|
.srcAccessMask = vk::AccessFlagBits2::eShaderStorageWrite,
|
||||||
.dstStageMask = vk::PipelineStageFlagBits2::eComputeShader,
|
.dstStageMask = vk::PipelineStageFlagBits2::eComputeShader,
|
||||||
.dstAccessMask = vk::AccessFlagBits2::eShaderStorageRead,
|
.dstAccessMask = vk::AccessFlagBits2::eShaderSampledRead,
|
||||||
|
.oldLayout = vk::ImageLayout::eGeneral,
|
||||||
|
.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||||
.image = squasher.get_image(),
|
.image = squasher.get_image(),
|
||||||
.subresourceRange = {
|
.subresourceRange = {
|
||||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||||
@@ -370,6 +382,8 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
|
|||||||
});
|
});
|
||||||
image_barriers.clear();
|
image_barriers.clear();
|
||||||
|
|
||||||
|
cmd.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||||
|
|
||||||
if (session.get_info().eye_gaze)
|
if (session.get_info().eye_gaze)
|
||||||
{
|
{
|
||||||
auto now = os_monotonic_get_ns();
|
auto now = os_monotonic_get_ns();
|
||||||
@@ -413,6 +427,7 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
|
|||||||
.imageMemoryBarrierCount = uint32_t(image_barriers.size()),
|
.imageMemoryBarrierCount = uint32_t(image_barriers.size()),
|
||||||
.pImageMemoryBarriers = image_barriers.data(),
|
.pImageMemoryBarriers = image_barriers.data(),
|
||||||
});
|
});
|
||||||
|
cmd.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
|
||||||
|
|
||||||
cmd.end();
|
cmd.end();
|
||||||
|
|
||||||
@@ -460,7 +475,25 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
|
|||||||
.pValues = &sem_value,
|
.pValues = &sem_value,
|
||||||
},
|
},
|
||||||
U_TIME_1S_IN_NS) == vk::Result::eTimeout)
|
U_TIME_1S_IN_NS) == vk::Result::eTimeout)
|
||||||
|
{
|
||||||
U_LOG_IFL_W(log_level, "compositor timeout");
|
U_LOG_IFL_W(log_level, "compositor timeout");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto [res, ts] = query_pool.getResults<uint64_t>(
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
3 * sizeof(uint64_t),
|
||||||
|
sizeof(uint64_t),
|
||||||
|
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait);
|
||||||
|
|
||||||
|
if (res == vk::Result::eSuccess)
|
||||||
|
{
|
||||||
|
static const auto period = vk.physical_device.getProperties().limits.timestampPeriod;
|
||||||
|
squasher_times.add((ts[1] - ts[0]) * period / 1e3);
|
||||||
|
foveation_times.add((ts[2] - ts[1]) * period / 1e3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now is a good point to garbage collect.
|
// Now is a good point to garbage collect.
|
||||||
comp_swapchain_shared_garbage_collect(&cscs);
|
comp_swapchain_shared_garbage_collect(&cscs);
|
||||||
@@ -564,6 +597,10 @@ compositor::compositor(wivrn_session & session) :
|
|||||||
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
||||||
.queueFamilyIndex = vk.queue_family_index,
|
.queueFamilyIndex = vk.queue_family_index,
|
||||||
}),
|
}),
|
||||||
|
query_pool(vk.device, vk::QueryPoolCreateInfo{
|
||||||
|
.queryType = vk::QueryType::eTimestamp,
|
||||||
|
.queryCount = 3,
|
||||||
|
}),
|
||||||
settings(get_encoder_settings(vk, session)),
|
settings(get_encoder_settings(vk, session)),
|
||||||
images{make_images(vk, cmd_pool, settings)},
|
images{make_images(vk, cmd_pool, settings)},
|
||||||
cmd{std::move(vk.device.allocateCommandBuffers({.commandPool = *cmd_pool, .commandBufferCount = 1})[0])},
|
cmd{std::move(vk.device.allocateCommandBuffers({.commandPool = *cmd_pool, .commandBufferCount = 1})[0])},
|
||||||
@@ -619,12 +656,17 @@ compositor::compositor(wivrn_session & session) :
|
|||||||
encoders[i] = video_encoder::create(vk, settings, i);
|
encoders[i] = video_encoder::create(vk, settings, i);
|
||||||
send_video_stream_description();
|
send_video_stream_description();
|
||||||
|
|
||||||
|
u_var_add_root(this, "Compositor", false);
|
||||||
|
u_var_add_f32_timing(this, &squasher_times.var, "layers processing");
|
||||||
|
u_var_add_f32_timing(this, &foveation_times.var, "foveation");
|
||||||
|
|
||||||
// Start the thread after everything is initialized
|
// Start the thread after everything is initialized
|
||||||
encoder_thread = std::jthread{[&](std::stop_token t) { encoder_work(t); }};
|
encoder_thread = std::jthread{[&](std::stop_token t) { encoder_work(t); }};
|
||||||
}
|
}
|
||||||
|
|
||||||
compositor::~compositor()
|
compositor::~compositor()
|
||||||
{
|
{
|
||||||
|
u_var_remove_root(this);
|
||||||
encoder_thread.request_stop();
|
encoder_thread.request_stop();
|
||||||
encode_request = -2;
|
encode_request = -2;
|
||||||
encode_request.notify_all();
|
encode_request.notify_all();
|
||||||
|
|||||||
@@ -58,10 +58,31 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct timings
|
||||||
|
{
|
||||||
|
std::array<float, 50> values{};
|
||||||
|
int index = 0;
|
||||||
|
u_var_timing var{
|
||||||
|
.values = {
|
||||||
|
.data = values.data(),
|
||||||
|
.index_ptr = &index,
|
||||||
|
.length = int(values.size()),
|
||||||
|
},
|
||||||
|
.range = 1000,
|
||||||
|
.dynamic_rescale = true,
|
||||||
|
.unit = "µs",
|
||||||
|
};
|
||||||
|
|
||||||
|
void add(float us);
|
||||||
|
};
|
||||||
|
|
||||||
const u_logging_level log_level;
|
const u_logging_level log_level;
|
||||||
|
timings squasher_times;
|
||||||
|
timings foveation_times;
|
||||||
wivrn_session & session;
|
wivrn_session & session;
|
||||||
vk_bundle vk;
|
vk_bundle vk;
|
||||||
vk::raii::CommandPool cmd_pool;
|
vk::raii::CommandPool cmd_pool;
|
||||||
|
vk::raii::QueryPool query_pool;
|
||||||
|
|
||||||
std::array<encoder_settings, 3> settings;
|
std::array<encoder_settings, 3> settings;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user