From 7c3d78fd82d4d1e1a0b15284386d39b4014cb7d1 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Thu, 21 Apr 2016 01:33:13 +0200 Subject: vo_opengl: support external user hooks This allows users to add their own near-arbitrary hooks to the vo_opengl processing pipeline, greatly enhancing the flexibility of user shaders. This enables, among other things, user shaders such as CrossBilateral, SuperRes, LumaSharpen and many more. To make parsing the user shaders easier, shaders are now loaded as bstrs, and the hooks are set up during video reconfig instead of on every single frame. --- video/out/opengl/user_shaders.h | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 video/out/opengl/user_shaders.h (limited to 'video/out/opengl/user_shaders.h') diff --git a/video/out/opengl/user_shaders.h b/video/out/opengl/user_shaders.h new file mode 100644 index 0000000000..051dcaaa58 --- /dev/null +++ b/video/out/opengl/user_shaders.h @@ -0,0 +1,42 @@ +/* + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with mpv. If not, see . + */ + +#ifndef MP_GL_USER_SHADERS_H +#define MP_GL_USER_SHADERS_H + +#include "common.h" +#include "utils.h" + +#define SHADER_API 1 +#define SHADER_MAX_HOOKS 16 +#define SHADER_MAX_BINDS 6 + +struct gl_user_shader { + struct bstr hook_tex[SHADER_MAX_HOOKS]; + struct bstr bind_tex[SHADER_MAX_BINDS]; + struct bstr save_tex; + struct bstr pass_body; + struct gl_transform transform; + int components; +}; + +// Parse the next shader pass from 'body'. Returns false if the end of the +// string was reached +bool parse_user_shader_pass(struct mp_log *log, struct bstr *body, + struct gl_user_shader *out); + +#endif -- cgit v1.2.3 From 034faaa9d818bd8c1c52c879e383b8e7350d3df5 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Thu, 12 May 2016 03:34:47 +0200 Subject: vo_opengl: use RPN expressions for user hook sizes This replaces the previous TRANSFORM by WIDTH, HEIGHT and OFFSET where WIDTH and HEIGHT are RPN expressions. This allows for more fine-grained control over the output size, and also makes sure that overwriting existing textures works more cleanly. (Also add some more useful bstr functions) --- video/out/opengl/user_shaders.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'video/out/opengl/user_shaders.h') diff --git a/video/out/opengl/user_shaders.h b/video/out/opengl/user_shaders.h index 051dcaaa58..0e32f53c57 100644 --- a/video/out/opengl/user_shaders.h +++ b/video/out/opengl/user_shaders.h @@ -24,13 +24,40 @@ #define SHADER_API 1 #define SHADER_MAX_HOOKS 16 #define SHADER_MAX_BINDS 6 +#define MAX_SZEXP_SIZE 32 + +enum szexp_op { + SZEXP_OP_ADD, + SZEXP_OP_SUB, + SZEXP_OP_MUL, + SZEXP_OP_DIV, +}; + +enum szexp_tag { + SZEXP_END = 0, // End of an RPN expression + SZEXP_CONST, // Push a constant value onto the stack + SZEXP_VAR_W, // Get the width/height of a named texture (variable) + SZEXP_VAR_H, + SZEXP_OP2, // Pop two elements and push the result of a dyadic operation +} tag; + +struct szexp { + enum szexp_tag tag; + union { + float cval; + struct bstr varname; + enum szexp_op op; + } val; +}; struct gl_user_shader { struct bstr hook_tex[SHADER_MAX_HOOKS]; struct bstr bind_tex[SHADER_MAX_BINDS]; struct bstr save_tex; struct bstr pass_body; - struct gl_transform transform; + struct gl_transform offset; + struct szexp width[MAX_SZEXP_SIZE]; + struct szexp height[MAX_SZEXP_SIZE]; int components; }; -- cgit v1.2.3 From 56ed5bf1c7b14aed87b273e9a989fa88e4d332ad Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 16 May 2016 12:41:55 +0200 Subject: vo_opengl: remove unused global variable ? --- video/out/opengl/user_shaders.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'video/out/opengl/user_shaders.h') diff --git a/video/out/opengl/user_shaders.h b/video/out/opengl/user_shaders.h index 0e32f53c57..3a651164e3 100644 --- a/video/out/opengl/user_shaders.h +++ b/video/out/opengl/user_shaders.h @@ -39,7 +39,7 @@ enum szexp_tag { SZEXP_VAR_W, // Get the width/height of a named texture (variable) SZEXP_VAR_H, SZEXP_OP2, // Pop two elements and push the result of a dyadic operation -} tag; +}; struct szexp { enum szexp_tag tag; -- cgit v1.2.3 From 54c48bd80120a3085e6d23f7cf6124b0657436e7 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 8 Jun 2016 15:05:28 +0200 Subject: vo_opengl: make user hook passes optional User hooks can now use an extra WHEN expression to specify when the shader should be run. For example, this can be used to only run a chroma scaling shader `WHEN CHROMA.w LUMA.w <`. There's a slight semantics change to user shaders: When trying to bind a texture that does not exist, a shader will now be silently skipped (similar to when the condition is false) instead of generating an error. This allows shader stages to depend on an optional earlier stage without having to copy/paste the same condition everywhere. (In other words: there's an implicit condition on all of the bound textures existing) --- video/out/opengl/user_shaders.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'video/out/opengl/user_shaders.h') diff --git a/video/out/opengl/user_shaders.h b/video/out/opengl/user_shaders.h index 3a651164e3..b8c287b6bd 100644 --- a/video/out/opengl/user_shaders.h +++ b/video/out/opengl/user_shaders.h @@ -31,6 +31,9 @@ enum szexp_op { SZEXP_OP_SUB, SZEXP_OP_MUL, SZEXP_OP_DIV, + SZEXP_OP_NOT, + SZEXP_OP_GT, + SZEXP_OP_LT, }; enum szexp_tag { @@ -39,6 +42,7 @@ enum szexp_tag { SZEXP_VAR_W, // Get the width/height of a named texture (variable) SZEXP_VAR_H, SZEXP_OP2, // Pop two elements and push the result of a dyadic operation + SZEXP_OP1, // Pop one element and push the result of a monadic operation }; struct szexp { @@ -58,6 +62,7 @@ struct gl_user_shader { struct gl_transform offset; struct szexp width[MAX_SZEXP_SIZE]; struct szexp height[MAX_SZEXP_SIZE]; + struct szexp cond[MAX_SZEXP_SIZE]; int components; }; -- cgit v1.2.3