From 0669babf2b5b50cbc185b0f714671b2c2b368778 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Wed, 4 Mar 2015 13:42:48 -0800 Subject: [PATCH] glamor: Perform texture2D() separately from swizzle. The texture2D() happens in each branch, so we may as well do it as early as possible and hide some of its latency in the branching instructions. Moving it outside the (uniform) control flow reduces the number of instructions in the fs_source shader from 64 to 46 and in the set_alpha_source shader from 69 to 47 on Haswell. Signed-off-by: Eric Anholt Reviewed-by: Eric Anholt --- glamor/glamor_core.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c index cbbe7593b..55174541f 100644 --- a/glamor/glamor_core.c +++ b/glamor/glamor_core.c @@ -173,46 +173,48 @@ glamor_init_finish_access_shaders(ScreenPtr screen) const char *fs_source = "void main()\n" "{\n" + " vec4 color = texture2D(sampler, source_texture);\n" " if (revert == REVERT_NONE) \n" " { \n" " if ((swap_rb != SWAP_NONE_DOWNLOADING) && (swap_rb != SWAP_NONE_UPLOADING)) \n" - " gl_FragColor = texture2D(sampler, source_texture).bgra;\n" + " gl_FragColor = color.bgra;\n" " else \n" - " gl_FragColor = texture2D(sampler, source_texture).rgba;\n" + " gl_FragColor = color.rgba;\n" " } \n" " else \n" " { \n" " if (swap_rb == SWAP_DOWNLOADING) \n" - " gl_FragColor = texture2D(sampler, source_texture).argb;\n" + " gl_FragColor = color.argb;\n" " else if (swap_rb == SWAP_NONE_DOWNLOADING)\n" - " gl_FragColor = texture2D(sampler, source_texture).abgr;\n" + " gl_FragColor = color.abgr;\n" " else if (swap_rb == SWAP_UPLOADING)\n" - " gl_FragColor = texture2D(sampler, source_texture).gbar;\n" + " gl_FragColor = color.gbar;\n" " else if (swap_rb == SWAP_NONE_UPLOADING)\n" - " gl_FragColor = texture2D(sampler, source_texture).abgr;\n" + " gl_FragColor = color.abgr;\n" " } \n" "}\n"; const char *set_alpha_source = "void main()\n" "{\n" + " vec4 color = texture2D(sampler, source_texture);\n" " if (revert == REVERT_NONE) \n" " { \n" " if ((swap_rb != SWAP_NONE_DOWNLOADING) && (swap_rb != SWAP_NONE_UPLOADING)) \n" - " gl_FragColor = vec4(texture2D(sampler, source_texture).bgr, 1);\n" + " gl_FragColor = vec4(color.bgr, 1);\n" " else \n" - " gl_FragColor = vec4(texture2D(sampler, source_texture).rgb, 1);\n" + " gl_FragColor = vec4(color.rgb, 1);\n" " } \n" " else \n" " { \n" " if (swap_rb == SWAP_DOWNLOADING) \n" - " gl_FragColor = vec4(1, texture2D(sampler, source_texture).rgb);\n" + " gl_FragColor = vec4(1, color.rgb);\n" " else if (swap_rb == SWAP_NONE_DOWNLOADING)\n" - " gl_FragColor = vec4(1, texture2D(sampler, source_texture).bgr);\n" + " gl_FragColor = vec4(1, color.bgr);\n" " else if (swap_rb == SWAP_UPLOADING)\n" - " gl_FragColor = vec4(texture2D(sampler, source_texture).gba, 1);\n" + " gl_FragColor = vec4(color.gba, 1);\n" " else if (swap_rb == SWAP_NONE_UPLOADING)\n" - " gl_FragColor = vec4(texture2D(sampler, source_texture).abg, 1);\n" + " gl_FragColor = vec4(color.abg, 1);\n" " } \n" "}\n"; GLint fs_prog, vs_prog, avs_prog, set_alpha_prog;