summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.dev>2022-11-03 16:16:59 +0100
committerNiklas Haas <github-daiK1o@haasn.dev>2022-11-11 13:58:35 +0100
commit33136c276c550a3a38bb36f512718a5fd2fd82ee (patch)
tree1b0491a3617cf147807b4a02e7c85665418551e5 /video
parentac3966184bc3ab2f475c8b28d4e5d749d07c0177 (diff)
downloadmpv-33136c276c550a3a38bb36f512718a5fd2fd82ee.tar.bz2
mpv-33136c276c550a3a38bb36f512718a5fd2fd82ee.tar.xz
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.
Diffstat (limited to 'video')
-rw-r--r--video/out/gpu/video.c1
-rw-r--r--video/out/gpu/video.h1
-rw-r--r--video/out/vo_gpu_next.c60
3 files changed, 61 insertions, 1 deletions
diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c
index 65a696cc38..abe5e9333c 100644
--- a/video/out/gpu/video.c
+++ b/video/out/gpu/video.c
@@ -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)},
diff --git a/video/out/gpu/video.h b/video/out/gpu/video.h
index 7637710fa7..30abd972f9 100644
--- a/video/out/gpu/video.h
+++ b/video/out/gpu/video.h
@@ -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;
diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c
index bbce4f2065..0536abcea1 100644
--- a/video/out/vo_gpu_next.c
+++ b/video/out/vo_gpu_next.c
@@ -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;