[Bf-blender-cvs] [2e5df2cfa64] functions: allow tuple call to modify fn_in

Jacques Lucke noreply at git.blender.org
Sat Mar 9 16:15:45 CET 2019


Commit: 2e5df2cfa6473afd1b4a2b1866d4eadc116bb2e3
Author: Jacques Lucke
Date:   Sat Mar 9 14:22:14 2019 +0100
Branches: functions
https://developer.blender.org/rB2e5df2cfa6473afd1b4a2b1866d4eadc116bb2e3

allow tuple call to modify fn_in

===================================================================

M	source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
M	source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
M	source/blender/functions/backends/tuple_call/tuple.hpp
M	source/blender/functions/backends/tuple_call/tuple_call.hpp
M	source/blender/functions/frontends/data_flow_nodes/inserters.cpp
M	source/blender/functions/functions/lists.cpp
M	source/blender/functions/functions/object_input.cpp
M	source/blender/functions/functions/random.cpp
M	source/blender/functions/functions/scalar_math.cpp
M	source/blender/functions/functions/vectors.cpp
A	source/blender/functions/notes.txt
M	source/blender/modifiers/intern/MOD_functiondeform.c

===================================================================

diff --git a/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp b/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
index a787390d4f8..ed1f36502c0 100644
--- a/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
@@ -56,7 +56,7 @@ namespace FN {
 
 			LLVMTypeInfo *type_info = get_type_info(
 				fn->signature().inputs()[i].type());
-			llvm::Value *value = type_info->build_load_ir__copy(
+			llvm::Value *value = type_info->build_load_ir__relocate(
 				builder, value_byte_addr);
 
 			input_values.append(value);
@@ -99,9 +99,11 @@ namespace FN {
 			m_call = (LLVMCallFN)m_compiled->function_ptr();
 		}
 
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
+			fn_out.destruct_all();
 			BLI_assert(fn_in.all_initialized());
+			BLI_assert(fn_out.all_uninitialized());
 
 			m_call(
 				fn_in.data_ptr(),
@@ -109,6 +111,7 @@ namespace FN {
 				fn_out.data_ptr(),
 				fn_out.offsets_ptr());
 
+			fn_in.set_all_uninitialized();
 			fn_out.set_all_initialized();
 		}
 	};
diff --git a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
index aa8bb1c2560..3768f3613e8 100644
--- a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
+++ b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
@@ -14,14 +14,14 @@ namespace FN {
 			  m_inputs(function_graph.inputs()),
 			  m_outputs(function_graph.outputs()) {}
 
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			for (uint i = 0; i < m_outputs.size(); i++) {
 				this->compute_socket(fn_in, fn_out, i, m_outputs[i]);
 			}
 		}
 
-		void compute_socket(const Tuple &fn_in, Tuple &out, uint out_index, Socket socket) const
+		void compute_socket(Tuple &fn_in, Tuple &out, uint out_index, Socket socket) const
 		{
 			if (m_inputs.contains(socket)) {
 				uint index = m_inputs.index(socket);
diff --git a/source/blender/functions/backends/tuple_call/tuple.hpp b/source/blender/functions/backends/tuple_call/tuple.hpp
index 44d1d0b71de..fbf01738d21 100644
--- a/source/blender/functions/backends/tuple_call/tuple.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple.hpp
@@ -86,11 +86,7 @@ namespace FN {
 
 		~Tuple()
 		{
-			for (uint i = 0; i < m_meta->element_amount(); i++) {
-				if (m_initialized[i]) {
-					m_meta->type_infos()[i]->destruct_type(this->element_ptr(i));
-				}
-			}
+			this->destruct_all();
 			if (m_owns_mem) {
 				std::free(m_data);
 				std::free(m_initialized);
@@ -206,6 +202,16 @@ namespace FN {
 			return true;
 		}
 
+		bool all_uninitialized() const
+		{
+			for (uint i = 0; i < m_meta->element_amount(); i++) {
+				if (m_initialized[i]) {
+					return false;
+				}
+			}
+			return true;
+		}
+
 		void set_all_initialized()
 		{
 			for (uint i = 0; i < m_meta->element_amount(); i++) {
@@ -220,6 +226,16 @@ namespace FN {
 			}
 		}
 
+		void destruct_all()
+		{
+			for (uint i = 0; i < m_meta->element_amount(); i++) {
+				if (m_initialized[i]) {
+					m_meta->type_infos()[i]->destruct_type(this->element_ptr(i));
+					m_initialized[i] = false;
+				}
+			}
+		}
+
 	private:
 		inline void *element_ptr(uint index) const
 		{
diff --git a/source/blender/functions/backends/tuple_call/tuple_call.hpp b/source/blender/functions/backends/tuple_call/tuple_call.hpp
index 33237778f29..f409cf1e047 100644
--- a/source/blender/functions/backends/tuple_call/tuple_call.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple_call.hpp
@@ -11,7 +11,7 @@ namespace FN {
 
 		virtual ~TupleCallBody() {};
 
-		virtual void call(const Tuple &fn_in, Tuple &fn_out) const = 0;
+		virtual void call(Tuple &fn_in, Tuple &fn_out) const = 0;
 		virtual void init_defaults(Tuple &fn_in) const;
 	};
 
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
index 1397612b746..922f06533e7 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
@@ -74,7 +74,7 @@ namespace FN { namespace DataFlowNodes {
 			SmallVector<SocketLoader> &loaders)
 			: m_btree(btree), m_bsockets(bsockets), m_loaders(loaders) {}
 
-		void call(const Tuple &UNUSED(fn_in), Tuple &fn_out) const override
+		void call(Tuple &UNUSED(fn_in), Tuple &fn_out) const override
 		{
 			for (uint i = 0; i < m_bsockets.size(); i++) {
 				PointerRNA ptr;
diff --git a/source/blender/functions/functions/lists.cpp b/source/blender/functions/functions/lists.cpp
index a6c3e7756e3..070b0b75528 100644
--- a/source/blender/functions/functions/lists.cpp
+++ b/source/blender/functions/functions/lists.cpp
@@ -9,7 +9,7 @@ namespace FN { namespace Functions {
 	using namespace Types;
 
 	class AppendFloat : public TupleCallBody {
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			auto list = fn_in.copy_out<SharedFloatList>(0);
 			float value = fn_in.get<float>(1);
diff --git a/source/blender/functions/functions/object_input.cpp b/source/blender/functions/functions/object_input.cpp
index 6069dc8d652..906683f96de 100644
--- a/source/blender/functions/functions/object_input.cpp
+++ b/source/blender/functions/functions/object_input.cpp
@@ -18,7 +18,7 @@ namespace FN { namespace Functions {
 		ObjectTransforms(Object *object)
 			: m_object(object) {}
 
-		void call(const Tuple &UNUSED(fn_in), Tuple &fn_out) const override
+		void call(Tuple &UNUSED(fn_in), Tuple &fn_out) const override
 		{
 			if (m_object) {
 				Vector position = *(Vector *)m_object->loc;
diff --git a/source/blender/functions/functions/random.cpp b/source/blender/functions/functions/random.cpp
index d322f20156f..c4658889be1 100644
--- a/source/blender/functions/functions/random.cpp
+++ b/source/blender/functions/functions/random.cpp
@@ -22,7 +22,7 @@ namespace FN { namespace Functions {
 
 
 	class RandomNumber : public TupleCallBody {
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			uint32_t seed = fn_in.get<int32_t>(0);
 			float min = fn_in.get<float>(1);
diff --git a/source/blender/functions/functions/scalar_math.cpp b/source/blender/functions/functions/scalar_math.cpp
index 31bd50b1c38..c04ffcfa58f 100644
--- a/source/blender/functions/functions/scalar_math.cpp
+++ b/source/blender/functions/functions/scalar_math.cpp
@@ -22,7 +22,7 @@ namespace FN { namespace Functions {
 
 
 	class AddFloats : public TupleCallBody {
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			float a = fn_in.get<float>(0);
 			float b = fn_in.get<float>(1);
@@ -51,7 +51,7 @@ namespace FN { namespace Functions {
 
 
 	class MultiplyFloats : public TupleCallBody {
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			float a = fn_in.get<float>(0);
 			float b = fn_in.get<float>(1);
@@ -68,7 +68,7 @@ namespace FN { namespace Functions {
 
 
 	class MinFloats : public TupleCallBody {
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			float a = fn_in.get<float>(0);
 			float b = fn_in.get<float>(1);
@@ -85,7 +85,7 @@ namespace FN { namespace Functions {
 
 
 	class MaxFloats : public TupleCallBody {
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			float a = fn_in.get<float>(0);
 			float b = fn_in.get<float>(1);
@@ -102,7 +102,7 @@ namespace FN { namespace Functions {
 
 
 	class MapRange : public TupleCallBody {
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			float value = fn_in.get<float>(0);
 			float from_min = fn_in.get<float>(1);
diff --git a/source/blender/functions/functions/vectors.cpp b/source/blender/functions/functions/vectors.cpp
index 9d09c522788..4d2ae029299 100644
--- a/source/blender/functions/functions/vectors.cpp
+++ b/source/blender/functions/functions/vectors.cpp
@@ -67,7 +67,7 @@ namespace FN { namespace Functions {
 
 
 	class VectorDistance : public TupleCallBody {
-		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		void call(Tuple &fn_in, Tuple &fn_out) const override
 		{
 			Vector a = fn_in.get<Vector>(0);
 			Vector b = fn_in.get<Vector>(1);
diff --git a/source/blender/functions/notes.txt b/source/blender/functions/notes.txt
new file mode 100644
index 00000000000..924244600f7
--- /dev/null
+++ b/source/blender/functions/notes.txt
@@ -0,0 +1,20 @@
+- Some types can have multiple owners and are reference counted.
+    - Function
+    - Type
+    - DataFlowGraph
+    - TupleMeta
+
+- Function bodies are owned by a single function.
+- A function can have multiple bodies.
+- A function can have at most one body of a certain type.
+
+- Type extensions are owned by a single type.
+- A type can have multiple extensions.
+- A type can have at most one extensions of a certain type.
+
+Inside a tuple call:
+    - A tuple call body can modify fn_in and fn_out.
+    - The underlying tuple buffers are owned by the caller and might be freed any time after the function finished.
+    - When a tuple is freed, all initialized values in it are freed.
+    - A tuple call body has to initialize all values in fn_out.
+    - fn_out might already contain initialized values on entry.
\ No newline at end of file
diff --git a/source/blender/modifiers/intern/MOD_functiondeform.c b/source/blender/modifiers/intern/MOD_functiondeform.c
index b92be185472..0aeb072185e 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform.c
+++ b/source/blender/modifiers/intern/MOD_functiondeform.c
@@ -83,13 +83,12 @@ static void do_deformation(
 	FnTuple fn_in = FN_tuple_for_input(fn);
 	FnTuple fn_out = FN_tuple_for_output(fn);
 
-	FN_tuple_set_f

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list