Blender  V2.93
depsgraph.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
30 #pragma once
31 
32 #include <stdlib.h>
33 
34 #include "MEM_guardedalloc.h"
35 
36 #include "DNA_ID.h" /* for ID_Type and INDEX_ID_MAX */
37 
38 #include "BLI_threads.h" /* for SpinLock */
39 
40 #include "DEG_depsgraph.h"
41 #include "DEG_depsgraph_physics.h"
42 
43 #include "intern/debug/deg_debug.h"
44 #include "intern/depsgraph_type.h"
45 
46 struct ID;
47 struct Scene;
48 struct ViewLayer;
49 
50 namespace blender {
51 namespace deg {
52 
53 struct IDNode;
54 struct Node;
55 struct OperationNode;
56 struct Relation;
57 struct TimeSourceNode;
58 
59 /* Dependency Graph object */
60 struct Depsgraph {
63 
65  ~Depsgraph();
66 
69  void tag_time_source();
70 
71  IDNode *find_id_node(const ID *id) const;
72  IDNode *add_id_node(ID *id, ID *id_cow_hint = nullptr);
73  void clear_id_nodes();
74 
75  /* Add new relationship between two nodes. */
76  Relation *add_new_relation(Node *from, Node *to, const char *description, int flags = 0);
77 
78  /* Check whether two nodes are connected by relation with given
79  * description. Description might be nullptr to check ANY relation between
80  * given nodes. */
81  Relation *check_nodes_connected(const Node *from, const Node *to, const char *description);
82 
83  /* Tag a specific node as needing updates. */
85 
86  /* Clear storage used by all nodes. */
87  void clear_all_nodes();
88 
89  /* Copy-on-Write Functionality ........ */
90 
91  /* For given original ID get ID which is created by CoW system. */
92  ID *get_cow_id(const ID *id_orig) const;
93 
94  /* Core Graph Functionality ........... */
95 
96  /* <ID : IDNode> mapping from ID blocks to nodes representing these
97  * blocks, used for quick lookups. */
99 
100  /* Ordered list of ID nodes, order matches ID allocation order.
101  * Used for faster iteration, especially for areas which are critical to
102  * keep exact order of iteration. */
104 
105  /* Top-level time source node. */
107 
108  /* Indicates whether relations needs to be updated. */
110 
111  /* Indicates which ID types were updated. */
113 
114  /* Indicates type of IDs present in the depsgraph. */
116 
117  /* Quick-Access Temp Data ............. */
118 
119  /* Nodes which have been tagged as "directly modified". */
121 
122  /* Convenience Data ................... */
123 
124  /* XXX: should be collected after building (if actually needed?) */
125  /* All operation nodes, sorted in order of single-thread traversal order. */
127 
128  /* Spin lock for threading-critical operations.
129  * Mainly used by graph evaluation. */
131 
132  /* Main, scene, layer, mode this dependency graph is built for. */
137 
138  /* Time at which dependency graph is being or was last evaluated. */
139  float ctime;
140 
141  /* Evaluated version of datablocks we access a lot.
142  * Stored here to save us form doing hash lookup. */
144 
145  /* Active dependency graph is a dependency graph which is used by the
146  * currently active window. When dependency graph is active, it is allowed
147  * for evaluation functions to write animation f-curve result, drivers
148  * result and other selective things (object matrix?) to original object.
149  *
150  * This way we simplify operators, which don't need to worry about where
151  * to read stuff from. */
152  bool is_active;
153 
155 
157 
158  /* Is set to truth for dependency graph which are used for post-processing (compositor and
159  * sequencer).
160  * Such dependency graph needs all view layers (so render pipeline can access names), but it
161  * does not need any bases. */
163 
164  /* Notify editors about changes to IDs in this depsgraph. */
166 
167  /* Cached list of colliders/effectors for collections and the scene
168  * created along with relations, for fast lookup during evaluation. */
170 
172 };
173 
174 } // namespace deg
175 } // namespace blender
pthread_spinlock_t SpinLock
Definition: BLI_threads.h:111
eEvaluationMode
Definition: DEG_depsgraph.h:60
@ DEG_PHYSICS_RELATIONS_NUM
ID and Library types, which are fundamental for sdna.
@ INDEX_ID_MAX
Definition: DNA_ID.h:859
Read Guarded memory(de)allocation.
OperationNode * node
StackEntry * from
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
Definition: node.h:98
ID * get_cow_id(const ID *id_orig) const
Definition: depsgraph.cc:249
Map< const ID *, ListBase * > * physics_relations[DEG_PHYSICS_RELATIONS_NUM]
Definition: depsgraph.h:169
IDNode * find_id_node(const ID *id) const
Definition: depsgraph.cc:112
char id_type_updated[INDEX_ID_MAX]
Definition: depsgraph.h:112
TimeSourceNode * find_time_source() const
Definition: depsgraph.cc:102
IDNode * add_id_node(ID *id, ID *id_cow_hint=nullptr)
Definition: depsgraph.cc:117
OperationNodes operations
Definition: depsgraph.h:126
eEvaluationMode mode
Definition: depsgraph.h:136
MEM_CXX_CLASS_ALLOC_FUNCS("Depsgraph")
Depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition: depsgraph.cc:62
ViewLayer * view_layer
Definition: depsgraph.h:135
Relation * add_new_relation(Node *from, Node *to, const char *description, int flags=0)
Definition: depsgraph.cc:183
char id_type_exist[INDEX_ID_MAX]
Definition: depsgraph.h:115
Map< const ID *, IDNode * > id_hash
Definition: depsgraph.h:98
Vector< OperationNode * > OperationNodes
Definition: depsgraph.h:61
Vector< IDNode * > IDDepsNodes
Definition: depsgraph.h:62
Relation * check_nodes_connected(const Node *from, const Node *to, const char *description)
Definition: depsgraph.cc:209
TimeSourceNode * add_time_source()
Definition: depsgraph.cc:93
DepsgraphDebug debug
Definition: depsgraph.h:154
Set< OperationNode * > entry_tags
Definition: depsgraph.h:120
TimeSourceNode * time_source
Definition: depsgraph.h:106
IDDepsNodes id_nodes
Definition: depsgraph.h:103
void add_entry_tag(OperationNode *node)
Definition: depsgraph.cc:229