19using nodes::FieldInferencingInterface;
21using nodes::NodeDeclaration;
22using nodes::OutputFieldDependency;
24using nodes::SocketDeclaration;
34 if (!socket->owner_node().is_dangling_reroute()) {
45 return InputSocketFieldType::None;
47 if (node.is_reroute()) {
48 return InputSocketFieldType::IsSupported;
50 if (node.is_group_output()) {
52 return InputSocketFieldType::IsSupported;
54 if (node.is_undefined()) {
55 return InputSocketFieldType::None;
58 return InputSocketFieldType::None;
80 if (node.is_reroute()) {
84 if (node.is_group_input()) {
88 if (node.is_undefined()) {
110 InputSocketFieldType::None);
113 return inferencing_interface;
125 if (node.is_group()) {
127 if (group ==
nullptr) {
129 return empty_interface;
135 if (!group->
runtime->field_inferencing_interface) {
139 return *group->
runtime->field_inferencing_interface;
145 inferencing_interface.
inputs.reinitialize(input_sockets.size());
146 for (
const int i : input_sockets.index_range()) {
151 inferencing_interface.
outputs.reinitialize(output_sockets.
size());
156 return inferencing_interface;
182 case OutputSocketFieldType::FieldSource:
183 case OutputSocketFieldType::None: {
186 case OutputSocketFieldType::DependentField: {
188 input_sockets.
extend(node.input_sockets());
191 case OutputSocketFieldType::PartiallyDependent: {
194 input_sockets.
append(&node.input_socket(
i));
199 return input_sockets;
220 handled_sockets.
add(&group_output_socket);
221 sockets_to_check.
push(&group_output_socket);
226 while (!sockets_to_check.
is_empty()) {
229 if (!input_socket->is_directly_linked() &&
230 !field_state_by_socket_id[input_socket->index_in_tree()].is_single)
236 for (
const bNodeSocket *origin_socket : input_socket->directly_linked_sockets()) {
237 const bNode &origin_node = origin_socket->owner_node();
239 field_state_by_socket_id[origin_socket->index_in_tree()];
242 if (origin_node.is_group_input()) {
253 *interface_by_node[origin_node.index()];
255 inferencing_interface.
outputs[origin_socket->index()];
261 if (!origin_input_socket->is_available()) {
264 if (!field_state_by_socket_id[origin_input_socket->index_in_tree()].is_single) {
265 if (handled_sockets.
add(origin_input_socket)) {
266 sockets_to_check.
push(origin_input_socket);
294 const bool requires_single = a.requires_single ||
b.requires_single;
295 const bool is_single = a.is_single &&
b.is_single;
298 if (a.requires_single != requires_single || a.is_single != is_single) {
299 res |= FieldStateSyncResult::CHANGED_A;
301 if (
b.requires_single != requires_single ||
b.is_single != is_single) {
302 res |= FieldStateSyncResult::CHANGED_B;
305 a.requires_single = requires_single;
306 b.requires_single = requires_single;
307 a.is_single = is_single;
308 b.is_single = is_single;
319 const bNode &input_node,
320 const bNode &output_node,
324 for (
const int i : output_node.output_sockets().index_range()) {
326 const bNodeSocket &input_socket = input_node.output_socket(
i + 1);
327 const bNodeSocket &output_socket = output_node.output_socket(
i);
328 SocketFieldState &input_state = field_state_by_socket_id[input_socket.index_in_tree()];
329 SocketFieldState &output_state = field_state_by_socket_id[output_socket.index_in_tree()];
336 const bNode &input_node,
337 const bNode &output_node,
342 for (
const int i :
IndexRange(storage.items_num)) {
343 const bNodeSocket &input_socket = input_node.output_socket(
i + 1);
344 const bNodeSocket &output_socket = output_node.output_socket(
i);
345 SocketFieldState &input_state = field_state_by_socket_id[input_socket.index_in_tree()];
346 SocketFieldState &output_state = field_state_by_socket_id[output_socket.index_in_tree()];
357 tree.ensure_topology_cache();
359 bool need_update =
false;
365 if (
const bNode *output_node =
tree.node_by_id(
data.output_node_id)) {
367 node, *output_node, field_state_by_socket_id);
375 for (
const bNode *input_node :
tree.nodes_by_type(
"GeometryNodeSimulationInput")) {
379 *input_node, node, field_state_by_socket_id);
389 if (
const bNode *output_node =
tree.node_by_id(
data.output_node_id)) {
391 node, *output_node, field_state_by_socket_id);
399 for (
const bNode *input_node :
tree.nodes_by_type(
"GeometryNodeRepeatInput")) {
403 *input_node, node, field_state_by_socket_id);
426 bool need_update =
false;
428 for (
const bNode *node : toposort_result) {
431 for (
const bNodeSocket *output_socket : node->output_sockets()) {
435 inferencing_interface.
outputs[output_socket->index()];
437 if (field_dependency.
field_type() == OutputSocketFieldType::FieldSource) {
440 if (field_dependency.
field_type() == OutputSocketFieldType::None) {
441 state.requires_single =
true;
442 state.is_always_single =
true;
448 for (
const bNodeSocket *target_socket : output_socket->directly_linked_sockets()) {
449 if (target_socket->is_available()) {
450 state.requires_single |=
451 field_state_by_socket_id[target_socket->index_in_tree()].requires_single;
455 if (
state.requires_single) {
456 bool any_input_is_field_implicitly =
false;
458 field_dependency, *node);
459 for (
const bNodeSocket *input_socket : connected_inputs) {
460 if (!input_socket->is_available()) {
463 if (inferencing_interface.
inputs[input_socket->index()] ==
464 InputSocketFieldType::Implicit)
466 if (!input_socket->is_logically_linked()) {
467 any_input_is_field_implicitly =
true;
472 if (any_input_is_field_implicitly) {
474 state.requires_single =
false;
479 for (
const bNodeSocket *input_socket : connected_inputs) {
480 field_state_by_socket_id[input_socket->index_in_tree()].requires_single =
true;
487 for (
const bNodeSocket *input_socket : node->input_sockets()) {
489 if (inferencing_interface.
inputs[input_socket->index()] == InputSocketFieldType::None) {
490 state.requires_single =
true;
491 state.is_always_single =
true;
514 for (
const int index :
tree.interface_inputs().index_range()) {
519 new_inferencing_interface.
inputs[index] = InputSocketFieldType::None;
522 new_inferencing_interface.
inputs[index] = InputSocketFieldType::Implicit;
525 new_inferencing_interface.
inputs[index] = InputSocketFieldType::Implicit;
528 new_inferencing_interface.
inputs[index] = InputSocketFieldType::None;
534 for (
const bNode *node :
tree.group_input_nodes()) {
535 for (
const bNodeSocket *output_socket : node->output_sockets().drop_back(1)) {
537 const int output_index = output_socket->index();
538 if (
state.requires_single) {
539 if (new_inferencing_interface.
inputs[output_index] == InputSocketFieldType::Implicit) {
543 new_inferencing_interface.
inputs[output_index] = InputSocketFieldType::None;
548 for (
const bNode *node :
tree.group_input_nodes()) {
549 for (
const bNodeSocket *output_socket : node->output_sockets().drop_back(1)) {
551 const bool supports_field = new_inferencing_interface.
inputs[output_socket->index()] !=
552 InputSocketFieldType::None;
553 if (supports_field) {
554 state.is_single =
false;
555 state.is_field_source =
true;
558 state.requires_single =
true;
562 field_state_by_socket_id[node->output_sockets().last()->index_in_tree()];
576 bool need_update =
false;
578 for (
const bNode *node : toposort_result) {
579 if (node->is_group_input()) {
586 for (
const bNodeSocket *input_socket : node->input_sockets()) {
588 if (
state.is_always_single) {
589 state.is_single =
true;
592 state.is_single =
true;
593 if (!input_socket->is_directly_linked() ||
596 if (inferencing_interface.
inputs[input_socket->index()] ==
597 InputSocketFieldType::Implicit)
599 state.is_single =
false;
603 for (
const bNodeSocket *origin_socket : input_socket->directly_linked_sockets()) {
604 if (!field_state_by_socket_id[origin_socket->index_in_tree()].is_single) {
605 state.is_single =
false;
613 for (
const bNodeSocket *output_socket : node->output_sockets()) {
616 inferencing_interface.
outputs[output_socket->index()];
619 case OutputSocketFieldType::None: {
620 state.is_single =
true;
623 case OutputSocketFieldType::FieldSource: {
624 state.is_single =
false;
625 state.is_field_source =
true;
628 case OutputSocketFieldType::PartiallyDependent:
629 case OutputSocketFieldType::DependentField: {
633 if (!input_socket->is_available()) {
636 if (!field_state_by_socket_id[input_socket->index_in_tree()].is_single) {
637 state.is_single =
false;
664 const bNode *group_output_node =
tree.group_output_node();
665 if (!group_output_node) {
669 for (
const bNodeSocket *group_output_socket : group_output_node->input_sockets().drop_back(1)) {
671 *group_output_socket, interface_by_node, field_state_by_socket_id);
672 new_inferencing_interface.
outputs[group_output_socket->index()] = std::move(field_dependency);
680 if (
state.is_always_single) {
683 if (!
state.is_single) {
686 if (
state.requires_single) {
693 for (
const int i : field_state_by_socket_id.
index_range()) {
694 result[
i] = get_state_to_store(field_state_by_socket_id[
i]);
704 for (
const int i :
nodes.index_range()) {
712 tree.ensure_topology_cache();
713 tree.ensure_interface_cache();
721 std::unique_ptr<FieldInferencingInterface> new_inferencing_interface =
722 std::make_unique<FieldInferencingInterface>();
724 tree.interface_inputs().size(), InputSocketFieldType::IsSupported);
732 tree, interface_by_node, field_state_by_socket_id);
736 tree, *new_inferencing_interface, interface_by_node, field_state_by_socket_id);
739 const bool group_interface_changed = !
tree.runtime->field_inferencing_interface ||
740 *
tree.runtime->field_inferencing_interface !=
741 *new_inferencing_interface;
742 tree.runtime->field_inferencing_interface = std::move(new_inferencing_interface);
745 return group_interface_changed;
#define GEO_NODE_SIMULATION_OUTPUT
#define GEO_NODE_REPEAT_OUTPUT
#define GEO_NODE_REPEAT_INPUT
#define GEO_NODE_SIMULATION_INPUT
#define BLI_assert_unreachable()
#define ENUM_OPERATORS(_type, _max)
@ NODE_DEFAULT_INPUT_VALUE
@ NODE_INTERFACE_SOCKET_STRUCTURE_TYPE_SINGLE
BMesh const char void * data
T & construct(Args &&...args)
constexpr int64_t size() const
constexpr IndexRange index_range() const
void push(const T &value)
void append(const T &value)
void extend(Span< T > array)
void append_non_duplicates(const T &value)
static OutputFieldDependency ForPartiallyDependentField(Vector< int > indices)
static OutputFieldDependency ForDataSource()
static OutputFieldDependency ForDependentField()
static OutputFieldDependency ForFieldSource()
Vector< SocketDeclaration * > inputs
Vector< SocketDeclaration * > outputs
Span< int > linked_input_indices() const
OutputSocketFieldType field_type() const
OutputFieldDependency output_field_dependency
InputSocketFieldType input_field_type
static void determine_group_output_states(const bNodeTree &tree, FieldInferencingInterface &new_inferencing_interface, const Span< const FieldInferencingInterface * > interface_by_node, const Span< SocketFieldState > field_state_by_socket_id)
static FieldStateSyncResult repeat_field_state_sync(const bNode &input_node, const bNode &output_node, const MutableSpan< SocketFieldState > field_state_by_socket_id)
static FieldStateSyncResult sync_field_states(SocketFieldState &a, SocketFieldState &b)
static InputSocketFieldType get_interface_input_field_type(const bNode &node, const bNodeSocket &socket)
static OutputFieldDependency get_interface_output_field_dependency(const bNode &node, const bNodeSocket &socket)
static bool all_dangling_reroutes(const Span< const bNodeSocket * > sockets)
static const FieldInferencingInterface & get_node_field_inferencing_interface(const bNode &node, ResourceScope &scope)
bool update_field_inferencing(const bNodeTree &tree)
static bool propagate_special_data_requirements(const bNodeTree &tree, const bNode &node, const MutableSpan< SocketFieldState > field_state_by_socket_id)
static bool is_field_socket_type(const bNodeSocket &socket)
static OutputFieldDependency find_group_output_dependencies(const bNodeSocket &group_output_socket, const Span< const FieldInferencingInterface * > interface_by_node, const Span< SocketFieldState > field_state_by_socket_id)
static void propagate_field_status_from_left_to_right(const bNodeTree &tree, const Span< const FieldInferencingInterface * > interface_by_node, const MutableSpan< SocketFieldState > field_state_by_socket_id)
static void propagate_data_requirements_from_right_to_left(const bNodeTree &tree, const Span< const FieldInferencingInterface * > interface_by_node, const MutableSpan< SocketFieldState > field_state_by_socket_id)
static FieldStateSyncResult simulation_nodes_field_state_sync(const bNode &input_node, const bNode &output_node, const MutableSpan< SocketFieldState > field_state_by_socket_id)
static Vector< const bNodeSocket * > gather_input_socket_dependencies(const OutputFieldDependency &field_dependency, const bNode &node)
static Array< FieldSocketState > calc_socket_states(const Span< SocketFieldState > field_state_by_socket_id)
static const FieldInferencingInterface & get_dummy_field_inferencing_interface(const bNode &node, ResourceScope &scope)
static void prepare_inferencing_interfaces(const Span< const bNode * > nodes, MutableSpan< const FieldInferencingInterface * > interface_by_node, ResourceScope &scope)
static void determine_group_input_states(const bNodeTree &tree, FieldInferencingInterface &new_inferencing_interface, const MutableSpan< SocketFieldState > field_state_by_socket_id)
bool node_tree_is_registered(const bNodeTree &ntree)
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
bool is_layer_selection_field(const bNodeTreeInterfaceSocket &socket)
bNodeSocketTypeHandle * typeinfo
bNodeTreeRuntimeHandle * runtime
Array< InputSocketFieldType > inputs
Array< OutputFieldDependency > outputs