diff options
author | wm4 <wm4@nowhere> | 2014-12-08 16:04:08 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-12-08 16:24:38 +0100 |
commit | 9c484cb080330d131e5a0b0049492f3583f463ff (patch) | |
tree | 7154bd7710f1b39488ea99aeec8435347673094e /video/out/gl_video.c | |
parent | 4a95be014b8875567e8e800a6075d876ba824081 (diff) | |
download | mpv-9c484cb080330d131e5a0b0049492f3583f463ff.tar.bz2 mpv-9c484cb080330d131e5a0b0049492f3583f463ff.tar.xz |
vo_opengl: refactor: instantiate scaler functions at runtime
Before this commit, the convolution scaler shader functions were pre-
instantiated in the shader file. For every filter size, a corresponding
function (with the filter size as suffix) had to be present.
Change this, and make the C code emit the necessary bits.
This means the shader code is much reduced. (Although hopefully it
doesn't make shader compilation faster - it would require a really dumb
compiler if it spends its time on dead code.)
It also makes it more flexible, which is the main goal.
The DEF_SCALER0 stuff is needed because the C code writes the header of
the shader, at a point where scaler macros are not defined yet.
Diffstat (limited to 'video/out/gl_video.c')
-rw-r--r-- | video/out/gl_video.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/video/out/gl_video.c b/video/out/gl_video.c index 124d949a03..cb32600395 100644 --- a/video/out/gl_video.c +++ b/video/out/gl_video.c @@ -835,27 +835,43 @@ static void shader_def_opt(char **shader, const char *name, bool b) shader_def(shader, name, "1"); } +#define APPENDF(s_ptr, ...) \ + *(s_ptr) = talloc_asprintf_append(*(s_ptr), __VA_ARGS__) + static void shader_setup_scaler(char **shader, struct scaler *scaler, int pass) { - const char *target = scaler->index == 0 ? "SAMPLE_L" : "SAMPLE_C"; + int unit = scaler->index; + const char *target = unit == 0 ? "SAMPLE_L" : "SAMPLE_C"; if (!scaler->kernel) { - *shader = talloc_asprintf_append(*shader, "#define %s(p0, p1, p2) " - "sample_%s(p0, p1, p2, filter_param1_%c)\n", - target, scaler->name, "lc"[scaler->index]); + APPENDF(shader, "#define %s(p0, p1, p2) " + "sample_%s(p0, p1, p2, filter_param1_%c)\n", + target, scaler->name, "lc"[unit]); } else { int size = scaler->kernel->size; + const char *lut_tex = scaler->lut_name; + char name[40]; + snprintf(name, sizeof(name), "sample_scaler%d", unit); + APPENDF(shader, "#define DEF_SCALER%d \\\n", unit); + char lut_fn[40]; + if (size < 8) { + snprintf(lut_fn, sizeof(lut_fn), "weights%d", size); + } else { + snprintf(lut_fn, sizeof(lut_fn), "weights_scaler%d", unit); + APPENDF(shader, " WEIGHTS_N(%s, %d) \\\n ", lut_fn, size); + } if (pass != -1) { // The direction/pass assignment is rather arbitrary, but fixed in // other parts of the code (like FBO setup). const char *direction = pass == 0 ? "0, 1" : "1, 0"; - *shader = talloc_asprintf_append(*shader, "#define %s(p0, p1, p2) " - "sample_convolution_sep%d(vec2(%s), %s, p0, p1, p2)\n", - target, size, direction, scaler->lut_name); + // SAMPLE_CONVOLUTION_SEP_N(NAME, DIR, N, LUT, WEIGHTS_FUNC) + APPENDF(shader, "SAMPLE_CONVOLUTION_SEP_N(%s, vec2(%s), %d, %s, %s)\n", + name, direction, size, lut_tex, lut_fn); } else { - *shader = talloc_asprintf_append(*shader, "#define %s(p0, p1, p2) " - "sample_convolution%d(%s, p0, p1, p2)\n", - target, size, scaler->lut_name); + // SAMPLE_CONVOLUTION_N(NAME, N, LUT, WEIGHTS_FUNC) + APPENDF(shader, "SAMPLE_CONVOLUTION_N(%s, %d, %s, %s)\n", + name, size, lut_tex, lut_fn); } + APPENDF(shader, "#define %s %s\n", target, name); } } |