Differential D11003 Diff 36252 source/blender/functions/intern/multi_function_network_optimization.cc
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/functions/intern/multi_function_network_optimization.cc
| Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | static Array<bool> mask_nodes_to_the_right(MFNetwork &network, Span<MFNode *> nodes) | ||||
| return is_to_the_right; | return is_to_the_right; | ||||
| } | } | ||||
| static Vector<MFNode *> find_nodes_based_on_mask(MFNetwork &network, | static Vector<MFNode *> find_nodes_based_on_mask(MFNetwork &network, | ||||
| Span<bool> id_mask, | Span<bool> id_mask, | ||||
| bool mask_value) | bool mask_value) | ||||
| { | { | ||||
| Vector<MFNode *> nodes; | Vector<MFNode *> nodes; | ||||
| for (int id : id_mask.index_range()) { | for (int id : iter_indices(id_mask)) { | ||||
| if (id_mask[id] == mask_value) { | if (id_mask[id] == mask_value) { | ||||
| MFNode *node = network.node_or_null_by_id(id); | MFNode *node = network.node_or_null_by_id(id); | ||||
| if (node != nullptr) { | if (node != nullptr) { | ||||
| nodes.append(node); | nodes.append(node); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return nodes; | return nodes; | ||||
| ▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | void constant_folding(MFNetwork &network, ResourceScope &scope) | ||||
| Vector<MFInputSocket *> inputs_to_fold = find_constant_inputs_to_fold(network, temporary_nodes); | Vector<MFInputSocket *> inputs_to_fold = find_constant_inputs_to_fold(network, temporary_nodes); | ||||
| if (inputs_to_fold.size() == 0) { | if (inputs_to_fold.size() == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| Array<MFOutputSocket *> folded_sockets = compute_constant_sockets_and_add_folded_nodes( | Array<MFOutputSocket *> folded_sockets = compute_constant_sockets_and_add_folded_nodes( | ||||
| network, inputs_to_fold, scope); | network, inputs_to_fold, scope); | ||||
| for (int i : inputs_to_fold.index_range()) { | for (int i : iter_indices(inputs_to_fold)) { | ||||
| MFOutputSocket &original_socket = *inputs_to_fold[i]->origin(); | MFOutputSocket &original_socket = *inputs_to_fold[i]->origin(); | ||||
| network.relink(original_socket, *folded_sockets[i]); | network.relink(original_socket, *folded_sockets[i]); | ||||
| } | } | ||||
| network.remove(temporary_nodes.as_span().cast<MFNode *>()); | network.remove(temporary_nodes.as_span().cast<MFNode *>()); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | static bool nodes_output_same_values(DisjointSet &cache, const MFNode &a, const MFNode &b) | ||||
| } | } | ||||
| if (a.is_dummy() || b.is_dummy()) { | if (a.is_dummy() || b.is_dummy()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!functions_are_equal(a.as_function().function(), b.as_function().function())) { | if (!functions_are_equal(a.as_function().function(), b.as_function().function())) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| for (int i : a.inputs().index_range()) { | for (int i : iter_indices(a.inputs())) { | ||||
| const MFOutputSocket *origin_a = a.input(i).origin(); | const MFOutputSocket *origin_a = a.input(i).origin(); | ||||
| const MFOutputSocket *origin_b = b.input(i).origin(); | const MFOutputSocket *origin_b = b.input(i).origin(); | ||||
| if (origin_a == nullptr || origin_b == nullptr) { | if (origin_a == nullptr || origin_b == nullptr) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!nodes_output_same_values(cache, origin_a->node(), origin_b->node())) { | if (!nodes_output_same_values(cache, origin_a->node(), origin_b->node())) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 17 Lines | for (Span<MFNode *> nodes_with_same_hash : nodes_by_hash.values()) { | ||||
| while (nodes_to_check.size() >= 2) { | while (nodes_to_check.size() >= 2) { | ||||
| Vector<MFNode *, 16> remaining_nodes; | Vector<MFNode *, 16> remaining_nodes; | ||||
| MFNode &deduplicated_node = *nodes_to_check[0]; | MFNode &deduplicated_node = *nodes_to_check[0]; | ||||
| for (MFNode *node : nodes_to_check.as_span().drop_front(1)) { | for (MFNode *node : nodes_to_check.as_span().drop_front(1)) { | ||||
| /* This is true with fairly high probability, but hash collisions can happen. So we have to | /* This is true with fairly high probability, but hash collisions can happen. So we have to | ||||
| * check if the node actually output the same values. */ | * check if the node actually output the same values. */ | ||||
| if (nodes_output_same_values(same_node_cache, deduplicated_node, *node)) { | if (nodes_output_same_values(same_node_cache, deduplicated_node, *node)) { | ||||
| for (int i : deduplicated_node.outputs().index_range()) { | for (int i : iter_indices(deduplicated_node.outputs())) { | ||||
| network.relink(node->output(i), deduplicated_node.output(i)); | network.relink(node->output(i), deduplicated_node.output(i)); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| remaining_nodes.append(node); | remaining_nodes.append(node); | ||||
| } | } | ||||
| } | } | ||||
| nodes_to_check = std::move(remaining_nodes); | nodes_to_check = std::move(remaining_nodes); | ||||
| Show All 18 Lines | |||||