[Bf-blender-cvs] [0549e0e] object_nodes: Cleanup: use size_t (i.e. size in bytes) for data types, rather than explicit stack size.

Lukas Tönne noreply at git.blender.org
Mon Jan 18 13:10:57 CET 2016


Commit: 0549e0eeaf8ee99157fae1e2a2059219723a26c6
Author: Lukas Tönne
Date:   Sat Jan 16 17:44:33 2016 +0100
Branches: object_nodes
https://developer.blender.org/rB0549e0eeaf8ee99157fae1e2a2059219723a26c6

Cleanup: use size_t (i.e. size in bytes) for data types, rather than explicit stack size.

The stack size is calculated during codegen by an int-ceil division,
currently padding to int size (probably later to be changed to int4 for
better SSE support).

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

M	source/blender/blenvm/bvm/bvm_eval.cc
M	source/blender/blenvm/bvm/bvm_eval.h
M	source/blender/blenvm/compile/bvm_codegen.cc
M	source/blender/blenvm/compile/bvm_typedesc.cc
M	source/blender/blenvm/compile/bvm_typedesc.h
M	source/blender/blenvm/util/bvm_util_math.h

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

diff --git a/source/blender/blenvm/bvm/bvm_eval.cc b/source/blender/blenvm/bvm/bvm_eval.cc
index 7285aa9..d389583 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -84,6 +84,13 @@ PointerRNA EvalGlobals::lookup_object(int key) const
 
 /* ------------------------------------------------------------------------- */
 
+int EvalStack::stack_size(size_t datasize)
+{
+	return int_div_ceil(datasize, sizeof(EvalStack));
+}
+
+/* ------------------------------------------------------------------------- */
+
 EvalContext::EvalContext()
 {
 }
