Use a separate packet for refresh rate change
This commit is contained in:
+7
-10
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
+17
-40
@@ -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;
|
||||
|
||||
@@ -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<wivrn::shard_accumulator::blit_handle> handle);
|
||||
@@ -240,6 +242,5 @@ 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);
|
||||
std::vector<XrCompositionLayerQuad> plot_performance_metrics(XrTime predicted_display_time);
|
||||
void on_xr_event(const xr::event &) override;
|
||||
};
|
||||
} // namespace scenes
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -299,7 +299,8 @@ std::vector<float> 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<PFN_xrRequestDisplayRefreshRateFB>("xrRequestDisplayRefreshRateFB");
|
||||
|
||||
if (xrRequestDisplayRefreshRateFB)
|
||||
|
||||
+18
-1
@@ -482,6 +482,23 @@ struct tracking_control
|
||||
std::array<bool, size_t(id::last) + 1> enabled;
|
||||
};
|
||||
|
||||
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>;
|
||||
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
|
||||
|
||||
@@ -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<to_headset::foveatio
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_comp_target::set_refresh_rate(float refresh_rate_hz)
|
||||
{
|
||||
desc.fps = refresh_rate_hz;
|
||||
pacer.set_frame_duration(U_TIME_1S_IN_NS / refresh_rate_hz);
|
||||
}
|
||||
|
||||
wivrn_comp_target::wivrn_comp_target(wivrn::wivrn_session & cnx, struct comp_compositor * c) :
|
||||
comp_target{
|
||||
.c = c,
|
||||
|
||||
@@ -107,6 +107,8 @@ struct wivrn_comp_target : public comp_target
|
||||
void reset_encoders();
|
||||
|
||||
void render_dynamic_foveation(std::array<to_headset::foveation_parameter, 2> foveation);
|
||||
|
||||
void set_refresh_rate(float);
|
||||
};
|
||||
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user