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 <mail@jlucke.com>2019-09-27 16:15:10 +0300
committerJacques Lucke <mail@jlucke.com>2019-09-27 16:15:10 +0300
commit254b69417b7fa226f38c4f1b282b1d206b11de88 (patch)
treed57d09b744d3ed9f23c5411561897993912c23fc
parent0102c06cb2b1ddb795c553252e869ca3a13788db (diff)
remove refcounter from Function class
-rw-r--r--source/blender/functions/backends/dependencies/fgraph_dependencies.cpp12
-rw-r--r--source/blender/functions/backends/dependencies/fgraph_dependencies.hpp2
-rw-r--r--source/blender/functions/backends/llvm/build_ir_body.cpp12
-rw-r--r--source/blender/functions/backends/llvm/fgraph_ir_generation.cpp16
-rw-r--r--source/blender/functions/backends/llvm/fgraph_ir_generation.hpp2
-rw-r--r--source/blender/functions/backends/llvm/ir_for_tuple_call.cpp18
-rw-r--r--source/blender/functions/backends/llvm/ir_for_tuple_call.hpp2
-rw-r--r--source/blender/functions/backends/llvm/ir_to_tuple_call.cpp26
-rw-r--r--source/blender/functions/backends/llvm/ir_to_tuple_call.hpp2
-rw-r--r--source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp38
-rw-r--r--source/blender/functions/backends/tuple_call/fgraph_tuple_call.hpp2
-rw-r--r--source/blender/functions/backends/tuple_call/lazy_to_normal.cpp8
-rw-r--r--source/blender/functions/backends/tuple_call/lazy_to_normal.hpp2
-rw-r--r--source/blender/functions/backends/tuple_call/tuple_call.cpp4
-rw-r--r--source/blender/functions/backends/tuple_call/tuple_call.hpp16
-rw-r--r--source/blender/functions/core/core-c.cpp2
-rw-r--r--source/blender/functions/core/data_graph.cpp2
-rw-r--r--source/blender/functions/core/data_graph.hpp30
-rw-r--r--source/blender/functions/core/data_graph_builder.cpp18
-rw-r--r--source/blender/functions/core/data_graph_builder.hpp16
-rw-r--r--source/blender/functions/core/dot_export.cpp2
-rw-r--r--source/blender/functions/core/function.hpp10
-rw-r--r--source/blender/functions/core/function_builder.cpp14
-rw-r--r--source/blender/functions/core/function_builder.hpp2
-rw-r--r--source/blender/functions/core/function_graph.cpp2
-rw-r--r--source/blender/functions/core/function_graph.hpp2
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp8
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/function_generation.cpp10
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/function_generation.hpp2
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/mappings.cpp4
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/mappings.hpp2
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/mappings/conversion_inserters.cpp2
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp123
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/unlinked_input_groupers.cpp4
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/unlinked_input_inserters.cpp11
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp6
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp13
-rw-r--r--source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.hpp6
-rw-r--r--source/blender/functions/functions/array_execution.cpp52
-rw-r--r--source/blender/functions/functions/array_execution.hpp8
-rw-r--r--source/blender/functions/functions/auto_vectorization.cpp115
-rw-r--r--source/blender/functions/functions/auto_vectorization.hpp12
-rw-r--r--source/blender/functions/functions/boolean.cpp10
-rw-r--r--source/blender/functions/functions/boolean.hpp6
-rw-r--r--source/blender/functions/functions/color.cpp4
-rw-r--r--source/blender/functions/functions/color.hpp4
-rw-r--r--source/blender/functions/functions/comparisons.cpp4
-rw-r--r--source/blender/functions/functions/comparisons.hpp4
-rw-r--r--source/blender/functions/functions/constants.cpp30
-rw-r--r--source/blender/functions/functions/constants.hpp20
-rw-r--r--source/blender/functions/functions/lists.cpp43
-rw-r--r--source/blender/functions/functions/lists.hpp12
-rw-r--r--source/blender/functions/functions/object_input.cpp4
-rw-r--r--source/blender/functions/functions/object_input.hpp4
-rw-r--r--source/blender/functions/functions/random.cpp2
-rw-r--r--source/blender/functions/functions/random.hpp2
-rw-r--r--source/blender/functions/functions/ranges.cpp2
-rw-r--r--source/blender/functions/functions/ranges.hpp2
-rw-r--r--source/blender/functions/functions/scalar_math.cpp52
-rw-r--r--source/blender/functions/functions/scalar_math.hpp58
-rw-r--r--source/blender/functions/functions/simple_conversions.cpp46
-rw-r--r--source/blender/functions/functions/simple_conversions.hpp24
-rw-r--r--source/blender/functions/functions/string.cpp2
-rw-r--r--source/blender/functions/functions/string.hpp2
-rw-r--r--source/blender/functions/functions/switch.cpp12
-rw-r--r--source/blender/functions/functions/switch.hpp2
-rw-r--r--source/blender/functions/functions/vectors.cpp24
-rw-r--r--source/blender/functions/functions/vectors.hpp22
-rw-r--r--source/blender/simulations/bparticles/action_interface.hpp2
-rw-r--r--source/blender/simulations/bparticles/emitters.hpp2
-rw-r--r--source/blender/simulations/bparticles/forces.cpp2
-rw-r--r--source/blender/simulations/bparticles/node_frontend.cpp8
-rw-r--r--source/blender/simulations/bparticles/particle_function.cpp10
-rw-r--r--source/blender/simulations/bparticles/particle_function.hpp10
-rw-r--r--source/blender/simulations/bparticles/particle_function_builder.cpp37
75 files changed, 550 insertions, 558 deletions
diff --git a/source/blender/functions/backends/dependencies/fgraph_dependencies.cpp b/source/blender/functions/backends/dependencies/fgraph_dependencies.cpp
index 55bcae3f0d4..dbc98521c75 100644
--- a/source/blender/functions/backends/dependencies/fgraph_dependencies.cpp
+++ b/source/blender/functions/backends/dependencies/fgraph_dependencies.cpp
@@ -32,11 +32,11 @@ class FGraphDependencies : public DepsBody {
}
else {
uint node_id = m_graph.node_id_of_output(socket);
- SharedFunction &fn = m_graph.function_of_node(node_id);
- if (fn->has_body<DepsBody>()) {
+ Function &fn = m_graph.function_of_node(node_id);
+ if (fn.has_body<DepsBody>()) {
MultiMap<uint, ID *> input_ids;
- for (uint i = 0; i < fn->input_amount(); i++) {
+ for (uint i = 0; i < fn.input_amount(); i++) {
input_ids.add_multiple_new(
i,
this->find_deps_and_outputs(m_graph.socket_of_node_input(node_id, i),
@@ -45,7 +45,7 @@ class FGraphDependencies : public DepsBody {
MultiMap<uint, ID *> output_ids;
FunctionDepsBuilder builder(input_ids, output_ids, parent_builder.dependency_components());
- DepsBody &body = fn->body<DepsBody>();
+ DepsBody &body = fn.body<DepsBody>();
body.build_deps(builder);
return output_ids.lookup_default(m_graph.index_of_output(socket));
}
@@ -59,9 +59,9 @@ class FGraphDependencies : public DepsBody {
}
};
-void fgraph_add_DependenciesBody(SharedFunction &fn, FunctionGraph &fgraph)
+void fgraph_add_DependenciesBody(Function &fn, FunctionGraph &fgraph)
{
- fn->add_body<FGraphDependencies>(fgraph);
+ fn.add_body<FGraphDependencies>(fgraph);
}
} // namespace FN
diff --git a/source/blender/functions/backends/dependencies/fgraph_dependencies.hpp b/source/blender/functions/backends/dependencies/fgraph_dependencies.hpp
index 50f2dfb373f..f2d373c4c7c 100644
--- a/source/blender/functions/backends/dependencies/fgraph_dependencies.hpp
+++ b/source/blender/functions/backends/dependencies/fgraph_dependencies.hpp
@@ -5,6 +5,6 @@
namespace FN {
-void fgraph_add_DependenciesBody(SharedFunction &fn, FunctionGraph &fgraph);
+void fgraph_add_DependenciesBody(Function &fn, FunctionGraph &fgraph);
} /* namespace FN */
diff --git a/source/blender/functions/backends/llvm/build_ir_body.cpp b/source/blender/functions/backends/llvm/build_ir_body.cpp
index 64a40c30962..5a30ac82944 100644
--- a/source/blender/functions/backends/llvm/build_ir_body.cpp
+++ b/source/blender/functions/backends/llvm/build_ir_body.cpp
@@ -7,11 +7,11 @@ llvm::Function *LLVMBuildIRBody::build_function(llvm::Module *module,
BuildIRSettings &settings,
FunctionIRCache &function_cache)
{
- Function *owner_fn = this->owner();
+ Function &owner_fn = this->owner();
llvm::LLVMContext &context = module->getContext();
- uint input_amount = owner_fn->input_amount();
- uint output_amount = owner_fn->output_amount();
+ uint input_amount = owner_fn.input_amount();
+ uint output_amount = owner_fn.output_amount();
Vector<LLVMTypeInfo *> input_type_infos(input_amount);
Vector<LLVMTypeInfo *> output_type_infos(output_amount);
@@ -19,13 +19,13 @@ llvm::Function *LLVMBuildIRBody::build_function(llvm::Module *module,
Vector<llvm::Type *> output_types(output_amount);
for (uint i = 0; i < input_amount; i++) {
- LLVMTypeInfo &type_info = owner_fn->input_type(i)->extension<LLVMTypeInfo>();
+ LLVMTypeInfo &type_info = owner_fn.input_type(i)->extension<LLVMTypeInfo>();
input_type_infos[i] = &type_info;
input_types[i] = type_info.get_type(context);
}
for (uint i = 0; i < output_amount; i++) {
- LLVMTypeInfo &type_info = owner_fn->output_type(i)->extension<LLVMTypeInfo>();
+ LLVMTypeInfo &type_info = owner_fn.output_type(i)->extension<LLVMTypeInfo>();
output_type_infos[i] = &type_info;
output_types[i] = type_info.get_type(context);
}
@@ -42,7 +42,7 @@ llvm::Function *LLVMBuildIRBody::build_function(llvm::Module *module,
Vector<llvm::Value *> input_values(input_amount);
for (uint i = 0; i < input_amount; i++) {
- input_values[i] = builder.take_function_input(i, owner_fn->input_name(i));
+ input_values[i] = builder.take_function_input(i, owner_fn.input_name(i));
}
llvm::Value *context_ptr = builder.take_function_input(input_amount, "context_ptr");
Vector<llvm::Value *> output_values(output_amount);
diff --git a/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp b/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
index 03958aa00e6..cd51310574b 100644
--- a/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
+++ b/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
@@ -14,15 +14,15 @@ class BuildGraphIR : public LLVMBuildIRBody {
BuildGraphIR(FunctionGraph &fgraph) : m_fgraph(fgraph), m_graph(fgraph.graph())
{
for (uint node_id : m_graph.node_ids()) {
- SharedFunction &fn = m_graph.function_of_node(node_id);
- if (fn->has_body<LLVMBuildIRBody>()) {
+ Function &fn = m_graph.function_of_node(node_id);
+ if (fn.has_body<LLVMBuildIRBody>()) {
continue;
}
- if (fn->has_body<TupleCallBody>()) {
+ if (fn.has_body<TupleCallBody>()) {
derive_LLVMBuildIRBody_from_TupleCallBody(fn);
continue;
}
- if (fn->has_body<LazyInTupleCallBody>()) {
+ if (fn.has_body<LazyInTupleCallBody>()) {
derive_TupleCallBody_from_LazyInTupleCallBody(fn);
derive_LLVMBuildIRBody_from_TupleCallBody(fn);
continue;
@@ -139,8 +139,8 @@ class BuildGraphIR : public LLVMBuildIRBody {
uint node_id,
Vector<llvm::Value *> &input_values) const
{
- SharedFunction &fn = m_graph.function_of_node(node_id);
- auto &body = fn->body<LLVMBuildIRBody>();
+ Function &fn = m_graph.function_of_node(node_id);
+ auto &body = fn.body<LLVMBuildIRBody>();
bool setup_stack = settings.maintain_stack() && body.prepare_execution_context();
if (setup_stack) {
@@ -210,9 +210,9 @@ class BuildGraphIR : public LLVMBuildIRBody {
}
};
-void fgraph_add_LLVMBuildIRBody(SharedFunction &fn, FunctionGraph &fgraph)
+void fgraph_add_LLVMBuildIRBody(Function &fn, FunctionGraph &fgraph)
{
- fn->add_body<BuildGraphIR>(fgraph);
+ fn.add_body<BuildGraphIR>(fgraph);
}
} /* namespace FN */
diff --git a/source/blender/functions/backends/llvm/fgraph_ir_generation.hpp b/source/blender/functions/backends/llvm/fgraph_ir_generation.hpp
index 7ddb7232fd7..a00dd62a397 100644
--- a/source/blender/functions/backends/llvm/fgraph_ir_generation.hpp
+++ b/source/blender/functions/backends/llvm/fgraph_ir_generation.hpp
@@ -4,6 +4,6 @@
namespace FN {
-void fgraph_add_LLVMBuildIRBody(SharedFunction &fn, FunctionGraph &fgraph);
+void fgraph_add_LLVMBuildIRBody(Function &fn, FunctionGraph &fgraph);
} /* namespace FN */
diff --git a/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp b/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
index b6cb2fcac31..b783077de93 100644
--- a/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
@@ -60,11 +60,11 @@ class TupleCallLLVM : public LLVMBuildIRBody {
CodeInterface &interface,
const BuildIRSettings &settings) const override
{
- Function *fn = m_tuple_call.owner();
+ Function &fn = m_tuple_call.owner();
/* Find relevant type information. */
- auto input_type_infos = fn->input_extensions<LLVMTypeInfo>();
- auto output_type_infos = fn->output_extensions<LLVMTypeInfo>();
+ auto input_type_infos = fn.input_extensions<LLVMTypeInfo>();
+ auto output_type_infos = fn.output_extensions<LLVMTypeInfo>();
/* Build wrapper function. */
llvm::Function *wrapper_function = this->get_wrapper_function(
@@ -91,7 +91,7 @@ class TupleCallLLVM : public LLVMBuildIRBody {
ArrayRef<LLVMTypeInfo *> input_type_infos,
ArrayRef<LLVMTypeInfo *> output_type_infos) const
{
- Function *fn = m_tuple_call.owner();
+ Function &fn = m_tuple_call.owner();
Vector<llvm::Type *> input_types = builder.types_of_values(interface.inputs());
if (settings.maintain_stack()) {
@@ -116,7 +116,7 @@ class TupleCallLLVM : public LLVMBuildIRBody {
wrapper_function = llvm::Function::Create(wrapper_function_type,
llvm::GlobalValue::LinkageTypes::InternalLinkage,
- fn->name() + " Wrapper",
+ fn.name() + " Wrapper",
builder.getModule());
this->build_wrapper_function(
@@ -182,12 +182,12 @@ class TupleCallLLVM : public LLVMBuildIRBody {
}
};
-void derive_LLVMBuildIRBody_from_TupleCallBody(SharedFunction &fn)
+void derive_LLVMBuildIRBody_from_TupleCallBody(Function &fn)
{
- BLI_assert(fn->has_body<TupleCallBody>());
- BLI_assert(!fn->has_body<LLVMBuildIRBody>());
+ BLI_assert(fn.has_body<TupleCallBody>());
+ BLI_assert(!fn.has_body<LLVMBuildIRBody>());
- fn->add_body<TupleCallLLVM>(fn->body<TupleCallBody>());
+ fn.add_body<TupleCallLLVM>(fn.body<TupleCallBody>());
}
} /* namespace FN */
diff --git a/source/blender/functions/backends/llvm/ir_for_tuple_call.hpp b/source/blender/functions/backends/llvm/ir_for_tuple_call.hpp
index ad72ffc94e4..dd0f8985532 100644
--- a/source/blender/functions/backends/llvm/ir_for_tuple_call.hpp
+++ b/source/blender/functions/backends/llvm/ir_for_tuple_call.hpp
@@ -8,6 +8,6 @@ class LLVMContext;
namespace FN {
-void derive_LLVMBuildIRBody_from_TupleCallBody(SharedFunction &fn);
+void derive_LLVMBuildIRBody_from_TupleCallBody(Function &fn);
} /* namespace FN */
diff --git a/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp b/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
index 34fa65457e1..021bab7e6d5 100644
--- a/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
@@ -25,14 +25,14 @@ typedef void(TupleCallFunction)(uint8_t *data_in,
uint32_t *offsets_out,
uint8_t *execution_context);
-static llvm::Function *insert_tuple_call_function(SharedFunction &fn, llvm::Module *module)
+static llvm::Function *insert_tuple_call_function(Function &fn, llvm::Module *module)
{
llvm::LLVMContext &context = module->getContext();
- LLVMBuildIRBody &body = fn->body<LLVMBuildIRBody>();
+ LLVMBuildIRBody &body = fn.body<LLVMBuildIRBody>();
llvm::FunctionType *function_type = llvm::TypeBuilder<TupleCallFunction, false>::get(context);
llvm::Function *function = llvm::Function::Create(
- function_type, llvm::GlobalValue::LinkageTypes::ExternalLinkage, fn->name().data(), module);
+ function_type, llvm::GlobalValue::LinkageTypes::ExternalLinkage, fn.name().data(), module);
llvm::BasicBlock *bb = llvm::BasicBlock::Create(context, "entry", function);
CodeBuilder builder(bb);
@@ -49,16 +49,16 @@ static llvm::Function *insert_tuple_call_function(SharedFunction &fn, llvm::Modu
context_ptr->setName("context");
Vector<llvm::Value *> input_values;
- for (uint i = 0; i < fn->input_amount(); i++) {
+ for (uint i = 0; i < fn.input_amount(); i++) {
llvm::Value *value_byte_addr = lookup_tuple_address(builder, fn_in_data, fn_in_offsets, i);
- LLVMTypeInfo &type_info = fn->input_type(i)->extension<LLVMTypeInfo>();
+ LLVMTypeInfo &type_info = fn.input_type(i)->extension<LLVMTypeInfo>();
llvm::Value *value = type_info.build_load_ir__relocate(builder, value_byte_addr);
input_values.append(value);
}
- Vector<llvm::Value *> output_values(fn->output_amount());
+ Vector<llvm::Value *> output_values(fn.output_amount());
BuildIRSettings settings;
FunctionIRCache function_cache;
CodeInterface interface(input_values, output_values, context_ptr, function_cache);
@@ -67,7 +67,7 @@ static llvm::Function *insert_tuple_call_function(SharedFunction &fn, llvm::Modu
for (uint i = 0; i < output_values.size(); i++) {
llvm::Value *value_byte_addr = lookup_tuple_address(builder, fn_out_data, fn_out_offsets, i);
- LLVMTypeInfo &type_info = fn->output_type(i)->extension<LLVMTypeInfo>();
+ LLVMTypeInfo &type_info = fn.output_type(i)->extension<LLVMTypeInfo>();
type_info.build_store_ir__relocate(builder, output_values[i], value_byte_addr);
}
@@ -106,23 +106,23 @@ class LLVMTupleCall : public TupleCallBody {
}
};
-static std::unique_ptr<CompiledLLVM> compile_ir_to_tuple_call(SharedFunction &fn,
+static std::unique_ptr<CompiledLLVM> compile_ir_to_tuple_call(Function &fn,
llvm::LLVMContext &context)
{
- llvm::Module *module = new llvm::Module(fn->name().data(), context);
+ llvm::Module *module = new llvm::Module(fn.name().data(), context);
llvm::Function *function = insert_tuple_call_function(fn, module);
auto compiled = CompiledLLVM::FromIR(module, function);
return compiled;
}
-void derive_TupleCallBody_from_LLVMBuildIRBody(SharedFunction &fn)
+void derive_TupleCallBody_from_LLVMBuildIRBody(Function &fn)
{
- BLI_assert(fn->has_body<LLVMBuildIRBody>());
- BLI_assert(!fn->has_body<TupleCallBody>());
+ BLI_assert(fn.has_body<LLVMBuildIRBody>());
+ BLI_assert(!fn.has_body<TupleCallBody>());
auto *context = aquire_llvm_context();
- fn->add_body<LLVMTupleCall>(compile_ir_to_tuple_call(fn, *context));
+ fn.add_body<LLVMTupleCall>(compile_ir_to_tuple_call(fn, *context));
release_llvm_context(context);
}
diff --git a/source/blender/functions/backends/llvm/ir_to_tuple_call.hpp b/source/blender/functions/backends/llvm/ir_to_tuple_call.hpp
index 0a8924d7949..b03b316c9a7 100644
--- a/source/blender/functions/backends/llvm/ir_to_tuple_call.hpp
+++ b/source/blender/functions/backends/llvm/ir_to_tuple_call.hpp
@@ -4,6 +4,6 @@
namespace FN {
-void derive_TupleCallBody_from_LLVMBuildIRBody(SharedFunction &fn);
+void derive_TupleCallBody_from_LLVMBuildIRBody(Function &fn);
} /* namespace FN */
diff --git a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
index 2f0e71bdbe8..46315f20487 100644
--- a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
+++ b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
@@ -10,16 +10,16 @@ using BLI::VectorAdaptor;
static void try_ensure_tuple_call_bodies(DataGraph &graph)
{
for (uint node_id : graph.node_ids()) {
- SharedFunction &fn = graph.function_of_node(node_id);
- if (fn->has_body<TupleCallBody>()) {
+ Function &fn = graph.function_of_node(node_id);
+ if (fn.has_body<TupleCallBody>()) {
continue;
}
- if (fn->has_body<LazyInTupleCallBody>()) {
+ if (fn.has_body<LazyInTupleCallBody>()) {
derive_TupleCallBody_from_LazyInTupleCallBody(fn);
}
- if (fn->has_body<LLVMBuildIRBody>()) {
+ if (fn.has_body<LLVMBuildIRBody>()) {
derive_TupleCallBody_from_LLVMBuildIRBody(fn);
}
}
@@ -67,34 +67,34 @@ class ExecuteFGraph : public TupleCallBody {
ExecuteFGraph(FunctionGraph &fgraph) : m_fgraph(fgraph), m_graph(fgraph.graph())
{
for (uint node_id : m_graph.node_ids()) {
- SharedFunction &fn = m_graph.function_of_node(node_id);
+ Function &fn = m_graph.function_of_node(node_id);
TupleCallBodyBase *body = nullptr;
bool is_lazy_body = false;
- if (fn->has_body<LazyInTupleCallBody>()) {
- body = &fn->body<LazyInTupleCallBody>();
+ if (fn.has_body<LazyInTupleCallBody>()) {
+ body = &fn.body<LazyInTupleCallBody>();
is_lazy_body = true;
}
- else if (fn->has_body<TupleCallBody>()) {
- body = &fn->body<TupleCallBody>();
+ else if (fn.has_body<TupleCallBody>()) {
+ body = &fn.body<TupleCallBody>();
is_lazy_body = false;
}
m_node_info.append(
NodeInfo(body, is_lazy_body, m_inputs_buffer_size, m_outputs_buffer_size));
- m_inputs_init_buffer_size += fn->input_amount();
- m_outputs_init_buffer_size += fn->output_amount();
+ m_inputs_init_buffer_size += fn.input_amount();
+ m_outputs_init_buffer_size += fn.output_amount();
if (body == nullptr) {
- for (auto type : fn->input_types()) {
+ for (auto type : fn.input_types()) {
CPPTypeInfo &type_info = type->extension<CPPTypeInfo>();
uint type_size = type_info.size();
m_input_info.append(SocketInfo(type_info, m_inputs_buffer_size, false));
m_inputs_buffer_size += type_size;
}
- for (auto type : fn->output_types()) {
+ for (auto type : fn.output_types()) {
CPPTypeInfo &type_info = type->extension<CPPTypeInfo>();
uint type_size = type_info.size();
m_output_info.append(SocketInfo(type_info, m_outputs_buffer_size, false));
@@ -103,14 +103,14 @@ class ExecuteFGraph : public TupleCallBody {
}
else {
TupleMeta &meta_in = body->meta_in();
- for (uint i = 0; i < fn->input_amount(); i++) {
+ for (uint i = 0; i < fn.input_amount(); i++) {
m_input_info.append(SocketInfo(
*meta_in.type_infos()[i], m_inputs_buffer_size + meta_in.offsets()[i], false));
}
m_inputs_buffer_size += meta_in.size_of_data();
TupleMeta &meta_out = body->meta_out();
- for (uint i = 0; i < fn->output_amount(); i++) {
+ for (uint i = 0; i < fn.output_amount(); i++) {
m_output_info.append(SocketInfo(
*meta_out.type_infos()[i], m_outputs_buffer_size + meta_out.offsets()[i], false));
}
@@ -584,8 +584,8 @@ class ExecuteFGraph_Simple : public TupleCallBody {
}
else {
uint node_id = m_graph.node_id_of_output(socket);
- SharedFunction &fn = m_graph.function_of_node(node_id);
- TupleCallBody &body = fn->body<TupleCallBody>();
+ Function &fn = m_graph.function_of_node(node_id);
+ TupleCallBody &body = fn.body<TupleCallBody>();
FN_TUPLE_CALL_ALLOC_TUPLES(body, tmp_in, tmp_out);
@@ -603,10 +603,10 @@ class ExecuteFGraph_Simple : public TupleCallBody {
}
};
-void fgraph_add_TupleCallBody(SharedFunction &fn, FunctionGraph &fgraph)
+void fgraph_add_TupleCallBody(Function &fn, FunctionGraph &fgraph)
{
try_ensure_tuple_call_bodies(fgraph.graph());
- fn->add_body<ExecuteFGraph>(fgraph);
+ fn.add_body<ExecuteFGraph>(fgraph);
}
} /* namespace FN */
diff --git a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.hpp b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.hpp
index 701d0b51462..4e7b7690373 100644
--- a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.hpp
+++ b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.hpp
@@ -4,6 +4,6 @@
namespace FN {
-void fgraph_add_TupleCallBody(SharedFunction &fn, FunctionGraph &fgraph);
+void fgraph_add_TupleCallBody(Function &fn, FunctionGraph &fgraph);
} /* namespace FN */
diff --git a/source/blender/functions/backends/tuple_call/lazy_to_normal.cpp b/source/blender/functions/backends/tuple_call/lazy_to_normal.cpp
index 6ad05d7b1c0..83929fca80a 100644
--- a/source/blender/functions/backends/tuple_call/lazy_to_normal.cpp
+++ b/source/blender/functions/backends/tuple_call/lazy_to_normal.cpp
@@ -29,12 +29,12 @@ class MakeEagerBody : public TupleCallBody {
}
};
-void derive_TupleCallBody_from_LazyInTupleCallBody(SharedFunction &fn)
+void derive_TupleCallBody_from_LazyInTupleCallBody(Function &fn)
{
- BLI_assert(fn->has_body<LazyInTupleCallBody>());
- BLI_assert(!fn->has_body<TupleCallBody>());
+ BLI_assert(fn.has_body<LazyInTupleCallBody>());
+ BLI_assert(!fn.has_body<TupleCallBody>());
- fn->add_body<MakeEagerBody>(fn->body<LazyInTupleCallBody>());
+ fn.add_body<MakeEagerBody>(fn.body<LazyInTupleCallBody>());
}
} /* namespace FN */
diff --git a/source/blender/functions/backends/tuple_call/lazy_to_normal.hpp b/source/blender/functions/backends/tuple_call/lazy_to_normal.hpp
index 813d199b20a..503d59fc674 100644
--- a/source/blender/functions/backends/tuple_call/lazy_to_normal.hpp
+++ b/source/blender/functions/backends/tuple_call/lazy_to_normal.hpp
@@ -4,6 +4,6 @@
namespace FN {
-void derive_TupleCallBody_from_LazyInTupleCallBody(SharedFunction &fn);
+void derive_TupleCallBody_from_LazyInTupleCallBody(Function &fn);
} /* namespace FN */
diff --git a/source/blender/functions/backends/tuple_call/tuple_call.cpp b/source/blender/functions/backends/tuple_call/tuple_call.cpp
index 82013ccc7d4..68bfa86c7f1 100644
--- a/source/blender/functions/backends/tuple_call/tuple_call.cpp
+++ b/source/blender/functions/backends/tuple_call/tuple_call.cpp
@@ -9,8 +9,8 @@ void TupleCallBodyBase::init_defaults(Tuple &fn_in) const
void TupleCallBodyBase::owner_init_post()
{
- m_meta_in = TupleMeta(this->owner()->input_types());
- m_meta_out = TupleMeta(this->owner()->output_types());
+ m_meta_in = TupleMeta(this->owner().input_types());
+ m_meta_out = TupleMeta(this->owner().output_types());
}
uint LazyInTupleCallBody::user_data_size() const
diff --git a/source/blender/functions/backends/tuple_call/tuple_call.hpp b/source/blender/functions/backends/tuple_call/tuple_call.hpp
index 196626e0ef2..1517ae2810b 100644
--- a/source/blender/functions/backends/tuple_call/tuple_call.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple_call.hpp
@@ -51,7 +51,7 @@ class TupleCallBody : public TupleCallBodyBase {
*/
inline void call__setup_stack(Tuple &fn_in, Tuple &fn_out, ExecutionContext &ctx) const
{
- TextStackFrame frame(this->owner()->name().data());
+ TextStackFrame frame(this->owner().name().data());
ctx.stack().push(&frame);
this->call(fn_in, fn_out, ctx);
ctx.stack().pop();
@@ -187,7 +187,7 @@ class LazyInTupleCallBody : public TupleCallBodyBase {
ExecutionContext &ctx,
LazyState &state) const
{
- TextStackFrame frame(this->owner()->name().data());
+ TextStackFrame frame(this->owner().name().data());
ctx.stack().push(&frame);
this->call(fn_in, fn_out, ctx, state);
ctx.stack().pop();
@@ -217,31 +217,31 @@ class LazyInTupleCallBody : public TupleCallBodyBase {
class FunctionInputNamesProvider final : public TupleElementNameProvider {
private:
- Function *m_function;
+ Function &m_function;
public:
- FunctionInputNamesProvider(Function *function) : m_function(function)
+ FunctionInputNamesProvider(Function &function) : m_function(function)
{
}
StringRefNull get_element_name(uint index) const override
{
- return m_function->input_name(index);
+ return m_function.input_name(index);
}
};
class FunctionOutputNamesProvider final : public TupleElementNameProvider {
private:
- Function *m_function;
+ Function &m_function;
public:
- FunctionOutputNamesProvider(Function *function) : m_function(function)
+ FunctionOutputNamesProvider(Function &function) : m_function(function)
{
}
StringRefNull get_element_name(uint index) const override
{
- return m_function->output_name(index);
+ return m_function.output_name(index);
}
};
diff --git a/source/blender/functions/core/core-c.cpp b/source/blender/functions/core/core-c.cpp
index 3b529f4b6d5..1945c902542 100644
--- a/source/blender/functions/core/core-c.cpp
+++ b/source/blender/functions/core/core-c.cpp
@@ -4,7 +4,7 @@ using namespace FN;
void FN_function_free(FnFunction fn_c)
{
- unwrap(fn_c)->decref();
+ delete unwrap(fn_c);
}
bool FN_function_has_signature(FnFunction fn_c, FnType *inputs_c, FnType *outputs_c)
diff --git a/source/blender/functions/core/data_graph.cpp b/source/blender/functions/core/data_graph.cpp
index c0621dd396a..c4781a5705a 100644
--- a/source/blender/functions/core/data_graph.cpp
+++ b/source/blender/functions/core/data_graph.cpp
@@ -30,7 +30,7 @@ void DataGraph::print_socket(DataSocket socket) const
{
uint node_id = this->node_id_of_socket(socket);
auto &node = m_nodes[node_id];
- std::cout << "<" << node.function->name() << " - ";
+ std::cout << "<" << node.function.name() << " - ";
if (socket.is_input()) {
std::cout << "Input";
}
diff --git a/source/blender/functions/core/data_graph.hpp b/source/blender/functions/core/data_graph.hpp
index d5aea1390d7..8dbaec61fca 100644
--- a/source/blender/functions/core/data_graph.hpp
+++ b/source/blender/functions/core/data_graph.hpp
@@ -157,15 +157,15 @@ template<typename SequenceT> class DataSocketSequence {
class DataGraph {
public:
struct Node {
- SharedFunction function;
+ Function &function;
SourceInfo *source_info;
/* Index into m_origins. */
uint inputs_start;
/* Index into m_targets_info. */
uint outputs_start;
- Node(SharedFunction fn, SourceInfo *source_info, uint inputs_start, uint outputs_start)
- : function(std::move(fn)),
+ Node(Function &fn, SourceInfo *source_info, uint inputs_start, uint outputs_start)
+ : function(fn),
source_info(source_info),
inputs_start(inputs_start),
outputs_start(outputs_start)
@@ -221,19 +221,19 @@ class DataGraph {
return IndexRange(m_nodes.size());
}
- SharedFunction &function_of_node(uint node_id) const
+ Function &function_of_node(uint node_id) const
{
/* A function is mostly immutable anyway. */
- const SharedFunction &fn = m_nodes[node_id].function;
- return const_cast<SharedFunction &>(fn);
+ const Function &fn = m_nodes[node_id].function;
+ return const_cast<Function &>(fn);
}
- SharedFunction &function_of_input(uint input_id) const
+ Function &function_of_input(uint input_id) const
{
return this->function_of_node(m_inputs[input_id].node);
}
- SharedFunction &function_of_output(uint output_id) const
+ Function &function_of_output(uint output_id) const
{
return this->function_of_node(m_outputs[output_id].node);
}
@@ -263,7 +263,7 @@ class DataGraph {
IndexRange input_ids_of_node(uint node_id) const
{
const Node &node = m_nodes[node_id];
- return IndexRange(node.inputs_start, node.function->input_amount());
+ return IndexRange(node.inputs_start, node.function.input_amount());
}
DataSocketSequence<IndexRange> inputs_of_node(uint node_id) const
@@ -274,7 +274,7 @@ class DataGraph {
IndexRange output_ids_of_node(uint node_id) const
{
const Node &node = m_nodes[node_id];
- return IndexRange(node.outputs_start, node.function->output_amount());
+ return IndexRange(node.outputs_start, node.function.output_amount());
}
DataSocketSequence<IndexRange> outputs_of_node(uint node_id) const
@@ -299,7 +299,7 @@ class DataGraph {
const char *name_ptr_of_node(uint node_id) const
{
- return m_nodes[node_id].function->name().data();
+ return m_nodes[node_id].function.name().data();
}
uint origin_of_input(uint input_id) const
@@ -411,22 +411,22 @@ class DataGraph {
StringRefNull name_of_input(uint input_id) const
{
- return this->function_of_input(input_id)->input_name(this->index_of_input(input_id));
+ return this->function_of_input(input_id).input_name(this->index_of_input(input_id));
}
StringRefNull name_of_output(uint output_id) const
{
- return this->function_of_output(output_id)->output_name(this->index_of_output(output_id));
+ return this->function_of_output(output_id).output_name(this->index_of_output(output_id));
}
Type *type_of_input(uint input_id) const
{
- return this->function_of_input(input_id)->input_type(this->index_of_input(input_id));
+ return this->function_of_input(input_id).input_type(this->index_of_input(input_id));
}
Type *type_of_output(uint output_id) const
{
- return this->function_of_output(output_id)->output_type(this->index_of_output(output_id));
+ return this->function_of_output(output_id).output_type(this->index_of_output(output_id));
}
Type *type_of_input(DataSocket input_socket) const
diff --git a/source/blender/functions/core/data_graph_builder.cpp b/source/blender/functions/core/data_graph_builder.cpp
index 8b46c810dcf..c410e52f0c1 100644
--- a/source/blender/functions/core/data_graph_builder.cpp
+++ b/source/blender/functions/core/data_graph_builder.cpp
@@ -21,20 +21,20 @@ DataGraphBuilder::~DataGraphBuilder()
}
}
-BuilderNode *DataGraphBuilder::insert_function(SharedFunction function, SourceInfo *source_info)
+BuilderNode *DataGraphBuilder::insert_function(Function &function, SourceInfo *source_info)
{
/* Allocate memory for node, input sockets and output sockets. */
BuilderNode *node = m_allocator.allocate<BuilderNode>();
MutableArrayRef<BuilderInputSocket> input_sockets =
- m_allocator.allocate_array<BuilderInputSocket>(function->input_amount());
+ m_allocator.allocate_array<BuilderInputSocket>(function.input_amount());
MutableArrayRef<BuilderInputSocket *> input_socket_pointers =
- m_allocator.allocate_array<BuilderInputSocket *>(function->input_amount());
+ m_allocator.allocate_array<BuilderInputSocket *>(function.input_amount());
MutableArrayRef<BuilderOutputSocket> output_sockets =
- m_allocator.allocate_array<BuilderOutputSocket>(function->output_amount());
+ m_allocator.allocate_array<BuilderOutputSocket>(function.output_amount());
MutableArrayRef<BuilderOutputSocket *> output_socket_pointers =
- m_allocator.allocate_array<BuilderOutputSocket *>(function->output_amount());
+ m_allocator.allocate_array<BuilderOutputSocket *>(function.output_amount());
/* Initialize input sockets. */
for (uint i = 0; i < input_sockets.size(); i++) {
@@ -61,7 +61,7 @@ BuilderNode *DataGraphBuilder::insert_function(SharedFunction function, SourceIn
/* Initialize node. */
new (node) BuilderNode();
node->m_id = m_nodes.size();
- node->m_function = std::move(function);
+ node->m_function = &function;
node->m_builder = this;
node->m_source_info = source_info;
node->m_inputs = input_socket_pointers;
@@ -104,10 +104,8 @@ std::unique_ptr<DataGraph> DataGraphBuilder::build()
for (BuilderNode *builder_node : m_nodes) {
uint node_id = builder_node->id();
- r_nodes.append(DataGraph::Node(std::move(builder_node->function()),
- builder_node->source_info(),
- r_inputs.size(),
- r_outputs.size()));
+ r_nodes.append(DataGraph::Node(
+ builder_node->function(), builder_node->source_info(), r_inputs.size(), r_outputs.size()));
for (BuilderInputSocket *builder_socket : builder_node->inputs()) {
BLI_assert(builder_socket->origin() != nullptr);
diff --git a/source/blender/functions/core/data_graph_builder.hpp b/source/blender/functions/core/data_graph_builder.hpp
index 4aae9ed48fe..eda47a55595 100644
--- a/source/blender/functions/core/data_graph_builder.hpp
+++ b/source/blender/functions/core/data_graph_builder.hpp
@@ -66,7 +66,7 @@ class BuilderOutputSocket : public BuilderSocket {
class BuilderNode {
private:
DataGraphBuilder *m_builder;
- SharedFunction m_function;
+ Function *m_function;
SourceInfo *m_source_info;
uint m_id;
@@ -82,9 +82,9 @@ class BuilderNode {
return *m_builder;
}
- SharedFunction &function()
+ Function &function()
{
- return m_function;
+ return *m_function;
}
uint id()
@@ -155,7 +155,7 @@ class DataGraphBuilder {
std::unique_ptr<DataGraph> build();
- BuilderNode *insert_function(SharedFunction function, SourceInfo *source_info = nullptr);
+ BuilderNode *insert_function(Function &function, SourceInfo *source_info = nullptr);
void insert_link(BuilderOutputSocket *from, BuilderInputSocket *to);
template<typename T> void add_resource(std::unique_ptr<T> resource, const char *name)
@@ -213,12 +213,12 @@ inline BuilderOutputSocket *BuilderInputSocket::origin()
inline StringRef BuilderInputSocket::name()
{
- return m_node->function()->input_name(this->index());
+ return m_node->function().input_name(this->index());
}
inline Type *BuilderInputSocket::type()
{
- return m_node->function()->input_type(this->index());
+ return m_node->function().input_type(this->index());
}
inline uint BuilderOutputSocket::output_id()
@@ -233,12 +233,12 @@ inline ArrayRef<BuilderInputSocket *> BuilderOutputSocket::targets()
inline StringRef BuilderOutputSocket::name()
{
- return m_node->function()->output_name(this->index());
+ return m_node->function().output_name(this->index());
}
inline Type *BuilderOutputSocket::type()
{
- return m_node->function()->output_type(this->index());
+ return m_node->function().output_type(this->index());
}
} // namespace FN
diff --git a/source/blender/functions/core/dot_export.cpp b/source/blender/functions/core/dot_export.cpp
index e68fe34c5e4..3d29d4bb8ff 100644
--- a/source/blender/functions/core/dot_export.cpp
+++ b/source/blender/functions/core/dot_export.cpp
@@ -33,7 +33,7 @@ static void insert_node_table(std::stringstream &ss, BuilderNode *node)
/* Header */
ss << "<tr><td colspan=\"3\" align=\"center\"><b>";
- ss << node->function()->name();
+ ss << node->function().name();
ss << "</b></td></tr>";
/* Sockets */
diff --git a/source/blender/functions/core/function.hpp b/source/blender/functions/core/function.hpp
index 8eceb8dde9d..045be14ad2d 100644
--- a/source/blender/functions/core/function.hpp
+++ b/source/blender/functions/core/function.hpp
@@ -47,12 +47,12 @@ class FunctionBody : BLI::NonCopyable, BLI::NonMovable {
virtual ~FunctionBody();
- Function *owner() const;
+ Function &owner() const;
static const uint BODY_TYPE_AMOUNT = 5;
};
-class Function final : public RefCounter {
+class Function final {
public:
Function(Function &fn) = delete;
@@ -173,8 +173,6 @@ class Function final : public RefCounter {
const char *m_strings;
};
-using SharedFunction = AutoRefCount<Function>;
-
/* Function inline functions
***********************************************/
@@ -308,9 +306,9 @@ inline void FunctionBody::set_owner(Function *fn)
this->owner_init_post();
}
-inline Function *FunctionBody::owner() const
+inline Function &FunctionBody::owner() const
{
- return m_owner;
+ return *m_owner;
}
} /* namespace FN */
diff --git a/source/blender/functions/core/function_builder.cpp b/source/blender/functions/core/function_builder.cpp
index 20f812e01c0..4a614cd6141 100644
--- a/source/blender/functions/core/function_builder.cpp
+++ b/source/blender/functions/core/function_builder.cpp
@@ -40,7 +40,7 @@ void FunctionBuilder::add_outputs(const DataGraph &data_graph, ArrayRef<DataSock
}
}
-SharedFunction FunctionBuilder::build(StringRef function_name)
+std::unique_ptr<Function> FunctionBuilder::build(StringRef function_name)
{
auto name_ref = m_strings_builder.add(function_name);
char *strings = m_strings_builder.build();
@@ -57,12 +57,12 @@ SharedFunction FunctionBuilder::build(StringRef function_name)
output_names.append(name.to_string_ref(strings));
}
- return SharedFunction::New(name_ref.to_string_ref(strings),
- input_names,
- m_input_types,
- output_names,
- m_output_types,
- strings);
+ return make_unique<Function>(name_ref.to_string_ref(strings),
+ input_names,
+ m_input_types,
+ output_names,
+ m_output_types,
+ strings);
}
} // namespace FN
diff --git a/source/blender/functions/core/function_builder.hpp b/source/blender/functions/core/function_builder.hpp
index 23c94a87290..9965039f5d8 100644
--- a/source/blender/functions/core/function_builder.hpp
+++ b/source/blender/functions/core/function_builder.hpp
@@ -39,7 +39,7 @@ class FunctionBuilder {
/**
* Create a new function with the given name and all the inputs and outputs previously added.
*/
- SharedFunction build(StringRef function_name);
+ std::unique_ptr<Function> build(StringRef function_name);
};
} // namespace FN
diff --git a/source/blender/functions/core/function_graph.cpp b/source/blender/functions/core/function_graph.cpp
index f122535b584..09ccb0bd4a8 100644
--- a/source/blender/functions/core/function_graph.cpp
+++ b/source/blender/functions/core/function_graph.cpp
@@ -2,7 +2,7 @@
namespace FN {
-SharedFunction FunctionGraph::new_function(StringRef name) const
+std::unique_ptr<Function> FunctionGraph::new_function(StringRef name) const
{
FunctionBuilder builder;
builder.add_inputs(*m_graph, m_inputs);
diff --git a/source/blender/functions/core/function_graph.hpp b/source/blender/functions/core/function_graph.hpp
index 78f0074113b..f390a8bdae5 100644
--- a/source/blender/functions/core/function_graph.hpp
+++ b/source/blender/functions/core/function_graph.hpp
@@ -51,7 +51,7 @@ class FunctionGraph {
* Create a new function with the given name. The inputs and outputs correspond to the sockets in
* the graph. The returned function does not contain any bodies.
*/
- SharedFunction new_function(StringRef name) const;
+ std::unique_ptr<Function> new_function(StringRef name) const;
/**
* Get a subset of all sockets in the graph that can influence the function execution (under the
diff --git a/source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp b/source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp
index 34d8965e554..cf548696537 100644
--- a/source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/data_flow_nodes-c.cpp
@@ -7,15 +7,13 @@ FnFunction FN_tree_to_function(bNodeTree *btree)
{
SCOPED_TIMER("Tree to function");
BLI_assert(btree);
- Optional<SharedFunction> optional_fn = DataFlowNodes::generate_function(btree);
+ Optional<std::unique_ptr<Function>> optional_fn = DataFlowNodes::generate_function(btree);
if (!optional_fn.has_value()) {
return nullptr;
}
- SharedFunction fn = optional_fn.extract();
- Function *fn_ptr = fn.ptr();
- fn_ptr->incref();
- return wrap(fn_ptr);
+ std::unique_ptr<Function> fn = optional_fn.extract();
+ return wrap(fn.release());
}
FnFunction FN_function_get_with_signature(bNodeTree *btree, FnType *inputs_c, FnType *outputs_c)
diff --git a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
index 462a6f7ef32..6aa3b4caa67 100644
--- a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
@@ -32,7 +32,7 @@ static void find_interface_sockets(VirtualNodeTree &vtree,
}
}
-Optional<SharedFunction> generate_function(bNodeTree *btree)
+Optional<std::unique_ptr<Function>> generate_function(bNodeTree *btree)
{
auto vtree = make_unique<VirtualNodeTree>();
vtree->add_all_of_tree(btree);
@@ -53,11 +53,11 @@ Optional<SharedFunction> generate_function(bNodeTree *btree)
// fgraph.graph().to_dot__clipboard();
- auto fn = fgraph.new_function(btree->id.name);
- fgraph_add_DependenciesBody(fn, fgraph);
- fgraph_add_LLVMBuildIRBody(fn, fgraph);
+ std::unique_ptr<Function> fn = fgraph.new_function(btree->id.name);
+ fgraph_add_DependenciesBody(*fn, fgraph);
+ fgraph_add_LLVMBuildIRBody(*fn, fgraph);
- fgraph_add_TupleCallBody(fn, fgraph);
+ fgraph_add_TupleCallBody(*fn, fgraph);
// derive_TupleCallBody_from_LLVMBuildIRBody(fn);
fn->add_resource(std::move(vtree), "Virtual Node Tree");
diff --git a/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp b/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
index 2771559c8bd..54fdadbaa6a 100644
--- a/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.hpp
@@ -10,7 +10,7 @@ namespace DataFlowNodes {
using BLI::Optional;
-Optional<SharedFunction> generate_function(struct bNodeTree *btree);
+Optional<std::unique_ptr<Function>> generate_function(struct bNodeTree *btree);
} // namespace DataFlowNodes
} // namespace FN
diff --git a/source/blender/functions/frontends/data_flow_nodes/mappings.cpp b/source/blender/functions/frontends/data_flow_nodes/mappings.cpp
index dced74ecc7c..50e74e4cd0d 100644
--- a/source/blender/functions/frontends/data_flow_nodes/mappings.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/mappings.cpp
@@ -50,7 +50,7 @@ void NodeInserters::register_inserter(StringRef idname, NodeInserter inserter)
void NodeInserters::register_function(StringRef idname, FunctionGetter getter)
{
auto inserter = [getter](VTreeDataGraphBuilder &builder, VirtualNode *vnode) {
- SharedFunction fn = getter();
+ Function &fn = getter();
BuilderNode *node = builder.insert_function(fn, vnode);
builder.map_sockets(node, vnode);
};
@@ -103,7 +103,7 @@ void LinkInserters::register_conversion_function(StringRef from_type,
{
auto inserter =
[getter](VTreeDataGraphBuilder &builder, BuilderOutputSocket *from, BuilderInputSocket *to) {
- auto fn = getter();
+ Function &fn = getter();
BuilderNode *node = builder.insert_function(fn);
builder.insert_link(from, node->input(0));
builder.insert_link(node->output(0), to);
diff --git a/source/blender/functions/frontends/data_flow_nodes/mappings.hpp b/source/blender/functions/frontends/data_flow_nodes/mappings.hpp
index e1eefba6e2a..6ee4eaeb261 100644
--- a/source/blender/functions/frontends/data_flow_nodes/mappings.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/mappings.hpp
@@ -23,7 +23,7 @@ typedef std::function<void(
VTreeDataGraphBuilder &builder, BuilderOutputSocket *from, BuilderInputSocket *to)>
ConversionInserter;
-typedef std::function<SharedFunction()> FunctionGetter;
+typedef std::function<Function &()> FunctionGetter;
class TypeMappings {
private:
diff --git a/source/blender/functions/frontends/data_flow_nodes/mappings/conversion_inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/mappings/conversion_inserters.cpp
index 69a440404b5..4340f410703 100644
--- a/source/blender/functions/frontends/data_flow_nodes/mappings/conversion_inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/mappings/conversion_inserters.cpp
@@ -10,7 +10,7 @@ static void INSERT_base_to_list(VTreeDataGraphBuilder &builder,
BuilderInputSocket *to)
{
Type *base_type = from->type();
- auto fn = Functions::GET_FN_list_from_element(base_type);
+ Function &fn = Functions::GET_FN_list_from_element(base_type);
BuilderNode *node = builder.insert_function(fn);
builder.insert_link(from, node->input(0));
builder.insert_link(node->output(0), to);
diff --git a/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
index 79f5a9fd2c1..cdb7a67f2ea 100644
--- a/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
@@ -15,24 +15,23 @@ using namespace Types;
struct AutoVectorizedInput {
const char *prop_name;
- SharedFunction &default_value_builder;
+ Function &default_value_builder;
};
-static SharedFunction get_vectorized_function(SharedFunction &original_fn,
- PointerRNA &node_rna,
- ArrayRef<AutoVectorizedInput> auto_vectorized_inputs,
- bool use_cache = true)
+static Function &get_vectorized_function(Function &original_fn,
+ PointerRNA &node_rna,
+ ArrayRef<AutoVectorizedInput> auto_vectorized_inputs)
{
#ifdef DEBUG
- BLI_assert(original_fn->input_amount() == auto_vectorized_inputs.size());
- for (uint i = 0; i < original_fn->input_amount(); i++) {
- BLI_assert(original_fn->input_type(i) ==
- auto_vectorized_inputs[i].default_value_builder->output_type(0));
+ BLI_assert(original_fn.input_amount() == auto_vectorized_inputs.size());
+ for (uint i = 0; i < original_fn.input_amount(); i++) {
+ BLI_assert(original_fn.input_type(i) ==
+ auto_vectorized_inputs[i].default_value_builder.output_type(0));
}
#endif
Vector<bool> vectorized_inputs;
- Vector<SharedFunction> used_default_value_builders;
+ Vector<Function *> used_default_value_builders;
for (auto &input : auto_vectorized_inputs) {
char state[5];
BLI_assert(RNA_string_length(&node_rna, input.prop_name) == strlen("BASE"));
@@ -42,19 +41,13 @@ static SharedFunction get_vectorized_function(SharedFunction &original_fn,
bool is_vectorized = STREQ(state, "LIST");
vectorized_inputs.append(is_vectorized);
if (is_vectorized) {
- used_default_value_builders.append(input.default_value_builder);
+ used_default_value_builders.append(&input.default_value_builder);
}
}
if (vectorized_inputs.contains(true)) {
- if (use_cache) {
- return Functions::to_vectorized_function__with_cache(
- original_fn, vectorized_inputs, used_default_value_builders);
- }
- else {
- return Functions::to_vectorized_function(
- original_fn, vectorized_inputs, used_default_value_builders);
- }
+ return Functions::to_vectorized_function__with_cache(
+ original_fn, vectorized_inputs, used_default_value_builders);
}
else {
return original_fn;
@@ -63,11 +56,11 @@ static SharedFunction get_vectorized_function(SharedFunction &original_fn,
static void INSERT_object_transforms(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
- auto fn = Functions::GET_FN_object_location();
+ Function &fn = Functions::GET_FN_object_location();
builder.insert_matching_function(fn, vnode);
}
-static SharedFunction &get_float_math_function(int operation)
+static Function &get_float_math_function(int operation)
{
switch (operation) {
case 1:
@@ -127,26 +120,25 @@ static void INSERT_float_math(VTreeDataGraphBuilder &builder, VirtualNode *vnode
PointerRNA rna = vnode->rna();
int operation = RNA_enum_get(&rna, "operation");
- SharedFunction &original_fn = get_float_math_function(operation);
- uint input_amount = original_fn->input_amount();
+ Function &original_fn = get_float_math_function(operation);
+ uint input_amount = original_fn.input_amount();
if (input_amount == 1) {
- SharedFunction fn = get_vectorized_function(
+ Function &fn = get_vectorized_function(
original_fn, rna, {{"use_list__a", Functions::GET_FN_output_float_0()}});
builder.insert_matching_function(fn, vnode);
}
else {
BLI_assert(input_amount == 2);
- SharedFunction fn = get_vectorized_function(
- original_fn,
- rna,
- {{"use_list__a", Functions::GET_FN_output_float_0()},
- {"use_list__b", Functions::GET_FN_output_float_0()}});
+ Function &fn = get_vectorized_function(original_fn,
+ rna,
+ {{"use_list__a", Functions::GET_FN_output_float_0()},
+ {"use_list__b", Functions::GET_FN_output_float_0()}});
builder.insert_matching_function(fn, vnode);
}
}
-static SharedFunction &get_vector_math_function(int operation)
+static Function &get_vector_math_function(int operation)
{
switch (operation) {
case 1:
@@ -176,18 +168,17 @@ static void INSERT_vector_math(VTreeDataGraphBuilder &builder, VirtualNode *vnod
PointerRNA rna = vnode->rna();
int operation = RNA_enum_get(&rna, "operation");
- SharedFunction fn = get_vectorized_function(
- get_vector_math_function(operation),
- rna,
- {{"use_list__a", Functions::GET_FN_output_float3_0()},
- {"use_list__b", Functions::GET_FN_output_float3_0()}});
+ Function &fn = get_vectorized_function(get_vector_math_function(operation),
+ rna,
+ {{"use_list__a", Functions::GET_FN_output_float3_0()},
+ {"use_list__b", Functions::GET_FN_output_float3_0()}});
builder.insert_matching_function(fn, vnode);
}
static void INSERT_clamp(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
- SharedFunction &max_fn = Functions::GET_FN_max_floats();
- SharedFunction &min_fn = Functions::GET_FN_min_floats();
+ Function &max_fn = Functions::GET_FN_max_floats();
+ Function &min_fn = Functions::GET_FN_min_floats();
BuilderNode *max_node = builder.insert_function(max_fn, vnode);
BuilderNode *min_node = builder.insert_function(min_fn, vnode);
@@ -202,14 +193,14 @@ static void INSERT_clamp(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
static void INSERT_get_list_element(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
Type *base_type = builder.query_type_property(vnode, "active_type");
- SharedFunction &fn = Functions::GET_FN_get_list_element(base_type);
+ Function &fn = Functions::GET_FN_get_list_element(base_type);
builder.insert_matching_function(fn, vnode);
}
static void INSERT_list_length(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
Type *base_type = builder.query_type_property(vnode, "active_type");
- SharedFunction &fn = Functions::GET_FN_list_length(base_type);
+ Function &fn = Functions::GET_FN_list_length(base_type);
builder.insert_matching_function(fn, vnode);
}
@@ -275,35 +266,35 @@ static void INSERT_call(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
return;
}
- Optional<SharedFunction> optional_fn = generate_function(btree);
+ Optional<std::unique_ptr<Function>> optional_fn = generate_function(btree);
BLI_assert(optional_fn.has_value());
- SharedFunction fn = optional_fn.extract();
- builder.insert_matching_function(fn, vnode);
+ auto fn = optional_fn.extract();
+ builder.insert_matching_function(*fn, vnode);
+ builder.add_resource(std::move(fn), "Generated function in for Call node");
}
static void INSERT_switch(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
Type *data_type = builder.query_type_property(vnode, "data_type");
- auto fn = Functions::GET_FN_bool_switch(data_type);
+ Function &fn = Functions::GET_FN_bool_switch(data_type);
builder.insert_matching_function(fn, vnode);
}
static void INSERT_combine_vector(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
PointerRNA rna = vnode->rna();
- SharedFunction fn = get_vectorized_function(
- Functions::GET_FN_combine_vector(),
- rna,
- {{"use_list__x", Functions::GET_FN_output_float_0()},
- {"use_list__y", Functions::GET_FN_output_float_0()},
- {"use_list__z", Functions::GET_FN_output_float_0()}});
+ Function &fn = get_vectorized_function(Functions::GET_FN_combine_vector(),
+ rna,
+ {{"use_list__x", Functions::GET_FN_output_float_0()},
+ {"use_list__y", Functions::GET_FN_output_float_0()},
+ {"use_list__z", Functions::GET_FN_output_float_0()}});
builder.insert_matching_function(fn, vnode);
}
static void INSERT_separate_vector(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
PointerRNA rna = vnode->rna();
- SharedFunction fn = get_vectorized_function(
+ Function &fn = get_vectorized_function(
Functions::GET_FN_separate_vector(),
rna,
{{"use_list__vector", Functions::GET_FN_output_float3_0()}});
@@ -313,7 +304,7 @@ static void INSERT_separate_vector(VTreeDataGraphBuilder &builder, VirtualNode *
static void INSERT_separate_color(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
PointerRNA rna = vnode->rna();
- SharedFunction fn = get_vectorized_function(
+ Function &fn = get_vectorized_function(
Functions::GET_FN_separate_color(),
rna,
{{"use_list__color", Functions::GET_FN_output_magenta()}});
@@ -323,7 +314,7 @@ static void INSERT_separate_color(VTreeDataGraphBuilder &builder, VirtualNode *v
static void INSERT_combine_color(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
PointerRNA rna = vnode->rna();
- SharedFunction fn = get_vectorized_function(
+ Function &fn = get_vectorized_function(
Functions::GET_FN_combine_color(),
rna,
{{"use_list__red", Functions::GET_FN_output_float_0()},
@@ -333,7 +324,7 @@ static void INSERT_combine_color(VTreeDataGraphBuilder &builder, VirtualNode *vn
builder.insert_matching_function(fn, vnode);
}
-static SharedFunction &get_compare_function(int operation)
+static Function &get_compare_function(int operation)
{
switch (operation) {
case 1:
@@ -348,15 +339,14 @@ static void INSERT_compare(VTreeDataGraphBuilder &builder, VirtualNode *vnode)
{
PointerRNA rna = vnode->rna();
int operation = RNA_enum_get(&rna, "operation");
- SharedFunction fn = get_vectorized_function(
- get_compare_function(operation),
- rna,
- {{"use_list__a", Functions::GET_FN_output_float_0()},
- {"use_list__b", Functions::GET_FN_output_float_0()}});
+ Function &fn = get_vectorized_function(get_compare_function(operation),
+ rna,
+ {{"use_list__a", Functions::GET_FN_output_float_0()},
+ {"use_list__b", Functions::GET_FN_output_float_0()}});
builder.insert_matching_function(fn, vnode);
}
-static SharedFunction &get_boolean_math_function(int operation)
+static Function &get_boolean_math_function(int operation)
{
switch (operation) {
case 1:
@@ -375,20 +365,19 @@ static void INSERT_boolean_math(VTreeDataGraphBuilder &builder, VirtualNode *vno
{
PointerRNA rna = vnode->rna();
int operation = RNA_enum_get(&rna, "operation");
- SharedFunction &original_fn = get_boolean_math_function(operation);
- uint input_amount = original_fn->input_amount();
+ Function &original_fn = get_boolean_math_function(operation);
+ uint input_amount = original_fn.input_amount();
if (input_amount == 1) {
- SharedFunction fn = get_vectorized_function(
+ Function &fn = get_vectorized_function(
original_fn, rna, {{"use_list__a", Functions::GET_FN_output_false()}});
builder.insert_matching_function(fn, vnode);
}
else {
BLI_assert(input_amount == 2);
- SharedFunction fn = get_vectorized_function(
- original_fn,
- rna,
- {{"use_list__a", Functions::GET_FN_output_false()},
- {"use_list__b", Functions::GET_FN_output_true()}});
+ Function &fn = get_vectorized_function(original_fn,
+ rna,
+ {{"use_list__a", Functions::GET_FN_output_false()},
+ {"use_list__b", Functions::GET_FN_output_true()}});
builder.insert_matching_function(fn, vnode);
}
}
diff --git a/source/blender/functions/frontends/data_flow_nodes/unlinked_input_groupers.cpp b/source/blender/functions/frontends/data_flow_nodes/unlinked_input_groupers.cpp
index 3fe53ffd6af..ecb5c4b164f 100644
--- a/source/blender/functions/frontends/data_flow_nodes/unlinked_input_groupers.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/unlinked_input_groupers.cpp
@@ -111,7 +111,7 @@ void GroupByNodeUsage::group(VTreeDataGraphBuilder &builder,
Vector<uint> updated_vsockets;
for (BuilderNode *node : builder.placeholder_nodes()) {
- VNodePlaceholderBody &placeholder_info = node->function()->body<VNodePlaceholderBody>();
+ VNodePlaceholderBody &placeholder_info = node->function().body<VNodePlaceholderBody>();
uint random = rand();
for (VirtualSocket *vsocket : placeholder_info.inputs()) {
update_hash_of_used_vsockets(
@@ -134,7 +134,7 @@ void GroupBySocketUsage::group(VTreeDataGraphBuilder &builder,
Vector<uint> updated_vsockets;
for (BuilderNode *node : builder.placeholder_nodes()) {
- VNodePlaceholderBody &placeholder_info = node->function()->body<VNodePlaceholderBody>();
+ VNodePlaceholderBody &placeholder_info = node->function().body<VNodePlaceholderBody>();
for (VirtualSocket *vsocket : placeholder_info.inputs()) {
update_hash_of_used_vsockets(
builder, vsocket, rand(), hash_per_vsocket, was_updated_per_vsocket, updated_vsockets);
diff --git a/source/blender/functions/frontends/data_flow_nodes/unlinked_input_inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/unlinked_input_inserters.cpp
index c603a8bbbe5..36b51cb892b 100644
--- a/source/blender/functions/frontends/data_flow_nodes/unlinked_input_inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/unlinked_input_inserters.cpp
@@ -86,11 +86,12 @@ void DynamicSocketLoader::insert(VTreeDataGraphBuilder &builder,
btrees.append(vsocket->btree());
}
- auto fn = fn_builder.build("Input Sockets");
+ std::unique_ptr<Function> fn = fn_builder.build("Input Sockets");
fn->add_body<SocketLoaderBody>(btrees, bsockets, loaders);
fn->add_body<SocketLoaderDependencies>(btrees, bsockets);
- BuilderNode *node = builder.insert_function(fn);
+ BuilderNode *node = builder.insert_function(*fn);
+ builder.add_resource(std::move(fn), "Owned dynamic socket loader function");
r_new_origins.copy_from(node->outputs());
}
@@ -165,7 +166,7 @@ void ConstantInputsHandler::insert(VTreeDataGraphBuilder &builder,
fn_builder.add_output(vsocket->name(), type);
}
- SharedFunction fn = fn_builder.build("Unlinked Inputs");
+ std::unique_ptr<Function> fn = fn_builder.build("Unlinked Inputs");
std::unique_ptr<TupleMeta> inputs_meta = make_unique<TupleMeta>(fn->output_types());
@@ -184,11 +185,13 @@ void ConstantInputsHandler::insert(VTreeDataGraphBuilder &builder,
tuple_call_body.set_tuple(inputs_tuple.get());
build_ir_body.set_tuple(inputs_tuple.get());
+ BuilderNode *node = builder.insert_function(*fn);
+
builder.add_resource(std::move(inputs_meta), "Meta information for tuple");
builder.add_resource(std::move(inputs_tuple_data_init), "Buffer for tuple");
builder.add_resource(std::move(inputs_tuple), "Tuple containing function inputs");
+ builder.add_resource(std::move(fn), "Owned constant input function");
- BuilderNode *node = builder.insert_function(fn);
r_new_origins.copy_from(node->outputs());
}
diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp
index 93a2613d99d..b306b1da401 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph.cpp
@@ -42,9 +42,9 @@ Vector<VirtualSocket *> VTreeDataGraph::find_placeholder_dependencies(ArrayRef<D
}
else {
uint node_id = m_graph->node_id_of_output(socket);
- SharedFunction &fn = m_graph->function_of_node(node_id);
- if (fn->has_body<VNodePlaceholderBody>()) {
- auto &body = fn->body<VNodePlaceholderBody>();
+ Function &fn = m_graph->function_of_node(node_id);
+ if (fn.has_body<VNodePlaceholderBody>()) {
+ auto &body = fn.body<VNodePlaceholderBody>();
VirtualNode *vnode = body.vnode();
uint data_output_index = m_graph->index_of_output(socket);
VirtualSocket *vsocket = this->find_data_output(vnode, data_output_index);
diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
index 8bcf4f2c2dc..43ff7109e36 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
@@ -107,20 +107,19 @@ class NodeSource : public SourceInfo {
}
};
-BuilderNode *VTreeDataGraphBuilder::insert_function(SharedFunction &fn)
+BuilderNode *VTreeDataGraphBuilder::insert_function(Function &fn)
{
return m_graph_builder.insert_function(fn);
}
-BuilderNode *VTreeDataGraphBuilder::insert_matching_function(SharedFunction &fn,
- VirtualNode *vnode)
+BuilderNode *VTreeDataGraphBuilder::insert_matching_function(Function &fn, VirtualNode *vnode)
{
BuilderNode *node = this->insert_function(fn, vnode);
this->map_sockets(node, vnode);
return node;
}
-BuilderNode *VTreeDataGraphBuilder::insert_function(SharedFunction &fn, VirtualNode *vnode)
+BuilderNode *VTreeDataGraphBuilder::insert_function(Function &fn, VirtualNode *vnode)
{
BLI_assert(vnode != nullptr);
NodeSource *source = m_graph_builder.new_source_info<NodeSource>(vnode->btree(), vnode->bnode());
@@ -147,9 +146,11 @@ BuilderNode *VTreeDataGraphBuilder::insert_placeholder(VirtualNode *vnode)
}
}
- auto fn = fn_builder.build(vnode->name());
+ std::unique_ptr<Function> fn = fn_builder.build(vnode->name());
fn->add_body<VNodePlaceholderBody>(vnode, std::move(vsocket_inputs));
- BuilderNode *node = this->insert_function(fn);
+ BuilderNode *node = this->insert_function(*fn);
+ this->add_resource(std::move(fn), "placeholder function");
+
this->map_data_sockets(node, vnode);
m_placeholder_nodes.append(node);
return node;
diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.hpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.hpp
index f9f6380f59f..672bf85c61c 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.hpp
@@ -36,9 +36,9 @@ class VTreeDataGraphBuilder {
return m_socket_map;
}
- BuilderNode *insert_function(SharedFunction &fn);
- BuilderNode *insert_matching_function(SharedFunction &fn, VirtualNode *vnode);
- BuilderNode *insert_function(SharedFunction &fn, VirtualNode *vnode);
+ BuilderNode *insert_function(Function &fn);
+ BuilderNode *insert_matching_function(Function &fn, VirtualNode *vnode);
+ BuilderNode *insert_function(Function &fn, VirtualNode *vnode);
BuilderNode *insert_placeholder(VirtualNode *vnode);
template<typename T> void add_resource(std::unique_ptr<T> resource, const char *name)
diff --git a/source/blender/functions/functions/array_execution.cpp b/source/blender/functions/functions/array_execution.cpp
index 2e11c4d2e48..afa70f1960a 100644
--- a/source/blender/functions/functions/array_execution.cpp
+++ b/source/blender/functions/functions/array_execution.cpp
@@ -11,12 +11,12 @@ ArrayExecution::~ArrayExecution()
{
}
-ArrayExecution::ArrayExecution(SharedFunction function) : m_function(std::move(function))
+ArrayExecution::ArrayExecution(Function &function) : m_function(function)
{
- for (Type *type : m_function->input_types()) {
+ for (Type *type : m_function.input_types()) {
m_input_sizes.append(type->extension<CPPTypeInfo>().size());
}
- for (Type *type : m_function->output_types()) {
+ for (Type *type : m_function.output_types()) {
m_output_sizes.append(type->extension<CPPTypeInfo>().size());
}
}
@@ -26,9 +26,9 @@ ArrayExecution::ArrayExecution(SharedFunction function) : m_function(std::move(f
class TupleCallArrayExecution : public ArrayExecution {
public:
- TupleCallArrayExecution(SharedFunction function) : ArrayExecution(std::move(function))
+ TupleCallArrayExecution(Function &function) : ArrayExecution(function)
{
- BLI_assert(m_function->has_body<TupleCallBody>());
+ BLI_assert(m_function.has_body<TupleCallBody>());
}
void call(ArrayRef<uint> indices,
@@ -36,13 +36,13 @@ class TupleCallArrayExecution : public ArrayExecution {
MutableArrayRef<void *> output_buffers,
ExecutionContext &execution_context) override
{
- uint input_amount = m_function->input_amount();
- uint output_amount = m_function->output_amount();
+ uint input_amount = m_function.input_amount();
+ uint output_amount = m_function.output_amount();
BLI_assert(input_amount == input_buffers.size());
BLI_assert(output_amount == output_buffers.size());
- TupleCallBody &body = m_function->body<TupleCallBody>();
+ TupleCallBody &body = m_function.body<TupleCallBody>();
FN_TUPLE_CALL_ALLOC_TUPLES(body, fn_in, fn_out);
for (uint index : indices) {
@@ -61,9 +61,9 @@ class TupleCallArrayExecution : public ArrayExecution {
}
};
-std::unique_ptr<ArrayExecution> get_tuple_call_array_execution(SharedFunction function)
+std::unique_ptr<ArrayExecution> get_tuple_call_array_execution(Function &function)
{
- return std::unique_ptr<ArrayExecution>(new TupleCallArrayExecution(std::move(function)));
+ return std::unique_ptr<ArrayExecution>(new TupleCallArrayExecution(function));
}
/* LLVM Array Execution
@@ -82,11 +82,11 @@ class LLVMArrayExecution : public ArrayExecution {
std::unique_ptr<CompiledLLVM> m_compiled_function;
public:
- LLVMArrayExecution(SharedFunction function) : ArrayExecution(std::move(function))
+ LLVMArrayExecution(Function &function) : ArrayExecution(function)
{
- BLI_assert(m_function->has_body<LLVMBuildIRBody>());
- m_input_type_infos = m_function->input_extensions<LLVMTypeInfo>();
- m_output_type_infos = m_function->output_extensions<LLVMTypeInfo>();
+ BLI_assert(m_function.has_body<LLVMBuildIRBody>());
+ m_input_type_infos = m_function.input_extensions<LLVMTypeInfo>();
+ m_output_type_infos = m_function.output_extensions<LLVMTypeInfo>();
this->compile();
}
@@ -108,7 +108,7 @@ class LLVMArrayExecution : public ArrayExecution {
void compile()
{
llvm::LLVMContext *context = aquire_llvm_context();
- llvm::Module *module = new llvm::Module(m_function->name() + " (Array Execution)", *context);
+ llvm::Module *module = new llvm::Module(m_function.name() + " (Array Execution)", *context);
llvm::Function *function = this->build_function_ir(module);
m_compiled_function = CompiledLLVM::FromIR(module, function);
release_llvm_context(context);
@@ -116,7 +116,7 @@ class LLVMArrayExecution : public ArrayExecution {
llvm::Function *build_function_ir(llvm::Module *module)
{
llvm::LLVMContext &context = module->getContext();
- LLVMBuildIRBody &body = m_function->body<LLVMBuildIRBody>();
+ LLVMBuildIRBody &body = m_function.body<LLVMBuildIRBody>();
/* Create the main function. */
llvm::FunctionType *ftype = llvm::TypeBuilder<CompiledFunctionSignature, false>::get(context);
@@ -151,7 +151,7 @@ class LLVMArrayExecution : public ArrayExecution {
FunctionIRCache function_cache;
BuildIRSettings settings;
llvm::Function *actual_function = body.build_function(
- module, m_function->name(), settings, function_cache);
+ module, m_function.name(), settings, function_cache);
llvm::Value *result = body_builder.CreateCall(actual_function, input_values);
/* Store the computed results in the output buffers. */
@@ -168,12 +168,12 @@ class LLVMArrayExecution : public ArrayExecution {
Vector<llvm::Value *> get_input_buffers(CodeBuilder &builder, llvm::Value *input_buffers_arg)
{
Vector<llvm::Value *> input_buffers;
- for (uint i = 0; i < m_function->input_amount(); i++) {
+ for (uint i = 0; i < m_function.input_amount(); i++) {
uint element_size = m_input_sizes[i];
llvm::Value *input_buffer = builder.CreateLoadAtIndex(input_buffers_arg, i);
llvm::Value *typed_input_buffer = builder.CastToPointerWithStride(input_buffer,
element_size);
- typed_input_buffer->setName(to_llvm(m_function->input_name(i) + " Array"));
+ typed_input_buffer->setName(to_llvm(m_function.input_name(i) + " Array"));
input_buffers.append(typed_input_buffer);
}
return input_buffers;
@@ -182,7 +182,7 @@ class LLVMArrayExecution : public ArrayExecution {
Vector<llvm::Value *> get_output_buffers(CodeBuilder &builder, llvm::Value *output_buffers_arg)
{
Vector<llvm::Value *> output_buffers;
- for (uint i = 0; i < m_function->output_amount(); i++) {
+ for (uint i = 0; i < m_function.output_amount(); i++) {
uint element_size = m_output_sizes[i];
llvm::Value *output_buffer = builder.CreateLoadAtIndex(output_buffers_arg, i);
llvm::Value *typed_output_buffer = builder.CastToPointerWithStride(output_buffer,
@@ -197,10 +197,10 @@ class LLVMArrayExecution : public ArrayExecution {
llvm::Value *index_to_process)
{
Vector<llvm::Value *> input_values;
- for (uint i = 0; i < m_function->input_amount(); i++) {
+ for (uint i = 0; i < m_function.input_amount(); i++) {
llvm::Value *addr = builder.CreateGEP(input_buffers[i], index_to_process);
llvm::Value *value = m_input_type_infos[i]->build_load_ir__copy(builder, addr);
- value->setName(to_llvm(m_function->input_name(i)));
+ value->setName(to_llvm(m_function.input_name(i)));
input_values.append(value);
}
return input_values;
@@ -211,18 +211,18 @@ class LLVMArrayExecution : public ArrayExecution {
llvm::Value *index_to_process,
llvm::Value *computed_results)
{
- for (uint i = 0; i < m_function->output_amount(); i++) {
+ for (uint i = 0; i < m_function.output_amount(); i++) {
llvm::Value *addr = builder.CreateGEP(output_buffers[i], index_to_process);
llvm::Value *value = builder.CreateExtractValue(computed_results, i);
- value->setName(to_llvm(m_function->output_name(i)));
+ value->setName(to_llvm(m_function.output_name(i)));
m_output_type_infos[i]->build_store_ir__relocate(builder, value, addr);
}
}
};
-std::unique_ptr<ArrayExecution> get_precompiled_array_execution(SharedFunction function)
+std::unique_ptr<ArrayExecution> get_precompiled_array_execution(Function &function)
{
- return std::unique_ptr<ArrayExecution>(new LLVMArrayExecution(std::move(function)));
+ return std::unique_ptr<ArrayExecution>(new LLVMArrayExecution(function));
}
} // namespace Functions
diff --git a/source/blender/functions/functions/array_execution.hpp b/source/blender/functions/functions/array_execution.hpp
index 2a04d2b7aaf..c69e11a3a32 100644
--- a/source/blender/functions/functions/array_execution.hpp
+++ b/source/blender/functions/functions/array_execution.hpp
@@ -9,12 +9,12 @@ namespace Functions {
class ArrayExecution {
protected:
- SharedFunction m_function;
+ Function &m_function;
Vector<uint> m_input_sizes;
Vector<uint> m_output_sizes;
public:
- ArrayExecution(SharedFunction function);
+ ArrayExecution(Function &function);
virtual ~ArrayExecution();
virtual void call(ArrayRef<uint> indices,
@@ -23,8 +23,8 @@ class ArrayExecution {
ExecutionContext &execution_context) = 0;
};
-std::unique_ptr<ArrayExecution> get_tuple_call_array_execution(SharedFunction function);
-std::unique_ptr<ArrayExecution> get_precompiled_array_execution(SharedFunction function);
+std::unique_ptr<ArrayExecution> get_tuple_call_array_execution(Function &function);
+std::unique_ptr<ArrayExecution> get_precompiled_array_execution(Function &function);
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/auto_vectorization.cpp b/source/blender/functions/functions/auto_vectorization.cpp
index 526067890fb..c367636d47b 100644
--- a/source/blender/functions/functions/auto_vectorization.cpp
+++ b/source/blender/functions/functions/auto_vectorization.cpp
@@ -23,9 +23,9 @@ class IterationStackFrame : public StackFrame {
class AutoVectorizationGen : public LLVMBuildIRBody {
private:
- SharedFunction m_main;
+ Function &m_main;
Vector<bool> m_input_is_list;
- Vector<SharedFunction> m_empty_list_value_builders;
+ Vector<Function *> m_empty_list_value_builders;
struct InputInfo {
bool is_list;
@@ -43,17 +43,17 @@ class AutoVectorizationGen : public LLVMBuildIRBody {
Vector<OutputInfo> m_output_info;
public:
- AutoVectorizationGen(SharedFunction main,
+ AutoVectorizationGen(Function &main,
ArrayRef<bool> input_is_list,
- ArrayRef<SharedFunction> empty_list_value_builders)
+ ArrayRef<Function *> empty_list_value_builders)
: m_main(main),
m_input_is_list(input_is_list),
m_empty_list_value_builders(empty_list_value_builders)
{
- BLI_assert(main->has_body<LLVMBuildIRBody>());
+ BLI_assert(main.has_body<LLVMBuildIRBody>());
BLI_assert(input_is_list.contains(true));
- for (uint i = 0; i < main->input_amount(); i++) {
- Type *base_type = main->input_type(i);
+ for (uint i = 0; i < main.input_amount(); i++) {
+ Type *base_type = main.input_type(i);
Type *list_type = get_list_type(base_type);
InputInfo info;
info.is_list = input_is_list[i];
@@ -62,7 +62,7 @@ class AutoVectorizationGen : public LLVMBuildIRBody {
info.list_llvm_type = &list_type->extension<LLVMTypeInfo>();
m_input_info.append(info);
}
- for (auto &base_type : main->output_types()) {
+ for (auto &base_type : main.output_types()) {
OutputInfo info;
info.base_cpp_type = &base_type->extension<CPPTypeInfo>();
info.base_llvm_type = &base_type->extension<LLVMTypeInfo>();
@@ -91,7 +91,7 @@ class AutoVectorizationGen : public LLVMBuildIRBody {
Vector<llvm::Value *> main_outputs(m_output_info.size());
CodeInterface main_interface(
main_inputs, main_outputs, interface.context_ptr(), interface.function_ir_cache());
- auto &body = m_main->body<LLVMBuildIRBody>();
+ auto &body = m_main.body<LLVMBuildIRBody>();
body.build_ir(body_builder, main_interface, settings);
this->store_computed_values_in_output_lists(
@@ -160,7 +160,7 @@ class AutoVectorizationGen : public LLVMBuildIRBody {
Vector<llvm::Value *> data_pointers;
for (uint i = 0; i < m_output_info.size(); i++) {
uint stride = m_output_info[i].base_cpp_type->size();
- Type *output_type = m_main->output_type(i);
+ Type *output_type = m_main.output_type(i);
llvm::Value *output_list = builder.CreateCallPointer(
(void *)callback__new_list,
@@ -212,8 +212,8 @@ class AutoVectorizationGen : public LLVMBuildIRBody {
CodeBuilder &else_builder = ifthenelse.else_builder();
/* Use default value when list has no elements. */
- const SharedFunction &default_builder = m_empty_list_value_builders[list_input_index];
- auto &default_builder_body = default_builder->body<LLVMBuildIRBody>();
+ const Function &default_builder = *m_empty_list_value_builders[list_input_index];
+ auto &default_builder_body = default_builder.body<LLVMBuildIRBody>();
Vector<llvm::Value *> default_builder_inputs(0);
Vector<llvm::Value *> default_builder_outputs(1);
CodeInterface default_builder_interface(default_builder_inputs,
@@ -260,7 +260,7 @@ class AutoVectorizationGen : public LLVMBuildIRBody {
class AutoVectorization : public TupleCallBody {
private:
- SharedFunction m_main;
+ Function &m_main;
TupleCallBody &m_main_body;
const Vector<bool> m_input_is_list;
@@ -274,8 +274,8 @@ class AutoVectorization : public TupleCallBody {
Vector<TupleCallBody *> m_append_bodies;
public:
- AutoVectorization(SharedFunction main, const Vector<bool> &input_is_list)
- : m_main(main), m_main_body(main->body<TupleCallBody>()), m_input_is_list(input_is_list)
+ AutoVectorization(Function &main, const Vector<bool> &input_is_list)
+ : m_main(main), m_main_body(main.body<TupleCallBody>()), m_input_is_list(input_is_list)
{
for (uint i = 0; i < input_is_list.size(); i++) {
if (input_is_list[i]) {
@@ -283,9 +283,9 @@ class AutoVectorization : public TupleCallBody {
}
}
for (uint i : m_list_inputs) {
- Type *base_type = main->input_type(i);
- m_get_length_bodies.append(&GET_FN_list_length(base_type)->body<TupleCallBody>());
- m_get_element_bodies.append(&GET_FN_get_list_element(base_type)->body<TupleCallBody>());
+ Type *base_type = main.input_type(i);
+ m_get_length_bodies.append(&GET_FN_list_length(base_type).body<TupleCallBody>());
+ m_get_element_bodies.append(&GET_FN_get_list_element(base_type).body<TupleCallBody>());
}
m_max_len_in_size = 0;
@@ -295,9 +295,9 @@ class AutoVectorization : public TupleCallBody {
m_max_len_out_size = std::max(m_max_len_out_size, body->meta_out().size_of_full_tuple());
}
- for (auto base_type : main->output_types()) {
- m_create_empty_bodies.append(&GET_FN_empty_list(base_type)->body<TupleCallBody>());
- m_append_bodies.append(&GET_FN_append_to_list(base_type)->body<TupleCallBody>());
+ for (auto base_type : main.output_types()) {
+ m_create_empty_bodies.append(&GET_FN_empty_list(base_type).body<TupleCallBody>());
+ m_append_bodies.append(&GET_FN_append_to_list(base_type).body<TupleCallBody>());
}
}
@@ -312,7 +312,7 @@ class AutoVectorization : public TupleCallBody {
FN_TUPLE_CALL_ALLOC_TUPLES(m_main_body, main_in, main_out);
IterationStackFrame iteration_frame;
- TextStackFrame function_name_frame(m_main->name().data());
+ TextStackFrame function_name_frame(m_main.name().data());
ctx.stack().push(&iteration_frame);
ctx.stack().push(&function_name_frame);
@@ -332,7 +332,7 @@ class AutoVectorization : public TupleCallBody {
iteration_frame.m_iteration = iteration;
m_main_body.call(main_in, main_out, ctx);
- for (uint i = 0; i < m_main->output_amount(); i++) {
+ for (uint i = 0; i < m_main.output_amount(); i++) {
this->append_to_output(main_out, fn_out, i, ctx);
}
}
@@ -390,7 +390,7 @@ class AutoVectorization : public TupleCallBody {
void initialize_empty_lists(Tuple &fn_out, ExecutionContext &ctx) const
{
- for (uint i = 0; i < m_main->output_amount(); i++) {
+ for (uint i = 0; i < m_main.output_amount(); i++) {
this->initialize_empty_list(fn_out, i, ctx);
}
}
@@ -416,23 +416,23 @@ class AutoVectorization : public TupleCallBody {
}
};
-static SharedFunction to_vectorized_function_internal(
- SharedFunction &original_fn,
+static std::unique_ptr<Function> to_vectorized_function_internal(
+ Function &original_fn,
ArrayRef<bool> &vectorized_inputs_mask,
- ArrayRef<SharedFunction> &empty_list_value_builders)
+ ArrayRef<Function *> &empty_list_value_builders)
{
- uint input_amount = original_fn->input_amount();
- uint output_amount = original_fn->output_amount();
+ uint input_amount = original_fn.input_amount();
+ uint output_amount = original_fn.output_amount();
BLI_assert(vectorized_inputs_mask.size() == input_amount);
BLI_assert(vectorized_inputs_mask.contains(true));
BLI_assert(empty_list_value_builders.size() == vectorized_inputs_mask.count(true));
- BLI_assert(original_fn->has_body<TupleCallBody>() || original_fn->has_body<LLVMBuildIRBody>());
+ BLI_assert(original_fn.has_body<TupleCallBody>() || original_fn.has_body<LLVMBuildIRBody>());
FunctionBuilder builder;
for (uint i = 0; i < input_amount; i++) {
- StringRef original_name = original_fn->input_name(i);
- Type *original_type = original_fn->input_type(i);
+ StringRef original_name = original_fn.input_name(i);
+ Type *original_type = original_fn.input_type(i);
if (vectorized_inputs_mask[i]) {
Type *list_type = get_list_type(original_type);
builder.add_input(original_name + " (List)", list_type);
@@ -443,15 +443,15 @@ static SharedFunction to_vectorized_function_internal(
}
for (uint i = 0; i < output_amount; i++) {
- StringRef original_name = original_fn->output_name(i);
- Type *original_type = original_fn->output_type(i);
+ StringRef original_name = original_fn.output_name(i);
+ Type *original_type = original_fn.output_type(i);
Type *list_type = get_list_type(original_type);
builder.add_output(original_name + " (List)", list_type);
}
- std::string name = original_fn->name() + " (Vectorized)";
+ std::string name = original_fn.name() + " (Vectorized)";
auto fn = builder.build(name);
- if (original_fn->has_body<LLVMBuildIRBody>()) {
+ if (original_fn.has_body<LLVMBuildIRBody>()) {
fn->add_body<AutoVectorizationGen>(
original_fn, vectorized_inputs_mask, empty_list_value_builders);
}
@@ -461,22 +461,14 @@ static SharedFunction to_vectorized_function_internal(
return fn;
}
-SharedFunction to_vectorized_function(SharedFunction &original_fn,
- ArrayRef<bool> vectorized_inputs_mask,
- ArrayRef<SharedFunction> empty_list_value_builders)
-{
- return to_vectorized_function_internal(
- original_fn, vectorized_inputs_mask, empty_list_value_builders);
-}
-
struct AutoVectorizationInput {
- SharedFunction m_original_fn;
+ Function &m_original_fn;
Vector<bool> m_vectorized_inputs_mask;
- Vector<SharedFunction> m_empty_list_value_builders;
+ Vector<Function *> m_empty_list_value_builders;
- AutoVectorizationInput(SharedFunction &original_fn,
+ AutoVectorizationInput(Function &original_fn,
ArrayRef<bool> vectorized_inputs_mask,
- ArrayRef<SharedFunction> empty_list_value_builders)
+ ArrayRef<Function *> empty_list_value_builders)
: m_original_fn(original_fn),
m_vectorized_inputs_mask(vectorized_inputs_mask),
m_empty_list_value_builders(empty_list_value_builders)
@@ -487,30 +479,39 @@ struct AutoVectorizationInput {
{
return (a.m_original_fn == b.m_original_fn &&
Vector<bool>::all_equal(a.m_vectorized_inputs_mask, b.m_vectorized_inputs_mask) &&
- Vector<SharedFunction>::all_equal(a.m_empty_list_value_builders,
- b.m_empty_list_value_builders));
+ Vector<Function *>::all_equal(a.m_empty_list_value_builders,
+ b.m_empty_list_value_builders));
}
};
-using VectorizeCacheMap = Map<AutoVectorizationInput, SharedFunction>;
+using VectorizeCacheMap = Map<AutoVectorizationInput, std::unique_ptr<Function>>;
BLI_LAZY_INIT_STATIC(VectorizeCacheMap, get_vectorized_function_cache)
{
return VectorizeCacheMap{};
}
-SharedFunction to_vectorized_function__with_cache(
- SharedFunction &original_fn,
- ArrayRef<bool> vectorized_inputs_mask,
- ArrayRef<SharedFunction> empty_list_value_builders)
+Function &to_vectorized_function__with_cache(Function &original_fn,
+ ArrayRef<bool> vectorized_inputs_mask,
+ ArrayRef<Function *> empty_list_value_builders)
{
static VectorizeCacheMap &cache = get_vectorized_function_cache();
AutoVectorizationInput cache_key(original_fn, vectorized_inputs_mask, empty_list_value_builders);
- return cache.lookup_or_add(cache_key, [&]() {
+
+ std::unique_ptr<Function> &vectorized_function = cache.lookup_or_add(cache_key, [&]() {
return to_vectorized_function_internal(
original_fn, vectorized_inputs_mask, empty_list_value_builders);
});
+ return *vectorized_function;
+}
+
+std::unique_ptr<Function> to_vectorized_function__without_cache(
+ Function &fn,
+ ArrayRef<bool> vectorized_inputs_mask,
+ ArrayRef<Function *> empty_list_value_builders)
+{
+ return to_vectorized_function_internal(fn, vectorized_inputs_mask, empty_list_value_builders);
}
} // namespace Functions
@@ -521,7 +522,7 @@ template<> struct DefaultHash<FN::Functions::AutoVectorizationInput> {
uint32_t operator()(const FN::Functions::AutoVectorizationInput &value) const
{
/* TODO: take other struct fields into account. */
- void *ptr = (void *)value.m_original_fn.ptr();
+ void *ptr = (void *)&value.m_original_fn;
return DefaultHash<void *>{}(ptr);
}
};
diff --git a/source/blender/functions/functions/auto_vectorization.hpp b/source/blender/functions/functions/auto_vectorization.hpp
index 72ba2e9cebb..dc7ec3c0385 100644
--- a/source/blender/functions/functions/auto_vectorization.hpp
+++ b/source/blender/functions/functions/auto_vectorization.hpp
@@ -5,14 +5,14 @@
namespace FN {
namespace Functions {
-SharedFunction to_vectorized_function(SharedFunction &fn,
- ArrayRef<bool> vectorized_inputs_mask,
- ArrayRef<SharedFunction> empty_list_value_builders);
+Function &to_vectorized_function__with_cache(Function &fn,
+ ArrayRef<bool> vectorized_inputs_mask,
+ ArrayRef<Function *> empty_list_value_builders);
-SharedFunction to_vectorized_function__with_cache(
- SharedFunction &fn,
+std::unique_ptr<Function> to_vectorized_function__without_cache(
+ Function &fn,
ArrayRef<bool> vectorized_inputs_mask,
- ArrayRef<SharedFunction> empty_list_value_builders);
+ ArrayRef<Function *> empty_list_value_builders);
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/boolean.cpp b/source/blender/functions/functions/boolean.cpp
index d1c09289a96..6dc155f504a 100644
--- a/source/blender/functions/functions/boolean.cpp
+++ b/source/blender/functions/functions/boolean.cpp
@@ -10,7 +10,7 @@ namespace Functions {
using namespace Types;
-static SharedFunction get_boolean_function__one_input(StringRef name)
+static std::unique_ptr<Function> get_boolean_function__one_input(StringRef name)
{
FunctionBuilder builder;
builder.add_input("Value", TYPE_bool);
@@ -18,7 +18,7 @@ static SharedFunction get_boolean_function__one_input(StringRef name)
return builder.build(name);
}
-static SharedFunction get_boolean_function__two_inputs(StringRef name)
+static std::unique_ptr<Function> get_boolean_function__two_inputs(StringRef name)
{
FunctionBuilder builder;
builder.add_input("A", TYPE_bool);
@@ -37,7 +37,7 @@ class AndBoolean : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_and)
+BLI_LAZY_INIT_REF(Function, GET_FN_and)
{
auto fn = get_boolean_function__two_inputs("And");
fn->add_body<AndBoolean>();
@@ -54,7 +54,7 @@ class OrBoolean : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_or)
+BLI_LAZY_INIT_REF(Function, GET_FN_or)
{
auto fn = get_boolean_function__two_inputs("Or");
fn->add_body<OrBoolean>();
@@ -70,7 +70,7 @@ class NotBoolean : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_not)
+BLI_LAZY_INIT_REF(Function, GET_FN_not)
{
auto fn = get_boolean_function__one_input("Not");
fn->add_body<NotBoolean>();
diff --git a/source/blender/functions/functions/boolean.hpp b/source/blender/functions/functions/boolean.hpp
index c75d189ebf2..ec701014f06 100644
--- a/source/blender/functions/functions/boolean.hpp
+++ b/source/blender/functions/functions/boolean.hpp
@@ -5,9 +5,9 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_and();
-SharedFunction &GET_FN_or();
-SharedFunction &GET_FN_not();
+Function &GET_FN_and();
+Function &GET_FN_or();
+Function &GET_FN_not();
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/color.cpp b/source/blender/functions/functions/color.cpp
index 4d9eec42c69..e8b4ea2dff2 100644
--- a/source/blender/functions/functions/color.cpp
+++ b/source/blender/functions/functions/color.cpp
@@ -22,7 +22,7 @@ class SeparateColor : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_separate_color)
+BLI_LAZY_INIT_REF(Function, GET_FN_separate_color)
{
FunctionBuilder fn_builder;
fn_builder.add_input("Color", TYPE_rgba_f);
@@ -50,7 +50,7 @@ class CombineColor : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_combine_color)
+BLI_LAZY_INIT_REF(Function, GET_FN_combine_color)
{
FunctionBuilder fn_builder;
fn_builder.add_input("Red", TYPE_float);
diff --git a/source/blender/functions/functions/color.hpp b/source/blender/functions/functions/color.hpp
index 424b4b9bf63..6a74966ab9a 100644
--- a/source/blender/functions/functions/color.hpp
+++ b/source/blender/functions/functions/color.hpp
@@ -5,8 +5,8 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_separate_color();
-SharedFunction &GET_FN_combine_color();
+Function &GET_FN_separate_color();
+Function &GET_FN_combine_color();
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/comparisons.cpp b/source/blender/functions/functions/comparisons.cpp
index a56b90bd78e..8747a9269e8 100644
--- a/source/blender/functions/functions/comparisons.cpp
+++ b/source/blender/functions/functions/comparisons.cpp
@@ -19,7 +19,7 @@ template<typename T> class LessThan : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_less_than_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_less_than_float)
{
FunctionBuilder builder;
builder.add_input("A", TYPE_float);
@@ -31,7 +31,7 @@ BLI_LAZY_INIT(SharedFunction, GET_FN_less_than_float)
return fn;
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_less_than_int32)
+BLI_LAZY_INIT_REF(Function, GET_FN_less_than_int32)
{
FunctionBuilder builder;
builder.add_input("A", TYPE_int32);
diff --git a/source/blender/functions/functions/comparisons.hpp b/source/blender/functions/functions/comparisons.hpp
index a97cd1ce62b..78d6f8893d1 100644
--- a/source/blender/functions/functions/comparisons.hpp
+++ b/source/blender/functions/functions/comparisons.hpp
@@ -5,8 +5,8 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_less_than_float();
-SharedFunction &GET_FN_less_than_int32();
+Function &GET_FN_less_than_float();
+Function &GET_FN_less_than_int32();
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/constants.cpp b/source/blender/functions/functions/constants.cpp
index 7c226fc2acb..d050c9aa314 100644
--- a/source/blender/functions/functions/constants.cpp
+++ b/source/blender/functions/functions/constants.cpp
@@ -79,7 +79,7 @@ class ConstBoolGen : public LLVMBuildIRBody {
}
};
-static SharedFunction get_output_int32_function(int32_t value)
+static std::unique_ptr<Function> get_output_int32_function(int32_t value)
{
FunctionBuilder builder;
builder.add_output("Value", TYPE_int32);
@@ -89,17 +89,17 @@ static SharedFunction get_output_int32_function(int32_t value)
return fn;
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_int32_0)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_int32_0)
{
return get_output_int32_function(0);
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_int32_1)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_int32_1)
{
return get_output_int32_function(1);
}
-static SharedFunction get_output_float_function(float value)
+static std::unique_ptr<Function> get_output_float_function(float value)
{
FunctionBuilder builder;
builder.add_output("Value", TYPE_float);
@@ -109,17 +109,17 @@ static SharedFunction get_output_float_function(float value)
return fn;
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_float_0)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_float_0)
{
return get_output_float_function(0.0f);
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_float_1)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_float_1)
{
return get_output_float_function(1.0f);
}
-static SharedFunction get_output_bool_function(bool value)
+static std::unique_ptr<Function> get_output_bool_function(bool value)
{
FunctionBuilder builder;
builder.add_output("Value", TYPE_bool);
@@ -129,12 +129,12 @@ static SharedFunction get_output_bool_function(bool value)
return fn;
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_false)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_false)
{
return get_output_bool_function(false);
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_true)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_true)
{
return get_output_bool_function(true);
}
@@ -162,7 +162,7 @@ template<uint N> class ConstFloatArrayGen : public LLVMBuildIRBody {
}
};
-static SharedFunction get_output_float3_function(float3 vector)
+static std::unique_ptr<Function> get_output_float3_function(float3 vector)
{
FunctionBuilder builder;
auto &float3_type = TYPE_float3;
@@ -173,17 +173,17 @@ static SharedFunction get_output_float3_function(float3 vector)
return fn;
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_float3_0)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_float3_0)
{
return get_output_float3_function(float3(0, 0, 0));
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_float3_1)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_float3_1)
{
return get_output_float3_function(float3(1, 1, 1));
}
-static SharedFunction get_output_rgba_f_function(rgba_f color)
+static std::unique_ptr<Function> get_output_rgba_f_function(rgba_f color)
{
FunctionBuilder builder;
auto &rgba_f_type = TYPE_rgba_f;
@@ -194,12 +194,12 @@ static SharedFunction get_output_rgba_f_function(rgba_f color)
return fn;
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_output_magenta)
+BLI_LAZY_INIT_REF(Function, GET_FN_output_magenta)
{
return get_output_rgba_f_function(rgba_f(1, 0, 1, 1));
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_none)
+BLI_LAZY_INIT_REF(Function, GET_FN_none)
{
FunctionBuilder builder;
auto fn = builder.build("None");
diff --git a/source/blender/functions/functions/constants.hpp b/source/blender/functions/functions/constants.hpp
index e7710597aa7..ab34257dcae 100644
--- a/source/blender/functions/functions/constants.hpp
+++ b/source/blender/functions/functions/constants.hpp
@@ -5,21 +5,21 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_output_int32_0();
-SharedFunction &GET_FN_output_int32_1();
+Function &GET_FN_output_int32_0();
+Function &GET_FN_output_int32_1();
-SharedFunction &GET_FN_output_float_0();
-SharedFunction &GET_FN_output_float_1();
+Function &GET_FN_output_float_0();
+Function &GET_FN_output_float_1();
-SharedFunction &GET_FN_output_false();
-SharedFunction &GET_FN_output_true();
+Function &GET_FN_output_false();
+Function &GET_FN_output_true();
-SharedFunction &GET_FN_output_float3_0();
-SharedFunction &GET_FN_output_float3_1();
+Function &GET_FN_output_float3_0();
+Function &GET_FN_output_float3_1();
-SharedFunction &GET_FN_output_magenta();
+Function &GET_FN_output_magenta();
-SharedFunction &GET_FN_none();
+Function &GET_FN_none();
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/lists.cpp b/source/blender/functions/functions/lists.cpp
index ebcffd953cc..2ab811d441c 100644
--- a/source/blender/functions/functions/lists.cpp
+++ b/source/blender/functions/functions/lists.cpp
@@ -26,7 +26,7 @@ class CreateEmptyList : public TupleCallBody {
}
};
-static SharedFunction build_create_empty_list_function(Type *base_type, Type *list_type)
+static std::unique_ptr<Function> build_create_empty_list_function(Type *base_type, Type *list_type)
{
FunctionBuilder builder;
builder.add_output("List", list_type);
@@ -61,7 +61,8 @@ class CreateSingleElementListDependencies : public DepsBody {
}
};
-static SharedFunction build_create_single_element_list_function(Type *base_type, Type *list_type)
+static std::unique_ptr<Function> build_create_single_element_list_function(Type *base_type,
+ Type *list_type)
{
FunctionBuilder builder;
builder.add_input("Value", base_type);
@@ -102,7 +103,7 @@ class AppendToListDependencies : public DepsBody {
}
};
-static SharedFunction build_append_function(Type *base_type, Type *list_type)
+static std::unique_ptr<Function> build_append_function(Type *base_type, Type *list_type)
{
FunctionBuilder builder;
builder.add_input("List", list_type);
@@ -149,7 +150,7 @@ class GetListElementDependencies : public DepsBody {
}
};
-static SharedFunction build_get_element_function(Type *base_type, Type *list_type)
+static std::unique_ptr<Function> build_get_element_function(Type *base_type, Type *list_type)
{
FunctionBuilder builder;
builder.add_input("List", list_type);
@@ -195,7 +196,7 @@ class CombineListsDependencies : public DepsBody {
}
};
-static SharedFunction build_combine_lists_function(Type *base_type, Type *list_type)
+static std::unique_ptr<Function> build_combine_lists_function(Type *base_type, Type *list_type)
{
FunctionBuilder builder;
builder.add_input("List 1", list_type);
@@ -220,7 +221,7 @@ class ListLength : public TupleCallBody {
}
};
-static SharedFunction build_list_length_function(Type *base_type, Type *list_type)
+static std::unique_ptr<Function> build_list_length_function(Type *base_type, Type *list_type)
{
FunctionBuilder builder;
builder.add_input("List", list_type);
@@ -235,7 +236,7 @@ static SharedFunction build_list_length_function(Type *base_type, Type *list_typ
/* Build List Functions
*************************************/
-using FunctionPerType = Map<Type *, SharedFunction>;
+using FunctionPerType = Map<Type *, std::unique_ptr<Function>>;
struct ListFunctions {
FunctionPerType m_create_empty;
@@ -275,52 +276,52 @@ BLI_LAZY_INIT_STATIC(ListFunctions, get_list_functions)
/* Access List Functions
*************************************/
-SharedFunction &GET_FN_empty_list(Type *base_type)
+Function &GET_FN_empty_list(Type *base_type)
{
FunctionPerType &functions = get_list_functions().m_create_empty;
BLI_assert(functions.contains(base_type));
- return functions.lookup(base_type);
+ return *functions.lookup(base_type);
}
-SharedFunction &GET_FN_list_from_element(Type *base_type)
+Function &GET_FN_list_from_element(Type *base_type)
{
FunctionPerType &functions = get_list_functions().m_from_element;
BLI_assert(functions.contains(base_type));
- return functions.lookup(base_type);
+ return *functions.lookup(base_type);
}
-SharedFunction &GET_FN_append_to_list(Type *base_type)
+Function &GET_FN_append_to_list(Type *base_type)
{
FunctionPerType &functions = get_list_functions().m_append;
BLI_assert(functions.contains(base_type));
- return functions.lookup(base_type);
+ return *functions.lookup(base_type);
}
-SharedFunction &GET_FN_get_list_element(Type *base_type)
+Function &GET_FN_get_list_element(Type *base_type)
{
FunctionPerType &functions = get_list_functions().m_get_element;
BLI_assert(functions.contains(base_type));
- return functions.lookup(base_type);
+ return *functions.lookup(base_type);
}
-SharedFunction &GET_FN_combine_lists(Type *base_type)
+Function &GET_FN_combine_lists(Type *base_type)
{
FunctionPerType &functions = get_list_functions().m_combine;
BLI_assert(functions.contains(base_type));
- return functions.lookup(base_type);
+ return *functions.lookup(base_type);
}
-SharedFunction &GET_FN_list_length(Type *base_type)
+Function &GET_FN_list_length(Type *base_type)
{
FunctionPerType &functions = get_list_functions().m_length;
BLI_assert(functions.contains(base_type));
- return functions.lookup(base_type);
+ return *functions.lookup(base_type);
}
Type *get_list_type(Type *base_type)
{
- SharedFunction &fn = GET_FN_append_to_list(base_type);
- return fn->input_type(0);
+ Function &fn = GET_FN_append_to_list(base_type);
+ return fn.input_type(0);
}
} // namespace Functions
diff --git a/source/blender/functions/functions/lists.hpp b/source/blender/functions/functions/lists.hpp
index d4623ae94a0..5fad8fae2a0 100644
--- a/source/blender/functions/functions/lists.hpp
+++ b/source/blender/functions/functions/lists.hpp
@@ -8,12 +8,12 @@ namespace Functions {
Type *get_list_type(Type *base_type);
-SharedFunction &GET_FN_empty_list(Type *base_type);
-SharedFunction &GET_FN_list_from_element(Type *base_type);
-SharedFunction &GET_FN_append_to_list(Type *base_type);
-SharedFunction &GET_FN_get_list_element(Type *base_type);
-SharedFunction &GET_FN_combine_lists(Type *base_type);
-SharedFunction &GET_FN_list_length(Type *base_type);
+Function &GET_FN_empty_list(Type *base_type);
+Function &GET_FN_list_from_element(Type *base_type);
+Function &GET_FN_append_to_list(Type *base_type);
+Function &GET_FN_get_list_element(Type *base_type);
+Function &GET_FN_combine_lists(Type *base_type);
+Function &GET_FN_list_length(Type *base_type);
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/object_input.cpp b/source/blender/functions/functions/object_input.cpp
index ad3269d2f04..d2f1874b260 100644
--- a/source/blender/functions/functions/object_input.cpp
+++ b/source/blender/functions/functions/object_input.cpp
@@ -35,7 +35,7 @@ class ObjectLocationDeps : public DepsBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_object_location)
+BLI_LAZY_INIT_REF(Function, GET_FN_object_location)
{
FunctionBuilder builder;
builder.add_input("Object", TYPE_object);
@@ -81,7 +81,7 @@ class ObjectMeshDeps : public DepsBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_object_mesh_vertices)
+BLI_LAZY_INIT_REF(Function, GET_FN_object_mesh_vertices)
{
FunctionBuilder builder;
builder.add_input("Object", TYPE_object);
diff --git a/source/blender/functions/functions/object_input.hpp b/source/blender/functions/functions/object_input.hpp
index 013b37f277b..0e5a08b37b0 100644
--- a/source/blender/functions/functions/object_input.hpp
+++ b/source/blender/functions/functions/object_input.hpp
@@ -5,8 +5,8 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_object_location();
-SharedFunction &GET_FN_object_mesh_vertices();
+Function &GET_FN_object_location();
+Function &GET_FN_object_mesh_vertices();
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/random.cpp b/source/blender/functions/functions/random.cpp
index e8a05fec4ae..6328e5a811a 100644
--- a/source/blender/functions/functions/random.cpp
+++ b/source/blender/functions/functions/random.cpp
@@ -36,7 +36,7 @@ class RandomNumber : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_random_number)
+BLI_LAZY_INIT_REF(Function, GET_FN_random_number)
{
FunctionBuilder builder;
builder.add_input("Seed", TYPE_float);
diff --git a/source/blender/functions/functions/random.hpp b/source/blender/functions/functions/random.hpp
index e8f9863dd39..d0c37b2f193 100644
--- a/source/blender/functions/functions/random.hpp
+++ b/source/blender/functions/functions/random.hpp
@@ -5,6 +5,6 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_random_number();
+Function &GET_FN_random_number();
}
} // namespace FN
diff --git a/source/blender/functions/functions/ranges.cpp b/source/blender/functions/functions/ranges.cpp
index 05abf6f6ab7..efbc19d09d3 100644
--- a/source/blender/functions/functions/ranges.cpp
+++ b/source/blender/functions/functions/ranges.cpp
@@ -37,7 +37,7 @@ class FloatRange : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_float_range)
+BLI_LAZY_INIT_REF(Function, GET_FN_float_range)
{
FunctionBuilder builder;
builder.add_input("Amount", TYPE_int32);
diff --git a/source/blender/functions/functions/ranges.hpp b/source/blender/functions/functions/ranges.hpp
index e6b549a1654..3517ca99ea8 100644
--- a/source/blender/functions/functions/ranges.hpp
+++ b/source/blender/functions/functions/ranges.hpp
@@ -5,6 +5,6 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_float_range();
+Function &GET_FN_float_range();
}
} // namespace FN
diff --git a/source/blender/functions/functions/scalar_math.cpp b/source/blender/functions/functions/scalar_math.cpp
index 22dc7854f1c..eb2af7917cb 100644
--- a/source/blender/functions/functions/scalar_math.cpp
+++ b/source/blender/functions/functions/scalar_math.cpp
@@ -12,7 +12,7 @@ namespace Functions {
using namespace Types;
-static SharedFunction get_math_function__one_input(std::string name)
+static std::unique_ptr<Function> get_math_function__one_input(std::string name)
{
FunctionBuilder builder;
builder.add_input("Value", TYPE_float);
@@ -20,7 +20,7 @@ static SharedFunction get_math_function__one_input(std::string name)
return builder.build(name);
}
-static SharedFunction get_math_function__two_inputs(std::string name)
+static std::unique_ptr<Function> get_math_function__two_inputs(std::string name)
{
FunctionBuilder builder;
builder.add_input("A", TYPE_float);
@@ -48,7 +48,7 @@ class AddFloatsGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_add_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_add_floats)
{
auto fn = get_math_function__two_inputs("Add Floats");
fn->add_body<AddFloats>();
@@ -75,7 +75,7 @@ class SubFloatsGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_sub_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_sub_floats)
{
auto fn = get_math_function__two_inputs("Sub Floats");
fn->add_body<SubFloats>();
@@ -102,7 +102,7 @@ class MultiplyFloatsGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_multiply_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_multiply_floats)
{
auto fn = get_math_function__two_inputs("Multiply Floats");
fn->add_body<MultiplyFloats>();
@@ -126,7 +126,7 @@ class DivideFloats : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_divide_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_divide_floats)
{
auto fn = get_math_function__two_inputs("Divide Floats");
fn->add_body<DivideFloats>();
@@ -147,7 +147,7 @@ class PowerFloats : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_power_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_power_floats)
{
auto fn = get_math_function__two_inputs("Power Floats");
fn->add_body<PowerFloats>();
@@ -167,7 +167,7 @@ class LogarithmFloats : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_log_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_log_floats)
{
auto fn = get_math_function__two_inputs("Logarithm");
fn->add_body<LogarithmFloats>();
@@ -182,7 +182,7 @@ class SqrtFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_sqrt_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_sqrt_float)
{
auto fn = get_math_function__one_input("Square Root");
fn->add_body<SqrtFloat>();
@@ -197,7 +197,7 @@ class AbsFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_abs_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_abs_float)
{
auto fn = get_math_function__one_input("Absolute Float");
fn->add_body<AbsFloat>();
@@ -213,7 +213,7 @@ class MinFloats : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_min_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_min_floats)
{
auto fn = get_math_function__two_inputs("Minimum");
fn->add_body<MinFloats>();
@@ -229,7 +229,7 @@ class MaxFloats : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_max_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_max_floats)
{
auto fn = get_math_function__two_inputs("Maximum");
fn->add_body<MaxFloats>();
@@ -254,7 +254,7 @@ class SinFloatGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_sin_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_sin_float)
{
auto fn = get_math_function__one_input("Sin");
fn->add_body<SinFloat>();
@@ -280,7 +280,7 @@ class CosFloatGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_cos_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_cos_float)
{
auto fn = get_math_function__one_input("Cos");
fn->add_body<CosFloat>();
@@ -300,7 +300,7 @@ class TanFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_tan_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_tan_float)
{
auto fn = get_math_function__one_input("Tan");
fn->add_body<TanFloat>();
@@ -315,7 +315,7 @@ class ArcsineFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_asin_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_asin_float)
{
auto fn = get_math_function__one_input("Arcsine");
fn->add_body<ArcsineFloat>();
@@ -330,7 +330,7 @@ class ArccosineFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_acos_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_acos_float)
{
auto fn = get_math_function__one_input("Arccosine");
fn->add_body<ArccosineFloat>();
@@ -345,7 +345,7 @@ class ArctangentFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_atan_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_atan_float)
{
auto fn = get_math_function__one_input("Arctangent");
fn->add_body<ArctangentFloat>();
@@ -361,7 +361,7 @@ class Arctangent2Floats : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_atan2_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_atan2_floats)
{
auto fn = get_math_function__two_inputs("Arctangent2");
fn->add_body<Arctangent2Floats>();
@@ -381,7 +381,7 @@ class ModuloFloats : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_mod_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_mod_floats)
{
auto fn = get_math_function__two_inputs("Modulo Floats");
fn->add_body<ModuloFloats>();
@@ -397,7 +397,7 @@ class FractFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_fract_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_fract_float)
{
auto fn = get_math_function__one_input("Fract Float");
fn->add_body<FractFloat>();
@@ -412,7 +412,7 @@ class CeilFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_ceil_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_ceil_float)
{
auto fn = get_math_function__one_input("Ceil Float");
fn->add_body<CeilFloat>();
@@ -427,7 +427,7 @@ class FloorFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_floor_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_floor_float)
{
auto fn = get_math_function__one_input("Floor Float");
fn->add_body<FloorFloat>();
@@ -442,7 +442,7 @@ class RoundFloat : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_round_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_round_float)
{
auto fn = get_math_function__one_input("Round Float");
fn->add_body<RoundFloat>();
@@ -464,7 +464,7 @@ class SnapFloats : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_snap_floats)
+BLI_LAZY_INIT_REF(Function, GET_FN_snap_floats)
{
auto fn = get_math_function__two_inputs("Snap Floats");
fn->add_body<SnapFloats>();
@@ -497,7 +497,7 @@ class MapRange : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_map_range)
+BLI_LAZY_INIT_REF(Function, GET_FN_map_range)
{
FunctionBuilder builder;
builder.add_input("Value", TYPE_float);
diff --git a/source/blender/functions/functions/scalar_math.hpp b/source/blender/functions/functions/scalar_math.hpp
index a8e0e12d496..202d64f7d32 100644
--- a/source/blender/functions/functions/scalar_math.hpp
+++ b/source/blender/functions/functions/scalar_math.hpp
@@ -5,35 +5,35 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_add_floats();
-SharedFunction &GET_FN_sub_floats();
-SharedFunction &GET_FN_multiply_floats();
-SharedFunction &GET_FN_divide_floats();
-
-SharedFunction &GET_FN_power_floats();
-SharedFunction &GET_FN_log_floats();
-SharedFunction &GET_FN_sqrt_float();
-
-SharedFunction &GET_FN_abs_float();
-SharedFunction &GET_FN_min_floats();
-SharedFunction &GET_FN_max_floats();
-SharedFunction &GET_FN_mod_floats();
-
-SharedFunction &GET_FN_sin_float();
-SharedFunction &GET_FN_cos_float();
-SharedFunction &GET_FN_tan_float();
-SharedFunction &GET_FN_asin_float();
-SharedFunction &GET_FN_acos_float();
-SharedFunction &GET_FN_atan_float();
-SharedFunction &GET_FN_atan2_floats();
-
-SharedFunction &GET_FN_fract_float();
-SharedFunction &GET_FN_ceil_float();
-SharedFunction &GET_FN_floor_float();
-SharedFunction &GET_FN_round_float();
-SharedFunction &GET_FN_snap_floats();
-
-SharedFunction &GET_FN_map_range();
+Function &GET_FN_add_floats();
+Function &GET_FN_sub_floats();
+Function &GET_FN_multiply_floats();
+Function &GET_FN_divide_floats();
+
+Function &GET_FN_power_floats();
+Function &GET_FN_log_floats();
+Function &GET_FN_sqrt_float();
+
+Function &GET_FN_abs_float();
+Function &GET_FN_min_floats();
+Function &GET_FN_max_floats();
+Function &GET_FN_mod_floats();
+
+Function &GET_FN_sin_float();
+Function &GET_FN_cos_float();
+Function &GET_FN_tan_float();
+Function &GET_FN_asin_float();
+Function &GET_FN_acos_float();
+Function &GET_FN_atan_float();
+Function &GET_FN_atan2_floats();
+
+Function &GET_FN_fract_float();
+Function &GET_FN_ceil_float();
+Function &GET_FN_floor_float();
+Function &GET_FN_round_float();
+Function &GET_FN_snap_floats();
+
+Function &GET_FN_map_range();
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/simple_conversions.cpp b/source/blender/functions/functions/simple_conversions.cpp
index aaf00ccaad0..9ce8c450a3f 100644
--- a/source/blender/functions/functions/simple_conversions.cpp
+++ b/source/blender/functions/functions/simple_conversions.cpp
@@ -18,7 +18,7 @@ template<typename From, typename To> class ImplicitConversion : public TupleCall
}
};
-static SharedFunction get_simple_conversion_function(Type *from_type, Type *to_type)
+static std::unique_ptr<Function> get_simple_conversion_function(Type *from_type, Type *to_type)
{
FunctionBuilder builder;
builder.add_input("In", from_type);
@@ -28,7 +28,7 @@ static SharedFunction get_simple_conversion_function(Type *from_type, Type *to_t
}
template<typename From, typename To>
-static SharedFunction get_implicit_conversion_function(Type *from_type, Type *to_type)
+static std::unique_ptr<Function> get_implicit_conversion_function(Type *from_type, Type *to_type)
{
auto fn = get_simple_conversion_function(from_type, to_type);
fn->add_body<ImplicitConversion<From, To>>();
@@ -37,66 +37,72 @@ static SharedFunction get_implicit_conversion_function(Type *from_type, Type *to
/* Individual Element Conversion */
-BLI_LAZY_INIT(SharedFunction, GET_FN_bool_to_int32)
+BLI_LAZY_INIT_REF(Function, GET_FN_bool_to_int32)
{
return get_implicit_conversion_function<bool, int32_t>(TYPE_bool, TYPE_int32);
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_bool_to_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_bool_to_float)
{
return get_implicit_conversion_function<bool, float>(TYPE_bool, TYPE_float);
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_int32_to_float)
+BLI_LAZY_INIT_REF(Function, GET_FN_int32_to_float)
{
return get_implicit_conversion_function<int32_t, float>(TYPE_int32, TYPE_float);
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_int32_to_bool)
+BLI_LAZY_INIT_REF(Function, GET_FN_int32_to_bool)
{
return get_implicit_conversion_function<int32_t, bool>(TYPE_int32, TYPE_bool);
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_float_to_int32)
+BLI_LAZY_INIT_REF(Function, GET_FN_float_to_int32)
{
return get_implicit_conversion_function<float, int32_t>(TYPE_float, TYPE_int32);
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_float_to_bool)
+BLI_LAZY_INIT_REF(Function, GET_FN_float_to_bool)
{
return get_implicit_conversion_function<float, bool>(TYPE_float, TYPE_bool);
}
/* List Conversions */
-BLI_LAZY_INIT(SharedFunction, GET_FN_bool_list_to_int32_list)
+BLI_LAZY_INIT_REF(Function, GET_FN_bool_list_to_int32_list)
{
- return to_vectorized_function(GET_FN_bool_to_int32(), {true}, {GET_FN_output_false()});
+ return to_vectorized_function__without_cache(
+ GET_FN_bool_to_int32(), {true}, {&GET_FN_output_false()});
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_bool_list_to_float_list)
+BLI_LAZY_INIT_REF(Function, GET_FN_bool_list_to_float_list)
{
- return to_vectorized_function(GET_FN_bool_to_float(), {true}, {GET_FN_output_false()});
+ return to_vectorized_function__without_cache(
+ GET_FN_bool_to_float(), {true}, {&GET_FN_output_false()});
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_int32_list_to_float_list)
+BLI_LAZY_INIT_REF(Function, GET_FN_int32_list_to_float_list)
{
- return to_vectorized_function(GET_FN_int32_to_float(), {true}, {GET_FN_output_int32_0()});
+ return to_vectorized_function__without_cache(
+ GET_FN_int32_to_float(), {true}, {&GET_FN_output_int32_0()});
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_int32_list_to_bool_list)
+BLI_LAZY_INIT_REF(Function, GET_FN_int32_list_to_bool_list)
{
- return to_vectorized_function(GET_FN_int32_to_bool(), {true}, {GET_FN_output_int32_0()});
+ return to_vectorized_function__without_cache(
+ GET_FN_int32_to_bool(), {true}, {&GET_FN_output_int32_0()});
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_float_list_to_int32_list)
+BLI_LAZY_INIT_REF(Function, GET_FN_float_list_to_int32_list)
{
- return to_vectorized_function(GET_FN_float_to_int32(), {true}, {GET_FN_output_float_0()});
+ return to_vectorized_function__without_cache(
+ GET_FN_float_to_int32(), {true}, {&GET_FN_output_float_0()});
}
-BLI_LAZY_INIT(SharedFunction, GET_FN_float_list_to_bool_list)
+BLI_LAZY_INIT_REF(Function, GET_FN_float_list_to_bool_list)
{
- return to_vectorized_function(GET_FN_float_to_bool(), {true}, {GET_FN_output_float_0()});
+ return to_vectorized_function__without_cache(
+ GET_FN_float_to_bool(), {true}, {&GET_FN_output_float_0()});
}
} // namespace Functions
diff --git a/source/blender/functions/functions/simple_conversions.hpp b/source/blender/functions/functions/simple_conversions.hpp
index be2911f6684..1cc5aa671ce 100644
--- a/source/blender/functions/functions/simple_conversions.hpp
+++ b/source/blender/functions/functions/simple_conversions.hpp
@@ -5,19 +5,19 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_bool_to_int32();
-SharedFunction &GET_FN_bool_to_float();
-SharedFunction &GET_FN_int32_to_float();
-SharedFunction &GET_FN_int32_to_bool();
-SharedFunction &GET_FN_float_to_int32();
-SharedFunction &GET_FN_float_to_bool();
+Function &GET_FN_bool_to_int32();
+Function &GET_FN_bool_to_float();
+Function &GET_FN_int32_to_float();
+Function &GET_FN_int32_to_bool();
+Function &GET_FN_float_to_int32();
+Function &GET_FN_float_to_bool();
-SharedFunction &GET_FN_bool_list_to_int32_list();
-SharedFunction &GET_FN_bool_list_to_float_list();
-SharedFunction &GET_FN_int32_list_to_float_list();
-SharedFunction &GET_FN_int32_list_to_bool_list();
-SharedFunction &GET_FN_float_list_to_int32_list();
-SharedFunction &GET_FN_float_list_to_bool_list();
+Function &GET_FN_bool_list_to_int32_list();
+Function &GET_FN_bool_list_to_float_list();
+Function &GET_FN_int32_list_to_float_list();
+Function &GET_FN_int32_list_to_bool_list();
+Function &GET_FN_float_list_to_int32_list();
+Function &GET_FN_float_list_to_bool_list();
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/string.cpp b/source/blender/functions/functions/string.cpp
index 4891ed56e81..cb52ccd5c00 100644
--- a/source/blender/functions/functions/string.cpp
+++ b/source/blender/functions/functions/string.cpp
@@ -19,7 +19,7 @@ class StringLength : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_string_length)
+BLI_LAZY_INIT_REF(Function, GET_FN_string_length)
{
FunctionBuilder builder;
builder.add_input("String", TYPE_string);
diff --git a/source/blender/functions/functions/string.hpp b/source/blender/functions/functions/string.hpp
index 7bb58f0bb0b..ad7d92c2cbf 100644
--- a/source/blender/functions/functions/string.hpp
+++ b/source/blender/functions/functions/string.hpp
@@ -5,6 +5,6 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_string_length();
+Function &GET_FN_string_length();
}
} // namespace FN
diff --git a/source/blender/functions/functions/switch.cpp b/source/blender/functions/functions/switch.cpp
index 7d4477b0d7e..50422abdeeb 100644
--- a/source/blender/functions/functions/switch.cpp
+++ b/source/blender/functions/functions/switch.cpp
@@ -55,7 +55,7 @@ class LazyBoolSwitch : public LazyInTupleCallBody {
}
};
-static SharedFunction build_bool_switch_function(Type *data_type)
+static std::unique_ptr<Function> build_bool_switch_function(Type *data_type)
{
FunctionBuilder builder;
builder.add_input("Condition", TYPE_bool);
@@ -69,20 +69,16 @@ static SharedFunction build_bool_switch_function(Type *data_type)
return fn;
}
-using CacheMap = Map<Type *, SharedFunction>;
+using CacheMap = Map<Type *, std::unique_ptr<Function>>;
BLI_LAZY_INIT_STATIC(CacheMap, get_cache)
{
return {};
}
-SharedFunction &GET_FN_bool_switch(Type *data_type)
+Function &GET_FN_bool_switch(Type *data_type)
{
CacheMap &cache = get_cache();
- if (!cache.contains(data_type)) {
- SharedFunction fn = build_bool_switch_function(data_type);
- cache.add(data_type, fn);
- }
- return cache.lookup(data_type);
+ return *cache.lookup_or_add(data_type, [&]() { return build_bool_switch_function(data_type); });
}
} // namespace Functions
diff --git a/source/blender/functions/functions/switch.hpp b/source/blender/functions/functions/switch.hpp
index 1846a3c762c..f4908c6ac35 100644
--- a/source/blender/functions/functions/switch.hpp
+++ b/source/blender/functions/functions/switch.hpp
@@ -5,6 +5,6 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_bool_switch(Type *data_type);
+Function &GET_FN_bool_switch(Type *data_type);
}
} // namespace FN
diff --git a/source/blender/functions/functions/vectors.cpp b/source/blender/functions/functions/vectors.cpp
index babb59ce2d1..64f1b008313 100644
--- a/source/blender/functions/functions/vectors.cpp
+++ b/source/blender/functions/functions/vectors.cpp
@@ -26,7 +26,7 @@ class CombineVectorGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_combine_vector)
+BLI_LAZY_INIT_REF(Function, GET_FN_combine_vector)
{
FunctionBuilder builder;
builder.add_input("X", TYPE_float);
@@ -51,7 +51,7 @@ class SeparateVector : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_separate_vector)
+BLI_LAZY_INIT_REF(Function, GET_FN_separate_vector)
{
FunctionBuilder builder;
builder.add_input("Vector", TYPE_float3);
@@ -73,7 +73,7 @@ class VectorDistance : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_vector_distance)
+BLI_LAZY_INIT_REF(Function, GET_FN_vector_distance)
{
FunctionBuilder builder;
builder.add_input("A", TYPE_float3);
@@ -85,7 +85,7 @@ BLI_LAZY_INIT(SharedFunction, GET_FN_vector_distance)
return fn;
}
-static SharedFunction get_math_function__two_inputs(std::string name)
+static std::unique_ptr<Function> get_math_function__two_inputs(std::string name)
{
FunctionBuilder builder;
builder.add_input("A", TYPE_float3);
@@ -115,7 +115,7 @@ class AddVectorsGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_add_vectors)
+BLI_LAZY_INIT_REF(Function, GET_FN_add_vectors)
{
auto fn = get_math_function__two_inputs("Add Vectors");
fn->add_body<AddVectors>();
@@ -144,7 +144,7 @@ class SubVectorsGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_sub_vectors)
+BLI_LAZY_INIT_REF(Function, GET_FN_sub_vectors)
{
auto fn = get_math_function__two_inputs("Subtract Vectors");
fn->add_body<SubVectors>();
@@ -172,7 +172,7 @@ class MultiplyVectorsGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_mul_vectors)
+BLI_LAZY_INIT_REF(Function, GET_FN_mul_vectors)
{
auto fn = get_math_function__two_inputs("Multiply Vectors");
fn->add_body<MultiplyVectors>();
@@ -189,7 +189,7 @@ class DivideVectors : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_div_vectors)
+BLI_LAZY_INIT_REF(Function, GET_FN_div_vectors)
{
auto fn = get_math_function__two_inputs("Divide Vectors");
fn->add_body<DivideVectors>();
@@ -244,7 +244,7 @@ class CrossProductVectorsGen : public LLVMBuildIRBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_cross_vectors)
+BLI_LAZY_INIT_REF(Function, GET_FN_cross_vectors)
{
auto fn = get_math_function__two_inputs("Cross Product");
fn->add_body<CrossProductVectors>();
@@ -261,7 +261,7 @@ class ReflectVector : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_reflect_vector)
+BLI_LAZY_INIT_REF(Function, GET_FN_reflect_vector)
{
auto fn = get_math_function__two_inputs("Reflect Vector");
fn->add_body<ReflectVector>();
@@ -280,7 +280,7 @@ class ProjectVector : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_project_vector)
+BLI_LAZY_INIT_REF(Function, GET_FN_project_vector)
{
auto fn = get_math_function__two_inputs("Project Vector");
fn->add_body<ProjectVector>();
@@ -298,7 +298,7 @@ class VectorDotProduct : public TupleCallBody {
}
};
-BLI_LAZY_INIT(SharedFunction, GET_FN_dot_product)
+BLI_LAZY_INIT_REF(Function, GET_FN_dot_product)
{
FunctionBuilder builder;
builder.add_input("A", TYPE_float3);
diff --git a/source/blender/functions/functions/vectors.hpp b/source/blender/functions/functions/vectors.hpp
index fe7dae882de..3c47fdb111b 100644
--- a/source/blender/functions/functions/vectors.hpp
+++ b/source/blender/functions/functions/vectors.hpp
@@ -5,17 +5,17 @@
namespace FN {
namespace Functions {
-SharedFunction &GET_FN_combine_vector();
-SharedFunction &GET_FN_separate_vector();
-SharedFunction &GET_FN_vector_distance();
-SharedFunction &GET_FN_add_vectors();
-SharedFunction &GET_FN_sub_vectors();
-SharedFunction &GET_FN_mul_vectors();
-SharedFunction &GET_FN_div_vectors();
-SharedFunction &GET_FN_cross_vectors();
-SharedFunction &GET_FN_reflect_vector();
-SharedFunction &GET_FN_project_vector();
-SharedFunction &GET_FN_dot_product();
+Function &GET_FN_combine_vector();
+Function &GET_FN_separate_vector();
+Function &GET_FN_vector_distance();
+Function &GET_FN_add_vectors();
+Function &GET_FN_sub_vectors();
+Function &GET_FN_mul_vectors();
+Function &GET_FN_div_vectors();
+Function &GET_FN_cross_vectors();
+Function &GET_FN_reflect_vector();
+Function &GET_FN_project_vector();
+Function &GET_FN_dot_product();
} // namespace Functions
} // namespace FN
diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index 31f6674d39b..5f7f36a4fb4 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -13,7 +13,7 @@ namespace BParticles {
using BLI::TemporaryArray;
using BLI::TemporaryVector;
using FN::ExecutionContext;
-using FN::SharedFunction;
+using FN::Function;
using FN::Tuple;
using FN::TupleCallBody;
diff --git a/source/blender/simulations/bparticles/emitters.hpp b/source/blender/simulations/bparticles/emitters.hpp
index f10e48e1082..29749eaa66b 100644
--- a/source/blender/simulations/bparticles/emitters.hpp
+++ b/source/blender/simulations/bparticles/emitters.hpp
@@ -8,7 +8,7 @@
namespace BParticles {
-using FN::SharedFunction;
+using FN::Function;
using FN::TupleCallBody;
class SurfaceEmitter : public Emitter {
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp
index 973a2e12740..9533c7de5e7 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -15,7 +15,7 @@ void GravityForce::add_force(ForceInterface &interface)
auto inputs = m_inputs_fn->compute(interface);
for (uint pindex : interface.pindices()) {
- float3 acceleration = inputs->get<float3>("Direction", 0, pindex);
+ float3 acceleration = inputs->get<float3>("Acceleration", 0, pindex);
float weight = inputs->get<float>("Weight", 1, pindex);
destination[pindex] += acceleration * weight;
}
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 8e8976894be..016de9bf482 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -68,7 +68,7 @@ class VTreeData {
VTreeDataGraph &m_vtree_data_graph;
Vector<std::unique_ptr<ParticleFunction>> m_particle_functions;
- Vector<SharedFunction> m_functions;
+ Vector<std::unique_ptr<Function>> m_functions;
Vector<destruct_ptr<Tuple>> m_tuples;
Vector<destruct_ptr<FunctionOutputNamesProvider>> m_name_providers;
Vector<destruct_ptr<Vector<std::string>>> m_string_vectors;
@@ -238,9 +238,9 @@ class VTreeData {
FunctionGraph fgraph(m_vtree_data_graph.graph(), {}, sockets_to_compute);
auto fn = fgraph.new_function(vnode->name());
- FN::fgraph_add_TupleCallBody(fn, fgraph);
- m_functions.append(fn);
- return &fn->body<TupleCallBody>();
+ FN::fgraph_add_TupleCallBody(*fn, fgraph);
+ m_functions.append(std::move(fn));
+ return &m_functions.last()->body<TupleCallBody>();
}
Vector<VirtualSocket *> find_execute_sockets(VirtualNode *vnode, StringRef name_prefix)
diff --git a/source/blender/simulations/bparticles/particle_function.cpp b/source/blender/simulations/bparticles/particle_function.cpp
index e3a8f281694..c0520e329a7 100644
--- a/source/blender/simulations/bparticles/particle_function.cpp
+++ b/source/blender/simulations/bparticles/particle_function.cpp
@@ -9,8 +9,8 @@ ParticleFunctionInputProvider::~ParticleFunctionInputProvider()
{
}
-ParticleFunction::ParticleFunction(SharedFunction fn_no_deps,
- SharedFunction fn_with_deps,
+ParticleFunction::ParticleFunction(std::unique_ptr<Function> fn_no_deps,
+ std::unique_ptr<Function> fn_with_deps,
Vector<ParticleFunctionInputProvider *> input_providers,
Vector<bool> parameter_depends_on_particle)
: m_fn_no_deps(std::move(fn_no_deps)),
@@ -37,7 +37,7 @@ ParticleFunction::ParticleFunction(SharedFunction fn_no_deps,
if (m_fn_with_deps->output_amount() > 0) {
// m_array_execution = FN::Functions::get_precompiled_array_execution(m_fn_with_deps);
- m_array_execution = FN::Functions::get_tuple_call_array_execution(m_fn_with_deps);
+ m_array_execution = FN::Functions::get_tuple_call_array_execution(*m_fn_with_deps);
}
}
@@ -95,8 +95,8 @@ std::unique_ptr<ParticleFunctionResult> ParticleFunction::compute(ArrayRef<uint>
result->m_buffers.append_n_times(nullptr, parameter_amount);
result->m_only_first.append_n_times(false, parameter_amount);
result->m_strides.append_n_times(0, parameter_amount);
- result->m_fn_no_deps = m_fn_no_deps.ptr();
- result->m_fn_with_deps = m_fn_with_deps.ptr();
+ result->m_fn_no_deps = m_fn_no_deps.get();
+ result->m_fn_with_deps = m_fn_with_deps.get();
result->m_output_indices = m_output_indices;
result->m_pindices = pindices;
diff --git a/source/blender/simulations/bparticles/particle_function.hpp b/source/blender/simulations/bparticles/particle_function.hpp
index 7ed281ba092..2727910f896 100644
--- a/source/blender/simulations/bparticles/particle_function.hpp
+++ b/source/blender/simulations/bparticles/particle_function.hpp
@@ -18,7 +18,7 @@ using BLI::Vector;
using FN::CPPTypeInfo;
using FN::ExecutionContext;
using FN::ExecutionStack;
-using FN::SharedFunction;
+using FN::Function;
using FN::TupleCallBody;
using FN::Type;
@@ -217,16 +217,16 @@ class ParticleFunctionInputProvider {
class ParticleFunction {
private:
- SharedFunction m_fn_no_deps;
- SharedFunction m_fn_with_deps;
+ std::unique_ptr<Function> m_fn_no_deps;
+ std::unique_ptr<Function> m_fn_with_deps;
Vector<ParticleFunctionInputProvider *> m_input_providers;
Vector<bool> m_parameter_depends_on_particle;
Vector<uint> m_output_indices;
std::unique_ptr<FN::Functions::ArrayExecution> m_array_execution;
public:
- ParticleFunction(SharedFunction fn_no_deps,
- SharedFunction fn_with_deps,
+ ParticleFunction(std::unique_ptr<Function> fn_no_deps,
+ std::unique_ptr<Function> fn_with_deps,
Vector<ParticleFunctionInputProvider *> input_providers,
Vector<bool> parameter_depends_on_particle);
diff --git a/source/blender/simulations/bparticles/particle_function_builder.cpp b/source/blender/simulations/bparticles/particle_function_builder.cpp
index cda1fb71038..cf7d7d3aa60 100644
--- a/source/blender/simulations/bparticles/particle_function_builder.cpp
+++ b/source/blender/simulations/bparticles/particle_function_builder.cpp
@@ -15,9 +15,9 @@ using BLI::float2;
using BLI::rgba_b;
using FN::DataGraph;
using FN::DataSocket;
+using FN::Function;
using FN::FunctionBuilder;
using FN::FunctionGraph;
-using FN::SharedFunction;
using FN::Type;
using FN::Types::StringW;
@@ -114,8 +114,8 @@ static ParticleFunctionInputProvider *INPUT_surface_image(VTreeDataGraph &vtree_
FunctionGraph fgraph(vtree_data_graph.graph(),
{},
{vtree_data_graph.lookup_socket(vsocket->vnode()->input(0))});
- FN::SharedFunction fn = fgraph.new_function(vsocket->vnode()->name());
- FN::fgraph_add_TupleCallBody(fn, fgraph);
+ std::unique_ptr<Function> fn = fgraph.new_function(vsocket->vnode()->name());
+ FN::fgraph_add_TupleCallBody(*fn, fgraph);
FN::TupleCallBody &body = fn->body<TupleCallBody>();
FN_TUPLE_CALL_ALLOC_TUPLES(body, fn_in, fn_out);
@@ -147,8 +147,8 @@ static ParticleFunctionInputProvider *INPUT_is_in_group(VTreeDataGraph &vtree_da
{
FunctionGraph fgraph(
vtree_data_graph.graph(), {}, {vtree_data_graph.lookup_socket(vsocket->vnode()->input(0))});
- FN::SharedFunction fn = fgraph.new_function(vsocket->vnode()->name());
- FN::fgraph_add_TupleCallBody(fn, fgraph);
+ std::unique_ptr<Function> fn = fgraph.new_function(vsocket->vnode()->name());
+ FN::fgraph_add_TupleCallBody(*fn, fgraph);
FN::TupleCallBody &body = fn->body<TupleCallBody>();
FN_TUPLE_CALL_ALLOC_TUPLES(body, fn_in, fn_out);
@@ -182,7 +182,7 @@ static ParticleFunctionInputProvider *create_input_provider(VTreeDataGraph &vtre
return provider;
}
-static SharedFunction create_function__with_deps(
+static std::unique_ptr<Function> create_function__with_deps(
VTreeDataGraph &data_graph,
StringRef function_name,
ArrayRef<DataSocket> sockets_to_compute,
@@ -202,22 +202,21 @@ static SharedFunction create_function__with_deps(
r_input_providers[i] = create_input_provider(data_graph, input_vsockets[i]);
}
- SharedFunction fn = fn_builder.build(function_name);
+ std::unique_ptr<Function> fn = fn_builder.build(function_name);
FunctionGraph fgraph(data_graph.graph(), input_sockets, sockets_to_compute);
- FN::fgraph_add_TupleCallBody(fn, fgraph);
- FN::fgraph_add_LLVMBuildIRBody(fn, fgraph);
+ FN::fgraph_add_TupleCallBody(*fn, fgraph);
+ FN::fgraph_add_LLVMBuildIRBody(*fn, fgraph);
return fn;
}
-static SharedFunction create_function__without_deps(DataGraph &graph,
- StringRef function_name,
- ArrayRef<DataSocket> sockets_to_compute)
+static std::unique_ptr<Function> create_function__without_deps(
+ DataGraph &graph, StringRef function_name, ArrayRef<DataSocket> sockets_to_compute)
{
FunctionBuilder fn_builder;
fn_builder.add_outputs(graph, sockets_to_compute);
- SharedFunction fn = fn_builder.build(function_name);
+ std::unique_ptr<Function> fn = fn_builder.build(function_name);
FunctionGraph fgraph(graph, {}, sockets_to_compute);
- FN::fgraph_add_TupleCallBody(fn, fgraph);
+ FN::fgraph_add_TupleCallBody(*fn, fgraph);
return fn;
}
@@ -241,13 +240,15 @@ static Optional<std::unique_ptr<ParticleFunction>> create_particle_function_from
Vector<ParticleFunctionInputProvider *> input_providers(dependencies.size(), nullptr);
- SharedFunction fn_without_deps = create_function__without_deps(
+ std::unique_ptr<Function> fn_without_deps = create_function__without_deps(
data_graph.graph(), name, sockets_without_deps);
- SharedFunction fn_with_deps = create_function__with_deps(
+ std::unique_ptr<Function> fn_with_deps = create_function__with_deps(
data_graph, name, sockets_with_deps, dependencies, input_providers);
- return make_unique<ParticleFunction>(
- fn_without_deps, fn_with_deps, input_providers, depends_on_particle_flags);
+ return make_unique<ParticleFunction>(std::move(fn_without_deps),
+ std::move(fn_with_deps),
+ input_providers,
+ depends_on_particle_flags);
}
Optional<std::unique_ptr<ParticleFunction>> create_particle_function(VirtualNode *vnode,