Skip to content

Commit 33136c2

Browse files
haasnNiklas Haas
authored andcommitted
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.
1 parent ac39661 commit 33136c2

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

DOCS/interface-changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Interface changes
4949
- deprecate `--gamma-factor`
5050
- deprecate `--gamma-auto`
5151
- remove `--vulkan-disable-events`
52+
- add `--glsl-shader-opts`
5253
--- mpv 0.34.0 ---
5354
- deprecate selecting by card number with `--drm-connector`, add
5455
`--drm-device` which can be used instead

DOCS/man/options.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5857,6 +5857,13 @@ them.
58575857
``--glsl-shader=<file>``
58585858
CLI/config file only alias for ``--glsl-shaders-append``.
58595859

5860+
``--glsl-shader-opts=param1=value1,param2=value2,...``
5861+
Specifies the options to use for tunable shader parameters. You can target
5862+
specific named shaders by prefixing the shader name with a ``/``, e.g.
5863+
``shader/param=value``. Without a prefix, parameters affect all shaders.
5864+
The shader name is the base part of the shader filename, without the
5865+
extension. (``--vo=gpu-next`` only)
5866+
58605867
``--deband``
58615868
Enable the debanding algorithm. This greatly reduces the amount of visible
58625869
banding, blocking and other quantization artifacts, at the expense of

video/out/gpu/video.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ const struct m_sub_options gl_video_conf = {
455455
{"video", BLEND_SUBS_VIDEO})},
456456
{"glsl-shaders", OPT_PATHLIST(user_shaders), .flags = M_OPT_FILE},
457457
{"glsl-shader", OPT_CLI_ALIAS("glsl-shaders-append")},
458+
{"glsl-shader-opts", OPT_KEYVALUELIST(user_shader_opts)},
458459
{"deband", OPT_FLAG(deband)},
459460
{"deband", OPT_SUBSTRUCT(deband_opts, deband_conf)},
460461
{"sharpen", OPT_FLOAT(unsharp)},

video/out/gpu/video.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct gl_video_opts {
162162
float interpolation_threshold;
163163
int blend_subs;
164164
char **user_shaders;
165+
char **user_shader_opts;
165166
int deband;
166167
struct deband_opts *deband_opts;
167168
float unsharp;

video/out/vo_gpu_next.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,62 @@ static void update_lut(struct priv *p, struct user_lut *lut)
16821682
talloc_free(lutdata.start);
16831683
}
16841684

1685+
static void update_hook_opts(struct priv *p, char **opts, const char *shaderpath,
1686+
const struct pl_hook *hook)
1687+
{
1688+
if (!opts)
1689+
return;
1690+
1691+
#if PL_API_VER >= 233
1692+
const char *basename = mp_basename(shaderpath);
1693+
struct bstr shadername;
1694+
if (!mp_splitext(basename, &shadername))
1695+
shadername = bstr0(basename);
1696+
1697+
for (int n = 0; opts[n * 2]; n++) {
1698+
struct bstr k = bstr0(opts[n * 2 + 0]);
1699+
struct bstr v = bstr0(opts[n * 2 + 1]);
1700+
int pos;
1701+
if ((pos = bstrchr(k, '/')) >= 0) {
1702+
if (!bstr_equals(bstr_splice(k, 0, pos), shadername))
1703+
continue;
1704+
k = bstr_cut(k, pos + 1);
1705+
}
1706+
1707+
for (int i = 0; i < hook->num_parameters; i++) {
1708+
const struct pl_hook_par *hp = &hook->parameters[i];
1709+
if (!bstr_equals0(k, hp->name) != 0)
1710+
continue;
1711+
1712+
m_option_t opt = {
1713+
.name = hp->name,
1714+
};
1715+
1716+
switch (hp->type) {
1717+
case PL_VAR_FLOAT:
1718+
opt.type = &m_option_type_float;
1719+
opt.min = hp->minimum.f;
1720+
opt.max = hp->maximum.f;
1721+
break;
1722+
case PL_VAR_SINT:
1723+
opt.type = &m_option_type_int;
1724+
opt.min = hp->minimum.i;
1725+
opt.max = hp->maximum.i;
1726+
break;
1727+
case PL_VAR_UINT:
1728+
opt.type = &m_option_type_int;
1729+
opt.min = MPMIN(hp->minimum.u, INT_MAX);
1730+
opt.max = MPMIN(hp->maximum.u, INT_MAX);
1731+
break;
1732+
}
1733+
1734+
opt.type->parse(p->log, &opt, k, v, hp->data);
1735+
break;
1736+
}
1737+
}
1738+
#endif
1739+
}
1740+
16851741
static void update_render_options(struct vo *vo)
16861742
{
16871743
struct priv *p = vo->priv;
@@ -1808,8 +1864,10 @@ static void update_render_options(struct vo *vo)
18081864

18091865
const struct pl_hook *hook;
18101866
for (int i = 0; opts->user_shaders && opts->user_shaders[i]; i++) {
1811-
if ((hook = load_hook(p, opts->user_shaders[i])))
1867+
if ((hook = load_hook(p, opts->user_shaders[i]))) {
18121868
MP_TARRAY_APPEND(p, p->hooks, p->params.num_hooks, hook);
1869+
update_hook_opts(p, opts->user_shader_opts, opts->user_shaders[i], hook);
1870+
}
18131871
}
18141872

18151873
p->params.hooks = p->hooks;

0 commit comments

Comments
 (0)