From 6a21ff91541d07427b4d8164f17705a06f735dad Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 17 Apr 2024 17:22:22 +0200 Subject: [PATCH] Cleanup: Remove includes and "using std" for opensubdiv wrapper Avoid unnecessary indirect includes for the module, which would slow down compilation. Avoid "using std" which is generally not considered good practice since it's helpful to see what namespace things are from. This is just a general cleanup of the area. I was trying to understand it better to reduce redundant mesh topology storage but finding that some intermediate cleanups would be helpful to ease the change. Pull Request: https://projects.blender.org/blender/blender/pulls/120743 --- intern/opensubdiv/CMakeLists.txt | 1 - intern/opensubdiv/internal/base/type.h | 39 ------------------- intern/opensubdiv/internal/base/util.cc | 18 ++++----- intern/opensubdiv/internal/base/util.h | 9 +++-- .../internal/evaluator/eval_output.h | 5 +-- .../internal/evaluator/eval_output_cpu.h | 2 +- .../internal/evaluator/eval_output_gpu.cc | 2 +- .../internal/evaluator/eval_output_gpu.h | 2 +- .../internal/evaluator/evaluator_impl.cc | 7 ++-- .../internal/topology/mesh_topology.cc | 4 +- .../internal/topology/mesh_topology.h | 15 ++++--- .../topology/mesh_topology_compare.cc | 5 +-- .../topology/topology_refiner_capi.cc | 2 - .../topology/topology_refiner_factory.cc | 11 ++---- .../topology/topology_refiner_impl_compare.cc | 1 - 15 files changed, 36 insertions(+), 87 deletions(-) delete mode 100644 intern/opensubdiv/internal/base/type.h diff --git a/intern/opensubdiv/CMakeLists.txt b/intern/opensubdiv/CMakeLists.txt index d34ff5f15e7..7f26fbefa67 100644 --- a/intern/opensubdiv/CMakeLists.txt +++ b/intern/opensubdiv/CMakeLists.txt @@ -37,7 +37,6 @@ if(WITH_OPENSUBDIV) # Base. internal/base/memory.h internal/base/opensubdiv_capi.cc - internal/base/type.h internal/base/type_convert.cc internal/base/type_convert.h internal/base/util.cc diff --git a/intern/opensubdiv/internal/base/type.h b/intern/opensubdiv/internal/base/type.h deleted file mode 100644 index 832078ec569..00000000000 --- a/intern/opensubdiv/internal/base/type.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-FileCopyrightText: 2013 Blender Foundation - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#ifndef OPENSUBDIV_BASE_TYPE_H_ -#define OPENSUBDIV_BASE_TYPE_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace blender { -namespace opensubdiv { - -using std::map; -using std::pair; -using std::stack; -using std::string; -using std::unordered_map; -using std::vector; - -using std::fill; -using std::make_pair; -using std::max; -using std::min; -using std::move; -using std::swap; - -} // namespace opensubdiv -} // namespace blender - -#endif // OPENSUBDIV_BASE_TYPE_H_ diff --git a/intern/opensubdiv/internal/base/util.cc b/intern/opensubdiv/internal/base/util.cc index 86d1c9cfb17..7e74c52e8b6 100644 --- a/intern/opensubdiv/internal/base/util.cc +++ b/intern/opensubdiv/internal/base/util.cc @@ -7,22 +7,22 @@ namespace blender { namespace opensubdiv { -void stringSplit(vector *tokens, - const string &str, - const string &separators, +void stringSplit(std::vector *tokens, + const std::string &str, + const std::string &separators, bool skip_empty) { size_t token_start = 0, token_length = 0; for (size_t i = 0; i < str.length(); ++i) { const char ch = str[i]; - if (separators.find(ch) == string::npos) { + if (separators.find(ch) == std::string::npos) { // Append non-separator char to a token. ++token_length; } else { // Append current token to the list (if any). if (token_length > 0 || !skip_empty) { - string token = str.substr(token_start, token_length); + std::string token = str.substr(token_start, token_length); tokens->push_back(token); } // Re-set token pointers. @@ -30,11 +30,11 @@ void stringSplit(vector *tokens, token_length = 0; } } - // Append token which might be at the end of the string. - if ((token_length != 0) || - (!skip_empty && token_start > 0 && separators.find(str[token_start - 1]) != string::npos)) + // Append token which might be at the end of the std::string. + if ((token_length != 0) || (!skip_empty && token_start > 0 && + separators.find(str[token_start - 1]) != std::string::npos)) { - string token = str.substr(token_start, token_length); + std::string token = str.substr(token_start, token_length); tokens->push_back(token); } } diff --git a/intern/opensubdiv/internal/base/util.h b/intern/opensubdiv/internal/base/util.h index e466d524c81..7def6240fbe 100644 --- a/intern/opensubdiv/internal/base/util.h +++ b/intern/opensubdiv/internal/base/util.h @@ -5,14 +5,15 @@ #ifndef OPENSUBDIV_BASE_UTIL_H_ #define OPENSUBDIV_BASE_UTIL_H_ -#include "internal/base/type.h" +#include +#include namespace blender { namespace opensubdiv { -void stringSplit(vector *tokens, - const string &str, - const string &separators, +void stringSplit(std::vector *tokens, + const std::string &str, + const std::string &separators, bool skip_empty); } // namespace opensubdiv diff --git a/intern/opensubdiv/internal/evaluator/eval_output.h b/intern/opensubdiv/internal/evaluator/eval_output.h index 5eb28ec73fb..b5f52353ebb 100644 --- a/intern/opensubdiv/internal/evaluator/eval_output.h +++ b/intern/opensubdiv/internal/evaluator/eval_output.h @@ -12,7 +12,6 @@ #include #include -#include "internal/base/type.h" #include "internal/evaluator/evaluator_impl.h" #include "opensubdiv_evaluator_capi.hh" @@ -325,7 +324,7 @@ class VolatileEvalOutput : public EvalOutputAPI::EvalOutput { VolatileEvalOutput(const StencilTable *vertex_stencils, const StencilTable *varying_stencils, - const vector &all_face_varying_stencils, + const std::vector &all_face_varying_stencils, const int face_varying_width, const PatchTable *patch_table, EvaluatorCache *evaluator_cache = NULL, @@ -641,7 +640,7 @@ class VolatileEvalOutput : public EvalOutputAPI::EvalOutput { const STENCIL_TABLE *varying_stencils_; int face_varying_width_; - vector face_varying_evaluators_; + std::vector face_varying_evaluators_; EvaluatorCache *evaluator_cache_; DEVICE_CONTEXT *device_context_; diff --git a/intern/opensubdiv/internal/evaluator/eval_output_cpu.h b/intern/opensubdiv/internal/evaluator/eval_output_cpu.h index a2e97f6e338..9c9eb332c0f 100644 --- a/intern/opensubdiv/internal/evaluator/eval_output_cpu.h +++ b/intern/opensubdiv/internal/evaluator/eval_output_cpu.h @@ -30,7 +30,7 @@ class CpuEvalOutput : public VolatileEvalOutput &all_face_varying_stencils, + const std::vector &all_face_varying_stencils, const int face_varying_width, const PatchTable *patch_table, EvaluatorCache *evaluator_cache = NULL) diff --git a/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc b/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc index 237ea914714..19aad131191 100644 --- a/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc +++ b/intern/opensubdiv/internal/evaluator/eval_output_gpu.cc @@ -31,7 +31,7 @@ static void buildPatchArraysBufferFromVector(const PatchArrayVector &patch_array GpuEvalOutput::GpuEvalOutput(const StencilTable *vertex_stencils, const StencilTable *varying_stencils, - const vector &all_face_varying_stencils, + const std::vector &all_face_varying_stencils, const int face_varying_width, const PatchTable *patch_table, VolatileEvalOutput::EvaluatorCache *evaluator_cache) diff --git a/intern/opensubdiv/internal/evaluator/eval_output_gpu.h b/intern/opensubdiv/internal/evaluator/eval_output_gpu.h index 0f589735758..54706a96d2c 100644 --- a/intern/opensubdiv/internal/evaluator/eval_output_gpu.h +++ b/intern/opensubdiv/internal/evaluator/eval_output_gpu.h @@ -26,7 +26,7 @@ class GpuEvalOutput : public VolatileEvalOutput &all_face_varying_stencils, + const std::vector &all_face_varying_stencils, const int face_varying_width, const PatchTable *patch_table, EvaluatorCache *evaluator_cache = NULL); diff --git a/intern/opensubdiv/internal/evaluator/evaluator_impl.cc b/intern/opensubdiv/internal/evaluator/evaluator_impl.cc index 0b8ae6f2d2f..732c028831e 100644 --- a/intern/opensubdiv/internal/evaluator/evaluator_impl.cc +++ b/intern/opensubdiv/internal/evaluator/evaluator_impl.cc @@ -22,7 +22,6 @@ #include "MEM_guardedalloc.h" -#include "internal/base/type.h" #include "internal/evaluator/eval_output_cpu.h" #include "internal/evaluator/eval_output_gpu.h" #include "internal/evaluator/evaluator_cache_impl.h" @@ -90,7 +89,8 @@ template class StackOrHeapArray { T *old_buffer = effective_elements_; effective_elements_ = allocate(num_elements); if (old_buffer != effective_elements_) { - memcpy(effective_elements_, old_buffer, sizeof(T) * min(old_num_elements, num_elements)); + memcpy( + effective_elements_, old_buffer, sizeof(T) * std::min(old_num_elements, num_elements)); } if (old_buffer != stack_elements_) { delete[] old_buffer; @@ -430,7 +430,6 @@ OpenSubdiv_EvaluatorImpl *openSubdiv_createEvaluatorInternal( eOpenSubdivEvaluator evaluator_type, OpenSubdiv_EvaluatorCacheImpl *evaluator_cache_descr) { - using blender::opensubdiv::vector; TopologyRefiner *refiner = topology_refiner->impl->topology_refiner; if (refiner == NULL) { // Happens on bad topology. @@ -480,7 +479,7 @@ OpenSubdiv_EvaluatorImpl *openSubdiv_createEvaluatorInternal( varying_stencils = StencilTableFactory::Create(*refiner, varying_stencil_options); } // Face warying stencil. - vector all_face_varying_stencils; + std::vector all_face_varying_stencils; all_face_varying_stencils.reserve(num_face_varying_channels); for (int face_varying_channel = 0; face_varying_channel < num_face_varying_channels; ++face_varying_channel) diff --git a/intern/opensubdiv/internal/topology/mesh_topology.cc b/intern/opensubdiv/internal/topology/mesh_topology.cc index f3c78ff767f..a207d980801 100644 --- a/intern/opensubdiv/internal/topology/mesh_topology.cc +++ b/intern/opensubdiv/internal/topology/mesh_topology.cc @@ -222,8 +222,8 @@ bool MeshTopology::isFaceVertexIndicesEqual(int face_index, sizeof(int) * num_expected_face_vertex_indices) == 0; } -bool MeshTopology::isFaceVertexIndicesEqual(int face_index, - const vector &expected_face_vertex_indices) const +bool MeshTopology::isFaceVertexIndicesEqual( + int face_index, const std::vector &expected_face_vertex_indices) const { return isFaceVertexIndicesEqual( face_index, expected_face_vertex_indices.size(), expected_face_vertex_indices.data()); diff --git a/intern/opensubdiv/internal/topology/mesh_topology.h b/intern/opensubdiv/internal/topology/mesh_topology.h index 906a0956c82..ab1f6514f1e 100644 --- a/intern/opensubdiv/internal/topology/mesh_topology.h +++ b/intern/opensubdiv/internal/topology/mesh_topology.h @@ -7,10 +7,9 @@ #ifndef OPENSUBDIV_MESH_TOPOLOGY_H_ #define OPENSUBDIV_MESH_TOPOLOGY_H_ -#include +#include #include "internal/base/memory.h" -#include "internal/base/type.h" struct OpenSubdiv_Converter; @@ -93,7 +92,7 @@ class MeshTopology { int num_expected_face_vertex_indices, const int *expected_face_vertex_indices) const; bool isFaceVertexIndicesEqual(int face_index, - const vector &expected_face_vertex_indices) const; + const std::vector &expected_face_vertex_indices) const; ////////////////////////////////////////////////////////////////////////////// // Pipeline related. @@ -142,21 +141,21 @@ class MeshTopology { }; int num_vertices_; - vector vertex_tags_; + std::vector vertex_tags_; int num_edges_; - vector edges_; - vector edge_tags_; + std::vector edges_; + std::vector edge_tags_; int num_faces_; // Continuous array of all vertices of all faces: // [vertex indices of face 0][vertex indices of face 1] .. [vertex indices of face n]. - vector face_vertex_indices_; + std::vector face_vertex_indices_; // Indexed by face contains index within face_vertex_indices_ which corresponds // to the element which contains first vertex of the face. - vector faces_first_vertex_index_; + std::vector faces_first_vertex_index_; MEM_CXX_CLASS_ALLOC_FUNCS("MeshTopology"); }; diff --git a/intern/opensubdiv/internal/topology/mesh_topology_compare.cc b/intern/opensubdiv/internal/topology/mesh_topology_compare.cc index 3098ffd6517..f4e2555df6a 100644 --- a/intern/opensubdiv/internal/topology/mesh_topology_compare.cc +++ b/intern/opensubdiv/internal/topology/mesh_topology_compare.cc @@ -9,8 +9,7 @@ #include #include #include - -#include "internal/base/type.h" +#include #include "opensubdiv_converter_capi.hh" @@ -80,7 +79,7 @@ bool isEqualGeometryFace(const MeshTopology &mesh_topology, const OpenSubdiv_Con return false; } - vector vertices_of_face; + std::vector vertices_of_face; for (int face_index = 0; face_index < num_requested_faces; ++face_index) { int num_face_vertices = converter->getNumFaceVertices(converter, face_index); if (mesh_topology.getNumFaceVertices(face_index) != num_face_vertices) { diff --git a/intern/opensubdiv/internal/topology/topology_refiner_capi.cc b/intern/opensubdiv/internal/topology/topology_refiner_capi.cc index 6404f6b270f..3ab1f28a7d4 100644 --- a/intern/opensubdiv/internal/topology/topology_refiner_capi.cc +++ b/intern/opensubdiv/internal/topology/topology_refiner_capi.cc @@ -10,8 +10,6 @@ #include "internal/base/type_convert.h" #include "internal/topology/topology_refiner_impl.h" -using blender::opensubdiv::vector; - namespace { const OpenSubdiv::Far::TopologyRefiner *getOSDTopologyRefiner( diff --git a/intern/opensubdiv/internal/topology/topology_refiner_factory.cc b/intern/opensubdiv/internal/topology/topology_refiner_factory.cc index 0b201970a77..dda7be3f215 100644 --- a/intern/opensubdiv/internal/topology/topology_refiner_factory.cc +++ b/intern/opensubdiv/internal/topology/topology_refiner_factory.cc @@ -15,16 +15,11 @@ #include -#include "internal/base/type.h" #include "internal/base/type_convert.h" #include "internal/topology/mesh_topology.h" #include "opensubdiv_converter_capi.hh" -using blender::opensubdiv::min; -using blender::opensubdiv::stack; -using blender::opensubdiv::vector; - struct TopologyRefinerData { const OpenSubdiv_Converter *converter; blender::opensubdiv::MeshTopology *base_mesh_topology; @@ -138,7 +133,7 @@ inline bool TopologyRefinerFactory::assignComponentTopology // Vertex relations. const int num_vertices = converter->getNumVertices(converter); - vector vertex_faces, vertex_edges; + std::vector vertex_faces, vertex_edges; for (int vertex_index = 0; vertex_index < num_vertices; ++vertex_index) { // Vertex-faces. IndexArray dst_vertex_faces = getBaseVertexFaces(refiner, vertex_index); @@ -247,8 +242,8 @@ inline bool TopologyRefinerFactory::assignComponentTags( const float sharpness0 = refiner._levels[0]->getEdgeSharpness(edge0); const float sharpness1 = refiner._levels[0]->getEdgeSharpness(edge1); // TODO(sergey): Find a better mixing between edge and vertex sharpness. - sharpness += min(sharpness0, sharpness1); - sharpness = min(sharpness, 10.0f); + sharpness += std::min(sharpness0, sharpness1); + sharpness = std::min(sharpness, 10.0f); } setBaseVertexSharpness(refiner, vertex_index, sharpness); diff --git a/intern/opensubdiv/internal/topology/topology_refiner_impl_compare.cc b/intern/opensubdiv/internal/topology/topology_refiner_impl_compare.cc index be12808d148..6213497caaf 100644 --- a/intern/opensubdiv/internal/topology/topology_refiner_impl_compare.cc +++ b/intern/opensubdiv/internal/topology/topology_refiner_impl_compare.cc @@ -6,7 +6,6 @@ #include "internal/topology/topology_refiner_impl.h" -#include "internal/base/type.h" #include "internal/base/type_convert.h" #include "internal/topology/mesh_topology.h" #include "internal/topology/topology_refiner_impl.h"