Commit: 3fcf50d37af95b1c64d122ce31cb54cb627bbe8e
Author: Hans Goudey
Date:   Sat Dec 10 00:01:20 2022 -0600
Branches: geometry-nodes-simulation
https://developer.blender.org/rB3fcf50d37af95b1c64d122ce31cb54cb627bbe8e

Make the simulation always run, remove run socket

Note: Still unstable. Simulation resets when playback stops bug.

Since the "Run" behavior can basically be implemented with the switch
node already, it's just adding unnecessary complexity to the interface
now, when it's use case isn't clear. We decided to remove it for now,
and only consider it later as a possible convenience feature, rather
than an essential part of the design.

Also, the simulation nodes are now considered "side effect nodes"
for the evaluator, meaning they are *always* evaluated, even if they
aren't needed because of switch nodes, etc. This was the best way
we thought of to make simulations run consistently even through
situations like that.

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

M       source/blender/modifiers/intern/MOD_nodes.cc
M       source/blender/nodes/NOD_geometry_exec.hh
M       source/blender/nodes/NOD_geometry_nodes_lazy_function.hh
M       source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
M       source/blender/nodes/intern/geometry_nodes_lazy_function.cc

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

diff --git a/source/blender/modifiers/intern/MOD_nodes.cc 
b/source/blender/modifiers/intern/MOD_nodes.cc
index 95b926ee172..cc16a2fe758 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -839,6 +839,12 @@ static const lf::FunctionNode &find_group_lf_node(const 
bNode &group_bnode)
               ->mapping.group_node_map.lookup(&group_bnode);
 }
 
+static const lf::FunctionNode &find_sim_output_lf_node(const bNode &node)
+{
+  return 
*blender::nodes::ensure_geometry_nodes_lazy_function_graph(node.owner_tree())
+              ->mapping.sim_output_node_map.lookup(&node);
+}
+
 static void find_side_effect_nodes_for_viewer_path(
     const ViewerPath &viewer_path,
     const NodesModifierData &nmd,
@@ -895,6 +901,28 @@ static void find_side_effect_nodes_for_viewer_path(
   }
 }
 
+static void add_simulation_output_side_effect_nodes(
+    blender::ComputeContextBuilder &compute_context_builder,
+    const bNodeTree &group,
+    MultiValueMap<blender::ComputeContextHash, const lf::FunctionNode *> 
&r_side_effect_nodes)
+{
+  group.ensure_topology_cache();
+
+  const blender::ComputeContextHash hash = compute_context_builder.hash();
+  for (const bNode *sim_output_node : 
group.nodes_by_type("GeometryNodeSimulationOutput")) {
+    r_side_effect_nodes.add(hash, &find_sim_output_lf_node(*sim_output_node));
+  }
+
+  for (const bNode *group_node : group.group_nodes()) {
+    if (group_node->id) {
+      
compute_context_builder.push<blender::bke::NodeGroupComputeContext>(*group_node);
+      add_simulation_output_side_effect_nodes(compute_context_builder,
+                                              *reinterpret_cast<const 
bNodeTree *>(group_node->id),
+                                              r_side_effect_nodes);
+    }
+  }
+}
+
 static void find_side_effect_nodes(
     const NodesModifierData &nmd,
     const ModifierEvalContext &ctx,
@@ -922,6 +950,15 @@ static void find_side_effect_nodes(
       }
     }
   }
+
+  {
+    /* Simulation output nodes are treated as side effect nodes because they 
always execute,
+     * even when their output is not needed, and because they potentially 
store caches. */
+    blender::ComputeContextBuilder compute_context_builder;
+    
compute_context_builder.push<blender::bke::ModifierComputeContext>(nmd.modifier.name);
+    add_simulation_output_side_effect_nodes(
+        compute_context_builder, *nmd.node_group, r_side_effect_nodes);
+  }
 }
 
 static void clear_runtime_data(NodesModifierData *nmd)
