[Bf-blender-cvs] [e9ce424492b] temp-viewport-compositor-merge: Viewport Compositor: Fix and refactor reference counting

Omar Emara noreply at git.blender.org
Fri May 6 10:14:52 CEST 2022


Commit: e9ce424492b0c09cfe203457a3dc70e4bcd8961b
Author: Omar Emara
Date:   Fri May 6 10:12:41 2022 +0200
Branches: temp-viewport-compositor-merge
https://developer.blender.org/rBe9ce424492b0c09cfe203457a3dc70e4bcd8961b

Viewport Compositor: Fix and refactor reference counting

After using eager evaluation and retaining results, reference counting
no longer worked. This patch refactors the reference counting system to
make it work again.

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

M	source/blender/nodes/composite/nodes/node_composite_image.cc
M	source/blender/nodes/composite/nodes/node_composite_movieclip.cc
M	source/blender/viewport_compositor/VPC_compile_state.hh
M	source/blender/viewport_compositor/VPC_gpu_material_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/VPC_result.hh
M	source/blender/viewport_compositor/VPC_utilities.hh
M	source/blender/viewport_compositor/intern/compile_state.cc
M	source/blender/viewport_compositor/intern/evaluator.cc
M	source/blender/viewport_compositor/intern/gpu_material_operation.cc
M	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
M	source/blender/viewport_compositor/intern/result.cc
M	source/blender/viewport_compositor/intern/unsupported_node_operation.cc
M	source/blender/viewport_compositor/intern/utilities.cc

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

diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc
index 7d358cc9096..ce38dfe25ad 100644
--- a/source/blender/nodes/composite/nodes/node_composite_image.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_image.cc
@@ -490,7 +490,7 @@ class ImageOperation : public NodeOperation {
   void allocate_invalid()
   {
     for (const OutputSocketRef *output : node()->outputs()) {
-      if (!is_output_needed(output->identifier())) {
+      if (!should_compute_output(output->identifier())) {
         continue;
       }
 
@@ -508,7 +508,7 @@ class ImageOperation : public NodeOperation {
 
   void compute_output(StringRef identifier)
   {
-    if (!is_output_needed(identifier)) {
+    if (!should_compute_output(identifier)) {
       return;
     }
 
diff --git a/source/blender/nodes/composite/nodes/node_composite_movieclip.cc b/source/blender/nodes/composite/nodes/node_composite_movieclip.cc
index eb171f5829c..b31a7e49b8e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_movieclip.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_movieclip.cc
@@ -108,7 +108,7 @@ class MovieClipOperation : public NodeOperation {
 
   void compute_image(GPUTexture *movie_clip_texture)
   {
-    if (!is_output_needed("Image")) {
+    if (!should_compute_output("Image")) {
       return;
     }
 
@@ -141,7 +141,7 @@ class MovieClipOperation : public NodeOperation {
 
   void compute_alpha(GPUTexture *movie_clip_texture)
   {
-    if (!is_output_needed("Alpha")) {
+    if (!should_compute_output("Alpha")) {
       return;
     }
 
@@ -177,22 +177,22 @@ class MovieClipOperation : public NodeOperation {
   {
     /* The movie clip texture is invalid or missing, set appropriate fallback values. */
     if (!movie_clip_texture) {
-      if (is_output_needed("Offset X")) {
+      if (should_compute_output("Offset X")) {
         Result &result = get_result("Offset X");
         result.allocate_single_value();
         result.set_float_value(0.0f);
       }
-      if (is_output_needed("Offset Y")) {
+      if (should_compute_output("Offset Y")) {
         Result &result = get_result("Offset Y");
         result.allocate_single_value();
         result.set_float_value(0.0f);
       }
-      if (is_output_needed("Scale")) {
+      if (should_compute_output("Scale")) {
         Result &result = get_result("Scale");
         result.allocate_single_value();
         result.set_float_value(1.0f);
       }
-      if (is_output_needed("Angle")) {
+      if (should_compute_output("Angle")) {
         Result &result = get_result("Angle");
         result.allocate_single_value();
         result.set_float_value(0.0f);
@@ -213,22 +213,22 @@ class MovieClipOperation : public NodeOperation {
     BKE_tracking_stabilization_data_get(
         movie_clip, frame_number, width, height, offset, &scale, &angle);
 
-    if (is_output_needed("Offset X")) {
+    if (should_compute_output("Offset X")) {
       Result &result = get_result("Offset X");
       result.allocate_single_value();
       result.set_float_value(offset.x);
     }
-    if (is_output_needed("Offset Y")) {
+    if (should_compute_output("Offset Y")) {
       Result &result = get_result("Offset Y");
       result.allocate_single_value();
       result.set_float_value(offset.y);
     }
-    if (is_output_needed("Scale")) {
+    if (should_compute_output("Scale")) {
       Result &result = get_result("Scale");
       result.allocate_single_value();
       result.set_float_value(scale);
     }
-    if (is_output_needed("Angle")) {
+    if (should_compute_output("Angle")) {
       Result &result = get_result("Angle");
       result.allocate_single_value();
       result.set_float_value(angle);
diff --git a/source/blender/viewport_compositor/VPC_compile_state.hh b/source/blender/viewport_compositor/VPC_compile_state.hh
index b5ad0a6710e..25bcb01e0f8 100644
--- a/source/blender/viewport_compositor/VPC_compile_state.hh
+++ b/source/blender/viewport_compositor/VPC_compile_state.hh
@@ -9,6 +9,7 @@
 #include "VPC_domain.hh"
 #include "VPC_gpu_material_operation.hh"
 #include "VPC_node_operation.hh"
+#include "VPC_scheduler.hh"
 
 namespace blender::viewport_compositor {
 
@@ -96,19 +97,15 @@ using namespace nodes::derived_node_tree_types;
  * the domain of the compile group is assumed to be the domain of the first node whose computed
  * domain is not an identity domain. Identity domains corresponds to single value results, so those
  * are always compatible with any domain. The domain of the compile group is computed and set in
- * the add_node_to_gpu_material_compile_group method. WHen processing a node, the computed domain
+ * the add_node_to_gpu_material_compile_group method. When processing a node, the computed domain
  * of node is compared to compile group domain in the should_compile_gpu_material_compile_group
  * method, noting that identity domains are always compatible. Node domains are computed in the
  * compute_gpu_material_node_domain method, which is analogous to Operation::compute_domain for
  * nodes that are not yet compiled. */
 class CompileState {
  private:
-  /* A contiguous subset of the node execution schedule that contains the group of nodes that will
-   * be compiled together into a GPU Material Operation. See the discussion in VPC_evaluator.hh for
-   * more information. */
-  SubSchedule gpu_material_compile_group_;
-  /* The domain of the GPU material compile group. */
-  Domain gpu_material_compile_group_domain_ = Domain::identity();
+  /* A reference to the node execution schedule that is being compiled. */
+  const Schedule &schedule_;
   /* Those two maps associate each node with the operation it was compiled into. Each node is
    * either compiled into a node operation and added to node_operations, or compiled into a GPU
    * material operation and added to gpu_material_operations. Those maps are used to retrieve the
@@ -116,8 +113,32 @@ class CompileState {
    * method for more information. */
   Map<DNode, NodeOperation *> node_operations_;
   Map<DNode, GPUMaterialOperation *> gpu_material_operations_;
+  /* A contiguous subset of the node execution schedule that contains the group of nodes that will
+   * be compiled together into a GPU Material Operation. See the discussion in VPC_evaluator.hh for
+   * more information. */
+  SubSchedule gpu_material_compile_group_;
+  /* The domain of the GPU material compile group. */
+  Domain gpu_material_compile_group_domain_ = Domain::identity();
 
  public:
+  /* Construct a compile state from the node execution schedule being compiled. */
+  CompileState(const Schedule &schedule);
+
+  /* Get a reference to the node execution schedule being compiled. */
+  const Schedule &get_schedule();
+
+  /* Add an association between the given node and the give node operation that the node was
+   * compiled into in the node_operations_ map. */
+  void map_node_to_node_operation(DNode node, NodeOperation *operation);
+
+  /* Add an association between the given node and the give GPU material operation that the node
+   * was compiled into in the gpu_material_operations_ map. */
+  void map_node_to_gpu_material_operation(DNode node, GPUMaterialOperation *operation);
+
+  /* Returns a reference to the result of the operation corresponding to the given output that the
+   * given output's node was compiled to. */
+  Result &get_result_from_output_socket(DOutputSocket output);
+
   /* Add the given node to the GPU material compile group. And if the domain of the GPU material
    * compile group is not yet determined or was determined to be an identity domain, update it to
    * the computed domain for the give node. */
@@ -140,18 +161,6 @@ class CompileState {
    *   be compiled. */
   bool should_compile_gpu_material_compile_group(DNode node);
 
-  /* Add an association between the given node and the give node operation that the node was
-   * compiled into in the node_operations_ map. */
-  void map_node_to_node_operation(DNode node, NodeOperation *operation);
-
-  /* Add an association between the given node and the give GPU material operation that the node
-   * was compiled into in the gpu_material_operations_ map. */
-  void map_node_to_gpu_material_operation(DNode node, GPUMaterialOperation *operation);
-
-  /* Returns a reference to the result of the operation corresponding to the given output that the
-   * given output's node was compiled to. */
-  Result &get_result_from_output_socket(DOutputSocket output);
-
  private:
   /* Compute the node domain of the given GPU material node. This is analogous to the
    * Operation::compute_domain method, except it is computed from the node itself as opposed to a
diff --git a/source/blender/viewport_compositor/VPC_gpu_material_operation.hh b/source/blender/viewport_compositor/VPC_gpu_material_operation.hh
index 58dc6899bb4..fc3404a444b 100644
--- a/source/blender/viewport_compositor/VPC_gpu_material_operation.hh
+++ b/source/blender/viewport_compositor/VPC_gpu_material_operation.hh
@@ -15,6 +15,7 @@
 
 #include "VPC_context.hh"
 #include "VPC_operation.hh"
+#include "VPC_scheduler.hh"
 
 namespace blender::viewport_compositor {
 
@@ -25,6 +26,9 @@ using SubSchedule = VectorSet<DNode>;
 /* A type representing a map that associates the identifier of each input of the operation with the
  * output socket it is linked to. */
 using InputsToLinkedOutputsMap = Map<StringRef, DOutputSocket>;
+/* A type representing a map that associates the output socket that provides the result of an
+ * output of the operation with the identifier of that output. */
+using OutputSocketsToOutputIdentifiersMap = Map<DOutputSocket, StringRef>;
 
 /* ------------------------------------------------------------------------------------------------
  * GPU Material Operation
@@ -102,7 +106,7 @@ class GPUMaterialOperation : public Operation {
   InputsToLinkedOutputsMap inputs_to_linked_outputs_map_;
   /* A map that associates the output socket that provides the result of an output of the operation
    * with the identifier of that output. See the above discussion for more information. */
-  Map<DOutputSocket, StringRef> output_sockets_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list