Allow changing refresh rate during stream
This commit is contained in:
@@ -232,11 +232,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
if (config.preferred_refresh_rate and (config.preferred_refresh_rate == 0 or utils::contains(info.available_refresh_rates, *config.preferred_refresh_rate)))
|
||||
{
|
||||
info.preferred_refresh_rate = *config.preferred_refresh_rate;
|
||||
if (info.preferred_refresh_rate == 0)
|
||||
info.available_refresh_rates = {
|
||||
std::ranges::lower_bound(info.available_refresh_rates, config.minimum_refresh_rate),
|
||||
info.available_refresh_rates.end(),
|
||||
};
|
||||
info.minimum_refresh_rate = config.minimum_refresh_rate.value_or(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -311,7 +311,7 @@ private:
|
||||
void accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps);
|
||||
void gui_performance_metrics();
|
||||
void gui_compact_view();
|
||||
void gui_settings();
|
||||
void gui_settings(float predicted_display_period);
|
||||
void gui_foveation_settings(float predicted_display_period);
|
||||
void gui_applications();
|
||||
void draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "implot.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "utils/ranges.h"
|
||||
#include <IconsFontAwesome6.h>
|
||||
@@ -382,13 +383,81 @@ void scenes::stream::gui_compact_view()
|
||||
}
|
||||
}
|
||||
|
||||
static void send_settings_changed_packet(xr::session & session, wivrn_session * network, const configuration & config, float predicted_display_period)
|
||||
{
|
||||
const auto & refresh_rates = session.get_refresh_rates();
|
||||
from_headset::settings_changed packet{};
|
||||
if (config.preferred_refresh_rate and (config.preferred_refresh_rate == 0 or utils::contains(refresh_rates, *config.preferred_refresh_rate)))
|
||||
{
|
||||
packet.preferred_refresh_rate = *config.preferred_refresh_rate;
|
||||
packet.minimum_refresh_rate = config.minimum_refresh_rate.value_or(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.preferred_refresh_rate = predicted_display_period;
|
||||
}
|
||||
network->send_control(std::move(packet));
|
||||
}
|
||||
|
||||
std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag); // TODO declaration in a .h file
|
||||
void scenes::stream::gui_settings()
|
||||
void scenes::stream::gui_settings(float predicted_display_period)
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20));
|
||||
|
||||
if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
|
||||
{
|
||||
const auto & refresh_rates = session.get_refresh_rates();
|
||||
if (not refresh_rates.empty())
|
||||
{
|
||||
float active_rate = config.preferred_refresh_rate.value_or(refresh_rates.back());
|
||||
if (ImGui::BeginCombo(_S("Refresh rate"), active_rate ? fmt::format("{}", active_rate).c_str() : _cS("automatic refresh rate", "Automatic")))
|
||||
{
|
||||
if (ImGui::Selectable(_cS("automatic refresh rate", "Automatic"), config.preferred_refresh_rate == 0, ImGuiSelectableFlags_SelectOnRelease))
|
||||
{
|
||||
session.set_refresh_rate(0);
|
||||
config.preferred_refresh_rate = 0;
|
||||
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
|
||||
config.save();
|
||||
}
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_("Select refresh rate based on measured application performance.\nMay cause flicker when a change happens."));
|
||||
for (float rate: refresh_rates)
|
||||
{
|
||||
if (ImGui::Selectable(fmt::format("{}", rate).c_str(), rate == config.preferred_refresh_rate, ImGuiSelectableFlags_SelectOnRelease))
|
||||
{
|
||||
session.set_refresh_rate(rate);
|
||||
config.preferred_refresh_rate = rate;
|
||||
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (config.preferred_refresh_rate == 0 and refresh_rates.size() > 2)
|
||||
{
|
||||
float min_rate = config.minimum_refresh_rate.value_or(refresh_rates.front());
|
||||
if (ImGui::BeginCombo(_S("Minimum refresh rate"), fmt::format("{}", min_rate).c_str()))
|
||||
{
|
||||
for (float rate: refresh_rates | std::views::take(refresh_rates.size() - 1))
|
||||
{
|
||||
if (ImGui::Selectable(fmt::format("{}", rate).c_str(), rate == config.minimum_refresh_rate, ImGuiSelectableFlags_SelectOnRelease))
|
||||
{
|
||||
config.minimum_refresh_rate = rate;
|
||||
send_settings_changed_packet(session, network_session.get(), config, predicted_display_period);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (application::get_openxr_post_processing_supported())
|
||||
{
|
||||
ImGui::Text("%s", _S("OpenXR post-processing"));
|
||||
@@ -845,7 +914,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
case gui_status::settings:
|
||||
ImGui::SetCursorPos({tab_width + 20, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
|
||||
gui_settings();
|
||||
gui_settings(predicted_display_period * 1.e-9f);
|
||||
ImGui::EndChild();
|
||||
break;
|
||||
|
||||
|
||||
@@ -221,6 +221,8 @@ struct headset_info_packet
|
||||
uint32_t recommended_eye_height;
|
||||
std::vector<float> available_refresh_rates;
|
||||
float preferred_refresh_rate;
|
||||
// for automatic
|
||||
float minimum_refresh_rate;
|
||||
struct audio_description
|
||||
{
|
||||
uint8_t num_channels;
|
||||
@@ -245,6 +247,13 @@ struct headset_info_packet
|
||||
std::string variant;
|
||||
};
|
||||
|
||||
struct settings_changed
|
||||
{
|
||||
float preferred_refresh_rate;
|
||||
// for automatic
|
||||
float minimum_refresh_rate;
|
||||
};
|
||||
|
||||
struct handshake
|
||||
{
|
||||
// Sending this on TCP means connection will be TCP only
|
||||
@@ -519,6 +528,7 @@ using packets = std::variant<
|
||||
pin_check_1,
|
||||
pin_check_3,
|
||||
headset_info_packet,
|
||||
settings_changed,
|
||||
feedback,
|
||||
audio_data,
|
||||
handshake,
|
||||
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
|
||||
std::optional<from_headset::packets> poll_control(int timeout);
|
||||
|
||||
const wivrn::from_headset::headset_info_packet & info() const
|
||||
wivrn::from_headset::headset_info_packet & info()
|
||||
{
|
||||
return info_packet;
|
||||
}
|
||||
|
||||
@@ -407,6 +407,12 @@ void wivrn_session::operator()(from_headset::headset_info_packet &&)
|
||||
U_LOG_W("unexpected headset info packet, ignoring");
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::settings_changed && settings)
|
||||
{
|
||||
connection->info().preferred_refresh_rate = settings.preferred_refresh_rate;
|
||||
connection->info().minimum_refresh_rate = settings.minimum_refresh_rate;
|
||||
}
|
||||
|
||||
static xrt_device_name get_name(interaction_profile profile)
|
||||
{
|
||||
switch (profile)
|
||||
@@ -902,23 +908,17 @@ struct refresh_rate_adjuster
|
||||
{
|
||||
std::chrono::seconds period{10};
|
||||
std::chrono::steady_clock::time_point next = std::chrono::steady_clock::now() + period;
|
||||
bool enabled;
|
||||
pacing_app_factory & pacers;
|
||||
const from_headset::headset_info_packet & info;
|
||||
from_headset::headset_info_packet & info;
|
||||
float last = 0;
|
||||
|
||||
refresh_rate_adjuster(const from_headset::headset_info_packet & info, pacing_app_factory & pacers) :
|
||||
enabled(info.preferred_refresh_rate == 0 and info.available_refresh_rates.size() > 1),
|
||||
refresh_rate_adjuster(from_headset::headset_info_packet & info, pacing_app_factory & pacers) :
|
||||
pacers(pacers),
|
||||
info(info)
|
||||
{
|
||||
if (enabled)
|
||||
U_LOG_I("Automatic refresh rate adjustment enabled");
|
||||
}
|
||||
info(info) {}
|
||||
|
||||
void adjust(wivrn_connection & cnx)
|
||||
{
|
||||
if (not enabled or std::chrono::steady_clock::now() < next)
|
||||
if (info.preferred_refresh_rate != 0 or info.available_refresh_rates.size() < 2 or std::chrono::steady_clock::now() < next)
|
||||
return;
|
||||
|
||||
// Maximum refresh rate the application can reach
|
||||
@@ -928,7 +928,7 @@ struct refresh_rate_adjuster
|
||||
auto requested = info.available_refresh_rates.back();
|
||||
for (auto rate: info.available_refresh_rates)
|
||||
{
|
||||
if (rate < app_rate * (rate == last ? 1. : 0.9))
|
||||
if (rate > info.minimum_refresh_rate and rate < app_rate * (rate == last ? 1. : 0.9))
|
||||
requested = rate;
|
||||
}
|
||||
if (requested != last)
|
||||
@@ -948,7 +948,7 @@ struct refresh_rate_adjuster
|
||||
|
||||
void wivrn_session::run(std::stop_token stop)
|
||||
{
|
||||
refresh_rate_adjuster refresh(get_info(), app_pacers);
|
||||
refresh_rate_adjuster refresh(connection->info(), app_pacers);
|
||||
while (not stop.stop_requested())
|
||||
{
|
||||
try
|
||||
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
|
||||
clock_offset get_offset();
|
||||
bool connected();
|
||||
const from_headset::headset_info_packet & get_info()
|
||||
const from_headset::headset_info_packet & get_info() const
|
||||
{
|
||||
return connection->info();
|
||||
};
|
||||
@@ -184,6 +184,7 @@ public:
|
||||
void operator()(from_headset::pin_check_1 &&) {}
|
||||
void operator()(from_headset::pin_check_3 &&) {}
|
||||
void operator()(from_headset::headset_info_packet &&);
|
||||
void operator()(from_headset::settings_changed &&);
|
||||
void operator()(from_headset::handshake &&) {}
|
||||
void operator()(from_headset::trackings &&);
|
||||
void operator()(const from_headset::tracking &);
|
||||
|
||||
+4
-1
@@ -512,10 +512,13 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
|
||||
{
|
||||
std::visit(utils::overloaded{
|
||||
[&](const wivrn::from_headset::headset_info_packet & info) {
|
||||
on_headset_info_packet(std::get<wivrn::from_headset::headset_info_packet>(*packet));
|
||||
on_headset_info_packet(info);
|
||||
inhibitor.emplace();
|
||||
wivrn_server_set_headset_connected(dbus_server, true);
|
||||
},
|
||||
[&](const wivrn::from_headset::settings_changed & settings) {
|
||||
wivrn_server_set_preferred_refresh_rate(dbus_server, settings.preferred_refresh_rate);
|
||||
},
|
||||
[&](const wivrn::from_headset::start_app & request) {
|
||||
const auto & apps = list_applications();
|
||||
if (auto it = apps.find(request.app_id); it != apps.end())
|
||||
|
||||
Reference in New Issue
Block a user