diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 5168284b..8fdad3ec 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -34,6 +34,7 @@ #include "boost/pfr/core.hpp" #include "decoder/shard_accumulator.h" #include "hardware.h" +#include "inplace_vector.hpp" #include "spdlog/spdlog.h" #include "utils/contains.h" #include "utils/named_thread.h" @@ -51,6 +52,7 @@ #endif using namespace wivrn; +using namespace beman::inplace_vector; // clang-format off static const std::unordered_map device_ids = { @@ -588,8 +590,7 @@ std::array, 3> scenes::stream::c if (decoders.empty()) return {}; std::unique_lock lock(frames_mutex); - thread_local std::vector common_frames; - common_frames.clear(); + inplace_vector common_frames; const bool alpha = decoders[0].latest_frames[0] and decoders[0].latest_frames[0]->view_info.alpha; for (size_t i = 0; i < view_count + alpha; ++i) { @@ -602,7 +603,7 @@ std::array, 3> scenes::stream::c else { // clang-format off - std::erase_if(common_frames, + erase_if(common_frames, [this, i](auto & left) { return std::ranges::none_of( @@ -615,7 +616,7 @@ std::array, 3> scenes::stream::c // clang-format on } } - std::array, view_count + 1> result; + std::array, decoder_count> result; if (not common_frames.empty()) { auto min = std::ranges::min_element(common_frames, @@ -958,9 +959,9 @@ void scenes::stream::render(const XrFrameState & frame_state) vk::SubmitInfo submit_info; submit_info.setCommandBuffers(*command_buffer); - std::vector semaphores; - std::vector semaphore_vals; - std::vector wait_stages; + inplace_vector semaphores; + inplace_vector semaphore_vals; + inplace_vector wait_stages; for (auto b: current_blit_handles) { if (b and b->semaphore) @@ -1069,8 +1070,8 @@ void scenes::stream::render(const XrFrameState & frame_state) // Network operations may be blocking, do them once everything was submitted { // Keep a copy of the feedback packets as they can be modified if they're encrypted - std::vector feedbacks; - std::vector packets; + inplace_vector feedbacks; + inplace_vector packets; feedbacks.reserve(current_blit_handles.size()); packets.reserve(current_blit_handles.size()); diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 2a526784..f9b37a58 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -53,6 +53,7 @@ public: private: static const size_t view_count = 2; + static const size_t decoder_count = view_count + 1; struct accumulator_images { @@ -68,7 +69,7 @@ private: // for frames inside accumulator images std::mutex frames_mutex; - std::array, view_count + 1> common_frame(XrTime display_time); + std::array, decoder_count> common_frame(XrTime display_time); std::unique_ptr network_session; std::atomic exiting = false; @@ -86,7 +87,7 @@ private: std::shared_mutex decoder_mutex; std::optional video_stream_description; - std::array decoders; // Locked by decoder_mutex + std::array decoders; // Locked by decoder_mutex std::optional defoveator; @@ -162,7 +163,7 @@ private: void update_gui_position(xr::spaces controller); // Keep a reference to the resources needed to blit the images until vkWaitForFences - std::array, view_count + 1> current_blit_handles; + std::array, decoder_count> current_blit_handles; XrTime running_application_req = 0; thread_safe running_applications; @@ -302,7 +303,7 @@ private: float compact_cpu_time = 0; float compact_gpu_time = 0; - void accumulate_metrics(XrTime predicted_display_time, const std::array, view_count + 1> & blit_handles, const gpu_timestamps & timestamps); + void accumulate_metrics(XrTime predicted_display_time, const std::array, decoder_count> & blit_handles, const gpu_timestamps & timestamps); void gui_performance_metrics(); void gui_compact_view(); void gui_settings(float predicted_display_period);