**System Information**
Operating system: Windows 10
Graphics card: RTX 2060 SUPER
**Blender Version**
Broken: blender-2.81-9b6aa740be31-windows64
In 2.78, you could do:
import bpy
preferences = bpy.context.preferences.addons['cycles'].user_preferences
for device in preferences.devices:
print('Device {} of type {} found'.format(device.name, device.type))
to get the devices available.
In 2.80, you have to add a call to preferences.get_devices() to get it to work reliably:
import bpy
preferences = bpy.context.preferences.addons['cycles'].preferences
preferences.get_devices()
for device in preferences.devices:
print('Device {} of type {} found'.format(device.name, device.type))
In 2.81, with the introduction of OPTIX, that is not enough. The working 2.80 code will not return the OPTIX device. You have to iterate over all the device types as so:
import bpy
preferences = bpy.context.preferences.addons['cycles'].preferences
for device_type in preferences.get_device_types(bpy.context):
preferences.get_devices_for_type(device_type[0])
for device in preferences.devices:
print('Device {} of type {} found'.format(device.name, device.type))
This is making the API confusing. There is a simple property, devices, that only works with an increasing set of preconditions.