vo_gpu_next: add tunable shader parameters

This is a very simple but easy way of doing it. Ideally, it would be
nice if we could also add some sort of introspection about shader
parameters at runtime, ideally exposing the entire list of parameters as
a custom property dict. But that is a lot of effort for dubious gain.

It's worth noting that, as currently implemented, re-setting
`glsl-shader-opts` to a new value doesn't reset back previously mutated
values to their defaults.
This commit is contained in:
Niklas Haas 2022-11-03 16:16:59 +01:00 committed by Niklas Haas
parent ac3966184b
commit 33136c276c
5 changed files with 69 additions and 1 deletions

View File

@ -49,6 +49,7 @@ Interface changes
- deprecate `--gamma-factor`
- deprecate `--gamma-auto`
- remove `--vulkan-disable-events`
- add `--glsl-shader-opts`
--- mpv 0.34.0 ---
- deprecate selecting by card number with `--drm-connector`, add
`--drm-device` which can be used instead

View File

@ -5857,6 +5857,13 @@ them.
``--glsl-shader=<file>``
CLI/config file only alias for ``--glsl-shaders-append``.
``--glsl-shader-opts=param1=value1,param2=value2,...``
Specifies the options to use for tunable shader parameters. You can target
specific named shaders by prefixing the shader name with a ``/``, e.g.
``shader/param=value``. Without a prefix, parameters affect all shaders.
The shader name is the base part of the shader filename, without the
extension. (``--vo=gpu-next`` only)
``--deband``
Enable the debanding algorithm. This greatly reduces the amount of visible
banding, blocking and other quantization artifacts, at the expense of

View File

@ -455,6 +455,7 @@ const struct m_sub_options gl_video_conf = {
{"video", BLEND_SUBS_VIDEO})},
{"glsl-shaders", OPT_PATHLIST(user_shaders), .flags = M_OPT_FILE},
{"glsl-shader", OPT_CLI_ALIAS("glsl-shaders-append")},
{"glsl-shader-opts", OPT_KEYVALUELIST(user_shader_opts)},
{"deband", OPT_FLAG(deband)},
{"deband", OPT_SUBSTRUCT(deband_opts, deband_conf)},
{"sharpen", OPT_FLOAT(unsharp)},

View File

@ -162,6 +162,7 @@ struct gl_video_opts {
float interpolation_threshold;
int blend_subs;
char **user_shaders;
char **user_shader_opts;
int deband;
struct deband_opts *deband_opts;
float unsharp;

View File

@ -1682,6 +1682,62 @@ static void update_lut(struct priv *p, struct user_lut *lut)
talloc_free(lutdata.start);
}
static void update_hook_opts(struct priv *p, char **opts, const char *shaderpath,
const struct pl_hook *hook)
{
if (!opts)
return;
#if PL_API_VER >= 233
const char *basename = mp_basename(shaderpath);
struct bstr shadername;
if (!mp_splitext(basename, &shadername))
shadername = bstr0(basename);
for (int n = 0; opts[n * 2]; n++) {
struct bstr k = bstr0(opts[n * 2 + 0]);
struct bstr v = bstr0(opts[n * 2 + 1]);
int pos;
if ((pos = bstrchr(k, '/')) >= 0) {
if (!bstr_equals(bstr_splice(k, 0, pos), shadername))
continue;
k = bstr_cut(k, pos + 1);
}
for (int i = 0; i < hook->num_parameters; i++) {
const struct pl_hook_par *hp = &hook->parameters[i];
if (!bstr_equals0(k, hp->name) != 0)
continue;
m_option_t opt = {
.name = hp->name,
};
switch (hp->type) {
case PL_VAR_FLOAT:
opt.type = &m_option_type_float;
opt.min = hp->minimum.f;
opt.max = hp->maximum.f;
break;
case PL_VAR_SINT:
opt.type = &m_option_type_int;
opt.min = hp->minimum.i;
opt.max = hp->maximum.i;
break;
case PL_VAR_UINT:
opt.type = &m_option_type_int;
opt.min = MPMIN(hp->minimum.u, INT_MAX);
opt.max = MPMIN(hp->maximum.u, INT_MAX);
break;
}
opt.type->parse(p->log, &opt, k, v, hp->data);
break;
}
}
#endif
}
static void update_render_options(struct vo *vo)
{
struct priv *p = vo->priv;
@ -1808,8 +1864,10 @@ static void update_render_options(struct vo *vo)
const struct pl_hook *hook;
for (int i = 0; opts->user_shaders && opts->user_shaders[i]; i++) {
if ((hook = load_hook(p, opts->user_shaders[i])))
if ((hook = load_hook(p, opts->user_shaders[i]))) {
MP_TARRAY_APPEND(p, p->hooks, p->params.num_hooks, hook);
update_hook_opts(p, opts->user_shader_opts, opts->user_shaders[i], hook);
}
}
p->params.hooks = p->hooks;