28using nodes::StructureType;
29namespace rl = nodes::reference_lifetimes;
32 const StructureType structure_type)
35 return StructureType::Single;
38 return StructureType::Single;
40 return structure_type;
44 const StructureType structure_type)
50 const StructureType structure_type)
54 return structure_type;
61 if (
node.is_group()) {
62 if (
const bNodeTree *group = id_cast<const bNodeTree *>(
node.id)) {
63 if (!
ID_MISSING(group) && group->runtime->structure_type_interface) {
64 return *group->runtime->structure_type_interface;
76 if (
node.is_undefined() || !
node.declaration() ||
node.declaration()->skip_updating_sockets) {
82 if (
node.is_reroute()) {
96 dependency.
type =
decl.structure_type;
97 if (dependency.
type != StructureType::Dynamic) {
101 [&]<
typename T>(
const T &value) {
102 if constexpr (std::is_same_v<T, nodes::OutputStructureTypeDependency::None>) {
105 else if constexpr (std::is_same_v<T, nodes::OutputStructureTypeDependency::All>) {
109 else if constexpr (std::is_same_v<T, nodes::OutputStructureTypeDependency::Partial>) {
116 decl.structure_type_output_dependency.variant);
126 for (
const int i :
nodes.index_range()) {
156 switch (requirement) {
158 return StructureType::Dynamic;
160 return StructureType::Field;
162 return StructureType::Single;
164 return StructureType::Grid;
166 return StructureType::List;
168 return StructureType::Dynamic;
171 return StructureType::Dynamic;
178 for (
const int i : tree.interface_inputs().index_range()) {
183 for (
const bNode *
node : tree.group_input_nodes()) {
185 is_auto_structure_type[socket.index_in_tree()].set();
190 if (
const bNode *group_output_node = tree.group_output_node()) {
191 is_auto_structure_type.
slice(group_output_node->input_socket_indices_in_tree().drop_back(1))
197 for (
const bNode *closure_input_node : tree.nodes_by_type(
"NodeClosureInput"_ustr)) {
199 tree, *closure_input_node);
200 if (!closure_output_node) {
207 const bNodeSocket &socket = closure_input_node->output_socket(i);
208 is_auto_structure_type[socket.index_in_tree()].set();
214 const bNodeSocket &socket = closure_output_node->input_socket(i);
215 is_auto_structure_type[socket.index_in_tree()].set();
221 for (
const bNode *evaluate_closure_node : tree.nodes_by_type(
"NodeEvaluateClosure"_ustr)) {
226 const bNodeSocket &socket = evaluate_closure_node->input_socket(i + 1);
227 is_auto_structure_type[socket.index_in_tree()].set();
233 const bNodeSocket &socket = evaluate_closure_node->output_socket(i);
234 is_auto_structure_type[socket.index_in_tree()].set();
240 for (
const bNode *
node : tree.nodes_by_type(
"NodeCombineBundle"_ustr)) {
246 is_auto_structure_type[socket.index_in_tree()].set();
252 for (
const bNode *
node : tree.nodes_by_type(
"NodeSeparateBundle"_ustr)) {
258 is_auto_structure_type[socket.index_in_tree()].set();
264 for (
const bNode *
node : tree.nodes_by_type(
"NodeStoreBundleItem"_ustr)) {
268 is_auto_structure_type[socket.index_in_tree()].set();
273 for (
const bNode *
node : tree.nodes_by_type(
"NodeGetBundleItem"_ustr)) {
277 is_auto_structure_type[socket.index_in_tree()].set();
286 for (
const bNode *
node : tree.all_nodes()) {
288 DataRequirement &requirement = input_requirements[socket->index_in_all_inputs()];
289 if (is_auto_structure_type[socket->index_in_tree()]) {
299 case StructureType::Dynamic: {
303 case StructureType::Single: {
307 case StructureType::Grid: {
311 case StructureType::Field: {
315 case StructureType::List: {
328 if (!output_socket.is_available()) {
331 for (
const bNodeSocket *socket : output_socket.directly_linked_sockets()) {
332 if (!socket->is_available()) {
335 requirement =
merge(requirement, input_requirements[socket->index_in_all_inputs()]);
347 for (
const bNode *
node : tree.group_input_nodes()) {
351 interface_requirements[i] =
merge(
357 for (
const int i : tree.interface_inputs().index_range()) {
379 if (socket.is_input()) {
383 if (
node.is_group_input()) {
403 const bNode &input_node,
404 const bNode &output_node,
408 for (
const int i : output_node.output_sockets().index_range()) {
410 const bNodeSocket &input_of_input_node = input_node.input_socket(i);
411 const bNodeSocket &output_of_output_node = output_node.output_socket(i);
412 const bNodeSocket &input_of_output_node = output_node.input_socket(i + 1);
414 input_requirements[input_of_input_node.index_in_all_inputs()],
416 if (input_requirements[input_of_input_node.index_in_all_inputs()] != new_value) {
417 input_requirements[input_of_input_node.index_in_all_inputs()] = new_value;
420 if (input_requirements[input_of_output_node.index_in_all_inputs()] != new_value) {
421 input_requirements[input_of_output_node.index_in_all_inputs()] = new_value;
429 const bNode &input_node,
430 const bNode &output_node,
434 for (
const int i : output_node.output_sockets().index_range()) {
435 const bNodeSocket &input_of_input_node = input_node.input_socket(i + 1);
436 const bNodeSocket &output_of_output_node = output_node.output_socket(i);
437 const bNodeSocket &input_of_output_node = output_node.input_socket(i);
439 input_requirements[input_of_input_node.index_in_all_inputs()],
441 if (input_requirements[input_of_input_node.index_in_all_inputs()] != new_value) {
442 input_requirements[input_of_input_node.index_in_all_inputs()] = new_value;
445 if (input_requirements[input_of_output_node.index_in_all_inputs()] != new_value) {
446 input_requirements[input_of_output_node.index_in_all_inputs()] = new_value;
458 switch (
node.type_legacy) {
461 if (
const bNode *output_node = tree.node_by_id(
data.output_node_id)) {
463 node, *output_node, input_requirements);
471 for (
const bNode *input_node : tree.nodes_by_type(
"GeometryNodeSimulationInput"_ustr)) {
473 if (
node.identifier ==
data.output_node_id) {
475 *input_node,
node, input_requirements);
485 if (
const bNode *output_node = tree.node_by_id(
data.output_node_id)) {
487 node, *output_node, input_requirements);
495 for (
const bNode *input_node : tree.nodes_by_type(
"GeometryNodeRepeatInput"_ustr)) {
497 if (
node.identifier ==
data.output_node_id) {
499 *input_node,
node, input_requirements);
517 bool need_update =
false;
519 for (
const bNode *
node : tree.toposort_right_to_left()) {
527 for (
const bNodeSocket *socket : output_socket.directly_linked_sockets()) {
528 if (!socket->is_available()) {
531 output_requirement =
merge(output_requirement,
532 input_requirements[socket->index_in_all_inputs()]);
535 switch (output_requirement) {
543 const bNodeSocket &input_socket = *input_sockets[input];
557 const bNodeSocket &input_socket = *input_sockets[input];
558 if (input_requirements[input_socket.index_in_all_inputs()] ==
564 if (input_socket.is_directly_linked()) {
565 inputs_with_links.
append(input_socket.index_in_all_inputs());
568 if (inputs_with_links.
size() == 1) {
569 input_requirements[inputs_with_links.
first()] = output_requirement;
572 for (
const int input : inputs_with_links) {
598 if (a == StructureType::Dynamic ||
b == StructureType::Dynamic) {
599 return StructureType::Dynamic;
601 if ((a == StructureType::Field &&
b == StructureType::Grid) ||
602 (a == StructureType::Grid &&
b == StructureType::Field))
604 return StructureType::Grid;
606 if ((a == StructureType::Single &&
b == StructureType::Field) ||
607 (a == StructureType::Field &&
b == StructureType::Single))
609 return StructureType::Field;
611 if ((a == StructureType::Single &&
b == StructureType::Grid) ||
612 (a == StructureType::Grid &&
b == StructureType::Single))
614 return StructureType::Grid;
616 if ((a == StructureType::Single &&
b == StructureType::List) ||
617 (a == StructureType::List &&
b == StructureType::Single))
619 return StructureType::List;
621 if ((a == StructureType::Field &&
b == StructureType::List) ||
622 (a == StructureType::List &&
b == StructureType::Field))
624 return StructureType::List;
631 const bNode &output_node,
635 for (
const int i : output_node.output_sockets().index_range()) {
637 const bNodeSocket &input = input_node.output_socket(i + 1);
639 const StructureType new_value =
left_to_right_merge(structure_types[input.index_in_tree()],
640 structure_types[
output.index_in_tree()]);
643 if (structure_types[input.index_in_tree()] != new_input_value) {
644 structure_types[input.index_in_tree()] = new_input_value;
647 if (structure_types[
output.index_in_tree()] != new_output_value) {
648 structure_types[
output.index_in_tree()] = new_output_value;
656 const bNode &output_node,
660 for (
const int i : output_node.output_sockets().index_range()) {
661 const bNodeSocket &input_of_input_node = input_node.output_socket(i + 1);
662 const bNodeSocket &output_of_output_node = output_node.output_socket(i);
664 structure_types[input_of_input_node.index_in_tree()],
665 structure_types[output_of_output_node.index_in_tree()]);
670 if (structure_types[input_of_input_node.index_in_tree()] != new_input_value) {
671 structure_types[input_of_input_node.index_in_tree()] = new_input_value;
674 if (structure_types[output_of_output_node.index_in_tree()] != new_output_value) {
675 structure_types[output_of_output_node.index_in_tree()] = new_output_value;
687 switch (
node.type_legacy) {
690 if (
const bNode *output_node = tree.node_by_id(
data.output_node_id)) {
692 node, *output_node, structure_types);
700 for (
const bNode *input_node : tree.nodes_by_type(
"GeometryNodeSimulationInput"_ustr)) {
702 if (
node.identifier ==
data.output_node_id) {
704 *input_node,
node, structure_types);
714 if (
const bNode *output_node = tree.node_by_id(
data.output_node_id)) {
716 node, *output_node, structure_types);
724 for (
const bNode *input_node : tree.nodes_by_type(
"GeometryNodeRepeatInput"_ustr)) {
726 if (
node.identifier ==
data.output_node_id) {
728 *input_node,
node, structure_types);
745 return StructureType::Field;
747 return StructureType::Single;
756 for (
const bNodeSocket *input : tree.all_input_sockets()) {
757 if (input->owner_node().is_undefined()) {
760 if (!input->is_directly_linked()) {
769 for (
const UString idname : {
"GeometryNodeRepeatInput"_ustr,
770 "GeometryNodeRepeatOutput"_ustr,
771 "GeometryNodeSimulationInput"_ustr,
772 "GeometryNodeSimulationOutput"_ustr})
774 for (
const bNode *
node : tree.nodes_by_type(idname)) {
776 structure_types[socket->index_in_tree()] = StructureType::Single;
782 bool need_update =
false;
783 for (
const bNode *
node : tree.toposort_left_to_right()) {
784 if (
node->is_undefined()) {
789 if (
node->is_group_input()) {
792 *output_sockets[i], group_input_structure_types[i]);
798 if (!input->is_available()) {
802 std::optional<StructureType> input_type;
803 for (
const bNodeLink *link : input->directly_linked_links()) {
804 if (!link->is_used()) {
807 const StructureType new_type = structure_types[link->fromsock->index_in_tree()];
812 input_type = new_type;
823 for (
const int output_index :
node_interface.outputs.index_range()) {
825 if (!
output.is_available() || !
output.runtime->declaration) {
828 if (is_auto_structure_type[
output.index_in_tree()]) {
834 std::optional<StructureType> output_type;
835 for (
const int input_index :
node_interface.outputs[output_index].linked_inputs) {
837 if (!input.is_available()) {
840 const StructureType new_type = structure_types[input.index_in_tree()];
845 output_type = new_type;
870 handled_sockets.
add(&group_output);
871 sockets_to_check.
push(&group_output);
875 while (!sockets_to_check.
is_empty()) {
877 if (!input_socket->is_directly_linked()) {
881 for (
const bNodeSocket *origin_socket : input_socket->directly_linked_sockets()) {
882 const bNode &origin_node = origin_socket->owner_node();
883 if (origin_node.is_group_input()) {
889 for (
const int input_index :
node_interface.outputs[origin_socket->index()].linked_inputs) {
890 const bNodeSocket &input = origin_node.input_socket(input_index);
891 if (!input.is_available()) {
894 if (handled_sockets.
add(&input)) {
895 sockets_to_check.
push(&input);
910 const bNode *group_output_node = tree.group_output_node();
911 if (!group_output_node) {
913 output.type = StructureType::Dynamic;
924 StructureType(interface_outputs[i]->structure_type)),
930 *interface_outputs[i], structure_types[sockets[i]->index_in_tree()]);
931 if (interface.
outputs[i].type == StructureType::Dynamic) {
934 interface.
outputs[i] = {StructureType::Dynamic, linked_inputs.
as_span()};
946 tree.ensure_topology_cache();
947 tree.ensure_interface_cache();
951 StructureType::Dynamic);
953 result.group_interface.inputs.reinitialize(tree.interface_inputs().size());
954 result.group_interface.outputs.reinitialize(tree.interface_outputs().size());
955 if (tree.has_available_link_cycle()) {
956 result.group_interface.inputs.fill(StructureType::Dynamic);
957 result.group_interface.outputs.fill({StructureType::Dynamic, {}});
971 tree, data_requirements, is_auto_structure_type,
result.socket_structure_types);
974 result.group_interface.inputs,
975 is_auto_structure_type,
976 result.socket_structure_types);
978 tree, node_interfaces,
result.socket_structure_types,
result.group_interface);
986 for (
const int i : tree.all_sockets().index_range()) {
987 const bNodeSocket &socket = *tree.all_sockets()[i];
996 std::move(
result.group_interface));
#define GEO_NODE_SIMULATION_OUTPUT
#define NODE_CLOSURE_OUTPUT
#define GEO_NODE_REPEAT_OUTPUT
#define GEO_NODE_REPEAT_INPUT
#define GEO_NODE_SIMULATION_INPUT
#define BLI_assert_unreachable()
#define BLI_assert_unreachable_static_t(T)
MutableSpan< T > as_mutable_span()
void reinitialize(const int64_t new_size)
constexpr IndexRange drop_back(int64_t n) const
constexpr IndexRange()=default
constexpr int64_t size() const
constexpr IndexRange index_range() const
void push(const T &value)
void append(const T &value)
void append_non_duplicates(const T &value)
Span< T > as_span() const
MutableBitSpan slice(const IndexRange range) const
nodes::StructureType inferred_structure_type
std::unique_ptr< nodes::StructureTypeInterface > structure_type_interface
const bNode * get_corresponding_output(const bNodeTree &tree, const bNode &input_bnode) const
StructureType structure_type
NodeDefaultInputType default_input_type
#define storage(slot, qualifiers)
void fill_index_range(MutableSpan< T > span, const T start=0)
void foreach_1_index(const BitSpanT &data, Fn &&fn)
static void store_group_input_structure_types(const bNodeTree &tree, const Span< DataRequirement > input_requirements, nodes::StructureTypeInterface &derived_interface)
static void store_auto_output_structure_types(const bNodeTree &tree, const Span< DataRequirement > input_requirements, const bits::BoundedBitSpan is_auto_structure_type, MutableSpan< StructureType > structure_types)
static void init_input_requirements(const bNodeTree &tree, const bits::BoundedBitSpan is_auto_structure_type, MutableSpan< DataRequirement > input_requirements)
static void propagate_right_to_left(const bNodeTree &tree, const Span< nodes::StructureTypeInterface > node_interfaces, MutableSpan< DataRequirement > input_requirements)
static DataRequirement merge(const DataRequirement a, const DataRequirement b)
static StructureType data_requirement_to_auto_structure_type(const DataRequirement requirement)
static StructureType left_to_right_merge(const StructureType a, const StructureType b)
static ZoneInOutChange simulation_zone_requirements_propagate(const bNode &input_node, const bNode &output_node, MutableSpan< DataRequirement > input_requirements)
static bool propagate_zone_status(const bNodeTree &tree, const bNode &node, MutableSpan< StructureType > structure_types)
static ZoneInOutChange simulation_zone_status_propagate(const bNode &input_node, const bNode &output_node, MutableSpan< StructureType > structure_types)
static StructureTypeInferenceResult calc_structure_type_interface(const bNodeTree &tree)
ENUM_OPERATORS(ZoneInOutChange)
static ZoneInOutChange repeat_zone_requirements_propagate(const bNode &input_node, const bNode &output_node, MutableSpan< DataRequirement > input_requirements)
bool update_structure_type_interface(bNodeTree &tree)
static StructureType ensure_supported_structure_type(const eNodeSocketDatatype socket_type, const StructureType structure_type)
static DataRequirement calc_output_socket_requirement(const bNodeSocket &output_socket, const Span< DataRequirement > input_requirements)
static Vector< int > find_dynamic_output_linked_inputs(const bNodeSocket &group_output, const Span< nodes::StructureTypeInterface > interface_by_node)
static nodes::StructureTypeInterface calc_node_interface(const bNode &node)
static void propagate_left_to_right(const bNodeTree &tree, const Span< nodes::StructureTypeInterface > node_interfaces, const Span< StructureType > group_input_structure_types, const bits::BoundedBitSpan is_auto_structure_type, MutableSpan< StructureType > structure_types)
static bool propagate_zone_data_requirements(const bNodeTree &tree, const bNode &node, MutableSpan< DataRequirement > input_requirements)
static ZoneInOutChange repeat_zone_status_propagate(const bNode &input_node, const bNode &output_node, MutableSpan< StructureType > structure_types)
static StructureType get_unconnected_input_structure_type(const nodes::SocketDeclaration &declaration)
static void store_group_output_structure_types(const bNodeTree &tree, const Span< nodes::StructureTypeInterface > interface_by_node, const Span< StructureType > structure_types, nodes::StructureTypeInterface &interface)
static Array< nodes::StructureTypeInterface > calc_node_interfaces(const bNodeTree &tree)
static void find_auto_structure_type_sockets(const bNodeTree &tree, bits::MutableBoundedBitSpan is_auto_structure_type)
const bNodeZoneType * zone_type_by_node_type(const int node_type)
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
bool default_input_type_is_field(const NodeDefaultInputType input_type)
bool socket_type_supports_grids(const eNodeSocketDatatype socket_type)
BMesh const char void * data
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
bke::bNodeSocketRuntime * runtime
NodeSocketInterfaceStructureType structure_type
bke::bNodeTreeRuntime * runtime
nodes::StructureTypeInterface group_interface
Array< StructureType > socket_structure_types
Array< int > linked_inputs
Array< StructureType > inputs
Array< OutputDependency > outputs