Commit: 59b1eb145d0aa7c1b9a13750ce5c5f941ad27638
Author: Hans Goudey
Date:   Wed Dec 14 18:42:04 2022 -0600
Branches: temp-nodes-group-declarations
https://developer.blender.org/rB59b1eb145d0aa7c1b9a13750ce5c5f941ad27638

Start of refactoring to use declaration for group nodes

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

M       source/blender/blenkernel/BKE_node.h
M       source/blender/blenkernel/BKE_node_runtime.hh
M       source/blender/blenkernel/intern/node.cc
M       source/blender/blenkernel/intern/node_tree_field_inferencing.cc
M       source/blender/blenkernel/intern/node_tree_update.cc
M       source/blender/editors/space_node/link_drag_search.cc
M       source/blender/editors/space_node/node_group.cc
M       source/blender/makesrna/intern/rna_nodetree.c
M       source/blender/nodes/NOD_common.h
M       source/blender/nodes/NOD_node_declaration.hh
M       source/blender/nodes/NOD_socket_declarations.hh
M       source/blender/nodes/composite/nodes/node_composite_common.cc
M       source/blender/nodes/geometry/nodes/node_geo_common.cc
M       source/blender/nodes/intern/node_common.cc
M       source/blender/nodes/intern/node_declaration.cc
M       source/blender/nodes/intern/node_socket.cc
M       source/blender/nodes/intern/node_socket_declarations.cc
M       source/blender/nodes/intern/socket_search_link.cc
M       source/blender/nodes/shader/nodes/node_shader_common.cc
M       source/blender/nodes/texture/nodes/node_texture_common.cc

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

diff --git a/source/blender/blenkernel/BKE_node.h 
b/source/blender/blenkernel/BKE_node.h
index 5a1198791fb..845b5a5566d 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -104,6 +104,7 @@ namespace nodes {
 class DNode;
 class NodeMultiFunctionBuilder;
 class GeoNodeExecParams;
+class NodeDeclaration;
 class NodeDeclarationBuilder;
 class GatherLinkSearchOpParams;
 }  // namespace nodes
@@ -121,6 +122,9 @@ using CPPTypeHandle = blender::CPPType;
 using NodeMultiFunctionBuildFunction = void 
(*)(blender::nodes::NodeMultiFunctionBuilder &builder);
 using NodeGeometryExecFunction = void (*)(blender::nodes::GeoNodeExecParams 
params);
 using NodeDeclareFunction = void (*)(blender::nodes::NodeDeclarationBuilder 
&builder);
+using NodeDeclareDynamicFunction = bool (*)(const bNodeTree &tree,
+                                            const bNode &node,
+                                            blender::nodes::NodeDeclaration 
&r_declaration);
 using SocketGetCPPValueFunction = void (*)(const struct bNodeSocket &socket, 
void *r_value);
 using SocketGetGeometryNodesCPPValueFunction = void (*)(const struct 
bNodeSocket &socket,
                                                         void *r_value);
@@ -140,6 +144,7 @@ typedef void *NodeGetCompositorShaderNodeFunction;
 typedef void *NodeMultiFunctionBuildFunction;
 typedef void *NodeGeometryExecFunction;
 typedef void *NodeDeclareFunction;
+typedef void *NodeDeclareDynamicFunction;
 typedef void *NodeGatherSocketLinkOperationsFunction;
 typedef void *SocketGetCPPTypeFunction;
 typedef void *SocketGetGeometryNodesCPPTypeFunction;
@@ -176,11 +181,6 @@ typedef struct bNodeSocketType {
                                 struct bNode *node,
                                 struct bNodeSocket *sock,
                                 const char *data_path);
