[Bf-blender-cvs] [3012e7a3c2e] functions: Tuple structure (no copy/move functionality yet)
Jacques Lucke
noreply at git.blender.org
Sun Feb 10 20:25:25 CET 2019
Commit: 3012e7a3c2ec09eca2a347a4a4b312bc10925858
Author: Jacques Lucke
Date: Fri Jan 25 14:53:55 2019 +0100
Branches: functions
https://developer.blender.org/rB3012e7a3c2ec09eca2a347a4a4b312bc10925858
Tuple structure (no copy/move functionality yet)
===================================================================
D source/blender/blenlib/BLI_small_buffer.hpp
M source/blender/blenlib/CMakeLists.txt
M source/blender/functions/FN_functions.h
M source/blender/functions/FN_functions.hpp
M source/blender/functions/intern/c_wrapper.cpp
M source/blender/functions/intern/function.cpp
M source/blender/modifiers/intern/MOD_functiondeform.c
===================================================================
diff --git a/source/blender/blenlib/BLI_small_buffer.hpp b/source/blender/blenlib/BLI_small_buffer.hpp
deleted file mode 100644
index 28ddff0c05a..00000000000
--- a/source/blender/blenlib/BLI_small_buffer.hpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#pragma once
-
-#include <cstring>
-#include "BLI_utildefines.h"
-#include "BLI_small_vector.hpp"
-
-namespace BLI {
-
- template<uint N = 16>
- class SmallBuffer : private SmallVector<char, N> {
- public:
- SmallBuffer() {}
-
- SmallBuffer(uint size)
- : SmallVector<char, N>(size) { }
-
- inline void copy_in(uint dst, void *src, uint amount)
- {
- BLI_assert(dst + amount <= this->size());
- memcpy(this->begin() + dst, src, amount);
- }
-
- inline void copy_out(void *dst, uint src, uint amount) const
- {
- BLI_assert(src + amount <= this->size());
- memcpy(dst, this->begin() + src, amount);
- }
-
- template<uint amount>
- inline void copy_in(uint dst, void *src)
- {
- BLI_assert(dst + amount <= this->size());
- memcpy(this->begin() + dst, src, amount);
- }
-
- template<uint amount>
- inline void copy_out(uint dst, void *src) const
- {
- BLI_assert(src + amount <= this->size());
- memcpy(dst, this->begin() + src, amount);
- }
- };
-
-} /* namespace BLI */
\ No newline at end of file
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 046cbe1a988..3f89a1c6603 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -226,7 +226,6 @@ set(SRC
PIL_time_utildefines.h
BLI_small_vector.hpp
- BLI_small_buffer.hpp
)
if(WITH_MEM_VALGRIND)
diff --git a/source/blender/functions/FN_functions.h b/source/blender/functions/FN_functions.h
index a6be74dcf56..be99a49165a 100644
--- a/source/blender/functions/FN_functions.h
+++ b/source/blender/functions/FN_functions.h
@@ -25,7 +25,6 @@ FnInputsRef FN_inputs_new(FunctionRef fn);
void FN_inputs_free(FnInputsRef fn_in);
/* Set a function input by index. Returns true on success. */
-void FN_inputs_set(FnInputsRef fn_in, uint index, void *src);
void FN_inputs_set_float(FnInputsRef fn_in, uint index, float value);
void FN_inputs_set_float_vector_3(FnInputsRef fn_in, uint index, float vector[3]);
@@ -36,7 +35,6 @@ FnOutputsRef FN_outputs_new(FunctionRef fn);
void FN_outputs_free(FnOutputsRef fn_out);
/* Extract the result of an executed function by index. */
-void FN_outputs_get(FnOutputsRef fn_out, uint index, void *dst);
void FN_outputs_get_float_vector_3(FnOutputsRef fn_out, uint index, float dst[3]);
const char *FN_type_name(FnTypeRef type);
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index 0c66e6990c2..87102419b58 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -1,10 +1,10 @@
#pragma once
#include <string>
+#include <type_traits>
#include "BLI_utildefines.h"
#include "BLI_small_vector.hpp"
-#include "BLI_small_buffer.hpp"
namespace FN {
using namespace BLI;
@@ -27,46 +27,77 @@ namespace FN {
uint m_size;
};
- class ValueArray {
+ class Tuple {
public:
- ValueArray() {};
- ValueArray(const SmallTypeVector &types);
-
- inline void set(uint index, void *src)
+ Tuple() {}
+ Tuple(const SmallTypeVector &types)
+ : types(types)
{
- BLI_assert(index < this->types.size());
- uint size = this->offsets[index + 1] - this->offsets[index];
- this->storage.copy_in(this->offsets[index], src, size);
+ int total_size = 0;
+ for (const Type *type : types) {
+ this->offsets.append(total_size);
+ this->initialized.append(false);
+ total_size += type->size();
+ }
+ this->offsets.append(total_size);
+ this->data = std::malloc(total_size);
}
- inline void get(uint index, void *dst) const
+ ~Tuple()
{
- BLI_assert(index < this->offsets.size());
- uint size = this->offsets[index + 1] - this->offsets[index];
- this->storage.copy_out(dst, this->offsets[index], size);
+ std::free(this->data);
}
- template<uint size>
- inline void set_static(uint index, void *src)
+ template<typename T>
+ inline void set(uint index, const T &value)
{
BLI_assert(index < this->types.size());
- this->storage.copy_in<size>(this->offsets[index], src);
+ BLI_assert(sizeof(T) == this->element_size(index));
+
+ if (std::is_trivial<T>::value) {
+ std::memcpy((char *)this->data + this->offsets[index], &value, sizeof(T));
+ }
+ else {
+ const T *begin = &value;
+ const T *end = begin + 1;
+ T *dst = (T *)((char *)this->data + this->offsets[index]);
+
+ if (this->initialized[index]) {
+ std::copy(begin, end, dst);
+ }
+ else {
+ std::uninitialized_copy(begin, end, dst);
+ this->initialized[index] = true;
+ }
+ }
}
- template<uint size>
- inline void get_static(uint index, void *dst) const
+ template<typename T>
+ inline const T &get(uint index) const
{
- BLI_assert(index < this->offsets.size());
- this->storage.copy_out(dst, this->offsets[index], size);
+ BLI_assert(index < this->types.size());
+ BLI_assert(sizeof(T) == this->element_size(index));
+
+ if (!std::is_trivial<T>::value) {
+ BLI_assert(this->initialized[index]);
+ }
+
+ return *(T *)((char *)this->data + this->offsets[index]);;
}
private:
+ inline uint element_size(uint index) const
+ {
+ return this->offsets[index + 1] - this->offsets[index];
+ }
+
const SmallTypeVector types;
- SmallVector<int> offsets;
- SmallBuffer<> storage;
+ SmallVector<uint> offsets;
+ SmallVector<bool> initialized;
+ void *data;
};
- class Inputs : public ValueArray {
+ class Inputs : public Tuple {
public:
Inputs(const Function &fn);
@@ -74,7 +105,7 @@ namespace FN {
const Function &fn;
};
- class Outputs : public ValueArray {
+ class Outputs : public Tuple {
public:
Outputs(const Function &fn);
diff --git a/source/blender/functions/intern/c_wrapper.cpp b/source/blender/functions/intern/c_wrapper.cpp
index 2c9660db3d6..9ccbc77accc 100644
--- a/source/blender/functions/intern/c_wrapper.cpp
+++ b/source/blender/functions/intern/c_wrapper.cpp
@@ -28,29 +28,24 @@ void FN_outputs_free(FnOutputsRef fn_out)
delete (FN::Outputs *)fn_out;
}
-void FN_inputs_set(FnInputsRef fn_in, uint index, void *src)
-{
- ((FN::Inputs *)fn_in)->set(index, src);
-}
-
void FN_inputs_set_float(FnInputsRef fn_in, uint index, float value)
{
- ((FN::Inputs *)fn_in)->set_static<sizeof(float)>(index, (void *)&value);
+ ((FN::Inputs *)fn_in)->set<float>(index, value);
}
-void FN_inputs_set_float_vector_3(FnInputsRef fn_in, uint index, float value[3])
-{
- ((FN::Inputs *)fn_in)->set_static<sizeof(float) * 3>(index, (void *)value);
-}
+struct Vector {
+ float x, y, z;
+};
-void FN_outputs_get(FnOutputsRef fn_out, uint index, void *dst)
+void FN_inputs_set_float_vector_3(FnInputsRef fn_in, uint index, float value[3])
{
- ((FN::Outputs *)fn_out)->get(index, dst);
+ ((FN::Inputs *)fn_in)->set<Vector>(index, *(Vector *)value);
}
void FN_outputs_get_float_vector_3(FnOutputsRef fn_out, uint index, float dst[3])
{
- ((FN::Outputs *)fn_out)->get_static<sizeof(float) * 3>(index, (void *)dst);
+ FN::Outputs *fn_out_ = (FN::Outputs *)fn_out;
+ *(Vector *)dst = fn_out_->get<Vector>(index);
}
const char *FN_type_name(FnTypeRef type)
@@ -68,36 +63,6 @@ FnTypeRef FN_type_get_float_vector_3d()
{ return (FnTypeRef)FN::Types::floatvec3d_ty; }
-class AddConstFunction : public FN::Function {
-private:
- AddConstFunction(FN::Signature sig, int value)
- : Function(sig), value(value) {}
-
-public:
- static AddConstFunction *Create(int value)
- {
- FN::Signature sig({FN::Types::int32_ty}, {FN::Types::int32_ty});
- return new AddConstFunction(sig, value);
- }
-
- bool call(const FN::Inputs &fn_in, FN::Outputs &fn_out) override
- {
- int a;
- fn_in.get(0, &a);
- int result = a + this->value;
- fn_out.set(0, &result);
- return true;
- }
-
-private:
- int value;
-};
-
-FunctionRef FN_get_add_const_function(int value)
-{
- return (FunctionRef)AddConstFunction::Create(value);
-}
-
#include <cmath>
class DeformFunction : public FN::Function {
@@ -114,18 +79,16 @@ public:
bool call(const FN::Inputs &fn_in, FN::Outputs &fn_out) override
{
- float vec[3];
- float control;
- fn_in.get_static<sizeof(float) * 3>(0, (void *)vec);
- fn_in.get_static<sizeof(float)>(1, (void *)&control);
+ Vector vec = fn_in.get<Vector>(0);
+ float control = fn_in.get<float>(1);
- float result[3];
+ Vector result;
- result[0] = vec[0] * control;
- result[1] = vec[1];
- result[2] = vec[2];
+ result.x = vec.x * control;
+ result.y = vec.y;
+ result.z = vec.z;
- fn_out.set_static<sizeof(float) * 3>(0, result);
+ fn_out.set<Vector>(0, result);
return true;
}
diff --git a/source/blender/functions/intern/function.cpp b/source/blender/functions/intern/function.cpp
index 0bd989c28fc..b97a227b994 100644
--- a/source/blender/functions/intern/function.cpp
+++ b/source/blender/functions/intern/function.cpp
@@ -14,24 +14,10 @@ const uint Type::size() const
Inputs::Inputs(const Function &fn)
- : ValueArray(fn.signature().inputs()), fn(fn) { }
+ : Tuple(fn.signature().inputs()), fn(fn) { }
Outputs::Outputs(const Function &fn)
- : ValueArray(fn.signature().outputs()), fn(fn) { }
-
-
-
-ValueArray::ValueArray(const SmallTypeVector &types)
- : types(types)
-{
- int total_size = 0;
- for (const Type *type : types) {
- this->offsets.append(total_size);
- total_size += type->size();
- }
- this->offsets.append(total_size);
- this->storage = SmallBuffer<>(total_size);
-}
+ : Tuple(fn.signature().outputs()), fn(fn) { }
Function::~Function()
{
diff --git a/source/blender/modifiers/intern/MOD_functiondeform.c b/source/blender/modifiers/intern/MOD_functiondeform.c
index 8319dd416dc..097340e7b6e 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform.c
+++ b/source/blender/modifiers/intern/MOD_functiondeform.c
@@ -48,15 +48,11 @@
#include "FN_functions.h"
-static void deformVerts(
- ModifierData *md,
- const ModifierEvalContext *UNUSED(ctx),
- Mesh *UNUSED(mesh),
+static void do_deformation(
+ FunctionDeformModifierData *fdmd,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list