43 if (tag != new_value) {
57 is_to_the_left[
node->id()] =
true;
66 if (origin !=
nullptr) {
69 nodes_to_check.
push(&origin_node);
75 return is_to_the_left;
84 is_to_the_right[
node->id()] =
true;
92 for (
MFInputSocket *target_socket : output_socket->targets()) {
93 MFNode &target_node = target_socket->node();
95 nodes_to_check.
push(&target_node);
101 return is_to_the_right;
110 if (id_mask[
id] == mask_value) {
112 if (
node !=
nullptr) {
134 network.
remove(nodes_to_remove);
145 if (
node->has_unlinked_inputs()) {
148 if (
node->function().depends_on_context()) {
164 return non_constant_nodes;
171 MFNode &target_node = target_socket->node();
172 bool target_is_not_constant = is_not_constant_mask[target_node.
id()];
173 if (target_is_not_constant) {
183 if (target_socket->node().is_dummy()) {
184 return target_socket;
199 if (
node->inputs().size() == 0) {
204 MFDataType data_type = output_socket->data_type();
207 if (dummy_target ==
nullptr) {
208 dummy_target = &network.
add_output(
"Dummy", data_type);
209 network.
add_link(*output_socket, *dummy_target);
213 sockets_to_compute.
append(dummy_target);
217 return sockets_to_compute;
241 params.add_vector_output(vector_array);
280 folded_sockets[param_index] = &folded_node.
output(0);
282 return folded_sockets;
308 if (inputs_to_fold.
size() == 0) {
313 network, inputs_to_fold, scope);
317 network.
relink(original_socket, *folded_sockets[i]);
331 if (
node.function().depends_on_context()) {
334 if (
node.has_unlinked_inputs()) {
338 uint64_t combined_inputs_hash = 394659347u;
342 origin_socket->
index());
364 node_hashes[
node->id()] = node_hash;
365 node_is_hashed[
node->id()] =
true;
371 while (!nodes_to_check.
is_empty()) {
373 if (node_is_hashed[
node.id()]) {
374 nodes_to_check.
pop();
379 bool all_dependencies_ready =
true;
382 if (origin_socket !=
nullptr) {
384 if (!node_is_hashed[origin_node.
id()]) {
385 all_dependencies_ready =
false;
390 if (!all_dependencies_ready) {
395 node_hashes[
node.id()] = node_hash;
396 node_is_hashed[
node.id()] =
true;
397 nodes_to_check.
pop();
410 if (
node !=
nullptr) {
412 nodes_by_hash.
add(node_hash,
node);
415 return nodes_by_hash;
423 if (
typeid(
a) ==
typeid(b)) {
441 for (
int i :
a.inputs().index_range()) {
444 if (origin_a ==
nullptr || origin_b ==
nullptr) {
462 if (nodes_with_same_hash.size() <= 1) {
467 while (nodes_to_check.
size() >= 2) {
470 MFNode &deduplicated_node = *nodes_to_check[0];
475 for (
int i : deduplicated_node.
outputs().index_range()) {
483 nodes_to_check = std::move(remaining_nodes);
size_t BLI_ghashutil_combine_hash(size_t hash_a, size_t hash_b)
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
unsigned int BLI_rng_get_uint(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
struct RNG * BLI_rng_new(unsigned int seed)
void join(int64_t x, int64_t y)
bool in_same_set(int64_t x, int64_t y)
constexpr int64_t size() const
void * allocate(const int64_t size, const int64_t alignment)
void add(const Key &key, const Value &value)
MapType::ValueIterator values() const
T & construct(const char *name, Args &&... args)
LinearAllocator & linear_allocator()
T * add(std::unique_ptr< T > resource, const char *name)
constexpr IndexRange index_range() const
void push(const T &value)
void push_multiple(Span< T > values)
void append(const T &value)
Span< T > as_span() const
IndexRange index_range() const
void extend(Span< T > array)
int64_t alignment() const
const CPPType & vector_base_type() const
const CPPType & single_type() const
Category category() const
const MultiFunction & function() const
Span< MFFunctionNode * > function_nodes()
void remove(MFNode &node)
void relink(MFOutputSocket &old_output, MFOutputSocket &new_output)
Span< MFDummyNode * > dummy_nodes()
MFNode * node_or_null_by_id(int id)
void add_link(MFOutputSocket &from, MFInputSocket &to)
MFFunctionNode & add_function(const MultiFunction &function)
MFInputSocket & add_output(StringRef name, MFDataType data_type)
int node_id_amount() const
MFOutputSocket & output(int index)
MFInputSocket & input(int index)
MFFunctionNode & as_function()
Span< MFOutputSocket * > outputs()
Span< MFInputSocket * > targets()
MFDataType data_type() const
MFParamType param_type(int param_index) const
IndexRange param_indices() const
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
static Array< uint64_t > compute_node_hashes(MFNetwork &network)
static bool nodes_output_same_values(DisjointSet &cache, const MFNode &a, const MFNode &b)
static Vector< MFNode * > find_nodes_based_on_mask(MFNetwork &network, Span< bool > id_mask, bool mask_value)
static bool function_node_can_be_constant(MFFunctionNode *node)
void common_subnetwork_elimination(MFNetwork &network)
static void relink_duplicate_nodes(MFNetwork &network, MultiValueMap< uint64_t, MFNode * > &nodes_by_hash)
void constant_folding(MFNetwork &network, ResourceScope &scope)
static bool set_tag_and_check_if_modified(bool &tag, bool new_value)
static bool functions_are_equal(const MultiFunction &a, const MultiFunction &b)
static Vector< MFNode * > find_non_constant_nodes(MFNetwork &network)
static uint64_t compute_node_hash(MFFunctionNode &node, RNG *rng, Span< uint64_t > node_hashes)
static MFInputSocket * try_find_dummy_target_socket(MFOutputSocket *output_socket)
static Array< bool > mask_nodes_to_the_right(MFNetwork &network, Span< MFNode * > nodes)
static Array< MFOutputSocket * > add_constant_folded_sockets(const MultiFunction &network_fn, MFParamsBuilder ¶ms, ResourceScope &scope, MFNetwork &network)
static Array< MFOutputSocket * > compute_constant_sockets_and_add_folded_nodes(MFNetwork &network, Span< const MFInputSocket * > sockets_to_compute, ResourceScope &scope)
static bool output_has_non_constant_target_node(MFOutputSocket *output_socket, Span< bool > is_not_constant_mask)
void dead_node_removal(MFNetwork &network)
static void prepare_params_for_constant_folding(const MultiFunction &network_fn, MFParamsBuilder ¶ms, ResourceScope &scope)
static Vector< MFInputSocket * > find_constant_inputs_to_fold(MFNetwork &network, Vector< MFDummyNode * > &r_temporary_nodes)
static MultiValueMap< uint64_t, MFNode * > group_nodes_by_hash(MFNetwork &network, Span< uint64_t > node_hashes)
static Array< bool > mask_nodes_to_the_left(MFNetwork &network, Span< MFNode * > nodes)
struct SELECTID_Context context
unsigned __int64 uint64_t