[Bf-blender-cvs] [6dc48fd18d6] functions: replace DataFlowGraphBuilder implementation
Jacques Lucke
noreply at git.blender.org
Thu Aug 1 18:23:01 CEST 2019
Commit: 6dc48fd18d682b778477f2ad5e70cf578a2ba4f1
Author: Jacques Lucke
Date: Thu Aug 1 13:26:34 2019 +0200
Branches: functions
https://developer.blender.org/rB6dc48fd18d682b778477f2ad5e70cf578a2ba4f1
replace DataFlowGraphBuilder implementation
===================================================================
M source/blender/blenlib/BLI_vector_adaptor.hpp
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_core.hpp
M source/blender/functions/backends/dependencies/dependencies.hpp
M source/blender/functions/core/data_flow_graph.cpp
M source/blender/functions/core/data_flow_graph.hpp
D source/blender/functions/core/data_flow_graph_builder.cpp
D source/blender/functions/core/data_flow_graph_builder.hpp
A source/blender/functions/core/data_graph_builder.cpp
A source/blender/functions/core/data_graph_builder.hpp
M source/blender/functions/core/dot_export.cpp
M source/blender/functions/core/function_graph.hpp
M source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
M source/blender/functions/frontends/data_flow_nodes/graph_generation.hpp
M source/blender/functions/frontends/data_flow_nodes/inserters.hpp
M source/blender/functions/frontends/data_flow_nodes/inserters/conversions.cpp
M source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
M source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
M source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.hpp
M source/blender/simulations/bparticles/inserters.cpp
===================================================================
diff --git a/source/blender/blenlib/BLI_vector_adaptor.hpp b/source/blender/blenlib/BLI_vector_adaptor.hpp
index 11352f3e73c..a2827a9ce7e 100644
--- a/source/blender/blenlib/BLI_vector_adaptor.hpp
+++ b/source/blender/blenlib/BLI_vector_adaptor.hpp
@@ -47,13 +47,6 @@ template<typename T> class VectorAdaptor {
{
}
- /**
- * Disable creating copies of the vector, because it would not be
- * clear, where the new adaptor should take the memory from.
- */
- VectorAdaptor(VectorAdaptor &other) = delete;
- VectorAdaptor(VectorAdaptor &&other) = delete;
-
/**
* Construct using any pointer and a capacity.
* The initial size is set to zero.
@@ -130,6 +123,11 @@ template<typename T> class VectorAdaptor {
return m_end - m_start;
}
+ bool is_full() const
+ {
+ return m_capacity == this->size();
+ }
+
operator ArrayRef<T>() const
{
return ArrayRef<T>(m_start, this->size());
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 85972fec3dd..33fd6a662e4 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -44,8 +44,8 @@ set(SRC
core/function_builder.cpp
core/data_flow_graph.hpp
core/data_flow_graph.cpp
- core/data_flow_graph_builder.hpp
- core/data_flow_graph_builder.cpp
+ core/data_graph_builder.hpp
+ core/data_graph_builder.cpp
core/function_graph.hpp
core/function_graph.cpp
core/source_info.hpp
diff --git a/source/blender/functions/FN_core.hpp b/source/blender/functions/FN_core.hpp
index 191d3aaecd5..0804084ea3a 100644
--- a/source/blender/functions/FN_core.hpp
+++ b/source/blender/functions/FN_core.hpp
@@ -7,4 +7,4 @@
#include "core/source_info.hpp"
#include "core/function_graph.hpp"
#include "core/data_flow_graph.hpp"
-#include "core/data_flow_graph_builder.hpp"
+#include "core/data_graph_builder.hpp"
diff --git a/source/blender/functions/backends/dependencies/dependencies.hpp b/source/blender/functions/backends/dependencies/dependencies.hpp
index 95acef230c6..7c6482be5ba 100644
--- a/source/blender/functions/backends/dependencies/dependencies.hpp
+++ b/source/blender/functions/backends/dependencies/dependencies.hpp
@@ -2,11 +2,15 @@
#include "FN_core.hpp"
+#include "BLI_multimap.hpp"
+
struct ID;
struct Object;
namespace FN {
+using BLI::MultiMap;
+
struct DependencyComponents {
SetVector<Object *> transform_dependencies;
SetVector<Object *> geometry_dependencies;
diff --git a/source/blender/functions/core/data_flow_graph.cpp b/source/blender/functions/core/data_flow_graph.cpp
index 394b5444124..8ec4b46ba0e 100644
--- a/source/blender/functions/core/data_flow_graph.cpp
+++ b/source/blender/functions/core/data_flow_graph.cpp
@@ -2,69 +2,22 @@
namespace FN {
-DataFlowGraph::BuildResult DataFlowGraph::FromBuilder(DataFlowGraphBuilder &builder)
+DataFlowGraph::DataFlowGraph(Vector<Node> nodes,
+ Vector<InputSocket> inputs,
+ Vector<OutputSocket> outputs,
+ Vector<uint> targets,
+ std::unique_ptr<MonotonicAllocator<>> source_info_allocator)
+ : m_nodes(std::move(nodes)),
+ m_inputs(std::move(inputs)),
+ m_outputs(std::move(outputs)),
+ m_targets(std::move(targets)),
+ m_source_info_allocator(std::move(source_info_allocator))
{
- BuildResult result = {SharedDataFlowGraph::New(), {}};
-
- SharedDataFlowGraph &graph = result.graph;
- ToBuilderMapping &mapping = result.mapping;
-
- auto dfgb_nodes = builder.nodes();
-
- graph->m_nodes.reserve(dfgb_nodes.size());
-
- const uint dummy = (uint)-1;
-
- for (DFGB_Node *dfgb_node : dfgb_nodes) {
- uint node_id = graph->m_nodes.size();
- graph->m_nodes.append(MyNode(dfgb_node->function(),
- dfgb_node->source(),
- graph->m_inputs.size(),
- graph->m_outputs.size()));
- mapping.node_indices.add_new(dfgb_node, node_id);
-
- for (DFGB_Socket dfgb_input : dfgb_node->inputs()) {
- mapping.input_socket_indices.add_new(dfgb_input, graph->m_inputs.size());
- graph->m_inputs.append(InputSocket(node_id, dummy));
- }
- for (DFGB_Socket output : dfgb_node->outputs()) {
- auto targets = output.targets();
- mapping.output_socket_indices.add_new(output, graph->m_outputs.size());
- graph->m_outputs.append(OutputSocket(node_id, graph->m_targets.size(), targets.size()));
- for (uint i = 0; i < targets.size(); i++) {
- graph->m_targets.append(dummy);
- }
- }
- }
-
- for (DFGB_Node *dfgb_node : dfgb_nodes) {
- for (DFGB_Socket dfgb_input : dfgb_node->inputs()) {
- uint input_id = mapping.input_socket_indices.lookup(dfgb_input);
- Optional<DFGB_Socket> dfgb_origin = dfgb_input.origin();
- BLI_assert(dfgb_origin.has_value());
- uint origin_id = mapping.output_socket_indices.lookup(dfgb_origin.value());
- graph->m_inputs[input_id].origin = origin_id;
- }
- for (DFGB_Socket dfgb_output : dfgb_node->outputs()) {
- uint output_id = mapping.output_socket_indices.lookup(dfgb_output);
- uint start = graph->m_outputs[output_id].targets_start;
- auto dfgb_targets = dfgb_output.targets();
- for (uint i = 0; i < dfgb_targets.size(); i++) {
- DFGB_Socket dfgb_target = dfgb_targets[i];
- uint target_id = mapping.input_socket_indices.lookup(dfgb_target);
- graph->m_targets[start + i] = target_id;
- }
- }
- }
-
- graph->m_source_info_allocator = std::move(builder.m_source_info_allocator);
-
- return result;
}
DataFlowGraph::~DataFlowGraph()
{
- for (MyNode node : m_nodes) {
+ for (Node node : m_nodes) {
if (node.source_info != nullptr) {
node.source_info->~SourceInfo();
}
@@ -87,41 +40,41 @@ void DataFlowGraph::print_socket(DFGraphSocket socket) const
std::string DataFlowGraph::to_dot()
{
- DataFlowGraphBuilder builder;
+ DataGraphBuilder builder;
this->insert_in_builder(builder);
return builder.to_dot();
}
void DataFlowGraph::to_dot__clipboard()
{
- DataFlowGraphBuilder builder;
+ DataGraphBuilder builder;
this->insert_in_builder(builder);
builder.to_dot__clipboard();
}
-void DataFlowGraph::insert_in_builder(DataFlowGraphBuilder &builder)
+void DataFlowGraph::insert_in_builder(DataGraphBuilder &builder)
{
- Vector<DFGB_Node *> dfgb_nodes;
+ Vector<BuilderNode *> builder_nodes;
for (auto &node : m_nodes) {
- DFGB_Node *dfgb_node = builder.insert_function(node.function);
- dfgb_nodes.append(dfgb_node);
+ BuilderNode *builder_node = builder.insert_function(node.function);
+ builder_nodes.append(builder_node);
}
for (uint input_id = 0; input_id < m_inputs.size(); input_id++) {
uint from_id = m_inputs[input_id].origin;
uint from_node_id = m_outputs[from_id].node;
uint from_index = this->index_of_output(from_id);
- DFGB_Node *from_dfgb_node = dfgb_nodes[from_node_id];
- DFGB_Socket from_dfgb_socket = from_dfgb_node->output(from_index);
+ BuilderNode *from_builder_node = builder_nodes[from_node_id];
+ auto *from_builder_socket = from_builder_node->outputs()[from_index];
uint to_id = input_id;
uint to_node_id = m_inputs[to_id].node;
uint to_index = this->index_of_input(to_id);
- DFGB_Node *to_dfgb_node = dfgb_nodes[to_node_id];
- DFGB_Socket to_dfgb_socket = to_dfgb_node->input(to_index);
+ BuilderNode *to_builder_node = builder_nodes[to_node_id];
+ auto *to_builder_socket = to_builder_node->inputs()[to_index];
- builder.insert_link(from_dfgb_socket, to_dfgb_socket);
+ builder.insert_link(from_builder_socket, to_builder_socket);
}
}
diff --git a/source/blender/functions/core/data_flow_graph.hpp b/source/blender/functions/core/data_flow_graph.hpp
index 8cc713b8d93..26a2e4fee67 100644
--- a/source/blender/functions/core/data_flow_graph.hpp
+++ b/source/blender/functions/core/data_flow_graph.hpp
@@ -23,12 +23,20 @@
* an output or output has to be stored.
*/
-#include "function.hpp"
-#include "data_flow_graph_builder.hpp"
#include "BLI_range.hpp"
+#include "BLI_map.hpp"
+#include "BLI_monotonic_allocator.hpp"
+
+#include "function.hpp"
+#include "source_info.hpp"
namespace FN {
+using BLI::Map;
+using BLI::MonotonicAllocator;
+
+class DataGraphBuilder;
+
/**
* Represents any socket in the graph by storing its ID and whether it is an input or output.
*/
@@ -150,8 +158,8 @@ class DataFlowGraph;
using SharedDataFlowGraph = AutoRefCount<DataFlowGraph>;
class DataFlowGraph : public RefCountedBase {
- private:
- struct MyNode {
+ public:
+ struct Node {
SharedFunction function;
SourceInfo *source_info;
/* Index into m_origins. */
@@ -159,7 +167,7 @@ class DataFlowGraph : public RefCountedBase {
/* Index into m_targets_info. */
uint outputs_start;
- MyNode(SharedFunction fn, SourceInfo *source_info, uint inputs_start, uint outputs_start)
+ Node(SharedFunction fn, SourceInfo *source_info, uint inputs_start, uint outputs_start)
: function(std::move(fn)),
source_info(source_info),
inputs_start(inputs_start),
@@ -188,49 +196,23 @@ class DataFlowGraph : public RefCountedBase {
}
};
- Vector<MyNode> m_nodes;
+ private:
+ Vector<Node> m_nodes;
Vector<InputSocket> m_inputs;
Vector<OutputSocket> m_outputs;
Vector<uint> m_targets;
std::unique_ptr<MonotonicAllocator<>> m_source_info_allocator;
public:
- DataFlowGraph() = default;
+ DataFlowGraph(Vector<Node> nodes,
+ Vector<InputSocket> inputs,
+ Vector<OutputSocket> outputs,
+ Vector<uint> targets,
+ std::unique_ptr<MonotonicAllocator<>> source_info_allocator);
+
DataFlowGraph(DataFlowGraph &other) = delete;
~DataFlowGraph();
- struct ToBuilderMapping {
- Map<DFGB_Node *, uint> node_indices;
- Map<DFGB_Socket, uint> input_socket_indices;
- Map<DFGB_Socket, uint> output_socket_indices;
-
- DFGraphSocket map_socket(DFGB_Socket dfgb_socket)
- {
- if (dfgb_socket.is_input()) {
- return DFGraphSocket(false
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list