diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-10-28 21:55:41 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-10-29 18:01:38 +0300 |
commit | f75b09e7e6b3ed9345993455ecab8a6d1690179f (patch) | |
tree | bc5b915e58deed55d9e8b406460765a8cdfc49c8 /intern/cycles/device | |
parent | 09be2a83580faaf4fa9b87da2632ab51d0934235 (diff) |
Cycles: abort rendering when --cycles-device not found
Rather than just printing a message and falling back to the CPU. For render
farms it's better to avoid a potentially slow render on the CPU if the intent
was to render on the GPU.
Ref T82193, D9086
Diffstat (limited to 'intern/cycles/device')
-rw-r--r-- | intern/cycles/device/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/cycles/device/device.cpp | 22 | ||||
-rw-r--r-- | intern/cycles/device/device.h | 3 | ||||
-rw-r--r-- | intern/cycles/device/device_dummy.cpp | 83 | ||||
-rw-r--r-- | intern/cycles/device/device_intern.h | 1 |
5 files changed, 102 insertions, 8 deletions
diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt index cc54f64b1bb..928249931a3 100644 --- a/intern/cycles/device/CMakeLists.txt +++ b/intern/cycles/device/CMakeLists.txt @@ -39,6 +39,7 @@ set(SRC device_cpu.cpp device_cuda.cpp device_denoising.cpp + device_dummy.cpp device_memory.cpp device_multi.cpp device_opencl.cpp diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp index 407f73e8451..eb8fb8040e3 100644 --- a/intern/cycles/device/device.cpp +++ b/intern/cycles/device/device.cpp @@ -375,7 +375,7 @@ Device *Device::create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool } #endif - Device *device; + Device *device = NULL; switch (info.type) { case DEVICE_CPU: @@ -385,16 +385,12 @@ Device *Device::create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool case DEVICE_CUDA: if (device_cuda_init()) device = device_cuda_create(info, stats, profiler, background); - else - device = NULL; break; #endif #ifdef WITH_OPTIX case DEVICE_OPTIX: if (device_optix_init()) device = device_optix_create(info, stats, profiler, background); - else - device = NULL; break; #endif #ifdef WITH_NETWORK @@ -406,12 +402,14 @@ Device *Device::create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool case DEVICE_OPENCL: if (device_opencl_init()) device = device_opencl_create(info, stats, profiler, background); - else - device = NULL; break; #endif default: - return NULL; + break; + } + + if (device == NULL) { + device = device_dummy_create(info, stats, profiler, background); } return device; @@ -549,6 +547,14 @@ vector<DeviceInfo> Device::available_devices(uint mask) return devices; } +DeviceInfo Device::dummy_device(const string &error_msg) +{ + DeviceInfo info; + info.type = DEVICE_DUMMY; + info.error_msg = error_msg; + return info; +} + string Device::device_capabilities(uint mask) { thread_scoped_lock lock(device_mutex); diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h index ddf608aa430..2006db02ce7 100644 --- a/intern/cycles/device/device.h +++ b/intern/cycles/device/device.h @@ -48,6 +48,7 @@ enum DeviceType { DEVICE_NETWORK, DEVICE_MULTI, DEVICE_OPTIX, + DEVICE_DUMMY, }; enum DeviceTypeMask { @@ -87,6 +88,7 @@ class DeviceInfo { int cpu_threads; vector<DeviceInfo> multi_devices; vector<DeviceInfo> denoising_devices; + string error_msg; DeviceInfo() { @@ -471,6 +473,7 @@ class Device { static string string_from_type(DeviceType type); static vector<DeviceType> available_types(); static vector<DeviceInfo> available_devices(uint device_type_mask = DEVICE_MASK_ALL); + static DeviceInfo dummy_device(const string &error_msg = ""); static string device_capabilities(uint device_type_mask = DEVICE_MASK_ALL); static DeviceInfo get_multi_device(const vector<DeviceInfo> &subdevices, int threads, diff --git a/intern/cycles/device/device_dummy.cpp b/intern/cycles/device/device_dummy.cpp new file mode 100644 index 00000000000..5112fc152e5 --- /dev/null +++ b/intern/cycles/device/device_dummy.cpp @@ -0,0 +1,83 @@ +/* + * Copyright 2011-2020 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device/device.h" +#include "device/device_intern.h" + +CCL_NAMESPACE_BEGIN + +/* Dummy device for when creating an appropriate rendering device fails. */ + +class DummyDevice : public Device { + public: + DummyDevice(DeviceInfo &info_, Stats &stats_, Profiler &profiler_, bool background_) + : Device(info_, stats_, profiler_, background_) + { + error_msg = info.error_msg; + } + + ~DummyDevice() + { + } + + virtual BVHLayoutMask get_bvh_layout_mask() const override + { + return 0; + } + + virtual void mem_alloc(device_memory &) override + { + } + + virtual void mem_copy_to(device_memory &) override + { + } + + virtual void mem_copy_from(device_memory &, int, int, int, int) override + { + } + + virtual void mem_zero(device_memory &) override + { + } + + virtual void mem_free(device_memory &) override + { + } + + virtual void const_copy_to(const char *, void *, size_t) override + { + } + + virtual void task_add(DeviceTask &) override + { + } + + virtual void task_wait() override + { + } + + virtual void task_cancel() override + { + } +}; + +Device *device_dummy_create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background) +{ + return new DummyDevice(info, stats, profiler, background); +} + +CCL_NAMESPACE_END diff --git a/intern/cycles/device/device_intern.h b/intern/cycles/device/device_intern.h index 94d63e8f333..ecc79c5d7ee 100644 --- a/intern/cycles/device/device_intern.h +++ b/intern/cycles/device/device_intern.h @@ -35,6 +35,7 @@ bool device_cuda_init(); Device *device_cuda_create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background); bool device_optix_init(); Device *device_optix_create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background); +Device *device_dummy_create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background); Device *device_network_create(DeviceInfo &info, Stats &stats, |