diff --git a/source/blender/blenvm/bvm/bvm_eval.h b/source/blender/blenvm/bvm/bvm_eval.h
index b50b924..2e167f7 100644
--- a/source/blender/blenvm/bvm/bvm_eval.h
+++ b/source/blender/blenvm/bvm/bvm_eval.h
@@ -67,6 +67,8 @@ private:
 };
 
 struct EvalStack {
+	static int stack_size(size_t datasize);
+	
 	int value;
 };
 
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 860d6fa..acdd081 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -149,10 +149,10 @@ StackIndex Compiler::find_stack_index(int size) const
 
 StackIndex Compiler::assign_stack_index(const TypeDesc &typedesc)
 {
-	int size = typedesc.stack_size();
+	int stack_size = EvalStack::stack_size(typedesc.size());
 	
-	StackIndex stack_offset = find_stack_index(size);
-	for (int i = 0; i < size; ++i) {
+	StackIndex stack_offset = find_stack_index(stack_size);
+	for (int i = 0; i < stack_size; ++i) {
 		// TODO keep track of value users
 		stack_users[stack_offset + i] += 1;
 	}
diff --git a/source/blender/blenvm/compile/bvm_typedesc.cc b/source/blender/blenvm/compile/bvm_typedesc.cc
index 3856517..2d59f2c 100644
--- a/source/blender/blenvm/compile/bvm_typedesc.cc
+++ b/source/blender/blenvm/compile/bvm_typedesc.cc
@@ -130,31 +130,31 @@ bool TypeDesc::assignable(const TypeDesc &other) const
 	return *this == other;
 }
 
-int TypeDesc::stack_size() const
+size_t TypeDesc::size() const
 {
 	if (m_structure) {
-		int size = 0;
+		size_t size = 0;
 		for (int i = 0; i < m_structure->num_fields(); ++i)
-			size += m_structure->field(i).typedesc.stack_size();
+			size += m_structure->field(i).typedesc.size();
 		return size;
 	}
 	else {
 		switch (m_buffer_type) {
 			case BVM_BUFFER_SINGLE:
 				switch (m_base_type) {
-					case BVM_FLOAT: return BaseTypeTraits<BVM_FLOAT>::stack_size;
-					case BVM_FLOAT3: return BaseTypeTraits<BVM_FLOAT3>::stack_size;
-					case BVM_FLOAT4: return BaseTypeTraits<BVM_FLOAT4>::stack_size;
-					case BVM_INT: return BaseTypeTraits<BVM_INT>::stack_size;
-					case BVM_MATRIX44: return BaseTypeTraits<BVM_MATRIX44>::stack_size;
-					case BVM_STRING: return BaseTypeTraits<BVM_STRING>::stack_size;
-					case BVM_RNAPOINTER: return BaseTypeTraits<BVM_RNAPOINTER>::stack_size;
-					case BVM_MESH: return BaseTypeTraits<BVM_MESH>::stack_size;
-					case BVM_DUPLIS: return BaseTypeTraits<BVM_DUPLIS>::stack_size;
+					case BVM_FLOAT: return BaseTypeTraits<BVM_FLOAT>::size;
+					case BVM_FLOAT3: return BaseTypeTraits<BVM_FLOAT3>::size;
+					case BVM_FLOAT4: return BaseTypeTraits<BVM_FLOAT4>::size;
+					case BVM_INT: return BaseTypeTraits<BVM_INT>::size;
+					case BVM_MATRIX44: return BaseTypeTraits<BVM_MATRIX44>::size;
+					case BVM_STRING: return BaseTypeTraits<BVM_STRING>::size;
+					case BVM_RNAPOINTER: return BaseTypeTraits<BVM_RNAPOINTER>::size;
+					case BVM_MESH: return BaseTypeTraits<BVM_MESH>::size;
+					case BVM_DUPLIS: return BaseTypeTraits<BVM_DUPLIS>::size;
 				}
 				break;
 			case BVM_BUFFER_ARRAY:
-				return 4;
+				return 16;
 		}
 	}
 	
@@ -167,9 +167,9 @@ void TypeDesc::copy_value(void *to, const void *from) const
 		for (int i = 0; i < m_structure->num_fields(); ++i) {
 			m_structure->field(i).typedesc.copy_value(to, from);
 			
-			int size = m_structure->field(i).typedesc.stack_size();
-			to = ((float *)to) + size;
-			from = ((float *)from) + size;
+			size_t size = m_structure->field(i).typedesc.size();
+			to = ((uint8_t *)to) + size;
+			from = ((uint8_t *)from) + size;
 		}
 	}
 	else {
diff --git a/source/blender/blenvm/compile/bvm_typedesc.h b/source/blender/blenvm/compile/bvm_typedesc.h
index b012e1c..48aa149 100644
--- a/source/blender/blenvm/compile/bvm_typedesc.h
+++ b/source/blender/blenvm/compile/bvm_typedesc.h
@@ -56,7 +56,7 @@ template <>
 struct BaseTypeTraits<BVM_FLOAT> {
 	typedef float POD;
 	
-	enum eStackSize { stack_size = 1 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -68,7 +68,7 @@ template <>
 struct BaseTypeTraits<BVM_FLOAT3> {
 	typedef float3 POD;
 	
-	enum eStackSize { stack_size = 3 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -80,7 +80,7 @@ template <>
 struct BaseTypeTraits<BVM_FLOAT4> {
 	typedef float4 POD;
 	
-	enum eStackSize { stack_size = 4 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -92,7 +92,7 @@ template <>
 struct BaseTypeTraits<BVM_INT> {
 	typedef int POD;
 	
-	enum eStackSize { stack_size = 1 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -104,7 +104,7 @@ template <>
 struct BaseTypeTraits<BVM_MATRIX44> {
 	typedef matrix44 POD;
 	
-	enum eStackSize { stack_size = 16 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -116,7 +116,7 @@ template <>
 struct BaseTypeTraits<BVM_STRING> {
 	typedef const char* POD;
 	
-	enum eStackSize { stack_size = 2 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -128,7 +128,7 @@ template <>
 struct BaseTypeTraits<BVM_RNAPOINTER> {
 	typedef PointerRNA POD;
 	
-	enum eStackSize { stack_size = 6 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -140,7 +140,7 @@ template <>
 struct BaseTypeTraits<BVM_MESH> {
 	typedef mesh_ptr POD;
 	
-	enum eStackSize { stack_size = 8 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -152,7 +152,7 @@ template <>
 struct BaseTypeTraits<BVM_DUPLIS> {
 	typedef duplis_ptr POD;
 	
-	enum eStackSize { stack_size = 8 };
+	enum eStackSize { size = sizeof(POD) };
 	
 	static inline void copy(POD *to, const POD *from)
 	{
@@ -239,7 +239,7 @@ struct TypeDesc {
 	
 	bool assignable(const TypeDesc &other) const;
 	
-	int stack_size() const;
+	size_t size() const;
 	void copy_value(void *to, const void *from) const;
 	
 	bool is_structure() const { return m_structure != NULL; }
diff --git a/source/blender/blenvm/util/bvm_util_math.h b/source/blender/blenvm/util/bvm_util_math.h
index 2f00b65..093c72b 100644
--- a/source/blender/blenvm/util/bvm_util_math.h
+++ b/source/blender/blenvm/util/bvm_util_math.h
@@ -32,12 +32,28 @@
  *  \ingroup bvm
  */
 
+#include <assert.h>
+
 extern "C" {
 #include "BLI_math.h"
 }
 
 namespace bvm {
 
+static inline int int_div_floor(int a, int b)
+{
+	assert(a > 0);
+	assert(b > 0);
+	return a / b;
+}
+
+static inline int int_div_ceil(int a, int b)
+{
+	assert(a > 0);
+	assert(b > 0);
+	return 1 + ((a - 1) / b);
+}
+
 /* types */
 
 struct float3 {




More information about the Bf-blender-cvs mailing list