diff options
author | Sergey Sharybin <sergey@blender.org> | 2021-10-08 17:38:40 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2021-10-11 15:01:42 +0300 |
commit | eca2a419648a9e4288f56b921dabafed0cb97526 (patch) | |
tree | 070a7b6a07c4d5b7c9ef46211e846761043d05c6 /intern/cycles/render | |
parent | a82c9e1e405c84b9ab8b5c1f31d7e135ab41c101 (diff) |
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
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/object.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/render/scene.cpp | 24 |
2 files changed, 13 insertions, 13 deletions
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() |