overlays: fix perf overlay switching detail levels

The body was lagging behind the text. This was fixed by calling an updated version of init() on settings change.
This introduced spikes in the frametime graph, so the data had to become members and m_force_update was adjusted to not interfere with data aquisition.
This commit is contained in:
Megamouse 2021-02-23 00:56:24 +01:00 committed by Ivan
parent 79b5b79de1
commit a771f168eb
2 changed files with 79 additions and 77 deletions

View File

@ -233,6 +233,12 @@ namespace rsx
reset_transforms(); reset_transforms();
force_next_update(); force_next_update();
if (m_is_initialised)
{
update();
return;
}
m_update_timer.Start(); m_update_timer.Start();
m_frametime_timer.Start(); m_frametime_timer.Start();
@ -382,7 +388,7 @@ namespace rsx
if (m_is_initialised) if (m_is_initialised)
{ {
if (m_frametime_graph_enabled) if (m_frametime_graph_enabled && !m_force_update)
{ {
const auto elapsed_frame = m_frametime_timer.GetElapsedTimeInMilliSec(); const auto elapsed_frame = m_frametime_timer.GetElapsedTimeInMilliSec();
m_frametime_timer.Start(); m_frametime_timer.Start();
@ -402,98 +408,79 @@ namespace rsx
if (elapsed_update >= m_update_interval || m_force_update) if (elapsed_update >= m_update_interval || m_force_update)
{ {
if (!m_force_update) // 1. Fetch/calculate metrics we'll need
if (!m_is_initialised || !m_force_update)
{ {
m_update_timer.Start(); m_update_timer.Start();
}
f32 fps{0}; const auto rsx_thread = g_fxo->get<rsx::thread>();
f32 frametime{0};
u64 ppu_cycles{0}; switch (m_detail)
u64 spu_cycles{0};
u64 rsx_cycles{0};
u64 total_cycles{0};
u32 ppus{0};
u32 spus{0};
f32 cpu_usage{-1.f};
u32 total_threads{0};
f32 ppu_usage{0};
f32 spu_usage{0};
f32 rsx_usage{0};
u32 rsx_load{0};
const auto rsx_thread = g_fxo->get<rsx::thread>();
std::string perf_text;
// 1. Fetch/calculate metrics we'll need
switch (m_detail)
{
case detail_level::high:
{
frametime = m_force_update ? 0.f : std::max(0.f, static_cast<float>(elapsed_update / m_frames));
rsx_load = rsx_thread->get_load();
total_threads = CPUStats::get_thread_count();
[[fallthrough]];
}
case detail_level::medium:
{
ppus = idm::select<named_thread<ppu_thread>>([&ppu_cycles](u32, named_thread<ppu_thread>& ppu)
{ {
ppu_cycles += thread_ctrl::get_cycles(ppu); case detail_level::high:
});
spus = idm::select<named_thread<spu_thread>>([&spu_cycles](u32, named_thread<spu_thread>& spu)
{ {
spu_cycles += thread_ctrl::get_cycles(spu); m_frametime = std::max(0.f, static_cast<float>(elapsed_update / m_frames));
});
rsx_cycles += rsx_thread->get_cycles(); m_rsx_load = rsx_thread->get_load();
total_cycles = std::max<u64>(1, ppu_cycles + spu_cycles + rsx_cycles); m_total_threads = CPUStats::get_thread_count();
cpu_usage = static_cast<f32>(m_cpu_stats.get_usage());
ppu_usage = std::clamp(cpu_usage * ppu_cycles / total_cycles, 0.f, 100.f); [[fallthrough]];
spu_usage = std::clamp(cpu_usage * spu_cycles / total_cycles, 0.f, 100.f); }
rsx_usage = std::clamp(cpu_usage * rsx_cycles / total_cycles, 0.f, 100.f); case detail_level::medium:
{
m_ppus = idm::select<named_thread<ppu_thread>>([this](u32, named_thread<ppu_thread>& ppu)
{
m_ppu_cycles += thread_ctrl::get_cycles(ppu);
});
[[fallthrough]]; m_spus = idm::select<named_thread<spu_thread>>([this](u32, named_thread<spu_thread>& spu)
} {
case detail_level::low: m_spu_cycles += thread_ctrl::get_cycles(spu);
{ });
if (cpu_usage < 0.)
cpu_usage = static_cast<f32>(m_cpu_stats.get_usage());
[[fallthrough]]; m_rsx_cycles += rsx_thread->get_cycles();
}
case detail_level::minimal: m_total_cycles = std::max<u64>(1, m_ppu_cycles + m_spu_cycles + m_rsx_cycles);
{ m_cpu_usage = static_cast<f32>(m_cpu_stats.get_usage());
fps = m_force_update ? 0.f : std::max(0.f, static_cast<f32>(m_frames / (elapsed_update / 1000)));
if (m_is_initialised && m_framerate_graph_enabled) m_ppu_usage = std::clamp(m_cpu_usage * m_ppu_cycles / m_total_cycles, 0.f, 100.f);
m_fps_graph.record_datapoint(fps); m_spu_usage = std::clamp(m_cpu_usage * m_spu_cycles / m_total_cycles, 0.f, 100.f);
} m_rsx_usage = std::clamp(m_cpu_usage * m_rsx_cycles / m_total_cycles, 0.f, 100.f);
[[fallthrough]];
}
case detail_level::low:
{
if (m_cpu_usage < 0.)
m_cpu_usage = static_cast<f32>(m_cpu_stats.get_usage());
[[fallthrough]];
}
case detail_level::minimal:
{
m_fps = std::max(0.f, static_cast<f32>(m_frames / (elapsed_update / 1000)));
if (m_is_initialised && m_framerate_graph_enabled)
m_fps_graph.record_datapoint(m_fps);
}
}
} }
// 2. Format output string // 2. Format output string
std::string perf_text;
switch (m_detail) switch (m_detail)
{ {
case detail_level::minimal: case detail_level::minimal:
{ {
perf_text += fmt::format("FPS : %05.2f", fps); perf_text += fmt::format("FPS : %05.2f", m_fps);
break; break;
} }
case detail_level::low: case detail_level::low:
{ {
perf_text += fmt::format("FPS : %05.2f\n" perf_text += fmt::format("FPS : %05.2f\n"
"CPU : %04.1f %%", "CPU : %04.1f %%",
fps, cpu_usage); m_fps, m_cpu_usage);
break; break;
} }
case detail_level::medium: case detail_level::medium:
@ -504,7 +491,7 @@ namespace rsx
" SPU : %04.1f %%\n" " SPU : %04.1f %%\n"
" RSX : %04.1f %%\n" " RSX : %04.1f %%\n"
" Total : %04.1f %%", " Total : %04.1f %%",
fps, std::string(title1_medium.size(), ' '), ppu_usage, spu_usage, rsx_usage, cpu_usage, std::string(title2.size(), ' ')); m_fps, std::string(title1_medium.size(), ' '), m_ppu_usage, m_spu_usage, m_rsx_usage, m_cpu_usage, std::string(title2.size(), ' '));
break; break;
} }
case detail_level::high: case detail_level::high:
@ -517,7 +504,7 @@ namespace rsx
" Total : %04.1f %% (%2u)\n\n" " Total : %04.1f %% (%2u)\n\n"
"%s\n" "%s\n"
" RSX : %02u %%", " RSX : %02u %%",
fps, frametime, std::string(title1_high.size(), ' '), ppu_usage, ppus, spu_usage, spus, rsx_usage, cpu_usage, total_threads, std::string(title2.size(), ' '), rsx_load); m_fps, m_frametime, std::string(title1_high.size(), ' '), m_ppu_usage, m_ppus, m_spu_usage, m_spus, m_rsx_usage, m_cpu_usage, m_total_threads, std::string(title2.size(), ' '), m_rsx_load);
break; break;
} }
} }
@ -755,11 +742,7 @@ namespace rsx
perf_overlay->set_title_colors(perf_settings.color_title, perf_settings.background_title); perf_overlay->set_title_colors(perf_settings.color_title, perf_settings.background_title);
perf_overlay->set_framerate_graph_enabled(perf_settings.framerate_graph_enabled.get()); perf_overlay->set_framerate_graph_enabled(perf_settings.framerate_graph_enabled.get());
perf_overlay->set_frametime_graph_enabled(perf_settings.frametime_graph_enabled.get()); perf_overlay->set_frametime_graph_enabled(perf_settings.frametime_graph_enabled.get());
perf_overlay->init();
if (!existed)
{
perf_overlay->init();
}
} }
else if (perf_overlay) else if (perf_overlay)
{ {

View File

@ -48,7 +48,7 @@ namespace rsx
std::string m_color_title; std::string m_color_title;
std::string m_background_title; std::string m_background_title;
bool m_force_update{}; bool m_force_update{}; // Used to update the overlay metrics without changing the data
bool m_force_repaint{}; bool m_force_repaint{};
bool m_is_initialised{}; bool m_is_initialised{};
@ -56,6 +56,25 @@ namespace rsx
const std::string title1_high{ "Host Utilization (CPU):" }; const std::string title1_high{ "Host Utilization (CPU):" };
const std::string title2{ "Guest Utilization (PS3):" }; const std::string title2{ "Guest Utilization (PS3):" };
f32 m_fps{0};
f32 m_frametime{0};
u64 m_ppu_cycles{0};
u64 m_spu_cycles{0};
u64 m_rsx_cycles{0};
u64 m_total_cycles{0};
u32 m_ppus{0};
u32 m_spus{0};
f32 m_cpu_usage{-1.f};
u32 m_total_threads{0};
f32 m_ppu_usage{0};
f32 m_spu_usage{0};
f32 m_rsx_usage{0};
u32 m_rsx_load{0};
void reset_transform(label& elm, u16 bottom_margin = 0) const; void reset_transform(label& elm, u16 bottom_margin = 0) const;
void reset_transforms(); void reset_transforms();
void reset_body(u16 bottom_margin); void reset_body(u16 bottom_margin);