diff --git a/source/blender/gpu/GPU_capabilities.hh b/source/blender/gpu/GPU_capabilities.hh index 844f1b196af..fc84af9e4ef 100644 --- a/source/blender/gpu/GPU_capabilities.hh +++ b/source/blender/gpu/GPU_capabilities.hh @@ -65,3 +65,6 @@ bool GPU_stereo_quadbuffer_support(); int GPU_minimum_per_vertex_stride(); bool GPU_transform_feedback_support(); + +/** WARNING: Should only be called at startup from creator_args. Never call it at runtime. */ +void GPU_compilation_subprocess_override_set(int count); diff --git a/source/blender/gpu/intern/gpu_capabilities.cc b/source/blender/gpu/intern/gpu_capabilities.cc index a4d743c1453..13e6aeefe31 100644 --- a/source/blender/gpu/intern/gpu_capabilities.cc +++ b/source/blender/gpu/intern/gpu_capabilities.cc @@ -239,3 +239,15 @@ bool GPU_stereo_quadbuffer_support() } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Creator arguments overrides + * \{ */ + +void GPU_compilation_subprocess_override_set(int count) +{ + BLI_assert(GCaps.max_parallel_compilations == -1); + GCaps.max_parallel_compilations = count; +} + +/** \} */ diff --git a/source/blender/gpu/intern/gpu_capabilities_private.hh b/source/blender/gpu/intern/gpu_capabilities_private.hh index 293dc7f3131..1faca3d1964 100644 --- a/source/blender/gpu/intern/gpu_capabilities_private.hh +++ b/source/blender/gpu/intern/gpu_capabilities_private.hh @@ -51,7 +51,7 @@ struct GPUCapabilities { bool texture_view_support = true; bool stencil_export_support = false; - int max_parallel_compilations = 0; + int max_parallel_compilations = -1; /* OpenGL related workarounds. */ bool mip_render_workaround = false; diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index 841f997477f..951aec1661a 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -599,8 +599,14 @@ void GLBackend::capabilities_init() detect_workarounds(); #if BLI_SUBPROCESS_SUPPORT - GCaps.max_parallel_compilations = std::min(int(U.max_shader_compilation_subprocesses), - BLI_system_thread_count()); + if (GCaps.max_parallel_compilations == -1) { + GCaps.max_parallel_compilations = std::min(int(U.max_shader_compilation_subprocesses), + BLI_system_thread_count()); + } + if (G.debug & G_DEBUG_GPU_RENDERDOC) { + /* Avoid crashes on RenderDoc sessions. */ + GCaps.max_parallel_compilations = 0; + } #else GCaps.max_parallel_compilations = 0; #endif diff --git a/source/creator/creator_args.cc b/source/creator/creator_args.cc index fd1719e76de..38530c35dcb 100644 --- a/source/creator/creator_args.cc +++ b/source/creator/creator_args.cc @@ -48,6 +48,7 @@ # include "BKE_scene.hh" # include "BKE_sound.h" +# include "GPU_capabilities.hh" # include "GPU_context.hh" # ifdef WITH_PYTHON @@ -777,6 +778,9 @@ static void print_help(bArgs *ba, bool all) PRINT("\n"); PRINT("GPU Options:\n"); BLI_args_print_arg_doc(ba, "--gpu-backend"); +# ifdef WITH_OPENGL_BACKEND + BLI_args_print_arg_doc(ba, "--gpu-compilation-subprocesses"); +# endif PRINT("\n"); PRINT("Misc Options:\n"); @@ -1484,6 +1488,42 @@ static int arg_handle_gpu_backend_set(int argc, const char **argv, void * /*data return 1; } +# ifdef WITH_OPENGL_BACKEND +static const char arg_handle_gpu_compilation_subprocesses_set_doc[] = + "\n" + "\tOverride the Max Compilation Subprocesses setting (OpenGL only)."; +static int arg_handle_gpu_compilation_subprocesses_set(int argc, + const char **argv, + void * /*data*/) +{ + const char *arg_id = "--gpu-compilation-subprocesses"; + const int min = 0, max = BLI_system_thread_count(); + if (argc > 1) { + const char *err_msg = nullptr; + int subprocesses; + if (!parse_int_strict_range(argv[1], nullptr, min, max, &subprocesses, &err_msg)) { + fprintf(stderr, + "\nError: %s '%s %s', expected number in [%d..%d].\n", + err_msg, + arg_id, + argv[1], + min, + max); + return 0; + } + + GPU_compilation_subprocess_override_set(subprocesses); + return 1; + } + fprintf(stderr, + "\nError: you must specify a number of subprocesses in [%d..%d] '%s'.\n", + min, + max, + arg_id); + return 0; +} +# endif + static const char arg_handle_debug_fpe_set_doc[] = "\n\t" "Enable floating-point exceptions."; @@ -2565,6 +2605,13 @@ void main_args_setup(bContext *C, bArgs *ba, bool all) /* GPU backend selection should be part of #ARG_PASS_ENVIRONMENT for correct GPU context * selection for animation player. */ BLI_args_add(ba, nullptr, "--gpu-backend", CB_ALL(arg_handle_gpu_backend_set), nullptr); +# ifdef WITH_OPENGL_BACKEND + BLI_args_add(ba, + nullptr, + "--gpu-compilation-subprocesses", + CB(arg_handle_gpu_compilation_subprocesses_set), + nullptr); +# endif /* Pass: Background Mode & Settings *