[RFCv2 4/9] gl-renderer: Tweak YUV shader.
Pekka Paalanen
ppaalanen at gmail.com
Mon Nov 19 00:33:38 PST 2012
On Sat, 17 Nov 2012 03:23:55 +0100
John Kåre Alsaker <john.kare.alsaker at gmail.com> wrote:
> A more vectorized version of the YUV shader, may or may not be faster.
>
> It's also untested...
Hi John,
I would not do this, until you have some performance numbers, or Mesa's
GLSL compiler output showing it indeed is an improvement (though that
might not be enough).
You are obviously adding some useless operations, like multiply by 1.0,
and multiply by 0.0 then add. If a shader compiler is smart enough, it
could eliminate those on a scalar shader arch, like all(?) major modern
architectures are, right?
It might be an improvement on vector architectures, whose shader
compilers are not smart enough to vectorize well.
Too many unknowns, and this "optimization" really depends on the
compiler.
> ---
> src/gl-shaders.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/src/gl-shaders.c b/src/gl-shaders.c
> index 32bb70d..8595daf 100644
> --- a/src/gl-shaders.c
> +++ b/src/gl-shaders.c
> @@ -225,13 +225,12 @@ shader_yuv_constructor(struct shader_builder *sb)
> }
>
> append(&sb->body, sample);
> - append(&sb->body,
> - "yuv = vec3(1.16438356 * (yuv.x - 0.0625), yuv.yz - 0.5);\n" \
> - "gl_FragColor.r = yuv.x + 1.59602678 * yuv.z;\n" \
> - "gl_FragColor.g = yuv.x - 0.39176229 * yuv.y - " \
> - "0.81296764 * yuv.z;\n" \
> - "gl_FragColor.b = yuv.x + 2.01723214 * yuv.y;\n" \
> - "gl_FragColor.a = 1.0;\n");
> + append(&sb->body, "yuv = yuv * vec3(1.16438356, 1.0, 0.81296764) - " \
> + "vec3(0.07277397, 0.5, 0.40648382);\n" \
> + "vec3 diff = vec3(yuv.x, yuv.x - yuv.z, 1.0);\n" \
> + "gl_FragColor = yuv.zyyy * " \
> + "vec4(1.96321071, -0.39176229, 2.01723214, 0.0) + " \
> + "diff.xyxz;\n");
>
> return 1;
> }
Thanks,
pq
More information about the wayland-devel
mailing list