18using nodes::FieldInferencingInterface;
20using nodes::NodeDeclaration;
21using nodes::OutputFieldDependency;
23using nodes::SocketDeclaration;
33 if (!socket->owner_node().is_dangling_reroute()) {
44 return InputSocketFieldType::None;
47 return InputSocketFieldType::IsSupported;
51 return InputSocketFieldType::IsSupported;
54 return InputSocketFieldType::None;
57 return InputSocketFieldType::None;
77 return OutputFieldDependency::ForDataSource();
81 return OutputFieldDependency::ForDependentField();
85 return OutputFieldDependency::ForDependentField();
88 return OutputFieldDependency::ForDataSource();
91 return OutputFieldDependency::ForDataSource();
109 node.input_sockets().size());
110 inferencing_interface.outputs.append_n_times(OutputFieldDependency::ForDataSource(),
111 node.output_sockets().size());
112 return inferencing_interface;
124 if (node.is_group()) {
126 if (group ==
nullptr) {
128 return empty_interface;
134 if (!group->runtime->field_inferencing_interface) {
138 return *group->runtime->field_inferencing_interface;
142 for (
const bNodeSocket *input_socket : node.input_sockets()) {
146 for (
const bNodeSocket *output_socket : node.output_sockets()) {
147 inferencing_interface.outputs.append(
150 return inferencing_interface;
171 const OutputFieldDependency &field_dependency,
const bNode &node)
173 const OutputSocketFieldType type = field_dependency.field_type();
176 case OutputSocketFieldType::FieldSource:
177 case OutputSocketFieldType::None: {
180 case OutputSocketFieldType::DependentField: {
182 input_sockets.
extend(node.input_sockets());
185 case OutputSocketFieldType::PartiallyDependent: {
187 for (
const int i : field_dependency.linked_input_indices()) {
188 input_sockets.
append(&node.input_socket(i));
193 return input_sockets;
206 return OutputFieldDependency::ForDataSource();
214 handled_sockets.
add(&group_output_socket);
215 sockets_to_check.
push(&group_output_socket);
220 while (!sockets_to_check.
is_empty()) {
223 if (!input_socket->is_directly_linked() &&
224 !field_state_by_socket_id[input_socket->index_in_tree()].is_single)
227 return OutputFieldDependency::ForFieldSource();
230 for (
const bNodeSocket *origin_socket : input_socket->directly_linked_sockets()) {
231 const bNode &origin_node = origin_socket->owner_node();
233 field_state_by_socket_id[origin_socket->index_in_tree()];
242 return OutputFieldDependency::ForFieldSource();
247 *interface_by_node[origin_node.index()];
248 const OutputFieldDependency &field_dependency =
249 inferencing_interface.
outputs[origin_socket->index()];
255 if (!origin_input_socket->is_available()) {
258 if (!field_state_by_socket_id[origin_input_socket->index_in_tree()].is_single) {
259 if (handled_sockets.
add(origin_input_socket)) {
260 sockets_to_check.
push(origin_input_socket);
267 return OutputFieldDependency::ForPartiallyDependentField(std::move(linked_input_indices));
288 const bool requires_single = a.requires_single ||
b.requires_single;
289 const bool is_single = a.is_single &&
b.is_single;
292 if (a.requires_single != requires_single || a.is_single != is_single) {
295 if (
b.requires_single != requires_single ||
b.is_single != is_single) {
299 a.requires_single = requires_single;
300 b.requires_single = requires_single;
301 a.is_single = is_single;
302 b.is_single = is_single;
313 const bNode &input_node,
314 const bNode &output_node,
318 for (
const int i : output_node.output_sockets().index_range()) {
320 const bNodeSocket &input_socket = input_node.output_socket(i + 1);
321 const bNodeSocket &output_socket = output_node.output_socket(i);
322 SocketFieldState &input_state = field_state_by_socket_id[input_socket.index_in_tree()];
323 SocketFieldState &output_state = field_state_by_socket_id[output_socket.index_in_tree()];
330 const bNode &input_node,
331 const bNode &output_node,
338 const bNodeSocket &input_socket = input_node.output_socket(i + 1);
339 const bNodeSocket &output_socket = output_node.output_socket(i);
340 SocketFieldState &input_state = field_state_by_socket_id[input_socket.index_in_tree()];
341 SocketFieldState &output_state = field_state_by_socket_id[output_socket.index_in_tree()];
352 tree.ensure_topology_cache();
354 bool need_update =
false;
361 if (
const bNode *output_node =
tree.node_by_id(data.output_node_id)) {
363 node, *output_node, field_state_by_socket_id);
371 for (
const bNode *input_node :
tree.nodes_by_type(
"GeometryNodeSimulationInput")) {
374 if (node.identifier == data.output_node_id) {
376 *input_node, node, field_state_by_socket_id);
387 if (
const bNode *output_node =
tree.node_by_id(data.output_node_id)) {
389 node, *output_node, field_state_by_socket_id);
397 for (
const bNode *input_node :
tree.nodes_by_type(
"GeometryNodeRepeatInput")) {
399 input_node->storage);
400 if (node.identifier == data.output_node_id) {
402 *input_node, node, field_state_by_socket_id);
425 bool need_update =
false;
427 for (
const bNode *node : toposort_result) {
430 for (
const bNodeSocket *output_socket : node->output_sockets()) {
433 const OutputFieldDependency &field_dependency =
434 inferencing_interface.
outputs[output_socket->index()];
436 if (field_dependency.field_type() == OutputSocketFieldType::FieldSource) {
439 if (field_dependency.field_type() == OutputSocketFieldType::None) {
440 state.requires_single =
true;
441 state.is_always_single =
true;
447 for (
const bNodeSocket *target_socket : output_socket->directly_linked_sockets()) {
448 if (target_socket->is_available()) {
449 state.requires_single |=
450 field_state_by_socket_id[target_socket->index_in_tree()].requires_single;
454 if (
state.requires_single) {
455 bool any_input_is_field_implicitly =
false;
457 field_dependency, *node);
458 for (
const bNodeSocket *input_socket : connected_inputs) {
459 if (!input_socket->is_available()) {
462 if (inferencing_interface.
inputs[input_socket->index()] ==
463 InputSocketFieldType::Implicit)
465 if (!input_socket->is_logically_linked()) {
466 any_input_is_field_implicitly =
true;
471 if (any_input_is_field_implicitly) {
473 state.requires_single =
false;
478 for (
const bNodeSocket *input_socket : connected_inputs) {
479 field_state_by_socket_id[input_socket->index_in_tree()].requires_single =
true;
486 for (
const bNodeSocket *input_socket : node->input_sockets()) {
488 if (inferencing_interface.
inputs[input_socket->index()] == InputSocketFieldType::None) {
489 state.requires_single =
true;
490 state.is_always_single =
true;
513 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) {
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()) {
615 const OutputFieldDependency &field_dependency =
616 inferencing_interface.
outputs[output_socket->index()];
618 switch (field_dependency.field_type()) {
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) {
694 const_cast<bNodeSocket *
>(socket)->runtime->field_state = get_state_to_store(
state);
703 for (
const int i : nodes.index_range()) {
711 tree.ensure_topology_cache();
712 tree.ensure_interface_cache();
720 std::unique_ptr<FieldInferencingInterface> new_inferencing_interface =
721 std::make_unique<FieldInferencingInterface>();
722 new_inferencing_interface->inputs.resize(
tree.interface_inputs().size(),
723 InputSocketFieldType::IsSupported);
724 new_inferencing_interface->outputs.resize(
tree.interface_outputs().size(),
725 OutputFieldDependency::ForDataSource());
731 tree, interface_by_node, field_state_by_socket_id);
735 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);
744 return group_interface_changed;
#define NODE_GROUP_OUTPUT
#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_INTERFACE_SOCKET_SINGLE_VALUE_ONLY
#define NODE_INPUT_DEFAULT_VALUE
T & construct(Args &&...args)
void push(const T &value)
void append(const T &value)
void extend(Span< T > array)
void append_non_duplicates(const T &value)
void append_n_times(const T &value, const int64_t n)
Vector< SocketDeclaration * > inputs
Vector< SocketDeclaration * > outputs
OutputFieldDependency output_field_dependency
InputSocketFieldType input_field_type
local_group_size(16, 16) .push_constant(Type b
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 void update_socket_states(const bNodeTree &tree, const Span< SocketFieldState > field_state_by_socket_id)
static InputSocketFieldType get_interface_input_field_type(const bNode &node, const bNodeSocket &socket)
static eFieldStateSyncResult sync_field_states(SocketFieldState &a, SocketFieldState &b)
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 Vector< const bNodeSocket * > gather_input_socket_dependencies(const OutputFieldDependency &field_dependency, const bNode &node)
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)
static eFieldStateSyncResult repeat_field_state_sync(const bNode &input_node, const bNode &output_node, const MutableSpan< SocketFieldState > field_state_by_socket_id)
static eFieldStateSyncResult simulation_nodes_field_state_sync(const bNode &input_node, const bNode &output_node, const MutableSpan< SocketFieldState > field_state_by_socket_id)
bNodeType NodeTypeUndefined
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
Vector< OutputFieldDependency > outputs
Vector< InputSocketFieldType > inputs