41 for (
const int i :
nodes.index_range()) {
43 node.runtime->index_in_tree = i;
46 if (
node.is_group()) {
55 tree_runtime.
links.clear();
61 tree_runtime.
links.append(&link);
73 node_runtime.
inputs.clear();
101 node_runtime.
panels.reinitialize(
node->num_panel_states);
130 node->runtime->has_available_linked_inputs =
false;
131 node->runtime->has_available_linked_outputs =
false;
137 if (link->is_available()) {
148 return a->multi_input_sort_id > b->multi_input_sort_id;
162 bool only_follow_first_input_link,
167 if (sockets_in_current_chain.
contains(&input_socket)) {
171 sockets_in_current_chain.
append(&input_socket);
174 if (only_follow_first_input_link) {
175 links_to_check = links_to_check.
take_front(1);
178 if (link->is_muted()) {
181 if (!link->is_available()) {
185 bNode &origin_node = *link->fromnode;
186 if (!origin_socket.is_available()) {
190 if (origin_node.is_reroute()) {
193 r_skipped_origins.
append(&reroute_input);
194 r_skipped_origins.
append(&reroute_output);
196 reroute_input,
false, sockets_in_current_chain, r_logical_origins, r_skipped_origins);
199 if (origin_node.is_muted()) {
201 r_skipped_origins.
append(&origin_socket);
202 r_skipped_origins.
append(mute_input);
204 *mute_input,
true, sockets_in_current_chain, r_logical_origins, r_skipped_origins);
208 r_logical_origins.
append(&origin_socket);
211 sockets_in_current_chain.
pop_last();
220 for (const int i : range) {
221 bNode &node = *nodes[i];
222 for (bNodeSocket *socket : node.runtime->inputs) {
223 Vector<bNodeSocket *, 16> sockets_in_current_chain;
224 socket->runtime->logically_linked_sockets.clear();
225 socket->runtime->logically_linked_skipped_sockets.clear();
226 find_logical_origins_for_socket_recursive(
229 sockets_in_current_chain,
230 socket->runtime->logically_linked_sockets,
231 socket->runtime->logically_linked_skipped_sockets);
238 for (const int i : range) {
239 bNode &node = *nodes[i];
240 for (bNodeSocket *socket : node.runtime->outputs) {
241 socket->runtime->logically_linked_sockets.clear();
271 for (bNode *node : nodes.slice(range)) {
272 node->runtime->inputs_by_identifier.clear();
273 node->runtime->outputs_by_identifier.clear();
274 for (bNodeSocket *socket : node->runtime->inputs) {
275 BLI_assert(socket->identifier == socket->identifier_ustr());
276 node->runtime->inputs_by_identifier.add_new(socket->identifier_ustr(), socket);
278 for (bNodeSocket *socket : node->runtime->outputs) {
279 BLI_assert(socket->identifier == socket->identifier_ustr());
280 node->runtime->outputs_by_identifier.add_new(socket->identifier_ustr(), socket);
303 for (
const bNode *input_node :
307 origin_nodes.
append(input_node);
320 target_nodes.
append(output_node);
331 bool &r_cycle_detected)
335 int socket_index = 0;
337 int implicit_link_index = 0;
341 nodes_to_check.
push({&start_node});
342 node_states[start_node.index()].is_in_stack =
true;
343 while (!nodes_to_check.
is_empty()) {
344 Item &item = nodes_to_check.
peek();
346 bool pushed_node =
false;
348 auto handle_linked_node = [&](
bNode &linked_node) {
350 if (linked_node_state.
is_done) {
355 r_cycle_detected =
true;
358 nodes_to_check.
push({&linked_node});
366 node.runtime->inputs :
367 node.runtime->outputs;
369 if (item.socket_index == sockets.
size()) {
375 if (item.link_index == linked_links.
size()) {
381 bNodeLink &link = *linked_links[item.link_index];
382 if (!link.is_available()) {
389 if (handle_linked_node(linked_node)) {
404 if (item.implicit_link_index == implicitly_linked_nodes.
size()) {
408 const bNode &linked_node = *implicitly_linked_nodes[item.implicit_link_index];
409 if (handle_linked_node(
const_cast<bNode &
>(linked_node))) {
411 item.implicit_link_index++;
425 nodes_to_check.
pop();
433 bool &r_cycle_detected)
436 r_sorted_nodes.
clear();
438 r_cycle_detected =
false;
442 if (node_states[
node->index()].is_done) {
447 node->runtime->has_available_linked_outputs :
448 node->runtime->has_available_linked_inputs)
454 ntree, direction, *
node, node_states, r_sorted_nodes, r_cycle_detected);
458 r_cycle_detected =
true;
460 if (node_states[
node->index()].is_done) {
466 ntree, direction, *
node, node_states, r_sorted_nodes, r_cycle_detected);
481 if (!
node->parent &&
node->is_frame()) {
493 node->runtime->direct_children_in_frame.clear();
498 frame->runtime->direct_children_in_frame.append(
node);
508 if (group_output_nodes.
is_empty()) {
511 else if (group_output_nodes.
size() == 1) {
516 for (
bNode *group_output : group_output_nodes) {
529 if (!
node->is_reroute()) {
539 const bNode &source_node = *links.
first()->fromnode;
557 [&]() { update_logically_linked_sockets(ntree); },
558 [&]() { update_sockets_by_identifier(ntree); },
560 update_toposort(ntree,
561 ToposortDirection::LeftToRight,
562 tree_runtime.toposort_left_to_right,
563 tree_runtime.has_available_link_cycle);
564 for (const int i : tree_runtime.toposort_left_to_right.index_range()) {
565 const bNode &node = *tree_runtime.toposort_left_to_right[i];
566 node.runtime->toposort_left_to_right_index = i;
575 node.runtime->toposort_right_to_left_index = i;
593 input_socket_index_ = link.
tosock->index();
595 const_cast<const bNodeSocket *
>(link.
tosock)->directly_linked_links().first_index(&link);
605 const bNode *to_node = ntree.node_by_id(to_node_id_);
609 if (input_socket_index_ >= to_node->input_sockets().size()) {
612 const bNodeSocket &input_socket = to_node->input_socket(input_socket_index_);
613 if (input_link_index_ >= input_socket.directly_linked_links().size()) {
616 return input_socket.directly_linked_links()[input_link_index_];
621void bNodeTree::ensure_topology_cache()
const
626const bNestedNodeRef *bNodeTree::find_nested_node_ref(
const int32_t nested_node_id)
const
628 for (
const bNestedNodeRef &ref : this->nested_node_refs_span()) {
629 if (ref.id == nested_node_id) {
636const bNestedNodeRef *bNodeTree::nested_node_ref_from_node_id_path(
642 for (
const bNestedNodeRef &ref : this->nested_node_refs_span()) {
643 Vector<int> current_node_ids;
644 if (this->node_id_path_from_nested_node_ref(ref.id, current_node_ids)) {
645 if (current_node_ids.as_span() == node_ids) {
653bool bNodeTree::node_id_path_from_nested_node_ref(
const int32_t nested_node_id,
654 Vector<int> &r_node_ids)
const
656 const bNestedNodeRef *ref = this->find_nested_node_ref(nested_node_id);
657 if (ref ==
nullptr) {
660 const int32_t node_id = ref->path.node_id;
661 const bNode *
node = this->node_by_id(node_id);
662 if (
node ==
nullptr) {
665 r_node_ids.append(node_id);
666 if (!
node->is_group()) {
669 const bNodeTree *group =
reinterpret_cast<const bNodeTree *
>(
node->id);
670 if (group ==
nullptr) {
673 return group->node_id_path_from_nested_node_ref(ref->path.id_in_node, r_node_ids);
676const bNode *bNodeTree::find_nested_node(
const int32_t nested_node_id,
677 const bNodeTree **r_tree)
const
679 const bNestedNodeRef *ref = this->find_nested_node_ref(nested_node_id);
680 if (ref ==
nullptr) {
683 const int32_t node_id = ref->path.node_id;
684 const bNode *
node = this->node_by_id(node_id);
685 if (
node ==
nullptr) {
688 if (!
node->is_group()) {
694 const bNodeTree *group =
reinterpret_cast<const bNodeTree *
>(
node->id);
695 if (group ==
nullptr) {
698 return group->find_nested_node(ref->path.id_in_node, r_tree);
701const bNodeSocket &bNode::socket_by_decl(
const nodes::SocketDeclaration &decl)
const
703 return decl.in_out ==
SOCK_IN ? this->input_socket(decl.index) : this->output_socket(decl.
index);
706bNodeSocket &bNode::socket_by_decl(
const nodes::SocketDeclaration &decl)
708 return decl.in_out ==
SOCK_IN ? this->input_socket(decl.index) : this->output_socket(decl.
index);
719bool bNodeSocket::affects_node_output()
const
722 BLI_assert(bke::node_tree_runtime::topology_cache_is_available(*
this));
723 const bNodeTree &tree = this->owner_tree();
724 ensure_inference_usage_cache(tree);
725 return tree.runtime->inferenced_socket_usage[this->index_in_tree()].is_used;
728bool bNodeSocket::inferred_socket_visibility()
const
730 BLI_assert(bke::node_tree_runtime::topology_cache_is_available(*
this));
731 const bNode &
node = this->owner_node();
732 if (
node.typeinfo->ignore_inferred_input_socket_visibility) {
735 const bNodeTree &tree = this->owner_tree();
738 return tree.runtime->inferenced_socket_usage[this->index_in_tree()].is_visible;
constexpr bool is_empty() const
void ensure(const FunctionRef< void()> compute_cache)
constexpr const T & first() const
constexpr int64_t size() const
constexpr Span take_front(int64_t n) const
constexpr bool is_empty() const
void push(const T &value)
bool contains(const Key &key) const
bool contains(const T &value) const
void append(const T &value)
void reserve(const int64_t min_capacity)
bool has_available_linked_inputs
Array< bNodePanelRuntime > panels
Vector< bNodeSocket * > outputs
Vector< bNodeSocket * > inputs
bool has_available_linked_outputs
Vector< bNodeSocket * > directly_linked_sockets
Vector< bNodeSocket * > logically_linked_sockets
int index_in_inout_sockets
bNodeSocket * internal_link_input
Vector< bNodeLink * > directly_linked_links
Vector< bNode * > root_frames
Vector< bNodeSocket * > output_sockets
Vector< bNode * > toposort_right_to_left
Vector< bNode * > group_nodes
Array< nodes::socket_usage_inference::SocketUsage > inferenced_socket_usage
bNode * group_output_node
Vector< bNodeSocket * > sockets
CacheMutex topology_cache_mutex
bool has_undefined_nodes_or_sockets
CacheMutex geometry_nodes_lazy_function_graph_info_mutex
Vector< bNodeLink * > links
CacheMutex inferenced_input_socket_usage_mutex
std::atomic< bool > topology_cache_exists
MultiValueMap< const bNodeType *, bNode * > nodes_by_type
NodeIDVectorSet nodes_by_id
Vector< bNode * > toposort_left_to_right
Vector< bNodeSocket * > input_sockets
virtual const int & get_corresponding_output_id(const bNode &input_bnode) const =0
const bNode * get_corresponding_output(const bNodeTree &tree, const bNode &input_bnode) const
static void toposort_from_start_node(const bNodeTree &ntree, const ToposortDirection direction, bNode &start_node, MutableSpan< ToposortNodeState > node_states, Vector< bNode * > &r_sorted_nodes, bool &r_cycle_detected)
static void update_dangling_reroute_nodes(const bNodeTree &ntree)
static void update_nodes_by_type(const bNodeTree &ntree)
static void update_direct_frames_childrens(const bNodeTree &ntree)
static Vector< const bNode * > get_implicit_origin_nodes(const bNodeTree &ntree, bNode &node)
static void update_group_output_node(const bNodeTree &ntree)
static void update_link_vector(const bNodeTree &ntree)
static void update_sockets_by_identifier(const bNodeTree &ntree)
static void update_logically_linked_sockets(const bNodeTree &ntree)
static void ensure_topology_cache(const bNodeTree &ntree)
static void find_logical_origins_for_socket_recursive(bNodeSocket &input_socket, bool only_follow_first_input_link, Vector< bNodeSocket *, 16 > &sockets_in_current_chain, Vector< bNodeSocket * > &r_logical_origins, Vector< bNodeSocket * > &r_skipped_origins)
static void update_internal_link_inputs(const bNodeTree &ntree)
static void update_panels(const bNodeTree &ntree)
static void update_node_vector(const bNodeTree &ntree)
static void update_directly_linked_links_and_sockets(const bNodeTree &ntree)
static void update_root_frames(const bNodeTree &ntree)
static void update_toposort(const bNodeTree &ntree, const ToposortDirection direction, Vector< bNode * > &r_sorted_nodes, bool &r_cycle_detected)
void preprocess_geometry_node_tree_for_evaluation(bNodeTree &tree_cow)
static Vector< const bNode * > get_implicit_target_nodes(const bNodeTree &ntree, bNode &node)
static void update_socket_vectors_and_owner_node(const bNodeTree &ntree)
const bNodeZoneType * zone_type_by_node_type(const int node_type)
bNodeSocketType NodeSocketTypeUndefined
Span< int > all_zone_output_node_types()
bNodeType * node_type_find(UString idname)
Span< int > all_zone_input_node_types()
Array< SocketUsage > infer_all_sockets_usage(const bNodeTree &tree)
const std::shared_ptr< const GeometryNodesLazyFunctionGraphInfo > & ensure_geometry_nodes_lazy_function_graph(const bNodeTree &btree)
void parallel_invoke(Functions &&...functions)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void ensure_inference_usage_cache(const bNodeTree &tree)
bke::bNodeSocketType * typeinfo
bke::bNodeSocketRuntime * runtime
ListBaseT< bNodeLink > links
bke::bNodeTreeRuntime * runtime
bke::bNodeRuntime * runtime
bNodeLink * try_find(bNodeTree &ntree) const
NodeLinkKey(const bNodeLink &link)