From: Leo Liu Date: Mon, 18 Sep 2017 01:15:51 +0000 (-0400) Subject: vl/compositor: create RGB to YUV fragment shader X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a2ebe579922d77d2fc5cbefacf46db875615d9dc;p=mesa.git vl/compositor: create RGB to YUV fragment shader Acked-by: Christian König --- diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c index 0749c4700c4..c084de9fb09 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.c +++ b/src/gallium/auxiliary/vl/vl_compositor.c @@ -432,6 +432,43 @@ create_frag_shader_rgba(struct vl_compositor *c) return ureg_create_shader_and_destroy(shader, c->pipe); } +static void * +create_frag_shader_rgb_yuv(struct vl_compositor *c, bool y) +{ + struct ureg_program *shader; + struct ureg_src tc, sampler; + struct ureg_dst texel, fragment; + + struct ureg_src csc[3]; + unsigned i; + + shader = ureg_create(PIPE_SHADER_FRAGMENT); + if (!shader) + return false; + + for (i = 0; i < 3; ++i) + csc[i] = ureg_DECL_constant(shader, i); + + sampler = ureg_DECL_sampler(shader, 0); + tc = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_VTEX, TGSI_INTERPOLATE_LINEAR); + texel = ureg_DECL_temporary(shader); + fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0); + + ureg_TEX(shader, texel, TGSI_TEXTURE_2D, tc, sampler); + + if (y) { + ureg_DP4(shader, ureg_writemask(fragment, TGSI_WRITEMASK_X), csc[0], ureg_src(texel)); + } else { + for (i = 0; i < 2; ++i) + ureg_DP4(shader, ureg_writemask(fragment, TGSI_WRITEMASK_X << i), csc[i + 1], ureg_src(texel)); + } + + ureg_release_temporary(shader, texel); + ureg_END(shader); + + return ureg_create_shader_and_destroy(shader, c->pipe); +} + static bool init_shaders(struct vl_compositor *c) { @@ -483,6 +520,13 @@ init_shaders(struct vl_compositor *c) return false; } + c->fs_rgb_yuv.y = create_frag_shader_rgb_yuv(c, true); + c->fs_rgb_yuv.uv = create_frag_shader_rgb_yuv(c, false); + if (!c->fs_rgb_yuv.y || !c->fs_rgb_yuv.uv) { + debug_printf("Unable to create RGB-to-YUV fragment shader.\n"); + return false; + } + return true; } @@ -500,6 +544,8 @@ static void cleanup_shaders(struct vl_compositor *c) c->pipe->delete_fs_state(c->pipe, c->fs_palette.yuv); c->pipe->delete_fs_state(c->pipe, c->fs_palette.rgb); c->pipe->delete_fs_state(c->pipe, c->fs_rgba); + c->pipe->delete_fs_state(c->pipe, c->fs_rgb_yuv.y); + c->pipe->delete_fs_state(c->pipe, c->fs_rgb_yuv.uv); } static bool diff --git a/src/gallium/auxiliary/vl/vl_compositor.h b/src/gallium/auxiliary/vl/vl_compositor.h index 1930f93e290..cbad60a7031 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.h +++ b/src/gallium/auxiliary/vl/vl_compositor.h @@ -130,6 +130,11 @@ struct vl_compositor void *rgb; void *yuv; } fs_palette; + + struct { + void *y; + void *uv; + } fs_rgb_yuv; }; /**