GPU backend selection
Keep in sync with https://hackmd.io/@55n-91bZTVmcvTOc9vZV5Q/r1BtJMIdo and eventually upload the plantuml diagrams here as images.
Requirements
- From the command line it should be possible to override the GPU backend selection.
- From the user preferences it should be possible to override the GPU backend selection.
- Blender should try multiple backends to find a matching backend.
- When an unsupported override is set blender should fallback to OpenGL.
- The command line argument has more priority than the user preference setting.
Current API
- GPU_context_create creates a new context based on GPU_backend_type_selection_get.
- GPU_context_create requires the correct ghost_context for the current GPU_backend_type_selection_get. Expect crashes when this isn't enforced.
- GPU_backend_supported checks if the backend returned by GPU_backend_type_selection_get is supported by the platform. It doesn't require the context to be created.
- GPU_backend_type_selection_set overrides the default backend with the given type. It is called during command line argument parsing for the --gpu-backend argument. It is also called by ShaderBuilder and test cases to check multiple backends during the same run.
- GPU_backend_get_type returns the backend type that was initialized when the context is created.
Proposal
User Preferences
In the user preferences system tab a new panel will be added "GPU Backend" with the next options:
- Default
- OpenGL
- Metal
For now the panel only appears on Apple
Changing this value requires a restart. This should be clearly communicated to the user.
Technical the user could set an override to something that isn't supported by his system. For example when copying/syncing user preferences to other machines. This could be detected and automatically switch back to the default behavior.
Impact
User preference
- Add gpu_backend to UserDef structure in DNA_userdef_types.h
- In rna_userdef.c define gpu_backend property.
- Add USERPREF_PT_system_gpu_backend to space_userpref.py.
GPU module
- Implement the new API functions and tweak the existing ones.
- Cache the result of GPU_backend_supported until GPU_backend_type_selection_set is called.
Command line arguments
- In creator_args.c#arg_handle_gpu_backend_set use GPU_backend_type_selection_set_override.
Window manager
- In wm_init_userdef check if backend types are not yet overridden. If so override the backend types with the setting stored in the user preference.
- In wm_init_userdeflet the GPU_module detect which GPU backend should be used.
