Enhancements in GCodeViewer Statistics imgui dialog

This commit is contained in:
enricoturri1966 2020-12-11 11:58:08 +01:00
parent 17c9358b0b
commit acf5e9a21f
2 changed files with 56 additions and 28 deletions

View File

@ -1431,24 +1431,26 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
const std::vector<float>& buffer_vertices = vertices[i]; const std::vector<float>& buffer_vertices = vertices[i];
buffer.vertices.count = buffer_vertices.size() / buffer.vertices.vertex_size_floats(); buffer.vertices.count = buffer_vertices.size() / buffer.vertices.vertex_size_floats();
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
m_statistics.vertices_gpu_size += buffer_vertices.size() * sizeof(float); m_statistics.total_vertices_gpu_size += buffer_vertices.size() * sizeof(float);
m_statistics.max_vbuffer_gpu_size = std::max(m_statistics.max_vbuffer_gpu_size, static_cast<int64_t>(buffer_vertices.size() * sizeof(float)));
m_statistics.max_vertices_in_vertex_buffer = std::max(m_statistics.max_vertices_in_vertex_buffer, static_cast<int64_t>(buffer.vertices.count)); m_statistics.max_vertices_in_vertex_buffer = std::max(m_statistics.max_vertices_in_vertex_buffer, static_cast<int64_t>(buffer.vertices.count));
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
if (buffer.vertices.count > 0) {
#if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.vbuffers_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
glsafe(::glGenBuffers(1, &buffer.vertices.id)); glsafe(::glGenBuffers(1, &buffer.vertices.id));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, buffer.vertices.id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, buffer.vertices.id));
glsafe(::glBufferData(GL_ARRAY_BUFFER, buffer_vertices.size() * sizeof(float), buffer_vertices.data(), GL_STATIC_DRAW)); glsafe(::glBufferData(GL_ARRAY_BUFFER, buffer_vertices.size() * sizeof(float), buffer_vertices.data(), GL_STATIC_DRAW));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
} }
}
// dismiss vertices data, no more needed // dismiss vertices data, no more needed
std::vector<std::vector<float>>().swap(vertices); std::vector<std::vector<float>>().swap(vertices);
// toolpaths data -> extract indices from result // toolpaths data -> extract indices from result
// ensure that at least one index buffer is defined for each multibuffer
for (auto i : indices) {
i.push_back(IndexBuffer());
}
// paths may have been filled while extracting vertices, // paths may have been filled while extracting vertices,
// so reset them, they will be filled again while extracting indices // so reset them, they will be filled again while extracting indices
for (TBuffer& buffer : m_buffers) { for (TBuffer& buffer : m_buffers) {
@ -1540,11 +1542,15 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
IBuffer& ibuffer = buffer.indices.back(); IBuffer& ibuffer = buffer.indices.back();
ibuffer.count = buffer_indices.size(); ibuffer.count = buffer_indices.size();
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
m_statistics.indices_gpu_size += ibuffer.count * sizeof(unsigned int); m_statistics.total_indices_gpu_size += ibuffer.count * sizeof(unsigned int);
m_statistics.max_ibuffer_gpu_size = std::max(m_statistics.max_ibuffer_gpu_size, static_cast<int64_t>(ibuffer.count * sizeof(unsigned int)));
m_statistics.max_indices_in_index_buffer = std::max(m_statistics.max_indices_in_index_buffer, static_cast<int64_t>(ibuffer.count)); m_statistics.max_indices_in_index_buffer = std::max(m_statistics.max_indices_in_index_buffer, static_cast<int64_t>(ibuffer.count));
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
if (ibuffer.count > 0) { if (ibuffer.count > 0) {
#if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.ibuffers_count;
#endif // ENABLE_GCODE_VIEWER_STATISTICS
glsafe(::glGenBuffers(1, &ibuffer.id)); glsafe(::glGenBuffers(1, &ibuffer.id));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer.id)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer.id));
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, buffer_indices.size() * sizeof(unsigned int), buffer_indices.data(), GL_STATIC_DRAW)); glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, buffer_indices.size() * sizeof(unsigned int), buffer_indices.data(), GL_STATIC_DRAW));
@ -2802,7 +2808,7 @@ void GCodeViewer::render_legend() const
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
void GCodeViewer::render_statistics() const void GCodeViewer::render_statistics() const
{ {
static const float offset = 250.0f; static const float offset = 275.0f;
ImGuiWrapper& imgui = *wxGetApp().imgui(); ImGuiWrapper& imgui = *wxGetApp().imgui();
@ -2815,18 +2821,26 @@ void GCodeViewer::render_statistics() const
}; };
auto add_memory = [this, &imgui](const std::string& label, int64_t memory) { auto add_memory = [this, &imgui](const std::string& label, int64_t memory) {
static const float mb = 1024.0f * 1024.0f; auto format_string = [memory](const std::string& units, float value) {
char buf[1024];
sprintf(buf, "%lld bytes (%.3f %s)", memory, static_cast<float>(memory) * value, units.c_str());
return std::string(buf);
};
static const float kb = 1024.0f;
static const float inv_kb = 1.0f / kb;
static const float mb = 1024.0f * kb;
static const float inv_mb = 1.0f / mb; static const float inv_mb = 1.0f / mb;
static const float gb = 1024.0f * mb; static const float gb = 1024.0f * mb;
static const float inv_gb = 1.0f / gb; static const float inv_gb = 1.0f / gb;
char buf[1024];
if (static_cast<float>(memory) < gb)
sprintf(buf, "%lld bytes (%.3f MB)", memory, static_cast<float>(memory) * inv_mb);
else
sprintf(buf, "%lld bytes (%.3f GB)", memory, static_cast<float>(memory) * inv_gb);
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
ImGui::SameLine(offset); ImGui::SameLine(offset);
imgui.text(buf); if (static_cast<float>(memory) < mb)
imgui.text(format_string("KB", inv_kb));
else if (static_cast<float>(memory) < gb)
imgui.text(format_string("MB", inv_mb));
else
imgui.text(format_string("GB", inv_gb));
}; };
auto add_counter = [this, &imgui](const std::string& label, int64_t counter) { auto add_counter = [this, &imgui](const std::string& label, int64_t counter) {
@ -2838,7 +2852,7 @@ void GCodeViewer::render_statistics() const
}; };
imgui.set_next_window_pos(0.5f * wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width(), 0.0f, ImGuiCond_Once, 0.5f, 0.0f); imgui.set_next_window_pos(0.5f * wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width(), 0.0f, ImGuiCond_Once, 0.5f, 0.0f);
ImGui::SetNextWindowSizeConstraints({ 300.0f, 100.0f }, { 600.0f, 500.0f }); ImGui::SetNextWindowSizeConstraints({ 300.0f, 100.0f }, { 600.0f, 900.0f });
imgui.begin(std::string("GCodeViewer Statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize); imgui.begin(std::string("GCodeViewer Statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize);
ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
@ -2872,8 +2886,11 @@ void GCodeViewer::render_statistics() const
} }
if (ImGui::CollapsingHeader("GPU memory")) { if (ImGui::CollapsingHeader("GPU memory")) {
add_memory(std::string("Vertices:"), m_statistics.vertices_gpu_size); add_memory(std::string("Vertices:"), m_statistics.total_vertices_gpu_size);
add_memory(std::string("Indices:"), m_statistics.indices_gpu_size); add_memory(std::string("Indices:"), m_statistics.total_indices_gpu_size);
ImGui::Separator();
add_memory(std::string("Max VBuffer:"), m_statistics.max_vbuffer_gpu_size);
add_memory(std::string("Max IBuffer:"), m_statistics.max_ibuffer_gpu_size);
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty(); wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame(); wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
} }
@ -2882,9 +2899,12 @@ void GCodeViewer::render_statistics() const
add_counter(std::string("Travel segments count:"), m_statistics.travel_segments_count); add_counter(std::string("Travel segments count:"), m_statistics.travel_segments_count);
add_counter(std::string("Wipe segments count:"), m_statistics.wipe_segments_count); add_counter(std::string("Wipe segments count:"), m_statistics.wipe_segments_count);
add_counter(std::string("Extrude segments count:"), m_statistics.extrude_segments_count); add_counter(std::string("Extrude segments count:"), m_statistics.extrude_segments_count);
add_counter(std::string("Max vertices in vertex buffer:"), m_statistics.max_vertices_in_vertex_buffer); ImGui::Separator();
add_counter(std::string("Max indices in index buffer:"), m_statistics.max_indices_in_index_buffer); add_counter(std::string("VBuffers count:"), m_statistics.vbuffers_count);
add_counter(std::string("IBuffers count:"), m_statistics.ibuffers_count);
ImGui::Separator();
add_counter(std::string("Max vertices in VBuffer:"), m_statistics.max_vertices_in_vertex_buffer);
add_counter(std::string("Max indices in IBuffer:"), m_statistics.max_indices_in_index_buffer);
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty(); wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame(); wxGetApp().plater()->get_current_canvas3D()->request_extra_frame();
} }

