BLI: add threading namespace

This namespace groups threading related functions/classes. This avoids
adding more threading related stuff to the blender namespace. Also it
makes naming a bit easier, e.g. the c++ version of BLI_task_isolate could
become blender::threading::isolate_task or something similar.

Differential Revision: https://developer.blender.org/D11624
This commit is contained in:
Jacques Lucke 2021-06-16 16:13:53 +02:00
parent 0cebe554d1
commit 45d59e0df5
23 changed files with 80 additions and 78 deletions

View File

@ -87,7 +87,7 @@ static void reserve_hash_maps(const Mesh *mesh,
MutableSpan<EdgeMap> edge_maps)
{
const int totedge_guess = std::max(keep_existing_edges ? mesh->totedge : 0, mesh->totpoly * 2);
parallel_for_each(
threading::parallel_for_each(
edge_maps, [&](EdgeMap &edge_map) { edge_map.reserve(totedge_guess / edge_maps.size()); });
}
@ -96,7 +96,7 @@ static void add_existing_edges_to_hash_maps(Mesh *mesh,
uint32_t parallel_mask)
{
/* Assume existing edges are valid. */
parallel_for_each(edge_maps, [&](EdgeMap &edge_map) {
threading::parallel_for_each(edge_maps, [&](EdgeMap &edge_map) {
const int task_index = &edge_map - &edge_maps[0];
for (const MEdge &edge : Span(mesh->medge, mesh->totedge)) {
OrderedEdge ordered_edge{edge.v1, edge.v2};
@ -113,7 +113,7 @@ static void add_polygon_edges_to_hash_maps(Mesh *mesh,
uint32_t parallel_mask)
{
const Span<MLoop> loops{mesh->mloop, mesh->totloop};
parallel_for_each(edge_maps, [&](EdgeMap &edge_map) {
threading::parallel_for_each(edge_maps, [&](EdgeMap &edge_map) {
const int task_index = &edge_map - &edge_maps[0];
for (const MPoly &poly : Span(mesh->mpoly, mesh->totpoly)) {
Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
@ -146,7 +146,7 @@ static void serialize_and_initialize_deduplicated_edges(MutableSpan<EdgeMap> edg
edge_index_offsets[i + 1] = edge_index_offsets[i] + edge_maps[i].size();
}
parallel_for_each(edge_maps, [&](EdgeMap &edge_map) {
threading::parallel_for_each(edge_maps, [&](EdgeMap &edge_map) {
const int task_index = &edge_map - &edge_maps[0];
int new_edge_index = edge_index_offsets[task_index];
@ -174,7 +174,7 @@ static void update_edge_indices_in_poly_loops(Mesh *mesh,
uint32_t parallel_mask)
{
const MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
parallel_for(IndexRange(mesh->totpoly), 100, [&](IndexRange range) {
threading::parallel_for(IndexRange(mesh->totpoly), 100, [&](IndexRange range) {
for (const int poly_index : range) {
MPoly &poly = mesh->mpoly[poly_index];
MutableSpan<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
@ -215,7 +215,7 @@ static int get_parallel_maps_count(const Mesh *mesh)
static void clear_hash_tables(MutableSpan<EdgeMap> edge_maps)
{
parallel_for_each(edge_maps, [](EdgeMap &edge_map) { edge_map.clear(); });
threading::parallel_for_each(edge_maps, [](EdgeMap &edge_map) { edge_map.clear(); });
}
} // namespace blender::bke::calc_edges

View File

@ -378,7 +378,7 @@ void Spline::sample_based_on_index_factors(const GVArray &src,
using T = decltype(dummy);
const GVArray_Typed<T> src_typed = src.typed<T>();
MutableSpan<T> dst_typed = dst.typed<T>();
blender::parallel_for(dst_typed.index_range(), 1024, [&](IndexRange range) {
blender::threading::parallel_for(dst_typed.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
const LookupResult interp = this->lookup_data_from_index_factor(index_factors[i]);
dst_typed[i] = blender::attribute_math::mix2(interp.factor,

View File

@ -417,7 +417,7 @@ static void calculate_mappings_linear_resolution(Span<int> offsets,
}
const int grain_size = std::max(2048 / resolution, 1);
parallel_for(IndexRange(1, size - 2), grain_size, [&](IndexRange range) {
blender::threading::parallel_for(IndexRange(1, size - 2), grain_size, [&](IndexRange range) {
for (const int i_control_point : range) {
const int segment_len = offsets[i_control_point + 1] - offsets[i_control_point];
const float segment_len_inv = 1.0f / segment_len;
@ -497,7 +497,7 @@ Span<float3> BezierSpline::evaluated_positions() const
Span<int> offsets = this->control_point_offsets();
const int grain_size = std::max(512 / resolution_, 1);
parallel_for(IndexRange(size - 1), grain_size, [&](IndexRange range) {
blender::threading::parallel_for(IndexRange(size - 1), grain_size, [&](IndexRange range) {
for (const int i : range) {
this->evaluate_segment(i, i + 1, positions.slice(offsets[i], offsets[i + 1] - offsets[i]));
}

View File

@ -26,7 +26,7 @@
#include "BLI_map.hh"
#include "BLI_utility_mixins.hh"
namespace blender {
namespace blender::threading {
namespace enumerable_thread_specific_utils {
inline std::atomic<int> next_id = 0;
@ -70,4 +70,4 @@ template<typename T> class EnumerableThreadSpecific : NonCopyable, NonMovable {
#endif /* WITH_TBB */
};
} // namespace blender
} // namespace blender::threading

View File

@ -44,7 +44,7 @@
#include "BLI_index_range.hh"
#include "BLI_utildefines.h"
namespace blender {
namespace blender::threading {
template<typename Range, typename Function>
void parallel_for_each(Range &range, const Function &function)
@ -75,4 +75,4 @@ void parallel_for(IndexRange range, int64_t grain_size, const Function &function
#endif
}
} // namespace blender
} // namespace blender::threading

View File

@ -1983,7 +1983,7 @@ static void populate_comp_bbs(const Vector<Vector<int>> &components,
* absolute value of any coordinate. Do it first per component,
* then get the overall max. */
Array<double> max_abs(components.size(), 0.0);
parallel_for(components.index_range(), comp_grainsize, [&](IndexRange comp_range) {
threading::parallel_for(components.index_range(), comp_grainsize, [&](IndexRange comp_range) {
for (int c : comp_range) {
BoundingBox &bb = comp_bb[c];
double &maxa = max_abs[c];
@ -2691,7 +2691,7 @@ static IMesh raycast_tris_boolean(const IMesh &tm,
tbb::spin_mutex mtx;
# endif
const int grainsize = 256;
parallel_for(IndexRange(tm.face_size()), grainsize, [&](IndexRange range) {
threading::parallel_for(IndexRange(tm.face_size()), grainsize, [&](IndexRange range) {
Array<float> in_shape(nshapes, 0);
Array<int> winding(nshapes, 0);
for (int t : range) {
@ -3391,7 +3391,7 @@ static IMesh polymesh_from_trimesh_with_dissolve(const IMesh &tm_out,
}
/* For now: need plane normals for all triangles. */
const int grainsize = 1024;
parallel_for(tm_out.face_index_range(), grainsize, [&](IndexRange range) {
threading::parallel_for(tm_out.face_index_range(), grainsize, [&](IndexRange range) {
for (int i : range) {
Face *tri = tm_out.face(i);
tri->populate_plane(false);

View File

@ -352,7 +352,7 @@ class GeometryNodesEvaluator {
* on cache line boundaries. Note, just because a value is allocated in one specific thread,
* does not mean that it will only be used by that thread.
*/
EnumerableThreadSpecific<LinearAllocator<>> local_allocators_;
threading::EnumerableThreadSpecific<LinearAllocator<>> local_allocators_;
/**
* Every node that is reachable from the output gets its own state. Once all states have been
@ -426,12 +426,13 @@ class GeometryNodesEvaluator {
/* Initialize the more complex parts of the node states in parallel. At this point no new
* node states are added anymore, so it is safe to lookup states from `node_states_` from
* multiple threads. */
parallel_for(IndexRange(node_states_.size()), 50, [&, this](const IndexRange range) {
LinearAllocator<> &allocator = this->local_allocators_.local();
for (const NodeWithState &item : node_states_.as_span().slice(range)) {
this->initialize_node_state(item.node, *item.state, allocator);
}
});
threading::parallel_for(
IndexRange(node_states_.size()), 50, [&, this](const IndexRange range) {
LinearAllocator<> &allocator = this->local_allocators_.local();
for (const NodeWithState &item : node_states_.as_span().slice(range)) {
this->initialize_node_state(item.node, *item.state, allocator);
}
});
}
void initialize_node_state(const DNode node, NodeState &node_state, LinearAllocator<> &allocator)
@ -507,11 +508,12 @@ class GeometryNodesEvaluator {
void destruct_node_states()
{
parallel_for(IndexRange(node_states_.size()), 50, [&, this](const IndexRange range) {
for (const NodeWithState &item : node_states_.as_span().slice(range)) {
this->destruct_node_state(item.node, *item.state);
}
});
threading::parallel_for(
IndexRange(node_states_.size()), 50, [&, this](const IndexRange range) {
for (const NodeWithState &item : node_states_.as_span().slice(range)) {
this->destruct_node_state(item.node, *item.state);
}
});
}
void destruct_node_state(const DNode node, NodeState &node_state)

View File

@ -78,7 +78,7 @@ static void align_rotations_auto_pivot(const VArray<float3> &vectors,
const float3 local_main_axis,
const MutableSpan<float3> rotations)
{
parallel_for(IndexRange(vectors.size()), 128, [&](IndexRange range) {
threading::parallel_for(IndexRange(vectors.size()), 128, [&](IndexRange range) {
for (const int i : range) {
const float3 vector = vectors[i];
if (is_zero_v3(vector)) {
@ -129,7 +129,7 @@ static void align_rotations_fixed_pivot(const VArray<float3> &vectors,
return;
}
parallel_for(IndexRange(vectors.size()), 128, [&](IndexRange range) {
threading::parallel_for(IndexRange(vectors.size()), 128, [&](IndexRange range) {
for (const int i : range) {
const float3 vector = vectors[i];
if (is_zero_v3(vector)) {

View File

@ -95,7 +95,7 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
MutableSpan<ColorGeometry4f> results = attribute_result.as_span();
ColorBand *color_ramp = &node_storage->color_ramp;
parallel_for(IndexRange(attribute_in.size()), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(attribute_in.size()), 512, [&](IndexRange range) {
for (const int i : range) {
BKE_colorband_evaluate(color_ramp, attribute_in[i], results[i]);
}

View File

@ -144,7 +144,7 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
GVArray_Typed<float> attribute_in = component.attribute_get_for_read<float>(
input_name, result_domain, float(0.0f));
MutableSpan<float> results = attribute_result.as_span<float>();
parallel_for(IndexRange(attribute_in.size()), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(attribute_in.size()), 512, [&](IndexRange range) {
for (const int i : range) {
results[i] = BKE_curvemapping_evaluateF(cumap, 3, attribute_in[i]);
}
@ -156,7 +156,7 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
GVArray_Typed<float3> attribute_in = component.attribute_get_for_read<float3>(
input_name, result_domain, float3(0.0f));
MutableSpan<float3> results = attribute_result.as_span<float3>();
parallel_for(IndexRange(attribute_in.size()), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(attribute_in.size()), 512, [&](IndexRange range) {
for (const int i : range) {
BKE_curvemapping_evaluate3F(cumap, results[i], attribute_in[i]);
}
@ -169,7 +169,7 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
component.attribute_get_for_read<ColorGeometry4f>(
input_name, result_domain, ColorGeometry4f(0.0f, 0.0f, 0.0f, 1.0f));
MutableSpan<ColorGeometry4f> results = attribute_result.as_span<ColorGeometry4f>();
parallel_for(IndexRange(attribute_in.size()), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(attribute_in.size()), 512, [&](IndexRange range) {
for (const int i : range) {
BKE_curvemapping_evaluateRGBF(cumap, results[i], attribute_in[i]);
}

View File

@ -209,7 +209,7 @@ static void map_range_float(const VArray<float> &attribute_input,
switch (interpolation_type) {
case NODE_MAP_RANGE_LINEAR: {
parallel_for(span.index_range(), 2048, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 2048, [&](IndexRange range) {
for (const int i : range) {
results[i] = map_linear(span[i], min_from, max_from, min_to, max_to);
}
@ -218,7 +218,7 @@ static void map_range_float(const VArray<float> &attribute_input,
}
case NODE_MAP_RANGE_STEPPED: {
const float steps = params.get_input<float>("Steps");
parallel_for(span.index_range(), 1024, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
results[i] = map_stepped(span[i], min_from, max_from, min_to, max_to, steps);
}
@ -226,7 +226,7 @@ static void map_range_float(const VArray<float> &attribute_input,
break;
}
case NODE_MAP_RANGE_SMOOTHSTEP: {
parallel_for(span.index_range(), 1024, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
results[i] = map_smoothstep(span[i], min_from, max_from, min_to, max_to);
}
@ -234,7 +234,7 @@ static void map_range_float(const VArray<float> &attribute_input,
break;
}
case NODE_MAP_RANGE_SMOOTHERSTEP: {
parallel_for(span.index_range(), 1024, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
results[i] = map_smootherstep(span[i], min_from, max_from, min_to, max_to);
}
@ -249,7 +249,7 @@ static void map_range_float(const VArray<float> &attribute_input,
const float clamp_min = min_to < max_to ? min_to : max_to;
const float clamp_max = min_to < max_to ? max_to : min_to;
parallel_for(results.index_range(), 2048, [&](IndexRange range) {
threading::parallel_for(results.index_range(), 2048, [&](IndexRange range) {
for (const int i : range) {
results[i] = std::clamp(results[i], clamp_min, clamp_max);
}
@ -273,7 +273,7 @@ static void map_range_float3(const VArray<float3> &attribute_input,
switch (interpolation_type) {
case NODE_MAP_RANGE_LINEAR: {
parallel_for(span.index_range(), 1024, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
results[i].x = map_linear(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x);
results[i].y = map_linear(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y);
@ -284,7 +284,7 @@ static void map_range_float3(const VArray<float3> &attribute_input,
}
case NODE_MAP_RANGE_STEPPED: {
const float3 steps = params.get_input<float3>("Steps_001");
parallel_for(span.index_range(), 1024, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
results[i].x = map_stepped(
span[i].x, min_from.x, max_from.x, min_to.x, max_to.x, steps.x);
@ -297,7 +297,7 @@ static void map_range_float3(const VArray<float3> &attribute_input,
break;
}
case NODE_MAP_RANGE_SMOOTHSTEP: {
parallel_for(span.index_range(), 1024, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
results[i].x = map_smoothstep(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x);
results[i].y = map_smoothstep(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y);
@ -307,7 +307,7 @@ static void map_range_float3(const VArray<float3> &attribute_input,
break;
}
case NODE_MAP_RANGE_SMOOTHERSTEP: {
parallel_for(span.index_range(), 1024, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
results[i].x = map_smootherstep(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x);
results[i].y = map_smootherstep(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y);

View File

@ -159,7 +159,7 @@ static void do_math_operation(const VArray<float> &span_a,
{
bool success = try_dispatch_float_math_fl_fl_fl_to_fl(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(span_result.size()), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(span_result.size()), 512, [&](IndexRange range) {
for (const int i : range) {
span_result[i] = math_function(span_a[i], span_b[i], span_c[i]);
}
@ -176,7 +176,7 @@ static void do_math_operation(const VArray<float> &span_a,
{
bool success = try_dispatch_float_math_fl_fl_to_fl(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(span_result.size()), 1024, [&](IndexRange range) {
threading::parallel_for(IndexRange(span_result.size()), 1024, [&](IndexRange range) {
for (const int i : range) {
span_result[i] = math_function(span_a[i], span_b[i]);
}
@ -192,7 +192,7 @@ static void do_math_operation(const VArray<float> &span_input,
{
bool success = try_dispatch_float_math_fl_to_fl(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(span_result.size()), 1024, [&](IndexRange range) {
threading::parallel_for(IndexRange(span_result.size()), 1024, [&](IndexRange range) {
for (const int i : range) {
span_result[i] = math_function(span_input[i]);
}

View File

@ -88,7 +88,7 @@ static void do_mix_operation_float(const int blend_mode,
VMutableArray<float> &results)
{
const int size = results.size();
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float factor = factors[i];
float3 a{inputs_a[i]};
@ -107,7 +107,7 @@ static void do_mix_operation_float3(const int blend_mode,
VMutableArray<float3> &results)
{
const int size = results.size();
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float factor = factors[i];
float3 a = inputs_a[i];
@ -125,7 +125,7 @@ static void do_mix_operation_color4f(const int blend_mode,
VMutableArray<ColorGeometry4f> &results)
{
const int size = results.size();
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float factor = factors[i];
ColorGeometry4f a = inputs_a[i];

View File

@ -71,7 +71,7 @@ static void proximity_calc(MutableSpan<float> distance_span,
const bool store_locations)
{
IndexRange range = positions.index_range();
parallel_for(range, 512, [&](IndexRange range) {
threading::parallel_for(range, 512, [&](IndexRange range) {
BVHTreeNearest nearest_from_mesh;
BVHTreeNearest nearest_from_pointcloud;

View File

@ -126,7 +126,7 @@ static void randomize_attribute(MutableSpan<T> span,
/* The operations could be templated too, but it doesn't make the code much shorter. */
switch (operation) {
case GEO_NODE_ATTRIBUTE_RANDOMIZE_REPLACE_CREATE:
parallel_for(span.index_range(), 512, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 512, [&](IndexRange range) {
for (const int i : range) {
const T random_value = random_value_in_range<T>(ids[i], seed, min, max);
span[i] = random_value;
@ -134,7 +134,7 @@ static void randomize_attribute(MutableSpan<T> span,
});
break;
case GEO_NODE_ATTRIBUTE_RANDOMIZE_ADD:
parallel_for(span.index_range(), 512, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 512, [&](IndexRange range) {
for (const int i : range) {
const T random_value = random_value_in_range<T>(ids[i], seed, min, max);
span[i] = span[i] + random_value;
@ -142,7 +142,7 @@ static void randomize_attribute(MutableSpan<T> span,
});
break;
case GEO_NODE_ATTRIBUTE_RANDOMIZE_SUBTRACT:
parallel_for(span.index_range(), 512, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 512, [&](IndexRange range) {
for (const int i : range) {
const T random_value = random_value_in_range<T>(ids[i], seed, min, max);
span[i] = span[i] - random_value;
@ -150,7 +150,7 @@ static void randomize_attribute(MutableSpan<T> span,
});
break;
case GEO_NODE_ATTRIBUTE_RANDOMIZE_MULTIPLY:
parallel_for(span.index_range(), 512, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 512, [&](IndexRange range) {
for (const int i : range) {
const T random_value = random_value_in_range<T>(ids[i], seed, min, max);
span[i] = span[i] * random_value;
@ -170,7 +170,7 @@ static void randomize_attribute_bool(MutableSpan<bool> span,
{
BLI_assert(operation == GEO_NODE_ATTRIBUTE_RANDOMIZE_REPLACE_CREATE);
UNUSED_VARS_NDEBUG(operation);
parallel_for(span.index_range(), 512, [&](IndexRange range) {
threading::parallel_for(span.index_range(), 512, [&](IndexRange range) {
for (const int i : range) {
const bool random_value = BLI_hash_int_2d_to_float(ids[i], seed) > 0.5f;
span[i] = random_value;
@ -190,7 +190,7 @@ Array<uint32_t> get_geometry_element_ids_as_uints(const GeometryComponent &compo
BLI_assert(hashes.size() == hash_attribute->size());
const CPPType &cpp_type = hash_attribute->type();
GVArray_GSpan items{*hash_attribute};
parallel_for(hashes.index_range(), 512, [&](IndexRange range) {
threading::parallel_for(hashes.index_range(), 512, [&](IndexRange range) {
for (const int i : range) {
hashes[i] = cpp_type.hash(items[i]);
}

View File

@ -90,7 +90,7 @@ static void execute_on_component(GeometryComponent &component, const GeoNodeExec
mapping_name, result_domain, {0, 0, 0});
MutableSpan<ColorGeometry4f> colors = attribute_out.as_span();
parallel_for(IndexRange(mapping_attribute.size()), 128, [&](IndexRange range) {
threading::parallel_for(IndexRange(mapping_attribute.size()), 128, [&](IndexRange range) {
for (const int i : range) {
TexResult texture_result = {0};
const float3 position = mapping_attribute[i];

View File

@ -186,7 +186,7 @@ static void do_math_operation_fl3_fl3_to_fl3(const VArray<float3> &input_a,
bool success = try_dispatch_float_math_fl3_fl3_to_fl3(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float3 a = span_a[i];
const float3 b = span_b[i];
@ -218,7 +218,7 @@ static void do_math_operation_fl3_fl3_fl3_to_fl3(const VArray<float3> &input_a,
bool success = try_dispatch_float_math_fl3_fl3_fl3_to_fl3(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float3 a = span_a[i];
const float3 b = span_b[i];
@ -251,7 +251,7 @@ static void do_math_operation_fl3_fl3_fl_to_fl3(const VArray<float3> &input_a,
bool success = try_dispatch_float_math_fl3_fl3_fl_to_fl3(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float3 a = span_a[i];
const float3 b = span_b[i];
@ -282,7 +282,7 @@ static void do_math_operation_fl3_fl3_to_fl(const VArray<float3> &input_a,
bool success = try_dispatch_float_math_fl3_fl3_to_fl(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float3 a = span_a[i];
const float3 b = span_b[i];
@ -312,7 +312,7 @@ static void do_math_operation_fl3_fl_to_fl3(const VArray<float3> &input_a,
bool success = try_dispatch_float_math_fl3_fl_to_fl3(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float3 a = span_a[i];
const float b = span_b[i];
@ -340,7 +340,7 @@ static void do_math_operation_fl3_to_fl3(const VArray<float3> &input_a,
bool success = try_dispatch_float_math_fl3_to_fl3(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float3 in = span_a[i];
const float3 out = math_function(in);
@ -367,7 +367,7 @@ static void do_math_operation_fl3_to_fl(const VArray<float3> &input_a,
bool success = try_dispatch_float_math_fl3_to_fl(
operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
parallel_for(IndexRange(size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(size), 512, [&](IndexRange range) {
for (const int i : range) {
const float3 in = span_a[i];
const float out = math_function(in);

View File

@ -154,7 +154,7 @@ static void do_vector_rotate_around_axis(const VArray<float3> &vector,
VArray_Span<float3> span_axis{axis};
VArray_Span<float> span_angle{angle};
parallel_for(IndexRange(results.size()), 1024, [&](IndexRange range) {
threading::parallel_for(IndexRange(results.size()), 1024, [&](IndexRange range) {
for (const int i : range) {
float angle = (invert) ? -span_angle[i] : span_angle[i];
results[i] = vector_rotate_around_axis(span_vector[i], span_center[i], span_axis[i], angle);
@ -173,7 +173,7 @@ static void do_vector_rotate_around_fixed_axis(const VArray<float3> &vector,
VArray_Span<float3> span_center{center};
VArray_Span<float> span_angle{angle};
parallel_for(IndexRange(results.size()), 1024, [&](IndexRange range) {
threading::parallel_for(IndexRange(results.size()), 1024, [&](IndexRange range) {
for (const int i : range) {
float angle = (invert) ? -span_angle[i] : span_angle[i];
results[i] = vector_rotate_around_axis(span_vector[i], span_center[i], axis, angle);
@ -191,7 +191,7 @@ static void do_vector_rotate_euler(const VArray<float3> &vector,
VArray_Span<float3> span_center{center};
VArray_Span<float3> span_rotation{rotation};
parallel_for(IndexRange(results.size()), 1024, [&](IndexRange range) {
threading::parallel_for(IndexRange(results.size()), 1024, [&](IndexRange range) {
for (const int i : range) {
results[i] = vector_rotate_euler(span_vector[i], span_center[i], span_rotation[i], invert);
}

View File

@ -76,7 +76,7 @@ static void geo_node_curve_reverse_exec(GeoNodeExecParams params)
GVArray_Typed<bool> selection = curve_component.attribute_get_for_read(
selection_name, ATTR_DOMAIN_CURVE, true);
parallel_for(splines.index_range(), 128, [&](IndexRange range) {
threading::parallel_for(splines.index_range(), 128, [&](IndexRange range) {
for (const int i : range) {
if (!selection[i]) {
continue;

View File

@ -71,7 +71,7 @@ namespace blender::nodes {
*/
static void evaluate_splines(Span<SplinePtr> splines)
{
parallel_for_each(splines, [](const SplinePtr &spline) {
threading::parallel_for_each(splines, [](const SplinePtr &spline) {
/* These functions fill the corresponding caches on each spline. */
spline->evaluated_positions();
spline->evaluated_tangents();
@ -192,7 +192,7 @@ static void copy_evaluated_point_attributes(Span<SplinePtr> splines,
Span<int> offsets,
ResultAttributes &data)
{
parallel_for(splines.index_range(), 64, [&](IndexRange range) {
threading::parallel_for(splines.index_range(), 64, [&](IndexRange range) {
for (const int i : range) {
const Spline &spline = *splines[i];
const int offset = offsets[i];
@ -225,7 +225,7 @@ static void copy_uniform_sample_point_attributes(Span<SplinePtr> splines,
Span<int> offsets,
ResultAttributes &data)
{
parallel_for(splines.index_range(), 64, [&](IndexRange range) {
threading::parallel_for(splines.index_range(), 64, [&](IndexRange range) {
for (const int i : range) {
const Spline &spline = *splines[i];
const int offset = offsets[i];
@ -313,7 +313,7 @@ static void copy_spline_domain_attributes(const CurveComponent &curve_component,
static void create_default_rotation_attribute(ResultAttributes &data)
{
parallel_for(IndexRange(data.result_size), 512, [&](IndexRange range) {
threading::parallel_for(IndexRange(data.result_size), 512, [&](IndexRange range) {
for (const int i : range) {
data.rotations[i] = float4x4::from_normalized_axis_data(
{0, 0, 0}, data.normals[i], data.tangents[i])

View File

@ -62,7 +62,7 @@ static void copy_attributes_to_points(CurveEval &curve,
if (source_attribute_names.contains_as("tilt")) {
const GVArray_Typed<float> tilt_attribute = mesh_component.attribute_get_for_read<float>(
"tilt", ATTR_DOMAIN_POINT, 0.0f);
parallel_for(splines.index_range(), 256, [&](IndexRange range) {
threading::parallel_for(splines.index_range(), 256, [&](IndexRange range) {
for (const int i : range) {
copy_attribute_to_points<float>(
*tilt_attribute, point_to_vert_maps[i], splines[i]->tilts());
@ -73,7 +73,7 @@ static void copy_attributes_to_points(CurveEval &curve,
if (source_attribute_names.contains_as("radius")) {
const GVArray_Typed<float> radius_attribute = mesh_component.attribute_get_for_read<float>(
"radius", ATTR_DOMAIN_POINT, 1.0f);
parallel_for(splines.index_range(), 256, [&](IndexRange range) {
threading::parallel_for(splines.index_range(), 256, [&](IndexRange range) {
for (const int i : range) {
copy_attribute_to_points<float>(
*radius_attribute, point_to_vert_maps[i], splines[i]->radii());
@ -97,7 +97,7 @@ static void copy_attributes_to_points(CurveEval &curve,
const CustomDataType data_type = bke::cpp_type_to_custom_data_type(mesh_attribute->type());
parallel_for(splines.index_range(), 128, [&](IndexRange range) {
threading::parallel_for(splines.index_range(), 128, [&](IndexRange range) {
for (const int i : range) {
/* Create attribute on the spline points. */
splines[i]->attributes.create(name, data_type);

View File

@ -189,7 +189,7 @@ static void add_instances_from_component(InstancesComponent &instances,
* (anything except for collection mode with "Whole Collection" turned off). */
if (possible_handles.size() == 1) {
const int handle = possible_handles.first();
parallel_for(IndexRange(domain_size), 1024, [&](IndexRange range) {
threading::parallel_for(IndexRange(domain_size), 1024, [&](IndexRange range) {
for (const int i : range) {
handles[i] = handle;
transforms[i] = float4x4::from_loc_eul_scale(positions[i], rotations[i], scales[i]);
@ -200,7 +200,7 @@ static void add_instances_from_component(InstancesComponent &instances,
else {
const int seed = params.get_input<int>("Seed");
Array<uint32_t> ids = get_geometry_element_ids_as_uints(src_geometry, ATTR_DOMAIN_POINT);
parallel_for(IndexRange(domain_size), 1024, [&](IndexRange range) {
threading::parallel_for(IndexRange(domain_size), 1024, [&](IndexRange range) {
for (const int i : range) {
const int index = BLI_hash_int_2d(ids[i], seed) % possible_handles.size();
const int handle = possible_handles[index];

View File

@ -60,7 +60,7 @@ static void select_mesh_by_material(const Mesh &mesh,
material_indices.append(i);
}
}
parallel_for(r_selection.index_range(), 1024, [&](IndexRange range) {
threading::parallel_for(r_selection.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
r_selection[i] = material_indices.contains(mesh.mpoly[i].mat_nr);
}