diff --git a/client/application.cpp b/client/application.cpp index 2ed1cba6..243b73d8 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -882,17 +882,14 @@ void application::initialize() spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE); config.emplace(xr_system_id); - if (xr_instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME)) + try { - try - { - xr_session.set_refresh_rate(config->preferred_refresh_rate); - } - catch (std::exception & e) - { - spdlog::warn("failed to set refresh rate to {}: {}", config->preferred_refresh_rate, e.what()); - config->preferred_refresh_rate = 0; - } + xr_session.set_refresh_rate(config->preferred_refresh_rate); + } + catch (std::exception & e) + { + spdlog::warn("failed to set refresh rate to {}: {}", config->preferred_refresh_rate, e.what()); + config->preferred_refresh_rate = 0; } if (hand_tracking_supported) diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 69f00c58..a8124c77 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -1227,6 +1227,8 @@ void scenes::lobby::on_xr_event(const xr::event & event) default: break; } + if (next_scene) + next_scene->on_xr_event(event); } scene::meta & scenes::lobby::get_meta_scene() diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index e551b0ab..6dfb39c1 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -933,39 +933,16 @@ void scenes::stream::exit() void scenes::stream::setup(const to_headset::video_stream_description & description) { + try + { + session.set_refresh_rate(description.fps); + } + catch (std::exception & e) + { + spdlog::warn("Failed to set refresh rate to {}: {}", description.fps, e.what()); + } + std::unique_lock lock(decoder_mutex); - - if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME)) - { - try - { - session.set_refresh_rate(description.fps); - } - catch (std::exception & e) - { - spdlog::warn("Failed to set refresh rate to {}: {}", description.fps, e.what()); - } - } - - if (std::ranges::equal(description.items, video_stream_description->items, [](const auto & a, const auto & b) { - // clang-format off - return a.width == b.width - and a.height == b.height - and a.video_width == b.video_width - and a.offset_x == b.offset_x - and a.offset_y == b.offset_y - and a.codec == b.codec - and a.channels == b.channels - and a.subsampling == b.subsampling - and a.range == b.range - and a.color_model == b.color_model; - //clang-format on - })) - { - video_stream_description = description; - return; - } - decoders.clear(); if (description.items.empty()) @@ -1180,25 +1157,25 @@ scene::meta & scenes::stream::get_meta_scene() return m; } -void scenes::stream::on_xr_event(const xr::event& event) +void scenes::stream::on_xr_event(const xr::event & event) { switch (event.header.type) { case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING: - if (event.space_changed_pending.referenceSpaceType== XrReferenceSpaceType::XR_REFERENCE_SPACE_TYPE_LOCAL) + if (event.space_changed_pending.referenceSpaceType == XrReferenceSpaceType::XR_REFERENCE_SPACE_TYPE_LOCAL) recenter_requested = true; break; case XR_TYPE_EVENT_DATA_DISPLAY_REFRESH_RATE_CHANGED_FB: network_session->send_control(from_headset::refresh_rate_changed{ - .from = event.refresh_rate_changed.fromDisplayRefreshRate, - .to = event.refresh_rate_changed.toDisplayRefreshRate, - }); + .from = event.refresh_rate_changed.fromDisplayRefreshRate, + .to = event.refresh_rate_changed.toDisplayRefreshRate, + }); break; case XR_TYPE_EVENT_DATA_VISIBILITY_MASK_CHANGED_KHR: network_session->send_control(from_headset::visibility_mask_changed{ - .data = get_visibility_mask(instance, session, event.visibility_mask_changed.viewIndex), - .view_index = uint8_t(event.visibility_mask_changed.viewIndex), - }); + .data = get_visibility_mask(instance, session, event.visibility_mask_changed.viewIndex), + .view_index = uint8_t(event.visibility_mask_changed.viewIndex), + }); break; default: break; diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 83f029ca..02a3cbd1 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -141,6 +141,7 @@ public: void render(const XrFrameState &) override; void on_focused() override; void on_unfocused() override; + void on_xr_event(const xr::event &) override; void operator()(to_headset::crypto_handshake &&) {}; void operator()(to_headset::pin_check_2 &&) {}; @@ -152,6 +153,7 @@ public: void operator()(to_headset::tracking_control &&); void operator()(to_headset::audio_stream_description &&); void operator()(to_headset::video_stream_description &&); + void operator()(to_headset::refresh_rate_change &&); void operator()(audio_data &&); void push_blit_handle(wivrn::shard_accumulator * decoder, std::shared_ptr handle); @@ -240,6 +242,5 @@ private: void accumulate_metrics(XrTime predicted_display_time, const std::vector> & blit_handles, const gpu_timestamps & timestamps); std::vector plot_performance_metrics(XrTime predicted_display_time); - void on_xr_event(const xr::event &) override; }; } // namespace scenes diff --git a/client/scenes/stream_network.cpp b/client/scenes/stream_network.cpp index d5794cbc..bbef21fc 100644 --- a/client/scenes/stream_network.cpp +++ b/client/scenes/stream_network.cpp @@ -69,6 +69,18 @@ void scenes::stream::operator()(to_headset::video_stream_description && desc) } } +void scenes::stream::operator()(to_headset::refresh_rate_change && rate) +{ + try + { + session.set_refresh_rate(rate.fps); + } + catch (std::exception & e) + { + spdlog::warn("Failed to set refresh rate to {}: {}", rate.fps, e.what()); + } +} + void scenes::stream::operator()(to_headset::timesync_query && query) { network_session->send_stream(from_headset::timesync_response{ diff --git a/client/xr/session.cpp b/client/xr/session.cpp index d2d670be..49e094c3 100644 --- a/client/xr/session.cpp +++ b/client/xr/session.cpp @@ -299,7 +299,8 @@ std::vector xr::session::get_refresh_rates() void xr::session::set_refresh_rate(float refresh_rate) { - assert(inst->has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME)); + if (not inst->has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME)) + return; static auto xrRequestDisplayRefreshRateFB = inst->get_proc("xrRequestDisplayRefreshRateFB"); if (xrRequestDisplayRefreshRateFB) diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 5dd0171b..68427c6c 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -482,6 +482,23 @@ struct tracking_control std::array enabled; }; -using packets = std::variant; +struct refresh_rate_change +{ + float fps; +}; + +using packets = std::variant< + crypto_handshake, + pin_check_2, + pin_check_4, + handshake, + audio_stream_description, + video_stream_description, + audio_data, + video_stream_data_shard, + haptics, + timesync_query, + tracking_control, + refresh_rate_change>; } // namespace to_headset } // namespace wivrn diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 36a13fe5..53dd45ab 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -734,9 +734,7 @@ static xrt_result_t comp_wivrn_request_refresh_rate(struct comp_target * ct, flo if (refresh_rate_hz == 0.0f) refresh_rate_hz = cn->cnx.get_info().preferred_refresh_rate; - cn->desc.fps = refresh_rate_hz; - cn->pacer.set_frame_duration(U_TIME_1S_IN_NS / refresh_rate_hz); - cn->cnx.send_control(to_headset::video_stream_description{cn->desc}); + cn->cnx.send_control(to_headset::refresh_rate_change{.fps = refresh_rate_hz}); return XRT_SUCCESS; } @@ -799,6 +797,12 @@ void wivrn_comp_target::render_dynamic_foveation(std::array foveation); + + void set_refresh_rate(float); }; } // namespace wivrn diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 87245e91..6203fb7e 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -413,6 +413,7 @@ void wivrn_session::operator()(from_headset::visibility_mask_changed && mask) void wivrn_session::operator()(from_headset::refresh_rate_changed && event) { + comp_target->set_refresh_rate(event.to); push_event( { .display = {