From a0b6233318b11fb2cae3b79fa3cd8a5be1149cb0 Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 6 Apr 2026 05:39:02 +0000 Subject: [PATCH] vo_gpu: add support for DEFINE parameters --- DOCS/man/options.rst | 6 ++++-- video/out/gpu/user_shaders.c | 3 +++ video/out/gpu/user_shaders.h | 1 + video/out/gpu/video.c | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index e124a5c9f0..f0fd0b5ba7 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -6445,8 +6445,10 @@ them. Parameters are global across the entire shader file, all hooks in the file can reference them, regardless of declaration order. - TYPE (required) + TYPE > (required) The parameter type. Supported types are ``float`` and ``int``. + The special type ``DEFINE`` emits a preprocessor define which can be + used inside ``#if`` directives. MINIMUM Minimum allowed value for this parameter. @@ -6464,7 +6466,7 @@ them. ``vo=gpu`` supports only a subset of the parameter features available in ``vo=gpu-next``. See libplacebo documentation for more detailed information about PARAM features supported in ``vo=gpu-next``. Notably - ``uint``, ``ENUM``, ``DEFINE``, ``DYNAMIC``, and ``CONSTANT`` types are + ``uint``, ``ENUM``, ``DYNAMIC``, and ``CONSTANT`` types are not available, and parameters cannot be referenced in ``WHEN`` expression. diff --git a/video/out/gpu/user_shaders.c b/video/out/gpu/user_shaders.c index bff7dcfcf9..850bba4eda 100644 --- a/video/out/gpu/user_shaders.c +++ b/video/out/gpu/user_shaders.c @@ -36,6 +36,7 @@ bool parse_shader_param_value(struct mp_log *log, struct gl_user_shader_param *p mp_err(log, "Missing type for param '%.*s'\n", BSTR_P(param->name)); return false; case GL_USER_SHADER_PARAM_INT: + case GL_USER_SHADER_PARAM_DEFINE: v = bstrtoll(val, &rest, 10); range[0] = INT_MIN; range[1] = INT_MAX; @@ -136,6 +137,8 @@ static bool parse_param(struct mp_log *log, struct bstr *body, param->type = GL_USER_SHADER_PARAM_FLOAT; } else if (bstr_equals0(line, "int")) { param->type = GL_USER_SHADER_PARAM_INT; + } else if (bstr_equals0(line, "DEFINE")) { + param->type = GL_USER_SHADER_PARAM_DEFINE; } else { mp_err(log, "Unrecognized PARAM TYPE: '%.*s'!\n", BSTR_P(line)); return false; diff --git a/video/out/gpu/user_shaders.h b/video/out/gpu/user_shaders.h index b7e0055367..15385c5645 100644 --- a/video/out/gpu/user_shaders.h +++ b/video/out/gpu/user_shaders.h @@ -67,6 +67,7 @@ enum gl_user_shader_param_type { GL_USER_SHADER_PARAM_UNKNOWN, GL_USER_SHADER_PARAM_FLOAT, GL_USER_SHADER_PARAM_INT, + GL_USER_SHADER_PARAM_DEFINE, }; struct gl_user_shader_param { diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c index 52f60ceabd..53faa2139a 100644 --- a/video/out/gpu/video.c +++ b/video/out/gpu/video.c @@ -2211,6 +2211,9 @@ static void user_hook(struct gl_video *p, struct image img, case GL_USER_SHADER_PARAM_INT: gl_sc_uniform_i_bstr(p->sc, param->name, lrint(value)); break; + case GL_USER_SHADER_PARAM_DEFINE: + GLSLHF("#define %.*s %d\n", BSTR_P(param->name), (int)lrint(value)); + break; } }