Skip to content

Commit

Permalink
Display real FPS as a fallback if GPU time information is not available
Browse files Browse the repository at this point in the history
This fixes FPS being reported as 100000 on the web editor and on
other platforms/renderers where GPU time information isn't available.
  • Loading branch information
Calinou committed Nov 15, 2024
1 parent 6c05ec3 commit 48c6d96
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
26 changes: 19 additions & 7 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,7 @@ void Node3DEditorViewport::_notification(int p_what) {
// Prevent unrealistically low values.
cpu_time = MAX(0.01, cpu_time);

const float gpu_render_time = RS::get_singleton()->viewport_get_measured_render_time_gpu(viewport->get_viewport_rid());
gpu_time_history[gpu_time_history_index] = RS::get_singleton()->viewport_get_measured_render_time_gpu(viewport->get_viewport_rid());
gpu_time_history_index = (gpu_time_history_index + 1) % FRAME_TIME_HISTORY;
double gpu_time = 0.0;
Expand All @@ -3055,14 +3056,25 @@ void Node3DEditorViewport::_notification(int p_what) {
frame_time_gradient->get_color_at_offset(
Math::remap(cpu_time, 0, 30, 0, 1)));

gpu_time_label->set_text(vformat(TTR("GPU Time: %s ms"), rtos(gpu_time).pad_decimals(2)));
// Middle point is at 15 ms.
gpu_time_label->add_theme_color_override(
SceneStringName(font_color),
frame_time_gradient->get_color_at_offset(
Math::remap(gpu_time, 0, 30, 0, 1)));
double fps = 0.0;
// GPU time is not always available as it depends on the platform and rendering method in use.
// For instance, it's not available in the web editor due to WebGL limitations.
// In this case, it's reported as 0.0 ms so we display a fallback instead.
if (!Math::is_zero_approx(gpu_render_time)) {
gpu_time_label->set_text(vformat(TTR("GPU Time: %s ms"), rtos(gpu_time).pad_decimals(2)));
// Middle point is at 15 ms.
gpu_time_label->add_theme_color_override(
SceneStringName(font_color),
frame_time_gradient->get_color_at_offset(
Math::remap(gpu_time, 0, 30, 0, 1)));

fps = 1000.0 / gpu_time;
} else {
gpu_time_label->set_text(TTR("GPU Time: N/A"));
// Fallback to the actual rendered frames per second, as GPU time information is not available.
fps = Engine::get_singleton()->get_frames_per_second();
}

const double fps = 1000.0 / gpu_time;
fps_label->set_text(vformat(TTR("FPS: %d"), fps));
// Middle point is at 60 FPS.
fps_label->add_theme_color_override(
Expand Down
9 changes: 9 additions & 0 deletions platform/windows/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,15 @@ def configure_mingw(env: "SConsEnvironment"):
env.AppendUnique(CPPDEFINES=["WINDOWS_SUBSYSTEM_CONSOLE"])

## Compiler configuration
# IMPORTANT:
# FIXME
# TODO
# WARNING
# NOTE
# XXX
# CHANGED
# CAUTION:
# DANGER:

if env["arch"] == "x86_32":
if env["use_static_cpp"]:
Expand Down

0 comments on commit 48c6d96

Please sign in to comment.