[Bf-blender-cvs] [c339917d7fe] functions: don't store attributes info ref directly in block
Jacques Lucke
noreply at git.blender.org
Tue Sep 10 14:24:09 CEST 2019
Commit: c339917d7fe042de2b182838ea0eabe4284939c2
Author: Jacques Lucke
Date: Tue Sep 10 12:56:54 2019 +0200
Branches: functions
https://developer.blender.org/rBc339917d7fe042de2b182838ea0eabe4284939c2
don't store attributes info ref directly in block
===================================================================
M source/blender/blenkernel/BKE_attributes_block_container.hpp
M source/blender/blenkernel/BKE_attributes_ref.hpp
M source/blender/blenkernel/intern/attributes_block_container.cpp
===================================================================
diff --git a/source/blender/blenkernel/BKE_attributes_block_container.hpp b/source/blender/blenkernel/BKE_attributes_block_container.hpp
index 20013b126f8..9bd886d688a 100644
--- a/source/blender/blenkernel/BKE_attributes_block_container.hpp
+++ b/source/blender/blenkernel/BKE_attributes_block_container.hpp
@@ -9,23 +9,71 @@
namespace BKE {
-class AttributesBlockContainer;
+class AttributesBlock;
+
+class AttributesBlockContainer : BLI::NonCopyable, BLI::NonMovable {
+ private:
+ std::unique_ptr<AttributesInfo> m_attributes_info;
+ uint m_block_size;
+ SetVector<AttributesBlock *> m_active_blocks;
+ std::mutex m_blocks_mutex;
+ std::atomic<uint> m_next_id;
+
+ public:
+ AttributesBlockContainer(std::unique_ptr<AttributesInfo> attributes_info, uint block_size);
+ ~AttributesBlockContainer();
+
+ uint count_active() const;
+
+ const AttributesInfo &attributes_info() const
+ {
+ return *m_attributes_info;
+ }
+
+ void update_attributes(std::unique_ptr<AttributesInfo> new_info);
+
+ AttributesBlock *new_block();
+ void release_block(AttributesBlock *block);
+
+ void flatten_attribute(StringRef attribute_name, void *dst) const;
+
+ template<typename T> Vector<T> flatten_attribute(StringRef attribute_name)
+ {
+ BLI_assert(m_attributes_info->type_of(attribute_name) == attribute_type_by_type<T>::value);
+ Vector<T> result(this->count_active());
+ this->flatten_attribute(attribute_name, (void *)result.begin());
+ return result;
+ }
+
+ friend bool operator==(const AttributesBlockContainer &a, const AttributesBlockContainer &b)
+ {
+ return &a == &b;
+ }
+
+ IndexRange new_ids(uint amount)
+ {
+ uint start = m_next_id.fetch_add(amount);
+ return IndexRange(start, amount);
+ }
+
+ ArrayRef<AttributesBlock *> active_blocks()
+ {
+ return m_active_blocks;
+ }
+};
class AttributesBlock : BLI::NonCopyable, BLI::NonMovable {
private:
- const AttributesInfo *m_attributes_info;
+ AttributesBlockContainer &m_owner;
Vector<void *> m_buffers;
uint m_size;
uint m_capacity;
- AttributesBlockContainer *m_owner;
public:
- AttributesBlock(const AttributesInfo *attributes_info,
- uint capacity,
- AttributesBlockContainer &owner);
+ AttributesBlock(AttributesBlockContainer &owner, uint capacity);
~AttributesBlock();
- void update_buffers(const AttributesInfo *new_info, const AttributesInfoDiff &info_diff);
+ void update_buffers(const AttributesInfoDiff &info_diff);
uint size() const
{
@@ -53,9 +101,14 @@ class AttributesBlock : BLI::NonCopyable, BLI::NonMovable {
m_size = new_size;
}
+ const AttributesInfo &attributes_info() const
+ {
+ return m_owner.attributes_info();
+ }
+
AttributesBlockContainer &owner()
{
- return *m_owner;
+ return m_owner;
}
void move(uint old_index, uint new_index);
@@ -70,63 +123,12 @@ class AttributesBlock : BLI::NonCopyable, BLI::NonMovable {
AttributesRef as_ref__all()
{
- return AttributesRef(*m_attributes_info, m_buffers, m_capacity);
+ return AttributesRef(m_owner.attributes_info(), m_buffers, m_capacity);
}
operator AttributesRef()
{
- return AttributesRef(*m_attributes_info, m_buffers, m_size);
- }
-};
-
-class AttributesBlockContainer : BLI::NonCopyable, BLI::NonMovable {
- private:
- std::unique_ptr<AttributesInfo> m_attributes_info;
- uint m_block_size;
- SetVector<AttributesBlock *> m_active_blocks;
- std::mutex m_blocks_mutex;
- std::atomic<uint> m_next_id;
-
- public:
- AttributesBlockContainer(std::unique_ptr<AttributesInfo> attributes_info, uint block_size);
- ~AttributesBlockContainer();
-
- uint count_active() const;
-
- const AttributesInfo &attributes_info() const
- {
- return *m_attributes_info;
- }
-
- void update_attributes(std::unique_ptr<AttributesInfo> new_info);
-
- AttributesBlock *new_block();
- void release_block(AttributesBlock *block);
-
- void flatten_attribute(StringRef attribute_name, void *dst) const;
-
- template<typename T> Vector<T> flatten_attribute(StringRef attribute_name)
- {
- BLI_assert(m_attributes_info->type_of(attribute_name) == attribute_type_by_type<T>::value);
- Vector<T> result(this->count_active());
- this->flatten_attribute(attribute_name, (void *)result.begin());
- return result;
- }
-
- friend bool operator==(const AttributesBlockContainer &a, const AttributesBlockContainer &b)
- {
- return &a == &b;
- }
-
- IndexRange new_ids(uint amount)
- {
- uint start = m_next_id.fetch_add(amount);
- return IndexRange(start, amount);
- }
-
- ArrayRef<AttributesBlock *> active_blocks()
- {
- return m_active_blocks;
+ return AttributesRef(m_owner.attributes_info(), m_buffers, m_size);
}
};
diff --git a/source/blender/blenkernel/BKE_attributes_ref.hpp b/source/blender/blenkernel/BKE_attributes_ref.hpp
index 8ab1b238549..16cef242e61 100644
--- a/source/blender/blenkernel/BKE_attributes_ref.hpp
+++ b/source/blender/blenkernel/BKE_attributes_ref.hpp
@@ -304,6 +304,11 @@ class AttributesInfoDiff {
void update(uint capacity,
ArrayRef<void *> old_buffers,
MutableArrayRef<void *> new_buffers) const;
+
+ uint new_buffer_amount() const
+ {
+ return m_new_info->size();
+ }
};
/**
diff --git a/source/blender/blenkernel/intern/attributes_block_container.cpp b/source/blender/blenkernel/intern/attributes_block_container.cpp
index c5599628a2b..1f9ca5045fe 100644
--- a/source/blender/blenkernel/intern/attributes_block_container.cpp
+++ b/source/blender/blenkernel/intern/attributes_block_container.cpp
@@ -29,14 +29,14 @@ void AttributesBlockContainer::update_attributes(std::unique_ptr<AttributesInfo>
{
AttributesInfoDiff info_diff(*m_attributes_info, *new_info);
for (auto &block : m_active_blocks) {
- block->update_buffers(new_info.get(), info_diff);
+ block->update_buffers(info_diff);
}
m_attributes_info = std::move(new_info);
}
AttributesBlock *AttributesBlockContainer::new_block()
{
- AttributesBlock *block = new AttributesBlock(m_attributes_info.get(), m_block_size, *this);
+ AttributesBlock *block = new AttributesBlock(*this, m_block_size);
{
std::lock_guard<std::mutex> lock(m_blocks_mutex);
@@ -70,15 +70,13 @@ void AttributesBlockContainer::flatten_attribute(StringRef attribute_name, void
}
}
-AttributesBlock::AttributesBlock(const AttributesInfo *attributes_info,
- uint capacity,
- AttributesBlockContainer &owner)
- : m_attributes_info(attributes_info), m_size(0), m_capacity(capacity), m_owner(&owner)
+AttributesBlock::AttributesBlock(AttributesBlockContainer &owner, uint capacity)
+ : m_owner(owner), m_size(0), m_capacity(capacity)
{
- BLI_assert(attributes_info != nullptr);
- m_buffers.reserve(attributes_info->size());
+ const AttributesInfo &info = owner.attributes_info();
+ m_buffers.reserve(info.size());
- for (AttributeType type : m_attributes_info->types()) {
+ for (AttributeType type : info.types()) {
uint byte_size = capacity * size_of_attribute_type(type);
void *ptr = MEM_mallocN_aligned(byte_size, 64, __func__);
m_buffers.append(ptr);
@@ -107,7 +105,7 @@ void AttributesBlock::move(uint old_index, uint new_index)
void AttributesBlock::MoveUntilFull(AttributesBlock &from, AttributesBlock &to)
{
- BLI_assert(to.m_attributes_info == from.m_attributes_info);
+ BLI_assert(to.attributes_info() == from.attributes_info());
uint move_amount = std::min(from.size(), to.remaining_capacity());
if (move_amount == 0) {
@@ -117,7 +115,7 @@ void AttributesBlock::MoveUntilFull(AttributesBlock &from, AttributesBlock &to)
uint src_start = from.m_size - move_amount;
uint dst_start = to.m_size;
- const AttributesInfo &info = *from.m_attributes_info;
+ const AttributesInfo &info = from.attributes_info();
for (uint i = 0; i < info.size(); i++) {
void *from_buffer = from.m_buffers[i];
@@ -157,12 +155,10 @@ void AttributesBlock::Compress(MutableArrayRef<AttributesBlock *> blocks)
}
}
-void AttributesBlock::update_buffers(const AttributesInfo *new_info,
- const AttributesInfoDiff &info_diff)
+void AttributesBlock::update_buffers(const AttributesInfoDiff &info_diff)
{
- m_attributes_info = new_info;
- Vector<void *> new_buffers(new_info->size());
+ Vector<void *> new_buffers(info_diff.new_buffer_amount());
info_diff.update(m_capacity, m_buffers, new_buffers);
m_buffers = new_buffers;
}
More information about the Bf-blender-cvs
mailing list