[Bf-blender-cvs] [34a4278] master: Code refactor: small code simplification for Cycles constant folding.

Brecht Van Lommel noreply at git.blender.org
Sun Jun 19 20:36:57 CEST 2016


Commit: 34a42788e702a4425afdff6fdbba7bdf549826be
Author: Brecht Van Lommel
Date:   Sun Jun 19 16:50:25 2016 +0200
Branches: master
https://developer.blender.org/rB34a42788e702a4425afdff6fdbba7bdf549826be

Code refactor: small code simplification for Cycles constant folding.

===================================================================

M	intern/cycles/render/graph.cpp
M	intern/cycles/render/graph.h
M	intern/cycles/render/nodes.cpp

===================================================================

diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 9210221..a1b992a 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -126,6 +126,17 @@ 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) {
diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h
index dccd8c2..61100cd 100644
--- a/intern/cycles/render/graph.h
+++ b/intern/cycles/render/graph.h
@@ -142,6 +142,8 @@ public:
 	/* Check whether the node can be replaced with single constant. */
 	virtual bool constant_fold(ShaderGraph * /*graph*/, ShaderOutput * /*socket*/, ShaderInput * /*optimized*/) { return false; }
 
+	bool all_inputs_constant() const;
+
 	/* Simplify settings used by artists to the ones which are simpler to
 	 * evaluate in the kernel but keep the final result unchanged.
 	 */
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 478443f..afdec23 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -1577,7 +1577,7 @@ RGBToBWNode::RGBToBWNode()
 
 bool RGBToBWNode::constant_fold(ShaderGraph *, ShaderOutput *, ShaderInput *optimized)
 {
-	if(inputs[0]->link == NULL) {
+	if(all_inputs_constant()) {
 		optimized->set(linear_rgb_to_gray(color));
 		return true;
 	}
@@ -1665,11 +1665,9 @@ bool ConvertNode::constant_fold(ShaderGraph *, ShaderOutput *, ShaderInput *opti
 	/* proxy nodes should have been removed at this point */
 	assert(special_type != SHADER_SPECIAL_TYPE_PROXY);
 
-	ShaderInput *in = inputs[0];
-
 	/* TODO(DingTo): conversion from/to int is not supported yet, don't fold in that case */
 
-	if(in->link == NULL) {
+	if(all_inputs_constant()) {
 		if(from == SocketType::FLOAT) {
 			if(SocketType::is_float3(to)) {
 				optimized->set(make_float3(value_float, value_float, value_float));
@@ -3856,10 +3854,7 @@ GammaNode::GammaNode()
 
 bool GammaNode::constant_fold(ShaderGraph *, ShaderOutput *, ShaderInput *optimized)
 {
-	ShaderInput *color_in = input("Color");
-	ShaderInput *gamma_in = input("Gamma");
-
-	if(color_in->link == NULL && gamma_in->link == NULL) {
+	if(all_inputs_constant()) {
 		optimized->set(svm_math_gamma_color(color, gamma));
 		return true;
 	}
@@ -4419,9 +4414,7 @@ BlackbodyNode::BlackbodyNode()
 
 bool BlackbodyNode::constant_fold(ShaderGraph *, ShaderOutput *, ShaderInput *optimized)
 {
-	ShaderInput *temperature_in = input("Temperature");
-
-	if(temperature_in->link == NULL) {
+	if(all_inputs_constant()) {
 		optimized->set(svm_math_blackbody_color(temperature));
 		return true;
 	}
@@ -4530,10 +4523,7 @@ MathNode::MathNode()
 
 bool MathNode::constant_fold(ShaderGraph *, ShaderOutput *, ShaderInput *optimized)
 {
-	ShaderInput *value1_in = input("Value1");
-	ShaderInput *value2_in = input("Value2");
-
-	if(value1_in->link == NULL && value2_in->link == NULL) {
+	if(all_inputs_constant()) {
 		float value = svm_math(type, value1, value2);
 
 		if(use_clamp) {
@@ -4601,13 +4591,10 @@ VectorMathNode::VectorMathNode()
 
 bool VectorMathNode::constant_fold(ShaderGraph *, ShaderOutput *socket, ShaderInput *optimized)
 {
-	ShaderInput *vector1_in = input("Vector1");
-	ShaderInput *vector2_in = input("Vector2");
-
 	float value;
 	float3 vector;
 
-	if(vector1_in->link == NULL && vector2_in->link == NULL) {
+	if(all_inputs_constant()) {
 		svm_vector_math(&value,
 		                &vector,
 		                type,




More information about the Bf-blender-cvs mailing list