Commit: 5f5ee2718e63efad28c1951db17751df65817eea
Author: Omar Emara
Date:   Fri Apr 8 18:19:51 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rB5f5ee2718e63efad28c1951db17751df65817eea

Viewport Compositor: Move node operation to its own file

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

M       source/blender/viewport_compositor/CMakeLists.txt
M       source/blender/viewport_compositor/VPC_compositor_execute.hh
A       source/blender/viewport_compositor/VPC_node_operation.hh
R080    source/blender/viewport_compositor/VPC_utils.hh 
source/blender/viewport_compositor/VPC_utilities.hh
M       source/blender/viewport_compositor/intern/compositor_execute.cc
A       source/blender/viewport_compositor/intern/node_operation.cc
M       source/blender/viewport_compositor/intern/scheduler.cc
R058    source/blender/viewport_compositor/intern/utils.cc      
source/blender/viewport_compositor/intern/utilities.cc

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

diff --git a/source/blender/viewport_compositor/CMakeLists.txt 
b/source/blender/viewport_compositor/CMakeLists.txt
index 22be0bf174b..58cf7567d83 100644
--- a/source/blender/viewport_compositor/CMakeLists.txt
+++ b/source/blender/viewport_compositor/CMakeLists.txt
@@ -20,6 +20,7 @@ set(SRC
   intern/context.cc
   intern/conversion_processor_operation.cc
   intern/domain.cc
+  intern/node_operation.cc
   intern/operation.cc
   intern/processor_operation.cc
   intern/realize_on_domain_processor_operation.cc
@@ -27,13 +28,14 @@ set(SRC
   intern/result.cc
   intern/scheduler.cc
   intern/texture_pool.cc
-  intern/utils.cc
+  intern/utilities.cc
 
   VPC_compositor_execute.hh
   VPC_context.hh
   VPC_conversion_processor_operation.hh
   VPC_domain.hh
   VPC_input_descriptor.hh
+  VPC_node_operation.hh
   VPC_operation.hh
   VPC_processor_operation.hh
   VPC_realize_on_domain_processor_operation.hh
@@ -41,7 +43,7 @@ set(SRC
   VPC_result.hh
   VPC_scheduler.hh
   VPC_texture_pool.hh
-  VPC_utils.hh
+  VPC_utilities.hh
 )
 
 set(LIB
diff --git a/source/blender/viewport_compositor/VPC_compositor_execute.hh 
b/source/blender/viewport_compositor/VPC_compositor_execute.hh
index db3e648160a..b0c37017db1 100644
--- a/source/blender/viewport_compositor/VPC_compositor_execute.hh
+++ b/source/blender/viewport_compositor/VPC_compositor_execute.hh
@@ -23,6 +23,7 @@
 
 #include "VPC_context.hh"
 #include "VPC_domain.hh"
+#include "VPC_node_operation.hh"
 #include "VPC_operation.hh"
 #include "VPC_result.hh"
 #include "VPC_scheduler.hh"
@@ -30,48 +31,8 @@
 
 namespace blender::viewport_compositor {
 
-/* --------------------------------------------------------------------
- * Node Operation.
- */
-
 using namespace nodes::derived_node_tree_types;
 
-/* The operation class that nodes should implement and instantiate in the 
bNodeType
- * get_compositor_operation, passing the given inputs to the constructor.  */
-class NodeOperation : public Operation {
- private:
-  /* The node that this operation represents. */
-  DNode node_;
-  /* A vector storing unique pointers to the results mapped to unlinked 
inputs. */
-  Vector<std::unique_ptr<Result>> unlinked_inputs_results_;
-  /* A mapping between each unlinked input in the node identified by its 
identifier and its
-   * corresponding input socket. */
-  Map<StringRef, DInputSocket> unlinked_inputs_sockets_;
-
- public:
-  /* Initialize members by the given arguments, populate the output results 
based on the node
-   * outputs, populate the input types maps based on the node inputs, and add 
results for unlinked
-   * inputs. */
-  NodeOperation(Context &context, DNode node);
-
-  /* Returns a reference to the node this operations represents. */
-  const bNode &node() const;
-
- protected:
-  /* Returns true if the output identified by the given identifier is needed 
and should be
-   * computed, otherwise returns false. */
-  bool is_output_needed(StringRef identifier) const;
-
-  /* Set the values of the results for unlinked inputs. */
-  void pre_execute() override;
-
- private:
-  /* For each unlinked input in the node, construct a new result of an 
appropriate type, add it to
-   * the unlinked_inputs_results_ vector, map the input to it, and map the 
input to its
-   * corresponding input socket through the unlinked_inputs_sockets_ map. */
-  void populate_results_for_unlinked_inputs();
-};
-
 /* --------------------------------------------------------------------
  * GPU Material Node.
  */
diff --git a/source/blender/viewport_compositor/VPC_node_operation.hh 
b/source/blender/viewport_compositor/VPC_node_operation.hh
new file mode 100644
index 00000000000..ee4b3235982
--- /dev/null
+++ b/source/blender/viewport_compositor/VPC_node_operation.hh
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+#pragma once
+
+#include <memory>
+
+#include "BLI_map.hh"
+#include "BLI_string_ref.hh"
+#include "BLI_vector.hh"
+
+#include "DNA_node_types.h"
+
+#include "NOD_derived_node_tree.hh"
+
+#include "VPC_context.hh"
+#include "VPC_operation.hh"
+#include "VPC_result.hh"
+
+namespace blender::viewport_compositor {
+
+using namespace nodes::derived_node_tree_types;
+
+/* The operation class that nodes should implement and instantiate in the 
bNodeType
+ * get_compositor_operation, passing the given inputs to the constructor.  */
+class NodeOperation : public Operation {
+ private:
+  /* The node that this operation represents. */
+  DNode node_;
+  /* A vector storing unique pointers to the results mapped to unlinked 
inputs. */
+  Vector<std::unique_ptr<Result>> unlinked_inputs_results_;
+  /* A mapping between each unlinked input in the node identified by its 
identifier and its
+   * corresponding input socket. */
+  Map<StringRef, DInputSocket> unlinked_inputs_sockets_;
+
+ public:
+  /* Initialize members by the given arguments, populate the output results 
based on the node
+   * outputs, populate the input types maps based on the node inputs, and add 
results for unlinked
+   * inputs. */
+  NodeOperation(Context &context, DNode node);
+
+  /* Returns a reference to the node this operations represents. */
+  const bNode &node() const;
+
+ protected:
+  /* Returns true if the output identified by the given identifier is needed 
and should be
+   * computed, otherwise returns false. */
+  bool is_output_needed(StringRef identifier) const;
+
+  /* Set the values of the results for unlinked inputs. */
+  void pre_execute() override;
+
+ private:
+  /* For each unlinked input in the node, construct a new result of an 
appropriate type, add it to
+   * the unlinked_inputs_results_ vector, map the input to it, and map the 
input to its
+   * corresponding input socket through the unlinked_inputs_sockets_ map. */
+  void populate_results_for_unlinked_inputs();
+};
+
+}  // namespace blender::viewport_compositor
diff --git a/source/blender/viewport_compositor/VPC_utils.hh 
b/source/blender/viewport_compositor/VPC_utilities.hh
similarity index 80%
rename from source/blender/viewport_compositor/VPC_utils.hh
rename to source/blender/viewport_compositor/VPC_utilities.hh
index ac20c6ee1c4..c6c78c04b5c 100644
--- a/source/blender/viewport_compositor/VPC_utils.hh
+++ b/source/blender/viewport_compositor/VPC_utilities.hh
@@ -5,6 +5,8 @@
 
 #include "NOD_derived_node_tree.hh"
 
+#include "VPC_result.hh"
+
 namespace blender::viewport_compositor {
 
 using namespace nodes::derived_node_tree_types;
@@ -15,4 +17,7 @@ using namespace nodes::derived_node_tree_types;
  * to an unlinked input of a group input node. */
 DSocket get_node_input_origin_socket(DInputSocket input);
 
+/* Get the result type that corresponds to the type of the given socket. */
+ResultType get_node_socket_result_type(const SocketRef *socket);
+
 }  // namespace blender::viewport_compositor
diff --git a/source/blender/viewport_compositor/intern/compositor_execute.cc 
b/source/blender/viewport_compositor/intern/compositor_execute.cc
index cc7d10c9148..73545bbf8cc 100644
--- a/source/blender/viewport_compositor/intern/compositor_execute.cc
+++ b/source/blender/viewport_compositor/intern/compositor_execute.cc
@@ -41,121 +41,20 @@
 #include "VPC_context.hh"
 #include "VPC_domain.hh"
 #include "VPC_input_descriptor.hh"
+#include "VPC_node_operation.hh"
 #include "VPC_operation.hh"
 #include "VPC_result.hh"
 #include "VPC_scheduler.hh"
 #include "VPC_texture_pool.hh"
-#include "VPC_utils.hh"
-
-namespace blender::viewport_compositor {
+#include "VPC_utilities.hh"
 
 /* --------------------------------------------------------------------
- * Node Operation.
+ * GPU Material Node.
  */
 
-using namespace nodes::derived_node_tree_types;
-
-static ResultType get_node_socket_result_type(const SocketRef *socket)
-{
-  switch (socket->bsocket()->type) {
-    case SOCK_FLOAT:
-      return ResultType::Float;
-    case SOCK_VECTOR:
-      return ResultType::Vector;
-    case SOCK_RGBA:
-      return ResultType::Color;
-    default:
-      BLI_assert_unreachable();
-      return ResultType::Float;
-  }
-}
-
-NodeOperation::NodeOperation(Context &context, DNode node) : 
Operation(context), node_(node)
-{
-  /* Populate the output results. */
-  for (const OutputSocketRef *output : node->outputs()) {
-    const ResultType result_type = get_node_socket_result_type(output);
-    const Result result = Result(result_type, texture_pool());
-    populate_result(output->identifier(), result);
-  }
-
-  /* Populate the input descriptors. */
-  for (const InputSocketRef *input : node->inputs()) {
-    InputDescriptor input_descriptor;
-    input_descriptor.type = get_node_socket_result_type(input);
-    const nodes::SocketDeclarationPtr &socket_declaration =
-        input->node().declaration()->inputs()[input->index()];
-    input_descriptor.domain_priority = 
socket_declaration->compositor_domain_priority();
-    input_descriptor.expects_single_value = 
socket_declaration->compositor_expects_single_value();
-    declare_input_descriptor(input->identifier(), input_descriptor);
-  }
-
-  populate_results_for_unlinked_inputs();
-}
-
-const bNode &NodeOperation::node() const
-{
-  return *node_->bnode();
-}
-
-bool NodeOperation::is_output_needed(StringRef identifier) const
-{
-  DOutputSocket output = node_.output_by_identifier(identifier);
-  if (output->logically_linked_sockets().is_empty()) {
-    return false;
-  }
-  return true;
-}
-
-void NodeOperation::pre_execute()
-{
-  /* For each unlinked input socket, allocate a single value and set the value 
to the socket's
-   * default value. */
-  for (const Map<StringRef, DInputSocket>::Item &item : 
unlinked_inputs_sockets_.items()) {
-    Result &result = get_input(item.key);
-    DInputSocket input = item.value;
-    result.allocate_single_value();
-    switch (result.type()) {
-      case ResultType::Float:
-        
result.set_float_value(input->default_value<bNodeSocketValueFloat>()->value);
-        continue;
-      case ResultType::Vector:
-        
result.set_vector_value(float3(input->default_value<bNodeSocketValueVector>()->value));
-        continue;
-      case ResultType::Color:
-        
result.set_color_value(float4(input->default_value<bNodeSocketValueRGBA>()->value));
-    

@@ 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