Blender V5.3
source/blender/depsgraph/intern/builder/pipeline.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "pipeline.h"
10
11#include "BLI_listbase.hh"
12#include "BLI_time.hh"
13
14#include "CLG_log.h"
15
16#include "BKE_global.hh"
17
18#include "DNA_scene_types.h"
19
20#include "deg_builder_cycle.h"
21#include "deg_builder_nodes.h"
24
25namespace blender {
26
27static CLG_LogRef LOG = {"depsgraph"};
28
29namespace deg {
30
31static bool need_sanity_checks()
32{
33#if !defined(NDEBUG)
34 return true;
35#endif
36 return G.debug & G_DEBUG_DEPSGRAPH_BUILD;
37}
38
39static void do_sanity_checks(const Depsgraph *graph,
40 const Set<const ID *> &ids_build_by_node_builder,
41 const Set<const ID *> &ids_build_by_relations_builder)
42{
43 if (ids_build_by_node_builder != ids_build_by_relations_builder) {
44 CLOG_ERROR(&LOG, "Some IDs missed nodes or relations building.");
45 for (const ID *id_iter : ids_build_by_node_builder) {
46 if (!ids_build_by_relations_builder.contains(id_iter)) {
47 CLOG_ERROR(&LOG, "\t- ID '%s' was not built for relations.", id_iter->name);
48 }
49 }
50 for (const ID *id_iter : ids_build_by_relations_builder) {
51 if (!ids_build_by_node_builder.contains(id_iter)) {
52 CLOG_ERROR(&LOG, "\t- ID '%s' was not built for nodes.", id_iter->name);
53 }
54 }
55 }
56
57 for (const IDNode *id_node : graph->id_nodes) {
58 if (!ids_build_by_node_builder.contains(id_node->id_orig)) {
60 "\t+ ID '%s' is in depsgraph but was not built for nodes.",
61 id_node->id_orig->name);
62 }
63
64 if (!ids_build_by_relations_builder.contains(id_node->id_orig)) {
66 "\t+ ID '%s' is in depsgraph but was not built for relations.",
67 id_node->id_orig->name);
68 }
69 }
70
71 for (const ID *id : ids_build_by_node_builder) {
72 if (graph->find_id_node(id) == nullptr) {
73 CLOG_ERROR(&LOG, "\t* ID '%s' was built for nodes but is not in Depsgraph.", id->name);
74 }
75 }
76
77 for (const ID *id : ids_build_by_relations_builder) {
78 if (graph->find_id_node(id) == nullptr) {
79 CLOG_ERROR(&LOG, "\t* ID '%s' was built for relations but is not in Depsgraph.", id->name);
80 }
81 }
82}
83
85 : deg_graph_(reinterpret_cast<Depsgraph *>(graph)),
86 bmain_(deg_graph_->bmain),
87 scene_(deg_graph_->scene),
88 view_layer_(deg_graph_->view_layer)
89{
90}
91
93{
94 double start_time = 0.0;
96 start_time = BLI_time_now_seconds();
97 }
98
103
104 if (need_sanity_checks()) {
106 }
107
109 printf("Depsgraph built in %f seconds.\n", BLI_time_now_seconds() - start_time);
110 }
111}
112
119
121{
122 /* Generate all the nodes in the graph first */
123 std::unique_ptr<DepsgraphNodeBuilder> node_builder = construct_node_builder();
124 node_builder->begin_build();
125 build_nodes(*node_builder);
126 node_builder->end_build();
127
128 if (need_sanity_checks()) {
129 ids_build_by_node_builder_ = node_builder->get_built_ids();
130 }
131}
132
134{
135 /* Hook up relationships between operations - to determine evaluation order. */
136 std::unique_ptr<DepsgraphRelationBuilder> relation_builder = construct_relation_builder();
137 relation_builder->begin_build();
138 build_relations(*relation_builder);
139 relation_builder->build_copy_on_write_relations();
140 relation_builder->build_driver_relations();
141
142 if (need_sanity_checks()) {
143 ids_build_by_relations_builder_ = relation_builder->get_built_ids();
144 }
145}
146
148{
149 /* Detect and solve cycles. */
151 /* Simplify the graph by removing redundant relations (to optimize
152 * traversal later). */
153 /* TODO: it would be useful to have an option to disable this in cases where
154 * it is causing trouble. */
155 if (G.debug_value == 799) {
157 }
158 /* Store pointers to commonly used evaluated datablocks. */
159 deg_graph_->scene_cow = reinterpret_cast<Scene *>(
161 /* Flush visibility layer and re-schedule nodes for update. */
163 DEG_graph_tag_on_visible_update(reinterpret_cast<blender::Depsgraph *>(deg_graph_), false);
164#if 0
166 printf("Consistency validation failed, ABORTING!\n");
167 abort();
168 }
169#endif
170 /* Relations are up to date. */
172}
173
174std::unique_ptr<DepsgraphNodeBuilder> AbstractBuilderPipeline::construct_node_builder()
175{
176 return std::make_unique<DepsgraphNodeBuilder>(bmain_, deg_graph_, &builder_cache_);
177}
178
179std::unique_ptr<DepsgraphRelationBuilder> AbstractBuilderPipeline::construct_relation_builder()
180{
181 return std::make_unique<DepsgraphRelationBuilder>(bmain_, deg_graph_, &builder_cache_);
182}
183
184} // namespace deg
185} // namespace blender
Platform independent time functions.
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
bool contains(const Key &key) const
Definition BLI_set.hh:310
virtual std::unique_ptr< DepsgraphNodeBuilder > construct_node_builder()
virtual void build_nodes(DepsgraphNodeBuilder &node_builder)=0
virtual std::unique_ptr< DepsgraphRelationBuilder > construct_relation_builder()
virtual void build_relations(DepsgraphRelationBuilder &relation_builder)=0
void deg_graph_transitive_reduction(Depsgraph *graph)
void deg_graph_detect_cycles(Depsgraph *graph)
void deg_graph_build_finalize(Main *bmain, Depsgraph *graph)
static void do_sanity_checks(const Depsgraph *graph, const Set< const ID * > &ids_build_by_node_builder, const Set< const ID * > &ids_build_by_relations_builder)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool DEG_debug_consistency_check(Depsgraph *graph)
@ G_DEBUG_DEPSGRAPH_BUILD
@ G_DEBUG_DEPSGRAPH_TIME
Global G
Definition blender.cc:57
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
static CLG_LogRef LOG
Definition logging.cpp:12
double BLI_time_now_seconds()
Definition time.cc:30
void DEG_graph_tag_on_visible_update(Depsgraph *depsgraph, bool do_time)
char name[258]
Definition DNA_ID.h:433
ListBaseT< ViewLayer > view_layers
ID * get_cow_id(const ID *id_orig) const
Definition depsgraph.cc:248
IDNode * find_id_node(const ID *id) const
Definition depsgraph.cc:102