Maniphest T101977

GPU: Backend selection
Closed, ResolvedDESIGN

Assigned To
Jeroen Bakker (jbakker)
Authored By
Jeroen Bakker (jbakker)
Oct 21 2022, 2:04 PM
Tags
  • EEVEE & Viewport
  • BF Blender (3.5)
Subscribers
Arbaz Arif (AcidRain0)
Donovane (Stimes)
Francesco Siddi (fsiddi)
Jarrett Johnson (jarrett.johnson)
Jeroen Bakker (jbakker)
Michael Parkin-White (MichaelPW)
Thomas Dinges (dingto)
Tokens
"Like" token, awarded by blueprintrandom.

Description

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.

NOTE: Q: Should this be hidden behind experimental feature? If so we might want to move this to the Experimental tab.

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.

Revisions and Commits

Event Timeline

Jeroen Bakker (jbakker) changed the task status from Needs Triage to Confirmed.Oct 21 2022, 2:04 PM
Jeroen Bakker (jbakker) created this task.
Jeroen Bakker (jbakker) changed the subtype of this task from "Report" to "Design".
Jacob Merrill (blueprintrandom) awarded a token.Oct 21 2022, 11:22 PM
Michael Parkin-White (MichaelPW) added a subscriber: Michael Parkin-White (MichaelPW).Oct 24 2022, 11:53 AM
Jarrett Johnson (jarrett.johnson) added a subscriber: Jarrett Johnson (jarrett.johnson).Nov 13 2022, 2:53 PM
Jeroen Bakker (jbakker) claimed this task.Dec 13 2022, 3:41 PM
Jeroen Bakker (jbakker) triaged this task as High priority.
Jeroen Bakker (jbakker) updated the task description.
Jeroen Bakker (jbakker) added a project: BF Blender (3.5).
Jeroen Bakker (jbakker) updated the task description.Dec 14 2022, 11:54 AM
Francesco Siddi (fsiddi) added a subscriber: Francesco Siddi (fsiddi).Dec 14 2022, 12:39 PM

Thanks for looking into this, Jeroen. It's not clear to me what "Default" means. Can we work under the following assumptions:

  • For now, default is OpenGL
  • As soon as deemed stable, default is Metal
  • If Metal is not supported, you switch back to OpenGL
  • Eventually OpenGL will be dropped (in a few releases)

    Further, I suggest to add a label under the enum saying "Updating the GPU backend requires a restart of Blender". Better wording is welcome.
Jeroen Bakker (jbakker) updated the task description.Dec 14 2022, 3:03 PM
Jeroen Bakker (jbakker) updated the task description.
Jeroen Bakker (jbakker) added a comment.Dec 14 2022, 3:15 PM

@Francesco Siddi (fsiddi) I applied your feedback to the design + implementation.

  • Removed the default option. This makes the need of the the new enumeration obsolete as we can reuse eGPUBackendType.
  • I also added the label. It will only show when the value is changed to keep the UI nice.
Francesco Siddi (fsiddi) added a comment.Dec 14 2022, 5:16 PM

Looks nice! Let me know when this lands in a branch for testing.

Arbaz Arif (AcidRain0) added a subscriber: Arbaz Arif (AcidRain0).Dec 14 2022, 5:59 PM

"GPU Backend" sounds very obfuscate, It's confusing

First we have Render Devices that says None and Metal
And below we have "GPU Backend" that says Metal and Opengl

I think the "GPU Backend" should be renamed to "Viewport Backend" or "Viewport GPU Backend" to clearly differentiate it

Donovane (Stimes) added a subscriber: Donovane (Stimes).Dec 31 2022, 8:36 PM
In T101977#1460442, @Arbaz Arif (AcidRain0) wrote:

"GPU Backend" sounds very obfuscate, It's confusing

First we have Render Devices that says None and Metal
And below we have "GPU Backend" that says Metal and Opengl

I think the "GPU Backend" should be renamed to "Viewport Backend" or "Viewport GPU Backend" to clearly differentiate it

Nah because is for the viewport and the render.... GPU Backend is perfect dude

Thomas Dinges (dingto) added a subscriber: Thomas Dinges (dingto).Jan 3 2023, 10:14 PM

@Jeroen Bakker (jbakker) Hey, I think this task can be closed now?

Jeroen Bakker (jbakker) closed this task as Resolved.Thu, Jan 12, 11:05 AM