[Bf-blender-cvs] [b09b5bccf32] cycles-x: Cycles X: Switch PassAccessor to BufferPass

Sergey Sharybin noreply at git.blender.org
Wed Sep 15 19:35:09 CEST 2021


Commit: b09b5bccf3223a1563c1f3212512a828cc265e1f
Author: Sergey Sharybin
Date:   Mon Sep 13 16:59:03 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBb09b5bccf3223a1563c1f3212512a828cc265e1f

Cycles X: Switch PassAccessor to BufferPass

Moving towards pixels access from only Buffers, without access to
the scene graph.

Should be no functional changes.

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

M	intern/cycles/integrator/pass_accessor.cpp
M	intern/cycles/integrator/pass_accessor.h
M	intern/cycles/render/buffers.cpp
M	intern/cycles/render/buffers.h
M	intern/cycles/render/film.cpp
M	intern/cycles/render/film.h
M	intern/cycles/render/session.cpp

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

diff --git a/intern/cycles/integrator/pass_accessor.cpp b/intern/cycles/integrator/pass_accessor.cpp
index d1e0f3c1031..5c91d5651bf 100644
--- a/intern/cycles/integrator/pass_accessor.cpp
+++ b/intern/cycles/integrator/pass_accessor.cpp
@@ -32,14 +32,13 @@ CCL_NAMESPACE_BEGIN
  * Pass input information.
  */
 
-PassAccessor::PassAccessInfo::PassAccessInfo(const Pass &pass,
+PassAccessor::PassAccessInfo::PassAccessInfo(const BufferPass &pass,
                                              const Film &film,
-                                             const Background &background,
-                                             const vector<Pass *> &passes)
-    : type(pass.get_type()),
-      mode(pass.get_mode()),
-      include_albedo(pass.get_include_albedo()),
-      offset(Pass::get_offset(passes, &pass)),
+                                             const Background &background)
+    : type(pass.type),
+      mode(pass.mode),
+      include_albedo(pass.include_albedo),
+      offset(pass.offset),
       use_approximate_shadow_catcher(film.get_use_approximate_shadow_catcher()),
       use_approximate_shadow_catcher_background(use_approximate_shadow_catcher &&
                                                 !background.get_transparent())
diff --git a/intern/cycles/integrator/pass_accessor.h b/intern/cycles/integrator/pass_accessor.h
index ce5b2983c09..0298b0f40d9 100644
--- a/intern/cycles/integrator/pass_accessor.h
+++ b/intern/cycles/integrator/pass_accessor.h
@@ -20,13 +20,13 @@
 #include "util/util_half.h"
 #include "util/util_string.h"
 #include "util/util_types.h"
-#include "util/util_vector.h"
 
 CCL_NAMESPACE_BEGIN
 
 class Background;
 class Film;
 class RenderBuffers;
+class BufferPass;
 class BufferParams;
 struct KernelFilmConvert;
 
