Render statistics now shows actual SwapBuffers() calls per second

This commit is contained in:
Lukas Matena 2021-07-21 10:16:00 +02:00
parent 3449550a7c
commit a54f5fb41a
5 changed files with 18 additions and 46 deletions

View File

@ -10,8 +10,6 @@
#define ENABLE_SELECTION_DEBUG_OUTPUT 0 #define ENABLE_SELECTION_DEBUG_OUTPUT 0
// Renders a small sphere in the center of the bounding box of the current selection when no gizmo is active // Renders a small sphere in the center of the bounding box of the current selection when no gizmo is active
#define ENABLE_RENDER_SELECTION_CENTER 0 #define ENABLE_RENDER_SELECTION_CENTER 0
// Shows an imgui dialog with render related data
#define ENABLE_RENDER_STATISTICS 0
// Shows an imgui dialog with camera related data // Shows an imgui dialog with camera related data
#define ENABLE_CAMERA_STATISTICS 0 #define ENABLE_CAMERA_STATISTICS 0
// Render the picking pass instead of the main scene (use [T] key to toggle between regular rendering and picking pass only rendering) // Render the picking pass instead of the main scene (use [T] key to toggle between regular rendering and picking pass only rendering)

View File

@ -1407,10 +1407,6 @@ void GLCanvas3D::render()
if (!is_initialized() && !init()) if (!is_initialized() && !init())
return; return;
#if ENABLE_RENDER_STATISTICS
auto start_time = std::chrono::high_resolution_clock::now();
#endif // ENABLE_RENDER_STATISTICS
if (wxGetApp().plater()->get_bed().get_shape().empty()) { if (wxGetApp().plater()->get_bed().get_shape().empty()) {
// this happens at startup when no data is still saved under <>\AppData\Roaming\Slic3rPE // this happens at startup when no data is still saved under <>\AppData\Roaming\Slic3rPE
post_event(SimpleEvent(EVT_GLCANVAS_UPDATE_BED_SHAPE)); post_event(SimpleEvent(EVT_GLCANVAS_UPDATE_BED_SHAPE));
@ -1505,19 +1501,12 @@ void GLCanvas3D::render()
// draw overlays // draw overlays
_render_overlays(); _render_overlays();
#if ENABLE_RENDER_STATISTICS
if (wxGetApp().plater()->is_render_statistic_dialog_visible()) { if (wxGetApp().plater()->is_render_statistic_dialog_visible()) {
ImGuiWrapper& imgui = *wxGetApp().imgui(); ImGuiWrapper& imgui = *wxGetApp().imgui();
imgui.begin(std::string("Render statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); imgui.begin(std::string("Render statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
imgui.text("Last frame:"); imgui.text("FPS (SwapBuffers() calls per second):");
ImGui::SameLine(); ImGui::SameLine();
int64_t average = m_render_stats.get_average(); imgui.text(std::to_string(m_render_stats.get_fps_and_reset_if_needed()));
imgui.text(std::to_string(average));
ImGui::SameLine();
imgui.text("ms");
imgui.text("FPS:");
ImGui::SameLine();
imgui.text(std::to_string((average == 0) ? 0 : static_cast<int>(1000.0f / static_cast<float>(average))));
ImGui::Separator(); ImGui::Separator();
imgui.text("Compressed textures:"); imgui.text("Compressed textures:");
ImGui::SameLine(); ImGui::SameLine();
@ -1527,7 +1516,6 @@ void GLCanvas3D::render()
imgui.text(std::to_string(OpenGLManager::get_gl_info().get_max_tex_size())); imgui.text(std::to_string(OpenGLManager::get_gl_info().get_max_tex_size()));
imgui.end(); imgui.end();
} }
#endif // ENABLE_RENDER_STATISTICS
#if ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW #if ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW
if (wxGetApp().is_editor() && wxGetApp().plater()->is_view3D_shown()) if (wxGetApp().is_editor() && wxGetApp().plater()->is_view3D_shown())
@ -1574,11 +1562,7 @@ void GLCanvas3D::render()
wxGetApp().imgui()->render(); wxGetApp().imgui()->render();
m_canvas->SwapBuffers(); m_canvas->SwapBuffers();
m_render_stats.increment_fps_counter();
#if ENABLE_RENDER_STATISTICS
auto end_time = std::chrono::high_resolution_clock::now();
m_render_stats.add_frame(std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count());
#endif // ENABLE_RENDER_STATISTICS
} }
void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params, Camera::EType camera_type) void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params, Camera::EType camera_type)
@ -2592,15 +2576,11 @@ void GLCanvas3D::on_key(wxKeyEvent& evt)
{ {
if (!m_gizmos.on_key(evt)) { if (!m_gizmos.on_key(evt)) {
if (evt.GetEventType() == wxEVT_KEY_UP) { if (evt.GetEventType() == wxEVT_KEY_UP) {
#if ENABLE_RENDER_STATISTICS
if (evt.ShiftDown() && evt.ControlDown() && keyCode == WXK_SPACE) { if (evt.ShiftDown() && evt.ControlDown() && keyCode == WXK_SPACE) {
wxGetApp().plater()->toggle_render_statistic_dialog(); wxGetApp().plater()->toggle_render_statistic_dialog();
m_dirty = true; m_dirty = true;
} }
if (m_tab_down && keyCode == WXK_TAB && !evt.HasAnyModifiers()) { if (m_tab_down && keyCode == WXK_TAB && !evt.HasAnyModifiers()) {
#else
if (m_tab_down && keyCode == WXK_TAB && !evt.HasAnyModifiers()) {
#endif // ENABLE_RENDER_STATISTICS
// Enable switching between 3D and Preview with Tab // Enable switching between 3D and Preview with Tab
// m_canvas->HandleAsNavigationKey(evt); // XXX: Doesn't work in some cases / on Linux // m_canvas->HandleAsNavigationKey(evt); // XXX: Doesn't work in some cases / on Linux
post_event(SimpleEvent(EVT_GLCANVAS_TAB)); post_event(SimpleEvent(EVT_GLCANVAS_TAB));

View File

@ -305,25 +305,27 @@ class GLCanvas3D
ObjectClashed ObjectClashed
}; };
#if ENABLE_RENDER_STATISTICS
class RenderStats class RenderStats
{ {
std::queue<std::pair<int64_t, int64_t>> m_frames; private:
int64_t m_curr_total{ 0 }; std::chrono::time_point<std::chrono::high_resolution_clock> m_measuring_start;
int m_fps_out = -1;
int m_fps_running = 0;
public: public:
void add_frame(int64_t frame) { void increment_fps_counter() { ++m_fps_running; }
int64_t now = GLCanvas3D::timestamp_now(); int get_fps() { return m_fps_out; }
if (!m_frames.empty() && now - m_frames.front().first > 1000) { int get_fps_and_reset_if_needed() {
m_curr_total -= m_frames.front().second; auto cur_time = std::chrono::high_resolution_clock::now();
m_frames.pop(); int elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(cur_time-m_measuring_start).count();
if (elapsed_ms > 1000 || m_fps_out == -1) {
m_measuring_start = cur_time;
m_fps_out = int (1000. * m_fps_running / elapsed_ms);
m_fps_running = 0;
} }
m_curr_total += frame; return m_fps_out;
m_frames.push({ now, frame });
} }
int64_t get_average() const { return m_frames.empty() ? 0 : m_curr_total / m_frames.size(); }
}; };
#endif // ENABLE_RENDER_STATISTICS
class Labels class Labels
{ {
@ -455,9 +457,7 @@ private:
bool m_show_picking_texture; bool m_show_picking_texture;
#endif // ENABLE_RENDER_PICKING_PASS #endif // ENABLE_RENDER_PICKING_PASS
#if ENABLE_RENDER_STATISTICS
RenderStats m_render_stats; RenderStats m_render_stats;
#endif // ENABLE_RENDER_STATISTICS
int m_imgui_undo_redo_hovered_pos{ -1 }; int m_imgui_undo_redo_hovered_pos{ -1 };
int m_mouse_wheel{ 0 }; int m_mouse_wheel{ 0 };

View File

@ -1565,9 +1565,7 @@ struct Plater::priv
std::string label_btn_export; std::string label_btn_export;
std::string label_btn_send; std::string label_btn_send;
#if ENABLE_RENDER_STATISTICS
bool show_render_statistic_dialog{ false }; bool show_render_statistic_dialog{ false };
#endif // ENABLE_RENDER_STATISTICS
static const std::regex pattern_bundle; static const std::regex pattern_bundle;
static const std::regex pattern_3mf; static const std::regex pattern_3mf;
@ -6515,7 +6513,6 @@ void Plater::enter_gizmos_stack() { p->enter_gizmos_stack(); }
void Plater::leave_gizmos_stack() { p->leave_gizmos_stack(); } void Plater::leave_gizmos_stack() { p->leave_gizmos_stack(); }
bool Plater::inside_snapshot_capture() { return p->inside_snapshot_capture(); } bool Plater::inside_snapshot_capture() { return p->inside_snapshot_capture(); }
#if ENABLE_RENDER_STATISTICS
void Plater::toggle_render_statistic_dialog() void Plater::toggle_render_statistic_dialog()
{ {
p->show_render_statistic_dialog = !p->show_render_statistic_dialog; p->show_render_statistic_dialog = !p->show_render_statistic_dialog;
@ -6525,7 +6522,6 @@ bool Plater::is_render_statistic_dialog_visible() const
{ {
return p->show_render_statistic_dialog; return p->show_render_statistic_dialog;
} }
#endif // ENABLE_RENDER_STATISTICS
// Wrapper around wxWindow::PopupMenu to suppress error messages popping out while tracking the popup menu. // Wrapper around wxWindow::PopupMenu to suppress error messages popping out while tracking the popup menu.
bool Plater::PopupMenu(wxMenu *menu, const wxPoint& pos) bool Plater::PopupMenu(wxMenu *menu, const wxPoint& pos)

View File

@ -403,10 +403,8 @@ public:
bool inside_snapshot_capture(); bool inside_snapshot_capture();
#if ENABLE_RENDER_STATISTICS
void toggle_render_statistic_dialog(); void toggle_render_statistic_dialog();
bool is_render_statistic_dialog_visible() const; bool is_render_statistic_dialog_visible() const;
#endif // ENABLE_RENDER_STATISTICS
// Wrapper around wxWindow::PopupMenu to suppress error messages popping out while tracking the popup menu. // Wrapper around wxWindow::PopupMenu to suppress error messages popping out while tracking the popup menu.
bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition); bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition);