Changeset View
Changeset View
Standalone View
Standalone View
source/creator/creator_args.c
| Show All 36 Lines | |||||
| # include "BKE_global.h" | # include "BKE_global.h" | ||||
| # include "BKE_image_format.h" | # include "BKE_image_format.h" | ||||
| # include "BKE_lib_id.h" | # include "BKE_lib_id.h" | ||||
| # include "BKE_main.h" | # include "BKE_main.h" | ||||
| # include "BKE_report.h" | # include "BKE_report.h" | ||||
| # include "BKE_scene.h" | # include "BKE_scene.h" | ||||
| # include "BKE_sound.h" | # include "BKE_sound.h" | ||||
| # include "GPU_context.h" | |||||
| # ifdef WITH_FFMPEG | # ifdef WITH_FFMPEG | ||||
| # include "IMB_imbuf.h" | # include "IMB_imbuf.h" | ||||
| # endif | # endif | ||||
| # ifdef WITH_PYTHON | # ifdef WITH_PYTHON | ||||
| # include "BPY_extern_python.h" | # include "BPY_extern_python.h" | ||||
| # include "BPY_extern_run.h" | # include "BPY_extern_run.h" | ||||
| # endif | # endif | ||||
| ▲ Show 20 Lines • Show All 1,053 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| /* Also enable logging because that how gl errors are reported. */ | /* Also enable logging because that how gl errors are reported. */ | ||||
| const char *gpu_filter = "gpu.*"; | const char *gpu_filter = "gpu.*"; | ||||
| CLG_type_filter_include(gpu_filter, strlen(gpu_filter)); | CLG_type_filter_include(gpu_filter, strlen(gpu_filter)); | ||||
| G.debug |= G_DEBUG_GPU; | G.debug |= G_DEBUG_GPU; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static const char arg_handle_gpu_backend_set_doc[] = | |||||
| "\n" | |||||
| "\tForce to use a specific GPU backend. Valid options: " | |||||
| # ifdef WITH_METAL_BACKEND | |||||
| "'metal', " | |||||
| # endif | |||||
| "'opengl')."; | |||||
| 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], "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; | |||||
| } | |||||
MichaelPW: As per other comment, this one may be less relevant but as Metal device initialisation may fail… | |||||
| GPU_backend_type_selection_set(gpu_backend); | |||||
| if (!GPU_backend_supported()) { | |||||
| printf("\nError: GPU backend not supported.\n"); | |||||
| return 0; | |||||
| } | |||||
| return 1; | |||||
| } | |||||
| static const char arg_handle_debug_fpe_set_doc[] = | static const char arg_handle_debug_fpe_set_doc[] = | ||||
| "\n\t" | "\n\t" | ||||
| "Enable floating-point exceptions."; | "Enable floating-point exceptions."; | ||||
| static int arg_handle_debug_fpe_set(int UNUSED(argc), | static int arg_handle_debug_fpe_set(int UNUSED(argc), | ||||
| const char **UNUSED(argv), | const char **UNUSED(argv), | ||||
| void *UNUSED(data)) | void *UNUSED(data)) | ||||
| { | { | ||||
| main_signal_setup_fpe(); | main_signal_setup_fpe(); | ||||
| ▲ Show 20 Lines • Show All 947 Lines • ▼ Show 20 Lines | # define CB_EX(a, b) a##_doc_##b, a | ||||
| * especially `bpy.appdir` since it's useful to show errors finding paths on startup. */ | * especially `bpy.appdir` since it's useful to show errors finding paths on startup. */ | ||||
| BLI_args_add(ba, NULL, "--log", CB(arg_handle_log_set), ba); | BLI_args_add(ba, NULL, "--log", CB(arg_handle_log_set), ba); | ||||
| BLI_args_add(ba, NULL, "--log-level", CB(arg_handle_log_level_set), ba); | BLI_args_add(ba, NULL, "--log-level", CB(arg_handle_log_level_set), ba); | ||||
| BLI_args_add(ba, NULL, "--log-show-basename", CB(arg_handle_log_show_basename_set), ba); | BLI_args_add(ba, NULL, "--log-show-basename", CB(arg_handle_log_show_basename_set), ba); | ||||
| BLI_args_add(ba, NULL, "--log-show-backtrace", CB(arg_handle_log_show_backtrace_set), ba); | BLI_args_add(ba, NULL, "--log-show-backtrace", CB(arg_handle_log_show_backtrace_set), ba); | ||||
| BLI_args_add(ba, NULL, "--log-show-timestamp", CB(arg_handle_log_show_timestamp_set), ba); | BLI_args_add(ba, NULL, "--log-show-timestamp", CB(arg_handle_log_show_timestamp_set), ba); | ||||
| BLI_args_add(ba, NULL, "--log-file", CB(arg_handle_log_file_set), ba); | BLI_args_add(ba, NULL, "--log-file", CB(arg_handle_log_file_set), ba); | ||||
| /* GPU backend selection should be part of ARG_PASS_ENVIRONMENT for correct GPU context selection | |||||
| * for anim player. */ | |||||
| BLI_args_add(ba, NULL, "--gpu-backend", CB(arg_handle_gpu_backend_set), NULL); | |||||
| /* Pass: Background Mode & Settings | /* Pass: Background Mode & Settings | ||||
| * | * | ||||
| * Also and commands that exit after usage. */ | * Also and commands that exit after usage. */ | ||||
| BLI_args_pass_set(ba, ARG_PASS_SETTINGS); | BLI_args_pass_set(ba, ARG_PASS_SETTINGS); | ||||
| BLI_args_add(ba, "-h", "--help", CB(arg_handle_print_help), ba); | BLI_args_add(ba, "-h", "--help", CB(arg_handle_print_help), ba); | ||||
| /* Windows only */ | /* Windows only */ | ||||
| BLI_args_add(ba, "/?", NULL, CB_EX(arg_handle_print_help, win32), ba); | BLI_args_add(ba, "/?", NULL, CB_EX(arg_handle_print_help, win32), ba); | ||||
| ▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines | |||||
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.