summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/vl/vl_compositor.c
diff options
context:
space:
mode:
authorLeo Liu <[email protected]>2017-09-17 21:15:51 -0400
committerLeo Liu <[email protected]>2017-09-25 09:42:14 -0400
commita2ebe579922d77d2fc5cbefacf46db875615d9dc (patch)
treeecae4d3b81e47596180cde249efa1956226c840f /src/gallium/auxiliary/vl/vl_compositor.c
parent169c077d1d10db9e4938bae193fbd14b25cc5795 (diff)
vl/compositor: create RGB to YUV fragment shader
Acked-by: Christian König <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/vl/vl_compositor.c')
-rw-r--r--src/gallium/auxiliary/vl/vl_compositor.c46
1 files changed, 46 insertions, 0 deletions
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