Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2017-07-18 13:12:15 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2017-07-19 16:20:06 +0300
commit5727e8706fa5bf847696d4433323c5a96c83dae8 (patch)
tree11b00bacb500038f55b980a42e9a9125c94209d0
parent2fe5cf4807d15eb5a1bbaef8715eb277627c17d4 (diff)
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!
-rw-r--r--source/blender/blenkernel/BKE_particle.h3
-rw-r--r--source/blender/blenkernel/intern/particle_system.c11
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes.cc37
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes.h2
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations.cc50
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations.h2
-rw-r--r--source/blender/depsgraph/intern/depsgraph_tag.cc43
-rw-r--r--source/blender/depsgraph/intern/depsgraph_type_defines.cc1
-rw-r--r--source/blender/depsgraph/intern/depsgraph_types.h1
9 files changed, 91 insertions, 59 deletions
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_ex(bmain, &object->id, flag & OB_RECALC_ALL);
- psys->recalc |= (flag & PSYS_RECALC);
- }
- }
- }
- }
- }
-}
-#endif
-
#ifdef WITH_COPY_ON_WRITE
void id_tag_copy_on_write_update(Main *bmain, Depsgraph *graph, ID *id)
{
@@ -261,14 +226,6 @@ void DEG_id_tag_update_ex(Main *bmain, ID *id, int flag)
}
}
}
-
-#ifdef DEPSGRAPH_USE_LEGACY_TAGGING
- /* Special handling from the legacy depsgraph.
- * TODO(sergey): Need to get rid of those once all the areas
- * are re-formulated in terms of franular nodes.
- */
- depsgraph_legacy_handle_update_tag(bmain, id, flag);
-#endif
}
/* Tag given ID type for update. */
diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cc b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
index b987fe9b6f1..cbc4d1b3037 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cc
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
@@ -131,6 +131,7 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
STRINGIFY_OPCODE(BONE_DONE);
/* Particles. */
STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL);
+ STRINGIFY_OPCODE(PARTICLE_SETTINGS_EVAL);
/* Collections. */
STRINGIFY_OPCODE(SCENE_LAYER_INIT);
STRINGIFY_OPCODE(SCENE_LAYER_EVAL);
diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h
index d90f331370a..af13dc37e2f 100644
--- a/source/blender/depsgraph/intern/depsgraph_types.h
+++ b/source/blender/depsgraph/intern/depsgraph_types.h
@@ -211,6 +211,7 @@ typedef enum eDepsOperation_Code {
/* Particles. --------------------------------------- */
/* Particle System evaluation. */
DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
+ DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
/* Collections. ------------------------------------- */
DEG_OPCODE_SCENE_LAYER_INIT,