Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/constant_fold.cpp
- This file was added.
| /* | |||||
| * Copyright 2011-2013 Blender Foundation | |||||
| * | |||||
dingto: Same as above. | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| */ | |||||
| #include "image.h" | |||||
| #include "integrator.h" | |||||
| #include "constant_fold.h" | |||||
| #include "scene.h" | |||||
| #include "svm.h" | |||||
| #include "osl.h" | |||||
| #include "util_sky_model.h" | |||||
| #include "util_foreach.h" | |||||
Not Done Inline ActionsToo many includes, don't think we need half of them. dingto: Too many includes, don't think we need half of them. | |||||
| #include "util_transform.h" | |||||
| CCL_NAMESPACE_BEGIN | |||||
| ConstantFolder::ConstantFolder(ShaderGraph *graph, ShaderNode *node, ShaderOutput *socket) | |||||
| : graph(graph), node(node), socket(socket) | |||||
| { | |||||
| // | |||||
| } | |||||
| ConstantFolder::~ConstantFolder() | |||||
| { | |||||
| // | |||||
| } | |||||
| bool ConstantFolder::process_fold() | |||||
| { | |||||
| return node->constant_fold(this); | |||||
| } | |||||
| /* Constant Folding Helpers */ | |||||
| bool ConstantFolder::make_constant(float value) | |||||
| { | |||||
| foreach(ShaderInput *sock, socket->links) { | |||||
| sock->set(value); | |||||
| } | |||||
| graph->disconnect(socket); | |||||
| return true; | |||||
| } | |||||
| bool ConstantFolder::make_constant(float3 value) | |||||
| { | |||||
| foreach(ShaderInput *sock, socket->links) { | |||||
| sock->set(value); | |||||
| } | |||||
| graph->disconnect(socket); | |||||
| return true; | |||||
| } | |||||
| bool ConstantFolder::make_constant_clamp(bool clamp, float value) | |||||
| { | |||||
| return make_constant(clamp ? saturate(value) : value); | |||||
| } | |||||
| bool ConstantFolder::make_constant_clamp(bool clamp, float3 value) | |||||
| { | |||||
| if (clamp) { | |||||
| value.x = saturate(value.x); | |||||
| value.y = saturate(value.y); | |||||
| value.z = saturate(value.z); | |||||
| } | |||||
| return make_constant(value); | |||||
| } | |||||
| bool ConstantFolder::make_noop(ShaderInput *redirect_from) | |||||
| { | |||||
| return substitute_node(redirect_from->link); | |||||
| } | |||||
| bool ConstantFolder::substitute_node(ShaderOutput *new_output) | |||||
| { | |||||
| assert(new_output); | |||||
| // Remove all outgoing links from socket and connect them to new_output instead. | |||||
| // The graph->relink method affects node inputs, so it's not safe to use in constant | |||||
| // folding if the node has multiple outputs and will thus be folded multiple times. | |||||
| vector<ShaderInput*> outputs = socket->links; | |||||
| graph->disconnect(socket); | |||||
| foreach(ShaderInput *sock, outputs) { | |||||
| graph->connect(new_output, sock); | |||||
| } | |||||
| return true; | |||||
| } | |||||
| bool ConstantFolder::discard_node() | |||||
| { | |||||
| graph->disconnect(socket); | |||||
| return true; | |||||
| } | |||||
| bool ConstantFolder::try_make_noop(bool clamp, ShaderInput *input, float3 input_value) | |||||
| { | |||||
| if(!input->link) { | |||||
| return make_constant_clamp(clamp, input_value); | |||||
| } | |||||
| else if(!clamp) { | |||||
| return make_noop(input); | |||||
| } | |||||
| return false; | |||||
| } | |||||
| CCL_NAMESPACE_END | |||||
Same as above.