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!
This commit is contained in:
Sergey Sharybin 2017-07-18 12:12:15 +02:00
parent 2fe5cf4807
commit 5727e8706f
9 changed files with 90 additions and 58 deletions

View File

@ -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,

View File

@ -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);
}

View File

@ -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);
/* this particle system */
// TODO: for now, this will just be a placeholder "ubereval" node
/* 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);
/* 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)

View File

@ -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);

View File

@ -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);
/* 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);
/* 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*/,

View File

@ -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,

View File

@ -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. */

View File

@ -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);

View File

@ -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,