Commit: 949d6e360bf5ca4168e694ae3f6e445a1b91e28e Author: Jeroen Bakker Date: Tue Oct 18 18:08:36 2022 +0200 Branches: temp-T101905-gpu-backend-argument https://developer.blender.org/rB949d6e360bf5ca4168e694ae3f6e445a1b91e28e
Add command line argument to swithc gpu backend. =================================================================== M source/blender/gpu/GPU_context.h M source/blender/gpu/intern/gpu_context.cc M source/creator/creator_args.c =================================================================== diff --git a/source/blender/gpu/GPU_context.h b/source/blender/gpu/GPU_context.h index b59ea9e55d2..e44da5b0640 100644 --- a/source/blender/gpu/GPU_context.h +++ b/source/blender/gpu/GPU_context.h @@ -21,6 +21,7 @@ extern "C" { * automatically initializes the back-end, and #GPU_context_discard frees it when there * are no more contexts. */ bool GPU_backend_supported(void); +void GPU_backend_type_set(const eGPUBackendType backend); eGPUBackendType GPU_backend_get_type(void); /** Opaque type hiding blender::gpu::Context. */ diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc index 48d7b2019c5..57f5f3a6d0d 100644 --- a/source/blender/gpu/intern/gpu_context.cc +++ b/source/blender/gpu/intern/gpu_context.cc @@ -223,9 +223,13 @@ void GPU_render_step() /* NOTE: To enable Metal API, we need to temporarily change this to `GPU_BACKEND_METAL`. * Until a global switch is added, Metal also needs to be enabled in GHOST_ContextCGL: * `m_useMetalForRendering = true`. */ -static const eGPUBackendType g_backend_type = GPU_BACKEND_OPENGL; +static eGPUBackendType g_backend_type = GPU_BACKEND_OPENGL; static GPUBackend *g_backend = nullptr; +void GPU_backend_type_set(const eGPUBackendType backend) +{ + g_backend_type = backend; +} bool GPU_backend_supported(void) { switch (g_backend_type) { diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index 06b898587bf..73966b80f21 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -42,6 +42,8 @@ # include "BKE_scene.h" # include "BKE_sound.h" +# include "GPU_context.h" + # ifdef WITH_FFMPEG # include "IMB_imbuf.h" # endif @@ -1111,6 +1113,42 @@ static int arg_handle_debug_gpu_set(int UNUSED(argc), return 0; } +static const char arg_handle_gpu_backend_set_doc[] = + "\n" + "\tForce to use a specific GPU backend. Valid options are " +# ifdef WITH_METAL_BACKEND + "'metal', " +# endif + "'opengl' and 'default'."; +static int arg_handle_gpu_backend_set(int argc, const char **argv, void *UNUSED(data)) +{ + if (argc == 0) { + printf("\nError: GPU backend must follow '--gpu-backend'.\n"); + return 0; + } + + eGPUBackendType gpu_backend = GPU_BACKEND_NONE; + + if (STREQ(argv[1], "default")) { + gpu_backend = GPU_BACKEND_NONE; + } + else if (STREQ(argv[1], "opengl")) { + gpu_backend = GPU_BACKEND_OPENGL; + } +# ifdef WITH_METAL_BACKEND + else if (STREQ(argv[1], "metal")) { + gpu_backend = GPU_BACKEND_METAL; + } +# endif + else { + printf("\nError: Unrecognized GPU backend for '--gpu-backend'.\n"); + return 0; + } + GPU_backend_type_set(gpu_backend); + + return 1; +} + static const char arg_handle_debug_fpe_set_doc[] = "\n\t" "Enable floating-point exceptions."; @@ -2095,6 +2133,8 @@ void main_args_setup(bContext *C, bArgs *ba) BLI_args_add(ba, "-a", NULL, CB(arg_handle_playback_mode), NULL); + BLI_args_add(ba, NULL, "--gpu-backend", CB(arg_handle_gpu_backend_set), NULL); + BLI_args_add(ba, "-d", "--debug", CB(arg_handle_debug_mode_set), ba); # ifdef WITH_FFMPEG _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs