Repository navigation
vo_gpu{,_next}: drop cached user shaders that leave glsl-shaders - #18920
Open
jdotcollins wants to merge 1 commit into
Open
jdotcollins wants to merge 1 commit into
jdotcollins wants to merge 1 commit into
Conversation
Both renderers cache the contents of every file ever listed in --glsl-shaders, keyed by the path string, until the renderer is destroyed. Editing a shader and setting the list again therefore keeps using the old text, even after removing the shader and adding it back. On vo=gpu-next a shader that failed to parse also stays failed under its path until the renderer is recreated, even after the file was fixed. The cache also grows with every path that was ever loaded, which matters for scripts that load edited copies under new names. Cache entries whose path is no longer in the list are now dropped when the list is applied, after the hooks were rebuilt from the new list. Removing a shader and adding it again (for example with 'change-list glsl-shaders toggle') now reads the file again; shaders that stay in the list keep their cached contents, as before. Fixes mpv-player#18919.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18919.
Both renderers cache user shader files by path for the lifetime of the renderer and never drop an entry, so an edited shader is not read again even after it is removed from
glsl-shadersand added back, a shader that failed to parse is never retried under the same path, and the cache grows with every path ever listed.This drops the cache entries whose path is no longer in the list, each time the list is applied:
evict_unused_files()runs at the end ofgl_video_setup_hooks(), afterload_user_shaders()rebuilt the hooks from the new list. The hooks point into the cached file contents, so eviction has to come after the rebuild; at that point no hook refers to an evicted file.evict_unused_hooks()runs inupdate_render_options()afterpars->params.hookswas rebuilt, and destroys the hooks of paths that left the list withpl_mpv_user_shader_destroy(). libplacebo's renderer does not keep hook pointers between calls (the frame cache stores a hash of the params and clearsparams.hooks; disabled hooks are tracked by signature), and the option update runs on the VO thread, so no render is in progress. GPU resources owned by the hook are reference counted by the backends (e.g.vk_tex_deref), so destroying them while the GPU still uses them is deferred.Shaders that stay in the list keep their cached contents, so nothing changes for normal use. The
--glsl-shadersdocs now say when a file is read.Tested on Windows 11 with a CI build of this branch (
x86_64-w64-mingw32-full),--gpu-api=d3d11, against a greylavfiframe, reading the centre pixel ofscreenshot-raw video:* 0.5loaded* 1.0, removed and added againSoak test with the same build, both renderers: 550 changes of
glsl-shaders30 ms apart, 400 during playback with--interpolation --video-sync=display-resampleand 150 while paused, cycling through a shader with a//!TEXTURE, a two-pass shader with//!SAVE, a//!PARAMshader whose file is rewritten every 7th change, and one that fails to parse. No crash or error.Not tested:
--gpu-api=vulkanand OpenGL (Vulkan fails to create a swapchain on this machine even with a release build), Linux and macOS at runtime (the CI builds pass there).Prepared with Claude Opus 5.5 in Claude Code.