clutter/blur: Pass direction as vec2

Yet another way to reduce the instruction count of the fragment
shader. Passing a pair of floats once is virtually free, compared
to computing horizontal and vertical on each fragment run.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1646>
This commit is contained in:
Georges Basile Stavracas Neto 2020-12-17 00:42:16 -03:00 committed by Marge Bot
parent 8588352d1d
commit 925809ea75

View File

@ -69,11 +69,9 @@
static const char *gaussian_blur_glsl_declarations = static const char *gaussian_blur_glsl_declarations =
"uniform float sigma; \n" "uniform float sigma; \n"
"uniform float pixel_step; \n" "uniform float pixel_step; \n"
"uniform int vertical; \n"; "uniform vec2 direction; \n";
static const char *gaussian_blur_glsl = static const char *gaussian_blur_glsl =
" int horizontal = 1 - vertical; \n"
" \n"
" vec2 uv = vec2 (cogl_tex_coord.st); \n" " vec2 uv = vec2 (cogl_tex_coord.st); \n"
" \n" " \n"
" vec3 gauss_coefficient; \n" " vec3 gauss_coefficient; \n"
@ -96,8 +94,7 @@ static const char *gaussian_blur_glsl =
" float gauss_ratio = gauss_coefficient.x / coefficient_subtotal; \n" " float gauss_ratio = gauss_coefficient.x / coefficient_subtotal; \n"
" \n" " \n"
" float foffset = float (i) + gauss_ratio; \n" " float foffset = float (i) + gauss_ratio; \n"
" vec2 offset = vec2 (foffset * pixel_step * float (horizontal), \n" " vec2 offset = direction * foffset * pixel_step; \n"
" foffset * pixel_step * float (vertical)); \n"
" \n" " \n"
" ret += texture2D (cogl_sampler, uv + offset) * coefficient_subtotal; \n" " ret += texture2D (cogl_sampler, uv + offset) * coefficient_subtotal; \n"
" ret += texture2D (cogl_sampler, uv - offset) * coefficient_subtotal; \n" " ret += texture2D (cogl_sampler, uv - offset) * coefficient_subtotal; \n"
@ -179,7 +176,7 @@ update_blur_uniforms (ClutterBlur *blur,
gboolean vertical = pass->orientation == VERTICAL; gboolean vertical = pass->orientation == VERTICAL;
int sigma_uniform; int sigma_uniform;
int pixel_step_uniform; int pixel_step_uniform;
int vertical_uniform; int direction_uniform;
pixel_step_uniform = pixel_step_uniform =
cogl_pipeline_get_uniform_location (pass->pipeline, "pixel_step"); cogl_pipeline_get_uniform_location (pass->pipeline, "pixel_step");
@ -205,13 +202,20 @@ update_blur_uniforms (ClutterBlur *blur,
blur->sigma / blur->downscale_factor); blur->sigma / blur->downscale_factor);
} }
vertical_uniform = direction_uniform =
cogl_pipeline_get_uniform_location (pass->pipeline, "vertical"); cogl_pipeline_get_uniform_location (pass->pipeline, "direction");
if (vertical_uniform > -1) if (direction_uniform > -1)
{ {
cogl_pipeline_set_uniform_1i (pass->pipeline, gboolean horizontal = !vertical;
vertical_uniform, float direction[2] = {
vertical); horizontal,
vertical,
};
cogl_pipeline_set_uniform_float (pass->pipeline,
direction_uniform,
2, 1,
direction);
} }
} }