[Bf-blender-cvs] [9d3fe9c60f6] temp-viewport-compositor-compiler: Viewport Compositor: Add operations for unlinked inputs

Omar Emara noreply at git.blender.org
Thu Apr 14 09:24:51 CEST 2022


Commit: 9d3fe9c60f61332ffbce1eb61ee56dcd3af3ba65
Author: Omar Emara
Date:   Thu Apr 14 09:23:17 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rB9d3fe9c60f61332ffbce1eb61ee56dcd3af3ba65

Viewport Compositor: Add operations for unlinked inputs

This is needed in preparation for eager evaluation and it also
simplifies things by removing pre execution logic in operations.

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

M	source/blender/viewport_compositor/CMakeLists.txt
M	source/blender/viewport_compositor/VPC_evaluator.hh
A	source/blender/viewport_compositor/VPC_input_single_value_operation.hh
M	source/blender/viewport_compositor/VPC_node_operation.hh
M	source/blender/viewport_compositor/VPC_operation.hh
M	source/blender/viewport_compositor/VPC_processor_operation.hh
M	source/blender/viewport_compositor/intern/evaluator.cc
A	source/blender/viewport_compositor/intern/input_single_value_operation.cc
M	source/blender/viewport_compositor/intern/node_operation.cc
M	source/blender/viewport_compositor/intern/operation.cc
M	source/blender/viewport_compositor/intern/processor_operation.cc

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

