[Bf-blender-cvs] [8138eb0dfef] blender2.7: Fix Cycles OpenCL multithreaded compilation not working on Windows.

Brecht Van Lommel noreply at git.blender.org
Tue Feb 19 13:50:11 CET 2019


Commit: 8138eb0dfefa3b6d05d197a9a701e964b8719328
Author: Brecht Van Lommel
Date:   Tue Feb 19 13:48:29 2019 +0100
Branches: blender2.7
https://developer.blender.org/rB8138eb0dfefa3b6d05d197a9a701e964b8719328

Fix Cycles OpenCL multithreaded compilation not working on Windows.

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

M	intern/cycles/device/opencl/opencl_util.cpp
M	intern/cycles/util/util_system.cpp

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

diff --git a/intern/cycles/device/opencl/opencl_util.cpp b/intern/cycles/device/opencl/opencl_util.cpp
index fe5ba4886a9..a6a80b0c2de 100644
--- a/intern/cycles/device/opencl/opencl_util.cpp
+++ b/intern/cycles/device/opencl/opencl_util.cpp
@@ -383,6 +383,12 @@ bool OpenCLDeviceBase::OpenCLProgram::compile_kernel(const string *debug_src)
 	return true;
 }
 
+static void escape_python_string(string& str)
+{
+	/* Escape string to be passed as a Python raw string with '' quotes'. */
+	string_replace(str, "'", "\'");
+}
+
 bool OpenCLDeviceBase::OpenCLProgram::compile_separate(const string& clbin)
 {
 	vector<string> args;
@@ -390,16 +396,30 @@ bool OpenCLDeviceBase::OpenCLProgram::compile_separate(const string& clbin)
 	args.push_back("--factory-startup");
 	args.push_back("--python-expr");
 
+	const char *force_all_platforms = (DebugFlags().opencl.kernel_type != DebugFlags::OpenCL::KERNEL_DEFAULT)? "true" : "false";
+	int device_platform_id = device->device_num;
+	string device_name = device->device_name;
+	string platform_name = device->platform_name;
+	string build_options = device->kernel_build_options(NULL) + kernel_build_options;
+	string kernel_file_escaped = kernel_file;
+	string clbin_escaped = clbin;
+
+	escape_python_string(device_name);
+	escape_python_string(platform_name);
+	escape_python_string(build_options);
+	escape_python_string(kernel_file_escaped);
+	escape_python_string(clbin_escaped);
+
 	args.push_back(
 		string_printf(
-			"import _cycles; _cycles.opencl_compile('%s', '%d', '%s', '%s', '%s', '%s', '%s')",
-			(DebugFlags().opencl.kernel_type != DebugFlags::OpenCL::KERNEL_DEFAULT)? "true" : "false",
-			device->device_num,
-			device->device_name.c_str(),
-			device->platform_name.c_str(),
-			(device->kernel_build_options(NULL) + kernel_build_options).c_str(),
-			kernel_file.c_str(),
-			clbin.c_str()));
+			"import _cycles; _cycles.opencl_compile(r'%s', r'%d', r'%s', r'%s', r'%s', r'%s', r'%s')",
+			force_all_platforms,
+			device_platform_id,
+			device_name.c_str(),
+			platform_name.c_str(),
+			build_options.c_str(),
+			kernel_file_escaped.c_str(),
+			clbin_escaped.c_str()));
 
 	double starttime = time_dt();
 	add_log(string("Cycles: compiling OpenCL program ") + program_name + "...", false);
diff --git a/intern/cycles/util/util_system.cpp b/intern/cycles/util/util_system.cpp
index a79829a3dd9..2a5c4a8f012 100644
--- a/intern/cycles/util/util_system.cpp
+++ b/intern/cycles/util/util_system.cpp
@@ -341,10 +341,11 @@ bool system_call_self(const vector<string>& args)
 		cmd += " \"" + args[i] + "\"";
 	}
 
-	/* Quiet output. */
 #ifdef _WIN32
-	cmd += " > nul";
+	/* Use cmd /S to avoid issues with spaces in arguments. */
+	cmd = "cmd /S /C \"" + cmd + " > nul \"";
 #else
+	/* Quiet output. */
 	cmd += " > /dev/null";
 #endif



More information about the Bf-blender-cvs mailing list