[Bf-blender-cvs] [bd42f7c275c] functions: remove operation hash of functions, a more reliable system is necessary
Jacques Lucke
noreply at git.blender.org
Mon Feb 17 10:45:29 CET 2020
Commit: bd42f7c275c0fccc56496be052918887ae697659
Author: Jacques Lucke
Date: Sat Feb 15 17:52:52 2020 +0100
Branches: functions
https://developer.blender.org/rBbd42f7c275c0fccc56496be052918887ae697659
remove operation hash of functions, a more reliable system is necessary
===================================================================
M source/blender/functions/FN_multi_function.h
M source/blender/functions/intern/multi_function_network_optimization.cc
M source/blender/functions/intern/multi_functions/constants.cc
M source/blender/functions/intern/multi_functions/constants.h
M source/blender/functions/intern/multi_functions/customizable.h
M source/blender/functions/intern/multi_functions/global_functions.cc
M source/blender/functions/intern/multi_functions/mixed.cc
M source/blender/functions/intern/multi_functions/particles.cc
M source/blender/functions/intern/multi_functions/surface_hook.cc
M source/blender/functions/intern/multi_functions/vectorize.cc
M source/blender/functions/intern/node_tree_multi_function_network/mappings_nodes.cc
===================================================================
diff --git a/source/blender/functions/FN_multi_function.h b/source/blender/functions/FN_multi_function.h
index 33022b710b5..893d7a10354 100644
--- a/source/blender/functions/FN_multi_function.h
+++ b/source/blender/functions/FN_multi_function.h
@@ -24,7 +24,6 @@ struct MFSignatureData {
Vector<BLI::class_id_t> used_element_contexts;
Vector<BLI::class_id_t> used_global_contexts;
Vector<uint> param_data_indices;
- Optional<uint32_t> operation_hash;
uint data_index(uint param_index) const
{
@@ -151,26 +150,6 @@ class MFSignatureBuilder {
break;
}
}
-
- /* Operation Hash */
-
- void operation_hash(uint32_t hash)
- {
- m_data.operation_hash.set(hash);
- }
-
- void operation_hash(Optional<uint32_t> maybe_hash)
- {
- m_data.operation_hash = maybe_hash;
- }
-
- void operation_hash_per_class()
- {
- const std::type_info &type_info = typeid(*this);
- uintptr_t ptr = (uintptr_t)&type_info;
- uint32_t hash = (ptr * 56247945663) ^ (ptr >> 32);
- this->operation_hash(hash);
- }
};
class MFParams;
@@ -225,11 +204,6 @@ class MultiFunction {
return m_signature_data.used_global_contexts.contains(id);
}
- Optional<uint32_t> operation_hash() const
- {
- return m_signature_data.operation_hash;
- }
-
protected:
MFSignatureBuilder get_builder(StringRef function_name)
{
diff --git a/source/blender/functions/intern/multi_function_network_optimization.cc b/source/blender/functions/intern/multi_function_network_optimization.cc
index 0d8d1124e3f..c5d8fc319f7 100644
--- a/source/blender/functions/intern/multi_function_network_optimization.cc
+++ b/source/blender/functions/intern/multi_function_network_optimization.cc
@@ -12,96 +12,8 @@ namespace FN {
using BLI::MultiMap;
using BLI::Stack;
-void optimize_network__remove_duplicates(MFNetworkBuilder &network_builder)
+void optimize_network__remove_duplicates(MFNetworkBuilder &UNUSED(network_builder))
{
- Array<Optional<uint32_t>> hash_by_output_socket(network_builder.socket_id_amount());
- Array<bool> node_outputs_are_hashed(network_builder.node_id_amount(), false);
-
- RNG *rng = BLI_rng_new(0);
-
- for (MFBuilderDummyNode *node : network_builder.dummy_nodes()) {
- for (MFBuilderOutputSocket *output_socket : node->outputs()) {
- uint32_t output_hash = BLI_rng_get_uint(rng);
- hash_by_output_socket[output_socket->id()].set_new(output_hash);
- }
- node_outputs_are_hashed[node->id()] = true;
- }
-
- Stack<MFBuilderFunctionNode *> nodes_to_check = network_builder.function_nodes();
- while (!nodes_to_check.is_empty()) {
- MFBuilderFunctionNode &node = *nodes_to_check.peek();
- if (node_outputs_are_hashed[node.id()]) {
- nodes_to_check.pop();
- continue;
- }
-
- bool all_dependencies_ready = true;
- node.foreach_origin_node([&](MFBuilderNode &origin_node) {
- if (!node_outputs_are_hashed[origin_node.id()]) {
- all_dependencies_ready = false;
- nodes_to_check.push(&origin_node.as_function());
- }
- });
-
- if (!all_dependencies_ready) {
- continue;
- }
-
- uint32_t combined_inputs_hash = BLI_RAND_PER_LINE_UINT32;
- for (MFBuilderInputSocket *input_socket : node.inputs()) {
- MFBuilderOutputSocket *origin = input_socket->origin();
- uint32_t input_hash;
- if (origin == nullptr) {
- input_hash = BLI_rng_get_uint(rng);
- }
- else {
- input_hash = *hash_by_output_socket[origin->id()];
- }
-
- combined_inputs_hash = combined_inputs_hash * BLI_RAND_PER_LINE_UINT32 + input_hash;
- }
-
- Optional<uint32_t> maybe_operation_hash = node.function().operation_hash();
- uint32_t operation_hash = (maybe_operation_hash.has_value()) ? *maybe_operation_hash :
- BLI_rng_get_uint(rng);
- uint32_t node_hash = combined_inputs_hash * BLI_RAND_PER_LINE_UINT32 + operation_hash;
-
- for (MFBuilderOutputSocket *output_socket : node.outputs()) {
- uint32_t output_hash = node_hash *
- (45234 + BLI_RAND_PER_LINE_UINT32 * output_socket->index());
- hash_by_output_socket[output_socket->id()].set_new(output_hash);
- }
-
- nodes_to_check.pop();
- node_outputs_are_hashed[node.id()] = true;
- }
-
- MultiMap<uint32_t, MFBuilderOutputSocket *> outputs_by_hash;
- for (uint id : hash_by_output_socket.index_range()) {
- Optional<uint32_t> maybe_hash = hash_by_output_socket[id];
- if (maybe_hash.has_value()) {
- uint32_t hash = *maybe_hash;
- MFBuilderOutputSocket &socket = network_builder.socket_by_id(id).as_output();
- outputs_by_hash.add(hash, &socket);
- }
- }
-
- outputs_by_hash.foreach_item(
- [&](uint32_t UNUSED(hash), ArrayRef<MFBuilderOutputSocket *> outputs_with_hash) {
- if (outputs_with_hash.size() <= 1) {
- return;
- }
-
- MFBuilderOutputSocket &deduplicated_output = *outputs_with_hash[0];
- for (MFBuilderOutputSocket *socket : outputs_with_hash.drop_front(1)) {
- BLI::ScopedVector<MFBuilderInputSocket *> targets_copy = socket->targets();
- for (MFBuilderInputSocket *target : targets_copy) {
- network_builder.relink_origin(deduplicated_output, *target);
- }
- }
- });
-
- BLI_rng_free(rng);
}
void optimize_network__remove_unused_nodes(MFNetworkBuilder &network_builder)
diff --git a/source/blender/functions/intern/multi_functions/constants.cc b/source/blender/functions/intern/multi_functions/constants.cc
index 49ecf4f2507..0cf59b48da5 100644
--- a/source/blender/functions/intern/multi_functions/constants.cc
+++ b/source/blender/functions/intern/multi_functions/constants.cc
@@ -33,11 +33,6 @@ MF_GenericConstantValue::MF_GenericConstantValue(const CPPType &type, const void
std::stringstream ss;
MF_GenericConstantValue::value_to_string(ss, type, value);
signature.single_output(ss.str(), type);
-
- if (type == CPPType_float) {
- uint32_t hash = BLI_hash_int_2d(*(uint *)value, 0);
- signature.operation_hash(hash);
- }
}
void MF_GenericConstantValue::call(IndexMask mask,
diff --git a/source/blender/functions/intern/multi_functions/constants.h b/source/blender/functions/intern/multi_functions/constants.h
index 7d3a0264a41..1095c9442da 100644
--- a/source/blender/functions/intern/multi_functions/constants.h
+++ b/source/blender/functions/intern/multi_functions/constants.h
@@ -48,31 +48,6 @@ template<typename T> class MF_ConstantValue : public MultiFunction {
std::stringstream ss;
MF_GenericConstantValue::value_to_string(ss, CPP_TYPE<T>(), (const void *)&m_value);
signature.single_output<T>(ss.str());
-
- if (CPP_TYPE<T>() == CPPType_float) {
- uint32_t hash = BLI_hash_int_2d(*(uint *)&m_value, 0);
- signature.operation_hash(hash);
- }
- else if (CPP_TYPE<T>() == CPPType_int32) {
- uint32_t hash = BLI_hash_int_2d(*(uint *)&m_value, 1);
- signature.operation_hash(hash);
- }
- else if (CPP_TYPE<T>() == CPPType_string) {
- uint32_t hash = BLI_hash_string(((std::string *)&m_value)->c_str());
- signature.operation_hash(hash);
- }
- else if (CPP_TYPE<T>() == CPP_TYPE<BKE::ObjectIDHandle>()) {
- BKE::ObjectIDHandle object_handle = *(BKE::ObjectIDHandle *)&m_value;
- uint32_t hash = object_handle.internal_identifier() ^ BLI_RAND_PER_LINE_UINT32;
- signature.operation_hash(hash);
- }
- else if (CPP_TYPE<T>() == CPPType_float3) {
- BLI::float3 vector = *(BLI::float3 *)&value;
- uint32_t hash = BLI_hash_int_2d(*(uint *)&vector.x, 0);
- hash = BLI_hash_int_2d(*(uint *)&vector.y, hash);
- hash = BLI_hash_int_2d(*(uint *)&vector.z, hash);
- signature.operation_hash(hash);
- }
}
void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
diff --git a/source/blender/functions/intern/multi_functions/customizable.h b/source/blender/functions/intern/multi_functions/customizable.h
index f48e2a4da96..bbc2839d767 100644
--- a/source/blender/functions/intern/multi_functions/customizable.h
+++ b/source/blender/functions/intern/multi_functions/customizable.h
@@ -14,7 +14,6 @@ template<typename FromT, typename ToT> class MF_Convert : public MultiFunction {
CPP_TYPE<ToT>().name());
signature.single_input<FromT>("Input");
signature.single_output<ToT>("Output");
- signature.operation_hash_per_class();
}
void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
@@ -36,20 +35,16 @@ template<typename InT, typename OutT> class MF_Custom_In1_Out1 final : public Mu
FunctionT m_fn;
public:
- MF_Custom_In1_Out1(StringRef name, FunctionT fn, Optional<uint32_t> operation_hash = {})
- : m_fn(std::move(fn))
+ MF_Custom_In1_Out1(StringRef name, FunctionT fn) : m_fn(std::move(fn))
{
MFSignatureBuilder signature = this->get_builder(name);
signature.single_input<InT>("Input");
signature.single_output<OutT>("Output");
- signature.operation_hash(operation_hash);
}
template<typename ElementFuncT>
- MF_Custom_In1_Out1(StringRef name,
- ElementFuncT element_fn,
- Optional<uint32_t> operation_hash = {})
- : MF_Custom_In1_Out1(name, MF_Custom_In1_Out1::create_function(element_fn), operation_hash)
+ MF_Custom_In1_Out1(StringRef name, ElementFuncT element_fn)
+ : MF_Custom_In1_Out1(name, MF_Custom_In1_Out1::create_function(element_fn))
{
}
@@ -87,21 +82,17 @@ class MF_Custom_In2_Out1 final : public MultiFunction {
FunctionT m_fn;
public:
- MF_Custom_In2_Out1(StringRef name, FunctionT fn, Optional<uint32_t> operation_hash = {})
- : m_fn(std::move(fn))
+ MF_Custom_In2_Out1(StringRef name, FunctionT fn) : m_fn(std::move(fn))
{
MFSignatureBuilder signature = this->get_builder(name);
signature.single_input<InT1>("Input 1");
signature.single_input<InT2>("Input 2");
signature.single_output<OutT>("Output");
- signature.operation_hash(operation_hash);
}
template<typename ElementFuncT>
- MF_Custom_In2_Out1(StringRef name,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list