[Bf-blender-cvs] [95a0bff] master: Cycles: Avoid strings passed by value in OpenCL device

Sergey Sharybin noreply at git.blender.org
Thu Jul 14 12:49:35 CEST 2016


Commit: 95a0bff83af260d618f5848925cb6f0602b66722
Author: Sergey Sharybin
Date:   Thu Jul 14 12:44:51 2016 +0200
Branches: master
https://developer.blender.org/rB95a0bff83af260d618f5848925cb6f0602b66722

Cycles: Avoid strings passed by value in OpenCL device

Also use more const qualifiers in the code.

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

M	intern/cycles/device/device_opencl.cpp

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

diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp
index afe21c4..08de384 100644
--- a/intern/cycles/device/device_opencl.cpp
+++ b/intern/cycles/device/device_opencl.cpp
@@ -795,7 +795,7 @@ public:
 
 	bool load_binary(const string& /*kernel_path*/,
 	                 const string& clbin,
-	                 string custom_kernel_build_options,
+	                 const string& custom_kernel_build_options,
 	                 cl_program *program,
 	                 const string *debug_src = NULL)
 	{
@@ -848,7 +848,7 @@ public:
 	}
 
 	bool build_kernel(cl_program *kernel_program,
-	                  string custom_kernel_build_options,
+	                  const string& custom_kernel_build_options,
 	                  const string *debug_src = NULL)
 	{
 		string build_options;
@@ -882,26 +882,34 @@ public:
 	}
 
 	bool compile_kernel(const string& kernel_path,
-	                    string source,
-	                    string custom_kernel_build_options,
+	                    const string& source,
+	                    const string& custom_kernel_build_options,
 	                    cl_program *kernel_program,
 	                    const string *debug_src = NULL)
 	{
-		/* we compile kernels consisting of many files. unfortunately opencl
+		/* We compile kernels consisting of many files. unfortunately OpenCL
 		 * kernel caches do not seem to recognize changes in included files.
-		 * so we force recompile on changes by adding the md5 hash of all files */
-		source = path_source_replace_includes(source, kernel_path);
+		 * so we force recompile on changes by adding the md5 hash of all files.
+		 */
+		string inlined_source = path_source_replace_includes(source,
+		                                                     kernel_path);
 
-		if(debug_src)
-			path_write_text(*debug_src, source);
+		if(debug_src) {
+			path_write_text(*debug_src, inlined_source);
+		}
 
-		size_t source_len = source.size();
-		const char *source_str = source.c_str();
+		size_t source_len = inlined_source.size();
+		const char *source_str = inlined_source.c_str();
 
-		*kernel_program = clCreateProgramWithSource(cxContext, 1, &source_str, &source_len, &ciErr);
+		*kernel_program = clCreateProgramWithSource(cxContext,
+		                                            1,
+		                                            &source_str,
+		                                            &source_len,
+		                                            &ciErr);
 
-		if(opencl_error(ciErr))
+		if(opencl_error(ciErr)) {
 			return false;
+		}
 
 		double starttime = time_dt();
 		printf("Compiling OpenCL kernel ...\n");
@@ -2078,24 +2086,25 @@ public:
 	/* TODO(sergey): Seems really close to load_kernel(),
 	 * could it be de-duplicated?
 	 */
-	bool load_split_kernel(string kernel_path,
-	                       string kernel_init_source,
-	                       string clbin,
-	                       string custom_kernel_build_options,
+	bool load_split_kernel(const string& kernel_path,
+	                       const string& kernel_init_source,
+	                       const string& clbin,
+	                       const string& custom_kernel_build_options,
 	                       cl_program *program,
 	                       const string *debug_src = NULL)
 	{
-		if(!opencl_version_check())
+		if(!opencl_version_check()) {
 			return false;
+		}
 
-		clbin = path_user_get(path_join("cache", clbin));
+		string cache_clbin = path_user_get(path_join("cache", clbin));
 
 		/* If exists already, try use it. */
-		if(path_exists(clbin) && load_binary(kernel_path,
-		                                     clbin,
-		                                     custom_kernel_build_options,
-		                                     program,
-		                                     debug_src))
+		if(path_exists(cache_clbin) && load_binary(kernel_path,
+		                                           cache_clbin,
+		                                           custom_kernel_build_options,
+		                                           program,
+		                                           debug_src))
 		{
 			/* Kernel loaded from binary. */
 		}
@@ -2110,7 +2119,7 @@ public:
 				return false;
 			}
 			/* Save binary for reuse. */
-			if(!save_binary(program, clbin)) {
+			if(!save_binary(program, cache_clbin)) {
 				return false;
 			}
 		}




More information about the Bf-blender-cvs mailing list