[Bf-blender-cvs] [f97d61c4bd2] blender2.8: Depsgraph: Bring back visibility checks based on collection restrict flags
Sergey Sharybin
noreply at git.blender.org
Thu Aug 23 16:41:10 CEST 2018
Commit: f97d61c4bd2a9ab3c1dd0ae4902778bc9703a716
Author: Sergey Sharybin
Date: Thu Aug 23 16:17:06 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBf97d61c4bd2a9ab3c1dd0ae4902778bc9703a716
Depsgraph: Bring back visibility checks based on collection restrict flags
The title says it all actually, the idea is to speedup the following case:
- Visible duplicator of a restricted collection (reported as T56512),
One of the questionable change is that none of the view layer bases is
ignored now. This ensures corresponding objects will have copy-on-write
component evaluated, making it possible to access those pointers. The
evaluation of those objects is skipped.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D3641
===================================================================
M source/blender/depsgraph/intern/builder/deg_builder.cc
M source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
M source/blender/depsgraph/intern/builder/deg_builder_nodes.h
M source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
M source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M source/blender/depsgraph/intern/builder/deg_builder_relations.h
M source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
M source/blender/depsgraph/intern/depsgraph_types.h
M source/blender/depsgraph/intern/eval/deg_eval.cc
M source/blender/depsgraph/intern/nodes/deg_node_id.cc
M source/blender/depsgraph/intern/nodes/deg_node_id.h
===================================================================
diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc
index 8f5925a5ce3..0549ec76f3c 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder.cc
@@ -34,6 +34,8 @@
#include "DNA_object_types.h"
#include "DNA_ID.h"
+#include "BLI_stack.h"
+
extern "C" {
#include "BKE_animsys.h"
}
@@ -43,6 +45,8 @@ extern "C" {
#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_id.h"
+#include "intern/nodes/deg_node_component.h"
+#include "intern/nodes/deg_node_operation.h"
#include "util/deg_util_foreach.h"
@@ -50,8 +54,61 @@ extern "C" {
namespace DEG {
+namespace {
+
+void deg_graph_build_flush_layers(Depsgraph *graph)
+{
+ BLI_Stack *stack = BLI_stack_new(sizeof(OperationDepsNode*),
+ "DEG flush layers stack");
+ foreach (OperationDepsNode *op_node, graph->operations) {
+ op_node->done = 0;
+ op_node->num_links_pending = 0;
+ foreach (DepsRelation *rel, op_node->outlinks) {
+ if ((rel->from->type == DEG_NODE_TYPE_OPERATION) &&
+ (rel->flag & DEPSREL_FLAG_CYCLIC) == 0)
+ {
+ ++op_node->num_links_pending;
+ }
+ }
+ if (op_node->num_links_pending == 0) {
+ BLI_stack_push(stack, &op_node);
+ op_node->done = 1;
+ }
+ }
+ while (!BLI_stack_is_empty(stack)) {
+ OperationDepsNode *op_node;
+ BLI_stack_pop(stack, &op_node);
+ /* Flush layers to parents. */
+ foreach (DepsRelation *rel, op_node->inlinks) {
+ if (rel->from->type == DEG_NODE_TYPE_OPERATION) {
+ OperationDepsNode *op_from = (OperationDepsNode *)rel->from;
+ op_from->owner->owner->is_visible |=
+ op_node->owner->owner->is_visible;
+ }
+ }
+ /* Schedule parent nodes. */
+ foreach (DepsRelation *rel, op_node->inlinks) {
+ if (rel->from->type == DEG_NODE_TYPE_OPERATION) {
+ OperationDepsNode *op_from = (OperationDepsNode *)rel->from;
+ if ((rel->flag & DEPSREL_FLAG_CYCLIC) == 0) {
+ BLI_assert(op_from->num_links_pending > 0);
+ --op_from->num_links_pending;
+ }
+ if (op_from->num_links_pending == 0 && op_from->done == 0) {
+ BLI_stack_push(stack, &op_from);
+ op_from->done = 1;
+ }
+ }
+ }
+ }
+ BLI_stack_free(stack);
+}
+
+} // namespace
+
void deg_graph_build_finalize(Main *bmain, Depsgraph *graph)
{
+ deg_graph_build_flush_layers(graph);
/* Re-tag IDs for update if it was tagged before the relations
* update tag.
*/
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index 8d2960d1587..45c8bb5c93d 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -141,6 +141,8 @@ DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph)
graph_(graph),
scene_(NULL),
view_layer_(NULL),
+ view_layer_index_(-1),
+ collection_(NULL),
cow_id_hash_(NULL)
{
}
@@ -394,7 +396,7 @@ void DepsgraphNodeBuilder::build_id(ID *id) {
build_camera((Camera *)id);
break;
case ID_GR:
- build_collection(DEG_COLLECTION_OWNER_UNKNOWN, (Collection *)id);
+ build_collection((Collection *)id);
break;
case ID_OB:
build_object(-1, (Object *)id, DEG_ID_LINKED_INDIRECTLY);
@@ -445,46 +447,49 @@ void DepsgraphNodeBuilder::build_id(ID *id) {
}
}
-void DepsgraphNodeBuilder::build_collection(
- eDepsNode_CollectionOwner owner_type,
- Collection *collection)
+void DepsgraphNodeBuilder::build_collection(Collection *collection)
{
if (built_map_.checkIsBuiltAndTag(collection)) {
+ /* NOTE: Currently collections restrict flags only depend on collection
+ * itself and do not depend on a "context" (like, particle system
+ * visibility).
+ *
+ * If we ever change this, we need to update restrict flag here for an
+ * already built collection.
+ */
return;
}
- const bool allow_restrict_flags = (owner_type == DEG_COLLECTION_OWNER_SCENE);
- if (allow_restrict_flags) {
- const int restrict_flag = (graph_->mode == DAG_EVAL_VIEWPORT)
- ? COLLECTION_RESTRICT_VIEW
- : COLLECTION_RESTRICT_RENDER;
- if (collection->flag & restrict_flag) {
- return;
- }
- }
+ Collection *current_state_collection = collection_;
+ collection_ = collection;
+ const int restrict_flag = (graph_->mode == DAG_EVAL_VIEWPORT)
+ ? COLLECTION_RESTRICT_VIEW
+ : COLLECTION_RESTRICT_RENDER;
+ const bool is_parent_collection_restricted =
+ (current_state_collection == NULL)
+ ? false
+ : (current_state_collection->flag & restrict_flag);
+ const bool is_collection_restricted = (collection->flag & restrict_flag);
+ const bool is_collection_visible =
+ !is_collection_restricted && !is_parent_collection_restricted;
/* Collection itself. */
- add_id_node(&collection->id);
+ IDDepsNode *id_node = add_id_node(&collection->id);
+ id_node->is_visible = is_collection_visible;
/* Build collection objects. */
LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
- if (allow_restrict_flags) {
- const int restrict_flag = (
- (graph_->mode == DAG_EVAL_VIEWPORT) ?
- OB_RESTRICT_VIEW :
- OB_RESTRICT_RENDER);
- if (cob->ob->restrictflag & restrict_flag) {
- continue;
- }
- }
- build_object(-1, cob->ob, DEG_ID_LINKED_INDIRECTLY);
+ build_object(
+ -1, cob->ob, DEG_ID_LINKED_INDIRECTLY, is_collection_visible);
}
/* Build child collections. */
LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
- build_collection(owner_type, child->collection);
+ build_collection(child->collection);
}
+ collection_ = current_state_collection;
}
void DepsgraphNodeBuilder::build_object(int base_index,
Object *object,
- eDepsNode_LinkedState_Type linked_state)
+ eDepsNode_LinkedState_Type linked_state,
+ bool is_visible)
{
const bool has_object = built_map_.checkIsBuiltAndTag(object);
/* Skip rest of components if the ID node was already there. */
@@ -497,11 +502,13 @@ void DepsgraphNodeBuilder::build_object(int base_index,
build_object_flags(base_index, object, linked_state);
}
id_node->linked_state = max(id_node->linked_state, linked_state);
+ id_node->is_visible |= is_visible;
return;
}
/* Create ID node for object and begin init. */
IDDepsNode *id_node = add_id_node(&object->id);
id_node->linked_state = linked_state;
+ id_node->is_visible = is_visible;
object->customdata_mask = 0;
/* Various flags, flushing from bases/collections. */
build_object_flags(base_index, object, linked_state);
@@ -562,7 +569,7 @@ void DepsgraphNodeBuilder::build_object(int base_index,
}
/* Object dupligroup. */
if (object->dup_group != NULL) {
- build_collection(DEG_COLLECTION_OWNER_OBJECT, object->dup_group);
+ build_collection(object->dup_group);
}
}
@@ -953,7 +960,7 @@ void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
/* objects - simulation participants */
if (rbw->group) {
- build_collection(DEG_COLLECTION_OWNER_OBJECT, rbw->group);
+ build_collection(rbw->group);
FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, object)
{
@@ -1029,7 +1036,7 @@ void DepsgraphNodeBuilder::build_particles(Object *object)
break;
case PART_DRAW_GR:
if (part->dup_group != NULL) {
- build_collection(DEG_COLLECTION_OWNER_OBJECT, part->dup_group);
+ build_collection(part->dup_group);
}
break;
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
index 66293a91e85..aacb0670a41 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
@@ -163,11 +163,11 @@ struct DepsgraphNodeBuilder {
void build_view_layer(Scene *scene,
ViewLayer *view_layer,
eDepsNode_LinkedState_Type linked_state);
- void build_collection(eDepsNode_CollectionOwner owner_type,
- Collection *collection);
+ void build_collection(Collection *collection);
void build_object(int base_index,
Object *object,
- eDepsNode_LinkedState_Type linked_state);
+ eDepsNode_LinkedState_Type linked_state,
+ bool is_visible = true);
void build_object_flags(int base_index,
Object *object,
eDepsNode_LinkedState_Type linked_state);
@@ -245,6 +245,10 @@ protected:
Scene *scene_;
ViewLayer *view_layer_;
int view_layer_index_;
+ /* NOTE: Collection are possibly built recursively, so be careful when
+ * setting the current state.
+ */
+ Collection *collection_;
GHash *cow_id_hash_;
BuilderMap built_map_;
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
index 3d7b2d6d232..409df45de27 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
@@ -75,7 +75,7 @@ void DepsgraphNodeBuilder::build_layer_collections(ListBase *lb)
continue;
}
if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
- build_collection(DEG_COLLECTION_OWNER_SCENE, lc->collection);
+ build_collection(lc->collection);
}
build_layer_collections(&lc->layer_collections);
}
@@ -108,10 +108,9 @@ void DepsgraphNodeBuilder::build_view_layer(
BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER;
LISTBASE_FOREACH(Base *, base, &view_layer->object_bases) {
/* object itself */
- if (base->flag & base_flag) {
- build_object(base_index, base->object, linked_state);
- base->object->select_color = select_color++;
- }
+ const bool is_object_visible = (base->flag & base_flag);
+ build_object(base_index
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list