January 14, 2021, 7:42am
Blender allows the user to select “GPU Compute” as the rendering device even if the computer has no valid GPU device. It simply Greys out the drop down menu:
To a Python script, it then looks like a GPU compute device is in use:
Cycles will silently default to the CPU if the user selects GPU but doesn’t have one, but I don’t know how to detect this from a script.
I need a way to check from my Python script if an actual valid GPU device will be used for rendering or not.
Can anyone help?
If you look at the UI code that draws those dropdown boxes you will see that it calls a function named
show_device_active(context). The method code itself looks like this:
cscene = context.scene.cycles
if cscene.device != 'GPU':
The relevant part is the last line. You can replicate this in an own Add-on or script by calling
January 14, 2021, 9:06am
I actually tried that already, but
context.preferences.addons[__package__].preferences.has_active_device() seemed to always return False, even on my computer with an Nvidia GPU (note I had to change
"cycles" in that code.
I probably made a mistake. I will revisit it.
Thanks for the help.
January 14, 2021, 9:48am
Yes this does work. I must have made some other error when I first tried it.
Many thanks for the help