Page MenuHome

Cycles: Add command line option for overriding the compute device

Authored by Lukas Stockner (lukasstockner97) on Oct 2 2020, 1:52 AM.



The current way of setting the compute device makes sense for local
use, but for headless rendering it it a massive pain to get Cycles
to use the correct device, usually involving entire Python scripts.

Therefore, this patch adds a simple command-line option to Blender
for specifying the type of device that should be used. If the option
is present, the settings in the user preferences and the scene are
ignored, and instead all devices matching the specified type are used.

Diff Detail

rB Blender

Event Timeline

Lukas Stockner (lukasstockner97) requested review of this revision.Oct 2 2020, 1:52 AM
Lukas Stockner (lukasstockner97) created this revision.

Hi @Lukas Stockner (lukasstockner97) nice patch, this feature is long overdue.

That said, I'm not thrilled about having Cycles hard-coded options defined in the Blender code. Specially since the options are defined in Cycles itself: /intern/cycles/blender/addon/ At the very least I think it should copy what we do for --engine and get the list of options dynamically.

Other than that some small details:

  • When I pick a render device that is not supported (e.g., cuda), I get the error three times:
Found no Cycles device of the specified type, falling back to CPU...
Found no Cycles device of the specified type, falling back to CPU...
Found no Cycles device of the specified type, falling back to CPU...
  • I think we should use CAPITAL LETTERS for the device names.
Brecht Van Lommel (brecht) requested changes to this revision.Oct 2 2020, 12:57 PM

Cycles specific arguments should be defined in intern/cycles/blender/addon/ (see for example --cycles-print-stats).

I agree uppercase would be more consistent with other Blender arguments here.


I think it may be better for rendering to fail entirely?

If you are expecting to render on the GPU on a render farm, and there is no GPU, then it's probably better to abort since there is a configuration issue.


4 -> strlen("+cpu")

This revision now requires changes to proceed.Oct 2 2020, 12:57 PM

Ah yes, I forgot that Cycles has its own argument handling.
One downside of that is that it doesn't show up in the help output, but as long as it's documented properly, that should be fine.

I agree that cancelling the render when the device in question is not available makes sense, but I'm not sure yet how to
implement this properly since the code in question is called from get_session_params, which is called from quite a few places,
none of which currently have any logic for failing.

Forgot to capitalize the options in the help text.

Ok, I can figure out how to make it cancel the render later.

This revision is now accepted and ready to land.Oct 2 2020, 7:19 PM

@Lukas Stockner (lukasstockner97) great work, remember to indeed mention this somewhere in the Cycles manual

@Dalai Felinto (dfelinto) Good point, release notes are updated and I opened D9098 for the manual.