Commit: 761de8713b52125560e993b7e24b658d22ccd73c Author: Sergey Sharybin Date: Fri May 22 10:25:34 2020 +0200 Branches: opensubdiv_compare https://developer.blender.org/rB761de8713b52125560e993b7e24b658d22ccd73c
OpenSubdiv: Reduce memory footprint of cached topology Brings down worst case of 1.5M faced mesh from 102 MiB to 90 MiB. =================================================================== M intern/opensubdiv/internal/topology/mesh_topology.h M intern/opensubdiv/internal/topology/mesh_topology_compare.cc =================================================================== diff --git a/intern/opensubdiv/internal/topology/mesh_topology.h b/intern/opensubdiv/internal/topology/mesh_topology.h index 196d79c87df..0810ae7a9a5 100644 --- a/intern/opensubdiv/internal/topology/mesh_topology.h +++ b/intern/opensubdiv/internal/topology/mesh_topology.h @@ -47,20 +47,41 @@ class EdgeTopology { class FaceTopology { public: - void setNumVertices(int num_vertices) + FaceTopology() { - vertex_indices.resize(num_vertices, -1); + } + + ~FaceTopology() + { + delete[] vertex_indices; + } + + void setNumVertices(int new_num_vertices) + { + num_vertices = new_num_vertices; + + delete[] vertex_indices; + vertex_indices = new int[num_vertices]; } void setVertexIndices(int *face_vertex_indices) { - memcpy(vertex_indices.data(), face_vertex_indices, sizeof(int) * vertex_indices.size()); + memcpy(vertex_indices, face_vertex_indices, sizeof(int) * getNumVertices()); + } + + bool isVertexIndicesEqual(const vector<int> &other_vertex_indices) const + { + if (other_vertex_indices.size() != getNumVertices()) { + return false; + } + + return memcmp(vertex_indices, other_vertex_indices.data(), sizeof(int) * num_vertices); } bool isValid() const { - for (int vertex_index : vertex_indices) { - if (vertex_index < 0) { + for (int i = 0; i < getNumVertices(); ++i) { + if (vertex_indices[i] < 0) { return false; } } @@ -70,10 +91,19 @@ class FaceTopology { int getNumVertices() const { - return vertex_indices.size(); + return num_vertices; } - vector<int> vertex_indices; + // NOTE: Use bare pointers to avoid object's size overhed. For example, when + // using managed vector<int> it is 24 bytes on GCC-10 (to store an internal + // state of the vector). Here is is only 8 bytes (on 64bit machine). + // + // TODO(sergey): Consider using packed structure to lower the memory footprint + // since, for some reason, due to padding the sizeof(FaceTopology) is 16 bytes + // which could be packed down to 12. + int *vertex_indices = nullptr; + + int num_vertices = 0; }; class EdgeTopologyTag { diff --git a/intern/opensubdiv/internal/topology/mesh_topology_compare.cc b/intern/opensubdiv/internal/topology/mesh_topology_compare.cc index 0aa217ac711..cb210e1ae86 100644 --- a/intern/opensubdiv/internal/topology/mesh_topology_compare.cc +++ b/intern/opensubdiv/internal/topology/mesh_topology_compare.cc @@ -106,7 +106,7 @@ bool isEqualGeometryFace(const MeshTopology &mesh_topology, const OpenSubdiv_Con vertices_of_face.resize(num_face_vertices); converter->getFaceVertices(converter, face_index, vertices_of_face.data()); - if (current_face.vertex_indices != vertices_of_face) { + if (!current_face.isVertexIndicesEqual(vertices_of_face)) { return false; } } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs