From ce05413a87ee24e706bf3cc044bf7eec422d034a Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Fri, 2 Sep 2016 00:08:43 +0200 Subject: vo_opengl: remove pre/post/scale-shaders Deprecated in favor of user-shaders, which are functionally equivalent but superior. (Except in the case of scaler-shader, which has no direct replacement, but it turned out to be a very unpopular feature either way - most custom scalers don't fit into the mpv kernel infrastructure and are therefore implemented as user shaders either way) Signed-off-by: wm4 --- DOCS/interface-changes.rst | 2 ++ DOCS/man/vo.rst | 78 +++++++++------------------------------------- video/out/opengl/video.c | 70 ++--------------------------------------- video/out/opengl/video.h | 3 -- 4 files changed, 20 insertions(+), 133 deletions(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index 9bfbdcf3b0..f2b8b19514 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -35,6 +35,8 @@ Interface changes - "idle" -> "idle-active" the old names are deprecated - remove deprecated "hwdec-active" and "hwdec-detected" properties + - remove "pre-shaders", "post-shaders" and "scale-shader": deprecated + in favor of "user-shaders" --- mpv 0.20.0 --- - add --image-display-duration option - this also means that image duration is not influenced by --mf-fps anymore in the general case (this is an diff --git a/DOCS/man/vo.rst b/DOCS/man/vo.rst index dda3ea61cd..2c7b995843 100644 --- a/DOCS/man/vo.rst +++ b/DOCS/man/vo.rst @@ -584,68 +584,9 @@ Available video output drivers are: better than without it) since it will extend the size to match only the milder of the scale factors between the axes. - ``pre-shaders=``, ``post-shaders=``, ``scale-shader=`` - Custom GLSL fragment shaders. - - pre-shaders (list) - These get applied after conversion to RGB and before linearization - and upscaling. Operates on non-linear RGB (same as input). This is - the best place to put things like sharpen filters. - scale-shader - This gets used instead of scale/cscale when those options are set - to ``custom``. The colorspace it operates on depends on the values - of ``linear-scaling`` and ``sigmoid-upscaling``, so no assumptions - should be made here. - post-shaders (list) - These get applied after upscaling and subtitle blending (when - ``blend-subtitles`` is enabled), but before color management. - Operates on linear RGB if ``linear-scaling`` is in effect, - otherwise non-linear RGB. This is the best place for colorspace - transformations (eg. saturation mapping). - - These files must define a function with the following signature:: - - vec4 sample_pixel(sampler2D tex, vec2 pos, vec2 tex_size) - - (If there is no string ``sample_pixel`` in the shader script, it will - use ``sample`` instead. This is a compatibility hack for older shader - scripts, and is deprecated.) - - The meanings of the parameters are as follows: - - sampler2D tex - The source texture for the shader. - vec2 pos - The position to be sampled, in coordinate space [0-1]. - vec2 tex_size - The size of the texture, in pixels. This may differ from image_size, - eg. for subsampled content or for post-shaders. - - In addition to these parameters, the following uniforms are also - globally available: - - float random - A random number in the range [0-1], different per frame. - int frame - A simple count of frames rendered, increases by one per frame and - never resets (regardless of seeks). - vec2 image_size - The size in pixels of the input image. - vec2 target_size - The size in pixels of the visible part of the scaled (and possibly - cropped) image. - - For example, a shader that inverts the colors could look like this:: - - vec4 sample(sampler2D tex, vec2 pos, vec2 tex_size) - { - vec4 color = texture(tex, pos); - return vec4(1.0 - color.rgb, color.a); - } - ``user-shaders=`` - Custom GLSL hooks. These are similar to ``post-shaders`` etc., but more - flexible: They can be injected at almost arbitrary points in the + Custom GLSL hooks. These are a flexible way to add custom fragment + shaders, which can be injected at almost arbitrary points in the rendering pipeline, and access all previous intermediate textures. .. admonition:: Warning @@ -738,8 +679,19 @@ Available video output drivers are: The raw bound texture itself. The use of this should be avoided unless absolutely necessary. - In addition, the global uniforms described in ``post-shaders`` are - also available. + In addition to these parameters, the following uniforms are also + globally available: + + float random + A random number in the range [0-1], different per frame. + int frame + A simple count of frames rendered, increases by one per frame and + never resets (regardless of seeks). + vec2 image_size + The size in pixels of the input image. + vec2 target_size + The size in pixels of the visible part of the scaled (and possibly + cropped) image. Internally, vo_opengl may generate any number of the following textures. Whenever a texture is rendered and saved by vo_opengl, all of diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 8e419a1bd5..658153372e 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -54,7 +54,6 @@ static const char *const fixed_scale_filters[] = { "bilinear", "bicubic_fast", "oversample", - "custom", NULL }; static const char *const fixed_tscale_filters[] = { @@ -268,7 +267,6 @@ struct gl_video { bool hwdec_active; bool dsi_warned; - bool custom_shader_fn_warned; bool broken_frame; // temporary error state }; @@ -436,9 +434,6 @@ const struct m_sub_options gl_video_conf = { ({"no", BLEND_SUBS_NO}, {"yes", BLEND_SUBS_YES}, {"video", BLEND_SUBS_VIDEO})), - OPT_STRING("scale-shader", scale_shader, 0), - OPT_STRINGLIST("pre-shaders", pre_shaders, 0), - OPT_STRINGLIST("post-shaders", post_shaders, 0), OPT_STRINGLIST("user-shaders", user_shaders, 0), OPT_FLAG("deband", deband, 0), OPT_SUBSTRUCT("deband", deband_opts, deband_conf, 0), @@ -452,6 +447,9 @@ const struct m_sub_options gl_video_conf = { OPT_REMOVED("srgb", "use target-prim=bt709:target-trc=srgb instead"), OPT_REMOVED("source-shader", "use :deband to enable debanding"), OPT_REMOVED("prescale-luma", "use user shaders for prescaling"), + OPT_REMOVED("scale-shader", "use user-shaders instead"), + OPT_REMOVED("pre-shaders", "use user-shaders instead"), + OPT_REMOVED("post-shaders", "use user-shaders instead"), OPT_REPLACED("lscale", "scale"), OPT_REPLACED("lscale-down", "scale-down"), @@ -1250,19 +1248,6 @@ static void load_shader(struct gl_video *p, struct bstr body) p->dst_rect.y1 - p->dst_rect.y0}); } -static const char *get_custom_shader_fn(struct gl_video *p, const char *body) -{ - if (!p->gl->es && strstr(body, "sample") && !strstr(body, "sample_pixel")) { - if (!p->custom_shader_fn_warned) { - MP_WARN(p, "sample() is deprecated in custom shaders. " - "Use sample_pixel()\n"); - p->custom_shader_fn_warned = true; - } - return "sample"; - } - return "sample_pixel"; -} - // Semantic equality static bool double_seq(double a, double b) { @@ -1455,16 +1440,6 @@ static void pass_sample(struct gl_video *p, struct img_tex tex, pass_sample_bicubic_fast(p->sc); } else if (strcmp(name, "oversample") == 0) { pass_sample_oversample(p->sc, scaler, w, h); - } else if (strcmp(name, "custom") == 0) { - struct bstr body = load_cached_file(p, p->opts.scale_shader); - if (body.start) { - load_shader(p, body); - const char *fn_name = get_custom_shader_fn(p, body.start); - GLSLF("// custom scale-shader\n"); - GLSLF("color = %s(tex, pos, size);\n", fn_name); - } else { - p->opts.scale_shader = NULL; - } } else if (scaler->kernel && scaler->kernel->polar) { pass_sample_polar(p->sc, scaler); } else if (scaler->kernel) { @@ -1538,19 +1513,6 @@ static void unsharp_hook(struct gl_video *p, struct img_tex tex, pass_sample_unsharp(p->sc, p->opts.unsharp); } -static void user_hook_old(struct gl_video *p, struct img_tex tex, - struct gl_transform *trans, void *priv) -{ - const char *body = priv; - assert(body); - - GLSLHF("#define pixel_size HOOKED_pt\n"); - load_shader(p, bstr0(body)); - const char *fn_name = get_custom_shader_fn(p, body); - GLSLF("// custom shader\n"); - GLSLF("color = %s(HOOKED_raw, HOOKED_pos, HOOKED_size);\n", fn_name); -} - struct szexp_ctx { struct gl_video *p; struct img_tex tex; @@ -1627,26 +1589,6 @@ static void user_hook_free(struct tex_hook *hook) talloc_free(hook->priv); } -static void pass_hook_user_shaders_old(struct gl_video *p, char *name, - char **shaders) -{ - assert(name); - if (!shaders) - return; - - for (int n = 0; shaders[n] != NULL; n++) { - char *body = load_cached_file(p, shaders[n]).start; - if (body) { - pass_add_hook(p, (struct tex_hook) { - .hook_tex = name, - .bind_tex = {"HOOKED"}, - .hook = user_hook_old, - .priv = body, - }); - } - } -} - static void pass_hook_user_shaders(struct gl_video *p, char **shaders) { if (!shaders) @@ -1698,8 +1640,6 @@ static void gl_video_setup_hooks(struct gl_video *p) }); } - pass_hook_user_shaders_old(p, "MAIN", p->opts.pre_shaders); - pass_hook_user_shaders_old(p, "SCALED", p->opts.post_shaders); pass_hook_user_shaders(p, p->opts.user_shaders); } @@ -2988,10 +2928,6 @@ static bool check_dumb_mode(struct gl_video *p) return false; } } - if (o->pre_shaders && o->pre_shaders[0]) - return false; - if (o->post_shaders && o->post_shaders[0]) - return false; if (o->user_shaders && o->user_shaders[0]) return false; if (p->use_lut_3d) diff --git a/video/out/opengl/video.h b/video/out/opengl/video.h index 140a4682c8..29300c3312 100644 --- a/video/out/opengl/video.h +++ b/video/out/opengl/video.h @@ -130,9 +130,6 @@ struct gl_video_opts { int interpolation; float interpolation_threshold; int blend_subs; - char *scale_shader; - char **pre_shaders; - char **post_shaders; char **user_shaders; int deband; struct deband_opts *deband_opts; -- cgit v1.2.3