Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6653,6 +6653,10 @@ them.
and overwrites the internal list with it. The latter is a path list option
(see `List Options`_ for details).

A shader file is read when it is added to the list. A file that stays in
the list is not read again; to load an edited file, remove it from the
list and add it again.

.. warning::

The syntax is not stable yet and may change any time.
Expand Down
26 changes: 26 additions & 0 deletions video/out/gpu/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,31 @@ static void load_user_shaders(struct gl_video *p, char **shaders)
}
}

// Drop cached shader files that are no longer in the list, so that removing a
// shader and adding it again reads the file again, and so that the cache does
// not grow without bound. Must run after the hooks were rebuilt from the list,
// because the hooks point into the cached file contents.
static void evict_unused_files(struct gl_video *p, char **shaders)
{
int kept = 0;
for (int n = 0; n < p->num_files; n++) {
bool used = false;
for (int i = 0; shaders && shaders[i]; i++) {
if (strcmp(p->files[n].path, shaders[i]) == 0) {
used = true;
break;
}
}
if (used) {
p->files[kept++] = p->files[n];
} else {
talloc_free(p->files[n].path);
talloc_free(p->files[n].body.start);
}
}
p->num_files = kept;
}

static void gl_video_setup_hooks(struct gl_video *p)
{
gl_video_reset_hooks(p);
Expand All @@ -2321,6 +2346,7 @@ static void gl_video_setup_hooks(struct gl_video *p)
}

load_user_shaders(p, p->opts.user_shaders);
evict_unused_files(p, p->opts.user_shaders);
}

// sample from video textures, set "color" variable to yuv value
Expand Down
26 changes: 26 additions & 0 deletions video/out/gpu_next/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,31 @@ static const struct pl_hook *load_hook(struct mppl_video *p, const char *path)
return hook;
}

// Destroy cached hooks whose shader is no longer in the list, so that removing
// a shader and adding it again reads the file again (also after it failed to
// parse), and so that the cache does not grow without bound. Must run after the
// renderer's hook list was rebuilt from the current list.
static void evict_unused_hooks(struct mppl_video *p, char **shaders)
{
int kept = 0;
for (int i = 0; i < p->num_user_hooks; i++) {
bool used = false;
for (int n = 0; shaders && shaders[n]; n++) {
if (strcmp(p->user_hooks[i].path, shaders[n]) == 0) {
used = true;
break;
}
}
if (used) {
p->user_hooks[kept++] = p->user_hooks[i];
} else {
pl_mpv_user_shader_destroy(&p->user_hooks[i].hook);
talloc_free(p->user_hooks[i].path);
}
}
p->num_user_hooks = kept;
}

static void update_icc_opts(struct mppl_video *p, const struct mp_icc_opts *opts)
{
if (!opts)
Expand Down Expand Up @@ -2867,6 +2892,7 @@ static void update_render_options(struct mppl_video *p)
}

pars->params.hooks = p->hooks;
evict_unused_hooks(p, opts->user_shaders);

MP_DBG(p, "Render options updated, flushing renderer cache.\n");
p->flush_cache = p->paused || !p->next_opts->inter_preserve;
Expand Down
Loading