-  void (*interface_verify_socket)(struct bNodeTree *ntree,
-                                  const struct bNodeSocket *interface_socket,
-                                  struct bNode *node,
-                                  struct bNodeSocket *sock,
-                                  const char *data_path);
   void (*interface_from_socket)(struct bNodeTree *ntree,
                                 struct bNodeSocket *interface_socket,
                                 struct bNode *node,
@@ -345,8 +345,12 @@ typedef struct bNodeType {
 
   /* Declares which sockets the node has. */
   NodeDeclareFunction declare;
-  /* Different nodes of this type can have different declarations. */
-  bool declaration_is_dynamic;
+  /**
+   * Declare which sockets the node has, but isn't static per node type. In 
orther words,
+   * different nodes of this type can have different declarations and 
different sockets.
+   */
+  NodeDeclareDynamicFunction declare_dynamic;
+
   /* Declaration to be used when it is not dynamic. */
   NodeDeclarationHandle *fixed_declaration;
 
diff --git a/source/blender/blenkernel/BKE_node_runtime.hh 
b/source/blender/blenkernel/BKE_node_runtime.hh
index 6a00e70cb5b..7f0e7f66936 100644
--- a/source/blender/blenkernel/BKE_node_runtime.hh
+++ b/source/blender/blenkernel/BKE_node_runtime.hh
@@ -324,7 +324,7 @@ inline bool topology_cache_is_available(const bNodeSocket 
&socket)
 
 namespace node_field_inferencing {
 bool update_field_inferencing(const bNodeTree &tree);
-}
+}  // namespace node_field_inferencing
 
 }  // namespace blender::bke
 
diff --git a/source/blender/blenkernel/intern/node.cc 
b/source/blender/blenkernel/intern/node.cc
index 9bc42879d78..0a318e42779 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -1374,7 +1374,7 @@ void nodeRegisterType(bNodeType *nt)
   BLI_assert(nt->idname[0] != '\0');
   BLI_assert(nt->poll != nullptr);
 
