Nodes: simplify handling of function nodes in declaration

This adds an explicit post processing step to node declarations.
The purpose of this is to keep the actual node declaration functions
concise by avoiding to specify redundant information. Also it improves
the separation of the creation of the declaration from using it.
This commit is contained in:
Jacques Lucke 2022-12-11 19:38:26 +01:00
parent 19491e5fc0
commit 05bf5c4e0e
Notes: blender-bot 2023-02-14 11:08:33 +01:00
Referenced by issue #103408, Regression: Blender crash when moving camera immediately after opening the project (OPTIX)
3 changed files with 21 additions and 28 deletions

View File

@ -56,13 +56,6 @@ static InputSocketFieldType get_interface_input_field_type(const bNode &node,
/* Get the field type from the declaration. */
const SocketDeclaration &socket_decl = *node_decl->inputs()[socket.index()];
const InputSocketFieldType field_type = socket_decl.input_field_type();
if (field_type == InputSocketFieldType::Implicit) {
return field_type;
}
if (node_decl->is_function_node()) {
/* In a function node, every socket supports fields. */
return InputSocketFieldType::IsSupported;
}
return field_type;
}
@ -93,11 +86,6 @@ static OutputFieldDependency get_interface_output_field_dependency(const bNode &
/* Node declarations should be implemented for nodes involved here. */
BLI_assert(node_decl != nullptr);
if (node_decl->is_function_node()) {
/* In a generic function node, all outputs depend on all inputs. */
return OutputFieldDependency::ForDependentField();
}
/* Use the socket declaration. */
const SocketDeclaration &socket_decl = *node_decl->outputs()[socket.index()];
return socket_decl.output_field_dependency();

View File

@ -309,7 +309,6 @@ class NodeDeclaration {
private:
Vector<SocketDeclarationPtr> inputs_;
Vector<SocketDeclarationPtr> outputs_;
bool is_function_node_ = false;
friend NodeDeclarationBuilder;
@ -320,11 +319,6 @@ class NodeDeclaration {
Span<SocketDeclarationPtr> outputs() const;
Span<SocketDeclarationPtr> sockets(eNodeSocketInOut in_out) const;
bool is_function_node() const
{
return is_function_node_;
}
MEM_CXX_CLASS_ALLOC_FUNCS("NodeDeclaration")
};
@ -332,22 +326,22 @@ class NodeDeclarationBuilder {
private:
NodeDeclaration &declaration_;
Vector<std::unique_ptr<BaseSocketDeclarationBuilder>> builders_;
bool is_function_node_ = false;
public:
NodeDeclarationBuilder(NodeDeclaration &declaration);
/**
* All inputs support fields, and all outputs are fields if any of the inputs is a field.
* Calling field status definitions on each socket is unnecessary. Must be called before adding
* any sockets.
* Calling field status definitions on each socket is unnecessary.
*/
void is_function_node(bool value = true)
void is_function_node()
{
BLI_assert_msg(declaration_.inputs().is_empty() && declaration_.outputs().is_empty(),
"is_function_node() must be called before any socket is created");
declaration_.is_function_node_ = value;
is_function_node_ = true;
}
void finalize();
template<typename DeclType>
typename DeclType::Builder &add_input(StringRef name, StringRef identifier = "");
template<typename DeclType>
@ -553,10 +547,6 @@ inline typename DeclType::Builder &NodeDeclarationBuilder::add_socket(StringRef
socket_decl->name_ = name;
socket_decl->identifier_ = identifier.is_empty() ? name : identifier;
socket_decl->in_out_ = in_out;
if (declaration_.is_function_node()) {
socket_decl->input_field_type_ = InputSocketFieldType::IsSupported;
socket_decl->output_field_dependency_ = OutputFieldDependency::ForDependentField();
}
declarations.append(std::move(socket_decl));
Builder &socket_decl_builder_ref = *socket_decl_builder;
builders_.append(std::move(socket_decl_builder));

View File

@ -11,6 +11,21 @@ void build_node_declaration(const bNodeType &typeinfo, NodeDeclaration &r_declar
{
NodeDeclarationBuilder node_decl_builder{r_declaration};
typeinfo.declare(node_decl_builder);
node_decl_builder.finalize();
}
void NodeDeclarationBuilder::finalize()
{
if (is_function_node_) {
for (SocketDeclarationPtr &socket_decl : declaration_.inputs_) {
if (socket_decl->input_field_type_ != InputSocketFieldType::Implicit) {
socket_decl->input_field_type_ = InputSocketFieldType::IsSupported;
}
}
for (SocketDeclarationPtr &socket_decl : declaration_.outputs_) {
socket_decl->output_field_dependency_ = OutputFieldDependency::ForDependentField();
}
}
}
bool NodeDeclaration::matches(const bNode &node) const