Cycles: add ConstantFolder class for constant folding boilerplate.

Reviewed By: brecht, sergey

Differential Revision: https://developer.blender.org/D2089
This commit is contained in:
Alexander Gavrilov
2016-07-16 13:16:54 +02:00
committed by Brecht Van Lommel
parent 10b0e33de1
commit 5234e9ddd3
7 changed files with 347 additions and 261 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 Blender Foundation
* Copyright 2011-2016 Blender Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
#include "graph.h"
#include "nodes.h"
#include "shader.h"
#include "constant_fold.h"
#include "util_algorithm.h"
#include "util_debug.h"
@@ -126,17 +127,6 @@ ShaderOutput *ShaderNode::output(ustring name)
return NULL;
}
bool ShaderNode::all_inputs_constant() const
{
foreach(ShaderInput *input, inputs) {
if(input->link) {
return false;
}
}
return true;
}
void ShaderNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
foreach(ShaderInput *input, inputs) {
@@ -278,6 +268,17 @@ void ShaderGraph::connect(ShaderOutput *from, ShaderInput *to)
}
}
void ShaderGraph::disconnect(ShaderOutput *from)
{
assert(!finalized);
foreach(ShaderInput *sock, from->links) {
sock->link = NULL;
}
from->links.clear();
}
void ShaderGraph::disconnect(ShaderInput *to)
{
assert(!finalized);
@@ -525,15 +526,8 @@ void ShaderGraph::constant_fold()
}
}
/* Optimize current node. */
if(node->constant_fold(this, output, output->links[0])) {
/* Apply optimized value to other connected sockets and disconnect. */
vector<ShaderInput*> links(output->links);
for(size_t i = 0; i < links.size(); i++) {
if(i > 0)
links[i]->parent->copy_value(links[i]->socket_type, *links[0]->parent, links[0]->socket_type);
disconnect(links[i]);
}
}
ConstantFolder folder(this, node, output);
node->constant_fold(folder);
}
}
}