[Bf-blender-cvs] [0099355bc6b] functions: continue with ParticleSet
Jacques Lucke
noreply at git.blender.org
Thu Jan 2 16:37:48 CET 2020
Commit: 0099355bc6bc1794d04fbcafb7a269bf593e728c
Author: Jacques Lucke
Date: Tue Dec 31 16:48:01 2019 +0100
Branches: functions
https://developer.blender.org/rB0099355bc6bc1794d04fbcafb7a269bf593e728c
continue with ParticleSet
===================================================================
M source/blender/functions/CMakeLists.txt
D source/blender/functions/FN_attributes_block_container.h
M source/blender/functions/FN_attributes_ref.h
D source/blender/functions/intern/attributes_block_container.cc
M source/blender/functions/intern/attributes_ref.cc
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/node_frontend.cpp
M source/blender/simulations/bparticles/particle_allocator.cpp
M source/blender/simulations/bparticles/particle_allocator.hpp
M source/blender/simulations/bparticles/particle_set.cpp
M source/blender/simulations/bparticles/particle_set.hpp
M source/blender/simulations/bparticles/particles_state.cpp
M source/blender/simulations/bparticles/particles_state.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 19034a59133..99e9678f38d 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -35,7 +35,6 @@ set(SRC
intern/node_tree_multi_function_network/mappings_nodes.cc
intern/node_tree_multi_function_network/mappings_sockets.cc
intern/node_tree_multi_function_network/mappings.cc
- intern/attributes_block_container.cc
intern/attributes_ref.cc
intern/cpp_type.cc
intern/cpp_types.cc
@@ -47,7 +46,6 @@ set(SRC
intern/multi_function_network.cc
intern/node_tree.cc
- FN_attributes_block_container.h
FN_attributes_ref.h
FN_cpp_type.h
FN_generic_array_ref.h
diff --git a/source/blender/functions/FN_attributes_block_container.h b/source/blender/functions/FN_attributes_block_container.h
deleted file mode 100644
index 0d44d070584..00000000000
--- a/source/blender/functions/FN_attributes_block_container.h
+++ /dev/null
@@ -1,139 +0,0 @@
-#ifndef __FN_ATTRIBUTES_BLOCK_CONTAINER_H__
-#define __FN_ATTRIBUTES_BLOCK_CONTAINER_H__
-
-#include <mutex>
-
-#include "FN_attributes_ref.h"
-
-namespace FN {
-
-class AttributesBlock;
-
-class AttributesBlockContainer : BLI::NonCopyable, BLI::NonMovable {
- private:
- std::unique_ptr<AttributesInfo> m_info;
- uint m_block_size;
- VectorSet<AttributesBlock *> m_active_blocks;
- std::mutex m_blocks_mutex;
-
- public:
- AttributesBlockContainer(const AttributesInfoBuilder &info_builder, uint block_size);
- ~AttributesBlockContainer();
-
- const AttributesInfo &info() const
- {
- return *m_info;
- }
-
- uint block_size() const
- {
- return m_block_size;
- }
-
- ArrayRef<AttributesBlock *> active_blocks()
- {
- return m_active_blocks;
- }
-
- uint count_active() const;
-
- template<typename T> Vector<T> flatten_attribute(StringRef name) const;
- void flatten_attribute(StringRef name, GenericMutableArrayRef dst) const;
-
- void update_attributes(const AttributesInfoBuilder &new_info_builder);
-
- AttributesBlock &new_block();
- void release_block(AttributesBlock &block);
-
- friend bool operator==(const AttributesBlockContainer &a, const AttributesBlockContainer &b)
- {
- return &a == &b;
- }
-};
-
-class AttributesBlock : BLI::NonCopyable, BLI::NonMovable {
- private:
- AttributesBlockContainer &m_owner;
- Vector<void *> m_buffers;
- uint m_used_size;
-
- friend AttributesBlockContainer;
-
- public:
- AttributesBlock(AttributesBlockContainer &owner);
- ~AttributesBlock();
-
- const AttributesInfo &info() const
- {
- return m_owner.info();
- }
-
- uint used_size() const
- {
- return m_used_size;
- }
-
- uint capacity() const
- {
- return m_owner.block_size();
- }
-
- uint unused_capacity() const
- {
- return this->capacity() - this->used_size();
- }
-
- IndexRange used_range() const
- {
- return IndexRange(m_used_size);
- }
-
- void set_used_size(uint new_used_size)
- {
- BLI_assert(new_used_size <= this->capacity());
- m_used_size = new_used_size;
- }
-
- void destruct_and_reorder(IndexMask indices_to_destruct);
-
- AttributesBlockContainer &owner()
- {
- return m_owner;
- }
-
- MutableAttributesRef as_ref()
- {
- return MutableAttributesRef(m_owner.info(), m_buffers, m_used_size);
- }
-
- MutableAttributesRef as_ref__all()
- {
- return MutableAttributesRef(m_owner.info(), m_buffers, this->capacity());
- }
-
- ArrayRef<void *> buffers()
- {
- return m_buffers;
- }
-
- static void MoveUntilFull(AttributesBlock &from, AttributesBlock &to);
- static void Compress(MutableArrayRef<AttributesBlock *> blocks);
-};
-
-template<typename T>
-inline Vector<T> AttributesBlockContainer::flatten_attribute(StringRef name) const
-{
- Vector<T> values;
- values.reserve(this->count_active());
-
- for (AttributesBlock *block : m_active_blocks) {
- AttributesRef attributes = block->as_ref();
- values.extend(attributes.get<T>(name));
- }
-
- return values;
-}
-
-} // namespace FN
-
-#endif /* __FN_ATTRIBUTES_BLOCK_CONTAINER_H__ */
diff --git a/source/blender/functions/FN_attributes_ref.h b/source/blender/functions/FN_attributes_ref.h
index 2648f4da973..b63dd374d06 100644
--- a/source/blender/functions/FN_attributes_ref.h
+++ b/source/blender/functions/FN_attributes_ref.h
@@ -275,6 +275,16 @@ class MutableAttributesRef {
return this->slice(0, n);
}
+ ArrayRef<void *> internal_buffers()
+ {
+ return m_buffers;
+ }
+
+ IndexRange internal_range()
+ {
+ return m_range;
+ }
+
void destruct_and_reorder(IndexMask indices_to_destruct);
static void RelocateUninitialized(MutableAttributesRef from, MutableAttributesRef to);
diff --git a/source/blender/functions/intern/attributes_block_container.cc b/source/blender/functions/intern/attributes_block_container.cc
deleted file mode 100644
index 88ae4700d2e..00000000000
--- a/source/blender/functions/intern/attributes_block_container.cc
+++ /dev/null
@@ -1,150 +0,0 @@
-#include "FN_attributes_block_container.h"
-
-namespace FN {
-
-AttributesBlockContainer::AttributesBlockContainer(const AttributesInfoBuilder &info_builder,
- uint block_size)
- : m_info(BLI::make_unique<AttributesInfo>(info_builder)), m_block_size(block_size)
-{
-}
-
-AttributesBlockContainer::~AttributesBlockContainer()
-{
- while (m_active_blocks.size() > 0) {
- this->release_block(**m_active_blocks.begin());
- }
-}
-
-uint AttributesBlockContainer::count_active() const
-{
- uint count = 0;
- for (AttributesBlock *block : m_active_blocks) {
- count += block->used_size();
- }
- return count;
-}
-
-void AttributesBlockContainer::flatten_attribute(StringRef name, GenericMutableArrayRef dst) const
-{
- BLI_assert(dst.size() == this->count_active());
- BLI_assert(dst.type() == m_info->type_of(name));
-
- uint offset = 0;
- for (AttributesBlock *block : m_active_blocks) {
- AttributesRef attributes = block->as_ref();
- GenericArrayRef src_array = attributes.get(name);
- GenericMutableArrayRef dst_array = dst.slice(offset, attributes.size());
- for (uint i = 0; i < attributes.size(); i++) {
- dst_array.copy_in__uninitialized(i, src_array[i]);
- }
- offset += attributes.size();
- }
-}
-
-void AttributesBlockContainer::update_attributes(const AttributesInfoBuilder &new_info_builder)
-{
- auto new_info = BLI::make_unique<AttributesInfo>(new_info_builder);
-
- AttributesInfoDiff diff{*m_info, *new_info};
- for (AttributesBlock *block : m_active_blocks) {
- Vector<void *> new_buffers{diff.new_buffer_amount()};
- diff.update(m_block_size, block->m_used_size, block->m_buffers, new_buffers);
- block->m_buffers = std::move(new_buffers);
- }
-
- m_info = std::move(new_info);
-}
-
-AttributesBlock &AttributesBlockContainer::new_block()
-{
- AttributesBlock *block = new AttributesBlock(*this);
- {
- std::lock_guard<std::mutex> lock(m_blocks_mutex);
- m_active_blocks.add(block);
- }
- return *block;
-}
-
-void AttributesBlockContainer::release_block(AttributesBlock &block)
-{
- {
- std::lock_guard<std::mutex> lock(m_blocks_mutex);
- m_active_blocks.remove(&block);
- }
- delete █
-}
-
-AttributesBlock::AttributesBlock(AttributesBlockContainer &owner) : m_owner(owner), m_used_size(0)
-{
- for (const CPPType *type : owner.info().types()) {
- void *buffer = MEM_mallocN_aligned(
- owner.block_size() * type->size(), type->alignment(), __func__);
- m_buffers.append(buffer);
- }
-}
-
-AttributesBlock::~AttributesBlock()
-{
- for (uint attribute_index : m_owner.info().indices()) {
- const CPPType &type = m_owner.info().type_of(attribute_index);
- void *buffer = m_buffers[attribute_index];
- type.destruct_n(buffer, m_used_size);
- MEM_freeN(buffer);
- }
-}
-
-void AttributesBlock::destruct_and_reorder(IndexMask indices_to_destruct)
-{
- this->as_ref().destruct_and_reorder(indices_to_destruct);
- this->set_used_size(m_used_size - indices_to_destruct.size());
-}
-
-void AttributesBlock::MoveUntilFull(AttributesBlock &from, AttributesBlock &to)
-{
- BLI_assert(from.owner() == to.owner());
- uint move_amount = std::min(from.used_size(), to.unused_capacity());
-
- if (move_amount == 0) {
- return;
- }
-
- MutableAttributesRef from_ref = from.as_ref__all().slice(from.used_size() - move_amount,
- move_amount);
- MutableAttributesRef to_ref = to.as_ref__all().slice(to.used_size(), move_amount);
-
- MutableAttributesRef::RelocateUninitialized(from_ref, to_ref);
-
- from.set_used_size(from.used_size() - move_amount);
- to.set_used_size(to.used_size() + move_amount);
-}
-
-void AttributesBlock::Compress(MutableArrayRef<AttributesBlock *> blocks)
-{
- if (blocks.size() == 0) {
- return;
- }
-
- std::sort(blocks.begin(), blocks.end(), [](AttributesBlock *a, AttributesBlock *b) {
- return a->used_size() < b->used_size();
- });
-
- int first_non_full_index = 0;
- int last_non_empty_index = blocks.size() - 1;
-
- while (first_non_full_index < last_non_empty_index) {
- AttributesBlock &first_non_full = *blocks[first_non_full_index];
- AttributesBlock &last_non_empty = *blocks[last_non_empty_index];
-
- if (first_non_full.used_size() == first_non_full.capacity()) {
- first_non_full_index++;
- }
- else if (last_non_empty.used_size() == 0) {
- last_non_empty_index--;
- }
- else {
- AttributesBlock::MoveUntilFull(last_non_empty, first_non_full);
- }
- }
-}
-
-} // namespace FN
diff --git a/source/blender/functions/intern/attributes_ref.cc b/source/blender/functions/intern/attributes_ref.cc
index 78ab5612f79..93c54a407ac 100644
--- a/source/blender/functions/intern/attributes_ref.cc
+++ b/source/blender/functions/intern/attributes_ref.cc
@@ -153,9 +153,10 @@ void AttributesInfoDiff::update(uint capacity,
for (uint old_index : m_old_info->indices()) {
int new_index = m_old_to_new_mapping[old_index];
+ void *old_buffer = old_buffers[old_index];
- if (new_index == -1) {
- MEM_freeN(old_buffers[old_index]);
+ if (new_index == -1 && old_buffer != nullptr) {
+ MEM_freeN
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list