diff options
author | Jacques Lucke <jacques@blender.org> | 2022-05-18 17:42:49 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-05-18 17:42:49 +0300 |
commit | f517b3a29568fd43b722973c7c46d3c358ba0dda (patch) | |
tree | c166fc983bb0a717fcf3e49f6f2bd604dc8998a3 /source/blender/blenkernel/intern/node_tree_update.cc | |
parent | 136a06285f0e953f65dc432a4dba1ff3d1f781ee (diff) |
Fix T98157: improve animation fps with better check in depsgraph
Previously, the depsgraph assumed that every node tree might contain
a reference to a video. This resulted noticeable overhead when there
was no video.
Checking whether a node tree contained a video was relatively expensive
to do in the depsgraph. It is cheaper now due to the structure of the new
node tree updater.
This also adds an additional run-time field to `bNodeTree` (there are
quite a few already). We should move those to a separate run-time
struct, but not as part of a bug fix.
Differential Revision: https://developer.blender.org/D14957
Diffstat (limited to 'source/blender/blenkernel/intern/node_tree_update.cc')
-rw-r--r-- | source/blender/blenkernel/intern/node_tree_update.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/node_tree_update.cc b/source/blender/blenkernel/intern/node_tree_update.cc index baf3a0c8d22..8afe7ce7520 100644 --- a/source/blender/blenkernel/intern/node_tree_update.cc +++ b/source/blender/blenkernel/intern/node_tree_update.cc @@ -12,6 +12,7 @@ #include "DNA_node_types.h" #include "BKE_anim_data.h" +#include "BKE_image.h" #include "BKE_main.h" #include "BKE_node.h" #include "BKE_node_tree_update.h" @@ -984,6 +985,7 @@ class NodeTreeMainUpdater { this->remove_unused_previews_when_necessary(ntree); this->ensure_tree_ref(ntree, tree_ref); + this->update_has_image_animation(*tree_ref); if (ntree.type == NTREE_GEOMETRY) { if (node_field_inferencing::update_field_inferencing(*tree_ref)) { result.interface_changed = true; @@ -1254,6 +1256,35 @@ class NodeTreeMainUpdater { BKE_node_preview_remove_unused(&ntree); } + void update_has_image_animation(const NodeTreeRef &tree_ref) + { + bNodeTree &ntree = *tree_ref.btree(); + ntree.runtime_flag &= ~NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; + if (ntree.type != NTREE_SHADER) { + return; + } + + /* Check if a used node group has an animated image. */ + for (const NodeRef *group_node : tree_ref.nodes_by_type("NodeGroup")) { + const bNodeTree *group = reinterpret_cast<bNodeTree *>(group_node->bnode()->id); + if (group != nullptr) { + if (group->runtime_flag & NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION) { + ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; + return; + } + } + } + /* Check if the tree itself has an animated image. */ + for (const StringRefNull idname : {"ShaderNodeTexImage", "ShaderNodeTexEnvironment"}) + for (const NodeRef *node : tree_ref.nodes_by_type(idname)) { + Image *image = reinterpret_cast<Image *>(node->bnode()->id); + if (image != nullptr && BKE_image_is_animated(image)) { + ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; + return; + } + } + } + void update_node_levels(bNodeTree &ntree) { ntreeUpdateNodeLevels(&ntree); |