RobotLocomotion / drake-blender

Drake glTF Render Client-Server API using Blender
https://drake.mit.edu/
Other
18 stars 6 forks source link

blender server doesn't actively make use of GPU #62

Open SeanCurtis-TRI opened 1 year ago

SeanCurtis-TRI commented 1 year ago

When running the blender server and rendering against the Cycles renderer, I found that the default configuration was CPU bound. Within blender, I could configure blender's preferences to use GPU (which makes a huge performance difference).

Following the guidance from this stackoverflow question, I was able to introduce a --bpy_settings_file with the following code:

if bpy.data.scenes[0].render.engine == "CYCLES":
    cycles_prefs = bpy.context.preferences.addons["cycles"].preferences
    cycles_prefs.compute_device_type = "CUDA"
    bpy.context.scene.cycles.device = "GPU"
    bpy.context.preferences.addons["cycles"].preferences.get_devices()
    for d in cycles_prefs.devices:
        d["use"] = 1

This successfully changed the rendering to be GPU accelerated.

Ideally, the server should be doing this for us.

Naively, we could simply stash this code into the server. At this point, it's not clear if that could be harmful:

We might consider simply adding the code stanza and including a flag called --disable_auto_gpu. It would at least allow a user to opt-out if it doesn't do what they want.

Finally, the stanza above is a bit of black magic incantation, it probably bears a bit more investigation to discover if it's all necessary/helpful.

jwnimmer-tri commented 1 year ago

So long as "the user has the final say", I think it'd be OK to default to better GPU.

By "the user has the final say", I mean at least that the user's --bpy_settings_file is run last, so change anything they didn't like about our defaults.

Ideally, the *.blend file (--blend_file) would also trump our defaults, but I'm not sure if that's possible. Possibly it would undo our GPU settings unconditionally, even though the user didn't mean to.