-  if (nt->declare && !nt->declaration_is_dynamic) {
+  if (nt->declare && !nt->declare_dynamic) {
     if (nt->fixed_declaration == nullptr) {
       nt->fixed_declaration = new blender::nodes::NodeDeclaration();
       blender::nodes::build_node_declaration(*nt, *nt->fixed_declaration);
@@ -2997,7 +2997,7 @@ static void node_free_node(bNodeTree *ntree, bNode *node)
     MEM_freeN(node->prop);
   }
 
-  if (node->typeinfo->declaration_is_dynamic) {
+  if (node->typeinfo->declare_dynamic) {
     delete node->runtime->declaration;
   }
 
@@ -3612,7 +3612,7 @@ bool nodeDeclarationEnsureOnOutdatedNode(bNodeTree * 
/*ntree*/, bNode *node)
   if (node->typeinfo->declare == nullptr) {
     return false;
   }
-  if (node->typeinfo->declaration_is_dynamic) {
+  if (node->typeinfo->declare_dynamic) {
     node->runtime->declaration = new blender::nodes::NodeDeclaration();
     blender::nodes::build_node_declaration(*node->typeinfo, 
*node->runtime->declaration);
   }
diff --git a/source/blender/blenkernel/intern/node_tree_field_inferencing.cc 
b/source/blender/blenkernel/intern/node_tree_field_inferencing.cc
index 88fd3636633..b828586ba0a 100644
--- a/source/blender/blenkernel/intern/node_tree_field_inferencing.cc
+++ b/source/blender/blenkernel/intern/node_tree_field_inferencing.cc
@@ -486,27 +486,34 @@ static void update_socket_shapes(const bNodeTree &tree,
   }
 }
 
-bool update_field_inferencing(const bNodeTree &tree)
+FieldInferencingInterface calculate_field_inferencing(const bNodeTree &tree)
 {
+  FieldInferencingInterface interface;
+
   tree.ensure_topology_cache();
 
-  /* Create new inferencing interface for this node group. */
-  std::unique_ptr<FieldInferencingInterface> new_inferencing_interface =
-      std::make_unique<FieldInferencingInterface>();
-  new_inferencing_interface->inputs.resize(BLI_listbase_count(&tree.inputs),
-                                           InputSocketFieldType::IsSupported);
-  new_inferencing_interface->outputs.resize(BLI_listbase_count(&tree.outputs),
-                                            
OutputFieldDependency::ForDataSource());
+  interface.inputs.resize(BLI_listbase_count(&tree.inputs), 
InputSocketFieldType::IsSupported);
+  interface.outputs.resize(BLI_listbase_count(&tree.outputs),
+                           OutputFieldDependency::ForDataSource());
 
   /* Keep track of the state of all sockets. The index into this array is 
#SocketRef::id(). */
   Array<SocketFieldState> field_state_by_socket_id(tree.all_sockets().size());
 
   propagate_data_requirements_from_right_to_left(tree, 
field_state_by_socket_id);
-  determine_group_input_states(tree, *new_inferencing_interface, 
field_state_by_socket_id);
+  determine_group_input_states(tree, interface, field_state_by_socket_id);
   propagate_field_status_from_left_to_right(tree, field_state_by_socket_id);
-  determine_group_output_states(tree, *new_inferencing_interface, 
field_state_by_socket_id);
+  determine_group_output_states(tree, interface, field_state_by_socket_id);
   update_socket_shapes(tree, field_state_by_socket_id);
 
+  return interface;
+}
+
+bool update_field_inferencing(const bNodeTree &tree)
+{
+  /* Create new inferencing interface for this node group. */
+  std::unique_ptr<FieldInferencingInterface> new_inferencing_interface =
+      
std::make_unique<FieldInferencingInterface>(calculate_field_inferencing(tree));
+
   /* Update the previous group interface. */
   const bool group_interface_changed = 
!tree.runtime->field_inferencing_interface ||
                                        
*tree.runtime->field_inferencing_interface !=
diff --git a/source/blender/blenkernel/intern/node_tree_update.cc 
b/source/blender/blenkernel/intern/node_tree_update.cc
index a49baf11680..3cec5e4a5fe 100644
--- a/source/blender/blenkernel/intern/node_tree_update.cc
+++ b/source/blender/blenkernel/intern/node_tree_update.cc
@@ -540,12 +540,18 @@ class NodeTreeMainUpdater {
       nodeDeclarationEnsure(&ntree, node);
       if (this->should_update_individual_node(ntree, *node)) {
         bNodeType &ntype = *node->typeinfo;
-        if (ntype.group_update_func) {
-          ntype.group_update_func(&ntree, node);
-        }
         if (ntype.updatefunc) {
           ntype.updatefunc(&ntree, node);
         }
+        if (ntype.declare_dynamic) {
+          if (!node->runtime->declaration) {
+            node->runtime->declaration = new blender::nodes::NodeDeclaration();
+          }
+          build_node_declaration_dynamic(ntree, *node, 
*node->runtime->declaration);
+        }
+        if (ntype.group_update_func) {
+          ntype.group_update_func(&ntree, node);
+        }
       }
       if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) {
         group_inout_nodes.append(node);
diff --git a/source/blender/editors/space_node/link_drag_search.cc 
b/source/blender/editors/space_node/link_drag_search.cc
index 8e156f409af..e4197c98ea1 100644
--- a/source/blender/editors/space_node/link_drag_search.cc
+++ b/source/blender/editors/space_node/link_drag_search.cc
@@ -198,7 +198,7 @@ static void search_link_ops_for_asset_metadata(const 
bNodeTree &node_tree,
            DEG_relations_tag_update(&bmain);
 
            /* Create the inputs and outputs on the new node. */
-           node.typeinfo->group_update_func(&params.node_tree, &node);
+           node.typeinfo->updatefunc(&params.node_tree, &node);
 
            bNodeSocket *new_node_socket = bke::node_find_enabled_socket(
                node, in_out, socket_property->name);
diff --git a/source/blender/editors/space_node/node_group.cc 
b/source/blender/editors/space_node/node_group.cc
index 2c28a8fae34..32946888635 100644
--- a/source/blender/editors/space_node/node_group.cc
+++ b/source/blender/editors/space_node/node_group.cc
@@ -780,8 +780,7 @@ static void node_group_make_redirect_incoming_link(
                                                                     
socket_for_naming->name);
 
     /* Update the group node and interface sockets so the new interface socket 
can be linked. */
-    node_group_update(&ntree, gnode);
-    node_group_input_update(ngroup, input_node);
+    /* TODO: Update sockets based on declaration here. */
 
     /* Create new internal link. */
     bNodeSocket *input_sock = node_group_input_find_socket(input_node, 
iosock->identifier);
@@ -942,11 +941,7 @@ static void node_group_make_insert_selected(const bContext 
&C,
             &ntree.li

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
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