From ba898560e98196e90cd6cb79078fbf8b29438fad Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 18 Feb 2024 15:15:01 +0100 Subject: [PATCH] Prefer consecutive frames when possible --- client/scenes/stream.cpp | 9 ++++++--- client/scenes/stream.h | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 774f9748..abb857ea 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -30,7 +30,6 @@ #include "utils/named_thread.h" #include "wivrn_packets.h" #include -#include #include #include #include @@ -256,7 +255,7 @@ std::vector scenes::stream::accumulator_images::frames() const return result; } -std::optional scenes::stream::accumulator_images::common_frame(const std::vector & sets) +std::optional scenes::stream::accumulator_images::common_frame(const std::vector & sets, uint64_t preferred_frame) { if (sets.empty()) return {}; @@ -272,6 +271,8 @@ std::optional scenes::stream::accumulator_images::common_frame(const s return {}; } assert(not common_frames.empty()); + if (std::ranges::find(common_frames, preferred_frame) != common_frames.end()) + return preferred_frame; return common_frames.back(); } @@ -369,7 +370,9 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render) std::unique_lock lock(decoder_mutex); // Search for the most recent frame available on all decoders. // If no such frame exists, use the latest frame for each decoder - auto common_frame = accumulator_images::common_frame(decoders); + auto common_frame = accumulator_images::common_frame(decoders, next_frame); + if (common_frame) + next_frame = *common_frame + 1; // Blit images from the decoders // TODO be smarter: group blits per eye, so that the framebuffer can use OP_DONT_CARE instead of OP_LOAD and use the same renderpass if possible for (auto & i: decoders) diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 6bc34b5e..5d82398b 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -54,7 +54,7 @@ private: // latest frames from oldest to most recent std::array, 2> latest_frames; - static std::optional common_frame(const std::vector &); + static std::optional common_frame(const std::vector &, uint64_t preferred_index); std::shared_ptr frame(std::optional id); std::vector frames() const; }; @@ -76,6 +76,7 @@ private: utils::sync_queue shard_queue; std::mutex decoder_mutex; + uint64_t next_frame; // Preferred index for next frame std::vector decoders; // Locked by decoder_mutex std::array decoder_output{};