WIP: Closures and deferred evaluation for geometry nodes #107842

Draft
Lukas Tönne wants to merge 35 commits from LukasTonne/blender:geometry-nodes-closures into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
7 changed files with 25 additions and 18 deletions
Showing only changes of commit a7ba495a82 - Show all commits

View File

@ -9,9 +9,10 @@
#include "DNA_meshdata_types.h"
#include "FN_closure.hh"
#include "FN_init.h"
#include "NOD_socket.h"
struct Tex;
struct Image;
struct Material;
@ -31,12 +32,11 @@ BLI_CPP_TYPE_MAKE(MStringProperty, CPPTypeFlags::None);
BLI_CPP_TYPE_MAKE(blender::bke::AnonymousAttributeSet, CPPTypeFlags::None);
BLI_CPP_TYPE_MAKE(blender::fn::Closure, CPPTypeFlags::None);
void BKE_cpp_types_init()
{
blender::register_cpp_types();
FN_register_cpp_types();
blender::nodes::register_cpp_types();
BLI_CPP_TYPE_REGISTER(GeometrySet);
BLI_CPP_TYPE_REGISTER(blender::bke::InstanceReference);
@ -52,6 +52,4 @@ void BKE_cpp_types_init()
BLI_CPP_TYPE_REGISTER(MStringProperty);
BLI_CPP_TYPE_REGISTER(blender::bke::AnonymousAttributeSet);
BLI_CPP_TYPE_REGISTER(blender::fn::Closure);
}

View File

@ -43,6 +43,8 @@ void register_standard_node_socket_types(void);
namespace blender::nodes {
void register_cpp_types();
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node);
} // namespace blender::nodes

View File

@ -4,12 +4,12 @@
#include "BKE_node_runtime.hh"
#include "FN_closure.hh"
#include "FN_lazy_function_graph.hh"
#include "UI_interface.h"
#include "UI_resources.h"
#include "NOD_closure.hh"
#include "NOD_common.h"
#include "NOD_node_declaration.hh"
@ -60,7 +60,7 @@ static void node_geo_exec(GeoNodeExecParams params)
bind_tree.runtime->geometry_nodes_lazy_function_graph_info;
BLI_assert(lf_graph_info_ptr);
fn::Closure closure(lf_graph_info_ptr->graph);
Closure closure(*lf_graph_info_ptr);
params.set_output("Function", std::move(closure));
}

View File

@ -4,13 +4,12 @@
#include "BLI_math_vector.h"
#include "BLI_string.h"
#include "FN_closure.hh"
#include "RNA_enum_types.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "NOD_closure.hh"
#include "NOD_common.h"
#include "node_geometry_util.hh"

View File

@ -17,7 +17,7 @@ Closure::Closure(const GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
const GeometryNodesLazyFunctionGraphInfo *Closure::lf_graph_info() const
{
return *lf_graph_info_;
return lf_graph_info_;
}
} // namespace blender::nodes

View File

@ -1158,14 +1158,14 @@ class LazyFunctionForEvaluateFunctionNode : public LazyFunction {
public:
LazyFunctionForEvaluateFunctionNode(const bNode &eval_node) : eval_node_(eval_node)
LazyFunctionForEvaluateFunctionNode(const bNode &eval_node,
MutableSpan<int> r_lf_index_by_bsocket)
: eval_node_(eval_node)
{
debug_name_ = eval_node.name;
allow_missing_requested_inputs_ = true;
Vector<const bNodeSocket *> tmp_inputs;
Vector<const bNodeSocket *> tmp_outputs;
lazy_function_interface_from_node(eval_node, tmp_inputs, tmp_outputs, inputs_, outputs_);
lazy_function_interface_from_node(eval_node, inputs_, outputs_, r_lf_index_by_bsocket);
}
void execute_impl(lf::Params &params, const lf::Context &context) const override
@ -1252,7 +1252,7 @@ class LazyFunctionForEvaluateFunctionNode : public LazyFunction {
/* The compute context changes when entering a node group. */
bke::NodeGroupComputeContext compute_context{
user_data->compute_context, group_node_.identifier, storage->context_hash_cache};
user_data->compute_context, eval_node_.identifier, storage->context_hash_cache};
storage->context_hash_cache = compute_context.hash();
GeoNodesLFUserData group_user_data = *user_data;
@ -1271,7 +1271,7 @@ class LazyFunctionForEvaluateFunctionNode : public LazyFunction {
param_input_usages,
param_output_usages,
param_set_outputs};
graph_executor->execute(params, func_context);
graph_executor.execute(func_params, func_context);
}
void *init_storage(LinearAllocator<> &allocator) const override

View File

@ -10,6 +10,7 @@
#include "DNA_node_types.h"
#include "BLI_color.hh"
#include "BLI_cpp_type_make.hh"
#include "BLI_listbase.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
@ -181,8 +182,15 @@ static void verify_socket_template_list(bNodeTree *ntree,
}
}
BLI_CPP_TYPE_MAKE(blender::nodes::Closure, CPPTypeFlags::None);
namespace blender::nodes {
void register_cpp_types()
{
BLI_CPP_TYPE_REGISTER(blender::nodes::Closure);
}
static void refresh_socket_list(bNodeTree &ntree,
bNode &node,
ListBase &sockets,
@ -789,9 +797,9 @@ static bNodeSocketType *make_socket_type_material()
static bNodeSocketType *make_socket_type_function()
{
bNodeSocketType *socktype = make_standard_socket_type(SOCK_FUNCTION, PROP_NONE);
socktype->base_cpp_type = &blender::CPPType::get<fn::Closure>();
socktype->base_cpp_type = &blender::CPPType::get<blender::nodes::Closure>();
socktype->get_base_cpp_value = [](const bNodeSocket &/*socket*/, void *r_value) {
new (r_value) fn::Closure();
new (r_value) blender::nodes::Closure();
};
socktype->geometry_nodes_cpp_type = socktype->base_cpp_type;
socktype->get_geometry_nodes_cpp_value = socktype->get_base_cpp_value;