View File

@ -322,14 +322,18 @@ class GCodeViewer
int64_t gl_multi_triangles_calls_count{ 0 }; int64_t gl_multi_triangles_calls_count{ 0 };
// memory // memory
int64_t results_size{ 0 }; int64_t results_size{ 0 };
int64_t vertices_gpu_size{ 0 }; int64_t total_vertices_gpu_size{ 0 };
int64_t indices_gpu_size{ 0 }; int64_t total_indices_gpu_size{ 0 };
int64_t max_vbuffer_gpu_size{ 0 };
int64_t max_ibuffer_gpu_size{ 0 };
int64_t paths_size{ 0 }; int64_t paths_size{ 0 };
int64_t render_paths_size{ 0 }; int64_t render_paths_size{ 0 };
// other // other
int64_t travel_segments_count{ 0 }; int64_t travel_segments_count{ 0 };
int64_t wipe_segments_count{ 0 }; int64_t wipe_segments_count{ 0 };
int64_t extrude_segments_count{ 0 }; int64_t extrude_segments_count{ 0 };
int64_t vbuffers_count{ 0 };
int64_t ibuffers_count{ 0 };
int64_t max_vertices_in_vertex_buffer{ 0 }; int64_t max_vertices_in_vertex_buffer{ 0 };
int64_t max_indices_in_index_buffer{ 0 }; int64_t max_indices_in_index_buffer{ 0 };
@ -355,8 +359,10 @@ class GCodeViewer
void reset_sizes() { void reset_sizes() {
results_size = 0; results_size = 0;
vertices_gpu_size = 0; total_vertices_gpu_size = 0;
indices_gpu_size = 0; total_indices_gpu_size = 0;
max_vbuffer_gpu_size = 0;
max_ibuffer_gpu_size = 0;
paths_size = 0; paths_size = 0;
render_paths_size = 0; render_paths_size = 0;
} }
@ -365,6 +371,8 @@ class GCodeViewer
travel_segments_count = 0; travel_segments_count = 0;
wipe_segments_count = 0; wipe_segments_count = 0;
extrude_segments_count = 0; extrude_segments_count = 0;
vbuffers_count = 0;
ibuffers_count = 0;
max_vertices_in_vertex_buffer = 0; max_vertices_in_vertex_buffer = 0;
max_indices_in_index_buffer = 0; max_indices_in_index_buffer = 0;
} }