WIP app pacer
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "accept_connection.h"
|
||||
#include "driver/app_pacer.h"
|
||||
#include "main/comp_compositor.h"
|
||||
#include "main/comp_main_interface.h"
|
||||
#include "main/comp_target.h"
|
||||
@@ -269,7 +270,7 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
|
||||
send_to_main(self->get_info());
|
||||
|
||||
wivrn_comp_target_factory ctf(*self);
|
||||
auto xret = comp_main_create_system_compositor(&self->hmd, &ctf, out_xsysc);
|
||||
auto xret = comp_main_create_system_compositor(&self->hmd, &ctf, &self->app_pacers, out_xsysc);
|
||||
if (xret != XRT_SUCCESS)
|
||||
{
|
||||
U_LOG_E("Failed to create system compositor");
|
||||
@@ -539,14 +540,63 @@ void wivrn_session::operator()(to_monado::set_bitrate && data)
|
||||
comp_target->set_bitrate(data.bitrate_bps);
|
||||
}
|
||||
|
||||
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;
|
||||
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),
|
||||
pacers(pacers),
|
||||
info(info)
|
||||
{
|
||||
}
|
||||
|
||||
void adjust(wivrn_connection & cnx)
|
||||
{
|
||||
if (not enabled or std::chrono::steady_clock::now() < next)
|
||||
return;
|
||||
|
||||
// Maximum refresh rate the application can reach
|
||||
auto app_rate = float(U_TIME_1S_IN_NS) / pacers.get_frame_time();
|
||||
app_rate *= 0.95; // add some margin
|
||||
// Get the highest rate reachable by the application
|
||||
// If none can be reached, set it to the maximum
|
||||
auto requested = info.available_refresh_rates.back();
|
||||
for (auto rate: info.available_refresh_rates)
|
||||
{
|
||||
if (rate < app_rate)
|
||||
requested = rate;
|
||||
}
|
||||
if (requested != last)
|
||||
{
|
||||
U_LOG_I("requesting refresh rate: %.0f (app rate %.1f)", requested, app_rate);
|
||||
cnx.send_control(to_headset::refresh_rate_change{.fps = requested});
|
||||
last = requested;
|
||||
}
|
||||
next += period;
|
||||
}
|
||||
};
|
||||
|
||||
void wivrn_session::run(std::stop_token stop)
|
||||
{
|
||||
std::chrono::seconds refresh_rate_adjust_period(10);
|
||||
auto refresh_rate_adjust = std::chrono::steady_clock::now() + refresh_rate_adjust_period;
|
||||
const auto & rates = get_info().available_refresh_rates;
|
||||
bool adjust_refresh = get_info().preferred_refresh_rate == 0 and rates.size() > 1;
|
||||
while (not stop.stop_requested())
|
||||
{
|
||||
try
|
||||
{
|
||||
offset_est.request_sample(*connection);
|
||||
tracking_control.send(*connection);
|
||||
if (adjust_refresh and std::chrono::steady_clock::now() > refresh_rate_adjust)
|
||||
{
|
||||
}
|
||||
connection->poll(*this, 20);
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
|
||||
Reference in New Issue
Block a user