[Bf-blender-cvs] [7e7a9d1] master: Cycles: Fix OpenCL speed regression introduced with the improved bump mapping

Lukas Stockner noreply at git.blender.org
Thu Sep 8 01:45:56 CEST 2016


Commit: 7e7a9d146ca631f3e71d35bb71add041570eab23
Author: Lukas Stockner
Date:   Thu Sep 8 01:33:41 2016 +0200
Branches: master
https://developer.blender.org/rB7e7a9d146ca631f3e71d35bb71add041570eab23

Cycles: Fix OpenCL speed regression introduced with the improved bump mapping

The two SVM nodes added with e7ea1ae78c caused a slowdown on AMD cards when rendering with OpenCL, whether displacement was used or not.
In the Barcelona Pavillon scene on a RX480, this would cause a 12% slowdown.

Therefore, this commit adds a additional flag for feature-adaptive compilation so that the new SVM nodes are only enabled when they are needed (Node tree connected to the Displacement output and Displacement type set to Both).

Also, the nodes were also added to shaders when the Displacement Type was set to Bump (the default), which was unneccessary and is fixed now.

Thanks to linda2 on IRC for reporting and testing and to maiself for help with the displacement shader code.

This fix might be relevant for 2.78, but it should be tested further before including it.

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

M	intern/cycles/kernel/svm/svm.h
M	intern/cycles/kernel/svm/svm_types.h
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/svm.cpp

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

diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h
index 998a32e..9ca8917 100644
--- a/intern/cycles/kernel/svm/svm.h
+++ b/intern/cycles/kernel/svm/svm.h
@@ -295,12 +295,14 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ccl_a
 			case NODE_CLOSURE_SET_NORMAL:
 				svm_node_set_normal(kg, sd, stack, node.y, node.z);
 				break;
+#      if NODES_FEATURE(NODE_FEATURE_BUMP_STATE)
 			case NODE_ENTER_BUMP_EVAL:
 				svm_node_enter_bump_eval(kg, sd, stack, node.y);
 				break;
 			case NODE_LEAVE_BUMP_EVAL:
 				svm_node_leave_bump_eval(kg, sd, stack, node.y);
 				break;
+#      endif /* NODES_FEATURE(NODE_FEATURE_BUMP_STATE) */
 #    endif  /* NODES_FEATURE(NODE_FEATURE_BUMP) */
 			case NODE_HSV:
 				svm_node_hsv(kg, sd, stack, node, &offset);
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index 9cfa839..5adf7d3 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -47,11 +47,12 @@ CCL_NAMESPACE_BEGIN
 #define NODE_FEATURE_VOLUME     (1 << 0)
 #define NODE_FEATURE_HAIR       (1 << 1)
 #define NODE_FEATURE_BUMP       (1 << 2)
+#define NODE_FEATURE_BUMP_STATE (1 << 3)
 /* TODO(sergey): Consider using something like ((uint)(-1)).
  * Need to check carefully operand types around usage of this
  * define first.
  */
-#define NODE_FEATURE_ALL        (NODE_FEATURE_VOLUME|NODE_FEATURE_HAIR|NODE_FEATURE_BUMP)
+#define NODE_FEATURE_ALL        (NODE_FEATURE_VOLUME|NODE_FEATURE_HAIR|NODE_FEATURE_BUMP|NODE_FEATURE_BUMP_STATE)
 
 typedef enum ShaderNodeType {
 	NODE_END = 0,
diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp
index 10c3507..70e1443 100644
--- a/intern/cycles/render/shader.cpp
+++ b/intern/cycles/render/shader.cpp
@@ -561,6 +561,9 @@ void ShaderManager::get_requested_features(Scene *scene,
 		ShaderNode *output_node = shader->graph->output();
 		if(output_node->input("Displacement")->link != NULL) {
 			requested_features->nodes_features |= NODE_FEATURE_BUMP;
+			if(shader->displacement_method == DISPLACE_BOTH && requested_features->experimental) {
+				requested_features->nodes_features |= NODE_FEATURE_BUMP_STATE;
+			}
 		}
 		/* On top of volume nodes, also check if we need volume sampling because
 		 * e.g. an Emission node would slip through the NODE_FEATURE_VOLUME check */
diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp
index 069c3e3..352bed8 100644
--- a/intern/cycles/render/svm.cpp
+++ b/intern/cycles/render/svm.cpp
@@ -671,8 +671,9 @@ void SVMCompiler::compile_type(Shader *shader, ShaderGraph *graph, ShaderType ty
 	}
 
 	/* for the bump shader we need add a node to store the shader state */
+	bool need_bump_state = (type == SHADER_TYPE_BUMP) && (shader->displacement_method == DISPLACE_BOTH);
 	int bump_state_offset = SVM_STACK_INVALID;
-	if(type == SHADER_TYPE_BUMP) {
+	if(need_bump_state) {
 		bump_state_offset = stack_find_offset(SVM_BUMP_EVAL_STATE_SIZE);
 		add_node(NODE_ENTER_BUMP_EVAL, bump_state_offset);
 	}
@@ -714,7 +715,7 @@ void SVMCompiler::compile_type(Shader *shader, ShaderGraph *graph, ShaderType ty
 	}
 
 	/* add node to restore state after bump shader has finished */
-	if(type == SHADER_TYPE_BUMP) {
+	if(need_bump_state) {
 		add_node(NODE_LEAVE_BUMP_EVAL, bump_state_offset);
 	}




More information about the Bf-blender-cvs mailing list