[Bf-blender-cvs] [6ba5dc9147c] blender2.8: Depsgraph: Generalize storage for already existing ID nodes

Sergey Sharybin noreply at git.blender.org
Mon Sep 3 13:44:36 CEST 2018


Commit: 6ba5dc9147c06ce9db1facd0bcf0e83ba6f6429c
Author: Sergey Sharybin
Date:   Mon Sep 3 12:39:56 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB6ba5dc9147c06ce9db1facd0bcf0e83ba6f6429c

Depsgraph: Generalize storage for already existing ID nodes

Currently no functional changes, just allows to store mo information.

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

M	source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.h

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

diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index 7546f7f7e4a..5e3496fa5a7 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -122,11 +122,15 @@ namespace DEG {
 
 namespace {
 
-void free_copy_on_write_datablock(void *id_v)
+void free_copy_on_write_datablock(void *id_info_v)
 {
-	ID *id = (ID *)id_v;
-	deg_free_copy_on_write_datablock(id);
-	MEM_freeN(id);
+	DepsgraphNodeBuilder::IDInfo *id_info =
+	    (DepsgraphNodeBuilder::IDInfo *)id_info_v;
+	if (id_info->id_cow != NULL) {
+		deg_free_copy_on_write_datablock(id_info->id_cow);
+		MEM_freeN(id_info->id_cow);
+	}
+	MEM_freeN(id_info);
 }
 
 }  /* namespace */
@@ -144,26 +148,25 @@ DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph)
       view_layer_index_(-1),
       collection_(NULL),
       is_parent_collection_visible_(true),
-      cow_id_hash_(NULL)
+      id_info_hash_(NULL)
 {
 }
 
 DepsgraphNodeBuilder::~DepsgraphNodeBuilder()
 {
-	if (cow_id_hash_ != NULL) {
-		BLI_ghash_free(cow_id_hash_, NULL, free_copy_on_write_datablock);
+	if (id_info_hash_ != NULL) {
+		BLI_ghash_free(id_info_hash_, NULL, free_copy_on_write_datablock);
 	}
 }
 
 IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id)
 {
 	IDDepsNode *id_node = NULL;
-	ID *id_cow = (ID *)BLI_ghash_lookup(cow_id_hash_, id);
+	IDInfo *id_info = (IDInfo *)BLI_ghash_lookup(id_info_hash_, id);
+	ID *id_cow = (id_info != NULL) ? id_info->id_cow : NULL;
 	if (id_cow != NULL) {
-		/* TODO(sergey): Is it possible to lookup and pop element from GHash
-		 * at the same time?
-		 */
-		BLI_ghash_remove(cow_id_hash_, id, NULL, NULL);
+		/* Tag ID info to not free the CoW ID pointer. */
+		id_info->id_cow = NULL;
 	}
 	id_node = graph_->add_id_node(id, id_cow);
 	/* Currently all ID nodes are supposed to have copy-on-write logic.
@@ -333,7 +336,7 @@ void DepsgraphNodeBuilder::begin_build()
 	/* Store existing copy-on-write versions of datablock, so we can re-use
 	 * them for new ID nodes.
 	 */
-	cow_id_hash_ = BLI_ghash_ptr_new("Depsgraph id hash");
+	id_info_hash_ = BLI_ghash_ptr_new("Depsgraph id hash");
 	foreach (IDDepsNode *id_node, graph_->id_nodes) {
 		if (!deg_copy_on_write_is_expanded(id_node->id_cow)) {
 			continue;
@@ -341,7 +344,10 @@ void DepsgraphNodeBuilder::begin_build()
 		if (id_node->id_orig == id_node->id_cow) {
 			continue;
 		}
-		BLI_ghash_insert(cow_id_hash_, id_node->id_orig, id_node->id_cow);
+		IDInfo *id_info = (IDInfo *)MEM_mallocN(
+		        sizeof(IDInfo), "depsgraph id info");
+		id_info->id_cow = id_node->id_cow;
+		BLI_ghash_insert(id_info_hash_, id_node->id_orig, id_info);
 		id_node->id_cow = NULL;
 	}
 
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
index e4b253f6d76..eadf4a23a5e 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
@@ -215,7 +215,19 @@ struct DepsgraphNodeBuilder {
 	void build_lightprobe(LightProbe *probe);
 	void build_speaker(Speaker *speaker);
 
+	/* Per-ID information about what was already in the dependency graph.
+	 * Allows to re-use certain values, to speed up following evaluation.
+	 */
+	struct IDInfo {
+		/* Copy-on-written pointer of the corresponding ID. */
+		ID *id_cow;
+	};
+
 protected:
+	/* Allows to identify an operation which was tagged for update at the time
+	 * relations are being updated. We can not reuse operation node pointer
+	 * since it will change during dependency graph construction.
+	 */
 	struct SavedEntryTag {
 		ID *id;
 		eDepsNode_Type component_type;
@@ -226,12 +238,10 @@ protected:
 	struct BuilderWalkUserData {
 		DepsgraphNodeBuilder *builder;
 	};
-
 	static void modifier_walk(void *user_data,
 	                          struct Object *object,
 	                          struct ID **idpoin,
 	                          int cb_flag);
-
 	static void constraint_walk(bConstraint *constraint,
 	                            ID **idpoin,
 	                            bool is_reference,
@@ -255,7 +265,12 @@ protected:
 	 */
 	bool is_parent_collection_visible_;
 
-	GHash *cow_id_hash_;
+	/* Indexed by original ID, values are IDInfo. */
+	GHash *id_info_hash_;
+
+	/* Set of IDs which were already build. Makes it easier to keep track of
+	 * what was already built and what was not.
+	 */
 	BuilderMap built_map_;
 };



More information about the Bf-blender-cvs mailing list