@@ -38,10 +38,7 @@ class PassAccessor {
   class PassAccessInfo {
    public:
     PassAccessInfo() = default;
-    PassAccessInfo(const Pass &pass,
-                   const Film &film,
-                   const Background &background,
-                   const vector<Pass *> &passes);
+    PassAccessInfo(const BufferPass &pass, const Film &film, const Background &background);
 
     PassType type = PASS_NONE;
     PassMode mode = PassMode::NOISY;
diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp
index f4bc3896c5c..a6fce4cb3c3 100644
--- a/intern/cycles/render/buffers.cpp
+++ b/intern/cycles/render/buffers.cpp
@@ -145,6 +145,22 @@ const BufferPass *BufferParams::find_pass(PassType type, PassMode mode) const
   return nullptr;
 }
 
+const BufferPass *BufferParams::get_actual_display_pass(const BufferPass *pass) const
+{
+  if (!pass) {
+    return nullptr;
+  }
+
+  if (pass->type == PASS_COMBINED) {
+    const BufferPass *shadow_catcher_matte_pass = find_pass(PASS_SHADOW_CATCHER_MATTE, pass->mode);
+    if (shadow_catcher_matte_pass) {
+      pass = shadow_catcher_matte_pass;
+    }
+  }
+
+  return pass;
+}
+
 void BufferParams::update_offset_stride()
 {
   offset = -(full_x + full_y * width);
diff --git a/intern/cycles/render/buffers.h b/intern/cycles/render/buffers.h
index 6e3f5c84853..2e6f689e5c7 100644
--- a/intern/cycles/render/buffers.h
+++ b/intern/cycles/render/buffers.h
@@ -92,6 +92,10 @@ class BufferParams {
   const BufferPass *find_pass(string_view name) const;
   const BufferPass *find_pass(PassType type, PassMode mode = PassMode::NOISY) const;
 
+  /* Get display pass from its name.
+   * Will do special logic to replace combined pass with shadow catcher matte. */
+  const BufferPass *get_actual_display_pass(const BufferPass *pass) const;
+
   void update_offset_stride();
 
   bool modified(const BufferParams &other) const;
diff --git a/intern/cycles/render/film.cpp b/intern/cycles/render/film.cpp
index 6af8187ce3d..8e14b338bd3 100644
--- a/intern/cycles/render/film.cpp
+++ b/intern/cycles/render/film.cpp
@@ -427,23 +427,6 @@ int Film::get_aov_offset(Scene *scene, string name, bool &is_color)
   return -1;
 }
 
-const Pass *Film::get_actual_display_pass(Scene *scene, const Pass *pass)
-{
-  if (!pass) {
-    return nullptr;
-  }
-
-  if (pass->get_type() == PASS_COMBINED && scene->has_shadow_catcher()) {
-    const Pass *shadow_catcher_matte_pass = Pass::find(
-        scene->passes, PASS_SHADOW_CATCHER_MATTE, pass->get_mode());
-    if (shadow_catcher_matte_pass) {
-      pass = shadow_catcher_matte_pass;
-    }
-  }
-
-  return pass;
-}
-
 void Film::update_passes(Scene *scene, bool add_sample_count_pass)
 {
   const Background *background = scene->background;
diff --git a/intern/cycles/render/film.h b/intern/cycles/render/film.h
index 77b4f6145d2..5d327353361 100644
--- a/intern/cycles/render/film.h
+++ b/intern/cycles/render/film.h
@@ -81,10 +81,6 @@ class Film : public Node {
 
   int get_aov_offset(Scene *scene, string name, bool &is_color);
 
-  /* Get display pass from its name.
-   * Will do special logic to replace combined pass with shadow catcher matte. */
-  const Pass *get_actual_display_pass(Scene *scene, const Pass *pass);
-
   /* Update passes so that they contain all passes required for the configured functionality.
    *
    * If `add_sample_count_pass` is true then the SAMPLE_COUNT pass is ensured to be added. */
diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp
index 98a5e017ab6..6fe7df0a160 100644
--- a/intern/cycles/render/session.cpp
+++ b/intern/cycles/render/session.cpp
@@ -628,27 +628,31 @@ bool Session::copy_render_tile_from_device()
 
 bool Session::get_render_tile_pixels(const string &pass_name, int num_components, float *pixels)
 {
-  const Pass *pass = Pass::find(scene->passes, pass_name);
+  /* NOTE: The code relies on a fact that session is fully update and no scene/buffer modification
+   * is happenning while this function runs. */
+
+  const BufferPass *pass = buffer_params_.find_pass(pass_name);
   if (pass == nullptr) {
     return false;
   }
 
+  /* TODO(sergey): Avoid access to path trace here to allow accessing pixels from render buffers
+   * after the rendering is done (for the "Save Buffers" memory optimization implementation). */
   const bool has_denoised_result = path_trace_->has_denoised_result();
-  if (pass->get_mode() == PassMode::DENOISED && !has_denoised_result) {
-    pass = Pass::find(scene->passes, pass->get_type());
+  if (pass->mode == PassMode::DENOISED && !has_denoised_result) {
+    pass = buffer_params_.find_pass(pass->type);
     if (pass == nullptr) {
       /* Happens when denoised result pass is requested but is never written by the kernel. */
       return false;
     }
   }
 
-  pass = scene->film->get_actual_display_pass(scene, pass);
+  pass = buffer_params_.get_actual_display_pass(pass);
 
   const float exposure = scene->film->get_exposure();
   const int num_samples = path_trace_->get_num_render_tile_samples();
 
-  const PassAccessor::PassAccessInfo pass_access_info(
-      *pass, *scene->film, *scene->background, scene->passes);
+  const PassAccessor::PassAccessInfo pass_access_info(*pass, *scene->film, *scene->background);
   const PassAccessorCPU pass_accessor(pass_access_info, exposure, num_samples);
   const PassAccessor::Destination destination(pixels, num_components);
 
@@ -659,8 +663,10 @@ bool Session::set_render_tile_pixels(const string &pass_name,
                                      int num_components,
                                      const float *pixels)
 {
-  /* TODO(sergey): Do we write to alias? */
-  const Pass *pass = Pass::find(scene->passes, pass_name);
+  /* NOTE: The code relies on a fact that session is fully update and no scene/buffer modification
+   * is happenning while this function runs. */
+
+  const BufferPass *pass = buffer_params_.find_pass(pass_name);
   if (!pass) {
     return false;
   }
@@ -668,8 +674,7 @@ bool Session::set_render_tile_pixels(const string &pass_name,
   const float exposure = scene->film->get_exposure();
   const int num_samples = render_scheduler_.get_num_rendered_samples();
 
-  const PassAccessor::PassAccessInfo pass_access_info(
-      *pass, *scene->film, *scene->background, scene->passes);
+  const PassAccessor::PassAccessInfo pass_access_info(*pass, *scene->film, *scene->background);
   PassAccessorCPU pass_accessor(pass_access_info, exposure, num_samples);
   PassAccessor::Source source(pixels, num_components);



More information about the Bf-blender-cvs mailing list