Page MenuHome

Blender: Add command line argument to switch gpu backends.
ClosedPublic

Authored by Jeroen Bakker (jbakker) on Oct 19 2022, 10:29 AM.

Details

Summary

Add command line argument to switch gpu backend. Add --gpu-backend option to
override the gpu backend selected by Blender.

Values for this option that will be available in releases for now are:

  • opengl: Force blender to select OpenGL backend.

During development and depending on compile options additional values can exist:

  • metal: Force Blender to select Metal backend.

--help text is dynamic based on the active compile options.

When this option isn't provided the internal logic for GPU backend selection will be used.
Note that this is at the time of writing the same as always selecting the opengl backend.

Diff Detail

Repository
rB Blender

Event Timeline

Jeroen Bakker (jbakker) updated this revision to Diff 56948.EditedOct 19 2022, 10:43 AM
  • Add support for animation playback.

On mac with WITH_METAL_BACKEND=On it creates the correct context + gpu backend. It fails compiling some shaders. There is a patch that could be applied to master that should fix outstanding shader compilation errors.

https://builder.blender.org/admin/#/builders/136/builds/167 started to check if GHOST changes compiles on all platforms.

source/blender/gpu/GPU_context.h
24

selection is a wrong name.
GPU_backend_default_type_get/set?

26

Should we rename this to GPU_backend_active_type_get

Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
  • Combined glSettings and type in ghost.
  • Add support for animation playback.
  • Fix compilation errors on linux.
  • Fix compilation errors windows.
  • Fix compilation errors SDL.
  • Merge branch 'master' into temp-T101905-gpu-backend-argument
  • Shader builder process all available backends.
Jeroen Bakker (jbakker) requested review of this revision.Oct 19 2022, 1:20 PM
  • Add support for animation playback.

On mac with WITH_METAL_BACKEND=On it creates the correct context + gpu backend. It fails compiling some shaders. There is a patch that could be applied to master that should fix outstanding shader compilation errors.

That's great to hear, thanks! I also have several follow-up patches to clean up certain paths for Metal as functionality is still not at 100%, including the currently in-review patch for porting EEVEE to use Shader Create Info's.

Edit: For reference, device requirements for Metal Viewport enablement. All recent devices will cover this, though there may be a number of edge cases for older devices.

  • Metal 2.2 support
  • macOS 10.15 and onwards
  • Argument Buffers Tier 2 support (Most GPUs supporting Metal will have this)
  • Support for shader barycentric
source/blender/gpu/intern/gpu_shader_builder.cc
97

Metal availability on certain devices is dependent on certain available API features, which are not available on all devices which do support Metal.
While the WITH_METAL_BACKEND CMake flag should guard against OS availability, this only applies to the build platform rather than the device that Blender is running on.

As a result, while I'm not sure how best to factor this into the code, it would be useful to ensure that areas in the code do not attempt to initialise a Metal device if the device fails compatibility as defined in: GPU_backend_supported().

The GPU_backend_supported() could also likely be refactored to take the backend type as a parameter, rather than reading the global for these cases. There may also be other places in the code that it makes sense to guard.

source/creator/creator_args.c
1144

As per other comment, this one may be less relevant but as Metal device initialisation may fail on certain configs, due to feature availability, then it could be good to call GPU_backend_supported() and if this fails, fall back to the default GPU backend.

Though this may not be relevant for an explicit launch flag, as it may be preferable just to let the app silently fail if Metal is not available, to avoid any confusion.
At the point where there is a selection in the app's interface, then I imagine falling back to the supported API would be idea.

Jeroen Bakker (jbakker) marked an inline comment as done.
  • Add supported backend check to shader builder.
  • Report error when choosing incorrect GPU backend.
This revision is now accepted and ready to land.Oct 19 2022, 3:09 PM
  • Add supported backend check to shader builder.
  • Report error when choosing incorrect GPU backend.

Looks good :)