Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-10-19 20:38:48 +0300
committerHans Goudey <h.goudey@me.com>2022-10-19 20:38:48 +0300
commita803dbe7ed80df577b648f9e289aaed2a2cc1700 (patch)
treefd8ad9e281530a070e485db82af31029e2754e76 /source/blender/blenkernel
parente6902d19a0d8b034e65f28df6dba914a876b08df (diff)
Geometry Nodes: Use common utility for copying attribute data
Attribute copying often uses identical logic for copying selected elements or copying with an index map. Instead of reimplementing this in each file, use the common implementation in the array_utils namespace. This makes the commonality more obvious, gives improved performance (this implementation is multithreaded), reduces binary size (I observed a 173KB reduction), and probably reduces compile time.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/intern/curves_geometry.cc13
-rw-r--r--source/blender/blenkernel/intern/instances.cc25
2 files changed, 9 insertions, 29 deletions
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 29f8d62545f..d65c31139fc 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -9,6 +9,7 @@
#include "MEM_guardedalloc.h"
+#include "BLI_array_utils.hh"
#include "BLI_bounds.hh"
#include "BLI_index_mask_ops.hh"
#include "BLI_length_parameterize.hh"
@@ -1111,21 +1112,11 @@ static void copy_between_buffers(const CPPType &type,
src_range.size());
}
-template<typename T>
-static void copy_with_map(const Span<T> src, const Span<int> map, MutableSpan<T> dst)
-{
- threading::parallel_for(map.index_range(), 1024, [&](const IndexRange range) {
- for (const int i : range) {
- dst[i] = src[map[i]];
- }
- });
-}
-
static void copy_with_map(const GSpan src, const Span<int> map, GMutableSpan dst)
{
attribute_math::convert_to_static_type(src.type(), [&](auto dummy) {
using T = decltype(dummy);
- copy_with_map(src.typed<T>(), map, dst.typed<T>());
+ array_utils::gather(src.typed<T>(), map, dst.typed<T>());
});
}
diff --git a/source/blender/blenkernel/intern/instances.cc b/source/blender/blenkernel/intern/instances.cc
index 2f8acf477e2..4675562e927 100644
--- a/source/blender/blenkernel/intern/instances.cc
+++ b/source/blender/blenkernel/intern/instances.cc
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BLI_array_utils.hh"
#include "BLI_cpp_type_make.hh"
#include "BLI_rand.hh"
#include "BLI_task.hh"
@@ -107,18 +108,6 @@ blender::Span<InstanceReference> Instances::references() const
return references_;
}
-template<typename T>
-static void copy_data_based_on_mask(Span<T> src, MutableSpan<T> dst, IndexMask mask)
-{
- BLI_assert(src.data() != dst.data());
- using namespace blender;
- threading::parallel_for(mask.index_range(), 1024, [&](IndexRange range) {
- for (const int i : range) {
- dst[i] = src[mask[i]];
- }
- });
-}
-
void Instances::remove(const IndexMask mask)
{
using namespace blender;
@@ -129,11 +118,14 @@ void Instances::remove(const IndexMask mask)
return;
}
+ const Span<int> old_handles = this->reference_handles();
Vector<int> new_handles(mask.size());
- copy_data_based_on_mask<int>(this->reference_handles(), new_handles, mask);
+ array_utils::gather(old_handles, mask.indices(), new_handles.as_mutable_span());
reference_handles_ = std::move(new_handles);
+
+ const Span<float4x4> old_tansforms = this->transforms();
Vector<float4x4> new_transforms(mask.size());
- copy_data_based_on_mask<float4x4>(this->transforms(), new_transforms, mask);
+ array_utils::gather(old_tansforms, mask.indices(), new_transforms.as_mutable_span());
transforms_ = std::move(new_transforms);
const bke::CustomDataAttributes &src_attributes = attributes_;
@@ -150,11 +142,8 @@ void Instances::remove(const IndexMask mask)
GSpan src = *src_attributes.get_for_read(id);
dst_attributes.create(id, meta_data.data_type);
GMutableSpan dst = *dst_attributes.get_for_write(id);
+ array_utils::gather(src, mask.indices(), dst);
- attribute_math::convert_to_static_type(src.type(), [&](auto dummy) {
- using T = decltype(dummy);
- copy_data_based_on_mask<T>(src.typed<T>(), dst.typed<T>(), mask);
- });
return true;
},
ATTR_DOMAIN_INSTANCE);