summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-09-23 22:13:03 +0200
committerwm4 <wm4@nowhere>2015-09-23 22:13:03 +0200
commit17cd6798a69ca2fea1d7e7df692c71172183731f (patch)
tree9708d64e0d52379ad80b489c45c145194033e33a
parentd8d4e188352160a2eac0e004d341ab5c3f997e6e (diff)
downloadmpv-17cd6798a69ca2fea1d7e7df692c71172183731f.tar.bz2
mpv-17cd6798a69ca2fea1d7e7df692c71172183731f.tar.xz
vo_opengl: move shader file caching to video.c
It's just about loading and cachign small files, not does not necessarily have anything to do with shaders. Move it to video.c where it's used.
-rw-r--r--video/out/opengl/utils.c44
-rw-r--r--video/out/opengl/utils.h4
-rw-r--r--video/out/opengl/video.c44
-rw-r--r--video/out/vo_rpi.c2
4 files changed, 44 insertions, 50 deletions
diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c
index b5d33b15c3..ac36bdffc4 100644
--- a/video/out/opengl/utils.c
+++ b/video/out/opengl/utils.c
@@ -28,7 +28,6 @@
#include <stdarg.h>
#include <assert.h>
-#include "stream/stream.h"
#include "common/common.h"
#include "utils.h"
@@ -465,7 +464,6 @@ void gl_set_debug_logger(GL *gl, struct mp_log *log)
#define SC_ENTRIES 16
#define SC_UNIFORM_ENTRIES 20
-#define SC_FILE_ENTRIES 10
enum uniform_type {
UT_invalid,
@@ -486,11 +484,6 @@ struct sc_uniform {
} v;
};
-struct sc_file {
- char *path;
- char *body;
-};
-
struct sc_entry {
GLuint gl_shader;
// the following fields define the shader's contents
@@ -501,7 +494,6 @@ struct sc_entry {
struct gl_shader_cache {
GL *gl;
struct mp_log *log;
- struct mpv_global *global;
// this is modified during use (gl_sc_add() etc.)
char *text;
@@ -513,19 +505,14 @@ struct gl_shader_cache {
struct sc_uniform uniforms[SC_UNIFORM_ENTRIES];
int num_uniforms;
-
- struct sc_file files[SC_FILE_ENTRIES];
- int num_files;
};
-struct gl_shader_cache *gl_sc_create(GL *gl, struct mp_log *log,
- struct mpv_global *global)
+struct gl_shader_cache *gl_sc_create(GL *gl, struct mp_log *log)
{
struct gl_shader_cache *sc = talloc_ptrtype(NULL, sc);
*sc = (struct gl_shader_cache){
.gl = gl,
.log = log,
- .global = global,
.text = talloc_strdup(sc, ""),
.header_text = talloc_strdup(sc, ""),
};
@@ -586,35 +573,6 @@ void gl_sc_haddf(struct gl_shader_cache *sc, const char *textf, ...)
va_end(ap);
}
-const char *gl_sc_loadfile(struct gl_shader_cache *sc, const char *path)
-{
- if (!path || !path[0] || !sc->global)
- return NULL;
- for (int n = 0; n < sc->num_files; n++) {
- if (strcmp(sc->files[n].path, path) == 0)
- return sc->files[n].body;
- }
- // not found -> load it
- if (sc->num_files == SC_FILE_ENTRIES) {
- // empty cache when it overflows
- for (int n = 0; n < sc->num_files; n++) {
- talloc_free(sc->files[n].path);
- talloc_free(sc->files[n].body);
- }
- sc->num_files = 0;
- }
- struct bstr s = stream_read_file(path, sc, sc->global, 100000); // 100 kB
- if (s.len) {
- struct sc_file *new = &sc->files[sc->num_files++];
- *new = (struct sc_file) {
- .path = talloc_strdup(sc, path),
- .body = s.start
- };
- return new->body;
- }
- return NULL;
-}
-
static struct sc_uniform *find_uniform(struct gl_shader_cache *sc,
const char *name)
{
diff --git a/video/out/opengl/utils.h b/video/out/opengl/utils.h
index 75cedd6efe..ffcaa4da0f 100644
--- a/video/out/opengl/utils.h
+++ b/video/out/opengl/utils.h
@@ -121,14 +121,12 @@ void gl_set_debug_logger(GL *gl, struct mp_log *log);
struct gl_shader_cache;
-struct gl_shader_cache *gl_sc_create(GL *gl, struct mp_log *log,
- struct mpv_global *global);
+struct gl_shader_cache *gl_sc_create(GL *gl, struct mp_log *log);
void gl_sc_destroy(struct gl_shader_cache *sc);
void gl_sc_add(struct gl_shader_cache *sc, const char *text);
void gl_sc_addf(struct gl_shader_cache *sc, const char *textf, ...);
void gl_sc_hadd(struct gl_shader_cache *sc, const char *text);
void gl_sc_haddf(struct gl_shader_cache *sc, const char *textf, ...);
-const char *gl_sc_loadfile(struct gl_shader_cache *sc, const char *path);
void gl_sc_uniform_sampler(struct gl_shader_cache *sc, char *name, GLenum target,
int unit);
void gl_sc_uniform_f(struct gl_shader_cache *sc, char *name, GLfloat f);
diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c
index 8d6776ce0e..45528d138a 100644
--- a/video/out/opengl/video.c
+++ b/video/out/opengl/video.c
@@ -37,6 +37,7 @@
#include "utils.h"
#include "hwdec.h"
#include "osd.h"
+#include "stream/stream.h"
#include "video_shaders.h"
#include "video/out/filter_kernels.h"
#include "video/out/aspect.h"
@@ -118,6 +119,11 @@ struct src_tex {
struct mp_rect_f src;
};
+struct cached_file {
+ char *path;
+ char *body;
+};
+
struct gl_video {
GL *gl;
@@ -197,6 +203,9 @@ struct gl_video {
int last_dither_matrix_size;
float *last_dither_matrix;
+ struct cached_file files[10];
+ int num_files;
+
struct gl_hwdec *hwdec;
bool hwdec_active;
};
@@ -472,6 +481,35 @@ static const struct fmt_entry *find_tex_format(GL *gl, int bytes_per_comp,
return &fmts[n_channels - 1 + (bytes_per_comp - 1) * 4];
}
+static const char *load_cached_file(struct gl_video *p, const char *path)
+{
+ if (!path || !path[0])
+ return NULL;
+ for (int n = 0; n < p->num_files; n++) {
+ if (strcmp(p->files[n].path, path) == 0)
+ return p->files[n].body;
+ }
+ // not found -> load it
+ if (p->num_files == MP_ARRAY_SIZE(p->files)) {
+ // empty cache when it overflows
+ for (int n = 0; n < p->num_files; n++) {
+ talloc_free(p->files[n].path);
+ talloc_free(p->files[n].body);
+ }
+ p->num_files = 0;
+ }
+ struct bstr s = stream_read_file(path, p, p->global, 100000); // 100 kB
+ if (s.len) {
+ struct cached_file *new = &p->files[p->num_files++];
+ *new = (struct cached_file) {
+ .path = talloc_strdup(p, path),
+ .body = s.start
+ };
+ return new->body;
+ }
+ return NULL;
+}
+
static void debug_check_gl(struct gl_video *p, const char *msg)
{
if (p->gl_debug)
@@ -868,7 +906,7 @@ static bool apply_shaders(struct gl_video *p, char **shaders,
bool success = false;
int tex = 0;
for (int n = 0; shaders[n]; n++) {
- const char *body = gl_sc_loadfile(p->sc, shaders[n]);
+ const char *body = load_cached_file(p, shaders[n]);
if (!body)
continue;
finish_pass_fbo(p, &textures[tex], w, h, tex_num, 0);
@@ -1067,7 +1105,7 @@ static void pass_sample(struct gl_video *p, int src_tex, struct scaler *scaler,
} else if (strcmp(name, "oversample") == 0) {
pass_sample_oversample(p->sc, scaler, w, h);
} else if (strcmp(name, "custom") == 0) {
- const char *body = gl_sc_loadfile(p->sc, p->opts.scale_shader);
+ const char *body = load_cached_file(p, p->opts.scale_shader);
if (body) {
load_shader(p, body);
GLSLF("// custom scale-shader\n");
@@ -2390,7 +2428,7 @@ struct gl_video *gl_video_init(GL *gl, struct mp_log *log, struct mpv_global *g)
.gl_target = GL_TEXTURE_2D,
.texture_16bit_depth = 16,
.scaler = {{.index = 0}, {.index = 1}, {.index = 2}, {.index = 3}},
- .sc = gl_sc_create(gl, log, g),
+ .sc = gl_sc_create(gl, log),
};
gl_video_set_debug(p, true);
init_gl(p);
diff --git a/video/out/vo_rpi.c b/video/out/vo_rpi.c
index 3c79797ff0..db65cead27 100644
--- a/video/out/vo_rpi.c
+++ b/video/out/vo_rpi.c
@@ -258,7 +258,7 @@ static int update_display_size(struct vo *vo)
MP_FATAL(vo, "EGL/GLES initialization for OSD renderer failed.\n");
return -1;
}
- p->sc = gl_sc_create(p->egl.gl, vo->log, vo->global),
+ p->sc = gl_sc_create(p->egl.gl, vo->log),
p->osd = mpgl_osd_init(p->egl.gl, vo->log, vo->osd);
p->osd_change_counter = -1; // force initial overlay rendering