[Bf-blender-cvs] [5e8fd3dba4e] cycles-x: Cycles X: Refactor pass info and accessor

Sergey Sharybin noreply at git.blender.org
Thu Jun 3 14:37:05 CEST 2021


Commit: 5e8fd3dba4ededd111ac763f78df63005c05b6b4
Author: Sergey Sharybin
Date:   Tue Jun 1 11:22:45 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB5e8fd3dba4ededd111ac763f78df63005c05b6b4

Cycles X: Refactor pass info and accessor

Makes it so pass accessor can be used without knowing passes array and
Film. Additionally, this should restore access to AOV passes, although
is hard to really verify this because AOVs are not written yet.

Differential Revision: https://developer.blender.org/D11448

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

M	intern/cycles/render/pass.cpp
M	intern/cycles/render/pass.h
M	intern/cycles/render/pass_accessor.cpp
M	intern/cycles/render/pass_accessor.h
M	intern/cycles/render/session.cpp

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

diff --git a/intern/cycles/render/pass.cpp b/intern/cycles/render/pass.cpp
index ed296532851..1a9a9c1fbe6 100644
--- a/intern/cycles/render/pass.cpp
+++ b/intern/cycles/render/pass.cpp
@@ -17,6 +17,7 @@
 #include "render/pass.h"
 
 #include "util/util_algorithm.h"
+#include "util/util_logging.h"
 
 CCL_NAMESPACE_BEGIN
 
@@ -84,101 +85,61 @@ Pass::Pass() : Node(get_node_type())
 {
 }
 