diff --git a/source/blender/nodes/NOD_geometry_exec.hh 
b/source/blender/nodes/NOD_geometry_exec.hh
index 73e82f741ab..2c1dd6d9b16 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -197,6 +197,10 @@ class GeoNodeExecParams {
   bool lazy_output_is_required(StringRef identifier)
   {
     const int index = this->get_output_index(identifier);
+    /* TODO: Why was this necessary to make the Delta Time socket not crash? */
+    // if (params_.output_was_set(index)) {
+    //   return false;
+    // }
     return params_.get_output_usage(index) == lf::ValueUsage::Used;
   }
 
diff --git a/source/blender/nodes/NOD_geometry_nodes_lazy_function.hh 
b/source/blender/nodes/NOD_geometry_nodes_lazy_function.hh
index ee706a7e9df..e3d92dae06d 100644
--- a/source/blender/nodes/NOD_geometry_nodes_lazy_function.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_lazy_function.hh
@@ -95,6 +95,7 @@ struct GeometryNodeLazyFunctionGraphMapping {
    */
   Map<const bNode *, const lf::FunctionNode *> group_node_map;
   Map<const bNode *, const lf::FunctionNode *> viewer_node_map;
+  Map<const bNode *, const lf::FunctionNode *> sim_output_node_map;
 };
 
 /**
diff --git a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc 
b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
index 295fb92d3f6..438a6c5f6ca 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
@@ -17,7 +17,6 @@ NODE_STORAGE_FUNCS(NodeGeometrySimulationOutput);
 
 static void node_declare(NodeDeclarationBuilder &b)
 {
-  b.add_input<decl::Bool>(N_("Run")).default_value(true);
   b.add_input<decl::Geometry>(N_("Geometry"));
   b.add_output<decl::Geometry>(N_("Geometry"));
 }
@@ -31,10 +30,6 @@ static void node_init(bNodeTree * /*tree*/, bNode *node)
 
 static void node_geo_exec(GeoNodeExecParams params)
 {
-  if (params.lazy_require_input("Run")) {
-    return;
-  }
-
   const bNode &node = params.node();
   const NodeGeometrySimulationOutput &storage = node_storage(node);
   const Scene *scene = DEG_get_input_scene(params.depsgraph());
@@ -47,17 +42,6 @@ static void node_geo_exec(GeoNodeExecParams params)
   const bke::NodeGroupComputeContext cache_context(lf_data.compute_context, 
node.identifier);
   bke::sim::SimulationCache &cache = 
all_caches.ensure_for_context(cache_context.hash());
 
-  const float elapsed_time = cache.is_empty() ? 0.0f : scene_ctime - 
cache.start_time()->time;
-  const bool run = params.get_input<bool>("Run");
-
-  if (!run) {
-    if (std::optional<GeometrySet> value = 
cache.value_at_or_before_time("Geometry", time)) {
-      params.set_output("Geometry", std::move(*value));
-      params.set_input_unused("Geometry");
-      return;
-    }
-  }
-
   if (std::optional<GeometrySet> value = cache.value_at_time("Geometry", 
time)) {
     params.set_output("Geometry", std::move(*value));
     params.set_input_unused("Geometry");
diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc 
b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
index d7d633353bd..696789c56b1 100644
--- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -837,6 +837,11 @@ struct GeometryNodesLazyFunctionGraphBuilder {
           this->handle_group_node(*bnode);
           break;
         }
+        case GEO_NODE_SIMULATION_OUTPUT: {
+          const lf::FunctionNode &lf_node = this->handle_geometry_node(*bnode);
+          mapping_->sim_output_node_map.add(bnode, &lf_node);
+          break;
+        }
         case GEO_NODE_VIEWER: {
           this->handle_viewer_node(*bnode);
           break;
@@ -973,13 +978,13 @@ struct GeometryNodesLazyFunctionGraphBuilder {
         group_lf_graph_info->num_inline_nodes_approximate;
   }
 
-  void handle_geometry_node(const bNode &bnode)
+  lf::FunctionNode &handle_geometry_node(const bNode &bnode)
   {
     Vector<const bNodeSocket *> used_inputs;
     Vector<const bNodeSocket *> used_outputs;
     auto lazy_function = std::make_unique<LazyFunctionForGeometryNode>(
         bnode, used_inputs, used_outputs);
-    lf::Node &lf_node = lf_graph_->add_function(*lazy_function);
+    lf::FunctionNode &lf_node = lf_graph_->add_function(*lazy_function);
     lf_graph_info_->functions.append(std::move(lazy_function));
 
     for (const int i : used_inputs.index_range()) {
@@ -1007,6 +1012,8 @@ struct GeometryNodesLazyFunctionGraphBuilder {
       output_socket_map_.add_new(&bsocket, &lf_socket);
       mapping_->bsockets_by_lf_socket_map.add(&lf_socket, &bsocket);
     }
+
+    return lf_node;
   }
 
   void handle_multi_function_node(const bNode &bnode, const 
NodeMultiFunctions::Item &fn_item)

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to