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:
authorCampbell Barton <ideasman42@gmail.com>2017-10-09 12:49:27 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-10-09 12:49:27 +0300
commita5b4b0f21c1ae8c96e4fea9abdcfac2fab1cf300 (patch)
tree0658d8bdfb8ec03652aa04f82ee8a4d243ec6370 /source/blender/depsgraph/intern
parentd68f698cf0321477c0734474150eb4bc43c4e85f (diff)
parentabcda06934aba054de8540b66b13c2bbc5f8f515 (diff)
Merge branch '28' into custom-manipulatorscustom-manipulators
Diffstat (limited to 'source/blender/depsgraph/intern')
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder.cc10
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes.cc441
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes.h40
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes_layer.cc6
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc157
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc3
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations.cc613
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations.h4
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations_layer.cc2
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc33
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc4
-rw-r--r--source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc12
-rw-r--r--source/blender/depsgraph/intern/depsgraph.cc66
-rw-r--r--source/blender/depsgraph/intern/depsgraph.h10
-rw-r--r--source/blender/depsgraph/intern/depsgraph_build.cc30
-rw-r--r--source/blender/depsgraph/intern/depsgraph_debug.cc2
-rw-r--r--source/blender/depsgraph/intern/depsgraph_eval.cc15
-rw-r--r--source/blender/depsgraph/intern/depsgraph_intern.h22
-rw-r--r--source/blender/depsgraph/intern/depsgraph_query.cc85
-rw-r--r--source/blender/depsgraph/intern/depsgraph_tag.cc440
-rw-r--r--source/blender/depsgraph/intern/depsgraph_type_defines.cc33
-rw-r--r--source/blender/depsgraph/intern/depsgraph_types.h46
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval.cc4
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc461
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h35
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval_flush.cc87
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node.cc73
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node.h2
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_component.cc7
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_component.h8
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_operation.cc3
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_operation.h10
32 files changed, 1962 insertions, 802 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc
index 92c79388657..deee2227f81 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder.cc
@@ -41,6 +41,8 @@
#include "intern/depsgraph_types.h"
#include "intern/nodes/deg_node.h"
+#include "DEG_depsgraph.h"
+
namespace DEG {
void deg_graph_build_finalize(Depsgraph *graph)
@@ -61,11 +63,9 @@ void deg_graph_build_finalize(Depsgraph *graph)
id_node->tag_update(graph);
}
}
- /* XXX: This is only so we've got proper COW IDs after rebuild. */
- /* TODO(sergey): Ideally we'll need to copy evaluated CoW from previous
- * depsgraph, so we don't need to re-tag anything what we already have.
- */
- id_node->tag_update(graph);
+#ifdef WITH_COPY_ON_WRITE
+ DEG_id_tag_update_ex(graph->bmain, id_node->id_orig, DEG_TAG_COPY_ON_WRITE);
+#endif
}
GHASH_FOREACH_END();
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index 1fc107f0437..02d20913177 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -81,6 +81,7 @@ extern "C" {
#include "BKE_lattice.h"
#include "BKE_library.h"
#include "BKE_main.h"
+#include "BKE_mask.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_mball.h"
@@ -144,6 +145,12 @@ void constraint_walk(bConstraint * /*con*/,
}
}
+void free_copy_on_write_datablock(void *id_v)
+{
+ ID *id = (ID *)id_v;
+ deg_free_copy_on_write_datablock(id);
+}
+
} /* namespace */
/* ************ */
@@ -153,18 +160,30 @@ void constraint_walk(bConstraint * /*con*/,
DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph) :
m_bmain(bmain),
- m_graph(graph)
+ m_graph(graph),
+ m_cow_id_hash(NULL)
{
}
DepsgraphNodeBuilder::~DepsgraphNodeBuilder()
{
+ if (m_cow_id_hash != NULL) {
+ BLI_ghash_free(m_cow_id_hash, NULL, free_copy_on_write_datablock);
+ }
}
-IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id)
+IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id, bool do_tag)
{
- IDDepsNode *id_node = m_graph->add_id_node(id, id->name);
#ifdef WITH_COPY_ON_WRITE
+ IDDepsNode *id_node = NULL;
+ ID *id_cow = (ID *)BLI_ghash_lookup(m_cow_id_hash, id);
+ if (id_cow != NULL) {
+ /* TODO(sergey): Is it possible to lookup and pop element from GHash
+ * at the same time?
+ */
+ BLI_ghash_remove(m_cow_id_hash, id, NULL, NULL);
+ }
+ id_node = m_graph->add_id_node(id, do_tag, id_cow);
/* Currently all ID nodes are supposed to have copy-on-write logic.
*
* NOTE: Zero number of components indicates that ID node was just created.
@@ -178,6 +197,9 @@ IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id)
"", -1);
m_graph->operations.push_back(op_cow);
}
+#else
+ IDDepsNode *id_node = m_graph->add_id_node(id);
+ UNUSED_VARS(do_tag);
#endif
return id_node;
}
@@ -295,6 +317,27 @@ ID *DepsgraphNodeBuilder::get_cow_id(const ID *id_orig) const
return m_graph->get_cow_id(id_orig);
}
+ID *DepsgraphNodeBuilder::ensure_cow_id(ID *id_orig)
+{
+ if (id_orig->tag & LIB_TAG_COPY_ON_WRITE) {
+ /* ID is already remapped to copy-on-write. */
+ return id_orig;
+ }
+ IDDepsNode *id_node = add_id_node(id_orig, false);
+ return id_node->id_cow;
+}
+
+ID *DepsgraphNodeBuilder::expand_cow_id(IDDepsNode *id_node)
+{
+ return deg_expand_copy_on_write_datablock(m_graph, id_node, this, true);
+}
+
+ID *DepsgraphNodeBuilder::expand_cow_id(ID *id_orig)
+{
+ IDDepsNode *id_node = add_id_node(id_orig);
+ return expand_cow_id(id_node);
+}
+
/* **** Build functions for entity nodes **** */
void DepsgraphNodeBuilder::begin_build(Main *bmain) {
@@ -307,11 +350,36 @@ void DepsgraphNodeBuilder::begin_build(Main *bmain) {
/* XXX nested node trees are not included in tag-clearing above,
* so we need to do this manually.
*/
- FOREACH_NODETREE(bmain, nodetree, id) {
+ FOREACH_NODETREE(bmain, nodetree, id)
+ {
if (id != (ID *)nodetree) {
nodetree->id.tag &= ~LIB_TAG_DOIT;
}
- } FOREACH_NODETREE_END
+ }
+ FOREACH_NODETREE_END;
+
+#ifdef WITH_COPY_ON_WRITE
+ /* Store existing copy-on-write versions of datablock, so we can re-use
+ * them for new ID nodes.
+ */
+ m_cow_id_hash = BLI_ghash_ptr_new("Depsgraph id hash");
+ GHASH_FOREACH_BEGIN(IDDepsNode *, id_node, m_graph->id_hash)
+ {
+ if (GS(id_node->id_orig->name) != ID_SCE) {
+ continue;
+ }
+ if (deg_copy_on_write_is_expanded(id_node->id_cow)) {
+ BLI_ghash_insert(m_cow_id_hash, id_node->id_orig, id_node->id_cow);
+ id_node->id_cow = NULL;
+ }
+ }
+ GHASH_FOREACH_END();
+#endif
+
+ /* Make sure graph has no nodes left from previous state. */
+ m_graph->clear_all_nodes();
+ m_graph->operations.clear();
+ BLI_gset_clear(m_graph->entry_tags, NULL);
}
void DepsgraphNodeBuilder::build_group(Scene *scene, Group *group)
@@ -445,39 +513,41 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, Object *ob)
void DepsgraphNodeBuilder::build_object_transform(Scene *scene, Object *ob)
{
OperationDepsNode *op_node;
+ Scene *scene_cow = get_cow_datablock(scene);
+ Object *ob_cow = get_cow_datablock(ob);
/* local transforms (from transform channels - loc/rot/scale + deltas) */
op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_local_transform, _1, scene, ob),
+ function_bind(BKE_object_eval_local_transform,
+ _1,
+ scene_cow, ob_cow),
DEG_OPCODE_TRANSFORM_LOCAL);
op_node->set_as_entry();
/* object parent */
- if (ob->parent) {
+ if (ob->parent != NULL) {
add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_parent, _1, scene, ob),
+ function_bind(BKE_object_eval_parent,
+ _1,
+ scene_cow, ob_cow),
DEG_OPCODE_TRANSFORM_PARENT);
}
/* object constraints */
- if (ob->constraints.first) {
+ if (ob->constraints.first != NULL) {
build_object_constraints(scene, ob);
}
- /* Temporary uber-update node, which does everything.
- * It is for the being we're porting old dependencies into the new system.
- * We'll get rid of this node as soon as all the granular update functions
- * are filled in.
- *
- * TODO(sergey): Get rid of this node.
- */
+ /* Rest of transformation update. */
add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_uber_transform, _1, scene, ob),
- DEG_OPCODE_OBJECT_UBEREVAL);
+ function_bind(BKE_object_eval_uber_transform,
+ _1,
+ scene_cow, ob_cow),
+ DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
/* object transform is done */
op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_done, _1, ob),
+ function_bind(BKE_object_eval_done, _1, ob_cow),
DEG_OPCODE_TRANSFORM_FINAL);
op_node->set_as_exit();
}
@@ -503,7 +573,9 @@ void DepsgraphNodeBuilder::build_object_constraints(Scene *scene, Object *ob)
{
/* create node for constraint stack */
add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_constraints, _1, scene, ob),
+ function_bind(BKE_object_eval_constraints, _1,
+ get_cow_datablock(scene),
+ get_cow_datablock(ob)),
DEG_OPCODE_TRANSFORM_CONSTRAINTS);
}
@@ -514,23 +586,31 @@ void DepsgraphNodeBuilder::build_object_constraints(Scene *scene, Object *ob)
void DepsgraphNodeBuilder::build_animdata(ID *id)
{
AnimData *adt = BKE_animdata_from_id(id);
-
- if (adt == NULL)
+ if (adt == NULL) {
return;
+ }
/* animation */
if (adt->action || adt->nla_tracks.first || adt->drivers.first) {
- // XXX: Hook up specific update callbacks for special properties which may need it...
+ (void) add_id_node(id);
+ ID *id_cow = get_cow_id(id);
+
+ // XXX: Hook up specific update callbacks for special properties which
+ // may need it...
- /* actions and NLA - as a single unit for now, as it gets complicated to schedule otherwise */
+ /* actions and NLA - as a single unit for now, as it gets complicated to
+ * schedule otherwise.
+ */
if ((adt->action) || (adt->nla_tracks.first)) {
/* create the node */
add_operation_node(id, DEG_NODE_TYPE_ANIMATION,
- function_bind(BKE_animsys_eval_animdata, _1, id),
+ function_bind(BKE_animsys_eval_animdata, _1, id_cow),
DEG_OPCODE_ANIMATION, id->name);
- // TODO: for each channel affected, we might also want to add some support for running RNA update callbacks on them
- // (which will be needed for proper handling of drivers later)
+ /* TODO: for each channel affected, we might also want to add some
+ * support for running RNA update callbacks on them
+ * (which will be needed for proper handling of drivers later)
+ */
}
/* drivers */
@@ -548,7 +628,7 @@ void DepsgraphNodeBuilder::build_animdata(ID *id)
*/
OperationDepsNode *DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcu)
{
- ChannelDriver *driver = fcu->driver;
+ ID *id_cow = get_cow_id(id);
/* Create data node for this driver */
/* TODO(sergey): Avoid creating same operation multiple times,
@@ -562,19 +642,15 @@ OperationDepsNode *DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcu)
fcu->array_index);
if (driver_op == NULL) {
+ /* TODO(sergey): Shall we use COW of fcu itself here? */
driver_op = add_operation_node(id,
DEG_NODE_TYPE_PARAMETERS,
- function_bind(BKE_animsys_eval_driver, _1, id, fcu),
+ function_bind(BKE_animsys_eval_driver, _1, id_cow, fcu),
DEG_OPCODE_DRIVER,
fcu->rna_path ? fcu->rna_path : "",
fcu->array_index);
}
- /* tag "scripted expression" drivers as needing Python (due to GIL issues, etc.) */
- if (driver->type == DRIVER_TYPE_PYTHON) {
- driver_op->flag |= DEPSOP_FLAG_USES_PYTHON;
- }
-
/* return driver node created */
return driver_op;
}
@@ -590,10 +666,10 @@ void DepsgraphNodeBuilder::build_world(World *world)
build_animdata(world_id);
/* world itself */
- add_component_node(world_id, DEG_NODE_TYPE_PARAMETERS);
-
- add_operation_node(world_id, DEG_NODE_TYPE_PARAMETERS, NULL,
- DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
+ add_operation_node(world_id,
+ DEG_NODE_TYPE_SHADING,
+ function_bind(BKE_world_eval, _1, world),
+ DEG_OPCODE_WORLD_UPDATE);
/* textures */
build_texture_stack(world->mtex);
@@ -608,43 +684,49 @@ void DepsgraphNodeBuilder::build_world(World *world)
void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
{
RigidBodyWorld *rbw = scene->rigidbody_world;
+ Scene *scene_cow = get_cow_datablock(scene);
/**
* Rigidbody Simulation Nodes
* ==========================
*
* There are 3 nodes related to Rigidbody Simulation:
- * 1) "Initialize/Rebuild World" - this is called sparingly, only when the simulation
- * needs to be rebuilt (mainly after file reload, or moving back to start frame)
- * 2) "Do Simulation" - perform a simulation step - interleaved between the evaluation
- * steps for clusters of objects (i.e. between those affected and/or not affected by
- * the sim for instance)
+ * 1) "Initialize/Rebuild World" - this is called sparingly, only when the
+ * simulation needs to be rebuilt (mainly after file reload, or moving
+ * back to start frame)
+ * 2) "Do Simulation" - perform a simulation step - interleaved between the
+ * evaluation steps for clusters of objects (i.e. between those affected
+ * and/or not affected by the sim for instance).
*
- * 3) "Pull Results" - grab the specific transforms applied for a specific object -
- * performed as part of object's transform-stack building
+ * 3) "Pull Results" - grab the specific transforms applied for a specific
+ * object - performed as part of object's transform-stack building.
*/
- /* create nodes ------------------------------------------------------------------------ */
- /* XXX: is this the right component, or do we want to use another one instead? */
+ /* Create nodes --------------------------------------------------------- */
+
+ /* XXX: is this the right component, or do we want to use another one
+ * instead?
+ */
/* init/rebuild operation */
- /*OperationDepsNode *init_node =*/ add_operation_node(&scene->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_rigidbody_rebuild_sim, _1, scene),
- DEG_OPCODE_RIGIDBODY_REBUILD);
+ /*OperationDepsNode *init_node =*/ add_operation_node(
+ &scene->id, DEG_NODE_TYPE_TRANSFORM,
+ function_bind(BKE_rigidbody_rebuild_sim, _1, scene_cow),
+ DEG_OPCODE_RIGIDBODY_REBUILD);
/* do-sim operation */
// XXX: what happens if we need to split into several groups?
- OperationDepsNode *sim_node = add_operation_node(&scene->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_rigidbody_eval_simulation, _1, scene),
- DEG_OPCODE_RIGIDBODY_SIM);
+ OperationDepsNode *sim_node = add_operation_node(
+ &scene->id, DEG_NODE_TYPE_TRANSFORM,
+ function_bind(BKE_rigidbody_eval_simulation, _1, scene_cow),
+ DEG_OPCODE_RIGIDBODY_SIM);
- /* XXX: For now, the sim node is the only one that really matters here. If any other
- * sims get added later, we may have to remove these hacks...
+ /* XXX: For now, the sim node is the only one that really matters here.
+ * If any other sims get added later, we may have to remove these hacks...
*/
sim_node->owner->entry_operation = sim_node;
sim_node->owner->exit_operation = sim_node;
-
/* objects - simulation participants */
if (rbw->group) {
LINKLIST_FOREACH (GroupObject *, go, &rbw->group->gobject) {
@@ -654,10 +736,14 @@ void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
continue;
/* 2) create operation for flushing results */
- /* object's transform component - where the rigidbody operation lives */
+ /* object's transform component - where the rigidbody operation
+ * lives. */
add_operation_node(&ob->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_rigidbody_object_sync_transforms, _1, scene, ob),
- DEG_OPCODE_TRANSFORM_RIGIDBODY);
+ function_bind(BKE_rigidbody_object_sync_transforms,
+ _1,
+ scene_cow,
+ get_cow_datablock(ob)),
+ DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
}
}
}
@@ -683,39 +769,78 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob)
ComponentDepsNode *psys_comp =
add_component_node(&ob->id, DEG_NODE_TYPE_EVAL_PARTICLES);
+ /* TODO(sergey): Need to get COW of PSYS. */
+ Scene *scene_cow = get_cow_datablock(scene);
+ Object *ob_cow = get_cow_datablock(ob);
+
+ add_operation_node(psys_comp,
+ function_bind(BKE_particle_system_eval_init,
+ _1,
+ scene_cow,
+ ob_cow),
+ DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
+
/* particle systems */
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_eval,
+ function_bind(BKE_particle_system_settings_eval,
_1,
- scene,
- ob,
psys),
- DEG_OPCODE_PSYS_EVAL,
+ DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
+ psys->name);
+
+ /* Particle system evaluation. */
+ add_operation_node(psys_comp,
+ NULL,
+ DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
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);
+ add_operation_node(part_id,
+ DEG_NODE_TYPE_PARAMETERS,
+ function_bind(BKE_particle_system_settings_recalc_clear,
+ _1,
+ part),
+ DEG_OPCODE_PARTICLE_SETTINGS_RECALC_CLEAR);
}
void DepsgraphNodeBuilder::build_cloth(Scene *scene, Object *object)
{
+ Scene *scene_cow = get_cow_datablock(scene);
+ Object *object_cow = get_cow_datablock(object);
+
ComponentDepsNode *cache_comp = add_component_node(&object->id,
DEG_NODE_TYPE_CACHE);
add_operation_node(cache_comp,
function_bind(BKE_object_eval_cloth,
_1,
- scene,
- object),
+ scene_cow,
+ object_cow),
DEG_OPCODE_PLACEHOLDER,
"Cloth Modifier");
}
@@ -733,8 +858,9 @@ void DepsgraphNodeBuilder::build_shapekeys(Key *key)
// XXX: what happens if the datablock is shared!
void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
{
- ID *obdata = (ID *)ob->data;
OperationDepsNode *op_node;
+ Scene *scene_cow = get_cow_datablock(scene);
+ Object *object_cow = get_cow_datablock(ob);
/* TODO(sergey): This way using this object's properties as driver target
* works fine.
@@ -744,8 +870,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
op_node = add_operation_node(&ob->id,
DEG_NODE_TYPE_PARAMETERS,
NULL,
- DEG_OPCODE_PLACEHOLDER,
- "Parameters Eval");
+ DEG_OPCODE_PARAMETERS_EVAL);
op_node->set_as_exit();
/* Temporary uber-update node, which does everything.
@@ -759,8 +884,8 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_object_eval_uber_data,
_1,
- (Scene *)get_cow_id(&scene->id),
- (Object *)get_cow_id(&ob->id)),
+ scene_cow,
+ object_cow),
DEG_OPCODE_GEOMETRY_UBEREVAL);
op_node->set_as_exit();
@@ -781,10 +906,20 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
}
/* materials */
- for (int a = 1; a <= ob->totcol; a++) {
- Material *ma = give_current_material(ob, a);
- if (ma != NULL) {
- build_material(ma);
+ if (ob->totcol != 0) {
+ if (ob->type == OB_MESH) {
+ add_operation_node(&ob->id,
+ DEG_NODE_TYPE_SHADING,
+ function_bind(BKE_object_eval_update_shading, _1,
+ object_cow),
+ DEG_OPCODE_SHADING);
+ }
+
+ for (int a = 1; a <= ob->totcol; a++) {
+ Material *ma = give_current_material(ob, a);
+ if (ma != NULL) {
+ build_material(ma);
+ }
}
}
@@ -793,9 +928,14 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
// add geometry collider relations
}
+ ID *obdata = (ID *)ob->data;
if (obdata->tag & LIB_TAG_DOIT) {
return;
}
+ obdata->tag |= LIB_TAG_DOIT;
+ /* Make sure we've got an ID node before requesting CoW pointer. */
+ (void) add_id_node((ID *)obdata);
+ ID *obdata_cow = get_cow_id(obdata);
/* ShapeKeys */
Key *key = BKE_key_from_object(ob);
@@ -818,7 +958,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_mesh_eval_geometry,
_1,
- (Mesh *)obdata),
+ (Mesh *)obdata_cow),
DEG_OPCODE_PLACEHOLDER,
"Geometry Eval");
op_node->set_as_entry();
@@ -837,7 +977,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_mball_eval_geometry,
_1,
- (MetaBall *)obdata),
+ (MetaBall *)obdata_cow),
DEG_OPCODE_PLACEHOLDER,
"Geometry Eval");
op_node->set_as_entry();
@@ -855,22 +995,10 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_curve_eval_geometry,
_1,
- (Curve *)obdata),
+ (Curve *)obdata_cow),
DEG_OPCODE_PLACEHOLDER,
"Geometry Eval");
op_node->set_as_entry();
-
- /* Calculate curve path - this is used by constraints, etc. */
- if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
- add_operation_node(obdata,
- DEG_NODE_TYPE_GEOMETRY,
- function_bind(BKE_curve_eval_path,
- _1,
- (Curve *)obdata),
- DEG_OPCODE_GEOMETRY_PATH,
- "Path");
- }
-
/* Make sure objects used for bevel.taper are in the graph.
* NOTE: This objects might be not linked to the scene.
*/
@@ -894,7 +1022,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_lattice_eval_geometry,
_1,
- (Lattice *)obdata),
+ (Lattice *)obdata_cow),
DEG_OPCODE_PLACEHOLDER,
"Geometry Eval");
op_node->set_as_entry();
@@ -907,14 +1035,24 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob)
op_node->set_as_exit();
/* Parameters for driver sources. */
- add_operation_node(obdata, DEG_NODE_TYPE_PARAMETERS, NULL,
- DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
+ add_operation_node(obdata,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PARAMETERS_EVAL);
}
/* Cameras */
void DepsgraphNodeBuilder::build_camera(Object *ob)
{
- /* TODO: Link scene-camera links in somehow... */
+ /* Object itself. */
+ add_operation_node(&ob->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PARAMETERS_EVAL,
+ "Camera Parameters");
+
+ /* Object data. */
+ /* TODO: Link scene-camera links in somehow. */
Camera *cam = (Camera *)ob->data;
ID *camera_id = &cam->id;
if (camera_id->tag & LIB_TAG_DOIT) {
@@ -923,19 +1061,23 @@ void DepsgraphNodeBuilder::build_camera(Object *ob)
build_animdata(&cam->id);
- add_operation_node(camera_id, DEG_NODE_TYPE_PARAMETERS, NULL,
- DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
-
- if (cam->dof_ob != NULL) {
- /* TODO(sergey): For now parametrs are on object level. */
- add_operation_node(&ob->id, DEG_NODE_TYPE_PARAMETERS, NULL,
- DEG_OPCODE_PLACEHOLDER, "Camera DOF");
- }
+ add_operation_node(camera_id,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PARAMETERS_EVAL);
}
/* Lamps */
void DepsgraphNodeBuilder::build_lamp(Object *ob)
{
+ /* Object itself. */
+ add_operation_node(&ob->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PARAMETERS_EVAL,
+ "Lamp Parameters");
+
+ /* Object data. */
Lamp *la = (Lamp *)ob->data;
ID *lamp_id = &la->id;
if (lamp_id->tag & LIB_TAG_DOIT) {
@@ -945,11 +1087,10 @@ void DepsgraphNodeBuilder::build_lamp(Object *ob)
build_animdata(&la->id);
/* node for obdata */
- add_component_node(lamp_id, DEG_NODE_TYPE_PARAMETERS);
-
- /* TODO(sergey): Is it really how we're supposed to work with drivers? */
- add_operation_node(lamp_id, DEG_NODE_TYPE_PARAMETERS, NULL,
- DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
+ add_operation_node(lamp_id,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PARAMETERS_EVAL);
/* lamp's nodetree */
if (la->nodetree) {
@@ -962,25 +1103,30 @@ void DepsgraphNodeBuilder::build_lamp(Object *ob)
void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree)
{
- if (!ntree)
+ if (ntree == NULL) {
return;
-
+ }
/* nodetree itself */
ID *ntree_id = &ntree->id;
- OperationDepsNode *op_node;
-
+ add_id_node(ntree_id);
+ bNodeTree *ntree_cow = get_cow_datablock(ntree);
+ /* Animation, */
build_animdata(ntree_id);
-
- /* Parameters for drivers. */
- op_node = add_operation_node(ntree_id, DEG_NODE_TYPE_PARAMETERS, NULL,
- DEG_OPCODE_PLACEHOLDER, "Parameters Eval");
- op_node->set_as_exit();
-
+ /* Shading update. */
+ add_operation_node(ntree_id,
+ DEG_NODE_TYPE_SHADING,
+ NULL,
+ DEG_OPCODE_MATERIAL_UPDATE);
+ add_operation_node(ntree_id,
+ DEG_NODE_TYPE_SHADING_PARAMETERS,
+ function_bind(BKE_nodetree_shading_params_eval,
+ _1, ntree_cow, ntree),
+ DEG_OPCODE_MATERIAL_UPDATE);
/* nodetree's nodes... */
LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) {
ID *id = bnode->id;
if (id != NULL) {
- short id_type = GS(id->name);
+ ID_Type id_type = GS(id->name);
if (id_type == ID_MA) {
build_material((Material *)id);
}
@@ -1003,27 +1149,27 @@ void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree)
}
/* Recursively build graph for material */
-void DepsgraphNodeBuilder::build_material(Material *ma)
+void DepsgraphNodeBuilder::build_material(Material *material)
{
- ID *ma_id = &ma->id;
- if (ma_id->tag & LIB_TAG_DOIT) {
+ ID *material_id = &material->id;
+ if (material_id->tag & LIB_TAG_DOIT) {
return;
}
-
- /* material itself */
- add_id_node(ma_id);
-
- add_operation_node(ma_id, DEG_NODE_TYPE_SHADING, NULL,
- DEG_OPCODE_PLACEHOLDER, "Material Update");
-
- /* material animation */
- build_animdata(ma_id);
-
- /* textures */
- build_texture_stack(ma->mtex);
-
- /* material's nodetree */
- build_nodetree(ma->nodetree);
+ material_id->tag |= LIB_TAG_DOIT;
+ /* Material itself. */
+ add_id_node(material_id);
+ Material *material_cow = get_cow_datablock(material);
+ /* Shading update. */
+ add_operation_node(material_id,
+ DEG_NODE_TYPE_SHADING,
+ function_bind(BKE_material_eval, _1, material_cow),
+ DEG_OPCODE_MATERIAL_UPDATE);
+ /* Material animation. */
+ build_animdata(material_id);
+ /* Textures. */
+ build_texture_stack(material->mtex);
+ /* Material's nodetree. */
+ build_nodetree(material->nodetree);
}
/* Texture-stack attached to some shading datablock */
@@ -1117,7 +1263,18 @@ void DepsgraphNodeBuilder::build_mask(Mask *mask)
{
ID *mask_id = &mask->id;
add_id_node(mask_id);
+ /* F-Curve based animation/ */
build_animdata(mask_id);
+ /* Animation based on mask's shapes. */
+ add_operation_node(mask_id,
+ DEG_NODE_TYPE_ANIMATION,
+ function_bind(BKE_mask_eval_animation, _1, mask),
+ DEG_OPCODE_MASK_ANIMATION);
+ /* Final mask evaluation. */
+ add_operation_node(mask_id,
+ DEG_NODE_TYPE_PARAMETERS,
+ function_bind(BKE_mask_eval_update, _1, mask),
+ DEG_OPCODE_MASK_EVAL);
}
void DepsgraphNodeBuilder::build_movieclip(MovieClip *clip)
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
index 54ad1bd5d8a..7e28df1276d 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;
@@ -71,11 +72,42 @@ struct DepsgraphNodeBuilder {
DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
~DepsgraphNodeBuilder();
- void begin_build(Main *bmain);
-
+ /* For given original ID get ID which is created by CoW system. */
ID *get_cow_id(const ID *id_orig) const;
+ /* Similar to above, but for the cases when there is no ID node we create
+ * one.
+ */
+ ID *ensure_cow_id(ID *id_orig);
+
+ /* Helper wrapper function which wraps get_cow_id with a needed type cast. */
+ template<typename T>
+ T *get_cow_datablock(const T *orig) const {
+ return (T *)get_cow_id(&orig->id);
+ }
+
+ /* Get fully expanded (ready for use) copy-on-write datablock for the given
+ * original datablock.
+ */
+ ID *expand_cow_id(IDDepsNode *id_node);
+ ID *expand_cow_id(ID *id_orig);
+ template<typename T>
+ T *expand_cow_datablock(T *orig) {
+ return (T *)expand_cow_id(&orig->id);
+ }
+
+ /* For a given COW datablock get corresponding original one. */
+ template<typename T>
+ T *get_orig_datablock(const T *cow) const {
+#ifdef WITH_COPY_ON_WRITE
+ return (T *)cow->id.newid;
+#else
+ return (T *)cow;
+#endif
+ }
+
+ void begin_build(Main *bmain);
- IDDepsNode *add_id_node(ID *id);
+ IDDepsNode *add_id_node(ID *id, bool do_tag = true);
TimeSourceDepsNode *add_time_source();
ComponentDepsNode *add_component_node(ID *id,
@@ -129,6 +161,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);
@@ -173,6 +206,7 @@ struct DepsgraphNodeBuilder {
protected:
Main *m_bmain;
Depsgraph *m_graph;
+ GHash *m_cow_id_hash;
};
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_layer.cc
index b6df176545e..b3a88d8ac4d 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_layer.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_layer.cc
@@ -24,7 +24,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc
+/** \file blender/depsgraph/intern/builder/deg_builder_nodes_layer.cc
* \ingroup depsgraph
*
* Methods for constructing depsgraph's nodes
@@ -98,9 +98,7 @@ void DepsgraphNodeBuilder::build_scene_layer_collections(Scene *scene)
{
#ifdef WITH_COPY_ON_WRITE
/* Make sure we've got ID node, so we can get pointer to CoW datablock. */
- IDDepsNode *id_node = add_id_node(&scene->id);
- Scene *scene_cow = (Scene *)deg_expand_copy_on_write_datablock(m_graph,
- id_node);
+ Scene *scene_cow = expand_cow_datablock(scene);
#else
Scene *scene_cow = scene;
#endif
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
index 51b27912298..d610dc51080 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
@@ -46,6 +46,7 @@ extern "C" {
#include "DNA_armature_types.h"
#include "DNA_constraint_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BKE_action.h"
#include "BKE_armature.h"
@@ -55,6 +56,7 @@ extern "C" {
#include "DEG_depsgraph_build.h"
#include "intern/builder/deg_builder.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_operation.h"
@@ -64,16 +66,25 @@ extern "C" {
namespace DEG {
-void DepsgraphNodeBuilder::build_pose_constraints(Scene *scene, Object *ob, bPoseChannel *pchan)
+void DepsgraphNodeBuilder::build_pose_constraints(Scene *scene,
+ Object *ob,
+ bPoseChannel *pchan)
{
/* create node for constraint stack */
add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name,
- function_bind(BKE_pose_constraints_evaluate, _1, scene, ob, pchan),
+ function_bind(BKE_pose_constraints_evaluate,
+ _1,
+ get_cow_datablock(scene),
+ get_cow_datablock(ob),
+ pchan),
DEG_OPCODE_BONE_CONSTRAINTS);
}
/* IK Solver Eval Steps */
-void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con)
+void DepsgraphNodeBuilder::build_ik_pose(Scene *scene,
+ Object *ob,
+ bPoseChannel *pchan,
+ bConstraint *con)
{
bKinematicConstraint *data = (bKinematicConstraint *)con->data;
@@ -88,12 +99,18 @@ void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, Object *ob, bPoseChannel
/* Operation node for evaluating/running IK Solver. */
add_operation_node(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name,
- function_bind(BKE_pose_iktree_evaluate, _1, scene, ob, rootchan),
+ function_bind(BKE_pose_iktree_evaluate, _1,
+ get_cow_datablock(scene),
+ get_cow_datablock(ob),
+ rootchan),
DEG_OPCODE_POSE_IK_SOLVER);
}
/* Spline IK Eval Steps */
-void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con)
+void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene,
+ Object *ob,
+ bPoseChannel *pchan,
+ bConstraint *con)
{
bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
@@ -101,30 +118,51 @@ void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, Object *ob, bPoseCh
bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data);
/* Operation node for evaluating/running Spline IK Solver.
- * Store the "root bone" of this chain in the solver, so it knows where to start.
+ * Store the "root bone" of this chain in the solver, so it knows where to
+ * start.
*/
add_operation_node(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name,
- function_bind(BKE_pose_splineik_evaluate, _1, scene, ob, rootchan),
+ function_bind(BKE_pose_splineik_evaluate,
+ _1,
+ get_cow_datablock(scene),
+ get_cow_datablock(ob),
+ rootchan),
DEG_OPCODE_POSE_SPLINE_IK_SOLVER);
}
/* Pose/Armature Bones Graph */
-void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob)
+void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *object)
{
- bArmature *arm = (bArmature *)ob->data;
+ bArmature *armature = (bArmature *)object->data;
+ const short armature_tag = armature->id.tag;
+#ifdef WITH_COPY_ON_WRITE
+ /* NOTE: We need to expand both object and armature, so this way we can
+ * safely create object level pose.
+ */
+ Scene *scene_cow = get_cow_datablock(scene);
+ Object *object_cow = expand_cow_datablock(object);
+ bArmature *armature_cow = expand_cow_datablock(armature);
+#else
+ Scene *scene_cow = scene;
+ Object *object_cow = object;
+ bArmature *armature_cow = armature;
+#endif
OperationDepsNode *op_node;
- /* animation and/or drivers linking posebones to base-armature used to define them
+ /* Animation and/or drivers linking posebones to base-armature used to
+ * define them.
+ *
* NOTE: AnimData here is really used to control animated deform properties,
- * which ideally should be able to be unique across different instances.
- * Eventually, we need some type of proxy/isolation mechanism in-between here
- * to ensure that we can use same rig multiple times in same scene...
+ * which ideally should be able to be unique across different
+ * instances. Eventually, we need some type of proxy/isolation
+ * mechanism in-between here to ensure that we can use same rig
+ * multiple times in same scene.
*/
- if ((arm->id.tag & LIB_TAG_DOIT) == 0) {
- build_animdata(&arm->id);
+ if ((armature_tag & LIB_TAG_DOIT) == 0) {
+ build_animdata(&armature->id);
/* Make sure pose is up-to-date with armature updates. */
- add_operation_node(&arm->id,
+ add_operation_node(&armature->id,
DEG_NODE_TYPE_PARAMETERS,
NULL,
DEG_OPCODE_PLACEHOLDER,
@@ -132,22 +170,22 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob)
}
/* Rebuild pose if not up to date. */
- if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC)) {
- BKE_pose_rebuild(ob, arm);
+ if (object_cow->pose == NULL || (object->pose->flag & POSE_RECALC)) {
+ BKE_pose_rebuild(object_cow, armature_cow);
/* XXX: Without this animation gets lost in certain circumstances
* after loading file. Need to investigate further since it does
* not happen with simple scenes..
*/
- if (ob->adt) {
- ob->adt->recalc |= ADT_RECALC_ANIM;
+ if (object_cow->adt) {
+ object_cow->adt->recalc |= ADT_RECALC_ANIM;
}
}
/* speed optimization for animation lookups */
- if (ob->pose) {
- BKE_pose_channels_hash_make(ob->pose);
- if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
- BKE_pose_update_constraint_flags(ob->pose);
+ if (object_cow->pose != NULL) {
+ BKE_pose_channels_hash_make(object_cow->pose);
+ if (object_cow->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
+ BKE_pose_update_constraint_flags(object_cow->pose);
}
}
@@ -168,74 +206,99 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob)
* - Used for representing each bone within the rig
* - Acts to encapsulate the evaluation operations (base matrix + parenting,
* and constraint stack) so that they can be easily found.
- * - Everything else which depends on bone-results hook up to the component only
- * so that we can redirect those to point at either the the post-IK/
+ * - Everything else which depends on bone-results hook up to the component
+ * only so that we can redirect those to point at either the the post-IK/
* post-constraint/post-matrix steps, as needed.
*/
/* pose eval context */
- op_node = add_operation_node(&ob->id,
+ op_node = add_operation_node(&object->id,
DEG_NODE_TYPE_EVAL_POSE,
- function_bind(BKE_pose_eval_init, _1, scene, ob, ob->pose),
+ function_bind(BKE_pose_eval_init,
+ _1,
+ scene_cow,
+ object_cow,
+ object_cow->pose),
DEG_OPCODE_POSE_INIT);
op_node->set_as_entry();
- op_node = add_operation_node(&ob->id,
+ op_node = add_operation_node(&object->id,
DEG_NODE_TYPE_EVAL_POSE,
- function_bind(BKE_pose_eval_flush, _1, scene, ob, ob->pose),
+ function_bind(BKE_pose_eval_init_ik,
+ _1,
+ scene_cow,
+ object_cow,
+ object_cow->pose),
+ DEG_OPCODE_POSE_INIT_IK);
+
+ op_node = add_operation_node(&object->id,
+ DEG_NODE_TYPE_EVAL_POSE,
+ function_bind(BKE_pose_eval_flush,
+ _1,
+ scene_cow,
+ object_cow,
+ object_cow->pose),
DEG_OPCODE_POSE_DONE);
op_node->set_as_exit();
/* bones */
- LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
+ LINKLIST_FOREACH (bPoseChannel *, pchan, &object_cow->pose->chanbase) {
/* node for bone eval */
- op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, NULL,
- DEG_OPCODE_BONE_LOCAL);
+ op_node = add_operation_node(&object->id, DEG_NODE_TYPE_BONE,
+ pchan->name, NULL, DEG_OPCODE_BONE_LOCAL);
op_node->set_as_entry();
- add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name,
- function_bind(BKE_pose_eval_bone, _1, scene, ob, pchan),
+ add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
+ function_bind(BKE_pose_eval_bone, _1,
+ scene_cow,
+ object_cow,
+ pchan),
DEG_OPCODE_BONE_POSE_PARENT);
- add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name,
- NULL, /* NOTE: dedicated noop for easier relationship construction */
+ /* NOTE: Dedicated noop for easier relationship construction. */
+ add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
+ NULL,
DEG_OPCODE_BONE_READY);
- op_node = add_operation_node(&ob->id, DEG_NODE_TYPE_BONE, pchan->name,
+ op_node = add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
function_bind(BKE_pose_bone_done, _1, pchan),
DEG_OPCODE_BONE_DONE);
op_node->set_as_exit();
-
- /* constraints */
+ /* Build constraints. */
if (pchan->constraints.first != NULL) {
- build_pose_constraints(scene, ob, pchan);
+ build_pose_constraints(scene, object, pchan);
}
-
/**
- * IK Solvers...
+ * IK Solvers.
*
* - These require separate processing steps are pose-level
* to be executed between chains of bones (i.e. once the
* base transforms of a bunch of bones is done)
*
* Unsolved Issues:
- * - Care is needed to ensure that multi-headed trees work out the same as in ik-tree building
- * - Animated chain-lengths are a problem...
+ * - Care is needed to ensure that multi-headed trees work out the same
+ * as in ik-tree building
+ * - Animated chain-lengths are a problem.
*/
LINKLIST_FOREACH (bConstraint *, con, &pchan->constraints) {
switch (con->type) {
case CONSTRAINT_TYPE_KINEMATIC:
- build_ik_pose(scene, ob, pchan, con);
+ build_ik_pose(scene, object, pchan, con);
break;
case CONSTRAINT_TYPE_SPLINEIK:
- build_splineik_pose(scene, ob, pchan, con);
+ build_splineik_pose(scene, object, pchan, con);
break;
default:
break;
}
}
+ /* Custom shape. */
+ /* NOTE: Custom shape datablock is already remapped to CoW version. */
+ if (pchan->custom != NULL) {
+ build_object(scene, get_orig_datablock(pchan->custom));
+ }
}
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc
index f24d4e8d3f2..a8acc88f7f3 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc
@@ -89,6 +89,9 @@ void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene)
base->object->select_color = select_color++;
}
}
+ if (scene->camera != NULL) {
+ build_object(scene, scene->camera);
+ }
/* rigidbody */
if (scene->rigidbody_world) {
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 006358ea9e1..0c5150f2f42 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -324,7 +324,7 @@ void DepsgraphRelationBuilder::add_collision_relations(const OperationKey &key,
void DepsgraphRelationBuilder::add_forcefield_relations(const OperationKey &key, Scene *scene, Object *ob, ParticleSystem *psys, EffectorWeights *eff, bool add_absorption, const char *name)
{
- ListBase *effectors = pdInitEffectors(scene, ob, psys, eff, false);
+ ListBase *effectors = pdInitEffectors(NULL, scene, ob, psys, eff, false);
if (effectors) {
for (EffectorCache *eff = (EffectorCache *)effectors->first; eff; eff = eff->next) {
@@ -343,7 +343,7 @@ void DepsgraphRelationBuilder::add_forcefield_relations(const OperationKey &key,
add_relation(mod_key, key, name);
}
else if (eff->psys != psys) {
- OperationKey eff_key(&eff->ob->id, DEG_NODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, eff->psys->name);
+ OperationKey eff_key(&eff->ob->id, DEG_NODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PARTICLE_SYSTEM_EVAL, eff->psys->name);
add_relation(eff_key, key, name);
}
}
@@ -423,7 +423,7 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o
OperationKey parent_transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT);
OperationKey final_transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
- OperationKey ob_ubereval_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_OBJECT_UBEREVAL);
+ OperationKey ob_ubereval_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
/* parenting */
if (ob->parent != NULL) {
@@ -521,7 +521,7 @@ void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *o
build_proxy_rig(ob);
}
else {
- build_rig(scene, ob);
+ build_rig(bmain, scene, ob);
}
break;
@@ -666,58 +666,74 @@ void DepsgraphRelationBuilder::build_object_parent(Object *ob)
}
}
-void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode_Type component_type, const char *component_subdata,
- ListBase *constraints, RootPChanMap *root_map)
+void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id,
+ eDepsNode_Type component_type,
+ const char *component_subdata,
+ ListBase *constraints,
+ RootPChanMap *root_map)
{
- OperationKey constraint_op_key(id, component_type, component_subdata,
- (component_type == DEG_NODE_TYPE_BONE) ? DEG_OPCODE_BONE_CONSTRAINTS : DEG_OPCODE_TRANSFORM_CONSTRAINTS);
-
- /* add dependencies for each constraint in turn */
+ OperationKey constraint_op_key(
+ id,
+ component_type,
+ component_subdata,
+ (component_type == DEG_NODE_TYPE_BONE)
+ ? DEG_OPCODE_BONE_CONSTRAINTS
+ : DEG_OPCODE_TRANSFORM_CONSTRAINTS);
+ /* Add dependencies for each constraint in turn. */
for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
-
- /* invalid constraint type... */
- if (cti == NULL)
+ /* Invalid constraint type. */
+ if (cti == NULL) {
continue;
-
- /* special case for camera tracking -- it doesn't use targets to define relations */
- // TODO: we can now represent dependencies in a much richer manner, so review how this is done...
- if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, CONSTRAINT_TYPE_OBJECTSOLVER)) {
+ }
+ /* Special case for camera tracking -- it doesn't use targets to
+ * define relations.
+ */
+ /* TODO: we can now represent dependencies in a much richer manner,
+ * so review how this is done.
+ */
+ if (ELEM(cti->type,
+ CONSTRAINT_TYPE_FOLLOWTRACK,
+ CONSTRAINT_TYPE_CAMERASOLVER,
+ CONSTRAINT_TYPE_OBJECTSOLVER))
+ {
bool depends_on_camera = false;
-
if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
-
- if (((data->clip) || (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0])
+ if (((data->clip) ||
+ (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0])
+ {
depends_on_camera = true;
-
+ }
if (data->depth_ob) {
- // DAG_RL_DATA_OB | DAG_RL_OB_OB
- ComponentKey depth_key(&data->depth_ob->id, DEG_NODE_TYPE_TRANSFORM);
- add_relation(depth_key, constraint_op_key, cti->name);
+ ComponentKey depth_transform_key(&data->depth_ob->id,
+ DEG_NODE_TYPE_TRANSFORM);
+ ComponentKey depth_geometry_key(&data->depth_ob->id,
+ DEG_NODE_TYPE_GEOMETRY);
+ add_relation(depth_transform_key, constraint_op_key, cti->name);
+ add_relation(depth_geometry_key, constraint_op_key, cti->name);
}
}
else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
depends_on_camera = true;
}
-
if (depends_on_camera && scene->camera) {
- // DAG_RL_DATA_OB | DAG_RL_OB_OB
ComponentKey camera_key(&scene->camera->id, DEG_NODE_TYPE_TRANSFORM);
add_relation(camera_key, constraint_op_key, cti->name);
}
-
- /* TODO(sergey): This is more a TimeSource -> MovieClip -> Constraint dependency chain. */
+ /* TODO(sergey): This is more a TimeSource -> MovieClip ->
+ * Constraint dependency chain.
+ */
TimeSourceKey time_src_key;
add_relation(time_src_key, constraint_op_key, "[TimeSrc -> Animation]");
}
else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
- /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint dependency chain. */
+ /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint
+ * dependency chain.
+ */
TimeSourceKey time_src_key;
add_relation(time_src_key, constraint_op_key, "[TimeSrc -> Animation]");
-
bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data;
-
if (data->cache_file) {
ComponentKey cache_key(&data->cache_file->id, DEG_NODE_TYPE_CACHE);
add_relation(cache_key, constraint_op_key, cti->name);
@@ -726,52 +742,73 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
else if (cti->get_constraint_targets) {
ListBase targets = {NULL, NULL};
cti->get_constraint_targets(con, &targets);
-
LINKLIST_FOREACH (bConstraintTarget *, ct, &targets) {
if (ct->tar == NULL) {
continue;
}
-
- if (ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK)) {
- /* ignore IK constraints - these are handled separately (on pose level) */
+ if (ELEM(con->type,
+ CONSTRAINT_TYPE_KINEMATIC,
+ CONSTRAINT_TYPE_SPLINEIK))
+ {
+ /* Ignore IK constraints - these are handled separately
+ * (on pose level).
+ */
}
- else if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO)) {
- /* these constraints require path geometry data... */
+ else if (ELEM(con->type,
+ CONSTRAINT_TYPE_FOLLOWPATH,
+ CONSTRAINT_TYPE_CLAMPTO))
+ {
+ /* These constraints require path geometry data. */
ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
- add_relation(target_key, constraint_op_key, cti->name); // XXX: type = geom_transform
- // TODO: path dependency
+ add_relation(target_key, constraint_op_key, cti->name);
+ ComponentKey target_transform_key(&ct->tar->id,
+ DEG_NODE_TYPE_TRANSFORM);
+ add_relation(target_transform_key, constraint_op_key, cti->name);
}
else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) {
/* bone */
if (&ct->tar->id == id) {
/* same armature */
eDepsOperation_Code target_key_opcode;
-
- /* Using "done" here breaks in-chain deps, while using "ready" here breaks most production rigs instead...
- * So, we do a compromise here, and only do this when an IK chain conflict may occur
+ /* Using "done" here breaks in-chain deps, while using
+ * "ready" here breaks most production rigs instead.
+ * So, we do a compromise here, and only do this when an
+ * IK chain conflict may occur.
*/
- if (root_map->has_common_root(component_subdata, ct->subtarget)) {
+ if (root_map->has_common_root(component_subdata,
+ ct->subtarget))
+ {
target_key_opcode = DEG_OPCODE_BONE_READY;
}
else {
target_key_opcode = DEG_OPCODE_BONE_DONE;
}
-
- OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_BONE, ct->subtarget, target_key_opcode);
+ OperationKey target_key(&ct->tar->id,
+ DEG_NODE_TYPE_BONE,
+ ct->subtarget,
+ target_key_opcode);
add_relation(target_key, constraint_op_key, cti->name);
}
else {
- /* different armature - we can safely use the result of that */
- OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_BONE, ct->subtarget, DEG_OPCODE_BONE_DONE);
+ /* Different armature - we can safely use the result
+ * of that.
+ */
+ OperationKey target_key(&ct->tar->id,
+ DEG_NODE_TYPE_BONE,
+ ct->subtarget,
+ DEG_OPCODE_BONE_DONE);
add_relation(target_key, constraint_op_key, cti->name);
}
}
- else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) {
- /* vertex group */
- /* NOTE: for now, we don't need to represent vertex groups separately... */
+ else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) &&
+ (ct->subtarget[0]))
+ {
+ /* Vertex group. */
+ /* NOTE: for now, we don't need to represent vertex groups
+ * separately.
+ */
ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
add_relation(target_key, constraint_op_key, cti->name);
-
if (ct->tar->type == OB_MESH) {
OperationDepsNode *node2 = find_operation_node(target_key);
if (node2 != NULL) {
@@ -783,37 +820,48 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
/* Constraints which requires the target object surface. */
ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
add_relation(target_key, constraint_op_key, cti->name);
-
- /* NOTE: obdata eval now doesn't necessarily depend on the object's transform... */
- ComponentKey target_transform_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM);
+ /* NOTE: obdata eval now doesn't necessarily depend on the
+ * object's transform.
+ */
+ ComponentKey target_transform_key(&ct->tar->id,
+ DEG_NODE_TYPE_TRANSFORM);
add_relation(target_transform_key, constraint_op_key, cti->name);
}
else {
- /* standard object relation */
+ /* Standard object relation. */
// TODO: loc vs rot vs scale?
if (&ct->tar->id == id) {
/* Constraint targetting own object:
- * - This case is fine IFF we're dealing with a bone constraint pointing to
- * its own armature. In that case, it's just transform -> bone.
- * - If however it is a real self targetting case, just make it depend on the
- * previous constraint (or the pre-constraint state)...
+ * - This case is fine IFF we're dealing with a bone
+ * constraint pointing to its own armature. In that
+ * case, it's just transform -> bone.
+ * - If however it is a real self targetting case, just
+ * make it depend on the previous constraint (or the
+ * pre-constraint state).
*/
- if ((ct->tar->type == OB_ARMATURE) && (component_type == DEG_NODE_TYPE_BONE)) {
- OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
+ if ((ct->tar->type == OB_ARMATURE) &&
+ (component_type == DEG_NODE_TYPE_BONE))
+ {
+ OperationKey target_key(&ct->tar->id,
+ DEG_NODE_TYPE_TRANSFORM,
+ DEG_OPCODE_TRANSFORM_FINAL);
add_relation(target_key, constraint_op_key, cti->name);
}
else {
- OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL);
+ OperationKey target_key(&ct->tar->id,
+ DEG_NODE_TYPE_TRANSFORM,
+ DEG_OPCODE_TRANSFORM_LOCAL);
add_relation(target_key, constraint_op_key, cti->name);
}
}
else {
- /* normal object dependency */
- OperationKey target_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
+ /* Normal object dependency. */
+ OperationKey target_key(&ct->tar->id,
+ DEG_NODE_TYPE_TRANSFORM,
+ DEG_OPCODE_TRANSFORM_FINAL);
add_relation(target_key, constraint_op_key, cti->name);
}
}
-
/* Constraints which needs world's matrix for transform.
* TODO(sergey): More constraints here?
*/
@@ -824,14 +872,14 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
CONSTRAINT_TYPE_TRANSLIKE))
{
/* TODO(sergey): Add used space check. */
- ComponentKey target_transform_key(&ct->tar->id, DEG_NODE_TYPE_TRANSFORM);
+ ComponentKey target_transform_key(&ct->tar->id,
+ DEG_NODE_TYPE_TRANSFORM);
add_relation(target_transform_key, constraint_op_key, cti->name);
}
-
}
-
- if (cti->flush_constraint_targets)
+ if (cti->flush_constraint_targets) {
cti->flush_constraint_targets(con, &targets, 1);
+ }
}
}
}
@@ -929,32 +977,35 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
fcu->rna_path ? fcu->rna_path : "",
fcu->array_index);
bPoseChannel *pchan = NULL;
-
const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
+ const ID_Type id_type = GS(id->name);
- /* create dependency between driver and data affected by it */
+ /* Create dependency between driver and data affected by it. */
/* - direct property relationship... */
//RNAPathKey affected_key(id, fcu->rna_path);
//add_relation(driver_key, affected_key, "[Driver -> Data] DepsRel");
- /* driver -> data components (for interleaved evaluation - bones/constraints/modifiers) */
- // XXX: this probably should probably be moved out into a separate function
+ /* Driver -> data components (for interleaved evaluation
+ * bones/constraints/modifiers).
+ */
+ // XXX: this probably should probably be moved out into a separate function.
if (strstr(rna_path, "pose.bones[") != NULL) {
/* interleaved drivers during bone eval */
- // TODO: ideally, if this is for a constraint, it goes to said constraint
+ /* TODO: ideally, if this is for a constraint, it goes to said
+ * constraint.
+ */
Object *ob = (Object *)id;
- char *bone_name;
-
- bone_name = BLI_str_quoted_substrN(rna_path, "pose.bones[");
+ char *bone_name = BLI_str_quoted_substrN(rna_path, "pose.bones[");
pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
-
- if (bone_name) {
+ if (bone_name != NULL) {
MEM_freeN(bone_name);
bone_name = NULL;
}
-
- if (pchan) {
- OperationKey bone_key(id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL);
+ if (pchan != NULL) {
+ OperationKey bone_key(id,
+ DEG_NODE_TYPE_BONE,
+ pchan->name,
+ DEG_OPCODE_BONE_LOCAL);
add_relation(driver_key, bone_key, "[Driver -> Bone]");
}
else {
@@ -963,31 +1014,36 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
rna_path);
}
}
- else if (GS(id->name) == ID_AR && strstr(rna_path, "bones[")) {
- /* drivers on armature-level bone settings (i.e. bbone stuff),
- * which will affect the evaluation of corresponding pose bones
+ else if (id_type == ID_AR && strstr(rna_path, "bones[")) {
+ /* Drivers on armature-level bone settings (i.e. bbone stuff),
+ * which will affect the evaluation of corresponding pose bones.
*/
IDDepsNode *arm_node = m_graph->find_id_node(id);
char *bone_name = BLI_str_quoted_substrN(rna_path, "bones[");
-
- if (arm_node && bone_name) {
- /* find objects which use this, and make their eval callbacks depend on this */
+ if (arm_node != NULL && bone_name != NULL) {
+ /* Find objects which use this, and make their eval callbacks
+ * depend on this.
+ */
foreach (DepsRelation *rel, arm_node->outlinks) {
IDDepsNode *to_node = (IDDepsNode *)rel->to;
-
- /* we only care about objects with pose data which use this... */
+ /* We only care about objects with pose data which use this. */
if (GS(to_node->id_orig->name) == ID_OB) {
Object *ob = (Object *)to_node->id_orig;
- bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name); // NOTE: ob->pose may be NULL
-
- if (pchan) {
- OperationKey bone_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL);
- add_relation(driver_key, bone_key, "[Arm Bone -> Driver -> Bone]");
+ // NOTE: ob->pose may be NULL
+ bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose,
+ bone_name);
+ if (pchan != NULL) {
+ OperationKey bone_key(&ob->id,
+ DEG_NODE_TYPE_BONE,
+ pchan->name,
+ DEG_OPCODE_BONE_LOCAL);
+ add_relation(driver_key,
+ bone_key,
+ "[Arm Bone -> Driver -> Bone]");
}
}
}
-
- /* free temp data */
+ /* Free temp data. */
MEM_freeN(bone_name);
bone_name = NULL;
}
@@ -997,8 +1053,10 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
rna_path);
}
}
- else if (GS(id->name) == ID_OB && strstr(rna_path, "modifiers[")) {
- OperationKey modifier_key(id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL);
+ else if (id_type == ID_OB && strstr(rna_path, "modifiers[")) {
+ OperationKey modifier_key(id,
+ DEG_NODE_TYPE_GEOMETRY,
+ DEG_OPCODE_GEOMETRY_UBEREVAL);
if (has_node(modifier_key)) {
add_relation(driver_key, modifier_key, "[Driver -> Modifier]");
}
@@ -1006,11 +1064,10 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
printf("Unexisting driver RNA path: %s\n", rna_path);
}
}
- else if (GS(id->name) == ID_KE && strstr(rna_path, "key_blocks[")) {
- /* shape key driver - hook into the base geometry operation */
+ else if (id_type == ID_KE && strstr(rna_path, "key_blocks[")) {
+ /* Shape key driver - hook into the base geometry operation. */
// XXX: double check where this points
Key *shape_key = (Key *)id;
-
ComponentKey geometry_key(shape_key->from, DEG_NODE_TYPE_GEOMETRY);
add_relation(driver_key, geometry_key, "[Driver -> ShapeKey Geom]");
}
@@ -1019,35 +1076,62 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
add_relation(driver_key, geometry_key, "[Driver -> ShapeKey Geom]");
}
else {
- if (GS(id->name) == ID_OB) {
- /* assume that driver affects a transform... */
- OperationKey local_transform_key(id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL);
- add_relation(driver_key, local_transform_key, "[Driver -> Transform]");
- }
- else if (GS(id->name) == ID_KE) {
- ComponentKey geometry_key(id, DEG_NODE_TYPE_GEOMETRY);
- add_relation(driver_key, geometry_key, "[Driver -> Shapekey Geometry]");
+ switch (id_type) {
+ case ID_OB:
+ {
+ /* Assume that driver affects a transform. */
+ OperationKey local_transform_key(id,
+ DEG_NODE_TYPE_TRANSFORM,
+ DEG_OPCODE_TRANSFORM_LOCAL);
+ add_relation(driver_key,
+ local_transform_key,
+ "[Driver -> Transform]");
+ break;
+ }
+ case ID_KE:
+ {
+ ComponentKey geometry_key(id, DEG_NODE_TYPE_GEOMETRY);
+ add_relation(driver_key,
+ geometry_key,
+ "[Driver -> Shapekey Geometry]");
+ break;
+ }
+ case ID_NT:
+ {
+ ComponentKey ntree_key(id, DEG_NODE_TYPE_SHADING);
+ add_relation(driver_key,
+ ntree_key,
+ "[Driver -> NTree Shading Update]");
+ break;
+ }
+ default:
+ break;
}
}
-
- /* ensure that affected prop's update callbacks will be triggered once done */
- // TODO: implement this once the functionality to add these links exists in RNA
- // XXX: the data itself could also set this, if it were to be truly initialised later?
-
- /* loop over variables to get the target relationships */
+ /* Ensure that affected prop's update callbacks will be triggered once
+ * done.
+ */
+ /* TODO: Implement this once the functionality to add these links exists
+ * RNA.
+ */
+ /* XXX: the data itself could also set this, if it were to be truly
+ * initialised later?
+ */
+ /* Loop over variables to get the target relationships. */
LINKLIST_FOREACH (DriverVar *, dvar, &driver->variables) {
- /* only used targets */
+ /* Only used targets. */
DRIVER_TARGETS_USED_LOOPER(dvar)
{
- if (dtar->id == NULL)
+ if (dtar->id == NULL) {
continue;
-
- /* special handling for directly-named bones */
+ }
+ /* Special handling for directly-named bones. */
if ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) {
Object *ob = (Object *)dtar->id;
- bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
+ bPoseChannel *target_pchan =
+ BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
if (target_pchan != NULL) {
- /* get node associated with bone */
+ /* Get node associated with bone. */
// XXX: watch the space!
/* Some cases can't use final bone transform, for example:
* - Driving the bone with itself (addressed here)
@@ -1059,55 +1143,75 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
{
continue;
}
- OperationKey target_key(dtar->id, DEG_NODE_TYPE_BONE, target_pchan->name, DEG_OPCODE_BONE_DONE);
- add_relation(target_key, driver_key, "[Bone Target -> Driver]");
+ OperationKey target_key(dtar->id,
+ DEG_NODE_TYPE_BONE,
+ target_pchan->name,
+ DEG_OPCODE_BONE_DONE);
+ add_relation(target_key,
+ driver_key,
+ "[Bone Target -> Driver]");
}
}
else if (dtar->flag & DTAR_FLAG_STRUCT_REF) {
- /* get node associated with the object's transforms */
- OperationKey target_key(dtar->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
+ /* Get node associated with the object's transforms. */
+ if (dtar->id == id) {
+ /* Ignore input dependency if we're driving properties of
+ * the same ID, otherwise we'll be ending up in a cyclic
+ * dependency here.
+ */
+ continue;
+ }
+ OperationKey target_key(dtar->id,
+ DEG_NODE_TYPE_TRANSFORM,
+ DEG_OPCODE_TRANSFORM_FINAL);
add_relation(target_key, driver_key, "[Target -> Driver]");
}
else if (dtar->rna_path && strstr(dtar->rna_path, "pose.bones[")) {
- /* workaround for ensuring that local bone transforms don't end up
- * having to wait for pose eval to finish (to prevent cycles)
+ /* Workaround for ensuring that local bone transforms don't end
+ * up having to wait for pose eval to finish (to prevent cycles).
*/
Object *ob = (Object *)dtar->id;
- char *bone_name = BLI_str_quoted_substrN(dtar->rna_path, "pose.bones[");
- bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
- if (bone_name) {
+ char *bone_name = BLI_str_quoted_substrN(dtar->rna_path,
+ "pose.bones[");
+ bPoseChannel *target_pchan =
+ BKE_pose_channel_find_name(ob->pose, bone_name);
+ if (bone_name != NULL) {
MEM_freeN(bone_name);
bone_name = NULL;
}
- if (target_pchan) {
+ if (target_pchan != NULL) {
if (dtar->id == id &&
pchan != NULL &&
STREQ(pchan->name, target_pchan->name))
{
continue;
}
- OperationKey bone_key(dtar->id, DEG_NODE_TYPE_BONE, target_pchan->name, DEG_OPCODE_BONE_LOCAL);
+ OperationKey bone_key(dtar->id,
+ DEG_NODE_TYPE_BONE,
+ target_pchan->name,
+ DEG_OPCODE_BONE_LOCAL);
add_relation(bone_key, driver_key, "[RNA Bone -> Driver]");
}
}
else {
if (dtar->id == id) {
- /* Ignore input dependency if we're driving properties of the same ID,
- * otherwise we'll be ending up in a cyclic dependency here.
+ /* Ignore input dependency if we're driving properties of
+ * the same ID, otherwise we'll be ending up in a cyclic
+ * dependency here.
*/
continue;
}
- /* resolve path to get node */
- RNAPathKey target_key(dtar->id, dtar->rna_path ? dtar->rna_path : "");
+ /* Resolve path to get node. */
+ RNAPathKey target_key(dtar->id,
+ dtar->rna_path ? dtar->rna_path : "");
add_relation(target_key, driver_key, "[RNA Target -> Driver]");
}
}
DRIVER_TARGETS_LOOPER_END
}
-
- /* It's quite tricky to detect if the driver actually depends on time or not,
- * so for now we'll be quite conservative here about optimization and consider
- * all python drivers to be depending on time.
+ /* It's quite tricky to detect if the driver actually depends on time or
+ * not, so for now we'll be quite conservative here about optimization and
+ * consider all python drivers to be depending on time.
*/
if ((driver->type == DRIVER_TYPE_PYTHON) &&
python_driver_depends_on_time(driver))
@@ -1135,9 +1239,9 @@ void DepsgraphRelationBuilder::build_world(World *world)
/* world's nodetree */
if (world->nodetree != NULL) {
build_nodetree(world->nodetree);
- ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
- ComponentKey world_key(world_id, DEG_NODE_TYPE_PARAMETERS);
- add_relation(ntree_key, world_key, "NTree->World Parameters");
+ ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_SHADING);
+ ComponentKey world_key(world_id, DEG_NODE_TYPE_SHADING);
+ add_relation(ntree_key, world_key, "NTree->World Shading Update");
}
}
@@ -1173,7 +1277,7 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
* XXX: there's probably a difference between passive and active
* - passive don't change, so may need to know full transform...
*/
- OperationKey rbo_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY);
+ OperationKey rbo_key(&ob->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
eDepsOperation_Code trans_opcode = ob->parent ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL;
OperationKey trans_op(&ob->id, DEG_NODE_TYPE_TRANSFORM, trans_opcode);
@@ -1202,7 +1306,7 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
*/
OperationKey uber_key(&ob->id,
DEG_NODE_TYPE_TRANSFORM,
- DEG_OPCODE_OBJECT_UBEREVAL);
+ DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
add_relation(rbo_key, uber_key, "RBO Sync -> Uber (Temp)");
}
@@ -1225,8 +1329,8 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
* constraint affects the physics sim for these objects
*/
ComponentKey trans_key(&ob->id, DEG_NODE_TYPE_TRANSFORM);
- OperationKey ob1_key(&rbc->ob1->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY);
- OperationKey ob2_key(&rbc->ob2->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY);
+ OperationKey ob1_key(&rbc->ob1->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
+ OperationKey ob2_key(&rbc->ob2->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
/* - constrained-objects sync depends on the constraint-holder */
add_relation(trans_key, ob1_key, "RigidBodyConstraint -> RBC.Object_1");
@@ -1244,25 +1348,53 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob)
OperationKey obdata_ubereval_key(&ob->id,
DEG_NODE_TYPE_GEOMETRY,
DEG_OPCODE_GEOMETRY_UBEREVAL);
+ OperationKey eval_init_key(&ob->id,
+ DEG_NODE_TYPE_EVAL_PARTICLES,
+ DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
+ /* TODO(sergey): Are all particle systems depends on time?
+ * Hair without dynamics i.e.
+ */
+ add_relation(time_src_key, eval_init_key, "TimeSrc -> PSys");
/* particle systems */
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_PSYS_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 particle_settings_recalc_clear_key(
+ &part->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ DEG_OPCODE_PARTICLE_SETTINGS_RECALC_CLEAR);
+ 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");
+ add_relation(psys_key,
+ particle_settings_recalc_clear_key,
+ "Particle Settings Recalc Clear");
/* XXX: if particle system is later re-enabled, we must do full rebuild? */
if (!psys_check_enabled(ob, psys, G.is_rendering))
continue;
- /* TODO(sergey): Are all particle systems depends on time?
- * Hair without dynamics i.e.
- */
- add_relation(time_src_key, psys_key, "TimeSrc -> PSys");
+ add_relation(eval_init_key, psys_key, "Init -> PSys");
/* TODO(sergey): Currently particle update is just a placeholder,
* hook it to the ubereval node so particle system is getting updated
@@ -1272,14 +1404,33 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob)
/* collisions */
if (part->type != PART_HAIR) {
- add_collision_relations(psys_key, scene, ob, part->collision_group, true, "Particle Collision");
+ add_collision_relations(psys_key,
+ scene,
+ ob,
+ part->collision_group,
+ true,
+ "Particle Collision");
}
- else if ((psys->flag & PSYS_HAIR_DYNAMICS) && psys->clmd && psys->clmd->coll_parms) {
- add_collision_relations(psys_key, scene, ob, psys->clmd->coll_parms->group, true, "Hair Collision");
+ else if ((psys->flag & PSYS_HAIR_DYNAMICS) &&
+ psys->clmd != NULL &&
+ psys->clmd->coll_parms != NULL)
+ {
+ add_collision_relations(psys_key,
+ scene,
+ ob,
+ psys->clmd->coll_parms->group,
+ true,
+ "Hair Collision");
}
/* 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 +1465,27 @@ 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);
+
+ OperationKey eval_key(part_id,
+ DEG_NODE_TYPE_PARAMETERS,
+ DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
+ OperationKey recalc_clear_key(part_id,
+ DEG_NODE_TYPE_PARAMETERS,
+ DEG_OPCODE_PARTICLE_SETTINGS_RECALC_CLEAR);
+ add_relation(eval_key, recalc_clear_key, "Particle Settings Clear Recalc");
}
void DepsgraphRelationBuilder::build_cloth(Scene * /*scene*/,
@@ -1448,6 +1618,14 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje
Material *ma = give_current_material(ob, a);
if (ma != NULL) {
build_material(ma);
+
+ if (ob->type == OB_MESH) {
+ OperationKey material_key(&ma->id,
+ DEG_NODE_TYPE_SHADING,
+ DEG_OPCODE_MATERIAL_UPDATE);
+ OperationKey shading_key(&ob->id, DEG_NODE_TYPE_SHADING, DEG_OPCODE_SHADING);
+ add_relation(material_key, shading_key, "Material Update");
+ }
}
}
}
@@ -1480,6 +1658,19 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje
/* type-specific node/links */
switch (ob->type) {
case OB_MESH:
+ /* NOTE: This is compatibility code to support particle systems
+ *
+ * for viewport being properly rendered in final render mode.
+ * This relation is similar to what dag_object_time_update_flags()
+ * was doing for mesh objects with particle system/
+ *
+ * Ideally we need to get rid of this relation.
+ */
+ if (ob->particlesystem.first != NULL) {
+ TimeSourceKey time_key;
+ OperationKey obdata_ubereval_key(&ob->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL);
+ add_relation(time_key, obdata_ubereval_key, "Legacy particle time");
+ }
break;
case OB_MBALL:
@@ -1563,18 +1754,21 @@ void DepsgraphRelationBuilder::build_camera(Object *ob)
}
camera_id->tag |= LIB_TAG_DOIT;
- ComponentKey parameters_key(camera_id, DEG_NODE_TYPE_PARAMETERS);
+ ComponentKey object_parameters_key(&ob->id, DEG_NODE_TYPE_PARAMETERS);
+ ComponentKey camera_parameters_key(camera_id, DEG_NODE_TYPE_PARAMETERS);
+
+ add_relation(camera_parameters_key, object_parameters_key,
+ "Camera -> Object");
if (needs_animdata_node(camera_id)) {
ComponentKey animation_key(camera_id, DEG_NODE_TYPE_ANIMATION);
- add_relation(animation_key, parameters_key, "Camera Parameters");
+ add_relation(animation_key, camera_parameters_key, "Camera Parameters");
}
/* DOF */
- if (cam->dof_ob) {
- ComponentKey ob_param_key(&ob->id, DEG_NODE_TYPE_PARAMETERS);
+ if (cam->dof_ob != NULL) {
ComponentKey dof_ob_key(&cam->dof_ob->id, DEG_NODE_TYPE_TRANSFORM);
- add_relation(dof_ob_key, ob_param_key, "Camera DOF");
+ add_relation(dof_ob_key, object_parameters_key, "Camera DOF");
}
}
@@ -1588,38 +1782,49 @@ void DepsgraphRelationBuilder::build_lamp(Object *ob)
}
lamp_id->tag |= LIB_TAG_DOIT;
- ComponentKey parameters_key(lamp_id, DEG_NODE_TYPE_PARAMETERS);
+ ComponentKey object_parameters_key(&ob->id, DEG_NODE_TYPE_PARAMETERS);
+ ComponentKey lamp_parameters_key(lamp_id, DEG_NODE_TYPE_PARAMETERS);
+
+ add_relation(lamp_parameters_key, object_parameters_key,
+ "Lamp -> Object");
if (needs_animdata_node(lamp_id)) {
ComponentKey animation_key(lamp_id, DEG_NODE_TYPE_ANIMATION);
- add_relation(animation_key, parameters_key, "Lamp Parameters");
+ add_relation(animation_key, lamp_parameters_key, "Lamp Parameters");
}
/* lamp's nodetree */
if (la->nodetree) {
build_nodetree(la->nodetree);
- ComponentKey nodetree_key(&la->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
- add_relation(nodetree_key, parameters_key, "NTree->Lamp Parameters");
+ ComponentKey nodetree_key(&la->nodetree->id, DEG_NODE_TYPE_SHADING);
+ add_relation(nodetree_key, lamp_parameters_key, "NTree->Lamp Parameters");
}
/* textures */
build_texture_stack(la->mtex);
+
+#ifdef WITH_COPY_ON_WRITE
+ /* Make sure copy on write of lamp data is always properly updated for
+ * visible lamps.
+ */
+ OperationKey ob_copy_on_write_key(&ob->id,
+ DEG_NODE_TYPE_COPY_ON_WRITE,
+ DEG_OPCODE_COPY_ON_WRITE);
+ OperationKey lamp_copy_on_write_key(lamp_id,
+ DEG_NODE_TYPE_COPY_ON_WRITE,
+ DEG_OPCODE_COPY_ON_WRITE);
+ add_relation(lamp_copy_on_write_key, ob_copy_on_write_key, "Eval Order");
+#endif
}
void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
{
- if (!ntree)
+ if (ntree == NULL) {
return;
-
+ }
ID *ntree_id = &ntree->id;
-
build_animdata(ntree_id);
-
- OperationKey parameters_key(ntree_id,
- DEG_NODE_TYPE_PARAMETERS,
- DEG_OPCODE_PLACEHOLDER,
- "Parameters Eval");
-
+ ComponentKey shading_key(ntree_id, DEG_NODE_TYPE_SHADING);
/* nodetree's nodes... */
LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) {
if (bnode->id) {
@@ -1635,19 +1840,25 @@ void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
build_nodetree(group_ntree);
group_ntree->id.tag |= LIB_TAG_DOIT;
}
- OperationKey group_parameters_key(&group_ntree->id,
- DEG_NODE_TYPE_PARAMETERS,
- DEG_OPCODE_PLACEHOLDER,
- "Parameters Eval");
- add_relation(group_parameters_key, parameters_key, "Group Node");
+ ComponentKey group_shading_key(&group_ntree->id,
+ DEG_NODE_TYPE_SHADING);
+ add_relation(group_shading_key, shading_key, "Group Node");
}
}
}
if (needs_animdata_node(ntree_id)) {
ComponentKey animation_key(ntree_id, DEG_NODE_TYPE_ANIMATION);
- add_relation(animation_key, parameters_key, "NTree Parameters");
+ add_relation(animation_key, shading_key, "NTree Parameters");
}
+
+ OperationKey shading_update_key(ntree_id,
+ DEG_NODE_TYPE_SHADING,
+ DEG_OPCODE_MATERIAL_UPDATE);
+ OperationKey shading_parameters_key(ntree_id,
+ DEG_NODE_TYPE_SHADING_PARAMETERS,
+ DEG_OPCODE_MATERIAL_UPDATE);
+ add_relation(shading_parameters_key, shading_update_key, "NTree Shading Parameters");
}
/* Recursively build graph for material */
@@ -1669,13 +1880,11 @@ void DepsgraphRelationBuilder::build_material(Material *ma)
if (ma->nodetree != NULL) {
build_nodetree(ma->nodetree);
OperationKey ntree_key(&ma->nodetree->id,
- DEG_NODE_TYPE_PARAMETERS,
- DEG_OPCODE_PLACEHOLDER,
- "Parameters Eval");
+ DEG_NODE_TYPE_SHADING,
+ DEG_OPCODE_MATERIAL_UPDATE);
OperationKey material_key(&ma->id,
DEG_NODE_TYPE_SHADING,
- DEG_OPCODE_PLACEHOLDER,
- "Material Update");
+ DEG_OPCODE_MATERIAL_UPDATE);
add_relation(ntree_key, material_key, "Material's NTree");
}
}
@@ -1739,8 +1948,18 @@ void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file) {
void DepsgraphRelationBuilder::build_mask(Mask *mask)
{
- /* Animation. */
- build_animdata(&mask->id);
+ ID *mask_id = &mask->id;
+ /* F-Curve animation. */
+ build_animdata(mask_id);
+ /* Own mask animation. */
+ OperationKey mask_animation_key(mask_id,
+ DEG_NODE_TYPE_ANIMATION,
+ DEG_OPCODE_MASK_ANIMATION);
+ TimeSourceKey time_src_key;
+ add_relation(time_src_key, mask_animation_key, "TimeSrc -> Mask Animation");
+ /* Final mask evaluation. */
+ ComponentKey parameters_key(mask_id, DEG_NODE_TYPE_PARAMETERS);
+ add_relation(mask_animation_key, parameters_key, "Mask Animation -> Mask Eval");
}
void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip)
@@ -1788,7 +2007,7 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDDepsNode *id_node
DEG_NODE_TYPE_COPY_ON_WRITE,
DEG_OPCODE_COPY_ON_WRITE);
/* XXX: This is a quick hack to make Alt-A to work. */
- add_relation(time_source_key, copy_on_write_key, "Fluxgate capacitor hack");
+ // add_relation(time_source_key, copy_on_write_key, "Fluxgate capacitor hack");
/* Resat of code is using rather low level trickery, so need to get some
* explicit pointers.
*/
@@ -1801,6 +2020,10 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDDepsNode *id_node
/* Copy-on-write component never depends on itself. */
continue;
}
+ if (!comp_node->depends_on_cow()) {
+ /* Component explicitly requests to not add relation. */
+ continue;
+ }
/* All entry operations of each component should wait for a proper
* copy of ID.
*/
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.h b/source/blender/depsgraph/intern/builder/deg_builder_relations.h
index 8a53bf4a6bf..e8bdc662bd6 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,
@@ -208,7 +210,7 @@ struct DepsgraphRelationBuilder
bPoseChannel *pchan,
bConstraint *con,
RootPChanMap *root_map);
- void build_rig(Scene *scene, Object *ob);
+ void build_rig(Main *bmain, Scene *scene, Object *ob);
void build_proxy_rig(Object *ob);
void build_shapekeys(ID *obdata, Key *key);
void build_obdata_geom(Main *bmain, Scene *scene, Object *ob);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_layer.cc
index a6c9fdfc6bc..1e57a98d6f7 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_layer.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_layer.cc
@@ -24,7 +24,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/depsgraph/intern/builder/deg_builder_relations_scene.cc
+/** \file blender/depsgraph/intern/builder/deg_builder_relations_layer.cc
* \ingroup depsgraph
*
* Methods for constructing depsgraph
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
index be666165a0b..88477e512d1 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
@@ -83,7 +83,15 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob,
* - see notes on direction of rel below...
*/
bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data);
- OperationKey solver_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name, DEG_OPCODE_POSE_IK_SOLVER);
+ OperationKey pchan_local_key(&ob->id, DEG_NODE_TYPE_BONE,
+ pchan->name, DEG_OPCODE_BONE_LOCAL);
+ OperationKey init_ik_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
+ OperationKey solver_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE,
+ rootchan->name,
+ DEG_OPCODE_POSE_IK_SOLVER);
+
+ add_relation(pchan_local_key, init_ik_key, "IK Constraint -> Init IK Tree");
+ add_relation(init_ik_key, solver_key, "Init IK -> IK Solver");
/* IK target */
// XXX: this should get handled as part of the constraint code
@@ -291,7 +299,7 @@ void DepsgraphRelationBuilder::build_splineik_pose(Object *ob,
}
/* Pose/Armature Bones Graph */
-void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob)
+void DepsgraphRelationBuilder::build_rig(Main *bmain, Scene *scene, Object *ob)
{
/* Armature-Data */
bArmature *arm = (bArmature *)ob->data;
@@ -300,9 +308,11 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob)
/* attach links between pose operations */
OperationKey init_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT);
+ OperationKey init_ik_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
OperationKey flush_key(&ob->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
- add_relation(init_key, flush_key, "[Pose Init -> Pose Cleanup]");
+ add_relation(init_key, init_ik_key, "Pose Init -> Pose Init IK");
+ add_relation(init_ik_key, flush_key, "Pose Init IK -> Pose Cleanup");
/* Make sure pose is up-to-date with armature updates. */
OperationKey armature_key(&arm->id,
@@ -379,16 +389,12 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob)
OperationKey bone_pose_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_POSE_PARENT);
OperationKey bone_ready_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY);
OperationKey bone_done_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE);
-
pchan->flag &= ~POSE_DONE;
-
- /* pose init to bone local */
+ /* Pose init to bone local. */
add_relation(init_key, bone_local_key, "PoseEval Source-Bone Link");
-
- /* local to pose parenting operation */
+ /* Local to pose parenting operation. */
add_relation(bone_local_key, bone_pose_key, "Bone Local - PoseSpace Link");
-
- /* parent relation */
+ /* Parent relation. */
if (pchan->parent != NULL) {
eDepsOperation_Code parent_key_opcode;
@@ -403,8 +409,7 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob)
OperationKey parent_key(&ob->id, DEG_NODE_TYPE_BONE, pchan->parent->name, parent_key_opcode);
add_relation(parent_key, bone_pose_key, "[Parent Bone -> Child Bone]");
}
-
- /* constraints */
+ /* Buil constraints. */
if (pchan->constraints.first != NULL) {
/* constraints stack and constraint dependencies */
build_constraints(scene, &ob->id, DEG_NODE_TYPE_BONE, pchan->name, &pchan->constraints, &root_map);
@@ -431,6 +436,10 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob)
/* assume that all bones must be done for the pose to be ready (for deformers) */
add_relation(bone_done_key, flush_key, "PoseEval Result-Bone Link");
+ /* Custom shape. */
+ if (pchan->custom != NULL) {
+ build_object(bmain, scene, pchan->custom);
+ }
}
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc
index 43204d5fe98..deed46339bb 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc
@@ -75,6 +75,7 @@ void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene)
}
/* XXX store scene to access from DAG_get_scene */
+ m_graph->bmain = bmain;
m_graph->scene = scene;
/* scene objects */
@@ -83,6 +84,9 @@ void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene)
build_object(bmain, scene, base->object);
}
}
+ if (scene->camera != NULL) {
+ build_object(bmain, scene, scene->camera);
+ }
/* rigidbody */
if (scene->rigidbody_world) {
diff --git a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
index 66b63f861ee..ce3a4182a0f 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
@@ -88,9 +88,10 @@ static const int deg_debug_node_type_color_map[][2] = {
{DEG_NODE_TYPE_GEOMETRY, 6},
{DEG_NODE_TYPE_SEQUENCER, 7},
{DEG_NODE_TYPE_SHADING, 8},
- {DEG_NODE_TYPE_CACHE, 9},
- {DEG_NODE_TYPE_LAYER_COLLECTIONS, 10},
- {DEG_NODE_TYPE_COPY_ON_WRITE, 11},
+ {DEG_NODE_TYPE_SHADING_PARAMETERS, 9},
+ {DEG_NODE_TYPE_CACHE, 10},
+ {DEG_NODE_TYPE_LAYER_COLLECTIONS, 11},
+ {DEG_NODE_TYPE_COPY_ON_WRITE, 12},
{-1, 0}
};
#endif
@@ -377,6 +378,7 @@ static void deg_debug_graphviz_node(const DebugContext &ctx,
case DEG_NODE_TYPE_EVAL_POSE:
case DEG_NODE_TYPE_BONE:
case DEG_NODE_TYPE_SHADING:
+ case DEG_NODE_TYPE_SHADING_PARAMETERS:
case DEG_NODE_TYPE_CACHE:
case DEG_NODE_TYPE_LAYER_COLLECTIONS:
case DEG_NODE_TYPE_EVAL_PARTICLES:
@@ -395,7 +397,9 @@ static void deg_debug_graphviz_node(const DebugContext &ctx,
}
break;
}
- default:
+ case DEG_NODE_TYPE_UNDEFINED:
+ case DEG_NODE_TYPE_TIMESOURCE:
+ case DEG_NODE_TYPE_OPERATION:
deg_debug_graphviz_node_single(ctx, node);
break;
}
diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index dc3174751bd..81a4f2bc0cc 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -53,6 +53,8 @@ extern "C" {
#include "DEG_depsgraph.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
+
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_operation.h"
@@ -250,11 +252,13 @@ DepsNode *Depsgraph::find_node_from_pointer(const PointerRNA *ptr,
/* Node Management ---------------------------- */
+#ifndef WITH_COPY_ON_WRITE
static void id_node_deleter(void *value)
{
IDDepsNode *id_node = reinterpret_cast<IDDepsNode *>(value);
OBJECT_GUARDED_DELETE(id_node, IDDepsNode);
}
+#endif
TimeSourceDepsNode *Depsgraph::add_time_source()
{
@@ -275,13 +279,17 @@ IDDepsNode *Depsgraph::find_id_node(const ID *id) const
return reinterpret_cast<IDDepsNode *>(BLI_ghash_lookup(id_hash, id));
}
-IDDepsNode *Depsgraph::add_id_node(ID *id, const char *name)
+IDDepsNode *Depsgraph::add_id_node(ID *id, bool do_tag, ID *id_cow_hint)
{
+ BLI_assert((id->tag & LIB_TAG_COPY_ON_WRITE) == 0);
IDDepsNode *id_node = find_id_node(id);
if (!id_node) {
DepsNodeFactory *factory = deg_get_node_factory(DEG_NODE_TYPE_ID_REF);
- id_node = (IDDepsNode *)factory->create_node(id, "", name);
- id->tag |= LIB_TAG_DOIT;
+ id_node = (IDDepsNode *)factory->create_node(id, "", id->name);
+ id_node->init_copy_on_write(id_cow_hint);
+ if (do_tag) {
+ id->tag |= LIB_TAG_DOIT;
+ }
/* Register node in ID hash.
*
* NOTE: We address ID nodes by the original ID pointer they are
@@ -289,12 +297,41 @@ IDDepsNode *Depsgraph::add_id_node(ID *id, const char *name)
*/
BLI_ghash_insert(id_hash, id, id_node);
}
+ else if (do_tag) {
+ id->tag |= LIB_TAG_DOIT;
+ }
return id_node;
}
void Depsgraph::clear_id_nodes()
{
+#ifndef WITH_COPY_ON_WRITE
BLI_ghash_clear(id_hash, NULL, id_node_deleter);
+#else
+ /* Stupid workaround to ensure we free IDs in a proper order. */
+ GHASH_FOREACH_BEGIN(IDDepsNode *, id_node, id_hash)
+ {
+ if (id_node->id_cow == NULL) {
+ /* This means builder "stole" ownership of the copy-on-written
+ * datablock for her own dirty needs.
+ */
+ continue;
+ }
+ if (!deg_copy_on_write_is_expanded(id_node->id_cow)) {
+ continue;
+ }
+ const ID_Type id_type = GS(id_node->id_cow->name);
+ if (id_type != ID_PA) {
+ id_node->destroy();
+ }
+ }
+ GHASH_FOREACH_END();
+ GHASH_FOREACH_BEGIN(IDDepsNode *, id_node, id_hash)
+ {
+ OBJECT_GUARDED_DELETE(id_node, IDDepsNode);
+ }
+ GHASH_FOREACH_END();
+#endif
}
/* Add new relationship between two nodes. */
@@ -389,9 +426,9 @@ DepsRelation::~DepsRelation()
void Depsgraph::add_entry_tag(OperationDepsNode *node)
{
/* Sanity check. */
- if (!node)
+ if (node == NULL) {
return;
-
+ }
/* Add to graph-level set of directly modified nodes to start searching from.
* NOTE: this is necessary since we have several thousand nodes to play with...
*/
@@ -412,6 +449,25 @@ ID *Depsgraph::get_cow_id(const ID *id_orig) const
{
IDDepsNode *id_node = find_id_node(id_orig);
if (id_node == NULL) {
+ /* This function is used from places where we expect ID to be either
+ * already a copy-on-write version or have a corresponding copy-on-write
+ * version.
+ *
+ * We try to enforce that in debug builds, for for release we play a bit
+ * safer game here.
+ */
+ if ((id_orig->tag & LIB_TAG_COPY_ON_WRITE) == 0) {
+ /* TODO(sergey): This is nice sanity check to have, but it fails
+ * in following situations:
+ *
+ * - Material has link to texture, which is not needed by new
+ * shading system and hence can be ignored at construction.
+ * - Object or mesh has material at a slot which is not used (for
+ * example, object has material slot by materials are set to
+ * object data).
+ */
+ // BLI_assert(!"Request for non-existing copy-on-write ID");
+ }
return (ID *)id_orig;
}
return id_node->id_cow;
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index 9785d2f90d0..823a1935e18 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -42,6 +42,7 @@
struct ID;
struct GHash;
+struct Main;
struct GSet;
struct PointerRNA;
struct PropertyRNA;
@@ -101,7 +102,8 @@ struct Depsgraph {
* Convenience wrapper to find node given just pointer + property.
*
* \param ptr: pointer to the data that node will represent
- * \param prop: optional property affected - providing this effectively results in inner nodes being returned
+ * \param prop: optional property affected - providing this effectively
+ * results in inner nodes being returned
*
* \return A node matching the required characteristics if it exists
* or NULL if no such node exists in the graph
@@ -112,7 +114,7 @@ struct Depsgraph {
TimeSourceDepsNode *find_time_source() const;
IDDepsNode *find_id_node(const ID *id) const;
- IDDepsNode *add_id_node(ID *id, const char *name = "");
+ IDDepsNode *add_id_node(ID *id, bool do_tag = true, ID *id_cow_hint = NULL);
void clear_id_nodes();
/* Add new relationship between two nodes. */
@@ -164,8 +166,8 @@ struct Depsgraph {
SpinLock lock;
// XXX: additional stuff like eval contexts, mempools for allocating nodes from, etc.
-
- Scene *scene; /* XXX: We really shouldn't do that, but it's required for shader preview */
+ Main *bmain; /* XXX: For until depsgraph has proper ownership. */
+ Scene *scene; /* XXX: We really shouldn't do that, but it's required for shader preview. */
};
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc
index 88ff1ac0a9c..e21c3d29aa5 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -257,12 +257,13 @@ void DEG_graph_tag_relations_update(Depsgraph *graph)
/* Tag all relations for update. */
void DEG_relations_tag_update(Main *bmain)
{
+ DEG_DEBUG_PRINTF("%s: Tagging relations for update.\n", __func__);
for (Scene *scene = (Scene *)bmain->scene.first;
scene != NULL;
scene = (Scene *)scene->id.next)
{
- if (scene->depsgraph != NULL) {
- DEG_graph_tag_relations_update(scene->depsgraph);
+ if (scene->depsgraph_legacy != NULL) {
+ DEG_graph_tag_relations_update(scene->depsgraph_legacy);
}
}
}
@@ -272,24 +273,19 @@ void DEG_relations_tag_update(Main *bmain)
*/
void DEG_scene_relations_update(Main *bmain, Scene *scene)
{
- if (scene->depsgraph == NULL) {
+ if (scene->depsgraph_legacy == NULL) {
/* Rebuild graph from scratch and exit. */
- scene->depsgraph = DEG_graph_new();
- DEG_graph_build_from_scene(scene->depsgraph, bmain, scene);
+ scene->depsgraph_legacy = DEG_graph_new();
+ DEG_graph_build_from_scene(scene->depsgraph_legacy, bmain, scene);
return;
}
- DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph);
+ DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph_legacy);
if (!graph->need_update) {
/* Graph is up to date, nothing to do. */
return;
}
- /* Clear all previous nodes and operations. */
- graph->clear_all_nodes();
- graph->operations.clear();
- BLI_gset_clear(graph->entry_tags, NULL);
-
/* Build new nodes and relations. */
DEG_graph_build_from_scene(reinterpret_cast< ::Depsgraph * >(graph),
bmain,
@@ -301,17 +297,17 @@ void DEG_scene_relations_update(Main *bmain, Scene *scene)
/* Rebuild dependency graph only for a given scene. */
void DEG_scene_relations_rebuild(Main *bmain, Scene *scene)
{
- if (scene->depsgraph != NULL) {
- DEG_graph_tag_relations_update(scene->depsgraph);
+ if (scene->depsgraph_legacy != NULL) {
+ DEG_graph_tag_relations_update(scene->depsgraph_legacy);
}
DEG_scene_relations_update(bmain, scene);
}
void DEG_scene_graph_free(Scene *scene)
{
- if (scene->depsgraph) {
- DEG_graph_free(scene->depsgraph);
- scene->depsgraph = NULL;
+ if (scene->depsgraph_legacy) {
+ DEG_graph_free(scene->depsgraph_legacy);
+ scene->depsgraph_legacy = NULL;
}
}
@@ -348,7 +344,7 @@ void DEG_add_forcefield_relations(DepsNodeHandle *handle,
int skip_forcefield,
const char *name)
{
- ListBase *effectors = pdInitEffectors(scene, ob, NULL, effector_weights, false);
+ ListBase *effectors = pdInitEffectors(NULL, scene, ob, NULL, effector_weights, false);
if (effectors) {
for (EffectorCache *eff = (EffectorCache*)effectors->first; eff; eff = eff->next) {
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc
index 388b692d742..453bd2aa75f 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cc
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cc
@@ -91,7 +91,7 @@ bool DEG_debug_scene_relations_validate(Main *bmain,
Depsgraph *depsgraph = DEG_graph_new();
bool valid = true;
DEG_graph_build_from_scene(depsgraph, bmain, scene);
- if (!DEG_debug_compare(depsgraph, scene->depsgraph)) {
+ if (!DEG_debug_compare(depsgraph, scene->depsgraph_legacy)) {
fprintf(stderr, "ERROR! Depsgraph wasn't tagged for update when it should have!\n");
BLI_assert(!"This should not happen!");
valid = false;
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc
index 73a0428c264..77a32740524 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cc
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cc
@@ -56,7 +56,7 @@ extern "C" {
/* Evaluation Context */
/* Create new evaluation context. */
-EvaluationContext *DEG_evaluation_context_new(int mode)
+EvaluationContext *DEG_evaluation_context_new(eEvaluationMode mode)
{
EvaluationContext *eval_ctx =
(EvaluationContext *)MEM_callocN(sizeof(EvaluationContext),
@@ -70,11 +70,22 @@ EvaluationContext *DEG_evaluation_context_new(int mode)
* Used by the areas which currently overrides the context or doesn't have
* access to a proper one.
*/
-void DEG_evaluation_context_init(EvaluationContext *eval_ctx, int mode)
+void DEG_evaluation_context_init(EvaluationContext *eval_ctx,
+ eEvaluationMode mode)
{
eval_ctx->mode = mode;
}
+void DEG_evaluation_context_init_from_scene(EvaluationContext *eval_ctx,
+ Scene *scene,
+ SceneLayer *scene_layer,
+ eEvaluationMode mode)
+{
+ DEG_evaluation_context_init(eval_ctx, mode);
+ eval_ctx->scene_layer = scene_layer;
+ eval_ctx->ctime = BKE_scene_frame_get(scene);
+}
+
/* Free evaluation context. */
void DEG_evaluation_context_free(EvaluationContext *eval_ctx)
{
diff --git a/source/blender/depsgraph/intern/depsgraph_intern.h b/source/blender/depsgraph/intern/depsgraph_intern.h
index 2d8e7dc841c..5ab090f3b3d 100644
--- a/source/blender/depsgraph/intern/depsgraph_intern.h
+++ b/source/blender/depsgraph/intern/depsgraph_intern.h
@@ -113,11 +113,23 @@ void deg_editors_id_update(struct Main *bmain, struct ID *id);
void deg_editors_scene_update(struct Main *bmain, struct Scene *scene, bool updated);
-#define DEG_DEBUG_PRINTF(...) \
- do { \
- if (G.debug & G_DEBUG_DEPSGRAPH) { \
- fprintf(stderr, __VA_ARGS__); \
- } \
+/* Tagging helpers ------------------------------------------------------ */
+
+void lib_id_recalc_tag(struct Main *bmain, struct ID *id);
+void lib_id_recalc_data_tag(struct Main *bmain, struct ID *id);
+
+#define DEG_DEBUG_PRINTF(...) \
+ do { \
+ if (G.debug & G_DEBUG_DEPSGRAPH) { \
+ fprintf(stderr, __VA_ARGS__); \
+ fflush(stderr); \
+ } \
+ } while (0)
+
+#define DEG_ERROR_PRINTF(...) \
+ do { \
+ fprintf(stderr, __VA_ARGS__); \
+ fflush(stderr); \
} while (0)
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc
index 3dfa6bf5e9d..9e9a2c38993 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -53,9 +53,9 @@ extern "C" {
# include "intern/eval/deg_eval_copy_on_write.h"
#endif
-bool DEG_id_type_tagged(Main *bmain, short idtype)
+bool DEG_id_type_tagged(Main *bmain, short id_type)
{
- return bmain->id_tag_update[BKE_idcode_to_index(idtype)] != 0;
+ return bmain->id_tag_update[BKE_idcode_to_index(id_type)] != 0;
}
short DEG_get_eval_flags_for_id(Depsgraph *graph, ID *id)
@@ -81,32 +81,39 @@ short DEG_get_eval_flags_for_id(Depsgraph *graph, ID *id)
return id_node->eval_flags;
}
-Scene *DEG_get_scene(Depsgraph *graph)
+Scene *DEG_get_evaluated_scene(Depsgraph *graph)
{
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
Scene *scene_orig = deg_graph->scene;
return reinterpret_cast<Scene *>(deg_graph->get_cow_id(&scene_orig->id));
}
-SceneLayer *DEG_get_scene_layer(Depsgraph *graph)
+SceneLayer *DEG_get_evaluated_scene_layer(Depsgraph *graph)
{
- Scene *scene = DEG_get_scene(graph);
- if (scene) {
- return BKE_scene_layer_render_active(scene);
+ Scene *scene = DEG_get_evaluated_scene(graph);
+ if (scene != NULL) {
+ return BKE_scene_layer_context_active_PLACEHOLDER(scene);
}
return NULL;
}
-Object *DEG_get_object(Depsgraph *depsgraph, Object *ob)
+Object *DEG_get_evaluated_object(Depsgraph *depsgraph, Object *object)
{
- DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(depsgraph);
- return (Object *)deg_graph->get_cow_id(&ob->id);
+ return (Object *)DEG_get_evaluated_id(depsgraph, &object->id);
}
ID *DEG_get_evaluated_id(struct Depsgraph *depsgraph, ID *id)
{
- DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(depsgraph);
- return deg_graph->get_cow_id(id);
+ /* TODO(sergey): This is a duplicate of Depsgraph::get_cow_id(),
+ * but here we never do assert, since we don't know nature of the
+ * incoming ID datablock.
+ */
+ DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph;
+ DEG::IDDepsNode *id_node = deg_graph->find_id_node(id);
+ if (id_node == NULL) {
+ return id;
+ }
+ return id_node->id_cow;
}
/* ************************ DAG ITERATORS ********************* */
@@ -116,12 +123,12 @@ ID *DEG_get_evaluated_id(struct Depsgraph *depsgraph, ID *id)
void DEG_objects_iterator_begin(BLI_Iterator *iter, DEGObjectsIteratorData *data)
{
Depsgraph *graph = data->graph;
- SceneLayer *scene_layer = DEG_get_scene_layer(graph);
+ SceneLayer *scene_layer = DEG_get_evaluated_scene_layer(graph);
iter->data = data;
iter->valid = true;
- data->scene = DEG_get_scene(graph);
+ data->scene = DEG_get_evaluated_scene(graph);
DEG_evaluation_context_init(&data->eval_ctx, DAG_EVAL_RENDER);
/* TODO(sergey): It's really confusing to store pointer to a local data. */
@@ -204,33 +211,29 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
}
base = data->base->next;
- while (base != NULL) {
- if ((base->flag & BASE_VISIBLED) != 0) {
- // Object *ob = DEG_get_object(data->graph, base->object);
- Object *ob = base->object;
- iter->current = ob;
- data->base = base;
-
- BLI_assert(DEG::deg_validate_copy_on_write_datablock(&ob->id));
-
- /* Make sure we have the base collection settings is already populated.
- * This will fail when BKE_layer_eval_layer_collection_pre hasn't run yet
- * Which usually means a missing call to DAG_id_tag_update(). */
- BLI_assert(!BLI_listbase_is_empty(&base->collection_properties->data.group));
-
- /* Flushing depsgraph data. */
- deg_flush_base_flags_and_settings(ob,
- base,
- data->base_flag);
-
- if ((data->flag & DEG_OBJECT_ITER_FLAG_DUPLI) && (ob->transflag & OB_DUPLI)) {
- data->dupli_parent = ob;
- data->dupli_list = object_duplilist(&data->eval_ctx, data->scene, ob);
- data->dupli_object_next = (DupliObject *)data->dupli_list->first;
- }
- return;
+ if (base != NULL) {
+ // Object *ob = DEG_get_evaluated_object(data->graph, base->object);
+ Object *ob = base->object;
+ iter->current = ob;
+ data->base = base;
+
+ BLI_assert(DEG::deg_validate_copy_on_write_datablock(&ob->id));
+
+ /* Make sure we have the base collection settings is already populated.
+ * This will fail when BKE_layer_eval_layer_collection_pre hasn't run yet
+ * Which usually means a missing call to DEG_id_tag_update(). */
+ BLI_assert(!BLI_listbase_is_empty(&base->collection_properties->data.group));
+
+ /* Flushing depsgraph data. */
+ deg_flush_base_flags_and_settings(
+ ob, base, data->base_flag);
+
+ if ((data->flag & DEG_OBJECT_ITER_FLAG_DUPLI) && (ob->transflag & OB_DUPLI)) {
+ data->dupli_parent = ob;
+ data->dupli_list = object_duplilist(&data->eval_ctx, data->scene, ob);
+ data->dupli_object_next = (DupliObject *)data->dupli_list->first;
}
- base = base->next;
+ return;
}
/* Look for an object in the next set. */
@@ -240,7 +243,7 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
data->base_flag = ~(BASE_SELECTED | BASE_SELECTABLED);
/* For the sets we use the layer used for rendering. */
- scene_layer = BKE_scene_layer_render_active(data->scene);
+ scene_layer = BKE_scene_layer_from_scene_get(data->scene);
/* TODO(sergey): It's really confusing to store pointer to a local data. */
Base base = {(Base *)scene_layer->object_bases.first, NULL};
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc
index 80fa89bbb97..0df2420d662 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -67,18 +67,17 @@ extern "C" {
#include "intern/depsgraph_intern.h"
#include "util/deg_util_foreach.h"
+/* Define this in order to have more strict sanitization of what tagging flags
+ * are used for ID databnlocks. Ideally, we would always want this, but there
+ * are cases in generic modules (like IR remapping) where we don't want to spent
+ * lots of time trying to guess which components are to be updated.
+ */
+// #define STRICT_COMPONENT_TAGGING
+
/* *********************** */
/* 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 {
+namespace DEG {
/* Data-Based Tagging ------------------------------- */
@@ -94,124 +93,312 @@ void lib_id_recalc_data_tag(Main *bmain, ID *id)
DEG_id_type_tag(bmain, GS(id->name));
}
+namespace {
+
+void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag);
+
void lib_id_recalc_tag_flag(Main *bmain, ID *id, int flag)
{
+ /* This bit of code ensures legacy object->recalc flags are still filled in
+ * the same way as it was expected with the old dependency graph.
+ *
+ * This is because some areas like motion paths and likely some other
+ * physics baking process are doing manual scene update on all the frames,
+ * trying to minimize number of updates.
+ *
+ * But this flag will also let us to re-construct entry nodes for update
+ * after relations update and after layer visibility changes.
+ */
if (flag) {
- /* This bit of code ensures legacy object->recalc flags
- * are still filled in the same way as it was expected
- * with the old dependency graph.
- *
- * This is because some areas like motion paths and likely
- * some other physics baking process are doing manual scene
- * update on all the frames, trying to minimize number of
- * updates.
- *
- * But this flag will also let us to re-construct entry
- * nodes for update after relations update and after layer
- * visibility changes.
- */
- short idtype = GS(id->name);
- if (idtype == ID_OB) {
+ ID_Type id_type = GS(id->name);
+ if (id_type == ID_OB) {
Object *object = (Object *)id;
object->recalc |= (flag & OB_RECALC_ALL);
}
-
- if (flag & OB_RECALC_OB)
+ if (flag & OB_RECALC_OB) {
lib_id_recalc_tag(bmain, id);
- if (flag & (OB_RECALC_DATA | PSYS_RECALC))
+ }
+ if (flag & (OB_RECALC_DATA | PSYS_RECALC)) {
lib_id_recalc_data_tag(bmain, id);
+ }
}
else {
lib_id_recalc_tag(bmain, id);
}
}
-#ifdef DEPSGRAPH_USE_LEGACY_TAGGING
-void depsgraph_legacy_handle_update_tag(Main *bmain, ID *id, int flag)
+/* Special tagging */
+void id_tag_update_special_zero_flag(Depsgraph *graph, IDDepsNode *id_node)
{
- 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);
- }
- }
+ /* NOTE: Full ID node update for now, need to minimize that i9n the future. */
+ id_node->tag_update(graph);
+}
+
+/* Tag corresponding to OB_RECALC_OB. */
+void id_tag_update_object_transform(Depsgraph *graph, IDDepsNode *id_node)
+{
+ ComponentDepsNode *transform_comp =
+ id_node->find_component(DEG_NODE_TYPE_TRANSFORM);
+ if (transform_comp == NULL) {
+#ifdef STRICT_COMPONENT_TAGGING
+ DEG_ERROR_PRINTF("ERROR: Unable to find transform component for %s\n",
+ id_node->id_orig->name);
+ BLI_assert(!"This is not supposed to happen!");
+#endif
+ return;
+ }
+ transform_comp->tag_update(graph);
+}
+
+/* Tag corresponding to OB_RECALC_DATA. */
+void id_tag_update_object_data(Depsgraph *graph, IDDepsNode *id_node)
+{
+ const ID_Type id_type = GS(id_node->id_orig->name);
+ ComponentDepsNode *data_comp = NULL;
+ switch (id_type) {
+ case ID_OB:
+ {
+ const Object *object = (Object *)id_node->id_orig;
+ switch (object->type) {
+ case OB_MESH:
+ case OB_CURVE:
+ case OB_SURF:
+ case OB_FONT:
+ case OB_MBALL:
+ data_comp = id_node->find_component(DEG_NODE_TYPE_GEOMETRY);
+ break;
+ case OB_ARMATURE:
+ data_comp = id_node->find_component(DEG_NODE_TYPE_EVAL_POSE);
+ break;
+ /* TODO(sergey): More cases here? */
}
+ break;
}
+ case ID_ME:
+ data_comp = id_node->find_component(DEG_NODE_TYPE_GEOMETRY);
+ break;
+ case ID_PA:
+ return;
+ case ID_LP:
+ data_comp = id_node->find_component(DEG_NODE_TYPE_PARAMETERS);
+ break;
+ default:
+ break;
+ }
+ if (data_comp == NULL) {
+#ifdef STRICT_COMPONENT_TAGGING
+ DEG_ERROR_PRINTF("ERROR: Unable to find data component for %s\n",
+ id_node->id_orig->name);
+ BLI_assert(!"This is not supposed to happen!");
+#endif
+ return;
}
+ data_comp->tag_update(graph);
+ /* Special legacy compatibility code, tag data ID for update when object
+ * is tagged for data update.
+ */
+ if (id_type == ID_OB) {
+ Object *object = (Object *)id_node->id_orig;
+ ID *data_id = (ID *)object->data;
+ if (data_id != NULL) {
+ IDDepsNode *data_id_node = graph->find_id_node(data_id);
+ // BLI_assert(data_id_node != NULL);
+ /* TODO(sergey): Do we want more granular tags here? */
+ /* TODO(sergey): Hrm, during some operations it's possible to have
+ * object node existing but not it's data. For example, when making
+ * objects local. This is valid situation, but how can we distinguish
+ * that from someone trying to do stupid things with dependency
+ * graph?
+ */
+ if (data_id_node != NULL) {
+ data_id_node->tag_update(graph);
+ }
+ }
+ }
+}
+
+/* Tag corresponding to OB_RECALC_TIME. */
+void id_tag_update_object_time(Depsgraph *graph, IDDepsNode *id_node)
+{
+ ComponentDepsNode *animation_comp =
+ id_node->find_component(DEG_NODE_TYPE_ANIMATION);
+ if (animation_comp == NULL) {
+ /* It's not necessarily we've got animation component in cases when
+ * we are tagging for time updates.
+ */
+ return;
+ }
+ animation_comp->tag_update(graph);
+ /* TODO(sergey): More components to tag here? */
+}
+
+void id_tag_update_particle(Depsgraph *graph, IDDepsNode *id_node, int tag)
+{
+ ComponentDepsNode *particle_comp =
+ id_node->find_component(DEG_NODE_TYPE_PARAMETERS);
+ ParticleSettings *particle_settings = (ParticleSettings *)id_node->id_orig;
+ particle_settings->recalc |= (tag & PSYS_RECALC);
+ if (particle_comp == NULL) {
+#ifdef STRICT_COMPONENT_TAGGING
+ DEG_ERROR_PRINTF("ERROR: Unable to find particle component for %s\n",
+ id_node->id_orig->name);
+ BLI_assert(!"This is not supposed to happen!");
+#endif
+ return;
+ }
+ particle_comp->tag_update(graph);
}
+
+void id_tag_update_shading(Depsgraph *graph, IDDepsNode *id_node)
+{
+ ComponentDepsNode *shading_comp;
+ if (GS(id_node->id_orig->name) == ID_NT) {
+ shading_comp = id_node->find_component(DEG_NODE_TYPE_SHADING_PARAMETERS);
+ }
+ else {
+ shading_comp = id_node->find_component(DEG_NODE_TYPE_SHADING);
+ }
+ if (shading_comp == NULL) {
+#ifdef STRICT_COMPONENT_TAGGING
+ DEG_ERROR_PRINTF("ERROR: Unable to find shading component for %s\n",
+ id_node->id_orig->name);
+ BLI_assert(!"This is not supposed to happen!");
#endif
+ return;
+ }
+ shading_comp->tag_update(graph);
+}
#ifdef WITH_COPY_ON_WRITE
-void id_tag_copy_on_write_update(Main *bmain, Depsgraph *graph, ID *id)
+/* Tag corresponding to DEG_TAG_COPY_ON_WRITE. */
+void id_tag_update_copy_on_write(Depsgraph *graph, IDDepsNode *id_node)
{
- lib_id_recalc_tag(bmain, id);
- DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
- DEG::IDDepsNode *id_node = deg_graph->find_id_node(id);
- DEG::ComponentDepsNode *cow_comp =
- id_node->find_component(DEG::DEG_NODE_TYPE_COPY_ON_WRITE);
- DEG::OperationDepsNode *cow_node = cow_comp->get_entry_operation();
- cow_node->tag_update(deg_graph);
- cow_node->flag |= DEG::DEPSOP_FLAG_SKIP_FLUSH;
+ ComponentDepsNode *cow_comp =
+ id_node->find_component(DEG_NODE_TYPE_COPY_ON_WRITE);
+ OperationDepsNode *cow_node = cow_comp->get_entry_operation();
+ cow_node->tag_update(graph);
}
#endif
-} /* namespace */
-
-/* Tag all nodes in ID-block for update.
- * This is a crude measure, but is most convenient for old code.
- */
-void DEG_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id)
+void id_tag_update_ntree_special(Main *bmain, Depsgraph *graph, ID *id, int flag)
{
- DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
- DEG::IDDepsNode *node = deg_graph->find_id_node(id);
- lib_id_recalc_tag(bmain, id);
- if (node != NULL) {
- node->tag_update(deg_graph);
+ bNodeTree *ntree = NULL;
+ switch (GS(id->name)) {
+ case ID_MA:
+ ntree = ((Material *)id)->nodetree;
+ break;
+ default:
+ break;
+ }
+ if (ntree == NULL) {
+ return;
+ }
+ IDDepsNode *id_node = graph->find_id_node(&ntree->id);
+ if (id_node != NULL) {
+ deg_graph_id_tag_update(bmain, graph, id_node->id_orig, flag);
}
}
-/* Tag nodes related to a specific piece of data */
-void DEG_graph_data_tag_update(Depsgraph *graph, const PointerRNA *ptr)
+void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag)
{
- DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
- DEG::DepsNode *node = deg_graph->find_node_from_pointer(ptr, NULL);
- if (node != NULL) {
- node->tag_update(deg_graph);
+ Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
+ IDDepsNode *id_node = deg_graph->find_id_node(id);
+ /* Make sure legacy flags are all nicely update. */
+ lib_id_recalc_tag_flag(bmain, id, flag);
+ if (id_node == NULL) {
+ /* Shouldn't happen, but better be sure here. */
+ return;
}
- else {
- printf("Missing node in %s\n", __func__);
- BLI_assert(!"Shouldn't happens since it'll miss crucial update.");
+ /* Tag components based on flags. */
+ if (flag == 0) {
+ id_tag_update_special_zero_flag(graph, id_node);
+ id_tag_update_ntree_special(bmain, graph, id, flag);
+ return;
+ }
+ if (flag & OB_RECALC_OB) {
+ id_tag_update_object_transform(graph, id_node);
}
+ if (flag & OB_RECALC_DATA) {
+ id_tag_update_object_data(graph, id_node);
+#ifdef WITH_COPY_ON_WRITE
+ if (flag & DEG_TAG_COPY_ON_WRITE) {
+ const ID_Type id_type = GS(id_node->id_orig->name);
+ if (id_type == ID_OB) {
+ Object *object = (Object *)id_node->id_orig;
+ ID *ob_data = (ID *)object->data;
+ DEG_id_tag_update_ex(bmain, ob_data, flag);
+ }
+ }
+#endif
+ }
+ if (flag & OB_RECALC_TIME) {
+ id_tag_update_object_time(graph, id_node);
+ }
+ if (flag & PSYS_RECALC) {
+ id_tag_update_particle(graph, id_node, flag);
+ }
+ if (flag & DEG_TAG_SHADING_UPDATE) {
+ id_tag_update_shading(graph, id_node);
+ }
+#ifdef WITH_COPY_ON_WRITE
+ if (flag & DEG_TAG_COPY_ON_WRITE) {
+ id_tag_update_copy_on_write(graph, id_node);
+ }
+#endif
+ id_tag_update_ntree_special(bmain, graph, id, flag);
}
-/* Tag nodes related to a specific property. */
-void DEG_graph_property_tag_update(Depsgraph *graph,
- const PointerRNA *ptr,
- const PropertyRNA *prop)
+void deg_id_tag_update(Main *bmain, ID *id, int flag)
{
- DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
- DEG::DepsNode *node = deg_graph->find_node_from_pointer(ptr, prop);
- if (node != NULL) {
- node->tag_update(deg_graph);
+ lib_id_recalc_tag_flag(bmain, id, flag);
+ for (Scene *scene = (Scene *)bmain->scene.first;
+ scene != NULL;
+ scene = (Scene *)scene->id.next)
+ {
+ if (scene->depsgraph_legacy != NULL) {
+ Depsgraph *graph = (Depsgraph *)scene->depsgraph_legacy;
+ deg_graph_id_tag_update(bmain, graph, id, flag);
+ }
}
- else {
- printf("Missing node in %s\n", __func__);
- BLI_assert(!"Shouldn't happens since it'll miss crucial update.");
+}
+
+void deg_graph_on_visible_update(Main *bmain, Scene *scene, Depsgraph *graph)
+{
+ /* Make sure objects are up to date. */
+ GHASH_FOREACH_BEGIN(DEG::IDDepsNode *, id_node, graph->id_hash)
+ {
+ const ID_Type id_type = GS(id_node->id_orig->name);
+ /* TODO(sergey): Special exception for now. */
+ if (id_type == ID_MSK) {
+ deg_graph_id_tag_update(bmain, graph, id_node->id_orig, 0);
+ }
+ if (id_type != ID_OB) {
+ /* Ignore non-object nodes on visibility changes. */
+ continue;
+ }
+ int flag = 0;
+ /* We only tag components which needs an update. Tagging everything is
+ * not a good idea because that might reset particles cache (or any
+ * other type of cache).
+ *
+ * TODO(sergey): Need to generalize this somehow.
+ */
+ if (id_type == ID_OB) {
+ flag |= OB_RECALC_OB | OB_RECALC_DATA | DEG_TAG_COPY_ON_WRITE;
+ }
+ deg_graph_id_tag_update(bmain, graph, id_node->id_orig, flag);
}
+ GHASH_FOREACH_END();
+ /* Make sure collection properties are up to date. */
+ IDDepsNode *scene_id_node = graph->find_id_node(&scene->id);
+ BLI_assert(scene_id_node != NULL);
+ scene_id_node->tag_update(graph);
}
+} /* namespace */
+
+} // namespace DEG
+
/* Tag given ID for an update in all the dependency graphs. */
void DEG_id_tag_update(ID *id, int flag)
{
@@ -225,56 +412,13 @@ void DEG_id_tag_update_ex(Main *bmain, ID *id, int flag)
return;
}
DEG_DEBUG_PRINTF("%s: id=%s flag=%d\n", __func__, id->name, flag);
- lib_id_recalc_tag_flag(bmain, id, flag);
- for (Scene *scene = (Scene *)bmain->scene.first;
- scene != NULL;
- scene = (Scene *)scene->id.next)
- {
- if (scene->depsgraph) {
- Depsgraph *graph = scene->depsgraph;
- if (flag == 0) {
- /* TODO(sergey): Currently blender is still tagging IDs
- * for recalc just using flag=0. This isn't totally correct
- * but we'd better deal with such cases and don't fail.
- */
- DEG_graph_id_tag_update(bmain, graph, id);
- continue;
- }
- if (flag & OB_RECALC_DATA && GS(id->name) == ID_OB) {
- Object *object = (Object *)id;
- if (object->data != NULL) {
- DEG_graph_id_tag_update(bmain,
- graph,
- (ID *)object->data);
- }
- }
- if (flag & (OB_RECALC_OB | OB_RECALC_DATA)) {
- DEG_graph_id_tag_update(bmain, graph, id);
- }
- else if (flag & OB_RECALC_TIME) {
- DEG_graph_id_tag_update(bmain, graph, id);
- }
- else if (flag & DEG_TAG_COPY_ON_WRITE) {
-#ifdef WITH_COPY_ON_WRITE
- id_tag_copy_on_write_update(bmain, graph, id);
-#endif
- }
- }
- }
-
-#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
+ DEG::deg_id_tag_update(bmain, id, flag);
}
/* Tag given ID type for update. */
-void DEG_id_type_tag(Main *bmain, short idtype)
+void DEG_id_type_tag(Main *bmain, short id_type)
{
- if (idtype == ID_NT) {
+ if (id_type == ID_NT) {
/* Stupid workaround so parent datablocks of nested nodetree get looped
* over when we loop over tagged datablock types.
*/
@@ -285,7 +429,7 @@ void DEG_id_type_tag(Main *bmain, short idtype)
DEG_id_type_tag(bmain, ID_SCE);
}
- bmain->id_tag_update[BKE_idcode_to_index(idtype)] = 1;
+ bmain->id_tag_update[BKE_idcode_to_index(id_type)] = 1;
}
/* Recursively push updates out to all nodes dependent on this,
@@ -297,25 +441,25 @@ void DEG_ids_flush_tagged(Main *bmain)
scene != NULL;
scene = (Scene *)scene->id.next)
{
- /* TODO(sergey): Only visible scenes? */
- if (scene->depsgraph != NULL) {
- DEG::deg_graph_flush_updates(
- bmain,
- reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph));
- }
+ DEG_scene_flush_update(bmain, scene);
+ }
+}
+
+void DEG_scene_flush_update(Main *bmain, Scene *scene)
+{
+ if (scene->depsgraph_legacy == NULL) {
+ return;
}
+ DEG::deg_graph_flush_updates(
+ bmain,
+ reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph_legacy));
}
/* Update dependency graph when visible scenes/layers changes. */
void DEG_graph_on_visible_update(Main *bmain, Scene *scene)
{
- (void) bmain;
- DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph);
- GHASH_FOREACH_BEGIN(DEG::IDDepsNode *, id_node, graph->id_hash)
- {
- id_node->tag_update(graph);
- }
- GHASH_FOREACH_END();
+ DEG::Depsgraph *graph = (DEG::Depsgraph *)scene->depsgraph_legacy;
+ DEG::deg_graph_on_visible_update(bmain, scene, graph);
}
void DEG_on_visible_update(Main *bmain, const bool UNUSED(do_time))
@@ -324,7 +468,7 @@ void DEG_on_visible_update(Main *bmain, const bool UNUSED(do_time))
scene != NULL;
scene = (Scene *)scene->id.next)
{
- if (scene->depsgraph != NULL) {
+ if (scene->depsgraph_legacy != NULL) {
DEG_graph_on_visible_update(bmain, scene);
}
}
diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cc b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
index bb75a85eea4..0d42acf382a 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cc
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
@@ -98,36 +98,55 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
{
switch (opcode) {
#define STRINGIFY_OPCODE(name) case DEG_OPCODE_##name: return #name
+ /* Generic Operations. */
STRINGIFY_OPCODE(OPERATION);
+ STRINGIFY_OPCODE(PARAMETERS_EVAL);
STRINGIFY_OPCODE(PLACEHOLDER);
+ /* Animation, Drivers, etc. */
STRINGIFY_OPCODE(ANIMATION);
STRINGIFY_OPCODE(DRIVER);
+ /* Transform. */
STRINGIFY_OPCODE(TRANSFORM_LOCAL);
STRINGIFY_OPCODE(TRANSFORM_PARENT);
STRINGIFY_OPCODE(TRANSFORM_CONSTRAINTS);
+ STRINGIFY_OPCODE(TRANSFORM_FINAL);
+ STRINGIFY_OPCODE(TRANSFORM_OBJECT_UBEREVAL);
+ /* Rigid body. */
STRINGIFY_OPCODE(RIGIDBODY_REBUILD);
STRINGIFY_OPCODE(RIGIDBODY_SIM);
- STRINGIFY_OPCODE(TRANSFORM_RIGIDBODY);
- STRINGIFY_OPCODE(TRANSFORM_FINAL);
- STRINGIFY_OPCODE(OBJECT_UBEREVAL);
+ STRINGIFY_OPCODE(RIGIDBODY_TRANSFORM_COPY);
+ /* Geometry. */
STRINGIFY_OPCODE(GEOMETRY_UBEREVAL);
- STRINGIFY_OPCODE(GEOMETRY_PATH);
+ /* Pose. */
STRINGIFY_OPCODE(POSE_INIT);
+ STRINGIFY_OPCODE(POSE_INIT_IK);
STRINGIFY_OPCODE(POSE_DONE);
STRINGIFY_OPCODE(POSE_IK_SOLVER);
STRINGIFY_OPCODE(POSE_SPLINE_IK_SOLVER);
+ /* Bone. */
STRINGIFY_OPCODE(BONE_LOCAL);
STRINGIFY_OPCODE(BONE_POSE_PARENT);
STRINGIFY_OPCODE(BONE_CONSTRAINTS);
STRINGIFY_OPCODE(BONE_READY);
STRINGIFY_OPCODE(BONE_DONE);
- STRINGIFY_OPCODE(PSYS_EVAL);
-
+ /* Particles. */
+ STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL_INIT);
+ STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL);
+ STRINGIFY_OPCODE(PARTICLE_SETTINGS_EVAL);
+ STRINGIFY_OPCODE(PARTICLE_SETTINGS_RECALC_CLEAR);
+ /* Masks. */
+ STRINGIFY_OPCODE(MASK_ANIMATION);
+ STRINGIFY_OPCODE(MASK_EVAL);
+ /* Collections. */
STRINGIFY_OPCODE(SCENE_LAYER_INIT);
STRINGIFY_OPCODE(SCENE_LAYER_EVAL);
STRINGIFY_OPCODE(SCENE_LAYER_DONE);
-
+ /* Copy on write. */
STRINGIFY_OPCODE(COPY_ON_WRITE);
+ /* Shading. */
+ STRINGIFY_OPCODE(SHADING);
+ STRINGIFY_OPCODE(MATERIAL_UPDATE);
+ STRINGIFY_OPCODE(WORLD_UPDATE);
case DEG_NUM_OPCODES: return "SpecialCase";
#undef STRINGIFY_OPCODE
diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h
index 737452549ec..abdedd8adb6 100644
--- a/source/blender/depsgraph/intern/depsgraph_types.h
+++ b/source/blender/depsgraph/intern/depsgraph_types.h
@@ -130,17 +130,21 @@ typedef enum eDepsNode_Type {
DEG_NODE_TYPE_EVAL_PARTICLES,
/* Material Shading Component */
DEG_NODE_TYPE_SHADING,
+ DEG_NODE_TYPE_SHADING_PARAMETERS,
/* Cache Component */
DEG_NODE_TYPE_CACHE,
} eDepsNode_Type;
/* Identifiers for common operations (as an enum). */
typedef enum eDepsOperation_Code {
- /* Generic Operations ------------------------------ */
+ /* Generic Operations. ------------------------------ */
/* Placeholder for operations which don't need special mention */
DEG_OPCODE_OPERATION = 0,
+ /* Generic parameters evaluation. */
+ DEG_OPCODE_PARAMETERS_EVAL,
+
// XXX: Placeholder while porting depsgraph code
DEG_OPCODE_PLACEHOLDER,
@@ -150,7 +154,7 @@ typedef enum eDepsOperation_Code {
/* Driver */
DEG_OPCODE_DRIVER,
- /* Transform --------------------------------------- */
+ /* Transform. -------------------------------------- */
/* Transform entry point - local transforms only */
DEG_OPCODE_TRANSFORM_LOCAL,
/* Parenting */
@@ -160,31 +164,31 @@ typedef enum eDepsOperation_Code {
/* Transform exit point */
DEG_OPCODE_TRANSFORM_FINAL,
/* Handle object-level updates, mainly proxies hacks and recalc flags. */
- DEG_OPCODE_OBJECT_UBEREVAL,
+ DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL,
- /* Rigid body -------------------------------------- */
+ /* Rigid body. -------------------------------------- */
/* Perform Simulation */
DEG_OPCODE_RIGIDBODY_REBUILD,
DEG_OPCODE_RIGIDBODY_SIM,
/* Copy results to object */
- DEG_OPCODE_TRANSFORM_RIGIDBODY,
+ DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY,
- /* Geometry ---------------------------------------- */
+ /* Geometry. ---------------------------------------- */
/* Evaluate the whole geometry, including modifiers. */
DEG_OPCODE_GEOMETRY_UBEREVAL,
- /* Curve Objects - Path Calculation (used for path-following tools, */
- DEG_OPCODE_GEOMETRY_PATH,
- /* Pose -------------------------------------------- */
- /* Init IK Trees, etc. */
+ /* Pose. -------------------------------------------- */
+ /* Init pose, clear flags, etc. */
DEG_OPCODE_POSE_INIT,
+ /* Initialize IK solver related pose stuff. */
+ DEG_OPCODE_POSE_INIT_IK,
/* Free IK Trees + Compute Deform Matrices */
DEG_OPCODE_POSE_DONE,
/* IK/Spline Solvers */
DEG_OPCODE_POSE_IK_SOLVER,
DEG_OPCODE_POSE_SPLINE_IK_SOLVER,
- /* Bone -------------------------------------------- */
+ /* Bone. -------------------------------------------- */
/* Bone local transforms - entry point */
DEG_OPCODE_BONE_LOCAL,
/* Pose-space conversion (includes parent + restpose, */
@@ -205,18 +209,30 @@ typedef enum eDepsOperation_Code {
DEG_OPCODE_BONE_READY,
DEG_OPCODE_BONE_DONE,
- /* Particles --------------------------------------- */
+ /* Particles. --------------------------------------- */
/* Particle System evaluation. */
- DEG_OPCODE_PSYS_EVAL,
+ DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT,
+ DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
+ DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
+ DEG_OPCODE_PARTICLE_SETTINGS_RECALC_CLEAR,
- /* Collections ------------------------------------- */
+ /* Collections. ------------------------------------- */
DEG_OPCODE_SCENE_LAYER_INIT,
DEG_OPCODE_SCENE_LAYER_EVAL,
DEG_OPCODE_SCENE_LAYER_DONE,
- /* Copy on Write ------------------------- */
+ /* Copy on Write. ------------------------------------ */
DEG_OPCODE_COPY_ON_WRITE,
+ /* Shading. ------------------------------------------- */
+ DEG_OPCODE_SHADING,
+ DEG_OPCODE_MATERIAL_UPDATE,
+ DEG_OPCODE_WORLD_UPDATE,
+
+ /* Masks ------------------------------------------- */
+ DEG_OPCODE_MASK_ANIMATION,
+ DEG_OPCODE_MASK_EVAL,
+
DEG_NUM_OPCODES,
} eDepsOperation_Code;
diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc
index 15ad6b8054d..120785ac548 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval.cc
@@ -38,7 +38,10 @@
#include "BLI_task.h"
#include "BLI_ghash.h"
+#include "DNA_object_types.h"
+
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "atomic_ops.h"
@@ -275,6 +278,7 @@ void deg_evaluate_on_refresh(EvaluationContext *eval_ctx,
/* Set time for the current graph evaluation context. */
TimeSourceDepsNode *time_src = graph->find_time_source();
+ eval_ctx->scene_layer = DEG_get_evaluated_scene_layer((::Depsgraph *)graph);
eval_ctx->ctime = time_src->cfra;
/* XXX could use a separate pool for each eval context */
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
index e2c1ef5c220..03be601ce2c 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
@@ -25,7 +25,7 @@
*/
-/** \file blender/depsgraph/intern/eval/deg_eval_copy_on_write.h
+/** \file blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
* \ingroup depsgraph
*/
@@ -65,18 +65,19 @@ extern "C" {
# include "DNA_lamp_types.h"
# include "DNA_linestyle_types.h"
# include "DNA_material_types.h"
-# include "DNA_mesh_types.h"
# include "DNA_node_types.h"
-# include "DNA_scene_types.h"
# include "DNA_texture_types.h"
# include "DNA_world_types.h"
#endif
+#include "BKE_action.h"
#include "BKE_editmesh.h"
#include "BKE_library_query.h"
+#include "BKE_object.h"
}
#include "intern/depsgraph.h"
+#include "intern/builder/deg_builder_nodes.h"
#include "intern/nodes/deg_node.h"
namespace DEG {
@@ -110,7 +111,17 @@ void nested_id_hack_discard_pointers(ID *id_cow)
SPECIAL_CASE(ID_LS, FreestyleLineStyle, nodetree)
SPECIAL_CASE(ID_LA, Lamp, nodetree)
SPECIAL_CASE(ID_MA, Material, nodetree)
+#if 0
SPECIAL_CASE(ID_SCE, Scene, nodetree)
+#else
+ case ID_SCE:
+ {
+ Scene *scene_cow = (Scene *)id_cow;
+ scene_cow->nodetree = NULL;
+ BLI_listbase_clear(&scene_cow->base);
+ break;
+ }
+#endif
SPECIAL_CASE(ID_TE, Tex, nodetree)
SPECIAL_CASE(ID_WO, World, nodetree)
@@ -142,7 +153,17 @@ const ID *nested_id_hack_get_discarded_pointers(NestedIDHackTempStorage *storage
SPECIAL_CASE(ID_LS, FreestyleLineStyle, nodetree, linestyle)
SPECIAL_CASE(ID_LA, Lamp, nodetree, lamp)
SPECIAL_CASE(ID_MA, Material, nodetree, material)
+#if 0
SPECIAL_CASE(ID_SCE, Scene, nodetree, scene)
+#else
+ case ID_SCE:
+ {
+ storage->scene = *(Scene *)id;
+ storage->scene.nodetree = NULL;
+ BLI_listbase_clear(&storage->scene.base);
+ return &storage->scene.id;
+ }
+#endif
SPECIAL_CASE(ID_TE, Tex, nodetree, tex)
SPECIAL_CASE(ID_WO, World, nodetree, world)
@@ -286,19 +307,114 @@ Scene *scene_copy_no_main(Scene *scene)
return new_scene;
}
+/* Check whether given ID is expanded or still a shallow copy. */
+BLI_INLINE bool check_datablock_expanded(const ID *id_cow)
+{
+ return (id_cow->name[0] != '\0');
+}
+
+/* Check whether datablock was already expanded during depsgraph
+ * construction.
+ */
+static bool check_datablock_expanded_at_construction(const ID *id_orig)
+{
+ const ID_Type id_type = GS(id_orig->name);
+ return (id_type == ID_SCE) ||
+ (id_type == ID_OB && ((Object *)id_orig)->type == OB_ARMATURE) ||
+ (id_type == ID_AR);
+}
+
+/* Those are datablocks which are not covered by dependency graph and hence
+ * does not need any remapping or anything.
+ *
+ * TODO(sergey): How to make it more robust for the future, so we don't have
+ * to maintain exception lists all over the code?
+ */
+static bool check_datablocks_copy_on_writable(const ID *id_orig)
+{
+ const ID_Type id_type = GS(id_orig->name);
+ /* We shouldn't bother if copied ID is same as original one. */
+ if (!deg_copy_on_write_is_needed(id_orig)) {
+ return false;
+ }
+ return !ELEM(id_type, ID_BR,
+ ID_LS,
+ ID_AC,
+ ID_GR,
+ ID_PAL);
+}
+
/* Callback for BKE_library_foreach_ID_link which remaps original ID pointer
* with the one created by CoW system.
*/
-int foreach_libblock_remap_callback(void *user_data,
- ID * /*id_self*/,
+
+struct RemapCallbackUserData {
+ /* Dependency graph for which remapping is happening. */
+ const Depsgraph *depsgraph;
+ /* Temporarily allocated memory for copying purposes. This ID will
+ * be discarded after expanding is done, so need to make sure temp_id
+ * is replaced with proper real_id.
+ *
+ * NOTE: This is due to our logic of "inplace" duplication, where we
+ * use generic duplication routines (which gives us new ID) which then
+ * is followed with copying data to a placeholder we prepared before and
+ * discarding pointer returned by duplication routines.
+ */
+ const ID *temp_id;
+ ID *real_id;
+ /* Create placeholder for ID nodes for cases when we need to remap original
+ * ID to it[s CoW version but we don't have required ID node yet.
+ *
+ * This happens when expansion happens a ta construction time.
+ */
+ DepsgraphNodeBuilder *node_builder;
+ bool create_placeholders;
+};
+
+int foreach_libblock_remap_callback(void *user_data_v,
+ ID *id_self,
ID **id_p,
int /*cb_flag*/)
{
- Depsgraph *depsgraph = (Depsgraph *)user_data;
+ RemapCallbackUserData *user_data = (RemapCallbackUserData *)user_data_v;
+ const Depsgraph *depsgraph = user_data->depsgraph;
if (*id_p != NULL) {
- const ID *id_orig = *id_p;
- ID *id_cow = depsgraph->get_cow_id(id_orig);
- if (id_cow != NULL) {
+ ID *id_orig = *id_p;
+ if (id_orig == user_data->temp_id) {
+ DEG_COW_PRINT(" Remapping datablock for %s: id_temp=%p id_cow=%p\n",
+ id_orig->name, id_orig, user_data->real_id);
+ *id_p = user_data->real_id;
+ }
+ else if (check_datablocks_copy_on_writable(id_orig)) {
+ ID *id_cow;
+ if (user_data->create_placeholders) {
+ /* Special workaround to stop creating temp datablocks for
+ * objects which are coming from scene's collection and which
+ * are never linked to any of layers.
+ *
+ * TODO(sergey): Ideally we need to tell ID looper to ignore
+ * those or at least make it more reliable check where the
+ * pointer is coming from.
+ */
+ const ID_Type id_type = GS(id_orig->name);
+ const ID_Type id_type_self = GS(id_self->name);
+ if (id_type == ID_OB && id_type_self == ID_SCE) {
+ IDDepsNode *id_node = depsgraph->find_id_node(id_orig);
+ if (id_node == NULL) {
+ id_cow = id_orig;
+ }
+ else {
+ id_cow = id_node->id_cow;
+ }
+ }
+ else {
+ id_cow = user_data->node_builder->ensure_cow_id(id_orig);
+ }
+ }
+ else {
+ id_cow = depsgraph->get_cow_id(id_orig);
+ }
+ BLI_assert(id_cow != NULL);
DEG_COW_PRINT(" Remapping datablock for %s: id_orig=%p id_cow=%p\n",
id_orig->name, id_orig, id_cow);
*id_p = id_cow;
@@ -307,12 +423,6 @@ int foreach_libblock_remap_callback(void *user_data,
return IDWALK_RET_NOP;
}
-/* Check whether given ID is expanded or still a shallow copy. */
-BLI_INLINE bool check_datablock_expanded(ID *id_cow)
-{
- return (id_cow->name[0] != '\0');
-}
-
/* Do some special treatment of data transfer from original ID to it's
* CoW complementary part.
*
@@ -321,7 +431,7 @@ BLI_INLINE bool check_datablock_expanded(ID *id_cow)
void update_special_pointers(const Depsgraph *depsgraph,
const ID *id_orig, ID *id_cow)
{
- const short type = GS(id_orig->name);
+ const ID_Type type = GS(id_orig->name);
switch (type) {
case ID_OB:
{
@@ -329,14 +439,16 @@ void update_special_pointers(const Depsgraph *depsgraph,
* new copy of the object.
*/
Object *object_cow = (Object *)id_cow;
+ const Object *object_orig = (const Object *)id_orig;
(void) object_cow; /* Ignored for release builds. */
BLI_assert(object_cow->derivedFinal == NULL);
BLI_assert(object_cow->derivedDeform == NULL);
+ object_cow->mode = object_orig->mode;
break;
}
case ID_ME:
{
- /* For meshes we need to update edit_brtmesh to make it to point
+ /* For meshes we need to update edit_btmesh to make it to point
* to the CoW version of object.
*
* This is kind of confusing, because actual bmesh is not owned by
@@ -366,7 +478,76 @@ void update_special_pointers(const Depsgraph *depsgraph,
}
break;
}
+ default:
+ break;
+ }
+}
+
+/* Update copy-on-write version of scene from original scene. */
+void update_copy_on_write_scene(const Depsgraph *depsgraph,
+ Scene *scene_cow,
+ const Scene *scene_orig)
+{
+ // Some non-pointer data sync, current frame for now.
+ // TODO(sergey): Are we missing something here?
+ scene_cow->r.cfra = scene_orig->r.cfra;
+ scene_cow->r.subframe = scene_orig->r.subframe;
+ // Update bases.
+ const SceneLayer *sl_orig = (SceneLayer *)scene_orig->render_layers.first;
+ SceneLayer *sl_cow = (SceneLayer *)scene_cow->render_layers.first;
+ while (sl_orig != NULL) {
+ // Update pointers to active base.
+ if (sl_orig->basact == NULL) {
+ sl_cow->basact = NULL;
+ }
+ else {
+ const Object *obact_orig = sl_orig->basact->object;
+ Object *obact_cow = (Object *)depsgraph->get_cow_id(&obact_orig->id);
+ sl_cow->basact = BKE_scene_layer_base_find(sl_cow, obact_cow);
+ }
+ // Update base flags.
+ //
+ // TODO(sergey): We should probably check visibled/selectabled
+ // flag here?
+ const Base *base_orig = (Base *)sl_orig->object_bases.first;
+ Base *base_cow = (Base *)sl_cow->object_bases.first;;
+ while (base_orig != NULL) {
+ base_cow->flag = base_orig->flag;
+ base_orig = base_orig->next;
+ base_cow = base_cow->next;
+ }
+ sl_orig = sl_orig->next;
+ sl_cow = sl_cow->next;
+ }
+ // Update edit object pointer.
+ if (scene_orig->obedit != NULL) {
+ scene_cow->obedit = (Object *)depsgraph->get_cow_id(&scene_orig->obedit->id);
}
+ else {
+ scene_cow->obedit = NULL;
+ }
+ /* Synchronize active render engine. */
+ BLI_strncpy_utf8(scene_cow->r.engine,
+ scene_orig->r.engine,
+ sizeof(scene_cow->r.engine));
+ /* TODO(sergey): What else do we need here? */
+}
+
+/* Update copy-on-write version of armature object from original scene. */
+void update_copy_on_write_object(const Depsgraph * /*depsgraph*/,
+ Object *object_cow,
+ const Object *object_orig)
+{
+ /* TODO(sergey): This function might be split into a smaller ones,
+ * reused for different updates. And maybe even moved to BKE.
+ */
+ /* Update armature/pose related flags. */
+ bPose *pose_cow = object_cow->pose;
+ const bPose *pose_orig = object_orig->pose;
+ extract_pose_from_pose(pose_cow, pose_orig);
+ /* Update object itself. */
+ BKE_object_transform_copy(object_cow, object_orig);
+ object_cow->mode = object_orig->mode;
}
/* Update copy-on-write version of datablock from it's original ID without re-building
@@ -378,50 +559,37 @@ void update_special_pointers(const Depsgraph *depsgraph,
void update_copy_on_write_datablock(const Depsgraph *depsgraph,
const ID *id_orig, ID *id_cow)
{
- if (GS(id_orig->name) == ID_SCE) {
- const Scene *scene_orig = (const Scene *)id_orig;
- Scene *scene_cow = (Scene *)id_cow;
- // Some non-pointer data sync, current frame for now.
- // TODO(sergey): Are we missing something here?
- scene_cow->r.cfra = scene_orig->r.cfra;
- scene_cow->r.subframe = scene_orig->r.subframe;
- // Update bases.
- const SceneLayer *sl_orig = (SceneLayer *)scene_orig->render_layers.first;
- SceneLayer *sl_cow = (SceneLayer *)scene_cow->render_layers.first;
- while (sl_orig != NULL) {
- // Update pointers to active base.
- if (sl_orig->basact == NULL) {
- sl_cow->basact = NULL;
- }
- else {
- const Object *obact_orig = sl_orig->basact->object;
- Object *obact_cow = (Object *)depsgraph->get_cow_id(&obact_orig->id);
- sl_cow->basact = BKE_scene_layer_base_find(sl_cow, obact_cow);
- }
- // Update base flags.
- //
- // TODO(sergey): We should probably check visibled/selectabled
- // flag here?
- const Base *base_orig = (Base *)sl_orig->object_bases.first;
- Base *base_cow = (Base *)sl_cow->object_bases.first;;
- while (base_orig != NULL) {
- base_cow->flag = base_orig->flag;
- base_orig = base_orig->next;
- base_cow = base_cow->next;
- }
- sl_orig = sl_orig->next;
- sl_cow = sl_cow->next;
- }
- // Update edit object pointer.
- if (scene_orig->obedit != NULL) {
- scene_cow->obedit = (Object *)depsgraph->get_cow_id(&scene_orig->obedit->id);
+ bool ok = false;
+ const ID_Type id_type = GS(id_orig->name);
+ switch (id_type) {
+ case ID_SCE: {
+ const Scene *scene_orig = (const Scene *)id_orig;
+ Scene *scene_cow = (Scene *)id_cow;
+ update_copy_on_write_scene(depsgraph, scene_cow, scene_orig);
+ ok = true;
+ break;
}
- else {
- scene_cow->obedit = NULL;
+ case ID_OB: {
+ const Object *object_orig = (const Object *)id_orig;
+ Object *object_cow = (Object *)id_cow;
+ if (object_orig->type == OB_ARMATURE) {
+ update_copy_on_write_object(depsgraph,
+ object_cow,
+ object_orig);
+ ok = true;
+ }
+ break;
}
- // TODO(sergey): Things which are still missing here:
- // - Active render engine.
- // - Something else?
+ case ID_AR:
+ /* Nothing to do currently. */
+ ok = true;
+ break;
+ default:
+ break;
+ }
+ // TODO(sergey): Other ID types here.
+ if (!ok) {
+ BLI_assert(!"Missing update logic of expanded datablock");
}
}
@@ -437,7 +605,7 @@ int foreach_libblock_validate_callback(void *user_data,
if (*id_p != NULL) {
if (!check_datablock_expanded(*id_p)) {
data->is_valid = false;
- /* TODO(sergey_: Store which is is not valid? */
+ /* TODO(sergey): Store which is is not valid? */
}
}
return IDWALK_RET_NOP;
@@ -451,14 +619,30 @@ int foreach_libblock_validate_callback(void *user_data,
* NOTE: Expects that CoW datablock is empty.
*/
ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
- const IDDepsNode *id_node)
+ const IDDepsNode *id_node,
+ DepsgraphNodeBuilder *node_builder,
+ bool create_placeholders)
{
+ BLI_assert(!create_placeholders ||
+ check_datablock_expanded_at_construction(id_node->id_orig));
const ID *id_orig = id_node->id_orig;
ID *id_cow = id_node->id_cow;
+ /* No need to expand such datablocks, their copied ID is same as original
+ * one already.
+ */
+ if (!deg_copy_on_write_is_needed(id_orig)) {
+ return id_cow;
+ }
DEG_COW_PRINT("Expanding datablock for %s: id_orig=%p id_cow=%p\n",
id_orig->name, id_orig, id_cow);
/* Sanity checks. */
- BLI_assert(check_datablock_expanded(id_cow) == false);
+ /* NOTE: Disabled for now, conflicts when re-using evaluated datablock when
+ * rebuilding dependencies.
+ */
+ if (check_datablock_expanded(id_cow) && create_placeholders) {
+ deg_free_copy_on_write_datablock(id_cow);
+ }
+ // BLI_assert(check_datablock_expanded(id_cow) == false);
/* Copy data from original ID to a copied version. */
/* TODO(sergey): Avoid doing full ID copy somehow, make Mesh to reference
* original geometry arrays for until those are modified.
@@ -472,12 +656,17 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
* - We don't want bmain's content to be freed when main is freed.
*/
bool done = false;
+ /* Need to make sure the possibly temporary allocated memory is correct for
+ * until we are fully done with remapping original pointers with copied on
+ * write ones.
+ */
+ ID *newid = NULL;
/* First we handle special cases which are not covered by id_copy() yet.
* or cases where we want to do something smarter than simple datablock
* copy.
*/
- const short type = GS(id_orig->name);
- switch (type) {
+ const ID_Type id_type = GS(id_orig->name);
+ switch (id_type) {
case ID_SCE:
{
Scene *new_scene = scene_copy_no_main((Scene *)id_orig);
@@ -493,9 +682,10 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
*/
break;
}
+ default:
+ break;
}
if (!done) {
- ID *newid;
if (id_copy_no_main(id_orig, &newid)) {
/* We copy contents of new ID to our CoW placeholder and free ID memory
* returned by id_copy().
@@ -505,7 +695,6 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
*/
const size_t size = BKE_libblock_get_alloc_info(GS(newid->name), NULL);
memcpy(id_cow, newid, size);
- MEM_freeN(newid);
done = true;
}
}
@@ -519,37 +708,62 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
#ifdef NESTED_ID_NASTY_WORKAROUND
ntree_hack_remap_pointers(depsgraph, id_cow);
#endif
-
+ /* Do it now, so remapping will understand that possibly remapped self ID
+ * is not to be remapped again.
+ */
+ deg_tag_copy_on_write_id(id_cow, id_orig);
+ /* Perform remapping of the nodes. */
+ RemapCallbackUserData user_data;
+ user_data.depsgraph = depsgraph;
+ user_data.temp_id = newid;
+ user_data.real_id = id_cow;
+ user_data.node_builder = node_builder;
+ user_data.create_placeholders = create_placeholders;
BKE_library_foreach_ID_link(NULL,
id_cow,
foreach_libblock_remap_callback,
- (void *)depsgraph,
+ (void *)&user_data,
IDWALK_NOP);
/* Correct or tweak some pointers which are not taken care by foreach
* from above.
*/
update_special_pointers(depsgraph, id_orig, id_cow);
+ /* Now we can safely discard temporary memory used for copying. */
+ if (newid != NULL) {
+ MEM_freeN(newid);
+ }
return id_cow;
}
/* NOTE: Depsgraph is supposed to have ID node already. */
-ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph, ID *id_orig)
+ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
+ ID *id_orig,
+ DepsgraphNodeBuilder *node_builder,
+ bool create_placeholders)
{
DEG::IDDepsNode *id_node = depsgraph->find_id_node(id_orig);
BLI_assert(id_node != NULL);
- return deg_expand_copy_on_write_datablock(depsgraph, id_node);
+ return deg_expand_copy_on_write_datablock(depsgraph,
+ id_node,
+ node_builder,
+ create_placeholders);
}
ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
const IDDepsNode *id_node)
{
const ID *id_orig = id_node->id_orig;
+ const ID_Type id_type = GS(id_orig->name);
ID *id_cow = id_node->id_cow;
+ /* Similar to expansion, no need to do anything here. */
+ if (!deg_copy_on_write_is_needed(id_orig)) {
+ return id_cow;
+ }
/* Special case for datablocks which are expanded at the dependency graph
* construction time. This datablocks must never change pointers of their
* nested data since it is used for function bindings.
*/
- if (GS(id_orig->name) == ID_SCE) {
+ if (check_datablock_expanded_at_construction(id_orig)) {
BLI_assert(check_datablock_expanded(id_cow) == true);
update_copy_on_write_datablock(depsgraph, id_orig, id_cow);
return id_cow;
@@ -557,14 +771,82 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
/* For the rest if datablock types we use simple logic:
* - Free previously expanded data, if any.
* - Perform full datablock copy.
+ *
+ * Note that we never free GPU materials from here since that's not
+ * safe for threading and GPU materials are likely to be re-used.
*/
+ ListBase gpumaterial_backup;
+ ListBase *gpumaterial_ptr = NULL;
+ Mesh *mesh_evaluated = NULL;
+ if (check_datablock_expanded(id_cow)) {
+ switch (id_type) {
+ case ID_MA:
+ {
+ Material *material = (Material *)id_cow;
+ gpumaterial_ptr = &material->gpumaterial;
+ break;
+ }
+ case ID_WO:
+ {
+ World *world = (World *)id_cow;
+ gpumaterial_ptr = &world->gpumaterial;
+ break;
+ }
+ case ID_OB:
+ {
+ Object *object = (Object *)id_cow;
+ /* Store evaluated mesh, make sure we don't free it. */
+ mesh_evaluated = object->mesh_evaluated;
+ object->mesh_evaluated = NULL;
+ /* Currently object update will override actual object->data
+ * to an evaluated version. Need to make sure we don't have
+ * data set to evaluated one before free anything.
+ */
+ if (mesh_evaluated != NULL) {
+ if (object->data == mesh_evaluated) {
+ object->data = mesh_evaluated->id.newid;
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ if (gpumaterial_ptr != NULL) {
+ gpumaterial_backup = *gpumaterial_ptr;
+ gpumaterial_ptr->first = gpumaterial_ptr->last = NULL;
+ }
+ }
deg_free_copy_on_write_datablock(id_cow);
deg_expand_copy_on_write_datablock(depsgraph, id_node);
+ /* Restore GPU materials. */
+ if (gpumaterial_ptr != NULL) {
+ *gpumaterial_ptr = gpumaterial_backup;
+ }
+ if (id_type == ID_OB) {
+ if (mesh_evaluated != NULL) {
+ Object *object = (Object *)id_cow;
+ object->mesh_evaluated = mesh_evaluated;
+ /* Do same thing as object update: override actual object data
+ * pointer with evaluated datablock.
+ */
+ if (object->type == OB_MESH) {
+ object->data = mesh_evaluated;
+ /* Evaluated mesh simply copied edit_btmesh pointer from
+ * original mesh during update, need to make sure no dead
+ * pointers are left behind.
+ */
+ mesh_evaluated->edit_btmesh =
+ ((Mesh *)mesh_evaluated->id.newid)->edit_btmesh;
+ }
+ }
+ }
return id_cow;
}
/* NOTE: Depsgraph is supposed to have ID node already. */
-ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph, ID *id_orig)
+ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
+ ID *id_orig)
{
DEG::IDDepsNode *id_node = depsgraph->find_id_node(id_orig);
BLI_assert(id_node != NULL);
@@ -584,7 +866,10 @@ void deg_free_copy_on_write_datablock(ID *id_cow)
*/
return;
}
- const short type = GS(id_cow->name);
+ const ID_Type type = GS(id_cow->name);
+#ifdef NESTED_ID_NASTY_WORKAROUND
+ nested_id_hack_discard_pointers(id_cow);
+#endif
switch (type) {
case ID_OB:
{
@@ -611,22 +896,22 @@ void deg_free_copy_on_write_datablock(ID *id_cow)
/* Special case for scene: we use explicit function call which
* ensures no access to other datablocks is done.
*/
- BKE_scene_free_ex((Scene *)id_cow, false);
+ Scene *scene = (Scene *)id_cow;
+ BKE_scene_free_ex(scene, false);
BKE_libblock_free_data(id_cow, false);
id_cow->name[0] = '\0';
return;
}
+ default:
+ break;
}
-#ifdef NESTED_ID_NASTY_WORKAROUND
- nested_id_hack_discard_pointers(id_cow);
-#endif
- BKE_libblock_free_datablock(id_cow);
+ BKE_libblock_free_datablock(id_cow, 0);
BKE_libblock_free_data(id_cow, false);
/* Signal datablock as not being expanded. */
id_cow->name[0] = '\0';
}
-void deg_evaluate_copy_on_write(EvaluationContext * /*eval_ctx*/,
+void deg_evaluate_copy_on_write(const EvaluationContext * /*eval_ctx*/,
const Depsgraph *depsgraph,
const IDDepsNode *id_node)
{
@@ -649,4 +934,22 @@ bool deg_validate_copy_on_write_datablock(ID *id_cow)
return data.is_valid;
}
+void deg_tag_copy_on_write_id(ID *id_cow, const ID *id_orig)
+{
+ id_cow->tag |= LIB_TAG_COPY_ON_WRITE;
+ /* TODO(sergey): Is it safe to re-use newid for original ID link? */
+ id_cow->newid = (ID *)id_orig;
+}
+
+bool deg_copy_on_write_is_expanded(const ID *id_cow)
+{
+ return check_datablock_expanded(id_cow);
+}
+
+bool deg_copy_on_write_is_needed(const ID *id_orig)
+{
+ const ID_Type id_type = GS(id_orig->name);
+ return !ELEM(id_type, ID_IM);
+}
+
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h
index 0e1b6642002..a2b57cb7198 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h
@@ -30,6 +30,8 @@
#pragma once
+#include <stddef.h>
+
struct EvaluationContext;
struct ID;
@@ -48,20 +50,25 @@ struct ID;
namespace DEG {
struct Depsgraph;
+struct DepsgraphNodeBuilder;
struct IDDepsNode;
/* Get fully expanded (ready for use) copy-on-write datablock for the given
* original datablock.
*/
-ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
- const IDDepsNode *id_node);
ID *deg_expand_copy_on_write_datablock(const struct Depsgraph *depsgraph,
- struct ID *id_orig);
+ const IDDepsNode *id_node,
+ DepsgraphNodeBuilder *node_builder = NULL,
+ bool create_placeholders = false);
+ID *deg_expand_copy_on_write_datablock(const struct Depsgraph *depsgraph,
+ struct ID *id_orig,
+ DepsgraphNodeBuilder *node_builder = NULL,
+ bool create_placeholders = false);
/* Makes sure given CoW datablock is brought back to state of the original
* datablock.
*/
-ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
+ID *deg_update_copy_on_write_datablock(const struct Depsgraph *depsgraph,
const IDDepsNode *id_node);
ID *deg_update_copy_on_write_datablock(const struct Depsgraph *depsgraph,
struct ID *id_orig);
@@ -72,7 +79,7 @@ void deg_free_copy_on_write_datablock(struct ID *id_cow);
/* Callback function for depsgraph operation node which ensures copy-on-write
* datablock is ready for use by further evaluation routines.
*/
-void deg_evaluate_copy_on_write(struct EvaluationContext *eval_ctx,
+void deg_evaluate_copy_on_write(const struct EvaluationContext *eval_ctx,
const struct Depsgraph *depsgraph,
const struct IDDepsNode *id_node);
@@ -81,4 +88,22 @@ void deg_evaluate_copy_on_write(struct EvaluationContext *eval_ctx,
*/
bool deg_validate_copy_on_write_datablock(ID *id_cow);
+/* Tag given ID block as being copy-on-wtritten. */
+void deg_tag_copy_on_write_id(struct ID *id_cow, const struct ID *id_orig);
+
+/* Check whether ID datablock is expanded.
+ *
+ * TODO(sergey): Make it an inline function or a macro.
+ */
+bool deg_copy_on_write_is_expanded(const struct ID *id_cow);
+
+/* Check whether copy-on-write datablock is needed for given ID.
+ *
+ * There are some exceptions on datablocks which are covered by dependency graph
+ * but which we don't want to start duplicating.
+ *
+ * This includes images.
+ */
+bool deg_copy_on_write_is_needed(const ID *id_orig);
+
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
index 605ca990e07..54a3a499e36 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
@@ -50,26 +50,16 @@ extern "C" {
#include "intern/nodes/deg_node_operation.h"
#include "intern/depsgraph_intern.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "util/deg_util_foreach.h"
namespace DEG {
-namespace {
-
-// TODO(sergey): De-duplicate with depsgraph_tag,cc
-void lib_id_recalc_tag(Main *bmain, ID *id)
-{
- id->tag |= LIB_TAG_ID_RECALC;
- DEG_id_type_tag(bmain, GS(id->name));
-}
-
-void lib_id_recalc_data_tag(Main *bmain, ID *id)
-{
- id->tag |= LIB_TAG_ID_RECALC_DATA;
- DEG_id_type_tag(bmain, GS(id->name));
-}
-
-} /* namespace */
+enum {
+ COMPONENT_STATE_NONE = 0,
+ COMPONENT_STATE_SCHEDULED = 1,
+ COMPONENT_STATE_DONE = 2,
+};
typedef std::deque<OperationDepsNode *> FlushQueue;
@@ -83,7 +73,7 @@ static void flush_init_func(void *data_v, int i)
ComponentDepsNode *comp_node = node->owner;
IDDepsNode *id_node = comp_node->owner;
id_node->done = 0;
- comp_node->done = 0;
+ comp_node->done = COMPONENT_STATE_NONE;
node->scheduled = false;
}
@@ -122,10 +112,8 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
*/
GSET_FOREACH_BEGIN(OperationDepsNode *, op_node, graph->entry_tags)
{
- if ((op_node->flag & DEPSOP_FLAG_SKIP_FLUSH) == 0) {
- queue.push_back(op_node);
- op_node->scheduled = true;
- }
+ queue.push_back(op_node);
+ op_node->scheduled = true;
}
GSET_FOREACH_END();
@@ -141,34 +129,51 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
IDDepsNode *id_node = comp_node->owner;
/* TODO(sergey): Do we need to pass original or evaluated ID here? */
- ID *id = id_node->id_orig;
+ ID *id_orig = id_node->id_orig;
+ ID *id_cow = id_node->id_cow;
if (id_node->done == 0) {
- deg_editors_id_update(bmain, id);
- lib_id_recalc_tag(bmain, id);
+ /* Copy tag from original data to CoW storage.
+ * This is because DEG_id_tag_update() sets tags on original
+ * data.
+ */
+ id_cow->tag |= (id_orig->tag & LIB_TAG_ID_RECALC_ALL);
+ if (deg_copy_on_write_is_expanded(id_cow)) {
+ deg_editors_id_update(bmain, id_cow);
+ }
+ lib_id_recalc_tag(bmain, id_orig);
/* TODO(sergey): For until we've got proper data nodes in the graph. */
- lib_id_recalc_data_tag(bmain, id);
+ lib_id_recalc_data_tag(bmain, id_orig);
+ }
+ if (comp_node->done != COMPONENT_STATE_DONE) {
#ifdef WITH_COPY_ON_WRITE
/* Currently this is needed to get ob->mesh to be replaced with
* original mesh (rather than being evaluated_mesh).
*
* TODO(sergey): This is something we need to avoid.
*/
- ComponentDepsNode *cow_comp =
- id_node->find_component(DEG_NODE_TYPE_COPY_ON_WRITE);
- cow_comp->tag_update(graph);
+ if (comp_node->depends_on_cow()) {
+ ComponentDepsNode *cow_comp =
+ id_node->find_component(DEG_NODE_TYPE_COPY_ON_WRITE);
+ cow_comp->tag_update(graph);
+ }
#endif
- }
-
- if (comp_node->done == 0) {
Object *object = NULL;
- if (GS(id->name) == ID_OB) {
- object = (Object *)id;
+ if (GS(id_orig->name) == ID_OB) {
+ object = (Object *)id_orig;
if (id_node->done == 0) {
++num_flushed_objects;
}
}
foreach (OperationDepsNode *op, comp_node->operations) {
+ /* We don't want to flush tags in "upstream" direction for
+ * certain types of operations.
+ *
+ * TODO(sergey): Need a more generic solution for this.
+ */
+ if (op->opcode == DEG_OPCODE_PARTICLE_SETTINGS_EVAL) {
+ continue;
+ }
op->flag |= DEPSOP_FLAG_NEEDS_UPDATE;
}
if (object != NULL) {
@@ -204,15 +209,29 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
case DEG_NODE_TYPE_PROXY:
object->recalc |= OB_RECALC_DATA;
break;
+ case DEG_NODE_TYPE_SHADING_PARAMETERS:
+ break;
}
/* TODO : replace with more granular flags */
object->deg_update_flag |= DEG_RUNTIME_DATA_UPDATE;
}
+ /* When some target changes bone, we might need to re-run the
+ * whole IK solver, otherwise result might be unpredictable.
+ */
+ if (comp_node->type == DEG_NODE_TYPE_BONE) {
+ ComponentDepsNode *pose_comp =
+ id_node->find_component(DEG_NODE_TYPE_EVAL_POSE);
+ BLI_assert(pose_comp != NULL);
+ if (pose_comp->done == COMPONENT_STATE_NONE) {
+ queue.push_front(pose_comp->get_entry_operation());
+ pose_comp->done = COMPONENT_STATE_SCHEDULED;
+ }
+ }
}
id_node->done = 1;
- comp_node->done = 1;
+ comp_node->done = COMPONENT_STATE_DONE;
/* Flush to nodes along links... */
/* TODO(sergey): This is mainly giving speedup due ot less queue pushes, which
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc
index 548911dcfa9..5e7ed249365 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node.cc
@@ -128,8 +128,8 @@ IDDepsNode::ComponentIDKey::ComponentIDKey(eDepsNode_Type type,
bool IDDepsNode::ComponentIDKey::operator== (const ComponentIDKey &other) const
{
- return type == other.type &&
- STREQ(name, other.name);
+ return type == other.type &&
+ STREQ(name, other.name);
}
static unsigned int id_deps_node_hash_key(const void *key_v)
@@ -165,24 +165,43 @@ static void id_deps_node_hash_value_free(void *value_v)
/* Initialize 'id' node - from pointer data given. */
void IDDepsNode::init(const ID *id, const char *UNUSED(subdata))
{
- /* Store ID-pointer. */
BLI_assert(id != NULL);
- this->id_orig = (ID *)id;
- this->eval_flags = 0;
+ /* Store ID-pointer. */
+ id_orig = (ID *)id;
+ eval_flags = 0;
components = BLI_ghash_new(id_deps_node_hash_key,
id_deps_node_hash_key_cmp,
"Depsgraph id components hash");
+}
+void IDDepsNode::init_copy_on_write(ID *id_cow_hint)
+{
#ifdef WITH_COPY_ON_WRITE
/* Create pointer as early as possible, so we can use it for function
* bindings. Rest of data we'll be copying to the new datablock when
* it is actually needed.
*/
- id_cow = (ID *)BKE_libblock_alloc_notest(GS(id->name));
- DEG_COW_PRINT("Create shallow copy for %s: id_orig=%p id_cow=%p\n",
- id_orig->name, id_orig, id_cow);
+ if (id_cow_hint != NULL) {
+ // BLI_assert(deg_copy_on_write_is_needed(id_orig));
+ if (deg_copy_on_write_is_needed(id_orig)) {
+ id_cow = id_cow_hint;
+ }
+ else {
+ id_cow = id_orig;
+ }
+ }
+ else if (deg_copy_on_write_is_needed(id_orig)) {
+ id_cow = (ID *)BKE_libblock_alloc_notest(GS(id_orig->name));
+ DEG_COW_PRINT("Create shallow copy for %s: id_orig=%p id_cow=%p\n",
+ id_orig->name, id_orig, id_cow);
+ deg_tag_copy_on_write_id(id_cow, id_orig);
+ }
+ else {
+ id_cow = id_orig;
+ }
#else
+ UNUSED_VARS(id_cow_hint);
id_cow = id_orig;
#endif
}
@@ -190,17 +209,30 @@ void IDDepsNode::init(const ID *id, const char *UNUSED(subdata))
/* Free 'id' node. */
IDDepsNode::~IDDepsNode()
{
+ destroy();
+}
+
+void IDDepsNode::destroy()
+{
+ if (id_orig == NULL) {
+ return;
+ }
+
BLI_ghash_free(components,
id_deps_node_hash_key_free,
id_deps_node_hash_value_free);
#ifdef WITH_COPY_ON_WRITE
/* Free memory used by this CoW ID. */
- deg_free_copy_on_write_datablock(id_cow);
- MEM_freeN(id_cow);
- DEG_COW_PRINT("Destroy CoW for %s: id_orig=%p id_cow=%p\n",
- id_orig->name, id_orig, id_cow);
+ if (id_cow != id_orig && id_cow != NULL) {
+ deg_free_copy_on_write_datablock(id_cow);
+ MEM_freeN(id_cow);
+ DEG_COW_PRINT("Destroy CoW for %s: id_orig=%p id_cow=%p\n",
+ id_orig->name, id_orig, id_cow);
+ }
#endif
+ /* Tag that the node is freed. */
+ id_orig = NULL;
}
ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type,
@@ -239,6 +271,23 @@ void IDDepsNode::tag_update(Depsgraph *graph)
do_component_tag = true;
}
}
+ else if (comp_node->type == DEG_NODE_TYPE_SHADING) {
+ /* TODO(sergey): For until we properly handle granular flags for DEG_id_tag_update()
+ * we skip flushing here to keep Luca happy.
+ */
+ if (GS(id_orig->name) != ID_MA &&
+ GS(id_orig->name) != ID_WO)
+ {
+ do_component_tag = false;
+ }
+ }
+ else if (comp_node->type == DEG_NODE_TYPE_SHADING_PARAMETERS) {
+ do_component_tag = false;
+ }
+ else if (comp_node->type == DEG_NODE_TYPE_EVAL_PARTICLES) {
+ /* Only do explicit particle settings tagging. */
+ do_component_tag = false;
+ }
if (do_component_tag) {
comp_node->tag_update(graph);
}
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.h b/source/blender/depsgraph/intern/nodes/deg_node.h
index 4e03072d486..16e75b2b5e7 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node.h
+++ b/source/blender/depsgraph/intern/nodes/deg_node.h
@@ -138,7 +138,9 @@ struct IDDepsNode : public DepsNode {
};
void init(const ID *id, const char *subdata);
+ void init_copy_on_write(ID *id_cow_hint = NULL);
~IDDepsNode();
+ void destroy();
ComponentDepsNode *find_component(eDepsNode_Type type,
const char *name = "") const;
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.cc b/source/blender/depsgraph/intern/nodes/deg_node_component.cc
index bd9583a7b67..a250dce1239 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_component.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_component.cc
@@ -396,6 +396,11 @@ static DepsNodeFactoryImpl<ParticlesComponentDepsNode> DNTI_EVAL_PARTICLES;
DEG_DEPSNODE_DEFINE(ShadingComponentDepsNode, DEG_NODE_TYPE_SHADING, "Shading Component");
static DepsNodeFactoryImpl<ShadingComponentDepsNode> DNTI_SHADING;
+/* Shading Parameters Component Defines ============================ */
+
+DEG_DEPSNODE_DEFINE(ShadingParametersComponentDepsNode, DEG_NODE_TYPE_SHADING_PARAMETERS, "Shading Parameters Component");
+static DepsNodeFactoryImpl<ShadingParametersComponentDepsNode> DNTI_SHADING_PARAMETERS;
+
/* Cache Component Defines ============================ */
DEG_DEPSNODE_DEFINE(CacheComponentDepsNode, DEG_NODE_TYPE_CACHE, "Cache Component");
@@ -426,7 +431,9 @@ void deg_register_component_depsnodes()
deg_register_node_typeinfo(&DNTI_BONE);
deg_register_node_typeinfo(&DNTI_EVAL_PARTICLES);
+
deg_register_node_typeinfo(&DNTI_SHADING);
+ deg_register_node_typeinfo(&DNTI_SHADING_PARAMETERS);
deg_register_node_typeinfo(&DNTI_CACHE);
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.h b/source/blender/depsgraph/intern/nodes/deg_node_component.h
index 955d197b33a..d2a375421fd 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_component.h
+++ b/source/blender/depsgraph/intern/nodes/deg_node_component.h
@@ -151,6 +151,7 @@ struct ComponentDepsNode : public DepsNode {
OperationDepsNode *exit_operation;
// XXX: a poll() callback to check if component's first node can be started?
+ virtual bool depends_on_cow() { return true; }
};
/* ---------------------------------------- */
@@ -200,6 +201,11 @@ struct ShadingComponentDepsNode : public ComponentDepsNode {
DEG_DEPSNODE_DECLARE;
};
+struct ShadingParametersComponentDepsNode : public ComponentDepsNode {
+ DEG_DEPSNODE_DECLARE;
+ virtual bool depends_on_cow() { return false; }
+};
+
struct CacheComponentDepsNode : public ComponentDepsNode {
DEG_DEPSNODE_DECLARE;
};
@@ -210,6 +216,8 @@ struct LayerCollectionsDepsNode : public ComponentDepsNode {
struct CopyOnWriteDepsNode : public ComponentDepsNode {
DEG_DEPSNODE_DECLARE;
+
+ virtual bool depends_on_cow() { return false; }
};
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
index 84b3d33f494..7467264f612 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
@@ -76,9 +76,6 @@ string OperationDepsNode::full_identifier() const
void OperationDepsNode::tag_update(Depsgraph *graph)
{
- if (flag & DEPSOP_FLAG_SKIP_FLUSH) {
- flag &= ~DEPSOP_FLAG_SKIP_FLUSH;
- }
if (flag & DEPSOP_FLAG_NEEDS_UPDATE) {
return;
}
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.h b/source/blender/depsgraph/intern/nodes/deg_node_operation.h
index 8a1fadd9c6c..d8203540fc5 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_operation.h
+++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.h
@@ -45,16 +45,6 @@ typedef enum eDepsOperation_Flag {
/* node was directly modified, causing need for update */
DEPSOP_FLAG_DIRECTLY_MODIFIED = (1 << 1),
-
- /* Operation is evaluated using CPython; has GIL and security
- * implications...
- */
- DEPSOP_FLAG_USES_PYTHON = (1 << 2),
-
- /* Special flag which indicates that update tag sohuld not be flushed
- * up to the dependent nodes.
- */
- DEPSOP_FLAG_SKIP_FLUSH = (1 << 3),
} eDepsOperation_Flag;
/* Atomic Operation - Base type for all operations */