[Bf-blender-cvs] [5727e8706fa] blender2.8: Depsgraph: Use dependency graph flush routines to update particle settings

Sergey Sharybin noreply at git.blender.org
Wed Jul 19 17:33:43 CEST 2017


Commit: 5727e8706fa5bf847696d4433323c5a96c83dae8
Author: Sergey Sharybin
Date:   Tue Jul 18 12:12:15 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB5727e8706fa5bf847696d4433323c5a96c83dae8

Depsgraph: Use dependency graph flush routines to update particle settings

Previously tagging particle settings for update will iterate over all objects and
all their particle system to see whether something needs an update or not. Now we
put ParticleSettings as an ID to the dependency graph, so tagging it for update
will nicely flush updates to all dependent particle systems.

Current downside of this is that due to limitation of flush routines it will cause
some extra particle system re-evaluation when it technically not needed, and what's
more annoying currently it will discard point caches more often.

However, this is a good and simple demonstration case to improve tagging/flushing
system to accommodate for such cases (similar issues happens with CoW and shading
components). So let's try to find some generic solution to the problem!

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

M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/particle_system.c
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/depsgraph_tag.cc
M	source/blender/depsgraph/intern/depsgraph_type_defines.cc
M	source/blender/depsgraph/intern/depsgraph_types.h

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

diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index ec707c84872..639aefd029f 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -473,6 +473,9 @@ typedef struct ParticleRenderData {
 
 struct EvaluationContext;
 
+void BKE_particle_system_settings_eval(struct EvaluationContext *eval_ctx,
+                                       struct ParticleSystem *psys);
+
 void BKE_particle_system_eval(struct EvaluationContext *eval_ctx,
                               struct Scene *scene,
                               struct Object *ob,
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index a6ed50fd0e9..389a98e2573 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -4353,13 +4353,22 @@ void BKE_particlesystem_id_loop(ParticleSystem *psys, ParticleSystemIDFunc func,
 
 /* **** Depsgraph evaluation **** */
 
+void BKE_particle_system_settings_eval(struct EvaluationContext *UNUSED(eval_ctx),
+                                       ParticleSystem *psys)
+{
+	if (G.debug & G_DEBUG_DEPSGRAPH) {
+		printf("%s on %s (%p)\n", __func__, psys->name, psys);
+	}
+	psys->recalc |= PSYS_RECALC;
+}
+
 void BKE_particle_system_eval(struct EvaluationContext *UNUSED(eval_ctx),
                               Scene *scene,
                               Object *ob,
                               ParticleSystem *psys)
 {
 	if (G.debug & G_DEBUG_DEPSGRAPH) {
-		printf("%s on %s:%s\n", __func__, ob->id.name, psys->name);
+		printf("%s on %s:%s (%p)\n", __func__, ob->id.name, psys->name, psys);
 	}
 	BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH);
 }
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index 647d2a024e3..b38cbf36b9d 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -714,12 +714,21 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob)
 	LINKLIST_FOREACH (ParticleSystem *, psys, &ob->particlesystem) {
 		ParticleSettings *part = psys->part;
 
-		/* particle settings */
-		// XXX: what if this is used more than once!
-		build_animdata(&part->id);
+		/* Build particle settings operations.
+		 *
+		 * NOTE: The call itself ensures settings are only build once.
+		 */
+		build_particle_settings(part);
+
+		/* Update on particle settings change. */
+		add_operation_node(psys_comp,
+		                   function_bind(BKE_particle_system_settings_eval,
+		                                 _1,
+		                                 psys),
+		                   DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
+		                   psys->name);
 
-		/* this particle system */
-		// TODO: for now, this will just be a placeholder "ubereval" node
+		/* Particle system evaluation. */
 		add_operation_node(psys_comp,
 		                   function_bind(BKE_particle_system_eval,
 		                                 _1,
@@ -730,8 +739,22 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob)
 		                   psys->name);
 	}
 
-	/* pointcache */
-	// TODO...
+	/* TODO(sergey): Do we need a point cache operations here? */
+}
+
+void DepsgraphNodeBuilder::build_particle_settings(ParticleSettings *part) {
+	ID *part_id = &part->id;
+	if (part_id->tag & LIB_TAG_DOIT) {
+		return;
+	}
+	part_id->tag |= LIB_TAG_DOIT;
+	/* Animation data. */
+	build_animdata(part_id);
+	/* Parameters change. */
+	add_operation_node(part_id,
+	                   DEG_NODE_TYPE_PARAMETERS,
+	                   NULL,
+	                   DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
 }
 
 void DepsgraphNodeBuilder::build_cloth(Scene *scene, Object *object)
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
index 81fbbb07bc8..8535ce6188e 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
@@ -49,6 +49,7 @@ struct MTex;
 struct MovieClip;
 struct bNodeTree;
 struct Object;
+struct ParticleSettings;
 struct Probe;
 struct bPoseChannel;
 struct bConstraint;
@@ -134,6 +135,7 @@ struct DepsgraphNodeBuilder {
 	void build_pose_constraints(Scene *scene, Object *ob, bPoseChannel *pchan);
 	void build_rigidbody(Scene *scene);
 	void build_particles(Scene *scene, Object *ob);
+	void build_particle_settings(ParticleSettings *part);
 	void build_cloth(Scene *scene, Object *object);
 	void build_animdata(ID *id);
 	OperationDepsNode *build_driver(ID *id, FCurve *fcurve);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index b9a4db17d44..dd457f4b21c 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -1249,11 +1249,28 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob)
 	LINKLIST_FOREACH (ParticleSystem *, psys, &ob->particlesystem) {
 		ParticleSettings *part = psys->part;
 
-		/* particle settings */
-		build_animdata(&part->id);
-
-		/* this particle system */
-		OperationKey psys_key(&ob->id, DEG_NODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PARTICLE_SYSTEM_EVAL, psys->name);
+		/* Build particle settings relations.
+		 *
+		 * NOTE: The call itself ensures settings are only build once.
+		 */
+		build_particle_settings(part);
+
+		/* This particle system. */
+		OperationKey psys_key(&ob->id,
+		                      DEG_NODE_TYPE_EVAL_PARTICLES,
+		                      DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
+		                      psys->name);
+
+		/* Update particle system when settings changes. */
+		OperationKey particle_settings_key(&part->id,
+		                                   DEG_NODE_TYPE_PARAMETERS,
+		                                   DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
+		OperationKey psys_settings_key(&ob->id,
+		                               DEG_NODE_TYPE_EVAL_PARTICLES,
+		                               DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
+		                               psys->name);
+		add_relation(particle_settings_key, psys_settings_key, "Particle Settings Change");
+		add_relation(psys_settings_key, psys_key, "Particle Settings Update");
 
 		/* XXX: if particle system is later re-enabled, we must do full rebuild? */
 		if (!psys_check_enabled(ob, psys, G.is_rendering))
@@ -1279,7 +1296,13 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob)
 		}
 
 		/* effectors */
-		add_forcefield_relations(psys_key, scene, ob, psys, part->effector_weights, part->type == PART_HAIR, "Particle Field");
+		add_forcefield_relations(psys_key,
+		                         scene,
+		                         ob,
+		                         psys,
+		                         part->effector_weights,
+		                         part->type == PART_HAIR,
+		                         "Particle Field");
 
 		/* boids */
 		if (part->boids) {
@@ -1314,8 +1337,19 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob)
 	ComponentKey transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM);
 	add_relation(transform_key, obdata_ubereval_key, "Partcile Eval");
 
