Report real predicted display time

This commit is contained in:
Patrick Nicolas
2024-03-07 17:20:46 +01:00
parent 16b993a81c
commit f5d73d33f4
4 changed files with 26 additions and 13 deletions
+6 -7
View File
@@ -532,10 +532,9 @@ static VkResult comp_wivrn_present(struct comp_target * ct,
}
assert(cn->psc.images[index].status == image_acquired);
cn->frame_index++;
// set bits to 1 for index 1..num encoder threads + 1
cn->psc.images[index].status = (1 << (cn->encoder_threads.size() + 1)) - 2;
cn->psc.images[index].frame_index = cn->frame_index;
cn->psc.images[index].frame_index = cn->current_frame_id;
auto & view_info = cn->psc.images[index].view_info;
view_info.display_time = cn->cnx->get_offset().to_headset(desired_present_time_ns).count();
@@ -582,7 +581,7 @@ static void comp_wivrn_calc_frame_pacing(struct comp_target * ct,
*out_desired_present_time_ns,
*out_present_slop_ns,
*out_predicted_display_time_ns);
*out_frame_id = cn->current_frame_id;
*out_frame_id = cn->current_frame_id++;
}
static void comp_wivrn_mark_timing_point(struct comp_target * ct,
@@ -591,22 +590,22 @@ static void comp_wivrn_mark_timing_point(struct comp_target * ct,
uint64_t when_ns)
{
struct wivrn_comp_target * cn = (struct wivrn_comp_target *)ct;
assert(frame_id == cn->current_frame_id);
assert(frame_id + 1 == cn->current_frame_id);
cn->pacer.mark_timing_point(point, frame_id, when_ns);
switch (point)
{
case COMP_TARGET_TIMING_POINT_WAKE_UP:
cn->cnx->dump_time("wake_up", cn->frame_index + 1, when_ns);
cn->cnx->dump_time("wake_up", frame_id, when_ns);
break;
case COMP_TARGET_TIMING_POINT_BEGIN:
cn->cnx->dump_time("begin", cn->frame_index + 1, when_ns);
cn->cnx->dump_time("begin", frame_id, when_ns);
break;
case COMP_TARGET_TIMING_POINT_SUBMIT_BEGIN:
break;
case COMP_TARGET_TIMING_POINT_SUBMIT_END:
cn->cnx->dump_time("submit", cn->frame_index + 1, when_ns);
cn->cnx->dump_time("submit", frame_id, when_ns);
break;
default:
assert(false);
+2 -5
View File
@@ -51,7 +51,7 @@ struct pseudo_swapchain
vk::raii::CommandBuffer command_buffer = nullptr;
yuv_converter yuv;
uint8_t status; // bitmask of consumer status, index 0 for acquired, the rest for each encoder
uint64_t frame_index;
int64_t frame_index;
to_headset::video_stream_data_shard::view_info_t view_info{};
};
std::vector<item> images;
@@ -68,10 +68,7 @@ struct wivrn_comp_target : public comp_target
float fps;
int64_t current_frame_id;
// Monotonic counter, for video stream
uint64_t frame_index = 0;
int64_t current_frame_id = 0;
pseudo_swapchain psc;
+11 -1
View File
@@ -55,7 +55,7 @@ void wivrn_pacer::predict(
out_wake_up_time_ns = next_frame_ns;
out_desired_present_time_ns = out_wake_up_time_ns + mean_wake_up_to_present_ns;
out_present_slop_ns = 0;
out_predicted_display_time_ns = out_desired_present_time_ns;
out_predicted_display_time_ns = out_desired_present_time_ns + mean_present_to_display_ns;
}
void wivrn_pacer::on_feedback(const xrt::drivers::wivrn::from_headset::feedback & feedback, const clock_offset & offset)
@@ -109,6 +109,15 @@ void wivrn_pacer::on_feedback(const xrt::drivers::wivrn::from_headset::feedback
next_frame_ns -= frame_duration_ns / 1000;
}
}
if (feedback.displayed)
{
auto & when = in_flight_frames[feedback.frame_index % in_flight_frames.size()];
if (when.frame_id == feedback.frame_index)
{
mean_present_to_display_ns = std::lerp(mean_present_to_display_ns, offset.from_headset(feedback.displayed) - when.present_ns, 0.1);
when.frame_id = 0;
}
}
}
void wivrn_pacer::mark_timing_point(
comp_target_timing_point point,
@@ -134,5 +143,6 @@ void wivrn_pacer::mark_timing_point(
//! Just after submitting work to the GPU.
case COMP_TARGET_TIMING_POINT_SUBMIT_END:
mean_wake_up_to_present_ns = std::lerp(mean_wake_up_to_present_ns, when_ns - last_wake_up_ns, 0.1);
in_flight_frames[frame_id % in_flight_frames.size()] = {.frame_id = uint64_t(frame_id), .present_ns = when_ns};
}
}
+7
View File
@@ -36,6 +36,7 @@ class wivrn_pacer
uint64_t frame_duration_ns;
uint64_t mean_wake_up_to_present_ns = 0;
uint64_t mean_present_to_display_ns = 0;
uint64_t last_wake_up_ns = 0;
@@ -48,6 +49,12 @@ class wivrn_pacer
};
std::vector<stream_data> streams;
struct frame_history{
uint64_t frame_id;
uint64_t present_ns;
};
std::array<frame_history, 4> in_flight_frames;
public:
wivrn_pacer(uint64_t frame_duration) :
next_frame_ns(0),