From 8138eb0dfefa3b6d05d197a9a701e964b8719328 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 19 Feb 2019 13:48:29 +0100 Subject: Fix Cycles OpenCL multithreaded compilation not working on Windows. --- intern/cycles/device/opencl/opencl_util.cpp | 36 ++++++++++++++++++++++------- intern/cycles/util/util_system.cpp | 5 ++-- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'intern') 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 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& 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 -- cgit v1.2.3