[Bf-blender-cvs] [db13aa8e43b] temp-geometry-nodes-evaluator-refactor: refactor lazy function graph generation

Jacques Lucke noreply at git.blender.org
Thu Sep 1 19:58:58 CEST 2022


Commit: db13aa8e43b38f9088badaaadc668651faf7494b
Author: Jacques Lucke
Date:   Thu Sep 1 18:56:19 2022 +0200
Branches: temp-geometry-nodes-evaluator-refactor
https://developer.blender.org/rBdb13aa8e43b38f9088badaaadc668651faf7494b

refactor lazy function graph generation

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

M	source/blender/blenkernel/BKE_node_runtime.hh
M	source/blender/blenkernel/intern/node.cc
M	source/blender/functions/FN_lazy_function.hh
M	source/blender/functions/intern/lazy_function_graph_executor.cc
M	source/blender/modifiers/intern/MOD_nodes.cc
M	source/blender/nodes/NOD_geometry_nodes_to_lazy_function_graph.hh
M	source/blender/nodes/intern/geometry_nodes_to_lazy_function_graph.cc

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

diff --git a/source/blender/blenkernel/BKE_node_runtime.hh b/source/blender/blenkernel/BKE_node_runtime.hh
index 4c13f73848c..3372f691bba 100644
--- a/source/blender/blenkernel/BKE_node_runtime.hh
+++ b/source/blender/blenkernel/BKE_node_runtime.hh
@@ -21,6 +21,7 @@ struct bNodeType;
 namespace blender::nodes {
 struct FieldInferencingInterface;
 class NodeDeclaration;
+struct GeometryNodesLazyFunctionGraphInfo;
 }  // namespace blender::nodes
 
 namespace blender::bke {
@@ -48,6 +49,10 @@ class bNodeTreeRuntime : NonCopyable, NonMovable {
   /** Information about how inputs and outputs of the node group interact with fields. */
   std::unique_ptr<nodes::FieldInferencingInterface> field_inferencing_interface;
 
+  std::mutex geometry_nodes_lazy_function_graph_info_mutex;
+  std::unique_ptr<nodes::GeometryNodesLazyFunctionGraphInfo>
+      geometry_nodes_lazy_function_graph_info;
+
   /**
    * Protects access to all topology cache variables below. This is necessary so that the cache can
    * be updated on a const #bNodeTree.
@@ -407,7 +412,6 @@ inline blender::Span<const bNodeLink *> bNode::internal_links_span() const
 
 inline const blender::nodes::NodeDeclaration *bNode::declaration() const
 {
-  BLI_assert(this->runtime->declaration != nullptr);
   return this->runtime->declaration;
 }
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 4eb48e9edc9..91616a00972 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -71,6 +71,7 @@
 #include "NOD_composite.h"
 #include "NOD_function.h"
 #include "NOD_geometry.h"
+#include "NOD_geometry_nodes_to_lazy_function_graph.hh"
 #include "NOD_node_declaration.hh"
 #include "NOD_shader.h"
 #include "NOD_socket.h"
diff --git a/source/blender/functions/FN_lazy_function.hh b/source/blender/functions/FN_lazy_function.hh
index 7fde531f4b7..f6528907c1b 100644
--- a/source/blender/functions/FN_lazy_function.hh
+++ b/source/blender/functions/FN_lazy_function.hh
@@ -32,7 +32,7 @@ struct Context {
 };
 
 class Params {
- protected:
+ public:
   const LazyFunction &fn_;
 
  public:
diff --git a/source/blender/functions/intern/lazy_function_graph_executor.cc b/source/blender/functions/intern/lazy_function_graph_executor.cc
index c03f7b3c097..0f0cb3a3520 100644
--- a/source/blender/functions/intern/lazy_function_graph_executor.cc
+++ b/source/blender/functions/intern/lazy_function_graph_executor.cc
@@ -387,15 +387,24 @@ class Executor {
       if (input_data == nullptr) {
         continue;
       }
-      const OutputSocket &socket = *graph_inputs_[graph_input_index];
-      const CPPType &type = socket.type();
-      void *buffer = allocator.allocate(type.size(), type.alignment());
-      type.move_construct(input_data, buffer);
-      this->forward_value_to_linked_inputs(socket, {type, buffer}, current_task);
-      loaded_inputs_[graph_input_index] = true;
+      this->forward_newly_provided_input(current_task, allocator, graph_input_index, input_data);
     }
   }
 
+  void forward_newly_provided_input(CurrentTask &current_task,
+                                    LinearAllocator<> &allocator,
+                                    const int graph_input_index,
+                                    void *input_data)
+  {
+    BLI_assert(!loaded_inputs_[graph_input_index]);
+    const OutputSocket &socket = *graph_inputs_[graph_input_index];
+    const CPPType &type = socket.type();
+    void *buffer = allocator.allocate(type.size(), type.alignment());
+    type.move_construct(input_data, buffer);
+    this->forward_value_to_linked_inputs(socket, {type, buffer}, current_task);
+    loaded_inputs_[graph_input_index] = true;
+  }
+
   void notify_output_required(const OutputSocket &socket, CurrentTask &current_task)
   {
     const Node &node = socket.node();
@@ -405,7 +414,12 @@ class Executor {
 
     if (node.is_dummy()) {
       const int graph_input_index = graph_inputs_.index_of(&socket);
-      params_->try_get_input_data_ptr_or_request(graph_input_index);
+      void *input_data = params_->try_get_input_data_ptr_or_request(graph_input_index);
+      if (input_data == nullptr) {
+        return;
+      }
+      this->forward_newly_provided_input(
+          current_task, local_allocators_.local(), graph_input_index, input_data);
       return;
     }
 
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 0c79672c30e..000092252a5 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -1088,7 +1088,7 @@ static void store_output_attributes(GeometrySet &geometry,
 /**
  * Evaluate a node group to compute the output geometry.
  */
-static GeometrySet compute_geometry(const bNodeTree &tree_ref,
+static GeometrySet compute_geometry(const bNodeTree &btree,
                                     const bNode &output_node,
                                     GeometrySet input_geometry_set,
                                     NodesModifierData *nmd,
@@ -1096,20 +1096,19 @@ static GeometrySet compute_geometry(const bNodeTree &tree_ref,
 {
   UNUSED_VARS(find_sockets_to_preview, logging_enabled);
 
-  lf::LazyFunctionGraph graph;
-  blender::nodes::GeometryNodeLazyFunctionMapping mapping;
-  blender::nodes::GeometryNodesLazyFunctionResources graph_resources;
-  blender::nodes::geometry_nodes_to_lazy_function_graph(tree_ref, graph, graph_resources, mapping);
-  graph.update_node_indices();
+  const blender::nodes::GeometryNodesLazyFunctionGraphInfo &lf_graph_info =
+      blender::nodes::ensure_geometry_nodes_lazy_function_graph(btree);
   // std::cout << graph.to_dot() << "\n";
 
+  const blender::nodes::GeometryNodeLazyFunctionMapping &mapping = lf_graph_info.mapping;
+
   Vector<const lf::OutputSocket *> graph_inputs;
   Vector<const lf::InputSocket *> graph_outputs;
   for (const lf::OutputSocket *socket : mapping.group_input_sockets) {
     graph_inputs.append(socket);
   }
-  for (const bNodeSocket *socket_ref : output_node.input_sockets().drop_back(1)) {
-    const lf::InputSocket &socket = mapping.dummy_socket_map.lookup(socket_ref)->as_input();
+  for (const bNodeSocket *bsocket : output_node.input_sockets().drop_back(1)) {
+    const lf::InputSocket &socket = mapping.dummy_socket_map.lookup(bsocket)->as_input();
     graph_outputs.append(&socket);
   }
 
@@ -1119,7 +1118,7 @@ static GeometrySet compute_geometry(const bNodeTree &tree_ref,
   Array<lf::ValueUsage> param_output_usages(graph_outputs.size(), lf::ValueUsage::Used);
   Array<bool> param_set_outputs(graph_outputs.size(), false);
 
-  lf::LazyFunctionGraphExecutor graph_executor{graph, graph_inputs, graph_outputs};
+  lf::LazyFunctionGraphExecutor graph_executor{lf_graph_info.graph, graph_inputs, graph_outputs};
 
   blender::nodes::GeoNodesModifierData geo_nodes_modifier_data;
   geo_nodes_modifier_data.depsgraph = ctx->depsgraph;
@@ -1137,7 +1136,7 @@ static GeometrySet compute_geometry(const bNodeTree &tree_ref,
   Vector<GMutablePointer> inputs_to_destruct;
 
   int input_index;
-  LISTBASE_FOREACH_INDEX (bNodeSocket *, interface_socket, &tree_ref.inputs, input_index) {
+  LISTBASE_FOREACH_INDEX (bNodeSocket *, interface_socket, &btree.inputs, input_index) {
     if (interface_socket->type == SOCK_GEOMETRY && input_index == 0) {
       param_inputs[input_index] = &input_geometry_set;
       continue;
@@ -1259,15 +1258,14 @@ static void modifyGeometry(ModifierData *md,
     return;
   }
 
-  Span<const bNode *> output_nodes = tree.nodes_by_type("NodeGroupOutput");
-  if (output_nodes.size() != 1) {
-    BKE_modifier_set_error(ctx->object, md, "Node group must have a single output node");
+  const bNode *output_node = tree.group_output_node();
+  if (output_node == nullptr) {
+    BKE_modifier_set_error(ctx->object, md, "Node group must have a group output node");
     geometry_set.clear();
     return;
   }
 
-  const bNode &output_node = *output_nodes[0];
-  Span<const bNodeSocket *> group_outputs = output_node.input_sockets().drop_back(1);
+  Span<const bNodeSocket *> group_outputs = output_node->input_sockets().drop_back(1);
   if (group_outputs.is_empty()) {
     BKE_modifier_set_error(ctx->object, md, "Node group must have an output socket");
     geometry_set.clear();
@@ -1291,7 +1289,7 @@ static void modifyGeometry(ModifierData *md,
     use_orig_index_polys = CustomData_has_layer(&mesh.pdata, CD_ORIGINDEX);
   }
 
-  geometry_set = compute_geometry(tree, output_node, std::move(geometry_set), nmd, ctx);
+  geometry_set = compute_geometry(tree, *output_node, std::move(geometry_set), nmd, ctx);
 
   if (geometry_set.has_mesh()) {
     /* Add #CD_ORIGINDEX layers if they don't exist already. This is required because the
diff --git a/source/blender/nodes/NOD_geometry_nodes_to_lazy_function_graph.hh b/source/blender/nodes/NOD_geometry_nodes_to_lazy_function_graph.hh
index a3d6e3f21f7..057616423ef 100644
--- a/source/blender/nodes/NOD_geometry_nodes_to_lazy_function_graph.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_to_lazy_function_graph.hh
@@ -84,13 +84,15 @@ struct GeometryNodeLazyFunctionMapping {
   Vector<lf::OutputSocket *> group_input_sockets;
 };
 
-struct GeometryNodesLazyFunctionResources {
+struct GeometryNodesLazyFunctionGraphInfo {
   LinearAllocator<> allocator;
+  std::unique_ptr<NodeMultiFunctions> node_multi_functions;
   Vector<std::unique_ptr<LazyFunction>> functions;
   Vector<GMutablePointer> values_to_destruct;
-  Vector<std::unique_ptr<NodeMultiFunctions>> node_multi_functions;
+  GeometryNodeLazyFunctionMapping mapping;
+  LazyFunctionGraph graph;
 
-  ~GeometryNodesLazyFunctionResources()
+  ~GeometryNodesLazyFunctionGraphInfo()
   {
     for (GMutablePointer &p : this->values_to_destruct) {
       p.destruct();
@@ -98,9 +100,7 @@ struct GeometryNodesLazyFunctionResources {
   }
 };
 
-void geometry_nodes_to_lazy_function_graph(const bNodeTree &tree,
-                                           LazyFunctionGraph &graph,
-                                           GeometryNodesLazyFunctionResources &resources,
-                                           GeometryNodeLazyFunctionMapping &mapping);
+const GeometryNo

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list