Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-08-31 12:41:53 +0300
committerJacques Lucke <jacques@blender.org>2021-08-31 12:41:53 +0300
commit149fd7b65f311bce7922cdb390710b40bdab1db8 (patch)
tree97aecfa012454b90fb59079eaf1ce1aec562b923
parenta55c230b8aeb341deb7d76619d21eb614e7d775f (diff)
initial support for function nodes in evaluator
-rw-r--r--source/blender/functions/FN_field.hh26
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.cc29
2 files changed, 29 insertions, 26 deletions
diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh
index 7889126fe76..77c1dedb721 100644
--- a/source/blender/functions/FN_field.hh
+++ b/source/blender/functions/FN_field.hh
@@ -153,6 +153,11 @@ class FieldFunction {
function_ = owned_function_.get();
}
+ FieldFunction(const MultiFunction &function, Vector<GField> inputs = {})
+ : function_(&function), inputs_(std::move(inputs))
+ {
+ }
+
Span<GField> inputs() const
{
return inputs_;
@@ -163,13 +168,20 @@ class FieldFunction {
return *function_;
}
- const CPPType &cpp_type_of_output_index(int index) const
- {
- MFParamType param_type = function_->param_type(index);
- MFDataType data_type = param_type.data_type();
- BLI_assert(param_type.interface_type() == MFParamType::Output);
- BLI_assert(data_type.is_single());
- return data_type.single_type();
+ const CPPType &cpp_type_of_output_index(int output_index) const
+ {
+ int output_counter = 0;
+ for (const int param_index : function_->param_indices()) {
+ MFParamType param_type = function_->param_type(param_index);
+ if (param_type.is_output()) {
+ if (output_counter == output_index) {
+ return param_type.data_type().single_type();
+ }
+ output_counter++;
+ }
+ }
+ BLI_assert_unreachable();
+ return CPPType::get<float>();
}
};
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 5646e37707c..6e5b5702da6 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -21,6 +21,7 @@
#include "DEG_depsgraph_query.h"
+#include "FN_field.hh"
#include "FN_generic_value_map.hh"
#include "FN_multi_function.hh"
@@ -33,6 +34,8 @@
namespace blender::modifiers::geometry_nodes {
using fn::CPPType;
+using fn::Field;
+using fn::GField;
using fn::GValueMap;
using nodes::GeoNodeExecParams;
using namespace fn::multi_function_types;
@@ -858,11 +861,10 @@ class GeometryNodesEvaluator {
const MultiFunction &fn,
NodeState &node_state)
{
- MFContextBuilder fn_context;
- MFParamsBuilder fn_params{fn, 1};
LinearAllocator<> &allocator = local_allocators_.local();
/* Prepare the inputs for the multi function. */
+ Vector<GField> input_fields;
for (const int i : node->inputs().index_range()) {
const InputSocketRef &socket_ref = node->input(i);
if (!socket_ref.is_available()) {
@@ -873,24 +875,12 @@ class GeometryNodesEvaluator {
BLI_assert(input_state.was_ready_for_execution);
SingleInputValue &single_value = *input_state.value.single;
BLI_assert(single_value.value != nullptr);
- fn_params.add_readonly_single_input(GPointer{*input_state.type, single_value.value});
- }
- /* Prepare the outputs for the multi function. */
- Vector<GMutablePointer> outputs;
- for (const int i : node->outputs().index_range()) {
- const OutputSocketRef &socket_ref = node->output(i);
- if (!socket_ref.is_available()) {
- continue;
- }
- const CPPType &type = *get_socket_cpp_type(socket_ref);
- void *buffer = allocator.allocate(type.size(), type.alignment());
- fn_params.add_uninitialized_single_output(GMutableSpan{type, buffer, 1});
- outputs.append({type, buffer});
+ input_fields.append(std::move(*(GField *)single_value.value));
}
- fn.call(IndexRange(1), fn_params, fn_context);
+ auto field_fn = std::make_shared<fn::FieldFunction>(fn, std::move(input_fields));
- /* Forward the computed outputs. */
+ /* Forward outputs. */
int output_index = 0;
for (const int i : node->outputs().index_range()) {
const OutputSocketRef &socket_ref = node->output(i);
@@ -899,8 +889,9 @@ class GeometryNodesEvaluator {
}
OutputState &output_state = node_state.outputs[i];
const DOutputSocket socket{node.context(), &socket_ref};
- GMutablePointer value = outputs[output_index];
- this->forward_output(socket, value);
+ const CPPType *cpp_type = get_socket_cpp_type(socket_ref);
+ GField &field = *allocator.construct<GField>(field_fn, output_index).release();
+ this->forward_output(socket, {cpp_type, &field});
output_state.has_been_computed = true;
output_index++;
}