Cycles: Fix crash using OptiX denoiser with unsupported device selected

Fixes an issue where Blender would crash if the OptiX denoiser was
selected, but an unsupported GPU device (E.g. Intel GPU) was
selected in preferences.

This crash would occur because Cycles uses the device in preferences
to setup the denoiser, and there was no check stopping an unsupported
GPU from being used to try and setup and run the denoiser.

Pull Request: https://projects.blender.org/blender/blender/pulls/124001
This commit is contained in:
Alaska 2024-07-02 15:58:56 +02:00 committed by Sergey Sharybin
parent 3f6d9fa00d
commit 4961b93136
4 changed files with 22 additions and 9 deletions

@ -1695,15 +1695,16 @@ class CyclesPreferences(bpy.types.AddonPreferences):
import _cycles
compute_device_type = self.get_compute_device_type()
# We need any OptiX devices, used for rendering
for device in _cycles.available_devices(compute_device_type):
device_type = device[1]
if device_type == 'CPU':
continue
if compute_device_type == 'OPTIX':
# We need any OptiX devices, used for rendering
for device in _cycles.available_devices(compute_device_type):
device_type = device[1]
if device_type == 'CPU':
continue
has_device_optixdenoiser_support = device[6]
if has_device_optixdenoiser_support and self.find_existing_device_entry(device).use:
return True
has_device_optixdenoiser_support = device[6]
if has_device_optixdenoiser_support and self.find_existing_device_entry(device).use:
return True
return False

@ -97,7 +97,9 @@ unique_ptr<Denoiser> Denoiser::create(Device *denoiser_device,
bool is_cpu_denoiser_device = single_denoiser_device->info.type == DEVICE_CPU;
if (is_cpu_denoiser_device == false) {
#ifdef WITH_OPTIX
if (params.type == DENOISER_OPTIX) {
if (params.type == DENOISER_OPTIX &&
OptiXDenoiser::is_device_supported(single_denoiser_device->info))
{
return make_unique<OptiXDenoiser>(single_denoiser_device, params);
}
#endif

@ -219,6 +219,14 @@ uint OptiXDenoiser::get_device_type_mask() const
return DEVICE_MASK_OPTIX;
}
bool OptiXDenoiser::is_device_supported(const DeviceInfo &device)
{
if (device.type == DEVICE_OPTIX) {
return device.denoisers & DENOISER_OPTIX;
}
return false;
}
bool OptiXDenoiser::denoise_buffer(const DenoiseTask &task)
{
OptiXDevice *const optix_device = static_cast<OptiXDevice *>(denoiser_device_);

@ -18,6 +18,8 @@ class OptiXDenoiser : public DenoiserGPU {
OptiXDenoiser(Device *denoiser_device, const DenoiseParams &params);
~OptiXDenoiser();
static bool is_device_supported(const DeviceInfo &device);
protected:
virtual uint get_device_type_mask() const override;