48 rl::RelationsInNode &relations =
b.get_reference_lifetime_relations();
51 if (can_contain_reference(input->socket_type)) {
52 for (const SocketDeclaration *other_input : node_decl.inputs) {
53 if (can_contain_referenced_data(other_input->socket_type)) {
54 relations.use_relations.append({input->index, other_input->index});
57 for (const SocketDeclaration *output : node_decl.outputs) {
58 if (can_contain_reference(output->socket_type)) {
59 relations.reference_propagations.append({input->index, output->index});
64 for (const SocketDeclaration *output : node_decl.outputs) {
65 if (can_contain_referenced_data(output->socket_type)) {
66 relations.data_propagations.append({input->index, output->index});
72 if (can_contain_reference(output->socket_type)) {
73 for (const SocketDeclaration *other_output : node_decl.outputs) {
74 if (can_contain_referenced_data(other_output->socket_type)) {
75 relations.available_relations.append({output->index, other_output->index});
84 b.use_custom_socket_order();
85 b.allow_any_socket_order();
95 auto &panel =
b.add_panel(
"Interface"_ustr);
103 auto &
decl = panel.add_output(socket_type,
UString(item.
name), identifier);
104 decl.socket_name_ptr(
110 decl.structure_type(StructureType::Dynamic);
113 panel.add_output<
decl::Extend>(
""_ustr,
"__extend__"_ustr)
115 socket_items::ui::draw_extend_socket_fn<EvaluateClosureOutputItemsAccessor>());
121 auto &
decl = panel.add_input(socket_type,
UString(item.
name), identifier);
122 decl.socket_name_ptr(
128 decl.structure_type(StructureType::Dynamic);
132 panel.add_input<
decl::Extend>(
""_ustr,
"__extend__"_ustr)
133 .custom_draw(socket_items::ui::draw_extend_socket_fn<EvaluateClosureInputItemsAccessor>());
143 auto *
storage = MEM_new<NodeEvaluateClosure>(__func__);
150 auto *dst_storage = MEM_new<NodeEvaluateClosure>(__func__,
dna::shallow_copy(src_storage));
151 dst_node->
storage = dst_storage;
170 if (
storage.input_items.items_num == 0 &&
storage.output_items.items_num == 0) {
194 layout.
op(
"node.sockets_sync",
IFACE_(
"Sync"), ICON_FILE_REFRESH);
195 layout.
prop(ptr,
"define_signature",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
198 socket_items::ui::draw_items_list_with_operators<EvaluateClosureInputItemsAccessor>(
199 C, panel, tree,
node);
200 socket_items::ui::draw_active_item_props<EvaluateClosureInputItemsAccessor>(
202 panel->use_property_split_set(
true);
203 panel->use_property_decorate_set(
false);
204 panel->prop(item_ptr,
"socket_type",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
209 socket_items::ui::draw_items_list_with_operators<EvaluateClosureOutputItemsAccessor>(
210 C, panel, tree,
node);
211 socket_items::ui::draw_active_item_props<EvaluateClosureOutputItemsAccessor>(
213 panel->use_property_split_set(
true);
214 panel->use_property_decorate_set(
false);
215 panel->prop(item_ptr,
"socket_type",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
303 TIP_(
"Stack limit reached. Closure becomes pass-through."));
309 closure->zone.output_node()->identifier,
310 closure->compute_context.hash(),
311 &closure->compute_context};
314 this->
node().identifier,
315 &this->
node().owner_tree(),
316 closure_source_location);
318 this->
context(), closure->zone, evaluate_closure_context);
322 zone_tree_operation, closure);
339 if (!
result.should_compute()) {
345 if (!matching_input) {
367 for (
const bNodeSocket *zone_output : closure->zone.output_node()->input_sockets()) {
372 Result &zone_result = zone_tree_operation.
get_result(zone_output->identifier);
375 if (!evaluate_node_output) {
392 for (
const bNodeSocket *zone_input : closure->zone.input_node()->output_sockets()) {
399 if (!evaluate_node_input) {
401 std::unique_ptr<Result> temporary_input = std::make_unique<Result>(
402 this->
context().create_result(zone_input_type));
403 temporary_input->allocate_invalid();
404 temporary_inputs.append(std::move(temporary_input));
406 temporary_inputs.last().get());
411 std::unique_ptr<Result> temporary_input = std::make_unique<Result>(
413 temporary_input->share_data(input_result);
414 temporary_inputs.append(std::move(temporary_input));
416 temporary_inputs.last().get());
418 return temporary_inputs;
428 const std::string &identifier = item.key;
429 const Result *value = item.value;
430 std::unique_ptr<Result> temporary_input = std::make_unique<Result>(
432 temporary_input->share_data(*value);
433 temporary_inputs.append(std::move(temporary_input));
436 return temporary_inputs;
443 for (
const bNodeSocket *zone_output : closure->zone.output_node()->input_sockets()) {
450 if (!evaluate_node_output) {
459 Result &zone_tree_result = zone_tree_operation.
get_result(zone_output->identifier);
461 if (zone_tree_result.
type() != evaluate_node_result.
type()) {
470 TIP_(
"Conversion not supported when evaluating closure"),
478 this->
context(), zone_tree_result.
type(), evaluate_node_result.
type());
487 TIP_(
"Implicit type conversion when evaluating closure"),
495 evaluate_node_result.
share_data(zone_tree_result);
512 const_cast<bNode &
>(*closure->zone.output_node()),
output->name);
513 if (closure_output) {
518 fmt::format(fmt::runtime(
TIP_(
"Closure not have output: \"{}\"")),
output->name));
525 if (input->identifier_ustr() ==
"Closure"_ustr) {
530 const_cast<bNode &
>(*closure->zone.input_node()), input->
name);
536 fmt::format(fmt::runtime(
TIP_(
"Closure not have input: \"{}\"")), input->name));
551 ntype.
ui_name =
"Evaluate Closure";
599 const bNode &
node = output_socket.owner_node();
603 if (output_socket.index() >=
storage.output_items.items_num) {
607 storage.output_items.items[output_socket.index()];
612 if (output_key == input_key) {
616 return &
node.input_socket(i + 1);
#define NODE_CLASS_CONVERTER
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_EVALUATE_CLOSURE
#define BLI_STR_UTF8_BLACK_RIGHT_POINTING_SMALL_TRIANGLE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bool is_convertible(const CPPType &from_type, const CPPType &to_type) const
NodeOperation(Context &context, const bNode &node)
void add_warning(nodes::NodeWarningType type, std::string message)
const ComputeContext & get_compute_context() const
const bNode & node() const
Result & get_result(StringRef identifier)
void allocate_default_remaining_outputs()
Context & context() const
Result & get_input(StringRef identifier) const
void map_input_to_result(StringRef identifier, Result *result)
void share_data(const Result &source)
const CPPType & get_cpp_type() const
bool should_compute() const
static const char * type_name(const ResultType type)
static ResultType type(gpu::TextureFormat format)
static ResultPrecision precision(gpu::TextureFormat format)
void set_reference_count(int count)
void map_input_to_result(Result *result)
static ClosureSignature from_evaluate_closure_node(const bNode &node, bool allow_auto_structure_type)
Span< const bke::SocketValueVariant * > captured_values() const
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeTree & node_tree() const
const bNodeSocket & other_socket() const
void connect_available_socket_by_identifier(bNode &new_node, UString socket_identifier)
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
void connect_available_socket(bNode &new_node, UString socket_name)
Vector< SocketDeclaration * > inputs
eNodeSocketDatatype socket_type
NodeOperation(Context &context, const bNode &node)
void write_outputs(ZoneTreeOperation &zone_tree_operation, const compositor::ClosurePtr &closure)
void write_default_outputs()
void set_reference_counts(ZoneTreeOperation &zone_tree_operation, const compositor::ClosurePtr &closure)
Vector< std::unique_ptr< Result > > map_inputs(ZoneTreeOperation &zone_tree_operation, const compositor::ClosurePtr &closure)
Vector< std::unique_ptr< Result > > map_captured_values(ZoneTreeOperation &zone_tree_operation, const compositor::ClosurePtr &closure)
void add_missing_inputs_outputs_warnings(const compositor::ClosurePtr &closure)
#define storage(slot, qualifiers)
bool can_contain_reference(eNodeSocketDatatype socket_type)
bool can_contain_referenced_data(eNodeSocketDatatype socket_type)
bNodeSocket * node_find_enabled_input_socket(bNode &node, StringRef name)
const DataTypeConversions & get_implicit_type_conversions()
void node_register_type(bNodeType &ntype)
bNodeSocket * node_find_enabled_output_socket(bNode &node, StringRef name)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
ImplicitSharingPtr< Closure > ClosurePtr
ResultType get_node_socket_result_type(const bNodeSocket *socket)
bool is_socket_available(const bNodeSocket *socket)
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
static void node_layout_ex(ui::Layout &layout, bContext *C, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static void node_operators()
static void node_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
static const bNodeSocket * node_internally_linked_input(const bNodeTree &, const bNode &, const bNodeSocket &output_socket)
static void node_register()
static void node_free_storage(bNode *node)
static void create_all_reference_lifetime_relations(NodeDeclarationBuilder &b)
static void node_copy_storage(bNodeTree *, bNode *dst_node, const bNode *src_node)
static void node_init(bNodeTree *, bNode *node)
static bool node_insert_link(bke::NodeInsertLinkParams ¶ms)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
void make_common_operators()
void blend_write(BlendWriter *writer, const bNode &node)
void destruct_array(bNode &node)
void blend_read_data(BlendDataReader *reader, bNode &node)
void copy_array(const bNode &src_node, bNode &dst_node)
Accessor::ItemT * add_item_with_socket_type_and_name(bNodeTree &ntree, bNode &node, const eNodeSocketDatatype socket_type, const char *name, std::optional< int > dimensions=std::nullopt)
bool try_add_item_via_any_extend_socket(bNodeTree &ntree, bNode &extend_node, bNode &storage_node, bNodeLink &link, const std::optional< StringRef > socket_identifier=std::nullopt, typename Accessor::ItemT **r_new_item=nullptr)
void sync_sockets_evaluate_closure(SpaceNode &snode, bNode &evaluate_closure_node, ReportList *reports, const bNodeSocket *src_closure_socket)
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node, Main *bmain)
const bNodeSocket * evaluate_closure_node_internally_linked_input(const bNodeSocket &output_socket)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ NODE_EVALUATE_CLOSURE_FLAG_DEFINE_SIGNATURE
void sh_geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
SpaceNode * CTX_wm_space_node(const bContext *C)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
void write_string(const char *data)
eNodeSocketDatatype socket_type
NodeSocketInterfaceStructureType structure_type
struct bNodeTree * edittree
bke::bNodeSocketType * typeinfo
bke::bNodeTreeType * typeinfo
ListBaseT< bNodeSocket > inputs
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
NodeInternallyLinkedInputFunction internally_linked_input
NodeBlendWriteFunction blend_write_storage_content
void(*) register_operators()
std::string ui_description
NodeBlendDataReadFunction blend_data_read_storage_content
NodeGetCompositorOperationFunction get_compositor_operation
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
void(*) initfunc(bNodeTree *ntree, bNode *node)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
bool(*) insert_link(NodeInsertLinkParams ¶ms)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
NodeEvaluateClosureOutputItem ItemT
static std::string socket_identifier_for_item(const ItemT &item)
static StructRNA ** item_srna
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
PanelLayout panel(const bContext *C, StringRef idname, bool default_closed)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)