summaryrefslogtreecommitdiff
path: root/glamor
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2015-03-04 13:42:48 -0800
committerEric Anholt <eric@anholt.net>2015-03-24 12:43:34 -0700
commit0669babf2b5b50cbc185b0f714671b2c2b368778 (patch)
tree0b10e248f84bad6583aff353e801e125439b4bd6 /glamor
parent9e9fcf578063b4155aab4adab83f8d956bde5d1a (diff)
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 <eric@anholt.net> Reviewed-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'glamor')
-rw-r--r--glamor/glamor_core.c26
1 files 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;