[Bf-blender-cvs] [3d6ceb737d8] master: Geometry Nodes: parallelize part of Duplicate Elements node
Jacques Lucke
noreply at git.blender.org
Sun Feb 5 21:00:06 CET 2023
Commit: 3d6ceb737d81361fb27edb017ede826692efa75c
Author: Jacques Lucke
Date: Sun Feb 5 20:59:39 2023 +0100
Branches: master
https://developer.blender.org/rB3d6ceb737d81361fb27edb017ede826692efa75c
Geometry Nodes: parallelize part of Duplicate Elements node
This implements two optimizations:
* If the duplication count is constant, the offsets array can be
filled directly in parallel.
* Otherwise, extracting the counts from the virtual array is parallelized.
But there is still a serial loop over all elements in the end to compute
the offsets.
===================================================================
M source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
===================================================================
diff --git a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
index 586b14ff29f..da4d3c7e641 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
@@ -81,8 +81,22 @@ static OffsetIndices<int> accumulate_counts_to_offsets(const IndexMask selection
Array<int> &r_offset_data)
{
r_offset_data.reinitialize(selection.size() + 1);
- counts.materialize_compressed(selection, r_offset_data);
- offset_indices::accumulate_counts_to_offsets(r_offset_data);
+ if (counts.is_single()) {
+ const int count = counts.get_internal_single();
+ threading::parallel_for(selection.index_range(), 1024, [&](const IndexRange range) {
+ for (const int64_t i : range) {
+ r_offset_data[i] = count * i;
+ }
+ });
+ r_offset_data.last() = count * selection.size();
+ }
+ else {
+ threading::parallel_for(selection.index_range(), 1024, [&](const IndexRange range) {
+ counts.materialize_compressed(selection.slice(range),
+ r_offset_data.as_mutable_span().slice(range));
+ });
+ offset_indices::accumulate_counts_to_offsets(r_offset_data);
+ }
return OffsetIndices<int>(r_offset_data);
}
More information about the Bf-blender-cvs
mailing list