Take CPU time into account when calculating FPS in the editor Frame Time

This commit is contained in:
Hugo Locurcio 2021-07-13 01:50:20 +02:00
parent 1ed00dca88
commit 9195982c7a
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C

View file

@ -2788,7 +2788,8 @@ void Node3DEditorViewport::_notification(int p_what) {
cpu_time += cpu_time_history[i];
}
cpu_time /= FRAME_TIME_HISTORY;
// Prevent unrealistically low values.
// Prevent division by zero for the FPS counter (and unrealistically low values).
// This limits the reported FPS to 100000.
cpu_time = MAX(0.01, cpu_time);
gpu_time_history[gpu_time_history_index] = RS::get_singleton()->viewport_get_measured_render_time_gpu(viewport->get_viewport_rid());
@ -2817,7 +2818,10 @@ void Node3DEditorViewport::_notification(int p_what) {
frame_time_gradient->get_color_at_offset(
Math::range_lerp(gpu_time, 0, 30, 0, 1)));
const double fps = 1000.0 / gpu_time;
// Tasks may run in parallel on both the CPU and GPU. Estimating the FPS
// is best done by using the highest measure of both,
// rather than summing both values (which assumes that nothing runs in parallel).
const double fps = 1000.0 / MAX(cpu_time, gpu_time);
fps_label->set_text(vformat(TTR("FPS: %d"), fps));
// Middle point is at 60 FPS.
fps_label->add_theme_color_override(