[Bf-blender-cvs] [5948c5b87e4] nodes_playground: cleanup node class
Jacques Lucke
noreply at git.blender.org
Sun Jan 6 17:25:24 CET 2019
Commit: 5948c5b87e44040f48f9934176d04d10a513e4e0
Author: Jacques Lucke
Date: Fri Jan 4 10:29:55 2019 +0100
Branches: nodes_playground
https://developer.blender.org/rB5948c5b87e44040f48f9934176d04d10a513e4e0
cleanup node class
===================================================================
M source/blender/modifiers/intern/node_compiler.cpp
M source/blender/modifiers/intern/node_compiler.hpp
M source/blender/modifiers/intern/node_compiler_testing.cpp
===================================================================
diff --git a/source/blender/modifiers/intern/node_compiler.cpp b/source/blender/modifiers/intern/node_compiler.cpp
index 77a1524d62b..d0d8572496f 100644
--- a/source/blender/modifiers/intern/node_compiler.cpp
+++ b/source/blender/modifiers/intern/node_compiler.cpp
@@ -25,10 +25,10 @@ AnySocket Graph::getOriginSocket(AnySocket socket) const
const SocketInfo *AnySocket::info() const
{
if (this->is_input()) {
- return &this->node()->inputs[this->index()];
+ return &this->node()->inputs()[this->index()];
}
else {
- return &this->node()->outputs[this->index()];
+ return &this->node()->outputs()[this->index()];
}
}
@@ -42,7 +42,7 @@ std::string AnySocket::debug_name() const
return this->info()->debug_name;
}
-std::string SimpleNode::debug_id() const
+std::string Node::debug_id() const
{
std::stringstream ss;
ss << this->debug_name << " at " << (void *)this;
@@ -142,9 +142,9 @@ llvm::Value *Graph::generateCodeForSocket(
}
if (socket.is_output()) {
- SimpleNode *node = socket.node();
+ Node *node = socket.node();
std::vector<llvm::Value *> input_values;
- for (uint i = 0; i < node->inputs.size(); i++) {
+ for (uint i = 0; i < node->inputs().size(); i++) {
llvm::IRBuilder<> *next_builder;
llvm::Value *value = this->generateCodeForSocket(node->Input(i), builder, values, &next_builder);
@@ -154,9 +154,9 @@ llvm::Value *Graph::generateCodeForSocket(
}
std::vector<llvm::Value *> output_values;
- node->generateCode(input_values, builder, output_values, r_builder);
+ node->build_ir(input_values, builder, output_values, r_builder);
- for (uint i = 0; i < node->outputs.size(); i++) {
+ for (uint i = 0; i < node->outputs().size(); i++) {
values.add(node->Output(i), output_values[i]);
}
@@ -196,8 +196,8 @@ void Graph::findRequiredSockets(AnySocket socket, SocketSet &inputs, SocketSet &
}
if (socket.is_output()) {
- SimpleNode *node = socket.node();
- for (uint i = 0; i < node->inputs.size(); i++) {
+ Node *node = socket.node();
+ for (uint i = 0; i < node->inputs().size(); i++) {
AnySocket input = AnySocket::NewInput(socket.node(), i);
this->findRequiredSockets(input, inputs, required_sockets);
}
@@ -205,19 +205,19 @@ void Graph::findRequiredSockets(AnySocket socket, SocketSet &inputs, SocketSet &
}
}
-std::string Graph::toDotFormat(std::vector<SimpleNode *> marked_nodes) const
+std::string Graph::toDotFormat(std::vector<Node *> marked_nodes) const
{
std::stringstream ss;
ss << "digraph MyGraph {" << std::endl;
- for (SimpleNode *node : this->nodes) {
+ for (Node *node : this->nodes) {
ss << " \"" << node->debug_id() << "\" [style=\"filled\", fillcolor=\"#FFFFFF\"]" << std::endl;
}
for (Link link : this->links.links) {
ss << " \"" << link.from.node()->debug_id() << "\" -> \"" << link.to.node()->debug_id() << "\"" << std::endl;
}
- for (SimpleNode *node : marked_nodes) {
+ for (Node *node : marked_nodes) {
ss << " \"" << node->debug_id() << "\" [fillcolor=\"#FFAAAA\"]" << std::endl;
}
diff --git a/source/blender/modifiers/intern/node_compiler.hpp b/source/blender/modifiers/intern/node_compiler.hpp
index be67c8b47ab..e27ad4fb8e6 100644
--- a/source/blender/modifiers/intern/node_compiler.hpp
+++ b/source/blender/modifiers/intern/node_compiler.hpp
@@ -15,7 +15,7 @@ namespace LLVMNodeCompiler {
struct AnySocket;
struct SocketInfo;
-struct SimpleNode;
+struct Node;
struct Link;
struct LinkSet;
struct Graph;
@@ -23,16 +23,16 @@ struct Graph;
struct AnySocket {
inline bool is_output() const { return this->_is_output; }
inline bool is_input() const { return !this->_is_output; }
- inline SimpleNode *node() const { return this->_node; }
+ inline Node *node() const { return this->_node; }
inline uint index() const { return this->_index; }
llvm::Type *type() const;
std::string debug_name() const;
- inline static AnySocket NewInput(SimpleNode *node, uint index)
+ inline static AnySocket NewInput(Node *node, uint index)
{ return AnySocket(node, false, index); }
- inline static AnySocket NewOutput(SimpleNode *node, uint index)
+ inline static AnySocket NewOutput(Node *node, uint index)
{ return AnySocket(node, true, index); }
friend bool operator==(const AnySocket &left, const AnySocket &right)
@@ -44,12 +44,12 @@ struct AnySocket {
}
private:
- AnySocket(SimpleNode *node, bool is_output, uint index)
+ AnySocket(Node *node, bool is_output, uint index)
: _node(node), _is_output(is_output), _index(index) {}
const SocketInfo *info() const;
- SimpleNode *_node;
+ Node *_node;
bool _is_output;
uint _index;
};
@@ -70,20 +70,50 @@ struct SocketInfo {
: debug_name(debug_name), type(type) {}
};
-struct SimpleNode {
+typedef std::function<void(
+ std::vector<llvm::Value *> &inputs, llvm::IRBuilder<> *builder,
+ std::vector<llvm::Value *> &r_outputs, llvm::IRBuilder<> **r_builder)> IRBuilderFunction;
+
+class Node {
+private:
std::string debug_name;
- std::vector<SocketInfo> inputs;
- std::vector<SocketInfo> outputs;
- std::function<void(
- std::vector<llvm::Value *> &inputs, llvm::IRBuilder<> *builder,
- std::vector<llvm::Value *> &r_outputs, llvm::IRBuilder<> **r_builder)> generateCode;
+ std::vector<SocketInfo> _inputs;
+ std::vector<SocketInfo> _outputs;
+ IRBuilderFunction generateCode;
+
+public:
+ static Node *FromIRBuilderFunction(
+ const std::string &debug_name,
+ const std::vector<SocketInfo> &inputs,
+ const std::vector<SocketInfo> &outputs,
+ const IRBuilderFunction &generateCode)
+ {
+ Node *node = new Node();
+ node->debug_name = debug_name;
+ node->_inputs = inputs;
+ node->_outputs = outputs;
+ node->generateCode = generateCode;
+ return node;
+ }
std::string debug_id() const;
+ inline const std::vector<SocketInfo> &inputs()
+ { return this->_inputs; }
+ inline const std::vector<SocketInfo> &outputs()
+ { return this->_outputs; }
+
inline AnySocket Input(uint index)
{ return AnySocket::NewInput(this, index); }
inline AnySocket Output(uint index)
{ return AnySocket::NewOutput(this, index); }
+
+ void build_ir(
+ std::vector<llvm::Value *> &inputs, llvm::IRBuilder<> *builder,
+ std::vector<llvm::Value *> &r_outputs, llvm::IRBuilder<> **r_builder)
+ {
+ this->generateCode(inputs, builder, r_outputs, r_builder);
+ }
};
struct Link {
@@ -107,7 +137,7 @@ struct AnySocketHash {
};
struct Graph {
- std::vector<SimpleNode *> nodes;
+ std::vector<Node *> nodes;
LinkSet links;
llvm::Function *generateFunction(
@@ -121,7 +151,7 @@ struct Graph {
AnySocket getOriginSocket(AnySocket socket) const;
- std::string toDotFormat(std::vector<SimpleNode *> marked_nodes = {}) const;
+ std::string toDotFormat(std::vector<Node *> marked_nodes = {}) const;
SocketSet findRequiredSockets(SocketSet &inputs, SocketSet &outputs);
private:
diff --git a/source/blender/modifiers/intern/node_compiler_testing.cpp b/source/blender/modifiers/intern/node_compiler_testing.cpp
index 54faa17edc9..a7349da24b5 100644
--- a/source/blender/modifiers/intern/node_compiler_testing.cpp
+++ b/source/blender/modifiers/intern/node_compiler_testing.cpp
@@ -18,45 +18,46 @@ static void generateCode_AddNode(
*r_builder = builder;
}
-static NC::SimpleNode *new_add_node(llvm::LLVMContext &context)
+static NC::Node *new_add_node(llvm::LLVMContext &context)
{
- auto node = new NC::SimpleNode();
- node->debug_name = "Add";
- node->inputs.push_back(NC::SocketInfo("A", llvm::Type::getInt32Ty(context)));
- node->inputs.push_back(NC::SocketInfo("B", llvm::Type::getInt32Ty(context)));
- node->outputs.push_back(NC::SocketInfo("Result", llvm::Type::getInt32Ty(context)));
- node->generateCode = generateCode_AddNode;
- return node;
+ return NC::Node::FromIRBuilderFunction("Add",
+ { NC::SocketInfo("A", llvm::Type::getInt32Ty(context)),
+ NC::SocketInfo("B", llvm::Type::getInt32Ty(context)) },
+ { NC::SocketInfo("Result", llvm::Type::getInt32Ty(context)) },
+ generateCode_AddNode
+ );
}
-static NC::SimpleNode *new_int_node(llvm::LLVMContext &context, int value)
+static NC::Node *new_int_node(llvm::LLVMContext &context, int value)
{
- auto node = new NC::SimpleNode();
- node->debug_name = "Int";
- node->outputs.push_back(NC::SocketInfo("Value", llvm::Type::getInt32Ty(context)));
- node->generateCode = [value](
- std::vector<llvm::Value *> &UNUSED(inputs), llvm::IRBuilder<> *builder,
- std::vector<llvm::Value *> &r_outputs, llvm::IRBuilder<> **r_builder) {
- r_outputs.push_back(builder->getInt32(value));
- *r_builder = builder;
- };
- return node;
+ return NC::Node::FromIRBuilderFunction("Int",
+ {},
+ { NC::SocketInfo("Value", llvm::Type::getInt32Ty(context)) },
+ [value](
+ std::vector<llvm::Value *> &UNUSED(inputs), llvm::IRBuilder<> *builder,
+ std::vector<llvm::Value *> &r_outputs, llvm::IRBuilder<> **r_builder)
+ {
+ r_outputs.push_back(builder->getInt32(value));
+ *r_builder = builder;
+ }
+ );
}
-static NC::SimpleNode *new_int_ref_node(llvm::LLVMContext &context, int *value)
+static NC::Node *new_int_ref_node(llvm::LLVMContext &context, int *value)
{
- auto node = new NC::SimpleNode();
- node->debug_name = "Int Ref";
- node->outputs.push_back(NC::SocketInfo("Value", llvm::Type::getInt32Ty(context)));
- node->generateCode = [value](
- std::vector<llvm::Value *> &UNUSED(inputs), llvm::IRBuilder<> *builder,
- std::vector<llvm::Value *> &r_outputs, llvm::IRBuilder<> **r_builder) {
- auto address_int = builder->getInt64((uint64_t)value);
- auto address = builder->CreateIntToPtr(address_int, llvm::Type::getInt32PtrTy(builder->getContext()));
- r_outputs.push_back(builder->CreateLoad(address));
- *r_builder = builder;
- };
- return node;
+ return NC::Node::FromIRBuilderFunction("Int Ref",
+ {},
+ { NC::SocketInfo("Value", llvm::Type::getInt32Ty(context)) },
+ [value](
+ std::vector<llvm::Value *> &UNUSED(inputs), llvm::IRBuilder<> *builder,
+ std::vector<llvm::Value *> &r_outputs, llvm::IRBuilder<> **r_builder)
+ {
+ auto address_int = builder->getInt64((uint64_t)value);
+ auto address = builder->CreateIntToPtr(address_int, llvm::Type::getInt32PtrTy(builder->getContext()));
+ r_outputs.push_back(builder->CreateLoad(address));
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list