From c984d73a7f5bbe06435c0fe85400c377553a3458 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 3 Jun 2019 09:51:07 +0200 Subject: [PATCH] Fixes for API changes done in Blender 2.80 Seems to work with both Blender 2.79 and 2,80. --- benchmark/configure.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/benchmark/configure.py b/benchmark/configure.py index 7185c27..8e6c4d6 100644 --- a/benchmark/configure.py +++ b/benchmark/configure.py @@ -2,6 +2,24 @@ import bpy +def getUserPreferences(context): + preferences = getattr(context, 'user_preferences', None) + if preferences is None: + preferences = context.preferences + return preferences + + +def getAllAvailableDevices(): + import _cycles + all_devices = [] + blender_version = bpy.app.version + if bpy.app.version < (2, 80, 0): + return _cycles.available_devices() + all_devices.extend(_cycles.available_devices('CPU')) + all_devices.extend(_cycles.available_devices('CUDA')) + all_devices.extend(_cycles.available_devices('OPENCL')) + return all_devices + def setDeviceCPU(context, cpref): cpref.compute_device_type = 'NONE' return True @@ -148,13 +166,13 @@ def logComputeDevices(cpref): def logSystemInfo(cpref): import json info_devices = [] - for device in cpref.devices: + for device in getAllAvailableDevices(): info_device = { - "name": device.name.replace(" (Display)", ""), - "type": device.type, + "name": device[0].replace(" (Display)", ""), + "type": device[1], } - if device.type != 'CPU': - info_device["is_display"] = '(Display)' in device.name + if device[1] != 'CPU': + info_device["is_display"] = '(Display)' in device[0] info_devices.append(info_device) print("Benchmark Devices: {}" . format(json.dumps(info_devices, sort_keys=True))) @@ -195,7 +213,7 @@ def main(): args = parser.parse_args(argv) context = bpy.context - cpref = context.user_preferences.addons['cycles'].preferences + cpref = getUserPreferences(context).addons['cycles'].preferences # Adjust samples so we render real quick. if args.benchmark_warmup: