mirror of https://github.com/mpv-player/mpv
vo_opengl: support user compute shaders
These are identical to regular fragment shader hooks, but with extra metadata indicating the preferred block size.
This commit is contained in:
parent
f338ec4591
commit
0c84ee01d5
|
@ -4271,6 +4271,17 @@ The following video options are currently all specific to ``--vo=opengl`` and
|
||||||
should be stored in the texture, up to 4 (rgba). By default, this value
|
should be stored in the texture, up to 4 (rgba). By default, this value
|
||||||
is equal to the number of components in HOOKED.
|
is equal to the number of components in HOOKED.
|
||||||
|
|
||||||
|
COMPUTE bw bh
|
||||||
|
Specifies that this shader should be treated as a compute shader, with
|
||||||
|
the block size bw and bh. The compute shader will be dispatched with
|
||||||
|
however many blocks are necessary to completely tile over the output.
|
||||||
|
Compute shaders in mpv are treated similarly to fragment shaders, and
|
||||||
|
are still required to produce an output color. In addition, mpv
|
||||||
|
provides a special function NAME_map(id) to map from the global ID
|
||||||
|
space to the texture coordinates for all bound textures. The only real
|
||||||
|
difference is the fact that you can use shared memory inside compute
|
||||||
|
shaders.
|
||||||
|
|
||||||
Each bound texture (via ``BIND``) will make available the following
|
Each bound texture (via ``BIND``) will make available the following
|
||||||
definitions to that shader pass, where NAME is the name of the bound
|
definitions to that shader pass, where NAME is the name of the bound
|
||||||
texture:
|
texture:
|
||||||
|
|
|
@ -269,6 +269,14 @@ bool parse_user_shader_pass(struct mp_log *log, struct bstr *body,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bstr_eatstart0(&line, "COMPUTE")) {
|
||||||
|
if (bstr_sscanf(line, "%d %d", &out->compute_w, &out->compute_h) != 2) {
|
||||||
|
mp_err(log, "Error while parsing COMPUTE!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Unknown command type
|
// Unknown command type
|
||||||
mp_err(log, "Unrecognized command '%.*s'!\n", BSTR_P(line));
|
mp_err(log, "Unrecognized command '%.*s'!\n", BSTR_P(line));
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -66,6 +66,8 @@ struct gl_user_shader {
|
||||||
struct szexp height[MAX_SZEXP_SIZE];
|
struct szexp height[MAX_SZEXP_SIZE];
|
||||||
struct szexp cond[MAX_SZEXP_SIZE];
|
struct szexp cond[MAX_SZEXP_SIZE];
|
||||||
int components;
|
int components;
|
||||||
|
int compute_w;
|
||||||
|
int compute_h;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse the next shader pass from 'body'. Returns false if the end of the
|
// Parse the next shader pass from 'body'. Returns false if the end of the
|
||||||
|
|
|
@ -1339,6 +1339,7 @@ static void hook_prelude(struct gl_video *p, const char *name, int id,
|
||||||
GLSLHF("#define %s_size texture_size%d\n", name, id);
|
GLSLHF("#define %s_size texture_size%d\n", name, id);
|
||||||
GLSLHF("#define %s_rot texture_rot%d\n", name, id);
|
GLSLHF("#define %s_rot texture_rot%d\n", name, id);
|
||||||
GLSLHF("#define %s_pt pixel_size%d\n", name, id);
|
GLSLHF("#define %s_pt pixel_size%d\n", name, id);
|
||||||
|
GLSLHF("#define %s_map texmap%d\n", name, id);
|
||||||
GLSLHF("#define %s_mul %f\n", name, tex.multiplier);
|
GLSLHF("#define %s_mul %f\n", name, tex.multiplier);
|
||||||
|
|
||||||
// Set up the sampling functions
|
// Set up the sampling functions
|
||||||
|
@ -1903,6 +1904,7 @@ static void user_hook(struct gl_video *p, struct img_tex tex,
|
||||||
pass_describe(p, "user shader: %.*s (%s)", BSTR_P(shader->desc),
|
pass_describe(p, "user shader: %.*s (%s)", BSTR_P(shader->desc),
|
||||||
plane_names[tex.type]);
|
plane_names[tex.type]);
|
||||||
|
|
||||||
|
compute_size_minimum(p, shader->compute_w, shader->compute_h);
|
||||||
load_shader(p, shader->pass_body);
|
load_shader(p, shader->pass_body);
|
||||||
GLSLF("color = hook();\n");
|
GLSLF("color = hook();\n");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue