114 for (
const bNode *node :
tree.all_nodes()) {
115 const aal::RelationsInNode *node_relations =
nullptr;
116 switch (node->type_legacy) {
122 aal::RelationsInNode &relations = scope.
construct<aal::RelationsInNode>();
125 int prev_geometry_index = -1;
126 for (
const int i : node->input_sockets().index_range()) {
129 prev_geometry_index =
i;
132 if (prev_geometry_index == -1) {
136 relations.eval_relations.append({
i, prev_geometry_index});
142 int prev_geometry_index = -1;
143 for (
const int i : node->output_sockets().index_range()) {
146 prev_geometry_index =
i;
148 if (prev_geometry_index == -1) {
152 relations.available_relations.append({
i, prev_geometry_index});
156 node_relations = &relations;
161 aal::RelationsInNode &relations = scope.
construct<aal::RelationsInNode>();
162 for (
const bNodeSocket *socket : node->output_sockets()) {
164 for (
const bNodeSocket *other_output : node->output_sockets()) {
166 relations.available_relations.append({other_output->index(), socket->index()});
171 for (
const bNodeSocket *socket : node->input_sockets()) {
173 for (
const bNodeSocket *other_input : node->input_sockets()) {
175 relations.eval_relations.append({other_input->index(), socket->index()});
184 const int input_items_start = 1;
185 const int output_items_start = 1;
186 const int items_num = node->output_sockets().size() - 1 - output_items_start;
188 const int input_index = input_items_start +
i;
189 const int output_index = output_items_start +
i;
190 const bNodeSocket &input_socket = node->input_socket(input_index);
192 relations.propagate_relations.append({input_index, output_index});
195 relations.reference_relations.append({input_index, output_index});
199 node_relations = &relations;
203 static const aal::RelationsInNode reroute_relations = []() {
204 aal::RelationsInNode relations;
205 relations.propagate_relations.append({0, 0});
206 relations.reference_relations.append({0, 0});
209 node_relations = &reroute_relations;
215 if (group->runtime->reference_lifetimes_info) {
216 node_relations = &group->runtime->reference_lifetimes_info->tree_relations;
223 node_relations = node_decl->anonymous_attribute_relations();
228 relations_by_node[node->index()] = node_relations;
230 return relations_by_node;
244 for (
const int input_i : interface_inputs.
index_range()) {
253 for (
const int output_i : interface_outputs.
index_range()) {
258 r_group_output_reference_sets.
append(
263 for (
const int input_i : interface_inputs.
index_range()) {
268 for (
const bNode *node :
tree.group_input_nodes()) {
269 const bNodeSocket &socket = node->output_socket(input_i);
271 source.potential_data_origins.append(&socket);
277 for (
const bNode *node :
tree.all_nodes()) {
278 if (node->is_muted()) {
281 if (
const aal::RelationsInNode *relations = relations_by_node[node->index()]) {
282 for (
const aal::AvailableRelation &relation : relations->available_relations) {
283 const bNodeSocket &data_socket = node->output_socket(relation.geometry_output);
284 const bNodeSocket &reference_socket = node->output_socket(relation.field_output);
285 if (!reference_socket.is_available() || !reference_socket.is_available()) {
288 if (!reference_socket.is_directly_linked() || !data_socket.is_directly_linked()) {
292 reference_sets.
last().potential_data_origins.append(&data_socket);
299 return reference_sets;
308 const int old_reference_sets_count = reference_sets.
size();
310 for (
const int input_i :
IndexRange(storage.input_items.items_num)) {
311 const bNodeSocket &socket = input_node.output_socket(input_i);
317 for (
const int output_i :
IndexRange(storage.output_items.items_num)) {
318 const bNodeSocket &socket = output_node.input_socket(output_i);
320 r_output_set_sources_by_closure_zone.
add(
327 old_reference_sets_count);
328 for (
const int input_i :
IndexRange(storage.input_items.items_num)) {
329 const bNodeSocket &socket = input_node.output_socket(input_i);
332 source.potential_data_origins.append(&socket);
337 return reference_sets;
402 bool needs_extra_pass =
false;
404 for (
const bNode *node :
tree.toposort_left_to_right()) {
405 for (
const bNodeSocket *socket : node->input_sockets()) {
406 if (!socket->is_available()) {
409 const int dst_index = socket->index_in_tree();
410 for (
const bNodeLink *link : socket->directly_linked_links()) {
411 if (!link->is_used()) {
414 const int src_index = link->fromsock->index_in_tree();
415 r_potential_data_by_socket[dst_index] |= r_potential_data_by_socket[src_index];
416 r_potential_reference_by_socket[dst_index] |= r_potential_reference_by_socket[src_index];
419 if (node->is_muted()) {
420 for (
const bNodeLink &link : node->internal_links()) {
423 if (!input_socket.is_available() || !output_socket.is_available()) {
426 const int src_index = input_socket.index_in_tree();
427 const int dst_index = output_socket.index_in_tree();
428 r_potential_data_by_socket[dst_index] |= r_potential_data_by_socket[src_index];
429 r_potential_reference_by_socket[dst_index] |= r_potential_reference_by_socket[src_index];
433 if (
const aal::RelationsInNode *relations = relations_by_node[node->index()]) {
435 for (
const aal::ReferenceRelation &relation : relations->reference_relations) {
436 const bNodeSocket &from_socket = node->input_socket(relation.from_field_input);
437 const bNodeSocket &to_socket = node->output_socket(relation.to_field_output);
438 if (!from_socket.is_available() || !to_socket.is_available()) {
441 const int src_index = from_socket.index_in_tree();
442 const int dst_index = to_socket.index_in_tree();
443 r_potential_reference_by_socket[dst_index] |= r_potential_reference_by_socket[src_index];
446 for (
const aal::PropagateRelation &relation : relations->propagate_relations) {
447 const bNodeSocket &from_socket = node->input_socket(relation.from_geometry_input);
448 const bNodeSocket &to_socket = node->output_socket(relation.to_geometry_output);
449 if (!from_socket.is_available() || !to_socket.is_available()) {
452 const int src_index = from_socket.index_in_tree();
453 const int dst_index = to_socket.index_in_tree();
454 r_potential_data_by_socket[dst_index] |= r_potential_data_by_socket[src_index];
457 switch (node->type_legacy) {
466 const bNode *output_node = node;
469 const int src_index = input_node->input_socket(0).index_in_tree();
470 for (
const bNodeSocket *output_socket : output_node->output_sockets()) {
472 const int dst_index = output_socket->index_in_tree();
473 r_potential_data_by_socket[dst_index] |= r_potential_data_by_socket[src_index];
481 *zone, {&r_potential_data_by_socket, &r_potential_reference_by_socket});
482 for (
const int item_i :
IndexRange(storage->generation_items.items_num)) {
483 const int src_index =
484 node->input_socket(storage->main_items.items_num + item_i).index_in_tree();
485 const int dst_index =
486 node->output_socket(1 + storage->main_items.items_num + item_i).index_in_tree();
489 r_potential_data_by_socket[src_index]);
492 r_potential_reference_by_socket[src_index]);
504 *zone, {&r_potential_data_by_socket, &r_potential_reference_by_socket});
505 for (
const int i : node->output_sockets().index_range()) {
506 const int dst_index = input_node.output_socket(
i).index_in_tree();
507 r_potential_data_by_socket[dst_index] |= outside_references;
508 r_potential_reference_by_socket[dst_index] |= outside_references;
520 *zone, {&r_potential_reference_by_socket});
521 const int dst_index = output_node.output_socket(0).index_in_tree();
522 for (
const int i : node->input_sockets().index_range()) {
523 const int src_index = output_node.input_socket(
i).index_in_tree();
524 r_potential_data_by_socket[dst_index] |= r_potential_data_by_socket[src_index];
525 r_potential_reference_by_socket[dst_index] |= r_potential_reference_by_socket[src_index];
526 r_potential_reference_by_socket[dst_index] |= passed_in_references;
537 const int items_num = output_node.output_sockets().size() - 1;
541 const int src_index = input_node.input_socket(
i + 1).index_in_tree();
542 const int dst_index = output_node.output_socket(
i).index_in_tree();
543 r_potential_data_by_socket[dst_index] |= r_potential_data_by_socket[src_index];
544 r_potential_reference_by_socket[dst_index] |= r_potential_reference_by_socket[src_index];
548 *zone, {&r_potential_data_by_socket, &r_potential_reference_by_socket});
552 const int src_index = output_node.input_socket(
i).index_in_tree();
553 const int dst_index = output_node.output_socket(
i).index_in_tree();
556 r_potential_data_by_socket[src_index]);
559 r_potential_reference_by_socket[src_index]);
565 const bNodeSocket &body_input_socket = input_node.output_socket(
i + 1);
566 const bNodeSocket &body_output_socket = output_node.input_socket(
i);
567 const int in_index = body_output_socket.index_in_tree();
568 const int out_index = body_input_socket.index_in_tree();
570 r_potential_data_by_socket[out_index],
573 r_potential_reference_by_socket[out_index],
580 return needs_extra_pass;
688 bool needs_extra_pass =
false;
690 for (
const bNode *node :
tree.toposort_right_to_left()) {
691 for (
const bNodeSocket *socket : node->output_sockets()) {
692 if (!socket->is_available()) {
695 const int dst_index = socket->index_in_tree();
696 for (
const bNodeLink *link : socket->directly_linked_links()) {
697 if (!link->is_used()) {
700 const int src_index = link->tosock->index_in_tree();
701 r_required_data_by_socket[dst_index] |= r_required_data_by_socket[src_index];
704 if (node->is_muted()) {
705 for (
const bNodeLink &link : node->internal_links()) {
708 if (!input_socket.is_available() || !output_socket.is_available()) {
711 const int dst_index = input_socket.index_in_tree();
712 const int src_index = output_socket.index_in_tree();
713 r_required_data_by_socket[dst_index] |= r_required_data_by_socket[src_index];
717 if (
const aal::RelationsInNode *relations = relations_by_node[node->index()]) {
718 for (
const aal::PropagateRelation &relation : relations->propagate_relations) {
719 const bNodeSocket &output_socket = node->output_socket(relation.to_geometry_output);
720 const bNodeSocket &input_socket = node->input_socket(relation.from_geometry_input);
721 if (!input_socket.is_available() || !output_socket.is_available()) {
724 const int dst_index = input_socket.index_in_tree();
725 const int src_index = output_socket.index_in_tree();
726 r_required_data_by_socket[dst_index] |= r_required_data_by_socket[src_index];
728 for (
const aal::EvalRelation &relation : relations->eval_relations) {
729 const bNodeSocket &data_socket = node->input_socket(relation.geometry_input);
730 const bNodeSocket &reference_socket = node->input_socket(relation.field_input);
731 if (!data_socket.is_available() || !reference_socket.is_available()) {
734 r_required_data_by_socket[data_socket.index_in_tree()] |=
735 potential_reference_by_socket[reference_socket.index_in_tree()];
739 switch (node->type_legacy) {
746 const bNode *input_node = node;
748 const int dst_index = input_node->input_socket(0).index_in_tree();
749 for (
const bNodeSocket *output_socket : output_node->output_sockets()) {
751 const int src_index = output_socket->index_in_tree();
752 r_required_data_by_socket[dst_index] |= r_required_data_by_socket[src_index];
758 const bNode *output_node = node;
762 for (
const int item_i :
IndexRange(storage->generation_items.items_num)) {
763 const int src_index =
764 node->output_socket(1 + storage->main_items.items_num + item_i).index_in_tree();
765 const int dst_index =
766 node->input_socket(storage->main_items.items_num + item_i).index_in_tree();
767 r_required_data_by_socket[dst_index] |= r_required_data_by_socket[src_index];
777 const int items_num = node->output_sockets().size() - 1;
779 const int src_index = node->output_socket(
i).index_in_tree();
780 const int dst_index = node->input_socket(
i).index_in_tree();
781 r_required_data_by_socket[dst_index] |= r_required_data_by_socket[src_index];
790 const bNode *input_node = node;
792 const int items_num = output_node->output_sockets().size() - 1;
794 const bNodeSocket &body_input_socket = input_node->output_socket(
i + 1);
795 const bNodeSocket &body_output_socket = output_node->input_socket(
i);
796 const int in_index = body_input_socket.index_in_tree();
797 const int out_index = body_output_socket.index_in_tree();
799 r_required_data_by_socket[out_index]);
805 const bNodeSocket &closure_socket = node->input_socket(0);
807 potential_reference_by_socket[closure_socket.index_in_tree()];
808 for (
const bNodeSocket *input_socket : node->input_sockets().drop_front(1)) {
809 const int dst_index = input_socket->index_in_tree();
810 r_required_data_by_socket[dst_index] |= required_references;
820 const bNodeSocket &output_socket = node->output_socket(0);
822 r_required_data_by_socket[output_socket.index_in_tree()];
823 for (
const bNodeSocket *input_socket : node->input_sockets()) {
824 r_required_data_by_socket[input_socket->index_in_tree()] |= required_data;
830 return needs_extra_pass;
863 aal::RelationsInNode tree_relations;
864 const bNode *group_output_node =
tree.group_output_node();
866 for (
const int input_i :
tree.interface_inputs().index_range()) {
871 for (
const bNode *input_node :
tree.group_input_nodes()) {
873 required_data_by_socket[input_node->output_socket(input_i).index_in_tree()];
877 switch (reference_set.
type) {
879 tree_relations.propagate_relations.append_non_duplicates(
880 {input_i, reference_set.
index});
884 tree_relations.eval_relations.append_non_duplicates({reference_set.
index, input_i});
893 if (group_output_node) {
894 for (
const int output_i :
tree.interface_outputs().index_range()) {
895 const bNodeSocket &socket = group_output_node->input_socket(output_i);
899 potential_reference_by_socket[socket.index_in_tree()];
902 switch (reference_set.
type) {
904 tree_relations.reference_relations.append_non_duplicates(
905 {reference_set.
index, output_i});
915 const BoundedBitSpan potential_data = potential_data_by_socket[socket.index_in_tree()];
918 switch (reference_set.
type) {
921 group_output_node->input_sockets().drop_back(1))
927 potential_reference_by_socket[other_socket->index_in_tree()];
928 if (potential_references[reference_set_i].test()) {
929 tree_relations.available_relations.append_non_duplicates(
930 {other_socket->index(), output_i});
944 return tree_relations;
949 tree.ensure_topology_cache();
950 tree.ensure_interface_cache();
951 if (
tree.has_available_link_cycle()) {
955 if (zones ==
nullptr) {
959 std::unique_ptr<ReferenceLifetimesInfo> reference_lifetimes_info =
960 std::make_unique<ReferenceLifetimesInfo>();
968 tree, relations_by_node, group_output_set_sources, output_set_sources_by_closure_zone);
971 const int sockets_num =
tree.all_sockets().size();
972 const int reference_sets_num = reference_sets.
size();
974 BitGroupVector<> potential_data_by_socket(sockets_num, reference_sets_num,
false);
975 BitGroupVector<> potential_reference_by_socket(sockets_num, reference_sets_num,
false);
977 tree, reference_sets, potential_data_by_socket, potential_reference_by_socket);
982 tree, relations_by_node, potential_data_by_socket, potential_reference_by_socket))
986 BitGroupVector<> required_data_by_socket(sockets_num, reference_sets_num,
false);
989 group_output_set_sources,
990 output_set_sources_by_closure_zone,
991 potential_data_by_socket,
992 potential_reference_by_socket,
993 required_data_by_socket);
996 tree, relations_by_node, potential_reference_by_socket, required_data_by_socket))
1008 {potential_reference_by_socket, required_data_by_socket}))
1015 potential_data_by_socket,
1016 potential_reference_by_socket,
1017 required_data_by_socket);
1018 reference_lifetimes_info->required_data_by_socket = std::move(required_data_by_socket);
1019 return reference_lifetimes_info;