-	/* pointcache */
-	// TODO...
+	/* TODO(sergey): Do we need a point cache operations here? */
+}
+
+void DepsgraphRelationBuilder::build_particle_settings(ParticleSettings *part)
+{
+	ID *part_id = &part->id;
+	if (part_id->tag & LIB_TAG_DOIT) {
+		return;
+	}
+	part_id->tag |= LIB_TAG_DOIT;
+
+	/* Animation data relations. */
+	build_animdata(&part->id);
 }
 
 void DepsgraphRelationBuilder::build_cloth(Scene * /*scene*/,
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.h b/source/blender/depsgraph/intern/builder/deg_builder_relations.h
index 8a53bf4a6bf..7a0f9934f9d 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.h
@@ -70,6 +70,7 @@ struct Tex;
 struct World;
 struct EffectorWeights;
 struct ParticleSystem;
+struct ParticleSettings;
 
 struct PropertyRNA;
 
@@ -199,6 +200,7 @@ struct DepsgraphRelationBuilder
 	void build_world(World *world);
 	void build_rigidbody(Scene *scene);
 	void build_particles(Scene *scene, Object *ob);
+	void build_particle_settings(ParticleSettings *part);
 	void build_cloth(Scene *scene, Object *object, ModifierData *md);
 	void build_ik_pose(Object *ob,
 	                   bPoseChannel *pchan,
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc
index abf4cba2617..bfa6f08b286 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -70,14 +70,6 @@ extern "C" {
 /* *********************** */
 /* Update Tagging/Flushing */
 
-/* Legacy depsgraph did some special trickery for things like particle systems
- * when tagging ID for an update. Ideally that tagging needs to become obsolete
- * in favor of havng dedicated node for that which gets tagged, but for until
- * design of those areas is more clear we'll do the same legacy code here.
- *                                                                  - sergey -
- */
-#define DEPSGRAPH_USE_LEGACY_TAGGING
-
 namespace {
 
 /* Data-Based Tagging ------------------------------- */
@@ -126,33 +118,6 @@ void lib_id_recalc_tag_flag(Main *bmain, ID *id, int flag)
 	}
 }
 
-#ifdef DEPSGRAPH_USE_LEGACY_TAGGING
-void depsgraph_legacy_handle_update_tag(Main *bmain, ID *id, int flag)
-{
-	if (flag) {
-		Object *object;
-		short idtype = GS(id->name);
-		if (idtype == ID_PA) {
-			ParticleSystem *psys;
-			for (object = (Object *)bmain->object.first;
-			     object != NULL;
-			     object = (Object *)object->id.next)
-			{
-				for (psys = (ParticleSystem *)object->particlesystem.first;
-				     psys != NULL;
-				     psys = (ParticleSystem *)psys->next)
-				{
-					if (&psys->part->id == id) {
-						DEG_id_tag_update

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list