[Bf-blender-cvs] [fab14f78542] master: Fix build when using WITH_TBB=OFF after recent changes

Brecht Van Lommel noreply at git.blender.org
Tue Mar 22 01:37:46 CET 2022


Commit: fab14f78542ca040cc1606dbd33a4db6aea5976a
Author: Brecht Van Lommel
Date:   Tue Mar 22 01:13:28 2022 +0100
Branches: master
https://developer.blender.org/rBfab14f78542ca040cc1606dbd33a4db6aea5976a

Fix build when using WITH_TBB=OFF after recent changes

And wrap tbb::parallel_sort in blender namespace similar to other TBB
functionality.

===================================================================

A	source/blender/blenlib/BLI_sort.hh
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/blenlib/intern/mesh_intersect.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_sort.hh b/source/blender/blenlib/BLI_sort.hh
new file mode 100644
index 00000000000..411e6a0c4df
--- /dev/null
+++ b/source/blender/blenlib/BLI_sort.hh
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#pragma once
+
+/** \file
+ * \ingroup bli
+ */
+
+#ifdef WITH_TBB
+#  include <tbb/parallel_sort.h>
+#else
+#  include <algorithm>
+#endif
+
+namespace blender {
+
+#ifdef WITH_TBB
+using tbb::parallel_sort;
+#else
+template<typename RandomAccessIterator>
+void parallel_sort(RandomAccessIterator begin, RandomAccessIterator end)
+{
+  std::sort<RandomAccessIterator>(begin, end);
+}
+template<typename RandomAccessIterator, typename Compare>
+void parallel_sort(RandomAccessIterator begin, RandomAccessIterator end, const Compare &comp)
+{
+  std::sort<RandomAccessIterator, Compare>(begin, end, comp);
+}
+#endif
+
+}  // namespace blender
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 6c216f873de..af71c96fc10 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -285,6 +285,7 @@ set(SRC
   BLI_simd.h
   BLI_smallhash.h
   BLI_sort.h
+  BLI_sort.hh
   BLI_sort_utils.h
   BLI_span.hh
   BLI_stack.h
diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc
index 8f2c86556aa..96ae0750899 100644
--- a/source/blender/blenlib/intern/mesh_intersect.cc
+++ b/source/blender/blenlib/intern/mesh_intersect.cc
@@ -26,6 +26,7 @@
 #  include "BLI_math_vector.h"
 #  include "BLI_polyfill_2d.h"
 #  include "BLI_set.hh"
+#  include "BLI_sort.hh"
 #  include "BLI_span.hh"
 #  include "BLI_task.h"
 #  include "BLI_task.hh"
@@ -37,10 +38,6 @@
 
 #  include "BLI_mesh_intersect.hh"
 
-#  ifdef WITH_TBB
-#    include <tbb/parallel_sort.h>
-#  endif
-
 // #  define PERFDEBUG
 
 namespace blender::meshintersect {
@@ -672,11 +669,7 @@ void IMesh::populate_vert(int max_verts)
    * TODO: when all debugged, set fix_order = false. */
   const bool fix_order = true;
   if (fix_order) {
-#  ifdef WITH_TBB
-    tbb::parallel_sort(vert_.begin(), vert_.end(), [](const Vert *a, const Vert *b) {
-#  else
-    std::sort(vert_.begin(), vert_.end(), [](const Vert *a, const Vert *b) {
-#  endif
+    blender::parallel_sort(vert_.begin(), vert_.end(), [](const Vert *a, const Vert *b) {
       if (a->orig != NO_INDEX && b->orig != NO_INDEX) {
         return a->orig < b->orig;
       }
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
index 9975f300150..a7508f01b0f 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
@@ -17,6 +17,7 @@
 #include "BLI_listbase.h"
 #include "BLI_map.hh"
 #include "BLI_math.h"
+#include "BLI_sort.hh"
 
 #include "DEG_depsgraph_query.h"
 
@@ -27,10 +28,6 @@
 
 #include "obj_export_mesh.hh"
 
-#ifdef WITH_TBB
-#  include <tbb/parallel_sort.h>
-#endif
-
 namespace blender::io::obj {
 OBJMesh::OBJMesh(Depsgraph *depsgraph, const OBJExportParams &export_params, Object *mesh_object)
 {
@@ -207,11 +204,7 @@ void OBJMesh::calc_poly_order()
   }
   const MPoly *mpolys = export_mesh_eval_->mpoly;
   /* Sort polygons by their material index. */
-#ifdef WITH_TBB
-  tbb::parallel_sort(poly_order_.begin(), poly_order_.end(), [&](int a, int b) {
-#else
-  std::sort(poly_order_.begin(), poly_order_.end(), [&](const Vert *a, const Vert *b) {
-#endif
+  blender::parallel_sort(poly_order_.begin(), poly_order_.end(), [&](int a, int b) {
     int mat_a = mpolys[a].mat_nr;
     int mat_b = mpolys[b].mat_nr;
     return mat_a < mat_b;



More information about the Bf-blender-cvs mailing list