[Bf-blender-cvs] [27ed752] master: Cycles: Make hair, object and motion blur selective compiled into OpenCL

Sergey Sharybin noreply at git.blender.org
Mon Jun 8 11:29:59 CEST 2015


Commit: 27ed75271c1948abe5a420d881686406bf8e0ce8
Author: Sergey Sharybin
Date:   Fri Jun 5 19:50:22 2015 +0200
Branches: master
https://developer.blender.org/rB27ed75271c1948abe5a420d881686406bf8e0ce8

Cycles: Make hair, object and motion blur selective compiled into OpenCL

This features are now based on the scene settings, so scenes without those features
used are rendered even faster.

This gives about 30% speedup on the AMD A10 APU here, but at the same time it does
not mean such an improvement will happen on all the hardware. That being said, the
Tonga device here seems to have no measurable difference.

In any case it seems handy to have for the future, when we'll want to support SSS
in the kernel or to port selective compilation/split kernel to CUDA devices.

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

M	intern/cycles/device/device.h
M	intern/cycles/device/device_opencl.cpp
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/session.cpp

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

diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 8ac3df1..6b4a190 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -92,6 +92,11 @@ public:
 	 */
 	int nodes_features;
 
+	/* BVH/sampling kernel features. */
+	bool use_hair;
+	bool use_object_motion;
+	bool use_camera_motion;
+
 	DeviceRequestedFeatures()
 	{
 		/* TODO(sergey): Find more meaningful defaults. */
@@ -99,6 +104,9 @@ public:
 		max_closure = 0;
 		max_nodes_group = 0;
 		nodes_features = 0;
+		use_hair = false;
+		use_object_motion = false;
+		use_camera_motion = false;
 	}
 
 	bool modified(const DeviceRequestedFeatures& requested_features)
diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp
index 6cda617..7873d70 100644
--- a/intern/cycles/device/device_opencl.cpp
+++ b/intern/cycles/device/device_opencl.cpp
@@ -1977,6 +1977,10 @@ public:
 #ifdef __WORK_STEALING__
 		build_options += " -D__WORK_STEALING__";
 #endif
+
+		/* TODO(sergey): Make it a separate function to convert requested
+		 * features to build flags in order to make code a bit cleaner.
+		 */
 		if(requested_features.experimental) {
 			build_options += " -D__KERNEL_EXPERIMENTAL__";
 		}
@@ -1985,6 +1989,15 @@ public:
 		build_options += " -D__NODES_FEATURES__=" +
 			string_printf("%d", requested_features.nodes_features);
 		build_options += string_printf(" -D__MAX_CLOSURE__=%d", max_closure);
+		if(!requested_features.use_hair) {
+			build_options += " -D__NO_HAIR__";
+		}
+		if(!requested_features.use_object_motion) {
+			build_options += " -D__NO_OBJECT_MOTION__";
+		}
+		if(!requested_features.use_camera_motion) {
+			build_options += " -D__NO_CAMERA_MOTION__";
+		}
 
 		/* Set compute device build option. */
 		cl_device_type device_type;
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 55b22a1..aec4fd9 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -172,6 +172,17 @@ CCL_NAMESPACE_BEGIN
 #  define __KERNEL_DEBUG__
 #endif
 
+/* Scene-based selective featrues compilation/ */
+#ifdef __NO_CAMERA_MOTION__
+#  undef __CAMERA_MOTION__
+#endif
+#ifdef __NO_OBJECT_MOTION__
+#  undef __OBJECT_MOTION__
+#endif
+#ifdef __NO_HAIR__
+#  undef __HAIR__
+#endif
+
 /* Random Numbers */
 
 typedef uint RNG;
diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp
index a9a03e5..975fa5a 100644
--- a/intern/cycles/render/session.cpp
+++ b/intern/cycles/render/session.cpp
@@ -22,6 +22,8 @@
 #include "device.h"
 #include "graph.h"
 #include "integrator.h"
+#include "mesh.h"
+#include "object.h"
 #include "scene.h"
 #include "session.h"
 #include "bake.h"
@@ -604,6 +606,7 @@ void Session::run_cpu()
 
 DeviceRequestedFeatures Session::get_requested_device_features()
 {
+	/* TODO(sergey): Consider moving this to the Scene level. */
 	DeviceRequestedFeatures requested_features;
 	requested_features.experimental = params.experimental;
 	if(!params.background) {
@@ -618,6 +621,22 @@ DeviceRequestedFeatures Session::get_requested_device_features()
 		        requested_features.max_nodes_group,
 		        requested_features.nodes_features);
 	}
+
+	/* This features are not being tweaked as often as shaders,
+	 * so could be done selective magic for the viewport as well.
+	 */
+	requested_features.use_hair = false;
+	requested_features.use_object_motion = false;
+	requested_features.use_camera_motion = scene->camera->use_motion;
+	foreach(Object *object, scene->objects) {
+		Mesh *mesh = object->mesh;
+		if(mesh->curves.size() > 0) {
+			requested_features.use_hair = true;
+		}
+		requested_features.use_object_motion |= object->use_motion | mesh->use_motion_blur;
+		requested_features.use_camera_motion |= mesh->use_motion_blur;
+	}
+
 	return requested_features;
 }




More information about the Bf-blender-cvs mailing list