[Bf-blender-cvs] [01f7d71] object_nodes: Strict separation of input and output socket keys for clarity.
Lukas Tönne
noreply at git.blender.org
Mon Jan 4 15:21:51 CET 2016
Commit: 01f7d71fa71f3417c7e17c5172fb7e0309dba22b
Author: Lukas Tönne
Date: Mon Jan 4 13:47:03 2016 +0100
Branches: object_nodes
https://developer.blender.org/rB01f7d71fa71f3417c7e17c5172fb7e0309dba22b
Strict separation of input and output socket keys for clarity.
This avoids confusion regarding what socket keys are stored in maps etc.
===================================================================
M source/blender/blenvm/compile/bvm_codegen.cc
M source/blender/blenvm/compile/bvm_codegen.h
M source/blender/blenvm/compile/bvm_nodegraph.cc
M source/blender/blenvm/compile/bvm_nodegraph.h
M source/blender/blenvm/intern/bvm_api.cc
M source/blender/blenvm/util/bvm_util_debug.h
===================================================================
diff --git a/source/blender/blenvm/compile/bvm_codegen.cc b/source/blender/blenvm/compile/bvm_codegen.cc
index 87564c5..a8ef742 100644
--- a/source/blender/blenvm/compile/bvm_codegen.cc
+++ b/source/blender/blenvm/compile/bvm_codegen.cc
@@ -87,12 +87,12 @@ void Compiler::resolve_basic_block_symbols(const NodeGraph &graph, Compiler::Bas
const NodeInstance &node = **it;
/* local arguments for expression inputs */
- SocketIndexMap local_input_index;
+ OutputIndexMap local_input_index;
/* initialize output data stack entries */
for (int i = 0; i < node.num_outputs(); ++i) {
const NodeOutput *output = node.type->find_output(i);
- ConstSocketPair key(&node, output->name);
+ ConstOutputKey key(&node, output->name);
StackIndex stack_index;
if (block.output_index.find(key) == block.output_index.end()) {
@@ -115,7 +115,7 @@ void Compiler::resolve_basic_block_symbols(const NodeGraph &graph, Compiler::Bas
/* prepare input stack entries */
for (int i = 0; i < node.num_inputs(); ++i) {
const NodeInput *input = node.type->find_input(i);
- ConstSocketPair key(&node, input->name);
+ ConstInputKey key(&node, input->name);
assert(block.input_index.find(key) == block.input_index.end());
if (node.is_input_constant(i)) {
@@ -129,7 +129,7 @@ void Compiler::resolve_basic_block_symbols(const NodeGraph &graph, Compiler::Bas
resolve_basic_block_symbols(graph, expr_block);
- ConstSocketPair link_key = key.node->link(key.socket);
+ ConstOutputKey link_key = key.node->link(key.socket);
if (link_key.node) {
expr_block.return_index = expr_block.output_index.at(link_key);
}
@@ -139,7 +139,7 @@ void Compiler::resolve_basic_block_symbols(const NodeGraph &graph, Compiler::Bas
block.input_index[key] = expr_block.return_index;
}
else if (node.has_input_link(i)) {
- ConstSocketPair link_key(node.find_input_link_node(i),
+ ConstOutputKey link_key(node.find_input_link_node(i),
node.find_input_link_socket(i)->name);
block.input_index[key] = block.output_index.at(link_key);
}
@@ -408,7 +408,7 @@ static void count_output_users(const NodeGraph &graph,
for (NodeGraph::NodeInstanceMap::const_iterator it = graph.nodes.begin(); it != graph.nodes.end(); ++it) {
const NodeInstance *node = it->second;
for (int i = 0; i < node->num_outputs(); ++i) {
- ConstSocketPair key(node, node->type->find_output(i)->name);
+ ConstOutputKey key(node, node->type->find_output(i)->name);
users[key] = 0;
}
}
@@ -422,7 +422,7 @@ static void count_output_users(const NodeGraph &graph,
for (int i = 0; i < node->num_inputs(); ++i) {
if (node->has_input_link(i)) {
- ConstSocketPair key(node->find_input_link_node(i),
+ ConstOutputKey key(node->find_input_link_node(i),
node->find_input_link_socket(i)->name);
users[key] += 1;
}
@@ -451,7 +451,7 @@ int Compiler::codegen_basic_block(const Compiler::BasicBlock &block,
/* store values for unconnected inputs */
for (int i = 0; i < node.num_inputs(); ++i) {
const NodeInput *input = node.type->find_input(i);
- ConstSocketPair key(&node, input->name);
+ ConstInputKey key(&node, input->name);
if (node.is_input_constant(i) || node.is_input_expression(i)) {
/* stored directly in instructions */
@@ -468,7 +468,7 @@ int Compiler::codegen_basic_block(const Compiler::BasicBlock &block,
/* initialize output data stack entries */
for (int i = 0; i < node.num_outputs(); ++i) {
const NodeOutput *output = node.type->find_output(i);
- ConstSocketPair key(&node, output->name);
+ ConstOutputKey key(&node, output->name);
/* if necessary, add a user count initializer */
OpCode init_op = ptr_init_opcode(output->typedesc);
@@ -489,7 +489,7 @@ int Compiler::codegen_basic_block(const Compiler::BasicBlock &block,
/* write input stack offsets and constants */
for (int i = 0; i < node.num_inputs(); ++i) {
const NodeInput *input = node.type->find_input(i);
- ConstSocketPair key(&node, input->name);
+ ConstInputKey key(&node, input->name);
if (node.is_input_constant(i)) {
const Value *value = node.find_input_value(i);
@@ -509,7 +509,7 @@ int Compiler::codegen_basic_block(const Compiler::BasicBlock &block,
/* write output stack offsets */
for (int i = 0; i < node.num_outputs(); ++i) {
const NodeOutput *output = node.type->find_output(i);
- ConstSocketPair key(&node, output->name);
+ ConstOutputKey key(&node, output->name);
push_stack_index(block.output_index.at(key));
}
@@ -523,7 +523,7 @@ int Compiler::codegen_basic_block(const Compiler::BasicBlock &block,
/* pass */
}
else if (node.has_input_link(i)) {
- ConstSocketPair link_key(node.find_input_link_node(i),
+ ConstOutputKey link_key(node.find_input_link_node(i),
node.find_input_link_socket(i)->name);
OpCode release_op = ptr_release_opcode(input->typedesc);
@@ -548,12 +548,12 @@ int Compiler::codegen_main(const NodeGraph &graph)
/* first generate expression functions */
for (ExpressionMap::iterator it = expression_map.begin(); it != expression_map.end(); ++it) {
- const ConstSocketPair &key = it->first;
+ const ConstInputKey &key = it->first;
BasicBlock &block = it->second;
block.entry_point = codegen_basic_block(block, output_users);
- ConstSocketPair link_key = key.node->link(key.socket);
+ ConstOutputKey link_key = key.node->link(key.socket);
if (link_key.node) {
/* uses output value from the stack */
}
diff --git a/source/blender/blenvm/compile/bvm_codegen.h b/source/blender/blenvm/compile/bvm_codegen.h
index df8b57a..7af82a8 100644
--- a/source/blender/blenvm/compile/bvm_codegen.h
+++ b/source/blender/blenvm/compile/bvm_codegen.h
@@ -51,19 +51,20 @@ struct TypeDesc;
typedef std::vector<const NodeInstance *> NodeList;
typedef std::set<const NodeInstance *> NodeSet;
-typedef std::map<ConstSocketPair, StackIndex> SocketIndexMap;
-typedef std::map<ConstSocketPair, int> SocketUserMap;
+typedef std::map<ConstInputKey, StackIndex> InputIndexMap;
+typedef std::map<ConstOutputKey, StackIndex> OutputIndexMap;
+typedef std::map<ConstOutputKey, int> SocketUserMap;
struct Compiler {
struct BasicBlock {
BasicBlock() : entry_point(0), return_index(BVM_STACK_INVALID) {}
NodeList nodes;
- SocketIndexMap input_index;
- SocketIndexMap output_index;
+ InputIndexMap input_index;
+ OutputIndexMap output_index;
int entry_point;
StackIndex return_index;
};
- typedef std::map<ConstSocketPair, BasicBlock> ExpressionMap;
+ typedef std::map<ConstInputKey, BasicBlock> ExpressionMap;
typedef std::vector<int> StackUsers;
Compiler();
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc b/source/blender/blenvm/compile/bvm_nodegraph.cc
index c4cd174..5626368 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -234,6 +234,132 @@ const NodeOutput *NodeType::add_output(const string &name,
/* ------------------------------------------------------------------------- */
+ConstOutputKey::ConstOutputKey() :
+ node(NULL), socket("")
+{}
+
+ConstOutputKey::ConstOutputKey(const NodeInstance *node, const string &socket) :
+ node(node), socket(socket)
+{}
+
+bool ConstOutputKey::operator < (const ConstOutputKey &other) const
+{
+ if (node < other.node)
+ return true;
+ else if (node > other.node)
+ return false;
+ else
+ return socket < other.socket;
+}
+
+ConstOutputKey::operator bool() const
+{
+ return node != NULL && !socket.empty();
+}
+
+/*****/
+
+OutputKey::OutputKey() :
+ node(NULL), socket("")
+{}
+
+OutputKey::OutputKey(NodeInstance *node, const string &socket) :
+ node(node), socket(socket)
+{}
+
+OutputKey::operator ConstOutputKey() const
+{
+ return ConstOutputKey(node, socket);
+}
+
+bool OutputKey::operator < (const OutputKey &other) const
+{
+ if (node < other.node)
+ return true;
+ else if (node > other.node)
+ return false;
+ else
+ return socket < other.socket;
+}
+
+OutputKey::operator bool() const
+{
+ return node != NULL && !socket.empty();
+}
+
+/*****/
+
+ConstInputKey::ConstInputKey() :
+ node(NULL), socket("")
+{}
+
+ConstInputKey::ConstInputKey(const NodeInstance *node, const string &socket) :
+ node(node), socket(socket)
+{}
+
+bool ConstInputKey::operator < (const ConstInputKey &other) const
+{
+ if (node < other.node)
+ return true;
+ else if (node > other.node)
+ return false;
+ else
+ return socket < other.socket;
+}
+
+ConstInputKey::operator bool() const
+{
+ return node != NULL && !socket.empty();
+}
+
+ConstOutputKey ConstInputKey::link() const
+{
+ if (node)
+ return node->link(socket);
+ else
+ return ConstOutputKey();
+}
+
+/*****/
+
+InputKey::InputKey() :
+ node(NULL), socket("")
+{}
+
+InputKey::InputKey(NodeInstance *node, const string &socket) :
+ node(node), socket(socket)
+{}
+
+InputKey::operator ConstInputKey() const
+{
+ return ConstInputKey(node, socket);
+}
+
+bool InputKey::operator < (const InputKey &other) const
+{
+ if (node < other.node)
+ return true;
+ else if (node > other.node)
+ return false;
+ else
+ return socket < other.socket;
+}
+
+InputKey::operator bool() const
+{
+ return node != NULL && !socket.empty();
+}
+
+OutputKey InputKey::link() const
+{
+ if (node)
+ return node->link(socket);
+ else
+ return OutputKey();
+}
+
+/* ------------------------------------------------------------------------- */
+
NodeInstance::NodeInstance(const NodeType *type, const string &name) :
type(type), name(name)
{
@@ -249,52 +375,52 @@ NodeInstance::~NodeInstance()
}
}
-SocketPair NodeInstance::input(const string &name)
+InputKey NodeInstance::input(const string &name)
{
assert(type->find_input(name) != NULL);
- return SocketPair(this, name);
+ return InputKey(this, name);
}
-SocketPair NodeInstance::input(int index)
+InputKey NodeInstance::input(int index)
{
assert(type->find_input(index) != NULL);
- return SocketPair(this, type->find_input(index)->name);
+ return InputKey(this, type->find_input(index)->name);
}
-SocketPair
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list