[Bf-blender-cvs] [40150c9] object_nodes: Extended TypeDesc to support compound type definitions (structures).

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


Commit: 40150c9e6e8f189452e08d4adaa0e509dda41f44
Author: Lukas Tönne
Date:   Fri Jan 15 11:10:03 2016 +0100
Branches: object_nodes
https://developer.blender.org/rB40150c9e6e8f189452e08d4adaa0e509dda41f44

Extended TypeDesc to support compound type definitions (structures).

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

M	source/blender/blenvm/compile/bvm_codegen.cc
M	source/blender/blenvm/compile/bvm_nodegraph.cc
M	source/blender/blenvm/compile/bvm_nodegraph.h
M	source/blender/blenvm/compile/bvm_typedesc.cc
M	source/blender/blenvm/compile/bvm_typedesc.h
M	source/blender/blenvm/intern/bvm_api.cc

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

diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index d95f4d9..860d6fa 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -234,7 +234,7 @@ void Compiler::resolve_symbols(const NodeGraph &graph)
 void Compiler::push_constant(const Value *value) const
 {
 	BLI_assert(value != NULL);
-	switch (value->typedesc().base_type) {
+	switch (value->typedesc().base_type()) {
 		case BVM_FLOAT: {
 			float f = 0.0f;
 			value->get(&f);
@@ -295,7 +295,7 @@ void Compiler::push_constant(const Value *value) const
 
 void Compiler::codegen_value(const Value *value, StackIndex offset) const
 {
-	switch (value->typedesc().base_type) {
+	switch (value->typedesc().base_type()) {
 		case BVM_FLOAT: {
 			float f = 0.0f;
 			value->get(&f);
@@ -371,7 +371,7 @@ void Compiler::codegen_value(const Value *value, StackIndex offset) const
 
 static OpCode ptr_init_opcode(const TypeDesc &typedesc)
 {
-	switch (typedesc.base_type) {
+	switch (typedesc.base_type()) {
 		case BVM_FLOAT:
 		case BVM_FLOAT3:
 		case BVM_FLOAT4:
@@ -391,7 +391,7 @@ static OpCode ptr_init_opcode(const TypeDesc &typedesc)
 
 static OpCode ptr_release_opcode(const TypeDesc &typedesc)
 {
-	switch (typedesc.base_type) {
+	switch (typedesc.base_type()) {
 		case BVM_FLOAT:
 		case BVM_FLOAT3:
 		case BVM_FLOAT4:
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 63b4d22..dd9d1c2 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -610,10 +610,10 @@ bool NodeGraph::has_typedef(const string &name)
 	return typedefs.find(name) != typedefs.end();
 }
 
-TypeDesc *NodeGraph::add_typedef(const string &name, BVMType base_type)
+TypeDesc *NodeGraph::add_typedef(const string &name, BVMType base_type, BVMBufferType buffer_type)
 {
 	std::pair<TypeDefMap::iterator, bool> result =
-	        typedefs.insert(TypeDefPair(name, TypeDesc(base_type)));
+	        typedefs.insert(TypeDefPair(name, TypeDesc(base_type, buffer_type)));
 	if (result.second) {
 		TypeDesc *typedesc = &result.first->second;
 		return typedesc;
@@ -622,6 +622,19 @@ TypeDesc *NodeGraph::add_typedef(const string &name, BVMType base_type)
 		return NULL;
 }
 
+TypeDesc *NodeGraph::add_typedef_struct(const string &name)
+{
+	std::pair<TypeDefMap::iterator, bool> result =
+	        typedefs.insert(TypeDefPair(name, TypeDesc(BVM_INT)));
+	if (result.second) {
+		TypeDesc *typedesc = &result.first->second;
+		typedesc->make_structure();
+		return typedesc;
+	}
+	else
+		return NULL;
+}
+
 void NodeGraph::remove_typedef(const string &name)
 {
 	TypeDefMap::iterator it = typedefs.find(name);
@@ -791,9 +804,9 @@ const NodeGraph::Output *NodeGraph::add_output(const string &name, const string
 NodeInstance *NodeGraph::add_proxy(const TypeDesc &typedesc, Value *default_value)
 {
 	NodeInstance *node = NULL;
-	switch (typedesc.buffer_type) {
+	switch (typedesc.buffer_type()) {
 		case BVM_BUFFER_SINGLE:
-			switch (typedesc.base_type) {
+			switch (typedesc.base_type()) {
 				case BVM_FLOAT: node = add_node("PASS_FLOAT"); break;
 				case BVM_FLOAT3: node = add_node("PASS_FLOAT3"); break;
 				case BVM_FLOAT4: node = add_node("PASS_FLOAT4"); break;
@@ -806,7 +819,7 @@ NodeInstance *NodeGraph::add_proxy(const TypeDesc &typedesc, Value *default_valu
 			}
 			break;
 		case BVM_BUFFER_ARRAY:
-			switch (typedesc.base_type) {
+			switch (typedesc.base_type()) {
 				case BVM_FLOAT: node = add_node("PASS_FLOAT_ARRAY"); break;
 				case BVM_FLOAT3: node = add_node("PASS_FLOAT3_ARRAY"); break;
 				case BVM_FLOAT4: node = add_node("PASS_FLOAT4_ARRAY"); break;
@@ -827,7 +840,7 @@ NodeInstance *NodeGraph::add_proxy(const TypeDesc &typedesc, Value *default_valu
 OutputKey NodeGraph::add_value_node(Value *value)
 {
 	NodeInstance *node = NULL;
-	switch (value->typedesc().base_type) {
+	switch (value->typedesc().base_type()) {
 		case BVM_FLOAT: node = add_node("VALUE_FLOAT"); break;
 		case BVM_FLOAT3: node = add_node("VALUE_FLOAT3"); break;
 		case BVM_FLOAT4: node = add_node("VALUE_FLOAT4"); break;
@@ -846,7 +859,7 @@ OutputKey NodeGraph::add_value_node(Value *value)
 OutputKey NodeGraph::add_argument_node(const TypeDesc &typedesc)
 {
 	NodeInstance *node = NULL;
-	switch (typedesc.base_type) {
+	switch (typedesc.base_type()) {
 		case BVM_FLOAT: node = add_node("ARG_FLOAT"); break;
 		case BVM_FLOAT3: node = add_node("ARG_FLOAT3"); break;
 		case BVM_FLOAT4: node = add_node("ARG_FLOAT4"); break;
@@ -1213,32 +1226,27 @@ static void register_typedefs()
 	t = NodeGraph::add_typedef("DUPLIS", BVM_DUPLIS);
 	
 	
-	t = NodeGraph::add_typedef("FLOAT_ARRAY", BVM_FLOAT);
-	t->buffer_type = BVM_BUFFER_ARRAY;
+	t = NodeGraph::add_typedef("FLOAT_ARRAY", BVM_FLOAT, BVM_BUFFER_ARRAY);
+	
+	t = NodeGraph::add_typedef("FLOAT3_ARRAY", BVM_FLOAT3, BVM_BUFFER_ARRAY);
+	
+	t = NodeGraph::add_typedef("FLOAT4_ARRAY", BVM_FLOAT4, BVM_BUFFER_ARRAY);
+	
+	t = NodeGraph::add_typedef("INT_ARRAY", BVM_INT, BVM_BUFFER_ARRAY);
 	
-	t = NodeGraph::add_typedef("FLOAT3_ARRAY", BVM_FLOAT3);
-	t->buffer_type = BVM_BUFFER_ARRAY;
+	t = NodeGraph::add_typedef("MATRIX44_ARRAY", BVM_MATRIX44, BVM_BUFFER_ARRAY);
 	
-	t = NodeGraph::add_typedef("FLOAT4_ARRAY", BVM_FLOAT4);
-	t->buffer_type = BVM_BUFFER_ARRAY;
+	t = NodeGraph::add_typedef("STRING_ARRAY", BVM_STRING, BVM_BUFFER_ARRAY);
 	
-	t = NodeGraph::add_typedef("INT_ARRAY", BVM_INT);
-	t->buffer_type = BVM_BUFFER_ARRAY;
+	t = NodeGraph::add_typedef("RNAPOINTER_ARRAY", BVM_RNAPOINTER, BVM_BUFFER_ARRAY);
 	
-	t = NodeGraph::add_typedef("MATRIX44_ARRAY", BVM_MATRIX44);
-	t->buffer_type = BVM_BUFFER_ARRAY;
+	t = NodeGraph::add_typedef("MESH_ARRAY", BVM_MESH, BVM_BUFFER_ARRAY);
 	
-	t = NodeGraph::add_typedef("STRING_ARRAY", BVM_STRING);
-	t->buffer_type = BVM_BUFFER_ARRAY;
+	t = NodeGraph::add_typedef("DUPLIS_ARRAY", BVM_DUPLIS, BVM_BUFFER_ARRAY);
 	
-	t = NodeGraph::add_typedef("RNAPOINTER_ARRAY", BVM_RNAPOINTER);
-	t->buffer_type = BVM_BUFFER_ARRAY;
 	
-	t = NodeGraph::add_typedef("MESH_ARRAY", BVM_MESH);
-	t->buffer_type = BVM_BUFFER_ARRAY;
 	
-	t = NodeGraph::add_typedef("DUPLIS_ARRAY", BVM_DUPLIS);
-	t->buffer_type = BVM_BUFFER_ARRAY;
+	(void)t;
 }
 
 OpCode get_opcode_from_node_type(const string &node)
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.h b/source/blender/blenvm/compile/bvm_nodegraph.h
index 4e6153d..bd01cf1 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.h
+++ b/source/blender/blenvm/compile/bvm_nodegraph.h
@@ -311,7 +311,8 @@ struct NodeGraph {
 	
 	static const TypeDesc &find_typedef(const string &name);
 	static bool has_typedef(const string &name);
-	static TypeDesc *add_typedef(const string &name, BVMType base_type);
+	static TypeDesc *add_typedef(const string &name, BVMType base_type, BVMBufferType buffer_type=BVM_BUFFER_SINGLE);
+	static TypeDesc *add_typedef_struct(const string &name);
 	static void remove_typedef(const string &name);
 	
 	static const NodeType *find_node_type(const string &name);
diff --git a/source/blender/blenvm/compile/bvm_typedesc.cc b/source/blender/blenvm/compile/bvm_typedesc.cc
index 23f679b..3856517 100644
--- a/source/blender/blenvm/compile/bvm_typedesc.cc
+++ b/source/blender/blenvm/compile/bvm_typedesc.cc
@@ -30,3 +30,191 @@
  */
 
 #include "bvm_typedesc.h"
+
+namespace bvm {
+
+StructSpec::StructSpec()
+{
+}
+
+StructSpec::StructSpec(const StructSpec &other) :
+	m_fields(other.m_fields)
+{
+}
+
+StructSpec::~StructSpec()
+{
+}
+
+StructSpec& StructSpec::operator = (const StructSpec &other)
+{
+	m_fields = other.m_fields;
+	return *this;
+}
+
+bool StructSpec::operator == (const StructSpec &other) const
+{
+	/* vector comparison: checks equality of size and of each element */
+	return m_fields == other.m_fields;
+}
+
+int StructSpec::find_field(const string &name) const
+{
+	for (int i = 0; i < m_fields.size(); ++i) {
+		if (m_fields[i].name == name)
+			return i;
+	}
+	return -1;
+}
+
+void StructSpec::add_field(const string &name, const TypeDesc &typedesc)
+{
+	m_fields.push_back(FieldSpec(name, typedesc));
+}
+
+/* ------------------------------------------------------------------------- */
+
+TypeDesc::TypeDesc(BVMType base_type, BVMBufferType buffer_type) :
+    m_base_type(base_type),
+    m_buffer_type(buffer_type),
+    m_structure(NULL)
+{
+}
+
+TypeDesc::TypeDesc(const TypeDesc &other)
+{
+	m_base_type = other.m_base_type;
+	m_buffer_type = other.m_buffer_type;
+	
+	if (other.m_structure)
+		m_structure = new StructSpec(*other.m_structure);
+	else
+		m_structure = NULL;
+}
+
+TypeDesc::~TypeDesc()
+{
+	if (m_structure)
+		delete m_structure;
+}
+
+TypeDesc& TypeDesc::operator = (const TypeDesc &other)
+{
+	m_base_type = other.m_base_type;
+	m_buffer_type = other.m_buffer_type;
+	
+	if (m_structure)
+		delete m_structure;
+	if (other.m_structure)
+		m_structure = new StructSpec(*other.m_structure);
+	else
+		m_structure = NULL;
+	return *this;
+}
+
+bool TypeDesc::operator == (const TypeDesc &other) const
+{
+	if (is_structure() && other.is_structure()) {
+		return *m_structure == *other.m_structure;
+	}
+	else if (!is_structure() && !other.is_structure()) {
+		return m_base_type == other.m_base_type &&
+		       m_buffer_type == other.m_buffer_type;
+	}
+	else
+		return false;
+}
+
+bool TypeDesc::assignable(const TypeDesc &other) const
+{
+	return *this == other;
+}
+
+int TypeDesc::stack_size() const
+{
+	if (m_structure) {
+		int size = 0;
+		for (int i = 0; i < m_structure->num_fields(); ++i)
+			size += m_structure->field(i).typedesc.stack_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_RNAPOINTE

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list