Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2022-10-18 19:08:36 +0300
committerJeroen Bakker <jeroen@blender.org>2022-10-18 19:08:36 +0300
commit949d6e360bf5ca4168e694ae3f6e445a1b91e28e (patch)
tree8ed47bad5d038ccd5eb3d7c28f98c8a291e8cc9b
parent5c1d2c5a9d336b7b41617139e04ace23229e8d1f (diff)
Add command line argument to swithc gpu backend.
-rw-r--r--source/blender/gpu/GPU_context.h1
-rw-r--r--source/blender/gpu/intern/gpu_context.cc6
-rw-r--r--source/creator/creator_args.c40
3 files changed, 46 insertions, 1 deletions
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