Fix build when using WITH_TBB=OFF after recent changes

And wrap tbb::parallel_sort in blender namespace similar to other TBB
functionality.
This commit is contained in:
Brecht Van Lommel 2022-03-22 01:13:28 +01:00
parent 976c91cd77
commit fab14f7854
4 changed files with 37 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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;