[Bf-blender-cvs] [eca2a419648] master: Cycles: Improve volume stack size calculation

Sergey Sharybin noreply at git.blender.org
Mon Oct 11 14:01:49 CEST 2021


Commit: eca2a419648a9e4288f56b921dabafed0cb97526
Author: Sergey Sharybin
Date:   Fri Oct 8 16:38:40 2021 +0200
Branches: master
https://developer.blender.org/rBeca2a419648a9e4288f56b921dabafed0cb97526

Cycles: Improve volume stack size calculation

Only count volume objects after shader optimization.

Allows to discard objects which don't have effective volume
BSDF connected to the shader output (i.e. constant folded,
or non-volume BSDF used by mistake).

Solves memory regression reported in T92014.

There is still possibility to improve memory even further
for cases when there are a lot of non-intersecting volume
objects, but that requires a deeper refactor of update
process. Will happen as a followup development.

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

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

M	intern/cycles/render/object.cpp
M	intern/cycles/render/scene.cpp

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

diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp
index d3ea93ca8a5..6d5c537e33d 100644
--- a/intern/cycles/render/object.cpp
+++ b/intern/cycles/render/object.cpp
@@ -375,7 +375,7 @@ bool Object::check_is_volume() const
 
   for (Node *node : get_geometry()->get_used_shaders()) {
     const Shader *shader = static_cast<const Shader *>(node);
-    if (shader->has_volume_connected) {
+    if (shader->has_volume) {
       return true;
     }
   }
diff --git a/intern/cycles/render/scene.cpp b/intern/cycles/render/scene.cpp
index e65f542bd2e..17dc99dd589 100644
--- a/intern/cycles/render/scene.cpp
+++ b/intern/cycles/render/scene.cpp
@@ -664,29 +664,29 @@ int Scene::get_max_closure_count()
 
 int Scene::get_volume_stack_size() const
 {
+  int volume_stack_size = 0;
+
+  /* Space for background volume and terminator.
+   * Don't do optional here because camera ray initialization expects that there is space for
+   * at least those elements (avoiding extra condition to check if there is actual volume or not).
+   */
+  volume_stack_size += 2;
+
   /* Quick non-expensive check. Can over-estimate maximum possible nested level, but does not
    * require expensive calculation during pre-processing. */
-  int num_volume_objects = 0;
   for (const Object *object : objects) {
     if (object->check_is_volume()) {
-      ++num_volume_objects;
+      ++volume_stack_size;
     }
 
-    if (num_volume_objects == MAX_VOLUME_STACK_SIZE) {
+    if (volume_stack_size == MAX_VOLUME_STACK_SIZE) {
       break;
     }
   }
 
-  /* Count background world for the stack. */
-  const Shader *background_shader = background->get_shader(this);
-  if (background_shader && background_shader->has_volume_connected) {
-    ++num_volume_objects;
-  }
-
-  /* Space for terminator. */
-  ++num_volume_objects;
+  volume_stack_size = min(volume_stack_size, MAX_VOLUME_STACK_SIZE);
 
-  return min(num_volume_objects, MAX_VOLUME_STACK_SIZE);
+  return volume_stack_size;
 }
 
 bool Scene::has_shadow_catcher()



More information about the Bf-blender-cvs mailing list