diff --git a/client/decoder/pyrowave/decoder.cpp b/client/decoder/pyrowave/decoder.cpp index b91fac83..6f519a7f 100644 --- a/client/decoder/pyrowave/decoder.cpp +++ b/client/decoder/pyrowave/decoder.cpp @@ -195,11 +195,21 @@ void decoder::worker_function(uint32_t queue_family_index) })[0])); vk::raii::Fence fence(device, vk::FenceCreateInfo{}); + vk::raii::QueryPool qp( + device, vk::QueryPoolCreateInfo{ + .queryType = vk::QueryType::eTimestamp, + .queryCount = 2, + }); + from_headset::feedback feedback; to_headset::video_stream_data_shard::view_info_t view_info; auto input = std::make_unique(dec); + // Record the encode duration for the previous frame, that's the best we can do + XrDuration last_encode = 0; + float timestamp_period = application::get_physical_device_properties().limits.timestampPeriod; + while (not exiting) { { @@ -215,6 +225,7 @@ void decoder::worker_function(uint32_t queue_family_index) locked->input->clear(); locked->ready = false; } + feedback.received_from_decoder = feedback.sent_to_decoder + last_encode; auto item = get_free(); if (not item) @@ -227,6 +238,8 @@ void decoder::worker_function(uint32_t queue_family_index) dec.device.resetFences(*fence); cmd_buf.reset(); cmd_buf.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit}); + cmd_buf.resetQueryPool(*qp, 0, 2); + cmd_buf.writeTimestamp(vk::PipelineStageFlagBits::eComputeShader, *qp, 0); if (item->current_layout != vk::ImageLayout::eGeneral) { @@ -273,6 +286,7 @@ void decoder::worker_function(uint32_t queue_family_index) {}, barrier); } + cmd_buf.writeTimestamp(vk::PipelineStageFlagBits::eComputeShader, *qp, 1); cmd_buf.end(); application::get_queue().lock()->submit( @@ -309,6 +323,12 @@ void decoder::worker_function(uint32_t queue_family_index) auto res = dec.device.waitForFences(*fence, true, UINT64_MAX); if (res != vk::Result::eSuccess) spdlog::warn("waitForFences failed"); + + std::array times; + res = (*device).getQueryPoolResults( + *qp, 0, 2, sizeof(uint64_t) * 2, times.data(), sizeof(uint64_t), vk::QueryResultFlagBits::eWait | vk::QueryResultFlagBits::e64); + if (res == vk::Result::eSuccess) + last_encode = (times[1] - times[0]) * timestamp_period; } catch (...) {} diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 3956e095..c86ab1a6 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -529,7 +529,8 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p { if (decoder != decoders[stream].decoder.get()) return; - handle->feedback.received_from_decoder = instance.now(); + if (handle->feedback.received_from_decoder == 0) + handle->feedback.received_from_decoder = instance.now(); std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]); }