[Bf-blender-cvs] [7b19d30441d] cycles-x: Cycles X: Move Pass to its own file

Sergey Sharybin noreply at git.blender.org
Wed May 19 10:19:00 CEST 2021


Commit: 7b19d30441dab28e08eb6bb3de943cd6bbf4d5a6
Author: Sergey Sharybin
Date:   Fri May 14 10:49:36 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB7b19d30441dab28e08eb6bb3de943cd6bbf4d5a6

Cycles X: Move Pass to its own file

While doing so found that the pass type enum could have double amount
of entries: items are added when initializing pass node and when
setting up film's display pass enum.

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

M	intern/cycles/render/CMakeLists.txt
M	intern/cycles/render/film.cpp
M	intern/cycles/render/film.h
A	intern/cycles/render/pass.cpp
A	intern/cycles/render/pass.h
M	intern/cycles/render/pass_accessor.h

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

diff --git a/intern/cycles/render/CMakeLists.txt b/intern/cycles/render/CMakeLists.txt
index bd34eb8d469..e1713161fcb 100644
--- a/intern/cycles/render/CMakeLists.txt
+++ b/intern/cycles/render/CMakeLists.txt
@@ -55,6 +55,7 @@ set(SRC
   object.cpp
   osl.cpp
   particles.cpp
+  pass.cpp
   pass_accessor.cpp
   curves.cpp
   scene.cpp
@@ -98,6 +99,7 @@ set(SRC_HEADERS
   object.h
   osl.h
   particles.h
+  pass.h
   pass_accessor.h
   procedural.h
   curves.h
diff --git a/intern/cycles/render/film.cpp b/intern/cycles/render/film.cpp
index 0e760151ea7..349952a7df6 100644
--- a/intern/cycles/render/film.cpp
+++ b/intern/cycles/render/film.cpp
@@ -31,390 +31,6 @@
 
 CCL_NAMESPACE_BEGIN
 
-/* Pass */
-
-static bool compare_pass_order(const Pass &a, const Pass &b)
-{
-  if (a.components == b.components)
-    return (a.type < b.type);
-  return (a.components > b.components);
-}
-
-static NodeEnum *get_pass_type_enum()
-{
-  static NodeEnum pass_type_enum;
-  pass_type_enum.insert("combined", PASS_COMBINED);
-  pass_type_enum.insert("depth", PASS_DEPTH);
-  pass_type_enum.insert("normal", PASS_NORMAL);
-  pass_type_enum.insert("uv", PASS_UV);
-  pass_type_enum.insert("object_id", PASS_OBJECT_ID);
-  pass_type_enum.insert("material_id", PASS_MATERIAL_ID);
-  pass_type_enum.insert("motion", PASS_MOTION);
-  pass_type_enum.insert("motion_weight", PASS_MOTION_WEIGHT);
-#ifdef __KERNEL_DEBUG__
-  pass_type_enum.insert("traversed_nodes", PASS_BVH_TRAVERSED_NODES);
-  pass_type_enum.insert("traverse_instances", PASS_BVH_TRAVERSED_INSTANCES);
-  pass_type_enum.insert("bvh_intersections", PASS_BVH_INTERSECTIONS);
-  pass_type_enum.insert("ray_bounces", PASS_RAY_BOUNCES);
-#endif
-  pass_type_enum.insert("render_time", PASS_RENDER_TIME);
-  pass_type_enum.insert("cryptomatte", PASS_CRYPTOMATTE);
-  pass_type_enum.insert("aov_color", PASS_AOV_COLOR);
-  pass_type_enum.insert("aov_value", PASS_AOV_VALUE);
-  pass_type_enum.insert("adaptive_aux_buffer", PASS_ADAPTIVE_AUX_BUFFER);
-  pass_type_enum.insert("sample_count", PASS_SAMPLE_COUNT);
-  pass_type_enum.insert("mist", PASS_MIST);
-  pass_type_enum.insert("emission", PASS_EMISSION);
-  pass_type_enum.insert("background", PASS_BACKGROUND);
-  pass_type_enum.insert("ambient_occlusion", PASS_AO);
-  pass_type_enum.insert("shadow", PASS_SHADOW);
-  pass_type_enum.insert("diffuse_direct", PASS_DIFFUSE_DIRECT);
-  pass_type_enum.insert("diffuse_indirect", PASS_DIFFUSE_INDIRECT);
-  pass_type_enum.insert("diffuse_color", PASS_DIFFUSE_COLOR);
-  pass_type_enum.insert("glossy_direct", PASS_GLOSSY_DIRECT);
-  pass_type_enum.insert("glossy_indirect", PASS_GLOSSY_INDIRECT);
-  pass_type_enum.insert("glossy_color", PASS_GLOSSY_COLOR);
-  pass_type_enum.insert("transmission_direct", PASS_TRANSMISSION_DIRECT);
-  pass_type_enum.insert("transmission_indirect", PASS_TRANSMISSION_INDIRECT);
-  pass_type_enum.insert("transmission_color", PASS_TRANSMISSION_COLOR);
-  pass_type_enum.insert("volume_direct", PASS_VOLUME_DIRECT);
-  pass_type_enum.insert("volume_indirect", PASS_VOLUME_INDIRECT);
-  pass_type_enum.insert("bake_primitive", PASS_BAKE_PRIMITIVE);
-  pass_type_enum.insert("bake_differential", PASS_BAKE_DIFFERENTIAL);
-
-  return &pass_type_enum;
-}
-
-NODE_DEFINE(Pass)
-{
-  NodeType *type = NodeType::add("pass", create);
-
-  NodeEnum *pass_type_enum = get_pass_type_enum();
-  SOCKET_ENUM(type, "Type", *pass_type_enum, PASS_COMBINED);
-  SOCKET_STRING(name, "Name", ustring());
-
-  return type;
-}
-
-Pass::Pass() : Node(get_node_type())
-{
-}
-
-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;
-    }
-  }
-
-  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;
-
-  switch (type) {
-    case PASS_NONE:
-      pass.components = 0;
-      break;
-    case PASS_COMBINED:
-      pass.components = 4;
-      pass.exposure = true;
-      break;
-    case PASS_DEPTH:
-      pass.components = 1;
-      pass.filter = false;
-      break;
-    case PASS_MIST:
-      pass.components = 1;
-      break;
-    case PASS_NORMAL:
-      pass.components = 4;
-      break;
-    case PASS_UV:
-      pass.components = 4;
-      break;
-    case PASS_MOTION:
-      pass.components = 4;
-      pass.divide_type = PASS_MOTION_WEIGHT;
-      break;
-    case PASS_MOTION_WEIGHT:
-      pass.components = 1;
-      break;
-    case PASS_OBJECT_ID:
-    case PASS_MATERIAL_ID:
-      pass.components = 1;
-      pass.filter = false;
-      break;
-
-    case PASS_EMISSION:
-    case PASS_BACKGROUND:
-      pass.components = 4;
-      pass.exposure = true;
-      break;
-    case PASS_AO:
-      pass.components = 4;
-      break;
-    case PASS_SHADOW:
-      pass.components = 4;
-      pass.exposure = false;
-      break;
-    case PASS_LIGHT:
-      /* This isn't a real pass, used by baking to see whether
-       * light data is needed or not.
-       *
-       * Set components to 0 so pass sort below happens in a
-       * determined way.
-       */
-      pass.components = 0;
-      break;
-#ifdef WITH_CYCLES_DEBUG
-    case PASS_BVH_TRAVERSED_NODES:
-    case PASS_BVH_TRAVERSED_INSTANCES:
-    case PASS_BVH_INTERSECTIONS:
-    case PASS_RAY_BOUNCES:
-      pass.components = 1;
-      pass.exposure = false;
-      break;
-#endif
-    case PASS_RENDER_TIME:
-      /* This pass is handled entirely on the host side. */
-      pass.components = 0;
-      break;
-
-    case PASS_DIFFUSE_COLOR:
-    case PASS_GLOSSY_COLOR:
-    case PASS_TRANSMISSION_COLOR:
-      pass.components = 4;
-      break;
-    case PASS_DIFFUSE_DIRECT:
-    case PASS_DIFFUSE_INDIRECT:
-      pass.components = 4;
-      pass.exposure = true;
-      pass.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;
-      break;
-    case PASS_TRANSMISSION_DIRECT:
-    case PASS_TRANSMISSION_INDIRECT:
-      pass.components = 4;
-      pass.exposure = true;
-      pass.divide_type = PASS_TRANSMISSION_COLOR;
-      break;
-    case PASS_VOLUME_DIRECT:
-    case PASS_VOLUME_INDIRECT:
-      pass.components = 4;
-      pass.exposure = true;
-      break;
-
-    case PASS_CRYPTOMATTE:
-      pass.components = 4;
-      break;
-
-    case PASS_DENOISING_COLOR:
-      pass.components = 3;
-      pass.exposure = true;
-      pass.is_unaligned = true;
-      break;
-    case PASS_DENOISING_NORMAL:
-      pass.components = 3;
-      pass.is_unaligned = true;
-      break;
-    case PASS_DENOISING_ALBEDO:
-      pass.components = 3;
-      pass.is_unaligned = true;
-      break;
-
-    case PASS_SHADOW_CATCHER:
-      pass.components = 4;
-      pass.exposure = true;
-      break;
-    case PASS_SHADOW_CATCHER_MATTE:
-      pass.components = 4;
-      pass.exposure = true;
-      break;
-
-    case PASS_ADAPTIVE_AUX_BUFFER:
-      pass.components = 4;
-      break;
-    case PASS_SAMPLE_COUNT:
-      pass.components = 1;
-      pass.exposure = false;
-      break;
-
-    case PASS_AOV_COLOR:
-      pass.components = 4;
-      break;
-    case PASS_AOV_VALUE:
-      pass.components = 1;
-      break;
-
-    case PASS_BAKE_PRIMITIVE:
-    case PASS_BAKE_DIFFERENTIAL:
-      pass.components = 4;
-      pass.exposure = false;
-      pass.filter = false;
-      break;
-
-    default:
-      assert(false);
-      break;
-  }
-
-  passes.push_back(pass);
-
-  /* Order from by components, to ensure alignment so passes with size 4
-   * come first and then passes with size 1. Note this must use stable sort
-   * so cryptomatte passes remain in the right order. */
-  stable_sort(&passes[0], &passes[0] + passes.size(), compare_pass_order);
-
-  if (pass.divide_type != PASS_NONE) {
-    Pass::add(pass.divide_type, passes, nullptr, is_auto);
-  }
-}
-
-bool Pass::equals_exact(const vector<Pass> &A, const vector<Pass> &B)
-{
-  if (A.size() != B.size())
-    return false;
-
-  for (int i = 0; i < A.size(); i++)
-    if (A[i].type != B[i].type || A[i].name != B[i].name)
-      return false;
-
-  return true;
-}
-
-/* Get first index which is greater than the given one which correspongs to a non-auto pass.
- * If there are only runtime passes after the given index, -1 is returned. */
-static const int get_next_no_auto_pass_index(const vector<Pass> &passes, int index)
-{
-  ++index;
-
-  while (index < passes.size()) {
-    if (!passes[index].is_auto) {
-      return index;
-    }
-  }
-
-  return -1;
-}
-
-bool Pass::equals_no_auto(const vector<Pass> &A, const vector<Pass> &B)
-{
-  int index_a = -1, index_b = -1;
-
-  while (true) {
-    index_a = get_next_no_auto_pass_index(A, index_a);
-    index_b = get_next_no_auto_pass_index(A, index_b);
-
-    if (index_a == -1 && index_b == -1) {
-      break;
-    }
-
-    if (index_a == -1 || index_b == -1) {
-    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list