diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-01-29 18:39:30 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-01-29 19:00:02 +0300 |
commit | 001414fb2f7346d2ff332bf851373522d87659d7 (patch) | |
tree | 366112462b869a31767d7439b04b900ba21044c1 /intern/cycles/blender/blender_python.cpp | |
parent | e37b9b5d0d2664697de8f1c7614e88073dd8ff49 (diff) |
Cycles: delay CUDA and OpenCL initialization to avoid driver crashes.
We've had many reported crashes on Windows where we suspect there is a
corrupted OpenCL driver. The purpose here is to keep Blender generally
usable in such cases.
Now it always shows None / CUDA / OpenCL in the preferences, and only when
selecting one will it reveal if there are any GPUs available. This should
avoid crashes when opening the preferences or on startup.
Differential Revision: https://developer.blender.org/D4265
Diffstat (limited to 'intern/cycles/blender/blender_python.cpp')
-rw-r--r-- | intern/cycles/blender/blender_python.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index d9ff95b2578..9dd0cd4c0bc 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -384,9 +384,18 @@ static PyObject *sync_func(PyObject * /*self*/, PyObject *value) Py_RETURN_NONE; } -static PyObject *available_devices_func(PyObject * /*self*/, PyObject * /*args*/) +static PyObject *available_devices_func(PyObject * /*self*/, PyObject * args) { - vector<DeviceInfo>& devices = Device::available_devices(); + const char *type_name; + if(!PyArg_ParseTuple(args, "s", &type_name)) { + return NULL; + } + + DeviceType type = Device::type_from_string(type_name); + uint mask = (type == DEVICE_NONE) ? DEVICE_MASK_ALL : DEVICE_MASK(type); + mask |= DEVICE_MASK_CPU; + + vector<DeviceInfo> devices = Device::available_devices(mask); PyObject *ret = PyTuple_New(devices.size()); for(size_t i = 0; i < devices.size(); i++) { @@ -742,11 +751,11 @@ static PyObject *enable_print_stats_func(PyObject * /*self*/, PyObject * /*args* static PyObject *get_device_types_func(PyObject * /*self*/, PyObject * /*args*/) { - vector<DeviceInfo>& devices = Device::available_devices(); + vector<DeviceType> device_types = Device::available_types(); bool has_cuda = false, has_opencl = false; - for(int i = 0; i < devices.size(); i++) { - has_cuda |= (devices[i].type == DEVICE_CUDA); - has_opencl |= (devices[i].type == DEVICE_OPENCL); + foreach(DeviceType device_type, device_types) { + has_cuda |= (device_type == DEVICE_CUDA); + has_opencl |= (device_type == DEVICE_OPENCL); } PyObject *list = PyTuple_New(2); PyTuple_SET_ITEM(list, 0, PyBool_FromLong(has_cuda)); @@ -768,7 +777,7 @@ static PyMethodDef methods[] = { {"osl_update_node", osl_update_node_func, METH_VARARGS, ""}, {"osl_compile", osl_compile_func, METH_VARARGS, ""}, #endif - {"available_devices", available_devices_func, METH_NOARGS, ""}, + {"available_devices", available_devices_func, METH_VARARGS, ""}, {"system_info", system_info_func, METH_NOARGS, ""}, #ifdef WITH_OPENCL {"opencl_disable", opencl_disable_func, METH_NOARGS, ""}, |