[Bf-blender-cvs] [5a1a8fa917c] functions: handle inputs with no dependencies separately
Jacques Lucke
noreply at git.blender.org
Mon Jul 29 17:57:13 CEST 2019
Commit: 5a1a8fa917c28f41c2445e2d8a8add94560e2e64
Author: Jacques Lucke
Date: Mon Jul 29 11:55:25 2019 +0200
Branches: functions
https://developer.blender.org/rB5a1a8fa917c28f41c2445e2d8a8add94560e2e64
handle inputs with no dependencies separately
===================================================================
M source/blender/blenlib/BLI_set_vector.hpp
M source/blender/simulations/bparticles/inserters.cpp
M source/blender/simulations/bparticles/particle_function.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_set_vector.hpp b/source/blender/blenlib/BLI_set_vector.hpp
index 80132bb74f0..e3da9070148 100644
--- a/source/blender/blenlib/BLI_set_vector.hpp
+++ b/source/blender/blenlib/BLI_set_vector.hpp
@@ -42,6 +42,10 @@ template<typename T> class SetVector : public Set<T> {
{
}
+ SetVector(ArrayRef<T> values) : Set<T>(values)
+ {
+ }
+
/**
* Return the index of the value, or -1 when it does not exist.
*/
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 00d4f2198ee..b166670a22c 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -22,6 +22,7 @@ using BLI::ValueOrError;
using FN::DFGraphSocket;
using FN::FunctionBuilder;
using FN::FunctionGraph;
+using FN::SharedDataFlowGraph;
using FN::SharedFunction;
using FN::SharedType;
@@ -38,6 +39,31 @@ static Vector<DFGraphSocket> find_input_data_sockets(VirtualNode *vnode,
return inputs;
}
+struct SocketDependencies {
+ SetVector<DFGraphSocket> sockets;
+ SetVector<VirtualSocket *> vsockets;
+};
+
+static SocketDependencies find_particle_dependencies(VTreeDataGraph &data_graph,
+ ArrayRef<DFGraphSocket> sockets,
+ ArrayRef<bool> r_depends_on_particle)
+{
+ SocketDependencies combined_dependencies;
+
+ for (uint i = 0; i < sockets.size(); i++) {
+ DFGraphSocket socket = sockets[i];
+ auto dependencies = data_graph.find_placeholder_dependencies(socket);
+ bool has_dependency = dependencies.size() > 0;
+ r_depends_on_particle[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());
+ }
+
+ return combined_dependencies;
+}
+
static ValueOrError<SharedFunction> create_function__emitter_inputs(VirtualNode *emitter_vnode,
VTreeDataGraph &data_graph)
{
@@ -54,21 +80,20 @@ static ValueOrError<SharedFunction> create_function__emitter_inputs(VirtualNode
return fn;
}
-ValueOrError<ParticleFunction> create_particle_function(VirtualNode *main_vnode,
- VTreeDataGraph &data_graph)
+static SharedFunction create_function__with_deps(SharedDataFlowGraph &graph,
+ StringRef function_name,
+ ArrayRef<DFGraphSocket> sockets_to_compute,
+ SocketDependencies &dependencies)
{
- Vector<DFGraphSocket> sockets_to_compute = find_input_data_sockets(main_vnode, data_graph);
- auto dependencies = data_graph.find_placeholder_dependencies(sockets_to_compute);
-
FunctionBuilder fn_builder;
- fn_builder.add_outputs(data_graph.graph(), sockets_to_compute);
+ fn_builder.add_outputs(graph, sockets_to_compute);
- for (uint i = 0; i < dependencies.size(); i++) {
+ for (uint i = 0; i < dependencies.sockets.size(); i++) {
VirtualSocket *vsocket = dependencies.vsockets[i];
DFGraphSocket socket = dependencies.sockets[i];
VirtualNode *vnode = vsocket->vnode();
- SharedType &type = data_graph.graph()->type_of_output(socket);
+ SharedType &type = graph->type_of_output(socket);
StringRef name_prefix;
if (STREQ(vnode->idname(), "bp_ParticleInfoNode")) {
name_prefix = "Attribute: ";
@@ -83,16 +108,50 @@ ValueOrError<ParticleFunction> create_particle_function(VirtualNode *main_vnode,
fn_builder.add_input(name, type);
}
- SharedFunction fn = fn_builder.build(main_vnode->name());
- FunctionGraph fgraph(data_graph.graph(), dependencies.sockets, sockets_to_compute);
+ SharedFunction fn = fn_builder.build(function_name);
+ FunctionGraph fgraph(graph, dependencies.sockets, sockets_to_compute);
+ FN::fgraph_add_TupleCallBody(fn, fgraph);
+
+ return fn;
+}
+
+static SharedFunction create_function__without_deps(SharedDataFlowGraph &graph,
+ StringRef function_name,
+ ArrayRef<DFGraphSocket> sockets_to_compute)
+{
+ FunctionBuilder fn_builder;
+ fn_builder.add_outputs(graph, sockets_to_compute);
+ SharedFunction fn = fn_builder.build(function_name);
+ FunctionGraph fgraph(graph, {}, sockets_to_compute);
FN::fgraph_add_TupleCallBody(fn, fgraph);
+ return fn;
+}
- FunctionBuilder empty_fn_builder;
- SharedFunction empty_fn = empty_fn_builder.build("Empty");
+ValueOrError<ParticleFunction> create_particle_function(VirtualNode *main_vnode,
+ VTreeDataGraph &data_graph)
+{
+ Vector<DFGraphSocket> sockets_to_compute = find_input_data_sockets(main_vnode, data_graph);
+ Vector<bool> parameter_depends_on_particle(sockets_to_compute.size());
+ auto dependencies = find_particle_dependencies(
+ data_graph, sockets_to_compute, parameter_depends_on_particle);
+
+ Vector<DFGraphSocket> sockets_with_deps;
+ Vector<DFGraphSocket> sockets_without_deps;
+ for (uint i = 0; i < sockets_to_compute.size(); i++) {
+ if (parameter_depends_on_particle[i]) {
+ sockets_with_deps.append(sockets_to_compute[i]);
+ }
+ else {
+ sockets_without_deps.append(sockets_to_compute[i]);
+ }
+ }
- Vector<bool> depends_on_particle(fn->output_amount(), true);
+ SharedFunction fn_without_deps = create_function__without_deps(
+ data_graph.graph(), main_vnode->name(), sockets_without_deps);
+ SharedFunction fn_with_deps = create_function__with_deps(
+ data_graph.graph(), main_vnode->name(), sockets_with_deps, dependencies);
- ParticleFunction particle_function(empty_fn, fn, depends_on_particle);
+ ParticleFunction particle_function(fn_without_deps, fn_with_deps, parameter_depends_on_particle);
return particle_function;
}
diff --git a/source/blender/simulations/bparticles/particle_function.hpp b/source/blender/simulations/bparticles/particle_function.hpp
index 464976edff9..9b51602e13b 100644
--- a/source/blender/simulations/bparticles/particle_function.hpp
+++ b/source/blender/simulations/bparticles/particle_function.hpp
@@ -85,6 +85,7 @@ class ParticleFunction {
{
BLI_assert(m_fn_no_deps->output_amount() + m_fn_with_deps->output_amount() ==
m_parameter_depends_on_particle.size());
+ BLI_assert(m_fn_no_deps->input_amount() == 0);
uint no_deps_index = 0;
uint with_deps_index = 0;
More information about the Bf-blender-cvs
mailing list