Files
test2/source/blender/blenkernel/BKE_node_tree_anonymous_attributes.hh
Jacques Lucke 7b61dcf6bc Geometry Nodes: deduplicate anonymous attribute analysis algorithm
Previously, there were two independent algorithms for analysing how anonymous
attributes are used in a node tree: One that just computed the `aal::RelationsInNode`
for an entire node tree and one that performed a more in depth analysis to
determine how far anonymous attributes should be propagated.

As it turns out, both operations can also be done at the same time and the result
can be cached on the node tree. This reduces the amount of code and allows for
better code reuse.

This simplification is likely only an intermediate step as things will probably have
to be refactored further to support e.g. serial loops (#108896).
2023-06-14 14:04:22 +02:00

81 lines
2.7 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include <variant>
#include "DNA_node_types.h"
#include "BLI_bit_group_vector.hh"
#include "BLI_vector.hh"
#include "NOD_node_declaration.hh"
namespace blender::bke::anonymous_attribute_inferencing {
/** Represents a group input socket that may be a field. */
struct InputFieldSource {
int input_index;
};
/** Represents an output of a node that is a field which may contain a new anonymous attribute. */
struct SocketFieldSource {
const bNodeSocket *socket;
};
struct FieldSource {
std::variant<InputFieldSource, SocketFieldSource> data;
/** Geometry source which may contain the anonymous attributes referenced by this field. */
Vector<int> geometry_sources;
};
/** Represents a geometry group input. */
struct InputGeometrySource {
int input_index;
};
/** Represents a geometry output of a node that may contain a new anonymous attribute. */
struct SocketGeometrySource {
const bNodeSocket *socket;
};
struct GeometrySource {
std::variant<InputGeometrySource, SocketGeometrySource> data;
/** Field sources that originate in this geometry source. */
Vector<int> field_sources;
};
struct AnonymousAttributeInferencingResult {
/** All field sockets that may introduce new anonymous attributes into the node tree. */
Vector<FieldSource> all_field_sources;
/** All geometry sockets that may introduce new anonymous attributes into the node tree. */
Vector<GeometrySource> all_geometry_sources;
/** Encodes which field sources are propagated to every field socket. */
BitGroupVector<> propagated_fields_by_socket;
/** Encodes which geometry sources are propagated to every geometry socket. */
BitGroupVector<> propagated_geometries_by_socket;
/** Encodes which field sources may be available on every geometry socket. */
BitGroupVector<> available_fields_by_geometry_socket;
/**
* Encodes which field sources have to be propagated to each geometry socket at run-time to
* ensure correct evaluation.
*/
BitGroupVector<> required_fields_by_geometry_socket;
/** Set of geometry output indices which may propagate attributes from input geometries. */
VectorSet<int> propagated_output_geometry_indices;
/** Encodes to which group outputs a geometry is propagated to. */
BitGroupVector<> propagate_to_output_by_geometry_socket;
nodes::aal::RelationsInNode tree_relations;
};
Array<const nodes::aal::RelationsInNode *> get_relations_by_node(const bNodeTree &tree,
ResourceScope &scope);
bool update_anonymous_attribute_relations(bNodeTree &tree);
} // namespace blender::bke::anonymous_attribute_inferencing