[Bf-blender-cvs] [c8f3377d035] master: Depsgraph: Add generic animated properties cache

Sergey Sharybin noreply at git.blender.org
Tue Apr 30 11:32:12 CEST 2019


Commit: c8f3377d03531ec52fc8dd6fa5802679166997b8
Author: Sergey Sharybin
Date:   Mon Apr 29 12:55:29 2019 +0200
Branches: master
https://developer.blender.org/rBc8f3377d03531ec52fc8dd6fa5802679166997b8

Depsgraph: Add generic animated properties cache

Allows to speed up lookups like "is property FOO of data BAR animated".
Can be used to optimize object's visibility check, but also allows to
check animation on bones without too much of time penalty.

The cache is shared between both nodes and relations builder.

Currently is not used, just a boilerplate for an upcoming changes in
an actual logic.

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

M	source/blender/depsgraph/CMakeLists.txt
M	source/blender/depsgraph/intern/builder/deg_builder.cc
M	source/blender/depsgraph/intern/builder/deg_builder.h
A	source/blender/depsgraph/intern/builder/deg_builder_cache.cc
A	source/blender/depsgraph/intern/builder/deg_builder_cache.h
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.h
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/depsgraph/intern/builder/deg_builder_relations.h
M	source/blender/depsgraph/intern/builder/deg_builder_rna.cc
M	source/blender/depsgraph/intern/builder/deg_builder_rna.h
M	source/blender/depsgraph/intern/depsgraph_build.cc

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

diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index e30b77ea742..aee925ad8f8 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -37,6 +37,7 @@ set(INC_SYS
 
 set(SRC
   intern/builder/deg_builder.cc
+  intern/builder/deg_builder_cache.cc
   intern/builder/deg_builder_cycle.cc
   intern/builder/deg_builder_map.cc
   intern/builder/deg_builder_nodes.cc
@@ -82,6 +83,7 @@ set(SRC
   DEG_depsgraph_query.h
 
   intern/builder/deg_builder.h
+  intern/builder/deg_builder_cache.h
   intern/builder/deg_builder_cycle.h
   intern/builder/deg_builder_map.h
   intern/builder/deg_builder_nodes.h
diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc
index ef36dec6f34..bcf397da335 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder.cc
@@ -55,6 +55,11 @@ namespace DEG {
  * Base class for builders.
  */
 
+DepsgraphBuilder::DepsgraphBuilder(Main *bmain, Depsgraph *graph, DepsgraphBuilderCache *cache)
+    : bmain_(bmain), graph_(graph), cache_(cache)
+{
+}
+
 namespace {
 
 struct VisibilityCheckData {
@@ -108,10 +113,6 @@ bool deg_check_base_available_for_build(const Depsgraph *graph, Base *base)
   return false;
 }
 
-DepsgraphBuilder::DepsgraphBuilder(Main *bmain, Depsgraph *graph) : bmain_(bmain), graph_(graph)
-{
-}
-
 bool DepsgraphBuilder::need_pull_base_into_graph(Base *base)
 {
   return deg_check_base_available_for_build(graph_, base);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder.h b/source/blender/depsgraph/intern/builder/deg_builder.h
index 310944f2f28..88df0e870f3 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder.h
@@ -29,17 +29,20 @@ struct Main;
 namespace DEG {
 
 struct Depsgraph;
+class DepsgraphBuilderCache;
 
 class DepsgraphBuilder {
  public:
   bool need_pull_base_into_graph(struct Base *base);
 
  protected:
-  DepsgraphBuilder(Main *bmain, Depsgraph *graph);
+  /* NOTE: The builder does NOT take ownership over any of those resources. */
+  DepsgraphBuilder(Main *bmain, Depsgraph *graph, DepsgraphBuilderCache *cache);
 
   /* State which never changes, same for the whole builder time. */
   Main *bmain_;
   Depsgraph *graph_;
+  DepsgraphBuilderCache *cache_;
 };
 
 bool deg_check_base_available_for_build(const Depsgraph *graph, Base *base);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_cache.cc b/source/blender/depsgraph/intern/builder/deg_builder_cache.cc
new file mode 100644
index 00000000000..3df707e92c1
--- /dev/null
+++ b/source/blender/depsgraph/intern/builder/deg_builder_cache.cc
@@ -0,0 +1,186 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2018 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup depsgraph
+ */
+
+#include "intern/builder/deg_builder_cache.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_anim_types.h"
+
+#include "BLI_utildefines.h"
+
+extern "C" {
+#include "BKE_animsys.h"
+}
+
+namespace DEG {
+
+/* Animated property storage. */
+
+AnimatedPropertyID::AnimatedPropertyID() : data(NULL), property_rna(NULL)
+{
+}
+
+AnimatedPropertyID::AnimatedPropertyID(const PointerRNA *pointer_rna,
+                                       const PropertyRNA *property_rna)
+    : AnimatedPropertyID(*pointer_rna, property_rna)
+{
+}
+
+AnimatedPropertyID::AnimatedPropertyID(const PointerRNA &pointer_rna,
+                                       const PropertyRNA *property_rna)
+    : data(pointer_rna.data), property_rna(property_rna)
+{
+}
+
+AnimatedPropertyID::AnimatedPropertyID(ID *id, StructRNA *type, const char *property_name)
+    : data(id)
+{
+  property_rna = RNA_struct_type_find_property(type, property_name);
+}
+
+AnimatedPropertyID::AnimatedPropertyID(ID * /*id*/,
+                                       StructRNA *type,
+                                       void *data,
+                                       const char *property_name)
+    : data(data)
+{
+  property_rna = RNA_struct_type_find_property(type, property_name);
+}
+
+bool AnimatedPropertyID::operator<(const AnimatedPropertyID &other) const
+{
+  if (data < other.data) {
+    return true;
+  }
+  else if (data == other.data) {
+    return property_rna < other.property_rna;
+  }
+  return false;
+}
+
+namespace {
+
+struct AnimatedPropertyCallbackData {
+  PointerRNA pointer_rna;
+  AnimatedPropertyStorage *animated_property_storage;
+  DepsgraphBuilderCache *builder_cache;
+};
+
+void animated_property_cb(ID * /*id*/, FCurve *fcurve, void *data_v)
+{
+  if (fcurve->rna_path == NULL || fcurve->rna_path[0] == '\0') {
+    return;
+  }
+  AnimatedPropertyCallbackData *data = static_cast<AnimatedPropertyCallbackData *>(data_v);
+  /* Resolve property. */
+  PointerRNA pointer_rna;
+  PropertyRNA *property_rna = NULL;
+  if (!RNA_path_resolve_property(
+          &data->pointer_rna, fcurve->rna_path, &pointer_rna, &property_rna)) {
+    return;
+  }
+  /* Get storage for the ID.
+   * This is needed to deal with cases when nested datablock is animated by its parent. */
+  AnimatedPropertyStorage *animated_property_storage = data->animated_property_storage;
+  if (pointer_rna.id.data != data->pointer_rna.id.data) {
+    animated_property_storage = data->builder_cache->ensureAnimatedPropertyStorage(
+        reinterpret_cast<ID *>(pointer_rna.id.data));
+  }
+  /* Set the property as animated. */
+  animated_property_storage->tagPropertyAsAnimated(&pointer_rna, property_rna);
+}
+
+}  // namespace
+
+AnimatedPropertyStorage::AnimatedPropertyStorage() : is_fully_initialized(false)
+{
+}
+
+void AnimatedPropertyStorage::initializeFromID(DepsgraphBuilderCache *builder_cache, ID *id)
+{
+  AnimatedPropertyCallbackData data;
+  RNA_id_pointer_create(id, &data.pointer_rna);
+  data.animated_property_storage = this;
+  data.builder_cache = builder_cache;
+  BKE_fcurves_id_cb(id, animated_property_cb, &data);
+}
+
+void AnimatedPropertyStorage::tagPropertyAsAnimated(const AnimatedPropertyID &property_id)
+{
+  animated_properties_set.insert(property_id);
+}
+
+void AnimatedPropertyStorage::tagPropertyAsAnimated(const PointerRNA *pointer_rna,
+                                                    const PropertyRNA *property_rna)
+{
+  tagPropertyAsAnimated(AnimatedPropertyID(pointer_rna, property_rna));
+}
+
+bool AnimatedPropertyStorage::isPropertyAnimated(const AnimatedPropertyID &property_id)
+{
+  return animated_properties_set.find(property_id) != animated_properties_set.end();
+}
+
+bool AnimatedPropertyStorage::isPropertyAnimated(const PointerRNA *pointer_rna,
+                                                 const PropertyRNA *property_rna)
+{
+  return isPropertyAnimated(AnimatedPropertyID(pointer_rna, property_rna));
+}
+
+/* Builder cache itself. */
+
+DepsgraphBuilderCache::DepsgraphBuilderCache()
+{
+}
+
+DepsgraphBuilderCache::~DepsgraphBuilderCache()
+{
+  for (AnimatedPropertyStorageMap::value_type &iter : animated_property_storage_map_) {
+    AnimatedPropertyStorage *animated_property_storage = iter.second;
+    OBJECT_GUARDED_DELETE(animated_property_storage, AnimatedPropertyStorage);
+  }
+}
+
+AnimatedPropertyStorage *DepsgraphBuilderCache::ensureAnimatedPropertyStorage(ID *id)
+{
+  AnimatedPropertyStorageMap::iterator it = animated_property_storage_map_.find(id);
+  if (it != animated_property_storage_map_.end()) {
+    return it->second;
+  }
+  AnimatedPropertyStorage *animated_property_storage = OBJECT_GUARDED_NEW(AnimatedPropertyStorage);
+  animated_property_storage_map_.insert(make_pair(id, animated_property_storage));
+  return animated_property_storage;
+}
+
+AnimatedPropertyStorage *DepsgraphBuilderCache::ensureInitializedAnimatedPropertyStorage(ID *id)
+{
+  AnimatedPropertyStorage *animated_property_storage = ensureAnimatedPropertyStorage(id);
+  if (!animated_property_storage->is_fully_initialized) {
+    animated_property_storage->initializeFromID(this, id);
+    animated_property_storage->is_fully_initialized = true;
+  }
+  return animated_property_storage;
+}
+
+}  // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_cache.h b/source/blender/depsgraph/intern/builder/deg_builder_cache.h
new file mode 100644
index 00000000000..949020e3a81
--- /dev/null
+++ b/source/blender/depsgraph/intern/builder/deg_builder_cache.h
@@ -0,0 +1,103 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2018 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup depsgraph
+ */
+
+#pragma once
+
+#include "intern/depsgraph_type.h"
+
+#include "RNA_access.h"
+
+struct ID;
+struct PointerRNA;
+struct

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list