[Bf-blender-cvs] [645293e2d90] functions: remove redundant values

Jacques Lucke noreply at git.blender.org
Fri Aug 2 19:14:43 CEST 2019


Commit: 645293e2d900e3e1231b575a85110f5264eec3a8
Author: Jacques Lucke
Date:   Fri Aug 2 10:08:51 2019 +0200
Branches: functions
https://developer.blender.org/rB645293e2d900e3e1231b575a85110f5264eec3a8

remove redundant values

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

M	source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp
M	source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
M	source/blender/simulations/bparticles/particle_function_builder.cpp

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

diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp
index 07d902367b5..69616abcf31 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp
@@ -7,7 +7,7 @@ namespace DataFlowNodes {
 
 using BLI::Stack;
 
-VTreeDataGraph::PlaceholderDependencies VTreeDataGraph::find_placeholder_dependencies(
+Vector<VirtualSocket *> VTreeDataGraph::find_placeholder_dependencies(
     ArrayRef<VirtualSocket *> vsockets)
 {
   Vector<DataSocket> sockets;
@@ -18,12 +18,11 @@ VTreeDataGraph::PlaceholderDependencies VTreeDataGraph::find_placeholder_depende
   return this->find_placeholder_dependencies(sockets);
 }
 
-VTreeDataGraph::PlaceholderDependencies VTreeDataGraph::find_placeholder_dependencies(
-    ArrayRef<DataSocket> sockets)
+Vector<VirtualSocket *> VTreeDataGraph::find_placeholder_dependencies(ArrayRef<DataSocket> sockets)
 {
   Stack<DataSocket> to_be_checked = sockets;
   Set<DataSocket> found = sockets;
-  PlaceholderDependencies dependencies;
+  Vector<VirtualSocket *> vsocket_dependencies;
 
   while (!to_be_checked.empty()) {
     DataSocket socket = to_be_checked.pop();
@@ -41,8 +40,7 @@ VTreeDataGraph::PlaceholderDependencies VTreeDataGraph::find_placeholder_depende
         VirtualNode *vnode = body.vnode();
         uint data_output_index = m_graph->index_of_output(socket);
         VirtualSocket *vsocket = this->find_data_output(vnode, data_output_index);
-        dependencies.sockets.append(socket);
-        dependencies.vsockets.append(vsocket);
+        vsocket_dependencies.append(vsocket);
       }
       else {
         for (DataSocket input : m_graph->inputs_of_node(node_id)) {
@@ -54,7 +52,7 @@ VTreeDataGraph::PlaceholderDependencies VTreeDataGraph::find_placeholder_depende
     }
   }
 
-  return dependencies;
+  return vsocket_dependencies;
 }
 
 VirtualSocket *VTreeDataGraph::find_data_output(VirtualNode *vnode, uint index)
diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
index d3f49713697..a5f3ea584ce 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.hpp
@@ -37,6 +37,16 @@ class VTreeDataGraph {
     return socket;
   }
 
+  Vector<DataSocket> lookup_sockets(ArrayRef<VirtualSocket *> vsockets)
+  {
+    Vector<DataSocket> sockets;
+    sockets.reserve(vsockets.size());
+    for (VirtualSocket *vsocket : vsockets) {
+      sockets.append(this->lookup_socket(vsocket));
+    }
+    return sockets;
+  }
+
   DataSocket lookup_socket(VirtualSocket *vsocket)
   {
     return m_socket_map[vsocket->id()];
@@ -47,19 +57,8 @@ class VTreeDataGraph {
     return !m_socket_map[vsocket->id()].is_none();
   }
 
-  struct PlaceholderDependencies {
-    Vector<VirtualSocket *> vsockets;
-    Vector<DataSocket> sockets;
-
-    uint size() const
-    {
-      BLI_assert(this->vsockets.size() == this->sockets.size());
-      return this->vsockets.size();
-    }
-  };
-
-  PlaceholderDependencies find_placeholder_dependencies(ArrayRef<VirtualSocket *> vsockets);
-  PlaceholderDependencies find_placeholder_dependencies(ArrayRef<DataSocket> sockets);
+  Vector<VirtualSocket *> find_placeholder_dependencies(ArrayRef<VirtualSocket *> vsockets);
+  Vector<VirtualSocket *> find_placeholder_dependencies(ArrayRef<DataSocket> sockets);
 
  private:
   VirtualSocket *find_data_output(VirtualNode *vnode, uint index);
diff --git a/source/blender/simulations/bparticles/particle_function_builder.cpp b/source/blender/simulations/bparticles/particle_function_builder.cpp
index 24b4d0fb473..53bb2df965a 100644
--- a/source/blender/simulations/bparticles/particle_function_builder.cpp
+++ b/source/blender/simulations/bparticles/particle_function_builder.cpp
@@ -26,16 +26,12 @@ Vector<DataSocket> find_input_data_sockets(VirtualNode *vnode, VTreeDataGraph &d
   return inputs;
 }
 
-struct SocketDependencies {
-  SetVector<DataSocket> sockets;
-  SetVector<VirtualSocket *> vsockets;
-};
-
-static SocketDependencies find_particle_dependencies(VTreeDataGraph &data_graph,
-                                                     ArrayRef<DataSocket> sockets,
-                                                     ArrayRef<bool> r_depends_on_particle_flags)
+static SetVector<VirtualSocket *> find_particle_dependencies(
+    VTreeDataGraph &data_graph,
+    ArrayRef<DataSocket> sockets,
+    ArrayRef<bool> r_depends_on_particle_flags)
 {
-  SocketDependencies combined_dependencies;
+  SetVector<VirtualSocket *> combined_dependencies;
 
   for (uint i = 0; i < sockets.size(); i++) {
     DataSocket socket = sockets[i];
@@ -43,9 +39,7 @@ static SocketDependencies find_particle_dependencies(VTreeDataGraph &data_graph,
     bool has_dependency = dependencies.size() > 0;
     r_depends_on_particle_flags[i] = has_dependency;
 
-    combined_dependencies.sockets.add_multiple(dependencies.sockets);
-    combined_dependencies.vsockets.add_multiple(dependencies.vsockets);
-    BLI_assert(combined_dependencies.sockets.size() == combined_dependencies.vsockets.size());
+    combined_dependencies.add_multiple(dependencies);
   }
 
   return combined_dependencies;
@@ -129,26 +123,27 @@ static ParticleFunctionInputProvider *create_input_provider(VirtualSocket *vsock
 }
 
 static SharedFunction create_function__with_deps(
-    SharedDataGraph &graph,
+    VTreeDataGraph &data_graph,
     StringRef function_name,
     ArrayRef<DataSocket> sockets_to_compute,
-    SocketDependencies &dependencies,
+    ArrayRef<VirtualSocket *> input_vsockets,
     ArrayRef<ParticleFunctionInputProvider *> r_input_providers)
 {
-  uint input_amount = dependencies.sockets.size();
+  uint input_amount = input_vsockets.size();
   BLI_assert(input_amount == r_input_providers.size());
 
+  Vector<DataSocket> input_sockets = data_graph.lookup_sockets(input_vsockets);
+
   FunctionBuilder fn_builder;
-  fn_builder.add_inputs(graph, dependencies.sockets);
-  fn_builder.add_outputs(graph, sockets_to_compute);
+  fn_builder.add_inputs(data_graph.graph(), input_sockets);
+  fn_builder.add_outputs(data_graph.graph(), sockets_to_compute);
 
   for (uint i = 0; i < input_amount; i++) {
-    VirtualSocket *vsocket = dependencies.vsockets[i];
-    r_input_providers[i] = create_input_provider(vsocket);
+    r_input_providers[i] = create_input_provider(input_vsockets[i]);
   }
 
   SharedFunction fn = fn_builder.build(function_name);
-  FunctionGraph fgraph(graph, dependencies.sockets, sockets_to_compute);
+  FunctionGraph fgraph(data_graph.graph(), input_sockets, sockets_to_compute);
   FN::fgraph_add_TupleCallBody(fn, fgraph);
   FN::fgraph_add_LLVMBuildIRBody(fn, fgraph);
   return fn;
@@ -167,11 +162,11 @@ static SharedFunction create_function__without_deps(SharedDataGraph &graph,
 }
 
 static ValueOrError<std::unique_ptr<ParticleFunction>> create_particle_function_from_sockets(
-    SharedDataGraph &graph,
+    VTreeDataGraph &data_graph,
     StringRef name,
     ArrayRef<DataSocket> sockets_to_compute,
     ArrayRef<bool> depends_on_particle_flags,
-    SocketDependencies &dependencies)
+    ArrayRef<VirtualSocket *> dependencies)
 {
   Vector<DataSocket> sockets_with_deps;
   Vector<DataSocket> sockets_without_deps;
@@ -184,12 +179,12 @@ static ValueOrError<std::unique_ptr<ParticleFunction>> create_particle_function_
     }
   }
 
-  Vector<ParticleFunctionInputProvider *> input_providers(dependencies.sockets.size(), nullptr);
+  Vector<ParticleFunctionInputProvider *> input_providers(dependencies.size(), nullptr);
 
   SharedFunction fn_without_deps = create_function__without_deps(
-      graph, name, sockets_without_deps);
+      data_graph.graph(), name, sockets_without_deps);
   SharedFunction fn_with_deps = create_function__with_deps(
-      graph, name, sockets_with_deps, dependencies, input_providers);
+      data_graph, name, sockets_with_deps, dependencies, input_providers);
 
   ParticleFunction *particle_fn = new ParticleFunction(
       fn_without_deps, fn_with_deps, input_providers, depends_on_particle_flags);
@@ -206,7 +201,7 @@ ValueOrError<std::unique_ptr<ParticleFunction>> create_particle_function(
 
   std::string name = vnode->name() + StringRef(" Inputs");
   return create_particle_function_from_sockets(
-      data_graph.graph(), name, sockets_to_compute, depends_on_particle_flags, dependencies);
+      data_graph, name, sockets_to_compute, depends_on_particle_flags, dependencies);
 }
 
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list