[Bf-blender-cvs] [1b3ee092dbf] functions: move attributes block container stuff to same file again
Jacques Lucke
noreply at git.blender.org
Tue Sep 10 14:24:06 CEST 2019
Commit: 1b3ee092dbf5b2b5d0d5dd5129f81de080c764f7
Author: Jacques Lucke
Date: Tue Sep 10 12:39:18 2019 +0200
Branches: functions
https://developer.blender.org/rB1b3ee092dbf5b2b5d0d5dd5129f81de080c764f7
move attributes block container stuff to same file again
===================================================================
D source/blender/blenkernel/BKE_attributes_block.hpp
M source/blender/blenkernel/BKE_attributes_block_container.hpp
M source/blender/blenkernel/CMakeLists.txt
D source/blender/blenkernel/intern/attributes_block.cpp
M source/blender/blenkernel/intern/attributes_block_container.cpp
===================================================================
diff --git a/source/blender/blenkernel/BKE_attributes_block.hpp b/source/blender/blenkernel/BKE_attributes_block.hpp
deleted file mode 100644
index 7625603e861..00000000000
--- a/source/blender/blenkernel/BKE_attributes_block.hpp
+++ /dev/null
@@ -1,78 +0,0 @@
-#pragma once
-
-#include "BKE_attributes_ref.hpp"
-#include "BLI_utility_mixins.hpp"
-
-namespace BKE {
-
-class AttributesBlockContainer;
-
-class AttributesBlock : BLI::NonCopyable, BLI::NonMovable {
- private:
- const AttributesInfo *m_attributes_info;
- Vector<void *> m_buffers;
- uint m_size;
- uint m_capacity;
- AttributesBlockContainer *m_owner;
-
- public:
- AttributesBlock(const AttributesInfo *attributes_info,
- uint capacity,
- AttributesBlockContainer &owner);
- ~AttributesBlock();
-
- void update_buffers(const AttributesInfo *new_info, const AttributesInfoDiff &info_diff);
-
- uint size() const
- {
- return m_size;
- }
-
- uint capacity() const
- {
- return m_capacity;
- }
-
- uint remaining_capacity() const
- {
- return m_capacity - m_size;
- }
-
- IndexRange active_range() const
- {
- return IndexRange(m_size);
- }
-
- void set_size(uint new_size)
- {
- BLI_assert(new_size <= m_capacity);
- m_size = new_size;
- }
-
- AttributesBlockContainer &owner()
- {
- return *m_owner;
- }
-
- void move(uint old_index, uint new_index);
-
- static void MoveUntilFull(AttributesBlock &from, AttributesBlock &to);
- static void Compress(MutableArrayRef<AttributesBlock *> blocks);
-
- AttributesRef as_ref()
- {
- return AttributesRef(*this);
- }
-
- AttributesRef as_ref__all()
- {
- return AttributesRef(*m_attributes_info, m_buffers, m_capacity);
- }
-
- operator AttributesRef()
- {
- return AttributesRef(*m_attributes_info, m_buffers, m_size);
- }
-};
-
-} // namespace BKE
diff --git a/source/blender/blenkernel/BKE_attributes_block_container.hpp b/source/blender/blenkernel/BKE_attributes_block_container.hpp
index abe6a9d02ba..20013b126f8 100644
--- a/source/blender/blenkernel/BKE_attributes_block_container.hpp
+++ b/source/blender/blenkernel/BKE_attributes_block_container.hpp
@@ -3,10 +3,82 @@
#include <mutex>
#include <atomic>
-#include "BKE_attributes_block.hpp"
+#include "BLI_utility_mixins.hpp"
+
+#include "BKE_attributes_ref.hpp"
namespace BKE {
+class AttributesBlockContainer;
+
+class AttributesBlock : BLI::NonCopyable, BLI::NonMovable {
+ private:
+ const AttributesInfo *m_attributes_info;
+ Vector<void *> m_buffers;
+ uint m_size;
+ uint m_capacity;
+ AttributesBlockContainer *m_owner;
+
+ public:
+ AttributesBlock(const AttributesInfo *attributes_info,
+ uint capacity,
+ AttributesBlockContainer &owner);
+ ~AttributesBlock();
+
+ void update_buffers(const AttributesInfo *new_info, const AttributesInfoDiff &info_diff);
+
+ uint size() const
+ {
+ return m_size;
+ }
+
+ uint capacity() const
+ {
+ return m_capacity;
+ }
+
+ uint remaining_capacity() const
+ {
+ return m_capacity - m_size;
+ }
+
+ IndexRange active_range() const
+ {
+ return IndexRange(m_size);
+ }
+
+ void set_size(uint new_size)
+ {
+ BLI_assert(new_size <= m_capacity);
+ m_size = new_size;
+ }
+
+ AttributesBlockContainer &owner()
+ {
+ return *m_owner;
+ }
+
+ void move(uint old_index, uint new_index);
+
+ static void MoveUntilFull(AttributesBlock &from, AttributesBlock &to);
+ static void Compress(MutableArrayRef<AttributesBlock *> blocks);
+
+ AttributesRef as_ref()
+ {
+ return AttributesRef(*this);
+ }
+
+ AttributesRef as_ref__all()
+ {
+ return AttributesRef(*m_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;
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index ea4b175e849..6edbdd08761 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -76,7 +76,6 @@ set(SRC
intern/armature.c
intern/armature_update.c
intern/attributes_block_container.cpp
- intern/attributes_block.cpp
intern/attributes_ref.cpp
intern/autoexec.c
intern/blender.c
@@ -241,7 +240,6 @@ set(SRC
BKE_appdir.h
BKE_armature.h
BKE_attributes_block_container.hpp
- BKE_attributes_block.hpp
BKE_attributes_ref.hpp
BKE_autoexec.h
BKE_blender.h
diff --git a/source/blender/blenkernel/intern/attributes_block.cpp b/source/blender/blenkernel/intern/attributes_block.cpp
deleted file mode 100644
index 614c30de4e9..00000000000
--- a/source/blender/blenkernel/intern/attributes_block.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-#include "BKE_attributes_block.hpp"
-
-namespace BKE {
-
-AttributesBlock::AttributesBlock(const AttributesInfo *attributes_info,
- uint capacity,
- AttributesBlockContainer &owner)
- : m_attributes_info(attributes_info), m_size(0), m_capacity(capacity), m_owner(&owner)
-{
- BLI_assert(attributes_info != nullptr);
- m_buffers.reserve(attributes_info->size());
-
- for (AttributeType type : m_attributes_info->types()) {
- uint byte_size = capacity * size_of_attribute_type(type);
- void *ptr = MEM_mallocN_aligned(byte_size, 64, __func__);
- m_buffers.append(ptr);
- }
-}
-
-AttributesBlock::~AttributesBlock()
-{
- for (void *ptr : m_buffers) {
- MEM_freeN(ptr);
- }
-}
-
-void AttributesBlock::move(uint old_index, uint new_index)
-{
- AttributesRef attributes = *this;
-
- for (uint attribute_index : attributes.info().attribute_indices()) {
- void *ptr = attributes.get_ptr(attribute_index);
- uint size = attributes.attribute_size(attribute_index);
- void *src = POINTER_OFFSET(ptr, old_index * size);
- void *dst = POINTER_OFFSET(ptr, new_index * size);
- memcpy(dst, src, size);
- }
-}
-
-void AttributesBlock::MoveUntilFull(AttributesBlock &from, AttributesBlock &to)
-{
- BLI_assert(to.m_attributes_info == from.m_attributes_info);
- uint move_amount = std::min(from.size(), to.remaining_capacity());
-
- if (move_amount == 0) {
- return;
- }
-
- uint src_start = from.m_size - move_amount;
- uint dst_start = to.m_size;
-
- const AttributesInfo &info = *from.m_attributes_info;
-
- for (uint i = 0; i < info.size(); i++) {
- void *from_buffer = from.m_buffers[i];
- void *to_buffer = to.m_buffers[i];
- AttributeType type = info.type_of(i);
- uint size = size_of_attribute_type(type);
- memcpy((char *)to_buffer + size * dst_start,
- (char *)from_buffer + size * src_start,
- size * move_amount);
- }
-
- from.m_size -= move_amount;
- to.m_size += move_amount;
-}
-
-void AttributesBlock::Compress(MutableArrayRef<AttributesBlock *> blocks)
-{
- std::sort(blocks.begin(), blocks.end(), [](AttributesBlock *a, AttributesBlock *b) {
- return a->size() < b->size();
- });
-
- uint last_non_full = blocks.size() - 1;
-
- for (uint i = 0; i < blocks.size(); i++) {
- while (i < last_non_full) {
- AttributesBlock &block = *blocks[last_non_full];
- if (block.m_size == block.m_capacity) {
- last_non_full--;
- continue;
- }
-
- AttributesBlock::MoveUntilFull(*blocks[i], block);
- if (blocks[i]->size() == 0) {
- break;
- }
- }
- }
-}
-
-void AttributesBlock::update_buffers(const AttributesInfo *new_info,
- const AttributesInfoDiff &info_diff)
-{
- m_attributes_info = new_info;
-
- Vector<void *> new_buffers(new_info->size());
- info_diff.update(m_capacity, m_buffers, new_buffers);
- m_buffers = new_buffers;
-}
-
-} // namespace BKE
diff --git a/source/blender/blenkernel/intern/attributes_block_container.cpp b/source/blender/blenkernel/intern/attributes_block_container.cpp
index dd4636f294c..c5599628a2b 100644
--- a/source/blender/blenkernel/intern/attributes_block_container.cpp
+++ b/source/blender/blenkernel/intern/attributes_block_container.cpp
@@ -70,4 +70,101 @@ 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)
+{
+ BLI_assert(attributes_info != nullptr);
+ m_buffers.reserve(attributes_info->size());
+
+ for (AttributeType type : m_attributes_info->types()) {
+ uint byte_size = capacity * size_of_attribute_type(type);
+ void *ptr = MEM_mallocN_aligned(byte_size, 64, __func__);
+ m_buffers.append(ptr);
+ }
+}
+
+AttributesBlock::~AttributesBlock()
+{
+ for (void *ptr : m_buffers) {
+ MEM_freeN(ptr);
+ }
+}
+
+void AttributesBlock::move(uint old_index, uint new_index)
+{
+ AttributesRef attributes = *this;
+
+ for (uint attribute_index : attributes.info().attribute_indices()) {
+ void *ptr = attributes.get_ptr(attribute_index);
+ uint size = attributes.attribute_size(attribute_index);
+ void *src = POINTER_OFFSET(ptr, old_index * size);
+ void *dst = POINTER_OFFSET(ptr, new_index * size);
+ memcpy(dst, src, size);
+ }
+}
+
+void AttributesBlock::MoveUntilFull(AttributesBlock &from, AttributesBlock &to)
+{
+ BLI_assert(to.m_attributes_info == from.m_attributes_info);
+ uint move_amount = std::min(from.size(), to.remaining_capacity());
+
+ if (move_amount == 0) {
+ return;
+ }
+
+ uint src_start = from.m_size - move_amount;
+ uint dst_start = to.m_size;
+
+ const AttributesInfo &info = *from.m_attributes_info;
+
+ for (uint i = 0; i < info.size(); i++) {
+ void *from_buffer = from.m_buffers[i];
+ void *to_buffer = to.m_buffers[i];
+ AttributeType type = info.type_of(i);
+ uint size = size_of_attribute_type(type);
+ memcpy((char *)to_buffer + size * dst_start,
+ (char *)from_buffer + size * src_start,
+ size * move_amount);
+ }
+
+ from.m_size -= move_amount
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list