Merge remote-tracking branch 'origin/et_splitted_vbuffer'
This commit is contained in:
commit
cd62a5bd97
3 changed files with 62 additions and 31 deletions
|
@ -24,7 +24,7 @@
|
|||
// Use wxDataViewRender instead of wxDataViewCustomRenderer
|
||||
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING 0
|
||||
// Enable G-Code viewer statistics imgui dialog
|
||||
#define ENABLE_GCODE_VIEWER_STATISTICS 0
|
||||
#define ENABLE_GCODE_VIEWER_STATISTICS 1
|
||||
// Enable G-Code viewer comparison between toolpaths height and width detected from gcode and calculated at gcode generation
|
||||
#define ENABLE_GCODE_VIEWER_DATA_CHECKING 0
|
||||
|
||||
|
|
|
@ -1431,29 +1431,35 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
const std::vector<float>& buffer_vertices = vertices[i];
|
||||
buffer.vertices.count = buffer_vertices.size() / buffer.vertices.vertex_size_floats();
|
||||
#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));
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
||||
glsafe(::glGenBuffers(1, &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(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
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(::glBindBuffer(GL_ARRAY_BUFFER, buffer.vertices.id));
|
||||
glsafe(::glBufferData(GL_ARRAY_BUFFER, buffer_vertices.size() * sizeof(float), buffer_vertices.data(), GL_STATIC_DRAW));
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
}
|
||||
}
|
||||
|
||||
// dismiss vertices data, no more needed
|
||||
std::vector<std::vector<float>>().swap(vertices);
|
||||
|
||||
// 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,
|
||||
// so reset them, they will be filled again while extracting indices
|
||||
for (TBuffer& buffer : m_buffers) {
|
||||
buffer.paths.clear();
|
||||
}
|
||||
|
||||
// max index buffer size
|
||||
const size_t IBUFFER_THRESHOLD = 1024 * 1024 * 32;
|
||||
|
||||
// variable used to keep track of the current size (in vertices) of the vertex buffer
|
||||
std::vector<size_t> curr_buffer_vertices_size(m_buffers.size(), 0);
|
||||
for (size_t i = 0; i < m_moves_count; ++i) {
|
||||
|
@ -1478,10 +1484,9 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
if (buffer_indices.empty())
|
||||
buffer_indices.push_back(IndexBuffer());
|
||||
|
||||
static const size_t THRESHOLD = 1024 * 1024 * 128;
|
||||
// if adding the indices for the current segment exceeds the threshold size of the current index buffer
|
||||
// create another index buffer, and move the current path indices into it
|
||||
if (buffer_indices.back().size() >= THRESHOLD - static_cast<size_t>(buffer.indices_per_segment())) {
|
||||
if (buffer_indices.back().size() >= IBUFFER_THRESHOLD - static_cast<size_t>(buffer.indices_per_segment())) {
|
||||
buffer_indices.push_back(IndexBuffer());
|
||||
if (buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::Point) {
|
||||
if (!(prev.type != curr.type || !buffer.paths.back().matches(curr))) {
|
||||
|
@ -1537,11 +1542,15 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
|||
IBuffer& ibuffer = buffer.indices.back();
|
||||
ibuffer.count = buffer_indices.size();
|
||||
#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));
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
||||
if (ibuffer.count > 0) {
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++m_statistics.ibuffers_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
glsafe(::glGenBuffers(1, &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));
|
||||
|
@ -2799,7 +2808,7 @@ void GCodeViewer::render_legend() const
|
|||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
void GCodeViewer::render_statistics() const
|
||||
{
|
||||
static const float offset = 250.0f;
|
||||
static const float offset = 275.0f;
|
||||
|
||||
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
||||
|
||||
|
@ -2812,18 +2821,26 @@ void GCodeViewer::render_statistics() const
|
|||
};
|
||||
|
||||
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 gb = 1024.0f * mb;
|
||||
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::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) {
|
||||
|
@ -2835,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::SetNextWindowSizeConstraints({ 300, -1 }, { 600, -1 });
|
||||
ImGui::SetNextWindowSizeConstraints({ 300.0f, 100.0f }, { 600.0f, 900.0f });
|
||||
imgui.begin(std::string("GCodeViewer Statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize);
|
||||
ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
|
||||
|
||||
|
@ -2869,8 +2886,11 @@ void GCodeViewer::render_statistics() const
|
|||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("GPU memory")) {
|
||||
add_memory(std::string("Vertices:"), m_statistics.vertices_gpu_size);
|
||||
add_memory(std::string("Indices:"), m_statistics.indices_gpu_size);
|
||||
add_memory(std::string("Vertices:"), m_statistics.total_vertices_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()->request_extra_frame();
|
||||
}
|
||||
|
@ -2879,9 +2899,12 @@ void GCodeViewer::render_statistics() const
|
|||
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("Extrude segments count:"), m_statistics.extrude_segments_count);
|
||||
add_counter(std::string("Max vertices in vertex buffer:"), m_statistics.max_vertices_in_vertex_buffer);
|
||||
add_counter(std::string("Max indices in index buffer:"), m_statistics.max_indices_in_index_buffer);
|
||||
|
||||
ImGui::Separator();
|
||||
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()->request_extra_frame();
|
||||
}
|
||||
|
|
|
@ -322,14 +322,18 @@ class GCodeViewer
|
|||
int64_t gl_multi_triangles_calls_count{ 0 };
|
||||
// memory
|
||||
int64_t results_size{ 0 };
|
||||
int64_t vertices_gpu_size{ 0 };
|
||||
int64_t indices_gpu_size{ 0 };
|
||||
int64_t total_vertices_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 render_paths_size{ 0 };
|
||||
// other
|
||||
int64_t travel_segments_count{ 0 };
|
||||
int64_t wipe_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_indices_in_index_buffer{ 0 };
|
||||
|
||||
|
@ -355,8 +359,10 @@ class GCodeViewer
|
|||
|
||||
void reset_sizes() {
|
||||
results_size = 0;
|
||||
vertices_gpu_size = 0;
|
||||
indices_gpu_size = 0;
|
||||
total_vertices_gpu_size = 0;
|
||||
total_indices_gpu_size = 0;
|
||||
max_vbuffer_gpu_size = 0;
|
||||
max_ibuffer_gpu_size = 0;
|
||||
paths_size = 0;
|
||||
render_paths_size = 0;
|
||||
}
|
||||
|
@ -365,6 +371,8 @@ class GCodeViewer
|
|||
travel_segments_count = 0;
|
||||
wipe_segments_count = 0;
|
||||
extrude_segments_count = 0;
|
||||
vbuffers_count = 0;
|
||||
ibuffers_count = 0;
|
||||
max_vertices_in_vertex_buffer = 0;
|
||||
max_indices_in_index_buffer = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue