[Bf-blender-cvs] [068f0122213] temp-parallel-multi-function: initial commit

Jacques Lucke noreply at git.blender.org
Fri Sep 10 11:02:27 CEST 2021


Commit: 068f0122213b1574ccad7ec1335969ad65bbf0d2
Author: Jacques Lucke
Date:   Wed Sep 8 15:47:45 2021 +0200
Branches: temp-parallel-multi-function
https://developer.blender.org/rB068f0122213b1574ccad7ec1335969ad65bbf0d2

initial commit

===================================================================

M	source/blender/functions/FN_generic_virtual_array.hh
A	source/blender/functions/FN_multi_function_parallel.hh
M	source/blender/functions/intern/generic_virtual_array.cc

===================================================================

diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index f429243e2de..b883db6fa31 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -911,4 +911,50 @@ template<typename T> class GVMutableArray_Typed {
   }
 };
 
+class GVArray_For_SlicedGVArray : public GVArray {
+ protected:
+  const GVArray &varray_;
+  int64_t offset_;
+
+ public:
+  GVArray_For_SlicedGVArray(const GVArray &varray, const IndexRange slice)
+      : GVArray(varray.type(), slice.size()), varray_(varray), offset_(slice.start())
+  {
+    BLI_assert(slice.one_after_last() <= varray.size());
+  }
+
+  void get_impl(const int64_t index, void *r_value) const override;
+  void get_to_uninitialized_impl(const int64_t index, void *r_value) const override;
+};
+
+/**
+ * Utility class to create the "best" sliced virtual array.
+ */
+class GVArray_Slice {
+ private:
+  const GVArray *varray_;
+  /* Of these optional virtual arrays, at most one is constructed at any time. */
+  std::optional<GVArray_For_GSpan> varray_span_;
+  std::optional<GVArray_For_SingleValue> varray_single_;
+  std::optional<GVArray_For_SlicedGVArray> varray_any_;
+
+ public:
+  GVArray_Slice(const GVArray &varray, const IndexRange slice);
+
+  const GVArray &operator*()
+  {
+    return *varray_;
+  }
+
+  const GVArray *operator->()
+  {
+    return varray_;
+  }
+
+  operator const GVArray &()
+  {
+    return *varray_;
+  }
+};
+
 }  // namespace blender::fn
diff --git a/source/blender/functions/FN_multi_function_parallel.hh b/source/blender/functions/FN_multi_function_parallel.hh
new file mode 100644
index 00000000000..b5b3e2f2f94
--- /dev/null
+++ b/source/blender/functions/FN_multi_function_parallel.hh
@@ -0,0 +1,24 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup fn
+ */
+
+namespace blender::fn {
+}
diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc
index bd033a429de..a3096417212 100644
--- a/source/blender/functions/intern/generic_virtual_array.cc
+++ b/source/blender/functions/intern/generic_virtual_array.cc
@@ -387,4 +387,43 @@ void GVMutableArray_GSpan::disable_not_applied_warning()
   show_not_saved_warning_ = false;
 }
 
+/* --------------------------------------------------------------------
+ * GVArray_For_SlicedGVArray.
+ */
+
+void GVArray_For_SlicedGVArray::get_impl(const int64_t index, void *r_value) const
+{
+  varray_.get(index + offset_, r_value);
+}
+
+void GVArray_For_SlicedGVArray::get_to_uninitialized_impl(const int64_t index, void *r_value) const
+{
+  varray_.get_to_uninitialized(index + offset_, r_value);
+}
+
+/* --------------------------------------------------------------------
+ * GVArray_Slice.
+ */
+
+GVArray_Slice::GVArray_Slice(const GVArray &varray, const IndexRange slice)
+{
+  const CPPType &type = varray.type();
+  if (varray.is_span()) {
+    const GSpan span = varray.get_internal_span();
+    varray_span_.emplace(span.slice(slice.start(), slice.size()));
+    varray_ = &*varray_span_;
+  }
+  else if (varray.is_single()) {
+    BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
+    varray_->get_internal_single_to_uninitialized(buffer);
+    varray_single_.emplace(type, slice.size(), buffer);
+    type.destruct(buffer);
+    varray_ = &*varray_single_;
+  }
+  else {
+    varray_any_.emplace(varray, slice);
+    varray_ = &*varray_any_;
+  }
+}
+
 }  // namespace blender::fn



More information about the Bf-blender-cvs mailing list