[Bf-blender-cvs] [1824b8fb52a] functions: make single element execution work again
Jacques Lucke
noreply at git.blender.org
Mon Jan 27 22:10:25 CET 2020
Commit: 1824b8fb52aa433902e17d2e12cf29dc9500640c
Author: Jacques Lucke
Date: Sun Jan 26 21:56:41 2020 +0100
Branches: functions
https://developer.blender.org/rB1824b8fb52aa433902e17d2e12cf29dc9500640c
make single element execution work again
===================================================================
M source/blender/functions/intern/multi_functions/network.cc
M source/blender/functions/intern/multi_functions/network.h
===================================================================
diff --git a/source/blender/functions/intern/multi_functions/network.cc b/source/blender/functions/intern/multi_functions/network.cc
index 731ce524e3c..b27a842e562 100644
--- a/source/blender/functions/intern/multi_functions/network.cc
+++ b/source/blender/functions/intern/multi_functions/network.cc
@@ -31,6 +31,7 @@ struct VectorFromCallerValue : public OutputValue {
struct SingleValue : public OutputValue {
GenericMutableArrayRef array_ref;
int max_remaining_users;
+ bool is_single_allocated;
};
struct VectorValue : public OutputValue {
@@ -44,14 +45,16 @@ class NetworkEvaluationStorage {
ArrayAllocator &m_array_allocator;
IndexMask m_mask;
Array<OutputValue *> m_value_per_output_id;
+ uint m_min_array_size;
public:
NetworkEvaluationStorage(ArrayAllocator &array_allocator, IndexMask mask, uint socket_id_amount)
: m_array_allocator(array_allocator),
m_mask(mask),
- m_value_per_output_id(socket_id_amount, nullptr)
+ m_value_per_output_id(socket_id_amount, nullptr),
+ m_min_array_size(mask.min_array_size())
{
- BLI_assert(array_allocator.array_size() >= mask.min_array_size());
+ BLI_assert(array_allocator.array_size() >= m_min_array_size);
}
~NetworkEvaluationStorage()
@@ -62,9 +65,15 @@ class NetworkEvaluationStorage {
}
else if (any_value->type == OutputValueType::Single) {
SingleValue *value = (SingleValue *)any_value;
- const CPPType &type = value->array_ref.type();
- type.destruct_indices(value->array_ref.buffer(), m_mask);
- m_array_allocator.deallocate(type.size(), value->array_ref.buffer());
+ GenericMutableArrayRef array_ref = value->array_ref;
+ const CPPType &type = array_ref.type();
+ if (value->is_single_allocated) {
+ type.destruct(array_ref.buffer());
+ }
+ else {
+ type.destruct_indices(value->array_ref.buffer(), m_mask);
+ m_array_allocator.deallocate(type.size(), value->array_ref.buffer());
+ }
}
else if (any_value->type == OutputValueType::Vector) {
VectorValue *value = (VectorValue *)any_value;
@@ -81,6 +90,7 @@ class NetworkEvaluationStorage {
void add_single_from_caller(const MFOutputSocket &socket, GenericVirtualListRef list_ref)
{
BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
+ BLI_assert(list_ref.size() >= m_min_array_size);
auto *value = m_monotonic_allocator.allocate<SingleFromCallerValue>();
m_value_per_output_id[socket.id()] = value;
@@ -92,6 +102,7 @@ class NetworkEvaluationStorage {
GenericVirtualListListRef list_list_ref)
{
BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
+ BLI_assert(list_list_ref.size() >= m_min_array_size);
auto *value = m_monotonic_allocator.allocate<VectorFromCallerValue>();
m_value_per_output_id[socket.id()] = value;
@@ -106,12 +117,29 @@ class NetworkEvaluationStorage {
auto *value = m_monotonic_allocator.allocate<SingleValue>();
m_value_per_output_id[socket.id()] = value;
value->type = OutputValueType::Single;
+ value->max_remaining_users = socket.targets().size();
+ value->is_single_allocated = false;
const CPPType &type = socket.data_type().single__cpp_type();
void *buffer = m_array_allocator.allocate(type.size(), type.alignment());
- value->array_ref = GenericMutableArrayRef(type, buffer, m_mask.min_array_size());
+ value->array_ref = GenericMutableArrayRef(type, buffer, m_min_array_size);
+ return value->array_ref;
+ }
+
+ GenericMutableArrayRef allocate_single_output__scalar(const MFOutputSocket &socket)
+ {
+ BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
+
+ auto *value = m_monotonic_allocator.allocate<SingleValue>();
+ m_value_per_output_id[socket.id()] = value;
+ value->type = OutputValueType::Single;
value->max_remaining_users = socket.targets().size();
+ value->is_single_allocated = true;
+
+ const CPPType &type = socket.data_type().single__cpp_type();
+ void *buffer = m_monotonic_allocator.allocate(type.size(), type.alignment());
+ value->array_ref = GenericMutableArrayRef(type, buffer, 1);
return value->array_ref;
}
@@ -123,13 +151,28 @@ class NetworkEvaluationStorage {
auto *value = m_monotonic_allocator.allocate<VectorValue>();
m_value_per_output_id[socket.id()] = value;
value->type = OutputValueType::Vector;
+ value->max_remaining_users = socket.targets().size();
const CPPType &type = socket.data_type().vector__cpp_base_type();
- GenericVectorArray *vector_array = new GenericVectorArray(type, m_mask.min_array_size());
+ GenericVectorArray *vector_array = new GenericVectorArray(type, m_min_array_size);
value->vector_array = vector_array;
+ return *value->vector_array;
+ }
+
+ GenericVectorArray &allocate_vector_output__scalar(const MFOutputSocket &socket)
+ {
+ BLI_assert(m_value_per_output_id[socket.id()] == nullptr);
+
+ auto *value = m_monotonic_allocator.allocate<VectorValue>();
+ m_value_per_output_id[socket.id()] = value;
+ value->type = OutputValueType::Vector;
value->max_remaining_users = socket.targets().size();
+ const CPPType &type = socket.data_type().vector__cpp_base_type();
+ GenericVectorArray *vector_array = new GenericVectorArray(type, 1);
+ value->vector_array = vector_array;
+
return *value->vector_array;
}
@@ -156,11 +199,12 @@ class NetworkEvaluationStorage {
m_value_per_output_id[to.id()] = new_value;
new_value->type = OutputValueType::Single;
new_value->max_remaining_users = to.targets().size();
+ new_value->is_single_allocated = false;
const CPPType &type = from.data_type().single__cpp_type();
void *new_buffer = m_array_allocator.allocate(type.size(), type.alignment());
type.copy_to_uninitialized_indices(value->array_ref.buffer(), new_buffer, m_mask);
- new_value->array_ref = GenericMutableArrayRef(type, new_buffer, m_mask.min_array_size());
+ new_value->array_ref = GenericMutableArrayRef(type, new_buffer, m_min_array_size);
return new_value->array_ref;
}
}
@@ -170,10 +214,11 @@ class NetworkEvaluationStorage {
m_value_per_output_id[to.id()] = new_value;
new_value->type = OutputValueType::Single;
new_value->max_remaining_users = to.targets().size();
+ new_value->is_single_allocated = false;
const CPPType &type = from.data_type().single__cpp_type();
void *new_buffer = m_array_allocator.allocate(type.size(), type.alignment());
- new_value->array_ref = GenericMutableArrayRef(type, new_buffer, m_mask.min_array_size());
+ new_value->array_ref = GenericMutableArrayRef(type, new_buffer, m_min_array_size);
value->list_ref.materialize_to_uninitialized(m_mask, new_value->array_ref);
return new_value->array_ref;
}
@@ -182,6 +227,58 @@ class NetworkEvaluationStorage {
return GenericMutableArrayRef(CPP_TYPE<float>());
}
+ GenericMutableArrayRef get_mutable_single__scalar(const MFInputSocket &input,
+ const MFOutputSocket &output)
+ {
+ const MFOutputSocket &from = input.origin();
+ const MFOutputSocket &to = output;
+
+ OutputValue *any_value = m_value_per_output_id[from.id()];
+ BLI_assert(any_value != nullptr);
+ BLI_assert(from.data_type().single__cpp_type() == to.data_type().single__cpp_type());
+
+ if (any_value->type == OutputValueType::Single) {
+ SingleValue *value = (SingleValue *)any_value;
+ if (value->max_remaining_users == 1) {
+ m_value_per_output_id[to.id()] = value;
+ m_value_per_output_id[from.id()] = nullptr;
+ value->max_remaining_users = to.targets().size();
+ BLI_assert(value->array_ref.size() == 1);
+ return value->array_ref;
+ }
+ else {
+ SingleValue *new_value = m_monotonic_allocator.allocate<SingleValue>();
+ m_value_per_output_id[to.id()] = new_value;
+ new_value->type = OutputValueType::Single;
+ new_value->max_remaining_users = to.targets().size();
+ new_value->is_single_allocated = true;
+
+ const CPPType &type = from.data_type().single__cpp_type();
+ void *new_buffer = m_monotonic_allocator.allocate(type.size(), type.alignment());
+ type.copy_to_uninitialized(value->array_ref[0], new_buffer);
+ new_value->array_ref = GenericMutableArrayRef(type, new_buffer, 1);
+ return new_value->array_ref;
+ }
+ }
+ else if (any_value->type == OutputValueType::SingleFromCaller) {
+ SingleFromCallerValue *value = (SingleFromCallerValue *)any_value;
+ SingleValue *new_value = m_monotonic_allocator.allocate<SingleValue>();
+ m_value_per_output_id[to.id()] = new_value;
+ new_value->type = OutputValueType::Single;
+ new_value->max_remaining_users = to.targets().size();
+ new_value->is_single_allocated = true;
+
+ const CPPType &type = from.data_type().single__cpp_type();
+ void *new_buffer = m_monotonic_allocator.allocate(type.size(), type.alignment());
+ type.copy_to_uninitialized(value->list_ref.as_single_element(), new_buffer);
+ new_value->array_ref = GenericMutableArrayRef(type, new_buffer, 1);
+ return new_value->array_ref;
+ }
+
+ BLI_assert(false);
+ return GenericMutableArrayRef(CPP_TYPE<float>());
+ }
+
GenericVectorArray &get_mutable_vector(const MFInputSocket &input, const MFOutputSocket &output)
{
const MFOutputSocket &from = input.origin();
@@ -206,9 +303,8 @@ class NetworkEvaluationStorage {
new_value->max_remaining_users = to.targets().size();
const CPPType &base_type = to.data_type().vector__cpp_base_type();
- new_value->vector_array = new GenericVectorArray(base_type, m_mask.min_array_size());
+ new_value->vector_array = new GenericVectorArray(base_type, m_min_array_size);
new_value->vector_array->extend_multiple__copy(m_mask, *value->vector_array);
-
return *new_value->vector_array;
}
}
@@ -220,12 +316,55 @@ class NetworkEvalu
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list