diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2018-12-03 18:09:45 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2018-12-03 18:29:06 +0300 |
commit | bb16167fd8727a330a97f591398ac0981c76a562 (patch) | |
tree | 3f19f8097a795242f254a3263bbe84ffb250c774 /source/blender/depsgraph/intern | |
parent | fadad895b2f44044b829e7ffe83174d8ecd8a487 (diff) |
Depsgraph: completely move customdata_mask to the ID node.
Move all mask-related fields from Object and OperationDepsNode
to Object_Runtime and IDDepsNode. Auto-apply DEG_TAG_GEOMETRY
if the mask changes after DEG rebuild. Update DEG API and all
code that uses it.
This fixes "source mesh data is not ready" errors from Data
Transfer modifier when parameters are changed in the UI after
the recent mesh_get_eval_final fix.
Reviewers: sergey
Differential Revision: https://developer.blender.org/D4025
Diffstat (limited to 'source/blender/depsgraph/intern')
14 files changed, 61 insertions, 52 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc index f7b2b482b1f..3fc54fed623 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder.cc @@ -142,6 +142,10 @@ void deg_graph_build_finalize(Main *bmain, Depsgraph *graph) if (id_node->eval_flags != id_node->previous_eval_flags) { flag |= DEG_TAG_TRANSFORM | DEG_TAG_GEOMETRY; } + /* Tag rebuild if the custom data mask changed. */ + if (id_node->customdata_mask != id_node->previous_customdata_mask) { + flag |= DEG_TAG_GEOMETRY; + } if (!deg_copy_on_write_is_expanded(id_node->id_cow)) { flag |= DEG_TAG_COPY_ON_WRITE; /* This means ID is being added to the dependency graph first diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index 55de6110b3b..8726f51012e 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -163,12 +163,14 @@ IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id) ID *id_cow = NULL; IDComponentsMask previously_visible_components_mask = 0; uint32_t previous_eval_flags = 0; + uint64_t previous_customdata_mask = 0; IDInfo *id_info = (IDInfo *)BLI_ghash_lookup(id_info_hash_, id); if (id_info != NULL) { id_cow = id_info->id_cow; previously_visible_components_mask = id_info->previously_visible_components_mask; previous_eval_flags = id_info->previous_eval_flags; + previous_customdata_mask = id_info->previous_customdata_mask; /* Tag ID info to not free the CoW ID pointer. */ id_info->id_cow = NULL; } @@ -176,6 +178,7 @@ IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id) id_node->previously_visible_components_mask = previously_visible_components_mask; id_node->previous_eval_flags = previous_eval_flags; + id_node->previous_customdata_mask = previous_customdata_mask; /* Currently all ID nodes are supposed to have copy-on-write logic. * * NOTE: Zero number of components indicates that ID node was just created. @@ -358,6 +361,7 @@ void DepsgraphNodeBuilder::begin_build() id_info->previously_visible_components_mask = id_node->visible_components_mask; id_info->previous_eval_flags = id_node->eval_flags; + id_info->previous_customdata_mask = id_node->customdata_mask; BLI_ghash_insert(id_info_hash_, id_node->id_orig, id_info); id_node->id_cow = NULL; } @@ -582,7 +586,6 @@ void DepsgraphNodeBuilder::build_object(int base_index, else { id_node->is_directly_visible = is_visible; } - object->customdata_mask = 0; /* Various flags, flushing from bases/collections. */ build_object_flags(base_index, object, linked_state); /* Transform. */ diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h index 3b795bf9d58..cdf1f6ed03d 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h @@ -235,6 +235,8 @@ struct DepsgraphNodeBuilder { IDComponentsMask previously_visible_components_mask; /* Special evaluation flag mask from the previous depsgraph. */ uint32_t previous_eval_flags; + /* Mesh CustomData mask from the previous depsgraph. */ + uint64_t previous_customdata_mask; }; protected: diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index b45d25d4b70..649bc1a4275 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -289,13 +289,16 @@ bool DepsgraphRelationBuilder::has_node(const OperationKey &key) const return find_node(key) != NULL; } -void DepsgraphRelationBuilder::add_customdata_mask(const ComponentKey &key, uint64_t mask) +void DepsgraphRelationBuilder::add_customdata_mask(Object *object, uint64_t mask) { - if (mask != 0) { - OperationDepsNode *node = find_operation_node(key); + if (mask != 0 && object != NULL && object->type == OB_MESH) { + DEG::IDDepsNode *id_node = graph_->find_id_node(&object->id); - if (node != NULL) { - node->customdata_mask |= mask; + if (id_node == NULL) { + BLI_assert(!"ID should always be valid"); + } + else { + id_node->customdata_mask |= mask; } } } @@ -828,7 +831,7 @@ void DepsgraphRelationBuilder::build_object_parent(Object *object) add_relation(parent_key, ob_key, "Vertex Parent"); /* XXX not sure what this is for or how you could be done properly - lukas */ - add_customdata_mask(parent_key, CD_MASK_ORIGINDEX); + add_customdata_mask(object->parent, CD_MASK_ORIGINDEX); ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM); add_relation(transform_key, ob_key, "Vertex Parent TFM"); @@ -1056,9 +1059,7 @@ void DepsgraphRelationBuilder::build_constraints(ID *id, */ 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) { - add_customdata_mask(target_key, CD_MASK_MDEFORMVERT); - } + add_customdata_mask(ct->tar, CD_MASK_MDEFORMVERT); } else if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) { bShrinkwrapConstraint *scon = (bShrinkwrapConstraint *) con->data; @@ -1071,7 +1072,7 @@ void DepsgraphRelationBuilder::build_constraints(ID *id, if (ct->tar->type == OB_MESH && scon->shrinkType != MOD_SHRINKWRAP_NEAREST_VERTEX) { bool track = (scon->flag & CON_SHRINKWRAP_TRACK_NORMAL) != 0; if (track || BKE_shrinkwrap_needs_normals(scon->shrinkType, scon->shrinkMode)) { - add_customdata_mask(target_key, CD_MASK_NORMAL | CD_MASK_CUSTOMLOOPNORMAL); + add_customdata_mask(ct->tar, CD_MASK_NORMAL | CD_MASK_CUSTOMLOOPNORMAL); } if (scon->shrinkType == MOD_SHRINKWRAP_TARGET_PROJECT) { add_special_eval_flag(&ct->tar->id, DAG_EVAL_NEED_SHRINKWRAP_BOUNDARY); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.h b/source/blender/depsgraph/intern/builder/deg_builder_relations.h index c6db975c6c2..face2a1d43f 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.h +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.h @@ -210,7 +210,7 @@ struct DepsgraphRelationBuilder bool check_unique = false, int flags = 0); - void add_customdata_mask(const ComponentKey &key, uint64_t mask); + void add_customdata_mask(Object *object, uint64_t mask); void add_special_eval_flag(ID *object, uint32_t flag); void build_id(ID *id); 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 ff8b13b4442..8de4a1cca07 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc @@ -140,9 +140,7 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *object, * separately. */ ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_GEOMETRY); add_relation(target_key, solver_key, con->name); - if (data->tar->type == OB_MESH) { - add_customdata_mask(target_key, CD_MASK_MDEFORMVERT); - } + add_customdata_mask(data->tar, CD_MASK_MDEFORMVERT); } else { /* Standard Object Target. */ @@ -172,9 +170,7 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *object, * separately. */ ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_GEOMETRY); add_relation(target_key, solver_key, con->name); - if (data->poletar->type == OB_MESH) { - add_customdata_mask(target_key, CD_MASK_MDEFORMVERT); - } + add_customdata_mask(data->poletar, CD_MASK_MDEFORMVERT); } else { ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_TRANSFORM); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc index 999508cffed..866b5e63031 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc @@ -132,15 +132,6 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_la LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) { build_movieclip(clip); } - /* TODO(sergey): Do this flush on CoW object? */ - foreach (OperationDepsNode *node, graph_->operations) { - IDDepsNode *id_node = node->owner->owner; - ID *id = id_node->id_orig; - if (GS(id->name) == ID_OB) { - Object *object = (Object *)id; - object->customdata_mask |= node->customdata_mask; - } - } /* Build all set scenes. */ if (scene->set != NULL) { ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set); diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc index d56c47a0d2a..408c6abb0c9 100644 --- a/source/blender/depsgraph/intern/depsgraph_build.cc +++ b/source/blender/depsgraph/intern/depsgraph_build.cc @@ -130,23 +130,6 @@ void DEG_add_object_relation(DepsNodeHandle *node_handle, description); } -void DEG_add_object_relation_with_customdata(DepsNodeHandle *node_handle, - Object *object, - eDepsObjectComponentType component, - uint64_t customdata_mask, - const char *description) -{ - DEG::eDepsNode_Type type = deg_build_object_component_type(component); - DEG::ComponentKey comp_key(&object->id, type); - DEG::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle); - deg_node_handle->builder->add_node_handle_relation(comp_key, - deg_node_handle, - description); - if (object->type == OB_MESH) { - deg_node_handle->builder->add_customdata_mask(comp_key, customdata_mask); - } -} - void DEG_add_object_cache_relation(DepsNodeHandle *node_handle, CacheFile *cache_file, eDepsObjectComponentType component, @@ -210,6 +193,14 @@ void DEG_add_special_eval_flag(struct DepsNodeHandle *node_handle, deg_node_handle->builder->add_special_eval_flag(id, flag); } +void DEG_add_customdata_mask(struct DepsNodeHandle *node_handle, + struct Object *object, + uint64_t mask) +{ + DEG::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle); + deg_node_handle->builder->add_customdata_mask(object, mask); +} + struct ID *DEG_get_id_from_handle(struct DepsNodeHandle *node_handle) { DEG::DepsNodeHandle *deg_handle = get_node_handle(node_handle); diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc index 946917afb26..c6ade6ac4c3 100644 --- a/source/blender/depsgraph/intern/depsgraph_query.cc +++ b/source/blender/depsgraph/intern/depsgraph_query.cc @@ -122,6 +122,28 @@ uint32_t DEG_get_eval_flags_for_id(const Depsgraph *graph, ID *id) return id_node->eval_flags; } +uint64_t DEG_get_customdata_mask_for_object(const Depsgraph *graph, Object *ob) +{ + if (graph == NULL) { + /* Happens when converting objects to mesh from a python script + * after modifying scene graph. + * + * Currently harmless because it's only called for temporary + * objects which are out of the DAG anyway. + */ + return 0; + } + + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + const DEG::IDDepsNode *id_node = deg_graph->find_id_node(DEG_get_original_id(&ob->id)); + if (id_node == NULL) { + /* TODO(sergey): Does it mean we need to check set scene? */ + return 0; + } + + return id_node->customdata_mask; +} + Scene *DEG_get_evaluated_scene(const Depsgraph *graph) { const DEG::Depsgraph *deg_graph = 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 89d3740c43e..21ca1636880 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 @@ -812,7 +812,6 @@ static void deg_update_copy_on_write_animation(const Depsgraph *depsgraph, typedef struct ObjectRuntimeBackup { Object_Runtime runtime; short base_flag; - CustomDataMask lastDataMask; } ObjectRuntimeBackup; /* Make a backup of object's evaluation runtime data, additionally @@ -836,7 +835,6 @@ static void deg_backup_object_runtime( } /* Make a backup of base flags. */ object_runtime_backup->base_flag = object->base_flag; - object_runtime_backup->lastDataMask = object->lastDataMask; } static void deg_restore_object_runtime( @@ -871,7 +869,6 @@ static void deg_restore_object_runtime( } } object->base_flag = object_runtime_backup->base_flag; - object->lastDataMask = object_runtime_backup->lastDataMask; } ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph, diff --git a/source/blender/depsgraph/intern/nodes/deg_node_id.cc b/source/blender/depsgraph/intern/nodes/deg_node_id.cc index b194e304e99..d431e68f904 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_id.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_id.cc @@ -104,6 +104,8 @@ void IDDepsNode::init(const ID *id, const char *UNUSED(subdata)) id_orig = (ID *)id; eval_flags = 0; previous_eval_flags = 0; + customdata_mask = 0; + previous_customdata_mask = 0; linked_state = DEG_ID_LINKED_INDIRECTLY; is_directly_visible = true; is_collection_fully_expanded = false; diff --git a/source/blender/depsgraph/intern/nodes/deg_node_id.h b/source/blender/depsgraph/intern/nodes/deg_node_id.h index f8d05eddffd..a968794e3b2 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_id.h +++ b/source/blender/depsgraph/intern/nodes/deg_node_id.h @@ -81,6 +81,10 @@ struct IDDepsNode : public DepsNode { uint32_t eval_flags; uint32_t previous_eval_flags; + /* Extra customdata mask which needs to be evaluated for the mesh object. */ + uint64_t customdata_mask; + uint64_t previous_customdata_mask; + eDepsNode_LinkedState_Type linked_state; /* Indicates the datablock is visible in the evaluated scene. */ diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc index ef1882dd715..f6fee6acf23 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc +++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc @@ -46,8 +46,7 @@ namespace DEG { OperationDepsNode::OperationDepsNode() : name_tag(-1), - flag(0), - customdata_mask(0) + flag(0) { } diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.h b/source/blender/depsgraph/intern/nodes/deg_node_operation.h index 71c03945d48..9ba3a0b4864 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_operation.h +++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.h @@ -93,9 +93,6 @@ struct OperationDepsNode : public DepsNode { /* (eDepsOperation_Flag) extra settings affecting evaluation. */ int flag; - /* Extra customdata mask which needs to be evaluated for the object. */ - uint64_t customdata_mask; - DEG_DEPSNODE_DECLARE; }; |