diff options
author | Jacques Lucke <jacques@blender.org> | 2021-10-18 12:40:00 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-10-18 12:46:21 +0300 |
commit | eb0d216dc1caab515eb7cf1ef6bb1632e5ca8fae (patch) | |
tree | 59e9f61142052255df5680d34d93fe8271251ec3 /source/blender/modifiers/intern/MOD_nodes_evaluator.cc | |
parent | 746ee29d3638402e2435f47787087b6458f026c7 (diff) |
Geometry Nodes: decouple multi-function lifetimes from modifier
Previously, some multi-functions were allocated in a resource scope.
This was fine as long as the multi-functions were only needed during
the current evaluation of the node tree. However, now cases arise
that require the multi-functions to be alive after the modifier is finished.
For example, we want to evaluate fields created with geometry nodes
outside of geometry nodes.
To make this work, `std::shared_ptr` has to be used in a few more places.
Realistically, this shouldn't have a noticable impact on performance.
If this does become a bottleneck in the future, we can think about ways
to make this work without using `shared_ptr` for multi-functions that
are only used once.
Diffstat (limited to 'source/blender/modifiers/intern/MOD_nodes_evaluator.cc')
-rw-r--r-- | source/blender/modifiers/intern/MOD_nodes_evaluator.cc | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc index 20ee6127504..0e7f5fe155b 100644 --- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc +++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc @@ -882,9 +882,9 @@ class GeometryNodesEvaluator { } /* Use the multi-function implementation if it exists. */ - const MultiFunction *multi_function = params_.mf_by_node->try_get(node); - if (multi_function != nullptr) { - this->execute_multi_function_node(node, *multi_function, node_state); + const nodes::NodeMultiFunctions::Item &fn_item = params_.mf_by_node->try_get(node); + if (fn_item.fn != nullptr) { + this->execute_multi_function_node(node, fn_item, node_state); return; } @@ -905,7 +905,7 @@ class GeometryNodesEvaluator { } void execute_multi_function_node(const DNode node, - const MultiFunction &fn, + const nodes::NodeMultiFunctions::Item &fn_item, NodeState &node_state) { if (node->idname().find("Legacy") != StringRef::not_found) { @@ -933,7 +933,13 @@ class GeometryNodesEvaluator { input_fields.append(std::move(*(GField *)single_value.value)); } - auto operation = std::make_shared<fn::FieldOperation>(fn, std::move(input_fields)); + std::shared_ptr<fn::FieldOperation> operation; + if (fn_item.owned_fn) { + operation = std::make_shared<fn::FieldOperation>(fn_item.owned_fn, std::move(input_fields)); + } + else { + operation = std::make_shared<fn::FieldOperation>(*fn_item.fn, std::move(input_fields)); + } /* Forward outputs. */ int output_index = 0; |