[vlc-commits] [Git][videolan/vlc][master] libplacebo: instance: activate libplacebo internal cache

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Thu Sep 14 08:02:09 UTC 2023



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
db063d7f by Niklas Haas at 2023-09-14T07:41:00+00:00
libplacebo: instance: activate libplacebo internal cache

Requires new enough libplacebo, but speeds up shader recompilation and
3DLUT generation significantly.

- - - - -


2 changed files:

- modules/video_output/libplacebo/instance.c
- modules/video_output/libplacebo/instance.h


Changes:

=====================================
modules/video_output/libplacebo/instance.c
=====================================
@@ -23,11 +23,17 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_configuration.h>
 #include <vlc_modules.h>
+#include <vlc_fs.h>
 
 #include "instance.h"
 #include "utils.h"
 
+// 20 MB is plenty of space to cache all shaders plus several 3DLUTs, while
+// still taking negligible amounts of time to parse on startup (<5ms)
+#define VLC_PL_MAX_CACHE_SIZE (20 << 20)
+
 static int vlc_placebo_start(void *func, bool forced, va_list ap)
 {
     int (*activate)(vlc_placebo_t *, const vout_display_cfg_t *) = func;
@@ -40,6 +46,23 @@ static int vlc_placebo_start(void *func, bool forced, va_list ap)
     return ret;
 }
 
+#if PL_API_VER >= 320
+static FILE *vlc_placebo_OpenCache(const char *mode)
+{
+    char *filename;
+    char *cachedir = config_GetUserDir(VLC_CACHE_DIR);
+    if (!cachedir)
+        return NULL;
+    int ret = asprintf(&filename, "%s" DIR_SEP "libplacebo", cachedir);
+    free(cachedir);
+    if (ret < 0)
+        return NULL;
+    FILE *file = vlc_fopen(filename, mode);
+    free(filename);
+    return file;
+}
+#endif
+
 /**
  * Creates a libplacebo context, and swapchain, tied to a window
  *
@@ -65,6 +88,20 @@ vlc_placebo_t *vlc_placebo_Create(const vout_display_cfg_t *cfg, const char *nam
     if (module == NULL)
         goto delete_log;
 
+#if PL_API_VER >= 320
+    pl->cache = pl_cache_create(pl_cache_params(
+        .log = pl->log,
+        .max_total_size = VLC_PL_MAX_CACHE_SIZE,
+    ));
+    assert(pl->gpu);
+    pl_gpu_set_cache(pl->gpu, pl->cache);
+    FILE *cache = vlc_placebo_OpenCache("rb");
+    if (cache) {
+        pl_cache_load_file(pl->cache, cache);
+        fclose(cache);
+    }
+#endif
+
     return pl;
 
 delete_log:
@@ -81,6 +118,15 @@ void vlc_placebo_Release(vlc_placebo_t *pl)
     if (pl->ops)
         pl->ops->close(pl);
 
+#if PL_API_VER >= 320
+    FILE *cache = vlc_placebo_OpenCache("wb");
+    if (cache) {
+        pl_cache_save_file(pl->cache, cache);
+        fclose(cache);
+    }
+    pl_cache_destroy(&pl->cache);
+#endif
+
     pl_log_destroy(&pl->log);
 
     /* TODO: use vlc_objres_clear */


=====================================
modules/video_output/libplacebo/instance.h
=====================================
@@ -50,6 +50,9 @@ typedef struct vlc_placebo_t
     pl_log log;
     pl_gpu gpu;
     pl_swapchain swapchain;
+#if PL_API_VER >= 320
+    pl_cache cache;
+#endif
 
     const struct vlc_placebo_operations *ops;
 } vlc_placebo_t;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/db063d7f513dde5b95ba8560bb8a0323cded738c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/db063d7f513dde5b95ba8560bb8a0323cded738c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list