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>
This commit is contained in:
parent
9e9fcf5780
commit
0669babf2b
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user