diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-06-17 18:10:19 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-06-17 18:10:19 +0300 |
commit | 06a1a66a9b6f120867d3bbebe3928744ec8e3495 (patch) | |
tree | 42e827a3cf58eb76474e479206b02a8d97dd3bf7 /source/blender/compositor/intern/COM_NodeOperationBuilder.cpp | |
parent | 61d27db35967710421ab92748e09624db068258d (diff) | |
parent | a24b4e6090057479796e914bc603119b12f6ca06 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/compositor/intern/COM_NodeOperationBuilder.cpp')
-rw-r--r-- | source/blender/compositor/intern/COM_NodeOperationBuilder.cpp | 160 |
1 files changed, 80 insertions, 80 deletions
diff --git a/source/blender/compositor/intern/COM_NodeOperationBuilder.cpp b/source/blender/compositor/intern/COM_NodeOperationBuilder.cpp index fc1584e3dbb..f282037823a 100644 --- a/source/blender/compositor/intern/COM_NodeOperationBuilder.cpp +++ b/source/blender/compositor/intern/COM_NodeOperationBuilder.cpp @@ -58,18 +58,18 @@ void NodeOperationBuilder::convertToOperations(ExecutionSystem *system) { /* interface handle for nodes */ NodeConverter converter(this); - + for (int index = 0; index < m_graph.nodes().size(); index++) { Node *node = (Node *)m_graph.nodes()[index]; - + m_current_node = node; - + DebugInfo::node_to_operations(node); node->convertToOperations(converter, *m_context); } - + m_current_node = NULL; - + /* The input map constructed by nodes maps operation inputs to node inputs. * Inverting yields a map of node inputs to all connected operation inputs, * so multiple operations can use the same node input. @@ -77,12 +77,12 @@ void NodeOperationBuilder::convertToOperations(ExecutionSystem *system) OpInputInverseMap inverse_input_map; for (InputSocketMap::const_iterator it = m_input_map.begin(); it != m_input_map.end(); ++it) inverse_input_map[it->second].push_back(it->first); - + for (NodeGraph::Links::const_iterator it = m_graph.links().begin(); it != m_graph.links().end(); ++it) { const NodeGraph::Link &link = *it; NodeOutput *from = link.getFromSocket(); NodeInput *to = link.getToSocket(); - + NodeOperationOutput *op_from = find_operation_output(m_output_map, from); const OpInputs &op_to_list = find_operation_inputs(inverse_input_map, to); if (!op_from || op_to_list.empty()) { @@ -94,36 +94,36 @@ void NodeOperationBuilder::convertToOperations(ExecutionSystem *system) */ continue; } - + for (OpInputs::const_iterator it = op_to_list.begin(); it != op_to_list.end(); ++it) { NodeOperationInput *op_to = *it; addLink(op_from, op_to); } } - + add_operation_input_constants(); - + resolve_proxies(); - + add_datatype_conversions(); - + determineResolutions(); - + /* surround complex ops with read/write buffer */ add_complex_operation_buffers(); - + /* links not available from here on */ /* XXX make m_links a local variable to avoid confusion! */ m_links.clear(); - + prune_operations(); - + /* ensure topological (link-based) order of nodes */ /*sort_operations();*/ /* not needed yet */ - + /* create execution groups */ group_operations(); - + /* transfer resulting operations to the system */ system->set_operations(m_operations, m_groups); } @@ -137,7 +137,7 @@ void NodeOperationBuilder::mapInputSocket(NodeInput *node_socket, NodeOperationI { BLI_assert(m_current_node); BLI_assert(node_socket->getNode() == m_current_node); - + /* note: this maps operation sockets to node sockets. * for resolving links the map will be inverted first in convertToOperations, * to get a list of links for each node input socket. @@ -149,7 +149,7 @@ void NodeOperationBuilder::mapOutputSocket(NodeOutput *node_socket, NodeOperatio { BLI_assert(m_current_node); BLI_assert(node_socket->getNode() == m_current_node); - + m_output_map[node_socket] = operation_socket; } @@ -157,9 +157,9 @@ void NodeOperationBuilder::addLink(NodeOperationOutput *from, NodeOperationInput { if (to->isConnected()) return; - + m_links.push_back(Link(from, to)); - + /* register with the input */ to->setLink(from); } @@ -171,7 +171,7 @@ void NodeOperationBuilder::removeInputLink(NodeOperationInput *to) if (link.to() == to) { /* unregister with the input */ to->setLink(NULL); - + m_links.erase(it); return; } @@ -200,7 +200,7 @@ NodeOperationOutput *NodeOperationBuilder::find_operation_output(const OutputSoc PreviewOperation *NodeOperationBuilder::make_preview_operation() const { BLI_assert(m_current_node); - + if (!(m_current_node->getbNode()->flag & NODE_PREVIEW)) return NULL; /* previews only in the active group */ @@ -209,7 +209,7 @@ PreviewOperation *NodeOperationBuilder::make_preview_operation() const /* do not calculate previews of hidden nodes */ if (m_current_node->getbNode()->flag & NODE_HIDDEN) return NULL; - + bNodeInstanceHash *previews = m_context->getPreviewHash(); if (previews) { PreviewOperation *operation = new PreviewOperation(m_context->getViewSettings(), m_context->getDisplaySettings()); @@ -217,7 +217,7 @@ PreviewOperation *NodeOperationBuilder::make_preview_operation() const operation->verifyPreview(previews, m_current_node->getInstanceKey()); return operation; } - + return NULL; } @@ -226,7 +226,7 @@ void NodeOperationBuilder::addPreview(NodeOperationOutput *output) PreviewOperation *operation = make_preview_operation(); if (operation) { addOperation(operation); - + addLink(output, operation->getInputSocket(0)); } } @@ -236,7 +236,7 @@ void NodeOperationBuilder::addNodeInputPreview(NodeInput *input) PreviewOperation *operation = make_preview_operation(); if (operation) { addOperation(operation); - + mapInputSocket(input, operation->getInputSocket(0)); } } @@ -247,7 +247,7 @@ void NodeOperationBuilder::registerViewer(ViewerOperation *viewer) if (m_current_node->isInActiveGroup()) { /* deactivate previous viewer */ m_active_viewer->setActive(false); - + m_active_viewer = viewer; viewer->setActive(true); } @@ -269,13 +269,13 @@ void NodeOperationBuilder::add_datatype_conversions() Links convert_links; for (Links::const_iterator it = m_links.begin(); it != m_links.end(); ++it) { const Link &link = *it; - + /* proxy operations can skip data type conversion */ NodeOperation *from_op = &link.from()->getOperation(); NodeOperation *to_op = &link.to()->getOperation(); if (!(from_op->useDatatypeConversion() || to_op->useDatatypeConversion())) continue; - + if (link.from()->getDataType() != link.to()->getDataType()) convert_links.push_back(link); } @@ -284,7 +284,7 @@ void NodeOperationBuilder::add_datatype_conversions() NodeOperation *converter = Converter::convertDataType(link.from(), link.to()); if (converter) { addOperation(converter); - + removeInputLink(link.to()); addLink(link.from(), converter->getInputSocket(0)); addLink(converter->getOutputSocket(0), link.to()); @@ -322,7 +322,7 @@ void NodeOperationBuilder::add_input_constant_value(NodeOperationInput *input, N value = node_input->getEditorValueFloat(); else value = 0.0f; - + SetValueOperation *op = new SetValueOperation(); op->setValue(value); addOperation(op); @@ -335,7 +335,7 @@ void NodeOperationBuilder::add_input_constant_value(NodeOperationInput *input, N node_input->getEditorValueColor(value); else zero_v4(value); - + SetColorOperation *op = new SetColorOperation(); op->setChannels(value); addOperation(op); @@ -348,7 +348,7 @@ void NodeOperationBuilder::add_input_constant_value(NodeOperationInput *input, N node_input->getEditorValueVector(value); else zero_v3(value); - + SetVectorOperation *op = new SetVectorOperation(); op->setVector(value); addOperation(op); @@ -370,17 +370,17 @@ void NodeOperationBuilder::resolve_proxies() proxy_links.push_back(link); } } - + for (Links::const_iterator it = proxy_links.begin(); it != proxy_links.end(); ++it) { const Link &link = *it; - + NodeOperationInput *to = link.to(); NodeOperationOutput *from = link.from(); do { /* walk upstream bypassing the proxy operation */ from = from->getOperation().getInputSocket(0)->getLink(); } while (from && from->getOperation().isProxyOperation()); - + removeInputLink(to); /* we may not have a final proxy input link, * in that case it just gets dropped @@ -395,7 +395,7 @@ void NodeOperationBuilder::determineResolutions() /* determine all resolutions of the operations (Width/Height) */ for (Operations::const_iterator it = m_operations.begin(); it != m_operations.end(); ++it) { NodeOperation *op = *it; - + if (op->isOutputOperation(m_context->isRendering()) && !op->isPreviewOperation()) { unsigned int resolution[2] = {0, 0}; unsigned int preferredResolution[2] = {0, 0}; @@ -403,10 +403,10 @@ void NodeOperationBuilder::determineResolutions() op->setResolution(resolution); } } - + for (Operations::const_iterator it = m_operations.begin(); it != m_operations.end(); ++it) { NodeOperation *op = *it; - + if (op->isOutputOperation(m_context->isRendering()) && op->isPreviewOperation()) { unsigned int resolution[2] = {0, 0}; unsigned int preferredResolution[2] = {0, 0}; @@ -414,13 +414,13 @@ void NodeOperationBuilder::determineResolutions() op->setResolution(resolution); } } - + /* add convert resolution operations when needed */ { Links convert_links; for (Links::const_iterator it = m_links.begin(); it != m_links.end(); ++it) { const Link &link = *it; - + if (link.to()->getResizeMode() != COM_SC_NO_RESIZE) { NodeOperation &from_op = link.from()->getOperation(); NodeOperation &to_op = link.to()->getOperation(); @@ -464,35 +464,35 @@ void NodeOperationBuilder::add_input_buffers(NodeOperation * /*operation*/, { if (!input->isConnected()) return; - + NodeOperationOutput *output = input->getLink(); if (output->getOperation().isReadBufferOperation()) { /* input is already buffered, no need to add another */ return; } - + /* this link will be replaced below */ removeInputLink(input); - + /* check of other end already has write operation, otherwise add a new one */ WriteBufferOperation *writeoperation = find_attached_write_buffer_operation(output); if (!writeoperation) { writeoperation = new WriteBufferOperation(output->getDataType()); writeoperation->setbNodeTree(m_context->getbNodeTree()); addOperation(writeoperation); - + addLink(output, writeoperation->getInputSocket(0)); - + writeoperation->readResolutionFromInputSocket(); } - + /* add readbuffer op for the input */ ReadBufferOperation *readoperation = new ReadBufferOperation(output->getDataType()); readoperation->setMemoryProxy(writeoperation->getMemoryProxy()); this->addOperation(readoperation); - + addLink(readoperation->getOutputSocket(), input); - + readoperation->readResolutionFromWriteBuffer(); } @@ -502,11 +502,11 @@ void NodeOperationBuilder::add_output_buffers(NodeOperation *operation, NodeOper OpInputs targets = cache_output_links(output); if (targets.empty()) return; - + WriteBufferOperation *writeOperation = NULL; for (OpInputs::const_iterator it = targets.begin(); it != targets.end(); ++it) { NodeOperationInput *target = *it; - + /* try to find existing write buffer operation */ if (target->getOperation().isWriteBufferOperation()) { BLI_assert(writeOperation == NULL); /* there should only be one write op connected */ @@ -517,30 +517,30 @@ void NodeOperationBuilder::add_output_buffers(NodeOperation *operation, NodeOper removeInputLink(target); } } - + /* if no write buffer operation exists yet, create a new one */ if (!writeOperation) { writeOperation = new WriteBufferOperation(operation->getOutputSocket()->getDataType()); writeOperation->setbNodeTree(m_context->getbNodeTree()); addOperation(writeOperation); - + addLink(output, writeOperation->getInputSocket(0)); } - + writeOperation->readResolutionFromInputSocket(); - + /* add readbuffer op for every former connected input */ for (OpInputs::const_iterator it = targets.begin(); it != targets.end(); ++it) { NodeOperationInput *target = *it; if (&target->getOperation() == writeOperation) continue; /* skip existing write op links */ - + ReadBufferOperation *readoperation = new ReadBufferOperation(operation->getOutputSocket()->getDataType()); readoperation->setMemoryProxy(writeOperation->getMemoryProxy()); addOperation(readoperation); - + addLink(readoperation->getOutputSocket(), target); - + readoperation->readResolutionFromWriteBuffer(); } } @@ -554,15 +554,15 @@ void NodeOperationBuilder::add_complex_operation_buffers() for (Operations::const_iterator it = m_operations.begin(); it != m_operations.end(); ++it) if ((*it)->isComplex()) complex_ops.push_back(*it); - + for (Operations::const_iterator it = complex_ops.begin(); it != complex_ops.end(); ++it) { NodeOperation *op = *it; - + DebugInfo::operation_read_write_buffer(op); - + for (int index = 0; index < op->getNumberOfInputSockets(); index++) add_input_buffers(op, op->getInputSocket(index)); - + for (int index = 0; index < op->getNumberOfOutputSockets(); index++) add_output_buffers(op, op->getOutputSocket(index)); } @@ -575,13 +575,13 @@ static void find_reachable_operations_recursive(Tags &reachable, NodeOperation * if (reachable.find(op) != reachable.end()) return; reachable.insert(op); - + for (int i = 0; i < op->getNumberOfInputSockets(); ++i) { NodeOperationInput *input = op->getInputSocket(i); if (input->isConnected()) find_reachable_operations_recursive(reachable, &input->getLink()->getOperation()); } - + /* associated write-buffer operations are executed as well */ if (op->isReadBufferOperation()) { ReadBufferOperation *read_op = (ReadBufferOperation *)op; @@ -595,17 +595,17 @@ void NodeOperationBuilder::prune_operations() Tags reachable; for (Operations::const_iterator it = m_operations.begin(); it != m_operations.end(); ++it) { NodeOperation *op = *it; - + /* output operations are primary executed operations */ if (op->isOutputOperation(m_context->isRendering())) find_reachable_operations_recursive(reachable, op); } - + /* delete unreachable operations */ Operations reachable_ops; for (Operations::const_iterator it = m_operations.begin(); it != m_operations.end(); ++it) { NodeOperation *op = *it; - + if (reachable.find(op) != reachable.end()) reachable_ops.push_back(op); else @@ -621,13 +621,13 @@ static void sort_operations_recursive(NodeOperationBuilder::Operations &sorted, if (visited.find(op) != visited.end()) return; visited.insert(op); - + for (int i = 0; i < op->getNumberOfInputSockets(); ++i) { NodeOperationInput *input = op->getInputSocket(i); if (input->isConnected()) sort_operations_recursive(sorted, visited, &input->getLink()->getOperation()); } - + sorted.push_back(op); } @@ -636,10 +636,10 @@ void NodeOperationBuilder::sort_operations() Operations sorted; sorted.reserve(m_operations.size()); Tags visited; - + for (Operations::const_iterator it = m_operations.begin(); it != m_operations.end(); ++it) sort_operations_recursive(sorted, visited, *it); - + m_operations = sorted; } @@ -648,10 +648,10 @@ static void add_group_operations_recursive(Tags &visited, NodeOperation *op, Exe if (visited.find(op) != visited.end()) return; visited.insert(op); - + if (!group->addOperation(op)) return; - + /* add all eligible input ops to the group */ for (int i = 0; i < op->getNumberOfInputSockets(); ++i) { NodeOperationInput *input = op->getInputSocket(i); @@ -664,10 +664,10 @@ ExecutionGroup *NodeOperationBuilder::make_group(NodeOperation *op) { ExecutionGroup *group = new ExecutionGroup(); m_groups.push_back(group); - + Tags visited; add_group_operations_recursive(visited, op, group); - + return group; } @@ -675,17 +675,17 @@ void NodeOperationBuilder::group_operations() { for (Operations::const_iterator it = m_operations.begin(); it != m_operations.end(); ++it) { NodeOperation *op = *it; - + if (op->isOutputOperation(m_context->isRendering())) { ExecutionGroup *group = make_group(op); group->setOutputExecutionGroup(true); } - + /* add new groups for associated memory proxies where needed */ if (op->isReadBufferOperation()) { ReadBufferOperation *read_op = (ReadBufferOperation *)op; MemoryProxy *memproxy = read_op->getMemoryProxy(); - + if (memproxy->getExecutor() == NULL) { ExecutionGroup *group = make_group(memproxy->getWriteBufferOperation()); memproxy->setExecutor(group); |