diff --git a/source/blender/viewport_compositor/CMakeLists.txt b/source/blender/viewport_compositor/CMakeLists.txt
index b8d6ab01a19..d2335f054bb 100644
--- a/source/blender/viewport_compositor/CMakeLists.txt
+++ b/source/blender/viewport_compositor/CMakeLists.txt
@@ -23,6 +23,7 @@ set(SRC
   intern/evaluator.cc
   intern/gpu_material_node.cc
   intern/gpu_material_operation.cc
+  intern/input_single_value_operation.cc
   intern/node_operation.cc
   intern/operation.cc
   intern/processor_operation.cc
@@ -42,6 +43,7 @@ set(SRC
   VPC_gpu_material_node.hh
   VPC_gpu_material_operation.hh
   VPC_input_descriptor.hh
+  VPC_input_single_value_operation.hh
   VPC_node_operation.hh
   VPC_operation.hh
   VPC_processor_operation.hh
diff --git a/source/blender/viewport_compositor/VPC_evaluator.hh b/source/blender/viewport_compositor/VPC_evaluator.hh
index 0ea49db4c0a..890f89ea059 100644
--- a/source/blender/viewport_compositor/VPC_evaluator.hh
+++ b/source/blender/viewport_compositor/VPC_evaluator.hh
@@ -139,19 +139,23 @@ class Evaluator {
   void compile_and_evaluate();
 
   /* Compile the given node into a node operation, map each input to the result of the output
-   * linked to it, update the compile state, and evaluate the operation. */
+   * linked to it, update the compile state, add the newly created operation to the operations
+   * stream, and evaluate the operation. */
   void compile_and_evaluate_node(DNode node, CompileState &compile_state);
 
   /* Map each input of the node operation to the result of the output linked to it. Unlinked inputs
-   * are left unmapped as they will be mapped internally to internal results in the node operation
-   * before execution. */
+   * are mapped to the result of a newly created Input Single Value Operation, which is added to
+   * the operations stream and evaluated. Since this method might add operations to the operations
+   * stream, the actual node operation should only be added to the stream once this method is
+   * called. */
   void map_node_operation_inputs_to_their_results(DNode node,
                                                   NodeOperation *operation,
                                                   CompileState &compile_state);
 
   /* Compile the GPU material compile group into a GPU material operation, map each input of the
-   * operation to the result of the output linked to it, update the compile state, evaluate the
-   * operation, and finally reset the GPU material compile group. */
+   * operation to the result of the output linked to it, update the compile state, add the newly
+   * created operation to the operations stream, evaluate the operation, and finally reset the GPU
+   * material compile group. */
   void compile_and_evaluate_gpu_material_compile_group(CompileState &compile_state);
 
   /* Map each input of the GPU material operation to the result of the output linked to it. */
diff --git a/source/blender/viewport_compositor/VPC_input_single_value_operation.hh b/source/blender/viewport_compositor/VPC_input_single_value_operation.hh
new file mode 100644
index 00000000000..52e38127c6a
--- /dev/null
+++ b/source/blender/viewport_compositor/VPC_input_single_value_operation.hh
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+#pragma once
+
+#include "BLI_string_ref.hh"
+
+#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;
+
+/* An input single value operation is an operation that outputs a single value result whose value
+ * is the value of an unlinked input socket. This is typically used to initialize the values of
+ * unlinked node input sockets. */
+class InputSingleValueOperation : public Operation {
+ private:
+  /* The identifier of the output. */
+  static const StringRef output_identifier_;
+  /* The input socket whose value the operation will set to its result. */
+  DInputSocket input_socket_;
+
+ public:
+  InputSingleValueOperation(Context &context, DInputSocket input_socket);
+
+  /* Allocate a single value result and set its value to the default value of the input socket. */
+  void execute() override;
+
+  /* Get a reference to the output result of the operation, this essentially calls the super
+   * get_result with the output identifier of the operation. */
+  Result &get_result();
+
+ private:
+  /* Populate the result of the operation, this essentially calls the super populate_result method
+   * with the output identifier of the operation. */
+  void populate_result(Result result);
+};
+
+}  // namespace blender::viewport_compositor
diff --git a/source/blender/viewport_compositor/VPC_node_operation.hh b/source/blender/viewport_compositor/VPC_node_operation.hh
index c03562daab7..8b1db034f94 100644
--- a/source/blender/viewport_compositor/VPC_node_operation.hh
+++ b/source/blender/viewport_compositor/VPC_node_operation.hh
@@ -27,16 +27,10 @@ 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. */
+  /* Populate the output results based on the node outputs and populate the input descriptors based
+   * on the node inputs. */
   NodeOperation(Context &context, DNode node);
 
   /* Returns a reference to the derived node that this operation represents. */
@@ -49,15 +43,6 @@ class NodeOperation : public Operation {
   /* 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_operation.hh b/source/blender/viewport_compositor/VPC_operation.hh
index 5ce181f3a55..ed7a658c2c9 100644
--- a/source/blender/viewport_compositor/VPC_operation.hh
+++ b/source/blender/viewport_compositor/VPC_operation.hh
@@ -72,19 +72,13 @@ class Operation {
    * logic. See the Domain class for the inference logic and more information. */
   virtual Domain compute_domain();
 
-  /* This method is called before the execute method and can be overridden by a derived class to do
-   * any necessary internal computations before the operation is executed. For instance, this is
-   * overridden by node operations to compute results for unlinked sockets. */
-  virtual void pre_execute();
-
   /* First, all the necessary input processors for each input. Then update the result mapped to
    * each input to be that of the last processor for that input if any input processors exist for
    * it. This is done now in a separate step after all processors were added because the operation
    * might use the original mapped results to determine what processors needs to be added. Finally,
    * evaluate all input processors in order. This is called before executing the operation to
-   * prepare its inputs but after the pre_execute method was called. The class defines a default
-   * implementation, but derived class can override the method to have a different
-   * implementation, extend the implementation, or remove it. */
+   * prepare its inputs. The class defines a default implementation, but derived class can override
+   * the method to have a different implementation, extend the implementation, or remove it. */
   virtual void evaluate_input_processors();
 
   /* This method should allocate the operation results, execute the operation, and compute the
diff --git a/source/blender/viewport_compositor/VPC_processor_operation.hh b/source/blender/viewport_compositor/VPC_processor_operation.hh
index 0e14bd8fb6b..3f5ec558655 100644
--- a/source/blender/viewport_compositor/VPC_processor_operation.hh
+++ b/source/blender/viewport_compositor/VPC_processor_operation.hh
@@ -13,11 +13,11 @@ namespace blender::viewport_compositor {
 /* A processor operation is an operation that takes exactly one input and computes exactly one
  * output. */
 class ProcessorOperation : public Operation {
- public:
+ private:
   /* The identifier of the output. This is constant for all operations. */
-  static const StringRef output_identifier;
+  static const StringRef output_identifier_;
   /* The identifier of the input. This is constant for all operations. */
-  static const StringRef input_identifier;
+  static const StringRef input_identifier_;
 
  public:
   using Operation::Operation;
diff --git a/source/blender/viewport_compositor/intern/evaluator.cc b/source/blender/viewport_compositor/intern/evaluator.cc
index a25c81f071c..14d3edc3b18 100644
--- a/source/blender/viewport_compositor/intern/evaluator.cc
+++ b/source/blender/viewport_compositor/intern/evaluator.cc
@@ -9,6 +9,7 @@
 #include "VPC_context.hh"
 #include "VPC_evaluator.hh"
 #include "VPC_gpu_material_operation.hh"
+#include "VPC_input_single_value_operation.hh"
 #include "VPC_node_operation.hh"
 #include "VPC_operation.hh"
 #include "VPC_result.hh"
@@ -86,9 +87,8 @@ void Evaluator::compile_and_evaluate()
 
 void Evaluator::compile_and_evaluate_node(DNode node, CompileState &compile_state)
 {
-  /* Get an instance of the node's compositor operation and add it to the

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list