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.
This commit is contained in:
Jacques Lucke 2023-02-05 20:59:39 +01:00
parent b7034e7280
commit 3d6ceb737d
1 changed files with 16 additions and 2 deletions

View File

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