2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include "COM_ExecutionSystemHelper.h"
31
#include "COM_Converter.h"
32
#include "COM_NodeOperation.h"
33
#include "COM_ExecutionGroup.h"
34
#include "COM_NodeBase.h"
35
#include "COM_WorkScheduler.h"
36
#include "COM_ReadBufferOperation.h"
37
#include "COM_GroupNode.h"
38
#include "COM_WriteBufferOperation.h"
39
#include "COM_ReadBufferOperation.h"
40
#include "COM_ViewerBaseOperation.h"
42
void ExecutionSystemHelper::addbNodeTree(ExecutionSystem &system, int nodes_start, bNodeTree *tree, bNode *groupnode)
44
vector<Node *>& nodes = system.getNodes();
45
vector<SocketConnection *>& links = system.getConnections();
46
const bNode *activeGroupNode = system.getContext().getActivegNode();
47
bool isActiveGroup = activeGroupNode == groupnode;
49
/* add all nodes of the tree to the node list */
50
bNode *node = (bNode *)tree->nodes.first;
51
while (node != NULL) {
52
Node *nnode = addNode(nodes, node, isActiveGroup, system.getContext().isFastCalculation());
53
nnode->setbNodeGroup(groupnode);
57
NodeRange node_range(nodes.begin() + nodes_start, nodes.end());
59
/* add all nodelinks of the tree to the link list */
60
bNodeLink *nodelink = (bNodeLink *)tree->links.first;
61
while (nodelink != NULL) {
62
addNodeLink(node_range, links, nodelink);
63
nodelink = nodelink->next;
66
/* Expand group nodes */
67
for (unsigned int i = nodes_start; i < nodes.size(); ++i) {
68
Node *execnode = nodes[i];
69
if (execnode->isGroupNode()) {
70
GroupNode *groupNode = (GroupNode *)execnode;
71
groupNode->ungroup(system);
76
void ExecutionSystemHelper::addNode(vector<Node *>& nodes, Node *node)
78
nodes.push_back(node);
81
Node *ExecutionSystemHelper::addNode(vector<Node *>& nodes, bNode *b_node, bool inActiveGroup, bool fast)
83
Node *node = Converter::convert(b_node, fast);
84
node->setIsInActiveGroup(inActiveGroup);
88
void ExecutionSystemHelper::addOperation(vector<NodeOperation *>& operations, NodeOperation *operation)
90
operations.push_back(operation);
93
void ExecutionSystemHelper::addExecutionGroup(vector<ExecutionGroup *>& executionGroups, ExecutionGroup *executionGroup)
95
executionGroups.push_back(executionGroup);
98
void ExecutionSystemHelper::findOutputNodeOperations(vector<NodeOperation *> *result, vector<NodeOperation *>& operations, bool rendering)
102
for (index = 0; index < operations.size(); index++) {
103
NodeOperation *operation = operations[index];
104
if (operation->isOutputOperation(rendering)) {
105
result->push_back(operation);
110
static InputSocket *find_input(NodeRange &node_range, bNode *bnode, bNodeSocket *bsocket)
113
for (NodeIterator it = node_range.first; it != node_range.second; ++it) {
115
if (node->getbNode() == bnode)
116
return node->findInputSocketBybNodeSocket(bsocket);
120
for (NodeIterator it = node_range.first; it != node_range.second; ++it) {
122
if (node->isProxyNode()) {
123
InputSocket *proxySocket = node->getInputSocket(0);
124
if (proxySocket->getbNodeSocket() == bsocket)
131
static OutputSocket *find_output(NodeRange &node_range, bNode *bnode, bNodeSocket *bsocket)
134
for (NodeIterator it = node_range.first; it != node_range.second; ++it) {
136
if (node->getbNode() == bnode)
137
return node->findOutputSocketBybNodeSocket(bsocket);
141
for (NodeIterator it = node_range.first; it != node_range.second; ++it) {
143
if (node->isProxyNode()) {
144
OutputSocket *proxySocket = node->getOutputSocket(0);
145
if (proxySocket->getbNodeSocket() == bsocket)
152
SocketConnection *ExecutionSystemHelper::addNodeLink(NodeRange &node_range, vector<SocketConnection *>& links, bNodeLink *b_nodelink)
154
/// @note: ignore invalid links
155
if (!(b_nodelink->flag & NODE_LINK_VALID))
158
InputSocket *inputSocket = find_input(node_range, b_nodelink->tonode, b_nodelink->tosock);
159
OutputSocket *outputSocket = find_output(node_range, b_nodelink->fromnode, b_nodelink->fromsock);
160
if (inputSocket == NULL || outputSocket == NULL) {
163
if (inputSocket->isConnected()) {
166
SocketConnection *connection = addLink(links, outputSocket, inputSocket);
170
SocketConnection *ExecutionSystemHelper::addLink(vector<SocketConnection *>& links, OutputSocket *fromSocket, InputSocket *toSocket)
172
SocketConnection *newconnection = new SocketConnection();
173
newconnection->setFromSocket(fromSocket);
174
newconnection->setToSocket(toSocket);
175
fromSocket->addConnection(newconnection);
176
toSocket->setConnection(newconnection);
177
links.push_back(newconnection);
178
return newconnection;
181
void ExecutionSystemHelper::debugDump(ExecutionSystem *system)
184
NodeOperation *operation;
185
ExecutionGroup *group;
186
SocketConnection *connection;
188
printf("-- BEGIN COMPOSITOR DUMP --\r\n");
189
printf("digraph compositorexecution {\r\n");
190
tot = system->getNodes().size();
191
for (int i = 0; i < tot; i++) {
192
node = system->getNodes()[i];
193
printf("// NODE: %s\r\n", node->getbNode()->typeinfo->name);
195
tot = system->getOperations().size();
196
for (int i = 0; i < tot; i++) {
197
operation = system->getOperations()[i];
198
printf("// OPERATION: %p\r\n", operation);
199
printf("\t\"O_%p\"", operation);
200
printf(" [shape=record,label=\"{");
201
tot2 = operation->getNumberOfInputSockets();
204
for (int j = 0; j < tot2; j++) {
205
InputSocket *socket = operation->getInputSocket(j);
209
printf("<IN_%p>", socket);
210
switch (socket->getDataType()) {
225
if (operation->isViewerOperation()) {
226
ViewerBaseOperation *viewer = (ViewerBaseOperation *)operation;
227
if (viewer->isActiveViewerOutput()) {
228
printf("Active viewer");
234
else if (operation->isOutputOperation(system->getContext().isRendering())) {
237
else if (operation->isSetOperation()) {
240
else if (operation->isReadBufferOperation()) {
241
printf("ReadBuffer");
243
else if (operation->isWriteBufferOperation()) {
244
printf("WriteBuffer");
247
printf("O_%p", operation);
249
printf(" (%d,%d)", operation->getWidth(), operation->getHeight());
250
tot2 = operation->getNumberOfOutputSockets();
254
for (int j = 0; j < tot2; j++) {
255
OutputSocket *socket = operation->getOutputSocket(j);
259
printf("<OUT_%p>", socket);
260
switch (socket->getDataType()) {
277
tot = system->getExecutionGroups().size();
278
for (int i = 0; i < tot; i++) {
279
group = system->getExecutionGroups()[i];
280
printf("// GROUP: %d\r\n", i);
281
printf("subgraph {\r\n");
282
printf("// OUTPUTOPERATION: %p\r\n", group->getOutputNodeOperation());
283
printf(" O_%p\r\n", group->getOutputNodeOperation());
286
tot = system->getOperations().size();
287
for (int i = 0; i < tot; i++) {
288
operation = system->getOperations()[i];
289
if (operation->isReadBufferOperation()) {
290
ReadBufferOperation *read = (ReadBufferOperation *)operation;
291
WriteBufferOperation *write = read->getMemoryProxy()->getWriteBufferOperation();
292
printf("\t\"O_%p\" -> \"O_%p\" [style=dotted]\r\n", write, read);
295
tot = system->getConnections().size();
296
for (int i = 0; i < tot; i++) {
297
connection = system->getConnections()[i];
298
printf("// CONNECTION: %p.%p -> %p.%p\r\n", connection->getFromNode(), connection->getFromSocket(), connection->getToNode(), connection->getToSocket());
299
printf("\t\"O_%p\":\"OUT_%p\" -> \"O_%p\":\"IN_%p\"", connection->getFromNode(), connection->getFromSocket(), connection->getToNode(), connection->getToSocket());
300
if (!connection->isValid()) {
301
printf(" [color=red]");
304
switch (connection->getFromSocket()->getDataType()) {
306
printf(" [color=grey]");
309
printf(" [color=blue]");
312
printf(" [color=orange]");
319
printf("-- END COMPOSITOR DUMP --\r\n");