From 4502522a7aee093c923e79a65e4684ea2634af30 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Tue, 2 May 2023 19:42:23 -0500 Subject: player: use XDG_CACHE_HOME by default This adds cache as a possible path for mpv to internally pick (~/.cache/mpv for non-darwin unix-like systems, the usual config directory for everyone else). For gpu shader cache and icc cache, controlling whether or not to write such files is done with the new --gpu-shader-cache and --icc-cache options respectively. Additionally, --cache-on-disk no longer requires explicitly setting the --cache-dir option. The old options, --cache-dir, --gpu-shader-cache-dir, and --icc-cache-dir simply set an override for the directory to save cache files. If unset, then the cache is saved in XDG_CACHE_HOME. --- video/out/gpu/lcms.c | 12 +++++++++--- video/out/gpu/lcms.h | 1 + video/out/gpu/shader_cache.c | 7 ++++++- video/out/gpu/shader_cache.h | 2 +- video/out/gpu/video.c | 4 +++- video/out/gpu/video.h | 1 + 6 files changed, 21 insertions(+), 6 deletions(-) (limited to 'video/out/gpu') diff --git a/video/out/gpu/lcms.c b/video/out/gpu/lcms.c index bbf857d968..be65dc965e 100644 --- a/video/out/gpu/lcms.c +++ b/video/out/gpu/lcms.c @@ -332,7 +332,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d, cmsContext cms = NULL; char *cache_file = NULL; - if (p->opts->cache_dir && p->opts->cache_dir[0]) { + if (p->opts->cache) { // Gamma is included in the header to help uniquely identify it, // because we may change the parameter in the future or make it // customizable, same for the primaries. @@ -352,7 +352,13 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d, av_sha_final(sha, hash); av_free(sha); - char *cache_dir = mp_get_user_path(tmp, p->global, p->opts->cache_dir); + char *cache_dir = p->opts->cache_dir; + if (cache_dir && cache_dir[0]) { + cache_dir = mp_get_user_path(NULL, p->global, cache_dir); + } else { + cache_dir = mp_find_user_file(NULL, p->global, "cache", ""); + } + cache_file = talloc_strdup(tmp, ""); for (int i = 0; i < sizeof(hash); i++) cache_file = talloc_asprintf_append(cache_file, "%02X", hash[i]); @@ -494,13 +500,13 @@ const struct m_sub_options mp_icc_conf = { {"use-embedded-icc-profile", OPT_BOOL(use_embedded)}, {"icc-profile", OPT_STRING(profile), .flags = M_OPT_FILE}, {"icc-profile-auto", OPT_BOOL(profile_auto)}, + {"icc-cache", OPT_BOOL(cache)}, {"icc-cache-dir", OPT_STRING(cache_dir), .flags = M_OPT_FILE}, {"icc-intent", OPT_INT(intent)}, {"icc-force-contrast", OPT_CHOICE(contrast, {"no", 0}, {"inf", -1}), M_RANGE(0, 1000000)}, {"icc-3dlut-size", OPT_STRING_VALIDATE(size_str, validate_3dlut_size_opt)}, {"3dlut-size", OPT_REPLACED("icc-3dlut-size")}, - {"icc-cache", OPT_REMOVED("see icc-cache-dir")}, {"icc-contrast", OPT_REMOVED("see icc-force-contrast")}, {0} }, diff --git a/video/out/gpu/lcms.h b/video/out/gpu/lcms.h index bd4b16175a..442c829333 100644 --- a/video/out/gpu/lcms.h +++ b/video/out/gpu/lcms.h @@ -13,6 +13,7 @@ struct mp_icc_opts { bool use_embedded; char *profile; bool profile_auto; + bool cache; char *cache_dir; char *size_str; int intent; diff --git a/video/out/gpu/shader_cache.c b/video/out/gpu/shader_cache.c index 9eedb1cd07..a046831f80 100644 --- a/video/out/gpu/shader_cache.c +++ b/video/out/gpu/shader_cache.c @@ -557,9 +557,14 @@ static void update_uniform(struct gl_shader_cache *sc, struct sc_entry *e, } } -void gl_sc_set_cache_dir(struct gl_shader_cache *sc, const char *dir) +void gl_sc_set_cache_dir(struct gl_shader_cache *sc, char *dir) { talloc_free(sc->cache_dir); + if (dir && dir[0]) { + dir = mp_get_user_path(NULL, sc->global, dir); + } else { + dir = mp_find_user_file(NULL, sc->global, "cache", ""); + } sc->cache_dir = talloc_strdup(sc, dir); } diff --git a/video/out/gpu/shader_cache.h b/video/out/gpu/shader_cache.h index 3c87513b2b..7c51c7aead 100644 --- a/video/out/gpu/shader_cache.h +++ b/video/out/gpu/shader_cache.h @@ -63,4 +63,4 @@ struct mp_pass_perf gl_sc_dispatch_compute(struct gl_shader_cache *sc, // The application can call this on errors, to reset the current shader. This // is normally done implicitly by gl_sc_dispatch_* void gl_sc_reset(struct gl_shader_cache *sc); -void gl_sc_set_cache_dir(struct gl_shader_cache *sc, const char *dir); +void gl_sc_set_cache_dir(struct gl_shader_cache *sc, char *dir); diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c index cfd864680b..2d16d8435e 100644 --- a/video/out/gpu/video.c +++ b/video/out/gpu/video.c @@ -465,6 +465,7 @@ const struct m_sub_options gl_video_conf = { {"gpu-tex-pad-x", OPT_INT(tex_pad_x), M_RANGE(0, 4096)}, {"gpu-tex-pad-y", OPT_INT(tex_pad_y), M_RANGE(0, 4096)}, {"", OPT_SUBSTRUCT(icc_opts, mp_icc_conf)}, + {"gpu-shader-cache", OPT_BOOL(shader_cache)}, {"gpu-shader-cache-dir", OPT_STRING(shader_cache_dir), .flags = M_OPT_FILE}, {"gpu-hwdec-interop", OPT_STRING_VALIDATE(hwdec_interop, ra_hwdec_validate_opt)}, @@ -4099,7 +4100,8 @@ static void reinit_from_options(struct gl_video *p) check_gl_features(p); uninit_rendering(p); - gl_sc_set_cache_dir(p->sc, p->opts.shader_cache_dir); + if (p->opts.shader_cache) + gl_sc_set_cache_dir(p->sc, p->opts.shader_cache_dir); p->ra->use_pbo = p->opts.pbo; gl_video_setup_hooks(p); reinit_osd(p); diff --git a/video/out/gpu/video.h b/video/out/gpu/video.h index 0ef4618790..5a974f9ee0 100644 --- a/video/out/gpu/video.h +++ b/video/out/gpu/video.h @@ -171,6 +171,7 @@ struct gl_video_opts { float unsharp; int tex_pad_x, tex_pad_y; struct mp_icc_opts *icc_opts; + bool shader_cache; int early_flush; char *shader_cache_dir; char *hwdec_interop; -- cgit v1.2.3