[Bf-blender-cvs] [9728f45e89c] functions: particles container has responsibility to allocate attribute arrays again
Jacques Lucke
noreply at git.blender.org
Wed Jun 26 18:19:07 CEST 2019
Commit: 9728f45e89cb54e2d34940d7041d398865081da5
Author: Jacques Lucke
Date: Wed Jun 26 12:06:22 2019 +0200
Branches: functions
https://developer.blender.org/rB9728f45e89cb54e2d34940d7041d398865081da5
particles container has responsibility to allocate attribute arrays again
===================================================================
M source/blender/simulations/bparticles/attributes.cpp
M source/blender/simulations/bparticles/attributes.hpp
M source/blender/simulations/bparticles/particles_container.cpp
M source/blender/simulations/bparticles/particles_container.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index 416be9b0247..a4b6e25ba6c 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -22,15 +22,26 @@ AttributesInfo::AttributesInfo(ArrayRef<std::string> byte_names,
m_types.append_n_times(AttributeType::Float3, m_float3_attributes.size());
}
-AttributeArraysCore::AttributeArraysCore(AttributesInfo &info, uint size)
- : m_info(info), m_size(size)
+AttributeArraysCore::AttributeArraysCore(AttributesInfo &info, ArrayRef<void *> arrays, uint size)
+ : m_info(info), m_arrays(arrays.to_small_vector()), m_size(size)
{
+}
+
+AttributeArraysCore::~AttributeArraysCore()
+{
+}
+
+AttributeArraysCore AttributeArraysCore::NewWithSeparateAllocations(AttributesInfo &info,
+ uint size)
+{
+ SmallVector<void *> arrays;
for (AttributeType type : info.types()) {
- m_arrays.append(MEM_malloc_arrayN(size, size_of_attribute_type(type), __func__));
+ arrays.append(MEM_malloc_arrayN(size, size_of_attribute_type(type), __func__));
}
+ return AttributeArraysCore(info, arrays, size);
}
-AttributeArraysCore::~AttributeArraysCore()
+void AttributeArraysCore::free_buffers()
{
for (void *ptr : m_arrays) {
MEM_freeN(ptr);
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index 5fbefc2afa4..a4711ca8d36 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -111,9 +111,12 @@ class AttributeArraysCore {
uint m_size = 0;
public:
- AttributeArraysCore(AttributesInfo &info, uint size);
+ AttributeArraysCore(AttributesInfo &info, ArrayRef<void *> arrays, uint size);
~AttributeArraysCore();
+ static AttributeArraysCore NewWithSeparateAllocations(AttributesInfo &info, uint size);
+ void free_buffers();
+
AttributesInfo &info();
void *get_ptr(uint index);
AttributeType get_type(uint index);
diff --git a/source/blender/simulations/bparticles/particles_container.cpp b/source/blender/simulations/bparticles/particles_container.cpp
index ca35fd2598b..acca5f9e687 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -2,15 +2,13 @@
namespace BParticles {
-ParticlesBlock::ParticlesBlock(ParticlesContainer &container)
- : m_container(container),
- m_arrays(m_container.attributes(), container.block_size()),
- m_active_amount(0)
+ParticlesBlock::ParticlesBlock(ParticlesContainer &container, AttributeArraysCore &attributes_core)
+ : m_container(container), m_attributes_core(attributes_core)
{
}
ParticlesContainer::ParticlesContainer(AttributesInfo attributes, uint block_size)
- : m_attributes(std::move(attributes)), m_block_size(block_size)
+ : m_attributes_info(std::move(attributes)), m_block_size(block_size)
{
}
@@ -25,7 +23,9 @@ ParticlesContainer::~ParticlesContainer()
ParticlesBlock *ParticlesContainer::new_block()
{
- ParticlesBlock *block = new ParticlesBlock(*this);
+ AttributeArraysCore attributes_core = AttributeArraysCore::NewWithSeparateAllocations(
+ m_attributes_info, m_block_size);
+ ParticlesBlock *block = new ParticlesBlock(*this, attributes_core);
m_blocks.add_new(block);
return block;
}
@@ -37,13 +37,14 @@ void ParticlesContainer::release_block(ParticlesBlock *block)
BLI_assert(m_blocks.contains(block));
BLI_assert(&block->container() == this);
+ block->attributes_core().free_buffers();
m_blocks.remove(block);
delete block;
}
void ParticlesContainer::update_attributes(AttributesInfo new_info)
{
- m_attributes = new_info;
+ m_attributes_info = new_info;
/* TODO: actually update attributes */
}
@@ -58,11 +59,11 @@ void ParticlesBlock::MoveUntilFull(ParticlesBlock &from, ParticlesBlock &to)
return;
}
- uint attribute_amount = from.container().attributes().amount();
+ uint attribute_amount = from.container().attributes_info().amount();
for (uint i = 0; i < attribute_amount; i++) {
- void *from_buffer = from.arrays_core().get_ptr(i);
- void *to_buffer = to.arrays_core().get_ptr(i);
- AttributeType type = from.arrays_core().get_type(i);
+ void *from_buffer = from.attributes_core().get_ptr(i);
+ void *to_buffer = to.attributes_core().get_ptr(i);
+ AttributeType type = from.attributes_core().get_type(i);
uint size = size_of_attribute_type(type);
memcpy((char *)to_buffer + size * dst_start,
(char *)from_buffer + size * src_start,
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index 5a06822eab2..1201f25c097 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -24,7 +24,7 @@ class ParticlesBlock;
class ParticlesContainer {
private:
- AttributesInfo m_attributes;
+ AttributesInfo m_attributes_info;
SmallSet<ParticlesBlock *> m_blocks;
uint m_block_size;
@@ -36,7 +36,7 @@ class ParticlesContainer {
uint block_size() const;
uint count_active() const;
- AttributesInfo &attributes();
+ AttributesInfo &attributes_info();
void update_attributes(AttributesInfo new_info);
const SmallSet<ParticlesBlock *> &active_blocks();
@@ -47,11 +47,11 @@ class ParticlesContainer {
class ParticlesBlock {
ParticlesContainer &m_container;
- AttributeArraysCore m_arrays;
- uint m_active_amount;
+ AttributeArraysCore m_attributes_core;
+ uint m_active_amount = 0;
public:
- ParticlesBlock(ParticlesContainer &container);
+ ParticlesBlock(ParticlesContainer &container, AttributeArraysCore &attributes_core);
uint &active_amount();
uint inactive_amount();
@@ -64,7 +64,7 @@ class ParticlesBlock {
void clear();
- AttributeArraysCore &arrays_core();
+ AttributeArraysCore &attributes_core();
AttributeArrays slice(uint start, uint length);
AttributeArrays slice_all();
AttributeArrays slice_active();
@@ -92,9 +92,9 @@ inline uint ParticlesContainer::count_active() const
return count;
}
-inline AttributesInfo &ParticlesContainer::attributes()
+inline AttributesInfo &ParticlesContainer::attributes_info()
{
- return m_attributes;
+ return m_attributes_info;
}
inline const SmallSet<ParticlesBlock *> &ParticlesContainer::active_blocks()
@@ -147,12 +147,12 @@ inline ParticlesContainer &ParticlesBlock::container()
inline AttributeArrays ParticlesBlock::slice(uint start, uint length)
{
- return m_arrays.slice_all().slice(start, length);
+ return m_attributes_core.slice_all().slice(start, length);
}
inline AttributeArrays ParticlesBlock::slice_all()
{
- return m_arrays.slice_all();
+ return m_attributes_core.slice_all();
}
inline AttributeArrays ParticlesBlock::slice_active()
@@ -160,14 +160,14 @@ inline AttributeArrays ParticlesBlock::slice_active()
return this->slice(0, m_active_amount);
}
-inline AttributeArraysCore &ParticlesBlock::arrays_core()
+inline AttributeArraysCore &ParticlesBlock::attributes_core()
{
- return m_arrays;
+ return m_attributes_core;
}
inline void ParticlesBlock::move(uint old_index, uint new_index)
{
- AttributesInfo &attributes = m_container.attributes();
+ AttributesInfo &attributes = m_container.attributes_info();
AttributeArrays arrays = this->slice_all();
for (uint i : attributes.byte_attributes()) {
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index c4a373e0e26..8f5851a7f2b 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -459,8 +459,8 @@ BLI_NOINLINE static void ensure_required_attributes_exist(
ParticleType &type = description.particle_type(type_id);
ParticlesContainer &container = *containers.lookup(type_id);
- AttributesInfo new_attributes_info = build_attribute_info_for_type(type,
- container.attributes());
+ AttributesInfo new_attributes_info = build_attribute_info_for_type(
+ type, container.attributes_info());
container.update_attributes(new_attributes_info);
}
}
More information about the Bf-blender-cvs
mailing list