Cycles: Refactor and add use_gpu() to UI code
Add a `use_gpu()` function to the UI code for Cycles. This is done to clean up some of the other code (`use_{backend}()`) and to help isolate `use_multi_device` and `show_device_active` from their context making them more robust to changes made in other parts of the UI code. Pull Request: https://projects.blender.org/blender/blender/pulls/124134
This commit is contained in:
parent
b42f2b7634
commit
9d1e613292
@ -100,48 +100,43 @@ def use_cpu(context):
|
||||
return (get_device_type(context) == 'NONE' or cscene.device == 'CPU' or not backend_has_active_gpu(context))
|
||||
|
||||
|
||||
def use_metal(context):
|
||||
def use_gpu(context):
|
||||
cscene = context.scene.cycles
|
||||
|
||||
return (get_device_type(context) == 'METAL' and cscene.device == 'GPU' and backend_has_active_gpu(context))
|
||||
return (get_device_type(context) != 'NONE' and cscene.device == 'GPU' and backend_has_active_gpu(context))
|
||||
|
||||
|
||||
def use_metal(context):
|
||||
return (get_device_type(context) == 'METAL' and use_gpu(context))
|
||||
|
||||
|
||||
def use_cuda(context):
|
||||
cscene = context.scene.cycles
|
||||
|
||||
return (get_device_type(context) == 'CUDA' and cscene.device == 'GPU' and backend_has_active_gpu(context))
|
||||
return (get_device_type(context) == 'CUDA' and use_gpu(context))
|
||||
|
||||
|
||||
def use_hip(context):
|
||||
cscene = context.scene.cycles
|
||||
|
||||
return (get_device_type(context) == 'HIP' and cscene.device == 'GPU' and backend_has_active_gpu(context))
|
||||
return (get_device_type(context) == 'HIP' and use_gpu(context))
|
||||
|
||||
|
||||
def use_optix(context):
|
||||
cscene = context.scene.cycles
|
||||
|
||||
return (get_device_type(context) == 'OPTIX' and cscene.device == 'GPU' and backend_has_active_gpu(context))
|
||||
return (get_device_type(context) == 'OPTIX' and use_gpu(context))
|
||||
|
||||
|
||||
def use_oneapi(context):
|
||||
cscene = context.scene.cycles
|
||||
|
||||
return (get_device_type(context) == 'ONEAPI' and cscene.device == 'GPU' and backend_has_active_gpu(context))
|
||||
return (get_device_type(context) == 'ONEAPI' and use_gpu(context))
|
||||
|
||||
|
||||
def use_multi_device(context):
|
||||
cscene = context.scene.cycles
|
||||
if cscene.device != 'GPU':
|
||||
return False
|
||||
return context.preferences.addons[__package__].preferences.has_multi_device()
|
||||
if use_gpu(context):
|
||||
return context.preferences.addons[__package__].preferences.has_multi_device()
|
||||
return False
|
||||
|
||||
|
||||
def show_device_active(context):
|
||||
cscene = context.scene.cycles
|
||||
if cscene.device != 'GPU':
|
||||
if cscene.device == 'CPU':
|
||||
return True
|
||||
return backend_has_active_gpu(context)
|
||||
return use_gpu(context)
|
||||
|
||||
|
||||
def show_preview_denoise_active(context):
|
||||
|
Loading…
Reference in New Issue
Block a user