CLI: move VSync from an environment variable to an argument

Add a command line argument --gpu-vsync on/off/auto.

Prefer command line arguments for GPU settings,
as it means the value is error checked and set when Blender starts.

Also refactor GHOST_Context to take a parameter argument which
includes the stereo-visual & debug arguments and includes the newly
added vsync setting. This makes it possible to add GPU context
parameters more easily in the future.

It also removes redundant parsing & setting the VSync setting for
off-screen contexts.

Changes to recent PR !143049.

Ref !144473
This commit is contained in:
Campbell Barton
2025-08-14 05:16:12 +00:00
parent 248a9653f6
commit 5540b9440a
42 changed files with 330 additions and 205 deletions

View File

@@ -784,6 +784,7 @@ static void print_help(bArgs *ba, bool all)
PRINT("\n");
PRINT("GPU Options:\n");
BLI_args_print_arg_doc(ba, "--gpu-backend");
BLI_args_print_arg_doc(ba, "--gpu-vsync");
if (defs.with_opengl_backend) {
BLI_args_print_arg_doc(ba, "--gpu-compilation-subprocesses");
}
@@ -871,9 +872,6 @@ static void print_help(bArgs *ba, bool all)
PRINT(" $BLENDER_CUSTOM_SPLASH Full path to an image that replaces the splash screen.\n");
PRINT(
" $BLENDER_CUSTOM_SPLASH_BANNER Full path to an image to overlay on the splash screen.\n");
PRINT(
" $BLENDER_VSYNC Set to 0 to disable VSync.\n"
" With OpenGL, other values set the swap interval.\n");
if (defs.with_opencolorio) {
PRINT(" $OCIO Path to override the OpenColorIO configuration file.\n");
@@ -1614,6 +1612,44 @@ static int arg_handle_gpu_backend_set(int argc, const char **argv, void * /*data
return 1;
}
static const char arg_handle_gpu_vsync_set_doc[] =
"\n"
"\tSet the VSync.\n"
"\tValid options are: 'on', 'off' & 'auto' for adaptive sync.\n"
"\n"
"\t* The default settings depend on the GPU driver.\n"
"\t* Disabling VSync can be useful for testing performance.\n"
"\t* 'auto' is only supported by the OpenGL backend.";
static int arg_handle_gpu_vsync_set(int argc, const char **argv, void * /*data*/)
{
const char *arg_id = "--gpu-vsync";
if (argc < 2) {
fprintf(stderr, "\nError: VSync value must follow '%s'.\n", arg_id);
return 0;
}
/* Must be compatible with #GHOST_TVSyncModes. */
int vsync;
if (STREQ(argv[1], "on")) {
vsync = 1;
}
else if (STREQ(argv[1], "off")) {
vsync = 0;
}
else if (STREQ(argv[1], "auto")) {
vsync = -1;
}
else {
fprintf(stderr, "\nError: expected a value in [on, off, auto] '%s %s'.\n", arg_id, argv[1]);
return 0;
}
GPU_backend_vsync_set_override(vsync);
return 1;
}
static const char arg_handle_gpu_compilation_subprocesses_set_doc[] =
"\n"
"\tOverride the Max Compilation Subprocesses setting (OpenGL only).";
@@ -2758,6 +2794,7 @@ 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);
BLI_args_add(ba, nullptr, "--gpu-vsync", CB(arg_handle_gpu_vsync_set), nullptr);
if (defs.with_opengl_backend) {
BLI_args_add(ba,
nullptr,