[Bf-blender-cvs] [97b6d31f415] functions: use new network evaluation storage

Jacques Lucke noreply at git.blender.org
Mon Jan 27 22:09:58 CET 2020


Commit: 97b6d31f41523d7836e17636918cc9f2872f223a
Author: Jacques Lucke
Date:   Sun Jan 26 13:16:43 2020 +0100
Branches: functions
https://developer.blender.org/rB97b6d31f41523d7836e17636918cc9f2872f223a

use new network evaluation storage

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

M	source/blender/functions/FN_generic_vector_array.h
M	source/blender/functions/intern/multi_functions/network.cc
M	source/blender/functions/intern/multi_functions/network.h

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

diff --git a/source/blender/functions/FN_generic_vector_array.h b/source/blender/functions/FN_generic_vector_array.h
index 77e12c612de..cd8d5de6dea 100644
--- a/source/blender/functions/FN_generic_vector_array.h
+++ b/source/blender/functions/FN_generic_vector_array.h
@@ -121,6 +121,13 @@ class GenericVectorArray : BLI::NonCopyable, BLI::NonMovable {
     m_lengths[index] = new_length;
   }
 
+  void extend_multiple__copy(IndexMask indices, const GenericVirtualListListRef &values)
+  {
+    for (uint i : indices) {
+      this->extend_single__copy(i, values[i]);
+    }
+  }
+
   GenericMutableArrayRef allocate_single(uint index, uint size)
   {
     if (m_lengths[index] + size > m_capacities[index]) {
diff --git a/source/blender/functions/intern/multi_functions/network.cc b/source/blender/functions/intern/multi_functions/network.cc
index 9544e7252b8..3d27a6eb5b5 100644
--- a/source/blender/functions/intern/multi_functions/network.cc
+++ b/source/blender/functions/intern/multi_functions/network.cc
@@ -72,6 +72,11 @@ class NetworkEvaluationStorage {
     }
   }
 
+  IndexMask mask() const
+  {
+    return m_mask;
+  }
+
   void add_single_from_caller(const MFOutputSocket &socket, GenericVirtualListRef list_ref)
   {
     BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
@@ -127,9 +132,12 @@ class NetworkEvaluationStorage {
     return *value->vector_array;
   }
 
-  GenericMutableArrayRef forward_mutable_single(const MFOutputSocket &from,
-                                                const MFOutputSocket &to)
+  GenericMutableArrayRef get_mutable_single(const MFInputSocket &input,
+                                            const MFOutputSocket &output)
   {
+    const MFOutputSocket &from = input.origin();
+    const MFOutputSocket &to = output;
+
     OutputValue *any_value = m_value_per_output_id[from.id()];
     BLI_assert(any_value != nullptr);
     BLI_assert(from.data_type().single__cpp_type() == to.data_type().single__cpp_type());
@@ -173,8 +181,11 @@ class NetworkEvaluationStorage {
     return GenericMutableArrayRef(CPP_TYPE<float>());
   }
 
-  GenericVectorArray &forward_mutable_vector(const MFOutputSocket &from, const MFOutputSocket &to)
+  GenericVectorArray &get_mutable_vector(const MFInputSocket &input, const MFOutputSocket &output)
   {
+    const MFOutputSocket &from = input.origin();
+    const MFOutputSocket &to = output;
+
     OutputValue *any_value = m_value_per_output_id[from.id()];
     BLI_assert(any_value != nullptr);
     BLI_assert(from.data_type().vector__cpp_base_type() == to.data_type().vector__cpp_base_type());
@@ -195,10 +206,7 @@ class NetworkEvaluationStorage {
 
         const CPPType &base_type = to.data_type().vector__cpp_base_type();
         new_value->vector_array = new GenericVectorArray(base_type, m_mask.min_array_size());
-
-        for (uint i : m_mask) {
-          new_value->vector_array->extend_single__copy(i, (*value->vector_array)[i]);
-        }
+        new_value->vector_array->extend_multiple__copy(m_mask, *value->vector_array);
 
         return *new_value->vector_array;
       }
@@ -298,200 +306,12 @@ class NetworkEvaluationStorage {
     BLI_assert(false);
     return GenericVirtualListListRef::FromSingleArray(CPP_TYPE<float>(), nullptr, 0, 0);
   }
-};
-
-class MF_EvaluateNetwork_Storage {
- private:
-  MonotonicAllocator<256> m_single_allocator;
-  IndexMask m_mask;
-  ArrayAllocator &m_array_allocator;
-  Vector<GenericVectorArray *> m_vector_arrays;
-  Vector<GenericMutableArrayRef> m_arrays;
-  Vector<GenericMutableArrayRef> m_single_element_arrays;
-  Map<uint, GenericVectorArray *> m_vector_array_for_inputs;
-  Map<uint, GenericVirtualListRef> m_virtual_list_for_inputs;
-  Map<uint, GenericVirtualListListRef> m_virtual_list_list_for_inputs;
-  Map<uint, GenericMutableArrayRef> m_array_ref_for_inputs;
-
- public:
-  MF_EvaluateNetwork_Storage(IndexMask mask, ArrayAllocator &array_allocator)
-      : m_mask(mask), m_array_allocator(array_allocator)
-  {
-    BLI_assert(array_allocator.array_size() >= mask.min_array_size());
-  }
-
-  ~MF_EvaluateNetwork_Storage()
-  {
-    for (GenericVectorArray *vector_array : m_vector_arrays) {
-      delete vector_array;
-    }
-    for (GenericMutableArrayRef array : m_arrays) {
-      array.destruct_indices(m_mask);
-      m_array_allocator.deallocate(array.type().size(), array.buffer());
-    }
-    for (GenericMutableArrayRef array : m_single_element_arrays) {
-      array.destruct_indices(IndexMask(1));
-    }
-  }
-
-  IndexMask &mask()
-  {
-    return m_mask;
-  }
-
-  GenericMutableArrayRef allocate_array(const CPPType &type)
-  {
-    uint size = m_mask.min_array_size();
-    void *buffer = m_array_allocator.allocate(type.size(), type.alignment());
-    GenericMutableArrayRef array(type, buffer, size);
-    m_arrays.append(array);
-    return array;
-  }
-
-  GenericMutableArrayRef allocate_array__single_element(const CPPType &type)
-  {
-    void *buffer = m_single_allocator.allocate(type.size(), type.alignment());
-    GenericMutableArrayRef array(type, buffer, 1);
-    m_single_element_arrays.append(array);
-    return array;
-  }
-
-  GenericVectorArray &allocate_vector_array(const CPPType &type)
-  {
-    uint size = m_mask.min_array_size();
-    GenericVectorArray *vector_array = new GenericVectorArray(type, size);
-    m_vector_arrays.append(vector_array);
-    return *vector_array;
-  }
-
-  GenericVectorArray &allocate_vector_array__single_element(const CPPType &type)
-  {
-    GenericVectorArray *vector_array = new GenericVectorArray(type, 1);
-    m_vector_arrays.append(vector_array);
-    return *vector_array;
-  }
-
-  GenericMutableArrayRef allocate_copy(GenericVirtualListRef array)
-  {
-    GenericMutableArrayRef new_array = this->allocate_array(array.type());
-    array.materialize_to_uninitialized(m_mask, new_array);
-    return new_array;
-  }
-
-  GenericVectorArray &allocate_copy(GenericVirtualListListRef vector_array)
-  {
-    GenericVectorArray &new_vector_array = this->allocate_vector_array(vector_array.type());
-    for (uint i : m_mask.indices()) {
-      new_vector_array.extend_single__copy(i, vector_array[i]);
-    }
-    return new_vector_array;
-  }
-
-  GenericMutableArrayRef allocate_single_copy(GenericMutableArrayRef array)
-  {
-    GenericMutableArrayRef new_array = this->allocate_array__single_element(array.type());
-    new_array.copy_in__uninitialized(0, array[0]);
-    return new_array;
-  }
-
-  GenericVectorArray &allocate_single_copy(GenericVectorArray &vector_array)
-  {
-    GenericVectorArray &new_vector_array = this->allocate_vector_array__single_element(
-        vector_array.type());
-    new_vector_array.extend_single__copy(0, vector_array[0]);
-    return new_vector_array;
-  }
-
-  GenericMutableArrayRef allocate_full_copy_from_single(GenericMutableArrayRef array)
-  {
-    BLI_assert(array.size() == 1);
-    GenericMutableArrayRef new_array = this->allocate_array(array.type());
-    array.type().fill_uninitialized_indices(array[0], new_array.buffer(), m_mask);
-    return new_array;
-  }
-
-  GenericVectorArray &allocate_full_copy_from_single(GenericVectorArray &vector_array)
-  {
-    BLI_assert(vector_array.size() == 1);
-    GenericVectorArray &new_vector_array = this->allocate_vector_array(vector_array.type());
-    for (uint i : m_mask.indices()) {
-      new_vector_array.extend_single__copy(i, vector_array[0]);
-    }
-    return new_vector_array;
-  }
-
-  void set_array_ref(const MFInputSocket &socket, GenericMutableArrayRef array)
-  {
-    m_array_ref_for_inputs.add_new(socket.id(), array);
-  }
-
-  void set_virtual_list(const MFInputSocket &socket, GenericVirtualListRef list)
-  {
-    m_virtual_list_for_inputs.add_new(socket.id(), list);
-  }
-
-  void set_virtual_list_list(const MFInputSocket &socket, GenericVirtualListListRef list)
-  {
-    m_virtual_list_list_for_inputs.add_new(socket.id(), list);
-  }
-
-  void set_vector_array(const MFInputSocket &socket, GenericVectorArray &vector_array)
-  {
-    m_vector_array_for_inputs.add_new(socket.id(), &vector_array);
-  }
-
-  GenericVirtualListRef get_virtual_list(const MFInputSocket &socket) const
-  {
-    return m_virtual_list_for_inputs.lookup(socket.id());
-  }
 
-  GenericVirtualListListRef get_virtual_list_list(const MFInputSocket &socket) const
+  bool input_is_computed(const MFInputSocket &socket)
   {
-    return m_virtual_list_list_for_inputs.lookup(socket.id());
-  }
-
-  GenericVectorArray &get_vector_array(const MFInputSocket &socket) const
-  {
-    return *m_vector_array_for_inputs.lookup(socket.id());
-  }
-
-  GenericMutableArrayRef get_array_ref(const MFInputSocket &socket) const
-  {
-    return m_array_ref_for_inputs.lookup(socket.id());
-  }
-
-  bool input_is_computed(const MFInputSocket &socket) const
-  {
-    switch (socket.data_type().category()) {
-      case MFDataType::Single:
-        return m_virtual_list_for_inputs.contains(socket.id());
-      case MFDataType::Vector:
-        return m_virtual_list_list_for_inputs.contains(socket.id()) ||
-               m_vector_array_for_inputs.contains(socket.id());
-    }
-    BLI_assert(false);
-    return false;
-  }
-
-  bool function_input_has_single_element(const MFInputSocket &socket) const
-  {
-    BLI_assert(socket.node().is_function());
-    MFParamType param_type = socket.param_type();
-    switch (param_type.type()) {
-      case MFParamType::SingleInput:
-        return m_virtual_list_for_inputs.lookup(socket.id()).is_single_element();
-      case MFParamType::VectorInput:
-        return m_virtual_list_list_for_inputs.lookup(socket.id()).is_single_list();
-      case MFParamType::MutableSingle:
-        return m_array_ref_for_inputs.lookup(socket.id()).size() == 1;
-      case MFParamType::MutableVector:
-        return m_vector_array_for_inputs.lookup(socket.id())->size() == 1;
-      case MFParamType::SingleOutput:
-      case MFParamType::VectorOutput:
-        break;
-    }
-    BLI_assert(false);
-    return false;
+    const MFOutputSocket &origin = socket.origin();
+    OutputValue *any_value = m_value_per_output_id[origin.id()];
+    return any_value != nullptr;
   }
 };
 
@@ -546,8 +366,9 @@ void MF_EvaluateNetwork::c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list