Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2016-11-07 04:33:53 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2016-11-07 05:19:29 +0300
commitdd921238d9223f550d3043313c9c38d07620de5d (patch)
tree762c114b9ccda879a2826be6c2205cb5a20665d3 /intern/cycles/blender/addon/properties.py
parentf89fbf580eae6202cef9da08756fd415ca34a8f3 (diff)
Cycles: Refactor Device selection to allow individual GPU compute device selection
Previously, it was only possible to choose a single GPU or all of that type (CUDA or OpenCL). Now, a toggle button is displayed for every device. These settings are tied to the PCI Bus ID of the devices, so they're consistent across hardware addition and removal (but not when swapping/moving cards). From the code perspective, the more important change is that now, the compute device properties are stored in the Addon preferences of the Cycles addon, instead of directly in the User Preferences. This allows for a cleaner implementation, removing the Cycles C API functions that were called by the RNA code to specify the enum items. Note that this change is neither backwards- nor forwards-compatible, but since it's only a User Preference no existing files are broken. Reviewers: #cycles, brecht Reviewed By: #cycles, brecht Subscribers: brecht, juicyfruit, mib2berlin, Blendify Differential Revision: https://developer.blender.org/D2338
Diffstat (limited to 'intern/cycles/blender/addon/properties.py')
-rw-r--r--intern/cycles/blender/addon/properties.py110
1 files changed, 109 insertions, 1 deletions
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index a8ab9100ded..27c9b922042 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -21,7 +21,8 @@ from bpy.props import (BoolProperty,
EnumProperty,
FloatProperty,
IntProperty,
- PointerProperty)
+ PointerProperty,
+ StringProperty)
# enums
@@ -122,6 +123,12 @@ enum_volume_interpolation = (
('CUBIC', "Cubic", "Smoothed high quality interpolation, but slower")
)
+enum_device_type = (
+ ('CPU', "CPU", "CPU", 0),
+ ('CUDA', "CUDA", "CUDA", 1),
+ ('OPENCL', "OpenCL", "OpenCL", 2)
+ )
+
class CyclesRenderSettings(bpy.types.PropertyGroup):
@classmethod
@@ -1130,6 +1137,103 @@ class CyclesCurveSettings(bpy.types.PropertyGroup):
del bpy.types.ParticleSettings.cycles
+class CyclesDeviceSettings(bpy.types.PropertyGroup):
+ @classmethod
+ def register(cls):
+ cls.id = StringProperty(name="ID")
+ cls.name = StringProperty(name="Name")
+ cls.use = BoolProperty(name="Use", default=True)
+ cls.type = EnumProperty(name="Type", items=enum_device_type, default='CUDA')
+
+
+class CyclesPreferences(bpy.types.AddonPreferences):
+ bl_idname = __package__
+
+ def get_device_types(self, context):
+ import _cycles
+ has_cuda, has_opencl = _cycles.get_device_types()
+ list = [('NONE', "None", "Don't use compute device", 0)]
+ if has_cuda:
+ list.append(('CUDA', "CUDA", "Use CUDA for GPU acceleration", 1))
+ if has_opencl:
+ list.append(('OPENCL', "OpenCL", "Use OpenCL for GPU acceleration", 2))
+ return list
+
+ compute_device_type = EnumProperty(
+ name="Compute Device Type",
+ description="Device to use for computation (rendering with Cycles)",
+ items=get_device_types,
+ )
+
+ devices = bpy.props.CollectionProperty(type=CyclesDeviceSettings)
+
+ def get_devices(self):
+ import _cycles
+ # Layout of the device tuples: (Name, Type, Internal ID, Persistent ID)
+ device_list = _cycles.available_devices()
+
+ cuda_devices = []
+ opencl_devices = []
+ for device in device_list:
+ if not device[1] in {'CUDA', 'OPENCL'}:
+ continue
+
+ entry = None
+ # Try to find existing Device entry
+ for dev in self.devices:
+ if dev.id == device[2] and dev.type == device[1]:
+ entry = dev
+ break
+ # Create new entry if no existing one was found
+ if not entry:
+ entry = self.devices.add()
+ entry.id = device[2]
+ entry.name = device[0]
+ entry.type = device[1]
+
+ # Sort entries into lists
+ if entry.type == 'CUDA':
+ cuda_devices.append(entry)
+ elif entry.type == 'OPENCL':
+ opencl_devices.append(entry)
+ return cuda_devices, opencl_devices
+
+
+ def has_active_device(self):
+ import _cycles
+ device_list = _cycles.available_devices()
+ for device in device_list:
+ if device[1] != self.compute_device_type:
+ continue
+ if any(dev.use and dev.id == device[2] for dev in self.devices):
+ return True
+ return False
+
+
+ def draw_impl(self, layout, context):
+ layout.label(text="Compute Device:")
+ layout.row().prop(self, "compute_device_type", expand=True)
+
+ cuda_devices, opencl_devices = self.get_devices()
+ row = layout.row()
+
+ if cuda_devices:
+ col = row.column(align=True)
+ col.label(text="CUDA devices:")
+ for device in cuda_devices:
+ col.prop(device, "use", text=device.name, toggle=True)
+
+ if opencl_devices:
+ col = row.column(align=True)
+ col.label(text="OpenCL devices:")
+ for device in opencl_devices:
+ col.prop(device, "use", text=device.name, toggle=True)
+
+
+ def draw(self, context):
+ self.draw_impl(self.layout, context)
+
+
def register():
bpy.utils.register_class(CyclesRenderSettings)
bpy.utils.register_class(CyclesCameraSettings)
@@ -1141,6 +1245,8 @@ def register():
bpy.utils.register_class(CyclesObjectSettings)
bpy.utils.register_class(CyclesCurveRenderSettings)
bpy.utils.register_class(CyclesCurveSettings)
+ bpy.utils.register_class(CyclesDeviceSettings)
+ bpy.utils.register_class(CyclesPreferences)
def unregister():
@@ -1154,3 +1260,5 @@ def unregister():
bpy.utils.unregister_class(CyclesVisibilitySettings)
bpy.utils.unregister_class(CyclesCurveRenderSettings)
bpy.utils.unregister_class(CyclesCurveSettings)
+ bpy.utils.unregister_class(CyclesDeviceSettings)
+ bpy.utils.unregister_class(CyclesPreferences)