-void Pass::add(PassType type, vector<Pass> &passes, const char *name, bool is_auto)
+PassInfo Pass::get_info(PassType type)
 {
-  for (Pass &pass : passes) {
-    if (pass.type != type) {
-      continue;
-    }
-
-    /* An empty name is used as a placeholder to signal that any pass of
-     * that type is fine (because the content always is the same).
-     * This is important to support divide_type: If the pass that has a
-     * divide_type is added first, a pass for divide_type with an empty
-     * name will be added. Then, if a matching pass with a name is later
-     * requested, the existing placeholder will be renamed to that.
-     * If the divide_type is explicitly allocated with a name first and
-     * then again as part of another pass, the second one will just be
-     * skipped because that type already exists. */
+  PassInfo pass_info;
 
-    /* If no name is specified, any pass of the correct type will match. */
-    if (name == NULL) {
-      pass.is_auto &= is_auto;
-      return;
-    }
-
-    /* If we already have a placeholder pass, rename that one. */
-    if (pass.name.empty()) {
-      pass.name = name;
-      pass.is_auto &= is_auto;
-      return;
-    }
-
-    /* If neither existing nor requested pass have placeholder name, they
-     * must match. */
-    if (name == pass.name) {
-      pass.is_auto &= is_auto;
-      return;
-    }
-  }
-
-  Pass pass;
-
-  pass.type = type;
-  pass.filter = true;
-  pass.exposure = false;
-  pass.divide_type = PASS_NONE;
-  if (name) {
-    pass.name = name;
-  }
-  pass.is_auto = is_auto;
-  pass.is_unaligned = false;
+  pass_info.type = type;
+  pass_info.use_filter = true;
+  pass_info.use_exposure = false;
+  pass_info.divide_type = PASS_NONE;
+  pass_info.is_unaligned = false;
 
   switch (type) {
     case PASS_NONE:
-      pass.components = 0;
+      pass_info.num_components = 0;
       break;
     case PASS_COMBINED:
-      pass.components = 4;
-      pass.exposure = true;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = true;
       break;
     case PASS_DEPTH:
-      pass.components = 1;
-      pass.filter = false;
+      pass_info.num_components = 1;
+      pass_info.use_filter = false;
       break;
     case PASS_MIST:
-      pass.components = 1;
+      pass_info.num_components = 1;
       break;
     case PASS_NORMAL:
-      pass.components = 4;
+      pass_info.num_components = 4;
       break;
     case PASS_UV:
-      pass.components = 4;
+      pass_info.num_components = 4;
       break;
     case PASS_MOTION:
-      pass.components = 4;
-      pass.divide_type = PASS_MOTION_WEIGHT;
+      pass_info.num_components = 4;
+      pass_info.divide_type = PASS_MOTION_WEIGHT;
       break;
     case PASS_MOTION_WEIGHT:
-      pass.components = 1;
+      pass_info.num_components = 1;
       break;
     case PASS_OBJECT_ID:
     case PASS_MATERIAL_ID:
-      pass.components = 1;
-      pass.filter = false;
+      pass_info.num_components = 1;
+      pass_info.use_filter = false;
       break;
 
     case PASS_EMISSION:
     case PASS_BACKGROUND:
-      pass.components = 4;
-      pass.exposure = true;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = true;
       break;
     case PASS_AO:
-      pass.components = 4;
+      pass_info.num_components = 4;
       break;
     case PASS_SHADOW:
-      pass.components = 4;
-      pass.exposure = false;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = false;
       break;
     case PASS_LIGHT:
       /* This isn't a real pass, used by baking to see whether
@@ -187,96 +148,155 @@ void Pass::add(PassType type, vector<Pass> &passes, const char *name, bool is_au
        * Set components to 0 so pass sort below happens in a
        * determined way.
        */
-      pass.components = 0;
+      pass_info.num_components = 0;
       break;
     case PASS_RENDER_TIME:
       /* This pass is handled entirely on the host side. */
-      pass.components = 0;
+      pass_info.num_components = 0;
       break;
 
     case PASS_DIFFUSE_COLOR:
     case PASS_GLOSSY_COLOR:
     case PASS_TRANSMISSION_COLOR:
-      pass.components = 4;
+      pass_info.num_components = 4;
       break;
     case PASS_DIFFUSE_DIRECT:
     case PASS_DIFFUSE_INDIRECT:
-      pass.components = 4;
-      pass.exposure = true;
-      pass.divide_type = PASS_DIFFUSE_COLOR;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = true;
+      pass_info.divide_type = PASS_DIFFUSE_COLOR;
       break;
     case PASS_GLOSSY_DIRECT:
     case PASS_GLOSSY_INDIRECT:
-      pass.components = 4;
-      pass.exposure = true;
-      pass.divide_type = PASS_GLOSSY_COLOR;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = true;
+      pass_info.divide_type = PASS_GLOSSY_COLOR;
       break;
     case PASS_TRANSMISSION_DIRECT:
     case PASS_TRANSMISSION_INDIRECT:
-      pass.components = 4;
-      pass.exposure = true;
-      pass.divide_type = PASS_TRANSMISSION_COLOR;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = true;
+      pass_info.divide_type = PASS_TRANSMISSION_COLOR;
       break;
     case PASS_VOLUME_DIRECT:
     case PASS_VOLUME_INDIRECT:
-      pass.components = 4;
-      pass.exposure = true;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = true;
       break;
 
     case PASS_CRYPTOMATTE:
-      pass.components = 4;
+      pass_info.num_components = 4;
       break;
 
     case PASS_DENOISING_COLOR:
-      pass.components = 3;
-      pass.exposure = true;
-      pass.is_unaligned = true;
+      pass_info.num_components = 3;
+      pass_info.use_exposure = true;
+      pass_info.is_unaligned = true;
       break;
     case PASS_DENOISING_NORMAL:
-      pass.components = 3;
-      pass.is_unaligned = true;
+      pass_info.num_components = 3;
+      pass_info.is_unaligned = true;
       break;
     case PASS_DENOISING_ALBEDO:
-      pass.components = 3;
-      pass.is_unaligned = true;
+      pass_info.num_components = 3;
+      pass_info.is_unaligned = true;
       break;
 
     case PASS_SHADOW_CATCHER:
-      pass.components = 4;
-      pass.exposure = true;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = true;
       break;
     case PASS_SHADOW_CATCHER_MATTE:
-      pass.components = 4;
-      pass.exposure = true;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = true;
       break;
 
     case PASS_ADAPTIVE_AUX_BUFFER:
-      pass.components = 4;
+      pass_info.num_components = 4;
       break;
     case PASS_SAMPLE_COUNT:
-      pass.components = 1;
-      pass.exposure = false;
+      pass_info.num_components = 1;
+      pass_info.use_exposure = false;
       break;
 
     case PASS_AOV_COLOR:
-      pass.components = 4;
+      pass_info.num_components = 4;
       break;
     case PASS_AOV_VALUE:
-      pass.components = 1;
+      pass_info.num_components = 1;
       break;
 
     case PASS_BAKE_PRIMITIVE:
     case PASS_BAKE_DIFFERENTIAL:
-      pass.components = 4;
-      pass.exposure = false;
-      pass.filter = false;
+      pass_info.num_components = 4;
+      pass_info.use_exposure = false;
+      pass_info.use_filter = false;
       break;
 
-    default:
-      assert(false);
+    case PASS_CATEGORY_LIGHT_END:
+    case PASS_CATEGORY_DATA_END:
+    case PASS_CATEGORY_BAKE_END:
+    case PASS_NUM:
+      LOG(DFATAL) << "Unexpected pass type is used " << type;
+      pass_info.num_components = 0;
       break;
   }
 
+  return pass_info;
+}
+
+void Pass::add(PassType type, vector<Pass> &passes, const char *name, bool is_auto)
+{
+  for (Pass &pass : passes) {
+    if (pass.type != type) {
+      continue;
+    }
+
+    /* An empty name is used as a placeholder to signal that any pass of
+     * that type is fine (because the content always is the same).
+     * This is important to support divide_type: If the pass that has a
+     * divide_type is added first, a pass for divide_type with an empty
+     * name will be added. Then, if a matching pass with a name is later
+     * requested, the existing placeholder will be renamed to that.
+     * If the divide_type is explicitly allocated with a name first and
+     * then again as part of another pass, the second one will just be
+     * skipped because that type already exists. */
+
+    /* If no name is specified, any pass of the correct type will match. */
+    if (name == NULL) {
+      pass.is_auto &= is_auto;
+      return;
+    }
+
+    /* If we already have a placeholder pass, rename that one. */
+    if (pass.name.empty()) {
+      pass.name = name;
+      pass.is_auto &= is_auto;
+      return;
+    }
+
+    /* If neither existing nor requested pass have placeholder name, they
+     * must match. */
+    if (name == pass.name) {
+      pass.is_auto &= is_auto;
+      return;
+    }
+  }
+
+  const PassInfo pass_info = get_info(type);
+
+  Pass pass;
+  pass.type = type;
+  pass.components = pass_info.num_components;
+  pass.filter = pass_info.use_filter;
+  pass.exposure = pass_info.use_exposure;
+  pass.divide_type = pass_info.divide_type;
+  pass.is_auto = is_auto;
+
+  if (name) {
+    pass.name = name;
+  }
+
   passes.push_back(pass);
 
   /* Order from by components, to ensure alignment so passes with size 4
@@ -426,4 +446,18 @@ int Pass::get_offset(const vector<Pass> &passes, PassType type)
   return PASS_UNUSED;
 }
 
+int Pass::get_offset(const vector<Pass> &passes, const Pass &pass)
+{
+  int pass_offset = 0;
+
+  for (const Pass &current_pass : passes) {
+    if (current_pass.type == pass.type && current_pass.name == pass.name) {
+      return pass_offset;
+    }
+    pass_offset += current_pass.components;
+  }
+
+  return PASS_UNUSED;
+}
+
 CCL_NAMESPACE_END
diff --git a/intern/cycles/render/pass.h b/intern/cycles/render/pass.h
i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list