[Bf-blender-cvs] [ae61e816c6a] cycles-x: Cycles X: Keep track of passes list in BufferParams

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


Commit: ae61e816c6a8d12058b63c83c4c228875f22b7ab
Author: Sergey Sharybin
Date:   Mon Sep 13 16:08:55 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBae61e816c6a8d12058b63c83c4c228875f22b7ab

Cycles X: Keep track of passes list in BufferParams

Currently should no functional changes.

The goal is to completely decouple BufferParams from Scene graph for
pass accessing.

This is needed for the on-disk tiled storage when EXR is to be read
from disk after the session got freed. Also, will make animation
denoising easier to implement.

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

M	intern/cycles/render/buffers.cpp
M	intern/cycles/render/buffers.h

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

diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp
index 9d9f205b11b..f4bc3896c5c 100644
--- a/intern/cycles/render/buffers.cpp
+++ b/intern/cycles/render/buffers.cpp
@@ -28,7 +28,9 @@
 
 CCL_NAMESPACE_BEGIN
 
-/* Convert part information to an index of `BufferParams::pass_offset_`. */
+/* --------------------------------------------------------------------
+ * Convert part information to an index of `BufferParams::pass_offset_`.
+ */
 
 static int pass_type_mode_to_index(PassType pass_type, PassMode mode)
 {
@@ -41,12 +43,26 @@ static int pass_type_mode_to_index(PassType pass_type, PassMode mode)
   return index;
 }
 
-static int pass_to_index(const Pass *pass)
+static int scene_pass_to_index(const Pass *pass)
 {
   return pass_type_mode_to_index(pass->get_type(), pass->get_mode());
 }
 
-/* Buffer Params */
+/* --------------------------------------------------------------------
+ * Buffer pass.
+ */
+
+BufferPass::BufferPass(const Pass *scene_pass)
+    : type(scene_pass->get_type()),
+      mode(scene_pass->get_mode()),
+      name(scene_pass->get_name()),
+      include_albedo(scene_pass->get_include_albedo())
+{
+}
+
+/* --------------------------------------------------------------------
+ * Buffer Params.
+ */
 
 BufferParams::BufferParams()
 {
@@ -61,22 +77,32 @@ BufferParams::BufferParams()
   reset_pass_offset();
 }
 
-void BufferParams::update_passes(const vector<Pass *> &passes)
+void BufferParams::update_passes(const vector<Pass *> &scene_passes)
 {
   update_offset_stride();
   reset_pass_offset();
 
+  passes.clear();
+
   pass_stride = 0;
-  for (const Pass *pass : passes) {
-    const int index = pass_to_index(pass);
+  for (const Pass *scene_pass : scene_passes) {
+    BufferPass buffer_pass(scene_pass);
+
+    if (scene_pass->is_written()) {
+      buffer_pass.offset = pass_stride;
 
-    if (pass->is_written()) {
+      const int index = scene_pass_to_index(scene_pass);
       if (pass_offset_[index] == PASS_UNUSED) {
         pass_offset_[index] = pass_stride;
       }
 
-      pass_stride += pass->get_info().num_components;
+      pass_stride += scene_pass->get_info().num_components;
     }
+    else {
+      buffer_pass.offset = PASS_UNUSED;
+    }
+
+    passes.emplace_back(std::move(buffer_pass));
   }
 }
 
@@ -97,6 +123,28 @@ int BufferParams::get_pass_offset(PassType pass_type, PassMode mode) const
   return pass_offset_[index];
 }
 
+const BufferPass *BufferParams::find_pass(string_view name) const
+{
+  for (const BufferPass &pass : passes) {
+    if (pass.name == name) {
+      return &pass;
+    }
+  }
+
+  return nullptr;
+}
+
+const BufferPass *BufferParams::find_pass(PassType type, PassMode mode) const
+{
+  for (const BufferPass &pass : passes) {
+    if (pass.type == type && pass.mode == mode) {
+      return &pass;
+    }
+  }
+
+  return nullptr;
+}
+
 void BufferParams::update_offset_stride()
 {
   offset = -(full_x + full_y * width);
@@ -112,10 +160,12 @@ bool BufferParams::modified(const BufferParams &other) const
     return true;
   }
 
-  return memcmp(pass_offset_, other.pass_offset_, sizeof(pass_offset_)) != 0;
+  return passes != other.passes;
 }
 
-/* Render Buffers */
+/* --------------------------------------------------------------------
+ * Render Buffers.
+ */
 
 RenderBuffers::RenderBuffers(Device *device) : buffer(device, "RenderBuffers", MEM_READ_WRITE)
 {
diff --git a/intern/cycles/render/buffers.h b/intern/cycles/render/buffers.h
index b3e8bcdbd81..6e3f5c84853 100644
--- a/intern/cycles/render/buffers.h
+++ b/intern/cycles/render/buffers.h
@@ -19,7 +19,7 @@
 
 #include "device/device_memory.h"
 
-#include "render/film.h"
+#include "render/pass.h"
 
 #include "kernel/kernel_types.h"
 
@@ -34,6 +34,28 @@ class Device;
 struct DeviceDrawParams;
 struct float4;
 
+class BufferPass {
+ public:
+  PassType type = PASS_NONE;
+  PassMode mode = PassMode::NOISY;
+  ustring name;
+  bool include_albedo = false;
+
+  int offset = -1;
+
+  explicit BufferPass(const Pass *scene_pass);
+
+  inline bool operator==(const BufferPass &other) const
+  {
+    return type == other.type && mode == other.mode && name == other.name &&
+           include_albedo == other.include_albedo && offset == other.offset;
+  }
+  inline bool operator!=(const BufferPass &other) const
+  {
+    return !(*this == other);
+  }
+};
+
 /* Buffer Parameters
  * Size of render buffer and how it fits in the full image (border render). */
 
@@ -55,15 +77,21 @@ class BufferParams {
   /* Runtime fields, only valid after `update_passes()`. */
   int pass_stride = -1;
 
+  vector<BufferPass> passes;
+
   /* functions */
   BufferParams();
 
-  /* Pre-calculate all fields which depends on the passes. */
-  void update_passes(const vector<Pass *> &passes);
+  /* Pre-calculate all fields which depends on the scene passes. */
+  void update_passes(const vector<Pass *> &scene_passes);
 
   /* Returns PASS_UNUSED if there is no such pass in the buffer. */
   int get_pass_offset(PassType type, PassMode mode = PassMode::NOISY) const;
 
+  /* Returns nullptr if pass with given name does not exist. */
+  const BufferPass *find_pass(string_view name) const;
+  const BufferPass *find_pass(PassType type, PassMode mode = PassMode::NOISY) const;
+
   void update_offset_stride();
 
   bool modified(const BufferParams &other) const;
@@ -74,7 +102,9 @@ class BufferParams {
   /* Multipled by 2 to be able to store noisy and denoised pass types. */
   static constexpr int kNumPassOffsets = PASS_NUM * 2;
 
-  /* Indexed by pass type, indicates offset of the corresponding pass in the buffer. */
+  /* Indexed by an index derived from pass type and mode, indicates offset of the corresponding
+   * pass in the buffer.
+   * If there are multiple passes with same type and mode contains lowest offset of all of them. */
   int pass_offset_[kNumPassOffsets];
 };



More information about the Bf-blender-cvs mailing list